pg-workflows 0.5.0 → 0.6.0
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 +36 -0
- package/dist/index.cjs +95 -15
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +95 -15
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -441,6 +441,41 @@ await engine.resumeWorkflow({
|
|
|
441
441
|
});
|
|
442
442
|
```
|
|
443
443
|
|
|
444
|
+
### Fast-Forward
|
|
445
|
+
|
|
446
|
+
Skip the current waiting step and immediately resume execution. `fastForwardWorkflow` inspects the paused step and dispatches the right internal action — `triggerEvent` for `waitFor`, timeout triggers for `delay`/`waitUntil`, resume for `pause`, and direct output writes for `poll`. If the workflow is not paused, it's a no-op.
|
|
447
|
+
|
|
448
|
+
This is useful for testing, debugging, or manually advancing workflows past long waits.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
// Fast-forward a waitFor step, providing mock event data
|
|
452
|
+
await engine.fastForwardWorkflow({
|
|
453
|
+
runId: run.id,
|
|
454
|
+
resourceId: 'user-123',
|
|
455
|
+
data: { approved: true, reviewer: 'admin' },
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// Fast-forward a delay/waitUntil step (no data needed)
|
|
459
|
+
await engine.fastForwardWorkflow({
|
|
460
|
+
runId: run.id,
|
|
461
|
+
resourceId: 'user-123',
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// Fast-forward a poll step with mock result data
|
|
465
|
+
await engine.fastForwardWorkflow({
|
|
466
|
+
runId: run.id,
|
|
467
|
+
resourceId: 'user-123',
|
|
468
|
+
data: { paymentId: 'pay_123', status: 'completed' },
|
|
469
|
+
});
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
| Paused step type | Behavior |
|
|
473
|
+
|------------------|----------|
|
|
474
|
+
| `step.waitFor()` | Triggers the event with `data` (defaults to `{}`) |
|
|
475
|
+
| `step.delay()` / `step.waitUntil()` | Triggers the timeout event to skip the wait |
|
|
476
|
+
| `step.poll()` | Writes `data` as the poll result and triggers resolution |
|
|
477
|
+
| `step.pause()` | Delegates to `resumeWorkflow()` |
|
|
478
|
+
|
|
444
479
|
---
|
|
445
480
|
|
|
446
481
|
## Examples
|
|
@@ -588,6 +623,7 @@ When `boss` is omitted, pg-boss is created automatically with an isolated schema
|
|
|
588
623
|
| `resumeWorkflow({ runId, resourceId?, options? })` | Resume a paused workflow |
|
|
589
624
|
| `cancelWorkflow({ runId, resourceId? })` | Cancel a workflow |
|
|
590
625
|
| `triggerEvent({ runId, resourceId?, eventName, data?, options? })` | Send an event to a workflow |
|
|
626
|
+
| `fastForwardWorkflow({ runId, resourceId?, data? })` | Skip the current waiting step and resume execution |
|
|
591
627
|
| `getRun({ runId, resourceId? })` | Get workflow run details |
|
|
592
628
|
| `checkProgress({ runId, resourceId? })` | Get workflow progress |
|
|
593
629
|
| `getRuns(filters)` | List workflow runs with pagination |
|
package/dist/index.cjs
CHANGED
|
@@ -317,18 +317,19 @@ async function insertWorkflowRun({
|
|
|
317
317
|
status,
|
|
318
318
|
input,
|
|
319
319
|
maxRetries,
|
|
320
|
-
timeoutAt
|
|
320
|
+
timeoutAt,
|
|
321
|
+
timeline
|
|
321
322
|
}, db) {
|
|
322
323
|
const runId = generateKSUID("run");
|
|
323
324
|
const now = new Date;
|
|
324
325
|
const result = await db.executeSql(`INSERT INTO workflow_runs (
|
|
325
|
-
id,
|
|
326
|
-
resource_id,
|
|
327
|
-
workflow_id,
|
|
328
|
-
current_step_id,
|
|
329
|
-
status,
|
|
330
|
-
input,
|
|
331
|
-
max_retries,
|
|
326
|
+
id,
|
|
327
|
+
resource_id,
|
|
328
|
+
workflow_id,
|
|
329
|
+
current_step_id,
|
|
330
|
+
status,
|
|
331
|
+
input,
|
|
332
|
+
max_retries,
|
|
332
333
|
timeout_at,
|
|
333
334
|
created_at,
|
|
334
335
|
updated_at,
|
|
@@ -347,7 +348,7 @@ async function insertWorkflowRun({
|
|
|
347
348
|
timeoutAt,
|
|
348
349
|
now,
|
|
349
350
|
now,
|
|
350
|
-
|
|
351
|
+
JSON.stringify(timeline ?? {}),
|
|
351
352
|
0
|
|
352
353
|
]);
|
|
353
354
|
const insertedRun = result.rows[0];
|
|
@@ -493,19 +494,24 @@ async function getWorkflowRuns({
|
|
|
493
494
|
}
|
|
494
495
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
495
496
|
const actualLimit = Math.min(Math.max(limit, 1), 100) + 1;
|
|
497
|
+
const isBackward = !!endingBefore && !startingAfter;
|
|
496
498
|
const query = `
|
|
497
499
|
SELECT * FROM workflow_runs
|
|
498
500
|
${whereClause}
|
|
499
|
-
ORDER BY created_at DESC
|
|
501
|
+
ORDER BY created_at ${isBackward ? "ASC" : "DESC"}
|
|
500
502
|
LIMIT $${paramIndex}
|
|
501
503
|
`;
|
|
502
504
|
values.push(actualLimit);
|
|
503
505
|
const result = await db.executeSql(query, values);
|
|
504
506
|
const rows = result.rows;
|
|
505
|
-
const
|
|
506
|
-
const rawItems =
|
|
507
|
+
const hasExtraRow = rows.length > (limit ?? 20);
|
|
508
|
+
const rawItems = hasExtraRow ? rows.slice(0, limit) : rows;
|
|
509
|
+
if (isBackward) {
|
|
510
|
+
rawItems.reverse();
|
|
511
|
+
}
|
|
507
512
|
const items = rawItems.map((row) => mapRowToWorkflowRun(row));
|
|
508
|
-
const
|
|
513
|
+
const hasMore = isBackward ? items.length > 0 : hasExtraRow;
|
|
514
|
+
const hasPrev = isBackward ? hasExtraRow : !!startingAfter && items.length > 0;
|
|
509
515
|
const nextCursor = hasMore && items.length > 0 ? items[items.length - 1]?.id ?? null : null;
|
|
510
516
|
const prevCursor = hasPrev && items.length > 0 ? items[0]?.id ?? null : null;
|
|
511
517
|
return { items, nextCursor, prevCursor, hasMore, hasPrev };
|
|
@@ -680,7 +686,8 @@ class WorkflowEngine {
|
|
|
680
686
|
status: "running" /* RUNNING */,
|
|
681
687
|
input,
|
|
682
688
|
maxRetries: options?.retries ?? workflow2.retries ?? 0,
|
|
683
|
-
timeoutAt
|
|
689
|
+
timeoutAt,
|
|
690
|
+
timeline: undefined
|
|
684
691
|
}, _db);
|
|
685
692
|
const job = {
|
|
686
693
|
runId: insertedRun.id,
|
|
@@ -733,6 +740,49 @@ class WorkflowEngine {
|
|
|
733
740
|
options
|
|
734
741
|
});
|
|
735
742
|
}
|
|
743
|
+
async fastForwardWorkflow({
|
|
744
|
+
runId,
|
|
745
|
+
resourceId,
|
|
746
|
+
data
|
|
747
|
+
}) {
|
|
748
|
+
await this.checkIfHasStarted();
|
|
749
|
+
const run = await this.getRun({ runId, resourceId });
|
|
750
|
+
if (run.status !== "paused" /* PAUSED */) {
|
|
751
|
+
return run;
|
|
752
|
+
}
|
|
753
|
+
const stepId = run.currentStepId;
|
|
754
|
+
const waitForStepEntry = run.timeline[`${stepId}-wait-for`];
|
|
755
|
+
const waitForStep = waitForStepEntry && typeof waitForStepEntry === "object" && "waitFor" in waitForStepEntry ? waitForStepEntry : null;
|
|
756
|
+
if (!waitForStep) {
|
|
757
|
+
return run;
|
|
758
|
+
}
|
|
759
|
+
const { eventName, timeoutEvent, skipOutput } = waitForStep.waitFor;
|
|
760
|
+
if (eventName === PAUSE_EVENT_NAME) {
|
|
761
|
+
return this.resumeWorkflow({ runId, resourceId });
|
|
762
|
+
}
|
|
763
|
+
if (skipOutput && timeoutEvent) {
|
|
764
|
+
await this.updateRun({
|
|
765
|
+
runId,
|
|
766
|
+
resourceId,
|
|
767
|
+
data: {
|
|
768
|
+
timeline: import_es_toolkit.merge(run.timeline, {
|
|
769
|
+
[stepId]: {
|
|
770
|
+
output: data ?? {},
|
|
771
|
+
timestamp: new Date
|
|
772
|
+
}
|
|
773
|
+
})
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });
|
|
777
|
+
}
|
|
778
|
+
if (eventName) {
|
|
779
|
+
return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });
|
|
780
|
+
}
|
|
781
|
+
if (timeoutEvent) {
|
|
782
|
+
return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });
|
|
783
|
+
}
|
|
784
|
+
return run;
|
|
785
|
+
}
|
|
736
786
|
async cancelWorkflow({
|
|
737
787
|
runId,
|
|
738
788
|
resourceId
|
|
@@ -1124,6 +1174,36 @@ ${error.stack}` : String(error)
|
|
|
1124
1174
|
if (cached?.output !== undefined) {
|
|
1125
1175
|
return cached.timedOut ? undefined : cached.output;
|
|
1126
1176
|
}
|
|
1177
|
+
const fastForwardConfig = persistedRun.timeline.__fastForward;
|
|
1178
|
+
if (fastForwardConfig && eventName !== PAUSE_EVENT_NAME) {
|
|
1179
|
+
let output = {};
|
|
1180
|
+
if (eventName) {
|
|
1181
|
+
if (typeof fastForwardConfig === "object" && fastForwardConfig !== null && !Array.isArray(fastForwardConfig)) {
|
|
1182
|
+
const mockData = fastForwardConfig[stepId];
|
|
1183
|
+
if (mockData !== undefined) {
|
|
1184
|
+
output = mockData;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
run = await this.updateRun({
|
|
1189
|
+
runId: run.id,
|
|
1190
|
+
resourceId: run.resourceId ?? undefined,
|
|
1191
|
+
data: {
|
|
1192
|
+
currentStepId: stepId,
|
|
1193
|
+
timeline: import_es_toolkit.merge(run.timeline, {
|
|
1194
|
+
[stepId]: {
|
|
1195
|
+
output,
|
|
1196
|
+
timestamp: new Date
|
|
1197
|
+
}
|
|
1198
|
+
})
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
this.logger.log(`Step ${stepId} fast-forwarded`, {
|
|
1202
|
+
runId: run.id,
|
|
1203
|
+
workflowId: run.workflowId
|
|
1204
|
+
});
|
|
1205
|
+
return output;
|
|
1206
|
+
}
|
|
1127
1207
|
const timeoutEvent = timeoutDate ? `__timeout_${stepId}` : undefined;
|
|
1128
1208
|
await this.updateRun({
|
|
1129
1209
|
runId: run.id,
|
|
@@ -1273,5 +1353,5 @@ ${error.stack}` : String(error)
|
|
|
1273
1353
|
}
|
|
1274
1354
|
}
|
|
1275
1355
|
|
|
1276
|
-
//# debugId=
|
|
1356
|
+
//# debugId=68C46DF96F96057E64756E2164756E21
|
|
1277
1357
|
//# sourceMappingURL=index.js.map
|
package/dist/index.d.cts
CHANGED
|
@@ -211,6 +211,11 @@ declare class WorkflowEngine {
|
|
|
211
211
|
expireInSeconds?: number;
|
|
212
212
|
};
|
|
213
213
|
}): Promise<WorkflowRun>;
|
|
214
|
+
fastForwardWorkflow({ runId, resourceId, data }: {
|
|
215
|
+
runId: string;
|
|
216
|
+
resourceId?: string;
|
|
217
|
+
data?: Record<string, unknown>;
|
|
218
|
+
}): Promise<WorkflowRun>;
|
|
214
219
|
cancelWorkflow({ runId, resourceId }: {
|
|
215
220
|
runId: string;
|
|
216
221
|
resourceId?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -211,6 +211,11 @@ declare class WorkflowEngine {
|
|
|
211
211
|
expireInSeconds?: number;
|
|
212
212
|
};
|
|
213
213
|
}): Promise<WorkflowRun>;
|
|
214
|
+
fastForwardWorkflow({ runId, resourceId, data }: {
|
|
215
|
+
runId: string;
|
|
216
|
+
resourceId?: string;
|
|
217
|
+
data?: Record<string, unknown>;
|
|
218
|
+
}): Promise<WorkflowRun>;
|
|
214
219
|
cancelWorkflow({ runId, resourceId }: {
|
|
215
220
|
runId: string;
|
|
216
221
|
resourceId?: string;
|
package/dist/index.js
CHANGED
|
@@ -241,18 +241,19 @@ async function insertWorkflowRun({
|
|
|
241
241
|
status,
|
|
242
242
|
input,
|
|
243
243
|
maxRetries,
|
|
244
|
-
timeoutAt
|
|
244
|
+
timeoutAt,
|
|
245
|
+
timeline
|
|
245
246
|
}, db) {
|
|
246
247
|
const runId = generateKSUID("run");
|
|
247
248
|
const now = new Date;
|
|
248
249
|
const result = await db.executeSql(`INSERT INTO workflow_runs (
|
|
249
|
-
id,
|
|
250
|
-
resource_id,
|
|
251
|
-
workflow_id,
|
|
252
|
-
current_step_id,
|
|
253
|
-
status,
|
|
254
|
-
input,
|
|
255
|
-
max_retries,
|
|
250
|
+
id,
|
|
251
|
+
resource_id,
|
|
252
|
+
workflow_id,
|
|
253
|
+
current_step_id,
|
|
254
|
+
status,
|
|
255
|
+
input,
|
|
256
|
+
max_retries,
|
|
256
257
|
timeout_at,
|
|
257
258
|
created_at,
|
|
258
259
|
updated_at,
|
|
@@ -271,7 +272,7 @@ async function insertWorkflowRun({
|
|
|
271
272
|
timeoutAt,
|
|
272
273
|
now,
|
|
273
274
|
now,
|
|
274
|
-
|
|
275
|
+
JSON.stringify(timeline ?? {}),
|
|
275
276
|
0
|
|
276
277
|
]);
|
|
277
278
|
const insertedRun = result.rows[0];
|
|
@@ -417,19 +418,24 @@ async function getWorkflowRuns({
|
|
|
417
418
|
}
|
|
418
419
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
419
420
|
const actualLimit = Math.min(Math.max(limit, 1), 100) + 1;
|
|
421
|
+
const isBackward = !!endingBefore && !startingAfter;
|
|
420
422
|
const query = `
|
|
421
423
|
SELECT * FROM workflow_runs
|
|
422
424
|
${whereClause}
|
|
423
|
-
ORDER BY created_at DESC
|
|
425
|
+
ORDER BY created_at ${isBackward ? "ASC" : "DESC"}
|
|
424
426
|
LIMIT $${paramIndex}
|
|
425
427
|
`;
|
|
426
428
|
values.push(actualLimit);
|
|
427
429
|
const result = await db.executeSql(query, values);
|
|
428
430
|
const rows = result.rows;
|
|
429
|
-
const
|
|
430
|
-
const rawItems =
|
|
431
|
+
const hasExtraRow = rows.length > (limit ?? 20);
|
|
432
|
+
const rawItems = hasExtraRow ? rows.slice(0, limit) : rows;
|
|
433
|
+
if (isBackward) {
|
|
434
|
+
rawItems.reverse();
|
|
435
|
+
}
|
|
431
436
|
const items = rawItems.map((row) => mapRowToWorkflowRun(row));
|
|
432
|
-
const
|
|
437
|
+
const hasMore = isBackward ? items.length > 0 : hasExtraRow;
|
|
438
|
+
const hasPrev = isBackward ? hasExtraRow : !!startingAfter && items.length > 0;
|
|
433
439
|
const nextCursor = hasMore && items.length > 0 ? items[items.length - 1]?.id ?? null : null;
|
|
434
440
|
const prevCursor = hasPrev && items.length > 0 ? items[0]?.id ?? null : null;
|
|
435
441
|
return { items, nextCursor, prevCursor, hasMore, hasPrev };
|
|
@@ -604,7 +610,8 @@ class WorkflowEngine {
|
|
|
604
610
|
status: "running" /* RUNNING */,
|
|
605
611
|
input,
|
|
606
612
|
maxRetries: options?.retries ?? workflow2.retries ?? 0,
|
|
607
|
-
timeoutAt
|
|
613
|
+
timeoutAt,
|
|
614
|
+
timeline: undefined
|
|
608
615
|
}, _db);
|
|
609
616
|
const job = {
|
|
610
617
|
runId: insertedRun.id,
|
|
@@ -657,6 +664,49 @@ class WorkflowEngine {
|
|
|
657
664
|
options
|
|
658
665
|
});
|
|
659
666
|
}
|
|
667
|
+
async fastForwardWorkflow({
|
|
668
|
+
runId,
|
|
669
|
+
resourceId,
|
|
670
|
+
data
|
|
671
|
+
}) {
|
|
672
|
+
await this.checkIfHasStarted();
|
|
673
|
+
const run = await this.getRun({ runId, resourceId });
|
|
674
|
+
if (run.status !== "paused" /* PAUSED */) {
|
|
675
|
+
return run;
|
|
676
|
+
}
|
|
677
|
+
const stepId = run.currentStepId;
|
|
678
|
+
const waitForStepEntry = run.timeline[`${stepId}-wait-for`];
|
|
679
|
+
const waitForStep = waitForStepEntry && typeof waitForStepEntry === "object" && "waitFor" in waitForStepEntry ? waitForStepEntry : null;
|
|
680
|
+
if (!waitForStep) {
|
|
681
|
+
return run;
|
|
682
|
+
}
|
|
683
|
+
const { eventName, timeoutEvent, skipOutput } = waitForStep.waitFor;
|
|
684
|
+
if (eventName === PAUSE_EVENT_NAME) {
|
|
685
|
+
return this.resumeWorkflow({ runId, resourceId });
|
|
686
|
+
}
|
|
687
|
+
if (skipOutput && timeoutEvent) {
|
|
688
|
+
await this.updateRun({
|
|
689
|
+
runId,
|
|
690
|
+
resourceId,
|
|
691
|
+
data: {
|
|
692
|
+
timeline: merge(run.timeline, {
|
|
693
|
+
[stepId]: {
|
|
694
|
+
output: data ?? {},
|
|
695
|
+
timestamp: new Date
|
|
696
|
+
}
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });
|
|
701
|
+
}
|
|
702
|
+
if (eventName) {
|
|
703
|
+
return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });
|
|
704
|
+
}
|
|
705
|
+
if (timeoutEvent) {
|
|
706
|
+
return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });
|
|
707
|
+
}
|
|
708
|
+
return run;
|
|
709
|
+
}
|
|
660
710
|
async cancelWorkflow({
|
|
661
711
|
runId,
|
|
662
712
|
resourceId
|
|
@@ -1048,6 +1098,36 @@ ${error.stack}` : String(error)
|
|
|
1048
1098
|
if (cached?.output !== undefined) {
|
|
1049
1099
|
return cached.timedOut ? undefined : cached.output;
|
|
1050
1100
|
}
|
|
1101
|
+
const fastForwardConfig = persistedRun.timeline.__fastForward;
|
|
1102
|
+
if (fastForwardConfig && eventName !== PAUSE_EVENT_NAME) {
|
|
1103
|
+
let output = {};
|
|
1104
|
+
if (eventName) {
|
|
1105
|
+
if (typeof fastForwardConfig === "object" && fastForwardConfig !== null && !Array.isArray(fastForwardConfig)) {
|
|
1106
|
+
const mockData = fastForwardConfig[stepId];
|
|
1107
|
+
if (mockData !== undefined) {
|
|
1108
|
+
output = mockData;
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
run = await this.updateRun({
|
|
1113
|
+
runId: run.id,
|
|
1114
|
+
resourceId: run.resourceId ?? undefined,
|
|
1115
|
+
data: {
|
|
1116
|
+
currentStepId: stepId,
|
|
1117
|
+
timeline: merge(run.timeline, {
|
|
1118
|
+
[stepId]: {
|
|
1119
|
+
output,
|
|
1120
|
+
timestamp: new Date
|
|
1121
|
+
}
|
|
1122
|
+
})
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
this.logger.log(`Step ${stepId} fast-forwarded`, {
|
|
1126
|
+
runId: run.id,
|
|
1127
|
+
workflowId: run.workflowId
|
|
1128
|
+
});
|
|
1129
|
+
return output;
|
|
1130
|
+
}
|
|
1051
1131
|
const timeoutEvent = timeoutDate ? `__timeout_${stepId}` : undefined;
|
|
1052
1132
|
await this.updateRun({
|
|
1053
1133
|
runId: run.id,
|
|
@@ -1206,5 +1286,5 @@ export {
|
|
|
1206
1286
|
StepType
|
|
1207
1287
|
};
|
|
1208
1288
|
|
|
1209
|
-
//# debugId=
|
|
1289
|
+
//# debugId=3C42BBABB5FBDC4364756E2164756E21
|
|
1210
1290
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
"import type {\n InputParameters,\n StepBaseContext,\n WorkflowContext,\n WorkflowDefinition,\n WorkflowFactory,\n WorkflowOptions,\n WorkflowPlugin,\n} from './types';\n\nfunction createWorkflowFactory<TStepExt extends object = object>(\n plugins: Array<WorkflowPlugin<unknown, object>> = [],\n): WorkflowFactory<TStepExt> {\n const factory = (<I extends InputParameters>(\n id: string,\n handler: (context: WorkflowContext<I, StepBaseContext & TStepExt>) => Promise<unknown>,\n { inputSchema, timeout, retries }: WorkflowOptions<I> = {},\n ): WorkflowDefinition<I, StepBaseContext & TStepExt> => ({\n id,\n handler,\n inputSchema,\n timeout,\n retries,\n plugins: plugins.length > 0 ? (plugins as WorkflowPlugin[]) : undefined,\n })) as WorkflowFactory<TStepExt>;\n\n factory.use = <TNewExt>(\n plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>,\n ): WorkflowFactory<TStepExt & TNewExt> =>\n createWorkflowFactory<TStepExt & TNewExt>([\n ...plugins,\n plugin as WorkflowPlugin<unknown, object>,\n ]);\n\n return factory;\n}\n\nexport const workflow: WorkflowFactory = createWorkflowFactory();\n",
|
|
6
6
|
"import parse from 'parse-duration';\nimport { WorkflowEngineError } from './error';\n\nexport type DurationObject = {\n weeks?: number;\n days?: number;\n hours?: number;\n minutes?: number;\n seconds?: number;\n};\n\nexport type Duration = string | DurationObject;\n\nconst MS_PER_SECOND = 1000;\nconst MS_PER_MINUTE = 60 * MS_PER_SECOND;\nconst MS_PER_HOUR = 60 * MS_PER_MINUTE;\nconst MS_PER_DAY = 24 * MS_PER_HOUR;\nconst MS_PER_WEEK = 7 * MS_PER_DAY;\n\nexport function parseDuration(duration: Duration): number {\n if (typeof duration === 'string') {\n if (duration.trim() === '') {\n throw new WorkflowEngineError('Invalid duration: empty string');\n }\n\n const ms = parse(duration);\n\n if (ms == null || ms <= 0) {\n throw new WorkflowEngineError(`Invalid duration: \"${duration}\"`);\n }\n\n return ms;\n }\n\n const { weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0 } = duration;\n\n const ms =\n weeks * MS_PER_WEEK +\n days * MS_PER_DAY +\n hours * MS_PER_HOUR +\n minutes * MS_PER_MINUTE +\n seconds * MS_PER_SECOND;\n\n if (ms <= 0) {\n throw new WorkflowEngineError('Invalid duration: must be a positive value');\n }\n\n return ms;\n}\n",
|
|
7
7
|
"export class WorkflowEngineError extends Error {\n constructor(\n message: string,\n public readonly workflowId?: string,\n public readonly runId?: string,\n public override readonly cause: Error | undefined = undefined,\n ) {\n super(message);\n this.name = 'WorkflowEngineError';\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, WorkflowEngineError);\n }\n }\n}\n\nexport class WorkflowRunNotFoundError extends WorkflowEngineError {\n constructor(runId?: string, workflowId?: string) {\n super('Workflow run not found', workflowId, runId);\n this.name = 'WorkflowRunNotFoundError';\n }\n}\n",
|
|
8
|
-
"import { merge } from 'es-toolkit';\nimport pg from 'pg';\nimport { type Db, type Job, PgBoss } from 'pg-boss';\nimport type { z } from 'zod';\nimport { parseWorkflowHandler } from './ast-parser';\nimport { runMigrations } from './db/migration';\nimport {\n getWorkflowRun,\n getWorkflowRuns,\n insertWorkflowRun,\n updateWorkflowRun,\n withPostgresTransaction,\n} from './db/queries';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\nimport { parseDuration } from './duration';\nimport { WorkflowEngineError, WorkflowRunNotFoundError } from './error';\nimport {\n type InferInputParameters,\n type InputParameters,\n type StepBaseContext,\n StepType,\n type WorkflowContext,\n type WorkflowDefinition,\n type WorkflowInternalDefinition,\n type WorkflowInternalLogger,\n type WorkflowInternalLoggerContext,\n type WorkflowLogger,\n type WorkflowRunProgress,\n WorkflowStatus,\n} from './types';\n\nconst PAUSE_EVENT_NAME = '__internal_pause';\nconst WORKFLOW_RUN_QUEUE_NAME = 'workflow-run';\nconst LOG_PREFIX = '[WorkflowEngine]';\nconst DEFAULT_PGBOSS_SCHEMA = 'pgboss_v12_pgworkflow';\n\nexport type WorkflowEngineOptions = {\n workflows?: WorkflowDefinition[];\n logger?: WorkflowLogger;\n boss?: PgBoss;\n} & ({ pool: pg.Pool; connectionString?: never } | { connectionString: string; pool?: never });\n\nconst StepTypeToIcon = {\n [StepType.RUN]: 'λ',\n [StepType.WAIT_FOR]: '○',\n [StepType.PAUSE]: '⏸',\n [StepType.WAIT_UNTIL]: '⏲',\n [StepType.DELAY]: '⏱',\n [StepType.POLL]: '↻',\n};\n\n// Timeline entry types\ntype TimelineStepEntry = {\n output?: unknown;\n timedOut?: true;\n timestamp: Date;\n};\n\ntype TimelineWaitForEntry = {\n waitFor: {\n eventName?: string;\n timeoutEvent?: string;\n skipOutput?: true;\n };\n timestamp: Date;\n};\n\ntype WorkflowRunJobParameters = {\n runId: string;\n resourceId?: string;\n workflowId: string;\n input: unknown;\n event?: {\n name: string;\n data?: Record<string, unknown>;\n };\n};\n\nconst defaultLogger: WorkflowLogger = {\n log: (_message: string) => console.warn(_message),\n error: (message: string, error: Error) => console.error(message, error),\n};\n\nconst defaultExpireInSeconds = process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS, 10)\n : 5 * 60; // 5 minutes\n\nexport class WorkflowEngine {\n private boss: PgBoss;\n private db: Db;\n private pool: pg.Pool;\n private _ownsPool = false;\n private unregisteredWorkflows = new Map<string, WorkflowDefinition>();\n private _started = false;\n\n public workflows: Map<string, WorkflowInternalDefinition> = new Map<\n string,\n WorkflowInternalDefinition\n >();\n private logger: WorkflowInternalLogger;\n\n constructor({ workflows, logger, boss, ...connectionOptions }: WorkflowEngineOptions) {\n this.logger = this.buildLogger(logger ?? defaultLogger);\n\n if ('pool' in connectionOptions && connectionOptions.pool) {\n this.pool = connectionOptions.pool;\n } else if ('connectionString' in connectionOptions && connectionOptions.connectionString) {\n this.pool = new pg.Pool({ connectionString: connectionOptions.connectionString });\n this._ownsPool = true;\n } else {\n throw new WorkflowEngineError('Either pool or connectionString must be provided');\n }\n\n if (workflows) {\n this.unregisteredWorkflows = new Map(workflows.map((workflow) => [workflow.id, workflow]));\n }\n\n const db: Db = {\n executeSql: (text: string, values?: unknown[]) =>\n this.pool.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n\n if (boss) {\n this.boss = boss;\n } else {\n this.boss = new PgBoss({ db, schema: DEFAULT_PGBOSS_SCHEMA });\n }\n this.db = this.boss.getDb();\n }\n\n async start(\n asEngine = true,\n { batchSize }: { batchSize?: number } = { batchSize: 1 },\n ): Promise<void> {\n if (this._started) {\n return;\n }\n\n // Start boss first to get the database connection\n await this.boss.start();\n\n await runMigrations(this.boss.getDb());\n\n if (this.unregisteredWorkflows.size > 0) {\n for (const workflow of this.unregisteredWorkflows.values()) {\n await this.registerWorkflow(workflow);\n }\n }\n\n await this.boss.createQueue(WORKFLOW_RUN_QUEUE_NAME);\n\n const numWorkers: number = +(process.env.WORKFLOW_RUN_WORKERS ?? 3);\n\n if (asEngine) {\n for (let i = 0; i < numWorkers; i++) {\n await this.boss.work<WorkflowRunJobParameters>(\n WORKFLOW_RUN_QUEUE_NAME,\n { pollingIntervalSeconds: 0.5, batchSize },\n (job) => this.handleWorkflowRun(job),\n );\n this.logger.log(\n `Worker ${i + 1}/${numWorkers} started for queue ${WORKFLOW_RUN_QUEUE_NAME}`,\n );\n }\n }\n\n this._started = true;\n\n this.logger.log('Workflow engine started!');\n }\n\n async stop(): Promise<void> {\n await this.boss.stop();\n\n if (this._ownsPool) {\n await this.pool.end();\n }\n\n this._started = false;\n\n this.logger.log('Workflow engine stopped');\n }\n\n async registerWorkflow<TStep extends StepBaseContext>(\n definition: WorkflowDefinition<InputParameters, TStep>,\n ): Promise<WorkflowEngine> {\n if (this.workflows.has(definition.id)) {\n throw new WorkflowEngineError(\n `Workflow ${definition.id} is already registered`,\n definition.id,\n );\n }\n\n const { steps } = parseWorkflowHandler(\n definition.handler as (context: WorkflowContext) => Promise<unknown>,\n );\n\n this.workflows.set(definition.id, {\n ...definition,\n steps,\n } as WorkflowInternalDefinition);\n\n this.logger.log(`Registered workflow \"${definition.id}\" with steps:`);\n for (const step of steps.values()) {\n const tags = [];\n if (step.conditional) tags.push('[conditional]');\n if (step.loop) tags.push('[loop]');\n if (step.isDynamic) tags.push('[dynamic]');\n this.logger.log(` └─ (${StepTypeToIcon[step.type]}) ${step.id} ${tags.join(' ')}`);\n }\n\n return this;\n }\n\n async unregisterWorkflow(workflowId: string): Promise<WorkflowEngine> {\n this.workflows.delete(workflowId);\n return this;\n }\n\n async unregisterAllWorkflows(): Promise<WorkflowEngine> {\n this.workflows.clear();\n return this;\n }\n\n async startWorkflow({\n resourceId,\n workflowId,\n input,\n options,\n }: {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n options?: {\n timeout?: number;\n retries?: number;\n expireInSeconds?: number;\n batchSize?: number;\n };\n }): Promise<WorkflowRun> {\n if (!this._started) {\n await this.start(false, { batchSize: options?.batchSize ?? 1 });\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Unknown workflow ${workflowId}`);\n }\n\n const hasSteps = workflow.steps.length > 0 && workflow.steps[0];\n const hasPlugins = (workflow.plugins?.length ?? 0) > 0;\n if (!hasSteps && !hasPlugins) {\n throw new WorkflowEngineError(`Workflow ${workflowId} has no steps`, workflowId);\n }\n if (workflow.inputSchema) {\n const result = workflow.inputSchema.safeParse(input);\n if (!result.success) {\n throw new WorkflowEngineError(result.error.message, workflowId);\n }\n }\n\n const initialStepId = workflow.steps[0]?.id ?? '__start__';\n\n const run = await withPostgresTransaction(\n this.boss.getDb(),\n async (_db) => {\n const timeoutAt = options?.timeout\n ? new Date(Date.now() + options.timeout)\n : workflow.timeout\n ? new Date(Date.now() + workflow.timeout)\n : null;\n\n const insertedRun = await insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId: initialStepId,\n status: WorkflowStatus.RUNNING,\n input,\n maxRetries: options?.retries ?? workflow.retries ?? 0,\n timeoutAt,\n },\n _db,\n );\n\n const job: WorkflowRunJobParameters = {\n runId: insertedRun.id,\n resourceId,\n workflowId,\n input,\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: new Date(),\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n\n return insertedRun;\n },\n this.pool,\n );\n\n this.logger.log('Started workflow run', {\n runId: run.id,\n workflowId,\n });\n\n return run;\n }\n\n async pauseWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n // TODO: Pause all running steps immediately\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.PAUSED,\n pausedAt: new Date(),\n },\n });\n\n this.logger.log('Paused workflow run', {\n runId,\n workflowId: run.workflowId,\n });\n\n return run;\n }\n\n async resumeWorkflow({\n runId,\n resourceId,\n options,\n }: {\n runId: string;\n resourceId?: string;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n return this.triggerEvent({\n runId,\n resourceId,\n eventName: PAUSE_EVENT_NAME,\n data: {},\n options,\n });\n }\n\n async cancelWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.CANCELLED,\n },\n });\n\n this.logger.log(`cancelled workflow run with id ${runId}`);\n\n return run;\n }\n\n async triggerEvent({\n runId,\n resourceId,\n eventName,\n data,\n options,\n }: {\n runId: string;\n resourceId?: string;\n eventName: string;\n data?: Record<string, unknown>;\n options?: {\n expireInSeconds?: number;\n };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n const jobResourceId = resourceId ?? run.resourceId ?? undefined;\n\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: jobResourceId,\n workflowId: run.workflowId,\n input: run.input,\n event: {\n name: eventName,\n data,\n },\n };\n\n this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n\n this.logger.log(`event ${eventName} sent for workflow run with id ${runId}`);\n return run;\n }\n\n async getRun(\n { runId, resourceId }: { runId: string; resourceId?: string },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await getWorkflowRun({ runId, resourceId }, { exclusiveLock, db: db ?? this.db });\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async updateRun(\n {\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n },\n { db }: { db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await updateWorkflowRun({ runId, resourceId, data }, db ?? this.db);\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async checkProgress({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRunProgress> {\n const run = await this.getRun({ runId, resourceId });\n const workflow = this.workflows.get(run.workflowId);\n\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${run.workflowId} not found`, run.workflowId, runId);\n }\n const steps = workflow?.steps ?? [];\n\n let completionPercentage = 0;\n let completedSteps = 0;\n\n if (steps.length > 0) {\n completedSteps = Object.values(run.timeline).filter(\n (step): step is TimelineStepEntry =>\n typeof step === 'object' &&\n step !== null &&\n 'output' in step &&\n step.output !== undefined,\n ).length;\n\n if (run.status === WorkflowStatus.COMPLETED) {\n completionPercentage = 100;\n } else if (run.status === WorkflowStatus.FAILED || run.status === WorkflowStatus.CANCELLED) {\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n } else {\n const currentStepIndex = steps.findIndex((step) => step.id === run.currentStepId);\n if (currentStepIndex >= 0) {\n completionPercentage = (currentStepIndex / steps.length) * 100;\n } else {\n const completedSteps = Object.keys(run.timeline).length;\n\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n }\n }\n }\n\n return {\n ...run,\n completedSteps,\n completionPercentage: Math.round(completionPercentage * 100) / 100, // Round to 2 decimal places\n totalSteps: steps.length,\n };\n }\n\n /**\n * Resolves the resource id used for scoped DB access (getRun/updateRun).\n * When the job omits resourceId, the run's stored resourceId is used.\n * When the job includes resourceId, it must match the run's resourceId if the run is scoped;\n * unscoped runs reject a job-supplied resourceId (authorization).\n */\n private resolveScopedResourceId(\n jobResourceId: string | undefined,\n run: WorkflowRun,\n ): string | undefined {\n const jobResourceProvided =\n jobResourceId !== undefined && jobResourceId !== null && jobResourceId !== '';\n\n if (jobResourceProvided) {\n if (run.resourceId === null) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n if (run.resourceId !== jobResourceId) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n return jobResourceId;\n }\n\n return run.resourceId ?? undefined;\n }\n\n private async handleWorkflowRun([job]: Job<WorkflowRunJobParameters>[]) {\n const { runId, resourceId, workflowId, input, event } = job?.data ?? {};\n\n if (!runId) {\n throw new WorkflowEngineError('Invalid workflow run job, missing runId', workflowId);\n }\n\n if (!workflowId) {\n throw new WorkflowEngineError(\n 'Invalid workflow run job, missing workflowId',\n undefined,\n runId,\n );\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${workflowId} not found`, workflowId, runId);\n }\n\n this.logger.log('Processing workflow run...', {\n runId,\n workflowId,\n });\n\n let run = await this.getRun({ runId });\n\n if (run.workflowId !== workflowId) {\n throw new WorkflowEngineError(\n `Workflow run ${runId} does not match job workflowId ${workflowId}`,\n workflowId,\n runId,\n );\n }\n\n const scopedResourceId = this.resolveScopedResourceId(resourceId, run);\n\n try {\n if (run.status === WorkflowStatus.CANCELLED) {\n this.logger.log(`Workflow run ${runId} is cancelled, skipping`);\n return;\n }\n\n if (!run.currentStepId) {\n throw new WorkflowEngineError('Missing current step id', workflowId, runId);\n }\n\n if (run.status === WorkflowStatus.PAUSED) {\n const waitForStepEntry = run.timeline[`${run.currentStepId}-wait-for`];\n const waitForStep =\n waitForStepEntry && typeof waitForStepEntry === 'object' && 'waitFor' in waitForStepEntry\n ? (waitForStepEntry as TimelineWaitForEntry)\n : null;\n const currentStep = this.getCachedStepEntry(run.timeline, run.currentStepId);\n const waitFor = waitForStep?.waitFor;\n const hasCurrentStepOutput = currentStep?.output !== undefined;\n\n const eventMatches =\n waitFor &&\n event?.name &&\n (event.name === waitFor.eventName || event.name === waitFor.timeoutEvent) &&\n !hasCurrentStepOutput;\n\n if (eventMatches) {\n const isTimeout = event?.name === waitFor?.timeoutEvent;\n const skipOutput = waitFor?.skipOutput;\n run = await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n ...(skipOutput\n ? {}\n : {\n timeline: merge(run.timeline, {\n [run.currentStepId]: {\n output: event?.data ?? {},\n ...(isTimeout ? { timedOut: true as const } : {}),\n timestamp: new Date(),\n },\n }),\n }),\n },\n });\n } else {\n run = await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n },\n });\n }\n }\n\n const baseStep = {\n run: async <T>(stepId: string, handler: () => Promise<T>) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n return this.runStep({ stepId, run, handler }) as Promise<T>;\n },\n waitFor: async <T extends InputParameters>(\n stepId: string,\n { eventName, timeout }: { eventName: string; timeout?: number; schema?: T },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const timeoutDate = timeout ? new Date(Date.now() + timeout) : undefined;\n return this.waitStep({ run, stepId, eventName, timeoutDate }) as Promise<\n InferInputParameters<T> | undefined\n >;\n },\n waitUntil: async (\n stepId: string,\n dateOrOptions: Date | string | { date: Date | string },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const date =\n dateOrOptions instanceof Date\n ? dateOrOptions\n : typeof dateOrOptions === 'string'\n ? new Date(dateOrOptions)\n : dateOrOptions.date instanceof Date\n ? dateOrOptions.date\n : new Date(dateOrOptions.date);\n await this.waitStep({ run, stepId, timeoutDate: date });\n },\n pause: async (stepId: string) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({ run, stepId, eventName: PAUSE_EVENT_NAME });\n },\n delay: async (stepId: string, duration: Duration) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({\n run,\n stepId,\n timeoutDate: new Date(Date.now() + parseDuration(duration)),\n });\n },\n get sleep() {\n return this.delay;\n },\n poll: async <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const intervalMs = parseDuration(options?.interval ?? '30s');\n if (intervalMs < 30_000) {\n throw new WorkflowEngineError(\n `step.poll interval must be at least 30s (got ${intervalMs}ms)`,\n workflowId,\n runId,\n );\n }\n const timeoutMs = options?.timeout ? parseDuration(options.timeout) : undefined;\n return this.pollStep({ run, stepId, conditionFn, intervalMs, timeoutMs }) as Promise<\n { timedOut: false; data: T } | { timedOut: true }\n >;\n },\n };\n\n let step = { ...baseStep };\n const plugins = workflow.plugins ?? [];\n for (const plugin of plugins) {\n const extra = plugin.methods(step);\n step = { ...step, ...extra };\n }\n\n const context: WorkflowContext = {\n input: run.input as z.ZodTypeAny,\n workflowId: run.workflowId,\n runId: run.id,\n timeline: run.timeline,\n logger: this.logger,\n step,\n };\n\n const result = await workflow.handler(context);\n\n run = await this.getRun({ runId, resourceId: scopedResourceId });\n\n const isLastParsedStep = run.currentStepId === workflow.steps[workflow.steps.length - 1]?.id;\n const hasPluginSteps = (workflow.plugins?.length ?? 0) > 0;\n const noParsedSteps = workflow.steps.length === 0;\n const shouldComplete =\n run.status === WorkflowStatus.RUNNING &&\n (noParsedSteps || isLastParsedStep || (hasPluginSteps && result !== undefined));\n if (shouldComplete) {\n const normalizedResult = result === undefined ? {} : result;\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.COMPLETED,\n output: normalizedResult,\n completedAt: new Date(),\n jobId: job?.id,\n },\n });\n\n this.logger.log('Workflow run completed.', {\n runId,\n workflowId,\n });\n }\n } catch (error) {\n if (run.retryCount < run.maxRetries) {\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n retryCount: run.retryCount + 1,\n jobId: job?.id,\n },\n });\n\n const retryDelay = 2 ** run.retryCount * 1000;\n\n // NOTE: Do not use pg-boss retryLimit and retryBackoff so that we can fully control the retry logic from the WorkflowEngine and not PGBoss.\n const pgBossJob: WorkflowRunJobParameters = {\n runId,\n resourceId: scopedResourceId,\n workflowId,\n input,\n };\n await this.boss?.send('workflow-run', pgBossJob, {\n startAfter: new Date(Date.now() + retryDelay),\n expireInSeconds: defaultExpireInSeconds,\n });\n\n return;\n }\n\n // TODO: Ensure that this code always runs, even if worker is stopped unexpectedly.\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.FAILED,\n error: error instanceof Error ? error.message : String(error),\n jobId: job?.id,\n },\n });\n\n throw error;\n }\n }\n\n private getCachedStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineStepEntry | null {\n const stepEntry = timeline[stepId];\n return stepEntry && typeof stepEntry === 'object' && 'output' in stepEntry\n ? (stepEntry as TimelineStepEntry)\n : null;\n }\n\n private async runStep({\n stepId,\n run,\n handler,\n }: {\n stepId: string;\n run: WorkflowRun;\n handler: () => Promise<unknown>;\n }) {\n return withPostgresTransaction(\n this.db,\n async (db) => {\n const persistedRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n {\n exclusiveLock: true,\n db,\n },\n );\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n this.logger.log(`Step ${stepId} skipped, workflow run is ${persistedRun.status}`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return;\n }\n\n try {\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.output;\n }\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n },\n },\n { db },\n );\n\n this.logger.log(`Running step ${stepId}...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n let output = await handler();\n\n if (output === undefined) {\n output = {};\n }\n\n run = await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n timeline: merge(run.timeline, {\n [stepId]: {\n output,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n\n return output;\n } catch (error) {\n this.logger.error(`Step ${stepId} failed:`, error as Error, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.FAILED,\n error: error instanceof Error ? `${error.message}\\n${error.stack}` : String(error),\n },\n },\n { db },\n );\n\n throw error;\n }\n },\n this.pool,\n );\n }\n\n private async waitStep({\n run,\n stepId,\n eventName,\n timeoutDate,\n }: {\n run: WorkflowRun;\n stepId: string;\n eventName?: string;\n timeoutDate?: Date;\n }): Promise<unknown> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return;\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? undefined : cached.output;\n }\n\n const timeoutEvent = timeoutDate ? `__timeout_${stepId}` : undefined;\n\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(run.timeline, {\n [`${stepId}-wait-for`]: {\n waitFor: { eventName, timeoutEvent },\n timestamp: new Date(),\n },\n }),\n },\n });\n\n if (timeoutDate && timeoutEvent) {\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: timeoutEvent, data: { date: timeoutDate.toISOString() } },\n };\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: timeoutDate.getTime() <= Date.now() ? new Date() : timeoutDate,\n expireInSeconds: defaultExpireInSeconds,\n });\n }\n\n this.logger.log(\n `Step ${stepId} waiting${eventName ? ` for event \"${eventName}\"` : ''}${timeoutDate ? ` until ${timeoutDate.toISOString()}` : ''}`,\n { runId: run.id, workflowId: run.workflowId },\n );\n }\n\n private async pollStep<T>({\n run,\n stepId,\n conditionFn,\n intervalMs,\n timeoutMs,\n }: {\n run: WorkflowRun;\n stepId: string;\n conditionFn: () => Promise<T | false>;\n intervalMs: number;\n timeoutMs?: number;\n }): Promise<{ timedOut: false; data: T } | { timedOut: true } | undefined> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return { timedOut: true };\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? { timedOut: true } : { timedOut: false, data: cached.output as T };\n }\n\n const pollStateEntry = persistedRun.timeline[`${stepId}-poll`];\n const startedAt =\n pollStateEntry && typeof pollStateEntry === 'object' && 'startedAt' in pollStateEntry\n ? new Date((pollStateEntry as { startedAt: string }).startedAt)\n : new Date();\n\n if (timeoutMs !== undefined && Date.now() >= startedAt.getTime() + timeoutMs) {\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(persistedRun.timeline, {\n [stepId]: { output: {}, timedOut: true as const, timestamp: new Date() },\n }),\n },\n });\n return { timedOut: true };\n }\n\n const result = await conditionFn();\n\n if (result !== false) {\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(persistedRun.timeline, {\n [stepId]: { output: result, timestamp: new Date() },\n }),\n },\n });\n return { timedOut: false, data: result };\n }\n\n const pollEvent = `__poll_${stepId}`;\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(persistedRun.timeline, {\n [`${stepId}-poll`]: { startedAt: startedAt.toISOString() },\n [`${stepId}-wait-for`]: {\n waitFor: { timeoutEvent: pollEvent, skipOutput: true },\n timestamp: new Date(),\n },\n }),\n },\n });\n\n await this.boss.send(\n WORKFLOW_RUN_QUEUE_NAME,\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: pollEvent, data: {} },\n },\n {\n startAfter: new Date(Date.now() + intervalMs),\n expireInSeconds: defaultExpireInSeconds,\n },\n );\n\n this.logger.log(`Step ${stepId} polling every ${intervalMs}ms...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return { timedOut: false, data: undefined as T };\n }\n\n private async checkIfHasStarted(): Promise<void> {\n if (!this._started) {\n throw new WorkflowEngineError('Workflow engine not started');\n }\n }\n\n private buildLogger(logger: WorkflowLogger): WorkflowInternalLogger {\n return {\n log: (message: string, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.log(`${parts}: ${message}`);\n },\n error: (message: string, error: Error, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.error(`${parts}: ${message}`, error);\n },\n };\n }\n\n async getRuns({\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: WorkflowStatus[];\n workflowId?: string;\n }): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n }> {\n return getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit,\n statuses,\n workflowId,\n },\n this.db,\n );\n }\n}\n",
|
|
8
|
+
"import { merge } from 'es-toolkit';\nimport pg from 'pg';\nimport { type Db, type Job, PgBoss } from 'pg-boss';\nimport type { z } from 'zod';\nimport { parseWorkflowHandler } from './ast-parser';\nimport { runMigrations } from './db/migration';\nimport {\n getWorkflowRun,\n getWorkflowRuns,\n insertWorkflowRun,\n updateWorkflowRun,\n withPostgresTransaction,\n} from './db/queries';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\nimport { parseDuration } from './duration';\nimport { WorkflowEngineError, WorkflowRunNotFoundError } from './error';\nimport {\n type InferInputParameters,\n type InputParameters,\n type StepBaseContext,\n StepType,\n type WorkflowContext,\n type WorkflowDefinition,\n type WorkflowInternalDefinition,\n type WorkflowInternalLogger,\n type WorkflowInternalLoggerContext,\n type WorkflowLogger,\n type WorkflowRunProgress,\n WorkflowStatus,\n} from './types';\n\nconst PAUSE_EVENT_NAME = '__internal_pause';\nconst WORKFLOW_RUN_QUEUE_NAME = 'workflow-run';\nconst LOG_PREFIX = '[WorkflowEngine]';\nconst DEFAULT_PGBOSS_SCHEMA = 'pgboss_v12_pgworkflow';\n\nexport type WorkflowEngineOptions = {\n workflows?: WorkflowDefinition[];\n logger?: WorkflowLogger;\n boss?: PgBoss;\n} & ({ pool: pg.Pool; connectionString?: never } | { connectionString: string; pool?: never });\n\nconst StepTypeToIcon = {\n [StepType.RUN]: 'λ',\n [StepType.WAIT_FOR]: '○',\n [StepType.PAUSE]: '⏸',\n [StepType.WAIT_UNTIL]: '⏲',\n [StepType.DELAY]: '⏱',\n [StepType.POLL]: '↻',\n};\n\n// Timeline entry types\ntype TimelineStepEntry = {\n output?: unknown;\n timedOut?: true;\n timestamp: Date;\n};\n\ntype TimelineWaitForEntry = {\n waitFor: {\n eventName?: string;\n timeoutEvent?: string;\n skipOutput?: true;\n };\n timestamp: Date;\n};\n\ntype WorkflowRunJobParameters = {\n runId: string;\n resourceId?: string;\n workflowId: string;\n input: unknown;\n event?: {\n name: string;\n data?: Record<string, unknown>;\n };\n};\n\nconst defaultLogger: WorkflowLogger = {\n log: (_message: string) => console.warn(_message),\n error: (message: string, error: Error) => console.error(message, error),\n};\n\nconst defaultExpireInSeconds = process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS\n ? Number.parseInt(process.env.WORKFLOW_RUN_EXPIRE_IN_SECONDS, 10)\n : 5 * 60; // 5 minutes\n\nexport class WorkflowEngine {\n private boss: PgBoss;\n private db: Db;\n private pool: pg.Pool;\n private _ownsPool = false;\n private unregisteredWorkflows = new Map<string, WorkflowDefinition>();\n private _started = false;\n\n public workflows: Map<string, WorkflowInternalDefinition> = new Map<\n string,\n WorkflowInternalDefinition\n >();\n private logger: WorkflowInternalLogger;\n\n constructor({ workflows, logger, boss, ...connectionOptions }: WorkflowEngineOptions) {\n this.logger = this.buildLogger(logger ?? defaultLogger);\n\n if ('pool' in connectionOptions && connectionOptions.pool) {\n this.pool = connectionOptions.pool;\n } else if ('connectionString' in connectionOptions && connectionOptions.connectionString) {\n this.pool = new pg.Pool({ connectionString: connectionOptions.connectionString });\n this._ownsPool = true;\n } else {\n throw new WorkflowEngineError('Either pool or connectionString must be provided');\n }\n\n if (workflows) {\n this.unregisteredWorkflows = new Map(workflows.map((workflow) => [workflow.id, workflow]));\n }\n\n const db: Db = {\n executeSql: (text: string, values?: unknown[]) =>\n this.pool.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n\n if (boss) {\n this.boss = boss;\n } else {\n this.boss = new PgBoss({ db, schema: DEFAULT_PGBOSS_SCHEMA });\n }\n this.db = this.boss.getDb();\n }\n\n async start(\n asEngine = true,\n { batchSize }: { batchSize?: number } = { batchSize: 1 },\n ): Promise<void> {\n if (this._started) {\n return;\n }\n\n // Start boss first to get the database connection\n await this.boss.start();\n\n await runMigrations(this.boss.getDb());\n\n if (this.unregisteredWorkflows.size > 0) {\n for (const workflow of this.unregisteredWorkflows.values()) {\n await this.registerWorkflow(workflow);\n }\n }\n\n await this.boss.createQueue(WORKFLOW_RUN_QUEUE_NAME);\n\n const numWorkers: number = +(process.env.WORKFLOW_RUN_WORKERS ?? 3);\n\n if (asEngine) {\n for (let i = 0; i < numWorkers; i++) {\n await this.boss.work<WorkflowRunJobParameters>(\n WORKFLOW_RUN_QUEUE_NAME,\n { pollingIntervalSeconds: 0.5, batchSize },\n (job) => this.handleWorkflowRun(job),\n );\n this.logger.log(\n `Worker ${i + 1}/${numWorkers} started for queue ${WORKFLOW_RUN_QUEUE_NAME}`,\n );\n }\n }\n\n this._started = true;\n\n this.logger.log('Workflow engine started!');\n }\n\n async stop(): Promise<void> {\n await this.boss.stop();\n\n if (this._ownsPool) {\n await this.pool.end();\n }\n\n this._started = false;\n\n this.logger.log('Workflow engine stopped');\n }\n\n async registerWorkflow<TStep extends StepBaseContext>(\n definition: WorkflowDefinition<InputParameters, TStep>,\n ): Promise<WorkflowEngine> {\n if (this.workflows.has(definition.id)) {\n throw new WorkflowEngineError(\n `Workflow ${definition.id} is already registered`,\n definition.id,\n );\n }\n\n const { steps } = parseWorkflowHandler(\n definition.handler as (context: WorkflowContext) => Promise<unknown>,\n );\n\n this.workflows.set(definition.id, {\n ...definition,\n steps,\n } as WorkflowInternalDefinition);\n\n this.logger.log(`Registered workflow \"${definition.id}\" with steps:`);\n for (const step of steps.values()) {\n const tags = [];\n if (step.conditional) tags.push('[conditional]');\n if (step.loop) tags.push('[loop]');\n if (step.isDynamic) tags.push('[dynamic]');\n this.logger.log(` └─ (${StepTypeToIcon[step.type]}) ${step.id} ${tags.join(' ')}`);\n }\n\n return this;\n }\n\n async unregisterWorkflow(workflowId: string): Promise<WorkflowEngine> {\n this.workflows.delete(workflowId);\n return this;\n }\n\n async unregisterAllWorkflows(): Promise<WorkflowEngine> {\n this.workflows.clear();\n return this;\n }\n\n async startWorkflow({\n resourceId,\n workflowId,\n input,\n options,\n }: {\n resourceId?: string;\n workflowId: string;\n input: unknown;\n options?: {\n timeout?: number;\n retries?: number;\n expireInSeconds?: number;\n batchSize?: number;\n };\n }): Promise<WorkflowRun> {\n if (!this._started) {\n await this.start(false, { batchSize: options?.batchSize ?? 1 });\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Unknown workflow ${workflowId}`);\n }\n\n const hasSteps = workflow.steps.length > 0 && workflow.steps[0];\n const hasPlugins = (workflow.plugins?.length ?? 0) > 0;\n if (!hasSteps && !hasPlugins) {\n throw new WorkflowEngineError(`Workflow ${workflowId} has no steps`, workflowId);\n }\n if (workflow.inputSchema) {\n const result = workflow.inputSchema.safeParse(input);\n if (!result.success) {\n throw new WorkflowEngineError(result.error.message, workflowId);\n }\n }\n\n const initialStepId = workflow.steps[0]?.id ?? '__start__';\n\n const run = await withPostgresTransaction(\n this.boss.getDb(),\n async (_db) => {\n const timeoutAt = options?.timeout\n ? new Date(Date.now() + options.timeout)\n : workflow.timeout\n ? new Date(Date.now() + workflow.timeout)\n : null;\n\n const insertedRun = await insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId: initialStepId,\n status: WorkflowStatus.RUNNING,\n input,\n maxRetries: options?.retries ?? workflow.retries ?? 0,\n timeoutAt,\n timeline: undefined,\n },\n _db,\n );\n\n const job: WorkflowRunJobParameters = {\n runId: insertedRun.id,\n resourceId,\n workflowId,\n input,\n };\n\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: new Date(),\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n\n return insertedRun;\n },\n this.pool,\n );\n\n this.logger.log('Started workflow run', {\n runId: run.id,\n workflowId,\n });\n\n return run;\n }\n\n async pauseWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n // TODO: Pause all running steps immediately\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.PAUSED,\n pausedAt: new Date(),\n },\n });\n\n this.logger.log('Paused workflow run', {\n runId,\n workflowId: run.workflowId,\n });\n\n return run;\n }\n\n async resumeWorkflow({\n runId,\n resourceId,\n options,\n }: {\n runId: string;\n resourceId?: string;\n options?: { expireInSeconds?: number };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n return this.triggerEvent({\n runId,\n resourceId,\n eventName: PAUSE_EVENT_NAME,\n data: {},\n options,\n });\n }\n\n async fastForwardWorkflow({\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data?: Record<string, unknown>;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n if (run.status !== WorkflowStatus.PAUSED) {\n return run;\n }\n\n const stepId = run.currentStepId;\n const waitForStepEntry = run.timeline[`${stepId}-wait-for`];\n const waitForStep =\n waitForStepEntry && typeof waitForStepEntry === 'object' && 'waitFor' in waitForStepEntry\n ? (waitForStepEntry as TimelineWaitForEntry)\n : null;\n\n if (!waitForStep) {\n return run;\n }\n\n const { eventName, timeoutEvent, skipOutput } = waitForStep.waitFor;\n\n // step.pause() — delegate to resumeWorkflow\n if (eventName === PAUSE_EVENT_NAME) {\n return this.resumeWorkflow({ runId, resourceId });\n }\n\n // step.poll() — write output to timeline first, then trigger resume\n if (skipOutput && timeoutEvent) {\n await this.updateRun({\n runId,\n resourceId,\n data: {\n timeline: merge(run.timeline, {\n [stepId]: {\n output: data ?? {},\n timestamp: new Date(),\n },\n }),\n },\n });\n\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent });\n }\n\n // waitFor steps — trigger the event with data\n if (eventName) {\n return this.triggerEvent({ runId, resourceId, eventName, data: data ?? {} });\n }\n\n // delay/waitUntil steps — trigger the timeout event\n if (timeoutEvent) {\n return this.triggerEvent({ runId, resourceId, eventName: timeoutEvent, data: data ?? {} });\n }\n\n return run;\n }\n\n async cancelWorkflow({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.updateRun({\n runId,\n resourceId,\n data: {\n status: WorkflowStatus.CANCELLED,\n },\n });\n\n this.logger.log(`cancelled workflow run with id ${runId}`);\n\n return run;\n }\n\n async triggerEvent({\n runId,\n resourceId,\n eventName,\n data,\n options,\n }: {\n runId: string;\n resourceId?: string;\n eventName: string;\n data?: Record<string, unknown>;\n options?: {\n expireInSeconds?: number;\n };\n }): Promise<WorkflowRun> {\n await this.checkIfHasStarted();\n\n const run = await this.getRun({ runId, resourceId });\n\n const jobResourceId = resourceId ?? run.resourceId ?? undefined;\n\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: jobResourceId,\n workflowId: run.workflowId,\n input: run.input,\n event: {\n name: eventName,\n data,\n },\n };\n\n this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n expireInSeconds: options?.expireInSeconds ?? defaultExpireInSeconds,\n });\n\n this.logger.log(`event ${eventName} sent for workflow run with id ${runId}`);\n return run;\n }\n\n async getRun(\n { runId, resourceId }: { runId: string; resourceId?: string },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await getWorkflowRun({ runId, resourceId }, { exclusiveLock, db: db ?? this.db });\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async updateRun(\n {\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n },\n { db }: { db?: Db } = {},\n ): Promise<WorkflowRun> {\n const run = await updateWorkflowRun({ runId, resourceId, data }, db ?? this.db);\n\n if (!run) {\n throw new WorkflowRunNotFoundError(runId);\n }\n\n return run;\n }\n\n async checkProgress({\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n }): Promise<WorkflowRunProgress> {\n const run = await this.getRun({ runId, resourceId });\n const workflow = this.workflows.get(run.workflowId);\n\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${run.workflowId} not found`, run.workflowId, runId);\n }\n const steps = workflow?.steps ?? [];\n\n let completionPercentage = 0;\n let completedSteps = 0;\n\n if (steps.length > 0) {\n completedSteps = Object.values(run.timeline).filter(\n (step): step is TimelineStepEntry =>\n typeof step === 'object' &&\n step !== null &&\n 'output' in step &&\n step.output !== undefined,\n ).length;\n\n if (run.status === WorkflowStatus.COMPLETED) {\n completionPercentage = 100;\n } else if (run.status === WorkflowStatus.FAILED || run.status === WorkflowStatus.CANCELLED) {\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n } else {\n const currentStepIndex = steps.findIndex((step) => step.id === run.currentStepId);\n if (currentStepIndex >= 0) {\n completionPercentage = (currentStepIndex / steps.length) * 100;\n } else {\n const completedSteps = Object.keys(run.timeline).length;\n\n completionPercentage = Math.min((completedSteps / steps.length) * 100, 100);\n }\n }\n }\n\n return {\n ...run,\n completedSteps,\n completionPercentage: Math.round(completionPercentage * 100) / 100, // Round to 2 decimal places\n totalSteps: steps.length,\n };\n }\n\n /**\n * Resolves the resource id used for scoped DB access (getRun/updateRun).\n * When the job omits resourceId, the run's stored resourceId is used.\n * When the job includes resourceId, it must match the run's resourceId if the run is scoped;\n * unscoped runs reject a job-supplied resourceId (authorization).\n */\n private resolveScopedResourceId(\n jobResourceId: string | undefined,\n run: WorkflowRun,\n ): string | undefined {\n const jobResourceProvided =\n jobResourceId !== undefined && jobResourceId !== null && jobResourceId !== '';\n\n if (jobResourceProvided) {\n if (run.resourceId === null) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n if (run.resourceId !== jobResourceId) {\n throw new WorkflowRunNotFoundError(run.id);\n }\n return jobResourceId;\n }\n\n return run.resourceId ?? undefined;\n }\n\n private async handleWorkflowRun([job]: Job<WorkflowRunJobParameters>[]) {\n const { runId, resourceId, workflowId, input, event } = job?.data ?? {};\n\n if (!runId) {\n throw new WorkflowEngineError('Invalid workflow run job, missing runId', workflowId);\n }\n\n if (!workflowId) {\n throw new WorkflowEngineError(\n 'Invalid workflow run job, missing workflowId',\n undefined,\n runId,\n );\n }\n\n const workflow = this.workflows.get(workflowId);\n if (!workflow) {\n throw new WorkflowEngineError(`Workflow ${workflowId} not found`, workflowId, runId);\n }\n\n this.logger.log('Processing workflow run...', {\n runId,\n workflowId,\n });\n\n let run = await this.getRun({ runId });\n\n if (run.workflowId !== workflowId) {\n throw new WorkflowEngineError(\n `Workflow run ${runId} does not match job workflowId ${workflowId}`,\n workflowId,\n runId,\n );\n }\n\n const scopedResourceId = this.resolveScopedResourceId(resourceId, run);\n\n try {\n if (run.status === WorkflowStatus.CANCELLED) {\n this.logger.log(`Workflow run ${runId} is cancelled, skipping`);\n return;\n }\n\n if (!run.currentStepId) {\n throw new WorkflowEngineError('Missing current step id', workflowId, runId);\n }\n\n if (run.status === WorkflowStatus.PAUSED) {\n const waitForStepEntry = run.timeline[`${run.currentStepId}-wait-for`];\n const waitForStep =\n waitForStepEntry && typeof waitForStepEntry === 'object' && 'waitFor' in waitForStepEntry\n ? (waitForStepEntry as TimelineWaitForEntry)\n : null;\n const currentStep = this.getCachedStepEntry(run.timeline, run.currentStepId);\n const waitFor = waitForStep?.waitFor;\n const hasCurrentStepOutput = currentStep?.output !== undefined;\n\n const eventMatches =\n waitFor &&\n event?.name &&\n (event.name === waitFor.eventName || event.name === waitFor.timeoutEvent) &&\n !hasCurrentStepOutput;\n\n if (eventMatches) {\n const isTimeout = event?.name === waitFor?.timeoutEvent;\n const skipOutput = waitFor?.skipOutput;\n run = await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n ...(skipOutput\n ? {}\n : {\n timeline: merge(run.timeline, {\n [run.currentStepId]: {\n output: event?.data ?? {},\n ...(isTimeout ? { timedOut: true as const } : {}),\n timestamp: new Date(),\n },\n }),\n }),\n },\n });\n } else {\n run = await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.RUNNING,\n pausedAt: null,\n resumedAt: new Date(),\n jobId: job?.id,\n },\n });\n }\n }\n\n const baseStep = {\n run: async <T>(stepId: string, handler: () => Promise<T>) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n return this.runStep({ stepId, run, handler }) as Promise<T>;\n },\n waitFor: async <T extends InputParameters>(\n stepId: string,\n { eventName, timeout }: { eventName: string; timeout?: number; schema?: T },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const timeoutDate = timeout ? new Date(Date.now() + timeout) : undefined;\n return this.waitStep({ run, stepId, eventName, timeoutDate }) as Promise<\n InferInputParameters<T> | undefined\n >;\n },\n waitUntil: async (\n stepId: string,\n dateOrOptions: Date | string | { date: Date | string },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const date =\n dateOrOptions instanceof Date\n ? dateOrOptions\n : typeof dateOrOptions === 'string'\n ? new Date(dateOrOptions)\n : dateOrOptions.date instanceof Date\n ? dateOrOptions.date\n : new Date(dateOrOptions.date);\n await this.waitStep({ run, stepId, timeoutDate: date });\n },\n pause: async (stepId: string) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({ run, stepId, eventName: PAUSE_EVENT_NAME });\n },\n delay: async (stepId: string, duration: Duration) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n await this.waitStep({\n run,\n stepId,\n timeoutDate: new Date(Date.now() + parseDuration(duration)),\n });\n },\n get sleep() {\n return this.delay;\n },\n poll: async <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => {\n if (!run) {\n throw new WorkflowEngineError('Missing workflow run', workflowId, runId);\n }\n const intervalMs = parseDuration(options?.interval ?? '30s');\n if (intervalMs < 30_000) {\n throw new WorkflowEngineError(\n `step.poll interval must be at least 30s (got ${intervalMs}ms)`,\n workflowId,\n runId,\n );\n }\n const timeoutMs = options?.timeout ? parseDuration(options.timeout) : undefined;\n return this.pollStep({ run, stepId, conditionFn, intervalMs, timeoutMs }) as Promise<\n { timedOut: false; data: T } | { timedOut: true }\n >;\n },\n };\n\n let step = { ...baseStep };\n const plugins = workflow.plugins ?? [];\n for (const plugin of plugins) {\n const extra = plugin.methods(step);\n step = { ...step, ...extra };\n }\n\n const context: WorkflowContext = {\n input: run.input as z.ZodTypeAny,\n workflowId: run.workflowId,\n runId: run.id,\n timeline: run.timeline,\n logger: this.logger,\n step,\n };\n\n const result = await workflow.handler(context);\n\n run = await this.getRun({ runId, resourceId: scopedResourceId });\n\n const isLastParsedStep = run.currentStepId === workflow.steps[workflow.steps.length - 1]?.id;\n const hasPluginSteps = (workflow.plugins?.length ?? 0) > 0;\n const noParsedSteps = workflow.steps.length === 0;\n const shouldComplete =\n run.status === WorkflowStatus.RUNNING &&\n (noParsedSteps || isLastParsedStep || (hasPluginSteps && result !== undefined));\n if (shouldComplete) {\n const normalizedResult = result === undefined ? {} : result;\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.COMPLETED,\n output: normalizedResult,\n completedAt: new Date(),\n jobId: job?.id,\n },\n });\n\n this.logger.log('Workflow run completed.', {\n runId,\n workflowId,\n });\n }\n } catch (error) {\n if (run.retryCount < run.maxRetries) {\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n retryCount: run.retryCount + 1,\n jobId: job?.id,\n },\n });\n\n const retryDelay = 2 ** run.retryCount * 1000;\n\n // NOTE: Do not use pg-boss retryLimit and retryBackoff so that we can fully control the retry logic from the WorkflowEngine and not PGBoss.\n const pgBossJob: WorkflowRunJobParameters = {\n runId,\n resourceId: scopedResourceId,\n workflowId,\n input,\n };\n await this.boss?.send('workflow-run', pgBossJob, {\n startAfter: new Date(Date.now() + retryDelay),\n expireInSeconds: defaultExpireInSeconds,\n });\n\n return;\n }\n\n // TODO: Ensure that this code always runs, even if worker is stopped unexpectedly.\n await this.updateRun({\n runId,\n resourceId: scopedResourceId,\n data: {\n status: WorkflowStatus.FAILED,\n error: error instanceof Error ? error.message : String(error),\n jobId: job?.id,\n },\n });\n\n throw error;\n }\n }\n\n private getCachedStepEntry(\n timeline: Record<string, unknown>,\n stepId: string,\n ): TimelineStepEntry | null {\n const stepEntry = timeline[stepId];\n return stepEntry && typeof stepEntry === 'object' && 'output' in stepEntry\n ? (stepEntry as TimelineStepEntry)\n : null;\n }\n\n private async runStep({\n stepId,\n run,\n handler,\n }: {\n stepId: string;\n run: WorkflowRun;\n handler: () => Promise<unknown>;\n }) {\n return withPostgresTransaction(\n this.db,\n async (db) => {\n const persistedRun = await this.getRun(\n { runId: run.id, resourceId: run.resourceId ?? undefined },\n {\n exclusiveLock: true,\n db,\n },\n );\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n this.logger.log(`Step ${stepId} skipped, workflow run is ${persistedRun.status}`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return;\n }\n\n try {\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.output;\n }\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n },\n },\n { db },\n );\n\n this.logger.log(`Running step ${stepId}...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n let output = await handler();\n\n if (output === undefined) {\n output = {};\n }\n\n run = await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n timeline: merge(run.timeline, {\n [stepId]: {\n output,\n timestamp: new Date(),\n },\n }),\n },\n },\n { db },\n );\n\n return output;\n } catch (error) {\n this.logger.error(`Step ${stepId} failed:`, error as Error, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n await this.updateRun(\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.FAILED,\n error: error instanceof Error ? `${error.message}\\n${error.stack}` : String(error),\n },\n },\n { db },\n );\n\n throw error;\n }\n },\n this.pool,\n );\n }\n\n private async waitStep({\n run,\n stepId,\n eventName,\n timeoutDate,\n }: {\n run: WorkflowRun;\n stepId: string;\n eventName?: string;\n timeoutDate?: Date;\n }): Promise<unknown> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return;\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? undefined : cached.output;\n }\n\n // Fast-forward: resolve immediately instead of pausing\n const fastForwardConfig = persistedRun.timeline.__fastForward;\n if (fastForwardConfig && eventName !== PAUSE_EVENT_NAME) {\n let output: unknown = {};\n\n if (eventName) {\n // This is a waitFor step — check for mock data\n if (\n typeof fastForwardConfig === 'object' &&\n fastForwardConfig !== null &&\n !Array.isArray(fastForwardConfig)\n ) {\n const mockData = (fastForwardConfig as Record<string, unknown>)[stepId];\n if (mockData !== undefined) {\n output = mockData;\n }\n }\n }\n\n // Write step output to timeline and continue (no pause, no job scheduling)\n run = await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(run.timeline, {\n [stepId]: {\n output,\n timestamp: new Date(),\n },\n }),\n },\n });\n\n this.logger.log(`Step ${stepId} fast-forwarded`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return output;\n }\n\n const timeoutEvent = timeoutDate ? `__timeout_${stepId}` : undefined;\n\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(run.timeline, {\n [`${stepId}-wait-for`]: {\n waitFor: { eventName, timeoutEvent },\n timestamp: new Date(),\n },\n }),\n },\n });\n\n if (timeoutDate && timeoutEvent) {\n const job: WorkflowRunJobParameters = {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: timeoutEvent, data: { date: timeoutDate.toISOString() } },\n };\n await this.boss.send(WORKFLOW_RUN_QUEUE_NAME, job, {\n startAfter: timeoutDate.getTime() <= Date.now() ? new Date() : timeoutDate,\n expireInSeconds: defaultExpireInSeconds,\n });\n }\n\n this.logger.log(\n `Step ${stepId} waiting${eventName ? ` for event \"${eventName}\"` : ''}${timeoutDate ? ` until ${timeoutDate.toISOString()}` : ''}`,\n { runId: run.id, workflowId: run.workflowId },\n );\n }\n\n private async pollStep<T>({\n run,\n stepId,\n conditionFn,\n intervalMs,\n timeoutMs,\n }: {\n run: WorkflowRun;\n stepId: string;\n conditionFn: () => Promise<T | false>;\n intervalMs: number;\n timeoutMs?: number;\n }): Promise<{ timedOut: false; data: T } | { timedOut: true } | undefined> {\n const persistedRun = await this.getRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n });\n\n if (\n persistedRun.status === WorkflowStatus.CANCELLED ||\n persistedRun.status === WorkflowStatus.PAUSED ||\n persistedRun.status === WorkflowStatus.FAILED\n ) {\n return { timedOut: true };\n }\n\n const cached = this.getCachedStepEntry(persistedRun.timeline, stepId);\n if (cached?.output !== undefined) {\n return cached.timedOut ? { timedOut: true } : { timedOut: false, data: cached.output as T };\n }\n\n const pollStateEntry = persistedRun.timeline[`${stepId}-poll`];\n const startedAt =\n pollStateEntry && typeof pollStateEntry === 'object' && 'startedAt' in pollStateEntry\n ? new Date((pollStateEntry as { startedAt: string }).startedAt)\n : new Date();\n\n if (timeoutMs !== undefined && Date.now() >= startedAt.getTime() + timeoutMs) {\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(persistedRun.timeline, {\n [stepId]: { output: {}, timedOut: true as const, timestamp: new Date() },\n }),\n },\n });\n return { timedOut: true };\n }\n\n const result = await conditionFn();\n\n if (result !== false) {\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n currentStepId: stepId,\n timeline: merge(persistedRun.timeline, {\n [stepId]: { output: result, timestamp: new Date() },\n }),\n },\n });\n return { timedOut: false, data: result };\n }\n\n const pollEvent = `__poll_${stepId}`;\n await this.updateRun({\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n data: {\n status: WorkflowStatus.PAUSED,\n currentStepId: stepId,\n pausedAt: new Date(),\n timeline: merge(persistedRun.timeline, {\n [`${stepId}-poll`]: { startedAt: startedAt.toISOString() },\n [`${stepId}-wait-for`]: {\n waitFor: { timeoutEvent: pollEvent, skipOutput: true },\n timestamp: new Date(),\n },\n }),\n },\n });\n\n await this.boss.send(\n WORKFLOW_RUN_QUEUE_NAME,\n {\n runId: run.id,\n resourceId: run.resourceId ?? undefined,\n workflowId: run.workflowId,\n input: run.input,\n event: { name: pollEvent, data: {} },\n },\n {\n startAfter: new Date(Date.now() + intervalMs),\n expireInSeconds: defaultExpireInSeconds,\n },\n );\n\n this.logger.log(`Step ${stepId} polling every ${intervalMs}ms...`, {\n runId: run.id,\n workflowId: run.workflowId,\n });\n\n return { timedOut: false, data: undefined as T };\n }\n\n private async checkIfHasStarted(): Promise<void> {\n if (!this._started) {\n throw new WorkflowEngineError('Workflow engine not started');\n }\n }\n\n private buildLogger(logger: WorkflowLogger): WorkflowInternalLogger {\n return {\n log: (message: string, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.log(`${parts}: ${message}`);\n },\n error: (message: string, error: Error, context?: WorkflowInternalLoggerContext) => {\n const { runId, workflowId } = context ?? {};\n const parts = [LOG_PREFIX, workflowId, runId].filter(Boolean).join(' ');\n logger.error(`${parts}: ${message}`, error);\n },\n };\n }\n\n async getRuns({\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: WorkflowStatus[];\n workflowId?: string;\n }): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n }> {\n return getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit,\n statuses,\n workflowId,\n },\n this.db,\n );\n }\n}\n",
|
|
9
9
|
"import * as ts from 'typescript';\nimport type { StepInternalDefinition, WorkflowContext } from './types';\nimport { StepType } from './types';\n\ntype ParseWorkflowHandlerReturnType = {\n steps: StepInternalDefinition[];\n};\n\nexport function parseWorkflowHandler(\n handler: (context: WorkflowContext) => Promise<unknown>,\n): ParseWorkflowHandlerReturnType {\n const handlerSource = handler.toString();\n const sourceFile = ts.createSourceFile('handler.ts', handlerSource, ts.ScriptTarget.Latest, true);\n\n const steps: Map<string, StepInternalDefinition> = new Map();\n\n function isInConditional(node: ts.Node): boolean {\n let current = node.parent;\n while (current) {\n if (\n ts.isIfStatement(current) ||\n ts.isConditionalExpression(current) ||\n ts.isSwitchStatement(current) ||\n ts.isCaseClause(current)\n ) {\n return true;\n }\n current = current.parent;\n }\n return false;\n }\n\n function isInLoop(node: ts.Node): boolean {\n let current = node.parent;\n while (current) {\n if (\n ts.isForStatement(current) ||\n ts.isForInStatement(current) ||\n ts.isForOfStatement(current) ||\n ts.isWhileStatement(current) ||\n ts.isDoStatement(current)\n ) {\n return true;\n }\n current = current.parent;\n }\n return false;\n }\n\n function extractStepId(arg: ts.Expression): {\n id: string;\n isDynamic: boolean;\n } {\n if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) {\n return { id: arg.text, isDynamic: false };\n }\n\n if (ts.isTemplateExpression(arg)) {\n let templateStr = arg.head.text;\n for (const span of arg.templateSpans) {\n templateStr += `\\${...}`;\n templateStr += span.literal.text;\n }\n return { id: templateStr, isDynamic: true };\n }\n\n return { id: arg.getText(sourceFile), isDynamic: true };\n }\n\n function visit(node: ts.Node) {\n if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {\n const propertyAccess = node.expression;\n const objectName = propertyAccess.expression.getText(sourceFile);\n const methodName = propertyAccess.name.text;\n\n if (\n objectName === 'step' &&\n (methodName === 'run' ||\n methodName === 'waitFor' ||\n methodName === 'pause' ||\n methodName === 'waitUntil' ||\n methodName === 'delay' ||\n methodName === 'sleep' ||\n methodName === 'poll')\n ) {\n const firstArg = node.arguments[0];\n if (firstArg) {\n const { id, isDynamic } = extractStepId(firstArg);\n const stepType = methodName === 'sleep' ? StepType.DELAY : (methodName as StepType);\n\n const stepDefinition: StepInternalDefinition = {\n id,\n type: stepType,\n conditional: isInConditional(node),\n loop: isInLoop(node),\n isDynamic,\n };\n\n if (steps.has(id)) {\n throw new Error(\n `Duplicate step ID detected: '${id}'. Step IDs must be unique within a workflow.`,\n );\n }\n\n steps.set(id, stepDefinition);\n }\n }\n }\n\n ts.forEachChild(node, visit);\n }\n\n visit(sourceFile);\n\n return { steps: Array.from(steps.values()) };\n}\n",
|
|
10
10
|
"import type { z } from 'zod';\nimport type { WorkflowRun } from './db/types';\nimport type { Duration } from './duration';\n\nexport enum WorkflowStatus {\n PENDING = 'pending',\n RUNNING = 'running',\n PAUSED = 'paused',\n COMPLETED = 'completed',\n FAILED = 'failed',\n CANCELLED = 'cancelled',\n}\n\nexport enum StepType {\n PAUSE = 'pause',\n RUN = 'run',\n WAIT_FOR = 'waitFor',\n WAIT_UNTIL = 'waitUntil',\n DELAY = 'delay',\n POLL = 'poll',\n}\n\nexport type InputParameters = z.ZodTypeAny;\nexport type InferInputParameters<P extends InputParameters> = P extends z.ZodTypeAny\n ? z.infer<P>\n : never;\n\nexport type WorkflowOptions<I extends InputParameters> = {\n timeout?: number;\n retries?: number;\n inputSchema?: I;\n};\n\nexport type StepBaseContext = {\n run: <T>(stepId: string, handler: () => Promise<T>) => Promise<T>;\n waitFor: {\n <T extends InputParameters>(\n stepId: string,\n options: { eventName: string; schema?: T },\n ): Promise<InferInputParameters<T>>;\n <T extends InputParameters>(\n stepId: string,\n options: { eventName: string; timeout: number; schema?: T },\n ): Promise<InferInputParameters<T> | undefined>;\n };\n waitUntil: {\n (stepId: string, date: Date): Promise<void>;\n (stepId: string, dateString: string): Promise<void>;\n (stepId: string, options: { date: Date | string }): Promise<void>;\n };\n /** Delay execution for a duration (sugar over waitUntil). Alias: sleep. */\n delay: (stepId: string, duration: Duration) => Promise<void>;\n /** Alias for delay. */\n sleep: (stepId: string, duration: Duration) => Promise<void>;\n pause: (stepId: string) => Promise<void>;\n poll: <T>(\n stepId: string,\n conditionFn: () => Promise<T | false>,\n options?: { interval?: Duration; timeout?: Duration },\n ) => Promise<{ timedOut: false; data: T } | { timedOut: true }>;\n};\n\n/**\n * Plugin that extends the workflow step API with extra methods.\n * @template TStepBase - The step type this plugin receives (base + previous plugins).\n * @template TStepExt - The extra methods this plugin adds to step.\n */\nexport interface WorkflowPlugin<TStepBase = StepBaseContext, TStepExt = object> {\n name: string;\n methods: (step: TStepBase) => TStepExt;\n}\n\nexport type WorkflowContext<\n TInput extends InputParameters = InputParameters,\n TStep extends StepBaseContext = StepBaseContext,\n> = {\n input: InferInputParameters<TInput>;\n step: TStep;\n workflowId: string;\n runId: string;\n timeline: Record<string, unknown>;\n logger: WorkflowLogger;\n};\n\nexport type WorkflowDefinition<\n TInput extends InputParameters = InputParameters,\n TStep extends StepBaseContext = StepBaseContext,\n> = {\n id: string;\n handler: (context: WorkflowContext<TInput, TStep>) => Promise<unknown>;\n inputSchema?: TInput;\n timeout?: number; // milliseconds\n retries?: number;\n plugins?: WorkflowPlugin[];\n};\n\nexport type StepInternalDefinition = {\n id: string;\n type: StepType;\n conditional: boolean;\n loop: boolean;\n isDynamic: boolean;\n};\n\nexport type WorkflowInternalDefinition<\n TInput extends InputParameters = InputParameters,\n TStep extends StepBaseContext = StepBaseContext,\n> = WorkflowDefinition<TInput, TStep> & {\n steps: StepInternalDefinition[];\n};\n\n/**\n * Chainable workflow factory: call as (id, handler, options) and/or use .use(plugin).\n * TStepExt is the accumulated step extension from all plugins (step = StepContext & TStepExt).\n */\nexport interface WorkflowFactory<TStepExt = object> {\n (\n id: string,\n handler: (\n context: WorkflowContext<InputParameters, StepBaseContext & TStepExt>,\n ) => Promise<unknown>,\n options?: WorkflowOptions<InputParameters>,\n ): WorkflowDefinition<InputParameters, StepBaseContext & TStepExt>;\n use<TNewExt>(\n plugin: WorkflowPlugin<StepBaseContext & TStepExt, TNewExt>,\n ): WorkflowFactory<TStepExt & TNewExt>;\n}\n\nexport type WorkflowRunProgress = WorkflowRun & {\n completionPercentage: number;\n totalSteps: number;\n completedSteps: number;\n};\n\nexport interface WorkflowLogger {\n log(message: string): void;\n error(message: string, ...args: unknown[]): void;\n}\n\nexport type WorkflowInternalLoggerContext = {\n runId?: string;\n workflowId?: string;\n};\nexport interface WorkflowInternalLogger {\n log(message: string, context?: WorkflowInternalLoggerContext): void;\n error(message: string, error: Error, context?: WorkflowInternalLoggerContext): void;\n}\n",
|
|
11
11
|
"import type { Db } from 'pg-boss';\n\nexport async function runMigrations(db: Db): Promise<void> {\n const tableExistsResult = await db.executeSql(\n `\n SELECT EXISTS (\n SELECT FROM information_schema.tables \n WHERE table_schema = 'public' \n AND table_name = 'workflow_runs'\n );\n `,\n [],\n );\n\n if (!tableExistsResult.rows[0]?.exists) {\n await db.executeSql(\n `\n CREATE TABLE workflow_runs (\n id varchar(32) PRIMARY KEY NOT NULL,\n created_at timestamp with time zone DEFAULT now() NOT NULL,\n updated_at timestamp with time zone DEFAULT now() NOT NULL,\n resource_id varchar(32),\n workflow_id varchar(32) NOT NULL,\n status text DEFAULT 'pending' NOT NULL,\n input jsonb NOT NULL,\n output jsonb,\n error text,\n current_step_id varchar(256) NOT NULL,\n timeline jsonb DEFAULT '{}'::jsonb NOT NULL,\n paused_at timestamp with time zone,\n resumed_at timestamp with time zone,\n completed_at timestamp with time zone,\n timeout_at timestamp with time zone,\n retry_count integer DEFAULT 0 NOT NULL,\n max_retries integer DEFAULT 0 NOT NULL,\n job_id varchar(256)\n );\n `,\n [],\n );\n\n await db.executeSql(\n `\n CREATE INDEX workflow_runs_workflow_id_idx ON workflow_runs USING btree (workflow_id);\n `,\n [],\n );\n\n await db.executeSql(\n `\n CREATE INDEX workflow_runs_created_at_idx ON workflow_runs USING btree (created_at);\n `,\n [],\n );\n\n await db.executeSql(\n `\n CREATE INDEX workflow_runs_resource_id_idx ON workflow_runs USING btree (resource_id);\n `,\n [],\n );\n }\n}\n",
|
|
12
|
-
"import ksuid from 'ksuid';\nimport type { Db } from 'pg-boss';\nimport type { WorkflowRun } from './types';\n\nexport function generateKSUID(prefix?: string): string {\n return `${prefix ? `${prefix}_` : ''}${ksuid.randomSync().string}`;\n}\n\ntype WorkflowRunRow = {\n id: string;\n created_at: string | Date;\n updated_at: string | Date;\n resource_id: string | null;\n workflow_id: string;\n status: 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled';\n input: string | unknown;\n output: string | unknown | null;\n error: string | null;\n current_step_id: string;\n timeline: string | Record<string, unknown>;\n paused_at: string | Date | null;\n resumed_at: string | Date | null;\n completed_at: string | Date | null;\n timeout_at: string | Date | null;\n retry_count: number;\n max_retries: number;\n job_id: string | null;\n};\n\nfunction mapRowToWorkflowRun(row: WorkflowRunRow): WorkflowRun {\n return {\n id: row.id,\n createdAt: new Date(row.created_at),\n updatedAt: new Date(row.updated_at),\n resourceId: row.resource_id,\n workflowId: row.workflow_id,\n status: row.status,\n input: typeof row.input === 'string' ? JSON.parse(row.input) : row.input,\n output:\n typeof row.output === 'string'\n ? row.output.trim().startsWith('{') || row.output.trim().startsWith('[')\n ? JSON.parse(row.output)\n : row.output\n : (row.output ?? null),\n error: row.error,\n currentStepId: row.current_step_id,\n timeline: typeof row.timeline === 'string' ? JSON.parse(row.timeline) : row.timeline,\n pausedAt: row.paused_at ? new Date(row.paused_at) : null,\n resumedAt: row.resumed_at ? new Date(row.resumed_at) : null,\n completedAt: row.completed_at ? new Date(row.completed_at) : null,\n timeoutAt: row.timeout_at ? new Date(row.timeout_at) : null,\n retryCount: row.retry_count,\n maxRetries: row.max_retries,\n jobId: row.job_id,\n };\n}\n\nexport async function insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId,\n status,\n input,\n maxRetries,\n timeoutAt,\n }: {\n resourceId?: string;\n workflowId: string;\n currentStepId: string;\n status: string;\n input: unknown;\n maxRetries: number;\n timeoutAt: Date | null;\n },\n db: Db,\n): Promise<WorkflowRun> {\n const runId = generateKSUID('run');\n const now = new Date();\n\n const result = await db.executeSql(\n `INSERT INTO workflow_runs (\n id, \n resource_id, \n workflow_id, \n current_step_id, \n status, \n input, \n max_retries, \n timeout_at,\n created_at,\n updated_at,\n timeline,\n retry_count\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)\n RETURNING *`,\n [\n runId,\n resourceId ?? null,\n workflowId,\n currentStepId,\n status,\n JSON.stringify(input),\n maxRetries,\n timeoutAt,\n now,\n now,\n '{}',\n 0,\n ],\n );\n\n const insertedRun = result.rows[0];\n\n if (!insertedRun) {\n throw new Error('Failed to insert workflow run');\n }\n\n return mapRowToWorkflowRun(insertedRun);\n}\n\nexport async function getWorkflowRun(\n {\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db: Db },\n): Promise<WorkflowRun | null> {\n const lockSuffix = exclusiveLock ? 'FOR UPDATE' : '';\n\n const result = resourceId\n ? await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1 AND resource_id = $2\n ${lockSuffix}`,\n [runId, resourceId],\n )\n : await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1\n ${lockSuffix}`,\n [runId],\n );\n\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function updateWorkflowRun(\n {\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n },\n db: Db,\n): Promise<WorkflowRun | null> {\n const now = new Date();\n\n const updates: string[] = ['updated_at = $1'];\n const values: (string | number | Date | null)[] = [now];\n let paramIndex = 2;\n\n if (data.status !== undefined) {\n updates.push(`status = $${paramIndex}`);\n values.push(data.status);\n paramIndex++;\n }\n if (data.currentStepId !== undefined) {\n updates.push(`current_step_id = $${paramIndex}`);\n values.push(data.currentStepId);\n paramIndex++;\n }\n if (data.timeline !== undefined) {\n updates.push(`timeline = $${paramIndex}`);\n values.push(JSON.stringify(data.timeline));\n paramIndex++;\n }\n if (data.pausedAt !== undefined) {\n updates.push(`paused_at = $${paramIndex}`);\n values.push(data.pausedAt);\n paramIndex++;\n }\n if (data.resumedAt !== undefined) {\n updates.push(`resumed_at = $${paramIndex}`);\n values.push(data.resumedAt);\n paramIndex++;\n }\n if (data.completedAt !== undefined) {\n updates.push(`completed_at = $${paramIndex}`);\n values.push(data.completedAt);\n paramIndex++;\n }\n if (data.output !== undefined) {\n updates.push(`output = $${paramIndex}`);\n values.push(JSON.stringify(data.output));\n paramIndex++;\n }\n if (data.error !== undefined) {\n updates.push(`error = $${paramIndex}`);\n values.push(data.error);\n paramIndex++;\n }\n if (data.retryCount !== undefined) {\n updates.push(`retry_count = $${paramIndex}`);\n values.push(data.retryCount);\n paramIndex++;\n }\n if (data.jobId !== undefined) {\n updates.push(`job_id = $${paramIndex}`);\n values.push(data.jobId);\n paramIndex++;\n }\n\n const whereClause = resourceId\n ? `WHERE id = $${paramIndex} AND resource_id = $${paramIndex + 1}`\n : `WHERE id = $${paramIndex}`;\n\n values.push(runId);\n if (resourceId) {\n values.push(resourceId);\n }\n\n const query = `\n UPDATE workflow_runs \n SET ${updates.join(', ')}\n ${whereClause}\n RETURNING *\n `;\n\n const result = await db.executeSql(query, values);\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: string[];\n workflowId?: string;\n },\n db: Db,\n): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n}> {\n const conditions: string[] = [];\n const values: (string | number | string[] | Date)[] = [];\n let paramIndex = 1;\n\n if (resourceId) {\n conditions.push(`resource_id = $${paramIndex}`);\n values.push(resourceId);\n paramIndex++;\n }\n\n if (statuses && statuses.length > 0) {\n conditions.push(`status = ANY($${paramIndex})`);\n values.push(statuses);\n paramIndex++;\n }\n\n if (workflowId) {\n conditions.push(`workflow_id = $${paramIndex}`);\n values.push(workflowId);\n paramIndex++;\n }\n\n if (startingAfter) {\n const cursorResult = await db.executeSql(\n 'SELECT created_at FROM workflow_runs WHERE id = $1 LIMIT 1',\n [startingAfter],\n );\n if (cursorResult.rows[0]?.created_at) {\n conditions.push(`created_at < $${paramIndex}`);\n values.push(\n typeof cursorResult.rows[0].created_at === 'string'\n ? new Date(cursorResult.rows[0].created_at)\n : cursorResult.rows[0].created_at,\n );\n paramIndex++;\n }\n }\n\n if (endingBefore) {\n const cursorResult = await db.executeSql(\n 'SELECT created_at FROM workflow_runs WHERE id = $1 LIMIT 1',\n [endingBefore],\n );\n if (cursorResult.rows[0]?.created_at) {\n conditions.push(`created_at > $${paramIndex}`);\n values.push(\n typeof cursorResult.rows[0].created_at === 'string'\n ? new Date(cursorResult.rows[0].created_at)\n : cursorResult.rows[0].created_at,\n );\n paramIndex++;\n }\n }\n\n const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';\n const actualLimit = Math.min(Math.max(limit, 1), 100) + 1;\n\n const query = `\n SELECT * FROM workflow_runs\n ${whereClause}\n ORDER BY created_at DESC\n LIMIT $${paramIndex}\n `;\n values.push(actualLimit);\n\n const result = await db.executeSql(query, values);\n const rows = result.rows;\n\n const hasMore = rows.length > (limit ?? 20);\n const rawItems = hasMore ? rows.slice(0, limit) : rows;\n const items = rawItems.map((row) => mapRowToWorkflowRun(row));\n const hasPrev = !!endingBefore;\n const nextCursor = hasMore && items.length > 0 ? (items[items.length - 1]?.id ?? null) : null;\n const prevCursor = hasPrev && items.length > 0 ? (items[0]?.id ?? null) : null;\n\n return { items, nextCursor, prevCursor, hasMore, hasPrev };\n}\n\n/**\n * Run a callback inside a PostgreSQL transaction using a dedicated client.\n *\n * When a `pool` is provided, a dedicated client is checked out so that\n * BEGIN / COMMIT / ROLLBACK all execute on the **same** connection.\n * This is critical for `SELECT … FOR UPDATE` locks and any work that\n * yields to the event-loop inside the transaction (e.g. async step handlers).\n *\n * Falls back to the pg-boss `Db` adapter when no pool is given (unit-test path).\n */\nexport async function withPostgresTransaction<T>(\n db: Db,\n callback: (db: Db) => Promise<T>,\n pool?: {\n connect: () => Promise<{\n query: (text: string, values?: unknown[]) => Promise<unknown>;\n release: () => void;\n }>;\n },\n): Promise<T> {\n let txDb: Db;\n let release: (() => void) | undefined;\n\n if (pool) {\n const client = await pool.connect();\n txDb = {\n executeSql: (text: string, values?: unknown[]) =>\n client.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n release = () => client.release();\n } else {\n txDb = db;\n }\n\n try {\n await txDb.executeSql('BEGIN', []);\n const result = await callback(txDb);\n await txDb.executeSql('COMMIT', []);\n return result;\n } catch (error) {\n await txDb.executeSql('ROLLBACK', []);\n throw error;\n } finally {\n release?.();\n }\n}\n"
|
|
12
|
+
"import ksuid from 'ksuid';\nimport type { Db } from 'pg-boss';\nimport type { WorkflowRun } from './types';\n\nexport function generateKSUID(prefix?: string): string {\n return `${prefix ? `${prefix}_` : ''}${ksuid.randomSync().string}`;\n}\n\ntype WorkflowRunRow = {\n id: string;\n created_at: string | Date;\n updated_at: string | Date;\n resource_id: string | null;\n workflow_id: string;\n status: 'pending' | 'running' | 'paused' | 'completed' | 'failed' | 'cancelled';\n input: string | unknown;\n output: string | unknown | null;\n error: string | null;\n current_step_id: string;\n timeline: string | Record<string, unknown>;\n paused_at: string | Date | null;\n resumed_at: string | Date | null;\n completed_at: string | Date | null;\n timeout_at: string | Date | null;\n retry_count: number;\n max_retries: number;\n job_id: string | null;\n};\n\nfunction mapRowToWorkflowRun(row: WorkflowRunRow): WorkflowRun {\n return {\n id: row.id,\n createdAt: new Date(row.created_at),\n updatedAt: new Date(row.updated_at),\n resourceId: row.resource_id,\n workflowId: row.workflow_id,\n status: row.status,\n input: typeof row.input === 'string' ? JSON.parse(row.input) : row.input,\n output:\n typeof row.output === 'string'\n ? row.output.trim().startsWith('{') || row.output.trim().startsWith('[')\n ? JSON.parse(row.output)\n : row.output\n : (row.output ?? null),\n error: row.error,\n currentStepId: row.current_step_id,\n timeline: typeof row.timeline === 'string' ? JSON.parse(row.timeline) : row.timeline,\n pausedAt: row.paused_at ? new Date(row.paused_at) : null,\n resumedAt: row.resumed_at ? new Date(row.resumed_at) : null,\n completedAt: row.completed_at ? new Date(row.completed_at) : null,\n timeoutAt: row.timeout_at ? new Date(row.timeout_at) : null,\n retryCount: row.retry_count,\n maxRetries: row.max_retries,\n jobId: row.job_id,\n };\n}\n\nexport async function insertWorkflowRun(\n {\n resourceId,\n workflowId,\n currentStepId,\n status,\n input,\n maxRetries,\n timeoutAt,\n timeline,\n }: {\n resourceId?: string;\n workflowId: string;\n currentStepId: string;\n status: string;\n input: unknown;\n maxRetries: number;\n timeoutAt: Date | null;\n timeline?: Record<string, unknown>;\n },\n db: Db,\n): Promise<WorkflowRun> {\n const runId = generateKSUID('run');\n const now = new Date();\n\n const result = await db.executeSql(\n `INSERT INTO workflow_runs (\n id,\n resource_id,\n workflow_id,\n current_step_id,\n status,\n input,\n max_retries,\n timeout_at,\n created_at,\n updated_at,\n timeline,\n retry_count\n )\n VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)\n RETURNING *`,\n [\n runId,\n resourceId ?? null,\n workflowId,\n currentStepId,\n status,\n JSON.stringify(input),\n maxRetries,\n timeoutAt,\n now,\n now,\n JSON.stringify(timeline ?? {}),\n 0,\n ],\n );\n\n const insertedRun = result.rows[0];\n\n if (!insertedRun) {\n throw new Error('Failed to insert workflow run');\n }\n\n return mapRowToWorkflowRun(insertedRun);\n}\n\nexport async function getWorkflowRun(\n {\n runId,\n resourceId,\n }: {\n runId: string;\n resourceId?: string;\n },\n { exclusiveLock = false, db }: { exclusiveLock?: boolean; db: Db },\n): Promise<WorkflowRun | null> {\n const lockSuffix = exclusiveLock ? 'FOR UPDATE' : '';\n\n const result = resourceId\n ? await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1 AND resource_id = $2\n ${lockSuffix}`,\n [runId, resourceId],\n )\n : await db.executeSql(\n `SELECT * FROM workflow_runs \n WHERE id = $1\n ${lockSuffix}`,\n [runId],\n );\n\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function updateWorkflowRun(\n {\n runId,\n resourceId,\n data,\n }: {\n runId: string;\n resourceId?: string;\n data: Partial<WorkflowRun>;\n },\n db: Db,\n): Promise<WorkflowRun | null> {\n const now = new Date();\n\n const updates: string[] = ['updated_at = $1'];\n const values: (string | number | Date | null)[] = [now];\n let paramIndex = 2;\n\n if (data.status !== undefined) {\n updates.push(`status = $${paramIndex}`);\n values.push(data.status);\n paramIndex++;\n }\n if (data.currentStepId !== undefined) {\n updates.push(`current_step_id = $${paramIndex}`);\n values.push(data.currentStepId);\n paramIndex++;\n }\n if (data.timeline !== undefined) {\n updates.push(`timeline = $${paramIndex}`);\n values.push(JSON.stringify(data.timeline));\n paramIndex++;\n }\n if (data.pausedAt !== undefined) {\n updates.push(`paused_at = $${paramIndex}`);\n values.push(data.pausedAt);\n paramIndex++;\n }\n if (data.resumedAt !== undefined) {\n updates.push(`resumed_at = $${paramIndex}`);\n values.push(data.resumedAt);\n paramIndex++;\n }\n if (data.completedAt !== undefined) {\n updates.push(`completed_at = $${paramIndex}`);\n values.push(data.completedAt);\n paramIndex++;\n }\n if (data.output !== undefined) {\n updates.push(`output = $${paramIndex}`);\n values.push(JSON.stringify(data.output));\n paramIndex++;\n }\n if (data.error !== undefined) {\n updates.push(`error = $${paramIndex}`);\n values.push(data.error);\n paramIndex++;\n }\n if (data.retryCount !== undefined) {\n updates.push(`retry_count = $${paramIndex}`);\n values.push(data.retryCount);\n paramIndex++;\n }\n if (data.jobId !== undefined) {\n updates.push(`job_id = $${paramIndex}`);\n values.push(data.jobId);\n paramIndex++;\n }\n\n const whereClause = resourceId\n ? `WHERE id = $${paramIndex} AND resource_id = $${paramIndex + 1}`\n : `WHERE id = $${paramIndex}`;\n\n values.push(runId);\n if (resourceId) {\n values.push(resourceId);\n }\n\n const query = `\n UPDATE workflow_runs \n SET ${updates.join(', ')}\n ${whereClause}\n RETURNING *\n `;\n\n const result = await db.executeSql(query, values);\n const run = result.rows[0];\n\n if (!run) {\n return null;\n }\n\n return mapRowToWorkflowRun(run);\n}\n\nexport async function getWorkflowRuns(\n {\n resourceId,\n startingAfter,\n endingBefore,\n limit = 20,\n statuses,\n workflowId,\n }: {\n resourceId?: string;\n startingAfter?: string | null;\n endingBefore?: string | null;\n limit?: number;\n statuses?: string[];\n workflowId?: string;\n },\n db: Db,\n): Promise<{\n items: WorkflowRun[];\n nextCursor: string | null;\n prevCursor: string | null;\n hasMore: boolean;\n hasPrev: boolean;\n}> {\n const conditions: string[] = [];\n const values: (string | number | string[] | Date)[] = [];\n let paramIndex = 1;\n\n if (resourceId) {\n conditions.push(`resource_id = $${paramIndex}`);\n values.push(resourceId);\n paramIndex++;\n }\n\n if (statuses && statuses.length > 0) {\n conditions.push(`status = ANY($${paramIndex})`);\n values.push(statuses);\n paramIndex++;\n }\n\n if (workflowId) {\n conditions.push(`workflow_id = $${paramIndex}`);\n values.push(workflowId);\n paramIndex++;\n }\n\n if (startingAfter) {\n const cursorResult = await db.executeSql(\n 'SELECT created_at FROM workflow_runs WHERE id = $1 LIMIT 1',\n [startingAfter],\n );\n if (cursorResult.rows[0]?.created_at) {\n conditions.push(`created_at < $${paramIndex}`);\n values.push(\n typeof cursorResult.rows[0].created_at === 'string'\n ? new Date(cursorResult.rows[0].created_at)\n : cursorResult.rows[0].created_at,\n );\n paramIndex++;\n }\n }\n\n if (endingBefore) {\n const cursorResult = await db.executeSql(\n 'SELECT created_at FROM workflow_runs WHERE id = $1 LIMIT 1',\n [endingBefore],\n );\n if (cursorResult.rows[0]?.created_at) {\n conditions.push(`created_at > $${paramIndex}`);\n values.push(\n typeof cursorResult.rows[0].created_at === 'string'\n ? new Date(cursorResult.rows[0].created_at)\n : cursorResult.rows[0].created_at,\n );\n paramIndex++;\n }\n }\n\n const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';\n const actualLimit = Math.min(Math.max(limit, 1), 100) + 1;\n\n const isBackward = !!endingBefore && !startingAfter;\n\n const query = `\n SELECT * FROM workflow_runs\n ${whereClause}\n ORDER BY created_at ${isBackward ? 'ASC' : 'DESC'}\n LIMIT $${paramIndex}\n `;\n values.push(actualLimit);\n\n const result = await db.executeSql(query, values);\n const rows = result.rows;\n\n const hasExtraRow = rows.length > (limit ?? 20);\n const rawItems = hasExtraRow ? rows.slice(0, limit) : rows;\n\n if (isBackward) {\n rawItems.reverse();\n }\n\n const items = rawItems.map((row) => mapRowToWorkflowRun(row));\n\n const hasMore = isBackward ? items.length > 0 : hasExtraRow;\n const hasPrev = isBackward ? hasExtraRow : !!startingAfter && items.length > 0;\n\n const nextCursor = hasMore && items.length > 0 ? (items[items.length - 1]?.id ?? null) : null;\n const prevCursor = hasPrev && items.length > 0 ? (items[0]?.id ?? null) : null;\n\n return { items, nextCursor, prevCursor, hasMore, hasPrev };\n}\n\n/**\n * Run a callback inside a PostgreSQL transaction using a dedicated client.\n *\n * When a `pool` is provided, a dedicated client is checked out so that\n * BEGIN / COMMIT / ROLLBACK all execute on the **same** connection.\n * This is critical for `SELECT … FOR UPDATE` locks and any work that\n * yields to the event-loop inside the transaction (e.g. async step handlers).\n *\n * Falls back to the pg-boss `Db` adapter when no pool is given (unit-test path).\n */\nexport async function withPostgresTransaction<T>(\n db: Db,\n callback: (db: Db) => Promise<T>,\n pool?: {\n connect: () => Promise<{\n query: (text: string, values?: unknown[]) => Promise<unknown>;\n release: () => void;\n }>;\n },\n): Promise<T> {\n let txDb: Db;\n let release: (() => void) | undefined;\n\n if (pool) {\n const client = await pool.connect();\n txDb = {\n executeSql: (text: string, values?: unknown[]) =>\n client.query(text, values) as Promise<{ rows: unknown[] }>,\n };\n release = () => client.release();\n } else {\n txDb = db;\n }\n\n try {\n await txDb.executeSql('BEGIN', []);\n const result = await callback(txDb);\n await txDb.executeSql('COMMIT', []);\n return result;\n } catch (error) {\n await txDb.executeSql('ROLLBACK', []);\n throw error;\n } finally {\n release?.();\n }\n}\n"
|
|
13
13
|
],
|
|
14
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,qBAAuD,CAC9D,UAAkD,CAAC,GACxB;AAAA,EAC3B,MAAM,UAAW,CACf,IACA,WACE,aAAa,SAAS,YAAgC,CAAC,OACF;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,QAAQ,SAAS,IAAK,UAA+B;AAAA,EAChE;AAAA,EAEA,QAAQ,MAAM,CACZ,WAEA,sBAA0C;AAAA,IACxC,GAAG;AAAA,IACH;AAAA,EACF,CAAC;AAAA,EAEH,OAAO;AAAA;AAGF,IAAM,WAA4B,sBAAsB;;ACrC7C,IAAlB;;;ACAO,MAAM,4BAA4B,MAAM;AAAA,EAG3B;AAAA,EACA;AAAA,EACS;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tE,OAAO,IAAI,GAAG,UAAU,SAAS;AAAA;AAAA,MAEnC,OAAO,CAAC,SAAiB,OAAc,YAA4C;AAAA,QACjF,QAAQ,OAAO,eAAe,WAAW,CAAC;AAAA,QAC1C,MAAM,QAAQ,CAAC,YAAY,YAAY,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,QACtE,OAAO,MAAM,GAAG,UAAU,WAAW,KAAK;AAAA;AAAA,IAE9C;AAAA;AAAA,OAGI,QAAO;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,KAcC;AAAA,IACD,OAAO,gBACL;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,GACA,KAAK,EACP;AAAA;AAEJ;",
|
|
15
|
+
"debugId": "68C46DF96F96057E64756E2164756E21",
|
|
16
16
|
"names": []
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pg-workflows",
|
|
3
3
|
"description": "The simplest Postgres workflow engine for TypeScript - durable execution, event-driven orchestration, and automatic retries powered entirely by PostgreSQL",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|