@voltro/workflow 0.83.1 → 0.85.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.
@@ -1,10 +1,10 @@
1
- import { C as e, S as t, _ as n, b as r, l as i, m as a } from "./journalEncryption--n5VDdYO.js";
1
+ import { C as e, S as t, _ as n, b as r, l as i, m as a } from "./journalEncryption-DTyhUzaS.js";
2
2
  import { Context as o, Effect as s, Schema as c } from "effect";
3
3
  import { WorkflowRestartObservationSchema as l, WorkflowRestartSelectionSchema as u, WorkflowRestartTargetSchema as d, WorkflowStartTerminalOutcomeSchema as f } from "@voltro/protocol";
4
4
  import { and as p, derivedRowId as m, eq as h, gt as g, id as _, integer as ee, isNull as v, json as y, or as te, table as ne, text as b, timestamp as re } from "@voltro/database";
5
5
  import { createHash as ie, randomUUID as x } from "node:crypto";
6
6
  import { isDeepStrictEqual as ae } from "node:util";
7
- import { SqlClient as S } from "@effect/sql";
7
+ import { SqlClient as S } from "effect/sql";
8
8
  //#region src/admissionTransaction.ts
9
9
  var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t) => (await e.insertIgnoreWithOutcome(oe, {
10
10
  id: se,
@@ -162,7 +162,11 @@ var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t)
162
162
  workflowName: c.String,
163
163
  tenantId: c.NullOr(c.String),
164
164
  sourceId: c.String,
165
- sourceKind: c.Literal("submission", "intent", "run"),
165
+ sourceKind: c.Literals([
166
+ "submission",
167
+ "intent",
168
+ "run"
169
+ ]),
166
170
  handler: c.NullOr(c.String),
167
171
  callerContext: c.Unknown,
168
172
  report: c.Struct({
@@ -245,7 +249,7 @@ var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t)
245
249
  return !1;
246
250
  }, Ce = c.Struct({
247
251
  handoffReceiptId: c.NullOr(c.String),
248
- handoffAttempt: c.NonNegativeInt,
252
+ handoffAttempt: c.Number.check(c.isInt(), c.isGreaterThanOrEqualTo(0)),
249
253
  acceptedExecutionId: c.NullOr(c.NonEmptyString)
250
254
  }), we = (e, t) => `wfrc_${ie("sha256").update(JSON.stringify([
251
255
  "failure",
@@ -382,8 +386,12 @@ var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t)
382
386
  workflowName: c.NonEmptyString,
383
387
  executionId: c.NonEmptyString,
384
388
  generation: c.NonEmptyString,
385
- parentStatus: c.Literal("succeeded", "failed", "cancelled"),
386
- closedAt: c.DateFromSelf
389
+ parentStatus: c.Literals([
390
+ "succeeded",
391
+ "failed",
392
+ "cancelled"
393
+ ]),
394
+ closedAt: c.Date
387
395
  }), Ae = async (e, t, n) => {
388
396
  let [r] = await e.query({
389
397
  table: "_voltro_workflow_runs",
@@ -440,7 +448,7 @@ var oe = "_voltro_workflow_admission_locks", se = "deployment", C = async (e, t)
440
448
  executionId: c.NullOr(c.String),
441
449
  runId: c.NullOr(c.String),
442
450
  receiptsBound: c.Boolean,
443
- dispatchAttempts: c.NonNegativeInt,
451
+ dispatchAttempts: c.Number.check(c.isInt(), c.isGreaterThanOrEqualTo(0)),
444
452
  failureId: c.NullOr(c.String),
445
453
  retry: c.Struct({
446
454
  attempts: c.Int,
@@ -706,8 +714,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
706
714
  pendingId: c.String,
707
715
  submissionId: c.NullOr(c.String),
708
716
  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) => {
717
+ requestFingerprint: c.optional(c.NullOr(c.String.pipe(c.check(c.isPattern(/^[a-f0-9]{64}$/)))))
718
+ }).pipe(c.check(c.makeFilter((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) => {
711
719
  let n = await e.query({
712
720
  table: N,
713
721
  predicate: h("id", t),
@@ -1161,27 +1169,28 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1161
1169
  direction: "asc"
1162
1170
  }], n)), i = t.getTime(), a = r.filter((e) => e.releasedAt != null && B(e.admittedAt) < i);
1163
1171
  return await Promise.all(a.map((t) => e.delete(L, String(t.id)))), a.length;
1164
- }, G = "_voltro_workflow_control_requests", K = c.String.pipe(c.minLength(1)), wt = c.Struct({
1165
- kind: c.Literal("confirmed", "already-terminal"),
1166
- status: c.Literal("succeeded", "failed", "cancelled"),
1167
- completedAt: c.Number.pipe(c.finite()),
1172
+ }, G = "_voltro_workflow_control_requests", K = c.String.pipe(c.check(c.isMinLength(1))), wt = c.Struct({
1173
+ kind: c.Literals(["confirmed", "already-terminal"]),
1174
+ status: c.Literals([
1175
+ "succeeded",
1176
+ "failed",
1177
+ "cancelled"
1178
+ ]),
1179
+ completedAt: c.Number.pipe(c.check(c.isFinite())),
1168
1180
  output: c.Unknown,
1169
1181
  errorTag: c.NullOr(c.String),
1170
1182
  errorMessage: c.NullOr(c.String)
1171
1183
  }), Tt = c.Struct({
1172
1184
  kind: c.Literal("confirmed"),
1173
1185
  status: c.Literal("running"),
1174
- enteredAt: c.Number.pipe(c.finite()),
1186
+ enteredAt: c.Number.pipe(c.check(c.isFinite())),
1175
1187
  generation: K
1176
- }), Et = c.Union(wt, Tt), Dt = c.Struct({
1188
+ }), Et = c.Union([wt, Tt]), Dt = c.Struct({
1177
1189
  reason: c.NonEmptyString,
1178
- detail: c.optional(c.Record({
1179
- key: c.String,
1180
- value: c.Unknown
1181
- }))
1190
+ detail: c.optional(c.Record(c.String, c.Unknown))
1182
1191
  }), Ot = c.Struct({ tenantId: c.NullOr(c.String) }), q = c.Struct({
1183
- requestId: c.String.pipe(c.pattern(/^[1-9]\d*$/)),
1184
- replyId: c.String.pipe(c.pattern(/^[1-9]\d*$/)),
1192
+ requestId: c.String.pipe(c.check(c.isPattern(/^[1-9]\d*$/))),
1193
+ replyId: c.String.pipe(c.check(c.isPattern(/^[1-9]\d*$/))),
1185
1194
  restartToken: c.NullOr(c.NonEmptyString)
1186
1195
  }), kt = c.Struct({
1187
1196
  id: K,
@@ -1189,16 +1198,20 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1189
1198
  workflowName: K,
1190
1199
  executionId: K,
1191
1200
  generation: K,
1192
- operation: c.Literal("cancel", "terminate", "resume"),
1193
- requestedAt: c.Number.pipe(c.finite()),
1201
+ operation: c.Literals([
1202
+ "cancel",
1203
+ "terminate",
1204
+ "resume"
1205
+ ]),
1206
+ requestedAt: c.Number.pipe(c.check(c.isFinite())),
1194
1207
  owner: c.NullOr(Ot),
1195
1208
  cause: c.optional(c.NullOr(Dt)),
1196
- dispatchAttempts: c.Number.pipe(c.int(), c.nonNegative()),
1209
+ dispatchAttempts: c.Number.pipe(c.check(c.isInt()), c.check(c.isGreaterThanOrEqualTo(0))),
1197
1210
  resumeJournal: c.NullOr(q),
1198
1211
  result: c.NullOr(Et)
1199
1212
  }), At = c.Struct({
1200
1213
  ...kt.fields,
1201
- requestedAt: c.DateFromSelf
1214
+ requestedAt: c.Date
1202
1215
  }), J = (e) => {
1203
1216
  let t = c.decodeUnknownSync(At)(e);
1204
1217
  return c.decodeUnknownSync(kt)({
@@ -1330,7 +1343,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1330
1343
  result: c.decodeUnknownSync(Et)({
1331
1344
  kind: "already-terminal",
1332
1345
  status: a.status,
1333
- completedAt: c.decodeUnknownSync(c.DateFromSelf)(a.completedAt).getTime(),
1346
+ completedAt: c.decodeUnknownSync(c.Date)(a.completedAt).getTime(),
1334
1347
  output: a.output,
1335
1348
  errorTag: a.errorTag,
1336
1349
  errorMessage: a.errorMessage
@@ -1516,7 +1529,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1516
1529
  if (typeof o.id != "string") throw Error("Workflow control cursor has an invalid identity");
1517
1530
  a = o.id;
1518
1531
  }
1519
- }, Wt = "voltro-workflow-restart", Gt = class extends o.Tag("voltro/CurrentWorkflowDelivery")() {}, Kt = (e) => ({
1532
+ }, Wt = "voltro-workflow-restart", Gt = class extends o.Service()("voltro/CurrentWorkflowDelivery") {}, Kt = (e) => ({
1520
1533
  ...e,
1521
1534
  registerEntity: (t, n, r) => e.registerEntity(t, t.type.startsWith("Workflow/") ? n.pipe(s.map((e) => {
1522
1535
  let t = e.run;
@@ -1535,13 +1548,10 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1535
1548
  }
1536
1549
  };
1537
1550
  })) : n, r)
1538
- }), qt = c.parseJson(c.Struct({
1551
+ }), qt = c.fromJsonString(c.Struct({
1539
1552
  _tag: c.Literal("Success"),
1540
1553
  value: c.Struct({ _tag: c.Literal("Suspended") })
1541
- })), Jt = c.parseJson(c.Record({
1542
- key: c.String,
1543
- value: c.String
1544
- })), Yt = (e) => s.gen(function* () {
1554
+ })), Jt = c.fromJsonString(c.Record(c.String, c.String)), Yt = (e) => s.gen(function* () {
1545
1555
  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"));
1546
1556
  let [t] = yield* (yield* S.SqlClient).withoutTransforms()`
1547
1557
  SELECT m.entity_type, m.entity_id, m.tag, m.headers, r.id AS reply_id, r.payload
@@ -1600,10 +1610,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1600
1610
  let [e] = yield* o`
1601
1611
  SELECT entity_type, entity_id, tag, headers FROM ${l} WHERE id = ${r.requestId}`;
1602
1612
  if (e?.entity_type !== `Workflow/${r.workflowName}` || e.entity_id !== r.executionId || e.tag !== "run" || r.workflowName.length === 0 || r.executionId.length === 0) return yield* s.die(/* @__PURE__ */ Error("Journal resume selection belongs to another execution or procedure"));
1603
- if (((yield* s.sync(() => c.decodeUnknownSync(c.parseJson(c.Record({
1604
- key: c.String,
1605
- value: c.String
1606
- })))(e.headers)))["voltro-workflow-restart"] ?? null) !== r.restartToken) return {
1613
+ if (((yield* s.sync(() => c.decodeUnknownSync(c.fromJsonString(c.Record(c.String, c.String)))(e.headers)))["voltro-workflow-restart"] ?? null) !== r.restartToken) return {
1607
1614
  kind: "changed",
1608
1615
  requestId: r.requestId
1609
1616
  };
@@ -1612,10 +1619,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1612
1619
  let [e] = yield* o`
1613
1620
  SELECT tag, entity_type, headers FROM ${l} WHERE id = ${n.requestId}`;
1614
1621
  if (e?.tag !== "run" || !e.entity_type.startsWith("Workflow/")) return yield* s.die(/* @__PURE__ */ Error("Journal restart marker can only target a workflow run"));
1615
- if (t = yield* s.sync(() => c.decodeUnknownSync(c.parseJson(c.Record({
1616
- key: c.String,
1617
- value: c.String
1618
- })))(e.headers)), t["voltro-workflow-restart"] === n.token) return {
1622
+ if (t = yield* s.sync(() => c.decodeUnknownSync(c.fromJsonString(c.Record(c.String, c.String)))(e.headers)), t["voltro-workflow-restart"] === n.token) return {
1619
1623
  kind: "already-reset",
1620
1624
  count: a.length
1621
1625
  };
@@ -1683,7 +1687,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1683
1687
  workflowName: c.NonEmptyString,
1684
1688
  tenantId: c.NullOr(c.NonEmptyString),
1685
1689
  selection: $,
1686
- withdrawnAt: c.DateFromSelf
1690
+ withdrawnAt: c.Date
1687
1691
  }), nn = async (e, t) => {
1688
1692
  let n = c.decodeUnknownSync(d)(t), [r] = await e.query({
1689
1693
  table: en.tableName,
@@ -1717,8 +1721,8 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
1717
1721
  executionId: Z,
1718
1722
  runId: c.String
1719
1723
  })),
1720
- requestedAt: c.DateFromSelf,
1721
- dispatchAttempts: c.NonNegativeInt,
1724
+ requestedAt: c.Date,
1725
+ dispatchAttempts: c.Number.check(c.isInt(), c.isGreaterThanOrEqualTo(0)),
1722
1726
  enteredGeneration: c.NullOr(Z)
1723
1727
  }), on = (e, t) => e.kind === t.kind && (e.kind === "failed-steps" || t.kind === "from-step" && e.stepName === t.stepName), sn = async (e, t) => {
1724
1728
  let n = c.decodeUnknownSync(d)(t), [r] = await e.query({
@@ -2064,7 +2068,7 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
2064
2068
  }
2065
2069
  })
