@voltro/workflow 0.85.0 → 0.86.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +666 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -33
  3. package/dist/admission.js +140 -0
  4. package/dist/admissionDrainer.js +705 -0
  5. package/dist/admissionGate.js +115 -0
  6. package/dist/admissionStore.js +347 -0
  7. package/dist/admissionSubmission.js +297 -0
  8. package/dist/admissionTables.js +137 -0
  9. package/dist/admissionTransaction.js +21 -0
  10. package/dist/awaitEvent.js +82 -0
  11. package/dist/budgetHold.js +136 -0
  12. package/dist/cancelOnPlan.js +75 -0
  13. package/dist/cancelOnSweep.js +188 -0
  14. package/dist/cancelPendingStart.js +50 -0
  15. package/dist/cluster.js +8 -2
  16. package/dist/clusterCron.js +11 -0
  17. package/dist/clusterDiagnostics.js +20 -0
  18. package/dist/clusterDiagnosticsSql.js +145 -0
  19. package/dist/clusterLayer.js +110 -0
  20. package/dist/clusterMigrationGate.js +61 -0
  21. package/dist/clusterRunnerLayer.js +21 -0
  22. package/dist/clusterTestSuite.js +101 -101
  23. package/dist/controlMonitor.js +13 -0
  24. package/dist/controlRequest.js +367 -0
  25. package/dist/executionRefusal.js +162 -0
  26. package/dist/failureHandoff.js +183 -0
  27. package/dist/failureMessage.js +12 -0
  28. package/dist/failureRecovery.js +50 -0
  29. package/dist/failureReportStore.js +60 -0
  30. package/dist/flowControl.js +142 -0
  31. package/dist/forwardStartReceipts.js +41 -0
  32. package/dist/inMemoryLayer.js +7 -0
  33. package/dist/inMemoryRecorder.js +56 -0
  34. package/dist/index.d.ts +82 -8
  35. package/dist/index.js +49 -5
  36. package/dist/inspectWorkflow.js +101 -0
  37. package/dist/{journalEncryption-DTyhUzaS.js → journalEncryption.js} +30 -37
  38. package/dist/messages.js +92 -0
  39. package/dist/nondeterminism.js +51 -0
  40. package/dist/parentClosure.js +141 -0
  41. package/dist/parentClosureRecovery.js +54 -0
  42. package/dist/pendingSubmission.js +85 -0
  43. package/dist/prepareSubmissionDispatch.js +17 -0
  44. package/dist/preparedExecution.js +14 -0
  45. package/dist/primitives.js +225 -2
  46. package/dist/queuedCancellationRequest.js +364 -0
  47. package/dist/queuedControl.js +21 -0
  48. package/dist/recorder.js +11 -0
  49. package/dist/residentExecutionEvidence.js +64 -0
  50. package/dist/retryPolicy.js +57 -0
  51. package/dist/runEventsTable.js +17 -0
  52. package/dist/runGeneration.js +345 -0
  53. package/dist/runRecording.js +615 -0
  54. package/dist/runStepsTable.js +28 -0
  55. package/dist/runnerStorageGuard.js +29 -0
  56. package/dist/runsTable.js +42 -0
  57. package/dist/scheduleDeclaration.js +44 -0
  58. package/dist/signalHint.js +23 -0
  59. package/dist/signals.js +70 -0
  60. package/dist/signalsSuspending.js +57 -0
  61. package/dist/sqliteWorkflowOwnership.js +26 -0
  62. package/dist/stalenessSweep.js +191 -0
  63. package/dist/startContextsTable.js +20 -0
  64. package/dist/startReceipt.js +143 -0
  65. package/dist/submissionRecovery.js +122 -0
  66. package/dist/submissionRejection.js +10 -0
  67. package/dist/submissionRetry.js +71 -0
  68. package/dist/suspensionUnavailable.js +9 -0
  69. package/dist/updates.js +87 -0
  70. package/dist/watermarkTable.js +9 -0
  71. package/dist/webCrypto.js +17 -0
  72. package/dist/workflowDelivery.js +24 -0
  73. package/dist/workflowJournal.js +124 -0
  74. package/dist/workflowJournalReset.js +111 -0
  75. package/dist/workflowReadSelections.js +12 -0
  76. package/dist/workflowRestartDispatch.js +29 -0
  77. package/dist/workflowRestartObservation.js +60 -0
  78. package/dist/workflowRestartPreparation.js +109 -0
  79. package/dist/workflowRestartReservation.js +426 -0
  80. package/dist/workflowResumeDispatch.js +29 -0
  81. package/package.json +4 -4
  82. package/dist/cluster-F_bhqVP7.js +0 -679
  83. package/dist/primitives-DX04WTWh.js +0 -507
  84. package/dist/src-C2NEyUM8.js +0 -3925
  85. package/dist/workflowReadSelections-CZAUjP7f.js +0 -2096
