@voltro/runtime 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.
- package/CHANGELOG.md +666 -0
- package/THIRD-PARTY-NOTICES.md +5 -33
- package/dist/aggregate.js +42 -0
- package/dist/aggregateExtrema.js +80 -0
- package/dist/aggregateIvm.js +115 -0
- package/dist/analyticsMirror.js +228 -0
- package/dist/analyticsSink.js +38 -0
- package/dist/apiKeyUsage.js +33 -0
- package/dist/apiKeys.js +223 -0
- package/dist/apiKeysWiring.js +114 -0
- package/dist/approvalBuiltins.js +10 -0
- package/dist/approvals.js +269 -0
- package/dist/authMiddlewareLayer.js +47 -0
- package/dist/bindEvent.js +72 -0
- package/dist/bootListener.js +76 -0
- package/dist/bootRefusal.js +7 -0
- package/dist/bootStoreCodec.js +70 -0
- package/dist/businessRules.js +67 -0
- package/dist/changeClaimsTable.js +12 -0
- package/dist/circuitBreaker.js +72 -0
- package/dist/columnOnUpdate.js +23 -0
- package/dist/composeAnalytics.js +108 -0
- package/dist/computedQuery.js +4 -0
- package/dist/connectionBuiltins.js +81 -0
- package/dist/connectionCredentials.js +66 -0
- package/dist/connectionState.js +34 -0
- package/dist/connectionVault.js +410 -0
- package/dist/connectionsFacade.js +54 -0
- package/dist/coordinatedSchedule.js +139 -0
- package/dist/crdtHistory.js +138 -0
- package/dist/crdtMerge.js +179 -0
- package/dist/crdtVersionsTable.js +25 -0
- package/dist/credentialBound.js +12 -0
- package/dist/crud.js +72 -0
- package/dist/dataStore.js +679 -0
- package/dist/dataloader.js +61 -0
- package/dist/declaredTablesGuard.js +48 -0
- package/dist/defineExecutor.js +4 -0
- package/dist/dependencyGraph.js +32 -0
- package/dist/devices.js +228 -0
- package/dist/devicesWiring.js +168 -0
- package/dist/dialectReplicationAdapter.js +29 -0
- package/dist/dispatcher.js +447 -0
- package/dist/effectStore.js +71 -0
- package/dist/eventBus.js +260 -0
- package/dist/eventPublish.js +49 -0
- package/dist/events.js +193 -0
- package/dist/expectation.js +52 -0
- package/dist/expectationEvaluator.js +308 -0
- package/dist/experiment.js +96 -0
- package/dist/experimentEvaluator.js +245 -0
- package/dist/externalizedTasks.js +25 -0
- package/dist/fieldCipher.js +61 -0
- package/dist/fingerprint.js +21 -0
- package/dist/finops.js +42 -0
- package/dist/finopsAccountant.js +216 -0
- package/dist/handlerBody.js +8 -0
- package/dist/healthProbes.js +55 -0
- package/dist/httpClientSsrf.js +49 -0
- package/dist/httpClientTracing.js +11 -0
- package/dist/httpCompression.js +76 -0
- package/dist/httpKeepAlive.js +12 -0
- package/dist/httpRouteMounts.js +47 -0
- package/dist/idempotencyStore.js +70 -0
- package/dist/idleDetector.js +21 -0
- package/dist/index.d.ts +88 -69
- package/dist/index.js +144 -15292
- package/dist/insertRequiredColumns.js +19 -0
- package/dist/inspectWorkflow.js +1 -0
- package/dist/instanceMembership.js +98 -0
- package/dist/ivm.js +125 -0
- package/dist/kvDataStore.js +86 -0
- package/dist/kvFacade.js +32 -0
- package/dist/matcher.js +304 -0
- package/dist/memoryColumnDefaults.js +11 -0
- package/dist/memoryQueryJoins.js +114 -0
- package/dist/metrics.js +161 -0
- package/dist/observability.js +123 -0
- package/dist/observedGraph.js +52 -0
- package/dist/originGuard.js +116 -0
- package/dist/outbox.js +352 -0
- package/dist/pluginRefRules.js +65 -0
- package/dist/policyGuardResolver.js +55 -0
- package/dist/preview.js +62 -0
- package/dist/projectedRows.js +12 -0
- package/dist/provenance.js +63 -0
- package/dist/rangeIndex.js +89 -0
- package/dist/rawReadScope.js +17 -0
- package/dist/reaction.js +85 -0
- package/dist/reactiveConfig.js +11 -0
- package/dist/readClassification.js +57 -0
- package/dist/readRecorder.js +66 -0
- package/dist/rebac.js +104 -0
- package/dist/rebacInterceptor.js +81 -0
- package/dist/registry.js +29 -0
- package/dist/relevantFields.js +65 -0
- package/dist/replicaHealth.js +42 -0
- package/dist/replicaLocality.js +44 -0
- package/dist/replicaObservations.js +121 -0
- package/dist/replicaSelection.js +32 -0
- package/dist/replicatedDataStore.js +239 -0
- package/dist/requestLoader.js +7 -0
- package/dist/resumeCensus.js +28 -0
- package/dist/revalidation.js +22 -0
- package/dist/rowFilter.js +65 -0
- package/dist/rowStateBytes.js +45 -0
- package/dist/rpcBodyCap.js +63 -0
- package/dist/rpcConnections.js +83 -0
- package/dist/rpcDefectDiagnostics.js +15 -0
- package/dist/rpcServer.js +992 -0
- package/dist/runAsSystem.js +23 -0
- package/dist/rywPositionStore.js +84 -0
- package/dist/schedule.js +23 -0
- package/dist/scheduleBackfillRequests.js +151 -0
- package/dist/scheduleClaimsTable.js +11 -0
- package/dist/scheduleRunsTable.js +37 -0
- package/dist/scheduler.js +835 -0
- package/dist/schemaRegistry.js +65 -0
- package/dist/secretsResolver.js +35 -0
- package/dist/securityHeaders.js +33 -0
- package/dist/servePipeline.js +305 -0
- package/dist/serverOnlyAudit.js +66 -0
- package/dist/serverTracer.js +15 -0
- package/dist/serviceCredentials.js +40 -0
- package/dist/singleNodeOrchestrator.js +91 -0
- package/dist/sourceResolution.js +42 -0
- package/dist/storeMiddleware.js +880 -0
- package/dist/storeQuery.js +204 -0
- package/dist/storeRead.js +10 -0
- package/dist/subscriber.js +7 -0
- package/dist/subscriptionOutbox.js +139 -0
- package/dist/subscriptionRegistry.js +82 -0
- package/dist/subscriptionResume.js +132 -0
- package/dist/subscriptionSocketMetrics.js +65 -0
- package/dist/systemSubject.js +5 -0
- package/dist/tenantScope.js +23 -0
- package/dist/tenantSelection.js +27 -0
- package/dist/timeline.js +105 -0
- package/dist/traceContext.js +5 -0
- package/dist/traceSink.js +63 -0
- package/dist/traceSpansTable.js +29 -0
- package/dist/traceparent.js +34 -0
- package/dist/transactionSubject.js +12 -0
- package/dist/trustedProxy.js +155 -0
- package/dist/undo.js +129 -0
- package/dist/undoBuiltins.js +69 -0
- package/dist/undoCapture.js +74 -0
- package/dist/undoLogTable.js +16 -0
- package/dist/upsertBinding.js +20 -0
- package/dist/wakeOrchestrator.js +34 -0
- package/dist/wakeRegistry.js +71 -0
- package/dist/wakeRouter.js +63 -0
- package/dist/wakeSupervisor.js +62 -0
- package/dist/wakeupsTable.js +12 -0
- package/dist/webSocketGatewayRuntime.js +114 -0
- package/dist/webhookVerification.js +18 -0
- package/dist/wireColumnStrip.js +84 -0
- package/dist/workflowReadBuiltins.js +87 -0
- package/dist/workflowRuntime.js +708 -0
- package/package.json +7 -7
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import { getRowFilter as e, resolveRowFilterScopeFor as t } from "./rowFilter.js";
|
|
2
|
+
import { SYSTEM_SUBJECT as n } from "./systemSubject.js";
|
|
3
|
+
import { makeEffectStoreLayer as r } from "./effectStore.js";
|
|
4
|
+
import { Cause as i, Effect as a, Exit as o, Layer as s, Option as c, Schema as l, SchemaIssue as u } from "effect";
|
|
5
|
+
import { SubjectService as d, WorkflowControlResultSchema as f, WorkflowQueuedCancellationResultSchema as p, WorkflowRestartCommandSchema as m, WorkflowRestartObservationSchema as h, WorkflowRestartResultSchema as g, WorkflowRestartTargetSchema as _, WorkflowRetryCommandSchema as v, WorkflowRetryObservationSchema as y, WorkflowRetryTargetSchema as b } from "@voltro/protocol";
|
|
6
|
+
import { createLogger as x } from "@voltro/logger";
|
|
7
|
+
import * as S from "effect/SchemaAST";
|
|
8
|
+
import { executePreparedWorkflow as C, getCurrentWorkflowExecutionId as w, hasPreparedWorkflowExecution as T } from "@voltro/workflow";
|
|
9
|
+
//#region src/workflowRuntime.ts
|
|
10
|
+
var E = class extends l.TaggedError()("WorkflowStartNotExecuted", {
|
|
11
|
+
workflowName: l.String,
|
|
12
|
+
handleId: l.String,
|
|
13
|
+
reason: l.Literals([
|
|
14
|
+
"dropped",
|
|
15
|
+
"skipped",
|
|
16
|
+
"superseded",
|
|
17
|
+
"cancelled",
|
|
18
|
+
"abandoned",
|
|
19
|
+
"rejected"
|
|
20
|
+
]),
|
|
21
|
+
failureId: l.NullOr(l.String),
|
|
22
|
+
incumbentExecutionId: l.NullOr(l.String)
|
|
23
|
+
}) {}, D = x({ scope: "voltro:workflow" }), O = /* @__PURE__ */ new Set(), k = 1e3, A = /* @__PURE__ */ new Set([
|
|
24
|
+
"succeeded",
|
|
25
|
+
"failed",
|
|
26
|
+
"cancelled"
|
|
27
|
+
]), j = async (e, t) => {
|
|
28
|
+
try {
|
|
29
|
+
return (await e({
|
|
30
|
+
idPrefix: t,
|
|
31
|
+
limit: 5
|
|
32
|
+
})).find((e) => e.executionId === t && A.has(e.status));
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}, M = (e, t, n) => ({
|
|
37
|
+
id: t,
|
|
38
|
+
workflowName: e,
|
|
39
|
+
executionId: t,
|
|
40
|
+
status: n
|
|
41
|
+
}), N = (e, t) => t.kind === "queued" ? {
|
|
42
|
+
id: t.receiptId,
|
|
43
|
+
workflowName: e,
|
|
44
|
+
executionId: null,
|
|
45
|
+
status: "queued",
|
|
46
|
+
deferral: {
|
|
47
|
+
mode: t.mode,
|
|
48
|
+
dueAt: t.dueAt,
|
|
49
|
+
retryAfterMs: null,
|
|
50
|
+
intentId: t.intentId
|
|
51
|
+
}
|
|
52
|
+
} : t.kind === "dropped" ? {
|
|
53
|
+
id: `dropped:${e}`,
|
|
54
|
+
workflowName: e,
|
|
55
|
+
executionId: null,
|
|
56
|
+
status: "dropped",
|
|
57
|
+
deferral: {
|
|
58
|
+
mode: "rateLimit",
|
|
59
|
+
dueAt: null,
|
|
60
|
+
retryAfterMs: t.retryAfterMs,
|
|
61
|
+
intentId: null
|
|
62
|
+
}
|
|
63
|
+
} : {
|
|
64
|
+
id: t.executionId,
|
|
65
|
+
workflowName: e,
|
|
66
|
+
executionId: t.executionId,
|
|
67
|
+
status: "skipped",
|
|
68
|
+
deferral: {
|
|
69
|
+
mode: "singleton",
|
|
70
|
+
dueAt: null,
|
|
71
|
+
retryAfterMs: null,
|
|
72
|
+
intentId: null
|
|
73
|
+
}
|
|
74
|
+
}, P = class extends Error {
|
|
75
|
+
workflowName;
|
|
76
|
+
retryAfterMs;
|
|
77
|
+
constructor(e, t) {
|
|
78
|
+
super(`workflow '${e}' is over its declared rateLimit; this start was DROPPED and will not run. The window reopens in ${t}ms. Use throttle instead of rateLimit if the excess should be queued rather than discarded.`), this.name = "WorkflowRateLimitedError", this.workflowName = e, this.retryAfterMs = t;
|
|
79
|
+
}
|
|
80
|
+
}, F = class extends Error {
|
|
81
|
+
workflowName;
|
|
82
|
+
executionId;
|
|
83
|
+
constructor(e, t) {
|
|
84
|
+
super(`workflow '${e}' holds its singleton key on run '${t}', and this workflow declares mode 'skip'. Nothing new was started. Wait on that run (ctx.workflows.wait('${e}', '${t}')) if its result is what you needed.`), this.name = "WorkflowSingletonHeldError", this.workflowName = e, this.executionId = t;
|
|
85
|
+
}
|
|
86
|
+
}, I = { kind: "passthrough" }, L = M, R = (e) => {
|
|
87
|
+
let t = i.findErrorOption(e), n = t._tag === "Some" ? t.value : i.squash(e);
|
|
88
|
+
return {
|
|
89
|
+
tag: n && typeof n == "object" && "_tag" in n ? String(n._tag) : null,
|
|
90
|
+
message: n?.message ?? String(n)
|
|
91
|
+
};
|
|
92
|
+
}, z = (e, t, n) => {
|
|
93
|
+
if (n === void 0) return {
|
|
94
|
+
id: t,
|
|
95
|
+
workflowName: e,
|
|
96
|
+
executionId: t,
|
|
97
|
+
status: "unknown"
|
|
98
|
+
};
|
|
99
|
+
if (typeof n == "object" && n && n._tag === "Suspended") return {
|
|
100
|
+
id: t,
|
|
101
|
+
workflowName: e,
|
|
102
|
+
executionId: t,
|
|
103
|
+
status: "suspended"
|
|
104
|
+
};
|
|
105
|
+
if (typeof n == "object" && n && n._tag === "Complete") {
|
|
106
|
+
let r = n.exit;
|
|
107
|
+
return o.isSuccess(r) ? {
|
|
108
|
+
id: t,
|
|
109
|
+
workflowName: e,
|
|
110
|
+
executionId: t,
|
|
111
|
+
status: "succeeded",
|
|
112
|
+
output: r.value
|
|
113
|
+
} : {
|
|
114
|
+
id: t,
|
|
115
|
+
workflowName: e,
|
|
116
|
+
executionId: t,
|
|
117
|
+
status: i.hasInterruptsOnly(r.cause) ? "cancelled" : "failed",
|
|
118
|
+
error: R(r.cause)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
id: t,
|
|
123
|
+
workflowName: e,
|
|
124
|
+
executionId: t,
|
|
125
|
+
status: "running"
|
|
126
|
+
};
|
|
127
|
+
}, B = (e) => new Promise((t) => setTimeout(t, e)), V = class extends Error {
|
|
128
|
+
workflowName;
|
|
129
|
+
missingFields;
|
|
130
|
+
detail;
|
|
131
|
+
_tag = "WorkflowPayloadError";
|
|
132
|
+
constructor(e, t, n) {
|
|
133
|
+
let r = t.length > 0 ? ` missing required field(s): ${t.join(", ")}.` : "";
|
|
134
|
+
super(`Workflow "${e}" was started with an invalid payload.${r} ${n}`), this.workflowName = e, this.missingFields = t, this.detail = n, this.name = "WorkflowPayloadError";
|
|
135
|
+
}
|
|
136
|
+
}, H = (e, t) => {
|
|
137
|
+
let n = e.ast, r = [], i = [];
|
|
138
|
+
return S.isObjects(n) && n.propertySignatures.forEach((e) => {
|
|
139
|
+
let n = e.name;
|
|
140
|
+
typeof n == "string" && (S.isOptional(e.type) ? t && i.push(n) : r.push(n));
|
|
141
|
+
}), {
|
|
142
|
+
required: r,
|
|
143
|
+
optional: i
|
|
144
|
+
};
|
|
145
|
+
}, U = (e) => H(e, !0), W = (e) => H(e, !1).required, G = (e) => {
|
|
146
|
+
let t = new Map(e.workflows.map((e) => [e.definition.name, e.definition])), r = (e) => {
|
|
147
|
+
let n = t.get(e);
|
|
148
|
+
if (!n) {
|
|
149
|
+
let n = [...t.keys()].sort().join(", ");
|
|
150
|
+
throw Error(`Unknown workflow: ${e}. Registered workflows: ${n || "(none)"}.`);
|
|
151
|
+
}
|
|
152
|
+
return n;
|
|
153
|
+
}, i = (e, t, n = e.payloadSchema) => {
|
|
154
|
+
let r = l.decodeUnknownResult(l.make(S.toType(n.ast)))(t);
|
|
155
|
+
if (r._tag === "Success") return;
|
|
156
|
+
let i = new Set(typeof t == "object" && t ? Object.keys(t) : []), a = W(n).filter((e) => !i.has(e));
|
|
157
|
+
throw new V(e.name, a, u.makeFormatterDefault()(r.failure.issue));
|
|
158
|
+
}, a = (t) => e.startPayloadSchema?.(t.name) ?? t.payloadSchema, s = (e, t, n = !1) => {
|
|
159
|
+
let o = r(e);
|
|
160
|
+
return i(o, t, n ? o.payloadSchema : a(o)), o;
|
|
161
|
+
}, d = async (t, n) => {
|
|
162
|
+
let i = r(t);
|
|
163
|
+
return z(t, n, c.getOrUndefined(await e.runEffect(i.poll(n))));
|
|
164
|
+
}, x = async () => e.runEffect(w()), L = async (t, n, r) => {
|
|
165
|
+
if (e.resolveQueuedStart === void 0) throw Error(`Workflow '${t}' remains queued under receipt '${n}'; no receipt resolver is configured`);
|
|
166
|
+
let i = await e.resolveQueuedStart({
|
|
167
|
+
workflowName: t,
|
|
168
|
+
receiptId: n,
|
|
169
|
+
callerContext: r
|
|
170
|
+
});
|
|
171
|
+
if (i.kind === "pending") return;
|
|
172
|
+
if (i.kind === "accepted") {
|
|
173
|
+
if (i.executionId.length === 0) throw Error("Queued workflow acceptance has an empty execution identity");
|
|
174
|
+
return i.executionId;
|
|
175
|
+
}
|
|
176
|
+
let a = i.kind === "terminal" ? i.outcome : void 0;
|
|
177
|
+
throw new E({
|
|
178
|
+
workflowName: t,
|
|
179
|
+
handleId: n,
|
|
180
|
+
reason: a?.kind ?? "rejected",
|
|
181
|
+
failureId: i.kind === "rejected" ? i.failureId : a?.kind === "abandoned" ? a.failureId : null,
|
|
182
|
+
incumbentExecutionId: a?.kind === "skipped" ? a.executionId : null
|
|
183
|
+
});
|
|
184
|
+
}, R = async (t, n) => {
|
|
185
|
+
let i = r(t);
|
|
186
|
+
for (;;) {
|
|
187
|
+
let t = c.getOrUndefined(await e.runEffect(i.poll(n)));
|
|
188
|
+
if (typeof t == "object" && t && "_tag" in t && t._tag === "Complete") {
|
|
189
|
+
if (!("exit" in t) || !o.isExit(t.exit)) throw Error("Completed workflow observation has no valid Exit");
|
|
190
|
+
return e.runEffect(t.exit);
|
|
191
|
+
}
|
|
192
|
+
await B(500);
|
|
193
|
+
}
|
|
194
|
+
}, H = async (e, t, n) => {
|
|
195
|
+
let r;
|
|
196
|
+
for (; r === void 0;) r = await L(e, t, n), r === void 0 && await B(500);
|
|
197
|
+
return {
|
|
198
|
+
executionId: r,
|
|
199
|
+
value: await R(e, r)
|
|
200
|
+
};
|
|
201
|
+
}, U = (e, t, n) => {
|
|
202
|
+
let r = l.decodeUnknownSync(f)(t), i = n === "submit" && r.kind === "unknown" && r.requestId === null;
|
|
203
|
+
if (r.operation !== e.operation || r.snapshot.workflowName !== e.workflowName || r.snapshot.executionId !== e.executionId || e.requestId !== void 0 && r.requestId !== e.requestId && !i) throw Error("Workflow control response does not match the requested control target");
|
|
204
|
+
return r;
|
|
205
|
+
}, G = async (t, n, i, a) => {
|
|
206
|
+
let o = r(n), s = a?.requestId;
|
|
207
|
+
if (a !== void 0 && (typeof s != "string" || s.trim().length === 0)) throw Error("Workflow control requestId must be a non-empty string");
|
|
208
|
+
if (e.control !== void 0) {
|
|
209
|
+
let r = {
|
|
210
|
+
operation: t,
|
|
211
|
+
workflowName: n,
|
|
212
|
+
executionId: i,
|
|
213
|
+
...s === void 0 ? {} : { requestId: s },
|
|
214
|
+
...a?.cause === void 0 ? {} : { cause: a.cause }
|
|
215
|
+
};
|
|
216
|
+
return U(r, await e.control(r), "submit");
|
|
217
|
+
}
|
|
218
|
+
if (s !== void 0) throw Error("Workflow control requestId requires a resident control adapter");
|
|
219
|
+
let c = await d(n, i);
|
|
220
|
+
if (A.has(c.status)) return {
|
|
221
|
+
operation: t,
|
|
222
|
+
kind: "already-terminal",
|
|
223
|
+
requestId: null,
|
|
224
|
+
snapshot: c
|
|
225
|
+
};
|
|
226
|
+
try {
|
|
227
|
+
await e.runEffect(t === "cancel" ? o.interrupt(i) : o.resume(i));
|
|
228
|
+
let r = await d(n, i);
|
|
229
|
+
return {
|
|
230
|
+
operation: t,
|
|
231
|
+
kind: t === "cancel" && r.status === "cancelled" ? "confirmed" : "unknown",
|
|
232
|
+
requestId: null,
|
|
233
|
+
snapshot: r
|
|
234
|
+
};
|
|
235
|
+
} catch (e) {
|
|
236
|
+
return D.warn("workflow control outcome is unknown", {
|
|
237
|
+
workflowName: n,
|
|
238
|
+
executionId: i,
|
|
239
|
+
operation: t,
|
|
240
|
+
error: e
|
|
241
|
+
}), {
|
|
242
|
+
operation: t,
|
|
243
|
+
kind: "unknown",
|
|
244
|
+
requestId: null,
|
|
245
|
+
snapshot: {
|
|
246
|
+
id: i,
|
|
247
|
+
workflowName: n,
|
|
248
|
+
executionId: i,
|
|
249
|
+
status: "unknown"
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}, q = async (t, n, r) => {
|
|
254
|
+
for (let e of [
|
|
255
|
+
n.workflowName,
|
|
256
|
+
n.receiptId,
|
|
257
|
+
n.requestId
|
|
258
|
+
]) if (typeof e != "string" || e.trim().length === 0) throw Error("Queued control requires non-empty workflow, receipt and request identities");
|
|
259
|
+
let i = t === "submit" ? e.cancelQueued : e.readQueuedCancellation;
|
|
260
|
+
if (i === void 0) throw Error("Queued cancellation requires a resident submit/read adapter");
|
|
261
|
+
let a = l.decodeUnknownSync(p)(await i({
|
|
262
|
+
workflowName: n.workflowName,
|
|
263
|
+
receiptId: n.receiptId,
|
|
264
|
+
requestId: n.requestId,
|
|
265
|
+
callerContext: r?.callerContext,
|
|
266
|
+
...t === "submit" && r?.cause !== void 0 ? { cause: r.cause } : {}
|
|
267
|
+
}));
|
|
268
|
+
if (a.workflowName !== n.workflowName || a.receiptId !== n.receiptId || a.requestId !== null && a.requestId !== n.requestId) throw Error("Queued cancellation response does not match the requested target");
|
|
269
|
+
return a;
|
|
270
|
+
}, J = async (t, r, i) => {
|
|
271
|
+
let o = i?.requestId;
|
|
272
|
+
if (o !== void 0 && (typeof o != "string" || o.trim().length === 0 || o.length > 64 || i?.at === void 0 || i?.admitted === !0 || i?.enqueueStart !== void 0)) throw Error("Workflow start requestId requires a non-empty identity of at most 64 characters and an explicit at instant, without admitted or transactional enqueue");
|
|
273
|
+
let c = i?.preparedExecutionId;
|
|
274
|
+
if (c !== void 0 && (c.length === 0 || i?.admitted !== !0 || i.wait === !0 || i.enqueueStart !== void 0 || i.at !== void 0)) throw Error("Prepared workflow execution requires a non-empty identity and admitted:true, without wait, enqueueStart or at");
|
|
275
|
+
let u = s(t, r, i?.admitted === !0);
|
|
276
|
+
if (i?.enqueueStart !== void 0) {
|
|
277
|
+
if (i.wait === !0 || i.admitted === !0) throw Error("A transactional workflow start cannot wait or bypass admission");
|
|
278
|
+
let e = i.at?.getTime() ?? Date.now();
|
|
279
|
+
if (!Number.isFinite(e)) throw Error(`ctx.workflows.start('${t}'): 'at' is not a valid Date`);
|
|
280
|
+
let n;
|
|
281
|
+
try {
|
|
282
|
+
n = l.encodeUnknownSync(a(u))(r);
|
|
283
|
+
} catch {
|
|
284
|
+
throw new V(t, [], "payload could not be encoded for the admission queue");
|
|
285
|
+
}
|
|
286
|
+
return N(t, {
|
|
287
|
+
kind: "queued",
|
|
288
|
+
mode: "transaction",
|
|
289
|
+
...await i.enqueueStart({
|
|
290
|
+
workflowName: t,
|
|
291
|
+
payload: n,
|
|
292
|
+
callerContext: i.callerContext,
|
|
293
|
+
at: e
|
|
294
|
+
})
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (i?.at !== void 0 && i.admitted !== !0) {
|
|
298
|
+
let n = i.at.getTime();
|
|
299
|
+
if (!Number.isFinite(n)) throw Error(`ctx.workflows.start('${t}', …, { at }): 'at' is not a valid Date`);
|
|
300
|
+
if (n > Date.now() || o !== void 0) {
|
|
301
|
+
if (e.parkDelayedStart === void 0) throw Error(`ctx.workflows.start('${t}', …, { at }): delayed starts are not configured in this runtime — the durable pending queue that fires them is wired by the framework boot (voltro dev / voltro serve).`);
|
|
302
|
+
let a = await e.parkDelayedStart({
|
|
303
|
+
...o === void 0 ? {} : { requestId: o },
|
|
304
|
+
workflowName: t,
|
|
305
|
+
payload: r,
|
|
306
|
+
callerContext: i.callerContext,
|
|
307
|
+
at: n
|
|
308
|
+
});
|
|
309
|
+
return i.wait === !0 ? M(t, (await H(t, a.receiptId, i.callerContext)).executionId, "succeeded") : {
|
|
310
|
+
id: a.receiptId,
|
|
311
|
+
workflowName: t,
|
|
312
|
+
executionId: null,
|
|
313
|
+
status: "queued",
|
|
314
|
+
deferral: {
|
|
315
|
+
mode: "delayed",
|
|
316
|
+
dueAt: a.dueAt,
|
|
317
|
+
retryAfterMs: null,
|
|
318
|
+
intentId: a.intentId
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
let d = i?.wait === !0, f = e.admitStart === void 0 || i?.admitted === !0 ? I : await e.admitStart({
|
|
324
|
+
workflowName: t,
|
|
325
|
+
payload: r,
|
|
326
|
+
callerContext: i?.callerContext,
|
|
327
|
+
waiting: d
|
|
328
|
+
});
|
|
329
|
+
if (f.kind === "queued" || f.kind === "dropped" || f.kind === "skipped") return d && f.kind === "queued" ? M(t, (await H(t, f.receiptId, i?.callerContext)).executionId, "succeeded") : N(t, f);
|
|
330
|
+
if (f.kind === "start") {
|
|
331
|
+
let n = await f.accept();
|
|
332
|
+
return typeof n == "string" ? (e.onEnqueue?.(), d && await R(t, n), M(t, n, d ? "succeeded" : "running")) : d ? M(t, (await H(t, n.receiptId, i?.callerContext)).executionId, "succeeded") : N(t, n);
|
|
333
|
+
}
|
|
334
|
+
let p = r;
|
|
335
|
+
if (e.listRuns !== void 0 && i?.admitted !== !0) {
|
|
336
|
+
let n = await e.runEffect(u.executionId(p)), r = await j(e.listRuns, n);
|
|
337
|
+
if (r !== void 0) return O.has(n) || (O.size >= k && O.clear(), O.add(n), D.warn("workflow start replayed — the idempotency key was already spent, nothing ran", {
|
|
338
|
+
workflow: t,
|
|
339
|
+
executionId: n,
|
|
340
|
+
runId: r.id,
|
|
341
|
+
status: r.status
|
|
342
|
+
})), d ? (await R(t, n), {
|
|
343
|
+
id: r.id,
|
|
344
|
+
workflowName: t,
|
|
345
|
+
executionId: n,
|
|
346
|
+
status: "succeeded"
|
|
347
|
+
}) : {
|
|
348
|
+
id: r.id,
|
|
349
|
+
workflowName: t,
|
|
350
|
+
executionId: n,
|
|
351
|
+
status: "replayed"
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
let m;
|
|
355
|
+
(e.rememberStartContext !== void 0 || i?.callerContext !== void 0) && (m = c ?? await e.runEffect(u.executionId(p)), await e.rememberStartContext?.(t, m, i?.callerContext ?? { subject: n }));
|
|
356
|
+
let h = c ?? (m !== void 0 && T(u) ? m : void 0);
|
|
357
|
+
if (d) return h === void 0 ? await e.runEffect(u.execute(p)) : await e.runEffect(C(u, p, h, { discard: !1 })), e.onEnqueue?.(), M(t, h ?? await e.runEffect(u.executionId(p)), "succeeded");
|
|
358
|
+
let g = await e.runEffect(h === void 0 ? u.execute(p, { discard: !0 }) : C(u, p, h));
|
|
359
|
+
return e.onEnqueue?.(), M(t, g, "running");
|
|
360
|
+
};
|
|
361
|
+
return {
|
|
362
|
+
start: J,
|
|
363
|
+
child: async (e, t, n) => {
|
|
364
|
+
let r = n?.callerContext?.parentExecutionId ?? await x();
|
|
365
|
+
if (r == null || r === "") throw Error("ctx.workflows.child(...) can only be used from inside a workflow execution; use ctx.workflows.start(...) for top-level starts.");
|
|
366
|
+
let i = n?.callerContext ?? {}, a = {
|
|
367
|
+
...i,
|
|
368
|
+
source: i.source ?? `workflow:${r}`,
|
|
369
|
+
parentExecutionId: r,
|
|
370
|
+
parentClosePolicy: n?.parentClosePolicy ?? i.parentClosePolicy ?? "cancel"
|
|
371
|
+
};
|
|
372
|
+
return J(e, t, {
|
|
373
|
+
...n?.wait === void 0 ? {} : { wait: n.wait },
|
|
374
|
+
...n?.enqueueStart === void 0 ? {} : { enqueueStart: n.enqueueStart },
|
|
375
|
+
callerContext: a
|
|
376
|
+
});
|
|
377
|
+
},
|
|
378
|
+
run: async (t, r, i) => {
|
|
379
|
+
let a = s(t, r);
|
|
380
|
+
if (e.admitStart !== void 0) {
|
|
381
|
+
let n = await e.admitStart({
|
|
382
|
+
workflowName: t,
|
|
383
|
+
payload: r,
|
|
384
|
+
callerContext: i?.callerContext,
|
|
385
|
+
waiting: !0
|
|
386
|
+
});
|
|
387
|
+
if (n.kind === "queued") return (await H(t, n.receiptId, i?.callerContext)).value;
|
|
388
|
+
if (n.kind === "dropped") throw new P(t, n.retryAfterMs);
|
|
389
|
+
if (n.kind === "skipped") throw new F(t, n.executionId);
|
|
390
|
+
if (n.kind === "start") {
|
|
391
|
+
let r = await n.accept();
|
|
392
|
+
return typeof r == "string" ? (e.onEnqueue?.(), await R(t, r)) : (await H(t, r.receiptId, i?.callerContext)).value;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (e.rememberStartContext !== void 0 || i?.callerContext !== void 0) {
|
|
396
|
+
let o = await e.runEffect(a.executionId(r));
|
|
397
|
+
await e.rememberStartContext?.(t, o, i?.callerContext ?? { subject: n });
|
|
398
|
+
}
|
|
399
|
+
return await e.runEffect(a.execute(r));
|
|
400
|
+
},
|
|
401
|
+
executionId: async (t, n) => {
|
|
402
|
+
let r = s(t, n, !0);
|
|
403
|
+
return e.runEffect(r.executionId(n));
|
|
404
|
+
},
|
|
405
|
+
poll: async (e, t) => d(e, t),
|
|
406
|
+
query: async (e, t) => d(e, t),
|
|
407
|
+
wait: (async (t, n, r) => {
|
|
408
|
+
let i = typeof t == "string" ? t : t.workflowName, a = typeof t == "string" ? n : t.executionId, o = typeof t == "string" ? r : n, s = Date.now(), c = o?.pollIntervalMs ?? 500, l = typeof t == "string" ? void 0 : t;
|
|
409
|
+
if (l?.status === "dropped" || l?.status === "skipped") throw new E({
|
|
410
|
+
workflowName: i,
|
|
411
|
+
handleId: l.id,
|
|
412
|
+
reason: l.status,
|
|
413
|
+
failureId: null,
|
|
414
|
+
incumbentExecutionId: l.status === "skipped" ? l.executionId : null
|
|
415
|
+
});
|
|
416
|
+
for (;;) {
|
|
417
|
+
if (a == null) {
|
|
418
|
+
if (l?.status !== "queued" || e.resolveQueuedStart === void 0) throw Error(`Workflow '${i}' has no execution or configured receipt resolver`);
|
|
419
|
+
if (a = await L(i, l.id, o?.callerContext), a === void 0) {
|
|
420
|
+
if (o?.timeoutMs !== void 0 && Date.now() - s >= o.timeoutMs) throw Error(`Timed out waiting for workflow '${i}' start receipt '${l.id}'`);
|
|
421
|
+
await B(c);
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
let t = await d(i, a);
|
|
426
|
+
if (t.status === "succeeded" || t.status === "failed" || t.status === "cancelled") return t;
|
|
427
|
+
if (o?.timeoutMs !== void 0 && Date.now() - s >= o.timeoutMs) throw Error(`Timed out waiting for workflow '${i}' run '${a}'`);
|
|
428
|
+
await B(c);
|
|
429
|
+
}
|
|
430
|
+
}),
|
|
431
|
+
cancel: (e, t, n) => G("cancel", e, t, n),
|
|
432
|
+
cancelQueued: (e, t) => q("submit", e, t),
|
|
433
|
+
readQueuedCancellation: (e, t) => q("read", e, t),
|
|
434
|
+
readStart: async (t, n) => {
|
|
435
|
+
if (t.status === "dropped" || t.status === "skipped") return {
|
|
436
|
+
kind: "not-executed",
|
|
437
|
+
reason: t.status,
|
|
438
|
+
failureId: null,
|
|
439
|
+
incumbentExecutionId: t.status === "skipped" ? t.executionId : null
|
|
440
|
+
};
|
|
441
|
+
if (t.status === "queued") {
|
|
442
|
+
if (e.resolveQueuedStart === void 0) throw Error(`Workflow '${t.workflowName}' remains queued under receipt '${t.id}'; no receipt resolver is configured`);
|
|
443
|
+
let r = await e.resolveQueuedStart({
|
|
444
|
+
workflowName: t.workflowName,
|
|
445
|
+
receiptId: t.id,
|
|
446
|
+
callerContext: n?.callerContext
|
|
447
|
+
});
|
|
448
|
+
if (r.kind === "pending") return { kind: "pending" };
|
|
449
|
+
if (r.kind === "accepted") {
|
|
450
|
+
if (r.executionId.length === 0) throw Error("Queued workflow acceptance has an empty execution identity");
|
|
451
|
+
return {
|
|
452
|
+
kind: "accepted",
|
|
453
|
+
executionId: r.executionId
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (r.kind === "rejected") return {
|
|
457
|
+
kind: "not-executed",
|
|
458
|
+
reason: "rejected",
|
|
459
|
+
failureId: r.failureId,
|
|
460
|
+
incumbentExecutionId: null
|
|
461
|
+
};
|
|
462
|
+
let i = r.outcome;
|
|
463
|
+
return {
|
|
464
|
+
kind: "not-executed",
|
|
465
|
+
reason: i.kind,
|
|
466
|
+
failureId: i.kind === "abandoned" ? i.failureId : null,
|
|
467
|
+
incumbentExecutionId: i.kind === "skipped" ? i.executionId : null
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
if (t.executionId === null || t.executionId.length === 0) throw Error(`Workflow '${t.workflowName}' handle '${t.id}' is '${t.status}' but names no execution`);
|
|
471
|
+
return {
|
|
472
|
+
kind: "accepted",
|
|
473
|
+
executionId: t.executionId
|
|
474
|
+
};
|
|
475
|
+
},
|
|
476
|
+
resume: (e, t, n) => G("resume", e, t, n),
|
|
477
|
+
readControl: async (t) => {
|
|
478
|
+
if (typeof t.requestId != "string" || t.requestId.trim().length === 0) throw Error("Workflow control requestId must be a non-empty string");
|
|
479
|
+
if (e.readControl === void 0) throw Error("Workflow control observation requires a resident readControl adapter");
|
|
480
|
+
return U(t, await e.readControl(t), "read");
|
|
481
|
+
},
|
|
482
|
+
signal: async (t, n, r) => {
|
|
483
|
+
if (!e.signal) throw Error("Workflow signals are not configured in this runtime");
|
|
484
|
+
return e.signal(t, n, r);
|
|
485
|
+
},
|
|
486
|
+
update: async (t, n, r, i) => {
|
|
487
|
+
if (!e.update) throw Error("Workflow updates are not configured in this runtime");
|
|
488
|
+
return e.update(t, n, r, i);
|
|
489
|
+
},
|
|
490
|
+
listRuns: (async (t) => {
|
|
491
|
+
if (!e.listRuns) throw Error("Workflow run listing is not configured in this runtime");
|
|
492
|
+
return e.listRuns(t);
|
|
493
|
+
}),
|
|
494
|
+
readRetry: async (t, n) => {
|
|
495
|
+
if (!e.readRetry) throw Error("Workflow retry observation is not configured in this runtime");
|
|
496
|
+
l.decodeUnknownSync(b)({
|
|
497
|
+
runId: t,
|
|
498
|
+
requestId: n
|
|
499
|
+
});
|
|
500
|
+
let r = l.decodeUnknownSync(y)(await e.readRetry(t, n));
|
|
501
|
+
if (r.originalRunId !== t || r.requestId !== n) throw Error("Workflow retry observation belongs to another intent");
|
|
502
|
+
return r;
|
|
503
|
+
},
|
|
504
|
+
retry: async (t, n) => {
|
|
505
|
+
if (!e.retry) throw Error("Workflow retry is not configured in this runtime");
|
|
506
|
+
let r = l.decodeUnknownSync(v)({
|
|
507
|
+
...n,
|
|
508
|
+
runId: t
|
|
509
|
+
}), i = l.decodeUnknownSync(y)(await e.retry(t, r));
|
|
510
|
+
if (i.originalRunId !== t || i.requestId !== r.requestId) throw Error("Workflow retry observation belongs to another intent");
|
|
511
|
+
return i;
|
|
512
|
+
},
|
|
513
|
+
restart: async (t, n) => {
|
|
514
|
+
if (!e.restart) throw Error("Workflow restart is not configured in this runtime");
|
|
515
|
+
let r = l.decodeUnknownSync(m)({
|
|
516
|
+
...n,
|
|
517
|
+
runId: t
|
|
518
|
+
}), i = l.decodeUnknownSync(g)(await e.restart(r));
|
|
519
|
+
return K(r, i), i;
|
|
520
|
+
},
|
|
521
|
+
readRestart: async (t, n) => {
|
|
522
|
+
if (!e.readRestart) throw Error("Workflow restart observation is not configured in this runtime");
|
|
523
|
+
let r = l.decodeUnknownSync(_)({
|
|
524
|
+
runId: t,
|
|
525
|
+
requestId: n
|
|
526
|
+
}), i = l.decodeUnknownSync(h)(await e.readRestart(r));
|
|
527
|
+
return K(r, i), i;
|
|
528
|
+
},
|
|
529
|
+
withdrawRestart: async (t, n) => {
|
|
530
|
+
if (!e.withdrawRestart) throw Error("Workflow restart withdrawal is not configured in this runtime");
|
|
531
|
+
let r = l.decodeUnknownSync(m)({
|
|
532
|
+
...n,
|
|
533
|
+
runId: t
|
|
534
|
+
}), i = l.decodeUnknownSync(h)(await e.withdrawRestart(r));
|
|
535
|
+
if (K(r, i), i.kind === "not-found") throw Error("Workflow withdrawal has no durable outcome");
|
|
536
|
+
return i;
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}, K = (e, t) => {
|
|
540
|
+
if (t.runId !== e.runId || t.requestId !== e.requestId) throw Error("Workflow restart receipt belongs to another intent");
|
|
541
|
+
if (e.selection !== void 0 && "selection" in t && (t.selection.kind !== e.selection.kind || t.selection.kind === "from-step" && e.selection.kind === "from-step" && t.selection.stepName !== e.selection.stepName)) throw Error("Workflow restart receipt changed the saved selection");
|
|
542
|
+
}, q = (e, t) => ({
|
|
543
|
+
...e,
|
|
544
|
+
startsDeferredUntilCommit: !0,
|
|
545
|
+
start: async (n, r, i) => {
|
|
546
|
+
if (i?.wait) throw Error("ctx.workflows.start(..., { wait: true }) is not allowed inside a mutation transaction; start the workflow and wait after commit.");
|
|
547
|
+
return e.start(n, r, {
|
|
548
|
+
...i,
|
|
549
|
+
enqueueStart: t
|
|
550
|
+
});
|
|
551
|
+
},
|
|
552
|
+
child: async (n, r, i) => {
|
|
553
|
+
if (i?.wait) throw Error("ctx.workflows.child(..., { wait: true }) is not allowed inside a mutation transaction; start the child workflow and wait after commit.");
|
|
554
|
+
return e.child(n, r, {
|
|
555
|
+
...i,
|
|
556
|
+
enqueueStart: t
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
run: async () => {
|
|
560
|
+
throw Error("ctx.workflows.run(...) is not allowed inside a mutation transaction; use ctx.workflows.start(...) so the workflow starts after commit.");
|
|
561
|
+
},
|
|
562
|
+
wait: async () => {
|
|
563
|
+
throw Error("ctx.workflows.wait(...) is not allowed inside a mutation transaction; wait after commit.");
|
|
564
|
+
},
|
|
565
|
+
restart: async () => {
|
|
566
|
+
throw Error("Restart workflows after the mutation transaction commits");
|
|
567
|
+
},
|
|
568
|
+
readRestart: async () => {
|
|
569
|
+
throw Error("Observe workflow restart after the mutation transaction commits");
|
|
570
|
+
},
|
|
571
|
+
withdrawRestart: async () => {
|
|
572
|
+
throw Error("Withdraw workflow restart after the mutation transaction commits");
|
|
573
|
+
},
|
|
574
|
+
cancelQueued: async () => {
|
|
575
|
+
throw Error("Cancel queued workflows after the mutation transaction commits");
|
|
576
|
+
},
|
|
577
|
+
readQueuedCancellation: async () => {
|
|
578
|
+
throw Error("Observe queued cancellation after the mutation transaction commits");
|
|
579
|
+
},
|
|
580
|
+
readStart: async () => {
|
|
581
|
+
throw Error("Observe a start after the mutation transaction commits; its receipt is provisional until then");
|
|
582
|
+
}
|
|
583
|
+
}), J = (e, t) => ({
|
|
584
|
+
...e,
|
|
585
|
+
cancelQueued: (n, r) => e.cancelQueued(n, {
|
|
586
|
+
...r,
|
|
587
|
+
callerContext: t
|
|
588
|
+
}),
|
|
589
|
+
readQueuedCancellation: (n, r) => e.readQueuedCancellation(n, {
|
|
590
|
+
...r,
|
|
591
|
+
callerContext: t
|
|
592
|
+
}),
|
|
593
|
+
readStart: (n, r) => e.readStart(n, {
|
|
594
|
+
...r,
|
|
595
|
+
callerContext: t
|
|
596
|
+
}),
|
|
597
|
+
start: (n, r, i) => e.start(n, r, {
|
|
598
|
+
...i,
|
|
599
|
+
callerContext: t
|
|
600
|
+
}),
|
|
601
|
+
child: (n, r, i) => e.child(n, r, {
|
|
602
|
+
...i,
|
|
603
|
+
callerContext: t
|
|
604
|
+
}),
|
|
605
|
+
run: (n, r, i) => e.run(n, r, {
|
|
606
|
+
...i,
|
|
607
|
+
callerContext: t
|
|
608
|
+
}),
|
|
609
|
+
wait: ((n, r, i) => typeof n == "string" ? e.wait(n, r, {
|
|
610
|
+
...i,
|
|
611
|
+
callerContext: t
|
|
612
|
+
}) : e.wait(n, {
|
|
613
|
+
...r,
|
|
614
|
+
callerContext: t
|
|
615
|
+
}))
|
|
616
|
+
}), Y = (e) => {
|
|
617
|
+
let t = () => {
|
|
618
|
+
let t = e();
|
|
619
|
+
if (!t) throw Error("Workflow runtime is not ready yet");
|
|
620
|
+
return t;
|
|
621
|
+
};
|
|
622
|
+
return {
|
|
623
|
+
start: (e, n, r) => t().start(e, n, r),
|
|
624
|
+
child: (e, n, r) => t().child(e, n, r),
|
|
625
|
+
run: (e, n, r) => t().run(e, n, r),
|
|
626
|
+
executionId: (e, n) => t().executionId(e, n),
|
|
627
|
+
poll: (e, n) => t().poll(e, n),
|
|
628
|
+
query: (e, n) => t().query(e, n),
|
|
629
|
+
wait: ((e, n, r) => typeof e == "string" ? t().wait(e, n, r) : t().wait(e, n)),
|
|
630
|
+
cancel: (e, n, r) => t().cancel(e, n, r),
|
|
631
|
+
resume: (e, n, r) => t().resume(e, n, r),
|
|
632
|
+
readControl: (e) => t().readControl(e),
|
|
633
|
+
cancelQueued: (e, n) => t().cancelQueued(e, n),
|
|
634
|
+
readQueuedCancellation: (e, n) => t().readQueuedCancellation(e, n),
|
|
635
|
+
readStart: (e, n) => t().readStart(e, n),
|
|
636
|
+
signal: (e, n, r) => t().signal(e, n, r),
|
|
637
|
+
update: (e, n, r, i) => t().update(e, n, r, i),
|
|
638
|
+
listRuns: ((e) => t().listRuns(e)),
|
|
639
|
+
readRetry: (e, n) => t().readRetry(e, n),
|
|
640
|
+
retry: (e, n) => t().retry(e, n),
|
|
641
|
+
restart: (e, n) => t().restart(e, n),
|
|
642
|
+
readRestart: (e, n) => t().readRestart(e, n),
|
|
643
|
+
withdrawRestart: (e, n) => t().withdrawRestart(e, n)
|
|
644
|
+
};
|
|
645
|
+
}, X = (e, t) => {
|
|
646
|
+
let n = {};
|
|
647
|
+
for (let r of e) n[r.definition.name] = (e) => (t ? a.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(a.map((e) => M(r.definition.name, e, "running")))).pipe(a.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
|
|
648
|
+
return n;
|
|
649
|
+
}, Z = (o, c, l) => o.map((o) => o.definition.toLayer(((u, f) => {
|
|
650
|
+
let p, m = a.suspend(() => {
|
|
651
|
+
let e = c.resolveStartContext?.(o.definition.name, f);
|
|
652
|
+
return e === void 0 ? a.succeed(void 0) : a.promise(() => Promise.resolve(e));
|
|
653
|
+
}), h = (e) => c.reportExecutionRefusal?.({
|
|
654
|
+
workflowName: o.definition.name,
|
|
655
|
+
executionId: f,
|
|
656
|
+
reason: e
|
|
657
|
+
});
|
|
658
|
+
return m.pipe(a.flatMap((e) => {
|
|
659
|
+
p = e;
|
|
660
|
+
let t = e?.subject;
|
|
661
|
+
return c.resolveStartContext !== void 0 && t == null ? a.die(/* @__PURE__ */ Error("workflow start context is missing its caller identity; execution refused")) : typeof t == "object" && t && "type" in t && t.type === "system" ? n.type === "system" ? a.succeed({
|
|
662
|
+
callerContext: e,
|
|
663
|
+
subject: {
|
|
664
|
+
...t,
|
|
665
|
+
scopes: n.scopes
|
|
666
|
+
}
|
|
667
|
+
}) : a.die(/* @__PURE__ */ Error("workflow system authority is invalid; execution refused")) : t == null || c.resolveAuthority === void 0 ? a.succeed({
|
|
668
|
+
callerContext: e,
|
|
669
|
+
subject: t ?? n
|
|
670
|
+
}) : a.tryPromise({
|
|
671
|
+
try: () => c.resolveAuthority(t),
|
|
672
|
+
catch: (e) => e
|
|
673
|
+
}).pipe(a.map((t) => ({
|
|
674
|
+
callerContext: e,
|
|
675
|
+
subject: t
|
|
676
|
+
})));
|
|
677
|
+
}), a.flatMap(({ callerContext: n, subject: r }) => t(e(), r).pipe(a.map((e) => ({
|
|
678
|
+
callerContext: n,
|
|
679
|
+
subject: r,
|
|
680
|
+
rowFilter: e
|
|
681
|
+
})))), a.catchCause((e) => a.sync(() => h(i.pretty(e))).pipe(a.andThen(a.suspend(() => p?.subject == null || c.onExecutionRefusal === void 0 ? a.failCause(e) : c.onExecutionRefusal({
|
|
682
|
+
workflowName: o.definition.name,
|
|
683
|
+
executionId: f,
|
|
684
|
+
payload: u,
|
|
685
|
+
cause: e,
|
|
686
|
+
callerContext: p
|
|
687
|
+
}).pipe(a.andThen(a.failCause(e))))))), a.flatMap(({ callerContext: e, subject: t, rowFilter: n }) => {
|
|
688
|
+
let i = {
|
|
689
|
+
...e,
|
|
690
|
+
subject: t,
|
|
691
|
+
traceId: e?.traceId ?? "workflow-bootstrap",
|
|
692
|
+
rowFilter: n
|
|
693
|
+
}, p = (t, n, s) => a.suspend(() => {
|
|
694
|
+
let l = c.buildContext(i, {
|
|
695
|
+
workflowName: o.definition.name,
|
|
696
|
+
executionId: n,
|
|
697
|
+
...s === void 0 ? {} : { generation: s },
|
|
698
|
+
parentExecutionId: e?.parentExecutionId ?? null,
|
|
699
|
+
parentGeneration: e?.parentGeneration ?? null,
|
|
700
|
+
parentClosePolicy: e?.parentClosePolicy ?? null
|
|
701
|
+
}), u = o.buildExecute(l)(t, n), d = l?.store;
|
|
702
|
+
return d === void 0 ? u : a.provide(u, r(d));
|
|
703
|
+
}), m = (l?.(o, p, i) ?? p)(u, f), h = s.succeed(d, i.subject);
|
|
704
|
+
return a.provide(m, h);
|
|
705
|
+
}));
|
|
706
|
+
})));
|
|
707
|
+
//#endregion
|
|
708
|
+
export { V as WorkflowPayloadError, P as WorkflowRateLimitedError, F as WorkflowSingletonHeldError, E as WorkflowStartNotExecuted, Y as makeLazyWorkflowFacade, q as makeTransactionalWorkflowFacade, G as makeWorkflowFacade, J as makeWorkflowFacadeWithCallerContext, X as makeWorkflowHandlers, Z as makeWorkflowLayers, L as makeWorkflowRunHandle, U as payloadPropertyNames };
|