pg-workflows 0.13.0 → 0.13.2
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/dist/client.entry.cjs +22 -1
- package/dist/client.entry.js +1 -1
- package/dist/client.entry.js.map +4 -4
- package/dist/index.cjs +79 -73
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +60 -74
- package/dist/index.js.map +6 -6
- package/dist/shared/{chunk-5xswmve7.js → chunk-hjycwrsq.js} +24 -3
- package/dist/shared/{chunk-5xswmve7.js.map → chunk-hjycwrsq.js.map} +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_PGBOSS_SCHEMA,
|
|
3
3
|
PAUSE_EVENT_NAME,
|
|
4
|
+
STEP_BASE_METHOD_TYPES,
|
|
4
5
|
WORKFLOW_RUN_DLQ_QUEUE_NAME,
|
|
5
6
|
WORKFLOW_RUN_QUEUE_NAME,
|
|
6
7
|
WorkflowClient,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
waitForTimelineKey,
|
|
23
24
|
withPostgresTransaction,
|
|
24
25
|
workflow
|
|
25
|
-
} from "./shared/chunk-
|
|
26
|
+
} from "./shared/chunk-hjycwrsq.js";
|
|
26
27
|
// src/engine.ts
|
|
27
28
|
import { merge } from "es-toolkit";
|
|
28
29
|
import pg from "pg";
|
|
@@ -73,11 +74,11 @@ function parseWorkflowHandler(handler) {
|
|
|
73
74
|
const propertyAccess = node.expression;
|
|
74
75
|
const objectName = propertyAccess.expression.getText(sourceFile);
|
|
75
76
|
const methodName = propertyAccess.name.text;
|
|
76
|
-
|
|
77
|
+
const stepType = objectName === "step" ? STEP_BASE_METHOD_TYPES.get(methodName) : undefined;
|
|
78
|
+
if (stepType !== undefined) {
|
|
77
79
|
const firstArg = node.arguments[0];
|
|
78
80
|
if (firstArg) {
|
|
79
81
|
const { id, isDynamic } = extractStepId(firstArg);
|
|
80
|
-
const stepType = methodName === "sleep" ? "delay" /* DELAY */ : methodName;
|
|
81
82
|
const stepDefinition = {
|
|
82
83
|
id,
|
|
83
84
|
type: stepType,
|
|
@@ -243,6 +244,7 @@ class WorkflowEngine {
|
|
|
243
244
|
for (const workflow2 of this.unregisteredWorkflows.values()) {
|
|
244
245
|
await this.registerWorkflow(workflow2);
|
|
245
246
|
}
|
|
247
|
+
this.unregisteredWorkflows.clear();
|
|
246
248
|
}
|
|
247
249
|
const mainQueueOptions = {
|
|
248
250
|
retryLimit: 0,
|
|
@@ -380,6 +382,9 @@ class WorkflowEngine {
|
|
|
380
382
|
});
|
|
381
383
|
return run;
|
|
382
384
|
}
|
|
385
|
+
async createChildWorkflowRun(params) {
|
|
386
|
+
return this.createWorkflowRun(params);
|
|
387
|
+
}
|
|
383
388
|
async createWorkflowRun({
|
|
384
389
|
workflowId,
|
|
385
390
|
input,
|
|
@@ -766,75 +771,7 @@ class WorkflowEngine {
|
|
|
766
771
|
}, { db });
|
|
767
772
|
}, this.pool);
|
|
768
773
|
}
|
|
769
|
-
|
|
770
|
-
run: async (stepId, handler) => {
|
|
771
|
-
if (!run) {
|
|
772
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
773
|
-
}
|
|
774
|
-
return this.runStep({ stepId, run, handler });
|
|
775
|
-
},
|
|
776
|
-
waitFor: async (stepId, { eventName, timeout }) => {
|
|
777
|
-
if (!run) {
|
|
778
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
779
|
-
}
|
|
780
|
-
const timeoutDate = timeout ? new Date(Date.now() + timeout) : undefined;
|
|
781
|
-
return this.waitStep({ run, stepId, eventName, timeoutDate });
|
|
782
|
-
},
|
|
783
|
-
waitUntil: async (stepId, dateOrOptions) => {
|
|
784
|
-
if (!run) {
|
|
785
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
786
|
-
}
|
|
787
|
-
const date = dateOrOptions instanceof Date ? dateOrOptions : typeof dateOrOptions === "string" ? new Date(dateOrOptions) : dateOrOptions.date instanceof Date ? dateOrOptions.date : new Date(dateOrOptions.date);
|
|
788
|
-
await this.waitStep({ run, stepId, timeoutDate: date });
|
|
789
|
-
},
|
|
790
|
-
pause: async (stepId) => {
|
|
791
|
-
if (!run) {
|
|
792
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
793
|
-
}
|
|
794
|
-
await this.waitStep({ run, stepId, eventName: PAUSE_EVENT_NAME });
|
|
795
|
-
},
|
|
796
|
-
delay: async (stepId, duration) => {
|
|
797
|
-
if (!run) {
|
|
798
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
799
|
-
}
|
|
800
|
-
await this.waitStep({
|
|
801
|
-
run,
|
|
802
|
-
stepId,
|
|
803
|
-
timeoutDate: new Date(Date.now() + parseDuration(duration))
|
|
804
|
-
});
|
|
805
|
-
},
|
|
806
|
-
get sleep() {
|
|
807
|
-
return this.delay;
|
|
808
|
-
},
|
|
809
|
-
poll: async (stepId, conditionFn, options) => {
|
|
810
|
-
if (!run) {
|
|
811
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
812
|
-
}
|
|
813
|
-
const intervalMs = parseDuration(options?.interval ?? "30s");
|
|
814
|
-
if (intervalMs < 30000) {
|
|
815
|
-
throw new WorkflowEngineError(`step.poll interval must be at least 30s (got ${intervalMs}ms)`, workflowId, runId);
|
|
816
|
-
}
|
|
817
|
-
const timeoutMs = options?.timeout ? parseDuration(options.timeout) : undefined;
|
|
818
|
-
return this.pollStep({ run, stepId, conditionFn, intervalMs, timeoutMs });
|
|
819
|
-
},
|
|
820
|
-
invokeChildWorkflow: async (stepId, refOrParams, inputArg, optionsArg) => {
|
|
821
|
-
if (!run) {
|
|
822
|
-
throw new WorkflowEngineError("Missing workflow run", workflowId, runId);
|
|
823
|
-
}
|
|
824
|
-
const resolvedChildCall = this.resolveWorkflowRunParameters(refOrParams, inputArg, optionsArg);
|
|
825
|
-
const childWorkflowInvocation = {
|
|
826
|
-
run,
|
|
827
|
-
stepId,
|
|
828
|
-
workflowId: resolvedChildCall.workflowId,
|
|
829
|
-
input: resolvedChildCall.input,
|
|
830
|
-
options: resolvedChildCall.options,
|
|
831
|
-
resourceId: resolvedChildCall.resourceId,
|
|
832
|
-
idempotencyKey: resolvedChildCall.idempotencyKey
|
|
833
|
-
};
|
|
834
|
-
return this.invokeChildWorkflowStep(childWorkflowInvocation);
|
|
835
|
-
}
|
|
836
|
-
};
|
|
837
|
-
let step = { ...baseStep };
|
|
774
|
+
let step = this.createBaseStep(run, workflowId, runId);
|
|
838
775
|
const plugins = workflow2.plugins ?? [];
|
|
839
776
|
const context = {
|
|
840
777
|
input: run.input,
|
|
@@ -924,6 +861,55 @@ class WorkflowEngine {
|
|
|
924
861
|
workflowId: run.workflowId
|
|
925
862
|
});
|
|
926
863
|
}
|
|
864
|
+
createBaseStep(run, workflowId, runId) {
|
|
865
|
+
return {
|
|
866
|
+
run: async (stepId, handler) => {
|
|
867
|
+
return this.runStep({ stepId, run, handler });
|
|
868
|
+
},
|
|
869
|
+
waitFor: async (stepId, { eventName, timeout }) => {
|
|
870
|
+
const timeoutDate = timeout ? new Date(Date.now() + timeout) : undefined;
|
|
871
|
+
return this.waitStep({ run, stepId, eventName, timeoutDate });
|
|
872
|
+
},
|
|
873
|
+
waitUntil: async (stepId, dateOrOptions) => {
|
|
874
|
+
const date = dateOrOptions instanceof Date ? dateOrOptions : typeof dateOrOptions === "string" ? new Date(dateOrOptions) : dateOrOptions.date instanceof Date ? dateOrOptions.date : new Date(dateOrOptions.date);
|
|
875
|
+
await this.waitStep({ run, stepId, timeoutDate: date });
|
|
876
|
+
},
|
|
877
|
+
pause: async (stepId) => {
|
|
878
|
+
await this.waitStep({ run, stepId, eventName: PAUSE_EVENT_NAME });
|
|
879
|
+
},
|
|
880
|
+
delay: async (stepId, duration) => {
|
|
881
|
+
await this.waitStep({
|
|
882
|
+
run,
|
|
883
|
+
stepId,
|
|
884
|
+
timeoutDate: new Date(Date.now() + parseDuration(duration))
|
|
885
|
+
});
|
|
886
|
+
},
|
|
887
|
+
get sleep() {
|
|
888
|
+
return this.delay;
|
|
889
|
+
},
|
|
890
|
+
poll: async (stepId, conditionFn, options) => {
|
|
891
|
+
const intervalMs = parseDuration(options?.interval ?? "30s");
|
|
892
|
+
if (intervalMs < 30000) {
|
|
893
|
+
throw new WorkflowEngineError(`step.poll interval must be at least 30s (got ${intervalMs}ms)`, workflowId, runId);
|
|
894
|
+
}
|
|
895
|
+
const timeoutMs = options?.timeout ? parseDuration(options.timeout) : undefined;
|
|
896
|
+
return this.pollStep({ run, stepId, conditionFn, intervalMs, timeoutMs });
|
|
897
|
+
},
|
|
898
|
+
invokeChildWorkflow: async (stepId, refOrParams, inputArg, optionsArg) => {
|
|
899
|
+
const resolvedChildCall = this.resolveWorkflowRunParameters(refOrParams, inputArg, optionsArg);
|
|
900
|
+
const childWorkflowInvocation = {
|
|
901
|
+
run,
|
|
902
|
+
stepId,
|
|
903
|
+
workflowId: resolvedChildCall.workflowId,
|
|
904
|
+
input: resolvedChildCall.input,
|
|
905
|
+
options: resolvedChildCall.options,
|
|
906
|
+
resourceId: resolvedChildCall.resourceId,
|
|
907
|
+
idempotencyKey: resolvedChildCall.idempotencyKey
|
|
908
|
+
};
|
|
909
|
+
return this.invokeChildWorkflowStep(childWorkflowInvocation);
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
927
913
|
getCachedStepEntry(timeline, stepId) {
|
|
928
914
|
const stepEntry = timeline[stepId];
|
|
929
915
|
return stepEntry && typeof stepEntry === "object" && "output" in stepEntry ? stepEntry : null;
|
|
@@ -1014,7 +1000,7 @@ class WorkflowEngine {
|
|
|
1014
1000
|
});
|
|
1015
1001
|
return;
|
|
1016
1002
|
}
|
|
1017
|
-
const result = await this.
|
|
1003
|
+
const result = await this.createChildWorkflowRun({
|
|
1018
1004
|
workflowId,
|
|
1019
1005
|
input,
|
|
1020
1006
|
resourceId: childResourceId,
|
|
@@ -1580,5 +1566,5 @@ export {
|
|
|
1580
1566
|
WorkflowClient
|
|
1581
1567
|
};
|
|
1582
1568
|
|
|
1583
|
-
//# debugId=
|
|
1569
|
+
//# debugId=EE11F9509955D59264756E2164756E21
|
|
1584
1570
|
//# sourceMappingURL=index.js.map
|