@@ -0,0 +1,141 @@
1
+ import { acceptWorkflowControlInTransaction as e, hasUnsettledParentClosureControls as t, readWorkflowControlInTransaction as n } from "./controlRequest.js";
2
+ import { cancelSuspendedWorkflowRunInTransaction as r } from "./runGeneration.js";
3
+ import { Schema as i } from "effect";
4
+ import { and as a, derivedRowId as o, eq as s, gt as c } from "@voltro/database";
5
+ //#region src/parentClosure.ts
6
+ var l = "_voltro_workflow_parent_closures", u = i.NonEmptyString, d = i.Struct({
7
+ id: u,
8
+ runId: u,
9
+ workflowName: u,
10
+ executionId: u,
11
+ generation: u,
12
+ parentStatus: i.Literals([
13
+ "succeeded",
14
+ "failed",
15
+ "cancelled"
16
+ ]),
17
+ closedAt: i.Date,
18
+ afterChildId: i.NullOr(u),
19
+ scanHasOpenChildren: i.Boolean,
20
+ completedAt: i.NullOr(i.Date)
21
+ }), f = i.Struct({
22
+ id: u,
23
+ tag: u,
24
+ executionId: u,
25
+ status: i.Literals([
26
+ "running",
27
+ "suspended",
28
+ "succeeded",
29
+ "failed",
30
+ "cancelled"
31
+ ]),
32
+ runnerGeneration: i.optional(i.NullOr(u)),
33
+ parentGeneration: i.optional(i.NullOr(u)),
34
+ parentClosePolicy: i.NullOr(i.Literals([
35
+ "cancel",
36
+ "terminate",
37
+ "abandon"
38
+ ]))
39
+ }), p = async (t, r, c) => {
40
+ if (r.parentClosePolicy !== "cancel" && r.parentClosePolicy !== "terminate") return !1;
41
+ if (typeof r.parentExecutionId != "string" || r.parentExecutionId.length === 0 || typeof r.parentGeneration != "string" || r.parentGeneration.length === 0) throw Error("Child entry requires its original parent execution and generation");
42
+ let u = c ?? (await t.query({
43
+ table: l,
44
+ predicate: a(s("executionId", r.parentExecutionId), s("generation", r.parentGeneration)),
45
+ lock: "update",
46
+ order: [],
47
+ take: 1,
48
+ skip: void 0,
49
+ projection: void 0
50
+ }))[0];
51
+ if (u === void 0) return !1;
52
+ let p = i.decodeUnknownSync(d)(u);
53
+ if (p.executionId !== r.parentExecutionId || p.generation !== r.parentGeneration) return !1;
54
+ let m = i.decodeUnknownSync(f)(r), h = o("wfctl", JSON.stringify([
55
+ "parent-close",
56
+ p.id,
57
+ m.id
58
+ ])), g = await n(t, h);
59
+ if (g !== void 0) {
60
+ if (g.runId !== m.id || g.workflowName !== m.tag || g.executionId !== m.executionId || g.operation === "resume" || g.cause?.reason !== "parent-close" || g.cause.detail?.closureId !== p.id) throw Error("Parent closure receipt belongs to another child");
61
+ } else {
62
+ if (m.status !== "running" && m.status !== "suspended") return !1;
63
+ if (m.runnerGeneration === void 0 || m.runnerGeneration === null) throw Error("Child entry requires its own generation");
64
+ await e(t, {
65
+ id: h,
66
+ runId: m.id,
67
+ workflowName: m.tag,
68
+ executionId: m.executionId,
69
+ generation: m.runnerGeneration,
70
+ operation: r.parentClosePolicy,
71
+ requestedAt: p.closedAt.getTime(),
72
+ cause: {
73
+ reason: "parent-close",
74
+ detail: {
75
+ closureId: p.id,
76
+ parentRunId: p.runId,
77
+ parentExecutionId: p.executionId,
78
+ parentGeneration: p.generation,
79
+ parentStatus: p.parentStatus,
80
+ parentClosePolicy: r.parentClosePolicy
81
+ }
82
+ }
83
+ });
84
+ }
85
+ return !0;
86
+ }, m = async (e, n, o = Date.now()) => {
87
+ let [u] = await e.query({
88
+ table: l,
89
+ predicate: s("id", n),
90
+ lock: "update",
91
+ order: [],
92
+ take: 1,
93
+ skip: void 0,
94
+ projection: void 0
95
+ });
96
+ if (u === void 0) throw Error("Parent closure is missing");
97
+ let m = i.decodeUnknownSync(d)(u);
98
+ if (m.completedAt !== null) return {
99
+ scanned: 0,
100
+ controls: 0,
101
+ wrapped: !1
102
+ };
103
+ if (!Number.isFinite(o)) throw Error("Parent closure requires a finite completion timestamp");
104
+ let h = await e.query({
105
+ table: "_voltro_workflow_runs",
106
+ predicate: a(s("parentExecutionId", m.executionId), ...m.afterChildId === null ? [] : [c("id", m.afterChildId)]),
107
+ lock: "update",
108
+ order: [{
109
+ column: "id",
110
+ direction: "asc"
111
+ }],
112
+ take: 100,
113
+ skip: void 0,
114
+ projection: void 0
115
+ }), g = 0, _ = m.scanHasOpenChildren, v = null;
116
+ for (let t of h) {
117
+ let n = i.decodeUnknownSync(f)(t);
118
+ if (v = n.id, n.parentClosePolicy !== null && n.parentClosePolicy !== "abandon") {
119
+ if (n.parentGeneration === void 0 || n.parentGeneration === null) throw Error("Parent closure cannot attribute a child without its parent generation");
120
+ n.parentGeneration === m.generation && ((n.status === "running" || n.status === "suspended") && (_ = !0), await p(e, t, m) && (g++, n.status === "suspended" && typeof n.runnerGeneration == "string" && await r(e, {
121
+ runId: n.id,
122
+ workflowName: n.tag,
123
+ executionId: n.executionId,
124
+ generation: n.runnerGeneration
125
+ }, o)));
126
+ }
127
+ }
128
+ let y = h.length < 100, b = y && !_ && !await t(e, m.id);
129
+ if (await e.update(l, m.id, {
130
+ afterChildId: y ? null : v,
131
+ scanHasOpenChildren: !y && _,
132
+ completedAt: b ? new Date(o) : null
133
+ }) === null) throw Error("Parent closure disappeared before saving its cursor");
134
+ return {
135
+ scanned: h.length,
136
+ controls: g,
137
+ wrapped: y
138
+ };
139
+ };
140
+ //#endregion
141
+ export { p as stageParentClosureAtChildEntry, m as stageWorkflowParentClosureInTransaction };
@@ -0,0 +1,54 @@
1
+ import { stageWorkflowParentClosureInTransaction as e } from "./parentClosure.js";
2
+ import { and as t, eq as n, gt as r, isNull as i } from "@voltro/database";
3
+ //#region src/parentClosureRecovery.ts
4
+ var a = "_voltro_workflow_parent_closures", o = /* @__PURE__ */ new WeakMap(), s = async (s, c, l) => {
5
+ let u = o.get(s), d = await s.store.query({
6
+ table: a,
7
+ predicate: t(i("completedAt"), ...u === void 0 ? [] : [r("id", u.afterId)]),
8
+ order: [{
9
+ column: "id",
10
+ direction: "asc"
11
+ }],
12
+ take: l,
13
+ skip: void 0,
14
+ projection: void 0
15
+ }), f = 0, p = u?.nextDueAt, m = () => {
16
+ p = Math.min(p ?? c + 1e3, c + 1e3);
17
+ };
18
+ for (let t of d) try {
19
+ if (typeof t.id != "string" || t.id.length === 0) throw Error("Parent closure has no identity");
20
+ let r = t.id;
21
+ await s.transaction(async (t) => {
22
+ await e(t, r, c);
23
+ let [i] = await t.query({
24
+ table: a,
25
+ predicate: n("id", r),
26
+ order: [],
27
+ take: 1,
28
+ skip: void 0,
29
+ projection: ["completedAt"]
30
+ });
31
+ if (i === void 0) throw Error("Parent closure disappeared");
32
+ return i.completedAt instanceof Date && Number.isFinite(i.completedAt.getTime());
33
+ }) || m();
34
+ } catch {
35
+ f++, m(), s.log?.warn?.("workflow parent closure could not be reconciled", { closureId: typeof t.id == "string" ? t.id : null });
36
+ }
37
+ let h = d.at(-1);
38
+ return d.length === l && typeof h?.id == "string" ? (o.set(s, {
39
+ afterId: h.id,
40
+ nextDueAt: p
41
+ }), {
42
+ scanned: d.length,
43
+ failed: f,
44
+ nextDueAt: c,
45
+ examined: !0
46
+ }) : (o.delete(s), {
47
+ scanned: d.length,
48
+ failed: f,
49
+ nextDueAt: p,
50
+ examined: d.length > 0
51
+ });
52
+ };
53
+ //#endregion
54
+ export { s as recoverWorkflowParentClosures };
@@ -0,0 +1,85 @@
1
+ import { withAdmissionTransaction as e } from "./admissionTransaction.js";
2
+ import { persistReservedSubmission as t, readAdmissionSubmission as n, reserveAdmissionSubmissionInTransaction as r } from "./admissionSubmission.js";
3
+ import { bindWorkflowStartReceipts as i } from "./startReceipt.js";
4
+ import { PENDING_TABLE as a, toPendingIntent as o } from "./admissionStore.js";
5
+ import { eq as s } from "@voltro/database";
6
+ //#region src/pendingSubmission.ts
7
+ var c = async (e, r) => {
8
+ if (new Set(r.intentIds).size !== r.intentIds.length) throw Error("Admitted transfer requires distinct pending identities");
9
+ let c = await n(e, r.id);
10
+ if (c !== void 0) {
11
+ if (c.workflowName !== r.workflowName || c.tenantId !== r.tenantId || c.ledgerId !== r.ledgerId || !c.receiptsBound) throw Error("Admitted transfer contradicts its existing submission");
12
+ return c;
13
+ }
14
+ for (let t of r.intentIds) {
15
+ let n = await e.query({
16
+ table: a,
17
+ predicate: s("id", t),
18
+ order: [],
19
+ take: 1,
20
+ skip: void 0,
21
+ projection: void 0,
22
+ lock: "update"
23
+ });
24
+ if (n[0] === void 0) throw Error("Admitted transfer lost a selected input");
25
+ let i = o(n[0]);
26
+ if (i.workflowName !== r.workflowName || i.tenantId !== r.tenantId || i.deadLetteredAt !== void 0) throw Error("Admitted transfer selected a foreign or dead-lettered input");
27
+ }
28
+ let l = await t(e, r);
29
+ await i(e, l.id);
30
+ for (let t of l.intentIds) if (!await e.delete("_voltro_workflow_pending", t)) throw Error("Admitted input disappeared during submission transfer");
31
+ return {
32
+ ...l,
33
+ receiptsBound: !0
34
+ };
35
+ }, l = async (t, n) => e(t, (e) => u(e, n)), u = async (e, t) => {
36
+ if (t.id.length === 0 || t.intentIds.length === 0 || new Set(t.intentIds).size !== t.intentIds.length) throw Error("Queue transfer requires a submission identity and distinct pending identities");
37
+ let c = await n(e, t.id);
38
+ if (c !== void 0) {
39
+ if (c.workflowName !== t.workflowName || c.tenantId !== t.tenantId) throw Error("Admission submission identity belongs to a different workflow or tenant");
40
+ if (!c.receiptsBound) throw Error("Submission exists without completed queue transfer");
41
+ return {
42
+ kind: "reserved",
43
+ submission: c,
44
+ reused: !0
45
+ };
46
+ }
47
+ let l = [];
48
+ for (let n of t.intentIds) {
49
+ let r = await e.query({
50
+ table: a,
51
+ predicate: s("id", n),
52
+ order: [],
53
+ take: 1,
54
+ skip: void 0,
55
+ projection: void 0,
56
+ lock: "update"
57
+ });
58
+ if (r[0] === void 0) return { kind: "selection-unavailable" };
59
+ let i = o(r[0]);
60
+ if (i.workflowName !== t.workflowName || i.tenantId !== t.tenantId) throw Error("Selected pending start belongs to a different workflow or tenant");
61
+ if (i.deadLetteredAt !== void 0 || i.dueAt > t.now) return { kind: "selection-unavailable" };
62
+ l.push(i);
63
+ }
64
+ let u = t.prepare(l);
65
+ if (u.control.workflowName !== t.workflowName) throw Error("Prepared submission belongs to a different workflow");
66
+ let d = await r(e, {
67
+ ...u,
68
+ id: t.id,
69
+ tenantId: t.tenantId,
70
+ intentIds: t.intentIds,
71
+ now: t.now
72
+ });
73
+ if (d.kind !== "reserved") return d;
74
+ await i(e, t.id);
75
+ for (let t of l) if (!await e.delete("_voltro_workflow_pending", t.id)) throw Error("Pending start disappeared during queue transfer");
76
+ return {
77
+ ...d,
78
+ submission: {
79
+ ...d.submission,
80
+ receiptsBound: !0
81
+ }
82
+ };
83
+ };
84
+ //#endregion
85
+ export { c as takeAdmittedSubmissionInTransaction, l as takePendingAdmissionSubmission, u as takePendingAdmissionSubmissionInTransaction };
@@ -0,0 +1,17 @@
1
+ import { prepareAdmissionSubmissionExecutionInTransaction as e, readAdmissionSubmission as t } from "./admissionSubmission.js";
2
+ //#region src/prepareSubmissionDispatch.ts
3
+ var n = async (n, r, i) => {
4
+ let a = await n.transaction((e) => t(e, r.id));
5
+ if (a === void 0 || a.workflowName !== r.workflowName || a.tenantId !== r.tenantId || a.ledgerId !== r.ledgerId) throw Error("Submission dispatch lost its resident owner");
6
+ if (!a.receiptsBound || a.failureId !== null) throw Error("Cannot dispatch an incomplete or rejected submission");
7
+ if (a.preparedExecutionId !== null) {
8
+ if (a.executionId !== null && a.executionId !== a.preparedExecutionId) throw Error("Submission acceptance contradicts its prepared identity");
9
+ return a.preparedExecutionId;
10
+ }
11
+ if (a.dispatchAttempts !== 0 || a.executionId !== null) throw Error("Submission has an unbound prior dispatch; reconciliation required");
12
+ let o = await n.resolveExecutionId(r.workflowName, i), s = await n.transaction((t) => e(t, r.id, o));
13
+ if (s.preparedExecutionId === null) throw Error("Submission preparation returned no execution identity");
14
+ return s.preparedExecutionId;
15
+ };
16
+ //#endregion
17
+ export { n as prepareSubmissionDispatch };
@@ -0,0 +1,14 @@
1
+ import { Effect as e } from "effect";
2
+ //#region src/preparedExecution.ts
3
+ var t = Symbol.for("@voltro/workflow/PreparedExecution"), n = (e, n) => {
4
+ Object.defineProperty(e, t, {
5
+ value: n,
6
+ enumerable: !0
7
+ });
8
+ }, r = (e) => (typeof e == "object" || typeof e == "function") && e !== null && typeof e[t] == "function", i = (n, r, i, a) => e.suspend(() => {
9
+ if (i.length === 0) return e.die(/* @__PURE__ */ Error("Prepared workflow execution requires a non-empty identity"));
10
+ let o = n[t];
11
+ return typeof o == "function" ? o(r, i, a?.discard ?? !0) : e.die(/* @__PURE__ */ Error("Workflow definition has no prepared-execution capability"));
12
+ });
13
+ //#endregion
14
+ export { n as attachPreparedWorkflowExecution, i as executePreparedWorkflow, r as hasPreparedWorkflowExecution };
@@ -1,2 +1,225 @@
1
- import { A as e, C as t, D as n, E as r, G as i, J as a, K as o, O as s, S as c, T as l, U as u, W as d, _ as f, a as p, b as m, c as h, d as g, f as _, g as v, h as y, i as b, j as x, k as S, l as C, m as w, n as T, o as E, p as D, q as O, r as k, s as A, t as j, u as M, v as N, w as P, x as F, y as I } from "./primitives-DX04WTWh.js";
2
- export { P as CurrentWorkflowReplayShape, s as DEFAULT_WORKFLOW_SCHEDULE_MAX_RUNTIME_MS, u as DEFERRING_CONTROLS, j as WorkflowFlowControlProperty, T as WorkflowMessagesProperty, S as WorkflowScheduleProperty, k as WorkflowVersionTypeId, b as WorkflowWorkerLayerTypeId, d as assertConsistentPools, i as deferringControlsOf, p as durableClock, E as durableQueue, A as durableQueueModule, h as getWorkflowFlowControl, e as getWorkflowSchedule, C as getWorkflowVersionMetadata, o as hasCancelOn, O as hasFlowControl, M as isCarrier, g as isWorkflowWorkerLayer, l as makeReplayShapeTracker, r as nondeterminismEventPayload, _ as patch, D as processQueue, w as queueWorker, y as rateLimit, n as reportNondeterminism, v as sleep, f as sleepUntil, N as step, I as stepIdempotencyKey, m as stepModule, a as validateFlowControl, x as validateWorkflowSchedule, F as withCompensation, c as workflow, t as workflowModule };
1
+ import { failureMessage as e } from "./failureMessage.js";
2
+ import { attachPreparedWorkflowExecution as t } from "./preparedExecution.js";
3
+ import { CurrentWorkflowEncrypted as n, isQueueEncrypted as r, markQueueEncrypted as i, markWorkflowEncrypted as a, openDefect as o, sealDefect as s, sealedPayloadFields as c, sealedSchema as l } from "./journalEncryption.js";
4
+ import { DEFERRING_CONTROLS as u, assertConsistentPools as d, deferringControlsOf as f, hasCancelOn as p, hasFlowControl as m, validateFlowControl as h } from "./flowControl.js";
5
+ import { CurrentWorkflowPatches as g, CurrentWorkflowRunId as _, CurrentWorkflowStep as v, CurrentWorkflowWakeTenant as ee, WorkflowRunRecorder as y, WorkflowStepInterceptorTag as b } from "./recorder.js";
6
+ import { DEFAULT_WORKFLOW_SCHEDULE_MAX_RUNTIME_MS as x, WorkflowScheduleProperty as S, getWorkflowSchedule as C, validateWorkflowSchedule as w } from "./scheduleDeclaration.js";
7
+ import { CurrentWorkflowReplayShape as T, makeReplayShapeTracker as E, nondeterminismEventPayload as D, reportNondeterminism as O } from "./nondeterminism.js";
8
+ import { applyRetryPolicy as k } from "./retryPolicy.js";
9
+ import { Activity as A, Activity as j, DurableClock as M, DurableClock as N, DurableQueue as P, DurableQueue as te, Workflow as F, Workflow as ne, WorkflowEngine as I } from "effect/workflow";
10
+ import { RateLimiter as L } from "effect/persistence";
11
+ import { Cause as R, Duration as z, Effect as B, Effectable as V, Schema as H } from "effect";
12
+ import { attachWorkflowAccess as U, resolveWorkflowAccess as W } from "@voltro/protocol";
13
+ //#region src/primitives.ts
14
+ var G = Symbol.for("voltro.workflow.workerLayer"), K = Symbol.for("voltro.workflow.version"), q = "__voltroWorkflowMessages", J = "__voltroWorkflowFlowControl", Y = (e) => typeof e == "object" && !!e && e[G] === !0, X = (e) => (typeof e == "object" || typeof e == "function") && e !== null, re = (e) => X(e) && e[K] !== void 0 ? e[K] : {
15
+ version: "1",
16
+ compatibleWith: ["1"],
17
+ patches: []
18
+ }, Z = (e) => {
19
+ let t = e, r = `workflow '${e.name}' defect`;
20
+ return Object.assign(Object.create(Object.getPrototypeOf(e)), e, {
21
+ toLayer: (e) => t.toLayer((t, i) => B.provideService(e(t, i), n, !0).pipe(B.catchDefect((e) => B.die(s(e, r))))),
22
+ execute: (...e) => t.execute(...e).pipe(B.catchDefect((e) => B.die(o(e, r)))),
23
+ annotate: (...e) => Z(t.annotate(...e)),
24
+ annotateContext: (...e) => Z(t.annotateContext(...e))
25
+ });
26
+ }, ie = ((e) => {
27
+ let n = e.encrypted === !0, r = F.make(e.name, n ? {
28
+ ...e,
29
+ payload: c(e.name, e.payload),
30
+ ...e.success === void 0 ? {} : { success: l(e.success, `workflow '${e.name}' result`) },
31
+ ...e.error === void 0 ? {} : { error: l(e.error, `workflow '${e.name}' failure`) }
32
+ } : e);
33
+ n && a(e.name);
34
+ let i = e.suspendOnFailure === !0 ? r.annotate(F.SuspendOnFailure, !0) : r, o = n ? Z(i) : i;
35
+ Object.defineProperty(o, "name", {
36
+ value: e.name,
37
+ enumerable: !0
38
+ }), t(o, (t, n, r) => B.gen(function* () {
39
+ let i = o.payloadSchema.make(t), a = yield* I.WorkflowEngine;
40
+ return yield* B.annotateCurrentSpan({ executionId: n }), yield* a.execute(o, {
41
+ executionId: n,
42
+ payload: i,
43
+ discard: r,
44
+ suspendedRetrySchedule: e.suspendedRetrySchedule
45
+ });
46
+ }).pipe(B.withSpan(`${e.name}.execute`)));
47
+ let s = String(e.version ?? "1"), u = {
48
+ version: s,
49
+ compatibleWith: (e.compatibleWith ?? [s]).map(String),
50
+ patches: [...e.patches ?? []]
51
+ }, d = {
52
+ signals: { ...e.messages?.signals ?? {} },
53
+ updates: { ...e.messages?.updates ?? {} }
54
+ };
55
+ Object.defineProperty(o, K, {
56
+ value: u,
57
+ enumerable: !1
58
+ }), Object.defineProperty(o, q, {
59
+ value: d,
60
+ enumerable: !1
61
+ }), U(o, W(e.name, e));
62
+ let f = h({
63
+ workflowName: e.name,
64
+ payloadSchema: H.isSchema(e.payload) ? e.payload : H.Struct(e.payload),
65
+ control: e
66
+ });
67
+ f !== void 0 && Object.defineProperty(o, J, {
68
+ value: f,
69
+ enumerable: !1
70
+ });
71
+ let p = w(e.name, e.schedule);
72
+ return p !== void 0 && Object.defineProperty(o, S, {
73
+ value: p,
74
+ enumerable: !1
75
+ }), o;
76
+ }), ae = (e) => {
77
+ if (!X(e)) return;
78
+ let t = e[J];
79
+ return t === void 0 ? void 0 : t;
80
+ }, oe = (e) => {
81
+ if (e.encrypted !== !0) return P.make(e);
82
+ i(e.name);
83
+ let t = H.isSchema(e.payload) ? e.payload : H.Struct(e.payload);
84
+ return P.make({
85
+ ...e,
86
+ payload: l(t, `queue '${e.name}' payload`),
87
+ success: l(e.success ?? H.Void, `queue '${e.name}' result`),
88
+ error: l(e.error ?? H.Never, `queue '${e.name}' failure`)
89
+ });
90
+ }, se = ((e, ...t) => B.flatMap(n, (n) => n && !r(e.name) ? B.die(/* @__PURE__ */ Error(`an encrypted workflow enqueued into durable queue '${e.name}', which is not encrypted: the queue's journal would hold the value in plaintext. Declare \`durableQueue({ …, encrypted: true })\`.`)) : P.process(e, ...t))), Q = ((...e) => {
91
+ let t = P.worker(...e);
92
+ return Object.defineProperty(t, G, {
93
+ value: !0,
94
+ enumerable: !1
95
+ }), t;
96
+ }), ce = (e) => B.gen(function* () {
97
+ let t = yield* A.make({
98
+ name: `${e.name}/rateLimit`,
99
+ success: H.Number,
100
+ error: L.RateLimiterError,
101
+ execute: B.gen(function* () {
102
+ let t = yield* (yield* L.RateLimiter).consume({
103
+ ...e,
104
+ onExceeded: "delay"
105
+ });
106
+ return z.toMillis(t.delay);
107
+ })
108
+ });
109
+ t > 0 && (yield* M.sleep({
110
+ name: `${e.name}/rateLimit`,
111
+ duration: z.millis(t)
112
+ }));
113
+ }), $ = (e) => B.gen(function* () {
114
+ let t = yield* _, n = yield* B.serviceOption(y), r = z.toMillis(z.fromInputUnsafe(e.duration));
115
+ if (t !== void 0 && n._tag === "Some") {
116
+ let i = n.value, a = new Date(Date.now() + r).toISOString(), o = yield* ee;
117
+ yield* B.promise(() => i.recordEvent({
118
+ runId: t,
119
+ eventType: "timer-set",
120
+ payload: {
121
+ name: e.name,
122
+ durationMs: r,
123
+ scheduledWakeAt: a,
124
+ ...o === void 0 ? {} : { tenantId: o }
125
+ }
126
+ }).catch(() => {}));
127
+ let s = Date.now();
128
+ yield* M.sleep(e), yield* B.promise(() => i.recordEvent({
129
+ runId: t,
130
+ eventType: "timer-fired",
131
+ payload: {
132
+ name: e.name,
133
+ actualDurationMs: Date.now() - s,
134
+ ...o === void 0 ? {} : { tenantId: o }
135
+ }
136
+ }).catch(() => {}));
137
+ } else yield* M.sleep(e);
138
+ }), le = (e) => B.gen(function* () {
139
+ let t = (yield* A.make({
140
+ name: `sleepUntil:${e.name}`,
141
+ success: H.Number,
142
+ execute: B.sync(() => e.until instanceof Date ? e.until.getTime() : e.until)
143
+ })) - Date.now();
144
+ t <= 0 || (yield* $({
145
+ name: e.name,
146
+ duration: `${t} millis`
147
+ }));
148
+ }), ue = (t, r, i, a) => B.gen(function* () {
149
+ let o = yield* _, s = yield* A.CurrentAttempt, c = yield* B.serviceOption(y), l = yield* B.serviceOption(b), u = l._tag === "Some" ? l.value.interceptor(r, {
150
+ runId: o ?? "unrecorded",
151
+ stepName: t,
152
+ attempt: s
153
+ }) : r, d, f, p = !1;
154
+ if (o !== void 0 && c._tag === "Some") {
155
+ f = c.value;
156
+ let e = a === void 0 ? void 0 : (({ retryable: e, ...t }) => t)(a);
157
+ p = yield* n;
158
+ try {
159
+ d = yield* B.promise(() => f.startStep({
160
+ runId: o,
161
+ stepName: t,
162
+ attempt: s,
163
+ stepInput: i,
164
+ sealed: p,
165
+ ...e === void 0 ? {} : { retryPolicy: e }
166
+ }));
167
+ } catch {
168
+ d = void 0;
169
+ }
170
+ }
171
+ let m = Date.now();
172
+ return yield* B.provideService(k(u, a), v, t).pipe(B.tap((e) => d && f ? B.promise(async () => {
173
+ try {
174
+ await f.endStepSuccess({
175
+ stepRecordId: d,
176
+ sealed: p,
177
+ output: e,
178
+ durationMs: Date.now() - m
179
+ });
180
+ } catch {}
181
+ }) : B.void), B.tapCause((t) => d && f && !R.hasInterruptsOnly(t) ? B.promise(async () => {
182
+ try {
183
+ let n = R.findErrorOption(t), r = t.reasons.filter(R.isFailReason).map((e) => e.error), i = t.reasons.filter(R.isDieReason).map((e) => e.defect), a = n._tag === "Some" ? n.value : i[0] ?? R.squash(t), o = e(a), s = a && typeof a == "object" && "_tag" in a ? String(a._tag) : null;
184
+ await f.endStepFailure({
185
+ stepRecordId: d,
186
+ sealed: p,
187
+ errorTag: s,
188
+ errorMessage: o,
189
+ errorCause: {
190
+ pretty: R.pretty(t),
191
+ failures: r,
192
+ defects: i
193
+ },
194
+ durationMs: Date.now() - m
195
+ });
196
+ } catch {}
197
+ }) : B.void));
198
+ }), de = (e) => B.gen(function* () {
199
+ let t = yield* T;
200
+ if (t === void 0) return;
201
+ let n = t.reach(e);
202
+ n !== void 0 && (yield* O([n]));
203
+ }), fe = (e, t, r) => {
204
+ let i = e;
205
+ return {
206
+ ...e,
207
+ ...V.Prototype({
208
+ label: "Activity",
209
+ evaluate: () => B.andThen(de(t), r === void 0 ? i : B.flatMap(n, (e) => e ? r().pipe(B.catchDefect((e) => B.die(o(e, `step '${t}' defect`)))) : i))
210
+ })
211
+ };
212
+ }, pe = (e) => {
213
+ let { input: t, retry: n, ...r } = e, i = ue(r.name, r.execute, t, n), a = A.make({
214
+ ...r,
215
+ execute: i
216
+ }), o, c = `step '${r.name}' defect`;
217
+ return fe(a, r.name, () => o ??= A.make({
218
+ ...r,
219
+ success: l(r.success ?? H.Void, `step '${r.name}' result`),
220
+ error: l(r.error ?? H.Never, `step '${r.name}' failure`),
221
+ execute: i.pipe(B.catchDefect((e) => B.die(s(e, c))))
222
+ }));
223
+ }, me = (e) => B.map(g, (t) => t.includes(e)), he = F.withCompensation, ge = A.idempotencyKey;
224
+ //#endregion
225
+ export { T as CurrentWorkflowReplayShape, x as DEFAULT_WORKFLOW_SCHEDULE_MAX_RUNTIME_MS, u as DEFERRING_CONTROLS, J as WorkflowFlowControlProperty, q as WorkflowMessagesProperty, S as WorkflowScheduleProperty, K as WorkflowVersionTypeId, G as WorkflowWorkerLayerTypeId, d as assertConsistentPools, f as deferringControlsOf, N as durableClock, oe as durableQueue, te as durableQueueModule, ae as getWorkflowFlowControl, C as getWorkflowSchedule, re as getWorkflowVersionMetadata, p as hasCancelOn, m as hasFlowControl, X as isCarrier, Y as isWorkflowWorkerLayer, E as makeReplayShapeTracker, D as nondeterminismEventPayload, me as patch, se as processQueue, Q as queueWorker, ce as rateLimit, O as reportNondeterminism, $ as sleep, le as sleepUntil, pe as step, ge as stepIdempotencyKey, j as stepModule, h as validateFlowControl, w as validateWorkflowSchedule, he as withCompensation, ie as workflow, ne as workflowModule };