@lovable.dev/workflows-sdk 0.0.0-dev.1 → 0.0.0-dev.11

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.
@@ -0,0 +1,115 @@
1
+ import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
2
+ import { loadTypeScript } from "./graph-CPDci8jW.js";
3
+ //#region src/manifests/duplicate-ids.ts
4
+ /** Where an explicit `{ id }` would sit for each operation. */
5
+ const optionsArgument = {
6
+ now: 0,
7
+ uuid: 0,
8
+ approve: 0,
9
+ sleep: 1,
10
+ sleepUntil: 1,
11
+ waitForEvent: 1
12
+ };
13
+ /**
14
+ * Durable calls sharing one defaulted id, which replay cannot tell apart. The
15
+ * pass sees literal arguments only; anything dynamic is left to the runtime.
16
+ */
17
+ async function findDuplicateDefaultIds(handler) {
18
+ const api = await loadTypeScript();
19
+ if (!api) return [];
20
+ const ts = api;
21
+ const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
22
+ const declaration = source.statements[0];
23
+ const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
24
+ if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn) || source.text.includes("[native code]")) return [];
25
+ const parameter = fn.parameters[0]?.name;
26
+ if (!parameter || !ts.isIdentifier(parameter)) return [];
27
+ const context = parameter.text;
28
+ function literalString(node) {
29
+ return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
30
+ }
31
+ function literalNumber(node) {
32
+ if (!node || !ts.isNumericLiteral(node)) return void 0;
33
+ const value = Number(node.text);
34
+ return Number.isFinite(value) ? value : void 0;
35
+ }
36
+ function hasExplicitId(options) {
37
+ if (!options || !ts.isObjectLiteralExpression(options)) return options !== void 0;
38
+ return options.properties.some((property) => {
39
+ if (ts.isPropertyAssignment(property) || ts.isShorthandPropertyAssignment(property)) {
40
+ const name = property.name;
41
+ return (ts.isIdentifier(name) || ts.isStringLiteral(name)) && name.text === "id";
42
+ }
43
+ return ts.isSpreadAssignment(property);
44
+ });
45
+ }
46
+ function sourceOf(call, method) {
47
+ switch (method) {
48
+ case "now":
49
+ case "uuid": return { kind: method };
50
+ case "sleep": {
51
+ const ms = literalNumber(call.arguments[0]);
52
+ return ms === void 0 ? void 0 : {
53
+ kind: "sleep",
54
+ ms
55
+ };
56
+ }
57
+ case "sleepUntil": {
58
+ const timestamp = literalNumber(call.arguments[0]);
59
+ return timestamp === void 0 ? void 0 : {
60
+ kind: "sleepUntil",
61
+ timestamp
62
+ };
63
+ }
64
+ case "waitForEvent": {
65
+ const name = literalString(call.arguments[0]);
66
+ return name === void 0 ? void 0 : {
67
+ kind: "waitForEvent",
68
+ name
69
+ };
70
+ }
71
+ case "approve": {
72
+ const options = call.arguments[0];
73
+ const title = options && ts.isObjectLiteralExpression(options) ? titleOf(options) : void 0;
74
+ return title === void 0 ? void 0 : {
75
+ kind: "approve",
76
+ title
77
+ };
78
+ }
79
+ }
80
+ }
81
+ function titleOf(options) {
82
+ for (const property of options.properties) {
83
+ if (!ts.isPropertyAssignment(property)) continue;
84
+ const name = property.name;
85
+ if ((ts.isIdentifier(name) || ts.isStringLiteral(name) ? name.text : void 0) === "title") return literalString(property.initializer);
86
+ }
87
+ }
88
+ const counts = /* @__PURE__ */ new Map();
89
+ const visit = (node) => {
90
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text in optionsArgument) {
91
+ const method = node.expression.name.text;
92
+ if (!hasExplicitId(node.arguments[optionsArgument[method]])) {
93
+ const derived = sourceOf(node, method);
94
+ if (derived) {
95
+ const id = defaultDurableId(derived);
96
+ const seen = counts.get(id);
97
+ if (seen) seen.count += 1;
98
+ else counts.set(id, {
99
+ method,
100
+ count: 1
101
+ });
102
+ }
103
+ }
104
+ }
105
+ ts.forEachChild(node, visit);
106
+ };
107
+ visit(fn);
108
+ return [...counts].filter(([, seen]) => seen.count > 1).map(([id, seen]) => ({
109
+ id,
110
+ method: seen.method,
111
+ count: seen.count
112
+ }));
113
+ }
114
+ //#endregion
115
+ export { findDuplicateDefaultIds };
@@ -0,0 +1,17 @@
1
+ //#region src/core/durable-ids.ts
2
+ /**
3
+ * Shared by the runtime and the build-time check, so the ids a build rejects
4
+ * are exactly the ones replay would collide.
5
+ */
6
+ function defaultDurableId(source) {
7
+ switch (source.kind) {
8
+ case "now": return "now";
9
+ case "uuid": return "uuid";
10
+ case "sleep": return `sleep:${source.ms}`;
11
+ case "sleepUntil": return `sleepUntil:${source.timestamp}`;
12
+ case "waitForEvent": return `event:${source.name}`;
13
+ case "approve": return `approve:${source.title}`;
14
+ }
15
+ }
16
+ //#endregion
17
+ export { defaultDurableId as t };
@@ -0,0 +1,235 @@
1
+ import { createMiddleware, createWorkflow } from "@tanstack/workflow-core";
2
+ //#region src/core/identifier.ts
3
+ function assertIdentifier(kind, id) {
4
+ if (typeof id !== "string" || id.trim() === "" || id !== id.trim()) throw new Error(`@lovable.dev/workflows-sdk: ${kind} IDs must be non-empty and have no surrounding whitespace`);
5
+ }
6
+ //#endregion
7
+ //#region src/core/cadence.ts
8
+ const WEEKDAYS = [
9
+ "mon",
10
+ "tue",
11
+ "wed",
12
+ "thu",
13
+ "fri",
14
+ "sat",
15
+ "sun"
16
+ ];
17
+ const WEEKDAY_NAMES = {
18
+ mon: "mon",
19
+ monday: "mon",
20
+ tue: "tue",
21
+ tuesday: "tue",
22
+ wed: "wed",
23
+ wednesday: "wed",
24
+ thu: "thu",
25
+ thursday: "thu",
26
+ fri: "fri",
27
+ friday: "fri",
28
+ sat: "sat",
29
+ saturday: "sat",
30
+ sun: "sun",
31
+ sunday: "sun"
32
+ };
33
+ function fail$1(message) {
34
+ throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
35
+ }
36
+ function parseWeekday(value, label) {
37
+ const day = typeof value === "string" ? WEEKDAY_NAMES[value.toLowerCase()] : void 0;
38
+ if (day === void 0) fail$1(`${label} names an unknown day "${String(value)}"; use ${WEEKDAYS.join(", ")}`);
39
+ return day;
40
+ }
41
+ function parseDays(value, label) {
42
+ if (!Array.isArray(value) || value.length === 0) fail$1(`${label} must be a non-empty array of days`);
43
+ const days = [...new Set(value.map((entry) => parseWeekday(entry, label)))].sort((a, b) => WEEKDAYS.indexOf(a) - WEEKDAYS.indexOf(b));
44
+ return days.length === WEEKDAYS.length ? null : days;
45
+ }
46
+ function parseHoursOfDay(value, label) {
47
+ const entries = Array.isArray(value) ? value : [value];
48
+ if (entries.length === 0) fail$1(`${label} must name at least one hour`);
49
+ for (const entry of entries) if (!Number.isInteger(entry) || entry < 0 || entry > 23) fail$1(`${label}: ${JSON.stringify(entry)} must be a whole hour from 0 to 23; the platform picks the minute`);
50
+ return [...new Set(entries)].sort((a, b) => a - b);
51
+ }
52
+ function hourly(options) {
53
+ if (options !== void 0) fail$1(`hourly() takes no options; the platform decides where in the hour a schedule runs`);
54
+ return { kind: "hourly" };
55
+ }
56
+ function daily(options = {}) {
57
+ return {
58
+ kind: "daily",
59
+ at: options.at === void 0 ? null : parseHoursOfDay(options.at, "daily({ at })"),
60
+ days: options.days === void 0 ? null : parseDays(options.days, "daily({ days })")
61
+ };
62
+ }
63
+ function weekly(options) {
64
+ if (typeof options !== "object" || options === null) fail$1(`weekly() requires { on: "monday", at: 7 }`);
65
+ return {
66
+ kind: "daily",
67
+ at: options.at === void 0 ? null : parseHoursOfDay(options.at, "weekly({ at })"),
68
+ days: [parseWeekday(options.on, "weekly({ on })")]
69
+ };
70
+ }
71
+ function isHourSet(value) {
72
+ if (value === null) return true;
73
+ if (!Array.isArray(value) || value.length === 0) return false;
74
+ return value.every((hour, index) => Number.isInteger(hour) && hour >= 0 && hour <= 23 && (index === 0 || hour > value[index - 1]));
75
+ }
76
+ function isDaySet(value) {
77
+ if (value === null) return true;
78
+ if (!Array.isArray(value) || value.length === 0 || value.length >= WEEKDAYS.length) return false;
79
+ const indexes = value.map((day) => WEEKDAYS.indexOf(day));
80
+ return indexes.every((index, position) => index >= 0 && (position === 0 || index > indexes[position - 1]));
81
+ }
82
+ function isCadence(value) {
83
+ if (typeof value !== "object" || value === null) return false;
84
+ const cadence = value;
85
+ if (cadence.kind === "hourly") return Object.keys(cadence).length === 1;
86
+ if (cadence.kind === "daily") return isHourSet(cadence.at) && isDaySet(cadence.days);
87
+ return false;
88
+ }
89
+ //#endregion
90
+ //#region src/core/schedule.ts
91
+ const OVERLAP_POLICIES = [
92
+ "skip",
93
+ "allow",
94
+ "buffer-one"
95
+ ];
96
+ function fail(message) {
97
+ throw new Error(`@lovable.dev/workflows-sdk: ${message}`);
98
+ }
99
+ const CANONICAL_ZONES = new Set(typeof Intl.supportedValuesOf === "function" ? Intl.supportedValuesOf("timeZone") : []);
100
+ function resolveTimeZone(schedule) {
101
+ const timeZone = schedule.timeZone;
102
+ if (typeof timeZone !== "string" || timeZone === "") fail(`schedule "${schedule.id}" needs a timeZone, such as "Europe/Stockholm" or "UTC"`);
103
+ if (timeZone !== "UTC" && CANONICAL_ZONES.size > 0 && !CANONICAL_ZONES.has(timeZone)) fail(`schedule "${schedule.id}" timeZone "${timeZone}" must be "UTC" or a canonical IANA name such as "Europe/Stockholm"; fixed offsets and aliases such as "EST", "GMT", "Etc/GMT+5", and "US/Pacific" are not accepted`);
104
+ new Intl.DateTimeFormat("en", { timeZone });
105
+ return timeZone;
106
+ }
107
+ function defineSchedule(schedule) {
108
+ assertIdentifier("schedule", schedule.id);
109
+ if (!isCadence(schedule.cadence)) fail(`schedule "${schedule.id}" cadence must come from hourly(), daily(), or weekly()`);
110
+ const cadence = schedule.cadence;
111
+ const timeZone = resolveTimeZone(schedule);
112
+ const overlapPolicy = schedule.overlapPolicy ?? "skip";
113
+ if (!OVERLAP_POLICIES.includes(overlapPolicy)) fail(`schedule "${schedule.id}" overlapPolicy must be one of ${OVERLAP_POLICIES.join(", ")}`);
114
+ const enabled = schedule.enabled ?? true;
115
+ if (typeof enabled !== "boolean") fail(`schedule "${schedule.id}" enabled must be a boolean`);
116
+ return {
117
+ ...schedule,
118
+ type: "schedule",
119
+ cadence,
120
+ timeZone,
121
+ overlapPolicy,
122
+ enabled
123
+ };
124
+ }
125
+ //#endregion
126
+ //#region src/core/workflow.ts
127
+ function registerWorkflows(definition) {
128
+ for (const key of Object.keys(definition)) {
129
+ if (key === "workflows" || key === "triggers") continue;
130
+ throw new Error(key === "schedules" ? `@lovable.dev/workflows-sdk: registerWorkflows() no longer takes "schedules"; rename the key to "triggers"` : `@lovable.dev/workflows-sdk: registerWorkflows() does not take "${key}"`);
131
+ }
132
+ const { workflows, triggers = [] } = definition;
133
+ const ids = /* @__PURE__ */ new Set();
134
+ for (const workflow of workflows) {
135
+ if (workflow.__kind !== "workflow" || typeof workflow.handler !== "function") throw new Error("@lovable.dev/workflows-sdk: expected a completed createWorkflow().handler() definition");
136
+ assertIdentifier("workflow", workflow.id);
137
+ if (!/^[a-z0-9][a-z0-9_-]{0,127}$/.test(workflow.id)) throw new Error("@lovable.dev/workflows-sdk: workflow names must be 1–128 lowercase letters, digits, hyphens or underscores, starting with a letter or digit");
138
+ if (ids.has(workflow.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate workflow ID "${workflow.id}"`);
139
+ ids.add(workflow.id);
140
+ }
141
+ const scheduleIds = /* @__PURE__ */ new Set();
142
+ const registeredTriggers = triggers.map((trigger) => {
143
+ const definition = defineSchedule(trigger);
144
+ if (scheduleIds.has(definition.id)) throw new Error(`@lovable.dev/workflows-sdk: duplicate schedule ID "${definition.id}"`);
145
+ if (!workflows.includes(definition.workflow)) throw new Error(`@lovable.dev/workflows-sdk: schedule "${definition.id}" references an unregistered workflow`);
146
+ scheduleIds.add(definition.id);
147
+ return definition;
148
+ });
149
+ return {
150
+ workflows: [...workflows],
151
+ triggers: registeredTriggers
152
+ };
153
+ }
154
+ //#endregion
155
+ //#region src/manifests/json.ts
156
+ function toJson(value, jsonPath, ancestors = /* @__PURE__ */ new Set()) {
157
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
158
+ if (typeof value === "number" && Number.isFinite(value)) return value;
159
+ if (typeof value !== "object" || ancestors.has(value)) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain finite, acyclic JSON values`);
160
+ ancestors.add(value);
161
+ try {
162
+ if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must not contain symbol keys`);
163
+ if (Array.isArray(value)) {
164
+ if (Object.keys(value).length !== value.length) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must be a dense JSON array without extra properties`);
165
+ return Array.from(value, (item, index) => toJson(item, `${jsonPath}[${index}]`, ancestors));
166
+ }
167
+ if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new Error(`@lovable.dev/workflows-sdk: ${jsonPath} must contain plain JSON objects`);
168
+ return Object.fromEntries(Object.keys(value).sort().map((key) => [key, toJson(value[key], `${jsonPath}.${key}`, ancestors)]));
169
+ } finally {
170
+ ancestors.delete(value);
171
+ }
172
+ }
173
+ //#endregion
174
+ //#region src/manifests/generate.ts
175
+ function serializeSchema(schema, direction, label) {
176
+ if (!schema) return void 0;
177
+ const standard = schema["~standard"];
178
+ if (typeof standard.jsonSchema?.[direction] !== "function") throw new Error(`@lovable.dev/workflows-sdk: ${label} must support Standard JSON Schema conversion`);
179
+ try {
180
+ return toJson(standard.jsonSchema[direction]({ target: "draft-2020-12" }), label);
181
+ } catch (cause) {
182
+ throw new Error(`@lovable.dev/workflows-sdk: cannot serialize ${label}`, { cause });
183
+ }
184
+ }
185
+ async function generateManifests(definition) {
186
+ const { extractWorkflowGraph } = await import("./graph-CPDci8jW.js");
187
+ const { findDuplicateDefaultIds } = await import("./duplicate-ids-CSzTGBYE.js");
188
+ const collection = registerWorkflows(definition);
189
+ const manifests = [];
190
+ for (const workflow of collection.workflows) {
191
+ if (workflow.previousVersions?.length) throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" previousVersions are not supported yet`);
192
+ for (const duplicate of await findDuplicateDefaultIds(workflow.handler)) throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${duplicate.method}() ${duplicate.count} times with the default id "${duplicate.id}"; replay cannot tell them apart, so pass an explicit { id } per call site`);
193
+ const metadata = {
194
+ id: workflow.id,
195
+ ...workflow.description === void 0 ? {} : { description: workflow.description },
196
+ ...workflow.version === void 0 ? {} : { version: workflow.version },
197
+ ...workflow.inputSchema ? { inputSchema: serializeSchema(workflow.inputSchema, "input", `${workflow.id}.input`) } : {},
198
+ ...workflow.outputSchema ? { outputSchema: serializeSchema(workflow.outputSchema, "output", `${workflow.id}.output`) } : {},
199
+ ...workflow.stateSchema ? { stateSchema: serializeSchema(workflow.stateSchema, "output", `${workflow.id}.state`) } : {}
200
+ };
201
+ const triggers = [];
202
+ for (const schedule of collection.triggers.filter((trigger) => trigger.workflow === workflow)) {
203
+ const input = toJson(schedule.input, `schedule "${schedule.id}" input`);
204
+ const schema = schedule.workflow.inputSchema;
205
+ if (schema) {
206
+ const result = await schema["~standard"].validate(input);
207
+ if (result.issues) throw new Error(`@lovable.dev/workflows-sdk: schedule "${schedule.id}" input is invalid: ${result.issues.map((issue) => issue.message).join("; ")}`);
208
+ }
209
+ triggers.push({
210
+ type: schedule.type,
211
+ id: schedule.id,
212
+ cadence: schedule.cadence,
213
+ timeZone: schedule.timeZone,
214
+ enabled: schedule.enabled,
215
+ overlapPolicy: schedule.overlapPolicy,
216
+ input
217
+ });
218
+ }
219
+ triggers.sort((a, b) => {
220
+ const key = (entry) => `${entry.type}\u0000${entry.id}`;
221
+ return key(a) < key(b) ? -1 : key(a) > key(b) ? 1 : 0;
222
+ });
223
+ const manifest = {
224
+ version: 1,
225
+ workflow: metadata,
226
+ triggers,
227
+ graph: await extractWorkflowGraph(workflow.handler)
228
+ };
229
+ toJson(manifest, "manifest");
230
+ manifests.push(manifest);
231
+ }
232
+ return manifests.sort((a, b) => a.workflow.id < b.workflow.id ? -1 : a.workflow.id > b.workflow.id ? 1 : 0);
233
+ }
234
+ //#endregion
235
+ export { defineSchedule as a, weekly as c, registerWorkflows as i, createMiddleware as n, daily as o, createWorkflow as r, hourly as s, generateManifests as t };
@@ -1,6 +1,24 @@
1
- import * as ts from "typescript";
2
- //#region src/graph-extract.ts
3
- function extractWorkflowGraph(handler) {
1
+ //#region src/manifests/graph.ts
2
+ const durableMethods = {
3
+ step: 0,
4
+ approve: 0,
5
+ waitForEvent: 0,
6
+ sleep: 0,
7
+ sleepUntil: 0
8
+ };
9
+ let loaded;
10
+ async function loadTypeScript() {
11
+ if (loaded !== void 0) return loaded;
12
+ try {
13
+ const module = await import("typescript");
14
+ const api = module.default ?? module;
15
+ loaded = typeof api?.createSourceFile === "function" ? api : null;
16
+ } catch {
17
+ loaded = null;
18
+ }
19
+ return loaded;
20
+ }
21
+ async function extractWorkflowGraph(handler) {
4
22
  const graph = {
5
23
  source: "inferred",
6
24
  scope: "handler",
@@ -9,7 +27,6 @@ function extractWorkflowGraph(handler) {
9
27
  edges: [],
10
28
  diagnostics: []
11
29
  };
12
- const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
13
30
  function addNode(node, parents) {
14
31
  const id = `node-${graph.nodes.length}`;
15
32
  graph.nodes.push({
@@ -23,14 +40,24 @@ function extractWorkflowGraph(handler) {
23
40
  });
24
41
  return [id];
25
42
  }
26
- function unknown(reason, parents) {
43
+ function degrade(reason) {
27
44
  graph.complete = false;
28
45
  if (!graph.diagnostics.includes(reason)) graph.diagnostics.push(reason);
46
+ }
47
+ function unknown(reason, parents) {
48
+ degrade(reason);
29
49
  return addNode({
30
50
  kind: "unknown",
31
51
  label: reason
32
52
  }, parents);
33
53
  }
54
+ const api = await loadTypeScript();
55
+ if (!api) {
56
+ unknown("Install typescript to infer step graphs", []);
57
+ return graph;
58
+ }
59
+ const ts = api;
60
+ const source = ts.createSourceFile("handler.js", `const handler = ${Function.prototype.toString.call(handler)};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS);
34
61
  const declaration = source.statements[0];
35
62
  const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
36
63
  if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn) || source.text.includes("[native code]")) {
@@ -47,22 +74,94 @@ function extractWorkflowGraph(handler) {
47
74
  if (skipFunctions && ts.isFunctionLike(node)) return false;
48
75
  return predicate(node) || Boolean(ts.forEachChild(node, (child) => contains(child, predicate, skipFunctions) || void 0));
49
76
  }
50
- function contextStep(node) {
51
- return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text === "step";
77
+ function durableCall(node) {
78
+ return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text in durableMethods;
79
+ }
80
+ function stringLiteral(node) {
81
+ return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
82
+ }
83
+ function numberLiteral(node) {
84
+ if (!node || !ts.isNumericLiteral(node)) return void 0;
85
+ const value = Number(node.text);
86
+ return Number.isFinite(value) ? value : void 0;
87
+ }
88
+ function readableOptions(node) {
89
+ return node && ts.isObjectLiteralExpression(node) && node.properties.every(ts.isPropertyAssignment) ? node : void 0;
90
+ }
91
+ function option(options, name) {
92
+ for (const property of options?.properties ?? []) {
93
+ if (!ts.isPropertyAssignment(property)) continue;
94
+ if ((ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : void 0) === name) return property.initializer;
95
+ }
96
+ }
97
+ function durableNode(call, parents) {
98
+ const method = call.expression.name.text;
99
+ if (method === "step") {
100
+ const stepId = stringLiteral(call.arguments[0]);
101
+ if (stepId === void 0) return unknown("Dynamic step IDs are not supported yet", parents);
102
+ return addNode({
103
+ kind: "step",
104
+ stepId,
105
+ label: stepId
106
+ }, parents);
107
+ }
108
+ if (method === "approve") {
109
+ const options = readableOptions(call.arguments[0]);
110
+ const title = stringLiteral(option(options, "title"));
111
+ if (title === void 0) return unknown("Dynamic approval titles are not supported yet", parents);
112
+ const given = option(options, "description");
113
+ const description = stringLiteral(given);
114
+ if (given && description === void 0) degrade("Dynamic approval descriptions are not recorded");
115
+ return addNode({
116
+ kind: "approve",
117
+ config: {
118
+ title,
119
+ ...description === void 0 ? {} : { description }
120
+ },
121
+ label: title
122
+ }, parents);
123
+ }
124
+ if (method === "waitForEvent") {
125
+ const event = stringLiteral(call.arguments[0]);
126
+ if (event === void 0) return unknown("Dynamic event names are not supported yet", parents);
127
+ const options = readableOptions(call.arguments[1]);
128
+ if (call.arguments[1] && !options) degrade("Dynamic waitForEvent options are not recorded");
129
+ const given = option(options, "deadline");
130
+ const deadline = numberLiteral(given);
131
+ if (given && deadline === void 0) degrade("Dynamic waitForEvent deadlines are not recorded");
132
+ return addNode({
133
+ kind: "wait-for-event",
134
+ config: {
135
+ event,
136
+ ...deadline === void 0 ? {} : { deadline }
137
+ },
138
+ label: event
139
+ }, parents);
140
+ }
141
+ if (method === "sleep") {
142
+ const ms = numberLiteral(call.arguments[0]);
143
+ if (ms === void 0) return unknown("Dynamic sleep durations are not supported yet", parents);
144
+ return addNode({
145
+ kind: "sleep",
146
+ config: { ms },
147
+ label: `sleep ${ms}ms`
148
+ }, parents);
149
+ }
150
+ const timestamp = numberLiteral(call.arguments[0]);
151
+ if (timestamp === void 0) return unknown("Dynamic sleepUntil timestamps are not supported yet", parents);
152
+ return addNode({
153
+ kind: "sleep-until",
154
+ config: { timestamp },
155
+ label: `sleep until ${timestamp}`
156
+ }, parents);
52
157
  }
53
158
  function expression(node, parents, awaited = false) {
54
159
  if (ts.isParenthesizedExpression(node)) return expression(node.expression, parents, awaited);
55
160
  if (ts.isAwaitExpression(node)) return expression(node.expression, parents, true);
56
- if (contextStep(node)) {
57
- if (!awaited) return unknown("Unawaited steps are not supported yet", parents);
58
- const stepId = node.arguments[0];
59
- if (!stepId || !ts.isStringLiteral(stepId) && !ts.isNoSubstitutionTemplateLiteral(stepId)) return unknown("Dynamic step IDs are not supported yet", parents);
60
- const tails = addNode({
61
- kind: "step",
62
- stepId: stepId.text,
63
- label: stepId.text
64
- }, parents);
65
- if (node.arguments.slice(1).some((argument) => contains(argument, contextStep))) return unknown("Nested steps are not supported yet", tails);
161
+ if (durableCall(node)) {
162
+ if (!awaited) return unknown("Unawaited durable calls are not supported yet", parents);
163
+ const tails = durableNode(node, parents);
164
+ if (node.arguments.some((argument) => contains(argument, durableCall))) return unknown("Nested durable calls are not supported yet", tails);
66
165
  return tails;
67
166
  }
68
167
  if (awaited && ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === "Promise" && node.expression.name.text === "all" && node.arguments.length === 1 && ts.isArrayLiteralExpression(node.arguments[0])) {
@@ -99,4 +198,4 @@ function extractWorkflowGraph(handler) {
99
198
  return graph;
100
199
  }
101
200
  //#endregion
102
- export { extractWorkflowGraph };
201
+ export { extractWorkflowGraph, loadTypeScript };