2066
2070
  };
2067
- }, _n = 6e5, vn = class extends o.Tag("@voltro/workflow/ClusterDiagnostics")() {}, yn = (e, t, n = Date.now()) => s.flatMap(e.messagesFor(t), (t) => {
2071
+ }, _n = 6e5, vn = class extends o.Service()("@voltro/workflow/ClusterDiagnostics") {}, yn = (e, t, n = Date.now()) => s.flatMap(e.messagesFor(t), (t) => {
2068
2072
  if (t.length === 0) return s.succeed(void 0);
2069
2073
  let r = [...new Set(t.filter((e) => !e.processed).map((e) => e.shardId))], i = r.length === 0 ? s.succeed([]) : e.shardLockHolders(r);
2070
2074
  return s.map(i, (r) => ({
@@ -2079,6 +2083,14 @@ var Fe = async (e, t, n) => (await Ie(e, t, n)).map((e) => Ne(e)), Ie = async (e
2079
2083
  })),
2080
2084
  shardLocks: r
2081
2085
  }));
2082
- });
2086
+ }), bn = (e) => e.findLast((e, t, n) => t in n && e._tag === "WithExit"), xn = (e) => {
2087
+ let t = /* @__PURE__ */ new Set();
2088
+ for (let n of e) {
2089
+ if (n.eventType !== "update-completed" && n.eventType !== "update-failed") continue;
2090
+ let e = n.payload?.updateId;
2091
+ typeof e == "string" && e.length > 0 && t.add(e);
2092
+ }
2093
+ return t;
2094
+ };
2083
2095
  //#endregion
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 };
2096
+ export { rt as $, Ht as A, Le as At, _t as B, ve as Bt, Bt as C, Ue as Ct, Nt as D, M as Dt, Rt as E, He as Et, I as F, Se as Ft, yt as G, me as Gt, pt as H, ge as Ht, ht as I, xe as It, nt as J, ue as Jt, lt as K, de as Kt, bt as L, Oe as Lt, L as M, Ae as Mt, tt as N, k as Nt, Mt as O, Ie as Ot, R as P, O as Pt, ot as Q, et as R, E as Rt, Vt as S, Me as St, Pt as T, ze as Tt, z as U, fe as Ut, vt as V, ce as Vt, St as W, he as Wt, ct as X, mt as Y, C as Yt, Ct as Z, Gt as _, Be as _t, yn as a, H as at, Ft as b, Ne as bt, cn as c, Qe as ct, hn as d, Ye as dt, dt as et, un as f, Ze as ft, Qt as g, je as gt, Yt as h, Ke as ht, vn as i, xt as it, Ut as j, Re as jt, Y as k, Ge as kt, dn as l, P as lt, en as m, $e as mt, xn as n, at as nt, gn as o, N as ot, X as p, Xe as pt, it as q, le as qt, _n as r, W as rt, ln as s, qe as st, bn as t, ft as tt, fn as u, F as ut, Wt as v, Ve as vt, Lt as w, Fe as wt, zt as x, Pe as xt, Kt as y, We as yt, gt as z, D as zt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/workflow",
3
- "version": "0.83.1",
3
+ "version": "0.85.0",
4
4
  "description": "Durable workflows for Voltro — the workflow() descriptor + step() / awaitSignal primitives over @effect/cluster, with a browser-safe define subpath.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -48,16 +48,13 @@
48
48
  "node": ">=24.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@effect/cluster": "^0.60.2",
52
- "@effect/sql": "^0.52.1",
53
- "@effect/workflow": "^0.19.1",
54
- "@voltro/database": "0.83.1",
55
- "@voltro/logger": "0.83.1",
56
- "@voltro/protocol": "0.83.1"
51
+ "@voltro/database": "0.85.0",
52
+ "@voltro/logger": "0.85.0",
53
+ "@voltro/protocol": "0.85.0"
57
54
  },
58
55
  "peerDependencies": {
59
- "effect": "^3.22.2",
60
- "vitest": "^5.0.0"
56
+ "effect": "4.0.1",
57
+ "vitest": ">=3.0.0"
61
58
  },
62
59
  "peerDependenciesMeta": {
63
60
  "vitest": {