@lovable.dev/workflows-sdk 0.0.0-dev.20 → 0.0.0-dev.22
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 +3 -1
- package/dist/{branch-metadata-CZOTNcFb.js → branch-metadata-BBVwmGtr.js} +1 -1
- package/dist/{context-escapes-B25pWh07.js → context-escapes-hJTV5O7I.js} +1 -1
- package/dist/{duplicate-ids-DElsXi_P.js → duplicate-ids-CBASgH8g.js} +1 -1
- package/dist/{generate-BXCYaFf_.js → generate-DJ7bQOT7.js} +7 -7
- package/dist/{graph-CHhlUDD3.js → graph-DKuhUjgo.js} +136 -61
- package/dist/index.js +1 -1
- package/dist/{nested-operations-A16hbdxU.js → nested-operations-CspliO3h.js} +1 -1
- package/dist/{operation-descriptions-BgyQzZ2-.js → operation-descriptions-ugamonwF.js} +1 -1
- package/dist/{step-metadata-DJ1CNwqI.js → step-metadata-DJRmHyNE.js} +1 -1
- package/dist/vite.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -315,7 +315,9 @@ Sequential awaited `ctx.step("name", callback, options)` calls produce order edg
|
|
|
315
315
|
that join at the next step. A `Promise.all()` mapped over a collection with the
|
|
316
316
|
step ID template `step-${item.id}` produces one dynamic parallel node labeled
|
|
317
317
|
from `meta.group.label`. Returned step promises work too. Keep step IDs literal
|
|
318
|
-
outside this mapped form.
|
|
318
|
+
outside this mapped form. A `try` block retains its durable operations when the
|
|
319
|
+
`catch` only handles the error in ordinary code. Durable operations in a `catch`
|
|
320
|
+
remain visible in a partial graph because edges do not encode error outcomes.
|
|
319
321
|
|
|
320
322
|
An `if` whose body contains durable operations produces a `branch` node. Every
|
|
321
323
|
durable operation inside it includes an outer-to-inner `meta.branches` path;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
|
|
2
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
2
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-DKuhUjgo.js";
|
|
3
3
|
//#region src/manifests/duplicate-ids.ts
|
|
4
4
|
/** Where an explicit `{ id }` would sit for each operation. */
|
|
5
5
|
const optionsArgument = {
|
|
@@ -183,13 +183,13 @@ function serializeSchema(schema, direction, label) {
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
async function generateManifests(definition) {
|
|
186
|
-
const { extractWorkflowGraph } = await import("./graph-
|
|
187
|
-
const { findBranchMetadataIssues } = await import("./branch-metadata-
|
|
188
|
-
const { findWorkflowContextEscapes } = await import("./context-escapes-
|
|
189
|
-
const { findDuplicateOperationIds } = await import("./duplicate-ids-
|
|
190
|
-
const { findNestedDurableOperations } = await import("./nested-operations-
|
|
191
|
-
const { findOperationDescriptionIssues } = await import("./operation-descriptions-
|
|
192
|
-
const { findStepMetadataIssues } = await import("./step-metadata-
|
|
186
|
+
const { extractWorkflowGraph } = await import("./graph-DKuhUjgo.js");
|
|
187
|
+
const { findBranchMetadataIssues } = await import("./branch-metadata-BBVwmGtr.js");
|
|
188
|
+
const { findWorkflowContextEscapes } = await import("./context-escapes-hJTV5O7I.js");
|
|
189
|
+
const { findDuplicateOperationIds } = await import("./duplicate-ids-CBASgH8g.js");
|
|
190
|
+
const { findNestedDurableOperations } = await import("./nested-operations-CspliO3h.js");
|
|
191
|
+
const { findOperationDescriptionIssues } = await import("./operation-descriptions-ugamonwF.js");
|
|
192
|
+
const { findStepMetadataIssues } = await import("./step-metadata-DJRmHyNE.js");
|
|
193
193
|
const collection = registerWorkflows(definition);
|
|
194
194
|
const manifests = [];
|
|
195
195
|
for (const workflow of collection.workflows) {
|
|
@@ -320,30 +320,67 @@ async function extractWorkflowGraph(handler) {
|
|
|
320
320
|
label: stepId
|
|
321
321
|
}, parents);
|
|
322
322
|
}
|
|
323
|
+
function path(tails, reachable = true) {
|
|
324
|
+
return {
|
|
325
|
+
tails: reachable ? tails : [],
|
|
326
|
+
reachable
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function mergePaths(...items) {
|
|
330
|
+
const tails = [];
|
|
331
|
+
const seen = /* @__PURE__ */ new Set();
|
|
332
|
+
for (const item of items) for (const tail of item.tails) {
|
|
333
|
+
const key = JSON.stringify(tail);
|
|
334
|
+
if (seen.has(key)) continue;
|
|
335
|
+
seen.add(key);
|
|
336
|
+
tails.push(tail);
|
|
337
|
+
}
|
|
338
|
+
return path(tails, items.some((item) => item.reachable));
|
|
339
|
+
}
|
|
323
340
|
function expression(node, parents, awaited = false) {
|
|
324
341
|
if (ts.isParenthesizedExpression(node)) return expression(node.expression, parents, awaited);
|
|
325
342
|
if (ts.isAwaitExpression(node)) return expression(node.expression, parents, true);
|
|
326
343
|
if (durableCall(node)) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
344
|
+
let tails = awaited ? durableNode(node, parents) : unknown("Unawaited durable calls are not supported yet", parents);
|
|
345
|
+
if (node.arguments.some((argument) => contains(argument, durableCall))) tails = unknown("Nested durable calls are not supported yet", tails);
|
|
346
|
+
return {
|
|
347
|
+
tails,
|
|
348
|
+
thrown: path(tails)
|
|
349
|
+
};
|
|
331
350
|
}
|
|
332
351
|
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) {
|
|
333
352
|
const argument = node.arguments[0];
|
|
334
353
|
if (ts.isArrayLiteralExpression(argument)) {
|
|
335
354
|
const elements = argument.elements;
|
|
336
|
-
if (elements.some((element) => contains(element, ts.isAwaitExpression, true)))
|
|
337
|
-
|
|
355
|
+
if (elements.some((element) => contains(element, ts.isAwaitExpression, true))) {
|
|
356
|
+
const tails = unknown("Await expressions inside Promise.all are not supported yet", parents);
|
|
357
|
+
return {
|
|
358
|
+
tails,
|
|
359
|
+
thrown: path(tails)
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
if (elements.length === 0) return {
|
|
363
|
+
tails: parents,
|
|
364
|
+
thrown: path([], false)
|
|
365
|
+
};
|
|
366
|
+
const flows = elements.map((element) => {
|
|
338
367
|
while (ts.isParenthesizedExpression(element)) element = element.expression;
|
|
339
|
-
|
|
340
|
-
|
|
368
|
+
if (ts.isCallExpression(element)) return expression(element, parents, true);
|
|
369
|
+
const tails = unknown("Dynamic Promise.all entries are not followed", parents);
|
|
370
|
+
return {
|
|
371
|
+
tails,
|
|
372
|
+
thrown: path(tails)
|
|
373
|
+
};
|
|
374
|
+
});
|
|
375
|
+
return {
|
|
376
|
+
tails: flows.flatMap((flow) => flow.tails),
|
|
377
|
+
thrown: mergePaths(...flows.map((flow) => flow.thrown))
|
|
378
|
+
};
|
|
341
379
|
}
|
|
342
380
|
const mapped = mappedStep(argument);
|
|
343
381
|
if (mapped !== void 0) {
|
|
344
382
|
const metadata = stepMetadata(mapped.call);
|
|
345
|
-
|
|
346
|
-
return addNode({
|
|
383
|
+
const tails = metadata?.group ? addNode({
|
|
347
384
|
kind: "parallel",
|
|
348
385
|
groupId: metadata.group.id,
|
|
349
386
|
cardinality: "dynamic",
|
|
@@ -353,12 +390,28 @@ async function extractWorkflowGraph(handler) {
|
|
|
353
390
|
description: metadata.description
|
|
354
391
|
},
|
|
355
392
|
label: metadata.group.label
|
|
356
|
-
}, parents);
|
|
393
|
+
}, parents) : unknown("Dynamic parallel steps need static group metadata", parents);
|
|
394
|
+
return {
|
|
395
|
+
tails,
|
|
396
|
+
thrown: path(tails)
|
|
397
|
+
};
|
|
357
398
|
}
|
|
358
399
|
}
|
|
359
|
-
if (contains(node, (child) => ts.isCallExpression(child) || ts.isAwaitExpression(child) || ts.isNewExpression(child)))
|
|
360
|
-
|
|
361
|
-
|
|
400
|
+
if (contains(node, (child) => ts.isCallExpression(child) || ts.isAwaitExpression(child) || ts.isNewExpression(child))) {
|
|
401
|
+
const tails = unknown("Helper calls and dynamic expressions are not followed", parents);
|
|
402
|
+
return {
|
|
403
|
+
tails,
|
|
404
|
+
thrown: path(tails)
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
if (ts.isIdentifier(node) && node.text === context) return {
|
|
408
|
+
tails: unknown("Workflow context aliases are not followed", parents),
|
|
409
|
+
thrown: path([], false)
|
|
410
|
+
};
|
|
411
|
+
return {
|
|
412
|
+
tails: parents,
|
|
413
|
+
thrown: path([], false)
|
|
414
|
+
};
|
|
362
415
|
}
|
|
363
416
|
function branchInfo(statement, depth) {
|
|
364
417
|
let result;
|
|
@@ -374,51 +427,63 @@ async function extractWorkflowGraph(handler) {
|
|
|
374
427
|
if (statement.elseStatement) visit(statement.elseStatement);
|
|
375
428
|
return result;
|
|
376
429
|
}
|
|
377
|
-
function
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
430
|
+
function statementFlow(normal, thrown = path([], false), returned = path([], false), stopped = path([], false)) {
|
|
431
|
+
return {
|
|
432
|
+
normal,
|
|
433
|
+
thrown,
|
|
434
|
+
returned,
|
|
435
|
+
stopped
|
|
381
436
|
};
|
|
437
|
+
}
|
|
438
|
+
function statements(items, parents, branchDepth) {
|
|
439
|
+
let normal = path(parents);
|
|
440
|
+
let thrown = path([], false);
|
|
441
|
+
let returned = path([], false);
|
|
442
|
+
let stopped = path([], false);
|
|
382
443
|
for (const statement of items) {
|
|
383
|
-
if (!
|
|
384
|
-
flow = walkStatement(statement,
|
|
444
|
+
if (!normal.reachable) break;
|
|
445
|
+
const flow = walkStatement(statement, normal.tails, branchDepth);
|
|
446
|
+
normal = flow.normal;
|
|
447
|
+
thrown = mergePaths(thrown, flow.thrown);
|
|
448
|
+
returned = mergePaths(returned, flow.returned);
|
|
449
|
+
stopped = mergePaths(stopped, flow.stopped);
|
|
385
450
|
}
|
|
386
|
-
return
|
|
451
|
+
return statementFlow(normal, thrown, returned, stopped);
|
|
387
452
|
}
|
|
388
453
|
function walkStatement(statement, parents, branchDepth) {
|
|
389
454
|
if (ts.isBlock(statement)) return statements(statement.statements, parents, branchDepth);
|
|
390
455
|
if (ts.isReturnStatement(statement)) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
fallsThrough: false
|
|
456
|
+
const result = statement.expression ? expression(statement.expression, parents, true) : {
|
|
457
|
+
tails: parents,
|
|
458
|
+
thrown: path([], false)
|
|
395
459
|
};
|
|
460
|
+
return statementFlow(path([], false), result.thrown, path(result.tails));
|
|
396
461
|
}
|
|
397
462
|
if (ts.isThrowStatement(statement)) {
|
|
398
|
-
expression(statement.expression, parents);
|
|
399
|
-
return
|
|
400
|
-
tails: [],
|
|
401
|
-
fallsThrough: false
|
|
402
|
-
};
|
|
463
|
+
const result = expression(statement.expression, parents);
|
|
464
|
+
return statementFlow(path([], false), mergePaths(result.thrown, path(result.tails)));
|
|
403
465
|
}
|
|
404
466
|
if (ts.isVariableStatement(statement)) {
|
|
405
|
-
if (statement.declarationList.declarations.some((item) => contains(item.name, (child) => ts.isIdentifier(child) && (child.text === "Promise" || child.text === context))))
|
|
406
|
-
tails
|
|
407
|
-
|
|
408
|
-
}
|
|
467
|
+
if (statement.declarationList.declarations.some((item) => contains(item.name, (child) => ts.isIdentifier(child) && (child.text === "Promise" || child.text === context)))) {
|
|
468
|
+
const tails = unknown("Shadowed context or Promise bindings are not supported yet", parents);
|
|
469
|
+
return statementFlow(path([], false), path([], false), path([], false), path(tails));
|
|
470
|
+
}
|
|
409
471
|
let tails = parents;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
472
|
+
let thrown = path([], false);
|
|
473
|
+
for (const item of statement.declarationList.declarations) {
|
|
474
|
+
if (!item.initializer) continue;
|
|
475
|
+
const result = expression(item.initializer, tails);
|
|
476
|
+
tails = result.tails;
|
|
477
|
+
thrown = mergePaths(thrown, result.thrown);
|
|
478
|
+
}
|
|
479
|
+
return statementFlow(path(tails), thrown);
|
|
480
|
+
}
|
|
481
|
+
if (ts.isExpressionStatement(statement)) {
|
|
482
|
+
const result = expression(statement.expression, parents);
|
|
483
|
+
return statementFlow(path(result.tails), result.thrown);
|
|
415
484
|
}
|
|
416
|
-
if (ts.isExpressionStatement(statement)) return {
|
|
417
|
-
tails: expression(statement.expression, parents),
|
|
418
|
-
fallsThrough: true
|
|
419
|
-
};
|
|
420
485
|
if (ts.isIfStatement(statement)) {
|
|
421
|
-
const
|
|
486
|
+
const conditionFlow = expression(statement.expression, parents);
|
|
422
487
|
const metadata = branchInfo(statement, branchDepth);
|
|
423
488
|
const condition = statement.expression.getText(source);
|
|
424
489
|
const branchTails = metadata ? addNode({
|
|
@@ -427,7 +492,7 @@ async function extractWorkflowGraph(handler) {
|
|
|
427
492
|
condition,
|
|
428
493
|
description: metadata.description,
|
|
429
494
|
label: metadata.description
|
|
430
|
-
},
|
|
495
|
+
}, conditionFlow.tails) : conditionFlow.tails;
|
|
431
496
|
const sourceId = metadata ? branchTails[0]?.source : void 0;
|
|
432
497
|
const thenParents = sourceId ? [{
|
|
433
498
|
source: sourceId,
|
|
@@ -440,23 +505,33 @@ async function extractWorkflowGraph(handler) {
|
|
|
440
505
|
outcome: false
|
|
441
506
|
}] : branchTails;
|
|
442
507
|
const thenFlow = walkStatement(statement.thenStatement, thenParents, branchDepth + 1);
|
|
443
|
-
const elseFlow = statement.elseStatement ? walkStatement(statement.elseStatement, elseParents, branchDepth + 1) :
|
|
444
|
-
|
|
445
|
-
fallsThrough: true
|
|
446
|
-
};
|
|
447
|
-
return {
|
|
448
|
-
tails: [...thenFlow.fallsThrough ? thenFlow.tails : [], ...elseFlow.fallsThrough ? elseFlow.tails : []],
|
|
449
|
-
fallsThrough: thenFlow.fallsThrough || elseFlow.fallsThrough
|
|
450
|
-
};
|
|
508
|
+
const elseFlow = statement.elseStatement ? walkStatement(statement.elseStatement, elseParents, branchDepth + 1) : statementFlow(path(elseParents));
|
|
509
|
+
return statementFlow(mergePaths(thenFlow.normal, elseFlow.normal), mergePaths(conditionFlow.thrown, thenFlow.thrown, elseFlow.thrown), mergePaths(thenFlow.returned, elseFlow.returned), mergePaths(thenFlow.stopped, elseFlow.stopped));
|
|
451
510
|
}
|
|
452
|
-
if (ts.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
511
|
+
if (ts.isTryStatement(statement)) {
|
|
512
|
+
const tryFlow = walkStatement(statement.tryBlock, parents, branchDepth);
|
|
513
|
+
const catchBlock = statement.catchClause?.block;
|
|
514
|
+
const catchHasDurableOperations = catchBlock ? contains(catchBlock, durableCall) : false;
|
|
515
|
+
const catchHasAbruptCompletion = catchBlock ? contains(catchBlock, (node) => ts.isReturnStatement(node) || ts.isThrowStatement(node), true) : false;
|
|
516
|
+
let catchFlow = statementFlow(path([], false));
|
|
517
|
+
if (catchBlock && (tryFlow.thrown.reachable || catchHasDurableOperations || catchHasAbruptCompletion)) if (catchHasDurableOperations || catchHasAbruptCompletion) catchFlow = walkStatement(catchBlock, unknown(catchHasDurableOperations ? "Durable catch paths are conditional on errors" : "Catch completion paths are conditional on errors", tryFlow.thrown.reachable ? tryFlow.thrown.tails : parents), branchDepth);
|
|
518
|
+
else catchFlow = statementFlow(path(tryFlow.thrown.tails));
|
|
519
|
+
const normal = mergePaths(tryFlow.normal, catchFlow.normal);
|
|
520
|
+
const thrown = catchBlock ? catchFlow.thrown : tryFlow.thrown;
|
|
521
|
+
const returned = mergePaths(tryFlow.returned, catchFlow.returned);
|
|
522
|
+
const stopped = mergePaths(tryFlow.stopped, catchFlow.stopped);
|
|
523
|
+
const flow = statementFlow(normal, thrown, returned, stopped);
|
|
524
|
+
if (!statement.finallyBlock) return flow;
|
|
525
|
+
const finallyHasDurableOperations = contains(statement.finallyBlock, durableCall);
|
|
526
|
+
const finallyHasAbruptCompletion = contains(statement.finallyBlock, (node) => ts.isReturnStatement(node) || ts.isThrowStatement(node), true);
|
|
527
|
+
if (!finallyHasDurableOperations && !finallyHasAbruptCompletion) return flow;
|
|
528
|
+
const finallyParents = mergePaths(normal, thrown, returned, stopped);
|
|
529
|
+
const finallyFlow = walkStatement(statement.finallyBlock, finallyParents.tails, branchDepth);
|
|
530
|
+
const completedFinally = finallyFlow.normal.reachable;
|
|
531
|
+
return statementFlow(path(finallyFlow.normal.tails, normal.reachable && completedFinally), mergePaths(finallyFlow.thrown, path(finallyFlow.normal.tails, thrown.reachable && completedFinally)), mergePaths(finallyFlow.returned, path(finallyFlow.normal.tails, returned.reachable && completedFinally)), mergePaths(finallyFlow.stopped, path(finallyFlow.normal.tails, stopped.reachable && completedFinally)));
|
|
532
|
+
}
|
|
533
|
+
if (ts.isEmptyStatement(statement)) return statementFlow(path(parents));
|
|
534
|
+
return statementFlow(path(unknown("Loops and other control flow are not supported yet", parents)));
|
|
460
535
|
}
|
|
461
536
|
const tails = [];
|
|
462
537
|
if (!ts.isBlock(fn.body)) {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as defineSchedule, c as weekly, i as registerWorkflows, n as createMiddleware, o as daily, r as createWorkflow, s as hourly, t as generateManifests } from "./generate-
|
|
1
|
+
import { a as defineSchedule, c as weekly, i as registerWorkflows, n as createMiddleware, o as daily, r as createWorkflow, s as hourly, t as generateManifests } from "./generate-DJ7bQOT7.js";
|
|
2
2
|
import { t as defaultDurableId } from "./durable-ids-LsygHSZC.js";
|
|
3
3
|
import { WorkflowRequestParseError, inMemoryRunStore, parseWorkflowRequest, runWorkflow } from "@tanstack/workflow-core";
|
|
4
4
|
//#region src/stacks/tanstack/sse.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadTypeScript, t as workflowHandlerSource } from "./graph-
|
|
1
|
+
import { loadTypeScript, t as workflowHandlerSource } from "./graph-DKuhUjgo.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-DJ7bQOT7.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";
|