@voltro/runtime 0.39.0 → 0.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Cause as e, Clock as t, Context as n, Cron as r, Deferred as i, Duration as a, Effect as o, Either as s, Exit as c, Fiber as l, Layer as u, ManagedRuntime as d, Metric as f, MetricBoundaries as p, MetricState as m, Option as h, Queue as g, Ref as _, Schedule as v, Schema as y, Stream as b, Tracer as x } from "effect";
2
- import { ENCRYPTED_PREFIX as S, and as C, attachEagerLoads as w, attributionFields as T, boolean as E, clearRetentions as ee, collectSubqueries as D, contains as te, decryptFieldsOnRead as ne, deserializeArraysOnRead as re, encryptFieldsForWrite as ie, eq as O, evaluatePredicate as k, externalChangeEvent as ae, generateId as A, getRelations as oe, getTable as j, gt as se, gte as ce, hasEagerLoads as le, id as M, inSet as ue, integer as N, isEncrypted as de, isNull as fe, isTableReactive as pe, json as P, listRetentionConflicts as me, listRetentions as he, lt as ge, lte as _e, missingConflictColumns as ve, missingRequiredColumns as ye, neq as be, or as xe, planVersionedUpdate as Se, queryFor as Ce, raiseChangeListenerCeiling as we, readableByColumns as Te, registerRetention as Ee, registerRetention as De, requireTable as Oe, retentionTtlMsFromEnv as ke, retentionTtlMsFromEnv as Ae, runWithWriteAttribution as je, serializeArraysForWrite as Me, serverOnlyColumns as Ne, settleVersionedUpdate as Pe, stampGeneratedId as Fe, startsWith as Ie, sweepRetention as Le, table as F, text as I, timestamp as L, walkLeaves as Re } from "@voltro/database";
3
- import { createCipheriv as ze, createDecipheriv as Be, createHash as Ve, randomBytes as He, randomUUID as Ue, scryptSync as We } from "node:crypto";
4
- import { EventEmitter as Ge } from "node:events";
5
- import { ADMIN_SCOPE as Ke, APIKEY_ISSUE_ORG_SCOPE as qe, APIKEY_ISSUE_OTHER_SCOPE as Je, APIKEY_ISSUE_SELF_SCOPE as Ye, ApprovalExpired as Xe, ApprovalForbidden as Ze, ApprovalNotFound as Qe, ApprovalNotPending as $e, ApprovalRejected as et, ApprovalRequired as tt, ApprovalSelfApproval as nt, ApprovalUnavailable as rt, AuthMiddleware as it, BusinessRuleViolation as at, ConnectionHandshakeFailed as R, ConnectionInfo as ot, ConnectionInfoMiddleware as st, ConnectionKindMismatch as ct, ConnectionNotDeclared as lt, ConnectionSubjectRequired as ut, EventKeyInvalid as dt, EventPayloadInvalid as ft, EventPayloadTooLarge as pt, MAX_EVENT_ENVELOPE_BYTES as mt, ScopeError as ht, SubjectService as gt, UndoConflict as _t, UndoForbidden as vt, UndoNotFound as yt, WorkflowRunHandleSchema as bt, beginIdempotent as xt, checkGuardsEffect as z, declaredReactivityChannelKeys as St, diffRows as Ct, effectiveScopes as wt, eventRoute as Tt, failIdempotent as Et, finishIdempotent as Dt, hasEffectiveScope as Ot, isIdKeyed as kt, isOpenAccess as At, isPolicyGuard as jt, isReactivityChannelKey as Mt, parseEventRoute as Nt, publishServerError as Pt, requireScope as Ft, setPolicyGuardResolver as It, sourceKeys as Lt, strictInput as Rt, systemSubject as zt, tsMs as Bt, wsMutationIdempotencyScope as Vt } from "@voltro/protocol";
2
+ import { ENCRYPTED_PREFIX as S, and as C, attachEagerLoads as w, attributionFields as T, boolean as E, clearRetentions as ee, collectSubqueries as D, contains as te, decryptFieldsOnRead as ne, deserializeArraysOnRead as re, encryptFieldsForWrite as ie, eq as O, evaluatePredicate as k, externalChangeEvent as ae, generateId as A, getRelations as oe, getTable as j, gt as M, gte as se, hasEagerLoads as ce, id as N, inSet as le, integer as P, isEncrypted as ue, isNull as de, isTableReactive as fe, json as F, listRetentionConflicts as pe, listRetentions as me, lt as he, lte as ge, missingConflictColumns as _e, missingRequiredColumns as ve, neq as ye, or as be, planVersionedUpdate as xe, queryFor as Se, raiseChangeListenerCeiling as Ce, readableByColumns as we, registerRetention as Te, registerRetention as Ee, requireTable as De, retentionTtlMsFromEnv as Oe, retentionTtlMsFromEnv as ke, runWithWriteAttribution as Ae, serializeArraysForWrite as je, serverOnlyColumns as Me, settleVersionedUpdate as Ne, stampGeneratedId as Pe, startsWith as Fe, sweepRetention as Ie, table as I, text as L, timestamp as R, walkLeaves as Le } from "@voltro/database";
3
+ import { createCipheriv as Re, createDecipheriv as ze, createHash as Be, randomBytes as Ve, randomUUID as He, scryptSync as Ue } from "node:crypto";
4
+ import { EventEmitter as We } from "node:events";
5
+ import { ADMIN_SCOPE as Ge, APIKEY_ISSUE_ORG_SCOPE as Ke, APIKEY_ISSUE_OTHER_SCOPE as qe, APIKEY_ISSUE_SELF_SCOPE as Je, ApprovalExpired as Ye, ApprovalForbidden as Xe, ApprovalNotFound as Ze, ApprovalNotPending as Qe, ApprovalRejected as $e, ApprovalRequired as et, ApprovalSelfApproval as tt, ApprovalUnavailable as nt, AuthMiddleware as rt, BusinessRuleViolation as it, ConnectionHandshakeFailed as z, ConnectionInfo as at, ConnectionInfoMiddleware as ot, ConnectionKindMismatch as st, ConnectionNotDeclared as ct, ConnectionSubjectRequired as lt, EventKeyInvalid as ut, EventPayloadInvalid as dt, EventPayloadTooLarge as ft, MAX_EVENT_ENVELOPE_BYTES as pt, ScopeError as mt, SubjectService as ht, UndoConflict as gt, UndoForbidden as _t, UndoNotFound as vt, WorkflowRunHandleSchema as yt, beginIdempotent as bt, checkGuardsEffect as xt, declaredReactivityChannelKeys as St, diffRows as Ct, effectiveScopes as wt, eventRoute as Tt, failIdempotent as Et, finishIdempotent as Dt, hasEffectiveScope as Ot, isIdKeyed as kt, isOpenAccess as At, isPolicyGuard as jt, isReactivityChannelKey as Mt, parseEventRoute as Nt, publishServerError as Pt, requireScope as Ft, setPolicyGuardResolver as It, sourceKeys as Lt, strictInput as Rt, systemSubject as zt, tsMs as Bt, wsMutationIdempotencyScope as Vt } from "@voltro/protocol";
6
6
  import { createLogger as B, log as Ht } from "@voltro/logger";
7
7
  import { AsyncLocalStorage as Ut } from "node:async_hooks";
8
8
  import * as Wt from "node:http";
@@ -66,7 +66,7 @@ var En = (e) => {
66
66
  }
