@lovable.dev/workflows-sdk 0.0.0-dev.31 → 0.0.0-dev.32
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/README.md +5 -1
- package/dist/{branch-metadata-CkZQpEi7.js → branch-metadata-DmTc2agd.js} +1 -1
- package/dist/{context-escapes-Di8ThJie.js → context-escapes-DjpWclA6.js} +1 -1
- package/dist/{duplicate-ids-CRaMUWON.js → duplicate-ids-D7HMDNMh.js} +19 -87
- package/dist/durable-ids-Cx341nJQ.js +17 -0
- package/dist/{generate-Dk1_3N-g.js → generate-D1zt5ZZf.js} +18 -15
- package/dist/{graph-CBdqyIz5.js → graph-Cd9aL2HY.js} +10 -22
- package/dist/index.js +17 -29
- package/dist/{nested-operations-BBGsI1HN.js → nested-operations-DgjRz2Ps.js} +1 -1
- package/dist/{operation-descriptions-CZAlt0vd.js → operation-descriptions-5RfHLwu3.js} +1 -1
- package/dist/{step-metadata-Xksj4MjW.js → step-metadata-BdT25yO4.js} +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
- package/dist/durable-ids-LsygHSZC.js +0 -17
package/README.md
CHANGED
|
@@ -75,7 +75,11 @@ await ctx.step("load-customer", () => loadCustomer(ctx.input.customerId), {
|
|
|
75
75
|
});
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Every durable operation takes an explicit `id` — `ctx.approve({ id, title })`,
|
|
79
|
+
`ctx.waitForEvent(name, { id })`, `ctx.sleep(ms, { id })`, `ctx.now({ id })` —
|
|
80
|
+
and none is derived from a title, name or duration. IDs share one namespace per
|
|
81
|
+
workflow, so the build fails on a missing or repeated one, including two calls
|
|
82
|
+
on mutually exclusive branches. Keep side effects inside step bodies;
|
|
79
83
|
handler code outside a step may run more than once. A step body is one atomic
|
|
80
84
|
execution unit and cannot contain another durable operation.
|
|
81
85
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-CBdqyIz5.js";
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-Cd9aL2HY.js";
|
|
3
2
|
//#region src/manifests/duplicate-ids.ts
|
|
4
3
|
/** Where an explicit `{ id }` would sit for each operation. */
|
|
5
4
|
const optionsArgument = {
|
|
@@ -11,27 +10,22 @@ const optionsArgument = {
|
|
|
11
10
|
waitForEvent: 1,
|
|
12
11
|
step: -1
|
|
13
12
|
};
|
|
14
|
-
/**
|
|
13
|
+
/** Ids provably reached more than once, or why the handler could not be checked. */
|
|
15
14
|
async function findDuplicateOperationIds(handler) {
|
|
16
15
|
const api = await loadTypeScript();
|
|
17
|
-
if (!api) return
|
|
16
|
+
if (!api) return { unchecked: "typescript" };
|
|
18
17
|
const ts = api;
|
|
19
18
|
const handlerSource = workflowHandlerSource(handler);
|
|
20
|
-
if (!handlerSource) return
|
|
19
|
+
if (!handlerSource) return { unchecked: "handler" };
|
|
21
20
|
const declaration = ts.createSourceFile("handler.js", `const handler = ${handlerSource};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS).statements[0];
|
|
22
21
|
const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
|
|
23
|
-
if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) return
|
|
22
|
+
if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) return { unchecked: "handler" };
|
|
24
23
|
const parameter = fn.parameters[0]?.name;
|
|
25
24
|
if (!parameter || !ts.isIdentifier(parameter)) return [];
|
|
26
25
|
const context = parameter.text;
|
|
27
26
|
function literalString(node) {
|
|
28
27
|
return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
|
|
29
28
|
}
|
|
30
|
-
function literalNumber(node) {
|
|
31
|
-
if (!node || !ts.isNumericLiteral(node)) return void 0;
|
|
32
|
-
const value = Number(node.text);
|
|
33
|
-
return Number.isFinite(value) ? value : void 0;
|
|
34
|
-
}
|
|
35
29
|
function property(options, name) {
|
|
36
30
|
if (!options || !ts.isObjectLiteralExpression(options)) return void 0;
|
|
37
31
|
for (const entry of options.properties) {
|
|
@@ -48,74 +42,20 @@ async function findDuplicateOperationIds(handler) {
|
|
|
48
42
|
if (given === void 0) return false;
|
|
49
43
|
return literalString(given);
|
|
50
44
|
}
|
|
51
|
-
function defaultSource(call, method) {
|
|
52
|
-
switch (method) {
|
|
53
|
-
case "now":
|
|
54
|
-
case "uuid": return { kind: method };
|
|
55
|
-
case "sleep": {
|
|
56
|
-
const ms = literalNumber(call.arguments[0]);
|
|
57
|
-
return ms === void 0 ? void 0 : {
|
|
58
|
-
kind: "sleep",
|
|
59
|
-
ms
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
case "sleepUntil": {
|
|
63
|
-
const timestamp = literalNumber(call.arguments[0]);
|
|
64
|
-
return timestamp === void 0 ? void 0 : {
|
|
65
|
-
kind: "sleepUntil",
|
|
66
|
-
timestamp
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
case "waitForEvent": {
|
|
70
|
-
const name = literalString(call.arguments[0]);
|
|
71
|
-
return name === void 0 ? void 0 : {
|
|
72
|
-
kind: "waitForEvent",
|
|
73
|
-
name
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
case "approve": {
|
|
77
|
-
const title = literalString(property(call.arguments[0], "title"));
|
|
78
|
-
return title === void 0 ? void 0 : {
|
|
79
|
-
kind: "approve",
|
|
80
|
-
title
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
case "step": return;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
45
|
function repeatedLoopRegion(parent, child) {
|
|
87
46
|
if (ts.isForOfStatement(parent) || ts.isForInStatement(parent)) return parent.statement === child;
|
|
88
47
|
if (ts.isForStatement(parent)) return parent.statement === child || parent.condition === child || parent.incrementor === child;
|
|
89
48
|
return ts.isWhileStatement(parent) || ts.isDoStatement(parent);
|
|
90
49
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let repeatable = false;
|
|
50
|
+
/** Whether anything between the call and the handler can run it more than once. */
|
|
51
|
+
function repeatable(call) {
|
|
94
52
|
let child = call;
|
|
95
53
|
let parent = call.parent;
|
|
96
54
|
while (parent && child !== fn) {
|
|
97
|
-
if (ts.
|
|
98
|
-
if (parent.thenStatement === child) branches.set(String(parent.pos), "then");
|
|
99
|
-
else if (parent.elseStatement === child) branches.set(String(parent.pos), "else");
|
|
100
|
-
} else if (ts.isConditionalExpression(parent)) {
|
|
101
|
-
if (parent.whenTrue === child) branches.set(String(parent.pos), "true");
|
|
102
|
-
else if (parent.whenFalse === child) branches.set(String(parent.pos), "false");
|
|
103
|
-
} else if (ts.isCaseClause(parent) || ts.isDefaultClause(parent)) branches.set(String(parent.parent.pos), String(parent.parent.clauses.indexOf(parent)));
|
|
104
|
-
else if (parent !== fn && (repeatedLoopRegion(parent, child) || ts.isFunctionLike(parent))) repeatable = true;
|
|
55
|
+
if (parent !== fn && (repeatedLoopRegion(parent, child) || ts.isFunctionLike(parent))) return true;
|
|
105
56
|
child = parent;
|
|
106
57
|
parent = parent.parent;
|
|
107
58
|
}
|
|
108
|
-
return {
|
|
109
|
-
branches,
|
|
110
|
-
repeatable
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/** True when a shared conditional puts the two calls on different sides. */
|
|
114
|
-
function exclusive(a, b) {
|
|
115
|
-
for (const [node, side] of a.branches) {
|
|
116
|
-
const other = b.branches.get(node);
|
|
117
|
-
if (other !== void 0 && other !== side) return true;
|
|
118
|
-
}
|
|
119
59
|
return false;
|
|
120
60
|
}
|
|
121
61
|
const calls = [];
|
|
@@ -124,42 +64,34 @@ async function findDuplicateOperationIds(handler) {
|
|
|
124
64
|
const method = node.expression.name.text;
|
|
125
65
|
const index = optionsArgument[method];
|
|
126
66
|
const given = method === "step" ? literalString(node.arguments[0]) : explicitId(node.arguments[index]);
|
|
127
|
-
if (given !== void 0) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
id: resolved,
|
|
133
|
-
method,
|
|
134
|
-
defaulted: id === void 0,
|
|
135
|
-
...placement(node)
|
|
136
|
-
});
|
|
137
|
-
}
|
|
67
|
+
if (given !== void 0) calls.push({
|
|
68
|
+
id: given === false ? "" : given,
|
|
69
|
+
method,
|
|
70
|
+
repeatable: repeatable(node)
|
|
71
|
+
});
|
|
138
72
|
}
|
|
139
73
|
ts.forEachChild(node, visit);
|
|
140
74
|
};
|
|
141
75
|
visit(fn);
|
|
142
76
|
const found = /* @__PURE__ */ new Map();
|
|
143
77
|
for (const call of calls) {
|
|
144
|
-
if (call.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
id: call.id,
|
|
78
|
+
if (call.id === "") {
|
|
79
|
+
found.set(`${call.method}:missing:${found.size}`, {
|
|
80
|
+
id: "",
|
|
148
81
|
method: call.method,
|
|
149
|
-
reason
|
|
82
|
+
reason: "missing"
|
|
150
83
|
});
|
|
151
84
|
continue;
|
|
152
85
|
}
|
|
153
|
-
if (!call.defaulted) continue;
|
|
154
86
|
if (call.repeatable) {
|
|
155
|
-
found.set(
|
|
87
|
+
found.set(call.id, {
|
|
156
88
|
id: call.id,
|
|
157
89
|
method: call.method,
|
|
158
90
|
reason: "loop"
|
|
159
91
|
});
|
|
160
92
|
continue;
|
|
161
93
|
}
|
|
162
|
-
if (calls.some((other) => other !== call && other.id === call.id
|
|
94
|
+
if (calls.some((other) => other !== call && other.id === call.id)) found.set(call.id, {
|
|
163
95
|
id: call.id,
|
|
164
96
|
method: call.method,
|
|
165
97
|
reason: "repeated"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/core/durable-ids.ts
|
|
14
|
+
var durable_ids_exports = /* @__PURE__ */ __exportAll({ DURABLE_ID_REQUIRED: () => DURABLE_ID_REQUIRED });
|
|
15
|
+
const DURABLE_ID_REQUIRED = "every durable operation needs an explicit, workflow-unique id: ctx.approve({ id, title }), ctx.waitForEvent(name, { id }), ctx.sleep(ms, { id }), ctx.now({ id }), ctx.uuid({ id })";
|
|
16
|
+
//#endregion
|
|
17
|
+
export { durable_ids_exports as n, DURABLE_ID_REQUIRED as t };
|
|
@@ -6626,7 +6626,7 @@ function listValueFromJson(listValue, json) {
|
|
|
6626
6626
|
}
|
|
6627
6627
|
//#endregion
|
|
6628
6628
|
//#region package.json
|
|
6629
|
-
var version = "0.0.0-dev.
|
|
6629
|
+
var version = "0.0.0-dev.32";
|
|
6630
6630
|
//#endregion
|
|
6631
6631
|
//#region src/proto/lovable/appworkflows/v1/workflow_manifest_pb.ts
|
|
6632
6632
|
/**
|
|
@@ -6819,13 +6819,14 @@ function serializeSchema(schema, direction, label) {
|
|
|
6819
6819
|
}
|
|
6820
6820
|
}
|
|
6821
6821
|
async function generateManifests(definition, options = {}) {
|
|
6822
|
-
const { extractWorkflowGraph } = await import("./graph-
|
|
6823
|
-
const { findBranchMetadataIssues } = await import("./branch-metadata-
|
|
6824
|
-
const { findWorkflowContextEscapes } = await import("./context-escapes-
|
|
6825
|
-
const { findDuplicateOperationIds } = await import("./duplicate-ids-
|
|
6826
|
-
const {
|
|
6827
|
-
const {
|
|
6828
|
-
const {
|
|
6822
|
+
const { extractWorkflowGraph } = await import("./graph-Cd9aL2HY.js");
|
|
6823
|
+
const { findBranchMetadataIssues } = await import("./branch-metadata-DmTc2agd.js");
|
|
6824
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-DjpWclA6.js");
|
|
6825
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-D7HMDNMh.js");
|
|
6826
|
+
const { DURABLE_ID_REQUIRED } = await import("./durable-ids-Cx341nJQ.js").then((n) => n.n);
|
|
6827
|
+
const { findNestedDurableOperations } = await import("./nested-operations-DgjRz2Ps.js");
|
|
6828
|
+
const { findOperationDescriptionIssues } = await import("./operation-descriptions-5RfHLwu3.js");
|
|
6829
|
+
const { findStepMetadataIssues } = await import("./step-metadata-BdT25yO4.js");
|
|
6829
6830
|
const collection = registerWorkflows(definition);
|
|
6830
6831
|
const manifests = [];
|
|
6831
6832
|
for (const workflow of collection.workflows.flatMap(workflowVersions)) {
|
|
@@ -6838,13 +6839,15 @@ async function generateManifests(definition, options = {}) {
|
|
|
6838
6839
|
const parent = nested.parentStepId ? `ctx.step(${JSON.stringify(nested.parentStepId)})` : "ctx.step()";
|
|
6839
6840
|
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${nested.method}() inside ${parent}; step bodies are atomic and cannot contain durable operations`);
|
|
6840
6841
|
}
|
|
6841
|
-
|
|
6842
|
-
|
|
6843
|
-
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${duplicate.method}()
|
|
6842
|
+
const duplicates = await findDuplicateOperationIds(workflow.handler);
|
|
6843
|
+
if (!Array.isArray(duplicates)) {
|
|
6844
|
+
const remedy = duplicates.unchecked === "typescript" ? "install the \"typescript\" peer dependency" : "define the workflow handler as a function in the workflow file";
|
|
6845
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" could not be checked for durable operation ids; ${remedy}, because ${DURABLE_ID_REQUIRED}`);
|
|
6846
|
+
}
|
|
6847
|
+
for (const duplicate of duplicates) {
|
|
6848
|
+
if (duplicate.reason === "missing") throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" calls ctx.${duplicate.method}() without an id; ${DURABLE_ID_REQUIRED}`);
|
|
6849
|
+
const where = duplicate.reason === "loop" ? "inside a loop or callback" : "more than once";
|
|
6850
|
+
throw new Error(`@lovable.dev/workflows-sdk: workflow "${workflow.id}" uses id ${JSON.stringify(duplicate.id)} ${where}; every durable operation id must be unique within a workflow`);
|
|
6848
6851
|
}
|
|
6849
6852
|
const metadataIssue = (await findStepMetadataIssues(workflow.handler))[0];
|
|
6850
6853
|
if (metadataIssue?.kind === "description") {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { _ as WorkflowManifestUnknownNodeV1Schema, a as WorkflowManifestGraphEdgeV1Schema, b as create, c as WorkflowManifestLoopNodeV1Schema, d as WorkflowManifestParallelNodeV1Schema, f as WorkflowManifestRepeatedStepV1Schema, g as WorkflowManifestStepNodeV1Schema, h as WorkflowManifestStepExecutionPolicyV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestNowNodeV1Schema, m as WorkflowManifestSleepUntilNodeV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphNodeV1Schema, p as WorkflowManifestSleepNodeV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphV1Schema, u as WorkflowManifestOrderEdgeV1Schema, v as WorkflowManifestUuidNodeV1Schema, y as WorkflowManifestWaitForEventNodeV1Schema } from "./generate-
|
|
2
|
-
import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
|
|
1
|
+
import { _ as WorkflowManifestUnknownNodeV1Schema, a as WorkflowManifestGraphEdgeV1Schema, b as create, c as WorkflowManifestLoopNodeV1Schema, d as WorkflowManifestParallelNodeV1Schema, f as WorkflowManifestRepeatedStepV1Schema, g as WorkflowManifestStepNodeV1Schema, h as WorkflowManifestStepExecutionPolicyV1Schema, i as WorkflowManifestBranchNodeV1Schema, l as WorkflowManifestNowNodeV1Schema, m as WorkflowManifestSleepUntilNodeV1Schema, n as WorkflowManifestApproveNodeV1Schema, o as WorkflowManifestGraphNodeV1Schema, p as WorkflowManifestSleepNodeV1Schema, r as WorkflowManifestBranchEdgeV1Schema, s as WorkflowManifestGraphV1Schema, u as WorkflowManifestOrderEdgeV1Schema, v as WorkflowManifestUuidNodeV1Schema, y as WorkflowManifestWaitForEventNodeV1Schema } from "./generate-D1zt5ZZf.js";
|
|
3
2
|
//#region src/manifests/handler-source.ts
|
|
4
3
|
const nativeFunctionSource = /\{\s*\[native code\]\s*\}\s*$/;
|
|
5
4
|
function workflowHandlerSource(handler) {
|
|
@@ -277,10 +276,11 @@ async function extractWorkflowGraph(workflow) {
|
|
|
277
276
|
function operationDescription(options) {
|
|
278
277
|
return stringLiteral(option(readableOptions(option(options, "meta")), "description"));
|
|
279
278
|
}
|
|
280
|
-
|
|
279
|
+
/** Undefined when the call names no static id, which the graph cannot invent. */
|
|
280
|
+
function durableStepId(argument, options) {
|
|
281
281
|
if (argument && !options) return void 0;
|
|
282
282
|
const given = option(options, "id");
|
|
283
|
-
return given ? stringLiteral(given) :
|
|
283
|
+
return given ? stringLiteral(given) : void 0;
|
|
284
284
|
}
|
|
285
285
|
function durableNode(call, parents) {
|
|
286
286
|
const method = call.expression.name.text;
|
|
@@ -303,11 +303,8 @@ async function extractWorkflowGraph(workflow) {
|
|
|
303
303
|
const options = readableOptions(call.arguments[0]);
|
|
304
304
|
const title = stringLiteral(option(options, "title"));
|
|
305
305
|
if (title === void 0) return unknown("Dynamic approval titles are not supported yet", parents);
|
|
306
|
-
const stepId = durableStepId(call.arguments[0], options
|
|
307
|
-
|
|
308
|
-
title
|
|
309
|
-
}));
|
|
310
|
-
if (stepId === void 0) return unknown("Dynamic approval IDs are not supported yet", parents);
|
|
306
|
+
const stepId = durableStepId(call.arguments[0], options);
|
|
307
|
+
if (stepId === void 0) return unknown("ctx.approve needs a static { id }", parents);
|
|
311
308
|
const description = stringLiteral(option(options, "description"));
|
|
312
309
|
if (description === void 0) return unknown("Approval descriptions must be static strings", parents);
|
|
313
310
|
return addNode(title, {
|
|
@@ -323,10 +320,7 @@ async function extractWorkflowGraph(workflow) {
|
|
|
323
320
|
const event = stringLiteral(call.arguments[0]);
|
|
324
321
|
if (event === void 0) return unknown("Dynamic event names are not supported yet", parents);
|
|
325
322
|
const options = readableOptions(call.arguments[1]);
|
|
326
|
-
const stepId = durableStepId(call.arguments[1], options
|
|
327
|
-
kind: "waitForEvent",
|
|
328
|
-
name: event
|
|
329
|
-
}));
|
|
323
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
330
324
|
if (stepId === void 0) return unknown("Dynamic waitForEvent IDs are not supported yet", parents);
|
|
331
325
|
const description = operationDescription(options);
|
|
332
326
|
if (description === void 0) return unknown("Wait descriptions must be static strings", parents);
|
|
@@ -347,10 +341,7 @@ async function extractWorkflowGraph(workflow) {
|
|
|
347
341
|
const ms = numberLiteral(call.arguments[0]);
|
|
348
342
|
if (ms === void 0) return unknown("Dynamic sleep durations are not supported yet", parents);
|
|
349
343
|
const options = readableOptions(call.arguments[1]);
|
|
350
|
-
const stepId = durableStepId(call.arguments[1], options
|
|
351
|
-
kind: "sleep",
|
|
352
|
-
ms
|
|
353
|
-
}));
|
|
344
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
354
345
|
if (stepId === void 0) return unknown("Dynamic sleep IDs are not supported yet", parents);
|
|
355
346
|
const description = operationDescription(options);
|
|
356
347
|
if (description === void 0) return unknown("Sleep descriptions must be static strings", parents);
|
|
@@ -367,10 +358,7 @@ async function extractWorkflowGraph(workflow) {
|
|
|
367
358
|
const timestamp = numberLiteral(call.arguments[0]);
|
|
368
359
|
if (timestamp === void 0) return unknown("Dynamic sleepUntil timestamps are not supported yet", parents);
|
|
369
360
|
const options = readableOptions(call.arguments[1]);
|
|
370
|
-
const stepId = durableStepId(call.arguments[1], options
|
|
371
|
-
kind: "sleepUntil",
|
|
372
|
-
timestamp
|
|
373
|
-
}));
|
|
361
|
+
const stepId = durableStepId(call.arguments[1], options);
|
|
374
362
|
if (stepId === void 0) return unknown("Dynamic sleepUntil IDs are not supported yet", parents);
|
|
375
363
|
const description = operationDescription(options);
|
|
376
364
|
if (description === void 0) return unknown("Sleep descriptions must be static strings", parents);
|
|
@@ -384,7 +372,7 @@ async function extractWorkflowGraph(workflow) {
|
|
|
384
372
|
}, parents);
|
|
385
373
|
}
|
|
386
374
|
const options = readableOptions(call.arguments[0]);
|
|
387
|
-
const stepId = durableStepId(call.arguments[0], options
|
|
375
|
+
const stepId = durableStepId(call.arguments[0], options);
|
|
388
376
|
if (stepId === void 0) return unknown(`Dynamic ${method} IDs are not supported yet`, parents);
|
|
389
377
|
const description = operationDescription(options);
|
|
390
378
|
if (description === void 0) return unknown(`${method} descriptions must be static strings`, parents);
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { t as DURABLE_ID_REQUIRED } from "./durable-ids-Cx341nJQ.js";
|
|
2
|
+
import { C as registerWorkflows, D as hourly, E as daily, O as weekly, S as createWorkflow, T as defineSchedule, t as generateManifests, w as workflowVersions, x as createMiddleware } from "./generate-D1zt5ZZf.js";
|
|
3
3
|
import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
|
|
4
4
|
//#region src/stacks/tanstack/sse.ts
|
|
5
5
|
const HEADERS = {
|
|
@@ -201,16 +201,16 @@ async function replay(options) {
|
|
|
201
201
|
results.push(result);
|
|
202
202
|
options.onStepSettle?.(result);
|
|
203
203
|
}
|
|
204
|
-
function durable(kind, stepId, run, config,
|
|
204
|
+
function durable(kind, stepId, run, config, meta) {
|
|
205
|
+
if (!stepId) {
|
|
206
|
+
nonDeterminism = `ctx.${kind}() was called without an id; ${DURABLE_ID_REQUIRED}`;
|
|
207
|
+
return never;
|
|
208
|
+
}
|
|
205
209
|
const index = seq++;
|
|
206
210
|
const occurrence = occurrences.get(stepId) ?? 0;
|
|
207
211
|
occurrences.set(stepId, occurrence + 1);
|
|
208
|
-
if (
|
|
209
|
-
nonDeterminism = `
|
|
210
|
-
return never;
|
|
211
|
-
}
|
|
212
|
-
if (defaulted && occurrence > 0) {
|
|
213
|
-
nonDeterminism = `ctx.${kind}() was reached more than once with the default id "${stepId}"; pass an explicit { id } per call site`;
|
|
212
|
+
if (occurrence > 0) {
|
|
213
|
+
nonDeterminism = `id "${stepId}" was reached more than once; every durable operation id must be unique within a workflow`;
|
|
214
214
|
return never;
|
|
215
215
|
}
|
|
216
216
|
const key = memoKey(stepId, occurrence);
|
|
@@ -293,31 +293,19 @@ async function replay(options) {
|
|
|
293
293
|
attempt: 1,
|
|
294
294
|
runtime,
|
|
295
295
|
signal: controller.signal
|
|
296
|
-
}), void 0,
|
|
297
|
-
sleep: (ms, opts) => durable("sleep", opts?.id
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
sleepUntil: (timestamp, opts) => durable("sleep", opts?.id ?? defaultDurableId({
|
|
302
|
-
kind: "sleepUntil",
|
|
303
|
-
timestamp
|
|
304
|
-
}), void 0, { timestamp }, opts?.id === void 0, opts?.meta),
|
|
305
|
-
waitForEvent: (name, opts) => durable("waitForEvent", opts?.id ?? defaultDurableId({
|
|
306
|
-
kind: "waitForEvent",
|
|
307
|
-
name
|
|
308
|
-
}), void 0, { name }, opts?.id === void 0, opts?.meta),
|
|
309
|
-
approve: (opts) => durable("approve", opts.id ?? defaultDurableId({
|
|
310
|
-
kind: "approve",
|
|
311
|
-
title: opts.title
|
|
312
|
-
}), void 0, {
|
|
296
|
+
}), void 0, stepOptions?.meta),
|
|
297
|
+
sleep: (ms, opts) => durable("sleep", opts?.id, void 0, { ms }, opts?.meta),
|
|
298
|
+
sleepUntil: (timestamp, opts) => durable("sleep", opts?.id, void 0, { timestamp }, opts?.meta),
|
|
299
|
+
waitForEvent: (name, opts) => durable("waitForEvent", opts?.id, void 0, { name }, opts?.meta),
|
|
300
|
+
approve: (opts) => durable("approve", opts.id, void 0, {
|
|
313
301
|
title: opts.title,
|
|
314
302
|
...opts.description === void 0 ? {} : { description: opts.description }
|
|
315
|
-
},
|
|
303
|
+
}, {
|
|
316
304
|
...opts.meta,
|
|
317
305
|
...opts.description === void 0 ? {} : { description: opts.description }
|
|
318
306
|
}),
|
|
319
|
-
now: (opts) => durable("now", opts?.id
|
|
320
|
-
uuid: (opts) => durable("uuid", opts?.id
|
|
307
|
+
now: (opts) => durable("now", opts?.id, async () => Date.now(), void 0, opts?.meta),
|
|
308
|
+
uuid: (opts) => durable("uuid", opts?.id, async () => crypto.randomUUID(), void 0, opts?.meta),
|
|
321
309
|
emit: (name, value) => {
|
|
322
310
|
emitted.push({
|
|
323
311
|
name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-Cd9aL2HY.js";
|
|
2
2
|
//#region src/manifests/step-metadata.ts
|
|
3
3
|
async function findStepMetadataIssues(handler) {
|
|
4
4
|
const api = await loadTypeScript();
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as generateManifests } from "./generate-
|
|
1
|
+
import { t as generateManifests } from "./generate-D1zt5ZZf.js";
|
|
2
2
|
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { createServer } from "vite";
|
|
4
4
|
import { lstat, mkdir, mkdtemp, readdir, rename, rm, writeFile } from "node:fs/promises";
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
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 };
|