terse-cli 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +3 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/typescript/TypeScriptProvider.d.ts +2 -0
- package/dist/providers/typescript/TypeScriptProvider.d.ts.map +1 -1
- package/dist/providers/typescript/TypeScriptProvider.js +32 -13
- package/dist/providers/typescript/TypeScriptProvider.js.map +1 -1
- package/dist/providers/typescript/jobMacro.d.ts +1 -2
- package/dist/providers/typescript/jobMacro.d.ts.map +1 -1
- package/dist/providers/typescript/jobMacro.js +69 -111
- package/dist/providers/typescript/jobMacro.js.map +1 -1
- package/dist/providers/typescript/jobSources.d.ts +7 -0
- package/dist/providers/typescript/jobSources.d.ts.map +1 -0
- package/dist/providers/typescript/jobSources.js +46 -0
- package/dist/providers/typescript/jobSources.js.map +1 -0
- package/dist/providers/typescript/runtimes/durableJobRuntime.d.ts.map +1 -1
- package/dist/providers/typescript/runtimes/durableJobRuntime.js +98 -54
- package/dist/providers/typescript/runtimes/durableJobRuntime.js.map +1 -1
- package/dist/providers/typescript/stepMacro.d.ts +2 -29
- package/dist/providers/typescript/stepMacro.d.ts.map +1 -1
- package/dist/providers/typescript/stepMacro.js +29 -120
- package/dist/providers/typescript/stepMacro.js.map +1 -1
- package/dist/providers/typescript/terseWorkflow.d.ts +8 -0
- package/dist/providers/typescript/terseWorkflow.d.ts.map +1 -0
- package/dist/providers/typescript/terseWorkflow.js +8 -0
- package/dist/providers/typescript/terseWorkflow.js.map +1 -0
- package/package.json +6 -8
- package/src/providers/typescript/modules/github/github.triggers.hbs +4 -0
- package/templates/typescript/init/gitignore.hbs +1 -0
- package/templates/typescript/init/package.json.hbs +0 -1
- package/dist/providers/typescript/durableRuntime.d.ts +0 -20
- package/dist/providers/typescript/durableRuntime.d.ts.map +0 -1
- package/dist/providers/typescript/durableRuntime.js +0 -211
- package/dist/providers/typescript/durableRuntime.js.map +0 -1
- package/dist/providers/typescript/rewindRun.d.ts +0 -9
- package/dist/providers/typescript/rewindRun.d.ts.map +0 -1
- package/dist/providers/typescript/rewindRun.js +0 -111
- package/dist/providers/typescript/rewindRun.js.map +0 -1
- package/dist/providers/typescript/terseWorkflowBuilder.d.ts +0 -8
- package/dist/providers/typescript/terseWorkflowBuilder.d.ts.map +0 -1
- package/dist/providers/typescript/terseWorkflowBuilder.js +0 -70
- package/dist/providers/typescript/terseWorkflowBuilder.js.map +0 -1
- package/dist/providers/typescript/workflowCoreVersion.d.ts +0 -2
- package/dist/providers/typescript/workflowCoreVersion.d.ts.map +0 -1
- package/dist/providers/typescript/workflowCoreVersion.js +0 -7
- package/dist/providers/typescript/workflowCoreVersion.js.map +0 -1
- package/dist/providers/typescript/workflowShim.d.ts +0 -2
- package/dist/providers/typescript/workflowShim.d.ts.map +0 -1
- package/dist/providers/typescript/workflowShim.js +0 -51
- package/dist/providers/typescript/workflowShim.js.map +0 -1
- package/dist/terseWorld.d.ts +0 -4
- package/dist/terseWorld.d.ts.map +0 -1
- package/dist/terseWorld.js +0 -46
- package/dist/terseWorld.js.map +0 -1
- package/templates/typescript/workflow-shim/api.js +0 -5
- package/templates/typescript/workflow-shim/index.js +0 -2
- package/templates/typescript/workflow-shim/internal/builtins.js +0 -83
- package/templates/typescript/workflow-shim/internal/class-serialization.js +0 -1
- package/templates/typescript/workflow-shim/runtime.js +0 -1
- package/templates/typescript/workflow-shim/stdlib.js +0 -18
- package/templates/typescript/workflow-shim/workflow.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobMacro.js","sourceRoot":"","sources":["../../../src/providers/typescript/jobMacro.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jobMacro.js","sourceRoot":"","sources":["../../../src/providers/typescript/jobMacro.ts"],"names":[],"mappings":"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SourcesParams = {
|
|
2
|
+
readonly cwd: string;
|
|
3
|
+
readonly entryFile: string;
|
|
4
|
+
};
|
|
5
|
+
/** Copies and macro-transforms project sources for direct loading through tsx. */
|
|
6
|
+
export declare function prepareJobSources({ cwd, entryFile }: PrepareJobSourcesParams): string;
|
|
7
|
+
//# sourceMappingURL=jobSources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobSources.d.ts","sourceRoot":"","sources":["../../../src/providers/typescript/jobSources.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,uBAAuB,GAAG;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAiBrF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { transformJobSource } from "./jobMacro.js";
|
|
5
|
+
/** Copies and macro-transforms project sources for direct loading through tsx. */
|
|
6
|
+
export function prepareJobSources({ cwd, entryFile }) {
|
|
7
|
+
const sourceDirectory = path.join(cwd, "src");
|
|
8
|
+
const runtimeDirectory = path.join(cwd, ".terse", "runtime");
|
|
9
|
+
const preparedSourceDirectory = path.join(runtimeDirectory, "src");
|
|
10
|
+
fs.rmSync(runtimeDirectory, { recursive: true, force: true });
|
|
11
|
+
fs.mkdirSync(runtimeDirectory, { recursive: true });
|
|
12
|
+
fs.cpSync(sourceDirectory, preparedSourceDirectory, { recursive: true });
|
|
13
|
+
const ts = loadTypescript(cwd);
|
|
14
|
+
for (const file of findSourceFiles(preparedSourceDirectory)) {
|
|
15
|
+
const source = fs.readFileSync(file, "utf8");
|
|
16
|
+
const transformed = transformJobSource(ts, source, path.relative(cwd, file));
|
|
17
|
+
if (transformed.code !== source)
|
|
18
|
+
fs.writeFileSync(file, transformed.code);
|
|
19
|
+
}
|
|
20
|
+
return path.join(runtimeDirectory, entryFile);
|
|
21
|
+
}
|
|
22
|
+
function findSourceFiles(directory) {
|
|
23
|
+
const files = [];
|
|
24
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
|
25
|
+
const file = path.join(directory, entry.name);
|
|
26
|
+
if (entry.isDirectory())
|
|
27
|
+
files.push(...findSourceFiles(file));
|
|
28
|
+
else if (/\.(?:ts|tsx|mts|cts)$/.test(entry.name))
|
|
29
|
+
files.push(file);
|
|
30
|
+
}
|
|
31
|
+
return files;
|
|
32
|
+
}
|
|
33
|
+
function loadTypescript(cwd) {
|
|
34
|
+
try {
|
|
35
|
+
return createRequire(path.join(cwd, "package.json"))("typescript");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
try {
|
|
39
|
+
return createRequire(import.meta.url)("typescript");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new Error("Durable execution needs TypeScript in your project. Run: npm install --save-dev typescript");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=jobSources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobSources.js","sourceRoot":"","sources":["../../../src/providers/typescript/jobSources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAOlD,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAAC,EAAE,GAAG,EAAE,SAAS,EAA2B;IACzE,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC7C,MAAM,gBAAg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AE,KAAK,CAAC,IAAI,CAAC,CAAA;QAC7C,IAAI,KAAK,CAAC,WAAW,EAAE;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,CAAA;aACxD,IAAI,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvE,CAAC;IACD,OAAO,KAAK,CAAA;AAChB,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IAC/B,IAAI,CAAC;QACD,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;IACtE,CAAC;IAAC,MAAM,CAAC;QACL,IAAI,CAAC;YACD,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,CAAA;QACvD,CAAC;QAAC,MAAM,CAAC;YACL,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAA;QACjH,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableJobRuntime.d.ts","sourceRoot":"","sources":["../../../../src/providers/typescript/runtimes/durableJobRuntime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"durableJobRuntime.d.ts","sourceRoot":"","sources":["../../../../src/providers/typescript/runtimes/durableJobRuntime.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,UAAU,EAAkE,MAAM,iBAAiB,CAAA;AAGjH,eAAO,MAAM,iBAAiB,EAAE,UA0C/B,CAAA"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
|
+
import { FileJournalStore, Runtime } from "little-durable";
|
|
2
3
|
import path from "node:path";
|
|
3
|
-
import {
|
|
4
|
+
import { __fetchRegisteredDurableWorkflow, __inputRequestHook, fetchRegisteredJobs } from "terse-sdk";
|
|
5
|
+
import { runWithJobContext } from "terse-sdk/dist/runIdentity/jobContextStore.js";
|
|
6
|
+
import { ApiRoutes } from "terse-types";
|
|
7
|
+
import { fetchWithAuth, readRuntimeKeyOrBail } from "../../../api.js";
|
|
4
8
|
import { CliError } from "../../../cliError.js";
|
|
5
9
|
import { BACKEND_URL } from "../../../config.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { readRunStatus, resolveWorkflowRunId, rewindFailedRun } from "../rewindRun.js";
|
|
10
|
+
import { readProjectConfig } from "../../../projectConfig.js";
|
|
11
|
+
import { shouldRunTerseWorkflow } from "../terseWorkflow.js";
|
|
9
12
|
import { formatErrorDetail } from "./JobRuntime.js";
|
|
10
13
|
import { withSession } from "./session.js";
|
|
11
14
|
export const durableJobRuntime = {
|
|
12
15
|
async executeJob(job, runId, event, opts) {
|
|
16
|
+
if (!runId)
|
|
17
|
+
throw new CliError("durable_run_id_missing", "Durable execution requires a run ID.");
|
|
13
18
|
const isVerbose = opts?.verbose ?? true;
|
|
14
19
|
const pauseUiAround = opts?.pauseUiAround ?? (async (fn) => fn());
|
|
15
20
|
const apiKey = readRuntimeKeyOrBail();
|
|
@@ -17,12 +22,17 @@ export const durableJobRuntime = {
|
|
|
17
22
|
await withSession(apiKey, isVerbose, pauseUiAround, async (sessionId) => {
|
|
18
23
|
if (isVerbose)
|
|
19
24
|
console.log(chalk.cyan(` Job "${job.name}" started`));
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
if (!
|
|
25
|
-
|
|
25
|
+
const journalStore = createJournalStore();
|
|
26
|
+
const runtime = new Runtime({ journalStore });
|
|
27
|
+
const context = jobContext({ sessionId, runId, job, projectId: opts?.projectId });
|
|
28
|
+
const shouldRun = await shouldRunTerseWorkflow({ job, event, context });
|
|
29
|
+
if (!shouldRun)
|
|
30
|
+
return;
|
|
31
|
+
const workflow = __fetchRegisteredDurableWorkflow(job.name);
|
|
32
|
+
if (!workflow)
|
|
33
|
+
throw new Error(`No durable workflow was registered for job "${job.name}".`);
|
|
34
|
+
const outcome = await runWithJobContext(context, () => runtime.start(workflow, { runId, input: event }).waitForOutcome());
|
|
35
|
+
await handleOutcome({ runId, outcome, apiKey });
|
|
26
36
|
}, opts?.onSessionEvent, opts?.session);
|
|
27
37
|
}
|
|
28
38
|
catch (error) {
|
|
@@ -30,10 +40,6 @@ export const durableJobRuntime = {
|
|
|
30
40
|
throw error;
|
|
31
41
|
throw new CliError("job_execution_failed", `Job "${job.name}" threw an error.`, { detail: formatErrorDetail(error) });
|
|
32
42
|
}
|
|
33
|
-
finally {
|
|
34
|
-
if (!isCliRunCommandEnabled())
|
|
35
|
-
await closeDurableRuntime();
|
|
36
|
-
}
|
|
37
43
|
},
|
|
38
44
|
async resumeRun(runId, opts) {
|
|
39
45
|
return driveResume(runId, opts);
|
|
@@ -46,31 +52,40 @@ async function driveResume(runId, opts, input) {
|
|
|
46
52
|
const isVerbose = opts?.verbose ?? true;
|
|
47
53
|
const pauseUiAround = opts?.pauseUiAround ?? (async (fn) => fn());
|
|
48
54
|
const apiKey = readRuntimeKeyOrBail();
|
|
49
|
-
const dataDir = resolveDataDir();
|
|
50
|
-
const workflowRunId = resolveWorkflowRunId(dataDir, runId);
|
|
51
|
-
const status = readRunStatus(dataDir, workflowRunId);
|
|
52
55
|
try {
|
|
53
|
-
await withSession(apiKey, isVerbose, pauseUiAround, async () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (input) {
|
|
64
|
-
await deliverInput(rt, input, isVerbose);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
await rt.start();
|
|
68
|
-
}
|
|
69
|
-
if (isCliRunCommandEnabled())
|
|
70
|
-
return;
|
|
71
|
-
await rt.awaitRunResult(workflowRunId);
|
|
56
|
+
await withSession(apiKey, isVerbose, pauseUiAround, async (sessionId) => {
|
|
57
|
+
const journalStore = createJournalStore();
|
|
58
|
+
const runtime = new Runtime({ journalStore });
|
|
59
|
+
const run = await runtime.getRun({ runId });
|
|
60
|
+
const job = fetchRegisteredJobs().get(run.workflowName);
|
|
61
|
+
if (!job)
|
|
62
|
+
throw new Error(`No registered job matches durable workflow "${run.workflowName}".`);
|
|
63
|
+
const workflow = __fetchRegisteredDurableWorkflow(job.name);
|
|
64
|
+
if (!workflow)
|
|
65
|
+
throw new Error(`No durable workflow was registered for job "${job.name}".`);
|
|
72
66
|
if (isVerbose)
|
|
73
|
-
console.log(chalk.
|
|
67
|
+
console.log(chalk.cyan(` Resuming run ${runId}`));
|
|
68
|
+
const context = jobContext({ sessionId, runId, job, projectId: readProjectConfig()?.projectId });
|
|
69
|
+
const outcome = await runWithJobContext(context, async () => {
|
|
70
|
+
const suspension = await runtime.getSuspension({ runId });
|
|
71
|
+
if (input) {
|
|
72
|
+
if (!suspension || suspension.request.name !== __inputRequestHook.name) {
|
|
73
|
+
throw new Error(`No unresolved input wait with token "${input.token}" exists in run "${runId}".`);
|
|
74
|
+
}
|
|
75
|
+
const request = __inputRequestHook.request.safeParse(suspension.request.payload);
|
|
76
|
+
if (!request.success || request.data.token !== input.token) {
|
|
77
|
+
throw new Error(`No unresolved input wait with token "${input.token}" exists in run "${runId}".`);
|
|
78
|
+
}
|
|
79
|
+
const resolution = __inputRequestHook.resolution.parse(input.payload);
|
|
80
|
+
return runtime.resumeHook(__inputRequestHook, { runId, workflow, waitId: suspension.waitId, resolution }).waitForOutcome();
|
|
81
|
+
}
|
|
82
|
+
return suspension?.request.name === "timer"
|
|
83
|
+
? runtime.resumeTimer(workflow, { runId, waitId: suspension.waitId }).waitForOutcome()
|
|
84
|
+
: runtime.resume(workflow, { runId }).waitForOutcome();
|
|
85
|
+
});
|
|
86
|
+
await handleOutcome({ runId, outcome, apiKey });
|
|
87
|
+
if (isVerbose && outcome.status === "completed")
|
|
88
|
+
console.log(chalk.green(` Run ${runId} completed`));
|
|
74
89
|
});
|
|
75
90
|
}
|
|
76
91
|
catch (error) {
|
|
@@ -78,26 +93,55 @@ async function driveResume(runId, opts, input) {
|
|
|
78
93
|
throw error;
|
|
79
94
|
throw new CliError("run_resume_failed", `Run "${runId}" could not be resumed.`, { detail: formatErrorDetail(error) });
|
|
80
95
|
}
|
|
81
|
-
finally {
|
|
82
|
-
if (!isCliRunCommandEnabled())
|
|
83
|
-
await closeDurableRuntime();
|
|
84
|
-
}
|
|
85
96
|
}
|
|
86
|
-
function
|
|
87
|
-
return
|
|
97
|
+
function createJournalStore() {
|
|
98
|
+
return new FileJournalStore(resolveDataDirectory());
|
|
88
99
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
function resolveDataDirectory() {
|
|
101
|
+
return process.env.TERSE_JOURNAL_ROOT ?? path.join(process.cwd(), ".terse", "data");
|
|
102
|
+
}
|
|
103
|
+
function jobContext({ sessionId, runId, job, projectId }) {
|
|
104
|
+
return {
|
|
105
|
+
sessionId,
|
|
106
|
+
runId,
|
|
107
|
+
apiBaseUrl: BACKEND_URL,
|
|
108
|
+
jobName: job.name,
|
|
109
|
+
projectId
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function handleOutcome({ runId, outcome, apiKey }) {
|
|
113
|
+
if (outcome.status === "completed")
|
|
114
|
+
return;
|
|
115
|
+
if (outcome.status === "failed") {
|
|
116
|
+
const error = new Error(outcome.error.message);
|
|
117
|
+
error.name = outcome.error.name;
|
|
118
|
+
throw error;
|
|
96
119
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
const body = suspendRequest({ runId, suspension: outcome.suspension });
|
|
121
|
+
await fetchWithAuth(ApiRoutes.SDK.SUSPEND, apiKey, body, "POST");
|
|
122
|
+
}
|
|
123
|
+
function suspendRequest({ runId, suspension }) {
|
|
124
|
+
const payload = suspension.request.payload;
|
|
125
|
+
if (suspension.request.name === "timer") {
|
|
126
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload) || typeof payload.wakeAt !== "string") {
|
|
127
|
+
throw new Error("Timer suspension has an invalid wakeAt.");
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
runId,
|
|
131
|
+
kind: "timer",
|
|
132
|
+
delaySeconds: Math.max(1, Math.ceil((Date.parse(payload.wakeAt) - Date.now()) / 1_000)),
|
|
133
|
+
idempotencyKey: suspension.waitId
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (suspension.request.name === __inputRequestHook.name) {
|
|
137
|
+
const input = __inputRequestHook.request.parse(payload);
|
|
138
|
+
return {
|
|
139
|
+
runId,
|
|
140
|
+
kind: "input",
|
|
141
|
+
hookToken: input.token,
|
|
142
|
+
idempotencyKey: suspension.waitId
|
|
143
|
+
};
|
|
101
144
|
}
|
|
145
|
+
throw new Error(`Terse does not know how to park hook "${suspension.request.name}".`);
|
|
102
146
|
}
|
|
103
147
|
//# sourceMappingURL=durableJobRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"durableJobRuntime.js","sourceRoot":"","sources":["../../../../src/providers/typescript/runtimes/durableJobRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"durableJobRuntime.js","sourceRoot":"","sources":["../../../../src/providers/typescript/runtimes/durableJobRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,gCAAgC,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAErG,OA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AC;QACtD,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACvD,OAAO;YACH,KAAK;YACL,IAAI,EAAE,OAAO;YACb,SAAS,EAAE,KAAK,CAAC,KAAK;YACtB,cAAc,EAAE,UAAU,CAAC,MAAM;SACpC,CAAA;IACL,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,yCAAyC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAA;AACzF,CAAC"}
|
|
@@ -1,37 +1,10 @@
|
|
|
1
1
|
import type TS from "typescript";
|
|
2
|
-
export type StepDef = {
|
|
3
|
-
name: string;
|
|
4
|
-
def: string;
|
|
5
|
-
};
|
|
6
2
|
export type StepEdit = {
|
|
7
3
|
start: number;
|
|
8
4
|
end: number;
|
|
9
5
|
text: string;
|
|
10
6
|
};
|
|
11
|
-
export declare enum StepCallKind {
|
|
12
|
-
JobStep = "jobStep",
|
|
13
|
-
Step = "step"
|
|
14
|
-
}
|
|
15
|
-
export type StepCall = {
|
|
16
|
-
kind: StepCallKind.Step;
|
|
17
|
-
call: TS.CallExpression;
|
|
18
|
-
} | {
|
|
19
|
-
kind: StepCallKind.JobStep;
|
|
20
|
-
call: TS.CallExpression;
|
|
21
|
-
config: TS.ObjectLiteralExpression;
|
|
22
|
-
};
|
|
23
7
|
export declare function findStepImportName(ts: typeof TS, sf: TS.SourceFile): string | null;
|
|
24
|
-
export declare function matchStepCall(ts: typeof TS, node: TS.Node, stepName: string | null):
|
|
25
|
-
export declare function transformStep(ts: typeof TS, sf: TS.SourceFile,
|
|
26
|
-
kind: StepCallKind.Step;
|
|
27
|
-
}>, fileName: string, index: number, stepName: string | null): {
|
|
28
|
-
stepDef: StepDef;
|
|
29
|
-
edit: StepEdit;
|
|
30
|
-
};
|
|
31
|
-
export declare function transformJobStep(ts: typeof TS, sf: TS.SourceFile, step: Extract<StepCall, {
|
|
32
|
-
kind: StepCallKind.JobStep;
|
|
33
|
-
}>, fileName: string, index: number, stepName: string | null): {
|
|
34
|
-
stepDef: StepDef;
|
|
35
|
-
edit: StepEdit;
|
|
36
|
-
} | null;
|
|
8
|
+
export declare function matchStepCall(ts: typeof TS, node: TS.Node, stepName: string | null): TS.CallExpression | null;
|
|
9
|
+
export declare function transformStep(ts: typeof TS, sf: TS.SourceFile, call: TS.CallExpression, fileName: string, index: number): StepEdit;
|
|
37
10
|
//# sourceMappingURL=stepMacro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stepMacro.d.ts","sourceRoot":"","sources":["../../../src/providers/typescript/stepMacro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"stepMacro.d.ts","sourceRoot":"","sources":["../../../src/providers/typescript/stepMacro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC,MAAM,MAAM,QAAQ,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAEnE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,MAAM,GAAG,IAAI,CASlF;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC,cAAc,GAAG,IAAI,CAG7G;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAkClI"}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export var StepCallKind;
|
|
2
|
-
(function (StepCallKind) {
|
|
3
|
-
StepCallKind["JobStep"] = "jobStep";
|
|
4
|
-
StepCallKind["Step"] = "step";
|
|
5
|
-
})(StepCallKind || (StepCallKind = {}));
|
|
6
|
-
// The local binding of `import { step } from "terse-sdk"` (aliases included), so plain
|
|
7
|
-
// `step` stays a safe name: user-defined step() functions never match the macro.
|
|
8
1
|
export function findStepImportName(ts, sf) {
|
|
9
2
|
for (const statement of sf.statements) {
|
|
10
3
|
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.moduleSpecifier.text !== "terse-sdk")
|
|
@@ -12,122 +5,79 @@ export function findStepImportName(ts, sf) {
|
|
|
12
5
|
const named = statement.importClause?.namedBindings;
|
|
13
6
|
if (!named || !ts.isNamedImports(named))
|
|
14
7
|
continue;
|
|
15
|
-
const element = named.elements.find(
|
|
8
|
+
const element = named.elements.find(candidate => (candidate.propertyName ?? candidate.name).text === "step");
|
|
16
9
|
if (element)
|
|
17
10
|
return element.name.text;
|
|
18
11
|
}
|
|
19
12
|
return null;
|
|
20
13
|
}
|
|
21
14
|
export function matchStepCall(ts, node, stepName) {
|
|
22
|
-
if (!ts.isCallExpression(node) || !ts.isIdentifier(node.expression))
|
|
15
|
+
if (!stepName || !ts.isCallExpression(node) || !ts.isIdentifier(node.expression) || node.expression.text !== stepName)
|
|
23
16
|
return null;
|
|
24
|
-
|
|
25
|
-
return { kind: StepCallKind.Step, call: node };
|
|
26
|
-
}
|
|
27
|
-
if (node.expression.text === "jobStep" && node.arguments.length > 0 && ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
28
|
-
return { kind: StepCallKind.JobStep, call: node, config: node.arguments[0] };
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
17
|
+
return node;
|
|
31
18
|
}
|
|
32
|
-
|
|
33
|
-
// `step(client.method(args))` hoists only the callee into a "use step" function.
|
|
34
|
-
// The argument expressions stay at the call site, where they evaluate in workflow
|
|
35
|
-
// scope and cross the step boundary as serialized step arguments.
|
|
36
|
-
export function transformStep(ts, sf, step, fileName, index, stepName) {
|
|
37
|
-
const { call } = step;
|
|
19
|
+
export function transformStep(ts, sf, call, fileName, index) {
|
|
38
20
|
const inner = call.arguments.length === 1 ? call.arguments[0] : undefined;
|
|
39
|
-
if (inner
|
|
21
|
+
if (!inner)
|
|
40
22
|
throw stepMacroError(sf, call, fileName, "step() takes exactly one argument: a direct call, e.g. step(client.method(args)).");
|
|
41
|
-
if (!ts.isCallExpression(inner))
|
|
23
|
+
if (!ts.isCallExpression(inner)) {
|
|
42
24
|
throw stepMacroError(sf, call, fileName, "step() must wrap a direct call, e.g. step(client.method(args)). Storing the promise in a variable first is not supported.");
|
|
43
|
-
|
|
25
|
+
}
|
|
26
|
+
if (containsStepCall(ts, inner, ts.isIdentifier(call.expression) ? call.expression.text : null)) {
|
|
44
27
|
throw stepMacroError(sf, call, fileName, "Steps cannot be nested inside a step() call. Await each step separately.");
|
|
28
|
+
}
|
|
45
29
|
const calleeNames = [];
|
|
46
|
-
let optionalChain = false;
|
|
47
30
|
let calleeRoot = inner.expression;
|
|
48
31
|
while (ts.isPropertyAccessExpression(calleeRoot)) {
|
|
49
32
|
calleeNames.unshift(calleeRoot.name.text);
|
|
50
|
-
if (calleeRoot.questionDotToken)
|
|
51
|
-
optionalChain = true;
|
|
52
33
|
calleeRoot = calleeRoot.expression;
|
|
53
34
|
}
|
|
54
35
|
if (!ts.isIdentifier(calleeRoot)) {
|
|
55
36
|
throw stepMacroError(sf, call, fileName, "step() requires a plain property path like step(client.method(args)). Computed access and intermediate calls are not supported.");
|
|
56
37
|
}
|
|
57
38
|
calleeNames.unshift(calleeRoot.text);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const fnArg = findLiteralFunctionArg(ts, arg);
|
|
63
|
-
if (fnArg) {
|
|
64
|
-
throw stepMacroError(sf, fnArg, fileName, "A function passed as a step argument cannot cross the step boundary, because step arguments are serialized into the journal. Move the whole call into a module-scope helper so the callback stays inside the step, then wrap the helper call in step().");
|
|
39
|
+
for (const argument of inner.arguments) {
|
|
40
|
+
const functionValue = findLiteralFunctionArgument(ts, argument);
|
|
41
|
+
if (functionValue) {
|
|
42
|
+
throw stepMacroError(sf, functionValue, fileName, "A function cannot cross the durable step input boundary. Move the callback inside a helper and wrap that helper call in step().");
|
|
65
43
|
}
|
|
66
44
|
}
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const def = `export async function ${name}(...__terseArgs${paramsType})${returnType} {\n` + ` "use step"\n` + ` return await ${calleeText}(...__terseArgs)\n` + `}`;
|
|
73
|
-
const text = `${name}(${inner.arguments.map(a => a.getText(sf)).join(", ")})`;
|
|
74
|
-
return { stepDef: { name, def }, edit: { start: call.getStart(sf), end: call.getEnd(), text } };
|
|
75
|
-
}
|
|
76
|
-
// MARK: jobStep
|
|
77
|
-
export function transformJobStep(ts, sf, step, fileName, index, stepName) {
|
|
78
|
-
const isProp = (p, key) => ts.isPropertyAssignment(p) && ts.isIdentifier(p.name) && p.name.text === key;
|
|
79
|
-
const { call, config } = step;
|
|
80
|
-
const inputProp = config.properties.find(p => isProp(p, "input"));
|
|
81
|
-
const inputSchemaProp = config.properties.find(p => isProp(p, "inputSchema"));
|
|
82
|
-
const outputSchemaProp = config.properties.find(p => isProp(p, "outputSchema"));
|
|
83
|
-
const run = config.properties.find(p => isProp(p, "run"))?.initializer;
|
|
84
|
-
if (!run || !(ts.isArrowFunction(run) || ts.isFunctionExpression(run)))
|
|
85
|
-
return null;
|
|
86
|
-
if (containsStepCall(ts, config, stepName))
|
|
87
|
-
throw stepMacroError(sf, call, fileName, "Steps cannot be nested inside a jobStep(). Await each step separately.");
|
|
88
|
-
const name = `terseStep_${index}`;
|
|
89
|
-
const def = stepFunctionText(ts, sf, name, run, inputSchemaProp?.initializer, outputSchemaProp?.initializer);
|
|
90
|
-
const text = `${name}(${inputProp ? inputProp.initializer.getText(sf) : ""})`;
|
|
91
|
-
return { stepDef: { name, def }, edit: { start: call.getStart(sf), end: call.getEnd(), text } };
|
|
45
|
+
const callee = inner.expression.getText(sf);
|
|
46
|
+
const args = inner.arguments.map(argument => argument.getText(sf)).join(", ");
|
|
47
|
+
const name = `${calleeNames.join(".")}:${index}`;
|
|
48
|
+
const text = `__runDurableStep({ name: "${name}", input: [${args}] as const, run: async (__terseArgs) => await ${callee}(...__terseArgs) })`;
|
|
49
|
+
return { start: call.getStart(sf), end: call.getEnd(), text };
|
|
92
50
|
}
|
|
93
|
-
function
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
51
|
+
function containsStepCall(ts, node, stepName) {
|
|
52
|
+
const visit = (candidate) => {
|
|
53
|
+
if (matchStepCall(ts, candidate, stepName))
|
|
54
|
+
return true;
|
|
55
|
+
return ts.forEachChild(candidate, visit);
|
|
56
|
+
};
|
|
57
|
+
return ts.forEachChild(node, visit) ?? false;
|
|
99
58
|
}
|
|
100
|
-
|
|
101
|
-
// Finds a function expression that ends up inside the evaluated argument value,
|
|
102
|
-
// where serialization would reject it: the argument itself, or a literal object
|
|
103
|
-
// property / array element (recursively). Functions merely consumed while the
|
|
104
|
-
// argument evaluates, like the arrow in `users.map(u => u.email)`, are fine since
|
|
105
|
-
// only the resulting data crosses the boundary. Those sit inside call expressions,
|
|
106
|
-
// which this deliberately does not descend into.
|
|
107
|
-
function findLiteralFunctionArg(ts, node) {
|
|
59
|
+
function findLiteralFunctionArgument(ts, node) {
|
|
108
60
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node))
|
|
109
61
|
return node;
|
|
110
62
|
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node))
|
|
111
|
-
return
|
|
63
|
+
return findLiteralFunctionArgument(ts, node.expression);
|
|
112
64
|
if (ts.isObjectLiteralExpression(node)) {
|
|
113
65
|
for (const property of node.properties) {
|
|
114
66
|
if (ts.isMethodDeclaration(property) || ts.isGetAccessorDeclaration(property) || ts.isSetAccessorDeclaration(property))
|
|
115
67
|
return property;
|
|
116
68
|
if (ts.isPropertyAssignment(property)) {
|
|
117
|
-
const found =
|
|
69
|
+
const found = findLiteralFunctionArgument(ts, property.initializer);
|
|
118
70
|
if (found)
|
|
119
71
|
return found;
|
|
120
72
|
}
|
|
121
73
|
}
|
|
122
|
-
return null;
|
|
123
74
|
}
|
|
124
75
|
if (ts.isArrayLiteralExpression(node)) {
|
|
125
76
|
for (const element of node.elements) {
|
|
126
|
-
const found =
|
|
77
|
+
const found = findLiteralFunctionArgument(ts, element);
|
|
127
78
|
if (found)
|
|
128
79
|
return found;
|
|
129
80
|
}
|
|
130
|
-
return null;
|
|
131
81
|
}
|
|
132
82
|
return null;
|
|
133
83
|
}
|
|
@@ -135,45 +85,4 @@ function stepMacroError(sf, node, fileName, message) {
|
|
|
135
85
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
136
86
|
return new Error(`${fileName}:${line}: ${message}`);
|
|
137
87
|
}
|
|
138
|
-
function containsStepCall(ts, node, stepName) {
|
|
139
|
-
const walk = (n) => (matchStepCall(ts, n, stepName) ? true : ts.forEachChild(n, walk));
|
|
140
|
-
return ts.forEachChild(node, walk) ?? false;
|
|
141
|
-
}
|
|
142
|
-
// Lexical lookup along the parent chain: params of enclosing functions and
|
|
143
|
-
// declarations directly inside enclosing blocks. Anything not found here is
|
|
144
|
-
// module-scope (or a global), which the steps bundle can also see.
|
|
145
|
-
function isDeclaredInEnclosingScopes(ts, from, name) {
|
|
146
|
-
let cur = from.parent;
|
|
147
|
-
while (cur && !ts.isSourceFile(cur)) {
|
|
148
|
-
if (scopeDeclares(ts, cur, name))
|
|
149
|
-
return true;
|
|
150
|
-
cur = cur.parent;
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
function scopeDeclares(ts, node, name) {
|
|
155
|
-
if (ts.isFunctionLike(node))
|
|
156
|
-
return node.parameters.some(p => bindingDeclares(ts, p.name, name));
|
|
157
|
-
if (ts.isBlock(node))
|
|
158
|
-
return node.statements.some(s => statementDeclares(ts, s, name));
|
|
159
|
-
if (ts.isCatchClause(node))
|
|
160
|
-
return node.variableDeclaration !== undefined && bindingDeclares(ts, node.variableDeclaration.name, name);
|
|
161
|
-
if (ts.isForOfStatement(node) || ts.isForInStatement(node))
|
|
162
|
-
return ts.isVariableDeclarationList(node.initializer) && node.initializer.declarations.some(d => bindingDeclares(ts, d.name, name));
|
|
163
|
-
if (ts.isForStatement(node))
|
|
164
|
-
return node.initializer !== undefined && ts.isVariableDeclarationList(node.initializer) && node.initializer.declarations.some(d => bindingDeclares(ts, d.name, name));
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
function statementDeclares(ts, statement, name) {
|
|
168
|
-
if (ts.isVariableStatement(statement))
|
|
169
|
-
return statement.declarationList.declarations.some(d => bindingDeclares(ts, d.name, name));
|
|
170
|
-
if (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement))
|
|
171
|
-
return statement.name?.text === name;
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
function bindingDeclares(ts, binding, name) {
|
|
175
|
-
if (ts.isIdentifier(binding))
|
|
176
|
-
return binding.text === name;
|
|
177
|
-
return binding.elements.some(el => !ts.isOmittedExpression(el) && bindingDeclares(ts, el.name, name));
|
|
178
|
-
}
|
|
179
88
|
//# sourceMappingURL=stepMacro.js.map
|