1import { OrchestrationGetWorkflowScriptError } from "@t3tools/contracts";
2import * as Effect from "effect/Effect";
3import { readContainedWorkflowFile } from "./workflowFileRead.ts";
4
5export const readWorkflowScript = Effect.fn("orchestration.readWorkflowScript")(function* (input: {
6 readonly scriptPath: string;
7}) {
8 const file = yield* readContainedWorkflowFile({
9 path: input.scriptPath,
10 extension: ".js",
11 byteCap: 256 * 1024,
12 }).pipe(
13 Effect.mapError(
14 (error) =>
15 new OrchestrationGetWorkflowScriptError({
16 reason: error.reason === "wrong-extension" ? "not-js" : error.reason,
17 scriptPath: error.path,
18 cause: error,
19 }),
20 ),
21 );
22 return { scriptPath: file.path, contents: file.contents, truncated: file.truncated };
23});