@lovable.dev/workflows-sdk 0.0.0-dev.4 → 0.0.0-dev.41

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,103 @@
1
+ import { loadTypeScript, t as workflowHandlerSource } from "./graph-Ci7cGckB.js";
2
+ //#region src/manifests/duplicate-ids.ts
3
+ /** Where an explicit `{ id }` would sit for each operation. */
4
+ const optionsArgument = {
5
+ now: 0,
6
+ uuid: 0,
7
+ approve: 0,
8
+ sleep: 1,
9
+ sleepUntil: 1,
10
+ waitForEvent: 1,
11
+ step: -1
12
+ };
13
+ /** Ids provably reached more than once, or why the handler could not be checked. */
14
+ async function findDuplicateOperationIds(handler) {
15
+ const api = await loadTypeScript();
16
+ if (!api) return { unchecked: "typescript" };
17
+ const ts = api;
18
+ const handlerSource = workflowHandlerSource(handler);
19
+ if (!handlerSource) return { unchecked: "handler" };
20
+ const declaration = ts.createSourceFile("handler.js", `const handler = ${handlerSource};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.JS).statements[0];
21
+ const fn = declaration && ts.isVariableStatement(declaration) ? declaration.declarationList.declarations[0]?.initializer : void 0;
22
+ if (!fn || !ts.isArrowFunction(fn) && !ts.isFunctionExpression(fn)) return { unchecked: "handler" };
23
+ const parameter = fn.parameters[0]?.name;
24
+ if (!parameter || !ts.isIdentifier(parameter)) return [];
25
+ const context = parameter.text;
26
+ function literalString(node) {
27
+ return node && (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : void 0;
28
+ }
29
+ function property(options, name) {
30
+ if (!options || !ts.isObjectLiteralExpression(options)) return void 0;
31
+ for (const entry of options.properties) {
32
+ if (!ts.isPropertyAssignment(entry)) continue;
33
+ if ((ts.isIdentifier(entry.name) || ts.isStringLiteral(entry.name) ? entry.name.text : void 0) === name) return entry.initializer;
34
+ }
35
+ }
36
+ /** `undefined` when the options bag is unreadable, so the call is skipped. */
37
+ function explicitId(options) {
38
+ if (options === void 0) return false;
39
+ if (!ts.isObjectLiteralExpression(options)) return void 0;
40
+ if (options.properties.some((entry) => ts.isSpreadAssignment(entry))) return void 0;
41
+ const given = property(options, "id");
42
+ if (given === void 0) return false;
43
+ return literalString(given);
44
+ }
45
+ function repeatedLoopRegion(parent, child) {
46
+ if (ts.isForOfStatement(parent) || ts.isForInStatement(parent)) return parent.statement === child;
47
+ if (ts.isForStatement(parent)) return parent.statement === child || parent.condition === child || parent.incrementor === child;
48
+ return ts.isWhileStatement(parent) || ts.isDoStatement(parent);
49
+ }
50
+ /** Whether anything between the call and the handler can run it more than once. */
51
+ function repeatable(call) {
52
+ let child = call;
53
+ let parent = call.parent;
54
+ while (parent && child !== fn) {
55
+ if (parent !== fn && (repeatedLoopRegion(parent, child) || ts.isFunctionLike(parent))) return true;
56
+ child = parent;
57
+ parent = parent.parent;
58
+ }
59
+ return false;
60
+ }
61
+ const calls = [];
62
+ const visit = (node) => {
63
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression) && node.expression.expression.text === context && node.expression.name.text in optionsArgument) {
64
+ const method = node.expression.name.text;
65
+ const index = optionsArgument[method];
66
+ const given = method === "step" ? literalString(node.arguments[0]) : explicitId(node.arguments[index]);
67
+ if (given !== void 0) calls.push({
68
+ id: given === false ? "" : given,
69
+ method,
70
+ repeatable: repeatable(node)
71
+ });
72
+ }
73
+ ts.forEachChild(node, visit);
74
+ };
75
+ visit(fn);
76
+ const found = /* @__PURE__ */ new Map();
77
+ for (const call of calls) {
78
+ if (call.id === "") {
79
+ found.set(`${call.method}:missing:${found.size}`, {
80
+ id: "",
81
+ method: call.method,
82
+ reason: "missing"
83
+ });
84
+ continue;
85
+ }
86
+ if (call.repeatable) {
87
+ found.set(call.id, {
88
+ id: call.id,
89
+ method: call.method,
90
+ reason: "loop"
91
+ });
92
+ continue;
93
+ }
94
+ if (calls.some((other) => other !== call && other.id === call.id)) found.set(call.id, {
95
+ id: call.id,
96
+ method: call.method,
97
+ reason: "repeated"
98
+ });
99
+ }
100
+ return [...found.values()];
101
+ }
102
+ //#endregion
103
+ export { findDuplicateOperationIds };
@@ -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 };