67
67
  }, On = (e) => {
68
68
  let t = [];
69
- for (let n of Re(e)) n.conjunctive && n.path === void 0 && (n.op === "eq" && t.push({
69
+ for (let n of Le(e)) n.conjunctive && n.path === void 0 && (n.op === "eq" && t.push({
70
70
  column: n.column,
71
71
  values: [n.value]
72
72
  }), n.op === "in" && t.push({
@@ -76,14 +76,14 @@ var En = (e) => {
76
76
  return t;
77
77
  }, kn = (e) => {
78
78
  let t = [];
79
- for (let n of Re(e)) n.conjunctive && n.path === void 0 && (n.op === "gt" || n.op === "gte" || n.op === "lt" || n.op === "lte") && t.push({
79
+ for (let n of Le(e)) n.conjunctive && n.path === void 0 && (n.op === "gt" || n.op === "gte" || n.op === "lt" || n.op === "lte") && t.push({
80
80
  column: n.column,
81
81
  op: n.op,
82
82
  threshold: n.value
83
83
  });
84
84
  return t;
85
85
  }, An = (e, t) => {
86
- for (let n of Re(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
86
+ for (let n of Le(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
87
87
  return null;
88
88
  }, jn = (e, t) => {
89
89
  let n = [];
@@ -317,7 +317,7 @@ var En = (e) => {
317
317
  predicate: t,
318
318
  indexHint: n ?? null
319
319
  });
320
- return Ve("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
320
+ return Be("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
321
321
  }, Ln = class {
322
322
  matcher;
323
323
  byFingerprint = /* @__PURE__ */ new Map();
@@ -532,7 +532,7 @@ var En = (e) => {
532
532
  #e;
533
533
  #t;
534
534
  #n(e) {
535
- pe(e.table) && this.#t.emit("change", {
535
+ fe(e.table) && this.#t.emit("change", {
536
536
  ...T(),
537
537
  ...e
538
538
  });
@@ -544,7 +544,7 @@ var En = (e) => {
544
544
  return r.#e = t.tables, r.#t = t.emitter, r.#r = t.numericCounters, r;
545
545
  }
546
546
  constructor(e, t = null) {
547
- if (this.#i = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new Ge(), we(this.#t), this.#r = /* @__PURE__ */ new Map(), e) for (let [n, r] of Object.entries(e)) {
547
+ if (this.#i = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new We(), Ce(this.#t), this.#r = /* @__PURE__ */ new Map(), e) for (let [n, r] of Object.entries(e)) {
548
548
  let e = /* @__PURE__ */ new Map();
549
549
  for (let t of r) {
550
550
  let n = t.id;
@@ -574,10 +574,10 @@ var En = (e) => {
574
574
  }
575
575
  async query(e) {
576
576
  let t = Hn(e, this.#e.get(this.#o(e.table)) ?? /* @__PURE__ */ new Map(), this.#s());
577
- return le(e) ? w(t, e.eager, Oe(e.table), (e) => this.query(e)) : t;
577
+ return ce(e) ? w(t, e.eager, De(e.table), (e) => this.query(e)) : t;
578
578
  }
579
579
  async insert(e, t) {
580
- t = Fe(e, t);
580
+ t = Pe(e, t);
581
581
  let n = t;
582
582
  if (n.id === void 0) {
583
583
  let r = this.#l(e);
@@ -768,10 +768,10 @@ var En = (e) => {
768
768
  }
769
769
  async query(e) {
770
770
  let t = this.buildTablesView(e), n = Hn(e, this.materialise(e.table), t);
771
- return le(e) ? w(n, e.eager, Oe(e.table), (e) => this.query(e)) : n;
771
+ return ce(e) ? w(n, e.eager, De(e.table), (e) => this.query(e)) : n;
772
772
  }
773
773
  async insert(e, t) {
774
- t = Fe(e, t);
774
+ t = Pe(e, t);
775
775
  let n = t;
776
776
  n.id === void 0 && (n = {
777
777
  ...t,
@@ -1145,7 +1145,7 @@ var En = (e) => {
1145
1145
  };
1146
1146
  }, Si = (e) => {
1147
1147
  let t = j(e);
1148
- return t === void 0 ? [] : Ne(t);
1148
+ return t === void 0 ? [] : Me(t);
1149
1149
  }, Ci = (e, t) => {
1150
1150
  if (t.length === 0) return e;
1151
1151
  let n = !1, r = e.map((e) => {
@@ -1157,7 +1157,7 @@ var En = (e) => {
1157
1157
  }, wi = (e, t) => Ci(t, Si(e)), Ti = (e, t) => {
1158
1158
  let n = j(e);
1159
1159
  if (n === void 0) return [];
1160
- let r = Ne(n), i = Te(n);
1160
+ let r = Me(n), i = we(n);
1161
1161
  if (i.length === 0) return r;
1162
1162
  let a = [...r];
1163
1163
  for (let { column: e, scopes: n } of i) n.some((e) => Ot(t, e)) || a.push(e);
@@ -1188,7 +1188,7 @@ var En = (e) => {
1188
1188
  }
1189
1189
  }
1190
1190
  async subscribe(e, t, n, r, i, a, o, s) {
1191
- let c = `sub_${Ue()}`, l = i ?? `subscription.${e.table}`, u = lr(e), d = _r(e);
1191
+ let c = `sub_${He()}`, l = i ?? `subscription.${e.table}`, u = lr(e), d = _r(e);
1192
1192
  e.predicate !== void 0 && this.subscriptionRegistry.subscribe(c, e.table, e.predicate, r);
1193
1193
  for (let e of u) {
1194
1194
  let t = this.dependentByTable.get(e);
@@ -1272,7 +1272,7 @@ var En = (e) => {
1272
1272
  });
1273
1273
  }
1274
1274
  async subscribeComputed(e, t, n, r) {
1275
- let i = `csub_${Ue()}`, a = r ?? "subscription.computed", o = or(), s = new Set(e.dependentTables);
1275
+ let i = `csub_${He()}`, a = r ?? "subscription.computed", o = or(), s = new Set(e.dependentTables);
1276
1276
  for (let e of o) for (let t of e.dependsOn) s.add(t);
1277
1277
  let c = Array.from(s);
1278
1278
  this.warnUndeclaredRawReads(a, o.filter((e) => e.dependsOn.length === 0));
@@ -1609,17 +1609,17 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
1609
1609
  if (e.size === 0) return !1;
1610
1610
  for (let n of e) if (n in t) return !0;
1611
1611
  return !1;
1612
- }, ia = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : We(e, "voltro:field-encryption:v1", 32), aa = (e) => {
1612
+ }, ia = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : Ue(e, "voltro:field-encryption:v1", 32), aa = (e) => {
1613
1613
  if (e.length !== 32) throw Error(`field cipher key must be 32 bytes, got ${e.length}`);
1614
1614
  return {
1615
1615
  encrypt: (t) => {
1616
- let n = He(12), r = ze("aes-256-gcm", e, n), i = Buffer.concat([r.update(t, "utf8"), r.final()]), a = r.getAuthTag();
1616
+ let n = Ve(12), r = Re("aes-256-gcm", e, n), i = Buffer.concat([r.update(t, "utf8"), r.final()]), a = r.getAuthTag();
1617
1617
  return `${S}${n.toString("base64")}:${a.toString("base64")}:${i.toString("base64")}`;
1618
1618
  },
1619
1619
  decrypt: (t) => {
1620
1620
  let [n, r, i] = t.slice(S.length).split(":");
1621
1621
  if (!n || !r || i === void 0) throw Error("field cipher: malformed ciphertext");
1622
- let a = Be("aes-256-gcm", e, Buffer.from(n, "base64"));
1622
+ let a = ze("aes-256-gcm", e, Buffer.from(n, "base64"));
1623
1623
  return a.setAuthTag(Buffer.from(r, "base64")), Buffer.concat([a.update(Buffer.from(i, "base64")), a.final()]).toString("utf8");
1624
1624
  }
1625
1625
  };
@@ -1630,7 +1630,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
1630
1630
  if (!t) throw Error(`encryptField: ${la}`);
1631
1631
  return t.encrypt(e);
1632
1632
  }, da = (e) => {
1633
- if (!de(e)) return e;
1633
+ if (!ue(e)) return e;
1634
1634
  let t = K();
1635
1635
  if (!t) throw Error(`decryptField: ${la}`);
1636
1636
  return t.decrypt(e);
@@ -1699,21 +1699,21 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
1699
1699
  switch (n) {
1700
1700
  case "=": return O(t, r);
1701
1701
  case "!=":
1702
- case "<>": return be(t, r);
1703
- case ">": return se(t, r);
1704
- case ">=": return ce(t, r);
1705
- case "<": return ge(t, r);
1706
- case "<=": return _e(t, r);
1707
- case "in": return ue(t, r);
1702
+ case "<>": return ye(t, r);
1703
+ case ">": return M(t, r);
1704
+ case ">=": return se(t, r);
1705
+ case "<": return he(t, r);
1706
+ case "<=": return ge(t, r);
1707
+ case "in": return le(t, r);
1708
1708
  case "contains":
1709
1709
  case "fts": return te(t, r);
1710
- case "startsWith": return Ie(t, r);
1710
+ case "startsWith": return Fe(t, r);
1711
1711
  default: return O(t, r);
1712
1712
  }
1713
1713
  }, Oa = (e) => {
1714
1714
  let t = j(e);
1715
1715
  if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
1716
- return Ce(t);
1716
+ return Se(t);
1717
1717
  }, ka = class e {
1718
1718
  backend;
1719
1719
  scope;
@@ -1762,7 +1762,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
1762
1762
  }
1763
1763
  scopedQuery() {
1764
1764
  let e = this.query, { subject: t, schemaRegistry: n } = this.scope;
1765
- !this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(O("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(fe("deletedAt")));
1765
+ !this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(O("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(de("deletedAt")));
1766
1766
  let r = (this.scope.rowFilter ?? gi)(this.table);
1767
1767
  return r !== void 0 && (e = e.where(r)), e;
1768
1768
  }
@@ -1982,7 +1982,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
1982
1982
  let e = { deletedAt: /* @__PURE__ */ new Date() };
1983
1983
  return r !== null && (e.deletedBy = r), e;
1984
1984
  }, f = (e, t, n) => {
1985
- let r = ve(n, t);
1985
+ let r = _e(n, t);
1986
1986
  if (r.length !== 0) throw new Fa({
1987
1987
  table: e,
1988
1988
  summary: `upsert conflictColumns [${n.map((e) => `'${e}'`).join(", ")}] but the payload is missing ${r.map((e) => `'${e}'`).join(", ")}`,
@@ -1994,7 +1994,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
1994
1994
  }, p = (e, n) => {
1995
1995
  let r = j(e);
1996
1996
  if (r !== void 0) {
1997
- let t = ye(r, n);
1997
+ let t = ve(r, n);
1998
1998
  if (t.length > 0) throw new Fa({
1999
1999
  table: e,
2000
2000
  summary: `missing required column${t.length > 1 ? "s" : ""} ${t.map((e) => `'${e}'`).join(", ")} — NOT NULL with no default and not auto-stamped`,
@@ -2018,7 +2018,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2018
2018
  issues: o
2019
2019
  });
2020
2020
  }, m = t.dialect, h = (e, t) => {
2021
- let n = j(e), r = m ? Me(t, n, m) : t;
2021
+ let n = j(e), r = m ? je(t, n, m) : t;
2022
2022
  return ie(r, n, K());
2023
2023
  }, g = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", _ = B({ scope: "store.fieldEncryption" }), v = /* @__PURE__ */ new Set(), b = (e) => {
2024
2024
  let t = `${e.table}.${e.column}`;
@@ -2041,11 +2041,11 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2041
2041
  r = r ? C(r, e) : e;
2042
2042
  }
2043
2043
  if (!e.includeDeleted && t.schemaRegistry.hasSoftDelete(n)) {
2044
- let e = fe("deletedAt");
2044
+ let e = de("deletedAt");
2045
2045
  r = r ? C(r, e) : e;
2046
2046
  }
2047
2047
  if (!e.includeExpired && t.schemaRegistry.hasExpires(n)) {
2048
- let e = xe(fe("expiresAt"), se("expiresAt", /* @__PURE__ */ new Date()));
2048
+ let e = be(de("expiresAt"), M("expiresAt", /* @__PURE__ */ new Date()));
2049
2049
  r = r ? C(r, e) : e;
2050
2050
  }
2051
2051
  return r = bi(a, n, r), r === e.predicate ? e : {
@@ -2091,7 +2091,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2091
2091
  a = u(e, a);
2092
2092
  let d = t.schemaRegistry.versionColumn(e);
2093
2093
  if (d !== void 0) {
2094
- let t = Se({
2094
+ let t = xe({
2095
2095
  versionColumn: d,
2096
2096
  patch: a
2097
2097
  }), i = await n.query({
@@ -2105,7 +2105,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2105
2105
  take: 1,
2106
2106
  skip: void 0,
2107
2107
  projection: void 0
2108
- }), o = i[0] === void 0 ? void 0 : i[0][d], s = typeof o == "number" && Number.isFinite(o) ? o : null, c = Pe({
2108
+ }), o = i[0] === void 0 ? void 0 : i[0][d], s = typeof o == "number" && Number.isFinite(o) ? o : null, c = Ne({
2109
2109
  table: e,
2110
2110
  id: r,
2111
2111
  expected: t.expected,
@@ -2123,10 +2123,10 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2123
2123
  }, D = async (e, r) => (await E(e, r), t.schemaRegistry.hasSoftDelete(e) ? await n.update(e, r, d()) !== null : n.delete(e, r)), te = async (e, t, r) => n.updateMany(e, h(e, s(e, t)), r), k = async (e, t) => n.deleteMany(e, t), ae = (e, n) => i != null && t.schemaRegistry.hasTenant(e) ? C(n, O("tenantId", i)) : n, oe = async (e, t, n) => te(e, t, {
2124
2124
  ...n,
2125
2125
  where: ae(e, n.where)
2126
- }), ce = async (e, t) => k(e, {
2126
+ }), se = async (e, t) => k(e, {
2127
2127
  ...t,
2128
2128
  where: ae(e, t.where)
2129
- }), le = Ma({
2129
+ }), ce = Ma({
2130
2130
  query: w,
2131
2131
  updateMany: te,
2132
2132
  deleteMany: k,
@@ -2135,10 +2135,10 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2135
2135
  subject: t.subject,
2136
2136
  schemaRegistry: t.schemaRegistry,
2137
2137
  rowFilter: a
2138
- }), M = ((e, t, n) => t === void 0 ? le.updateWhere(e) : ee(e, t, n)), N = ((e, t) => t === void 0 ? le.deleteWhere(e) : D(e, t)), de = async (e, t) => {
2138
+ }), N = ((e, t, n) => t === void 0 ? ce.updateWhere(e) : ee(e, t, n)), P = ((e, t) => t === void 0 ? ce.deleteWhere(e) : D(e, t)), ue = async (e, t) => {
2139
2139
  let r = t.map((t) => o(e, t)), i = r.map((t) => h(e, p(e, t))), a = await c(e, r[0] ?? {}, () => n.insertMany(e, i));
2140
2140
  return x(e, a);
2141
- }, pe = (e, t) => {
2141
+ }, fe = (e, t) => {
2142
2142
  let n = Object.keys(t);
2143
2143
  if (n.length !== 1) throw Error(`store.links('${e}'): anchor must name exactly one source column, got [${n.join(", ")}]`);
2144
2144
  let r = n[0], i = t[r], a = j(e);
@@ -2181,9 +2181,9 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2181
2181
  let r = o(e, t), i = await c(e, r, () => n.insert(e, h(e, p(e, r))));
2182
2182
  return x(e, [i])[0];
2183
2183
  },
2184
- insertMany: (async (e, t) => de(e, t)),
2184
+ insertMany: (async (e, t) => ue(e, t)),
2185
2185
  links: (e, t) => {
2186
- let { sourceCol: n, sourceId: r, targetCol: i } = pe(e, t), a = async () => (await T({
2186
+ let { sourceCol: n, sourceId: r, targetCol: i } = fe(e, t), a = async () => (await T({
2187
2187
  table: e,
2188
2188
  predicate: O(n, r),
2189
2189
  order: [],
@@ -2191,12 +2191,12 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2191
2191
  skip: void 0,
2192
2192
  take: void 0
2193
2193
  })).map((e) => String(e[i])), o = async (t) => {
2194
- t.length !== 0 && await de(e, t.map((e) => ({
2194
+ t.length !== 0 && await ue(e, t.map((e) => ({
2195
2195
  [n]: r,
2196
2196
  [i]: e
2197
2197
  })));
2198
2198
  }, s = async (t) => {
2199
- t.length !== 0 && await ce(e, { where: C(O(n, r), ue(i, t)) });
2199
+ t.length !== 0 && await se(e, { where: C(O(n, r), le(i, t)) });
2200
2200
  };
2201
2201
  return {
2202
2202
  list: a,
@@ -2240,7 +2240,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2240
2240
  for (let [e, t] of Object.entries(o)) e !== n && e !== i && s[e] !== t && (c[e] = t, l = !0);
2241
2241
  l && (d.push(t), await oe(e, c, { where: C(O(n, r), O(i, t)) }));
2242
2242
  }
2243
- return f.length > 0 && await de(e, f), {
2243
+ return f.length > 0 && await ue(e, f), {
2244
2244
  added: u,
2245
2245
  removed: l,
2246
2246
  updated: d
@@ -2253,13 +2253,13 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
2253
2253
  let a = await n.patchJson(e, t, r, i);
2254
2254
  return a === null ? null : x(e, [a])[0];
2255
2255
  },
2256
- select: le.select,
2257
- update: M,
2258
- delete: N,
2256
+ select: ce.select,
2257
+ update: N,
2258
+ delete: P,
2259
2259
  applyDefined: Ba,
2260
2260
  hardDelete: async (e, t) => (await E(e, t), n.delete(e, t)),
2261
2261
  updateMany: oe,
2262
- deleteMany: ce,
2262
+ deleteMany: se,
2263
2263
  upsert: async (e, t, r) => {
2264
2264
  let i = o(e, t);
2265
2265
  f(e, i, r.conflictColumns);
@@ -3015,13 +3015,13 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3015
3015
  let n = Ho(e);
3016
3016
  return n === void 0 ? t() : ya(n, t);
3017
3017
  }, Wo = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, Go = (e, t) => o.async((n) => {
3018
- let r = je(t, () => o.runFork(e));
3018
+ let r = Ae(t, () => o.runFork(e));
3019
3019
  return r.addObserver((e) => {
3020
3020
  n(e);
3021
3021
  }), o.asVoid(l.interrupt(r));
3022
3022
  }), Ko = (e, t, n) => ({
3023
3023
  subject: e,
3024
- traceId: t?.traceId ?? Ue(),
3024
+ traceId: t?.traceId ?? He(),
3025
3025
  ...t?.spanId === void 0 ? {} : { spanId: t.spanId },
3026
3026
  ...n === void 0 ? {} : { clientId: n }
3027
3027
  }), qo = o.currentSpan.pipe(o.catchAll(() => o.succeed(void 0))), Jo = (e) => ({
@@ -3099,7 +3099,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3099
3099
  yield* o.addFinalizer(() => o.sync(() => e()));
3100
3100
  }
3101
3101
  })), ns = (e, t, n = "rpc.subscription", r, i, a, s) => b.unwrap(o.gen(function* () {
3102
- let c = yield* gt, l = yield* ot, u = yield* qo;
3102
+ let c = yield* ht, l = yield* at, u = yield* qo;
3103
3103
  Yo(u, n, c);
3104
3104
  let d = Ko(c, u, l.clientId), f = Ja(c.id, l.clientId), p = Qa({ subjectKey: f }, () => ea({
3105
3105
  traceId: d.traceId,
@@ -3130,9 +3130,9 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3130
3130
  swrMs: i.swrMs
3131
3131
  }, a?.(c), s?.(c) ?? Xo(c)), l.credentialExpiresAt, b.empty);
3132
3132
  }).pipe(o.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), rs = (e, t = "rpc.stream", n, r) => b.unwrap(o.gen(function* () {
3133
- let a = yield* gt, s = yield* ot, c = yield* qo;
3133
+ let a = yield* ht, s = yield* at, c = yield* qo;
3134
3134
  Yo(c, t, a);
3135
- let l = Ko(a, c, s.clientId), u = Uo(t, () => e(l)), d = o.isEffect(u) ? yield* u.pipe(o.orDie) : u, f = n === void 0 || n.length === 0 ? void 0 : () => z(a, n, r), p = io(f === void 0 ? d : b.unwrap(f().pipe(o.map((e) => e ? b.fail(e) : b.flatMap(d, (e) => b.unwrap(f().pipe(o.map((t) => t ? b.fail(t) : b.make(e)))))))), s.credentialExpiresAt, b.empty);
3135
+ let l = Ko(a, c, s.clientId), u = Uo(t, () => e(l)), d = o.isEffect(u) ? yield* u.pipe(o.orDie) : u, f = n === void 0 || n.length === 0 ? void 0 : () => xt(a, n, r), p = io(f === void 0 ? d : b.unwrap(f().pipe(o.map((e) => e ? b.fail(e) : b.flatMap(d, (e) => b.unwrap(f().pipe(o.map((t) => t ? b.fail(t) : b.make(e)))))))), s.credentialExpiresAt, b.empty);
3136
3136
  if (l.clientId === void 0) return p;
3137
3137
  let m = l.clientId;
3138
3138
  return b.unwrapScoped(o.gen(function* () {
@@ -3204,7 +3204,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3204
3204
  message: "a request with this idempotency key is already in flight",
3205
3205
  traceId: e
3206
3206
  }), gs = (e, t, n = "rpc.mutation", r, i, a) => o.gen(function* () {
3207
- let s = yield* gt, c = yield* ot, l = yield* qo;
3207
+ let s = yield* ht, c = yield* at, l = yield* qo;
3208
3208
  Yo(l, n, s);
3209
3209
  let u = Ko(s, l, c.clientId), d = i && c.idempotencyKey ? {
3210
3210
  store: i.store,
@@ -3213,7 +3213,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3213
3213
  scope: Vt(s.tenantId, Ua(s), n)
3214
3214
  } : null;
3215
3215
  if (d) {
3216
- let e = yield* o.promise(() => xt(d.store, d.scope, d.key, d.ttlMs, Date.now()));
3216
+ let e = yield* o.promise(() => bt(d.store, d.scope, d.key, d.ttlMs, Date.now()));
3217
3217
  if (e.kind === "replay") return r ? r.decode(e.response.body) : e.response.body;
3218
3218
  if (e.kind === "conflict") return yield* o.die(hs(u.traceId));
3219
3219
  }
@@ -3224,7 +3224,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3224
3224
  }, m = Qa({ subjectKey: f }, () => ea({
3225
3225
  traceId: u.traceId,
3226
3226
  ...u.spanId === void 0 ? {} : { spanId: u.spanId }
3227
- }, () => je(p, () => Uo(n, () => e(t, u))))), h = o.isEffect(m) ? Go(m, p) : o.tryPromise({
3227
+ }, () => Ae(p, () => Uo(n, () => e(t, u))))), h = o.isEffect(m) ? Go(m, p) : o.tryPromise({
3228
3228
  try: () => Promise.resolve(m),
3229
3229
  catch: (e) => e
3230
3230
  });
@@ -3514,11 +3514,11 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3514
3514
  t.tracerLayer && (A = A.pipe(u.provide(t.tracerLayer)));
3515
3515
  let oe = B({ scope: "voltro:rpc" }), j = u.launch(A).pipe(o.catchAllCause((t) => o.sync(() => {
3516
3516
  oe.error("rpc server crashed", {}, e.squash(t)), process.exit(1);
3517
- }))), se = o.runFork(j);
3518
- return ys.add(se), Os(), {
3517
+ }))), M = o.runFork(j);
3518
+ return ys.add(M), Os(), {
3519
3519
  server: s,
3520
3520
  shutdown: async () => {
3521
- ys.delete(se), await o.runPromise(l.interrupt(se)).then(() => void 0, () => void 0);
3521
+ ys.delete(M), await o.runPromise(l.interrupt(M)).then(() => void 0, () => void 0);
3522
3522
  }
3523
3523
  };
3524
3524
  }, ys = /* @__PURE__ */ new Set(), bs = /* @__PURE__ */ new Set(), xs = !1, Ss = (e) => (bs.add(e), () => {
@@ -3860,7 +3860,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3860
3860
  return t === null ? !1 : !oc(t, Date.now()) || (await e.delete(q, t.id), !1);
3861
3861
  }),
3862
3862
  list: (n) => t("list", "", async () => {
3863
- let t = Date.now(), r = xe(fe("expiresAt"), se("expiresAt", new Date(t))), i = n === "" ? r : C(te("key", n), r), a = await e.query({
3863
+ let t = Date.now(), r = be(de("expiresAt"), M("expiresAt", new Date(t))), i = n === "" ? r : C(te("key", n), r), a = await e.query({
3864
3864
  table: q,
3865
3865
  predicate: i,
3866
3866
  order: [],
@@ -3902,7 +3902,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
3902
3902
  has: () => Promise.resolve(!1),
3903
3903
  list: () => Promise.resolve([]),
3904
3904
  clear: () => Promise.resolve()
3905
- }, fc = "_voltro_api_keys", pc = (e) => Ve("sha256").update(e, "utf8").digest("hex"), mc = (e = "voltro_") => `${e}${He(30).toString("base64url")}`, hc = (e) => ({
3905
+ }, fc = "_voltro_api_keys", pc = (e) => Be("sha256").update(e, "utf8").digest("hex"), mc = (e = "voltro_") => `${e}${Ve(30).toString("base64url")}`, hc = (e) => ({
3906
3906
  id: e.id,
3907
3907
  name: e.name,
3908
3908
  keyPrefix: e.keyPrefix,
@@ -4084,10 +4084,10 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4084
4084
  path: `${t}/issue`,
4085
4085
  summary: "Issue an API key (the token is returned ONCE).",
4086
4086
  guards: [sn([
4087
+ Ge,
4088
+ Je,
4087
4089
  Ke,
4088
- Ye,
4089
- qe,
4090
- Je
4090
+ qe
4091
4091
  ])],
4092
4092
  input: y.Struct({ body: y.Struct({
4093
4093
  name: y.String,
@@ -4101,25 +4101,25 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4101
4101
  keyPrefix: y.String
4102
4102
  }),
4103
4103
  handler: async (t, n) => {
4104
- let r = t.body, i = wc(n), a = new Set(i.scopes), o = (e) => a.has(Ke) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
4104
+ let r = t.body, i = wc(n), a = new Set(i.scopes), o = (e) => a.has(Ge) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
4105
4105
  if (s === null) {
4106
- if (!o(qe)) throw new ht({
4107
- required: qe,
4106
+ if (!o(Ke)) throw new mt({
4107
+ required: Ke,
4108
4108
  message: "not allowed to issue an organization key"
4109
4109
  });
4110
4110
  } else if (s !== i.id) {
4111
- if (!o(Je)) throw new ht({
4112
- required: Je,
4111
+ if (!o(qe)) throw new mt({
4112
+ required: qe,
4113
4113
  message: "not allowed to issue a key on behalf of another user"
4114
4114
  });
4115
- } else if (!o(Ye)) throw new ht({
4116
- required: Ye,
4115
+ } else if (!o(Je)) throw new mt({
4116
+ required: Je,
4117
4117
  message: "not allowed to issue an api key"
4118
4118
  });
4119
4119
  let c = r.scopes ?? [...a];
4120
- if (!a.has(Ke)) {
4120
+ if (!a.has(Ge)) {
4121
4121
  let e = c.filter((e) => !a.has(e));
4122
- if (e.length > 0) throw new ht({
4122
+ if (e.length > 0) throw new mt({
4123
4123
  required: String(e[0]),
4124
4124
  message: `cannot issue a key with scopes you do not hold: ${e.join(", ")}`
4125
4125
  });
@@ -4143,7 +4143,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4143
4143
  method: "GET",
4144
4144
  path: t,
4145
4145
  summary: "List the caller tenant's API keys (no secrets).",
4146
- guards: [cn(Ke)],
4146
+ guards: [cn(Ge)],
4147
4147
  input: y.Struct({}),
4148
4148
  output: y.Struct({ keys: y.Array(n) }),
4149
4149
  handler: async (t, n) => ({ keys: [...await e.list(wc(n).tenantId)] })
@@ -4152,7 +4152,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4152
4152
  method: "POST",
4153
4153
  path: `${t}/revoke`,
4154
4154
  summary: "Revoke an API key by id.",
4155
- guards: [cn(Ke)],
4155
+ guards: [cn(Ge)],
4156
4156
  input: y.Struct({ body: y.Struct({ id: y.String }) }),
4157
4157
  output: y.Struct({ ok: y.Boolean }),
4158
4158
  handler: async (t, n) => ({ ok: await e.revoke(t.body.id, wc(n).tenantId) })
@@ -4177,7 +4177,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4177
4177
  hardDelete: (t, n) => kc("hardDelete", t, () => e.hardDelete(t, n))
4178
4178
  }), jc = (e) => tn.make(e.name, {
4179
4179
  payload: Rt(e.payloadSchema),
4180
- success: bt,
4180
+ success: yt,
4181
4181
  error: e.errorSchema
4182
4182
  }), Mc = (e, t) => ({
4183
4183
  id: t,
@@ -4536,7 +4536,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4536
4536
  executionId: i,
4537
4537
  parentExecutionId: a?.parentExecutionId ?? null,
4538
4538
  parentClosePolicy: a?.parentClosePolicy ?? null
4539
- }), d = e.buildExecute(l), f = (n?.(e, d, c) ?? d)(r, i), p = u.succeed(gt, c.subject), m = l?.store, h = m === void 0 ? f : o.provide(f, Ac(m));
4539
+ }), d = e.buildExecute(l), f = (n?.(e, d, c) ?? d)(r, i), p = u.succeed(ht, c.subject), m = l?.store, h = m === void 0 ? f : o.provide(f, Ac(m));
4540
4540
  return o.provide(h, p);
4541
4541
  }));
4542
4542
  }))), Zc = (e) => {
@@ -4555,32 +4555,32 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4555
4555
  }, Qc = Zc, $c = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", el = () => {
4556
4556
  let e = globalThis.crypto;
4557
4557
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
4558
- }, tl = (e) => `${e}_${el()}`, nl = (e) => e.id ?? `${e.event}->${e.workflow}`, rl = F("_voltro_workflow_events", {
4559
- id: M({ prefix: "wfe" }),
4560
- name: I(),
4561
- payload: P(),
4562
- source: I(),
4563
- subject: P().nullable(),
4564
- traceId: I().nullable(),
4565
- occurredAt: L().default("now")
4566
- }).index(["name"]).index(["source"]).index(["occurredAt"]), il = F("_voltro_workflow_event_deliveries", {
4567
- id: M({ prefix: "wfed" }),
4568
- eventId: I(),
4569
- eventName: I(),
4570
- triggerId: I(),
4571
- workflowName: I(),
4572
- executionId: I().nullable(),
4573
- status: I().oneOf([
4558
+ }, tl = (e) => `${e}_${el()}`, nl = (e) => e.id ?? `${e.event}->${e.workflow}`, rl = I("_voltro_workflow_events", {
4559
+ id: N({ prefix: "wfe" }),
4560
+ name: L(),
4561
+ payload: F(),
4562
+ source: L(),
4563
+ subject: F().nullable(),
4564
+ traceId: L().nullable(),
4565
+ occurredAt: R().default("now")
4566
+ }).index(["name"]).index(["source"]).index(["occurredAt"]), il = I("_voltro_workflow_event_deliveries", {
4567
+ id: N({ prefix: "wfed" }),
4568
+ eventId: L(),
4569
+ eventName: L(),
4570
+ triggerId: L(),
4571
+ workflowName: L(),
4572
+ executionId: L().nullable(),
4573
+ status: L().oneOf([
4574
4574
  "starting",
4575
4575
  "started",
4576
4576
  "skipped",
4577
4577
  "failed"
4578
4578
  ]).default("starting"),
4579
- idempotencyKey: I().unique(),
4579
+ idempotencyKey: L().unique(),
4580
4580
  skipped: E().default(!1),
4581
- errorMessage: I().nullable(),
4582
- createdAt: L().default("now"),
4583
- completedAt: L().nullable()
4581
+ errorMessage: L().nullable(),
4582
+ createdAt: R().default("now"),
4583
+ completedAt: R().nullable()
4584
4584
  }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]), al = (e) => {
4585
4585
  let t = e.makeId ?? tl, n = /* @__PURE__ */ new Map();
4586
4586
  for (let t of e.triggers) {
@@ -4932,10 +4932,10 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4932
4932
  this.routes.clear();
4933
4933
  }
4934
4934
  }, dl = (e) => e instanceof Error ? e.message : String(e), fl = (e, t, n, r) => o.gen(function* () {
4935
- let i = y.encode(t.key), a = y.encode(t.payload), s = yield* i(n).pipe(o.mapError((e) => new dt({
4935
+ let i = y.encode(t.key), a = y.encode(t.payload), s = yield* i(n).pipe(o.mapError((e) => new ut({
4936
4936
  event: t.name,
4937
4937
  message: dl(e)
4938
- }))), c = yield* a(r).pipe(o.mapError((e) => new ft({
4938
+ }))), c = yield* a(r).pipe(o.mapError((e) => new dt({
4939
4939
  event: t.name,
4940
4940
  message: dl(e)
4941
4941
  }))), l = Buffer.byteLength(JSON.stringify({
@@ -4943,10 +4943,10 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4943
4943
  key: s,
4944
4944
  payload: c
4945
4945
  }), "utf8");
4946
- if (l > mt) return yield* o.fail(new pt({
4946
+ if (l > pt) return yield* o.fail(new ft({
4947
4947
  event: t.name,
4948
4948
  bytes: l,
4949
- limit: mt
4949
+ limit: pt
4950
4950
  }));
4951
4951
  let u = () => {
4952
4952
  let n = e.bus.publish({
@@ -4986,9 +4986,9 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
4986
4986
  return t.set(e.origin, Math.max(r, e.n)), r === 0 && n === 0 ? 0 : Math.max(0, e.n - r - 1);
4987
4987
  };
4988
4988
  }, yl = (e) => b.unwrapScoped(o.gen(function* () {
4989
- let t = yield* gt, n = yield* ot, r = t.tenantId ?? null, i = e.guards === void 0 ? void 0 : e.guards.filter((e) => !At(e));
4989
+ let t = yield* ht, n = yield* at, r = t.tenantId ?? null, i = e.guards === void 0 ? void 0 : e.guards.filter((e) => !At(e));
4990
4990
  if (i !== void 0 && i.length > 0) {
4991
- let n = yield* z(t, i, e.key);
4991
+ let n = yield* xt(t, i, e.key);
4992
4992
  if (n) return yield* o.fail(n);
4993
4993
  }
4994
4994
  let a = e.bus.deliveryFor(e.event) === "latest", s = yield* g.sliding(e.queueSize ?? (a ? 1 : 64)), c = /* @__PURE__ */ new Map(), l = e.bus.subscribe({
@@ -5013,7 +5013,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5013
5013
  e();
5014
5014
  }));
5015
5015
  }
5016
- let u = a ? () => 0 : vl(c), d = i === void 0 || i.length === 0 ? void 0 : () => z(t, i, e.key), f = b.fromQueue(s, { shutdown: !0 }).pipe(b.flatMap((e) => d === void 0 ? p(e) : b.unwrap(d().pipe(o.map((t) => t ? b.fail(t) : p(e))))));
5016
+ let u = a ? () => 0 : vl(c), d = i === void 0 || i.length === 0 ? void 0 : () => xt(t, i, e.key), f = b.fromQueue(s, { shutdown: !0 }).pipe(b.flatMap((e) => d === void 0 ? p(e) : b.unwrap(d().pipe(o.map((t) => t ? b.fail(t) : p(e))))));
5017
5017
  function p(t) {
5018
5018
  return b.suspend(() => {
5019
5019
  if (t.kind === "gap") return b.make(_l(t));
@@ -5133,48 +5133,48 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5133
5133
  }, Cl = B({ scope: "voltro:outbox" }), J = "_voltro_outbox", wl = {
5134
5134
  kind: "typeid",
5135
5135
  prefix: "obx"
5136
- }, Tl = F(J, {
5137
- id: M({ prefix: "obx" }),
5138
- effect: I(),
5139
- payload: P(),
5140
- status: I(),
5141
- attempts: N(),
5142
- maxAttempts: N(),
5143
- nextAttemptAt: L(),
5144
- idempotencyKey: I().nullable(),
5145
- lastError: I().nullable(),
5146
- subjectId: I().nullable(),
5147
- tenantId: I().nullable(),
5148
- traceId: I().nullable(),
5149
- createdAt: L(),
5150
- deliveredAt: L().nullable(),
5151
- resendRequestedBy: I().nullable(),
5152
- resendReason: I().nullable(),
5153
- resendCount: N()
5136
+ }, Tl = I(J, {
5137
+ id: N({ prefix: "obx" }),
5138
+ effect: L(),
5139
+ payload: F(),
5140
+ status: L(),
5141
+ attempts: P(),
5142
+ maxAttempts: P(),
5143
+ nextAttemptAt: R(),
5144
+ idempotencyKey: L().nullable(),
5145
+ lastError: L().nullable(),
5146
+ subjectId: L().nullable(),
5147
+ tenantId: L().nullable(),
5148
+ traceId: L().nullable(),
5149
+ createdAt: R(),
5150
+ deliveredAt: R().nullable(),
5151
+ resendRequestedBy: L().nullable(),
5152
+ resendReason: L().nullable(),
5153
+ resendCount: P()
5154
5154
  }), El = "_voltro_outbox_attempts", Dl = {
5155
5155
  kind: "typeid",
5156
5156
  prefix: "obxa"
5157
- }, Ol = F(El, {
5158
- id: M({ prefix: "obxa" }),
5159
- outboxId: I(),
5160
- effect: I(),
5161
- attempt: N(),
5162
- trigger: I().oneOf(["automatic", "manual"]),
5163
- triggeredBy: I().nullable(),
5164
- reason: I().nullable(),
5165
- outcome: I().oneOf([
5157
+ }, Ol = I(El, {
5158
+ id: N({ prefix: "obxa" }),
5159
+ outboxId: L(),
5160
+ effect: L(),
5161
+ attempt: P(),
5162
+ trigger: L().oneOf(["automatic", "manual"]),
5163
+ triggeredBy: L().nullable(),
5164
+ reason: L().nullable(),
5165
+ outcome: L().oneOf([
5166
5166
  "delivered",
5167
5167
  "failed",
5168
5168
  "dead"
5169
5169
  ]),
5170
- startedAt: L(),
5171
- finishedAt: L(),
5172
- durationMs: N(),
5173
- error: I().nullable(),
5174
- response: P().nullable(),
5175
- subjectId: I().nullable(),
5176
- tenantId: I().nullable(),
5177
- traceId: I().nullable()
5170
+ startedAt: R(),
5171
+ finishedAt: R(),
5172
+ durationMs: P(),
5173
+ error: L().nullable(),
5174
+ response: F().nullable(),
5175
+ subjectId: L().nullable(),
5176
+ tenantId: L().nullable(),
5177
+ traceId: L().nullable()
5178
5178
  }).index(["outboxId", "attempt"]).index(["startedAt"]).index(["outcome"]), kl = (e) => {
5179
5179
  if (e.effect.trim() === "") throw Error("defineOutboxHandler: `effect` must be a non-empty name");
5180
5180
  if (e.maxAttempts !== void 0 && e.maxAttempts < 1) throw Error(`defineOutboxHandler("${e.effect}"): maxAttempts must be >= 1`);
@@ -5395,42 +5395,42 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5395
5395
  }, Rl = B({ scope: "voltro:connections" }), Y = "_voltro_connections", zl = {
5396
5396
  kind: "typeid",
5397
5397
  prefix: "conn"
5398
- }, Bl = F(Y, {
5399
- id: M({ prefix: "conn" }),
5400
- connectionId: I(),
5401
- subjectId: I(),
5402
- tenantId: I().nullable(),
5403
- kind: I().oneOf(["oauth2", "pat"]),
5404
- status: I().oneOf([
5398
+ }, Bl = I(Y, {
5399
+ id: N({ prefix: "conn" }),
5400
+ connectionId: L(),
5401
+ subjectId: L(),
5402
+ tenantId: L().nullable(),
5403
+ kind: L().oneOf(["oauth2", "pat"]),
5404
+ status: L().oneOf([
5405
5405
  "connected",
5406
5406
  "expired",
5407
5407
  "revoked",
5408
5408
  "error"
5409
5409
  ]),
5410
- accessToken: I(),
5411
- refreshToken: I().nullable(),
5412
- expiresAt: L().nullable(),
5413
- scopes: I().nullable(),
5414
- accountId: I().nullable(),
5415
- accountLabel: I().nullable(),
5416
- lastError: I().nullable(),
5417
- refreshLockedUntil: L(),
5418
- metadata: P().nullable(),
5419
- connectedAt: L(),
5420
- updatedAt: L()
5410
+ accessToken: L(),
5411
+ refreshToken: L().nullable(),
5412
+ expiresAt: R().nullable(),
5413
+ scopes: L().nullable(),
5414
+ accountId: L().nullable(),
5415
+ accountLabel: L().nullable(),
5416
+ lastError: L().nullable(),
5417
+ refreshLockedUntil: R(),
5418
+ metadata: F().nullable(),
5419
+ connectedAt: R(),
5420
+ updatedAt: R()
5421
5421
  }).unique("byConnectionSubject", ["connectionId", "subjectId"]).index(["subjectId"]), Vl = "_voltro_connection_grants", Hl = {
5422
5422
  kind: "typeid",
5423
5423
  prefix: "cgrant"
5424
- }, Ul = F(Vl, {
5425
- id: M({ prefix: "cgrant" }),
5426
- state: I().unique(),
5427
- connectionId: I(),
5428
- subjectId: I(),
5429
- tenantId: I().nullable(),
5430
- codeVerifier: I().nullable(),
5431
- redirectTo: I(),
5432
- createdAt: L(),
5433
- expiresAt: L()
5424
+ }, Ul = I(Vl, {
5425
+ id: N({ prefix: "cgrant" }),
5426
+ state: L().unique(),
5427
+ connectionId: L(),
5428
+ subjectId: L(),
5429
+ tenantId: L().nullable(),
5430
+ codeVerifier: L().nullable(),
5431
+ redirectTo: L(),
5432
+ createdAt: R(),
5433
+ expiresAt: R()
5434
5434
  }).index(["expiresAt"]), Wl = /^[a-z][a-z0-9-]*$/, Gl = (e) => {
5435
5435
  if (!Wl.test(e.id)) throw Error(`defineConnection: id "${e.id}" must be lowercase kebab-case (it becomes a URL path segment).`);
5436
5436
  if (e.kind === "oauth2") {
@@ -5550,7 +5550,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5550
5550
  });
5551
5551
  i = n.status, a = await n.text();
5552
5552
  } catch (t) {
5553
- throw new R({
5553
+ throw new z({
5554
5554
  connectionId: e.id,
5555
5555
  reason: `token endpoint unreachable: ${String(t)}`,
5556
5556
  transient: !0
@@ -5562,12 +5562,12 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5562
5562
  } catch {
5563
5563
  o = {};
5564
5564
  }
5565
- if (i < 200 || i >= 300) throw new R({
5565
+ if (i < 200 || i >= 300) throw new z({
5566
5566
  connectionId: e.id,
5567
5567
  reason: `token endpoint ${i}: ${o.error ?? ""} ${o.error_description ?? a.slice(0, 200)}`.trim(),
5568
5568
  transient: i >= 500
5569
5569
  });
5570
- if (typeof o.access_token != "string" || o.access_token.length === 0) throw new R({
5570
+ if (typeof o.access_token != "string" || o.access_token.length === 0) throw new z({
5571
5571
  connectionId: e.id,
5572
5572
  reason: "token response carried no access_token",
5573
5573
  transient: !1
@@ -5628,14 +5628,14 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5628
5628
  return fu.set(o, c), c;
5629
5629
  }, vu = async (e) => {
5630
5630
  let { store: t, subjectId: n, now: r } = e, i = e.definition, a = e.sleep ?? du, o = i.refreshSkewMs ?? 6e4, s = e.row.id;
5631
- if (await t.updateMany("_voltro_connections", { refreshLockedUntil: new Date(r() + 3e4) }, { where: C(O("id", s), _e("refreshLockedUntil", new Date(r()))) }) === 0) {
5631
+ if (await t.updateMany("_voltro_connections", { refreshLockedUntil: new Date(r() + 3e4) }, { where: C(O("id", s), ge("refreshLockedUntil", new Date(r()))) }) === 0) {
5632
5632
  for (let e = 0; e < 10; e++) {
5633
5633
  await a(200);
5634
5634
  let e = await $l(t, i.id, n);
5635
5635
  if (e === void 0) throw new uu(i.id, n);
5636
5636
  if (!gu(e, o, r())) return hu(i, e);
5637
5637
  }
5638
- throw new R({
5638
+ throw new z({
5639
5639
  connectionId: i.id,
5640
5640
  reason: "another replica held the refresh lease and did not publish a fresh token in time",
5641
5641
  transient: !0
@@ -5647,7 +5647,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5647
5647
  lastError: "access token expired and no refresh token is on file — reconnect required",
5648
5648
  refreshLockedUntil: /* @__PURE__ */ new Date(0),
5649
5649
  updatedAt: new Date(r())
5650
- }), new R({
5650
+ }), new z({
5651
5651
  connectionId: i.id,
5652
5652
  reason: "access token expired and no refresh token is on file — reconnect required",
5653
5653
  transient: !1
@@ -5656,7 +5656,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5656
5656
  try {
5657
5657
  l = await su(i, da(String(c)), r);
5658
5658
  } catch (e) {
5659
- let n = e instanceof R ? e : new R({
5659
+ let n = e instanceof z ? e : new z({
5660
5660
  connectionId: i.id,
5661
5661
  reason: String(e),
5662
5662
  transient: !0
@@ -5737,20 +5737,20 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5737
5737
  skip: void 0,
5738
5738
  projection: void 0
5739
5739
  }))[0];
5740
- if (n === void 0) throw new R({
5740
+ if (n === void 0) throw new z({
5741
5741
  connectionId: "unknown",
5742
5742
  reason: "unknown or already-used handshake state",
5743
5743
  transient: !1
5744
5744
  });
5745
5745
  await e.store.delete(Vl, n.id);
5746
5746
  let r = String(n.connectionId), i = Yl(n.expiresAt);
5747
- if (i !== null && i.getTime() < t.getTime()) throw new R({
5747
+ if (i !== null && i.getTime() < t.getTime()) throw new z({
5748
5748
  connectionId: r,
5749
5749
  reason: "handshake expired — start again",
5750
5750
  transient: !1
5751
5751
  });
5752
5752
  let a = e.registry.get(r);
5753
- if (a === void 0 || a.kind !== "oauth2") throw new R({
5753
+ if (a === void 0 || a.kind !== "oauth2") throw new z({
5754
5754
  connectionId: r,
5755
5755
  reason: "no oauth2 connection is declared under that id",
5756
5756
  transient: !1
@@ -5780,7 +5780,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5780
5780
  }, Ou = async (e, t = /* @__PURE__ */ new Date()) => {
5781
5781
  let n = await e.query({
5782
5782
  table: Vl,
5783
- predicate: _e("expiresAt", t),
5783
+ predicate: ge("expiresAt", t),
5784
5784
  order: [],
5785
5785
  take: void 0,
5786
5786
  skip: void 0,
@@ -5839,11 +5839,11 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5839
5839
  };
5840
5840
  }, Fu = (e, t) => {
5841
5841
  let n = e.request?.subject?.id ?? null;
5842
- if (n === null || n === "") throw new ut({ connectionId: t });
5842
+ if (n === null || n === "") throw new lt({ connectionId: t });
5843
5843
  return n;
5844
5844
  }, Iu = (e, t) => {
5845
5845
  let n = e.registry.get(t);
5846
- if (n === void 0) throw new lt({ connectionId: t });
5846
+ if (n === void 0) throw new ct({ connectionId: t });
5847
5847
  return n;
5848
5848
  }, Lu = (e) => async (t, n) => {
5849
5849
  let r = n.request?.subject?.id ?? null;
@@ -5861,7 +5861,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5861
5861
  })) : ru(n.store, e.registry, r);
5862
5862
  }, Ru = (e) => async (t, n) => {
5863
5863
  let r = Iu(e, t.connectionId), i = Fu(n, t.connectionId);
5864
- if (r.kind !== "oauth2") throw new ct({
5864
+ if (r.kind !== "oauth2") throw new st({
5865
5865
  connectionId: t.connectionId,
5866
5866
  expected: "oauth2",
5867
5867
  actual: r.kind
@@ -5876,13 +5876,13 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5876
5876
  });
5877
5877
  }, zu = (e) => async (t, n) => {
5878
5878
  let r = Iu(e, t.connectionId), i = Fu(n, t.connectionId);
5879
- if (r.kind !== "pat") throw new ct({
5879
+ if (r.kind !== "pat") throw new st({
5880
5880
  connectionId: t.connectionId,
5881
5881
  expected: "pat",
5882
5882
  actual: r.kind
5883
5883
  });
5884
5884
  let a = t.token.trim();
5885
- if (a.length === 0) throw new R({
5885
+ if (a.length === 0) throw new z({
5886
5886
  connectionId: t.connectionId,
5887
5887
  reason: "token is empty",
5888
5888
  transient: !1
@@ -5891,7 +5891,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5891
5891
  if (r.validate !== void 0) try {
5892
5892
  o = await r.validate(a);
5893
5893
  } catch (e) {
5894
- throw new R({
5894
+ throw new z({
5895
5895
  connectionId: t.connectionId,
5896
5896
  reason: `the provider rejected that token: ${e instanceof Error ? e.message : String(e)}`,
5897
5897
  transient: !1
@@ -5967,7 +5967,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
5967
5967
  td.enterWith(e);
5968
5968
  }, rd = () => td.getStore(), id = (e, t) => td.run(e, t), ad = B({ scope: "voltro:policy" }), od, sd = (e) => {
5969
5969
  od = e;
5970
- }, cd = () => od, ld = () => {
5970
+ }, cd = () => od, ld = (e) => od === void 0 && (od = e, !0), ud = () => {
5971
5971
  It((e) => o.gen(function* () {
5972
5972
  let t = Gu(e.resourceType);
5973
5973
  if (t === void 0) return ad.warn("policy guard denied — no resource policy registered for this type", {
@@ -6005,10 +6005,10 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6005
6005
  tuples: r
6006
6006
  });
6007
6007
  }));
6008
- }, ud = (e) => {
6009
- Promise.resolve().then(e);
6010
6008
  }, dd = (e) => {
6011
- let t = e.schedule ?? ud, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => `${e}\u0000${t}`, a = async (t) => {
6009
+ Promise.resolve().then(e);
6010
+ }, fd = (e) => {
6011
+ let t = e.schedule ?? dd, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => `${e}\u0000${t}`, a = async (t) => {
6012
6012
  let a = r.get(t);
6013
6013
  if (a === void 0) return;
6014
6014
  r.delete(t);
@@ -6017,7 +6017,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6017
6017
  if (o.length > 0) {
6018
6018
  let r = await e.store.query({
6019
6019
  table: t,
6020
- predicate: ue("id", o),
6020
+ predicate: le("id", o),
6021
6021
  order: [],
6022
6022
  take: void 0,
6023
6023
  skip: void 0,
@@ -6054,23 +6054,23 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6054
6054
  load: async (e, t) => (await o(e, [t]))[0] ?? null,
6055
6055
  loadMany: (e, t) => o(e, t)
6056
6056
  };
6057
- }, fd = u.effect(Kt.HttpClient, o.map(Kt.HttpClient, (e) => e.pipe(Kt.mapRequestEffect((e) => o.currentSpan.pipe(o.map((t) => e.headers.traceparent === void 0 ? Jt.setHeader(e, "traceparent", Xi({
6057
+ }, pd = u.effect(Kt.HttpClient, o.map(Kt.HttpClient, (e) => e.pipe(Kt.mapRequestEffect((e) => o.currentSpan.pipe(o.map((t) => e.headers.traceparent === void 0 ? Jt.setHeader(e, "traceparent", Xi({
6058
6058
  traceId: t.traceId,
6059
6059
  spanId: t.spanId,
6060
6060
  sampled: t.sampled
6061
- })) : e), o.catchAll(() => o.succeed(e))))))), pd = class extends Error {
6061
+ })) : e), o.catchAll(() => o.succeed(e))))))), md = class extends Error {
6062
6062
  url;
6063
6063
  reason;
6064
6064
  _tag = "SsrfBlockedError";
6065
6065
  constructor(e, t) {
6066
6066
  super(`SSRF: blocked outbound request to ${e} — ${t}. If this target is intentional, add its host to \`http.allowHosts\` in app.config.ts.`), this.url = e, this.reason = t, this.name = "SsrfBlockedError";
6067
6067
  }
6068
- }, md = (e, t) => e === 0 || e === 10 || e === 127 || e === 100 && t >= 64 && t <= 127 || e === 169 && t === 254 || e === 172 && t >= 16 && t <= 31 || e === 192 && t === 168 || e === 198 && (t === 18 || t === 19) || e >= 224, hd = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), gd = (e, t, n) => n.some((n) => {
6068
+ }, hd = (e, t) => e === 0 || e === 10 || e === 127 || e === 100 && t >= 64 && t <= 127 || e === 169 && t === 254 || e === 172 && t >= 16 && t <= 31 || e === 192 && t === 168 || e === 198 && (t === 18 || t === 19) || e >= 224, gd = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), _d = (e, t, n) => n.some((n) => {
6069
6069
  let r = n.trim().toLowerCase();
6070
6070
  if (r === "") return !1;
6071
6071
  let i = t === "" ? e : `${e}:${t}`;
6072
6072
  return r === e || r === i ? !0 : r.startsWith("*.") ? e.endsWith(r.slice(1)) : !1;
6073
- }), _d = (e, t = {}) => {
6073
+ }), vd = (e, t = {}) => {
6074
6074
  let n;
6075
6075
  try {
6076
6076
  n = new URL(e);
@@ -6079,30 +6079,30 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6079
6079
  }
6080
6080
  if (n.protocol !== "http:" && n.protocol !== "https:") return `blocked scheme "${n.protocol}"`;
6081
6081
  let r = n.hostname.replace(/^\[|\]$/g, "").toLowerCase();
6082
- if (gd(r, n.port, t.allowHosts ?? [])) return null;
6082
+ if (_d(r, n.port, t.allowHosts ?? [])) return null;
6083
6083
  if (r === "localhost" || r.endsWith(".localhost") || r.endsWith(".internal") || r.endsWith(".local")) return `blocked host "${r}"`;
6084
6084
  let i = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(r);
6085
6085
  if (i) {
6086
6086
  let e = Number(i[1]), t = Number(i[2]);
6087
- return e > 255 || t > 255 || Number(i[3]) > 255 || Number(i[4]) > 255 ? "malformed ipv4 literal" : md(e, t) ? `blocked private/reserved address ${r}` : null;
6087
+ return e > 255 || t > 255 || Number(i[3]) > 255 || Number(i[4]) > 255 ? "malformed ipv4 literal" : hd(e, t) ? `blocked private/reserved address ${r}` : null;
6088
6088
  }
6089
6089
  if (r.includes(":")) {
6090
6090
  let e = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(r);
6091
- return e ? _d(`${n.protocol}//${e[1]}`, t) : hd(r) ? `blocked private/reserved address ${r}` : null;
6091
+ return e ? vd(`${n.protocol}//${e[1]}`, t) : gd(r) ? `blocked private/reserved address ${r}` : null;
6092
6092
  }
6093
6093
  return null;
6094
- }, vd = (e = {}) => u.effect(Kt.HttpClient, o.map(Kt.HttpClient, (t) => {
6094
+ }, yd = (e = {}) => u.effect(Kt.HttpClient, o.map(Kt.HttpClient, (t) => {
6095
6095
  let n = Kt.transform(t, (t, n) => o.suspend(() => {
6096
- let r = _d(n.url, e);
6096
+ let r = vd(n.url, e);
6097
6097
  return r === null ? t : o.fail(new qt.RequestError({
6098
6098
  request: n,
6099
6099
  reason: "Transport",
6100
- cause: new pd(n.url, r),
6100
+ cause: new md(n.url, r),
6101
6101
  description: `SSRF policy: ${r}`
6102
6102
  }));
6103
6103
  }));
6104
6104
  return Kt.followRedirects(n, e.maxRedirects ?? 5);
6105
- })), yd = (e) => {
6105
+ })), bd = (e) => {
6106
6106
  let t = e.now ?? Date.now, n = e.intervalMs ?? 3e4, r = e.maxPending ?? 500, i = /* @__PURE__ */ new Map(), a = !1, o = async () => {
6107
6107
  if (i.size === 0) return;
6108
6108
  let t = i;
@@ -6131,7 +6131,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6131
6131
  },
6132
6132
  pending: () => i.size
6133
6133
  };
6134
- }, bd = "voltro/audit", xd = "voltro/softDelete", Sd = "voltro/expires", Cd = "voltro/tenant", wd = "voltro/localFirst", Td = (e) => {
6134
+ }, xd = "voltro/audit", Sd = "voltro/softDelete", Cd = "voltro/expires", wd = "voltro/tenant", Td = "voltro/localFirst", Ed = (e) => {
6135
6135
  let t = /* @__PURE__ */ new Map();
6136
6136
  for (let n of e) {
6137
6137
  let e = /* @__PURE__ */ new Set();
@@ -6179,25 +6179,25 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6179
6179
  return !1;
6180
6180
  },
6181
6181
  idScheme: (e) => t.get(e)?.idScheme,
6182
- defaultFactories: (e) => t.get(e)?.defaultFactories ?? Ed,
6183
- computedFields: (e) => t.get(e)?.computedFields ?? Dd,
6182
+ defaultFactories: (e) => t.get(e)?.defaultFactories ?? Dd,
6183
+ computedFields: (e) => t.get(e)?.computedFields ?? Od,
6184
6184
  versionColumn: (e) => t.get(e)?.versionColumn,
6185
- generatedColumns: (e) => t.get(e)?.generatedColumns ?? Od,
6186
- crdtColumns: (e) => t.get(e)?.crdtColumns ?? kd,
6185
+ generatedColumns: (e) => t.get(e)?.generatedColumns ?? kd,
6186
+ crdtColumns: (e) => t.get(e)?.crdtColumns ?? Ad,
6187
6187
  insertSchema: (e) => t.get(e)?.insertSchema,
6188
6188
  validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
6189
6189
  };
6190
- }, Ed = /* @__PURE__ */ new Map(), Dd = /* @__PURE__ */ new Map(), Od = /* @__PURE__ */ new Set(), kd = /* @__PURE__ */ new Set(), Ad = Td([]), jd = B({ scope: "store.fieldEncryption" }), Md = (e, t) => {
6190
+ }, Dd = /* @__PURE__ */ new Map(), Od = /* @__PURE__ */ new Map(), kd = /* @__PURE__ */ new Set(), Ad = /* @__PURE__ */ new Set(), jd = Ed([]), Md = B({ scope: "store.fieldEncryption" }), Nd = (e, t) => {
6191
6191
  let n = t, r = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", i = /* @__PURE__ */ new Set(), a = (e) => {
6192
6192
  let t = `${e.table}.${e.column}`;
6193
- i.has(t) || (i.add(t), jd.warn("encrypted column degraded to null — could not decrypt with the active key", {
6193
+ i.has(t) || (i.add(t), Md.warn("encrypted column degraded to null — could not decrypt with the active key", {
6194
6194
  table: e.table,
6195
6195
  column: e.column,
6196
6196
  reason: e.reason,
6197
6197
  hint: "VOLTRO_FIELD_DECRYPT_ON_ERROR=null is set — this row was likely encrypted under a different key"
6198
6198
  }));
6199
6199
  }, o = (e, t) => {
6200
- let r = j(e), i = n ? Me(t, r, n) : t;
6200
+ let r = j(e), i = n ? je(t, r, n) : t;
6201
6201
  return ie(i, r, K());
6202
6202
  }, s = (e, t) => {
6203
6203
  let i = j(e), o = ne(t, i, K(), {
@@ -6214,7 +6214,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6214
6214
  e.injectExternalChange(t);
6215
6215
  },
6216
6216
  ...e.changeScope === void 0 ? {} : { changeScope: e.changeScope },
6217
- ...e.withNamespace === void 0 ? {} : { withNamespace: (n) => Md(e.withNamespace(n), t) },
6217
+ ...e.withNamespace === void 0 ? {} : { withNamespace: (n) => Nd(e.withNamespace(n), t) },
6218
6218
  ...e.raw === void 0 ? {} : { raw: ((...t) => e.raw(...t)) },
6219
6219
  ...e.close === void 0 ? {} : { close: (t) => e.close(t) },
6220
6220
  ...e.ping === void 0 ? {} : { ping: () => e.ping() },
@@ -6226,32 +6226,32 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6226
6226
  upsert: async (t, n, r) => c(t, await e.upsert(t, o(t, n), r)),
6227
6227
  insertIgnore: async (t, n, r) => c(t, await e.insertIgnore(t, o(t, n), r)),
6228
6228
  patchJson: async (t, n, r, i) => c(t, await e.patchJson(t, n, r, i)),
6229
- transactional: (n) => e.transactional((e) => n(Md(e, t)))
6229
+ transactional: (n) => e.transactional((e) => n(Nd(e, t)))
6230
6230
  };
6231
- }, Nd = (e, t) => {
6231
+ }, Pd = (e, t) => {
6232
6232
  if (t === void 0 || t.length === 0) return e;
6233
6233
  let n = { ...e };
6234
6234
  for (let e of t) delete n[e];
6235
6235
  return n;
6236
- }, Pd = (e, t) => {
6237
- let n = j(e), r = n === void 0 ? [] : Ne(n);
6238
- return r.length === 0 ? t ?? [] : t === void 0 ? r : [...t, ...r];
6239
6236
  }, Fd = (e, t) => {
6237
+ let n = j(e), r = n === void 0 ? [] : Me(n);
6238
+ return r.length === 0 ? t ?? [] : t === void 0 ? r : [...t, ...r];
6239
+ }, Id = (e, t) => {
6240
6240
  let n = j(e);
6241
6241
  if (n === void 0) return;
6242
- let r = Ne(n).filter((e) => t[e] !== void 0);
6242
+ let r = Me(n).filter((e) => t[e] !== void 0);
6243
6243
  if (r.length !== 0) throw new La({
6244
6244
  table: e,
6245
6245
  columns: r
6246
6246
  });
6247
- }, Id = (e, t) => t.length === 0 ? e : e.map((e) => Nd(e, t)), Ld = (e, t, n, r, i) => {
6247
+ }, Ld = (e, t) => t.length === 0 ? e : e.map((e) => Pd(e, t)), Rd = (e, t, n, r, i) => {
6248
6248
  let a = {
6249
6249
  ...t?.(r) ?? {},
6250
6250
  ...n?.(i) ?? {}
6251
6251
  }, o = e;
6252
6252
  for (let [e, t] of Object.entries(a)) t !== void 0 && (o = o.where(e, t));
6253
6253
  return o;
6254
- }, Rd = 1e3, zd = (e, t = Rd) => {
6254
+ }, zd = 1e3, Bd = (e, t = zd) => {
6255
6255
  let n = (e) => typeof e == "number" && Number.isFinite(e) ? e : void 0, r = (e) => Math.max(1, Math.min(Math.floor(e), t)), i = n(e.page);
6256
6256
  if (i !== void 0) {
6257
6257
  let t = r(n(e.pageSize) ?? 100);
@@ -6264,37 +6264,37 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6264
6264
  limit: r(n(e.limit) ?? 100),
6265
6265
  offset: Math.max(0, Math.floor(n(e.offset) ?? 0))
6266
6266
  };
6267
- }, Bd = {
6267
+ }, Vd = {
6268
6268
  list: (e, t = {}) => async (n, r) => {
6269
6269
  let i = n ?? {}, a = r.store.select(e);
6270
6270
  if (t.columns !== void 0 && t.columns.length > 0) {
6271
- let n = new Set(Pd(e, void 0)), r = t.columns.filter((e) => !n.has(e));
6271
+ let n = new Set(Fd(e, void 0)), r = t.columns.filter((e) => !n.has(e));
6272
6272
  r.length > 0 && (a = a.select(...r));
6273
6273
  }
6274
- t.include !== void 0 && (a = a.with(t.include)), a = Ld(a, t.filter, t.scope, i, r);
6274
+ t.include !== void 0 && (a = a.with(t.include)), a = Rd(a, t.filter, t.scope, i, r);
6275
6275
  for (let e of t.sort ?? []) a = a.orderBy(e.column, e.direction ?? "asc");
6276
6276
  if (t.paginate === !0) {
6277
- let { limit: e, offset: n } = zd(i, t.maxPageSize);
6277
+ let { limit: e, offset: n } = Bd(i, t.maxPageSize);
6278
6278
  a = a.limit(e).offset(n);
6279
6279
  }
6280
- return Id(await a.all(), Pd(e, t.redact));
6280
+ return Ld(await a.all(), Fd(e, t.redact));
6281
6281
  },
6282
6282
  getById: (e, t = {}) => async (n, r) => {
6283
6283
  let i = r.store.select(e).where("id", n.id);
6284
6284
  t.include !== void 0 && (i = i.with(t.include));
6285
6285
  let a = await i.first();
6286
- return a === null ? null : Nd(a, Pd(e, t.redact));
6286
+ return a === null ? null : Pd(a, Fd(e, t.redact));
6287
6287
  },
6288
- create: (e, t = {}) => async (n, r) => (Fd(e, n), Nd(await r.store.insert(e, n), Pd(e, t.redact))),
6288
+ create: (e, t = {}) => async (n, r) => (Id(e, n), Pd(await r.store.insert(e, n), Fd(e, t.redact))),
6289
6289
  update: (e, t = {}) => async (n, r) => {
6290
6290
  let { id: i, ...a } = n;
6291
- Fd(e, a);
6291
+ Id(e, a);
6292
6292
  let o = await r.store.update(e, i, a);
6293
- return o === null ? null : Nd(o, Pd(e, t.redact));
6293
+ return o === null ? null : Pd(o, Fd(e, t.redact));
6294
6294
  },
6295
- count: (e, t = {}) => async (n, r) => Ld(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
6295
+ count: (e, t = {}) => async (n, r) => Rd(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
6296
6296
  remove: (e) => async (t, n) => ({ deleted: await n.store.delete(e, t.id) })
6297
- }, Vd = (e) => {
6297
+ }, Hd = (e) => {
6298
6298
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = (e) => {
6299
6299
  if (!n.has(e)) switch (n.add(e), e._tag) {
6300
6300
  case "TypeLiteral":
@@ -6318,7 +6318,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6318
6318
  }
6319
6319
  };
6320
6320
  return r(e.ast), t;
6321
- }, Hd = (e) => {
6321
+ }, Ud = (e) => {
6322
6322
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = (e) => {
6323
6323
  switch (e._tag) {
6324
6324
  case "Literal": return e.literal === null;
@@ -6350,24 +6350,24 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6350
6350
  }
6351
6351
  };
6352
6352
  return i(e.ast), t;
6353
- }, Ud = (e, t) => {
6353
+ }, Wd = (e, t) => {
6354
6354
  let n = e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source];
6355
6355
  if (n.length === 0) return [];
6356
- let r = Vd(e.output), i = Hd(e.output), a = [];
6356
+ let r = Hd(e.output), i = Ud(e.output), a = [];
6357
6357
  for (let o of n) for (let n of t.get(o) ?? []) r.has(n) && !i.has(n) && a.push({
6358
6358
  query: e.name,
6359
6359
  table: o,
6360
6360
  column: n
6361
6361
  });
6362
6362
  return a;
6363
- }, Wd = (e) => {
6363
+ }, Gd = (e) => {
6364
6364
  if (e.length !== 0) return `A wire-reachable query exposes a server-only column:\n${e.map((e) => ` • query '${e.query}' output declares '${e.column}' — a .serverOnly() column of '${e.table}'`).join("\n")}\nThree ways out, in order of preference:\n 1. Omit the column from the query's output schema. The crud.* read helpers strip these automatically.\n 2. Keep the KEY but type it \`Schema.Null\` — for a view that must stay wire-compatible (an importer that breaks if the key vanishes) while never sending a value. The audit accepts that, because the schema then PROVES no value can flow instead of promising it. Pair it with a \`hasX\` boolean.\n 3. Drop the .serverOnly() marker, if the column may in fact reach a client.\nNote the audit reads the DECLARED shape, not what your handler emits: a field typed \`string\` that you always set to null still fails, and should — the next edit to that handler is one line away from sending it.`;
6365
- }, Gd = (e, t) => e.cache?.scope === "global" ? (e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source]).filter((e) => t.has(e)).map((t) => ({
6365
+ }, Kd = (e, t) => e.cache?.scope === "global" ? (e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source]).filter((e) => t.has(e)).map((t) => ({
6366
6366
  query: e.name,
6367
6367
  table: t
6368
- })) : [], Kd = (e) => {
6368
+ })) : [], qd = (e) => {
6369
6369
  if (e.length !== 0) return `A cached query shares one entry across tenants:\n${e.map((e) => ` • query '${e.query}' caches scope:'global' while reading '${e.table}', a tenant()-scoped table`).join("\n")}\n\nscope:'global' stores ONE entry for every caller. On a tenant-scoped table the\nrows depend on who asked, so the first caller's rows are served to the next one.\n\nUse scope:'tenant' — one entry per org, none shared across orgs. Use 'subject'\nif the result also depends on WHICH person is asking, and 'global' only for data\nthat depends on neither.`;
6370
- }, qd = (e, t) => {
6370
+ }, Jd = (e, t) => {
6371
6371
  let n, r = 0;
6372
6372
  for (let i of t) {
6373
6373
  let t = 0;
@@ -6378,7 +6378,7 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6378
6378
  o > r && o >= .6 && (r = o, n = i);
6379
6379
  }
6380
6380
  return n;
6381
- }, Jd = (e, t) => {
6381
+ }, Yd = (e, t) => {
6382
6382
  let n = St(), r = [];
6383
6383
  for (let i of e) for (let e of Lt(i.source)) {
6384
6384
  if (Mt(e)) {
@@ -6394,12 +6394,12 @@ var G = /* @__PURE__ */ new Map(), Gi = (e, t) => {
6394
6394
  t.size === 0 || t.has(e) || r.push({
6395
6395
  procedure: i.name,
6396
6396
  source: e,
6397
- didYouMean: qd(e, t),
6397
+ didYouMean: Jd(e, t),
6398
6398
  channel: !1
6399
6399
  });
6400
6400
  }
6401
6401
  return r;
6402
- }, Yd = (e) => {
6402
+ }, Xd = (e) => {
6403
6403
  if (e.length === 0) return;
6404
6404
  let t = e.map((e) => e.channel ? ` ${e.procedure}: source '${e.source}' names a reactivity channel nobody declared` : ` ${e.procedure}: source '${e.source}' matches no declared table` + (e.didYouMean === void 0 ? "" : ` — did you mean '${e.didYouMean}'?`)), n = e.some((e) => e.channel) ? "\nFor the `channel:` entries: declare it with `reactivityChannel(<name>)` and pass the\nCHANNEL as `source:`, not its key as a string. Authoring against the object is what\nmakes a channel source impossible to leave stale — you cannot import a declaration\nthat does not exist." : "";
6405
6405
  return `${e.length} reactive source(s) name a table that does not exist:\n${t.join("\n")}\n
@@ -6408,16 +6408,16 @@ update again, which is indistinguishable from "nothing has changed" — so the
6408
6408
  symptom is silence, and silence is what this surface exists to eliminate.
6409
6409
  A \`source:\` is a STRING, so \`tsc\` cannot see a stale one and a rename leaves it
6410
6410
  behind quietly.` + n;
6411
- }, Xd = (e) => e.old ?? e.new ?? {}, Zd = (e) => String(Xd(e).id ?? ""), Qd = (e) => {
6412
- let t = Xd(e).tenantId;
6411
+ }, Zd = (e) => e.old ?? e.new ?? {}, Qd = (e) => String(Zd(e).id ?? ""), $d = (e) => {
6412
+ let t = Zd(e).tenantId;
6413
6413
  return typeof t == "string" ? t : null;
6414
- }, $d = (e) => e.op === "update" && (e.old?.deletedAt ?? null) === null && (e.new?.deletedAt ?? null) !== null, ef = (e, t) => {
6415
- let n = $d(t);
6414
+ }, ef = (e) => e.op === "update" && (e.old?.deletedAt ?? null) === null && (e.new?.deletedAt ?? null) !== null, tf = (e, t) => {
6415
+ let n = ef(t);
6416
6416
  return t.op !== "delete" && !n ? [] : e.filter((e) => e.targetTable === t.table && e.policy !== "keep" && (!n || e.onSoftDelete));
6417
- }, tf = async (e, t, n) => {
6418
- let r = ef(t, n);
6417
+ }, nf = async (e, t, n) => {
6418
+ let r = tf(t, n);
6419
6419
  if (r.length === 0) return [];
6420
- let i = Zd(n), a = Qd(n), o = [];
6420
+ let i = Qd(n), a = $d(n), o = [];
6421
6421
  for (let t of r) {
6422
6422
  let n = await e.query({
6423
6423
  table: t.table,
@@ -6441,7 +6441,7 @@ behind quietly.` + n;
6441
6441
  });
6442
6442
  }
6443
6443
  return o;
6444
- }, nf = (e, t) => {
6444
+ }, rf = (e, t) => {
6445
6445
  let n = [];
6446
6446
  for (let r of e) for (let e of r.appliedPluginRefs ?? []) {
6447
6447
  let i = e.column, a;
@@ -6460,26 +6460,26 @@ behind quietly.` + n;
6460
6460
  });
6461
6461
  }
6462
6462
  return n.filter((e) => e.policy !== "keep");
6463
- }, rf = class extends y.TaggedError()("CircuitOpen", {
6463
+ }, af = class extends y.TaggedError()("CircuitOpen", {
6464
6464
  name: y.String,
6465
6465
  retryAfterMs: y.Number
6466
- }) {}, af = {
6466
+ }) {}, of = {
6467
6467
  tag: "closed",
6468
6468
  failureCount: 0,
6469
6469
  halfOpenSuccesses: 0,
6470
6470
  openedAt: 0
6471
- }, of = { make: (n) => o.gen(function* () {
6472
- let r = n.name ?? "circuit", i = a.toMillis(a.decode(n.resetTimeout)), s = n.halfOpenSuccessThreshold ?? 1, c = n.isFailure ?? (() => !0), l = yield* _.make(af), u = o.gen(function* () {
6471
+ }, sf = { make: (n) => o.gen(function* () {
6472
+ let r = n.name ?? "circuit", i = a.toMillis(a.decode(n.resetTimeout)), s = n.halfOpenSuccessThreshold ?? 1, c = n.isFailure ?? (() => !0), l = yield* _.make(of), u = o.gen(function* () {
6473
6473
  let e = yield* _.get(l);
6474
6474
  if (e.tag === "half-open") {
6475
6475
  let t = e.halfOpenSuccesses + 1;
6476
- yield* _.set(l, t >= s ? af : {
6476
+ yield* _.set(l, t >= s ? of : {
6477
6477
  ...e,
6478
6478
  halfOpenSuccesses: t
6479
6479
  });
6480
6480
  return;
6481
6481
  }
6482
- e.failureCount !== 0 && (yield* _.set(l, af));
6482
+ e.failureCount !== 0 && (yield* _.set(l, of));
6483
6483
  }), d = o.gen(function* () {
6484
6484
  let e = yield* t.currentTimeMillis, r = yield* _.get(l);
6485
6485
  if (r.tag === "half-open" || r.tag === "open") {
@@ -6517,7 +6517,7 @@ behind quietly.` + n;
6517
6517
  if (e.isInterruptedOnly(t)) return o.void;
6518
6518
  let n = e.failureOption(t), r = n._tag === "Some" ? n.value : void 0;
6519
6519
  return c(r) ? d : o.void;
6520
- })) : yield* o.fail(new rf({
6520
+ })) : yield* o.fail(new af({
6521
6521
  name: r,
6522
6522
  retryAfterMs: n
6523
6523
  }));
@@ -6526,15 +6526,15 @@ behind quietly.` + n;
6526
6526
  value: _.get(l).pipe(o.map((e) => e.tag)),
6527
6527
  enumerable: !0
6528
6528
  }), Object.defineProperty(m, "reset", {
6529
- value: _.set(l, af),
6529
+ value: _.set(l, of),
6530
6530
  enumerable: !0
6531
6531
  }), m;
6532
- }) }, sf, cf = (e) => {
6533
- sf = e;
6534
- }, lf = () => {
6535
- sf = void 0;
6536
- }, uf = () => sf, df = async (e, t = {}) => {
6537
- let n = t.scopes === void 0 ? zt(t.id ?? "system") : zt(t.id ?? "system", t.scopes), r = t.store ?? sf?.dataStore, i = t.schemaRegistry ?? sf?.schemaRegistry, a = t.dialect ?? sf?.dialect;
6532
+ }) }, cf, lf = (e) => {
6533
+ cf = e;
6534
+ }, uf = () => {
6535
+ cf = void 0;
6536
+ }, df = () => cf, ff = async (e, t = {}) => {
6537
+ let n = t.scopes === void 0 ? zt(t.id ?? "system") : zt(t.id ?? "system", t.scopes), r = t.store ?? cf?.dataStore, i = t.schemaRegistry ?? cf?.schemaRegistry, a = t.dialect ?? cf?.dialect;
6538
6538
  if (r === void 0 || i === void 0) throw Error("runAsSystem: no data store available — register one at boot via setSystemStoreHandle({ dataStore, schemaRegistry }) or pass { store, schemaRegistry } in the options.");
6539
6539
  return e({
6540
6540
  subject: n,
@@ -6545,20 +6545,20 @@ behind quietly.` + n;
6545
6545
  rowFilter: gi
6546
6546
  })
6547
6547
  });
6548
- }, ff = (e) => u.mergeAll(u.succeed(it, it.of(({ headers: t, clientId: n }) => o.promise(async () => {
6548
+ }, pf = (e) => u.mergeAll(u.succeed(rt, rt.of(({ headers: t, clientId: n }) => o.promise(async () => {
6549
6549
  let r = await e.resolveSubject({
6550
6550
  headers: Ui(n, t),
6551
6551
  clientId: n
6552
6552
  });
6553
6553
  return Li(n, r.credentialExpiresAt), r.subject;
6554
- }))), u.succeed(st, st.of(({ headers: e, clientId: t }) => o.sync(() => {
6554
+ }))), u.succeed(ot, ot.of(({ headers: e, clientId: t }) => o.sync(() => {
6555
6555
  let n = Ri(t) ?? wn(Ui(t, e)), r = e["idempotency-key"];
6556
6556
  return {
6557
6557
  clientId: t,
6558
6558
  ...r ? { idempotencyKey: r } : {},
6559
6559
  ...n === void 0 ? {} : { credentialExpiresAt: n }
6560
6560
  };
6561
- })))), pf = (e) => {
6561
+ })))), mf = (e) => {
6562
6562
  let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
6563
6563
  if (t === void 0) return {
6564
6564
  sameRegion: [],
@@ -6586,7 +6586,7 @@ behind quietly.` + n;
6586
6586
  return r.loadSnapshot();
6587
6587
  }
6588
6588
  };
6589
- }, mf = (e = process.env) => {
6589
+ }, hf = (e = process.env) => {
6590
6590
  for (let t of [
6591
6591
  "VOLTRO_REGION",
6592
6592
  "AWS_REGION",
@@ -6598,7 +6598,7 @@ behind quietly.` + n;
6598
6598
  let n = e[t];
6599
6599
  if (typeof n == "string" && n.length > 0) return n;
6600
6600
  }
6601
- }, hf = () => {
6601
+ }, gf = () => {
6602
6602
  let e = {
6603
6603
  primary: 0,
6604
6604
  lagByReplica: /* @__PURE__ */ new Map()
@@ -6623,7 +6623,7 @@ behind quietly.` + n;
6623
6623
  e.lagByReplica.set(t, n);
6624
6624
  }
6625
6625
  };
6626
- }, gf = Symbol.for("@voltro/ScheduleDefinition"), _f = (e) => typeof e == "object" && !!e && gf in e, vf = 18e5, yf = (e) => {
6626
+ }, _f = Symbol.for("@voltro/ScheduleDefinition"), vf = (e) => typeof e == "object" && !!e && _f in e, yf = 18e5, bf = (e) => {
6627
6627
  let t = r.parse(e.cron, e.timezone);
6628
6628
  if (s.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
6629
6629
  if (!e.timezone || e.timezone.trim() === "") throw Error(`defineSchedule("${e.name}"): timezone is required (e.g. "UTC", "Europe/Berlin").\nThe field is non-optional in \`ScheduleDefinition\`, so an ABSENT one is a tsc error and never reaches here. Arriving at this message means the value was present and EMPTY — almost always \`process.env.TZ ?? ''\` or a config lookup that missed. A reporter lost a crashloop to it, so the distinction is worth stating: this is not a check the type could have made for you.`);
@@ -6632,22 +6632,22 @@ behind quietly.` + n;
6632
6632
  ...e,
6633
6633
  onOverlap: e.onOverlap ?? "skip",
6634
6634
  backfill: e.backfill ?? "skip",
6635
- maxRuntimeMs: e.maxRuntimeMs ?? vf,
6636
- [gf]: !0
6635
+ maxRuntimeMs: e.maxRuntimeMs ?? yf,
6636
+ [_f]: !0
6637
6637
  };
6638
- }, bf = (e) => r.unsafeParse(e.cron, e.timezone), xf = (e, t = /* @__PURE__ */ new Date()) => r.next(bf(e), t), Sf = (e, t, n, i) => {
6639
- let a = bf(e), o = [], s = r.next(a, t);
6638
+ }, xf = (e) => r.unsafeParse(e.cron, e.timezone), Sf = (e, t = /* @__PURE__ */ new Date()) => r.next(xf(e), t), Cf = (e, t, n, i) => {
6639
+ let a = xf(e), o = [], s = r.next(a, t);
6640
6640
  for (; s.getTime() <= n.getTime() && o.length <= i;) o.push(s), s = r.next(a, s);
6641
6641
  return o;
6642
- }, X = "_voltro_wakeups", Cf = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, wf = (e) => ({
6642
+ }, X = "_voltro_wakeups", wf = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Tf = (e) => ({
6643
6643
  tenantId: String(e.tenantId),
6644
6644
  kind: String(e.kind),
6645
6645
  refId: String(e.refId),
6646
6646
  wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
6647
6647
  status: e.status === "fired" ? "fired" : "pending"
6648
- }), Tf = async (e, t) => {
6648
+ }), Ef = async (e, t) => {
6649
6649
  await e.upsert(X, {
6650
- id: Cf(t),
6650
+ id: wf(t),
6651
6651
  tenantId: t.tenantId,
6652
6652
  kind: t.kind,
6653
6653
  refId: t.refId,
@@ -6657,7 +6657,7 @@ behind quietly.` + n;
6657
6657
  conflictColumns: ["id"],
6658
6658
  update: ["wakeAt", "status"]
6659
6659
  });
6660
- }, Ef = async (e, t) => e.delete(X, Cf(t)), Df = async (e, t) => await e.update(X, Cf(t), { status: "fired" }) !== null, Of = (e, t) => ({ and: [{
6660
+ }, Df = async (e, t) => e.delete(X, wf(t)), Of = async (e, t) => await e.update(X, wf(t), { status: "fired" }) !== null, kf = (e, t) => ({ and: [{
6661
6661
  column: "id",
6662
6662
  op: "eq",
6663
6663
  value: e
@@ -6665,16 +6665,16 @@ behind quietly.` + n;
6665
6665
  column: "status",
6666
6666
  op: "eq",
6667
6667
  value: t
6668
- }] }), kf = async (e, t) => await e.updateMany(X, { status: "fired" }, { where: Of(Cf(t), "pending") }) > 0, Af = async (e, t) => {
6669
- await e.updateMany(X, { status: "pending" }, { where: Of(Cf(t), "fired") });
6670
- }, jf = {
6668
+ }] }), Af = async (e, t) => await e.updateMany(X, { status: "fired" }, { where: kf(wf(t), "pending") }) > 0, jf = async (e, t) => {
6669
+ await e.updateMany(X, { status: "pending" }, { where: kf(wf(t), "fired") });
6670
+ }, Mf = {
6671
6671
  column: "status",
6672
6672
  op: "eq",
6673
6673
  value: "pending"
6674
- }, Mf = async (e, t) => {
6674
+ }, Nf = async (e, t) => {
6675
6675
  let n = {
6676
6676
  table: X,
6677
- predicate: jf,
6677
+ predicate: Mf,
6678
6678
  order: [{
6679
6679
  column: "wakeAt",
6680
6680
  direction: "asc"
@@ -6683,18 +6683,18 @@ behind quietly.` + n;
6683
6683
  skip: void 0,
6684
6684
  projection: void 0
6685
6685
  };
6686
- return (await e.query(n)).map(wf);
6687
- }, Nf = async (e, t, n = 500) => {
6688
- let r = await Mf(e, n), i = t.getTime();
6686
+ return (await e.query(n)).map(Tf);
6687
+ }, Pf = async (e, t, n = 500) => {
6688
+ let r = await Nf(e, n), i = t.getTime();
6689
6689
  return r.filter((e) => e.wakeAt.getTime() <= i);
6690
- }, Pf = async (e) => (await Mf(e, 1))[0] ?? null, Ff = {
6690
+ }, Ff = async (e) => (await Nf(e, 1))[0] ?? null, If = {
6691
6691
  column: "status",
6692
6692
  op: "eq",
6693
6693
  value: "fired"
6694
- }, If = async (e, t = {}) => {
6694
+ }, Lf = async (e, t = {}) => {
6695
6695
  let n = {
6696
6696
  table: X,
6697
- predicate: Ff,
6697
+ predicate: If,
6698
6698
  order: [{
6699
6699
  column: "wakeAt",
6700
6700
  direction: "asc"
@@ -6705,12 +6705,12 @@ behind quietly.` + n;
6705
6705
  }, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
6706
6706
  for (let t of r) i !== void 0 && (t.wakeAt instanceof Date ? t.wakeAt : new Date(String(t.wakeAt))).getTime() >= i || await e.delete(X, String(t.id)) && a++;
6707
6707
  return a;
6708
- }, Lf = Ec, Rf = "default", zf = {
6708
+ }, Rf = Ec, zf = "default", Bf = {
6709
6709
  kind: "single",
6710
6710
  tryClaim: async () => !0
6711
- }, Bf = "_voltro_schedule_claims", Vf = 6e4, Hf = 64, Uf = (e) => Math.max((e ?? 6e4) * 64, 6e4), Wf = (e, t, n) => {
6711
+ }, Vf = "_voltro_schedule_claims", Hf = 6e4, Uf = 64, Wf = (e) => Math.max((e ?? 6e4) * 64, 6e4), Gf = (e, t, n) => {
6712
6712
  let r = async (t) => (await e.query({
6713
- table: Bf,
6713
+ table: Vf,
6714
6714
  order: [],
6715
6715
  predicate: O("id", t),
6716
6716
  projection: ["id"],
@@ -6721,7 +6721,7 @@ behind quietly.` + n;
6721
6721
  if (!(r - (i.get(t) ?? 0) < n)) {
6722
6722
  i.set(t, r);
6723
6723
  try {
6724
- await e.deleteMany(Bf, { where: C(O("scheduleName", t), ge("claimedAt", new Date(r - n))) });
6724
+ await e.deleteMany(Vf, { where: C(O("scheduleName", t), he("claimedAt", new Date(r - n))) });
6725
6725
  } catch {}
6726
6726
  }
6727
6727
  };
@@ -6733,13 +6733,13 @@ behind quietly.` + n;
6733
6733
  if (await r(u)) return !1;
6734
6734
  } catch {}
6735
6735
  try {
6736
- return await e.insert(Bf, {
6736
+ return await e.insert(Vf, {
6737
6737
  id: u,
6738
6738
  scheduleName: i,
6739
6739
  bucket: l,
6740
6740
  claimedBy: t,
6741
6741
  claimedAt: /* @__PURE__ */ new Date()
6742
- }), await a(i, Uf(s)), !0;
6742
+ }), await a(i, Wf(s)), !0;
6743
6743
  } catch (e) {
6744
6744
  try {
6745
6745
  if (await r(u)) return !1;
@@ -6751,12 +6751,12 @@ behind quietly.` + n;
6751
6751
  }
6752
6752
  }
6753
6753
  };
6754
- }, Gf = "_voltro_schedule_runs", Kf = async (e, t) => {
6754
+ }, Kf = "_voltro_schedule_runs", qf = async (e, t) => {
6755
6755
  let { store: n, coordinator: i, buildContext: a, replicaId: o, log: s, onRunEvent: c, interceptFire: l } = t, u = t.dormancy === "sleep", d = t.dormancyTenantId ?? "default", f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Map(), h = !1, g = new Map(e.map((e) => [e.name, e])), _ = (e, t) => {
6756
- c?.(e, Jf(t));
6756
+ c?.(e, Yf(t));
6757
6757
  }, v = async (e, t, r, i, a, c) => {
6758
6758
  try {
6759
- let s = `sr_${Ue()}`, l = await n.insert(Gf, {
6759
+ let s = `sr_${He()}`, l = await n.insert(Kf, {
6760
6760
  id: s,
6761
6761
  name: e.name,
6762
6762
  status: i,
@@ -6781,7 +6781,7 @@ behind quietly.` + n;
6781
6781
  }
6782
6782
  }, y = async (e, t) => {
6783
6783
  try {
6784
- let r = await n.update(Gf, e, t);
6784
+ let r = await n.update(Kf, e, t);
6785
6785
  r && _("update", r);
6786
6786
  } catch (t) {
6787
6787
  s.warn("schedule: failed to record run finish", {
@@ -6792,7 +6792,7 @@ behind quietly.` + n;
6792
6792
  }, b = async (e) => {
6793
6793
  try {
6794
6794
  let t = await n.query({
6795
- table: Gf,
6795
+ table: Kf,
6796
6796
  predicate: {
6797
6797
  _tag: "leaf",
6798
6798
  column: "status",
@@ -6827,7 +6827,7 @@ behind quietly.` + n;
6827
6827
  scheduleName: e.name,
6828
6828
  trigger: n,
6829
6829
  runId: o,
6830
- subject: Lf
6830
+ subject: Rf
6831
6831
  })
6832
6832
  };
6833
6833
  try {
@@ -6863,7 +6863,7 @@ behind quietly.` + n;
6863
6863
  let n = Z(t).includes("exceeded maxRuntimeMs"), r = Yn(t).dbMessage, i = typeof r == "string" && r !== "" ? `${Z(t)} — ${r}` : Z(t);
6864
6864
  o && await y(o, {
6865
6865
  status: "failed",
6866
- errorTag: n ? "timeout" : qf(t),
6866
+ errorTag: n ? "timeout" : Jf(t),
6867
6867
  errorMessage: i,
6868
6868
  completedAt: /* @__PURE__ */ new Date(),
6869
6869
  durationMs: Date.now() - c
@@ -6927,8 +6927,8 @@ behind quietly.` + n;
6927
6927
  }
6928
6928
  }, w = async (e) => {
6929
6929
  try {
6930
- let t = r.next(bf(e), /* @__PURE__ */ new Date());
6931
- await Tf(n, {
6930
+ let t = r.next(xf(e), /* @__PURE__ */ new Date());
6931
+ await Ef(n, {
6932
6932
  tenantId: d,
6933
6933
  kind: "schedule",
6934
6934
  refId: e.name,
@@ -6942,7 +6942,7 @@ behind quietly.` + n;
6942
6942
  }
6943
6943
  }, T = 2147483647, E = (e) => {
6944
6944
  if (h) return;
6945
- let n = bf(e), i = r.next(n, /* @__PURE__ */ new Date()), a = () => {
6945
+ let n = xf(e), i = r.next(n, /* @__PURE__ */ new Date()), a = () => {
6946
6946
  if (h) return;
6947
6947
  let n = i.getTime() - Date.now();
6948
6948
  if (n > T) {
@@ -6964,7 +6964,7 @@ behind quietly.` + n;
6964
6964
  let i;
6965
6965
  try {
6966
6966
  let t = (await n.query({
6967
- table: Gf,
6967
+ table: Kf,
6968
6968
  order: [{
6969
6969
  column: "scheduledAt",
6970
6970
  direction: "desc"
@@ -6983,7 +6983,7 @@ behind quietly.` + n;
6983
6983
  return;
6984
6984
  }
6985
6985
  if (!i) return;
6986
- let a = bf(e), o = [], c = r.next(a, i), l = Date.now();
6986
+ let a = xf(e), o = [], c = r.next(a, i), l = Date.now();
6987
6987
  for (; c.getTime() < l && o.length < 1e3;) o.push(c), c = r.next(a, c);
6988
6988
  if (o.length !== 0) {
6989
6989
  if (s.info("schedule: backfill", {
@@ -7028,7 +7028,7 @@ behind quietly.` + n;
7028
7028
  let i = g.get(e);
7029
7029
  if (!i) throw Error(`scheduler.backfillRange: unknown schedule "${e}"`);
7030
7030
  if (!(t.getTime() < n.getTime())) throw Error(`scheduler.backfillRange("${e}"): 'from' (${t.toISOString()}) must be before 'to' (${n.toISOString()})`);
7031
- let a = Sf(i, t, n, r.cap);
7031
+ let a = Cf(i, t, n, r.cap);
7032
7032
  if (a.length > r.cap) throw Error(`scheduler.backfillRange("${e}"): more than ${r.cap} occurrences in ${t.toISOString()}..${n.toISOString()} — narrow the range or raise the cap`);
7033
7033
  let o = [];
7034
7034
  for (let e of a) {
@@ -7047,17 +7047,17 @@ behind quietly.` + n;
7047
7047
  f.clear(), s.info("scheduler: stopped");
7048
7048
  }
7049
7049
  };
7050
- }, Z = (e) => e?.message ?? String(e), qf = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Jf = (e) => {
7050
+ }, Z = (e) => e?.message ?? String(e), Jf = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Yf = (e) => {
7051
7051
  let t = {};
7052
7052
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
7053
7053
  return t;
7054
- }, Yf = 3e4, Xf = (e = process.env) => {
7054
+ }, Xf = 3e4, Zf = (e = process.env) => {
7055
7055
  let t = e.VOLTRO_POLL_CEILING_MS;
7056
- if (t === void 0) return Yf;
7056
+ if (t === void 0) return Xf;
7057
7057
  let n = Number(t);
7058
- return Number.isFinite(n) && n > 0 ? n : Yf;
7059
- }, Zf = (e, t, n, r) => {
7060
- let i = Math.max(t, r.maxIdleIntervalMs ?? Xf()), a = !1, o, s = !1, c = t, l = !1, u = !1, d = 0, f = (e) => {
7058
+ return Number.isFinite(n) && n > 0 ? n : Xf;
7059
+ }, Qf = (e, t, n, r) => {
7060
+ let i = Math.max(t, r.maxIdleIntervalMs ?? Zf()), a = !1, o, s = !1, c = t, l = !1, u = !1, d = 0, f = (e) => {
7061
7061
  if (!a) {
7062
7062
  if (o !== void 0 && clearTimeout(o), o = void 0, e === "disarm") {
7063
7063
  s = !0;
@@ -7100,7 +7100,7 @@ behind quietly.` + n;
7100
7100
  }), f(t);
7101
7101
  return;
7102
7102
  }
7103
- f(Qf(s, t, c, i, r.disarmWhenIdle ?? !1));
7103
+ f($f(s, t, c, i, r.disarmWhenIdle ?? !1));
7104
7104
  } finally {
7105
7105
  l = !1, u && !a && (u = !1, f(0));
7106
7106
  }
@@ -7124,107 +7124,107 @@ behind quietly.` + n;
7124
7124
  a || (a = !0, o !== void 0 && clearTimeout(o), o = void 0);
7125
7125
  }
7126
7126
  };
7127
- }, Qf = (e, t, n, r, i = !1) => {
7127
+ }, $f = (e, t, n, r, i = !1) => {
7128
7128
  if (e === void 0 || !e.idle) return t;
7129
7129
  if (e.nextDueInMs === void 0 && i) return "disarm";
7130
7130
  let a = Math.min(Math.max(n, t) * 2, r);
7131
7131
  return e.nextDueInMs === void 0 ? a : Math.max(t, Math.min(a, e.nextDueInMs));
7132
- }, $f = (e) => (t, n, r, i) => Zf(t, n, r, {
7132
+ }, ep = (e) => (t, n, r, i) => Qf(t, n, r, {
7133
7133
  ...e,
7134
7134
  ...i?.disarmWhenIdle === void 0 ? {} : { disarmWhenIdle: i.disarmWhenIdle }
7135
- }), ep = F("_voltro_schedule_runs", {
7136
- id: M({ prefix: "schrun" }),
7137
- name: I(),
7138
- status: I().oneOf([
7135
+ }), tp = I("_voltro_schedule_runs", {
7136
+ id: N({ prefix: "schrun" }),
7137
+ name: L(),
7138
+ status: L().oneOf([
7139
7139
  "running",
7140
7140
  "succeeded",
7141
7141
  "failed",
7142
7142
  "skipped",
7143
7143
  "missed"
7144
7144
  ]).default("running"),
7145
- trigger: I().oneOf([
7145
+ trigger: L().oneOf([
7146
7146
  "self",
7147
7147
  "external",
7148
7148
  "manual"
7149
7149
  ]).default("self"),
7150
- scheduledAt: L(),
7151
- firedAt: L().nullable(),
7152
- completedAt: L().nullable(),
7153
- durationMs: N().nullable(),
7154
- errorTag: I().nullable(),
7155
- errorMessage: I().nullable(),
7156
- coordinationOutcome: I().oneOf([
7150
+ scheduledAt: R(),
7151
+ firedAt: R().nullable(),
7152
+ completedAt: R().nullable(),
7153
+ durationMs: P().nullable(),
7154
+ errorTag: L().nullable(),
7155
+ errorMessage: L().nullable(),
7156
+ coordinationOutcome: L().oneOf([
7157
7157
  "single",
7158
7158
  "wonLock",
7159
7159
  "lostLock",
7160
7160
  "external",
7161
7161
  "cluster"
7162
7162
  ]).nullable(),
7163
- replicaId: I().nullable(),
7164
- result: P().nullable()
7165
- }).index(["name", "scheduledAt"]).index(["status"]), tp = F("_voltro_schedule_claims", {
7166
- id: M({ prefix: "schclaim" }),
7167
- scheduleName: I(),
7168
- bucket: I(),
7169
- claimedBy: I(),
7170
- claimedAt: L()
7171
- }).index(["scheduleName", "claimedAt"]).index(["claimedAt"]), np = F("_voltro_traces", {
7172
- id: M({ prefix: "span" }),
7173
- traceId: I(),
7174
- spanId: I(),
7175
- parentSpanId: I().nullable(),
7176
- name: I(),
7177
- kind: I().oneOf([
7163
+ replicaId: L().nullable(),
7164
+ result: F().nullable()
7165
+ }).index(["name", "scheduledAt"]).index(["status"]), np = I("_voltro_schedule_claims", {
7166
+ id: N({ prefix: "schclaim" }),
7167
+ scheduleName: L(),
7168
+ bucket: L(),
7169
+ claimedBy: L(),
7170
+ claimedAt: R()
7171
+ }).index(["scheduleName", "claimedAt"]).index(["claimedAt"]), rp = I("_voltro_traces", {
7172
+ id: N({ prefix: "span" }),
7173
+ traceId: L(),
7174
+ spanId: L(),
7175
+ parentSpanId: L().nullable(),
7176
+ name: L(),
7177
+ kind: L().oneOf([
7178
7178
  "internal",
7179
7179
  "server",
7180
7180
  "client",
7181
7181
  "producer",
7182
7182
  "consumer"
7183
7183
  ]).default("internal"),
7184
- status: I().oneOf([
7184
+ status: L().oneOf([
7185
7185
  "ok",
7186
7186
  "error",
7187
7187
  "unset"
7188
7188
  ]).default("unset"),
7189
- statusMessage: I().nullable(),
7190
- startedAt: L(),
7191
- endedAt: L(),
7192
- durationMs: N(),
7193
- attributes: P().nullable(),
7194
- events: P().nullable()
7195
- }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), rp = F("_voltro_undo_log", {
7196
- id: M({ prefix: "undo" }),
7197
- tag: I(),
7198
- label: I().nullable(),
7199
- subjectId: I().nullable(),
7200
- tenantId: I().nullable(),
7201
- traceId: I().nullable(),
7202
- changes: I(),
7189
+ statusMessage: L().nullable(),
7190
+ startedAt: R(),
7191
+ endedAt: R(),
7192
+ durationMs: P(),
7193
+ attributes: F().nullable(),
7194
+ events: F().nullable()
7195
+ }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), ip = I("_voltro_undo_log", {
7196
+ id: N({ prefix: "undo" }),
7197
+ tag: L(),
7198
+ label: L().nullable(),
7199
+ subjectId: L().nullable(),
7200
+ tenantId: L().nullable(),
7201
+ traceId: L().nullable(),
7202
+ changes: L(),
7203
7203
  crossesAction: E().default(!1),
7204
7204
  undone: E().default(!1),
7205
- createdAt: L().default("now")
7206
- }).index(["subjectId", "createdAt"]), ip = (e = process.env) => {
7205
+ createdAt: R().default("now")
7206
+ }).index(["subjectId", "createdAt"]), ap = (e = process.env) => {
7207
7207
  let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
7208
7208
  return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
7209
- }, ap = (e = process.env) => {
7209
+ }, op = (e = process.env) => {
7210
7210
  let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
7211
7211
  return t !== "off" && t !== "0" && t !== "false";
7212
- }, op = (e) => e.startsWith("_voltro"), sp = async (e, t, n) => (await e.query({
7212
+ }, sp = (e) => e.startsWith("_voltro"), cp = async (e, t, n) => (await e.query({
7213
7213
  table: t,
7214
7214
  predicate: O("id", n),
7215
7215
  order: []
7216
- }))[0] ?? null, cp = (e, t) => new Proxy(e, { get(e, n, r) {
7216
+ }))[0] ?? null, lp = (e, t) => new Proxy(e, { get(e, n, r) {
7217
7217
  if (n === "insert") return async (n, r) => {
7218
7218
  let i = await e.insert(n, r);
7219
- return op(n) || t({
7219
+ return sp(n) || t({
7220
7220
  table: n,
7221
7221
  op: "insert",
7222
7222
  next: i
7223
7223
  }), i;
7224
7224
  };
7225
7225
  if (n === "update") return async (n, r, i) => {
7226
- let a = op(n) ? null : await sp(e, n, r), o = await e.update(n, r, i);
7227
- return op(n) || t({
7226
+ let a = sp(n) ? null : await cp(e, n, r), o = await e.update(n, r, i);
7227
+ return sp(n) || t({
7228
7228
  table: n,
7229
7229
  op: "update",
7230
7230
  id: r,
@@ -7233,8 +7233,8 @@ behind quietly.` + n;
7233
7233
  }), o;
7234
7234
  };
7235
7235
  if (n === "delete") return async (n, r) => {
7236
- let i = op(n) ? null : await sp(e, n, r), a = await e.delete(n, r);
7237
- return !op(n) && a && t({
7236
+ let i = sp(n) ? null : await cp(e, n, r), a = await e.delete(n, r);
7237
+ return !sp(n) && a && t({
7238
7238
  table: n,
7239
7239
  op: "delete",
7240
7240
  id: r,
@@ -7243,10 +7243,10 @@ behind quietly.` + n;
7243
7243
  };
7244
7244
  let i = Reflect.get(e, n, r);
7245
7245
  return typeof i == "function" ? i.bind(e) : i;
7246
- } }), lp = (e) => {
7246
+ } }), up = (e) => {
7247
7247
  let t = [];
7248
7248
  return {
7249
- tx: cp(e, (e) => t.push(e)),
7249
+ tx: lp(e, (e) => t.push(e)),
7250
7250
  persist: async (e, n) => {
7251
7251
  if (t.length === 0 || n.tag.startsWith("__voltro")) return;
7252
7252
  let r = n.subject;
@@ -7262,13 +7262,13 @@ behind quietly.` + n;
7262
7262
  });
7263
7263
  }
7264
7264
  };
7265
- }, up = (e) => e.startsWith("_voltro"), dp = (e) => {
7265
+ }, dp = (e) => e.startsWith("_voltro"), fp = (e) => {
7266
7266
  let t = e?.id;
7267
7267
  return typeof t == "string" ? t : void 0;
7268
- }, fp = (e) => {
7268
+ }, pp = (e) => {
7269
7269
  let t = /* @__PURE__ */ new Map(), n = (e, n) => {
7270
- if (n == null || up(e)) return;
7271
- let r = dp(n);
7270
+ if (n == null || dp(e)) return;
7271
+ let r = fp(n);
7272
7272
  r !== void 0 && t.set(`${e}\u0000${r}`, {
7273
7273
  table: e,
7274
7274
  id: r,
@@ -7293,9 +7293,9 @@ behind quietly.` + n;
7293
7293
  } }),
7294
7294
  drain: () => [...t.values()]
7295
7295
  };
7296
- }, pp = (e) => {
7296
+ }, mp = (e) => {
7297
7297
  if (e !== !0 && e !== void 0) return e === !1 ? {} : e;
7298
- }, mp = async (e) => {
7298
+ }, hp = async (e) => {
7299
7299
  if (e.touched.length === 0) return;
7300
7300
  let t = {
7301
7301
  store: e.store,
@@ -7304,7 +7304,7 @@ behind quietly.` + n;
7304
7304
  for (let { table: n, row: r } of e.touched) {
7305
7305
  let e = j(n)?.appliedRules;
7306
7306
  if (e !== void 0 && e.length !== 0) for (let i of e) {
7307
- let e = pp(await i.predicate(r, t));
7307
+ let e = mp(await i.predicate(r, t));
7308
7308
  if (e !== void 0) {
7309
7309
  if (i.severity === "warning") {
7310
7310
  Ht.warn("business rule violated (warning)", {
@@ -7315,7 +7315,7 @@ behind quietly.` + n;
7315
7315
  });
7316
7316
  continue;
7317
7317
  }
7318
- throw new at({
7318
+ throw new it({
7319
7319
  rule: i.name,
7320
7320
  severity: "error",
7321
7321
  ...e.params === void 0 ? {} : { params: e.params },
@@ -7325,14 +7325,14 @@ behind quietly.` + n;
7325
7325
  }
7326
7326
  }
7327
7327
  }
7328
- }, hp = (e) => {
7328
+ }, gp = (e) => {
7329
7329
  if (e.id !== void 0) return e.id;
7330
7330
  let t = e.next?.id;
7331
7331
  if (typeof t == "string") return t;
7332
7332
  let n = e.prev?.id;
7333
7333
  return typeof n == "string" ? n : void 0;
7334
- }, gp = (e) => {
7335
- let t = hp(e);
7334
+ }, _p = (e) => {
7335
+ let t = gp(e);
7336
7336
  switch (e.op) {
7337
7337
  case "insert": return t === void 0 ? null : {
7338
7338
  table: e.table,
@@ -7356,28 +7356,28 @@ behind quietly.` + n;
7356
7356
  row: e.prev
7357
7357
  };
7358
7358
  }
7359
- }, _p = (e) => {
7360
- if (e.crossesAction) throw new vp(e.invocationId, "action");
7359
+ }, vp = (e) => {
7360
+ if (e.crossesAction) throw new yp(e.invocationId, "action");
7361
7361
  let t = [];
7362
7362
  for (let n = e.changes.length - 1; n >= 0; --n) {
7363
- let r = gp(e.changes[n]);
7363
+ let r = _p(e.changes[n]);
7364
7364
  r !== null && t.push(r);
7365
7365
  }
7366
7366
  return t;
7367
- }, vp = class extends Error {
7367
+ }, yp = class extends Error {
7368
7368
  invocationId;
7369
7369
  boundary;
7370
7370
  _tag = "UndoBoundaryError";
7371
7371
  constructor(e, t) {
7372
7372
  super(t === "action" ? `cannot undo invocation ${e}: it crossed an action (external side effect)` : `cannot undo invocation ${e}: the row changed since (conflict)`), this.invocationId = e, this.boundary = t, this.name = "UndoBoundaryError";
7373
7373
  }
7374
- }, yp = (e, t, n = ["updatedAt", "updatedBy"]) => {
7374
+ }, bp = (e, t, n = ["updatedAt", "updatedBy"]) => {
7375
7375
  if (t == null) return e == null;
7376
7376
  if (e == null) return !1;
7377
7377
  let r = new Set(n);
7378
7378
  for (let [n, i] of Object.entries(t)) if (!r.has(n) && !Object.is(e[n], i) && JSON.stringify(e[n]) !== JSON.stringify(i)) return !1;
7379
7379
  return !0;
7380
- }, bp = class {
7380
+ }, xp = class {
7381
7381
  capacity;
7382
7382
  done = [];
7383
7383
  undone = [];
@@ -7413,7 +7413,7 @@ behind quietly.` + n;
7413
7413
  redo: [...this.undone]
7414
7414
  };
7415
7415
  }
7416
- }, xp = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
7416
+ }, Sp = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
7417
7417
  table: e.table,
7418
7418
  op: "insert",
7419
7419
  next: e.new ?? null
@@ -7430,7 +7430,7 @@ behind quietly.` + n;
7430
7430
  table: e.table,
7431
7431
  op: "delete",
7432
7432
  prev: e.old ?? null
7433
- }, Sp = async (e, t) => {
7433
+ }, Cp = async (e, t) => {
7434
7434
  switch (t.op) {
7435
7435
  case "delete":
7436
7436
  await e.delete(t.table, t.id);
@@ -7448,21 +7448,21 @@ behind quietly.` + n;
7448
7448
  await e.insert(t.table, t.row);
7449
7449
  return;
7450
7450
  }
7451
- }, Cp = async (e, t) => {
7452
- for (let n of t) await Sp(e, n);
7453
- }, wp = (e) => e.request?.subject?.id ?? null, Tp = (e) => e === !0 || e === 1, Ep = async (e, t, n) => (await e.query({
7451
+ }, wp = async (e, t) => {
7452
+ for (let n of t) await Cp(e, n);
7453
+ }, Tp = (e) => e.request?.subject?.id ?? null, Ep = (e) => e === !0 || e === 1, Dp = async (e, t, n) => (await e.query({
7454
7454
  table: t,
7455
7455
  predicate: O("id", n),
7456
7456
  order: []
7457
- }))[0] ?? null, Dp = (e) => {
7457
+ }))[0] ?? null, Op = (e) => {
7458
7458
  try {
7459
7459
  let t = JSON.parse(String(e ?? "[]"));
7460
7460
  return Array.isArray(t) ? t : [];
7461
7461
  } catch {
7462
7462
  return [];
7463
7463
  }
7464
- }, Op = (e) => e.id ?? e.next?.id ?? e.prev?.id, kp = async (e, t) => {
7465
- let n = wp(t);
7464
+ }, kp = (e) => e.id ?? e.next?.id ?? e.prev?.id, Ap = async (e, t) => {
7465
+ let n = Tp(t);
7466
7466
  return [...await t.store.query({
7467
7467
  table: "_voltro_undo_log",
7468
7468
  predicate: O("subjectId", n),
@@ -7471,72 +7471,72 @@ behind quietly.` + n;
7471
7471
  id: String(e.id),
7472
7472
  tag: String(e.tag ?? ""),
7473
7473
  label: e.label ?? null,
7474
- undone: Tp(e.undone),
7475
- crossesAction: Tp(e.crossesAction),
7474
+ undone: Ep(e.undone),
7475
+ crossesAction: Ep(e.crossesAction),
7476
7476
  createdAt: String(e.createdAt ?? "")
7477
7477
  }));
7478
- }, Ap = async (e, t) => {
7479
- let n = await Ep(t.store, "_voltro_undo_log", e.invocationId);
7480
- if (!n) throw new yt({ invocationId: e.invocationId });
7481
- if ((n.subjectId ?? null) !== wp(t)) throw new vt({ invocationId: e.invocationId });
7482
- return n;
7483
7478
  }, jp = async (e, t) => {
7484
- let n = await Ap(e, t);
7485
- if (Tp(n.undone)) return { ok: !0 };
7486
- if (Tp(n.crossesAction)) throw new _t({
7479
+ let n = await Dp(t.store, "_voltro_undo_log", e.invocationId);
7480
+ if (!n) throw new vt({ invocationId: e.invocationId });
7481
+ if ((n.subjectId ?? null) !== Tp(t)) throw new _t({ invocationId: e.invocationId });
7482
+ return n;
7483
+ }, Mp = async (e, t) => {
7484
+ let n = await jp(e, t);
7485
+ if (Ep(n.undone)) return { ok: !0 };
7486
+ if (Ep(n.crossesAction)) throw new gt({
7487
7487
  invocationId: e.invocationId,
7488
7488
  reason: "action"
7489
7489
  });
7490
- let r = Dp(n.changes);
7490
+ let r = Op(n.changes);
7491
7491
  for (let n of r) {
7492
- let r = Op(n);
7493
- if (r !== void 0 && !yp(await Ep(t.store, n.table, r), n.next ?? null)) throw new _t({
7492
+ let r = kp(n);
7493
+ if (r !== void 0 && !bp(await Dp(t.store, n.table, r), n.next ?? null)) throw new gt({
7494
7494
  invocationId: e.invocationId,
7495
7495
  reason: "conflict"
7496
7496
  });
7497
7497
  }
7498
7498
  let i = {
7499
7499
  invocationId: e.invocationId,
7500
- subject: wp(t),
7500
+ subject: Tp(t),
7501
7501
  changes: r,
7502
7502
  crossesAction: !1
7503
7503
  };
7504
- return await Cp(t.store, _p(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
7505
- }, Mp = async (e, t) => {
7506
- let n = await Ap(e, t);
7507
- if (!Tp(n.undone)) return { ok: !0 };
7508
- for (let e of Dp(n.changes)) {
7509
- let n = Op(e);
7504
+ return await wp(t.store, vp(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
7505
+ }, Np = async (e, t) => {
7506
+ let n = await jp(e, t);
7507
+ if (!Ep(n.undone)) return { ok: !0 };
7508
+ for (let e of Op(n.changes)) {
7509
+ let n = kp(e);
7510
7510
  e.op === "insert" && e.next ? await t.store.insert(e.table, e.next) : e.op === "update" && n !== void 0 && e.next ? await t.store.update(e.table, n, e.next) : e.op === "delete" && n !== void 0 && await t.store.delete(e.table, n);
7511
7511
  }
7512
7512
  return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
7513
- }, Np = "_voltro_approvals", Pp = 864e5, Fp = F(Np, {
7514
- id: M({ prefix: "apv" }),
7515
- intentKey: I().maxLength(191),
7516
- procedure: I(),
7517
- kind: I(),
7518
- requestedBy: I().nullable(),
7519
- tenantId: I().nullable(),
7520
- payload: I(),
7521
- approverGuards: I(),
7522
- approverScopes: I(),
7523
- reason: I().nullable(),
7524
- status: I().default("pending"),
7525
- decidedBy: I().nullable(),
7526
- decidedAt: L().nullable(),
7527
- note: I().nullable(),
7528
- traceId: I().nullable(),
7529
- requestedAt: L().default("now"),
7530
- expiresAt: L(),
7531
- consumedAt: L().nullable()
7532
- }).index(["status", "expiresAt"]).index(["requestedBy"]), Ip = () => {
7533
- De({
7513
+ }, Pp = "_voltro_approvals", Fp = 864e5, Ip = I(Pp, {
7514
+ id: N({ prefix: "apv" }),
7515
+ intentKey: L().maxLength(191),
7516
+ procedure: L(),
7517
+ kind: L(),
7518
+ requestedBy: L().nullable(),
7519
+ tenantId: L().nullable(),
7520
+ payload: L(),
7521
+ approverGuards: L(),
7522
+ approverScopes: L(),
7523
+ reason: L().nullable(),
7524
+ status: L().default("pending"),
7525
+ decidedBy: L().nullable(),
7526
+ decidedAt: R().nullable(),
7527
+ note: L().nullable(),
7528
+ traceId: L().nullable(),
7529
+ requestedAt: R().default("now"),
7530
+ expiresAt: R(),
7531
+ consumedAt: R().nullable()
7532
+ }).index(["status", "expiresAt"]).index(["requestedBy"]), Lp = () => {
7533
+ Ee({
7534
7534
  source: "framework",
7535
- table: Np,
7535
+ table: Pp,
7536
7536
  timeColumn: "requestedAt",
7537
- ttlMs: Ae(process.env.VOLTRO_APPROVALS_TTL_HOURS, 720)
7537
+ ttlMs: ke(process.env.VOLTRO_APPROVALS_TTL_HOURS, 720)
7538
7538
  });
7539
- }, Lp = (e, t) => e.map((e) => jt(e) ? {
7539
+ }, Rp = (e, t) => e.map((e) => jt(e) ? {
7540
7540
  kind: "policy",
7541
7541
  action: e.action,
7542
7542
  resourceType: e.resourceType,
@@ -7546,7 +7546,7 @@ behind quietly.` + n;
7546
7546
  scope: typeof e.scope == "string" ? [e.scope] : [...e.scope],
7547
7547
  mode: e.mode ?? "all",
7548
7548
  resource: e.resource?.(t) ?? null
7549
- }), Rp = (e) => e.map((e) => e.kind === "policy" ? {
7549
+ }), zp = (e) => e.map((e) => e.kind === "policy" ? {
7550
7550
  action: e.action,
7551
7551
  resourceType: e.resourceType,
7552
7552
  resource: () => e.resource ?? void 0
@@ -7554,7 +7554,7 @@ behind quietly.` + n;
7554
7554
  scope: e.scope,
7555
7555
  mode: e.mode,
7556
7556
  ...e.resource === null ? {} : { resource: () => e.resource ?? void 0 }
7557
- }), zp = (e) => e.flatMap((e) => e.kind === "policy" ? [`${e.resourceType}:${e.action}`] : [...e.scope]), Bp = (e) => {
7557
+ }), Bp = (e) => e.flatMap((e) => e.kind === "policy" ? [`${e.resourceType}:${e.action}`] : [...e.scope]), Vp = (e) => {
7558
7558
  let t = (e) => {
7559
7559
  if (Array.isArray(e)) return e.map(t);
7560
7560
  if (typeof e == "object" && e) {
@@ -7565,7 +7565,7 @@ behind quietly.` + n;
7565
7565
  return e;
7566
7566
  };
7567
7567
  return JSON.stringify(t(e) ?? null);
7568
- }, Vp = (e) => {
7568
+ }, Hp = (e) => {
7569
7569
  let t = [
7570
7570
  e.procedure,
7571
7571
  e.requestedBy ?? "",
@@ -7573,49 +7573,49 @@ behind quietly.` + n;
7573
7573
  e.payload,
7574
7574
  e.nonce ?? ""
7575
7575
  ].map((e) => `${e.length}:${e}`).join("");
7576
- return Ve("sha256").update(t, "utf8").digest("hex");
7577
- }, Hp = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" ? e : (/* @__PURE__ */ new Date(0)).toISOString(), Up = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : 0, Wp = (e) => {
7576
+ return Be("sha256").update(t, "utf8").digest("hex");
7577
+ }, Up = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" ? e : (/* @__PURE__ */ new Date(0)).toISOString(), Wp = (e) => e instanceof Date ? e.getTime() : typeof e == "string" ? Date.parse(e) : 0, Gp = (e) => {
7578
7578
  try {
7579
7579
  let t = JSON.parse(String(e ?? "[]"));
7580
7580
  return Array.isArray(t) ? t : [];
7581
7581
  } catch {
7582
7582
  return [];
7583
7583
  }
7584
- }, Gp = async (e, t) => (await e.query({
7584
+ }, Kp = async (e, t) => (await e.query({
7585
7585
  table: "_voltro_approvals",
7586
7586
  predicate: O("intentKey", t),
7587
7587
  order: []
7588
- }))[0] ?? null, Kp = async (e, t) => (await e.query({
7588
+ }))[0] ?? null, qp = async (e, t) => (await e.query({
7589
7589
  table: "_voltro_approvals",
7590
7590
  predicate: O("id", t),
7591
7591
  order: []
7592
- }))[0] ?? null, qp = async (e, t, n) => {
7592
+ }))[0] ?? null, Jp = async (e, t, n) => {
7593
7593
  let r = String(t.intentKey ?? ""), i = r.includes("#") ? r : `${r}#${String(t.id)}`;
7594
- await e.update(Np, String(t.id), {
7594
+ await e.update(Pp, String(t.id), {
7595
7595
  ...n,
7596
7596
  intentKey: i
7597
7597
  });
7598
- }, Jp = (e) => {
7598
+ }, Yp = (e) => {
7599
7599
  let t = /^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)$/.exec(e.trim());
7600
7600
  if (t === null) return null;
7601
7601
  let n = Number(t[1]);
7602
7602
  if (!(Number.isFinite(n) && n > 0)) return null;
7603
7603
  let r = t[2];
7604
7604
  return n * (r === "ms" ? 1 : r === "s" ? 1e3 : r === "m" ? 6e4 : r === "h" ? 36e5 : 864e5);
7605
- }, Yp = (e) => {
7605
+ }, Xp = (e) => {
7606
7606
  let t = e.store, n = e.now ?? Date.now, r = e.defaultExpiryMs ?? 864e5;
7607
- Ip();
7607
+ Lp();
7608
7608
  let i = (e) => {
7609
7609
  if (e.expiresIn === void 0) return r;
7610
- let t = Jp(e.expiresIn);
7610
+ let t = Yp(e.expiresIn);
7611
7611
  if (t === null) throw Error(`requiresApproval.expiresIn must be an interval like '4h' / '30m' (got ${JSON.stringify(e.expiresIn)})`);
7612
7612
  return t;
7613
7613
  }, a = async (e, r, a) => {
7614
- let o = Lp(e.policy.approvers, e.input), s = A({
7614
+ let o = Rp(e.policy.approvers, e.input), s = A({
7615
7615
  kind: "typeid",
7616
7616
  prefix: "apv"
7617
- }, Np), c = n();
7618
- await t.insertIgnore(Np, {
7617
+ }, Pp), c = n();
7618
+ await t.insertIgnore(Pp, {
7619
7619
  id: s,
7620
7620
  intentKey: r,
7621
7621
  procedure: e.procedure,
@@ -7624,7 +7624,7 @@ behind quietly.` + n;
7624
7624
  tenantId: e.subject?.tenantId ?? null,
7625
7625
  payload: a,
7626
7626
  approverGuards: JSON.stringify(o),
7627
- approverScopes: JSON.stringify(zp(o)),
7627
+ approverScopes: JSON.stringify(Bp(o)),
7628
7628
  reason: e.policy.reason ?? null,
7629
7629
  status: "pending",
7630
7630
  decidedBy: null,
@@ -7635,36 +7635,36 @@ behind quietly.` + n;
7635
7635
  expiresAt: new Date(c + i(e.policy)),
7636
7636
  consumedAt: null
7637
7637
  }, { conflictColumns: ["intentKey"] });
7638
- let l = await Gp(t, r);
7639
- if (l === null) throw new rt({
7638
+ let l = await Kp(t, r);
7639
+ if (l === null) throw new nt({
7640
7640
  procedure: e.procedure,
7641
7641
  message: "the approval intent was written and could not be read back"
7642
7642
  });
7643
7643
  return l;
7644
- }, o = (e, t) => new tt({
7644
+ }, o = (e, t) => new et({
7645
7645
  approvalId: String(e.id),
7646
7646
  procedure: String(e.procedure),
7647
- expiresAt: Hp(e.expiresAt),
7648
- requiredScopes: zp(Wp(e.approverGuards)),
7647
+ expiresAt: Up(e.expiresAt),
7648
+ requiredScopes: Bp(Gp(e.approverGuards)),
7649
7649
  reason: e.reason ?? null,
7650
7650
  created: t
7651
7651
  });
7652
7652
  return { admit: async (e) => {
7653
- let r = Bp(e.input), i = Vp({
7653
+ let r = Vp(e.input), i = Hp({
7654
7654
  procedure: e.procedure,
7655
7655
  requestedBy: e.subject?.id ?? null,
7656
7656
  tenantId: e.subject?.tenantId ?? null,
7657
7657
  payload: r,
7658
7658
  nonce: e.nonce
7659
- }), s = await Gp(t, i);
7659
+ }), s = await Kp(t, i);
7660
7660
  if (s === null) throw o(await a(e, i, r), !0);
7661
- let c = String(s.status ?? "pending"), l = Up(s.expiresAt);
7662
- if ((c === "pending" || c === "approved") && n() > l) throw await qp(t, s, { status: "expired" }), new Xe({
7661
+ let c = String(s.status ?? "pending"), l = Wp(s.expiresAt);
7662
+ if ((c === "pending" || c === "approved") && n() > l) throw await Jp(t, s, { status: "expired" }), new Ye({
7663
7663
  approvalId: String(s.id),
7664
- expiredAt: Hp(s.expiresAt)
7664
+ expiredAt: Up(s.expiresAt)
7665
7665
  });
7666
7666
  if (c === "pending") throw o(s, !1);
7667
- if (c === "rejected") throw await qp(t, s, {}), new et({
7667
+ if (c === "rejected") throw await Jp(t, s, {}), new $e({
7668
7668
  approvalId: String(s.id),
7669
7669
  decidedBy: s.decidedBy ?? null,
7670
7670
  note: s.note ?? null
@@ -7675,18 +7675,18 @@ behind quietly.` + n;
7675
7675
  consumedAt: new Date(n()),
7676
7676
  intentKey: `${i}#${String(s.id)}`
7677
7677
  }, { where: C(O("id", String(s.id)), O("status", "approved")) }) === 1) return;
7678
- throw s = await Gp(t, i), s === null ? o(await a(e, i, r), !0) : o(s, !1);
7678
+ throw s = await Kp(t, i), s === null ? o(await a(e, i, r), !0) : o(s, !1);
7679
7679
  }
7680
- throw await qp(t, s, {}), o(await a(e, i, r), !0);
7680
+ throw await Jp(t, s, {}), o(await a(e, i, r), !0);
7681
7681
  } };
7682
- }, Xp, Zp = (e) => {
7683
- Xp = e;
7684
- }, Qp = () => Xp, $p = () => {
7685
- Xp = void 0;
7686
- }, em = async (e) => {
7682
+ }, Zp, Qp = (e) => {
7683
+ Zp = e;
7684
+ }, $p = () => Zp, em = () => {
7685
+ Zp = void 0;
7686
+ }, tm = async (e) => {
7687
7687
  if (e.policy === void 0) return;
7688
- let t = Qp();
7689
- if (t === void 0) throw new rt({
7688
+ let t = $p();
7689
+ if (t === void 0) throw new nt({
7690
7690
  procedure: e.procedure,
7691
7691
  message: `${e.procedure} declares \`requiresApproval\` and no approvals gate is installed on this boot path, so the framework cannot record the intent or verify a decision. Refusing the call rather than running it unapproved.`
7692
7692
  });
@@ -7698,30 +7698,30 @@ behind quietly.` + n;
7698
7698
  input: e.input,
7699
7699
  ...e.traceId === void 0 ? {} : { traceId: e.traceId }
7700
7700
  });
7701
- }, tm = async (e, t) => {
7702
- let n = t.now ?? Date.now, r = await Kp(e, t.approvalId);
7703
- if (r === null) throw new Qe({ approvalId: t.approvalId });
7701
+ }, nm = async (e, t) => {
7702
+ let n = t.now ?? Date.now, r = await qp(e, t.approvalId);
7703
+ if (r === null) throw new Ze({ approvalId: t.approvalId });
7704
7704
  let i = String(r.status ?? "pending");
7705
- if (i !== "pending") throw new $e({
7705
+ if (i !== "pending") throw new Qe({
7706
7706
  approvalId: t.approvalId,
7707
7707
  status: i
7708
7708
  });
7709
- if (n() > Up(r.expiresAt)) throw await qp(e, r, { status: "expired" }), new Xe({
7709
+ if (n() > Wp(r.expiresAt)) throw await Jp(e, r, { status: "expired" }), new Ye({
7710
7710
  approvalId: t.approvalId,
7711
- expiredAt: Hp(r.expiresAt)
7711
+ expiredAt: Up(r.expiresAt)
7712
7712
  });
7713
7713
  let a = t.approver?.id ?? null;
7714
- if (a === null) throw new Ze({
7714
+ if (a === null) throw new Xe({
7715
7715
  approvalId: t.approvalId,
7716
7716
  required: null,
7717
7717
  message: "an approval decision needs an identified subject — an anonymous caller cannot be the second human"
7718
7718
  });
7719
- if (a === (r.requestedBy ?? null)) throw new nt({
7719
+ if (a === (r.requestedBy ?? null)) throw new tt({
7720
7720
  approvalId: t.approvalId,
7721
7721
  subjectId: a
7722
7722
  });
7723
- let s = Rp(Wp(r.approverGuards)), c = await o.runPromise(z(t.approver, s, JSON.parse(String(r.payload ?? "null"))));
7724
- if (c) throw new Ze({
7723
+ let s = zp(Gp(r.approverGuards)), c = await o.runPromise(xt(t.approver, s, JSON.parse(String(r.payload ?? "null"))));
7724
+ if (c) throw new Xe({
7725
7725
  approvalId: t.approvalId,
7726
7726
  required: c.required ?? null,
7727
7727
  message: c.message
@@ -7733,8 +7733,8 @@ behind quietly.` + n;
7733
7733
  decidedAt: new Date(n()),
7734
7734
  note: t.note ?? null
7735
7735
  }, { where: C(O("id", t.approvalId), O("status", "pending")) }) !== 1) {
7736
- let n = await Kp(e, t.approvalId);
7737
- throw new $e({
7736
+ let n = await qp(e, t.approvalId);
7737
+ throw new Qe({
7738
7738
  approvalId: t.approvalId,
7739
7739
  status: String(n?.status ?? "unknown")
7740
7740
  });
@@ -7743,62 +7743,62 @@ behind quietly.` + n;
7743
7743
  approvalId: t.approvalId,
7744
7744
  status: l
7745
7745
  };
7746
- }, nm = async (e, t, n) => {
7746
+ }, rm = async (e, t, n) => {
7747
7747
  let r = t?.id ?? null;
7748
7748
  if (r === null) return [];
7749
7749
  let i = n?.now ?? Date.now, a = await e.query({
7750
- table: Np,
7751
- predicate: ue("status", ["pending", "approved"]),
7750
+ table: Pp,
7751
+ predicate: le("status", ["pending", "approved"]),
7752
7752
  order: []
7753
7753
  }), s = [];
7754
7754
  for (let e of a) {
7755
- if (i() > Up(e.expiresAt)) continue;
7756
- let n = Wp(e.approverGuards), a = (e.requestedBy ?? null) === r, c = a ? "requested" : null;
7757
- a || await o.runPromise(z(t, Rp(n), JSON.parse(String(e.payload ?? "null")))) === null && String(e.status) === "pending" && (c = "to-decide"), c !== null && s.push({
7755
+ if (i() > Wp(e.expiresAt)) continue;
7756
+ let n = Gp(e.approverGuards), a = (e.requestedBy ?? null) === r, c = a ? "requested" : null;
7757
+ a || await o.runPromise(xt(t, zp(n), JSON.parse(String(e.payload ?? "null")))) === null && String(e.status) === "pending" && (c = "to-decide"), c !== null && s.push({
7758
7758
  id: String(e.id),
7759
7759
  procedure: String(e.procedure),
7760
7760
  kind: String(e.kind) === "action" ? "action" : "mutation",
7761
7761
  requestedBy: e.requestedBy ?? null,
7762
7762
  status: String(e.status ?? "pending"),
7763
7763
  reason: e.reason ?? null,
7764
- requiredScopes: zp(n),
7765
- requestedAt: Hp(e.requestedAt),
7766
- expiresAt: Hp(e.expiresAt),
7764
+ requiredScopes: Bp(n),
7765
+ requestedAt: Up(e.requestedAt),
7766
+ expiresAt: Up(e.expiresAt),
7767
7767
  decidedBy: e.decidedBy ?? null,
7768
- decidedAt: e.decidedAt == null ? null : Hp(e.decidedAt),
7768
+ decidedAt: e.decidedAt == null ? null : Up(e.decidedAt),
7769
7769
  note: e.note ?? null,
7770
7770
  relation: c
7771
7771
  });
7772
7772
  }
7773
7773
  return s.sort((e, t) => t.requestedAt.localeCompare(e.requestedAt)).slice(0, n?.limit ?? 50);
7774
- }, rm = () => Ue(), im = (e) => e.request?.subject ?? null, am = async (e, t) => nm(t.store, im(t), { limit: e.limit ?? 50 }), om = async (e, t) => tm(t.store, {
7774
+ }, im = () => He(), am = (e) => e.request?.subject ?? null, om = async (e, t) => rm(t.store, am(t), { limit: e.limit ?? 50 }), sm = async (e, t) => nm(t.store, {
7775
7775
  approvalId: e.approvalId,
7776
7776
  decision: e.decision,
7777
- approver: im(t),
7777
+ approver: am(t),
7778
7778
  ...e.note === void 0 ? {} : { note: e.note }
7779
- }), sm = (e = process.env) => {
7779
+ }), cm = (e = process.env) => {
7780
7780
  let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
7781
7781
  return t === "off" || t === "0" || t === "false" ? "off" : t === "all" ? "all" : t === "interesting" || t === "on" || t === "1" || t === "true" ? "interesting" : e.NODE_ENV === "production" ? "off" : "interesting";
7782
- }, cm = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, lm = "«redacted»", um = (e) => {
7782
+ }, lm = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, um = "«redacted»", dm = (e) => {
7783
7783
  if (e == null) return null;
7784
7784
  let t = {};
7785
- for (let [n, r] of Object.entries(e)) t[n] = cm.test(n) ? lm : r;
7785
+ for (let [n, r] of Object.entries(e)) t[n] = lm.test(n) ? um : r;
7786
7786
  return t;
7787
- }, dm = (e) => {
7787
+ }, fm = (e) => {
7788
7788
  let t = e?.id;
7789
7789
  return typeof t == "string" ? t : void 0;
7790
- }, fm = (e, t) => {
7790
+ }, pm = (e, t) => {
7791
7791
  if (t.op === "insert") {
7792
- let n = dm(t.new);
7792
+ let n = fm(t.new);
7793
7793
  return n === void 0 ? e : e.filter((e) => e.id !== n);
7794
7794
  }
7795
7795
  if (t.op === "update") {
7796
7796
  if (t.old == null) return e;
7797
- let n = dm(t.new) ?? dm(t.old);
7797
+ let n = fm(t.new) ?? fm(t.old);
7798
7798
  return e.map((e) => e.id === n ? t.old : e);
7799
7799
  }
7800
7800
  return t.old == null ? e : [...e, t.old];
7801
- }, pm = class {
7801
+ }, mm = class {
7802
7802
  mode;
7803
7803
  capacity;
7804
7804
  now;
@@ -7818,8 +7818,8 @@ behind quietly.` + n;
7818
7818
  ts: this.now(),
7819
7819
  table: e.table,
7820
7820
  op: e.op,
7821
- old: um(e.old),
7822
- new: um(e.new),
7821
+ old: dm(e.old),
7822
+ new: dm(e.new),
7823
7823
  tenantId: n
7824
7824
  }), this.ring.length > this.capacity && this.ring.shift(), t;
7825
7825
  }
@@ -7832,23 +7832,23 @@ behind quietly.` + n;
7832
7832
  }
7833
7833
  replay(e, t, n) {
7834
7834
  let r = this.ring.filter((n) => n.table === e && n.seq > t).sort((e, t) => t.seq - e.seq), i = n;
7835
- for (let e of r) i = fm(i, e);
7835
+ for (let e of r) i = pm(i, e);
7836
7836
  return i;
7837
7837
  }
7838
- }, mm, hm = () => (mm === void 0 && (mm = new pm(sm())), mm), gm = (e) => {
7839
- mm = e;
7840
- }, _m = (e) => {
7841
- let t = hm();
7838
+ }, hm, gm = () => (hm === void 0 && (hm = new mm(cm())), hm), _m = (e) => {
7839
+ hm = e;
7840
+ }, vm = (e) => {
7841
+ let t = gm();
7842
7842
  if (t.enabled) try {
7843
7843
  t.record(e);
7844
7844
  } catch {}
7845
- }, vm = /* @__PURE__ */ new Set([
7845
+ }, ym = /* @__PURE__ */ new Set([
7846
7846
  "count",
7847
7847
  "sum",
7848
7848
  "avg",
7849
7849
  "min",
7850
7850
  "max"
7851
- ]), ym = (e) => {
7851
+ ]), bm = (e) => {
7852
7852
  if (e.joins !== void 0 && e.joins.length > 0) return {
7853
7853
  maintainable: !1,
7854
7854
  reason: "joins are not maintainable in v1"
@@ -7870,7 +7870,7 @@ behind quietly.` + n;
7870
7870
  reason: "v1 maintains exactly one aggregation"
7871
7871
  };
7872
7872
  let t = e.aggregations[0];
7873
- return vm.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
7873
+ return ym.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
7874
7874
  maintainable: !1,
7875
7875
  reason: `op '${t.op}' requires a column`
7876
7876
  } : {
@@ -7884,7 +7884,7 @@ behind quietly.` + n;
7884
7884
  maintainable: !1,
7885
7885
  reason: `op '${t.op}' is not maintainable`
7886
7886
  };
7887
- }, bm = "\0", xm = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(bm), Sm = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Cm = (e, t) => {
7887
+ }, xm = "\0", Sm = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(xm), Cm = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), wm = (e, t) => {
7888
7888
  switch (e.op) {
7889
7889
  case "count": return t.count;
7890
7890
  case "sum": return t.sum ?? 0;
@@ -7892,10 +7892,10 @@ behind quietly.` + n;
7892
7892
  case "min":
7893
7893
  case "max": return t.count > 0 ? t.extreme ?? null : null;
7894
7894
  }
7895
- }, wm = (e, t) => {
7895
+ }, Tm = (e, t) => {
7896
7896
  let n = /* @__PURE__ */ new Map();
7897
7897
  for (let r of t) {
7898
- let t = xm(r, e.groupBy), i = n.get(t), a = Sm(r, e.column);
7898
+ let t = Sm(r, e.groupBy), i = n.get(t), a = Cm(r, e.column);
7899
7899
  if (i === void 0) n.set(t, {
7900
7900
  count: 1,
7901
7901
  ...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
@@ -7911,19 +7911,19 @@ behind quietly.` + n;
7911
7911
  }
7912
7912
  }
7913
7913
  return n;
7914
- }, Tm = (e, t) => [...t.entries()].map(([t, n]) => ({
7914
+ }, Em = (e, t) => [...t.entries()].map(([t, n]) => ({
7915
7915
  groupKey: t,
7916
- value: Cm(e, n)
7917
- })), Em = (e, t, n) => {
7916
+ value: wm(e, n)
7917
+ })), Dm = (e, t, n) => {
7918
7918
  let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
7919
- let n = xm(t, e.groupBy), a = r.get(n);
7919
+ let n = Sm(t, e.groupBy), a = r.get(n);
7920
7920
  if (a === void 0) return;
7921
7921
  let o = a.count - 1;
7922
7922
  if (o <= 0) {
7923
7923
  r.delete(n);
7924
7924
  return;
7925
7925
  }
7926
- let s = Sm(t, e.column);
7926
+ let s = Cm(t, e.column);
7927
7927
  e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
7928
7928
  count: o,
7929
7929
  ...a.extreme === void 0 ? {} : { extreme: a.extreme }
@@ -7932,7 +7932,7 @@ behind quietly.` + n;
7932
7932
  ...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
7933
7933
  });
7934
7934
  }, o = (t) => {
7935
- let n = xm(t, e.groupBy), i = r.get(n), a = Sm(t, e.column);
7935
+ let n = Sm(t, e.groupBy), i = r.get(n), a = Cm(t, e.column);
7936
7936
  if (i === void 0) {
7937
7937
  r.set(n, {
7938
7938
  count: 1,
@@ -7952,15 +7952,15 @@ behind quietly.` + n;
7952
7952
  state: r,
7953
7953
  rescanGroups: [...i]
7954
7954
  };
7955
- }, Dm = (e, t, n, r) => {
7955
+ }, Om = (e, t, n, r) => {
7956
7956
  if (n.length === 0) return t;
7957
- let i = new Set(n), a = wm(e, r.filter((t) => i.has(xm(t, e.groupBy)))), o = new Map(t);
7957
+ let i = new Set(n), a = Tm(e, r.filter((t) => i.has(Sm(t, e.groupBy)))), o = new Map(t);
7958
7958
  for (let e of i) {
7959
7959
  let t = a.get(e);
7960
7960
  t === void 0 ? o.delete(e) : o.set(e, t);
7961
7961
  }
7962
7962
  return o;
7963
- }, Om = class {
7963
+ }, km = class {
7964
7964
  shape;
7965
7965
  state = /* @__PURE__ */ new Map();
7966
7966
  groups = /* @__PURE__ */ new Map();
@@ -7968,35 +7968,35 @@ behind quietly.` + n;
7968
7968
  this.shape = e;
7969
7969
  }
7970
7970
  seed(e) {
7971
- this.state = wm(this.shape, e), this.groups.clear();
7971
+ this.state = Tm(this.shape, e), this.groups.clear();
7972
7972
  for (let t of e) {
7973
- let e = xm(t, this.shape.groupBy);
7973
+ let e = Sm(t, this.shape.groupBy);
7974
7974
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
7975
7975
  }
7976
7976
  }
7977
7977
  applyChange(e) {
7978
7978
  let t = e.new;
7979
7979
  if (t) {
7980
- let e = xm(t, this.shape.groupBy);
7980
+ let e = Sm(t, this.shape.groupBy);
7981
7981
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
7982
7982
  }
7983
- let n = Em(this.shape, this.state, e);
7983
+ let n = Dm(this.shape, this.state, e);
7984
7984
  this.state = n.state;
7985
7985
  for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
7986
7986
  return n.rescanGroups;
7987
7987
  }
7988
7988
  resolveRescan(e, t) {
7989
7989
  if (e.length === 0) return;
7990
- this.state = Dm(this.shape, this.state, e, t);
7990
+ this.state = Om(this.shape, this.state, e, t);
7991
7991
  let n = new Set(e);
7992
7992
  for (let e of t) {
7993
- let t = xm(e, this.shape.groupBy);
7993
+ let t = Sm(e, this.shape.groupBy);
7994
7994
  n.has(t) && this.state.has(t) && !this.groups.has(t) && this.groups.set(t, this.groupValues(e));
7995
7995
  }
7996
7996
  for (let e of n) this.state.has(e) || this.groups.delete(e);
7997
7997
  }
7998
7998
  materialize() {
7999
- return Tm(this.shape, this.state).map((e) => ({
7999
+ return Em(this.shape, this.state).map((e) => ({
8000
8000
  groupKey: e.groupKey,
8001
8001
  group: this.groups.get(e.groupKey) ?? {},
8002
8002
  value: e.value
@@ -8009,19 +8009,19 @@ behind quietly.` + n;
8009
8009
  for (let r of t) n[r] = e[r];
8010
8010
  return n;
8011
8011
  }
8012
- }, km = F("_voltro_rebac_tuples", {
8013
- id: M({ prefix: "rbct" }),
8014
- subjectId: I(),
8015
- relation: I(),
8016
- resourceType: I(),
8017
- resourceId: I(),
8018
- tenantId: I().nullable(),
8019
- createdAt: L().default("now")
8012
+ }, Am = I("_voltro_rebac_tuples", {
8013
+ id: N({ prefix: "rbct" }),
8014
+ subjectId: L(),
8015
+ relation: L(),
8016
+ resourceType: L(),
8017
+ resourceId: L(),
8018
+ tenantId: L().nullable(),
8019
+ createdAt: R().default("now")
8020
8020
  }).index([
8021
8021
  "subjectId",
8022
8022
  "resourceType",
8023
8023
  "resourceId"
8024
- ]), Am = async (e, t, n, r) => t === null ? [] : (await e.query({
8024
+ ]), jm = async (e, t, n, r) => t === null ? [] : (await e.query({
8025
8025
  table: "_voltro_rebac_tuples",
8026
8026
  predicate: C(O("subjectId", t), O("resourceType", n), O("resourceId", r)),
8027
8027
  order: [],
@@ -8033,11 +8033,11 @@ behind quietly.` + n;
8033
8033
  relation: e.relation,
8034
8034
  resourceType: e.resourceType,
8035
8035
  resourceId: e.resourceId
8036
- })), jm = (e) => ({
8036
+ })), Mm = (e) => ({
8037
8037
  id: e.id,
8038
8038
  tenantId: e.tenantId,
8039
8039
  ...e.scopes === void 0 ? {} : { scopes: e.scopes }
8040
- }), Mm = (e, t) => {
8040
+ }), Nm = (e, t) => {
8041
8041
  let n = t.getPolicy ?? Gu;
8042
8042
  return (r, i) => {
8043
8043
  let a = e[i.tag];
@@ -8050,7 +8050,7 @@ behind quietly.` + n;
8050
8050
  if (s === void 0) return c("");
8051
8051
  let l = a.resourceId(i.input);
8052
8052
  if (l === null || l === "") return c("");
8053
- let u = jm(i.subject), d = {
8053
+ let u = Mm(i.subject), d = {
8054
8054
  type: a.resourceType,
8055
8055
  id: l,
8056
8056
  tenantId: i.subject.tenantId
@@ -8060,7 +8060,7 @@ behind quietly.` + n;
8060
8060
  tuples: e
8061
8061
  }) ? r : c(l));
8062
8062
  };
8063
- }, Nm = async (e, t, n) => t === null ? [] : (await e.query({
8063
+ }, Pm = async (e, t, n) => t === null ? [] : (await e.query({
8064
8064
  table: "_voltro_rebac_tuples",
8065
8065
  predicate: C(O("subjectId", t), O("resourceType", n)),
8066
8066
  order: [],
@@ -8072,18 +8072,18 @@ behind quietly.` + n;
8072
8072
  relation: e.relation,
8073
8073
  resourceType: e.resourceType,
8074
8074
  resourceId: e.resourceId
8075
- })), Pm = (e) => {
8075
+ })), Fm = (e) => {
8076
8076
  let t = e.getPolicy ?? Gu;
8077
8077
  return async (n, r, i, a) => {
8078
8078
  let o = t(r);
8079
8079
  if (o === void 0) return [];
8080
- let s = jm(n);
8080
+ let s = Mm(n);
8081
8081
  return $u(s, i, r, a, {
8082
8082
  policy: o,
8083
8083
  tuples: await e.loadSubjectTuples(s.id, r)
8084
8084
  });
8085
8085
  };
8086
- }, Fm = (e) => {
8086
+ }, Im = (e) => {
8087
8087
  if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
8088
8088
  if (e.watch === void 0 || typeof e.watch.table != "string" || e.watch.table.length === 0) throw Error(`reaction '${e.name}': watch.table is required`);
8089
8089
  if (e.act === void 0 || e.act.kind !== "agent" && e.act.kind !== "workflow") throw Error(`reaction '${e.name}': act must be { kind: 'agent' | 'workflow', … }`);
@@ -8091,14 +8091,14 @@ behind quietly.` + n;
8091
8091
  if (e.guards.rateLimit !== void 0 && (e.guards.rateLimit.limit <= 0 || e.guards.rateLimit.windowMs <= 0)) throw Error(`reaction '${e.name}': guards.rateLimit needs positive limit + windowMs`);
8092
8092
  if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
8093
8093
  return e;
8094
- }, Im = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, Lm = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, Rm = class {
8094
+ }, Lm = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, Rm = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, zm = class {
8095
8095
  hits = /* @__PURE__ */ new Map();
8096
8096
  allow(e, t, n, r) {
8097
8097
  let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
8098
8098
  return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
8099
8099
  }
8100
- }, zm = (e, t, n, r, i) => `${e}\u0000${t}\u0000${Math.floor(i / n)}\u0000${r}`, Bm = async (e, t, n) => {
8101
- if (t.table !== e.watch.table || !Im(e.watch.on, t.op)) return "skipped-op";
8100
+ }, Bm = (e, t, n, r, i) => `${e}\u0000${t}\u0000${Math.floor(i / n)}\u0000${r}`, Vm = async (e, t, n) => {
8101
+ if (t.table !== e.watch.table || !Lm(e.watch.on, t.op)) return "skipped-op";
8102
8102
  if (e.when !== void 0 && !e.when(t)) return "skipped-when";
8103
8103
  let r = `${e.name}:${e.guards.dedupeKey(t)}`;
8104
8104
  if (await n.dedupe.has(r)) return "skipped-dedupe";
@@ -8107,23 +8107,23 @@ behind quietly.` + n;
8107
8107
  let r = n.now?.() ?? Date.now(), a = i.key === void 0 ? "" : i.key(t);
8108
8108
  if (n.claimRateSlot !== void 0) {
8109
8109
  let t = !1;
8110
- for (let o = 0; o < i.limit; o++) if (await n.claimRateSlot(zm(e.name, a, i.windowMs, o, r))) {
8110
+ for (let o = 0; o < i.limit; o++) if (await n.claimRateSlot(Bm(e.name, a, i.windowMs, o, r))) {
8111
8111
  t = !0;
8112
8112
  break;
8113
8113
  }
8114
8114
  if (!t) return "skipped-ratelimit";
8115
8115
  } else if (n.rateLimiter !== void 0 && !n.rateLimiter.allow(`${e.name} ${a}`, i.limit, i.windowMs, r)) return "skipped-ratelimit";
8116
8116
  }
8117
- let a = Lm(t);
8117
+ let a = Rm(t);
8118
8118
  return e.guards.costBudgetUsd !== void 0 && n.checkBudget !== void 0 && !await n.checkBudget(a, e.guards.costBudgetUsd) ? "skipped-budget" : (await n.runAct(e.act, t, {
8119
8119
  id: a,
8120
8120
  via: "agent"
8121
8121
  }), await n.dedupe.add(r), "acted");
8122
- }, Vm = /* @__PURE__ */ new Set([
8122
+ }, Hm = /* @__PURE__ */ new Set([
8123
8123
  "info",
8124
8124
  "warn",
8125
8125
  "critical"
8126
- ]), Q = (e, t) => /* @__PURE__ */ Error(`defineExpectation(${JSON.stringify(e)}): ${t}`), Hm = (e) => {
8126
+ ]), Q = (e, t) => /* @__PURE__ */ Error(`defineExpectation(${JSON.stringify(e)}): ${t}`), Um = (e) => {
8127
8127
  let t = e.name;
8128
8128
  if (typeof t != "string" || t.length === 0) throw Error("defineExpectation: a non-empty `name` is required");
8129
8129
  if (e.on === void 0 || typeof e.on.table != "string" || e.on.table.length === 0) throw Q(t, "on.table is required — the table whose writes drive the expectation");
@@ -8152,7 +8152,7 @@ behind quietly.` + n;
8152
8152
  default: throw Q(t, `unknown invariant kind ${JSON.stringify(n.kind)}`);
8153
8153
  }
8154
8154
  let r = e.severity ?? "warn";
8155
- if (!Vm.has(r)) throw Q(t, `severity must be one of info | warn | critical (got ${JSON.stringify(r)})`);
8155
+ if (!Hm.has(r)) throw Q(t, `severity must be one of info | warn | critical (got ${JSON.stringify(r)})`);
8156
8156
  return {
8157
8157
  _voltroExpectation: !0,
8158
8158
  name: t,
@@ -8164,9 +8164,9 @@ behind quietly.` + n;
8164
8164
  severity: r,
8165
8165
  ...e.description === void 0 ? {} : { description: e.description }
8166
8166
  };
8167
- }, Um = (e) => typeof e == "object" && !!e && e._voltroExpectation === !0, Wm = class extends n.Tag("@voltro/ExpectationRegistry")() {}, Gm = (e) => o.gen(function* () {
8168
- return (yield* Wm).get(e.name);
8169
- }), Km = (e) => {
8167
+ }, Wm = (e) => typeof e == "object" && !!e && e._voltroExpectation === !0, Gm = class extends n.Tag("@voltro/ExpectationRegistry")() {}, Km = (e) => o.gen(function* () {
8168
+ return (yield* Gm).get(e.name);
8169
+ }), qm = (e) => {
8170
8170
  if (e instanceof Date) return e.getTime();
8171
8171
  if (typeof e == "number" && Number.isFinite(e)) return e;
8172
8172
  if (typeof e == "string" && e.length > 0) {
@@ -8174,20 +8174,20 @@ behind quietly.` + n;
8174
8174
  return Number.isNaN(t) ? null : t;
8175
8175
  }
8176
8176
  return null;
8177
- }, qm = class {
8177
+ }, Jm = class {
8178
8178
  maxAgeMs;
8179
8179
  timeDependent = !0;
8180
8180
  maintainer;
8181
8181
  column;
8182
8182
  constructor(e, t) {
8183
- this.maxAgeMs = t, this.column = e, this.maintainer = new Om({
8183
+ this.maxAgeMs = t, this.column = e, this.maintainer = new km({
8184
8184
  op: "max",
8185
8185
  column: e
8186
8186
  });
8187
8187
  }
8188
8188
  project(e) {
8189
8189
  if (e == null) return null;
8190
- let t = Km(e[this.column]);
8190
+ let t = qm(e[this.column]);
8191
8191
  return t === null ? null : {
8192
8192
  ...e,
8193
8193
  [this.column]: t
@@ -8229,7 +8229,7 @@ behind quietly.` + n;
8229
8229
  violated: n > this.maxAgeMs
8230
8230
  };
8231
8231
  }
8232
- }, Jm = class {
8232
+ }, Ym = class {
8233
8233
  matches;
8234
8234
  reduce;
8235
8235
  timeDependent = !1;
@@ -8254,16 +8254,16 @@ behind quietly.` + n;
8254
8254
  read() {
8255
8255
  return this.reduce(this.total, this.matching);
8256
8256
  }
8257
- }, Ym = (e) => e == null, Xm = (e, t, n) => {
8258
- if (Ym(e)) return !1;
8257
+ }, Xm = (e) => e == null, Zm = (e, t, n) => {
8258
+ if (Xm(e)) return !1;
8259
8259
  let r = Number(e);
8260
8260
  return Number.isNaN(r) ? !1 : t !== void 0 && r < t || n !== void 0 && r > n;
8261
- }, Zm = (e) => {
8261
+ }, Qm = (e) => {
8262
8262
  switch (e.kind) {
8263
- case "freshness": return new qm(e.column, e.maxAgeMs);
8263
+ case "freshness": return new Jm(e.column, e.maxAgeMs);
8264
8264
  case "nullRate": {
8265
8265
  let t = e.column, n = e.maxRate;
8266
- return new Jm((e) => Ym(e[t]), (e, t) => {
8266
+ return new Ym((e) => Xm(e[t]), (e, t) => {
8267
8267
  let r = e > 0 ? t / e : 0;
8268
8268
  return {
8269
8269
  metric: r,
@@ -8274,7 +8274,7 @@ behind quietly.` + n;
8274
8274
  }
8275
8275
  case "rowCount": {
8276
8276
  let { min: t, max: n } = e;
8277
- return new Jm(() => !1, (e) => ({
8277
+ return new Ym(() => !1, (e) => ({
8278
8278
  metric: e,
8279
8279
  threshold: n ?? t ?? null,
8280
8280
  violated: t !== void 0 && e < t || n !== void 0 && e > n
@@ -8282,7 +8282,7 @@ behind quietly.` + n;
8282
8282
  }
8283
8283
  case "valueBounds": {
8284
8284
  let { column: t, min: n, max: r, maxViolationRate: i } = e;
8285
- return new Jm((e) => Xm(e[t], n, r), (e, t) => {
8285
+ return new Ym((e) => Zm(e[t], n, r), (e, t) => {
8286
8286
  if (i !== void 0) {
8287
8287
  let n = e > 0 ? t / e : 0;
8288
8288
  return {
@@ -8299,13 +8299,13 @@ behind quietly.` + n;
8299
8299
  });
8300
8300
  }
8301
8301
  }
8302
- }, Qm = (e) => ({
8302
+ }, $m = (e) => ({
8303
8303
  table: e.table,
8304
8304
  op: e.op,
8305
8305
  traceId: e.traceId ?? null,
8306
8306
  subjectId: e.subjectId ?? null,
8307
8307
  procedure: e.procedure ?? null
8308
- }), $m = (e, t) => !t || e.metric === null ? "unknown" : e.violated ? "violated" : "holding", eh = class {
8308
+ }), eh = (e, t) => !t || e.metric === null ? "unknown" : e.violated ? "violated" : "holding", th = class {
8309
8309
  def;
8310
8310
  deps;
8311
8311
  engine;
@@ -8318,7 +8318,7 @@ behind quietly.` + n;
8318
8318
  lastEvaluatedAt = null;
8319
8319
  lastCause = null;
8320
8320
  constructor(e, t) {
8321
- this.def = e, this.deps = t, this.engine = Zm(e.invariant), this.now = t.now ?? Date.now, this.threshold = null;
8321
+ this.def = e, this.deps = t, this.engine = Qm(e.invariant), this.now = t.now ?? Date.now, this.threshold = null;
8322
8322
  }
8323
8323
  get timeDependent() {
8324
8324
  return this.engine.timeDependent;
@@ -8347,13 +8347,13 @@ behind quietly.` + n;
8347
8347
  let e = (await this.deps.queryBase()).filter((e) => this.inScope(e));
8348
8348
  this.engine.resolveRescan(i, e);
8349
8349
  }
8350
- return this.commitReading(this.engine.read(this.now()), !0, Qm(e));
8350
+ return this.commitReading(this.engine.read(this.now()), !0, $m(e));
8351
8351
  }
8352
8352
  tick() {
8353
8353
  return this.seeded ? this.commitReading(this.engine.read(this.now()), !0, null) : null;
8354
8354
  }
8355
8355
  commitReading(e, t, n) {
8356
- let r = this.status, i = $m(e, this.seeded);
8356
+ let r = this.status, i = eh(e, this.seeded);
8357
8357
  if (this.metric = e.metric, this.threshold = e.threshold, this.lastEvaluatedAt = new Date(this.now()), i !== r) {
8358
8358
  if (this.status = i, this.since = this.lastEvaluatedAt, i === "violated" && (this.lastCause = n), t && i === "violated" && r !== "violated") return {
8359
8359
  kind: "violated",
@@ -8383,7 +8383,7 @@ behind quietly.` + n;
8383
8383
  ...this.def.description === void 0 ? {} : { description: this.def.description }
8384
8384
  };
8385
8385
  }
8386
- }, th = (e) => {
8386
+ }, nh = (e) => {
8387
8387
  let t = e.now ?? Date.now, n = e.log, r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = (e) => {
8388
8388
  for (let t of r) try {
8389
8389
  t(e);
@@ -8400,7 +8400,7 @@ behind quietly.` + n;
8400
8400
  }), s = /* @__PURE__ */ new Map(), c = !1;
8401
8401
  for (let { definition: r } of e.discovered) {
8402
8402
  if (i.has(r.name)) throw Error(`expectation: duplicate name '${r.name}' — names must be unique across all expectations`);
8403
- let e = new eh(r, {
8403
+ let e = new th(r, {
8404
8404
  queryBase: o(r.on.table),
8405
8405
  now: t,
8406
8406
  ...n === void 0 ? {} : { log: n }
@@ -8454,30 +8454,30 @@ behind quietly.` + n;
8454
8454
  registered: [...i.keys()],
8455
8455
  runTick: u
8456
8456
  };
8457
- }, nh = /* @__PURE__ */ new Set([
8457
+ }, rh = /* @__PURE__ */ new Set([
8458
8458
  "info",
8459
8459
  "warn",
8460
8460
  "critical"
8461
- ]), rh = /* @__PURE__ */ new Set(["observe", "suspend"]), ih = (e, t) => /* @__PURE__ */ Error(`defineCostBudget(${JSON.stringify(e)}): ${t}`), ah = (e) => {
8461
+ ]), ih = /* @__PURE__ */ new Set(["observe", "suspend"]), ah = (e, t) => /* @__PURE__ */ Error(`defineCostBudget(${JSON.stringify(e)}): ${t}`), oh = (e) => {
8462
8462
  let t = /^(\d+(?:\.\d+)?)\s*(ms|s|m|h|d)$/.exec(e.trim());
8463
8463
  if (t === null) return null;
8464
8464
  let n = Number(t[1]);
8465
8465
  if (!(Number.isFinite(n) && n > 0)) return null;
8466
8466
  let r = t[2];
8467
8467
  return n * (r === "ms" ? 1 : r === "s" ? 1e3 : r === "m" ? 6e4 : r === "h" ? 36e5 : 864e5);
8468
- }, oh = (e) => {
8468
+ }, sh = (e) => {
8469
8469
  let t = e.name;
8470
8470
  if (typeof t != "string" || t.length === 0) throw Error("defineCostBudget: a non-empty `name` is required");
8471
- if (!(typeof e.limit == "number" && Number.isFinite(e.limit) && e.limit > 0)) throw ih(t, "a positive, finite `limit` is required");
8472
- if (e.unit !== void 0 && (typeof e.unit != "string" || e.unit.length === 0)) throw ih(t, "unit, when present, must be a non-empty string");
8471
+ if (!(typeof e.limit == "number" && Number.isFinite(e.limit) && e.limit > 0)) throw ah(t, "a positive, finite `limit` is required");
8472
+ if (e.unit !== void 0 && (typeof e.unit != "string" || e.unit.length === 0)) throw ah(t, "unit, when present, must be a non-empty string");
8473
8473
  let n = e.warnAt ?? .8;
8474
- if (!(typeof n == "number" && n >= 0 && n <= 1)) throw ih(t, "warnAt, when present, must be in [0, 1]");
8474
+ if (!(typeof n == "number" && n >= 0 && n <= 1)) throw ah(t, "warnAt, when present, must be in [0, 1]");
8475
8475
  let r = null;
8476
- if (e.window !== void 0 && (r = ah(e.window), r === null)) throw ih(t, `window must be an interval like '1h' / '24h' (got ${JSON.stringify(e.window)})`);
8476
+ if (e.window !== void 0 && (r = oh(e.window), r === null)) throw ah(t, `window must be an interval like '1h' / '24h' (got ${JSON.stringify(e.window)})`);
8477
8477
  let i = e.severity ?? "warn";
8478
- if (!nh.has(i)) throw ih(t, `severity must be one of info | warn | critical (got ${JSON.stringify(i)})`);
8478
+ if (!rh.has(i)) throw ah(t, `severity must be one of info | warn | critical (got ${JSON.stringify(i)})`);
8479
8479
  let a = e.onExceeded ?? "observe";
8480
- if (!rh.has(a)) throw ih(t, `onExceeded must be observe | suspend (got ${JSON.stringify(e.onExceeded)})`);
8480
+ if (!ih.has(a)) throw ah(t, `onExceeded must be observe | suspend (got ${JSON.stringify(e.onExceeded)})`);
8481
8481
  return {
8482
8482
  _voltroCostBudget: !0,
8483
8483
  name: t,
@@ -8489,9 +8489,9 @@ behind quietly.` + n;
8489
8489
  onExceeded: a,
8490
8490
  ...e.description === void 0 ? {} : { description: e.description }
8491
8491
  };
8492
- }, sh = (e) => typeof e == "object" && !!e && e._voltroCostBudget === !0, ch = class extends n.Tag("@voltro/CostRegistry")() {}, lh = (e, t) => o.gen(function* () {
8493
- return (yield* ch).budget(e.name, t);
8494
- }), uh = class {
8492
+ }, ch = (e) => typeof e == "object" && !!e && e._voltroCostBudget === !0, lh = class extends n.Tag("@voltro/CostRegistry")() {}, uh = (e, t) => o.gen(function* () {
8493
+ return (yield* lh).budget(e.name, t);
8494
+ }), dh = class {
8495
8495
  total = 0;
8496
8496
  byUnit = /* @__PURE__ */ new Map();
8497
8497
  bySubscription = /* @__PURE__ */ new Map();
@@ -8510,11 +8510,11 @@ behind quietly.` + n;
8510
8510
  lastUpdatedAt: this.lastUpdatedAt
8511
8511
  };
8512
8512
  }
8513
- }, dh = {
8513
+ }, fh = {
8514
8514
  ok: 0,
8515
8515
  warn: 1,
8516
8516
  exceeded: 2
8517
- }, fh = class {
8517
+ }, ph = class {
8518
8518
  def;
8519
8519
  tenantId;
8520
8520
  spent = 0;
@@ -8540,7 +8540,7 @@ behind quietly.` + n;
8540
8540
  }
8541
8541
  settle(e, t, n) {
8542
8542
  let r = this.status;
8543
- return e === r ? null : (this.status = e, this.since = t, dh[e] > dh[r] ? (this.lastCause = n, {
8543
+ return e === r ? null : (this.status = e, this.since = t, fh[e] > fh[r] ? (this.lastCause = n, {
8544
8544
  kind: e === "exceeded" ? "exceeded" : "warn",
8545
8545
  state: this.state(),
8546
8546
  cause: n
@@ -8553,7 +8553,7 @@ behind quietly.` + n;
8553
8553
  apply(e, t, n) {
8554
8554
  let r = [], i = this.rollWindow(n);
8555
8555
  i !== null && r.push(i), this.spent += t, this.lastUpdatedAt = e.at ?? n;
8556
- let a = this.settle(this.statusOf(this.spent), n, ph(e));
8556
+ let a = this.settle(this.statusOf(this.spent), n, mh(e));
8557
8557
  return a !== null && r.push(a), r;
8558
8558
  }
8559
8559
  tick(e) {
@@ -8580,12 +8580,12 @@ behind quietly.` + n;
8580
8580
  ...this.def.description === void 0 ? {} : { description: this.def.description }
8581
8581
  };
8582
8582
  }
8583
- }, ph = (e) => ({
8583
+ }, mh = (e) => ({
8584
8584
  unit: e.unit,
8585
8585
  subscriptionId: e.subscriptionId ?? null,
8586
8586
  procedure: e.procedure ?? null,
8587
8587
  traceId: e.traceId ?? null
8588
- }), mh = (e) => Number.isFinite(e) && e > 0 ? e : 0, hh = class {
8588
+ }), hh = (e) => Number.isFinite(e) && e > 0 ? e : 0, gh = class {
8589
8589
  now;
8590
8590
  attribution = /* @__PURE__ */ new Map();
8591
8591
  counters = /* @__PURE__ */ new Map();
@@ -8605,13 +8605,13 @@ behind quietly.` + n;
8605
8605
  }
8606
8606
  counterFor(e, t) {
8607
8607
  let n = this.counters.get(e.name), r = n.get(t);
8608
- return r === void 0 && (r = new fh(e, t), n.set(t, r)), r;
8608
+ return r === void 0 && (r = new ph(e, t), n.set(t, r)), r;
8609
8609
  }
8610
8610
  record(e) {
8611
- let t = mh(e.amount);
8611
+ let t = hh(e.amount);
8612
8612
  if (t === 0) return [];
8613
8613
  let n = e.at ?? this.now(), r = this.attribution.get(e.tenantId);
8614
- r === void 0 && (r = new uh(), this.attribution.set(e.tenantId, r)), r.add(e, t, n);
8614
+ r === void 0 && (r = new dh(), this.attribution.set(e.tenantId, r)), r.add(e, t, n);
8615
8615
  let i = this.unitBudgets.get(e.unit);
8616
8616
  if (this.totalBudgets.length === 0 && i === void 0) return [];
8617
8617
  let a = [];
@@ -8664,8 +8664,8 @@ behind quietly.` + n;
8664
8664
  breaches() {
8665
8665
  return this.budgetStates().filter((e) => e.status !== "ok");
8666
8666
  }
8667
- }, gh = (e) => {
8668
- let t = e.now ?? Date.now, n = e.log, r = /* @__PURE__ */ new Set(), i = e.discovered.map((e) => e.definition), a = new hh(i, {
8667
+ }, _h = (e) => {
8668
+ let t = e.now ?? Date.now, n = e.log, r = /* @__PURE__ */ new Set(), i = e.discovered.map((e) => e.definition), a = new gh(i, {
8669
8669
  now: t,
8670
8670
  ...n === void 0 ? {} : { log: n }
8671
8671
  }), o = i.some((e) => e.windowMs !== null), s = (e) => {
@@ -8700,12 +8700,12 @@ behind quietly.` + n;
8700
8700
  registered: i.map((e) => e.name),
8701
8701
  runTick: l
8702
8702
  };
8703
- }, _h = "holdout", $ = (e, t) => /* @__PURE__ */ Error(`defineExperiment(${JSON.stringify(e)}): ${t}`), vh = (e) => {
8703
+ }, vh = "holdout", $ = (e, t) => /* @__PURE__ */ Error(`defineExperiment(${JSON.stringify(e)}): ${t}`), yh = (e) => {
8704
8704
  if (e == null) return null;
8705
8705
  if (typeof e == "number") return Number.isFinite(e) ? String(e) : null;
8706
8706
  let t = String(e);
8707
8707
  return t.length > 0 ? t : null;
8708
- }, yh = (e) => {
8708
+ }, bh = (e) => {
8709
8709
  let t = e.name;
8710
8710
  if (typeof t != "string" || t.length === 0) throw Error("defineExperiment: a non-empty `name` is required");
8711
8711
  if (e.on === void 0 || typeof e.on.table != "string" || e.on.table.length === 0) throw $(t, "on.table is required — the table whose writes drive the experiment");
@@ -8717,18 +8717,18 @@ behind quietly.` + n;
8717
8717
  if (typeof e.variantFrom == "string") {
8718
8718
  if (e.variantFrom.length === 0) throw $(t, "variantFrom, when a column name, must be non-empty");
8719
8719
  let n = e.variantFrom;
8720
- a = (e) => vh(e[n]);
8720
+ a = (e) => yh(e[n]);
8721
8721
  } else if (typeof e.variantFrom == "function") {
8722
8722
  let t = e.variantFrom;
8723
- a = (e) => vh(t(e));
8723
+ a = (e) => yh(t(e));
8724
8724
  } else throw $(t, "variantFrom must be a column name or a (row) => variantName function");
8725
8725
  } else if (typeof e.subject == "string") {
8726
8726
  if (e.subject.length === 0) throw $(t, "subject, when a column name, must be non-empty");
8727
8727
  let n = e.subject;
8728
- i = (e) => vh(e[n]);
8728
+ i = (e) => yh(e[n]);
8729
8729
  } else if (typeof e.subject == "function") {
8730
8730
  let t = e.subject;
8731
- i = (e) => vh(t(e));
8731
+ i = (e) => yh(t(e));
8732
8732
  } else throw $(t, "subject is required — a column name or a (row) => key function (or use `variantFrom` to measure an arm something else assigned)");
8733
8733
  if (!Array.isArray(e.variants) || e.variants.length < 2) throw $(t, "at least two variants are required (a control + one treatment)");
8734
8734
  let o = /* @__PURE__ */ new Set(), s = [];
@@ -8745,9 +8745,9 @@ behind quietly.` + n;
8745
8745
  }
8746
8746
  let c = 0;
8747
8747
  if (e.holdout !== void 0) {
8748
- if (a !== null && e.holdout > 0) throw $(t, `holdout is meaningless with \`variantFrom\` — a holdout is carved out AT ASSIGNMENT, and this experiment does not assign. Declare the holdout arm on whatever does (a flag variant named "${_h}", say) and list it in \`variants\`.`);
8748
+ if (a !== null && e.holdout > 0) throw $(t, `holdout is meaningless with \`variantFrom\` — a holdout is carved out AT ASSIGNMENT, and this experiment does not assign. Declare the holdout arm on whatever does (a flag variant named "${vh}", say) and list it in \`variants\`.`);
8749
8749
  if (!(typeof e.holdout == "number" && e.holdout >= 0 && e.holdout < 1)) throw $(t, "holdout, when present, must be a fraction in [0, 1)");
8750
- if (c = e.holdout, c > 0 && o.has("holdout")) throw $(t, `a variant may not be named ${JSON.stringify(_h)} when holdout > 0 (reserved)`);
8750
+ if (c = e.holdout, c > 0 && o.has("holdout")) throw $(t, `a variant may not be named ${JSON.stringify(vh)} when holdout > 0 (reserved)`);
8751
8751
  }
8752
8752
  let l = e.metric;
8753
8753
  if (l === void 0 || typeof l.kind != "string") throw $(t, "metric is required");
@@ -8779,23 +8779,23 @@ behind quietly.` + n;
8779
8779
  baseline: u,
8780
8780
  ...e.description === void 0 ? {} : { description: e.description }
8781
8781
  };
8782
- }, bh = (e) => typeof e == "object" && !!e && e._voltroExperiment === !0, xh = (e) => {
8782
+ }, xh = (e) => typeof e == "object" && !!e && e._voltroExperiment === !0, Sh = (e) => {
8783
8783
  let t = 2166136261;
8784
8784
  for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619);
8785
8785
  return (t >>> 0) / 4294967296;
8786
- }, Sh = (e, t) => {
8787
- let n = xh(`${e.name}\u0000${t}`);
8788
- if (e.holdout > 0 && n < e.holdout) return _h;
8786
+ }, Ch = (e, t) => {
8787
+ let n = Sh(`${e.name}\u0000${t}`);
8788
+ if (e.holdout > 0 && n < e.holdout) return vh;
8789
8789
  let r = e.holdout > 0 ? (n - e.holdout) / (1 - e.holdout) : n, i = e.variants.reduce((e, t) => e + t.weight, 0), a = 0;
8790
8790
  for (let t of e.variants) if (a += t.weight / i, r < a) return t.name;
8791
8791
  return e.variants[e.variants.length - 1].name;
8792
- }, Ch = (e) => e.holdout > 0 ? [...e.variants.map((e) => e.name), _h] : e.variants.map((e) => e.name), wh = class extends n.Tag("@voltro/ExperimentRegistry")() {}, Th = (e) => o.gen(function* () {
8793
- return (yield* wh).get(e.name);
8794
- }), Eh = "__voltro_variant", Dh = "__voltro_metric", Oh = class {
8792
+ }, wh = (e) => e.holdout > 0 ? [...e.variants.map((e) => e.name), vh] : e.variants.map((e) => e.name), Th = class extends n.Tag("@voltro/ExperimentRegistry")() {}, Eh = (e) => o.gen(function* () {
8793
+ return (yield* Th).get(e.name);
8794
+ }), Dh = "__voltro_variant", Oh = "__voltro_metric", kh = class {
8795
8795
  project;
8796
8796
  maintainer;
8797
8797
  constructor(e, t) {
8798
- this.project = t, this.maintainer = new Om(e);
8798
+ this.project = t, this.maintainer = new km(e);
8799
8799
  }
8800
8800
  seed(e) {
8801
8801
  this.maintainer.seed(e.map((e) => this.project(e)).filter((e) => e !== null));
@@ -8819,56 +8819,56 @@ behind quietly.` + n;
8819
8819
  byVariant() {
8820
8820
  let e = /* @__PURE__ */ new Map();
8821
8821
  for (let t of this.maintainer.materialize()) {
8822
- let n = t.group[Eh];
8822
+ let n = t.group[Dh];
8823
8823
  typeof n == "string" && e.set(n, t.value);
8824
8824
  }
8825
8825
  return e;
8826
8826
  }
8827
- }, kh = (e) => typeof e == "number" && Number.isFinite(e), Ah = (e) => {
8828
- if (kh(e)) return e;
8827
+ }, Ah = (e) => typeof e == "number" && Number.isFinite(e), jh = (e) => {
8828
+ if (Ah(e)) return e;
8829
8829
  let t = Number(e);
8830
8830
  return Number.isFinite(t) ? t : null;
8831
- }, jh = (e, t) => new Oh(e.kind === "count" ? {
8831
+ }, Mh = (e, t) => new kh(e.kind === "count" ? {
8832
8832
  op: "count",
8833
- groupBy: [Eh]
8833
+ groupBy: [Dh]
8834
8834
  } : {
8835
8835
  op: e.kind === "sum" ? "sum" : "avg",
8836
- column: Dh,
8837
- groupBy: [Eh]
8836
+ column: Oh,
8837
+ groupBy: [Dh]
8838
8838
  }, (n) => {
8839
8839
  let r = t(n);
8840
8840
  if (r === null) return null;
8841
8841
  switch (e.kind) {
8842
- case "count": return { [Eh]: r };
8842
+ case "count": return { [Dh]: r };
8843
8843
  case "sum":
8844
8844
  case "avg": {
8845
- let t = Ah(n[e.column]);
8845
+ let t = jh(n[e.column]);
8846
8846
  return t === null ? null : {
8847
- [Eh]: r,
8848
- [Dh]: t
8847
+ [Dh]: r,
8848
+ [Oh]: t
8849
8849
  };
8850
8850
  }
8851
8851
  case "conversionRate": {
8852
8852
  let t = n[e.column], i = e.equals === void 0 ? !!t : t === e.equals;
8853
8853
  return {
8854
- [Eh]: r,
8855
- [Dh]: +!!i
8854
+ [Dh]: r,
8855
+ [Oh]: +!!i
8856
8856
  };
8857
8857
  }
8858
8858
  }
8859
- }), Mh = (e) => new Oh({
8859
+ }), Nh = (e) => new kh({
8860
8860
  op: "count",
8861
- groupBy: [Eh]
8861
+ groupBy: [Dh]
8862
8862
  }, (t) => {
8863
8863
  let n = e(t);
8864
- return n === null ? null : { [Eh]: n };
8865
- }), Nh = (e) => ({
8864
+ return n === null ? null : { [Dh]: n };
8865
+ }), Ph = (e) => ({
8866
8866
  table: e.table,
8867
8867
  op: e.op,
8868
8868
  traceId: e.traceId ?? null,
8869
8869
  subjectId: e.subjectId ?? null,
8870
8870
  procedure: e.procedure ?? null
8871
- }), Ph = class {
8871
+ }), Fh = class {
8872
8872
  def;
8873
8873
  deps;
8874
8874
  exposure;
@@ -8879,9 +8879,9 @@ behind quietly.` + n;
8879
8879
  lastUpdatedAt = null;
8880
8880
  declaredVariants;
8881
8881
  constructor(e, t) {
8882
- this.def = e, this.deps = t, this.now = t.now ?? Date.now, this.declaredVariants = new Set(Ch(e));
8882
+ this.def = e, this.deps = t, this.now = t.now ?? Date.now, this.declaredVariants = new Set(wh(e));
8883
8883
  let n = (e) => this.variantOf(e);
8884
- this.exposure = Mh(n), this.metricIsCount = e.metric.kind === "count", this.metric = this.metricIsCount ? this.exposure : jh(e.metric, n);
8884
+ this.exposure = Nh(n), this.metricIsCount = e.metric.kind === "count", this.metric = this.metricIsCount ? this.exposure : Mh(e.metric, n);
8885
8885
  }
8886
8886
  variantOf(e) {
8887
8887
  if (e == null) return null;
@@ -8893,7 +8893,7 @@ behind quietly.` + n;
8893
8893
  }
8894
8894
  if (this.def.subject === null) return null;
8895
8895
  let n = this.def.subject(e);
8896
- return n === null ? null : Sh(this.def, n);
8896
+ return n === null ? null : Ch(this.def, n);
8897
8897
  }
8898
8898
  inScope(e) {
8899
8899
  return this.variantOf(e) !== null;
@@ -8913,12 +8913,12 @@ behind quietly.` + n;
8913
8913
  };
8914
8914
  return this.exposure.apply(r), this.metricIsCount || this.metric.apply(r), this.lastUpdatedAt = new Date(this.now()), {
8915
8915
  result: this.result(),
8916
- cause: Nh(e)
8916
+ cause: Ph(e)
8917
8917
  };
8918
8918
  }
8919
8919
  result() {
8920
8920
  let e = this.exposure.byVariant(), t = this.metricIsCount ? e : this.metric.byVariant(), n = this.def.baseline, r = this.metricValueFor(n, t, e), i = 0, a = [];
8921
- for (let o of Ch(this.def)) {
8921
+ for (let o of wh(this.def)) {
8922
8922
  let s = e.get(o) ?? 0;
8923
8923
  i += s;
8924
8924
  let c = this.metricValueFor(o, t, e), l = o === n, u = l || c === null || r === null ? null : c - r, d = l || c === null || r === null || r === 0 ? null : (c - r) / r;
@@ -8955,7 +8955,7 @@ behind quietly.` + n;
8955
8955
  get isSeeded() {
8956
8956
  return this.seeded;
8957
8957
  }
8958
- }, Fh = (e) => {
8958
+ }, Ih = (e) => {
8959
8959
  let t = e.now ?? Date.now, n = e.log, r = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), a = (e) => {
8960
8960
  for (let t of r) try {
8961
8961
  t(e);
@@ -8972,7 +8972,7 @@ behind quietly.` + n;
8972
8972
  }), s = /* @__PURE__ */ new Map();
8973
8973
  for (let { definition: r } of e.discovered) {
8974
8974
  if (i.has(r.name)) throw Error(`experiment: duplicate name '${r.name}' — names must be unique across all experiments`);
8975
- let e = new Ph(r, {
8975
+ let e = new Fh(r, {
8976
8976
  queryBase: o(r.on.table),
8977
8977
  now: t,
8978
8978
  ...n === void 0 ? {} : { log: n }
@@ -9014,21 +9014,21 @@ behind quietly.` + n;
9014
9014
  },
9015
9015
  registered: [...i.keys()]
9016
9016
  };
9017
- }, Ih = F("_voltro_wakeups", {
9018
- id: M({ prefix: "wakeup" }),
9019
- tenantId: I(),
9020
- kind: I(),
9021
- refId: I(),
9022
- wakeAt: L(),
9023
- status: I()
9024
- }).index(["status", "wakeAt"]).index(["tenantId"]), Lh = async (e) => {
9025
- let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Nf(e.store, t, e.batchLimit ?? 100);
9017
+ }, Lh = I("_voltro_wakeups", {
9018
+ id: N({ prefix: "wakeup" }),
9019
+ tenantId: L(),
9020
+ kind: L(),
9021
+ refId: L(),
9022
+ wakeAt: R(),
9023
+ status: L()
9024
+ }).index(["status", "wakeAt"]).index(["tenantId"]), Rh = async (e) => {
9025
+ let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Pf(e.store, t, e.batchLimit ?? 100);
9026
9026
  if (n.length === 0) return 0;
9027
9027
  let r = 0;
9028
- for (let t of n) if (await kf(e.store, t)) try {
9028
+ for (let t of n) if (await Af(e.store, t)) try {
9029
9029
  await e.adapter.wake(t), r++;
9030
9030
  } catch (n) {
9031
- await Af(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
9031
+ await jf(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
9032
9032
  tenantId: t.tenantId,
9033
9033
  kind: t.kind,
9034
9034
  refId: t.refId,
@@ -9036,11 +9036,11 @@ behind quietly.` + n;
9036
9036
  });
9037
9037
  }
9038
9038
  return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
9039
- }, Rh = (e, t = 1e3) => {
9039
+ }, zh = (e, t = 1e3) => {
9040
9040
  let n = !1, r, i = async () => {
9041
9041
  if (!n) {
9042
9042
  try {
9043
- await Lh(e);
9043
+ await Rh(e);
9044
9044
  } catch (t) {
9045
9045
  e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
9046
9046
  }
@@ -9050,10 +9050,10 @@ behind quietly.` + n;
9050
9050
  return i(), { stop: () => {
9051
9051
  n = !0, r !== void 0 && clearTimeout(r);
9052
9052
  } };
9053
- }, zh = (e) => ({ wake: async () => {
9053
+ }, Bh = (e) => ({ wake: async () => {
9054
9054
  await e.start();
9055
- } }), Bh = (e) => new Promise((t) => setTimeout(t, e)), Vh = (e) => {
9056
- let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? Bh, i = e.spawnImpl ?? Tn, a = e.startTimeoutMs ?? 3e4, o = e.healthPollMs ?? 200, s = e.stopSignal ?? "SIGTERM", c = e.stopGraceMs ?? 1e4, l, u, d = e.healthCheck ?? ((e) => e.ok), f = async () => {
9055
+ } }), Vh = (e) => new Promise((t) => setTimeout(t, e)), Hh = (e) => {
9056
+ let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? Vh, i = e.spawnImpl ?? Tn, a = e.startTimeoutMs ?? 3e4, o = e.healthPollMs ?? 200, s = e.stopSignal ?? "SIGTERM", c = e.stopGraceMs ?? 1e4, l, u, d = e.healthCheck ?? ((e) => e.ok), f = async () => {
9057
9057
  try {
9058
9058
  let n = await t(e.healthUrl);
9059
9059
  return d(n);
@@ -9107,11 +9107,11 @@ behind quietly.` + n;
9107
9107
  },
9108
9108
  stop: m
9109
9109
  };
9110
- }, Hh = async (e) => {
9110
+ }, Uh = async (e) => {
9111
9111
  if (e.signals.connectedClients() > 0 || e.signals.inFlightRequests() > 0 || e.signals.activeWorkflowExecutions() > 0) return !1;
9112
- let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Pf(e.store);
9112
+ let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Ff(e.store);
9113
9113
  return !(n !== null && n.wakeAt.getTime() <= t);
9114
- }, Uh = (e, t = Date.now) => {
9114
+ }, Wh = (e, t = Date.now) => {
9115
9115
  let n;
9116
9116
  return {
9117
9117
  update: (r) => {
@@ -9123,7 +9123,7 @@ behind quietly.` + n;
9123
9123
  n = void 0;
9124
9124
  }
9125
9125
  };
9126
- }, Wh = () => {
9126
+ }, Gh = () => {
9127
9127
  let e = 0, t = 0;
9128
9128
  return {
9129
9129
  onRequestStart: () => {
@@ -9141,7 +9141,7 @@ behind quietly.` + n;
9141
9141
  inFlightRequests: () => e,
9142
9142
  openConnections: () => t
9143
9143
  };
9144
- }, Gh = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), Kh = (e, t, n, r) => new Promise((i, a) => {
9144
+ }, Kh = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), qh = (e, t, n, r) => new Promise((i, a) => {
9145
9145
  let o = Wt.request({
9146
9146
  host: n,
9147
9147
  port: r,
@@ -9152,7 +9152,7 @@ behind quietly.` + n;
9152
9152
  t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
9153
9153
  });
9154
9154
  o.on("error", a), e.pipe(o);
9155
- }), qh = (e, t, n, r, i) => new Promise((a, o) => {
9155
+ }), Jh = (e, t, n, r, i) => new Promise((a, o) => {
9156
9156
  let s = Wt.request({
9157
9157
  host: r,
9158
9158
  port: i,
@@ -9167,21 +9167,21 @@ behind quietly.` + n;
9167
9167
  };
9168
9168
  t.on("close", s), r.on("close", s), r.on("error", o);
9169
9169
  }), s.on("error", o), s.end();
9170
- }), Jh = (e) => {
9171
- let t = Gh({
9170
+ }), Yh = (e) => {
9171
+ let t = Kh({
9172
9172
  ensureAwake: () => e.supervisor.start(),
9173
9173
  ...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
9174
9174
  }), n = e.activity, r = Wt.createServer((r, i) => {
9175
- n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => Kh(r, i, e.targetHost, e.targetPort)).catch((t) => {
9175
+ n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => qh(r, i, e.targetHost, e.targetPort)).catch((t) => {
9176
9176
  e.log?.warn("wake-router: proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.headersSent || i.writeHead(502), i.end("wake/proxy failed");
9177
9177
  });
9178
9178
  });
9179
9179
  return r.on("upgrade", (r, i, a) => {
9180
- n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => qh(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
9180
+ n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Jh(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
9181
9181
  e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
9182
9182
  });
9183
9183
  }), r;
9184
- }, Yh = async (e) => {
9184
+ }, Xh = async (e) => {
9185
9185
  try {
9186
9186
  return (await e.query({
9187
9187
  table: "_voltro_workflow_runs",
@@ -9198,15 +9198,15 @@ behind quietly.` + n;
9198
9198
  } catch {
9199
9199
  return 0;
9200
9200
  }
9201
- }, Xh = async (e) => {
9202
- let t = zh(e.supervisor), n = await Lh({
9201
+ }, Zh = async (e) => {
9202
+ let t = Bh(e.supervisor), n = await Rh({
9203
9203
  store: e.store,
9204
9204
  adapter: t,
9205
9205
  ...e.now === void 0 ? {} : { now: e.now },
9206
9206
  ...e.log === void 0 ? {} : { log: e.log }
9207
9207
  });
9208
9208
  n > 0 && e.idleGate.reset();
9209
- let r = await Hh({
9209
+ let r = await Uh({
9210
9210
  store: e.store,
9211
9211
  signals: e.signals,
9212
9212
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
@@ -9216,12 +9216,12 @@ behind quietly.` + n;
9216
9216
  woke: n,
9217
9217
  stopped: i
9218
9218
  };
9219
- }, Zh = async (e) => {
9220
- let t = Uh(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = Wh(), i = 0, a = e.signals === void 0, o = e.signals ?? {
9219
+ }, Qh = async (e) => {
9220
+ let t = Wh(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = Gh(), i = 0, a = e.signals === void 0, o = e.signals ?? {
9221
9221
  connectedClients: () => r.openConnections(),
9222
9222
  inFlightRequests: () => r.inFlightRequests(),
9223
9223
  activeWorkflowExecutions: () => i
9224
- }, s = Jh({
9224
+ }, s = Yh({
9225
9225
  supervisor: e.supervisor,
9226
9226
  targetHost: e.targetHost,
9227
9227
  targetPort: e.targetPort,
@@ -9240,7 +9240,7 @@ behind quietly.` + n;
9240
9240
  let l = !1, u, d = e.firedRetentionMs ?? 6e5, f = 0, p = async () => {
9241
9241
  if (!l) {
9242
9242
  try {
9243
- if (a && (i = await Yh(e.store)), await Xh({
9243
+ if (a && (i = await Xh(e.store)), await Zh({
9244
9244
  store: e.store,
9245
9245
  supervisor: e.supervisor,
9246
9246
  signals: o,
@@ -9248,7 +9248,7 @@ behind quietly.` + n;
9248
9248
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
9249
9249
  ...e.log === void 0 ? {} : { log: e.log }
9250
9250
  }), f++ % 60 == 0) {
9251
- let t = await If(e.store, { firedOlderThan: new Date(Date.now() - d) });
9251
+ let t = await Lf(e.store, { firedOlderThan: new Date(Date.now() - d) });
9252
9252
  t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
9253
9253
  }
9254
9254
  } catch (t) {
@@ -9263,14 +9263,14 @@ behind quietly.` + n;
9263
9263
  l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
9264
9264
  }
9265
9265
  };
9266
- }, Qh = (e) => e, $h = class extends y.TaggedError()("AnalyticsError", {
9266
+ }, $h = (e) => e, eg = class extends y.TaggedError()("AnalyticsError", {
9267
9267
  provider: y.String,
9268
9268
  operation: y.String,
9269
9269
  cause: y.String
9270
- }) {}, eg = class extends y.TaggedError()("AnalyticsCapabilityNotSupported", {
9270
+ }) {}, tg = class extends y.TaggedError()("AnalyticsCapabilityNotSupported", {
9271
9271
  provider: y.String,
9272
9272
  capability: y.String
9273
- }) {}, tg = class extends n.Tag("@voltro/AnalyticsSink")() {}, ng = (e, t) => ({
9273
+ }) {}, ng = class extends n.Tag("@voltro/AnalyticsSink")() {}, rg = (e, t) => ({
9274
9274
  info: e.info,
9275
9275
  track: (n) => e.track(n.tenantId === void 0 ? {
9276
9276
  ...n,
@@ -9289,20 +9289,20 @@ behind quietly.` + n;
9289
9289
  tenantId: t
9290
9290
  } : n),
9291
9291
  ...e.mirror === void 0 ? {} : { mirror: e.mirror }
9292
- }), rg = () => o.gen(function* () {
9293
- let e = yield* tg, t = yield* o.serviceOption(gt), n = h.match(t, {
9292
+ }), ig = () => o.gen(function* () {
9293
+ let e = yield* ng, t = yield* o.serviceOption(ht), n = h.match(t, {
9294
9294
  onNone: () => null,
9295
9295
  onSome: (e) => e.tenantId ?? null
9296
9296
  });
9297
- return n === null ? e : ng(e, n);
9298
- }), ig = "noop", ag = () => {
9299
- let e = (e) => o.fail(new eg({
9300
- provider: ig,
9297
+ return n === null ? e : rg(e, n);
9298
+ }), ag = "noop", og = () => {
9299
+ let e = (e) => o.fail(new tg({
9300
+ provider: ag,
9301
9301
  capability: e
9302
9302
  }));
9303
9303
  return {
9304
9304
  info: {
9305
- provider: ig,
9305
+ provider: ag,
9306
9306
  capabilities: {
9307
9307
  track: !0,
9308
9308
  aggregate: !1,
@@ -9316,8 +9316,8 @@ behind quietly.` + n;
9316
9316
  timeseries: () => e("timeseries"),
9317
9317
  topN: () => e("topN")
9318
9318
  };
9319
- }, og = (e) => {
9320
- if (e.length === 0) return ag();
9319
+ }, sg = (e) => {
9320
+ if (e.length === 0) return og();
9321
9321
  if (e.length === 1) return e[0];
9322
9322
  let t = {
9323
9323
  provider: "compose",
@@ -9334,7 +9334,7 @@ behind quietly.` + n;
9334
9334
  discard: !0
9335
9335
  }), r = (t, n) => {
9336
9336
  let r = e.find((e) => e.info.capabilities[t]);
9337
- return r === void 0 ? o.fail(new eg({
9337
+ return r === void 0 ? o.fail(new tg({
9338
9338
  provider: "compose",
9339
9339
  capability: t
9340
9340
  })) : n(r);
@@ -9361,11 +9361,11 @@ behind quietly.` + n;
9361
9361
  topN: (e) => r("topN", (t) => t.topN(e)),
9362
9362
  ...a === void 0 ? {} : { mirror: a }
9363
9363
  };
9364
- }, sg = (e) => {
9364
+ }, cg = (e) => {
9365
9365
  let t = e.filter((e) => e.dispose !== void 0);
9366
9366
  return {
9367
9367
  kind: "compose",
9368
- build: (t) => og(e.map((e) => e.build(t))),
9368
+ build: (t) => sg(e.map((e) => e.build(t))),
9369
9369
  tables: e.flatMap((e) => e.tables ?? []),
9370
9370
  initialize: (t) => o.forEach(e, (e) => e.initialize ? e.initialize(t) : o.void, {
9371
9371
  concurrency: 1,
@@ -9376,34 +9376,34 @@ behind quietly.` + n;
9376
9376
  discard: !0
9377
9377
  }) } : {}
9378
9378
  };
9379
- }, cg = {
9379
+ }, lg = {
9380
9380
  kind: "noop",
9381
- build: () => ag()
9382
- }, lg = f.counter("voltro_analytics_mirror_forwarded_total", { description: "Reactive-table changes successfully applied to the analytics mirror." }), ug = f.counter("voltro_analytics_mirror_retries_total", { description: "Analytics-mirror write attempts that failed (each is retried until the budget runs out)." }), dg = f.counter("voltro_analytics_mirror_repair_queued_total", { description: "Analytics-mirror changes whose retries were exhausted and were queued for repair." }), fg = f.counter("voltro_analytics_mirror_dropped_total", { description: "Analytics-mirror changes provably lost (repair queue overflow)." }), pg = (e) => {
9381
+ build: () => og()
9382
+ }, ug = f.counter("voltro_analytics_mirror_forwarded_total", { description: "Reactive-table changes successfully applied to the analytics mirror." }), dg = f.counter("voltro_analytics_mirror_retries_total", { description: "Analytics-mirror write attempts that failed (each is retried until the budget runs out)." }), fg = f.counter("voltro_analytics_mirror_repair_queued_total", { description: "Analytics-mirror changes whose retries were exhausted and were queued for repair." }), pg = f.counter("voltro_analytics_mirror_dropped_total", { description: "Analytics-mirror changes provably lost (repair queue overflow)." }), mg = (e) => {
9383
9383
  o.runSync(f.increment(e));
9384
- }, mg = (t) => e.pretty(t), hg = {
9384
+ }, hg = (t) => e.pretty(t), gg = {
9385
9385
  retryAttempts: 5,
9386
9386
  retryBaseDelayMs: 100,
9387
9387
  retryMaxDelayMs: 3e4,
9388
9388
  repairIntervalMs: 6e4,
9389
9389
  repairQueueLimit: 1e4,
9390
9390
  versionStateLimit: 1e5
9391
- }, gg = (e) => {
9391
+ }, _g = (e) => {
9392
9392
  let t = process.env[e];
9393
9393
  if (t === void 0 || t.trim() === "") return;
9394
9394
  let n = Number(t);
9395
9395
  return Number.isFinite(n) && n >= 0 ? n : void 0;
9396
- }, _g = (e) => {
9397
- let t = hg, n = e ?? {};
9396
+ }, vg = (e) => {
9397
+ let t = gg, n = e ?? {};
9398
9398
  return {
9399
- retryAttempts: Math.max(1, n.retryAttempts ?? gg("VOLTRO_ANALYTICS_MIRROR_RETRY_ATTEMPTS") ?? t.retryAttempts),
9400
- retryBaseDelayMs: n.retryBaseDelayMs ?? gg("VOLTRO_ANALYTICS_MIRROR_RETRY_BASE_MS") ?? t.retryBaseDelayMs,
9401
- retryMaxDelayMs: n.retryMaxDelayMs ?? gg("VOLTRO_ANALYTICS_MIRROR_RETRY_MAX_MS") ?? t.retryMaxDelayMs,
9402
- repairIntervalMs: n.repairIntervalMs ?? gg("VOLTRO_ANALYTICS_MIRROR_REPAIR_INTERVAL_MS") ?? t.repairIntervalMs,
9403
- repairQueueLimit: Math.max(1, n.repairQueueLimit ?? gg("VOLTRO_ANALYTICS_MIRROR_REPAIR_QUEUE_LIMIT") ?? t.repairQueueLimit),
9404
- versionStateLimit: Math.max(1, n.versionStateLimit ?? gg("VOLTRO_ANALYTICS_MIRROR_VERSION_STATE_LIMIT") ?? t.versionStateLimit)
9405
- };
9406
- }, vg = {
9399
+ retryAttempts: Math.max(1, n.retryAttempts ?? _g("VOLTRO_ANALYTICS_MIRROR_RETRY_ATTEMPTS") ?? t.retryAttempts),
9400
+ retryBaseDelayMs: n.retryBaseDelayMs ?? _g("VOLTRO_ANALYTICS_MIRROR_RETRY_BASE_MS") ?? t.retryBaseDelayMs,
9401
+ retryMaxDelayMs: n.retryMaxDelayMs ?? _g("VOLTRO_ANALYTICS_MIRROR_RETRY_MAX_MS") ?? t.retryMaxDelayMs,
9402
+ repairIntervalMs: n.repairIntervalMs ?? _g("VOLTRO_ANALYTICS_MIRROR_REPAIR_INTERVAL_MS") ?? t.repairIntervalMs,
9403
+ repairQueueLimit: Math.max(1, n.repairQueueLimit ?? _g("VOLTRO_ANALYTICS_MIRROR_REPAIR_QUEUE_LIMIT") ?? t.repairQueueLimit),
9404
+ versionStateLimit: Math.max(1, n.versionStateLimit ?? _g("VOLTRO_ANALYTICS_MIRROR_VERSION_STATE_LIMIT") ?? t.versionStateLimit)
9405
+ };
9406
+ }, yg = {
9407
9407
  tables: [],
9408
9408
  detach: () => {},
9409
9409
  flush: () => Promise.resolve(),
@@ -9414,10 +9414,10 @@ behind quietly.` + n;
9414
9414
  awaitingRepair: 0,
9415
9415
  dropped: 0
9416
9416
  })
9417
- }, yg = (e, t) => `${e}\u0000${String(t)}`, bg = (e) => {
9417
+ }, bg = (e, t) => `${e}\u0000${String(t)}`, xg = (e) => {
9418
9418
  let { store: t, sink: n, log: r } = e, i = n.mirror;
9419
- if (i === void 0 || i.tables.length === 0) return vg;
9420
- let s = _g(e), c = e.run ?? ((e) => o.runPromise(e)), l = i.primaryKey ?? "id", u = new Set(i.tables), d = n.info.provider, f = t.changeScope === "fleet", p = 0, m = () => {
9419
+ if (i === void 0 || i.tables.length === 0) return yg;
9420
+ let s = vg(e), c = e.run ?? ((e) => o.runPromise(e)), l = i.primaryKey ?? "id", u = new Set(i.tables), d = n.info.provider, f = t.changeScope === "fleet", p = 0, m = () => {
9421
9421
  let e = Date.now() * 1e3;
9422
9422
  return p = e > p ? e : p + 1, p;
9423
9423
  }, h = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Set(), b = 0, x = 0, S = /* @__PURE__ */ new Map(), C = (e) => {
@@ -9437,7 +9437,7 @@ behind quietly.` + n;
9437
9437
  primaryKeyValue: t.pk
9438
9438
  }).pipe(o.map((e) => (n.baseline = e ?? 0, n.baseline))) : o.succeed(n.baseline);
9439
9439
  }), T = (e, t, n) => n.kind === "clock" ? o.succeed(n.version) : w(e, t).pipe(o.map((e) => e + n.ordinal)), E = v.exponential(a.millis(Math.max(1, s.retryBaseDelayMs)), 2).pipe(v.either(v.spaced(a.millis(Math.max(1, s.retryMaxDelayMs)))), v.intersect(v.recurs(s.retryAttempts - 1))), ee = (e, t) => o.gen(function* () {
9440
- let n = yield* T(yg(e.table, e.pk), e, t.stamp);
9440
+ let n = yield* T(bg(e.table, e.pk), e, t.stamp);
9441
9441
  yield* t.kind === "upsert" ? i.upsert({
9442
9442
  table: e.table,
9443
9443
  row: t.row,
@@ -9448,27 +9448,27 @@ behind quietly.` + n;
9448
9448
  version: n
9449
9449
  });
9450
9450
  }), D = (e) => e instanceof Error ? `${e.name}: ${e.message}` : String(e), te = (e, t) => ee(e, t).pipe(o.tapErrorCause(() => o.sync(() => {
9451
- pg(ug);
9451
+ mg(dg);
9452
9452
  })), o.retry(E), o.matchCauseEffect({
9453
9453
  onSuccess: () => o.sync(() => {
9454
- b += 1, pg(lg);
9454
+ b += 1, mg(ug);
9455
9455
  }),
9456
9456
  onFailure: (n) => o.sync(() => {
9457
- ne(e, t, mg(n));
9457
+ ne(e, t, hg(n));
9458
9458
  })
9459
9459
  })), ne = (e, t, n) => {
9460
- let i = yg(e.table, e.pk);
9460
+ let i = bg(e.table, e.pk);
9461
9461
  for (r.warn("analytics-mirror: change forward failed, queued for repair", {
9462
9462
  provider: d,
9463
9463
  table: e.table,
9464
9464
  op: t.kind,
9465
9465
  attempts: s.retryAttempts,
9466
9466
  err: n
9467
- }), _.set(i, e), pg(dg); _.size > s.repairQueueLimit;) {
9467
+ }), _.set(i, e), mg(fg); _.size > s.repairQueueLimit;) {
9468
9468
  let e = _.keys().next();
9469
9469
  if (e.done === !0) break;
9470
9470
  let t = _.get(e.value);
9471
- _.delete(e.value), x += 1, pg(fg), r.error("analytics-mirror: repair queue full — change dropped, mirror is diverged", {
9471
+ _.delete(e.value), x += 1, mg(pg), r.error("analytics-mirror: repair queue full — change dropped, mirror is diverged", {
9472
9472
  provider: d,
9473
9473
  table: t?.table ?? "<unknown>",
9474
9474
  limit: s.repairQueueLimit
@@ -9498,7 +9498,7 @@ behind quietly.` + n;
9498
9498
  y.delete(t);
9499
9499
  });
9500
9500
  }, ae = (e, t) => {
9501
- let n = yg(e.table, e.pk);
9501
+ let n = bg(e.table, e.pk);
9502
9502
  h.set(n, t), !g.has(n) && (g.add(n), k(ie(n, e)));
9503
9503
  }, A = (e) => o.tryPromise({
9504
9504
  try: () => t.query({
@@ -9520,18 +9520,18 @@ behind quietly.` + n;
9520
9520
  table: t.table,
9521
9521
  row: r,
9522
9522
  version: n
9523
- }), _.delete(e), b += 1, pg(lg), !0;
9523
+ }), _.delete(e), b += 1, mg(ug), !0;
9524
9524
  }).pipe(o.catchAllCause((e) => o.sync(() => (r.warn("analytics-mirror: repair pass failed, key stays queued", {
9525
9525
  provider: d,
9526
9526
  table: t.table,
9527
- err: mg(e)
9527
+ err: hg(e)
9528
9528
  }), !1)))), j = () => o.gen(function* () {
9529
9529
  let e = [..._.entries()];
9530
9530
  if (e.length === 0) return 0;
9531
9531
  let t = 0;
9532
9532
  for (let [n, r] of e) (yield* oe(n, r)) && (t += 1);
9533
9533
  return t;
9534
- }), se = () => {
9534
+ }), M = () => {
9535
9535
  let e = 0;
9536
9536
  return Promise.resolve(c(j().pipe(o.tap((t) => o.sync(() => {
9537
9537
  e = t;
@@ -9539,21 +9539,21 @@ behind quietly.` + n;
9539
9539
  provider: d,
9540
9540
  err: D(e)
9541
9541
  }), 0));
9542
- }, ce = s.repairIntervalMs > 0 ? setInterval(() => {
9543
- se();
9542
+ }, se = s.repairIntervalMs > 0 ? setInterval(() => {
9543
+ M();
9544
9544
  }, s.repairIntervalMs) : void 0;
9545
- ce?.unref?.();
9546
- let le = (e) => {
9545
+ se?.unref?.();
9546
+ let ce = (e) => {
9547
9547
  if (!f) return {
9548
9548
  kind: "clock",
9549
9549
  version: m()
9550
9550
  };
9551
- let t = C(yg(e.table, e.pk));
9551
+ let t = C(bg(e.table, e.pk));
9552
9552
  return t.ordinal += 1, {
9553
9553
  kind: "ordinal",
9554
9554
  ordinal: t.ordinal
9555
9555
  };
9556
- }, M = (e) => {
9556
+ }, N = (e) => {
9557
9557
  if (e.op === "delete") {
9558
9558
  let t = e.old;
9559
9559
  if (t === null) return;
@@ -9565,7 +9565,7 @@ behind quietly.` + n;
9565
9565
  };
9566
9566
  ae(r, {
9567
9567
  kind: "remove",
9568
- stamp: le(r)
9568
+ stamp: ce(r)
9569
9569
  });
9570
9570
  return;
9571
9571
  }
@@ -9580,15 +9580,15 @@ behind quietly.` + n;
9580
9580
  ae(r, {
9581
9581
  kind: "upsert",
9582
9582
  row: t,
9583
- stamp: le(r)
9583
+ stamp: ce(r)
9584
9584
  });
9585
- }, ue = t.onChange((e) => {
9586
- u.has(e.table) && M(e);
9585
+ }, le = t.onChange((e) => {
9586
+ u.has(e.table) && N(e);
9587
9587
  });
9588
9588
  return {
9589
9589
  tables: i.tables,
9590
9590
  detach: () => {
9591
- ue(), ce !== void 0 && clearInterval(ce);
9591
+ le(), se !== void 0 && clearInterval(se);
9592
9592
  },
9593
9593
  flush: async () => {
9594
9594
  for (let e = 0; e < 1e3; e++) {
@@ -9596,7 +9596,7 @@ behind quietly.` + n;
9596
9596
  await Promise.all([...y]);
9597
9597
  }
9598
9598
  },
9599
- repair: se,
9599
+ repair: M,
9600
9600
  stats: () => ({
9601
9601
  forwarded: b,
9602
9602
  pending: h.size,
@@ -9604,11 +9604,11 @@ behind quietly.` + n;
9604
9604
  dropped: x
9605
9605
  })
9606
9606
  };
9607
- }, xg = (e) => {
9607
+ }, Sg = (e) => {
9608
9608
  let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
9609
9609
  if (n === "merge" && (e.mergeKey === void 0 || e.mergeKey.length === 0)) throw Error(`defineAggregate("${e.name}"): strategy: 'merge' requires mergeKey — the property on each row to upsert by`);
9610
9610
  if (e.incremental !== void 0) {
9611
- let t = ym({
9611
+ let t = bm({
9612
9612
  aggregations: [{
9613
9613
  op: e.incremental.op,
9614
9614
  ...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
@@ -9630,46 +9630,46 @@ behind quietly.` + n;
9630
9630
  build: e.build,
9631
9631
  ...e.incremental === void 0 ? {} : { incremental: e.incremental }
9632
9632
  };
9633
- }, Sg = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Cg = class extends y.TaggedError()("AggregateStale", {
9633
+ }, Cg = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, wg = class extends y.TaggedError()("AggregateStale", {
9634
9634
  name: y.String,
9635
9635
  ageMs: y.Number,
9636
9636
  maxAgeMs: y.Number
9637
- }) {}, wg = class extends y.TaggedError()("AggregateNotFound", { name: y.String }) {}, Tg = class extends y.TaggedError()("AggregateError", {
9637
+ }) {}, Tg = class extends y.TaggedError()("AggregateNotFound", { name: y.String }) {}, Eg = class extends y.TaggedError()("AggregateError", {
9638
9638
  name: y.String,
9639
9639
  operation: y.String,
9640
9640
  cause: y.String
9641
- }) {}, Eg = class extends n.Tag("@voltro/AggregateRegistry")() {}, Dg = (e) => o.gen(function* () {
9642
- return (yield* Eg).getHandle(e);
9643
- }), Og = (e, t, n) => {
9641
+ }) {}, Dg = class extends n.Tag("@voltro/AggregateRegistry")() {}, Og = (e) => o.gen(function* () {
9642
+ return (yield* Dg).getHandle(e);
9643
+ }), kg = (e, t, n) => {
9644
9644
  if (e.crossTenant || !t.has(e.table) || n == null) return e;
9645
9645
  let r = O("tenantId", n);
9646
9646
  return {
9647
9647
  ...e,
9648
9648
  predicate: e.predicate ? C(e.predicate, r) : r
9649
9649
  };
9650
- }, kg = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Ag = (e) => e?.type === "user" && e.tenantId === "", jg = (e, t) => {
9650
+ }, Ag = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), jg = (e) => e?.type === "user" && e.tenantId === "", Mg = (e, t) => {
9651
9651
  if (e.includeDeleted || !t.has(e.table)) return e;
9652
- let n = fe("deletedAt");
9652
+ let n = de("deletedAt");
9653
9653
  return {
9654
9654
  ...e,
9655
9655
  predicate: e.predicate ? C(e.predicate, n) : n
9656
9656
  };
9657
- }, Mg = (e) => (t, n) => {
9657
+ }, Ng = (e) => (t, n) => {
9658
9658
  e.observe?.beforeScope?.({ ...t }, n);
9659
- let r = jg(Og(t, e.tenantScopedTables, n.tenantId), e.softDeleteScopedTables);
9659
+ let r = Mg(kg(t, e.tenantScopedTables, n.tenantId), e.softDeleteScopedTables);
9660
9660
  return e.observe?.afterScope?.({ ...r }), r;
9661
- }, Ng = (e, t) => t, Pg = (t) => o.runPromiseExit(t).then((t) => {
9661
+ }, Pg = (e, t) => t, Fg = (t) => o.runPromiseExit(t).then((t) => {
9662
9662
  if (c.isSuccess(t)) return t.value;
9663
9663
  let n = e.failureOption(t.cause);
9664
9664
  throw h.isSome(n) ? n.value : e.squash(t.cause);
9665
- }), Fg = (e, t) => e.pipe(o.provideService(gt, t)), Ig = async (e, t, n, r) => {
9666
- let i = await o.runPromise(z(t, e.guards, n, {
9665
+ }), Ig = (e, t) => e.pipe(o.provideService(ht, t)), Lg = async (e, t, n, r) => {
9666
+ let i = await o.runPromise(xt(t, e.guards, n, {
9667
9667
  defaultDeny: r === !0,
9668
9668
  procedure: e.name
9669
9669
  }));
9670
9670
  if (i) throw i;
9671
- }, Lg = async (e, t, n, r) => {
9672
- e.requiresApproval !== void 0 && await em({
9671
+ }, Rg = async (e, t, n, r) => {
9672
+ e.requiresApproval !== void 0 && await tm({
9673
9673
  procedure: e.name,
9674
9674
  kind: t,
9675
9675
  policy: e.requiresApproval,
@@ -9677,16 +9677,16 @@ behind quietly.` + n;
9677
9677
  input: r,
9678
9678
  traceId: n.traceId
9679
9679
  });
9680
- }, Rg = async (e) => {
9680
+ }, zg = async (e) => {
9681
9681
  if (mi() === void 0) return e;
9682
- let t = await Pg(_i(e.subject, (e) => {
9682
+ let t = await Fg(_i(e.subject, (e) => {
9683
9683
  console.error("[voltro] row filter failed to load", e);
9684
9684
  }));
9685
9685
  return {
9686
9686
  ...e,
9687
9687
  rowFilter: t
9688
9688
  };
9689
- }, zg = (e) => {
9689
+ }, Bg = (e) => {
9690
9690
  let t = e.descriptor.target;
9691
9691
  if (t == null) return [];
9692
9692
  let n = Array.isArray(t) ? t : [t], r = /* @__PURE__ */ new Set();
@@ -9695,7 +9695,7 @@ behind quietly.` + n;
9695
9695
  typeof t == "string" && t.length > 0 && r.add(t);
9696
9696
  }
9697
9697
  return [...r];
9698
- }, Bg = async (t) => {
9698
+ }, Vg = async (t) => {
9699
9699
  let n = `${t.kind}.${t.name}`, r = Date.now(), i = "ok";
9700
9700
  try {
9701
9701
  if (t.interceptor) {
@@ -9725,46 +9725,46 @@ behind quietly.` + n;
9725
9725
  status: i
9726
9726
  });
9727
9727
  }
9728
- }, Vg = /* @__PURE__ */ new Set([1213, 1205]), Hg = /* @__PURE__ */ new Set([
9728
+ }, Hg = /* @__PURE__ */ new Set([1213, 1205]), Ug = /* @__PURE__ */ new Set([
9729
9729
  "ER_LOCK_DEADLOCK",
9730
9730
  "ER_LOCK_WAIT_TIMEOUT",
9731
9731
  "40001",
9732
9732
  "40P01"
9733
- ]), Ug = (e) => {
9733
+ ]), Wg = (e) => {
9734
9734
  let t = e;
9735
9735
  for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
9736
9736
  let e = t;
9737
- if (typeof e.errno == "number" && Vg.has(e.errno) || typeof e.code == "string" && Hg.has(e.code) || typeof e.sqlState == "string" && Hg.has(e.sqlState)) return !0;
9737
+ if (typeof e.errno == "number" && Hg.has(e.errno) || typeof e.code == "string" && Ug.has(e.code) || typeof e.sqlState == "string" && Ug.has(e.sqlState)) return !0;
9738
9738
  t = e.cause;
9739
9739
  }
9740
9740
  return !1;
9741
- }, Wg = 3, Gg = (e) => new Promise((t) => setTimeout(t, e)), Kg = async (e, t) => {
9742
- let n = t?.delay ?? ((e) => Gg(e * 20 + Math.floor(Math.random() * 30)));
9741
+ }, Gg = 3, Kg = (e) => new Promise((t) => setTimeout(t, e)), qg = async (e, t) => {
9742
+ let n = t?.delay ?? ((e) => Kg(e * 20 + Math.floor(Math.random() * 30)));
9743
9743
  for (let t = 1;; t++) try {
9744
9744
  return await e();
9745
9745
  } catch (e) {
9746
- if (t >= Wg || !Ug(e)) throw e;
9746
+ if (t >= Gg || !Wg(e)) throw e;
9747
9747
  await n(t);
9748
9748
  }
9749
- }, qg = (e) => (t, n, r) => Bg({
9749
+ }, Jg = (e) => (t, n, r) => Vg({
9750
9750
  name: t.descriptor.name,
9751
9751
  kind: "mutation",
9752
9752
  input: n,
9753
9753
  requestContext: r,
9754
- target: zg(t),
9754
+ target: Bg(t),
9755
9755
  ...e.interceptor ? { interceptor: e.interceptor } : {},
9756
9756
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
9757
9757
  runExecutor: async () => {
9758
- await Ig(t.descriptor, r.subject, n, e.defaultDeny), await Lg(t.descriptor, "mutation", r, n);
9759
- let i = await Rg(r), a = [], s = await Kg(async () => (a.length = 0, e.store.transactional(async (s) => {
9760
- let c = e.undoCapture?.(s), l = fp(c ? c.tx : s), u = e.buildContext(i, l.tx, { afterCommit: (e) => {
9758
+ await Lg(t.descriptor, r.subject, n, e.defaultDeny), await Rg(t.descriptor, "mutation", r, n);
9759
+ let i = await zg(r), a = [], s = await qg(async () => (a.length = 0, e.store.transactional(async (s) => {
9760
+ let c = e.undoCapture?.(s), l = pp(c ? c.tx : s), u = e.buildContext(i, l.tx, { afterCommit: (e) => {
9761
9761
  a.push(e);
9762
- } }), d = t.executor(n, u), f = o.isEffect(d) ? await e.runEffect(Fg(d, r.subject), u.store) : await d;
9762
+ } }), d = t.executor(n, u), f = o.isEffect(d) ? await e.runEffect(Ig(d, r.subject), u.store) : await d;
9763
9763
  return c && await c.persist(u.store, {
9764
9764
  tag: t.descriptor.name,
9765
9765
  subject: r.subject,
9766
9766
  traceId: r.traceId
9767
- }), await mp({
9767
+ }), await hp({
9768
9768
  touched: l.drain(),
9769
9769
  store: u.store,
9770
9770
  subject: r.subject
@@ -9773,40 +9773,40 @@ behind quietly.` + n;
9773
9773
  for (let e of a) await e();
9774
9774
  return s;
9775
9775
  }
9776
- }), Jg = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, Yg = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, Xg = (e) => {
9776
+ }), Yg = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, Xg = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, Zg = (e) => {
9777
9777
  let t = e.descriptor.source;
9778
9778
  return t == null ? [] : typeof t == "string" ? [t] : [...t];
9779
- }, Zg = (e, t, n) => (r) => () => {
9779
+ }, Qg = (e, t, n) => (r) => () => {
9780
9780
  let i = e.descriptor.guards;
9781
- return (!i || i.length === 0) && n !== !0 ? Promise.resolve(null) : o.runPromise(z(r, i, t, {
9781
+ return (!i || i.length === 0) && n !== !0 ? Promise.resolve(null) : o.runPromise(xt(r, i, t, {
9782
9782
  defaultDeny: n === !0,
9783
9783
  procedure: e.descriptor.name
9784
9784
  }));
9785
- }, Qg = (e, t) => e.rowFilter !== void 0 || mi() === void 0 ? t(e) : o.promise(() => Rg(e)).pipe(o.flatMap((e) => {
9785
+ }, $g = (e, t) => e.rowFilter !== void 0 || mi() === void 0 ? t(e) : o.promise(() => zg(e)).pipe(o.flatMap((e) => {
9786
9786
  let n = t(e);
9787
9787
  return o.isEffect(n) ? n : o.succeed(n);
9788
- })), $g = (e) => (t, n) => (r) => {
9789
- if (r.rowFilter === void 0 && mi() !== void 0) return Qg(r, (r) => $g(e)(t, n)(r));
9790
- let i = e.buildContext(r), a = Zg(t, n, e.defaultDeny)(r.subject), s = async () => {
9788
+ })), e_ = (e) => (t, n) => (r) => {
9789
+ if (r.rowFilter === void 0 && mi() !== void 0) return $g(r, (r) => e_(e)(t, n)(r));
9790
+ let i = e.buildContext(r), a = Qg(t, n, e.defaultDeny)(r.subject), s = async () => {
9791
9791
  let i = await a();
9792
9792
  if (i) throw i;
9793
- let s = e.buildContext(await Rg(r)), c = t.executor(n, s);
9794
- return o.isEffect(c) ? o.runPromise(e.provideEffect(Fg(c, r.subject), s.store)) : Jg(await Promise.resolve(c));
9793
+ let s = e.buildContext(await zg(r)), c = t.executor(n, s);
9794
+ return o.isEffect(c) ? o.runPromise(e.provideEffect(Ig(c, r.subject), s.store)) : Yg(await Promise.resolve(c));
9795
9795
  }, c = (n) => {
9796
- let i = Jg(n);
9797
- return Yg(i) ? e.finalize(i, r) : {
9796
+ let i = Yg(n);
9797
+ return Xg(i) ? e.finalize(i, r) : {
9798
9798
  __voltroComputed: !0,
9799
9799
  value: i,
9800
- dependentTables: Xg(t),
9800
+ dependentTables: Zg(t),
9801
9801
  tenantId: r.subject?.tenantId ?? null,
9802
9802
  recompute: s
9803
9803
  };
9804
9804
  }, l = () => {
9805
9805
  let a = t.executor(n, i);
9806
- return o.isEffect(a) ? e.provideEffect(Fg(a, r.subject), i.store).pipe(o.map(c)) : a instanceof Promise ? o.promise(() => a).pipe(o.map(c)) : c(a);
9806
+ return o.isEffect(a) ? e.provideEffect(Ig(a, r.subject), i.store).pipe(o.map(c)) : a instanceof Promise ? o.promise(() => a).pipe(o.map(c)) : c(a);
9807
9807
  }, u = () => {
9808
9808
  let i = t.descriptor.guards;
9809
- return (!i || i.length === 0) && e.defaultDeny !== !0 ? l() : z(r.subject, i, n, {
9809
+ return (!i || i.length === 0) && e.defaultDeny !== !0 ? l() : xt(r.subject, i, n, {
9810
9810
  defaultDeny: e.defaultDeny === !0,
9811
9811
  procedure: t.descriptor.name
9812
9812
  }).pipe(o.flatMap((e) => {
@@ -9828,14 +9828,14 @@ behind quietly.` + n;
9828
9828
  traceId: r.traceId,
9829
9829
  ...r.spanId === void 0 ? {} : { spanId: r.spanId }
9830
9830
  });
9831
- }, e_ = (e) => async (t, n, r) => {
9832
- let i = await Rg(r), a = $g(e)(t, n)(i), s = o.isEffect(a) ? await Pg(a) : a;
9831
+ }, t_ = (e) => async (t, n, r) => {
9832
+ let i = await zg(r), a = e_(e)(t, n)(i), s = o.isEffect(a) ? await Fg(a) : a;
9833
9833
  return Mi(s) ? s.value : e.queryRows(s, i);
9834
- }, t_ = (e) => (t, n, r, i) => {
9834
+ }, n_ = (e) => (t, n, r, i) => {
9835
9835
  let a = !1, s;
9836
9836
  return (async () => {
9837
9837
  try {
9838
- let c = await Rg(r), l = $g(e)(t, n)(c), u = o.isEffect(l) ? await Pg(l) : l, d = (e) => i(e), f = Mi(u) ? await e.subscribeComputed(u, d, c) : await e.subscribeDescriptor(u, d, c);
9838
+ let c = await zg(r), l = e_(e)(t, n)(c), u = o.isEffect(l) ? await Fg(l) : l, d = (e) => i(e), f = Mi(u) ? await e.subscribeComputed(u, d, c) : await e.subscribeDescriptor(u, d, c);
9839
9839
  a ? f() : s = f;
9840
9840
  } catch (e) {
9841
9841
  i({
@@ -9846,25 +9846,25 @@ behind quietly.` + n;
9846
9846
  })(), () => {
9847
9847
  a = !0, s?.();
9848
9848
  };
9849
- }, n_ = (e) => (t, n, r) => Bg({
9849
+ }, r_ = (e) => (t, n, r) => Vg({
9850
9850
  name: t.descriptor.name,
9851
9851
  kind: "action",
9852
9852
  input: n,
9853
9853
  requestContext: r,
9854
- target: zg(t),
9854
+ target: Bg(t),
9855
9855
  ...e.interceptor ? { interceptor: e.interceptor } : {},
9856
9856
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
9857
9857
  runExecutor: async () => {
9858
- await Ig(t.descriptor, r.subject, n, e.defaultDeny), await Lg(t.descriptor, "action", r, n);
9859
- let i = e.buildContext(await Rg(r)), a = t.executor(n, i);
9860
- return o.isEffect(a) ? e.runEffect(Fg(a, r.subject), i.store) : a;
9858
+ await Lg(t.descriptor, r.subject, n, e.defaultDeny), await Rg(t.descriptor, "action", r, n);
9859
+ let i = e.buildContext(await zg(r)), a = t.executor(n, i);
9860
+ return o.isEffect(a) ? e.runEffect(Ig(a, r.subject), i.store) : a;
9861
9861
  }
9862
- }), r_ = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, i_ = (e) => typeof e == "string" && e.length > 0 ? e : null, a_ = [
9862
+ }), i_ = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, a_ = (e) => typeof e == "string" && e.length > 0 ? e : null, o_ = [
9863
9863
  "updatedAt",
9864
9864
  "createdAt",
9865
9865
  "updatedBy",
9866
9866
  "createdBy"
9867
- ], o_ = (e) => a_.some((t) => t in e), s_ = (e, t, n) => {
9867
+ ], s_ = (e) => o_.some((t) => t in e), c_ = (e, t, n) => {
9868
9868
  let r = {
9869
9869
  table: t.table,
9870
9870
  id: t.id,
@@ -9879,14 +9879,14 @@ behind quietly.` + n;
9879
9879
  found: !1
9880
9880
  };
9881
9881
  let i = t.column === void 0 ? void 0 : e[t.column];
9882
- if (!o_(e)) return {
9882
+ if (!s_(e)) return {
9883
9883
  ...r,
9884
9884
  value: i,
9885
9885
  lastWrite: null,
9886
9886
  attribution: "none",
9887
9887
  found: !0
9888
9888
  };
9889
- let a = i_(e.updatedBy) ?? i_(e.createdBy), o = r_(e.updatedAt) ?? r_(e.createdAt);
9889
+ let a = a_(e.updatedBy) ?? a_(e.createdBy), o = i_(e.updatedAt) ?? i_(e.createdAt);
9890
9890
  return {
9891
9891
  ...r,
9892
9892
  value: i,
@@ -9898,12 +9898,12 @@ behind quietly.` + n;
9898
9898
  attribution: "audit",
9899
9899
  found: !0
9900
9900
  };
9901
- }, c_ = (e, t) => {
9901
+ }, l_ = (e, t) => {
9902
9902
  let n = e.map((e) => {
9903
9903
  let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
9904
9904
  return {
9905
- actor: { id: i_(e.actor) ?? i_(e.changedBy) },
9906
- at: r_(e.at) ?? r_(e.changedAt),
9905
+ actor: { id: a_(e.actor) ?? a_(e.changedBy) },
9906
+ at: i_(e.at) ?? i_(e.changedAt),
9907
9907
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
9908
9908
  value: r
9909
9909
  };
@@ -9918,12 +9918,12 @@ behind quietly.` + n;
9918
9918
  history: n,
9919
9919
  found: n.length > 0
9920
9920
  };
9921
- }, l_ = (e) => {
9921
+ }, u_ = (e) => {
9922
9922
  let t = e.new?.id;
9923
9923
  if (typeof t == "string") return t;
9924
9924
  let n = e.old?.id;
9925
9925
  return typeof n == "string" ? n : void 0;
9926
- }, u_ = (e) => {
9926
+ }, d_ = (e) => {
9927
9927
  let t = {};
9928
9928
  if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
9929
9929
  from: void 0,
@@ -9943,11 +9943,11 @@ behind quietly.` + n;
9943
9943
  return {
9944
9944
  table: e.table,
9945
9945
  op: e.op,
9946
- id: l_(e),
9946
+ id: u_(e),
9947
9947
  fields: t
9948
9948
  };
9949
- }, d_ = (e) => {
9950
- let t = e.map(u_);
9949
+ }, f_ = (e) => {
9950
+ let t = e.map(d_);
9951
9951
  return {
9952
9952
  rows: t,
9953
9953
  summary: {
@@ -9956,21 +9956,21 @@ behind quietly.` + n;
9956
9956
  deletes: t.filter((e) => e.op === "delete").length
9957
9957
  }
9958
9958
  };
9959
- }, f_ = class extends Error {
9959
+ }, p_ = class extends Error {
9960
9960
  constructor() {
9961
9961
  super("voltro:preview-rollback"), this.name = "PreviewRollback";
9962
9962
  }
9963
- }, p_ = async (e, t) => {
9963
+ }, m_ = async (e, t) => {
9964
9964
  let n, r = !1;
9965
9965
  try {
9966
9966
  await e.transactional(async (e) => {
9967
- throw n = await t(e), r = !0, new f_();
9967
+ throw n = await t(e), r = !0, new p_();
9968
9968
  });
9969
9969
  } catch (e) {
9970
- if (!(e instanceof f_)) throw e;
9970
+ if (!(e instanceof p_)) throw e;
9971
9971
  }
9972
9972
  if (!r) throw Error("preview: handler did not complete");
9973
9973
  return n;
9974
- }, m_ = "framework-runtime";
9974
+ }, h_ = "framework-runtime";
9975
9975
  //#endregion
9976
- export { Ao as API_CSP, fc as API_KEYS_TABLE, Np as APPROVALS_TABLE, Hu as AccessDenied, Tg as AggregateError, Om as AggregateMaintainer, wg as AggregateNotFound, Eg as AggregateRegistry, Cg as AggregateStale, eg as AnalyticsCapabilityNotSupported, $h as AnalyticsError, tg as AnalyticsSink, Hf as CLAIM_RETENTION_BUCKETS, Y as CONNECTIONS_TABLE, Vl as CONNECTION_GRANTS_TABLE, of as CircuitBreaker, rf as CircuitOpen, uu as ConnectionNotConnected, hh as CostAccountant, ch as CostRegistry, hg as DEFAULT_ANALYTICS_MIRROR_TUNABLES, Pp as DEFAULT_APPROVAL_EXPIRY_MS, Vf as DEFAULT_CLAIM_BUCKET_MS, $n as DEFAULT_DELIVERY_CONCURRENCY, Mo as DEFAULT_HSTS, Yf as DEFAULT_MAX_IDLE_INTERVAL_MS, _s as DEFAULT_MAX_RPC_BODY_BYTES, er as DEFAULT_RAW_READ_TRACKING_LIMIT, cu as DEFAULT_REFRESH_SKEW_MS, li as DEFAULT_ROW_FILTER_RETRY, Rf as DORMANCY_WAKEUP_TENANT, ja as DeleteBuilder, ki as Dispatcher, hl as EVENT_CLIENT_QUEUE_SIZE, gl as EVENT_LATEST_QUEUE_SIZE, Dc as EffectStore, ul as EventBus, eh as ExpectationEvaluator, Wm as ExpectationRegistry, Ph as ExperimentEvaluator, wh as ExperimentRegistry, Su as GRANT_TTL_MS, _h as HOLDOUT_VARIANT, jo as HTML_CSP, qn as InMemoryDataStore, Pn as IndexedMatcher, Sl as InstanceMembership, Dn as LinearScanMatcher, p as MetricBoundaries, ig as NOOP_ANALYTICS_PROVIDER, gi as NO_ROW_FILTER, vo as NO_TRUSTED_PROXIES, wa as NoRowFound, El as OUTBOX_ATTEMPTS_TABLE, Nl as OUTBOX_ATTEMPT_LOG_CAP, J as OUTBOX_TABLE, Ta as OptimisticLockError, Vu as REBAC_ADMIN_SCOPE, lu as REFRESH_LEASE_MS, m_ as RUNTIME_NAME, Rm as ReactionRateLimiter, eo as ReplicatedDataStore, ci as RowFilterUnavailable, Lf as SCHEDULE_SUBJECT, Ec as SYSTEM_SUBJECT, ka as SelectBuilder, La as ServerOnlyColumnWrite, pd as SsrfBlockedError, Pa as StoreOperationFailed, Ln as SubscriptionRegistry, Fa as TableValidationFailed, Ia as TenantRowNotFound, Na as TenantScopeViolation, pm as TimelineRecorder, vp as UndoBoundaryError, bp as UndoStack, Bo as UnverifiedWebhookRoute, Aa as UpdateBuilder, bd as VOLTRO_AUDIT_MIXIN_ID, Sd as VOLTRO_EXPIRES_MIXIN_ID, wd as VOLTRO_LOCAL_FIRST_MIXIN_ID, xd as VOLTRO_SOFT_DELETE_MIXIN_ID, Cd as VOLTRO_TENANT_MIXIN_ID, Lo as WEBHOOK_VERIFICATION_PROPERTY, Pc as WorkflowDeferredResultError, Hc as WorkflowPayloadError, Fc as WorkflowRateLimitedError, Ic as WorkflowSingletonHeldError, qi as _connectionStreamCount, Ji as _resetConnectionCredentialsForTest, Fp as _voltroApprovalsTable, Ul as _voltroConnectionGrantsTable, Bl as _voltroConnectionsTable, km as _voltroRebacTuplesTable, tp as _voltroScheduleClaimsTable, ep as _voltroScheduleRunsTable, np as _voltroTracesTable, rp as _voltroUndoLogTable, Ih as _voltroWakeupsTable, il as _voltroWorkflowEventDeliveriesTable, rl as _voltroWorkflowEventsTable, Ua as actingUserId, Tc as apiKeyManagementRoutes, Ui as applyConnectionCredential, Ba as applyDefined, Em as applyDelta, Sp as applyInverse, Cp as applyInverses, tf as applyPluginRefRules, bi as applyRowFilter, xi as applyRowFilterToDescriptor, jg as applySoftDeleteScope, Og as applyTenantScope, jp as applyUndoInvocation, Vp as approvalIntentKey, rm as approvalNonce, am as approvalsPendingExecutor, Qu as assertCan, ql as assertConnectionCipherConfigured, Vo as assertWebhookRoutesDeclareVerification, Sh as assignVariant, bg as attachAnalyticsMirror, th as attachExpectations, Fh as attachExperiments, gh as attachFinops, ks as awaitServerListening, Ml as backoffMs, Eu as beginOAuthConnect, zi as bindConnectionCredential, yl as bindEvent, gs as bindMutation, rs as bindStream, ns as bindSubscription, Zo as bindSubscriptionUntyped, wm as buildIvmState, d_ as buildPreview, Mm as buildRebacInterceptor, Pm as buildRebacReadFilter, Ja as buildSubjectKey, Is as buildTracingLayer, Gd as cacheScopeLeaks, Zs as cachedBackend, Zu as can, Ef as cancelWakeup, Bp as canonicalJson, Fn as canonicalize, Uf as claimGraceMs, go as classifyRequestOrigin, ym as classifyShape, $p as clearApprovalGate, mu as clearConnectionRefreshFlights, qu as clearResourcePolicies, ee as clearRetentions, lf as clearSystemStoreHandle, nf as collectPluginRefRules, bf as compileCron, Du as completeOAuthConnect, sg as composeAnalytics, og as composeAnalyticsSinks, Cu as connectionCallbackPath, Kl as connectionLabel, Yh as countRunningWorkflows, ni as counter, Sf as cronOccurrences, Bd as crud, or as currentRawReads, rd as currentRequestLoader, $a as currentRoutingContext, ta as currentTraceContext, Sc as dataStoreApiKeyStore, ic as dataStoreIdempotencyStore, lc as dataStoreKvStore, tm as decideApproval, om as decideApprovalInvocation, da as decryptField, fs as defectMessage, xg as defineAggregate, Gl as defineConnection, oh as defineCostBudget, Qc as defineEventTrigger, Ng as defineExecutor, Hm as defineExpectation, yh as defineExperiment, kl as defineOutboxHandler, Fm as defineReaction, Wu as defineResourcePolicy, yf as defineSchedule, Qh as defineSubscriber, Di as deliveredRowCount, ia as deriveKey, u_ as diffChange, Ds as drainForShutdown, Ll as drainOutbox, Nf as dueWakeups, Xu as effectiveRelations, Ad as emptySchemaRegistry, _a as enableGraphObservation, ua as encryptField, em as enforceApproval, nd as enterRequestLoader, Gs as envSecretsBackend, mp as evaluateTouchedRules, Wr as eventMetricTagCacheSizeForTests, ou as exchangeAuthorizationCode, Qi as externalSpanFromTraceparent, Yn as extractDbCause, In as fingerprintFor, Ti as forbiddenColumnsForSubject, nu as forgetCredential, Kd as formatCacheScopeLeaks, Wd as formatServerOnlyLeaks, Xi as formatTraceparent, Yd as formatUnresolvedSources, xp as forwardChangeFromCdc, Cc as frameworkApiKeyStrategy, ri as gauge, mc as generateApiKeyToken, Qp as getApprovalGate, Bi as getConnectionCredential, ju as getConnectionResolver, Ri as getCredentialExpiry, K as getFieldCipher, Gu as getResourcePolicy, mi as getRowFilter, uf as getSystemStoreHandle, hm as getTimelineRecorder, cd as getTupleSource, xm as groupKeyOf, xh as hashUnitInterval, ii as histogramMetric, c_ as historyProvenance, Qs as httpSecretsBackend, Cn as inspectWorkflow, Zp as installApprovalGate, ld as installPolicyGuardResolver, Ki as interruptConnectionStreams, gp as invertChange, So as ipToBytes, Sg as isAggregateDefinition, sh as isCostBudgetDefinition, kg as isEmptyTenantScopedRead, Um as isExpectationDefinition, bh as isExperimentDefinition, Xn as isForeignKeyViolation, Hh as isIdleNow, ls as isInfraError, va as isObservingGraph, Ag as isOrglessUserSubject, Zn as isQueryTimeout, yp as isSafeToApply, _f as isScheduleDefinition, $d as isSoftDelete, ao as isStateChangingMethod, Eo as isTrustedProxy, $c as isWorkflowEventTriggerDefinition, ir as isolateRawReadScope, Cm as ivmValue, s_ as lastWriteProvenance, ru as listConnectionStates, Ku as listResourcePolicies, me as listRetentionConflicts, he as listRetentions, Am as loadResourceTuples, Nm as loadSubjectTuples, pf as localityAwareSelector, n_ as makeActionRunner, Wf as makeAdvisoryLockCoordinator, aa as makeAesCipher, _c as makeApiKeyService, yd as makeApiKeyUsageBuffer, xc as makeApiKeyUsageFlusher, Qn as makeAppAccess, Yp as makeApprovalGate, uc as makeAsyncKv, ff as makeAuthMiddlewareLayers, vl as makeBufferGapDetector, Ws as makeBufferingSpanProcessor, Jl as makeConnectionRegistry, Nu as makeConnectionResolver, Pu as makeConnectionsFacade, $f as makeCoordinatedScheduler, dd as makeDataLoader, Bu as makeDisconnectConnectionExecutor, Ac as makeEffectStoreLayer, ml as makeEventPublisher, al as makeEventsFacade, oa as makeFieldCipher, Ma as makeFluentStore, Uh as makeIdleGate, Jc as makeLazyWorkflowFacade, Lu as makeListConnectionsExecutor, ms as makeMutationOutputCodec, qg as makeMutationRunner, e_ as makeOneShotQueryRunner, co as makeOriginGuardExemption, jl as makeOutboxFacade, Kc as makePostCommitWorkflowFacade, zh as makeProcessAdapter, $g as makeQueryDescriptorProducer, Mg as makeQueryFinalizer, Zg as makeQueryReauthorizer, t_ as makeQuerySubscriber, Wh as makeRouterActivity, fp as makeRuleCapture, Td as makeSchemaRegistry, Ru as makeStartConnectionExecutor, zu as makeSubmitTokenExecutor, lp as makeUndoCapture, Gh as makeWakeGate, Jh as makeWakeProxyServer, Gc as makeWorkflowFacade, qc as makeWorkflowFacadeWithCallerContext, Yc as makeWorkflowHandlers, Xc as makeWorkflowLayers, Rc as makeWorkflowRunHandle, Df as markWakeupFired, Tm as materializeIvm, vc as memoryApiKeyStore, hf as memoryReplicationAdapter, qa as memoryRywPositionStore, Hi as mergeCookieHeader, Qf as nextDelay, xf as nextFiring, Pf as nextWakeup, Vh as nodeProcessSupervisor, ag as noopAnalytics, cg as noopAnalyticsSpec, dc as noopKv, yo as normalizeIp, uo as normalizeOrigin, Ca as observeStore, xa as observedGraph, Ss as onProcessShutdown, Ns as otelImportFailure, Ol as outboxAttemptsTable, Tl as outboxTable, Jp as parseApprovalInterval, Zi as parseTraceparent, Uc as payloadPropertyNames, nm as pendingApprovalsFor, Ga as powerOfTwoSelector, p_ as previewInRollback, Ql as projectConnectionState, If as pruneWakeups, fl as publishEvent, cr as rawSqlPreview, Xf as readPollCeilingMs, Ju as rebacPolicyGraph, Li as recordCredentialExpiry, Kr as recordEventDelivered, qr as recordEventDropped, Gr as recordEventPublished, Jr as recordEventSubscribers, ar as recordRawRead, Yr as recordSample, ei as recordScheduleRun, $r as recordSubscriptionActive, Zr as recordSubscriptionDelivery, ba as recordTableAccess, _m as recordTimelineEvent, ti as recordWorkflowRun, Id as redactColumns, um as redactRow, Ya as redisRywPositionStore, Mp as redoUndoInvocation, su as refreshAccessToken, Gi as registerConnectionStream, Ee as registerRetention, Tf as registerWakeup, Rp as rehydrateGuards, Af as releaseWakeup, Ka as replicaHealth, $o as resetComputedQueryCacheWarnings, Ur as resetEventMetricTagCacheForTests, Sa as resetObservedGraph, Js as resetSecretsBackend, Oo as resolveClientAddress, _u as resolveConnection, Mu as resolveConnectionForSubject, mf as resolveCurrentRegion, lr as resolveDependentTables, _o as resolveOriginGuardConfig, nr as resolveReactiveConfig, Tu as resolveRedirectUri, ko as resolveRequestIsHttps, Dm as resolveRescan, _i as resolveRowFilterScope, vi as resolveRowFilterScopeFor, Ys as resolveSecret, Xs as resolveSecretSync, $s as resolveSecretsBackend, Fo as resolveSecurityHeaders, sm as resolveTimelineMode, Do as resolveTrustedProxies, Ch as resultVariantNames, ke as retentionTtlMsFromEnv, fm as reverseEventOverRows, ed as revokedIds, hi as rowFilterRegistered, ef as rulesFor, df as runAsSystem, Xh as runOrchestratorTick, Pg as runProvidedEffect, Bm as runReaction, Zh as runSingleNodeOrchestrator, Rh as runWakeLoop, Kg as runWithDeadlockRetry, ya as runWithObservedProcedure, sr as runWithRawReadScope, id as runWithRequestLoader, Qa as runWithRoutingContext, ea as runWithTraceContext, wu as sanitizeRedirectTo, Zf as scheduleCoordinated, Vd as schemaPropertyNames, zp as scopeStringsOf, Io as securityHeadersFor, Lp as serializeGuards, Si as serverOnlyColumnNames, Ud as serverOnlyLeaks, Au as setConnectionResolver, ca as setFieldCipher, pi as setRowFilter, qs as setSecretsBackend, cf as setSystemStoreHandle, gm as setTimelineRecorderForTest, sd as setTupleSource, En as settleHandlerBody, pc as sha256Hex, Es as shutdownGraceMsFromEnv, zf as singleCoordinator, oi as snapshotMetrics, si as snapshotMetricsSync, vd as ssrfGuardHttpClientLayer, _d as ssrfReason, vs as startRpcServer, Kf as startScheduler, eu as storeCredential, Ci as stripColumnsFromRows, Ei as stripForbiddenForWire, wi as stripServerOnlyForWire, Ou as sweepExpiredGrants, Le as sweepRetention, _p as synthesizeInverse, fd as tracingHttpClientLayer, Zc as triggerWorkflow, kf as tryClaimWakeup, Vi as unbindConnection, ip as undoCaptureEnabled, kp as undoLogExecutor, ap as undoSurfaceEnabled, Jd as unresolvedSources, Dg as useAggregate, rg as useAnalytics, lh as useCostBudget, Gm as useExpectation, Th as useExperiment, $u as visibleRows, Lh as wakeDueOnce, zo as webhookVerificationOf, Rg as withRowFilter, Qg as withScopedRequest, jc as workflowToRpc, cp as wrapCaptureStore, Md as wrapStoreWithBootCodec, Wa as wrapStoreWithMixinBehaviour };
9976
+ export { Ao as API_CSP, fc as API_KEYS_TABLE, Pp as APPROVALS_TABLE, Hu as AccessDenied, Eg as AggregateError, km as AggregateMaintainer, Tg as AggregateNotFound, Dg as AggregateRegistry, wg as AggregateStale, tg as AnalyticsCapabilityNotSupported, eg as AnalyticsError, ng as AnalyticsSink, Uf as CLAIM_RETENTION_BUCKETS, Y as CONNECTIONS_TABLE, Vl as CONNECTION_GRANTS_TABLE, sf as CircuitBreaker, af as CircuitOpen, uu as ConnectionNotConnected, gh as CostAccountant, lh as CostRegistry, gg as DEFAULT_ANALYTICS_MIRROR_TUNABLES, Fp as DEFAULT_APPROVAL_EXPIRY_MS, Hf as DEFAULT_CLAIM_BUCKET_MS, $n as DEFAULT_DELIVERY_CONCURRENCY, Mo as DEFAULT_HSTS, Xf as DEFAULT_MAX_IDLE_INTERVAL_MS, _s as DEFAULT_MAX_RPC_BODY_BYTES, er as DEFAULT_RAW_READ_TRACKING_LIMIT, cu as DEFAULT_REFRESH_SKEW_MS, li as DEFAULT_ROW_FILTER_RETRY, zf as DORMANCY_WAKEUP_TENANT, ja as DeleteBuilder, ki as Dispatcher, hl as EVENT_CLIENT_QUEUE_SIZE, gl as EVENT_LATEST_QUEUE_SIZE, Dc as EffectStore, ul as EventBus, th as ExpectationEvaluator, Gm as ExpectationRegistry, Fh as ExperimentEvaluator, Th as ExperimentRegistry, Su as GRANT_TTL_MS, vh as HOLDOUT_VARIANT, jo as HTML_CSP, qn as InMemoryDataStore, Pn as IndexedMatcher, Sl as InstanceMembership, Dn as LinearScanMatcher, p as MetricBoundaries, ag as NOOP_ANALYTICS_PROVIDER, gi as NO_ROW_FILTER, vo as NO_TRUSTED_PROXIES, wa as NoRowFound, El as OUTBOX_ATTEMPTS_TABLE, Nl as OUTBOX_ATTEMPT_LOG_CAP, J as OUTBOX_TABLE, Ta as OptimisticLockError, Vu as REBAC_ADMIN_SCOPE, lu as REFRESH_LEASE_MS, h_ as RUNTIME_NAME, zm as ReactionRateLimiter, eo as ReplicatedDataStore, ci as RowFilterUnavailable, Rf as SCHEDULE_SUBJECT, Ec as SYSTEM_SUBJECT, ka as SelectBuilder, La as ServerOnlyColumnWrite, md as SsrfBlockedError, Pa as StoreOperationFailed, Ln as SubscriptionRegistry, Fa as TableValidationFailed, Ia as TenantRowNotFound, Na as TenantScopeViolation, mm as TimelineRecorder, yp as UndoBoundaryError, xp as UndoStack, Bo as UnverifiedWebhookRoute, Aa as UpdateBuilder, xd as VOLTRO_AUDIT_MIXIN_ID, Cd as VOLTRO_EXPIRES_MIXIN_ID, Td as VOLTRO_LOCAL_FIRST_MIXIN_ID, Sd as VOLTRO_SOFT_DELETE_MIXIN_ID, wd as VOLTRO_TENANT_MIXIN_ID, Lo as WEBHOOK_VERIFICATION_PROPERTY, Pc as WorkflowDeferredResultError, Hc as WorkflowPayloadError, Fc as WorkflowRateLimitedError, Ic as WorkflowSingletonHeldError, qi as _connectionStreamCount, Ji as _resetConnectionCredentialsForTest, Ip as _voltroApprovalsTable, Ul as _voltroConnectionGrantsTable, Bl as _voltroConnectionsTable, Am as _voltroRebacTuplesTable, np as _voltroScheduleClaimsTable, tp as _voltroScheduleRunsTable, rp as _voltroTracesTable, ip as _voltroUndoLogTable, Lh as _voltroWakeupsTable, il as _voltroWorkflowEventDeliveriesTable, rl as _voltroWorkflowEventsTable, Ua as actingUserId, Tc as apiKeyManagementRoutes, Ui as applyConnectionCredential, Ba as applyDefined, Dm as applyDelta, Cp as applyInverse, wp as applyInverses, nf as applyPluginRefRules, bi as applyRowFilter, xi as applyRowFilterToDescriptor, Mg as applySoftDeleteScope, kg as applyTenantScope, Mp as applyUndoInvocation, Hp as approvalIntentKey, im as approvalNonce, om as approvalsPendingExecutor, Qu as assertCan, ql as assertConnectionCipherConfigured, Vo as assertWebhookRoutesDeclareVerification, Ch as assignVariant, xg as attachAnalyticsMirror, nh as attachExpectations, Ih as attachExperiments, _h as attachFinops, ks as awaitServerListening, Ml as backoffMs, Eu as beginOAuthConnect, zi as bindConnectionCredential, yl as bindEvent, gs as bindMutation, rs as bindStream, ns as bindSubscription, Zo as bindSubscriptionUntyped, Tm as buildIvmState, f_ as buildPreview, Nm as buildRebacInterceptor, Fm as buildRebacReadFilter, Ja as buildSubjectKey, Is as buildTracingLayer, Kd as cacheScopeLeaks, Zs as cachedBackend, Zu as can, Df as cancelWakeup, Vp as canonicalJson, Fn as canonicalize, Wf as claimGraceMs, go as classifyRequestOrigin, bm as classifyShape, em as clearApprovalGate, mu as clearConnectionRefreshFlights, qu as clearResourcePolicies, ee as clearRetentions, uf as clearSystemStoreHandle, rf as collectPluginRefRules, xf as compileCron, Du as completeOAuthConnect, cg as composeAnalytics, sg as composeAnalyticsSinks, Cu as connectionCallbackPath, Kl as connectionLabel, Xh as countRunningWorkflows, ni as counter, Cf as cronOccurrences, Vd as crud, or as currentRawReads, rd as currentRequestLoader, $a as currentRoutingContext, ta as currentTraceContext, Sc as dataStoreApiKeyStore, ic as dataStoreIdempotencyStore, lc as dataStoreKvStore, nm as decideApproval, sm as decideApprovalInvocation, da as decryptField, fs as defectMessage, Sg as defineAggregate, Gl as defineConnection, sh as defineCostBudget, Qc as defineEventTrigger, Pg as defineExecutor, Um as defineExpectation, bh as defineExperiment, kl as defineOutboxHandler, Im as defineReaction, Wu as defineResourcePolicy, bf as defineSchedule, $h as defineSubscriber, Di as deliveredRowCount, ia as deriveKey, d_ as diffChange, Ds as drainForShutdown, Ll as drainOutbox, Pf as dueWakeups, Xu as effectiveRelations, jd as emptySchemaRegistry, _a as enableGraphObservation, ua as encryptField, tm as enforceApproval, nd as enterRequestLoader, Gs as envSecretsBackend, hp as evaluateTouchedRules, Wr as eventMetricTagCacheSizeForTests, ou as exchangeAuthorizationCode, Qi as externalSpanFromTraceparent, Yn as extractDbCause, In as fingerprintFor, Ti as forbiddenColumnsForSubject, nu as forgetCredential, qd as formatCacheScopeLeaks, Gd as formatServerOnlyLeaks, Xi as formatTraceparent, Xd as formatUnresolvedSources, Sp as forwardChangeFromCdc, Cc as frameworkApiKeyStrategy, ri as gauge, mc as generateApiKeyToken, $p as getApprovalGate, Bi as getConnectionCredential, ju as getConnectionResolver, Ri as getCredentialExpiry, K as getFieldCipher, Gu as getResourcePolicy, mi as getRowFilter, df as getSystemStoreHandle, gm as getTimelineRecorder, cd as getTupleSource, Sm as groupKeyOf, Sh as hashUnitInterval, ii as histogramMetric, l_ as historyProvenance, Qs as httpSecretsBackend, Cn as inspectWorkflow, Qp as installApprovalGate, ud as installPolicyGuardResolver, Ki as interruptConnectionStreams, _p as invertChange, So as ipToBytes, Cg as isAggregateDefinition, ch as isCostBudgetDefinition, Ag as isEmptyTenantScopedRead, Wm as isExpectationDefinition, xh as isExperimentDefinition, Xn as isForeignKeyViolation, Uh as isIdleNow, ls as isInfraError, va as isObservingGraph, jg as isOrglessUserSubject, Zn as isQueryTimeout, bp as isSafeToApply, vf as isScheduleDefinition, ef as isSoftDelete, ao as isStateChangingMethod, Eo as isTrustedProxy, $c as isWorkflowEventTriggerDefinition, ir as isolateRawReadScope, wm as ivmValue, c_ as lastWriteProvenance, ru as listConnectionStates, Ku as listResourcePolicies, pe as listRetentionConflicts, me as listRetentions, jm as loadResourceTuples, Pm as loadSubjectTuples, mf as localityAwareSelector, r_ as makeActionRunner, Gf as makeAdvisoryLockCoordinator, aa as makeAesCipher, _c as makeApiKeyService, bd as makeApiKeyUsageBuffer, xc as makeApiKeyUsageFlusher, Qn as makeAppAccess, Xp as makeApprovalGate, uc as makeAsyncKv, pf as makeAuthMiddlewareLayers, vl as makeBufferGapDetector, Ws as makeBufferingSpanProcessor, Jl as makeConnectionRegistry, Nu as makeConnectionResolver, Pu as makeConnectionsFacade, ep as makeCoordinatedScheduler, fd as makeDataLoader, Bu as makeDisconnectConnectionExecutor, Ac as makeEffectStoreLayer, ml as makeEventPublisher, al as makeEventsFacade, oa as makeFieldCipher, Ma as makeFluentStore, Wh as makeIdleGate, Jc as makeLazyWorkflowFacade, Lu as makeListConnectionsExecutor, ms as makeMutationOutputCodec, Jg as makeMutationRunner, t_ as makeOneShotQueryRunner, co as makeOriginGuardExemption, jl as makeOutboxFacade, Kc as makePostCommitWorkflowFacade, Bh as makeProcessAdapter, e_ as makeQueryDescriptorProducer, Ng as makeQueryFinalizer, Qg as makeQueryReauthorizer, n_ as makeQuerySubscriber, Gh as makeRouterActivity, pp as makeRuleCapture, Ed as makeSchemaRegistry, Ru as makeStartConnectionExecutor, zu as makeSubmitTokenExecutor, up as makeUndoCapture, Kh as makeWakeGate, Yh as makeWakeProxyServer, Gc as makeWorkflowFacade, qc as makeWorkflowFacadeWithCallerContext, Yc as makeWorkflowHandlers, Xc as makeWorkflowLayers, Rc as makeWorkflowRunHandle, Of as markWakeupFired, Em as materializeIvm, vc as memoryApiKeyStore, gf as memoryReplicationAdapter, qa as memoryRywPositionStore, Hi as mergeCookieHeader, $f as nextDelay, Sf as nextFiring, Ff as nextWakeup, Hh as nodeProcessSupervisor, og as noopAnalytics, lg as noopAnalyticsSpec, dc as noopKv, yo as normalizeIp, uo as normalizeOrigin, Ca as observeStore, xa as observedGraph, Ss as onProcessShutdown, Ns as otelImportFailure, Ol as outboxAttemptsTable, Tl as outboxTable, Yp as parseApprovalInterval, Zi as parseTraceparent, Uc as payloadPropertyNames, rm as pendingApprovalsFor, Ga as powerOfTwoSelector, m_ as previewInRollback, Ql as projectConnectionState, Lf as pruneWakeups, fl as publishEvent, cr as rawSqlPreview, Zf as readPollCeilingMs, Ju as rebacPolicyGraph, Li as recordCredentialExpiry, Kr as recordEventDelivered, qr as recordEventDropped, Gr as recordEventPublished, Jr as recordEventSubscribers, ar as recordRawRead, Yr as recordSample, ei as recordScheduleRun, $r as recordSubscriptionActive, Zr as recordSubscriptionDelivery, ba as recordTableAccess, vm as recordTimelineEvent, ti as recordWorkflowRun, Ld as redactColumns, dm as redactRow, Ya as redisRywPositionStore, Np as redoUndoInvocation, su as refreshAccessToken, Gi as registerConnectionStream, ld as registerDefaultTupleSource, Te as registerRetention, Ef as registerWakeup, zp as rehydrateGuards, jf as releaseWakeup, Ka as replicaHealth, $o as resetComputedQueryCacheWarnings, Ur as resetEventMetricTagCacheForTests, Sa as resetObservedGraph, Js as resetSecretsBackend, Oo as resolveClientAddress, _u as resolveConnection, Mu as resolveConnectionForSubject, hf as resolveCurrentRegion, lr as resolveDependentTables, _o as resolveOriginGuardConfig, nr as resolveReactiveConfig, Tu as resolveRedirectUri, ko as resolveRequestIsHttps, Om as resolveRescan, _i as resolveRowFilterScope, vi as resolveRowFilterScopeFor, Ys as resolveSecret, Xs as resolveSecretSync, $s as resolveSecretsBackend, Fo as resolveSecurityHeaders, cm as resolveTimelineMode, Do as resolveTrustedProxies, wh as resultVariantNames, Oe as retentionTtlMsFromEnv, pm as reverseEventOverRows, ed as revokedIds, hi as rowFilterRegistered, tf as rulesFor, ff as runAsSystem, Zh as runOrchestratorTick, Fg as runProvidedEffect, Vm as runReaction, Qh as runSingleNodeOrchestrator, zh as runWakeLoop, qg as runWithDeadlockRetry, ya as runWithObservedProcedure, sr as runWithRawReadScope, id as runWithRequestLoader, Qa as runWithRoutingContext, ea as runWithTraceContext, wu as sanitizeRedirectTo, Qf as scheduleCoordinated, Hd as schemaPropertyNames, Bp as scopeStringsOf, Io as securityHeadersFor, Rp as serializeGuards, Si as serverOnlyColumnNames, Wd as serverOnlyLeaks, Au as setConnectionResolver, ca as setFieldCipher, pi as setRowFilter, qs as setSecretsBackend, lf as setSystemStoreHandle, _m as setTimelineRecorderForTest, sd as setTupleSource, En as settleHandlerBody, pc as sha256Hex, Es as shutdownGraceMsFromEnv, Bf as singleCoordinator, oi as snapshotMetrics, si as snapshotMetricsSync, yd as ssrfGuardHttpClientLayer, vd as ssrfReason, vs as startRpcServer, qf as startScheduler, eu as storeCredential, Ci as stripColumnsFromRows, Ei as stripForbiddenForWire, wi as stripServerOnlyForWire, Ou as sweepExpiredGrants, Ie as sweepRetention, vp as synthesizeInverse, pd as tracingHttpClientLayer, Zc as triggerWorkflow, Af as tryClaimWakeup, Vi as unbindConnection, ap as undoCaptureEnabled, Ap as undoLogExecutor, op as undoSurfaceEnabled, Yd as unresolvedSources, Og as useAggregate, ig as useAnalytics, uh as useCostBudget, Km as useExpectation, Eh as useExperiment, $u as visibleRows, Rh as wakeDueOnce, zo as webhookVerificationOf, zg as withRowFilter, $g as withScopedRequest, jc as workflowToRpc, lp as wrapCaptureStore, Nd as wrapStoreWithBootCodec, Wa as wrapStoreWithMixinBehaviour };