@voltro/workflow 0.82.0 → 0.83.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/CHANGELOG.md +286 -0
- package/dist/{cluster-MboOAwcv.js → cluster-NnChVZoK.js} +9 -9
- package/dist/cluster.d.ts +7 -4
- package/dist/cluster.js +1 -1
- package/dist/{clusterDiagnostics-Dc7yBP3b.js → clusterDiagnostics-CGUtnJkX.js} +145 -130
- package/dist/clusterTestSuite.d.ts +1 -1
- package/dist/clusterTestSuite.js +2 -2
- package/dist/index.d.ts +17 -0
- package/dist/index.js +3 -3
- package/dist/{src-BAN5Xovf.js → src--sCbH8Fs.js} +656 -655
- package/package.json +4 -4
|
@@ -274,7 +274,7 @@ var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t)
|
|
|
274
274
|
if (t.handler === null || t.handler.length === 0) throw Error("Cannot queue an unconfigured failure handler");
|
|
275
275
|
if (!Number.isSafeInteger(n) || n < 0) throw Error("Failure handoff attempt exhausted");
|
|
276
276
|
if (!Number.isFinite(r)) throw Error("Failure handoff retry deadline is invalid");
|
|
277
|
-
let a = await
|
|
277
|
+
let a = await lt({
|
|
278
278
|
store: e,
|
|
279
279
|
workflowName: t.handler,
|
|
280
280
|
payload: Ee(t),
|
|
@@ -282,7 +282,7 @@ var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t)
|
|
|
282
282
|
tenantId: t.tenantId,
|
|
283
283
|
at: r,
|
|
284
284
|
now: i
|
|
285
|
-
}), o = await
|
|
285
|
+
}), o = await Ze(e, {
|
|
286
286
|
id: we(t.id, n),
|
|
287
287
|
workflowName: t.handler,
|
|
288
288
|
tenantId: t.tenantId,
|
|
@@ -522,7 +522,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
522
522
|
reused: !0
|
|
523
523
|
};
|
|
524
524
|
}
|
|
525
|
-
let r = ue(t.control, t.keyPayload), i = await
|
|
525
|
+
let r = ue(t.control, t.keyPayload), i = await St({
|
|
526
526
|
store: e,
|
|
527
527
|
control: t.control,
|
|
528
528
|
keys: r,
|
|
@@ -534,7 +534,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
534
534
|
kind: "not-admitted",
|
|
535
535
|
decision: i
|
|
536
536
|
};
|
|
537
|
-
let a = await
|
|
537
|
+
let a = await dt({
|
|
538
538
|
store: e,
|
|
539
539
|
control: t.control,
|
|
540
540
|
keys: r,
|
|
@@ -694,14 +694,20 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
694
694
|
let n = await D(e, t.failureId);
|
|
695
695
|
if (t.executionId !== null || t.dispatchAttempts > 1 || n === void 0 || n.sourceKind !== "submission" || n.sourceId !== t.id || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.report.executionId !== null || n.report.runId !== null) throw Error("Workflow start rejection has contradictory ownership or execution evidence");
|
|
696
696
|
return n.id;
|
|
697
|
-
}, N = "_voltro_workflow_start_receipts", qe =
|
|
697
|
+
}, N = "_voltro_workflow_start_receipts", qe = class extends Error {
|
|
698
|
+
_tag = "WorkflowStartRequestConflictError";
|
|
699
|
+
constructor() {
|
|
700
|
+
super("Workflow start request identity belongs to a different start"), this.name = "WorkflowStartRequestConflictError";
|
|
701
|
+
}
|
|
702
|
+
}, Je = c.Struct({
|
|
698
703
|
id: c.String,
|
|
699
704
|
workflowName: c.String,
|
|
700
705
|
tenantId: c.NullOr(c.String),
|
|
701
706
|
pendingId: c.String,
|
|
702
707
|
submissionId: c.NullOr(c.String),
|
|
703
|
-
terminal: c.NullOr(f)
|
|
704
|
-
|
|
708
|
+
terminal: c.NullOr(f),
|
|
709
|
+
requestFingerprint: c.optional(c.NullOr(c.String.pipe(c.pattern(/^[a-f0-9]{64}$/))))
|
|
710
|
+
}).pipe(c.filter((e) => e.submissionId === null || e.terminal === null, { message: () => "A start receipt cannot be both submitted and terminal before admission" })), P = c.decodeUnknownSync(Je), F = async (e, t) => {
|
|
705
711
|
let n = await e.query({
|
|
706
712
|
table: N,
|
|
707
713
|
predicate: h("id", t),
|
|
@@ -711,7 +717,14 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
711
717
|
projection: void 0
|
|
712
718
|
});
|
|
713
719
|
return n[0] === void 0 ? void 0 : P(n[0]);
|
|
714
|
-
},
|
|
720
|
+
}, Ye = async (e, t) => {
|
|
721
|
+
if (t.id.trim().length === 0 || !/^[a-f0-9]{64}$/.test(t.requestFingerprint)) throw Error("Workflow start request requires an identity and a SHA-256 fingerprint");
|
|
722
|
+
let n = await F(e, t.id);
|
|
723
|
+
if (n !== void 0) {
|
|
724
|
+
if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.requestFingerprint !== t.requestFingerprint) throw new qe();
|
|
725
|
+
return n;
|
|
726
|
+
}
|
|
727
|
+
}, Xe = async (e, t) => {
|
|
715
728
|
let n = await F(e, t.receiptId);
|
|
716
729
|
if (n === void 0 || n.workflowName !== t.workflowName || n.tenantId !== t.tenantId) throw Error("Workflow start receipt is missing or belongs to another workflow or tenant");
|
|
717
730
|
if (n.terminal !== null) {
|
|
@@ -754,16 +767,18 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
754
767
|
kind: "accepted",
|
|
755
768
|
executionId: r.executionId
|
|
756
769
|
};
|
|
757
|
-
},
|
|
770
|
+
}, Ze = async (e, t) => {
|
|
758
771
|
if (t.id.length === 0 || t.id === t.pendingId) throw Error("Workflow start receipt requires an identity distinct from its queue slot");
|
|
772
|
+
if (t.requestFingerprint != null && !/^[a-f0-9]{64}$/.test(t.requestFingerprint)) throw Error("Workflow start request requires a SHA-256 fingerprint");
|
|
759
773
|
let n = P((await e.insertIgnoreWithOutcome(N, {
|
|
760
774
|
...t,
|
|
775
|
+
requestFingerprint: t.requestFingerprint ?? null,
|
|
761
776
|
submissionId: null,
|
|
762
777
|
terminal: null
|
|
763
778
|
}, { conflictColumns: ["id"] })).row);
|
|
764
|
-
if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.pendingId !== t.pendingId) throw Error("Workflow start receipt identity belongs to a different start");
|
|
779
|
+
if (n.workflowName !== t.workflowName || n.tenantId !== t.tenantId || n.pendingId !== t.pendingId || (n.requestFingerprint ?? null) !== (t.requestFingerprint ?? null)) throw Error("Workflow start receipt identity belongs to a different start");
|
|
765
780
|
return n;
|
|
766
|
-
},
|
|
781
|
+
}, Qe = async (e, t) => {
|
|
767
782
|
let n = await M(e, t);
|
|
768
783
|
if (n === void 0) throw Error("Cannot bind receipts to an unknown admission submission");
|
|
769
784
|
if (n.receiptsBound) return 0;
|
|
@@ -790,7 +805,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
790
805
|
}
|
|
791
806
|
if (await e.update("_voltro_workflow_submissions", t, { receiptsBound: !0 }) === null) throw Error("Admission submission disappeared during receipt binding");
|
|
792
807
|
return r;
|
|
793
|
-
},
|
|
808
|
+
}, $e = async (e, t) => {
|
|
794
809
|
let n = c.decodeUnknownSync(f)(t.terminal);
|
|
795
810
|
for (;;) {
|
|
796
811
|
let r = await e.query({
|
|
@@ -811,7 +826,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
811
826
|
if (await e.update("_voltro_workflow_start_receipts", r.id, { terminal: n }) === null) throw Error("Start receipt disappeared while recording its terminal outcome");
|
|
812
827
|
}
|
|
813
828
|
}
|
|
814
|
-
}, I = "_voltro_workflow_pending", L = "_voltro_workflow_admissions", R = "_voltro_workflow_pauses", z = (e, t, n) => e.encodeWorkflowPayload === void 0 ? n : e.encodeWorkflowPayload(t, n),
|
|
829
|
+
}, I = "_voltro_workflow_pending", L = "_voltro_workflow_admissions", R = "_voltro_workflow_pauses", z = (e, t, n) => e.encodeWorkflowPayload === void 0 ? n : e.encodeWorkflowPayload(t, n), et = (e, t, n) => e.decodeWorkflowPayload === void 0 ? n : e.decodeWorkflowPayload(t, n), tt = 864e5, nt = (e, t, n) => `wfp_${ie("sha256").update(`${e}\u0000${t}\u0000${n}`).digest("hex").slice(0, 40)}`, B = (e) => {
|
|
815
830
|
if (e instanceof Date) return e.getTime();
|
|
816
831
|
if (typeof e == "number") return e;
|
|
817
832
|
let t = Date.parse(String(e));
|
|
@@ -844,10 +859,10 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
844
859
|
take: r,
|
|
845
860
|
skip: void 0,
|
|
846
861
|
projection: void 0
|
|
847
|
-
}),
|
|
862
|
+
}), rt = async (e) => {
|
|
848
863
|
let t = await e.query(U(R, void 0, [], 1e3));
|
|
849
864
|
return new Set(t.map((e) => String(e.id)));
|
|
850
|
-
},
|
|
865
|
+
}, it = async (e, t, n, r) => {
|
|
851
866
|
await e.upsert(R, {
|
|
852
867
|
id: t,
|
|
853
868
|
pausedAt: /* @__PURE__ */ new Date(),
|
|
@@ -861,7 +876,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
861
876
|
"reason"
|
|
862
877
|
]
|
|
863
878
|
});
|
|
864
|
-
},
|
|
879
|
+
}, at = async (e, t) => e.delete(R, t), ot = async (e) => {
|
|
865
880
|
let { store: t, control: n, keys: r, now: i } = e, a = { paused: e.paused }, o = [];
|
|
866
881
|
n.debounce !== void 0 && r.debounceKey !== void 0 && o.push((async () => {
|
|
867
882
|
let e = (await t.query(U(I, p(h("workflowName", n.workflowName), h("controlKey", r.debounceKey), h("mode", "debounce")), [], 1)))[0];
|
|
@@ -882,7 +897,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
882
897
|
firstSeenAt: B(e[0].firstSeenAt)
|
|
883
898
|
});
|
|
884
899
|
})()), n.singleton !== void 0 && r.singletonKey !== void 0 && o.push((async () => {
|
|
885
|
-
let e = await
|
|
900
|
+
let e = await st(t, n.workflowName, r.singletonKey, i);
|
|
886
901
|
e === "unacknowledged" ? a.singletonUnacknowledged = !0 : e !== void 0 && (a.singletonHolder = e);
|
|
887
902
|
})()), n.concurrency !== void 0 && r.concurrencyKey !== void 0 && o.push((async () => {
|
|
888
903
|
let e = n.concurrency.pool === void 0 ? [h("workflowName", n.workflowName)] : [], o = await t.query(U(L, p(...e, h("concurrencyKey", r.concurrencyKey), v("releasedAt"), te(v("executionId"), g("expiresAt", new Date(i)))), [], n.concurrency.limit));
|
|
@@ -896,7 +911,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
896
911
|
}], s.limit));
|
|
897
912
|
a.recentAdmissions = e.map((e) => B(e.admittedAt));
|
|
898
913
|
})()), await Promise.all(o), a;
|
|
899
|
-
},
|
|
914
|
+
}, st = async (e, t, n, r) => {
|
|
900
915
|
if ((await e.query(U("_voltro_workflow_admissions", p(h("workflowName", t), h("singletonKey", n), v("releasedAt"), v("executionId")), [], 1))).length > 0) return "unacknowledged";
|
|
901
916
|
let i = (await e.query(U(L, p(h("workflowName", t), h("singletonKey", n), v("releasedAt"), g("expiresAt", new Date(r))), [{
|
|
902
917
|
column: "admittedAt",
|
|
@@ -909,18 +924,18 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
909
924
|
runId: i.runId === null || i.runId === void 0 ? "" : String(i.runId),
|
|
910
925
|
admittedAt: B(i.admittedAt)
|
|
911
926
|
};
|
|
912
|
-
},
|
|
913
|
-
let { store: t, control: n, decision: r, now: i } = e, a =
|
|
927
|
+
}, ct = async (e) => {
|
|
928
|
+
let { store: t, control: n, decision: r, now: i } = e, a = ut(r.mode, r.keys);
|
|
914
929
|
if (r.collapse === "hold") {
|
|
915
|
-
let o = e.existingId ??
|
|
930
|
+
let o = e.existingId ?? nt(n.workflowName, r.mode, a);
|
|
916
931
|
return await t.update(I, o, {
|
|
917
932
|
dueAt: new Date(r.dueAt),
|
|
918
933
|
updatedAt: new Date(i)
|
|
919
934
|
}), o;
|
|
920
935
|
}
|
|
921
936
|
if (r.collapse === "replace") {
|
|
922
|
-
let o =
|
|
923
|
-
return await
|
|
937
|
+
let o = nt(n.workflowName, r.mode, a);
|
|
938
|
+
return await $e(t, {
|
|
924
939
|
pendingId: o,
|
|
925
940
|
workflowName: n.workflowName,
|
|
926
941
|
tenantId: e.tenantId,
|
|
@@ -986,7 +1001,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
986
1001
|
deadLetteredAt: null
|
|
987
1002
|
});
|
|
988
1003
|
return String(o.id);
|
|
989
|
-
},
|
|
1004
|
+
}, lt = async (e) => {
|
|
990
1005
|
let t = await e.store.insert(I, {
|
|
991
1006
|
id: `wfpi_${x()}`,
|
|
992
1007
|
tenantId: e.tenantId,
|
|
@@ -1011,7 +1026,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1011
1026
|
intentId: String(t.id),
|
|
1012
1027
|
dueAt: e.at
|
|
1013
1028
|
};
|
|
1014
|
-
},
|
|
1029
|
+
}, ut = (e, t) => {
|
|
1015
1030
|
switch (e) {
|
|
1016
1031
|
case "debounce": return t.debounceKey ?? "";
|
|
1017
1032
|
case "batch": return t.batchKey ?? "";
|
|
@@ -1020,7 +1035,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1020
1035
|
case "singleton": return t.singletonKey ?? "";
|
|
1021
1036
|
default: return "";
|
|
1022
1037
|
}
|
|
1023
|
-
},
|
|
1038
|
+
}, dt = async (e) => {
|
|
1024
1039
|
let { control: t, keys: n, now: r } = e, i = t.timeouts?.finishMs ?? 864e5, a = await e.store.insert(L, {
|
|
1025
1040
|
id: `wfad_${x()}`,
|
|
1026
1041
|
tenantId: e.tenantId,
|
|
@@ -1045,7 +1060,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1045
1060
|
releasedAt: e.outcome === "admitted" ? null : new Date(r)
|
|
1046
1061
|
});
|
|
1047
1062
|
return String(a.id);
|
|
1048
|
-
},
|
|
1063
|
+
}, ft = async (e, t, n) => {
|
|
1049
1064
|
let r = !1;
|
|
1050
1065
|
for (;;) {
|
|
1051
1066
|
let i = await e.query(U(L, p(h("executionId", t), h("outcome", "admitted"), v("releasedAt")), [], 10));
|
|
@@ -1053,7 +1068,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1053
1068
|
for (let t of i) if (await e.update("_voltro_workflow_admissions", String(t.id), { releasedAt: new Date(n) }) === null) throw Error("Admission lease disappeared during release");
|
|
1054
1069
|
r = !0;
|
|
1055
1070
|
}
|
|
1056
|
-
},
|
|
1071
|
+
}, pt = async (e, t, n) => (await mt(e, t, n)).due, mt = async (e, t, n) => {
|
|
1057
1072
|
let r = (await e.query(U(I, v("deadLetteredAt"), [{
|
|
1058
1073
|
column: "priority",
|
|
1059
1074
|
direction: "desc"
|
|
@@ -1066,10 +1081,10 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1066
1081
|
due: r.filter((e) => e.dueAt <= t).sort(ge),
|
|
1067
1082
|
nextDueAt: i
|
|
1068
1083
|
};
|
|
1069
|
-
},
|
|
1084
|
+
}, ht = async (e, t) => (await e.query(U(I, void 0, [{
|
|
1070
1085
|
column: "firstSeenAt",
|
|
1071
1086
|
direction: "asc"
|
|
1072
|
-
}], t))).map(H),
|
|
1087
|
+
}], t))).map(H), gt = async (e, t) => e.delete(I, t), _t = async (e, t, n, r) => C(e, (e) => vt(e, t, n, r)), vt = async (e, t, n, r) => {
|
|
1073
1088
|
let i = (await e.query(U(I, h("id", t), [], 1)))[0];
|
|
1074
1089
|
if (i === void 0) return !1;
|
|
1075
1090
|
let a = H(i);
|
|
@@ -1090,7 +1105,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1090
1105
|
admittedAt: new Date(r),
|
|
1091
1106
|
expiresAt: null,
|
|
1092
1107
|
releasedAt: new Date(r)
|
|
1093
|
-
}), await
|
|
1108
|
+
}), await $e(e, {
|
|
1094
1109
|
pendingId: t,
|
|
1095
1110
|
workflowName: a.workflowName,
|
|
1096
1111
|
tenantId: a.tenantId,
|
|
@@ -1103,7 +1118,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1103
1118
|
}, W = (e, t = Math.random) => {
|
|
1104
1119
|
let n = Math.min(1e3 * 2 ** Math.max(0, e - 1), 3e5);
|
|
1105
1120
|
return Math.round(n / 2 + t() * (n / 2));
|
|
1106
|
-
},
|
|
1121
|
+
}, yt = async (e, t, n, i) => {
|
|
1107
1122
|
let a = t.attempts + 1;
|
|
1108
1123
|
await e.update(I, t.id, {
|
|
1109
1124
|
attempts: a,
|
|
@@ -1111,12 +1126,12 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1111
1126
|
dueAt: new Date(i + W(a)),
|
|
1112
1127
|
updatedAt: new Date(i)
|
|
1113
1128
|
});
|
|
1114
|
-
},
|
|
1129
|
+
}, bt = async (e, t, n, i) => await e.update(I, t.id, {
|
|
1115
1130
|
attempts: t.attempts + 1,
|
|
1116
1131
|
lastError: r(t.workflowName, n.slice(0, 500)),
|
|
1117
1132
|
deadLetteredAt: new Date(i),
|
|
1118
1133
|
updatedAt: new Date(i)
|
|
1119
|
-
}) !== null,
|
|
1134
|
+
}) !== null, xt = async (e, t, n) => {
|
|
1120
1135
|
let r = (await e.query(U(I, h("id", t), [], 1)))[0];
|
|
1121
1136
|
return r === void 0 || r.deadLetteredAt === null || r.deadLetteredAt === void 0 ? !1 : await e.update(I, t, {
|
|
1122
1137
|
attempts: 0,
|
|
@@ -1125,8 +1140,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1125
1140
|
dueAt: new Date(n),
|
|
1126
1141
|
updatedAt: new Date(n)
|
|
1127
1142
|
}) !== null;
|
|
1128
|
-
},
|
|
1129
|
-
let t = await
|
|
1143
|
+
}, St = async (e) => {
|
|
1144
|
+
let t = await ot({
|
|
1130
1145
|
store: e.store,
|
|
1131
1146
|
control: e.control,
|
|
1132
1147
|
keys: e.keys,
|
|
@@ -1140,35 +1155,35 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1140
1155
|
now: e.now,
|
|
1141
1156
|
reconsidering: e.reconsidering
|
|
1142
1157
|
});
|
|
1143
|
-
},
|
|
1158
|
+
}, Ct = async (e, t, n = 1e3) => {
|
|
1144
1159
|
let r = await e.query(U(L, void 0, [{
|
|
1145
1160
|
column: "admittedAt",
|
|
1146
1161
|
direction: "asc"
|
|
1147
1162
|
}], n)), i = t.getTime(), a = r.filter((e) => e.releasedAt != null && B(e.admittedAt) < i);
|
|
1148
1163
|
return await Promise.all(a.map((t) => e.delete(L, String(t.id)))), a.length;
|
|
1149
|
-
}, G = "_voltro_workflow_control_requests", K = c.String.pipe(c.minLength(1)),
|
|
1164
|
+
}, G = "_voltro_workflow_control_requests", K = c.String.pipe(c.minLength(1)), wt = c.Struct({
|
|
1150
1165
|
kind: c.Literal("confirmed", "already-terminal"),
|
|
1151
1166
|
status: c.Literal("succeeded", "failed", "cancelled"),
|
|
1152
1167
|
completedAt: c.Number.pipe(c.finite()),
|
|
1153
1168
|
output: c.Unknown,
|
|
1154
1169
|
errorTag: c.NullOr(c.String),
|
|
1155
1170
|
errorMessage: c.NullOr(c.String)
|
|
1156
|
-
}),
|
|
1171
|
+
}), Tt = c.Struct({
|
|
1157
1172
|
kind: c.Literal("confirmed"),
|
|
1158
1173
|
status: c.Literal("running"),
|
|
1159
1174
|
enteredAt: c.Number.pipe(c.finite()),
|
|
1160
1175
|
generation: K
|
|
1161
|
-
}),
|
|
1176
|
+
}), Et = c.Union(wt, Tt), Dt = c.Struct({
|
|
1162
1177
|
reason: c.NonEmptyString,
|
|
1163
1178
|
detail: c.optional(c.Record({
|
|
1164
1179
|
key: c.String,
|
|
1165
1180
|
value: c.Unknown
|
|
1166
1181
|
}))
|
|
1167
|
-
}),
|
|
1182
|
+
}), Ot = c.Struct({ tenantId: c.NullOr(c.String) }), q = c.Struct({
|
|
1168
1183
|
requestId: c.String.pipe(c.pattern(/^[1-9]\d*$/)),
|
|
1169
1184
|
replyId: c.String.pipe(c.pattern(/^[1-9]\d*$/)),
|
|
1170
1185
|
restartToken: c.NullOr(c.NonEmptyString)
|
|
1171
|
-
}),
|
|
1186
|
+
}), kt = c.Struct({
|
|
1172
1187
|
id: K,
|
|
1173
1188
|
runId: K,
|
|
1174
1189
|
workflowName: K,
|
|
@@ -1176,21 +1191,21 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1176
1191
|
generation: K,
|
|
1177
1192
|
operation: c.Literal("cancel", "terminate", "resume"),
|
|
1178
1193
|
requestedAt: c.Number.pipe(c.finite()),
|
|
1179
|
-
owner: c.NullOr(
|
|
1180
|
-
cause: c.optional(c.NullOr(
|
|
1194
|
+
owner: c.NullOr(Ot),
|
|
1195
|
+
cause: c.optional(c.NullOr(Dt)),
|
|
1181
1196
|
dispatchAttempts: c.Number.pipe(c.int(), c.nonNegative()),
|
|
1182
1197
|
resumeJournal: c.NullOr(q),
|
|
1183
|
-
result: c.NullOr(
|
|
1184
|
-
}),
|
|
1185
|
-
...
|
|
1198
|
+
result: c.NullOr(Et)
|
|
1199
|
+
}), At = c.Struct({
|
|
1200
|
+
...kt.fields,
|
|
1186
1201
|
requestedAt: c.DateFromSelf
|
|
1187
1202
|
}), J = (e) => {
|
|
1188
|
-
let t = c.decodeUnknownSync(
|
|
1189
|
-
return c.decodeUnknownSync(
|
|
1203
|
+
let t = c.decodeUnknownSync(At)(e);
|
|
1204
|
+
return c.decodeUnknownSync(kt)({
|
|
1190
1205
|
...t,
|
|
1191
1206
|
requestedAt: t.requestedAt.getTime()
|
|
1192
1207
|
});
|
|
1193
|
-
},
|
|
1208
|
+
}, jt = async (e, t, n, r) => {
|
|
1194
1209
|
if (await e.update("_voltro_workflow_control_requests", t.id, { result: n }) === null) throw Error("Workflow control request disappeared during settlement");
|
|
1195
1210
|
await e.insert("_voltro_workflow_run_events", {
|
|
1196
1211
|
id: m("wfev", JSON.stringify(["control-settled", t.id])),
|
|
@@ -1211,7 +1226,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1211
1226
|
..."generation" in n ? { enteredGeneration: n.generation } : {}
|
|
1212
1227
|
}
|
|
1213
1228
|
});
|
|
1214
|
-
},
|
|
1229
|
+
}, Mt = async (e, t) => {
|
|
1215
1230
|
let n = [], r;
|
|
1216
1231
|
for (;;) {
|
|
1217
1232
|
let i = await e({
|
|
@@ -1232,21 +1247,21 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1232
1247
|
if (i.length < 100) return n;
|
|
1233
1248
|
r = J(i[i.length - 1]).id;
|
|
1234
1249
|
}
|
|
1235
|
-
},
|
|
1250
|
+
}, Nt = async (e, t) => (await Mt(e, t)).length > 0, Pt = (e, t) => Nt((t) => e.query({
|
|
1236
1251
|
...t,
|
|
1237
1252
|
lock: "update"
|
|
1238
|
-
}), t),
|
|
1253
|
+
}), t), Ft = {
|
|
1239
1254
|
source: "flow-control",
|
|
1240
1255
|
timeout: "finish"
|
|
1241
|
-
},
|
|
1256
|
+
}, It = c.Struct({
|
|
1242
1257
|
reason: c.NonEmptyString,
|
|
1243
1258
|
detail: c.Struct({
|
|
1244
1259
|
source: c.Literal("flow-control"),
|
|
1245
1260
|
timeout: c.Literal("finish"),
|
|
1246
1261
|
onFailure: c.NullOr(c.NonEmptyString)
|
|
1247
1262
|
})
|
|
1248
|
-
}),
|
|
1249
|
-
let t = c.decodeUnknownOption(
|
|
1263
|
+
}), Lt = (e) => {
|
|
1264
|
+
let t = c.decodeUnknownOption(It)(e.cause);
|
|
1250
1265
|
return t._tag === "Some" ? t.value : void 0;
|
|
1251
1266
|
}, Y = async (e, t) => {
|
|
1252
1267
|
let [n] = await e.query({
|
|
@@ -1259,7 +1274,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1259
1274
|
projection: void 0
|
|
1260
1275
|
});
|
|
1261
1276
|
if (n !== void 0) return J(n);
|
|
1262
|
-
},
|
|
1277
|
+
}, Rt = async (e, t) => {
|
|
1263
1278
|
let n;
|
|
1264
1279
|
for (;;) {
|
|
1265
1280
|
let r = await e.query({
|
|
@@ -1282,8 +1297,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1282
1297
|
}
|
|
1283
1298
|
if (r.length < 100) return !1;
|
|
1284
1299
|
}
|
|
1285
|
-
},
|
|
1286
|
-
let n = c.decodeUnknownSync(
|
|
1300
|
+
}, zt = async (e, t) => {
|
|
1301
|
+
let n = c.decodeUnknownSync(kt)({
|
|
1287
1302
|
...t,
|
|
1288
1303
|
owner: null,
|
|
1289
1304
|
cause: t.cause ?? null,
|
|
@@ -1307,12 +1322,12 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1307
1322
|
projection: void 0
|
|
1308
1323
|
});
|
|
1309
1324
|
if (a !== void 0 && (a.tag !== n.workflowName || a.executionId !== n.executionId)) throw Error("Workflow control target does not match its resident run");
|
|
1310
|
-
let o = c.decodeUnknownOption(
|
|
1325
|
+
let o = c.decodeUnknownOption(Ot)(a?.runnerGeneration === n.generation ? a.subject : void 0), s = {
|
|
1311
1326
|
...n,
|
|
1312
1327
|
owner: o._tag === "Some" ? o.value : null
|
|
1313
1328
|
}, l = a !== void 0 && a.runnerGeneration === n.generation && (a.status === "succeeded" || a.status === "failed" || a.status === "cancelled") ? {
|
|
1314
1329
|
...s,
|
|
1315
|
-
result: c.decodeUnknownSync(
|
|
1330
|
+
result: c.decodeUnknownSync(Et)({
|
|
1316
1331
|
kind: "already-terminal",
|
|
1317
1332
|
status: a.status,
|
|
1318
1333
|
completedAt: c.decodeUnknownSync(c.DateFromSelf)(a.completedAt).getTime(),
|
|
@@ -1325,8 +1340,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1325
1340
|
...l,
|
|
1326
1341
|
requestedAt: i,
|
|
1327
1342
|
parentClosureId: u
|
|
1328
|
-
}), l.result !== null && await
|
|
1329
|
-
},
|
|
1343
|
+
}), l.result !== null && await jt(e, l, l.result, n.requestedAt), l;
|
|
1344
|
+
}, Bt = async (e, t, n) => {
|
|
1330
1345
|
let r = await Y(e, t);
|
|
1331
1346
|
if (r === void 0) throw Error("Workflow control request is missing");
|
|
1332
1347
|
if (r.operation !== "resume") throw Error("Only resume controls can bind a suspension journal");
|
|
@@ -1394,7 +1409,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1394
1409
|
resumeJournal: s
|
|
1395
1410
|
}
|
|
1396
1411
|
};
|
|
1397
|
-
},
|
|
1412
|
+
}, Vt = async (e, t) => {
|
|
1398
1413
|
let n = await Y(e, t);
|
|
1399
1414
|
if (n === void 0) throw Error("Workflow control request is missing");
|
|
1400
1415
|
if (n.result !== null) return {
|
|
@@ -1435,7 +1450,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1435
1450
|
dispatchAttempts: i
|
|
1436
1451
|
}
|
|
1437
1452
|
};
|
|
1438
|
-
},
|
|
1453
|
+
}, Ht = async (e, n) => {
|
|
1439
1454
|
let a = n.owner, o;
|
|
1440
1455
|
for (;;) {
|
|
1441
1456
|
let s = await e.query({
|
|
@@ -1456,7 +1471,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1456
1471
|
if (s === void 0) throw Error("Workflow control request disappeared during completion");
|
|
1457
1472
|
if (s.result !== null) continue;
|
|
1458
1473
|
let l = n.outcome;
|
|
1459
|
-
await
|
|
1474
|
+
await jt(e, s, c.decodeUnknownSync(Et)({
|
|
1460
1475
|
kind: l.status === "cancelled" && s.operation !== "resume" ? "confirmed" : "already-terminal",
|
|
1461
1476
|
status: l.status,
|
|
1462
1477
|
completedAt: n.now,
|
|
@@ -1470,8 +1485,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1470
1485
|
if (typeof l.id != "string") throw Error("Workflow control cursor has an invalid identity");
|
|
1471
1486
|
o = l.id;
|
|
1472
1487
|
}
|
|
1473
|
-
},
|
|
1474
|
-
let i = c.decodeUnknownSync(
|
|
1488
|
+
}, Ut = async (e, t, n, r) => {
|
|
1489
|
+
let i = c.decodeUnknownSync(Tt)({
|
|
1475
1490
|
kind: "confirmed",
|
|
1476
1491
|
status: "running",
|
|
1477
1492
|
generation: n,
|
|
@@ -1494,14 +1509,14 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1494
1509
|
if (typeof t.id != "string") throw Error("Workflow control request has an invalid identity");
|
|
1495
1510
|
let n = await Y(e, t.id);
|
|
1496
1511
|
if (n === void 0) throw Error("Workflow control request disappeared during resume");
|
|
1497
|
-
n.result === null && await
|
|
1512
|
+
n.result === null && await jt(e, n, i, r);
|
|
1498
1513
|
}
|
|
1499
1514
|
if (n.length < 100) return;
|
|
1500
1515
|
let o = n[n.length - 1];
|
|
1501
1516
|
if (typeof o.id != "string") throw Error("Workflow control cursor has an invalid identity");
|
|
1502
1517
|
a = o.id;
|
|
1503
1518
|
}
|
|
1504
|
-
},
|
|
1519
|
+
}, Wt = "voltro-workflow-restart", Gt = class extends o.Tag("voltro/CurrentWorkflowDelivery")() {}, Kt = (e) => ({
|
|
1505
1520
|
...e,
|
|
1506
1521
|
registerEntity: (t, n, r) => e.registerEntity(t, t.type.startsWith("Workflow/") ? n.pipe(s.map((e) => {
|
|
1507
1522
|
let t = e.run;
|
|
@@ -1516,17 +1531,17 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1516
1531
|
return s.suspend(() => {
|
|
1517
1532
|
let n = t(e);
|
|
1518
1533
|
return s.isEffect(n) ? n : s.die(/* @__PURE__ */ Error("Workflow run handler must return an Effect"));
|
|
1519
|
-
}).pipe(s.provideService(
|
|
1534
|
+
}).pipe(s.provideService(Gt, n));
|
|
1520
1535
|
}
|
|
1521
1536
|
};
|
|
1522
1537
|
})) : n, r)
|
|
1523
|
-
}),
|
|
1538
|
+
}), qt = c.parseJson(c.Struct({
|
|
1524
1539
|
_tag: c.Literal("Success"),
|
|
1525
1540
|
value: c.Struct({ _tag: c.Literal("Suspended") })
|
|
1526
|
-
})),
|
|
1541
|
+
})), Jt = c.parseJson(c.Record({
|
|
1527
1542
|
key: c.String,
|
|
1528
1543
|
value: c.String
|
|
1529
|
-
})),
|
|
1544
|
+
})), Yt = (e) => s.gen(function* () {
|
|
1530
1545
|
if (!/^[1-9]\d*$/.test(e.requestId) || e.workflowName.length === 0 || e.executionId.length === 0) return yield* s.die(/* @__PURE__ */ Error("Suspension observation requires an exact engine delivery owner"));
|
|
1531
1546
|
let [t] = yield* (yield* S.SqlClient).withoutTransforms()`
|
|
1532
1547
|
SELECT m.entity_type, m.entity_id, m.tag, m.headers, r.id AS reply_id, r.payload
|
|
@@ -1535,13 +1550,13 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1535
1550
|
WHERE m.id = ${e.requestId} AND m.kind = 0`;
|
|
1536
1551
|
if (t === void 0) return;
|
|
1537
1552
|
if (t.entity_type !== `Workflow/${e.workflowName}` || t.entity_id !== e.executionId || t.tag !== "run") return yield* s.die(/* @__PURE__ */ Error("Suspension observation belongs to another execution or procedure"));
|
|
1538
|
-
if (((yield* s.sync(() => c.decodeUnknownSync(
|
|
1553
|
+
if (((yield* s.sync(() => c.decodeUnknownSync(Jt)(t.headers)))["voltro-workflow-restart"] ?? null) !== e.restartToken || t.reply_id === null || c.decodeUnknownOption(qt)(t.payload)._tag === "None") return;
|
|
1539
1554
|
let n = String(t.reply_id);
|
|
1540
1555
|
return /^[1-9]\d*$/.test(n) ? {
|
|
1541
1556
|
...e,
|
|
1542
1557
|
replyId: n
|
|
1543
1558
|
} : yield* s.die(/* @__PURE__ */ Error("Suspension reply has an invalid identity"));
|
|
1544
|
-
}).pipe(s.provideService(S.SafeIntegers, !0)),
|
|
1559
|
+
}).pipe(s.provideService(S.SafeIntegers, !0)), Xt = (e, t) => s.gen(function* () {
|
|
1545
1560
|
let { restart: n, suspension: r } = t, i = /* @__PURE__ */ new Map();
|
|
1546
1561
|
for (let t of e) {
|
|
1547
1562
|
if (!/^[1-9]\d*$/.test(t.requestId) || !/^[1-9]\d*$/.test(t.replyId)) return yield* s.die(/* @__PURE__ */ Error("Journal reset requires positive decimal request and reply identities"));
|
|
@@ -1616,14 +1631,14 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1616
1631
|
};
|
|
1617
1632
|
let i = yield* o`SELECT payload FROM ${u}
|
|
1618
1633
|
WHERE id = ${n} AND request_id = ${t} AND kind = 0`;
|
|
1619
|
-
if (i.length !== 1 || r !== void 0 && c.decodeUnknownOption(
|
|
1634
|
+
if (i.length !== 1 || r !== void 0 && c.decodeUnknownOption(qt)(i[0]?.payload)._tag === "None") return {
|
|
1620
1635
|
kind: "changed",
|
|
1621
1636
|
requestId: t
|
|
1622
1637
|
};
|
|
1623
1638
|
}
|
|
1624
1639
|
n !== void 0 && (yield* o`UPDATE ${l} SET headers = ${JSON.stringify({
|
|
1625
1640
|
...t,
|
|
1626
|
-
[
|
|
1641
|
+
[Wt]: n.token
|
|
1627
1642
|
})}
|
|
1628
1643
|
WHERE id = ${n.requestId}`);
|
|
1629
1644
|
for (let [e] of a) yield* o`DELETE FROM ${u} WHERE request_id = ${e} AND kind = 0`, yield* o`DELETE FROM ${l} WHERE request_id = ${e} AND kind = 2`, yield* o`UPDATE ${l} SET processed = ${d}, last_reply_id = NULL,
|
|
@@ -1633,7 +1648,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1633
1648
|
count: a.length
|
|
1634
1649
|
};
|
|
1635
1650
|
}).pipe(o.withTransaction, s.provideService(S.SafeIntegers, !0));
|
|
1636
|
-
}),
|
|
1651
|
+
}), Zt = (e, t) => Xt(e, t === void 0 ? {} : { restart: t }), Qt = (e) => Xt([e], { suspension: e }), X = ne("_voltro_workflow_restart_requests", {
|
|
1637
1652
|
id: _({ prefix: "wfrs" }),
|
|
1638
1653
|
runId: b(),
|
|
1639
1654
|
workflowName: b(),
|
|
@@ -1652,26 +1667,26 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1652
1667
|
}).unique(["runId", "generation"]).unique(["runId", "token"]).nonReactive(), Z = c.NonEmptyString, Q = c.Struct({
|
|
1653
1668
|
requestId: Z,
|
|
1654
1669
|
restartToken: c.NullOr(Z)
|
|
1655
|
-
}),
|
|
1670
|
+
}), $t = c.Struct({
|
|
1656
1671
|
requestId: Z,
|
|
1657
1672
|
replyId: Z
|
|
1658
|
-
}),
|
|
1673
|
+
}), $ = u, en = ne("_voltro_workflow_restart_withdrawals", {
|
|
1659
1674
|
id: _({ prefix: "wfrw" }),
|
|
1660
1675
|
runId: b(),
|
|
1661
1676
|
workflowName: b(),
|
|
1662
1677
|
tenantId: b().nullable(),
|
|
1663
1678
|
selection: y(),
|
|
1664
1679
|
withdrawnAt: re()
|
|
1665
|
-
}).nonReactive(),
|
|
1680
|
+
}).nonReactive(), tn = c.Struct({
|
|
1666
1681
|
id: c.NonEmptyString,
|
|
1667
1682
|
runId: c.NonEmptyString,
|
|
1668
1683
|
workflowName: c.NonEmptyString,
|
|
1669
1684
|
tenantId: c.NullOr(c.NonEmptyString),
|
|
1670
|
-
selection:
|
|
1685
|
+
selection: $,
|
|
1671
1686
|
withdrawnAt: c.DateFromSelf
|
|
1672
|
-
}),
|
|
1687
|
+
}), nn = async (e, t) => {
|
|
1673
1688
|
let n = c.decodeUnknownSync(d)(t), [r] = await e.query({
|
|
1674
|
-
table:
|
|
1689
|
+
table: en.tableName,
|
|
1675
1690
|
predicate: h("id", n.requestId),
|
|
1676
1691
|
lock: "update",
|
|
1677
1692
|
order: [],
|
|
@@ -1680,13 +1695,13 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1680
1695
|
projection: void 0
|
|
1681
1696
|
});
|
|
1682
1697
|
if (r === void 0) return;
|
|
1683
|
-
let i = c.decodeUnknownSync(
|
|
1698
|
+
let i = c.decodeUnknownSync(tn)(r);
|
|
1684
1699
|
if (i.runId !== n.runId) throw Error("Restart identity belongs to a different command");
|
|
1685
1700
|
if (!Number.isFinite(i.withdrawnAt.getTime())) throw Error("Invalid restart withdrawal timestamp");
|
|
1686
1701
|
return i;
|
|
1687
|
-
},
|
|
1688
|
-
if (await
|
|
1689
|
-
},
|
|
1702
|
+
}, rn = async (e, t) => {
|
|
1703
|
+
if (await nn(e, t) !== void 0) throw Error("Restart request was permanently withdrawn");
|
|
1704
|
+
}, an = c.Struct({
|
|
1690
1705
|
id: Z,
|
|
1691
1706
|
runId: Z,
|
|
1692
1707
|
workflowName: Z,
|
|
@@ -1696,8 +1711,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1696
1711
|
ledgerId: Z,
|
|
1697
1712
|
tenantId: c.NullOr(Z),
|
|
1698
1713
|
delivery: Q,
|
|
1699
|
-
replies: c.Array(
|
|
1700
|
-
selection:
|
|
1714
|
+
replies: c.Array($t),
|
|
1715
|
+
selection: $,
|
|
1701
1716
|
eviction: c.NullOr(c.Struct({
|
|
1702
1717
|
executionId: Z,
|
|
1703
1718
|
runId: c.String
|
|
@@ -1705,7 +1720,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1705
1720
|
requestedAt: c.DateFromSelf,
|
|
1706
1721
|
dispatchAttempts: c.NonNegativeInt,
|
|
1707
1722
|
enteredGeneration: c.NullOr(Z)
|
|
1708
|
-
}),
|
|
1723
|
+
}), on = (e, t) => e.kind === t.kind && (e.kind === "failed-steps" || t.kind === "from-step" && e.stepName === t.stepName), sn = async (e, t) => {
|
|
1709
1724
|
let n = c.decodeUnknownSync(d)(t), [r] = await e.query({
|
|
1710
1725
|
table: X.tableName,
|
|
1711
1726
|
predicate: h("id", n.requestId),
|
|
@@ -1716,11 +1731,11 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1716
1731
|
projection: void 0
|
|
1717
1732
|
});
|
|
1718
1733
|
if (r === void 0) return;
|
|
1719
|
-
let i = c.decodeUnknownSync(
|
|
1734
|
+
let i = c.decodeUnknownSync(an)(r);
|
|
1720
1735
|
if (i.runId !== n.runId) throw Error("Restart identity belongs to a different command");
|
|
1721
1736
|
return i;
|
|
1722
|
-
},
|
|
1723
|
-
let n = await
|
|
1737
|
+
}, cn = async (e, t) => {
|
|
1738
|
+
let n = await nn(e, t);
|
|
1724
1739
|
if (n !== void 0) return c.decodeUnknownSync(l)({
|
|
1725
1740
|
...t,
|
|
1726
1741
|
kind: "withdrawn",
|
|
@@ -1728,7 +1743,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1728
1743
|
selection: n.selection,
|
|
1729
1744
|
withdrawnAt: n.withdrawnAt.getTime()
|
|
1730
1745
|
});
|
|
1731
|
-
let r = await
|
|
1746
|
+
let r = await sn(e, t);
|
|
1732
1747
|
if (r === void 0) return c.decodeUnknownSync(l)({
|
|
1733
1748
|
...t,
|
|
1734
1749
|
kind: "not-found"
|
|
@@ -1751,7 +1766,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1751
1766
|
kind: "entered",
|
|
1752
1767
|
enteredGeneration: r.enteredGeneration
|
|
1753
1768
|
});
|
|
1754
|
-
},
|
|
1769
|
+
}, ln = async (e, t) => {
|
|
1755
1770
|
for (let e of [
|
|
1756
1771
|
t.id,
|
|
1757
1772
|
t.runId,
|
|
@@ -1759,21 +1774,21 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1759
1774
|
]) c.decodeUnknownSync(Z)(e);
|
|
1760
1775
|
if (t.id.length > 64) throw Error("Invalid restart request identity");
|
|
1761
1776
|
c.decodeUnknownSync(c.NullOr(Z))(t.tenantId);
|
|
1762
|
-
let n = c.decodeUnknownSync(
|
|
1763
|
-
await
|
|
1777
|
+
let n = c.decodeUnknownSync($)(t.selection);
|
|
1778
|
+
await rn(e, {
|
|
1764
1779
|
requestId: t.id,
|
|
1765
1780
|
runId: t.runId
|
|
1766
1781
|
});
|
|
1767
|
-
let r = await
|
|
1782
|
+
let r = await sn(e, {
|
|
1768
1783
|
requestId: t.id,
|
|
1769
1784
|
runId: t.runId
|
|
1770
1785
|
});
|
|
1771
1786
|
if (r !== void 0) {
|
|
1772
|
-
if (r.runId !== t.runId || r.workflowName !== t.workflowName || r.tenantId !== t.tenantId || !
|
|
1787
|
+
if (r.runId !== t.runId || r.workflowName !== t.workflowName || r.tenantId !== t.tenantId || !on(r.selection, n)) throw Error("Restart identity belongs to a different command");
|
|
1773
1788
|
return r;
|
|
1774
1789
|
}
|
|
1775
|
-
},
|
|
1776
|
-
let n = c.decodeUnknownSync(
|
|
1790
|
+
}, un = async (e, t) => {
|
|
1791
|
+
let n = c.decodeUnknownSync(tn)({
|
|
1777
1792
|
...t,
|
|
1778
1793
|
withdrawnAt: new Date(t.now)
|
|
1779
1794
|
});
|
|
@@ -1781,19 +1796,19 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1781
1796
|
requestId: n.id,
|
|
1782
1797
|
runId: n.runId
|
|
1783
1798
|
}), !Number.isFinite(n.withdrawnAt.getTime())) throw Error("Invalid restart withdrawal timestamp");
|
|
1784
|
-
let r = await
|
|
1799
|
+
let r = await nn(e, {
|
|
1785
1800
|
requestId: n.id,
|
|
1786
1801
|
runId: n.runId
|
|
1787
1802
|
});
|
|
1788
1803
|
if (r !== void 0) {
|
|
1789
|
-
if (r.workflowName !== n.workflowName || r.tenantId !== n.tenantId || !
|
|
1804
|
+
if (r.workflowName !== n.workflowName || r.tenantId !== n.tenantId || !on(r.selection, n.selection)) throw Error("Restart identity belongs to a different command");
|
|
1790
1805
|
return {
|
|
1791
1806
|
kind: "withdrawn",
|
|
1792
1807
|
withdrawal: r,
|
|
1793
1808
|
reused: !0
|
|
1794
1809
|
};
|
|
1795
1810
|
}
|
|
1796
|
-
let i = await
|
|
1811
|
+
let i = await ln(e, n);
|
|
1797
1812
|
if (i !== void 0) return {
|
|
1798
1813
|
kind: "reserved",
|
|
1799
1814
|
request: i
|
|
@@ -1809,17 +1824,17 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1809
1824
|
});
|
|
1810
1825
|
if (a === void 0 || a.tag !== n.workflowName) throw Error("Restart withdrawal requires its resident workflow");
|
|
1811
1826
|
if ((c.decodeUnknownSync(c.NullOr(c.Struct({ tenantId: c.NullOr(Z) })))(a.subject ?? null)?.tenantId ?? null) !== n.tenantId) throw Error("Restart withdrawal belongs to another resident tenant");
|
|
1812
|
-
return await e.insert(
|
|
1827
|
+
return await e.insert(en.tableName, n), {
|
|
1813
1828
|
kind: "withdrawn",
|
|
1814
1829
|
withdrawal: n,
|
|
1815
1830
|
reused: !1
|
|
1816
1831
|
};
|
|
1817
|
-
},
|
|
1832
|
+
}, dn = async (e, t) => {
|
|
1818
1833
|
c.decodeUnknownSync(Z)(t.generation);
|
|
1819
|
-
let n = await
|
|
1834
|
+
let n = await ln(e, t);
|
|
1820
1835
|
if (n !== void 0 && n.generation !== t.generation) throw Error("Restart identity belongs to a different command");
|
|
1821
1836
|
return n;
|
|
1822
|
-
},
|
|
1837
|
+
}, fn = async (e, t) => {
|
|
1823
1838
|
for (let e of [
|
|
1824
1839
|
t.id,
|
|
1825
1840
|
t.runId,
|
|
@@ -1827,13 +1842,13 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1827
1842
|
t.token
|
|
1828
1843
|
]) c.decodeUnknownSync(Z)(e);
|
|
1829
1844
|
if (t.id.length > 64 || !Number.isFinite(new Date(t.now).getTime())) throw Error("Invalid restart request identity or timestamp");
|
|
1830
|
-
await
|
|
1845
|
+
await rn(e, {
|
|
1831
1846
|
requestId: t.id,
|
|
1832
1847
|
runId: t.runId
|
|
1833
1848
|
});
|
|
1834
|
-
let n = c.decodeUnknownSync(Q)(t.delivery), r = c.decodeUnknownSync(
|
|
1849
|
+
let n = c.decodeUnknownSync(Q)(t.delivery), r = c.decodeUnknownSync($)(t.selection);
|
|
1835
1850
|
if (n.restartToken === t.token) throw Error("Restart requires a new delivery token");
|
|
1836
|
-
let i = c.decodeUnknownSync(c.Array(
|
|
1851
|
+
let i = c.decodeUnknownSync(c.Array($t))(t.replies), a = /* @__PURE__ */ new Map();
|
|
1837
1852
|
for (let e of i) {
|
|
1838
1853
|
if (!/^[1-9]\d*$/.test(e.requestId) || !/^[1-9]\d*$/.test(e.replyId) || a.has(e.requestId)) throw Error("Restart requires distinct, exact journal reply identities");
|
|
1839
1854
|
a.set(e.requestId, e.replyId);
|
|
@@ -1849,8 +1864,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1849
1864
|
projection: void 0
|
|
1850
1865
|
});
|
|
1851
1866
|
if (o !== void 0) {
|
|
1852
|
-
let e = c.decodeUnknownSync(
|
|
1853
|
-
if (e.runId !== t.runId || e.generation !== t.generation || e.token !== t.token || e.workflowName !== t.control.workflowName || e.tenantId !== t.tenantId || e.delivery.requestId !== n.requestId || e.delivery.restartToken !== n.restartToken || !
|
|
1867
|
+
let e = c.decodeUnknownSync(an)(o);
|
|
1868
|
+
if (e.runId !== t.runId || e.generation !== t.generation || e.token !== t.token || e.workflowName !== t.control.workflowName || e.tenantId !== t.tenantId || e.delivery.requestId !== n.requestId || e.delivery.restartToken !== n.restartToken || !on(e.selection, r) || e.replies.length !== a.size || e.replies.some((e) => a.get(e.requestId) !== e.replyId)) throw Error("Restart identity belongs to a different request");
|
|
1854
1869
|
return {
|
|
1855
1870
|
kind: "reserved",
|
|
1856
1871
|
request: e,
|
|
@@ -1883,7 +1898,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1883
1898
|
if (u.generation !== t.generation) throw Error("Restart delivery token was already used by this run");
|
|
1884
1899
|
return { kind: "already-requested" };
|
|
1885
1900
|
}
|
|
1886
|
-
let d =
|
|
1901
|
+
let d = et(e, t.control.workflowName, s.payload), f = ue(t.control, d), m = await St({
|
|
1887
1902
|
store: e,
|
|
1888
1903
|
control: t.control,
|
|
1889
1904
|
keys: f,
|
|
@@ -1895,7 +1910,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1895
1910
|
kind: "not-admitted",
|
|
1896
1911
|
decision: m
|
|
1897
1912
|
};
|
|
1898
|
-
let g = await
|
|
1913
|
+
let g = await dt({
|
|
1899
1914
|
store: e,
|
|
1900
1915
|
control: t.control,
|
|
1901
1916
|
keys: f,
|
|
@@ -1910,7 +1925,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1910
1925
|
now: t.now
|
|
1911
1926
|
});
|
|
1912
1927
|
if (g === void 0) throw Error("Restart has no admission reservation");
|
|
1913
|
-
let _ = c.decodeUnknownSync(
|
|
1928
|
+
let _ = c.decodeUnknownSync(an)({
|
|
1914
1929
|
id: t.id,
|
|
1915
1930
|
runId: t.runId,
|
|
1916
1931
|
workflowName: t.control.workflowName,
|
|
@@ -1932,7 +1947,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1932
1947
|
request: _,
|
|
1933
1948
|
reused: !1
|
|
1934
1949
|
};
|
|
1935
|
-
},
|
|
1950
|
+
}, pn = async (e, t) => {
|
|
1936
1951
|
let [n] = await e.query({
|
|
1937
1952
|
table: X.tableName,
|
|
1938
1953
|
predicate: h("id", t),
|
|
@@ -1943,7 +1958,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1943
1958
|
projection: void 0
|
|
1944
1959
|
});
|
|
1945
1960
|
if (n === void 0) throw Error("Restart dispatch has no resident request");
|
|
1946
|
-
let r = c.decodeUnknownSync(
|
|
1961
|
+
let r = c.decodeUnknownSync(an)(n);
|
|
1947
1962
|
if (r.enteredGeneration !== null) throw Error("Restart request has already entered its resident generation");
|
|
1948
1963
|
let [i] = await e.query({
|
|
1949
1964
|
table: "_voltro_workflow_admissions",
|
|
@@ -1971,26 +1986,26 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
1971
1986
|
request: r,
|
|
1972
1987
|
run: a
|
|
1973
1988
|
};
|
|
1974
|
-
},
|
|
1975
|
-
let { request: n } = await
|
|
1989
|
+
}, mn = async (e, t) => {
|
|
1990
|
+
let { request: n } = await pn(e, t), r = n.dispatchAttempts + 1;
|
|
1976
1991
|
if (!Number.isSafeInteger(r)) throw Error("Restart dispatch attempt counter exhausted");
|
|
1977
1992
|
if (await e.update(X.tableName, t, { dispatchAttempts: r }) === null) throw Error("Restart request disappeared before dispatch");
|
|
1978
1993
|
return {
|
|
1979
1994
|
...n,
|
|
1980
1995
|
dispatchAttempts: r
|
|
1981
1996
|
};
|
|
1982
|
-
},
|
|
1983
|
-
let { request: t } = yield* s.promise(() => e.transaction((t) =>
|
|
1997
|
+
}, hn = (e) => s.gen(function* () {
|
|
1998
|
+
let { request: t } = yield* s.promise(() => e.transaction((t) => pn(t, e.requestId)));
|
|
1984
1999
|
if (!(yield* s.promise(() => e.acquireCapacity(t)))) return { kind: "waiting-capacity" };
|
|
1985
|
-
let n = yield* s.promise(() => e.transaction((e) =>
|
|
1986
|
-
return yield*
|
|
2000
|
+
let n = yield* s.promise(() => e.transaction((e) => mn(e, t.id)));
|
|
2001
|
+
return yield* Zt(n.replies, {
|
|
1987
2002
|
requestId: n.delivery.requestId,
|
|
1988
2003
|
previousToken: n.delivery.restartToken,
|
|
1989
2004
|
token: n.token,
|
|
1990
2005
|
workflowName: n.workflowName,
|
|
1991
2006
|
executionId: n.executionId
|
|
1992
2007
|
});
|
|
1993
|
-
}),
|
|
2008
|
+
}), gn = async (e, t) => {
|
|
1994
2009
|
for (let e of [
|
|
1995
2010
|
t.runId,
|
|
1996
2011
|
t.workflowName,
|
|
@@ -2010,7 +2025,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
2010
2025
|
projection: ["id"]
|
|
2011
2026
|
});
|
|
2012
2027
|
if (r === void 0) throw Error("Restart delivery has no matching resident request");
|
|
2013
|
-
let { request: i, run: a } = await
|
|
2028
|
+
let { request: i, run: a } = await pn(e, c.decodeUnknownSync(Z)(r.id));
|
|
2014
2029
|
if (i.runId !== t.runId || i.workflowName !== t.workflowName || i.executionId !== t.executionId || i.generation === t.generation || i.delivery.requestId !== n.requestId || i.token !== n.restartToken) throw Error("Restart entry does not match its reserved delivery");
|
|
2015
2030
|
if (i.dispatchAttempts === 0) throw Error("Restart entry has no committed dispatch attempt");
|
|
2016
2031
|
if (await e.update("_voltro_workflow_admissions", i.ledgerId, {
|
|
@@ -2049,7 +2064,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
2049
2064
|
}
|
|
2050
2065
|
})
|
|
2051
2066
|
};
|
|
2052
|
-
},
|
|
2067
|
+
}, _n = 6e5, vn = class extends o.Tag("@voltro/workflow/ClusterDiagnostics")() {}, yn = (e, t, n = Date.now()) => s.flatMap(e.messagesFor(t), (t) => {
|
|
2053
2068
|
if (t.length === 0) return s.succeed(void 0);
|
|
2054
2069
|
let r = [...new Set(t.filter((e) => !e.processed).map((e) => e.shardId))], i = r.length === 0 ? s.succeed([]) : e.shardLockHolders(r);
|
|
2055
2070
|
return s.map(i, (r) => ({
|
|
@@ -2066,4 +2081,4 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
|
|
|
2066
2081
|
}));
|
|
2067
2082
|
});
|
|
2068
2083
|
//#endregion
|
|
2069
|
-
export {
|
|
2084
|
+
export { ft as $, L as A, Ae as At, pt as B, ge as Bt, Pt as C, ze as Ct, Y as D, Ge as Dt, Mt as E, Ie as Et, bt as F, Oe as Ft, it as G, le as Gt, St as H, he as Ht, et as I, E as It, ct as J, nt as K, ue as Kt, gt as L, D as Lt, R as M, O as Mt, I as N, Se as Nt, Ht as O, Le as Ot, ht as P, xe as Pt, dt as Q, _t as R, ve as Rt, Lt as S, Fe as St, Nt as T, M as Tt, yt as U, me as Ut, z as V, fe as Vt, lt as W, de as Wt, ot as X, Ct as Y, rt as Z, Kt as _, We as _t, ln as a, qe as at, Vt as b, Me as bt, fn as c, F as ct, X as d, Xe as dt, at as et, en as f, $e as ft, Wt as g, Ve as gt, Gt as h, Be as ht, gn as i, N as it, tt as j, k as jt, Ut as k, Re as kt, hn as l, Ye as lt, Qt as m, je as mt, vn as n, xt as nt, cn as o, Qe as ot, Yt as p, Ke as pt, mt as q, C as qt, yn as r, H as rt, dn as s, P as st, _n as t, W as tt, un as u, Ze as ut, Ft as v, Ne as vt, Rt as w, He as wt, Bt as x, Ue as xt, zt as y, Pe as yt, vt as z, ce as zt };
|