@voltro/runtime 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1443,7 +1443,9 @@ var Qt = (e) => {
1443
1443
  if (e.length !== t.length) return !1;
1444
1444
  for (let n = 0; n < e.length; n++) if (JSON.stringify(e[n]) !== JSON.stringify(t[n])) return !1;
1445
1445
  return !0;
1446
- }, zr = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0, Br = 1440 * 60 * 1e3, Vr = 3600 * 1e3, Hr = /* @__PURE__ */ new Map(), Ur = /* @__PURE__ */ new Set(), Wr = (e, t) => {
1446
+ }, zr = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0, Br = 1440 * 60 * 1e3, Vr = 3600 * 1e3, Hr = /* @__PURE__ */ new Map(), Ur = /* @__PURE__ */ new Set(), Wr = /* @__PURE__ */ new Map(), Gr = (e, t) => {
1447
+ t === void 0 ? Wr.delete(e) : Wr.set(e, t);
1448
+ }, Kr = (e) => Wr.get(e), qr = (e, t) => {
1447
1449
  Hr.set(e, {
1448
1450
  subject: t,
1449
1451
  touchedAt: Date.now()
@@ -1451,25 +1453,25 @@ var Qt = (e) => {
1451
1453
  for (let n of Ur) try {
1452
1454
  n(e, t);
1453
1455
  } catch {}
1454
- }, Gr = (e) => {
1456
+ }, Jr = (e) => {
1455
1457
  let t = Hr.get(e);
1456
1458
  if (t) return t.touchedAt = Date.now(), t.subject;
1457
- }, Kr = (e) => {
1458
- Hr.delete(e);
1459
- }, qr = (e) => (Ur.add(e), () => {
1459
+ }, Yr = (e) => {
1460
+ Wr.delete(e), Hr.delete(e);
1461
+ }, Xr = (e) => (Ur.add(e), () => {
1460
1462
  Ur.delete(e);
1461
- }), Jr = setInterval(() => {
1463
+ }), Zr = setInterval(() => {
1462
1464
  let e = Date.now() - Br;
1463
1465
  for (let [t, n] of Hr) n.touchedAt < e && Hr.delete(t);
1464
1466
  }, Vr);
1465
- typeof Jr == "object" && Jr && "unref" in Jr && Jr.unref();
1466
- var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1467
+ typeof Zr == "object" && Zr && "unref" in Zr && Zr.unref();
1468
+ var K = /* @__PURE__ */ new Map(), Qr = (e, t) => {
1467
1469
  let n = K.get(e);
1468
1470
  return n || (n = /* @__PURE__ */ new Set(), K.set(e, n)), n.add(t), () => {
1469
1471
  let n = K.get(e);
1470
1472
  n && (n.delete(t), n.size === 0 && K.delete(e));
1471
1473
  };
1472
- }, Xr = (e) => {
1474
+ }, $r = (e) => {
1473
1475
  let t = K.get(e);
1474
1476
  if (t) {
1475
1477
  for (let e of [...t]) try {
@@ -1477,15 +1479,15 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1477
1479
  } catch {}
1478
1480
  K.delete(e);
1479
1481
  }
1480
- }, Zr = (e) => K.get(e)?.size ?? 0, Qr = () => {
1482
+ }, ei = (e) => K.get(e)?.size ?? 0, ti = () => {
1481
1483
  Hr.clear(), K.clear();
1482
- }, $r = () => [...Hr.entries()].map(([e, t]) => ({
1484
+ }, ni = () => [...Hr.entries()].map(([e, t]) => ({
1483
1485
  clientId: e,
1484
1486
  subjectType: t.subject.type,
1485
1487
  tenantId: t.subject.tenantId
1486
- })), ei = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/, ti = (e) => `00-${e.traceId}-${e.spanId}-${e.sampled ? "01" : "00"}`, ni = (e) => {
1488
+ })), ri = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/, ii = (e) => `00-${e.traceId}-${e.spanId}-${e.sampled ? "01" : "00"}`, ai = (e) => {
1487
1489
  if (typeof e != "string") return null;
1488
- let t = ei.exec(e.trim().toLowerCase());
1490
+ let t = ri.exec(e.trim().toLowerCase());
1489
1491
  if (t === null) return null;
1490
1492
  let [, n, r, i] = t;
1491
1493
  return n === "0".repeat(32) || r === "0".repeat(16) ? null : {
@@ -1493,14 +1495,14 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1493
1495
  spanId: r,
1494
1496
  sampled: (parseInt(i, 16) & 1) == 1
1495
1497
  };
1496
- }, ri = (e) => {
1497
- let t = ni(e);
1498
+ }, oi = (e) => {
1499
+ let t = ai(e);
1498
1500
  if (t !== null) return x.externalSpan({
1499
1501
  traceId: t.traceId,
1500
1502
  spanId: t.spanId,
1501
1503
  sampled: t.sampled
1502
1504
  });
1503
- }, ii = new Lt(), ai = (e, t) => ii.run(e, t), oi = () => ii.getStore(), si = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : ze(e, "voltro:field-encryption:v1", 32), ci = (e) => {
1505
+ }, si = new Lt(), ci = (e, t) => si.run(e, t), li = () => si.getStore(), ui = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : ze(e, "voltro:field-encryption:v1", 32), di = (e) => {
1504
1506
  if (e.length !== 32) throw Error(`field cipher key must be 32 bytes, got ${e.length}`);
1505
1507
  return {
1506
1508
  encrypt: (t) => {
@@ -1514,27 +1516,27 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1514
1516
  return a.setAuthTag(Buffer.from(r, "base64")), Buffer.concat([a.update(Buffer.from(i, "base64")), a.final()]).toString("utf8");
1515
1517
  }
1516
1518
  };
1517
- }, li = (e) => ci(si(e)), ui, di = (e) => {
1518
- ui = e;
1519
- }, q = () => ui, fi = "no field cipher registered — enable `@voltro/plugin-governance` `governancePlugin({ fieldEncryption: { key } })` (or call setFieldCipher) so a key is available.", pi = (e) => {
1519
+ }, fi = (e) => di(ui(e)), pi, mi = (e) => {
1520
+ pi = e;
1521
+ }, q = () => pi, hi = "no field cipher registered — enable `@voltro/plugin-governance` `governancePlugin({ fieldEncryption: { key } })` (or call setFieldCipher) so a key is available.", gi = (e) => {
1520
1522
  let t = q();
1521
- if (!t) throw Error(`encryptField: ${fi}`);
1523
+ if (!t) throw Error(`encryptField: ${hi}`);
1522
1524
  return t.encrypt(e);
1523
- }, mi = (e) => {
1525
+ }, _i = (e) => {
1524
1526
  if (!ue(e)) return e;
1525
1527
  let t = q();
1526
- if (!t) throw Error(`decryptField: ${fi}`);
1528
+ if (!t) throw Error(`decryptField: ${hi}`);
1527
1529
  return t.decrypt(e);
1528
- }, hi = new Lt(), gi = /* @__PURE__ */ new Set(), _i = /* @__PURE__ */ new Set(), vi = "\0", yi = process.env.VOLTRO_OBSERVE_GRAPH === "1", bi = () => {
1529
- yi = !0;
1530
- }, xi = () => yi, Si = (e, t) => yi ? (_i.add(e.tag), hi.run(e, t)) : t(), Ci = (e, t) => {
1531
- if (!yi) return;
1532
- let n = hi.getStore();
1533
- n !== void 0 && (e.startsWith("_voltro_") || gi.add(`${n.tag}${vi}${n.kind}${vi}${e}${vi}${t}`));
1534
- }, wi = () => ({
1530
+ }, vi = new Lt(), yi = /* @__PURE__ */ new Set(), bi = /* @__PURE__ */ new Set(), xi = "\0", Si = process.env.VOLTRO_OBSERVE_GRAPH === "1", Ci = () => {
1531
+ Si = !0;
1532
+ }, wi = () => Si, Ti = (e, t) => Si ? (bi.add(e.tag), vi.run(e, t)) : t(), Ei = (e, t) => {
1533
+ if (!Si) return;
1534
+ let n = vi.getStore();
1535
+ n !== void 0 && (e.startsWith("_voltro_") || yi.add(`${n.tag}${xi}${n.kind}${xi}${e}${xi}${t}`));
1536
+ }, Di = () => ({
1535
1537
  version: 1,
1536
- edges: [...gi].map((e) => {
1537
- let [t, n, r, i] = e.split(vi);
1538
+ edges: [...yi].map((e) => {
1539
+ let [t, n, r, i] = e.split(xi);
1538
1540
  return {
1539
1541
  tag: t,
1540
1542
  kind: n,
@@ -1542,11 +1544,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1542
1544
  op: i
1543
1545
  };
1544
1546
  }).sort((e, t) => e.tag.localeCompare(t.tag) || e.table.localeCompare(t.table) || e.op.localeCompare(t.op)),
1545
- exercised: [..._i].sort()
1546
- }), Ti = () => {
1547
- gi.clear(), _i.clear();
1548
- }, Ei = (e) => {
1549
- if (!yi) return e;
1547
+ exercised: [...bi].sort()
1548
+ }), Oi = () => {
1549
+ yi.clear(), bi.clear();
1550
+ }, ki = (e) => {
1551
+ if (!Si) return e;
1550
1552
  let t = Object.create(Object.getPrototypeOf(e));
1551
1553
  for (let n of Reflect.ownKeys(e)) Object.defineProperty(t, n, Object.getOwnPropertyDescriptor(e, n));
1552
1554
  let n = (n, r, i) => {
@@ -1555,7 +1557,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1555
1557
  let o = a;
1556
1558
  t[n] = (...t) => {
1557
1559
  let n = r(t);
1558
- return n !== void 0 && Ci(n, i), o.apply(e, t);
1560
+ return n !== void 0 && Ei(n, i), o.apply(e, t);
1559
1561
  };
1560
1562
  }, r = (e) => typeof e[0] == "string" ? e[0] : void 0;
1561
1563
  n("query", (e) => {
@@ -1565,25 +1567,25 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1565
1567
  let i = e.transactional;
1566
1568
  if (typeof i == "function") {
1567
1569
  let n = i;
1568
- t.transactional = (t) => n.call(e, (e) => t(Ei(e)));
1570
+ t.transactional = (t) => n.call(e, (e) => t(ki(e)));
1569
1571
  }
1570
1572
  return t;
1571
- }, Di = class extends y.TaggedError()("NoRowFound", {
1573
+ }, Ai = class extends y.TaggedError()("NoRowFound", {
1572
1574
  table: y.String,
1573
1575
  found: y.Number
1574
1576
  }) {
1575
1577
  get message() {
1576
1578
  return this.found === 0 ? `expected exactly one row in '${this.table}', found none` : `expected exactly one row in '${this.table}', found more than one`;
1577
1579
  }
1578
- }, Oi = class extends y.TaggedError()("OptimisticLockError", {
1580
+ }, ji = class extends y.TaggedError()("OptimisticLockError", {
1579
1581
  table: y.String,
1580
1582
  expected: y.Number
1581
1583
  }) {
1582
1584
  get message() {
1583
1585
  return `optimistic lock failed on '${this.table}': expected version ${this.expected}`;
1584
1586
  }
1585
- }, ki = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), Ai = (e) => {
1586
- if (e.length === 1 && ki(e[0])) return e[0];
1587
+ }, Mi = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), Ni = (e) => {
1588
+ if (e.length === 1 && Mi(e[0])) return e[0];
1587
1589
  let t = e[0];
1588
1590
  if (e.length === 2) return O(t, e[1]);
1589
1591
  let n = e[1], r = e[2];
@@ -1601,11 +1603,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1601
1603
  case "startsWith": return je(t, r);
1602
1604
  default: return O(t, r);
1603
1605
  }
1604
- }, ji = (e) => {
1606
+ }, Pi = (e) => {
1605
1607
  let t = j(e);
1606
1608
  if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
1607
1609
  return xe(t);
1608
- }, Mi = class e {
1610
+ }, Fi = class e {
1609
1611
  backend;
1610
1612
  scope;
1611
1613
  table;
@@ -1619,7 +1621,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1619
1621
  return new e(this.backend, this.scope, this.table, t, this.skipTenant, this.skipSoftDelete);
1620
1622
  }
1621
1623
  where(...e) {
1622
- return this.clone(this.query.where(Ai(e)));
1624
+ return this.clone(this.query.where(Ni(e)));
1623
1625
  }
1624
1626
  orderBy(e, t = "asc") {
1625
1627
  return this.clone(this.query.orderBy(e, t));
@@ -1668,11 +1670,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1668
1670
  }
1669
1671
  async one() {
1670
1672
  let e = await this.backend.query(this.scopedQuery().limit(2).descriptor), t = e[0];
1671
- if (t === void 0) throw new Di({
1673
+ if (t === void 0) throw new Ai({
1672
1674
  table: this.table,
1673
1675
  found: 0
1674
1676
  });
1675
- if (e.length > 1) throw new Di({
1677
+ if (e.length > 1) throw new Ai({
1676
1678
  table: this.table,
1677
1679
  found: e.length
1678
1680
  });
@@ -1688,7 +1690,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1688
1690
  get descriptor() {
1689
1691
  return this.scopedQuery().descriptor;
1690
1692
  }
1691
- }, Ni = class {
1693
+ }, Ii = class {
1692
1694
  backend;
1693
1695
  scope;
1694
1696
  table;
@@ -1699,7 +1701,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1699
1701
  this.backend = e, this.scope = t, this.table = n;
1700
1702
  }
1701
1703
  where(...e) {
1702
- let t = Ai(e);
1704
+ let t = Ni(e);
1703
1705
  return this.predicate = this.predicate ? C(this.predicate, t) : t, this;
1704
1706
  }
1705
1707
  unscoped() {
@@ -1723,7 +1725,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1723
1725
  }
1724
1726
  async set(e) {
1725
1727
  let t = await this.backend.updateMany(this.table, e, { where: this.scopedWhere() });
1726
- if (this.expectedVersion !== void 0 && t === 0) throw new Oi({
1728
+ if (this.expectedVersion !== void 0 && t === 0) throw new ji({
1727
1729
  table: this.table,
1728
1730
  expected: this.expectedVersion
1729
1731
  });
@@ -1732,7 +1734,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1732
1734
  async restore() {
1733
1735
  return this.backend.updateMany(this.table, { deletedAt: null }, { where: this.scopedWhere() });
1734
1736
  }
1735
- }, Pi = class {
1737
+ }, Li = class {
1736
1738
  backend;
1737
1739
  scope;
1738
1740
  table;
@@ -1742,7 +1744,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1742
1744
  this.backend = e, this.scope = t, this.table = n;
1743
1745
  }
1744
1746
  where(...e) {
1745
- let t = Ai(e);
1747
+ let t = Ni(e);
1746
1748
  return this.predicate = this.predicate ? C(this.predicate, t) : t, this;
1747
1749
  }
1748
1750
  unscoped() {
@@ -1763,50 +1765,50 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1763
1765
  async hard() {
1764
1766
  return this.backend.deleteMany(this.table, { where: this.scopedWhere() });
1765
1767
  }
1766
- }, Fi = (e, t) => ({
1767
- select: (n) => new Mi(e, t, n, ji(n)),
1768
- updateWhere: (n) => new Ni(e, t, n),
1769
- deleteWhere: (n) => new Pi(e, t, n)
1770
- }), Ii = class extends y.TaggedError()("TenantScopeViolation", {
1768
+ }, Ri = (e, t) => ({
1769
+ select: (n) => new Fi(e, t, n, Pi(n)),
1770
+ updateWhere: (n) => new Ii(e, t, n),
1771
+ deleteWhere: (n) => new Li(e, t, n)
1772
+ }), zi = class extends y.TaggedError()("TenantScopeViolation", {
1771
1773
  table: y.String,
1772
1774
  reason: y.String
1773
- }) {}, Li = class extends y.TaggedError()("StoreOperationFailed", {
1775
+ }) {}, Bi = class extends y.TaggedError()("StoreOperationFailed", {
1774
1776
  operation: y.String,
1775
1777
  table: y.String,
1776
1778
  cause: y.String
1777
- }) {}, Ri = class extends y.TaggedError()("TableValidationFailed", {
1779
+ }) {}, Vi = class extends y.TaggedError()("TableValidationFailed", {
1778
1780
  table: y.String,
1779
1781
  summary: y.String,
1780
1782
  issues: y.Array(y.Struct({
1781
1783
  path: y.String,
1782
1784
  message: y.String
1783
1785
  }))
1784
- }) {}, zi = "id", Bi = (e) => "descriptor" in e ? e.descriptor : e, Vi = (e, t) => {
1786
+ }) {}, Hi = "id", Ui = (e) => "descriptor" in e ? e.descriptor : e, Wi = (e, t) => {
1785
1787
  let n = {};
1786
1788
  for (let r of t) e[r] !== void 0 && (n[r] = e[r]);
1787
1789
  return n;
1788
- }, Hi = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", Ui = (e) => {
1789
- throw new Ii({
1790
+ }, Gi = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", Ki = (e) => {
1791
+ throw new zi({
1790
1792
  table: e,
1791
- reason: Hi
1793
+ reason: Gi
1792
1794
  });
1793
- }, Wi = (e) => {
1795
+ }, qi = (e) => {
1794
1796
  if (e.type !== "apiKey") return e.id;
1795
1797
  let t = e.metadata?.userId;
1796
1798
  return typeof t == "string" && t !== "" ? t : e.id;
1797
- }, Gi = (e, t) => {
1798
- let n = Ei(e), r = Wi(t.subject), i = t.subject.tenantId, a = t.rowFilter ?? Or, o = (e, n) => {
1799
+ }, Ji = (e, t) => {
1800
+ let n = ki(e), r = qi(t.subject), i = t.subject.tenantId, a = t.rowFilter ?? Or, o = (e, n) => {
1799
1801
  let a = { ...n }, o = t.schemaRegistry, s = o.idScheme(e);
1800
- if (s !== void 0 && a[zi] == null) if (s.kind === "numeric") delete a[zi];
1802
+ if (s !== void 0 && a[Hi] == null) if (s.kind === "numeric") delete a[Hi];
1801
1803
  else {
1802
1804
  let t = A(s, e);
1803
- t !== null && (a[zi] = t);
1805
+ t !== null && (a[Hi] = t);
1804
1806
  }
1805
1807
  if (o.hasAudit(e)) {
1806
1808
  let e = /* @__PURE__ */ new Date();
1807
1809
  "createdAt" in a || (a.createdAt = e), "updatedAt" in a || (a.updatedAt = e), r !== null && ("createdBy" in a || (a.createdBy = r), "updatedBy" in a || (a.updatedBy = r));
1808
1810
  }
1809
- o.hasTenant(e) && ("tenantId" in a || (i === null && Ui(e), a.tenantId = i));
1811
+ o.hasTenant(e) && ("tenantId" in a || (i === null && Ki(e), a.tenantId = i));
1810
1812
  let c = o.defaultFactories(e);
1811
1813
  if (c.size > 0) for (let [e, t] of c) (!(e in a) || a[e] === void 0) && (a[e] = t());
1812
1814
  let l = o.computedFields(e);
@@ -1826,7 +1828,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1826
1828
  let r = xn(t);
1827
1829
  if (Sn(r)) {
1828
1830
  let t = n.tenantId, i = `${r.dbConstraint ?? ""} ${r.dbColumn ?? ""} ${r.dbMessage ?? ""} ${r.dbCauseChain ?? ""}`.toLowerCase();
1829
- if (i.includes("tenantid") || /\btenants\b/.test(i) || t != null && i.includes(String(t).toLowerCase())) throw new Ii({
1831
+ if (i.includes("tenantid") || /\btenants\b/.test(i) || t != null && i.includes(String(t).toLowerCase())) throw new zi({
1830
1832
  table: e,
1831
1833
  reason: t == null ? "write references a tenant that does not exist" : `tenant '${String(t)}' does not exist — seed the row in \`tenants\`, or fix how the request resolved this tenant (subject.tenantId / the x-tenant header / the dev TENANT fallback)`
1832
1834
  });
@@ -1851,7 +1853,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1851
1853
  path: e.path.length === 0 ? "<root>" : e.path.join("."),
1852
1854
  message: e.message
1853
1855
  })), o = a[0];
1854
- throw new Ri({
1856
+ throw new Vi({
1855
1857
  table: e,
1856
1858
  summary: o === void 0 ? "patch validation failed" : `${o.path}: ${o.message}`,
1857
1859
  issues: a
@@ -1861,7 +1863,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1861
1863
  return r !== null && (e.deletedBy = r), e;
1862
1864
  }, f = (e, t, n) => {
1863
1865
  let r = ge(n, t);
1864
- if (r.length !== 0) throw new Ri({
1866
+ if (r.length !== 0) throw new Vi({
1865
1867
  table: e,
1866
1868
  summary: `upsert conflictColumns [${n.map((e) => `'${e}'`).join(", ")}] but the payload is missing ${r.map((e) => `'${e}'`).join(", ")}`,
1867
1869
  issues: r.map((e) => ({
@@ -1873,7 +1875,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1873
1875
  let r = j(e);
1874
1876
  if (r !== void 0) {
1875
1877
  let t = _e(r, n);
1876
- if (t.length > 0) throw new Ri({
1878
+ if (t.length > 0) throw new Vi({
1877
1879
  table: e,
1878
1880
  summary: `missing required column${t.length > 1 ? "s" : ""} ${t.map((e) => `'${e}'`).join(", ")} — NOT NULL with no default and not auto-stamped`,
1879
1881
  issues: t.map((e) => ({
@@ -1890,7 +1892,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1890
1892
  path: e.path.length === 0 ? "<root>" : e.path.join("."),
1891
1893
  message: e.message
1892
1894
  })), s = o[0];
1893
- throw new Ri({
1895
+ throw new Vi({
1894
1896
  table: e,
1895
1897
  summary: s === void 0 ? "row validation failed" : `${s.path}: ${s.message}`,
1896
1898
  issues: o
@@ -1939,7 +1941,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1939
1941
  let t = (await n.query({
1940
1942
  table: e,
1941
1943
  predicate: {
1942
- column: zi,
1944
+ column: Hi,
1943
1945
  op: "eq",
1944
1946
  value: r
1945
1947
  },
@@ -1960,7 +1962,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1960
1962
  }), i = await n.query({
1961
1963
  table: e,
1962
1964
  predicate: {
1963
- column: zi,
1965
+ column: Hi,
1964
1966
  op: "eq",
1965
1967
  value: r
1966
1968
  },
@@ -1989,7 +1991,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
1989
1991
  }), se = async (e, t) => te(e, {
1990
1992
  ...t,
1991
1993
  where: k(e, t.where)
1992
- }), ce = Fi({
1994
+ }), ce = Ri({
1993
1995
  query: w,
1994
1996
  updateMany: D,
1995
1997
  deleteMany: te,
@@ -2018,26 +2020,26 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2018
2020
  return {
2019
2021
  query: T,
2020
2022
  one: (async (e) => {
2021
- let t = Bi(e), n = await T({
2023
+ let t = Ui(e), n = await T({
2022
2024
  ...t,
2023
2025
  take: 2
2024
2026
  }), r = n[0];
2025
- if (r === void 0) throw new Di({
2027
+ if (r === void 0) throw new Ai({
2026
2028
  table: t.table,
2027
2029
  found: 0
2028
2030
  });
2029
- if (n.length > 1) throw new Di({
2031
+ if (n.length > 1) throw new Ai({
2030
2032
  table: t.table,
2031
2033
  found: n.length
2032
2034
  });
2033
2035
  return r;
2034
2036
  }),
2035
2037
  first: (async (e) => (await T({
2036
- ...Bi(e),
2038
+ ...Ui(e),
2037
2039
  take: 1
2038
2040
  }))[0] ?? null),
2039
2041
  maybeOne: (async (e) => (await T({
2040
- ...Bi(e),
2042
+ ...Ui(e),
2041
2043
  take: 1
2042
2044
  }))[0] ?? null),
2043
2045
  insert: async (e, t) => {
@@ -2118,7 +2120,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2118
2120
  select: ce.select,
2119
2121
  update: M,
2120
2122
  delete: N,
2121
- applyDefined: Vi,
2123
+ applyDefined: Wi,
2122
2124
  hardDelete: async (e, t) => n.delete(e, t),
2123
2125
  updateMany: ae,
2124
2126
  deleteMany: se,
@@ -2134,13 +2136,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2134
2136
  let a = await c(e, i, () => n.insertIgnore(e, h(e, p(e, i)), r));
2135
2137
  return x(e, [a])[0];
2136
2138
  },
2137
- transactional: (e) => n.transactional(async (n) => e(Gi(n, t))),
2139
+ transactional: (e) => n.transactional(async (n) => e(Ji(n, t))),
2138
2140
  ...n.raw ? { raw: n.raw.bind(n) } : {},
2139
2141
  onChange: (e) => n.onChange(e),
2140
2142
  injectExternalChange: (e) => n.injectExternalChange(e),
2141
2143
  ...n.changeScope === void 0 ? {} : { changeScope: n.changeScope }
2142
2144
  };
2143
- }, Ki = (e = {}) => {
2145
+ }, Yi = (e = {}) => {
2144
2146
  let t = e.random ?? Math.random, n = /* @__PURE__ */ new Map(), r = (e) => n.get(e) ?? 0;
2145
2147
  return {
2146
2148
  pick(e) {
@@ -2165,7 +2167,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2165
2167
  }));
2166
2168
  }
2167
2169
  };
2168
- }, qi = (e = {}) => {
2170
+ }, Xi = (e = {}) => {
2169
2171
  let t = e.thresholdFailures ?? 3, n = e.windowMs ?? 1e4, r = e.blackoutMs ?? 6e4, i = e.now ?? Date.now, a = /* @__PURE__ */ new Map(), o = (e) => {
2170
2172
  let t = a.get(e);
2171
2173
  return t === void 0 && (t = {
@@ -2199,7 +2201,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2199
2201
  }));
2200
2202
  }
2201
2203
  };
2202
- }, Ji = (e = {}) => {
2204
+ }, Zi = (e = {}) => {
2203
2205
  let t = e.now ?? Date.now, n = /* @__PURE__ */ new Map();
2204
2206
  return {
2205
2207
  get(e) {
@@ -2222,7 +2224,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2222
2224
  return n.size;
2223
2225
  }
2224
2226
  };
2225
- }, Yi = (e, t) => e === null ? t === void 0 ? "anon:bg" : `anon:${t}` : `subject:${e}`, Xi = (e) => {
2227
+ }, Qi = (e, t) => e === null ? t === void 0 ? "anon:bg" : `anon:${t}` : `subject:${e}`, $i = (e) => {
2226
2228
  let t = e.now ?? Date.now, n = e.keyPrefix ?? "voltro:ryw", r = e.channel ?? `${n}:bus`, i = e.onError ?? ((e, t) => {
2227
2229
  process.stderr.write(`[voltro:ryw] redis ${t} failed: ${String(e)}\n`);
2228
2230
  }), a = `${process.pid ?? 0}:${Math.random() * 1e9 | 0}:${t()}`, o = /* @__PURE__ */ new Map(), s = (e) => {
@@ -2281,7 +2283,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2281
2283
  return o.size;
2282
2284
  }
2283
2285
  };
2284
- }, Zi = z({ scope: "voltro:replication" }), Qi = new Lt(), $i = (e, t) => Qi.run(e, t), ea = () => Qi.getStore(), ta = class {
2286
+ }, ea = z({ scope: "voltro:replication" }), ta = new Lt(), na = (e, t) => ta.run(e, t), ra = () => ta.getStore(), ia = class {
2285
2287
  primary;
2286
2288
  replicas;
2287
2289
  adapter;
@@ -2294,10 +2296,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2294
2296
  recordRouting;
2295
2297
  now;
2296
2298
  constructor(e) {
2297
- this.primary = e.primary, this.replicas = e.replicas, this.adapter = e.replicationAdapter, this.policy = e.rywPolicy ?? "fallback", this.rywTtlMs = e.rywTtlMs ?? 3e4, this.rywMaxWaitMs = e.rywMaxWaitMs ?? 500, this.now = e.now ?? Date.now, this.rywStore = e.rywStore ?? Ji({ now: this.now }), this.selector = e.replicaSelector ?? Ki(), this.health = e.replicaHealth ?? qi({ now: this.now }), e.recordRouting !== void 0 && (this.recordRouting = e.recordRouting);
2299
+ this.primary = e.primary, this.replicas = e.replicas, this.adapter = e.replicationAdapter, this.policy = e.rywPolicy ?? "fallback", this.rywTtlMs = e.rywTtlMs ?? 3e4, this.rywMaxWaitMs = e.rywMaxWaitMs ?? 500, this.now = e.now ?? Date.now, this.rywStore = e.rywStore ?? Zi({ now: this.now }), this.selector = e.replicaSelector ?? Yi(), this.health = e.replicaHealth ?? Xi({ now: this.now }), e.recordRouting !== void 0 && (this.recordRouting = e.recordRouting);
2298
2300
  }
2299
2301
  async query(e) {
2300
- let t = Qi.getStore(), n = t?.subjectKey ?? "anon:bg";
2302
+ let t = ta.getStore(), n = t?.subjectKey ?? "anon:bg";
2301
2303
  if (t?.forcePrimary === !0) return this.emitRouting({
2302
2304
  target: "primary",
2303
2305
  replicaIndex: null,
@@ -2361,7 +2363,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2361
2363
  waitMs: 0
2362
2364
  }), r;
2363
2365
  } catch (r) {
2364
- return this.health.reportFailure(i, String(r)), Zi.warn("replica query failed; falling back to primary", {
2366
+ return this.health.reportFailure(i, String(r)), ea.warn("replica query failed; falling back to primary", {
2365
2367
  idx: a,
2366
2368
  err: r
2367
2369
  }), this.emitRouting({
@@ -2430,7 +2432,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2430
2432
  fallbackReason: "wait-timeout"
2431
2433
  }), this.primary.query(e);
2432
2434
  }
2433
- await na(10);
2435
+ await aa(10);
2434
2436
  }
2435
2437
  }
2436
2438
  async insert(e, t) {
@@ -2470,8 +2472,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2470
2472
  return await this.stampPostWrite(), r;
2471
2473
  }
2472
2474
  async transactional(e) {
2473
- let t = await $i({
2474
- subjectKey: Qi.getStore()?.subjectKey ?? "anon:bg",
2475
+ let t = await na({
2476
+ subjectKey: ta.getStore()?.subjectKey ?? "anon:bg",
2475
2477
  forcePrimary: !0
2476
2478
  }, () => this.primary.transactional(e));
2477
2479
  return await this.stampPostWrite(), t;
@@ -2487,7 +2489,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2487
2489
  }
2488
2490
  async stampPostWrite() {
2489
2491
  if (this.replicas.length === 0) return;
2490
- let e = Qi.getStore()?.subjectKey ?? "anon:bg";
2492
+ let e = ta.getStore()?.subjectKey ?? "anon:bg";
2491
2493
  try {
2492
2494
  let t = await this.adapter.capturePrimaryPosition(this.primary);
2493
2495
  this.rywStore.set(e, {
@@ -2495,17 +2497,17 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2495
2497
  expiresAt: this.now() + this.rywTtlMs
2496
2498
  });
2497
2499
  } catch (e) {
2498
- Zi.warn("failed to capture primary position; RYW skipped", { err: e });
2500
+ ea.warn("failed to capture primary position; RYW skipped", { err: e });
2499
2501
  }
2500
2502
  }
2501
2503
  emitRouting(e) {
2502
2504
  this.recordRouting?.(e);
2503
2505
  }
2504
- }, na = (e) => new Promise((t) => setTimeout(t, e)), ra = (e, t, n) => {
2506
+ }, aa = (e) => new Promise((t) => setTimeout(t, e)), oa = (e, t, n) => {
2505
2507
  if (t === void 0) return e;
2506
2508
  let r = t * 1e3 - Date.now();
2507
2509
  return r <= 0 ? n : b.interruptWhen(e, o.sleep(a.millis(r)));
2508
- }, ia = (e) => {
2510
+ }, sa = (e) => {
2509
2511
  let t = e.indexOf(".");
2510
2512
  if (t <= 0) return;
2511
2513
  let n = e.slice(0, t), r = e.slice(t + 1);
@@ -2519,25 +2521,25 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2519
2521
  kind: n
2520
2522
  };
2521
2523
  }
2522
- }, aa = (e, t) => {
2523
- let n = ia(e);
2524
- return n === void 0 ? t() : Si(n, t);
2525
- }, oa = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, sa = (e, t) => o.async((n) => {
2524
+ }, ca = (e, t) => {
2525
+ let n = sa(e);
2526
+ return n === void 0 ? t() : Ti(n, t);
2527
+ }, la = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, ua = (e, t) => o.async((n) => {
2526
2528
  let r = Ee(t, () => o.runFork(e));
2527
2529
  return r.addObserver((e) => {
2528
2530
  n(e);
2529
2531
  }), o.asVoid(l.interrupt(r));
2530
- }), ca = (e, t, n) => ({
2532
+ }), da = (e, t, n) => ({
2531
2533
  subject: e,
2532
2534
  traceId: t?.traceId ?? Re(),
2533
2535
  ...t?.spanId === void 0 ? {} : { spanId: t.spanId },
2534
2536
  ...n === void 0 ? {} : { clientId: n }
2535
- }), la = o.currentSpan.pipe(o.catchAll(() => o.succeed(void 0))), ua = (e) => ({
2537
+ }), fa = o.currentSpan.pipe(o.catchAll(() => o.succeed(void 0))), pa = (e) => ({
2536
2538
  traceId: e.traceId,
2537
2539
  ...e.spanId === void 0 ? {} : { spanId: e.spanId }
2538
- }), da = (e, t, n) => {
2540
+ }), ma = (e, t, n) => {
2539
2541
  e !== void 0 && (e.attribute("rpc.tag", t), e.attribute("subject.type", n.type), n.tenantId !== void 0 && n.tenantId !== null && e.attribute("tenant.id", n.tenantId));
2540
- }, fa = (e) => {
2542
+ }, ha = (e) => {
2541
2543
  if (Dr() !== void 0) return async () => {
2542
2544
  let t = await o.runPromise(o.either(kr(e, (e) => {
2543
2545
  console.error("[voltro] row filter failed to load — subscription", e);
@@ -2545,13 +2547,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2545
2547
  if (t._tag === "Left") throw t.left;
2546
2548
  return t.right;
2547
2549
  };
2548
- }, pa = (e, t, n, r, i, a, s, c) => b.asyncScoped((l) => o.gen(function* () {
2550
+ }, ga = (e, t, n, r, i, a, s, c) => b.asyncScoped((l) => o.gen(function* () {
2549
2551
  let u = yield* o.tryPromise(() => t.subscribe(e, (e) => {
2550
2552
  l.single(e);
2551
2553
  }, n, r, i, a, s, c)).pipe(o.matchCause({
2552
- onFailure: (e) => (Ca(`subscription.${i}`, n.traceId, e), {
2554
+ onFailure: (e) => (Ea(`subscription.${i}`, n.traceId, e), {
2553
2555
  ok: !1,
2554
- error: Da(e)
2556
+ error: Aa(e)
2555
2557
  }),
2556
2558
  onSuccess: (e) => ({
2557
2559
  ok: !0,
@@ -2567,25 +2569,25 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2567
2569
  }
2568
2570
  let d = u.unsubscribe;
2569
2571
  if (yield* o.addFinalizer(() => o.sync(() => d())), n.clientId !== void 0) {
2570
- let e = Yr(n.clientId, () => {
2572
+ let e = Qr(n.clientId, () => {
2571
2573
  l.end();
2572
2574
  });
2573
2575
  yield* o.addFinalizer(() => o.sync(() => e()));
2574
2576
  }
2575
- })), ma = /* @__PURE__ */ new Set(), ha = () => {
2576
- ma.clear();
2577
- }, ga = (e) => {
2578
- ma.has(e) || (ma.add(e), process.stderr.write(`[voltro] ${e}: \`cache:\` is declared but NOT applied — this query's handler returns a computed value, and the snapshot cache only wraps a store read. Every subscriber re-runs the handler. Either return a query descriptor (so the read can be cached), or drop \`cache:\` so the declaration matches what happens.\n`));
2579
- }, _a = (e, t, n, r) => b.asyncScoped((i) => o.gen(function* () {
2577
+ })), _a = /* @__PURE__ */ new Set(), va = () => {
2578
+ _a.clear();
2579
+ }, ya = (e) => {
2580
+ _a.has(e) || (_a.add(e), process.stderr.write(`[voltro] ${e}: \`cache:\` is declared but NOT applied — this query's handler returns a computed value, and the snapshot cache only wraps a store read. Every subscriber re-runs the handler. Either return a query descriptor (so the read can be cached), or drop \`cache:\` so the declaration matches what happens.\n`));
2581
+ }, ba = (e, t, n, r) => b.asyncScoped((i) => o.gen(function* () {
2580
2582
  let a = yield* o.tryPromise(() => t.subscribeComputed(e, (e) => {
2581
2583
  i.single(e._tag === "snapshot" ? {
2582
2584
  ...e,
2583
2585
  computed: !0
2584
2586
  } : e);
2585
2587
  }, n, r)).pipe(o.matchCause({
2586
- onFailure: (e) => (Ca(`subscription.${r}`, n.traceId, e), {
2588
+ onFailure: (e) => (Ea(`subscription.${r}`, n.traceId, e), {
2587
2589
  ok: !1,
2588
- error: Da(e)
2590
+ error: Aa(e)
2589
2591
  }),
2590
2592
  onSuccess: (e) => ({
2591
2593
  ok: !0,
@@ -2601,21 +2603,21 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2601
2603
  }
2602
2604
  let s = a.unsubscribe;
2603
2605
  if (yield* o.addFinalizer(() => o.sync(() => s())), n.clientId !== void 0) {
2604
- let e = Yr(n.clientId, () => {
2606
+ let e = Qr(n.clientId, () => {
2605
2607
  i.end();
2606
2608
  });
2607
2609
  yield* o.addFinalizer(() => o.sync(() => e()));
2608
2610
  }
2609
- })), va = (e, t, n = "rpc.subscription", r, i, a, s) => b.unwrap(o.gen(function* () {
2610
- let c = yield* et, l = yield* Ge, u = yield* la;
2611
- da(u, n, c);
2612
- let d = ca(c, u, l.clientId), f = Yi(c.id, l.clientId), p = $i({ subjectKey: f }, () => ai({
2611
+ })), xa = (e, t, n = "rpc.subscription", r, i, a, s) => b.unwrap(o.gen(function* () {
2612
+ let c = yield* et, l = yield* Ge, u = yield* fa;
2613
+ ma(u, n, c);
2614
+ let d = da(c, u, l.clientId), f = Qi(c.id, l.clientId), p = na({ subjectKey: f }, () => ci({
2613
2615
  traceId: d.traceId,
2614
2616
  ...d.spanId === void 0 ? {} : { spanId: d.spanId }
2615
- }, () => aa(n, () => e(d)))), m = o.isEffect(p) ? yield* p.pipe(o.matchCause({
2616
- onFailure: (e) => (Ca(`subscription.${n}`, d.traceId, e), {
2617
+ }, () => ca(n, () => e(d)))), m = o.isEffect(p) ? yield* p.pipe(o.matchCause({
2618
+ onFailure: (e) => (Ea(`subscription.${n}`, d.traceId, e), {
2617
2619
  ok: !1,
2618
- error: Da(e)
2620
+ error: Aa(e)
2619
2621
  }),
2620
2622
  onSuccess: (e) => ({
2621
2623
  ok: !0,
@@ -2630,44 +2632,44 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2630
2632
  error: m.error
2631
2633
  });
2632
2634
  let h = m.value;
2633
- if (zr(h)) return i !== void 0 && ga(n), _a(h, t, d, n);
2634
- let g = h, _ = r?.(g), v = i === void 0 ? void 0 : oa(i.scope, i.baseKey, f, c);
2635
- return ra(pa(g, t, d, _, n, i === void 0 || v === void 0 ? void 0 : {
2635
+ if (zr(h)) return i !== void 0 && ya(n), ba(h, t, d, n);
2636
+ let g = h, _ = r?.(g), v = i === void 0 ? void 0 : la(i.scope, i.baseKey, f, c);
2637
+ return oa(ga(g, t, d, _, n, i === void 0 || v === void 0 ? void 0 : {
2636
2638
  key: v,
2637
2639
  ttlMs: i.ttlMs,
2638
2640
  swrMs: i.swrMs
2639
- }, a?.(c), s?.(c) ?? fa(c)), l.credentialExpiresAt, b.empty);
2640
- }).pipe(o.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), ya = (e, t = "rpc.stream", n, r) => b.unwrap(o.gen(function* () {
2641
- let a = yield* et, s = yield* Ge, c = yield* la;
2642
- da(c, t, a);
2643
- let l = ca(a, c, s.clientId), u = aa(t, () => e(l)), d = o.isEffect(u) ? yield* u.pipe(o.orDie) : u, f = n === void 0 || n.length === 0 ? void 0 : () => ot(a, n, r), p = ra(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);
2641
+ }, a?.(c), s?.(c) ?? ha(c)), l.credentialExpiresAt, b.empty);
2642
+ }).pipe(o.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), Sa = (e, t = "rpc.stream", n, r) => b.unwrap(o.gen(function* () {
2643
+ let a = yield* et, s = yield* Ge, c = yield* fa;
2644
+ ma(c, t, a);
2645
+ let l = da(a, c, s.clientId), u = ca(t, () => e(l)), d = o.isEffect(u) ? yield* u.pipe(o.orDie) : u, f = n === void 0 || n.length === 0 ? void 0 : () => ot(a, n, r), p = oa(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);
2644
2646
  if (l.clientId === void 0) return p;
2645
2647
  let m = l.clientId;
2646
2648
  return b.unwrapScoped(o.gen(function* () {
2647
- let e = yield* i.make(), t = Yr(m, () => {
2649
+ let e = yield* i.make(), t = Qr(m, () => {
2648
2650
  i.unsafeDone(e, o.void);
2649
2651
  });
2650
2652
  return yield* o.addFinalizer(() => o.sync(() => t())), p.pipe(b.interruptWhen(i.await(e)));
2651
2653
  }));
2652
- }).pipe(o.withSpan(t, { attributes: { "framework.kind": "stream" } }))), ba = z({ scope: "voltro:rpc" }), xa = z({ scope: "voltro:http" }), Sa = z({ scope: "voltro:shutdown" }), Ca = (t, n, r) => {
2654
+ }).pipe(o.withSpan(t, { attributes: { "framework.kind": "stream" } }))), Ca = z({ scope: "voltro:rpc" }), wa = z({ scope: "voltro:http" }), Ta = z({ scope: "voltro:shutdown" }), Ea = (t, n, r) => {
2653
2655
  if (e.isInterruptedOnly(r)) return;
2654
2656
  let i = e.squash(r), a = i?._tag, o = i instanceof Error ? i.message : i?.message ?? String(i), s = e.dieOption(r)._tag === "Some", c = xn(i), l = {
2655
2657
  traceId: n,
2656
2658
  ...a === void 0 ? {} : { errorTag: a },
2657
2659
  ...c
2658
2660
  }, u = o === "Failed to execute statement" && typeof c.dbMessage == "string" ? c.dbMessage : o;
2659
- s ? ba.error(`${t} failed: ${u}`, l) : ba.warn(`${t} failed: ${u}`, l);
2660
- }, wa = /* @__PURE__ */ new Set([
2661
+ s ? Ca.error(`${t} failed: ${u}`, l) : Ca.warn(`${t} failed: ${u}`, l);
2662
+ }, Da = /* @__PURE__ */ new Set([
2661
2663
  "SqlError",
2662
2664
  "ResultLengthMismatch",
2663
2665
  "FieldDecryptionError"
2664
- ]), Ta = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && wa.has(e._tag), Ea = (e) => ({
2666
+ ]), Oa = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && Da.has(e._tag), ka = (e) => ({
2665
2667
  _tag: "InternalError",
2666
2668
  message: "internal server error",
2667
2669
  traceId: e
2668
- }), Da = (t) => {
2670
+ }), Aa = (t) => {
2669
2671
  let n = e.squash(t);
2670
- if (n && typeof n == "object" && n._tag === "UnknownException" && (n = n.error ?? n.cause ?? n), Ta(n)) return {
2672
+ if (n && typeof n == "object" && n._tag === "UnknownException" && (n = n.error ?? n.cause ?? n), Oa(n)) return {
2671
2673
  _tag: "InternalError",
2672
2674
  message: "internal server error"
2673
2675
  };
@@ -2679,7 +2681,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2679
2681
  ...typeof a == "string" ? { _tag: a } : {},
2680
2682
  message: typeof o == "string" ? o : String(n)
2681
2683
  };
2682
- }, Oa = (e) => {
2684
+ }, ja = (e) => {
2683
2685
  if (e === void 0) return;
2684
2686
  let t = y.encodeUnknownSync(e), n = y.decodeUnknownSync(e);
2685
2687
  return {
@@ -2698,40 +2700,40 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2698
2700
  }
2699
2701
  }
2700
2702
  };
2701
- }, ka = (e) => ({
2703
+ }, Ma = (e) => ({
2702
2704
  _tag: "MutationInFlight",
2703
2705
  message: "a request with this idempotency key is already in flight",
2704
2706
  traceId: e
2705
- }), Aa = (e, t, n = "rpc.mutation", r, i) => o.gen(function* () {
2706
- let a = yield* et, s = yield* Ge, c = yield* la;
2707
- da(c, n, a);
2708
- let l = ca(a, c, s.clientId), u = i && s.idempotencyKey ? {
2707
+ }), Na = (e, t, n = "rpc.mutation", r, i) => o.gen(function* () {
2708
+ let a = yield* et, s = yield* Ge, c = yield* fa;
2709
+ ma(c, n, a);
2710
+ let l = da(a, c, s.clientId), u = i && s.idempotencyKey ? {
2709
2711
  store: i.store,
2710
2712
  ttlMs: i.ttlMs,
2711
2713
  key: s.idempotencyKey,
2712
- scope: bt(a.tenantId, Wi(a), n)
2714
+ scope: bt(a.tenantId, qi(a), n)
2713
2715
  } : null;
2714
2716
  if (u) {
2715
2717
  let e = yield* o.promise(() => at(u.store, u.scope, u.key, u.ttlMs, Date.now()));
2716
2718
  if (e.kind === "replay") return r ? r.decode(e.response.body) : e.response.body;
2717
- if (e.kind === "conflict") return yield* o.die(ka(l.traceId));
2719
+ if (e.kind === "conflict") return yield* o.die(Ma(l.traceId));
2718
2720
  }
2719
- let d = Yi(a.id, s.clientId), f = {
2721
+ let d = Qi(a.id, s.clientId), f = {
2720
2722
  traceId: l.traceId,
2721
- subjectId: Wi(a),
2723
+ subjectId: qi(a),
2722
2724
  procedure: n
2723
- }, p = $i({ subjectKey: d }, () => ai({
2725
+ }, p = na({ subjectKey: d }, () => ci({
2724
2726
  traceId: l.traceId,
2725
2727
  ...l.spanId === void 0 ? {} : { spanId: l.spanId }
2726
- }, () => Ee(f, () => aa(n, () => e(t, l))))), m = o.isEffect(p) ? sa(p, f) : o.tryPromise({
2728
+ }, () => Ee(f, () => ca(n, () => e(t, l))))), m = o.isEffect(p) ? ua(p, f) : o.tryPromise({
2727
2729
  try: () => Promise.resolve(p),
2728
2730
  catch: (e) => e
2729
2731
  });
2730
2732
  return yield* (u ? m.pipe(o.tap((e) => o.promise(() => dt(u.store, u.scope, u.key, {
2731
2733
  status: 200,
2732
2734
  body: r ? r.encode(e) : e
2733
- }, Date.now())).pipe(o.ignore)), o.tapErrorCause(() => o.promise(() => ut(u.store, u.scope, u.key)).pipe(o.ignore))) : m).pipe(o.tapErrorCause((e) => o.sync(() => Ca(n, l.traceId, e))), o.catchIf(Ta, () => o.die(Ea(l.traceId))), o.annotateLogs(ua(l)));
2734
- }).pipe(o.withSpan(n, { attributes: { "framework.kind": "mutation" } })), ja = 8 * 1024 * 1024, Ma = (t) => {
2735
+ }, Date.now())).pipe(o.ignore)), o.tapErrorCause(() => o.promise(() => ut(u.store, u.scope, u.key)).pipe(o.ignore))) : m).pipe(o.tapErrorCause((e) => o.sync(() => Ea(n, l.traceId, e))), o.catchIf(Oa, () => o.die(ka(l.traceId))), o.annotateLogs(pa(l)));
2736
+ }).pipe(o.withSpan(n, { attributes: { "framework.kind": "mutation" } })), Pa = 8 * 1024 * 1024, Fa = (t) => {
2735
2737
  let n = t.port ?? 4e3, r = t.host, i = t.path ?? "/ws", a = St(), s = (e) => Dt.HttpServerRequest.pipe(o.flatMap((e) => o.gen(function* () {
2736
2738
  if (!t.inspectRoute) return V.text("inspect route not configured", { status: 404 });
2737
2739
  let n = {};
@@ -2808,7 +2810,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2808
2810
  let e = (e) => Dt.HttpServerRequest.pipe(o.flatMap((t) => o.gen(function* () {
2809
2811
  let n = {};
2810
2812
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
2811
- let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(o.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], s = ri(n.traceparent), c = yield* o.promise(() => e.handle({
2813
+ let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(o.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], s = oi(n.traceparent), c = yield* o.promise(() => e.handle({
2812
2814
  method: t.method,
2813
2815
  path: a,
2814
2816
  headers: n,
@@ -2840,7 +2842,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2840
2842
  rawBody: c,
2841
2843
  ...l === void 0 ? {} : { store: l }
2842
2844
  }, d = yield* o.promise(() => Pt(n, u));
2843
- d.status >= 500 && xa.warn(`${e.method} ${a} → ${d.status}`, {
2845
+ d.status >= 500 && wa.warn(`${e.method} ${a} → ${d.status}`, {
2844
2846
  method: e.method,
2845
2847
  path: a,
2846
2848
  status: d.status,
@@ -2875,7 +2877,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2875
2877
  });
2876
2878
  }
2877
2879
  return d.body instanceof Uint8Array ? V.uint8Array(d.body, p) : V.text(d.body ?? "", p);
2878
- })), o.tapErrorCause((t) => e.isInterruptedOnly(t) ? o.void : o.sync(() => xa.error(`${n.map((e) => e.method).join("|")} ${n[0].path} threw`, { path: n[0].path }, e.squash(t))))), r = /* @__PURE__ */ new Map();
2880
+ })), o.tapErrorCause((t) => e.isInterruptedOnly(t) ? o.void : o.sync(() => wa.error(`${n.map((e) => e.method).join("|")} ${n[0].path} threw`, { path: n[0].path }, e.squash(t))))), r = /* @__PURE__ */ new Map();
2879
2881
  for (let e of t.httpRoutes) {
2880
2882
  let t = r.get(e.path);
2881
2883
  t ? t.push(e) : r.set(e.path, [e]);
@@ -2890,7 +2892,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2890
2892
  let e = yield* Mt.Protocol;
2891
2893
  yield* o.forkScoped(o.gen(function* () {
2892
2894
  let t = yield* e.disconnects.take;
2893
- Kr(t), Xr(t);
2895
+ Yr(t), $r(t);
2894
2896
  }).pipe(o.forever));
2895
2897
  })), y = u.mergeAll(g, v).pipe(u.provide(h), u.provide(jt.layerJson), u.provide(t.handlersLayer)), x = u.mergeAll(y, _, f, p, m), S = t.pluginHttpInterceptor, C = t.healthCheck, w = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), T = t.maxRpcBodyBytes ?? (Number.isFinite(w) && w > 0 ? w : 8388608), E = { "cache-control": "no-store" }, ee = (e) => o.gen(function* () {
2896
2898
  let t = yield* Dt.HttpServerRequest, n = {};
@@ -2941,20 +2943,20 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2941
2943
  let te = z({ scope: "voltro:rpc" }), ne = u.launch(D).pipe(o.catchAllCause((t) => o.sync(() => {
2942
2944
  te.error("rpc server crashed", {}, e.squash(t)), process.exit(1);
2943
2945
  }))), re = o.runFork(ne);
2944
- return Na.add(re), Ha(), {
2946
+ return Ia.add(re), Ga(), {
2945
2947
  server: a,
2946
2948
  shutdown: async () => {
2947
- Na.delete(re), await o.runPromise(l.interrupt(re)).then(() => void 0, () => void 0);
2949
+ Ia.delete(re), await o.runPromise(l.interrupt(re)).then(() => void 0, () => void 0);
2948
2950
  }
2949
2951
  };
2950
- }, Na = /* @__PURE__ */ new Set(), Pa = /* @__PURE__ */ new Set(), Fa = !1, Ia = (e) => (Pa.add(e), () => {
2951
- Pa.delete(e);
2952
- }), La = 1e4, Ra = 1e3, za = 3e5, Ba = () => {
2952
+ }, Ia = /* @__PURE__ */ new Set(), La = /* @__PURE__ */ new Set(), Ra = !1, za = (e) => (La.add(e), () => {
2953
+ La.delete(e);
2954
+ }), Ba = 1e4, Va = 1e3, Ha = 3e5, Ua = () => {
2953
2955
  let e = process.env.VOLTRO_SHUTDOWN_GRACE_MS;
2954
- if (e === void 0 || e === "") return La;
2956
+ if (e === void 0 || e === "") return Ba;
2955
2957
  let t = Number(e);
2956
- return !Number.isFinite(t) || t <= 0 ? La : Math.min(za, Math.max(Ra, Math.trunc(t)));
2957
- }, Va = (e) => {
2958
+ return !Number.isFinite(t) || t <= 0 ? Ba : Math.min(Ha, Math.max(Va, Math.trunc(t)));
2959
+ }, Wa = (e) => {
2958
2960
  let t = Date.now(), n = !1, r = (r) => () => {
2959
2961
  n || (n = !0, clearTimeout(i), e.onOutcome?.({
2960
2962
  reason: r,
@@ -2962,23 +2964,23 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2962
2964
  }), e.exit());
2963
2965
  }, i = setTimeout(r("deadline"), e.deadlineMs);
2964
2966
  i.unref?.(), Promise.all(e.hooks.map((e) => Promise.resolve().then(e).then(() => void 0, () => void 0))).then(() => Promise.all(e.fibers.map((e) => o.runPromise(l.interrupt(e)).then(() => void 0, () => void 0)))).then(r("drained"), r("drained"));
2965
- }, Ha = () => {
2966
- if (Fa) return;
2967
- Fa = !0;
2967
+ }, Ga = () => {
2968
+ if (Ra) return;
2969
+ Ra = !0;
2968
2970
  let e = () => {
2969
- let e = [...Na], t = [...Pa];
2970
- Na.clear(), Pa.clear(), Va({
2971
+ let e = [...Ia], t = [...La];
2972
+ Ia.clear(), La.clear(), Wa({
2971
2973
  fibers: e,
2972
2974
  hooks: t,
2973
- deadlineMs: Ba(),
2975
+ deadlineMs: Ua(),
2974
2976
  exit: () => process.exit(0),
2975
2977
  onOutcome: ({ reason: e, ms: t }) => {
2976
- e === "drained" ? Sa.info(`drained in ${t}ms`) : Sa.error(`drain deadline exceeded — cut at ${t}ms`, { hint: "a shutdown hook or a pool drain did not complete; whatever had not finished did not happen" });
2978
+ e === "drained" ? Ta.info(`drained in ${t}ms`) : Ta.error(`drain deadline exceeded — cut at ${t}ms`, { hint: "a shutdown hook or a pool drain did not complete; whatever had not finished did not happen" });
2977
2979
  }
2978
2980
  });
2979
2981
  };
2980
2982
  process.once("SIGINT", e), process.once("SIGTERM", e);
2981
- }, Ua = (e, t = 1e4) => new Promise((n, r) => {
2983
+ }, Ka = (e, t = 1e4) => new Promise((n, r) => {
2982
2984
  if (e.listening) {
2983
2985
  n();
2984
2986
  return;
@@ -2994,13 +2996,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
2994
2996
  o(e);
2995
2997
  }
2996
2998
  a = setTimeout(() => o(/* @__PURE__ */ Error(`rpc server did not bind within ${t}ms`)), t), e.on("listening", s), e.on("error", c);
2997
- }), Wa = () => {
2999
+ }), qa = () => {
2998
3000
  let e = process.env.FRAMEWORK_TRACING?.toLowerCase();
2999
3001
  return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ? "otlp" : "off";
3000
- }, Ga = () => {
3002
+ }, Ja = () => {
3001
3003
  let e = process.env.FRAMEWORK_METRICS?.toLowerCase();
3002
3004
  return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ? "otlp" : "off";
3003
- }, Ka = async () => {
3005
+ }, Ya = async () => {
3004
3006
  let [e, t, n, r, i] = await Promise.all([
3005
3007
  import("@opentelemetry/sdk-trace-base"),
3006
3008
  import("@opentelemetry/sdk-metrics"),
@@ -3015,7 +3017,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3015
3017
  otlpMetrics: r,
3016
3018
  nodeSdk: i
3017
3019
  };
3018
- }, qa = (e, t, n) => {
3020
+ }, Xa = (e, t, n) => {
3019
3021
  let { PeriodicExportingMetricReader: r, ConsoleMetricExporter: i, InMemoryMetricExporter: a, AggregationTemporality: o } = e.sdkMetrics;
3020
3022
  if (t === "off") return {
3021
3023
  reader: void 0,
@@ -3038,8 +3040,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3038
3040
  }),
3039
3041
  inMemory: void 0
3040
3042
  };
3041
- }, Ja = async (e = {}) => {
3042
- let t = e.mode ?? Wa(), n = e.metricsMode ?? Ga(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
3043
+ }, Za = async (e = {}) => {
3044
+ let t = e.mode ?? qa(), n = e.metricsMode ?? Ja(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
3043
3045
  if (t === "off" && e.traceSink === void 0 && n === "off" && r.length === 0 && i.length === 0) return {
3044
3046
  layer: u.empty,
3045
3047
  mode: t,
@@ -3048,13 +3050,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3048
3050
  metricsMode: n,
3049
3051
  inMemoryMetricExporter: void 0
3050
3052
  };
3051
- let a = await Ka(), { ConsoleSpanExporter: o, InMemorySpanExporter: s, SimpleSpanProcessor: c, BatchSpanProcessor: l } = a.sdkTrace, d = t === "off", f = e.serviceName ?? process.env.OTEL_SERVICE_NAME ?? "voltro-app", p, m;
3053
+ let a = await Ya(), { ConsoleSpanExporter: o, InMemorySpanExporter: s, SimpleSpanProcessor: c, BatchSpanProcessor: l } = a.sdkTrace, d = t === "off", f = e.serviceName ?? process.env.OTEL_SERVICE_NAME ?? "voltro-app", p, m;
3052
3054
  e.spanProcessor ? m = e.spanProcessor : d ? m = void 0 : t === "memory" ? (p = new s(), m = new c(p)) : m = t === "console" ? new c(new o()) : new l(new a.otlpTrace.OTLPTraceExporter());
3053
3055
  let h = [
3054
3056
  ...e.traceSink ? [e.traceSink] : [],
3055
3057
  ...m ? [m] : [],
3056
3058
  ...r
3057
- ], g = h.length === 1 ? h[0] : h, { reader: _, inMemory: v } = qa(a, n, e.metricExportIntervalMillis ?? (process.env.OTEL_METRIC_EXPORT_INTERVAL ? Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) : 6e4)), y = [..._ ? [_] : [], ...i], b = y.length === 0 ? void 0 : y.length === 1 ? y[0] : y, x = {
3059
+ ], g = h.length === 1 ? h[0] : h, { reader: _, inMemory: v } = Xa(a, n, e.metricExportIntervalMillis ?? (process.env.OTEL_METRIC_EXPORT_INTERVAL ? Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) : 6e4)), y = [..._ ? [_] : [], ...i], b = y.length === 0 ? void 0 : y.length === 1 ? y[0] : y, x = {
3058
3060
  serviceName: f,
3059
3061
  ...e.serviceVersion ? { serviceVersion: e.serviceVersion } : {},
3060
3062
  ...e.resourceAttributes ? { attributes: e.resourceAttributes } : {}
@@ -3072,18 +3074,18 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3072
3074
  metricsMode: n,
3073
3075
  inMemoryMetricExporter: v
3074
3076
  };
3075
- }, Ya = {
3077
+ }, Qa = {
3076
3078
  [Bt.INTERNAL]: "internal",
3077
3079
  [Bt.SERVER]: "server",
3078
3080
  [Bt.CLIENT]: "client",
3079
3081
  [Bt.PRODUCER]: "producer",
3080
3082
  [Bt.CONSUMER]: "consumer"
3081
- }, Xa = (e) => e[0] * 1e3 + e[1] / 1e6, Za = 512, Qa = 48, $a = (e) => {
3083
+ }, $a = (e) => e[0] * 1e3 + e[1] / 1e6, eo = 512, to = 48, no = (e) => {
3082
3084
  let t = {}, n = 0;
3083
3085
  for (let r in e) {
3084
- if (n >= Qa) break;
3086
+ if (n >= to) break;
3085
3087
  let i = e[r];
3086
- if (typeof i == "string") t[r] = i.length > Za ? `${i.slice(0, Za)}…` : i;
3088
+ if (typeof i == "string") t[r] = i.length > eo ? `${i.slice(0, eo)}…` : i;
3087
3089
  else if (typeof i == "number" || typeof i == "boolean" || i == null) t[r] = i;
3088
3090
  else {
3089
3091
  let e;
@@ -3092,49 +3094,49 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3092
3094
  } catch {
3093
3095
  e = String(i);
3094
3096
  }
3095
- t[r] = e.length > Za ? `${e.slice(0, Za)}…` : e;
3097
+ t[r] = e.length > eo ? `${e.slice(0, eo)}…` : e;
3096
3098
  }
3097
3099
  n++;
3098
3100
  }
3099
3101
  return t;
3100
- }, eo = {
3102
+ }, ro = {
3101
3103
  [Vt.UNSET]: "unset",
3102
3104
  [Vt.OK]: "ok",
3103
3105
  [Vt.ERROR]: "error"
3104
- }, to = (e) => {
3106
+ }, io = (e) => {
3105
3107
  let t = e.spanContext(), n = e.events.length > 0 ? e.events.slice(0, 16).map((e) => ({
3106
3108
  name: e.name,
3107
- tsMs: Xa(e.time),
3108
- ...e.attributes ? { attributes: $a(e.attributes) } : {}
3109
+ tsMs: $a(e.time),
3110
+ ...e.attributes ? { attributes: no(e.attributes) } : {}
3109
3111
  })) : void 0;
3110
3112
  return {
3111
3113
  traceId: t.traceId,
3112
3114
  spanId: t.spanId,
3113
3115
  parentSpanId: e.parentSpanContext?.spanId ?? null,
3114
3116
  name: e.name,
3115
- kind: Ya[e.kind] ?? "internal",
3116
- attributes: $a(e.attributes),
3117
- startMs: Xa(e.startTime),
3118
- endMs: Xa(e.endTime),
3119
- durationMs: Xa(e.duration),
3120
- status: eo[e.status.code] ?? "unset",
3117
+ kind: Qa[e.kind] ?? "internal",
3118
+ attributes: no(e.attributes),
3119
+ startMs: $a(e.startTime),
3120
+ endMs: $a(e.endTime),
3121
+ durationMs: $a(e.duration),
3122
+ status: ro[e.status.code] ?? "unset",
3121
3123
  ...e.status.message ? { statusMessage: e.status.message } : {},
3122
3124
  ...n ? { events: n } : {}
3123
3125
  };
3124
- }, no = (e) => ({
3126
+ }, ao = (e) => ({
3125
3127
  onStart: () => {},
3126
3128
  onEnd: (t) => {
3127
3129
  try {
3128
- e(to(t));
3130
+ e(io(t));
3129
3131
  } catch {}
3130
3132
  },
3131
3133
  forceFlush: () => Promise.resolve(),
3132
3134
  shutdown: () => Promise.resolve()
3133
- }), ro = { get: (e) => Promise.resolve(process.env[e]) }, io = ro, ao = (e) => {
3134
- io = e;
3135
- }, oo = () => {
3136
- io = ro;
3137
- }, so = async (e) => await io.get(e) ?? process.env[e], co = (e) => process.env[e], lo = (e, t = 6e4, n = () => Date.now()) => {
3135
+ }), oo = { get: (e) => Promise.resolve(process.env[e]) }, so = oo, co = (e) => {
3136
+ so = e;
3137
+ }, lo = () => {
3138
+ so = oo;
3139
+ }, uo = async (e) => await so.get(e) ?? process.env[e], fo = (e) => process.env[e], po = (e, t = 6e4, n = () => Date.now()) => {
3138
3140
  let r = /* @__PURE__ */ new Map();
3139
3141
  return { get: async (i) => {
3140
3142
  let a = r.get(i);
@@ -3145,12 +3147,12 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3145
3147
  at: n()
3146
3148
  }), o;
3147
3149
  } };
3148
- }, uo = (e) => {
3150
+ }, mo = (e) => {
3149
3151
  let t = {
3150
3152
  accept: "application/json",
3151
3153
  ...e.headers ?? {}
3152
3154
  };
3153
- if (e.perKey) return lo({ get: async (n) => {
3155
+ if (e.perKey) return po({ get: async (n) => {
3154
3156
  let r = await fetch(`${e.url.replace(/\/$/, "")}/${encodeURIComponent(n)}`, { headers: t });
3155
3157
  if (!r.ok) return;
3156
3158
  let i = await r.json();
@@ -3161,34 +3163,34 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3161
3163
  let t = (await a())[e];
3162
3164
  return typeof t == "string" ? t : void 0;
3163
3165
  } };
3164
- }, fo = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? ro : e.kind === "custom" ? e.backend : e.kind === "http" ? uo(e) : ro, po = "_voltro_idempotency", mo = (e) => {
3166
+ }, ho = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? oo : e.kind === "custom" ? e.backend : e.kind === "http" ? mo(e) : oo, go = "_voltro_idempotency", _o = (e) => {
3165
3167
  if (e == null) return null;
3166
3168
  let t = typeof e == "string" ? JSON.parse(e) : e;
3167
3169
  return t && typeof t == "object" && "status" in t ? t : null;
3168
- }, ho = (e) => ({
3170
+ }, vo = (e) => ({
3169
3171
  scope: e.scope,
3170
3172
  key: e.key,
3171
3173
  status: e.status === "completed" ? "completed" : "in_flight",
3172
- response: mo(e.response),
3174
+ response: _o(e.response),
3173
3175
  createdAt: yt(e.createdAt)
3174
- }), go = async (e, t, n) => (await e.query({
3175
- table: po,
3176
+ }), yo = async (e, t, n) => (await e.query({
3177
+ table: go,
3176
3178
  predicate: C(O("scope", t), O("key", n)),
3177
3179
  order: [],
3178
3180
  take: 1,
3179
3181
  skip: void 0,
3180
3182
  projection: void 0
3181
- }))[0] ?? null, _o = (e) => ({
3183
+ }))[0] ?? null, bo = (e) => ({
3182
3184
  get: async (t, n) => {
3183
- let r = await go(e, t, n);
3184
- return r ? ho(r) : null;
3185
+ let r = await yo(e, t, n);
3186
+ return r ? vo(r) : null;
3185
3187
  },
3186
3188
  claim: async (t, n, r, i) => {
3187
3189
  for (let a = 0; a < 2; a++) {
3188
3190
  let a = A({
3189
3191
  kind: "typeid",
3190
3192
  prefix: "idem"
3191
- }, po), o = await e.insertIgnore(po, {
3193
+ }, go), o = await e.insertIgnore(go, {
3192
3194
  id: a,
3193
3195
  scope: t,
3194
3196
  key: n,
@@ -3197,11 +3199,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3197
3199
  createdAt: new Date(r)
3198
3200
  }, { conflictColumns: ["scope", "key"] });
3199
3201
  if (o.id === a) return "claimed";
3200
- if (r - yt(o.createdAt) < i) return ho(o);
3201
- await e.delete(po, o.id);
3202
+ if (r - yt(o.createdAt) < i) return vo(o);
3203
+ await e.delete(go, o.id);
3202
3204
  }
3203
- let a = await go(e, t, n);
3204
- return a ? ho(a) : {
3205
+ let a = await yo(e, t, n);
3206
+ return a ? vo(a) : {
3205
3207
  scope: t,
3206
3208
  key: n,
3207
3209
  status: "in_flight",
@@ -3210,33 +3212,33 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3210
3212
  };
3211
3213
  },
3212
3214
  complete: async (t, n, r, i) => {
3213
- let a = await go(e, t, n);
3214
- a && await e.update(po, a.id, {
3215
+ let a = await yo(e, t, n);
3216
+ a && await e.update(go, a.id, {
3215
3217
  status: "completed",
3216
3218
  response: r
3217
3219
  });
3218
3220
  },
3219
3221
  release: async (t, n) => {
3220
- let r = await go(e, t, n);
3221
- r && await e.delete(po, r.id);
3222
+ let r = await yo(e, t, n);
3223
+ r && await e.delete(go, r.id);
3222
3224
  }
3223
- }), J = "_voltro_kv", vo = (e) => {
3225
+ }), J = "_voltro_kv", xo = (e) => {
3224
3226
  if (e == null) return null;
3225
3227
  if (e instanceof Date) return e.getTime();
3226
3228
  if (typeof e == "number") return e;
3227
3229
  let t = Date.parse(String(e));
3228
3230
  return Number.isNaN(t) ? null : t;
3229
- }, yo = (e, t) => {
3230
- let n = vo(e.expiresAt);
3231
+ }, So = (e, t) => {
3232
+ let n = xo(e.expiresAt);
3231
3233
  return n !== null && n <= t;
3232
- }, bo = (e) => e === null ? null : JSON.parse(e), xo = async (e, t) => (await e.query({
3234
+ }, Co = (e) => e === null ? null : JSON.parse(e), wo = async (e, t) => (await e.query({
3233
3235
  table: J,
3234
3236
  predicate: O("key", t),
3235
3237
  order: [],
3236
3238
  take: 1,
3237
3239
  skip: void 0,
3238
3240
  projection: void 0
3239
- }))[0] ?? null, So = (e) => {
3241
+ }))[0] ?? null, To = (e) => {
3240
3242
  let t = (e, t, n) => o.tryPromise({
3241
3243
  try: n,
3242
3244
  catch: (n) => new Ut({
@@ -3247,8 +3249,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3247
3249
  });
3248
3250
  return {
3249
3251
  get: (n) => t("get", n, async () => {
3250
- let t = await xo(e, n);
3251
- return t === null ? h.none() : yo(t, Date.now()) ? (await e.delete(J, t.id), h.none()) : h.some(bo(t.value));
3252
+ let t = await wo(e, n);
3253
+ return t === null ? h.none() : So(t, Date.now()) ? (await e.delete(J, t.id), h.none()) : h.some(Co(t.value));
3252
3254
  }),
3253
3255
  set: (n, r, i) => t("set", n, async () => {
3254
3256
  let t = Date.now(), a = i?.ttlMs !== void 0 && i.ttlMs > 0 ? new Date(t + i.ttlMs) : null, o = A({
@@ -3271,14 +3273,14 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3271
3273
  });
3272
3274
  }),
3273
3275
  delete: (n) => t("delete", n, async () => {
3274
- let t = await xo(e, n);
3276
+ let t = await wo(e, n);
3275
3277
  if (t === null) return !1;
3276
- let r = !yo(t, Date.now());
3278
+ let r = !So(t, Date.now());
3277
3279
  return await e.delete(J, t.id), r;
3278
3280
  }),
3279
3281
  has: (n) => t("has", n, async () => {
3280
- let t = await xo(e, n);
3281
- return t === null ? !1 : yo(t, Date.now()) ? (await e.delete(J, t.id), !1) : !0;
3282
+ let t = await wo(e, n);
3283
+ return t === null ? !1 : So(t, Date.now()) ? (await e.delete(J, t.id), !1) : !0;
3282
3284
  }),
3283
3285
  list: (n) => t("list", "", async () => {
3284
3286
  let t = Date.now(), r = ye(de("expiresAt"), oe("expiresAt", new Date(t))), i = n === "" ? r : C(te("key", n), r), a = await e.query({
@@ -3289,7 +3291,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3289
3291
  skip: void 0,
3290
3292
  projection: void 0
3291
3293
  }), o = [];
3292
- for (let e of a) yo(e, t) || (n === "" || e.key.startsWith(n)) && o.push(e.key);
3294
+ for (let e of a) So(e, t) || (n === "" || e.key.startsWith(n)) && o.push(e.key);
3293
3295
  return o;
3294
3296
  }),
3295
3297
  clear: () => t("clear", "", async () => {
@@ -3299,8 +3301,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3299
3301
  } });
3300
3302
  })
3301
3303
  };
3302
- }, Co = async ({ store: e, env: t = process.env }) => {
3303
- let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? qt(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(u.provide(Gt)) : r === "memory" ? Kt() : u.succeed(Wt, Wt.of(So(e))), a = d.make(Ht.Default.pipe(u.provide(i))), o = await a.runPromise(Ht);
3304
+ }, Eo = async ({ store: e, env: t = process.env }) => {
3305
+ let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? qt(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(u.provide(Gt)) : r === "memory" ? Kt() : u.succeed(Wt, Wt.of(To(e))), a = d.make(Ht.Default.pipe(u.provide(i))), o = await a.runPromise(Ht);
3304
3306
  return {
3305
3307
  kv: {
3306
3308
  get: (e) => a.runPromise(o.get(e)).then((e) => h.getOrUndefined(e)),
@@ -3315,7 +3317,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3315
3317
  backend: r,
3316
3318
  dispose: () => a.dispose()
3317
3319
  };
3318
- }, wo = {
3320
+ }, Do = {
3319
3321
  get: () => Promise.resolve(void 0),
3320
3322
  getOrElse: (e, t) => Promise.resolve(t()),
3321
3323
  set: () => Promise.resolve(),
@@ -3323,7 +3325,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3323
3325
  has: () => Promise.resolve(!1),
3324
3326
  list: () => Promise.resolve([]),
3325
3327
  clear: () => Promise.resolve()
3326
- }, To = "_voltro_api_keys", Eo = (e) => Ie("sha256").update(e, "utf8").digest("hex"), Do = (e = "voltro_") => `${e}${Le(30).toString("base64url")}`, Oo = (e) => ({
3328
+ }, Oo = "_voltro_api_keys", ko = (e) => Ie("sha256").update(e, "utf8").digest("hex"), Ao = (e = "voltro_") => `${e}${Le(30).toString("base64url")}`, jo = (e) => ({
3327
3329
  id: e.id,
3328
3330
  name: e.name,
3329
3331
  keyPrefix: e.keyPrefix,
@@ -3336,18 +3338,18 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3336
3338
  createdBy: e.createdBy ?? null,
3337
3339
  onBehalfOf: e.onBehalfOf ?? null,
3338
3340
  ...e.metadata == null ? {} : { metadata: e.metadata }
3339
- }), ko = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), Ao = (e, t = {}) => {
3341
+ }), Mo = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), No = (e, t = {}) => {
3340
3342
  let n = t.prefix ?? "voltro_", r = t.usage, i = async (t) => {
3341
- let r = Do(n), i = A({
3343
+ let r = Ao(n), i = A({
3342
3344
  kind: "typeid",
3343
3345
  prefix: "apikey"
3344
- }, To), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
3346
+ }, Oo), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
3345
3347
  return await e.insert({
3346
3348
  id: i,
3347
3349
  tenantId: t.tenantId ?? null,
3348
3350
  name: t.name,
3349
3351
  onBehalfOf: t.onBehalfOf ?? null,
3350
- hashedKey: Eo(r),
3352
+ hashedKey: ko(r),
3351
3353
  keyPrefix: r.slice(0, n.length + 6),
3352
3354
  scopes: a,
3353
3355
  lastUsedAt: null,
@@ -3366,7 +3368,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3366
3368
  };
3367
3369
  }, a = async (t, n = Date.now()) => {
3368
3370
  let i = await e.findByHash(t);
3369
- return !i || !ko(i, n) ? null : (r === void 0 ? await e.patch(i.id, { lastUsedAt: n }) : r.touch(i.id, n), {
3371
+ return !i || !Mo(i, n) ? null : (r === void 0 ? await e.patch(i.id, { lastUsedAt: n }) : r.touch(i.id, n), {
3370
3372
  id: i.id,
3371
3373
  tenantId: i.tenantId ?? "",
3372
3374
  createdBy: i.createdBy ?? null,
@@ -3378,7 +3380,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3378
3380
  return {
3379
3381
  issue: i,
3380
3382
  resolveByHash: a,
3381
- verify: (e, t) => a(Eo(e), t),
3383
+ verify: (e, t) => a(ko(e), t),
3382
3384
  revoke: async (t, n, r = Date.now()) => {
3383
3385
  let i = await e.findById(t);
3384
3386
  return !i || (i.tenantId ?? null) !== n ? !1 : (await e.patch(t, { revokedAt: r }), !0);
@@ -3394,9 +3396,9 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3394
3396
  ...a.metadata == null ? {} : { metadata: a.metadata }
3395
3397
  }));
3396
3398
  },
3397
- list: async (t) => (await e.listByTenant(t)).map(Oo)
3399
+ list: async (t) => (await e.listByTenant(t)).map(jo)
3398
3400
  };
3399
- }, jo = () => {
3401
+ }, Po = () => {
3400
3402
  let e = /* @__PURE__ */ new Map();
3401
3403
  return {
3402
3404
  insert: async (t) => {
@@ -3413,21 +3415,21 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3413
3415
  });
3414
3416
  }
3415
3417
  };
3416
- }, Mo = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, No = (e) => ({
3418
+ }, Fo = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, Io = (e) => ({
3417
3419
  id: String(e.id),
3418
3420
  tenantId: e.tenantId ?? null,
3419
3421
  name: String(e.name),
3420
3422
  hashedKey: String(e.hashedKey),
3421
3423
  keyPrefix: String(e.keyPrefix),
3422
3424
  scopes: e.scopes ?? null,
3423
- lastUsedAt: Mo(e.lastUsedAt),
3424
- expiresAt: Mo(e.expiresAt),
3425
- revokedAt: Mo(e.revokedAt),
3425
+ lastUsedAt: Fo(e.lastUsedAt),
3426
+ expiresAt: Fo(e.expiresAt),
3427
+ revokedAt: Fo(e.revokedAt),
3426
3428
  createdBy: e.createdBy ?? null,
3427
3429
  onBehalfOf: e.onBehalfOf ?? null,
3428
- createdAt: Mo(e.createdAt) ?? 0,
3430
+ createdAt: Fo(e.createdAt) ?? 0,
3429
3431
  ...e.metadata == null ? {} : { metadata: e.metadata }
3430
- }), Po = (e) => async (t, n) => {
3432
+ }), Lo = (e) => async (t, n) => {
3431
3433
  let r = await e.findById(t);
3432
3434
  if (r === null) return;
3433
3435
  let i = r.requestCount ?? 0, a = r.lastUsedAt ?? 0;
@@ -3435,9 +3437,9 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3435
3437
  requestCount: i + n.requests,
3436
3438
  lastUsedAt: Math.max(a, n.lastUsedAt)
3437
3439
  });
3438
- }, Fo = (e) => {
3440
+ }, Ro = (e) => {
3439
3441
  let t = async (t) => await e.query({
3440
- table: To,
3442
+ table: Oo,
3441
3443
  predicate: t,
3442
3444
  order: [],
3443
3445
  take: void 0,
@@ -3455,33 +3457,33 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3455
3457
  };
3456
3458
  return {
3457
3459
  insert: async (t) => {
3458
- await e.insert(To, n(t));
3460
+ await e.insert(Oo, n(t));
3459
3461
  },
3460
3462
  findByHash: async (e) => {
3461
3463
  let n = await t(O("hashedKey", e));
3462
- return n[0] ? No(n[0]) : null;
3464
+ return n[0] ? Io(n[0]) : null;
3463
3465
  },
3464
3466
  findById: async (e) => {
3465
3467
  let n = await t(O("id", e));
3466
- return n[0] ? No(n[0]) : null;
3468
+ return n[0] ? Io(n[0]) : null;
3467
3469
  },
3468
- listByTenant: async (e) => (await t(e === null ? void 0 : O("tenantId", e))).map(No).filter((t) => e === null || t.tenantId === e),
3470
+ listByTenant: async (e) => (await t(e === null ? void 0 : O("tenantId", e))).map(Io).filter((t) => e === null || t.tenantId === e),
3469
3471
  patch: async (t, r) => {
3470
- await e.update(To, t, n(r));
3472
+ await e.update(Oo, t, n(r));
3471
3473
  }
3472
3474
  };
3473
- }, Io = (e, t = {}) => Jt({
3475
+ }, zo = (e, t = {}) => Jt({
3474
3476
  id: "voltro-apikey",
3475
3477
  ...t.prefix ? { prefix: t.prefix } : {},
3476
3478
  resolveKey: (t) => e.resolveByHash(t)
3477
- }), Lo = (e) => {
3479
+ }), Bo = (e) => {
3478
3480
  let t = e.subject;
3479
3481
  return {
3480
3482
  id: t.id ?? null,
3481
3483
  tenantId: t.tenantId ?? null,
3482
3484
  scopes: t.scopes ?? []
3483
3485
  };
3484
- }, Ro = (e, t = "/v1/api-keys") => {
3486
+ }, Vo = (e, t = "/v1/api-keys") => {
3485
3487
  let n = y.Struct({
3486
3488
  id: y.String,
3487
3489
  name: y.String,
@@ -3522,7 +3524,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3522
3524
  keyPrefix: y.String
3523
3525
  }),
3524
3526
  handler: async (t, n) => {
3525
- let r = t.body, i = Lo(n), a = new Set(i.scopes), o = (e) => a.has(Ve) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
3527
+ let r = t.body, i = Bo(n), a = new Set(i.scopes), o = (e) => a.has(Ve) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
3526
3528
  if (s === null) {
3527
3529
  if (!o(He)) throw new $e({
3528
3530
  required: He,
@@ -3567,7 +3569,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3567
3569
  guards: [It(Ve)],
3568
3570
  input: y.Struct({}),
3569
3571
  output: y.Struct({ keys: y.Array(n) }),
3570
- handler: async (t, n) => ({ keys: [...await e.list(Lo(n).tenantId)] })
3572
+ handler: async (t, n) => ({ keys: [...await e.list(Bo(n).tenantId)] })
3571
3573
  }),
3572
3574
  Nt({
3573
3575
  method: "POST",
@@ -3576,42 +3578,42 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3576
3578
  guards: [It(Ve)],
3577
3579
  input: y.Struct({ body: y.Struct({ id: y.String }) }),
3578
3580
  output: y.Struct({ ok: y.Boolean }),
3579
- handler: async (t, n) => ({ ok: await e.revoke(t.body.id, Lo(n).tenantId) })
3581
+ handler: async (t, n) => ({ ok: await e.revoke(t.body.id, Bo(n).tenantId) })
3580
3582
  })
3581
3583
  ];
3582
- }, zo = {
3584
+ }, Ho = {
3583
3585
  type: "anonymous",
3584
3586
  id: null,
3585
3587
  tenantId: null
3586
- }, Bo = class extends n.Tag("@voltro/EffectStore")() {}, Vo = (e, t) => (n) => n instanceof Ii ? n : new Li({
3588
+ }, Uo = class extends n.Tag("@voltro/EffectStore")() {}, Wo = (e, t) => (n) => n instanceof zi ? n : new Bi({
3587
3589
  operation: e,
3588
3590
  table: t,
3589
3591
  cause: String(n)
3590
- }), Ho = (e, t, n) => o.tryPromise({
3592
+ }), Go = (e, t, n) => o.tryPromise({
3591
3593
  try: n,
3592
- catch: Vo(e, t)
3593
- }), Uo = (e) => u.succeed(Bo, {
3594
- query: ((t) => Ho("query", t.table, () => e.query(t))),
3595
- insert: (t, n) => Ho("insert", t, () => e.insert(t, n)),
3596
- update: (t, n, r) => Ho("update", t, () => e.update(t, n, r)),
3597
- delete: (t, n) => Ho("delete", t, () => e.delete(t, n)),
3598
- hardDelete: (t, n) => Ho("hardDelete", t, () => e.hardDelete(t, n))
3599
- }), Wo = (e) => At.make(e.name, {
3594
+ catch: Wo(e, t)
3595
+ }), Ko = (e) => u.succeed(Uo, {
3596
+ query: ((t) => Go("query", t.table, () => e.query(t))),
3597
+ insert: (t, n) => Go("insert", t, () => e.insert(t, n)),
3598
+ update: (t, n, r) => Go("update", t, () => e.update(t, n, r)),
3599
+ delete: (t, n) => Go("delete", t, () => e.delete(t, n)),
3600
+ hardDelete: (t, n) => Go("hardDelete", t, () => e.hardDelete(t, n))
3601
+ }), qo = (e) => At.make(e.name, {
3600
3602
  payload: e.payloadSchema,
3601
3603
  success: it,
3602
3604
  error: e.errorSchema
3603
- }), Go = (e, t) => ({
3605
+ }), Jo = (e, t) => ({
3604
3606
  id: t,
3605
3607
  workflowName: e,
3606
3608
  executionId: t,
3607
3609
  status: "running"
3608
- }), Ko = Go, qo = (t) => {
3610
+ }), Yo = Jo, Xo = (t) => {
3609
3611
  let n = e.failureOption(t), r = n._tag === "Some" ? n.value : e.squash(t);
3610
3612
  return {
3611
3613
  tag: r && typeof r == "object" && "_tag" in r ? String(r._tag) : null,
3612
3614
  message: r?.message ?? String(r)
3613
3615
  };
3614
- }, Jo = (e, t, n) => {
3616
+ }, Zo = (e, t, n) => {
3615
3617
  if (n === void 0) return {
3616
3618
  id: t,
3617
3619
  workflowName: e,
@@ -3637,7 +3639,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3637
3639
  workflowName: e,
3638
3640
  executionId: t,
3639
3641
  status: "failed",
3640
- error: qo(r.cause)
3642
+ error: Xo(r.cause)
3641
3643
  };
3642
3644
  }
3643
3645
  return {
@@ -3646,7 +3648,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3646
3648
  executionId: t,
3647
3649
  status: "running"
3648
3650
  };
3649
- }, Yo = (e) => new Promise((t) => setTimeout(t, e)), Xo = class extends Error {
3651
+ }, Qo = (e) => new Promise((t) => setTimeout(t, e)), $o = class extends Error {
3650
3652
  workflowName;
3651
3653
  missingFields;
3652
3654
  detail;
@@ -3655,7 +3657,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3655
3657
  let r = t.length > 0 ? ` missing required field(s): ${t.join(", ")}.` : "";
3656
3658
  super(`Workflow "${e}" was started with an invalid payload.${r} ${n}`), this.workflowName = e, this.missingFields = t, this.detail = n, this.name = "WorkflowPayloadError";
3657
3659
  }
3658
- }, Zo = (e) => {
3660
+ }, es = (e) => {
3659
3661
  let t = e.ast;
3660
3662
  if (!Array.isArray(t.propertySignatures)) return {
3661
3663
  required: [],
@@ -3666,10 +3668,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3666
3668
  required: n.filter((e) => !e.isOptional).map((e) => String(e.name)),
3667
3669
  optional: n.filter((e) => e.isOptional).map((e) => String(e.name))
3668
3670
  };
3669
- }, Qo = (e) => {
3671
+ }, ts = (e) => {
3670
3672
  let t = e.ast;
3671
3673
  return Array.isArray(t.propertySignatures) ? t.propertySignatures.filter((e) => !e.isOptional && typeof e.name == "string").map((e) => String(e.name)) : [];
3672
- }, $o = (e) => {
3674
+ }, ns = (e) => {
3673
3675
  let t = new Map(e.workflows.map((e) => [e.definition.name, e.definition])), n = (e) => {
3674
3676
  let n = t.get(e);
3675
3677
  if (!n) {
@@ -3680,19 +3682,19 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3680
3682
  }, r = (e, t) => {
3681
3683
  let n = y.validateEither(e.payloadSchema)(t);
3682
3684
  if (n._tag === "Right") return;
3683
- let r = typeof t == "object" && t ? Object.keys(t) : [], i = Qo(e.payloadSchema).filter((e) => !r.includes(e));
3684
- throw new Xo(e.name, i, zt.formatErrorSync(n.left));
3685
+ let r = typeof t == "object" && t ? Object.keys(t) : [], i = ts(e.payloadSchema).filter((e) => !r.includes(e));
3686
+ throw new $o(e.name, i, zt.formatErrorSync(n.left));
3685
3687
  }, i = (e, t) => {
3686
3688
  let i = n(e);
3687
3689
  return r(i, t), i;
3688
3690
  }, a = async (t, r) => {
3689
3691
  let i = n(t);
3690
- return Jo(t, r, await e.runEffect(i.poll(r)));
3692
+ return Zo(t, r, await e.runEffect(i.poll(r)));
3691
3693
  }, o = async () => e.runEffect(Yt()), s = async (t, n, r) => {
3692
3694
  let a = i(t, n), o;
3693
- if (r?.callerContext !== void 0 && (o = await e.runEffect(a.executionId(n)), await e.rememberStartContext?.(t, o, r.callerContext)), r?.wait) return await e.runEffect(a.execute(n)), e.onEnqueue?.(), Go(t, o ?? await e.runEffect(a.executionId(n)));
3695
+ if (r?.callerContext !== void 0 && (o = await e.runEffect(a.executionId(n)), await e.rememberStartContext?.(t, o, r.callerContext)), r?.wait) return await e.runEffect(a.execute(n)), e.onEnqueue?.(), Jo(t, o ?? await e.runEffect(a.executionId(n)));
3694
3696
  let s = await e.runEffect(a.execute(n, { discard: !0 }));
3695
- return e.onEnqueue?.(), Go(t, s);
3697
+ return e.onEnqueue?.(), Jo(t, s);
3696
3698
  };
3697
3699
  return {
3698
3700
  start: s,
@@ -3730,7 +3732,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3730
3732
  let e = await a(r, i);
3731
3733
  if (e.status === "succeeded" || e.status === "failed" || e.status === "cancelled") return e;
3732
3734
  if (o?.timeoutMs !== void 0 && Date.now() - s >= o.timeoutMs) throw Error(`Timed out waiting for workflow '${r}' run '${i}'`);
3733
- await Yo(c);
3735
+ await Qo(c);
3734
3736
  }
3735
3737
  }),
3736
3738
  cancel: async (t, r) => {
@@ -3772,22 +3774,22 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3772
3774
  return e.redrive(t);
3773
3775
  }
3774
3776
  };
3775
- }, es = (e, t) => ({
3777
+ }, rs = (e, t) => ({
3776
3778
  ...e,
3777
3779
  start: async (n, r, i) => {
3778
3780
  if (i?.wait) throw Error("ctx.workflows.start(..., { wait: true }) is not allowed inside a mutation transaction; start the workflow and wait after commit.");
3779
3781
  let a = await e.executionId(n, r);
3780
- return t(() => e.start(n, r)), Go(n, a);
3782
+ return t(() => e.start(n, r)), Jo(n, a);
3781
3783
  },
3782
3784
  child: async (n, r, i) => {
3783
3785
  if (i?.wait) throw Error("ctx.workflows.child(..., { wait: true }) is not allowed inside a mutation transaction; start the child workflow and wait after commit.");
3784
3786
  let a = await e.executionId(n, r);
3785
- return t(() => e.child(n, r, i)), Go(n, a);
3787
+ return t(() => e.child(n, r, i)), Jo(n, a);
3786
3788
  },
3787
3789
  run: async () => {
3788
3790
  throw Error("ctx.workflows.run(...) is not allowed inside a mutation transaction; use ctx.workflows.start(...) so the workflow starts after commit.");
3789
3791
  }
3790
- }), ts = (e, t) => ({
3792
+ }), is = (e, t) => ({
3791
3793
  ...e,
3792
3794
  start: (n, r, i) => e.start(n, r, {
3793
3795
  ...i,
@@ -3801,7 +3803,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3801
3803
  ...i,
3802
3804
  callerContext: t
3803
3805
  })
3804
- }), ns = (e) => {
3806
+ }), as = (e) => {
3805
3807
  let t = () => {
3806
3808
  let t = e();
3807
3809
  if (!t) throw Error("Workflow runtime is not ready yet");
@@ -3823,26 +3825,26 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3823
3825
  retry: (e, n) => t().retry(e, n),
3824
3826
  redrive: (e) => t().redrive(e)
3825
3827
  };
3826
- }, rs = (e, t) => {
3828
+ }, os = (e, t) => {
3827
3829
  let n = {};
3828
- for (let r of e) n[r.definition.name] = (e) => (t ? o.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(o.map((e) => Go(r.definition.name, e)))).pipe(o.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
3830
+ for (let r of e) n[r.definition.name] = (e) => (t ? o.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(o.map((e) => Jo(r.definition.name, e)))).pipe(o.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
3829
3831
  return n;
3830
- }, is = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
3832
+ }, ss = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
3831
3833
  let a = t.resolveStartContext?.(e.definition.name, i);
3832
3834
  return (a === void 0 ? o.succeed(void 0) : o.promise(() => Promise.resolve(a))).pipe(o.flatMap((a) => {
3833
3835
  let s = {
3834
3836
  ...a,
3835
- subject: a?.subject ?? zo,
3837
+ subject: a?.subject ?? Ho,
3836
3838
  traceId: a?.traceId ?? "workflow-bootstrap"
3837
3839
  }, c = t.buildContext(s, {
3838
3840
  workflowName: e.definition.name,
3839
3841
  executionId: i,
3840
3842
  parentExecutionId: a?.parentExecutionId ?? null,
3841
3843
  parentClosePolicy: a?.parentClosePolicy ?? null
3842
- }), l = e.buildExecute(c), d = (n?.(e, l, s) ?? l)(r, i), f = u.succeed(et, s.subject), p = c?.store, m = p === void 0 ? d : o.provide(d, Uo(p));
3844
+ }), l = e.buildExecute(c), d = (n?.(e, l, s) ?? l)(r, i), f = u.succeed(et, s.subject), p = c?.store, m = p === void 0 ? d : o.provide(d, Ko(p));
3843
3845
  return o.provide(m, f);
3844
3846
  }));
3845
- }))), as = (e) => {
3847
+ }))), cs = (e) => {
3846
3848
  if ("on" in e) {
3847
3849
  let { on: t, ...n } = e;
3848
3850
  return {
@@ -3855,10 +3857,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3855
3857
  _tag: "workflowEventTrigger",
3856
3858
  ...e
3857
3859
  };
3858
- }, os = as, ss = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", cs = () => {
3860
+ }, ls = cs, us = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", ds = () => {
3859
3861
  let e = globalThis.crypto;
3860
3862
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
3861
- }, ls = (e) => `${e}_${cs()}`, us = (e) => e.id ?? `${e.event}->${e.workflow}`, ds = F("_voltro_workflow_events", {
3863
+ }, fs = (e) => `${e}_${ds()}`, ps = (e) => e.id ?? `${e.event}->${e.workflow}`, ms = F("_voltro_workflow_events", {
3862
3864
  id: M({ prefix: "wfe" }),
3863
3865
  name: I(),
3864
3866
  payload: P(),
@@ -3866,7 +3868,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3866
3868
  subject: P().nullable(),
3867
3869
  traceId: I().nullable(),
3868
3870
  occurredAt: L().default("now")
3869
- }).index(["name"]).index(["source"]).index(["occurredAt"]), fs = F("_voltro_workflow_event_deliveries", {
3871
+ }).index(["name"]).index(["source"]).index(["occurredAt"]), hs = F("_voltro_workflow_event_deliveries", {
3870
3872
  id: M({ prefix: "wfed" }),
3871
3873
  eventId: I(),
3872
3874
  eventName: I(),
@@ -3884,8 +3886,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3884
3886
  errorMessage: I().nullable(),
3885
3887
  createdAt: L().default("now"),
3886
3888
  completedAt: L().nullable()
3887
- }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]), ps = (e) => {
3888
- let t = e.makeId ?? ls, n = /* @__PURE__ */ new Map();
3889
+ }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]), gs = (e) => {
3890
+ let t = e.makeId ?? fs, n = /* @__PURE__ */ new Map();
3889
3891
  for (let t of e.triggers) {
3890
3892
  let e = n.get(t.event);
3891
3893
  e ? e.push(t) : n.set(t.event, [t]);
@@ -3926,7 +3928,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
3926
3928
  });
3927
3929
  let f = o(n), p = [];
3928
3930
  for (let o of f) {
3929
- let s = us(o), l = o.workflow, u;
3931
+ let s = ps(o), l = o.workflow, u;
3930
3932
  try {
3931
3933
  let f = o.idempotencyKey?.(d) ?? `${c}:${s}`;
3932
3934
  if (o.filter && !await o.filter(d)) {
@@ -4029,7 +4031,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4029
4031
  triggered: p
4030
4032
  };
4031
4033
  } };
4032
- }, ms = z({ scope: "voltro:events" }), hs = 64, gs = 5 * 6e4, _s = 1e4, vs = class {
4034
+ }, _s = z({ scope: "voltro:events" }), vs = 64, ys = 5 * 6e4, bs = 1e4, xs = class {
4033
4035
  routes = /* @__PURE__ */ new Map();
4034
4036
  origin;
4035
4037
  ringSize;
@@ -4041,7 +4043,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4041
4043
  interestListeners = /* @__PURE__ */ new Set();
4042
4044
  now;
4043
4045
  constructor(e) {
4044
- this.origin = e.origin, this.ringSize = e.ringSize ?? hs, this.ringTtlMs = e.ringTtlMs ?? gs, this.maxRoutes = e.maxRoutes ?? _s, this.publishRemote = e.publishRemote, this.deliveryOf = e.deliveryOf, this.now = e.now ?? Date.now;
4046
+ this.origin = e.origin, this.ringSize = e.ringSize ?? vs, this.ringTtlMs = e.ringTtlMs ?? ys, this.maxRoutes = e.maxRoutes ?? bs, this.publishRemote = e.publishRemote, this.deliveryOf = e.deliveryOf, this.now = e.now ?? Date.now;
4045
4047
  }
4046
4048
  get instanceOrigin() {
4047
4049
  return this.origin;
@@ -4061,7 +4063,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4061
4063
  for (let n of this.interestListeners) try {
4062
4064
  n(e, t);
4063
4065
  } catch (n) {
4064
- ms.warn("event interest listener threw", {
4066
+ _s.warn("event interest listener threw", {
4065
4067
  event: e,
4066
4068
  active: t,
4067
4069
  cause: n
@@ -4096,7 +4098,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4096
4098
  this.routes.delete(r), n += 1;
4097
4099
  }
4098
4100
  if (n === 0) {
4099
- ms.warn("event ring capacity reached with all routes live — replay buffers cleared", {
4101
+ _s.warn("event ring capacity reached with all routes live — replay buffers cleared", {
4100
4102
  routes: this.routes.size,
4101
4103
  maxRoutes: this.maxRoutes
4102
4104
  });
@@ -4121,7 +4123,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4121
4123
  if (n.localNext += 1, this.accept(n, r), or(e.event), this.publishRemote !== void 0) try {
4122
4124
  this.publishRemote(r);
4123
4125
  } catch (t) {
4124
- ms.warn("event broadcast publish failed — local delivery unaffected", {
4126
+ _s.warn("event broadcast publish failed — local delivery unaffected", {
4125
4127
  event: e.event,
4126
4128
  cause: t
4127
4129
  });
@@ -4150,7 +4152,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4150
4152
  for (let n of e.listeners) try {
4151
4153
  n(i);
4152
4154
  } catch (e) {
4153
- ms.warn("event listener threw — other subscribers unaffected", {
4155
+ _s.warn("event listener threw — other subscribers unaffected", {
4154
4156
  event: t.event,
4155
4157
  cause: e
4156
4158
  });
@@ -4158,9 +4160,17 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4158
4160
  }
4159
4161
  subscribe(e) {
4160
4162
  let t = lt(e.tenantId, e.event, e.key), n = this.state(t);
4161
- e.onAttach?.(new Map(n.watermark)), n.listeners.add(e.listener), lr(e.event, 1), this.shiftInterest(e.event, 1);
4162
- let r = e.options?.resume;
4163
- if (r !== void 0) this.replayForResume(n, r, e.listener);
4163
+ e.onAttach?.(new Map(n.watermark));
4164
+ let r = !0, i = [], a = (t) => {
4165
+ if (r) {
4166
+ i.push(t);
4167
+ return;
4168
+ }
4169
+ e.listener(t);
4170
+ };
4171
+ n.listeners.add(a), lr(e.event, 1), this.shiftInterest(e.event, 1);
4172
+ let o = e.options?.resume;
4173
+ if (o !== void 0) this.replayForResume(n, o, e.listener);
4164
4174
  else if (e.options?.rewind === !0) {
4165
4175
  this.pruneRing(n);
4166
4176
  for (let t of n.ring) e.listener({
@@ -4169,9 +4179,12 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4169
4179
  prior: t.envelope.n - 1
4170
4180
  });
4171
4181
  }
4172
- let i = !0;
4182
+ r = !1;
4183
+ for (let t of i) e.listener(t);
4184
+ i.length = 0;
4185
+ let s = !0;
4173
4186
  return () => {
4174
- i && (i = !1, n.listeners.delete(e.listener), lr(e.event, -1), this.shiftInterest(e.event, -1));
4187
+ s && (s = !1, n.listeners.delete(a), lr(e.event, -1), this.shiftInterest(e.event, -1));
4175
4188
  };
4176
4189
  }
4177
4190
  replayForResume(e, t, n) {
@@ -4223,13 +4236,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4223
4236
  clear() {
4224
4237
  this.routes.clear();
4225
4238
  }
4226
- }, ys = (e) => e instanceof Error ? e.message : String(e), bs = (e, t, n, r) => o.gen(function* () {
4239
+ }, Ss = (e) => e instanceof Error ? e.message : String(e), Cs = (e, t, n, r) => o.gen(function* () {
4227
4240
  let i = y.encode(t.key), a = y.encode(t.payload), s = yield* i(n).pipe(o.mapError((e) => new Ye({
4228
4241
  event: t.name,
4229
- message: ys(e)
4242
+ message: Ss(e)
4230
4243
  }))), c = yield* a(r).pipe(o.mapError((e) => new Xe({
4231
4244
  event: t.name,
4232
- message: ys(e)
4245
+ message: Ss(e)
4233
4246
  }))), l = Buffer.byteLength(JSON.stringify({
4234
4247
  event: t.name,
4235
4248
  key: s,
@@ -4258,10 +4271,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4258
4271
  n: -1,
4259
4272
  deferred: !0
4260
4273
  });
4261
- }), xs = (e) => {
4274
+ }), ws = (e) => {
4262
4275
  let t;
4263
4276
  return Object.assign(e, { then: (n, r) => (t ??= o.runPromise(e), t.then(n, r)) });
4264
- }, Ss = (e) => ({ publish: (t, n, r) => xs(bs(e, t, n, r)) }), Cs = 64, ws = 1, Ts = (e) => e.kind === "gap" ? {
4277
+ }, Ts = (e) => ({ publish: (t, n, r) => ws(Cs(e, t, n, r)) }), Es = 64, Ds = 1, Os = (e) => e.kind === "gap" ? {
4265
4278
  _tag: "gap",
4266
4279
  missed: e.missed,
4267
4280
  reason: e.reason
@@ -4271,13 +4284,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4271
4284
  n: e.envelope.n,
4272
4285
  emittedAt: e.envelope.emittedAt,
4273
4286
  payload: e.envelope.payload
4274
- }, Es = (e) => {
4287
+ }, ks = (e) => {
4275
4288
  let t = new Map(e ?? []);
4276
4289
  return (e, n = 0) => {
4277
4290
  let r = t.get(e.origin) ?? 0;
4278
4291
  return t.set(e.origin, Math.max(r, e.n)), r === 0 && n === 0 ? 0 : Math.max(0, e.n - r - 1);
4279
4292
  };
4280
- }, Ds = (e) => b.unwrapScoped(o.gen(function* () {
4293
+ }, As = (e) => b.unwrapScoped(o.gen(function* () {
4281
4294
  let t = yield* et, n = yield* Ge, r = t.tenantId ?? null;
4282
4295
  if (e.guards !== void 0 && e.guards.length > 0) {
4283
4296
  let n = yield* ot(t, e.guards, e.key);
@@ -4298,20 +4311,20 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4298
4311
  if (yield* o.addFinalizer(() => o.sync(() => {
4299
4312
  c();
4300
4313
  })), n.clientId !== void 0) {
4301
- let e = Yr(n.clientId, () => {
4314
+ let e = Qr(n.clientId, () => {
4302
4315
  o.runPromise(g.shutdown(a));
4303
4316
  });
4304
4317
  yield* o.addFinalizer(() => o.sync(() => {
4305
4318
  e();
4306
4319
  }));
4307
4320
  }
4308
- let l = i ? () => 0 : Es(s), u = e.guards, d = u === void 0 || u.length === 0 ? void 0 : () => ot(t, u, e.key), f = b.fromQueue(a, { shutdown: !0 }).pipe(b.flatMap((e) => d === void 0 ? p(e) : b.unwrap(d().pipe(o.map((t) => t ? b.fail(t) : p(e))))));
4321
+ let l = i ? () => 0 : ks(s), u = e.guards, d = u === void 0 || u.length === 0 ? void 0 : () => ot(t, u, e.key), f = b.fromQueue(a, { shutdown: !0 }).pipe(b.flatMap((e) => d === void 0 ? p(e) : b.unwrap(d().pipe(o.map((t) => t ? b.fail(t) : p(e))))));
4309
4322
  function p(t) {
4310
4323
  return b.suspend(() => {
4311
- if (t.kind === "gap") return b.make(Ts(t));
4324
+ if (t.kind === "gap") return b.make(Os(t));
4312
4325
  let n = l(t.envelope, t.prior);
4313
4326
  sr(e.event);
4314
- let r = Ts(t);
4327
+ let r = Os(t);
4315
4328
  if (n === 0) return b.make(r);
4316
4329
  cr(e.event, "buffer", n);
4317
4330
  let i = {
@@ -4323,8 +4336,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4323
4336
  });
4324
4337
  }
4325
4338
  let m = { _tag: "attached" };
4326
- return ra(b.concat(b.fromIterable([m]), f), n.credentialExpiresAt, b.fromIterable([m]));
4327
- })), Os = z({ scope: "voltro:members" }), ks = 5e3, As = class {
4339
+ return oa(b.concat(b.fromIterable([m]), f), n.credentialExpiresAt, b.fromIterable([m]));
4340
+ })), js = z({ scope: "voltro:members" }), Ms = 5e3, Ns = class {
4328
4341
  members = /* @__PURE__ */ new Map();
4329
4342
  listeners = /* @__PURE__ */ new Set();
4330
4343
  instanceId;
@@ -4336,7 +4349,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4336
4349
  now;
4337
4350
  timer;
4338
4351
  constructor(e) {
4339
- this.instanceId = e.instanceId, this.now = e.now ?? Date.now, this.startedAt = e.startedAt ?? this.now(), this.meta = e.meta, this.heartbeatMs = e.heartbeatMs ?? ks, this.downAfterMs = e.downAfterMs ?? this.heartbeatMs * 3, this.announce = e.announce, this.members.set(this.instanceId, {
4352
+ this.instanceId = e.instanceId, this.now = e.now ?? Date.now, this.startedAt = e.startedAt ?? this.now(), this.meta = e.meta, this.heartbeatMs = e.heartbeatMs ?? Ms, this.downAfterMs = e.downAfterMs ?? this.heartbeatMs * 3, this.announce = e.announce, this.members.set(this.instanceId, {
4340
4353
  startedAt: this.startedAt,
4341
4354
  meta: this.meta,
4342
4355
  lastHeardAt: this.now()
@@ -4362,7 +4375,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4362
4375
  ...this.meta === void 0 ? {} : { meta: this.meta }
4363
4376
  });
4364
4377
  } catch (e) {
4365
- Os.warn("membership: announce failed", { cause: e });
4378
+ js.warn("membership: announce failed", { cause: e });
4366
4379
  }
4367
4380
  }
4368
4381
  receive(e) {
@@ -4416,16 +4429,16 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4416
4429
  for (let t of this.listeners) try {
4417
4430
  t(e);
4418
4431
  } catch (t) {
4419
- Os.warn("membership: listener threw", {
4432
+ js.warn("membership: listener threw", {
4420
4433
  event: e.kind,
4421
4434
  cause: t
4422
4435
  });
4423
4436
  }
4424
4437
  }
4425
- }, js = z({ scope: "voltro:outbox" }), Y = "_voltro_outbox", Ms = {
4438
+ }, Ps = z({ scope: "voltro:outbox" }), Y = "_voltro_outbox", Fs = {
4426
4439
  kind: "typeid",
4427
4440
  prefix: "obx"
4428
- }, Ns = F(Y, {
4441
+ }, Is = F(Y, {
4429
4442
  id: M({ prefix: "obx" }),
4430
4443
  effect: I(),
4431
4444
  payload: P(),
@@ -4443,10 +4456,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4443
4456
  resendRequestedBy: I().nullable(),
4444
4457
  resendReason: I().nullable(),
4445
4458
  resendCount: N()
4446
- }), Ps = "_voltro_outbox_attempts", Fs = {
4459
+ }), Ls = "_voltro_outbox_attempts", Rs = {
4447
4460
  kind: "typeid",
4448
4461
  prefix: "obxa"
4449
- }, Is = F(Ps, {
4462
+ }, zs = F(Ls, {
4450
4463
  id: M({ prefix: "obxa" }),
4451
4464
  outboxId: I(),
4452
4465
  effect: I(),
@@ -4467,11 +4480,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4467
4480
  subjectId: I().nullable(),
4468
4481
  tenantId: I().nullable(),
4469
4482
  traceId: I().nullable()
4470
- }).index(["outboxId", "attempt"]).index(["startedAt"]).index(["outcome"]), Ls = (e) => {
4483
+ }).index(["outboxId", "attempt"]).index(["startedAt"]).index(["outcome"]), Bs = (e) => {
4471
4484
  if (e.effect.trim() === "") throw Error("defineOutboxHandler: `effect` must be a non-empty name");
4472
4485
  if (e.maxAttempts !== void 0 && e.maxAttempts < 1) throw Error(`defineOutboxHandler("${e.effect}"): maxAttempts must be >= 1`);
4473
4486
  return e;
4474
- }, Rs = 8, zs = (e) => ({
4487
+ }, Vs = 8, Hs = (e) => ({
4475
4488
  enqueue: async (t, n, r) => {
4476
4489
  let i = (e.now ?? (() => /* @__PURE__ */ new Date()))(), a = r?.idempotencyKey;
4477
4490
  if (a !== void 0) {
@@ -4486,12 +4499,12 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4486
4499
  if (t !== void 0) return t.id;
4487
4500
  }
4488
4501
  let o = {
4489
- id: A(Ms, Y),
4502
+ id: A(Fs, Y),
4490
4503
  effect: t,
4491
4504
  payload: n,
4492
4505
  status: "pending",
4493
4506
  attempts: 0,
4494
- maxAttempts: r?.maxAttempts ?? Rs,
4507
+ maxAttempts: r?.maxAttempts ?? Vs,
4495
4508
  nextAttemptAt: new Date(i.getTime() + (r?.delayMs ?? 0)),
4496
4509
  idempotencyKey: a ?? null,
4497
4510
  lastError: null,
@@ -4538,7 +4551,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4538
4551
  });
4539
4552
  } else e.nudge?.();
4540
4553
  }
4541
- }), Bs = (e) => Math.min(1e3 * 2 ** Math.max(0, e - 1), 5 * 6e4), Vs = 50, Hs = (e, t) => e.length <= t ? e : `${e.slice(0, t)}… [clipped]`, Us = (e) => {
4554
+ }), Us = (e) => Math.min(1e3 * 2 ** Math.max(0, e - 1), 5 * 6e4), Ws = 50, Gs = (e, t) => e.length <= t ? e : `${e.slice(0, t)}… [clipped]`, Ks = (e) => {
4542
4555
  if (e == null) return null;
4543
4556
  let t = typeof e == "object" && !Array.isArray(e) ? e : { value: e }, n;
4544
4557
  try {
@@ -4548,13 +4561,13 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4548
4561
  }
4549
4562
  return n.length > 8192 ? {
4550
4563
  truncated: !0,
4551
- preview: Hs(n, 8192)
4564
+ preview: Gs(n, 8192)
4552
4565
  } : t;
4553
- }, Ws = async (e, t, n) => {
4566
+ }, qs = async (e, t, n) => {
4554
4567
  let r = t.outboxRow, i = r.id, a = r.resendRequestedBy ?? null;
4555
4568
  try {
4556
- await e.insert(Ps, {
4557
- id: A(Fs, Ps),
4569
+ await e.insert(Ls, {
4570
+ id: A(Rs, Ls),
4558
4571
  outboxId: i,
4559
4572
  effect: r.effect,
4560
4573
  attempt: t.attempt,
@@ -4565,14 +4578,14 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4565
4578
  startedAt: t.startedAt,
4566
4579
  finishedAt: t.finishedAt,
4567
4580
  durationMs: Math.max(0, t.finishedAt.getTime() - t.startedAt.getTime()),
4568
- error: t.error === null ? null : Hs(t.error, 4e3),
4569
- response: Us(t.response),
4581
+ error: t.error === null ? null : Gs(t.error, 4e3),
4582
+ response: Ks(t.response),
4570
4583
  subjectId: r.subjectId ?? null,
4571
4584
  tenantId: r.tenantId ?? null,
4572
4585
  traceId: r.traceId ?? null
4573
4586
  });
4574
4587
  } catch (e) {
4575
- js.warn("outbox: could not record delivery attempt (delivery itself is unaffected)", {
4588
+ Ps.warn("outbox: could not record delivery attempt (delivery itself is unaffected)", {
4576
4589
  outboxId: i,
4577
4590
  attempt: t.attempt
4578
4591
  }, e);
@@ -4580,7 +4593,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4580
4593
  }
4581
4594
  if (!(t.attempt <= n)) try {
4582
4595
  let t = await e.query({
4583
- table: Ps,
4596
+ table: Ls,
4584
4597
  predicate: O("outboxId", i),
4585
4598
  order: [{
4586
4599
  column: "attempt",
@@ -4590,11 +4603,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4590
4603
  skip: void 0,
4591
4604
  projection: ["id"]
4592
4605
  });
4593
- for (let r of t.slice(0, Math.max(0, t.length - n))) await e.delete(Ps, r.id);
4606
+ for (let r of t.slice(0, Math.max(0, t.length - n))) await e.delete(Ls, r.id);
4594
4607
  } catch (e) {
4595
- js.warn("outbox: attempt-log trim failed; the log may exceed its cap", { outboxId: i }, e);
4608
+ Ps.warn("outbox: attempt-log trim failed; the log may exceed its cap", { outboxId: i }, e);
4596
4609
  }
4597
- }, Gs = async (e) => {
4610
+ }, Js = async (e) => {
4598
4611
  let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), n = await e.store.query({
4599
4612
  table: Y,
4600
4613
  predicate: C(O("status", "pending"), he("nextAttemptAt", t)),
@@ -4612,7 +4625,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4612
4625
  o++;
4613
4626
  continue;
4614
4627
  }
4615
- let u = s.attempts + 1, d = s.maxAttempts ?? Rs, f = /* @__PURE__ */ new Date(), p = e.attemptLogCap ?? 50;
4628
+ let u = s.attempts + 1, d = s.maxAttempts ?? Vs, f = /* @__PURE__ */ new Date(), p = e.attemptLogCap ?? 50;
4616
4629
  try {
4617
4630
  let t = await l.handler({
4618
4631
  payload: s.payload ?? {},
@@ -4621,7 +4634,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4621
4634
  tenantId: s.tenantId ?? null,
4622
4635
  traceId: s.traceId ?? null
4623
4636
  });
4624
- await Ws(e.store, {
4637
+ await qs(e.store, {
4625
4638
  outboxRow: s,
4626
4639
  attempt: u,
4627
4640
  outcome: "delivered",
@@ -4639,7 +4652,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4639
4652
  }), r++;
4640
4653
  } catch (r) {
4641
4654
  let o = r instanceof Error ? r.message : String(r), l = u >= d;
4642
- await Ws(e.store, {
4655
+ await qs(e.store, {
4643
4656
  outboxRow: s,
4644
4657
  attempt: u,
4645
4658
  outcome: l ? "dead" : "failed",
@@ -4651,20 +4664,20 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4651
4664
  status: l ? "dead" : "pending",
4652
4665
  attempts: u,
4653
4666
  lastError: o,
4654
- nextAttemptAt: new Date(t.getTime() + Bs(u)),
4667
+ nextAttemptAt: new Date(t.getTime() + Us(u)),
4655
4668
  resendRequestedBy: null,
4656
4669
  resendReason: null
4657
- }), l ? (a++, js.error("outbox effect dead-lettered after exhausting attempts", {
4670
+ }), l ? (a++, Ps.error("outbox effect dead-lettered after exhausting attempts", {
4658
4671
  id: n,
4659
4672
  effect: c,
4660
4673
  attempts: u,
4661
4674
  maxAttempts: d
4662
- }, r)) : (i++, js.warn("outbox delivery failed; will retry", {
4675
+ }, r)) : (i++, Ps.warn("outbox delivery failed; will retry", {
4663
4676
  id: n,
4664
4677
  effect: c,
4665
4678
  attempt: u,
4666
4679
  maxAttempts: d,
4667
- retryInMs: Bs(u)
4680
+ retryInMs: Us(u)
4668
4681
  }));
4669
4682
  }
4670
4683
  }
@@ -4674,10 +4687,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4674
4687
  dead: a,
4675
4688
  skipped: o
4676
4689
  };
4677
- }, Ks = z({ scope: "voltro:connections" }), X = "_voltro_connections", qs = {
4690
+ }, Ys = z({ scope: "voltro:connections" }), X = "_voltro_connections", Xs = {
4678
4691
  kind: "typeid",
4679
4692
  prefix: "conn"
4680
- }, Js = F(X, {
4693
+ }, Zs = F(X, {
4681
4694
  id: M({ prefix: "conn" }),
4682
4695
  connectionId: I(),
4683
4696
  subjectId: I(),
@@ -4700,10 +4713,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4700
4713
  metadata: P().nullable(),
4701
4714
  connectedAt: L(),
4702
4715
  updatedAt: L()
4703
- }).unique("byConnectionSubject", ["connectionId", "subjectId"]).index(["subjectId"]), Ys = "_voltro_connection_grants", Xs = {
4716
+ }).unique("byConnectionSubject", ["connectionId", "subjectId"]).index(["subjectId"]), Qs = "_voltro_connection_grants", $s = {
4704
4717
  kind: "typeid",
4705
4718
  prefix: "cgrant"
4706
- }, Zs = F(Ys, {
4719
+ }, ec = F(Qs, {
4707
4720
  id: M({ prefix: "cgrant" }),
4708
4721
  state: I().unique(),
4709
4722
  connectionId: I(),
@@ -4713,8 +4726,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4713
4726
  redirectTo: I(),
4714
4727
  createdAt: L(),
4715
4728
  expiresAt: L()
4716
- }).index(["expiresAt"]), Qs = /^[a-z][a-z0-9-]*$/, $s = (e) => {
4717
- if (!Qs.test(e.id)) throw Error(`defineConnection: id "${e.id}" must be lowercase kebab-case (it becomes a URL path segment).`);
4729
+ }).index(["expiresAt"]), tc = /^[a-z][a-z0-9-]*$/, nc = (e) => {
4730
+ if (!tc.test(e.id)) throw Error(`defineConnection: id "${e.id}" must be lowercase kebab-case (it becomes a URL path segment).`);
4718
4731
  if (e.kind === "oauth2") {
4719
4732
  for (let t of [
4720
4733
  "authorizeUrl",
@@ -4724,9 +4737,9 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4724
4737
  ]) if (typeof e[t] != "string" || e[t].length === 0) throw Error(`defineConnection("${e.id}"): \`${t}\` is required for kind 'oauth2'.`);
4725
4738
  }
4726
4739
  return e;
4727
- }, ec = (e) => e.label ?? e.id, tc = (e) => {
4740
+ }, rc = (e) => e.label ?? e.id, ic = (e) => {
4728
4741
  if (e.length !== 0 && q() === void 0) throw Error(`connections: ${e.length} connection(s) declared (${e.map((e) => e.id).join(", ")}) but no field cipher is registered. Connection tokens are stored encrypted and there is no plaintext fallback. Enable \`@voltro/plugin-governance\` with \`governancePlugin({ fieldEncryption: { key: env.FIELD_ENCRYPTION_KEY } })\` (or call setFieldCipher at boot).`);
4729
- }, nc = (e) => {
4742
+ }, ac = (e) => {
4730
4743
  let t = /* @__PURE__ */ new Map();
4731
4744
  for (let n of e) {
4732
4745
  if (t.has(n.id)) throw Error(`connections: duplicate connection id "${n.id}" — each *.connection.ts must declare a distinct id.`);
@@ -4736,14 +4749,14 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4736
4749
  get: (e) => t.get(e),
4737
4750
  list: () => [...t.values()]
4738
4751
  };
4739
- }, rc = (e) => {
4752
+ }, oc = (e) => {
4740
4753
  if (e == null) return null;
4741
4754
  let t = e instanceof Date ? e : new Date(String(e));
4742
4755
  return Number.isNaN(t.getTime()) ? null : t;
4743
- }, ic = (e) => rc(e)?.toISOString() ?? null, ac = (e) => String(e ?? "").split(" ").filter((e) => e.length > 0), oc = (e, t) => t === void 0 ? {
4756
+ }, sc = (e) => oc(e)?.toISOString() ?? null, cc = (e) => String(e ?? "").split(" ").filter((e) => e.length > 0), lc = (e, t) => t === void 0 ? {
4744
4757
  connectionId: e.id,
4745
4758
  kind: e.kind,
4746
- label: ec(e),
4759
+ label: rc(e),
4747
4760
  status: "disconnected",
4748
4761
  accountId: null,
4749
4762
  accountLabel: null,
@@ -4754,31 +4767,31 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4754
4767
  } : {
4755
4768
  connectionId: e.id,
4756
4769
  kind: e.kind,
4757
- label: ec(e),
4770
+ label: rc(e),
4758
4771
  status: String(t.status ?? "connected"),
4759
4772
  accountId: t.accountId ?? null,
4760
4773
  accountLabel: t.accountLabel ?? null,
4761
- scopes: ac(t.scopes),
4762
- expiresAt: ic(t.expiresAt),
4774
+ scopes: cc(t.scopes),
4775
+ expiresAt: sc(t.expiresAt),
4763
4776
  lastError: t.lastError ?? null,
4764
- connectedAt: ic(t.connectedAt)
4765
- }, sc = async (e, t, n) => (await e.query({
4777
+ connectedAt: sc(t.connectedAt)
4778
+ }, uc = async (e, t, n) => (await e.query({
4766
4779
  table: X,
4767
4780
  predicate: C(O("connectionId", t), O("subjectId", n)),
4768
4781
  order: [],
4769
4782
  take: 1,
4770
4783
  skip: void 0,
4771
4784
  projection: void 0
4772
- }))[0], cc = async (e) => {
4785
+ }))[0], dc = async (e) => {
4773
4786
  let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), n = e.tokens.expiresAt === void 0 ? null : new Date(e.tokens.expiresAt), r = {
4774
- id: A(qs, X),
4787
+ id: A(Xs, X),
4775
4788
  connectionId: e.definition.id,
4776
4789
  subjectId: e.subjectId,
4777
4790
  tenantId: e.tenantId,
4778
4791
  kind: e.definition.kind,
4779
4792
  status: "connected",
4780
- accessToken: pi(e.tokens.accessToken),
4781
- refreshToken: e.tokens.refreshToken === void 0 ? null : pi(e.tokens.refreshToken),
4793
+ accessToken: gi(e.tokens.accessToken),
4794
+ refreshToken: e.tokens.refreshToken === void 0 ? null : gi(e.tokens.refreshToken),
4782
4795
  expiresAt: n,
4783
4796
  scopes: e.tokens.scopes.length > 0 ? e.tokens.scopes.join(" ") : null,
4784
4797
  accountId: e.account?.accountId ?? null,
@@ -4789,8 +4802,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4789
4802
  connectedAt: t,
4790
4803
  updatedAt: t
4791
4804
  };
4792
- return lc(e.store, r);
4793
- }, lc = (e, t) => e.upsert(X, t, {
4805
+ return fc(e.store, r);
4806
+ }, fc = (e, t) => e.upsert(X, t, {
4794
4807
  conflictColumns: ["connectionId", "subjectId"],
4795
4808
  update: [
4796
4809
  "kind",
@@ -4806,10 +4819,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4806
4819
  "metadata",
4807
4820
  "updatedAt"
4808
4821
  ]
4809
- }), uc = async (e, t, n) => {
4810
- let r = await sc(e, t, n);
4822
+ }), pc = async (e, t, n) => {
4823
+ let r = await uc(e, t, n);
4811
4824
  return r !== void 0 && e.delete(X, r.id);
4812
- }, dc = async (e, t, n) => {
4825
+ }, mc = async (e, t, n) => {
4813
4826
  let r = await e.query({
4814
4827
  table: X,
4815
4828
  predicate: O("subjectId", n),
@@ -4818,9 +4831,9 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4818
4831
  skip: void 0,
4819
4832
  projection: void 0
4820
4833
  }), i = new Map(r.map((e) => [String(e.connectionId), e]));
4821
- return t.list().map((e) => oc(e, i.get(e.id)));
4822
- }, fc = (e, t) => globalThis.fetch(e, t), pc = async (e, t, n) => {
4823
- let r = e.fetchImpl ?? fc, i, a;
4834
+ return t.list().map((e) => lc(e, i.get(e.id)));
4835
+ }, hc = (e, t) => globalThis.fetch(e, t), gc = async (e, t, n) => {
4836
+ let r = e.fetchImpl ?? hc, i, a;
4824
4837
  try {
4825
4838
  let n = await r(e.tokenUrl, {
4826
4839
  method: "POST",
@@ -4860,62 +4873,62 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4860
4873
  ...Number.isFinite(o.expires_in) ? { expiresAt: n() + o.expires_in * 1e3 } : {},
4861
4874
  scopes: (o.scope ?? e.scopes?.join(" ") ?? "").split(" ").filter(Boolean)
4862
4875
  };
4863
- }, mc = (e, t, n = Date.now) => pc(e, {
4876
+ }, _c = (e, t, n = Date.now) => gc(e, {
4864
4877
  grant_type: "authorization_code",
4865
4878
  client_id: e.clientId,
4866
4879
  client_secret: e.clientSecret,
4867
4880
  code: t.code,
4868
4881
  redirect_uri: t.redirectUri,
4869
4882
  ...t.codeVerifier ? { code_verifier: t.codeVerifier } : {}
4870
- }, n), hc = (e, t, n = Date.now) => pc(e, {
4883
+ }, n), vc = (e, t, n = Date.now) => gc(e, {
4871
4884
  grant_type: "refresh_token",
4872
4885
  client_id: e.clientId,
4873
4886
  client_secret: e.clientSecret,
4874
4887
  refresh_token: t
4875
- }, n), gc = 6e4, _c = 3e4, vc = class extends Error {
4888
+ }, n), yc = 6e4, bc = 3e4, xc = class extends Error {
4876
4889
  connectionId;
4877
4890
  subjectId;
4878
4891
  _tag = "ConnectionNotConnected";
4879
4892
  constructor(e, t) {
4880
4893
  super(`connection "${e}" is not connected for this subject`), this.connectionId = e, this.subjectId = t, this.name = "ConnectionNotConnected";
4881
4894
  }
4882
- }, yc = (e) => new Promise((t) => {
4895
+ }, Sc = (e) => new Promise((t) => {
4883
4896
  setTimeout(t, e);
4884
- }), bc = /* @__PURE__ */ new Map(), xc = (e, t) => `${e}\u0000${t}`, Sc = () => {
4885
- bc.clear();
4886
- }, Cc = (e, t) => ({
4897
+ }), Cc = /* @__PURE__ */ new Map(), wc = (e, t) => `${e}\u0000${t}`, Tc = () => {
4898
+ Cc.clear();
4899
+ }, Ec = (e, t) => ({
4887
4900
  connectionId: e.id,
4888
4901
  kind: e.kind,
4889
- accessToken: mi(String(t.accessToken)),
4890
- expiresAt: rc(t.expiresAt),
4891
- scopes: ac(t.scopes),
4902
+ accessToken: _i(String(t.accessToken)),
4903
+ expiresAt: oc(t.expiresAt),
4904
+ scopes: cc(t.scopes),
4892
4905
  accountId: t.accountId ?? null,
4893
4906
  accountLabel: t.accountLabel ?? null
4894
- }), wc = (e, t, n) => {
4895
- let r = rc(e.expiresAt);
4907
+ }), Dc = (e, t, n) => {
4908
+ let r = oc(e.expiresAt);
4896
4909
  return r !== null && r.getTime() - n < t;
4897
- }, Tc = async (e) => {
4898
- let t = e.now ?? Date.now, { store: n, definition: r, subjectId: i } = e, a = await sc(n, r.id, i);
4899
- if (a === void 0) throw new vc(r.id, i);
4900
- if (r.kind === "pat" || !wc(a, r.refreshSkewMs ?? 6e4, t())) return Cc(r, a);
4901
- let o = xc(r.id, i), s = bc.get(o);
4910
+ }, Oc = async (e) => {
4911
+ let t = e.now ?? Date.now, { store: n, definition: r, subjectId: i } = e, a = await uc(n, r.id, i);
4912
+ if (a === void 0) throw new xc(r.id, i);
4913
+ if (r.kind === "pat" || !Dc(a, r.refreshSkewMs ?? 6e4, t())) return Ec(r, a);
4914
+ let o = wc(r.id, i), s = Cc.get(o);
4902
4915
  if (s !== void 0) return s;
4903
- let c = Ec({
4916
+ let c = kc({
4904
4917
  ...e,
4905
4918
  now: t,
4906
4919
  row: a
4907
4920
  }).finally(() => {
4908
- bc.delete(o);
4921
+ Cc.delete(o);
4909
4922
  });
4910
- return bc.set(o, c), c;
4911
- }, Ec = async (e) => {
4912
- let { store: t, subjectId: n, now: r } = e, i = e.definition, a = e.sleep ?? yc, o = i.refreshSkewMs ?? 6e4, s = e.row.id;
4923
+ return Cc.set(o, c), c;
4924
+ }, kc = async (e) => {
4925
+ let { store: t, subjectId: n, now: r } = e, i = e.definition, a = e.sleep ?? Sc, o = i.refreshSkewMs ?? 6e4, s = e.row.id;
4913
4926
  if (await t.updateMany("_voltro_connections", { refreshLockedUntil: new Date(r() + 3e4) }, { where: C(O("id", s), he("refreshLockedUntil", new Date(r()))) }) === 0) {
4914
4927
  for (let e = 0; e < 10; e++) {
4915
4928
  await a(200);
4916
- let e = await sc(t, i.id, n);
4917
- if (e === void 0) throw new vc(i.id, n);
4918
- if (!wc(e, o, r())) return Cc(i, e);
4929
+ let e = await uc(t, i.id, n);
4930
+ if (e === void 0) throw new xc(i.id, n);
4931
+ if (!Dc(e, o, r())) return Ec(i, e);
4919
4932
  }
4920
4933
  throw new R({
4921
4934
  connectionId: i.id,
@@ -4936,7 +4949,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4936
4949
  });
4937
4950
  let l;
4938
4951
  try {
4939
- l = await hc(i, mi(String(c)), r);
4952
+ l = await vc(i, _i(String(c)), r);
4940
4953
  } catch (e) {
4941
4954
  let n = e instanceof R ? e : new R({
4942
4955
  connectionId: i.id,
@@ -4949,11 +4962,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4949
4962
  refreshLockedUntil: /* @__PURE__ */ new Date(0),
4950
4963
  updatedAt: new Date(r()),
4951
4964
  ...n.transient ? {} : {
4952
- accessToken: pi(""),
4965
+ accessToken: gi(""),
4953
4966
  refreshToken: null,
4954
4967
  expiresAt: null
4955
4968
  }
4956
- }), Ks.warn("connection refresh failed", {
4969
+ }), Ys.warn("connection refresh failed", {
4957
4970
  connectionId: i.id,
4958
4971
  transient: n.transient,
4959
4972
  reason: n.reason
@@ -4961,40 +4974,40 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
4961
4974
  }
4962
4975
  let u = {
4963
4976
  status: "connected",
4964
- accessToken: pi(l.accessToken),
4965
- ...l.refreshToken === void 0 ? {} : { refreshToken: pi(l.refreshToken) },
4977
+ accessToken: gi(l.accessToken),
4978
+ ...l.refreshToken === void 0 ? {} : { refreshToken: gi(l.refreshToken) },
4966
4979
  expiresAt: l.expiresAt === void 0 ? null : new Date(l.expiresAt),
4967
4980
  ...l.scopes.length > 0 ? { scopes: l.scopes.join(" ") } : {},
4968
4981
  lastError: null,
4969
4982
  refreshLockedUntil: /* @__PURE__ */ new Date(0),
4970
4983
  updatedAt: new Date(r())
4971
4984
  };
4972
- return Cc(i, await t.update(X, s, u) ?? {
4985
+ return Ec(i, await t.update(X, s, u) ?? {
4973
4986
  ...e.row,
4974
4987
  ...u
4975
4988
  });
4976
- }, Dc = (e = 32) => {
4989
+ }, Ac = (e = 32) => {
4977
4990
  let t = new Uint8Array(e);
4978
4991
  return globalThis.crypto.getRandomValues(t), Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
4979
- }, Oc = (e) => {
4992
+ }, jc = (e) => {
4980
4993
  let t = "";
4981
4994
  for (let n of e) t += String.fromCharCode(n);
4982
4995
  return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
4983
- }, kc = async (e) => {
4996
+ }, Mc = async (e) => {
4984
4997
  let t = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
4985
- return Oc(new Uint8Array(t));
4986
- }, Ac = 10 * 6e4, jc = (e) => `/_voltro/connections/${e}/callback`, Mc = (e) => e === void 0 || e.length === 0 || !e.startsWith("/") || e.startsWith("//") || e.startsWith("/\\") ? "/" : e, Nc = (e, t) => e.redirectUri ?? `${t.replace(/\/+$/, "")}${jc(e.id)}`, Pc = async (e) => {
4987
- let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), { definition: n } = e, r = Dc(), i = n.pkce === !1 ? null : Dc(48), a = Nc(n, e.publicUrl);
4988
- await e.store.insert(Ys, {
4989
- id: A(Xs, Ys),
4998
+ return jc(new Uint8Array(t));
4999
+ }, Nc = 10 * 6e4, Pc = (e) => `/_voltro/connections/${e}/callback`, Fc = (e) => e === void 0 || e.length === 0 || !e.startsWith("/") || e.startsWith("//") || e.startsWith("/\\") ? "/" : e, Ic = (e, t) => e.redirectUri ?? `${t.replace(/\/+$/, "")}${Pc(e.id)}`, Lc = async (e) => {
5000
+ let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), { definition: n } = e, r = Ac(), i = n.pkce === !1 ? null : Ac(48), a = Ic(n, e.publicUrl);
5001
+ await e.store.insert(Qs, {
5002
+ id: A($s, Qs),
4990
5003
  state: r,
4991
5004
  connectionId: n.id,
4992
5005
  subjectId: e.subjectId,
4993
5006
  tenantId: e.tenantId,
4994
- codeVerifier: i === null ? null : pi(i),
4995
- redirectTo: Mc(e.redirectTo),
5007
+ codeVerifier: i === null ? null : gi(i),
5008
+ redirectTo: Fc(e.redirectTo),
4996
5009
  createdAt: t,
4997
- expiresAt: new Date(t.getTime() + Ac)
5010
+ expiresAt: new Date(t.getTime() + Nc)
4998
5011
  });
4999
5012
  let o = new URLSearchParams({
5000
5013
  response_type: "code",
@@ -5004,15 +5017,15 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5004
5017
  ...n.scopes && n.scopes.length > 0 ? { scope: n.scopes.join(" ") } : {},
5005
5018
  ...n.authorizeParams ?? {}
5006
5019
  });
5007
- i !== null && (o.set("code_challenge", await kc(i)), o.set("code_challenge_method", "S256"));
5020
+ i !== null && (o.set("code_challenge", await Mc(i)), o.set("code_challenge_method", "S256"));
5008
5021
  let s = n.authorizeUrl.includes("?") ? "&" : "?";
5009
5022
  return {
5010
5023
  authorizeUrl: `${n.authorizeUrl}${s}${o.toString()}`,
5011
5024
  state: r
5012
5025
  };
5013
- }, Fc = async (e) => {
5026
+ }, Rc = async (e) => {
5014
5027
  let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), n = (await e.store.query({
5015
- table: Ys,
5028
+ table: Qs,
5016
5029
  predicate: O("state", e.state),
5017
5030
  order: [],
5018
5031
  take: 1,
@@ -5024,8 +5037,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5024
5037
  reason: "unknown or already-used handshake state",
5025
5038
  transient: !1
5026
5039
  });
5027
- await e.store.delete(Ys, n.id);
5028
- let r = String(n.connectionId), i = rc(n.expiresAt);
5040
+ await e.store.delete(Qs, n.id);
5041
+ let r = String(n.connectionId), i = oc(n.expiresAt);
5029
5042
  if (i !== null && i.getTime() < t.getTime()) throw new R({
5030
5043
  connectionId: r,
5031
5044
  reason: "handshake expired — start again",
@@ -5037,17 +5050,17 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5037
5050
  reason: "no oauth2 connection is declared under that id",
5038
5051
  transient: !1
5039
5052
  });
5040
- let o = n.codeVerifier === null || n.codeVerifier === void 0 ? null : mi(String(n.codeVerifier)), s = await mc(a, {
5053
+ let o = n.codeVerifier === null || n.codeVerifier === void 0 ? null : _i(String(n.codeVerifier)), s = await _c(a, {
5041
5054
  code: e.code,
5042
- redirectUri: Nc(a, e.publicUrl),
5055
+ redirectUri: Ic(a, e.publicUrl),
5043
5056
  codeVerifier: o
5044
5057
  }, () => t.getTime()), c = a.identify === void 0 ? void 0 : await a.identify(s).catch((e) => {
5045
- Ks.warn("connection identify failed; storing without account details", {
5058
+ Ys.warn("connection identify failed; storing without account details", {
5046
5059
  connectionId: r,
5047
5060
  reason: String(e)
5048
5061
  });
5049
5062
  });
5050
- return await cc({
5063
+ return await dc({
5051
5064
  store: e.store,
5052
5065
  definition: a,
5053
5066
  subjectId: String(n.subjectId),
@@ -5057,11 +5070,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5057
5070
  now: () => t
5058
5071
  }), {
5059
5072
  connectionId: r,
5060
- redirectTo: Mc(String(n.redirectTo ?? "/"))
5073
+ redirectTo: Fc(String(n.redirectTo ?? "/"))
5061
5074
  };
5062
- }, Ic = async (e, t = /* @__PURE__ */ new Date()) => {
5075
+ }, zc = async (e, t = /* @__PURE__ */ new Date()) => {
5063
5076
  let n = await e.query({
5064
- table: Ys,
5077
+ table: Qs,
5065
5078
  predicate: he("expiresAt", t),
5066
5079
  order: [],
5067
5080
  take: void 0,
@@ -5070,27 +5083,27 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5070
5083
  }), r = 0;
5071
5084
  for (let t of n) await e.delete("_voltro_connection_grants", t.id) && r++;
5072
5085
  return r;
5073
- }, Lc, Rc = (e) => {
5074
- Lc = e;
5075
- }, zc = () => Lc, Bc = (e, t) => {
5076
- let n = Lc;
5086
+ }, Bc, Vc = (e) => {
5087
+ Bc = e;
5088
+ }, Hc = () => Bc, Uc = (e, t) => {
5089
+ let n = Bc;
5077
5090
  return n === void 0 ? Promise.reject(/* @__PURE__ */ Error(`resolveConnectionForSubject("${t}"): no connection vault is registered — the app declares no \`*.connection.ts\`, or this call ran before boot completed.`)) : n(e, t);
5078
- }, Vc = (e) => async (t, n) => {
5091
+ }, Wc = (e) => async (t, n) => {
5079
5092
  let r = e.registry.get(n);
5080
5093
  if (r === void 0) throw Error(`connection "${n}" is not declared. Declared: ${e.registry.list().map((e) => e.id).join(", ") || "(none)"}.`);
5081
5094
  let i = t.id ?? null;
5082
- if (i === null || i === "") throw new vc(n, "<anonymous>");
5083
- return Tc({
5095
+ if (i === null || i === "") throw new xc(n, "<anonymous>");
5096
+ return Oc({
5084
5097
  store: e.store,
5085
5098
  definition: r,
5086
5099
  subjectId: i
5087
5100
  });
5088
- }, Hc = (e) => {
5101
+ }, Gc = (e) => {
5089
5102
  let t = e.subject.id ?? null, n = async (n) => {
5090
5103
  let r = e.registry.get(n);
5091
5104
  if (r === void 0) throw Error(`ctx.connections.get("${n}"): no such connection is declared. Declared: ${e.registry.list().map((e) => e.id).join(", ") || "(none)"}.`);
5092
- if (t === null || t === "") throw new vc(n, "<anonymous>");
5093
- return Tc({
5105
+ if (t === null || t === "") throw new xc(n, "<anonymous>");
5106
+ return Oc({
5094
5107
  store: e.store,
5095
5108
  definition: r,
5096
5109
  subjectId: t
@@ -5102,7 +5115,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5102
5115
  try {
5103
5116
  return await n(e);
5104
5117
  } catch (e) {
5105
- if (e instanceof vc) return null;
5118
+ if (e instanceof xc) return null;
5106
5119
  throw e;
5107
5120
  }
5108
5121
  },
@@ -5117,17 +5130,17 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5117
5130
  expiresAt: null,
5118
5131
  lastError: null,
5119
5132
  connectedAt: null
5120
- })) : dc(e.store, e.registry, t)
5133
+ })) : mc(e.store, e.registry, t)
5121
5134
  };
5122
- }, Uc = (e, t) => {
5135
+ }, Kc = (e, t) => {
5123
5136
  let n = e.request?.subject?.id ?? null;
5124
5137
  if (n === null || n === "") throw new Je({ connectionId: t });
5125
5138
  return n;
5126
- }, Wc = (e, t) => {
5139
+ }, qc = (e, t) => {
5127
5140
  let n = e.registry.get(t);
5128
5141
  if (n === void 0) throw new qe({ connectionId: t });
5129
5142
  return n;
5130
- }, Gc = (e) => async (t, n) => {
5143
+ }, Jc = (e) => async (t, n) => {
5131
5144
  let r = n.request?.subject?.id ?? null;
5132
5145
  return r === null || r === "" ? e.registry.list().map((e) => ({
5133
5146
  connectionId: e.id,
@@ -5140,15 +5153,15 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5140
5153
  expiresAt: null,
5141
5154
  lastError: null,
5142
5155
  connectedAt: null
5143
- })) : dc(n.store, e.registry, r);
5144
- }, Kc = (e) => async (t, n) => {
5145
- let r = Wc(e, t.connectionId), i = Uc(n, t.connectionId);
5156
+ })) : mc(n.store, e.registry, r);
5157
+ }, Yc = (e) => async (t, n) => {
5158
+ let r = qc(e, t.connectionId), i = Kc(n, t.connectionId);
5146
5159
  if (r.kind !== "oauth2") throw new Ke({
5147
5160
  connectionId: t.connectionId,
5148
5161
  expected: "oauth2",
5149
5162
  actual: r.kind
5150
5163
  });
5151
- return Pc({
5164
+ return Lc({
5152
5165
  store: n.store,
5153
5166
  definition: r,
5154
5167
  subjectId: i,
@@ -5156,8 +5169,8 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5156
5169
  publicUrl: e.publicUrl,
5157
5170
  ...t.redirectTo === void 0 ? {} : { redirectTo: t.redirectTo }
5158
5171
  });
5159
- }, qc = (e) => async (t, n) => {
5160
- let r = Wc(e, t.connectionId), i = Uc(n, t.connectionId);
5172
+ }, Xc = (e) => async (t, n) => {
5173
+ let r = qc(e, t.connectionId), i = Kc(n, t.connectionId);
5161
5174
  if (r.kind !== "pat") throw new Ke({
5162
5175
  connectionId: t.connectionId,
5163
5176
  expected: "pat",
@@ -5179,7 +5192,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5179
5192
  transient: !1
5180
5193
  });
5181
5194
  }
5182
- return await cc({
5195
+ return await dc({
5183
5196
  store: n.store,
5184
5197
  definition: r,
5185
5198
  subjectId: i,
@@ -5190,20 +5203,20 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5190
5203
  },
5191
5204
  ...o === void 0 ? {} : { account: o }
5192
5205
  }), { ok: !0 };
5193
- }, Jc = (e) => async (t, n) => {
5194
- Wc(e, t.connectionId);
5195
- let r = Uc(n, t.connectionId);
5196
- return { ok: await uc(n.store, t.connectionId, r) };
5197
- }, Yc = "admin:full", Xc = class extends y.TaggedError()("AccessDenied", {
5206
+ }, Zc = (e) => async (t, n) => {
5207
+ qc(e, t.connectionId);
5208
+ let r = Kc(n, t.connectionId);
5209
+ return { ok: await pc(n.store, t.connectionId, r) };
5210
+ }, Qc = "admin:full", $c = class extends y.TaggedError()("AccessDenied", {
5198
5211
  action: y.String,
5199
5212
  resourceType: y.String,
5200
5213
  resourceId: y.String
5201
- }) {}, Zc = /* @__PURE__ */ new Map(), Qc = (e) => {
5214
+ }) {}, el = /* @__PURE__ */ new Map(), tl = (e) => {
5202
5215
  if (typeof e.resourceType != "string" || e.resourceType.length === 0) throw Error("defineResourcePolicy: a non-empty `resourceType` is required");
5203
5216
  if (e.actions === void 0 || Object.keys(e.actions).length === 0) throw Error(`resource policy '${e.resourceType}': at least one action is required`);
5204
- if (Zc.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
5205
- return Zc.set(e.resourceType, e), e;
5206
- }, $c = (e) => Zc.get(e), el = () => [...Zc.values()], tl = () => Zc.clear(), nl = () => el().map((e) => {
5217
+ if (el.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
5218
+ return el.set(e.resourceType, e), e;
5219
+ }, nl = (e) => el.get(e), rl = () => [...el.values()], il = () => el.clear(), al = () => rl().map((e) => {
5207
5220
  let t = /* @__PURE__ */ new Set();
5208
5221
  for (let n of Object.values(e.actions)) for (let e of n) t.add(e);
5209
5222
  for (let [n, r] of Object.entries(e.implies ?? {})) {
@@ -5216,7 +5229,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5216
5229
  relations: [...t],
5217
5230
  implies: e.implies ?? {}
5218
5231
  };
5219
- }), rl = (e, t) => {
5232
+ }), ol = (e, t) => {
5220
5233
  let n = new Set(e);
5221
5234
  if (t === void 0) return n;
5222
5235
  let r = [...e];
@@ -5225,39 +5238,39 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5225
5238
  for (let i of t[e] ?? []) n.has(i) || (n.add(i), r.push(i));
5226
5239
  }
5227
5240
  return n;
5228
- }, il = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : rl(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), al = (e, t, n, r) => {
5241
+ }, sl = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : ol(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), cl = (e, t, n, r) => {
5229
5242
  if (e.scopes?.includes("admin:full")) return !0;
5230
5243
  if (e.id === null || n.tenantId != null && e.tenantId !== n.tenantId) return !1;
5231
5244
  let i = r.policy.actions[t];
5232
5245
  if (i === void 0 || i.length === 0) return !1;
5233
- let a = il(e, n, r.tuples, r.policy);
5246
+ let a = sl(e, n, r.tuples, r.policy);
5234
5247
  return i.some((e) => a.has(e));
5235
- }, ol = (e, t, n, r) => {
5236
- if (!al(e, t, n, r)) throw new Xc({
5248
+ }, ll = (e, t, n, r) => {
5249
+ if (!cl(e, t, n, r)) throw new $c({
5237
5250
  action: t,
5238
5251
  resourceType: n.type,
5239
5252
  resourceId: n.id
5240
5253
  });
5241
- }, sl = (e, t, n, r, i) => r.filter((r) => al(e, t, {
5254
+ }, ul = (e, t, n, r, i) => r.filter((r) => cl(e, t, {
5242
5255
  type: n,
5243
5256
  id: r.id,
5244
5257
  ...r.tenantId === void 0 ? {} : { tenantId: r.tenantId }
5245
- }, i)), cl = (e, t) => {
5258
+ }, i)), dl = (e, t) => {
5246
5259
  let n = new Set(t.map((e) => e.id));
5247
5260
  return e.filter((e) => !n.has(e.id)).map((e) => e.id);
5248
- }, ll = new Lt(), ul = (e) => {
5249
- ll.enterWith(e);
5250
- }, dl = () => ll.getStore(), fl = (e, t) => ll.run(e, t), pl = z({ scope: "voltro:policy" }), ml, hl = (e) => {
5251
- ml = e;
5252
- }, gl = () => ml, _l = () => {
5261
+ }, fl = new Lt(), pl = (e) => {
5262
+ fl.enterWith(e);
5263
+ }, ml = () => fl.getStore(), hl = (e, t) => fl.run(e, t), gl = z({ scope: "voltro:policy" }), _l, vl = (e) => {
5264
+ _l = e;
5265
+ }, yl = () => _l, bl = () => {
5253
5266
  _t((e) => o.gen(function* () {
5254
- let t = $c(e.resourceType);
5255
- if (t === void 0) return pl.warn("policy guard denied — no resource policy registered for this type", {
5267
+ let t = nl(e.resourceType);
5268
+ if (t === void 0) return gl.warn("policy guard denied — no resource policy registered for this type", {
5256
5269
  resourceType: e.resourceType,
5257
5270
  action: e.action
5258
5271
  }), !1;
5259
- let n = ml;
5260
- if (n === void 0) return pl.warn("policy guard denied — no tuple source registered (call setTupleSource at boot)", {
5272
+ let n = _l;
5273
+ if (n === void 0) return gl.warn("policy guard denied — no tuple source registered (call setTupleSource at boot)", {
5261
5274
  resourceType: e.resourceType,
5262
5275
  action: e.action
5263
5276
  }), !1;
@@ -5266,14 +5279,14 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5266
5279
  subjectId: e.subject.id,
5267
5280
  resourceType: e.resourceType,
5268
5281
  resourceId: e.resourceId,
5269
- load: dl()
5282
+ load: ml()
5270
5283
  }),
5271
5284
  catch: (e) => e
5272
- }).pipe(o.catchAll((t) => (pl.error("policy guard denied — tuple source failed", {
5285
+ }).pipe(o.catchAll((t) => (gl.error("policy guard denied — tuple source failed", {
5273
5286
  resourceType: e.resourceType,
5274
5287
  resourceId: e.resourceId
5275
5288
  }, t), o.succeed([])))), i = e.subject;
5276
- return al({
5289
+ return cl({
5277
5290
  id: e.subject.id,
5278
5291
  tenantId: i.tenantId ?? null,
5279
5292
  ...i.scopes === void 0 ? {} : { scopes: i.scopes }
@@ -5286,10 +5299,10 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5286
5299
  tuples: r
5287
5300
  });
5288
5301
  }));
5289
- }, vl = (e) => {
5302
+ }, xl = (e) => {
5290
5303
  Promise.resolve().then(e);
5291
- }, yl = (e) => {
5292
- let t = e.schedule ?? vl, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => `${e}\u0000${t}`, a = async (t) => {
5304
+ }, Sl = (e) => {
5305
+ let t = e.schedule ?? xl, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => `${e}\u0000${t}`, a = async (t) => {
5293
5306
  let a = r.get(t);
5294
5307
  if (a === void 0) return;
5295
5308
  r.delete(t);
@@ -5335,23 +5348,23 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5335
5348
  load: async (e, t) => (await o(e, [t]))[0] ?? null,
5336
5349
  loadMany: (e, t) => o(e, t)
5337
5350
  };
5338
- }, bl = u.effect(Ct.HttpClient, o.map(Ct.HttpClient, (e) => e.pipe(Ct.mapRequestEffect((e) => o.currentSpan.pipe(o.map((t) => e.headers.traceparent === void 0 ? Tt.setHeader(e, "traceparent", ti({
5351
+ }, Cl = u.effect(Ct.HttpClient, o.map(Ct.HttpClient, (e) => e.pipe(Ct.mapRequestEffect((e) => o.currentSpan.pipe(o.map((t) => e.headers.traceparent === void 0 ? Tt.setHeader(e, "traceparent", ii({
5339
5352
  traceId: t.traceId,
5340
5353
  spanId: t.spanId,
5341
5354
  sampled: t.sampled
5342
- })) : e), o.catchAll(() => o.succeed(e))))))), xl = class extends Error {
5355
+ })) : e), o.catchAll(() => o.succeed(e))))))), wl = class extends Error {
5343
5356
  url;
5344
5357
  reason;
5345
5358
  _tag = "SsrfBlockedError";
5346
5359
  constructor(e, t) {
5347
5360
  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";
5348
5361
  }
5349
- }, Sl = (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, Cl = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), wl = (e, t, n) => n.some((n) => {
5362
+ }, Tl = (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, El = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), Dl = (e, t, n) => n.some((n) => {
5350
5363
  let r = n.trim().toLowerCase();
5351
5364
  if (r === "") return !1;
5352
5365
  let i = t === "" ? e : `${e}:${t}`;
5353
5366
  return r === e || r === i ? !0 : r.startsWith("*.") ? e.endsWith(r.slice(1)) : !1;
5354
- }), Tl = (e, t = {}) => {
5367
+ }), Ol = (e, t = {}) => {
5355
5368
  let n;
5356
5369
  try {
5357
5370
  n = new URL(e);
@@ -5360,30 +5373,30 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5360
5373
  }
5361
5374
  if (n.protocol !== "http:" && n.protocol !== "https:") return `blocked scheme "${n.protocol}"`;
5362
5375
  let r = n.hostname.replace(/^\[|\]$/g, "").toLowerCase();
5363
- if (wl(r, n.port, t.allowHosts ?? [])) return null;
5376
+ if (Dl(r, n.port, t.allowHosts ?? [])) return null;
5364
5377
  if (r === "localhost" || r.endsWith(".localhost") || r.endsWith(".internal") || r.endsWith(".local")) return `blocked host "${r}"`;
5365
5378
  let i = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(r);
5366
5379
  if (i) {
5367
5380
  let e = Number(i[1]), t = Number(i[2]);
5368
- return e > 255 || t > 255 || Number(i[3]) > 255 || Number(i[4]) > 255 ? "malformed ipv4 literal" : Sl(e, t) ? `blocked private/reserved address ${r}` : null;
5381
+ return e > 255 || t > 255 || Number(i[3]) > 255 || Number(i[4]) > 255 ? "malformed ipv4 literal" : Tl(e, t) ? `blocked private/reserved address ${r}` : null;
5369
5382
  }
5370
5383
  if (r.includes(":")) {
5371
5384
  let e = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(r);
5372
- return e ? Tl(`${n.protocol}//${e[1]}`, t) : Cl(r) ? `blocked private/reserved address ${r}` : null;
5385
+ return e ? Ol(`${n.protocol}//${e[1]}`, t) : El(r) ? `blocked private/reserved address ${r}` : null;
5373
5386
  }
5374
5387
  return null;
5375
- }, El = (e = {}) => u.effect(Ct.HttpClient, o.map(Ct.HttpClient, (t) => {
5388
+ }, kl = (e = {}) => u.effect(Ct.HttpClient, o.map(Ct.HttpClient, (t) => {
5376
5389
  let n = Ct.transform(t, (t, n) => o.suspend(() => {
5377
- let r = Tl(n.url, e);
5390
+ let r = Ol(n.url, e);
5378
5391
  return r === null ? t : o.fail(new wt.RequestError({
5379
5392
  request: n,
5380
5393
  reason: "Transport",
5381
- cause: new xl(n.url, r),
5394
+ cause: new wl(n.url, r),
5382
5395
  description: `SSRF policy: ${r}`
5383
5396
  }));
5384
5397
  }));
5385
5398
  return Ct.followRedirects(n, e.maxRedirects ?? 5);
5386
- })), Dl = (e) => {
5399
+ })), Al = (e) => {
5387
5400
  let t = e.now ?? Date.now, n = e.intervalMs ?? 3e4, r = e.maxPending ?? 500, i = /* @__PURE__ */ new Map(), a = !1, o = async () => {
5388
5401
  if (i.size === 0) return;
5389
5402
  let t = i;
@@ -5412,7 +5425,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5412
5425
  },
5413
5426
  pending: () => i.size
5414
5427
  };
5415
- }, Ol = "voltro/audit", kl = "voltro/softDelete", Al = "voltro/expires", jl = "voltro/tenant", Ml = (e) => {
5428
+ }, jl = "voltro/audit", Ml = "voltro/softDelete", Nl = "voltro/expires", Pl = "voltro/tenant", Fl = (e) => {
5416
5429
  let t = /* @__PURE__ */ new Map();
5417
5430
  for (let n of e) {
5418
5431
  let e = /* @__PURE__ */ new Set();
@@ -5458,17 +5471,17 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5458
5471
  return !1;
5459
5472
  },
5460
5473
  idScheme: (e) => t.get(e)?.idScheme,
5461
- defaultFactories: (e) => t.get(e)?.defaultFactories ?? Nl,
5462
- computedFields: (e) => t.get(e)?.computedFields ?? Pl,
5474
+ defaultFactories: (e) => t.get(e)?.defaultFactories ?? Il,
5475
+ computedFields: (e) => t.get(e)?.computedFields ?? Ll,
5463
5476
  versionColumn: (e) => t.get(e)?.versionColumn,
5464
- generatedColumns: (e) => t.get(e)?.generatedColumns ?? Fl,
5477
+ generatedColumns: (e) => t.get(e)?.generatedColumns ?? Rl,
5465
5478
  insertSchema: (e) => t.get(e)?.insertSchema,
5466
5479
  validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
5467
5480
  };
5468
- }, Nl = /* @__PURE__ */ new Map(), Pl = /* @__PURE__ */ new Map(), Fl = /* @__PURE__ */ new Set(), Il = Ml([]), Ll = z({ scope: "store.fieldEncryption" }), Rl = (e, t) => {
5481
+ }, Il = /* @__PURE__ */ new Map(), Ll = /* @__PURE__ */ new Map(), Rl = /* @__PURE__ */ new Set(), zl = Fl([]), Bl = z({ scope: "store.fieldEncryption" }), Vl = (e, t) => {
5469
5482
  let n = t, r = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", i = /* @__PURE__ */ new Set(), a = (e) => {
5470
5483
  let t = `${e.table}.${e.column}`;
5471
- i.has(t) || (i.add(t), Ll.warn("encrypted column degraded to null — could not decrypt with the active key", {
5484
+ i.has(t) || (i.add(t), Bl.warn("encrypted column degraded to null — could not decrypt with the active key", {
5472
5485
  table: e.table,
5473
5486
  column: e.column,
5474
5487
  reason: e.reason,
@@ -5492,7 +5505,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5492
5505
  e.injectExternalChange(t);
5493
5506
  },
5494
5507
  ...e.changeScope === void 0 ? {} : { changeScope: e.changeScope },
5495
- ...e.withNamespace === void 0 ? {} : { withNamespace: (n) => Rl(e.withNamespace(n), t) },
5508
+ ...e.withNamespace === void 0 ? {} : { withNamespace: (n) => Vl(e.withNamespace(n), t) },
5496
5509
  ...e.raw === void 0 ? {} : { raw: ((...t) => e.raw(...t)) },
5497
5510
  ...e.close === void 0 ? {} : { close: (t) => e.close(t) },
5498
5511
  ...e.ping === void 0 ? {} : { ping: () => e.ping() },
@@ -5504,24 +5517,24 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5504
5517
  upsert: async (t, n, r) => c(t, await e.upsert(t, o(t, n), r)),
5505
5518
  insertIgnore: async (t, n, r) => c(t, await e.insertIgnore(t, o(t, n), r)),
5506
5519
  patchJson: async (t, n, r, i) => c(t, await e.patchJson(t, n, r, i)),
5507
- transactional: (n) => e.transactional((e) => n(Rl(e, t)))
5520
+ transactional: (n) => e.transactional((e) => n(Vl(e, t)))
5508
5521
  };
5509
- }, zl = (e, t) => {
5522
+ }, Hl = (e, t) => {
5510
5523
  if (t === void 0 || t.length === 0) return e;
5511
5524
  let n = { ...e };
5512
5525
  for (let e of t) delete n[e];
5513
5526
  return n;
5514
- }, Bl = (e, t) => {
5527
+ }, Ul = (e, t) => {
5515
5528
  let n = j(e), r = n === void 0 ? [] : Oe(n);
5516
5529
  return r.length === 0 ? t ?? [] : t === void 0 ? r : [...t, ...r];
5517
- }, Vl = (e, t) => t.length === 0 ? e : e.map((e) => zl(e, t)), Hl = (e, t, n, r, i) => {
5530
+ }, Wl = (e, t) => t.length === 0 ? e : e.map((e) => Hl(e, t)), Gl = (e, t, n, r, i) => {
5518
5531
  let a = {
5519
5532
  ...t?.(r) ?? {},
5520
5533
  ...n?.(i) ?? {}
5521
5534
  }, o = e;
5522
5535
  for (let [e, t] of Object.entries(a)) t !== void 0 && (o = o.where(e, t));
5523
5536
  return o;
5524
- }, Ul = 1e3, Wl = (e, t = Ul) => {
5537
+ }, Kl = 1e3, ql = (e, t = Kl) => {
5525
5538
  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);
5526
5539
  if (i !== void 0) {
5527
5540
  let t = r(n(e.pageSize) ?? 100);
@@ -5534,35 +5547,35 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5534
5547
  limit: r(n(e.limit) ?? 100),
5535
5548
  offset: Math.max(0, Math.floor(n(e.offset) ?? 0))
5536
5549
  };
5537
- }, Gl = {
5550
+ }, Jl = {
5538
5551
  list: (e, t = {}) => async (n, r) => {
5539
5552
  let i = n ?? {}, a = r.store.select(e);
5540
5553
  if (t.columns !== void 0 && t.columns.length > 0) {
5541
- let n = new Set(Bl(e, void 0)), r = t.columns.filter((e) => !n.has(e));
5554
+ let n = new Set(Ul(e, void 0)), r = t.columns.filter((e) => !n.has(e));
5542
5555
  r.length > 0 && (a = a.select(...r));
5543
5556
  }
5544
- t.include !== void 0 && (a = a.with(t.include)), a = Hl(a, t.filter, t.scope, i, r);
5557
+ t.include !== void 0 && (a = a.with(t.include)), a = Gl(a, t.filter, t.scope, i, r);
5545
5558
  for (let e of t.sort ?? []) a = a.orderBy(e.column, e.direction ?? "asc");
5546
5559
  if (t.paginate === !0) {
5547
- let { limit: e, offset: n } = Wl(i, t.maxPageSize);
5560
+ let { limit: e, offset: n } = ql(i, t.maxPageSize);
5548
5561
  a = a.limit(e).offset(n);
5549
5562
  }
5550
- return Vl(await a.all(), Bl(e, t.redact));
5563
+ return Wl(await a.all(), Ul(e, t.redact));
5551
5564
  },
5552
5565
  getById: (e, t = {}) => async (n, r) => {
5553
5566
  let i = r.store.select(e).where("id", n.id);
5554
5567
  t.include !== void 0 && (i = i.with(t.include));
5555
5568
  let a = await i.first();
5556
- return a === null ? null : zl(a, Bl(e, t.redact));
5569
+ return a === null ? null : Hl(a, Ul(e, t.redact));
5557
5570
  },
5558
- create: (e, t = {}) => async (n, r) => zl(await r.store.insert(e, n), Bl(e, t.redact)),
5571
+ create: (e, t = {}) => async (n, r) => Hl(await r.store.insert(e, n), Ul(e, t.redact)),
5559
5572
  update: (e, t = {}) => async (n, r) => {
5560
5573
  let { id: i, ...a } = n, o = await r.store.update(e, i, a);
5561
- return o === null ? null : zl(o, Bl(e, t.redact));
5574
+ return o === null ? null : Hl(o, Ul(e, t.redact));
5562
5575
  },
5563
- count: (e, t = {}) => async (n, r) => Hl(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
5576
+ count: (e, t = {}) => async (n, r) => Gl(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
5564
5577
  remove: (e) => async (t, n) => ({ deleted: await n.store.delete(e, t.id) })
5565
- }, Kl = (e) => {
5578
+ }, Yl = (e) => {
5566
5579
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = (e) => {
5567
5580
  if (!n.has(e)) switch (n.add(e), e._tag) {
5568
5581
  case "TypeLiteral":
@@ -5589,7 +5602,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5589
5602
  }
5590
5603
  };
5591
5604
  return r(e.ast), t;
5592
- }, ql = (e) => {
5605
+ }, Xl = (e) => {
5593
5606
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = (e) => {
5594
5607
  switch (e._tag) {
5595
5608
  case "Literal": return e.literal === null;
@@ -5624,24 +5637,24 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5624
5637
  }
5625
5638
  };
5626
5639
  return i(e.ast), t;
5627
- }, Jl = (e, t) => {
5640
+ }, Zl = (e, t) => {
5628
5641
  let n = e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source];
5629
5642
  if (n.length === 0) return [];
5630
- let r = Kl(e.output), i = ql(e.output), a = [];
5643
+ let r = Yl(e.output), i = Xl(e.output), a = [];
5631
5644
  for (let o of n) for (let n of t.get(o) ?? []) r.has(n) && !i.has(n) && a.push({
5632
5645
  query: e.name,
5633
5646
  table: o,
5634
5647
  column: n
5635
5648
  });
5636
5649
  return a;
5637
- }, Yl = (e) => {
5650
+ }, Ql = (e) => {
5638
5651
  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.`;
5639
- }, Xl = (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) => ({
5652
+ }, $l = (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) => ({
5640
5653
  query: e.name,
5641
5654
  table: t
5642
- })) : [], Zl = (e) => {
5655
+ })) : [], eu = (e) => {
5643
5656
  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.`;
5644
- }, Ql = (e, t) => {
5657
+ }, tu = (e, t) => {
5645
5658
  let n, r = 0;
5646
5659
  for (let i of t) {
5647
5660
  let t = 0;
@@ -5652,7 +5665,7 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5652
5665
  o > r && o >= .6 && (r = o, n = i);
5653
5666
  }
5654
5667
  return n;
5655
- }, $l = (e, t) => {
5668
+ }, nu = (e, t) => {
5656
5669
  if (t.size === 0) return [];
5657
5670
  let n = [];
5658
5671
  for (let r of e) {
@@ -5661,11 +5674,11 @@ var K = /* @__PURE__ */ new Map(), Yr = (e, t) => {
5661
5674
  for (let i of e) t.has(i) || n.push({
5662
5675
  procedure: r.name,
5663
5676
  source: i,
5664
- didYouMean: Ql(i, t)
5677
+ didYouMean: tu(i, t)
5665
5678
  });
5666
5679
  }
5667
5680
  return n;
5668
- }, eu = (e) => {
5681
+ }, ru = (e) => {
5669
5682
  if (e.length === 0) return;
5670
5683
  let t = e.map((e) => ` ${e.procedure}: source '${e.source}' matches no declared table` + (e.didYouMean === void 0 ? "" : ` — did you mean '${e.didYouMean}'?`));
5671
5684
  return `${e.length} reactive source(s) name a table that does not exist:\n${t.join("\n")}\n
@@ -5674,77 +5687,78 @@ update again, which is indistinguishable from "nothing has changed" — so the
5674
5687
  symptom is silence, and silence is what this surface exists to eliminate.
5675
5688
  A \`source:\` is a STRING, so \`tsc\` cannot see a stale one and a rename leaves it
5676
5689
  behind quietly.`;
5677
- }, tu = (e) => e.op === "update" && (e.old?.deletedAt ?? null) === null && (e.new?.deletedAt ?? null) !== null, nu = (e, t) => {
5678
- let n = tu(t);
5690
+ }, iu = (e) => e.old ?? e.new ?? {}, au = (e) => String(iu(e).id ?? ""), ou = (e) => {
5691
+ let t = iu(e).tenantId;
5692
+ return typeof t == "string" ? t : null;
5693
+ }, su = (e) => e.op === "update" && (e.old?.deletedAt ?? null) === null && (e.new?.deletedAt ?? null) !== null, cu = (e, t) => {
5694
+ let n = su(t);
5679
5695
  return t.op !== "delete" && !n ? [] : e.filter((e) => e.targetTable === t.table && e.policy !== "keep" && (!n || e.onSoftDelete));
5680
- }, ru = async (e, t, n) => {
5681
- let r = nu(t, n);
5696
+ }, lu = async (e, t, n) => {
5697
+ let r = cu(t, n);
5682
5698
  if (r.length === 0) return [];
5683
- let i = [];
5699
+ let i = au(n), a = ou(n), o = [];
5684
5700
  for (let t of r) {
5685
- let r = await e.query({
5701
+ let n = await e.query({
5686
5702
  table: t.table,
5687
5703
  predicate: {
5688
5704
  kind: "eq",
5689
5705
  column: t.column,
5690
- value: n.rowId
5706
+ value: i
5691
5707
  },
5692
5708
  order: void 0,
5693
5709
  take: void 0,
5694
5710
  skip: void 0,
5695
5711
  projection: void 0
5696
- }), a = n.tenantId === null || n.tenantId === void 0 ? r : r.filter((e) => e.tenantId === n.tenantId);
5697
- for (let n of a) {
5712
+ }), r = a === null ? n : n.filter((e) => e.tenantId === a);
5713
+ for (let n of r) {
5698
5714
  let r = String(n.id);
5699
5715
  t.policy === "delete" ? await e.delete(t.table, r) : await e.update(t.table, r, { [t.column]: null });
5700
5716
  }
5701
- i.push({
5717
+ o.push({
5702
5718
  rule: t,
5703
- affected: a.length
5719
+ affected: r.length
5704
5720
  });
5705
5721
  }
5706
- return i;
5707
- }, iu = (e, t, n) => {
5708
- let r = [];
5709
- for (let i of e) for (let [e, a] of Object.entries(i.columns)) {
5710
- let o = t(a);
5711
- if (o === void 0) continue;
5712
- let s;
5722
+ return o;
5723
+ }, uu = (e, t) => {
5724
+ let n = [];
5725
+ for (let r of e) for (let e of r.appliedPluginRefs ?? []) {
5726
+ let i = e.column, a;
5713
5727
  try {
5714
- s = o.target()?.name;
5728
+ a = e.target()?.tableName;
5715
5729
  } catch {
5716
- s = void 0;
5717
- }
5718
- if (s === void 0 || !n.has(s)) throw Error(`pluginRef: ${i.name}.${e} points at ${s ?? "an unresolvable table"}, which no installed plugin registers. A declared orphan rule against an absent table would look enforced and never fire — install the plugin that owns it, or drop the column.`);
5719
- r.push({
5720
- table: i.name,
5721
- column: e,
5722
- targetTable: s,
5723
- policy: o.orphanPolicy,
5724
- onSoftDelete: o.onSoftDelete
5730
+ a = void 0;
5731
+ }
5732
+ if (a === void 0 || !t.has(a)) throw Error(`pluginRef: ${r.name}.${i} points at ${a ?? "an unresolvable table"}, which no installed plugin registers. A declared orphan rule against an absent table would look enforced and never fire — install the plugin that owns it, or drop the column.`);
5733
+ n.push({
5734
+ table: r.name,
5735
+ column: i,
5736
+ targetTable: a,
5737
+ policy: e.orphanPolicy,
5738
+ onSoftDelete: e.onSoftDelete
5725
5739
  });
5726
5740
  }
5727
- return r.filter((e) => e.policy !== "keep");
5728
- }, au = class extends y.TaggedError()("CircuitOpen", {
5741
+ return n.filter((e) => e.policy !== "keep");
5742
+ }, du = class extends y.TaggedError()("CircuitOpen", {
5729
5743
  name: y.String,
5730
5744
  retryAfterMs: y.Number
5731
- }) {}, ou = {
5745
+ }) {}, fu = {
5732
5746
  tag: "closed",
5733
5747
  failureCount: 0,
5734
5748
  halfOpenSuccesses: 0,
5735
5749
  openedAt: 0
5736
- }, su = { make: (n) => o.gen(function* () {
5737
- let r = n.name ?? "circuit", i = a.toMillis(a.decode(n.resetTimeout)), s = n.halfOpenSuccessThreshold ?? 1, c = n.isFailure ?? (() => !0), l = yield* _.make(ou), u = o.gen(function* () {
5750
+ }, pu = { make: (n) => o.gen(function* () {
5751
+ let r = n.name ?? "circuit", i = a.toMillis(a.decode(n.resetTimeout)), s = n.halfOpenSuccessThreshold ?? 1, c = n.isFailure ?? (() => !0), l = yield* _.make(fu), u = o.gen(function* () {
5738
5752
  let e = yield* _.get(l);
5739
5753
  if (e.tag === "half-open") {
5740
5754
  let t = e.halfOpenSuccesses + 1;
5741
- yield* _.set(l, t >= s ? ou : {
5755
+ yield* _.set(l, t >= s ? fu : {
5742
5756
  ...e,
5743
5757
  halfOpenSuccesses: t
5744
5758
  });
5745
5759
  return;
5746
5760
  }
5747
- e.failureCount !== 0 && (yield* _.set(l, ou));
5761
+ e.failureCount !== 0 && (yield* _.set(l, fu));
5748
5762
  }), d = o.gen(function* () {
5749
5763
  let e = yield* t.currentTimeMillis, r = yield* _.get(l);
5750
5764
  if (r.tag === "half-open" || r.tag === "open") {
@@ -5782,7 +5796,7 @@ behind quietly.`;
5782
5796
  if (e.isInterruptedOnly(t)) return o.void;
5783
5797
  let n = e.failureOption(t), r = n._tag === "Some" ? n.value : void 0;
5784
5798
  return c(r) ? d : o.void;
5785
- })) : yield* o.fail(new au({
5799
+ })) : yield* o.fail(new du({
5786
5800
  name: r,
5787
5801
  retryAfterMs: n
5788
5802
  }));
@@ -5791,25 +5805,25 @@ behind quietly.`;
5791
5805
  value: _.get(l).pipe(o.map((e) => e.tag)),
5792
5806
  enumerable: !0
5793
5807
  }), Object.defineProperty(m, "reset", {
5794
- value: _.set(l, ou),
5808
+ value: _.set(l, fu),
5795
5809
  enumerable: !0
5796
5810
  }), m;
5797
- }) }, cu, lu = (e) => {
5798
- cu = e;
5799
- }, uu = () => {
5800
- cu = void 0;
5801
- }, du = () => cu, fu = async (e, t = {}) => {
5802
- let n = t.scopes === void 0 ? vt(t.id ?? "system") : vt(t.id ?? "system", t.scopes), r = t.store ?? cu?.dataStore, i = t.schemaRegistry ?? cu?.schemaRegistry, a = t.dialect ?? cu?.dialect;
5811
+ }) }, mu, hu = (e) => {
5812
+ mu = e;
5813
+ }, gu = () => {
5814
+ mu = void 0;
5815
+ }, _u = () => mu, vu = async (e, t = {}) => {
5816
+ let n = t.scopes === void 0 ? vt(t.id ?? "system") : vt(t.id ?? "system", t.scopes), r = t.store ?? mu?.dataStore, i = t.schemaRegistry ?? mu?.schemaRegistry, a = t.dialect ?? mu?.dialect;
5803
5817
  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.");
5804
5818
  return e({
5805
5819
  subject: n,
5806
- store: Gi(r, {
5820
+ store: Ji(r, {
5807
5821
  subject: n,
5808
5822
  schemaRegistry: i,
5809
5823
  ...a === void 0 ? {} : { dialect: a }
5810
5824
  })
5811
5825
  });
5812
- }, pu = (e) => {
5826
+ }, yu = (e) => {
5813
5827
  let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
5814
5828
  if (t === void 0) return {
5815
5829
  sameRegion: [],
@@ -5837,7 +5851,7 @@ behind quietly.`;
5837
5851
  return r.loadSnapshot();
5838
5852
  }
5839
5853
  };
5840
- }, mu = (e = process.env) => {
5854
+ }, bu = (e = process.env) => {
5841
5855
  for (let t of [
5842
5856
  "VOLTRO_REGION",
5843
5857
  "AWS_REGION",
@@ -5849,7 +5863,7 @@ behind quietly.`;
5849
5863
  let n = e[t];
5850
5864
  if (typeof n == "string" && n.length > 0) return n;
5851
5865
  }
5852
- }, hu = () => {
5866
+ }, xu = () => {
5853
5867
  let e = {
5854
5868
  primary: 0,
5855
5869
  lagByReplica: /* @__PURE__ */ new Map()
@@ -5874,7 +5888,7 @@ behind quietly.`;
5874
5888
  e.lagByReplica.set(t, n);
5875
5889
  }
5876
5890
  };
5877
- }, gu = Symbol.for("@voltro/ScheduleDefinition"), _u = (e) => typeof e == "object" && !!e && gu in e, vu = 30 * 6e4, yu = (e) => {
5891
+ }, Su = Symbol.for("@voltro/ScheduleDefinition"), Cu = (e) => typeof e == "object" && !!e && Su in e, wu = 30 * 6e4, Tu = (e) => {
5878
5892
  let t = r.parse(e.cron, e.timezone);
5879
5893
  if (s.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
5880
5894
  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.`);
@@ -5883,18 +5897,18 @@ behind quietly.`;
5883
5897
  ...e,
5884
5898
  onOverlap: e.onOverlap ?? "skip",
5885
5899
  backfill: e.backfill ?? "skip",
5886
- maxRuntimeMs: e.maxRuntimeMs ?? vu,
5887
- [gu]: !0
5900
+ maxRuntimeMs: e.maxRuntimeMs ?? wu,
5901
+ [Su]: !0
5888
5902
  };
5889
- }, bu = (e) => r.unsafeParse(e.cron, e.timezone), xu = (e, t = /* @__PURE__ */ new Date()) => r.next(bu(e), t), Z = "_voltro_wakeups", Su = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Cu = (e) => ({
5903
+ }, Eu = (e) => r.unsafeParse(e.cron, e.timezone), Du = (e, t = /* @__PURE__ */ new Date()) => r.next(Eu(e), t), Z = "_voltro_wakeups", Ou = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, ku = (e) => ({
5890
5904
  tenantId: String(e.tenantId),
5891
5905
  kind: String(e.kind),
5892
5906
  refId: String(e.refId),
5893
5907
  wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
5894
5908
  status: e.status === "fired" ? "fired" : "pending"
5895
- }), wu = async (e, t) => {
5909
+ }), Au = async (e, t) => {
5896
5910
  await e.upsert(Z, {
5897
- id: Su(t),
5911
+ id: Ou(t),
5898
5912
  tenantId: t.tenantId,
5899
5913
  kind: t.kind,
5900
5914
  refId: t.refId,
@@ -5904,7 +5918,7 @@ behind quietly.`;
5904
5918
  conflictColumns: ["id"],
5905
5919
  update: ["wakeAt", "status"]
5906
5920
  });
5907
- }, Tu = async (e, t) => e.delete(Z, Su(t)), Eu = async (e, t) => await e.update(Z, Su(t), { status: "fired" }) !== null, Du = (e, t) => ({ and: [{
5921
+ }, ju = async (e, t) => e.delete(Z, Ou(t)), Mu = async (e, t) => await e.update(Z, Ou(t), { status: "fired" }) !== null, Nu = (e, t) => ({ and: [{
5908
5922
  column: "id",
5909
5923
  op: "eq",
5910
5924
  value: e
@@ -5912,16 +5926,16 @@ behind quietly.`;
5912
5926
  column: "status",
5913
5927
  op: "eq",
5914
5928
  value: t
5915
- }] }), Ou = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: Du(Su(t), "pending") }) > 0, ku = async (e, t) => {
5916
- await e.updateMany(Z, { status: "pending" }, { where: Du(Su(t), "fired") });
5917
- }, Au = {
5929
+ }] }), Pu = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: Nu(Ou(t), "pending") }) > 0, Fu = async (e, t) => {
5930
+ await e.updateMany(Z, { status: "pending" }, { where: Nu(Ou(t), "fired") });
5931
+ }, Iu = {
5918
5932
  column: "status",
5919
5933
  op: "eq",
5920
5934
  value: "pending"
5921
- }, ju = async (e, t) => {
5935
+ }, Lu = async (e, t) => {
5922
5936
  let n = {
5923
5937
  table: Z,
5924
- predicate: Au,
5938
+ predicate: Iu,
5925
5939
  order: [{
5926
5940
  column: "wakeAt",
5927
5941
  direction: "asc"
@@ -5930,18 +5944,18 @@ behind quietly.`;
5930
5944
  skip: void 0,
5931
5945
  projection: void 0
5932
5946
  };
5933
- return (await e.query(n)).map(Cu);
5934
- }, Mu = async (e, t, n = 500) => {
5935
- let r = await ju(e, n), i = t.getTime();
5947
+ return (await e.query(n)).map(ku);
5948
+ }, Ru = async (e, t, n = 500) => {
5949
+ let r = await Lu(e, n), i = t.getTime();
5936
5950
  return r.filter((e) => e.wakeAt.getTime() <= i);
5937
- }, Nu = async (e) => (await ju(e, 1))[0] ?? null, Pu = {
5951
+ }, zu = async (e) => (await Lu(e, 1))[0] ?? null, Bu = {
5938
5952
  column: "status",
5939
5953
  op: "eq",
5940
5954
  value: "fired"
5941
- }, Fu = async (e, t = {}) => {
5955
+ }, Vu = async (e, t = {}) => {
5942
5956
  let n = {
5943
5957
  table: Z,
5944
- predicate: Pu,
5958
+ predicate: Bu,
5945
5959
  order: [{
5946
5960
  column: "wakeAt",
5947
5961
  direction: "asc"
@@ -5952,12 +5966,12 @@ behind quietly.`;
5952
5966
  }, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
5953
5967
  for (let t of r) i !== void 0 && (t.wakeAt instanceof Date ? t.wakeAt : new Date(String(t.wakeAt))).getTime() >= i || await e.delete(Z, String(t.id)) && a++;
5954
5968
  return a;
5955
- }, Iu = zo, Lu = "default", Ru = {
5969
+ }, Hu = Ho, Uu = "default", Wu = {
5956
5970
  kind: "single",
5957
5971
  tryClaim: async () => !0
5958
- }, zu = "_voltro_schedule_claims", Bu = (e, t, n) => {
5972
+ }, Gu = "_voltro_schedule_claims", Ku = (e, t, n) => {
5959
5973
  let r = async (t) => (await e.query({
5960
- table: zu,
5974
+ table: Gu,
5961
5975
  order: [],
5962
5976
  predicate: void 0,
5963
5977
  projection: ["id"],
@@ -5972,7 +5986,7 @@ behind quietly.`;
5972
5986
  if (await r(s)) return !1;
5973
5987
  } catch {}
5974
5988
  try {
5975
- return await e.insert(zu, {
5989
+ return await e.insert(Gu, {
5976
5990
  id: s,
5977
5991
  scheduleName: i,
5978
5992
  bucket: o,
@@ -5990,12 +6004,12 @@ behind quietly.`;
5990
6004
  }
5991
6005
  }
5992
6006
  };
5993
- }, Vu = "_voltro_schedule_runs", Hu = async (e, t) => {
6007
+ }, qu = "_voltro_schedule_runs", Ju = async (e, t) => {
5994
6008
  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) => {
5995
- c?.(e, Wu(t));
6009
+ c?.(e, Xu(t));
5996
6010
  }, v = async (e, t, r, i, a, c) => {
5997
6011
  try {
5998
- let s = `sr_${Re()}`, l = await n.insert(Vu, {
6012
+ let s = `sr_${Re()}`, l = await n.insert(qu, {
5999
6013
  id: s,
6000
6014
  name: e.name,
6001
6015
  status: i,
@@ -6020,7 +6034,7 @@ behind quietly.`;
6020
6034
  }
6021
6035
  }, y = async (e, t) => {
6022
6036
  try {
6023
- let r = await n.update(Vu, e, t);
6037
+ let r = await n.update(qu, e, t);
6024
6038
  r && _("update", r);
6025
6039
  } catch (t) {
6026
6040
  s.warn("schedule: failed to record run finish", {
@@ -6031,7 +6045,7 @@ behind quietly.`;
6031
6045
  }, b = async (e) => {
6032
6046
  try {
6033
6047
  let t = await n.query({
6034
- table: Vu,
6048
+ table: qu,
6035
6049
  predicate: {
6036
6050
  _tag: "leaf",
6037
6051
  column: "status",
@@ -6066,7 +6080,7 @@ behind quietly.`;
6066
6080
  scheduleName: e.name,
6067
6081
  trigger: n,
6068
6082
  runId: o,
6069
- subject: Iu
6083
+ subject: Hu
6070
6084
  })
6071
6085
  };
6072
6086
  try {
@@ -6102,7 +6116,7 @@ behind quietly.`;
6102
6116
  let n = Q(t).includes("exceeded maxRuntimeMs"), r = xn(t).dbMessage, i = typeof r == "string" && r !== "" ? `${Q(t)} — ${r}` : Q(t);
6103
6117
  o && await y(o, {
6104
6118
  status: "failed",
6105
- errorTag: n ? "timeout" : Uu(t),
6119
+ errorTag: n ? "timeout" : Yu(t),
6106
6120
  errorMessage: i,
6107
6121
  completedAt: /* @__PURE__ */ new Date(),
6108
6122
  durationMs: Date.now() - c
@@ -6166,8 +6180,8 @@ behind quietly.`;
6166
6180
  }
6167
6181
  }, w = async (e) => {
6168
6182
  try {
6169
- let t = r.next(bu(e), /* @__PURE__ */ new Date());
6170
- await wu(n, {
6183
+ let t = r.next(Eu(e), /* @__PURE__ */ new Date());
6184
+ await Au(n, {
6171
6185
  tenantId: d,
6172
6186
  kind: "schedule",
6173
6187
  refId: e.name,
@@ -6181,7 +6195,7 @@ behind quietly.`;
6181
6195
  }
6182
6196
  }, T = 2147483647, E = (e) => {
6183
6197
  if (h) return;
6184
- let n = bu(e), i = r.next(n, /* @__PURE__ */ new Date()), a = () => {
6198
+ let n = Eu(e), i = r.next(n, /* @__PURE__ */ new Date()), a = () => {
6185
6199
  if (h) return;
6186
6200
  let n = i.getTime() - Date.now();
6187
6201
  if (n > T) {
@@ -6203,7 +6217,7 @@ behind quietly.`;
6203
6217
  let i;
6204
6218
  try {
6205
6219
  let t = (await n.query({
6206
- table: Vu,
6220
+ table: qu,
6207
6221
  order: [{
6208
6222
  column: "scheduledAt",
6209
6223
  direction: "desc"
@@ -6222,7 +6236,7 @@ behind quietly.`;
6222
6236
  return;
6223
6237
  }
6224
6238
  if (!i) return;
6225
- let a = bu(e), o = [], c = r.next(a, i), l = Date.now();
6239
+ let a = Eu(e), o = [], c = r.next(a, i), l = Date.now();
6226
6240
  for (; c.getTime() < l && o.length < 1e3;) o.push(c), c = r.next(a, c);
6227
6241
  if (o.length !== 0) if (s.info("schedule: backfill", {
6228
6242
  name: e.name,
@@ -6267,11 +6281,11 @@ behind quietly.`;
6267
6281
  f.clear(), s.info("scheduler: stopped");
6268
6282
  }
6269
6283
  };
6270
- }, Q = (e) => e?.message ?? String(e), Uu = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Wu = (e) => {
6284
+ }, Q = (e) => e?.message ?? String(e), Yu = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Xu = (e) => {
6271
6285
  let t = {};
6272
6286
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
6273
6287
  return t;
6274
- }, Gu = (e, t, n, r) => {
6288
+ }, Zu = (e, t, n, r) => {
6275
6289
  let i = !1, a, o = async () => {
6276
6290
  if (i) return;
6277
6291
  let a = new Date(Math.floor(Date.now() / t) * t), o = !1;
@@ -6301,7 +6315,7 @@ behind quietly.`;
6301
6315
  i || (i = !0, a && clearInterval(a), a = void 0);
6302
6316
  }
6303
6317
  };
6304
- }, Ku = (e) => (t, n, r) => Gu(t, n, r, e), qu = F("_voltro_schedule_runs", {
6318
+ }, Qu = (e) => (t, n, r) => Zu(t, n, r, e), $u = F("_voltro_schedule_runs", {
6305
6319
  id: M({ prefix: "schrun" }),
6306
6320
  name: I(),
6307
6321
  status: I().oneOf([
@@ -6331,13 +6345,13 @@ behind quietly.`;
6331
6345
  ]).nullable(),
6332
6346
  replicaId: I().nullable(),
6333
6347
  result: P().nullable()
6334
- }).index(["name", "scheduledAt"]).index(["status"]), Ju = F("_voltro_schedule_claims", {
6348
+ }).index(["name", "scheduledAt"]).index(["status"]), ed = F("_voltro_schedule_claims", {
6335
6349
  id: M({ prefix: "schclaim" }),
6336
6350
  scheduleName: I(),
6337
6351
  bucket: I(),
6338
6352
  claimedBy: I(),
6339
6353
  claimedAt: L()
6340
- }).index(["scheduleName", "bucket"]).index(["claimedAt"]), Yu = F("_voltro_traces", {
6354
+ }).index(["scheduleName", "bucket"]).index(["claimedAt"]), td = F("_voltro_traces", {
6341
6355
  id: M({ prefix: "span" }),
6342
6356
  traceId: I(),
6343
6357
  spanId: I(),
@@ -6361,7 +6375,7 @@ behind quietly.`;
6361
6375
  durationMs: N(),
6362
6376
  attributes: P().nullable(),
6363
6377
  events: P().nullable()
6364
- }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Xu = F("_voltro_undo_log", {
6378
+ }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), nd = F("_voltro_undo_log", {
6365
6379
  id: M({ prefix: "undo" }),
6366
6380
  tag: I(),
6367
6381
  label: I().nullable(),
@@ -6372,25 +6386,25 @@ behind quietly.`;
6372
6386
  crossesAction: E().default(!1),
6373
6387
  undone: E().default(!1),
6374
6388
  createdAt: L().default("now")
6375
- }).index(["subjectId", "createdAt"]), Zu = (e = process.env) => {
6389
+ }).index(["subjectId", "createdAt"]), rd = (e = process.env) => {
6376
6390
  let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
6377
6391
  return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
6378
- }, Qu = (e) => e.startsWith("_voltro"), $u = async (e, t, n) => (await e.query({
6392
+ }, id = (e) => e.startsWith("_voltro"), ad = async (e, t, n) => (await e.query({
6379
6393
  table: t,
6380
6394
  predicate: O("id", n),
6381
6395
  order: []
6382
- }))[0] ?? null, ed = (e, t) => new Proxy(e, { get(e, n, r) {
6396
+ }))[0] ?? null, od = (e, t) => new Proxy(e, { get(e, n, r) {
6383
6397
  if (n === "insert") return async (n, r) => {
6384
6398
  let i = await e.insert(n, r);
6385
- return Qu(n) || t({
6399
+ return id(n) || t({
6386
6400
  table: n,
6387
6401
  op: "insert",
6388
6402
  next: i
6389
6403
  }), i;
6390
6404
  };
6391
6405
  if (n === "update") return async (n, r, i) => {
6392
- let a = Qu(n) ? null : await $u(e, n, r), o = await e.update(n, r, i);
6393
- return Qu(n) || t({
6406
+ let a = id(n) ? null : await ad(e, n, r), o = await e.update(n, r, i);
6407
+ return id(n) || t({
6394
6408
  table: n,
6395
6409
  op: "update",
6396
6410
  id: r,
@@ -6399,8 +6413,8 @@ behind quietly.`;
6399
6413
  }), o;
6400
6414
  };
6401
6415
  if (n === "delete") return async (n, r) => {
6402
- let i = Qu(n) ? null : await $u(e, n, r), a = await e.delete(n, r);
6403
- return !Qu(n) && a && t({
6416
+ let i = id(n) ? null : await ad(e, n, r), a = await e.delete(n, r);
6417
+ return !id(n) && a && t({
6404
6418
  table: n,
6405
6419
  op: "delete",
6406
6420
  id: r,
@@ -6409,10 +6423,10 @@ behind quietly.`;
6409
6423
  };
6410
6424
  let i = Reflect.get(e, n, r);
6411
6425
  return typeof i == "function" ? i.bind(e) : i;
6412
- } }), td = (e) => {
6426
+ } }), sd = (e) => {
6413
6427
  let t = [];
6414
6428
  return {
6415
- tx: ed(e, (e) => t.push(e)),
6429
+ tx: od(e, (e) => t.push(e)),
6416
6430
  persist: async (e, n) => {
6417
6431
  if (t.length === 0 || n.tag.startsWith("__voltro")) return;
6418
6432
  let r = n.subject;
@@ -6428,14 +6442,14 @@ behind quietly.`;
6428
6442
  });
6429
6443
  }
6430
6444
  };
6431
- }, nd = (e) => {
6445
+ }, cd = (e) => {
6432
6446
  if (e.id !== void 0) return e.id;
6433
6447
  let t = e.next?.id;
6434
6448
  if (typeof t == "string") return t;
6435
6449
  let n = e.prev?.id;
6436
6450
  return typeof n == "string" ? n : void 0;
6437
- }, rd = (e) => {
6438
- let t = nd(e);
6451
+ }, ld = (e) => {
6452
+ let t = cd(e);
6439
6453
  switch (e.op) {
6440
6454
  case "insert": return t === void 0 ? null : {
6441
6455
  table: e.table,
@@ -6459,28 +6473,28 @@ behind quietly.`;
6459
6473
  row: e.prev
6460
6474
  };
6461
6475
  }
6462
- }, id = (e) => {
6463
- if (e.crossesAction) throw new ad(e.invocationId, "action");
6476
+ }, ud = (e) => {
6477
+ if (e.crossesAction) throw new dd(e.invocationId, "action");
6464
6478
  let t = [];
6465
6479
  for (let n = e.changes.length - 1; n >= 0; --n) {
6466
- let r = rd(e.changes[n]);
6480
+ let r = ld(e.changes[n]);
6467
6481
  r !== null && t.push(r);
6468
6482
  }
6469
6483
  return t;
6470
- }, ad = class extends Error {
6484
+ }, dd = class extends Error {
6471
6485
  invocationId;
6472
6486
  boundary;
6473
6487
  _tag = "UndoBoundaryError";
6474
6488
  constructor(e, t) {
6475
6489
  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";
6476
6490
  }
6477
- }, od = (e, t, n = ["updatedAt", "updatedBy"]) => {
6491
+ }, fd = (e, t, n = ["updatedAt", "updatedBy"]) => {
6478
6492
  if (t == null) return e == null;
6479
6493
  if (e == null) return !1;
6480
6494
  let r = new Set(n);
6481
6495
  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;
6482
6496
  return !0;
6483
- }, sd = class {
6497
+ }, pd = class {
6484
6498
  capacity;
6485
6499
  done = [];
6486
6500
  undone = [];
@@ -6516,7 +6530,7 @@ behind quietly.`;
6516
6530
  redo: [...this.undone]
6517
6531
  };
6518
6532
  }
6519
- }, cd = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
6533
+ }, md = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
6520
6534
  table: e.table,
6521
6535
  op: "insert",
6522
6536
  next: e.new ?? null
@@ -6533,7 +6547,7 @@ behind quietly.`;
6533
6547
  table: e.table,
6534
6548
  op: "delete",
6535
6549
  prev: e.old ?? null
6536
- }, ld = async (e, t) => {
6550
+ }, hd = async (e, t) => {
6537
6551
  switch (t.op) {
6538
6552
  case "delete":
6539
6553
  await e.delete(t.table, t.id);
@@ -6551,21 +6565,21 @@ behind quietly.`;
6551
6565
  await e.insert(t.table, t.row);
6552
6566
  return;
6553
6567
  }
6554
- }, ud = async (e, t) => {
6555
- for (let n of t) await ld(e, n);
6556
- }, dd = (e) => e.request?.subject?.id ?? null, fd = (e) => e === !0 || e === 1, pd = async (e, t, n) => (await e.query({
6568
+ }, gd = async (e, t) => {
6569
+ for (let n of t) await hd(e, n);
6570
+ }, _d = (e) => e.request?.subject?.id ?? null, vd = (e) => e === !0 || e === 1, yd = async (e, t, n) => (await e.query({
6557
6571
  table: t,
6558
6572
  predicate: O("id", n),
6559
6573
  order: []
6560
- }))[0] ?? null, md = (e) => {
6574
+ }))[0] ?? null, bd = (e) => {
6561
6575
  try {
6562
6576
  let t = JSON.parse(String(e ?? "[]"));
6563
6577
  return Array.isArray(t) ? t : [];
6564
6578
  } catch {
6565
6579
  return [];
6566
6580
  }
6567
- }, hd = (e) => e.id ?? e.next?.id ?? e.prev?.id, gd = async (e, t) => {
6568
- let n = dd(t);
6581
+ }, xd = (e) => e.id ?? e.next?.id ?? e.prev?.id, Sd = async (e, t) => {
6582
+ let n = _d(t);
6569
6583
  return [...await t.store.query({
6570
6584
  table: "_voltro_undo_log",
6571
6585
  predicate: O("subjectId", n),
@@ -6574,68 +6588,68 @@ behind quietly.`;
6574
6588
  id: String(e.id),
6575
6589
  tag: String(e.tag ?? ""),
6576
6590
  label: e.label ?? null,
6577
- undone: fd(e.undone),
6578
- crossesAction: fd(e.crossesAction),
6591
+ undone: vd(e.undone),
6592
+ crossesAction: vd(e.crossesAction),
6579
6593
  createdAt: String(e.createdAt ?? "")
6580
6594
  }));
6581
- }, _d = async (e, t) => {
6582
- let n = await pd(t.store, "_voltro_undo_log", e.invocationId);
6595
+ }, Cd = async (e, t) => {
6596
+ let n = await yd(t.store, "_voltro_undo_log", e.invocationId);
6583
6597
  if (!n) throw new rt({ invocationId: e.invocationId });
6584
- if ((n.subjectId ?? null) !== dd(t)) throw new nt({ invocationId: e.invocationId });
6598
+ if ((n.subjectId ?? null) !== _d(t)) throw new nt({ invocationId: e.invocationId });
6585
6599
  return n;
6586
- }, vd = async (e, t) => {
6587
- let n = await _d(e, t);
6588
- if (fd(n.undone)) return { ok: !0 };
6589
- if (fd(n.crossesAction)) throw new tt({
6600
+ }, wd = async (e, t) => {
6601
+ let n = await Cd(e, t);
6602
+ if (vd(n.undone)) return { ok: !0 };
6603
+ if (vd(n.crossesAction)) throw new tt({
6590
6604
  invocationId: e.invocationId,
6591
6605
  reason: "action"
6592
6606
  });
6593
- let r = md(n.changes);
6607
+ let r = bd(n.changes);
6594
6608
  for (let n of r) {
6595
- let r = hd(n);
6596
- if (r !== void 0 && !od(await pd(t.store, n.table, r), n.next ?? null)) throw new tt({
6609
+ let r = xd(n);
6610
+ if (r !== void 0 && !fd(await yd(t.store, n.table, r), n.next ?? null)) throw new tt({
6597
6611
  invocationId: e.invocationId,
6598
6612
  reason: "conflict"
6599
6613
  });
6600
6614
  }
6601
6615
  let i = {
6602
6616
  invocationId: e.invocationId,
6603
- subject: dd(t),
6617
+ subject: _d(t),
6604
6618
  changes: r,
6605
6619
  crossesAction: !1
6606
6620
  };
6607
- return await ud(t.store, id(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
6608
- }, yd = async (e, t) => {
6609
- let n = await _d(e, t);
6610
- if (!fd(n.undone)) return { ok: !0 };
6611
- for (let e of md(n.changes)) {
6612
- let n = hd(e);
6621
+ return await gd(t.store, ud(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
6622
+ }, Td = async (e, t) => {
6623
+ let n = await Cd(e, t);
6624
+ if (!vd(n.undone)) return { ok: !0 };
6625
+ for (let e of bd(n.changes)) {
6626
+ let n = xd(e);
6613
6627
  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);
6614
6628
  }
6615
6629
  return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
6616
- }, bd = (e = process.env) => {
6630
+ }, Ed = (e = process.env) => {
6617
6631
  let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
6618
6632
  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";
6619
- }, xd = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, Sd = "«redacted»", Cd = (e) => {
6633
+ }, Dd = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, Od = "«redacted»", kd = (e) => {
6620
6634
  if (e == null) return null;
6621
6635
  let t = {};
6622
- for (let [n, r] of Object.entries(e)) t[n] = xd.test(n) ? Sd : r;
6636
+ for (let [n, r] of Object.entries(e)) t[n] = Dd.test(n) ? Od : r;
6623
6637
  return t;
6624
- }, wd = (e) => {
6638
+ }, Ad = (e) => {
6625
6639
  let t = e?.id;
6626
6640
  return typeof t == "string" ? t : void 0;
6627
- }, Td = (e, t) => {
6641
+ }, jd = (e, t) => {
6628
6642
  if (t.op === "insert") {
6629
- let n = wd(t.new);
6643
+ let n = Ad(t.new);
6630
6644
  return n === void 0 ? e : e.filter((e) => e.id !== n);
6631
6645
  }
6632
6646
  if (t.op === "update") {
6633
6647
  if (t.old == null) return e;
6634
- let n = wd(t.new) ?? wd(t.old);
6648
+ let n = Ad(t.new) ?? Ad(t.old);
6635
6649
  return e.map((e) => e.id === n ? t.old : e);
6636
6650
  }
6637
6651
  return t.old == null ? e : [...e, t.old];
6638
- }, Ed = class {
6652
+ }, Md = class {
6639
6653
  mode;
6640
6654
  capacity;
6641
6655
  now;
@@ -6655,8 +6669,8 @@ behind quietly.`;
6655
6669
  ts: this.now(),
6656
6670
  table: e.table,
6657
6671
  op: e.op,
6658
- old: Cd(e.old),
6659
- new: Cd(e.new),
6672
+ old: kd(e.old),
6673
+ new: kd(e.new),
6660
6674
  tenantId: n
6661
6675
  }), this.ring.length > this.capacity && this.ring.shift(), t;
6662
6676
  }
@@ -6669,23 +6683,23 @@ behind quietly.`;
6669
6683
  }
6670
6684
  replay(e, t, n) {
6671
6685
  let r = this.ring.filter((n) => n.table === e && n.seq > t).sort((e, t) => t.seq - e.seq), i = n;
6672
- for (let e of r) i = Td(i, e);
6686
+ for (let e of r) i = jd(i, e);
6673
6687
  return i;
6674
6688
  }
6675
- }, Dd, Od = () => (Dd === void 0 && (Dd = new Ed(bd())), Dd), kd = (e) => {
6676
- Dd = e;
6677
- }, Ad = (e) => {
6678
- let t = Od();
6689
+ }, Nd, Pd = () => (Nd === void 0 && (Nd = new Md(Ed())), Nd), Fd = (e) => {
6690
+ Nd = e;
6691
+ }, Id = (e) => {
6692
+ let t = Pd();
6679
6693
  if (t.enabled) try {
6680
6694
  t.record(e);
6681
6695
  } catch {}
6682
- }, jd = /* @__PURE__ */ new Set([
6696
+ }, Ld = /* @__PURE__ */ new Set([
6683
6697
  "count",
6684
6698
  "sum",
6685
6699
  "avg",
6686
6700
  "min",
6687
6701
  "max"
6688
- ]), Md = (e) => {
6702
+ ]), Rd = (e) => {
6689
6703
  if (e.joins !== void 0 && e.joins.length > 0) return {
6690
6704
  maintainable: !1,
6691
6705
  reason: "joins are not maintainable in v1"
@@ -6707,7 +6721,7 @@ behind quietly.`;
6707
6721
  reason: "v1 maintains exactly one aggregation"
6708
6722
  };
6709
6723
  let t = e.aggregations[0];
6710
- return jd.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
6724
+ return Ld.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
6711
6725
  maintainable: !1,
6712
6726
  reason: `op '${t.op}' requires a column`
6713
6727
  } : {
@@ -6721,7 +6735,7 @@ behind quietly.`;
6721
6735
  maintainable: !1,
6722
6736
  reason: `op '${t.op}' is not maintainable`
6723
6737
  };
6724
- }, Nd = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(Nd), Pd = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Fd = (e, t) => {
6738
+ }, zd = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(zd), Bd = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Vd = (e, t) => {
6725
6739
  switch (e.op) {
6726
6740
  case "count": return t.count;
6727
6741
  case "sum": return t.sum ?? 0;
@@ -6729,10 +6743,10 @@ behind quietly.`;
6729
6743
  case "min":
6730
6744
  case "max": return t.count > 0 ? t.extreme ?? null : null;
6731
6745
  }
6732
- }, Id = (e, t) => {
6746
+ }, Hd = (e, t) => {
6733
6747
  let n = /* @__PURE__ */ new Map();
6734
6748
  for (let r of t) {
6735
- let t = $(r, e.groupBy), i = n.get(t), a = Pd(r, e.column);
6749
+ let t = $(r, e.groupBy), i = n.get(t), a = Bd(r, e.column);
6736
6750
  if (i === void 0) n.set(t, {
6737
6751
  count: 1,
6738
6752
  ...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
@@ -6748,10 +6762,10 @@ behind quietly.`;
6748
6762
  }
6749
6763
  }
6750
6764
  return n;
6751
- }, Ld = (e, t) => [...t.entries()].map(([t, n]) => ({
6765
+ }, Ud = (e, t) => [...t.entries()].map(([t, n]) => ({
6752
6766
  groupKey: t,
6753
- value: Fd(e, n)
6754
- })), Rd = (e, t, n) => {
6767
+ value: Vd(e, n)
6768
+ })), Wd = (e, t, n) => {
6755
6769
  let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
6756
6770
  let n = $(t, e.groupBy), a = r.get(n);
6757
6771
  if (a === void 0) return;
@@ -6760,7 +6774,7 @@ behind quietly.`;
6760
6774
  r.delete(n);
6761
6775
  return;
6762
6776
  }
6763
- let s = Pd(t, e.column);
6777
+ let s = Bd(t, e.column);
6764
6778
  e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
6765
6779
  count: o,
6766
6780
  ...a.extreme === void 0 ? {} : { extreme: a.extreme }
@@ -6769,7 +6783,7 @@ behind quietly.`;
6769
6783
  ...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
6770
6784
  });
6771
6785
  }, o = (t) => {
6772
- let n = $(t, e.groupBy), i = r.get(n), a = Pd(t, e.column);
6786
+ let n = $(t, e.groupBy), i = r.get(n), a = Bd(t, e.column);
6773
6787
  if (i === void 0) {
6774
6788
  r.set(n, {
6775
6789
  count: 1,
@@ -6789,15 +6803,15 @@ behind quietly.`;
6789
6803
  state: r,
6790
6804
  rescanGroups: [...i]
6791
6805
  };
6792
- }, zd = (e, t, n, r) => {
6806
+ }, Gd = (e, t, n, r) => {
6793
6807
  if (n.length === 0) return t;
6794
- let i = new Set(n), a = Id(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
6808
+ let i = new Set(n), a = Hd(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
6795
6809
  for (let e of i) {
6796
6810
  let t = a.get(e);
6797
6811
  t === void 0 ? o.delete(e) : o.set(e, t);
6798
6812
  }
6799
6813
  return o;
6800
- }, Bd = class {
6814
+ }, Kd = class {
6801
6815
  shape;
6802
6816
  state = /* @__PURE__ */ new Map();
6803
6817
  groups = /* @__PURE__ */ new Map();
@@ -6805,7 +6819,7 @@ behind quietly.`;
6805
6819
  this.shape = e;
6806
6820
  }
6807
6821
  seed(e) {
6808
- this.state = Id(this.shape, e), this.groups.clear();
6822
+ this.state = Hd(this.shape, e), this.groups.clear();
6809
6823
  for (let t of e) {
6810
6824
  let e = $(t, this.shape.groupBy);
6811
6825
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
@@ -6817,14 +6831,14 @@ behind quietly.`;
6817
6831
  let e = $(t, this.shape.groupBy);
6818
6832
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
6819
6833
  }
6820
- let n = Rd(this.shape, this.state, e);
6834
+ let n = Wd(this.shape, this.state, e);
6821
6835
  this.state = n.state;
6822
6836
  for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
6823
6837
  return n.rescanGroups;
6824
6838
  }
6825
6839
  resolveRescan(e, t) {
6826
6840
  if (e.length === 0) return;
6827
- this.state = zd(this.shape, this.state, e, t);
6841
+ this.state = Gd(this.shape, this.state, e, t);
6828
6842
  let n = new Set(e);
6829
6843
  for (let e of t) {
6830
6844
  let t = $(e, this.shape.groupBy);
@@ -6833,7 +6847,7 @@ behind quietly.`;
6833
6847
  for (let e of n) this.state.has(e) || this.groups.delete(e);
6834
6848
  }
6835
6849
  materialize() {
6836
- return Ld(this.shape, this.state).map((e) => ({
6850
+ return Ud(this.shape, this.state).map((e) => ({
6837
6851
  groupKey: e.groupKey,
6838
6852
  group: this.groups.get(e.groupKey) ?? {},
6839
6853
  value: e.value
@@ -6846,7 +6860,7 @@ behind quietly.`;
6846
6860
  for (let r of t) n[r] = e[r];
6847
6861
  return n;
6848
6862
  }
6849
- }, Vd = F("_voltro_rebac_tuples", {
6863
+ }, qd = F("_voltro_rebac_tuples", {
6850
6864
  id: M({ prefix: "rbct" }),
6851
6865
  subjectId: I(),
6852
6866
  relation: I(),
@@ -6858,7 +6872,7 @@ behind quietly.`;
6858
6872
  "subjectId",
6859
6873
  "resourceType",
6860
6874
  "resourceId"
6861
- ]), Hd = async (e, t, n, r) => t === null ? [] : (await e.query({
6875
+ ]), Jd = async (e, t, n, r) => t === null ? [] : (await e.query({
6862
6876
  table: "_voltro_rebac_tuples",
6863
6877
  predicate: C(O("subjectId", t), O("resourceType", n), O("resourceId", r)),
6864
6878
  order: [],
@@ -6870,16 +6884,16 @@ behind quietly.`;
6870
6884
  relation: e.relation,
6871
6885
  resourceType: e.resourceType,
6872
6886
  resourceId: e.resourceId
6873
- })), Ud = (e) => ({
6887
+ })), Yd = (e) => ({
6874
6888
  id: e.id,
6875
6889
  tenantId: e.tenantId,
6876
6890
  ...e.scopes === void 0 ? {} : { scopes: e.scopes }
6877
- }), Wd = (e, t) => {
6878
- let n = t.getPolicy ?? $c;
6891
+ }), Xd = (e, t) => {
6892
+ let n = t.getPolicy ?? nl;
6879
6893
  return (r, i) => {
6880
6894
  let a = e[i.tag];
6881
6895
  if (a === void 0) return r;
6882
- let s = n(a.resourceType), c = (e) => o.fail(new Xc({
6896
+ let s = n(a.resourceType), c = (e) => o.fail(new $c({
6883
6897
  action: a.action,
6884
6898
  resourceType: a.resourceType,
6885
6899
  resourceId: e
@@ -6887,17 +6901,17 @@ behind quietly.`;
6887
6901
  if (s === void 0) return c("");
6888
6902
  let l = a.resourceId(i.input);
6889
6903
  if (l === null || l === "") return c("");
6890
- let u = Ud(i.subject), d = {
6904
+ let u = Yd(i.subject), d = {
6891
6905
  type: a.resourceType,
6892
6906
  id: l,
6893
6907
  tenantId: i.subject.tenantId
6894
6908
  };
6895
- return o.flatMap(o.promise(async () => t.loadTuples(u.id, a.resourceType, l)), (e) => al(u, a.action, d, {
6909
+ return o.flatMap(o.promise(async () => t.loadTuples(u.id, a.resourceType, l)), (e) => cl(u, a.action, d, {
6896
6910
  policy: s,
6897
6911
  tuples: e
6898
6912
  }) ? r : c(l));
6899
6913
  };
6900
- }, Gd = async (e, t, n) => t === null ? [] : (await e.query({
6914
+ }, Zd = async (e, t, n) => t === null ? [] : (await e.query({
6901
6915
  table: "_voltro_rebac_tuples",
6902
6916
  predicate: C(O("subjectId", t), O("resourceType", n)),
6903
6917
  order: [],
@@ -6909,18 +6923,18 @@ behind quietly.`;
6909
6923
  relation: e.relation,
6910
6924
  resourceType: e.resourceType,
6911
6925
  resourceId: e.resourceId
6912
- })), Kd = (e) => {
6913
- let t = e.getPolicy ?? $c;
6926
+ })), Qd = (e) => {
6927
+ let t = e.getPolicy ?? nl;
6914
6928
  return async (n, r, i, a) => {
6915
6929
  let o = t(r);
6916
6930
  if (o === void 0) return [];
6917
- let s = Ud(n);
6918
- return sl(s, i, r, a, {
6931
+ let s = Yd(n);
6932
+ return ul(s, i, r, a, {
6919
6933
  policy: o,
6920
6934
  tuples: await e.loadSubjectTuples(s.id, r)
6921
6935
  });
6922
6936
  };
6923
- }, qd = (e) => {
6937
+ }, $d = (e) => {
6924
6938
  if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
6925
6939
  if (e.watch === void 0 || typeof e.watch.table != "string" || e.watch.table.length === 0) throw Error(`reaction '${e.name}': watch.table is required`);
6926
6940
  if (e.act === void 0 || e.act.kind !== "agent" && e.act.kind !== "workflow") throw Error(`reaction '${e.name}': act must be { kind: 'agent' | 'workflow', … }`);
@@ -6928,14 +6942,14 @@ behind quietly.`;
6928
6942
  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`);
6929
6943
  if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
6930
6944
  return e;
6931
- }, Jd = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, Yd = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, Xd = class {
6945
+ }, ef = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, tf = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, nf = class {
6932
6946
  hits = /* @__PURE__ */ new Map();
6933
6947
  allow(e, t, n, r) {
6934
6948
  let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
6935
6949
  return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
6936
6950
  }
6937
- }, Zd = async (e, t, n) => {
6938
- if (t.table !== e.watch.table || !Jd(e.watch.on, t.op)) return "skipped-op";
6951
+ }, rf = async (e, t, n) => {
6952
+ if (t.table !== e.watch.table || !ef(e.watch.on, t.op)) return "skipped-op";
6939
6953
  if (e.when !== void 0 && !e.when(t)) return "skipped-when";
6940
6954
  let r = `${e.name}:${e.guards.dedupeKey(t)}`;
6941
6955
  if (await n.dedupe.has(r)) return "skipped-dedupe";
@@ -6944,26 +6958,26 @@ behind quietly.`;
6944
6958
  let t = n.now?.() ?? Date.now();
6945
6959
  if (!n.rateLimiter.allow(e.name, i.limit, i.windowMs, t)) return "skipped-ratelimit";
6946
6960
  }
6947
- let a = Yd(t);
6961
+ let a = tf(t);
6948
6962
  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, {
6949
6963
  id: a,
6950
6964
  via: "agent"
6951
6965
  }), await n.dedupe.add(r), "acted");
6952
- }, Qd = F("_voltro_wakeups", {
6966
+ }, af = F("_voltro_wakeups", {
6953
6967
  id: M({ prefix: "wakeup" }),
6954
6968
  tenantId: I(),
6955
6969
  kind: I(),
6956
6970
  refId: I(),
6957
6971
  wakeAt: L(),
6958
6972
  status: I()
6959
- }).index(["status", "wakeAt"]).index(["tenantId"]), $d = async (e) => {
6960
- let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Mu(e.store, t, e.batchLimit ?? 100);
6973
+ }).index(["status", "wakeAt"]).index(["tenantId"]), of = async (e) => {
6974
+ let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Ru(e.store, t, e.batchLimit ?? 100);
6961
6975
  if (n.length === 0) return 0;
6962
6976
  let r = 0;
6963
- for (let t of n) if (await Ou(e.store, t)) try {
6977
+ for (let t of n) if (await Pu(e.store, t)) try {
6964
6978
  await e.adapter.wake(t), r++;
6965
6979
  } catch (n) {
6966
- await ku(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
6980
+ await Fu(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
6967
6981
  tenantId: t.tenantId,
6968
6982
  kind: t.kind,
6969
6983
  refId: t.refId,
@@ -6971,11 +6985,11 @@ behind quietly.`;
6971
6985
  });
6972
6986
  }
6973
6987
  return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
6974
- }, ef = (e, t = 1e3) => {
6988
+ }, sf = (e, t = 1e3) => {
6975
6989
  let n = !1, r, i = async () => {
6976
6990
  if (!n) {
6977
6991
  try {
6978
- await $d(e);
6992
+ await of(e);
6979
6993
  } catch (t) {
6980
6994
  e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
6981
6995
  }
@@ -6985,10 +6999,10 @@ behind quietly.`;
6985
6999
  return i(), { stop: () => {
6986
7000
  n = !0, r !== void 0 && clearTimeout(r);
6987
7001
  } };
6988
- }, tf = (e) => ({ wake: async () => {
7002
+ }, cf = (e) => ({ wake: async () => {
6989
7003
  await e.start();
6990
- } }), nf = (e) => new Promise((t) => setTimeout(t, e)), rf = (e) => {
6991
- let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? nf, i = e.spawnImpl ?? Zt, 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 () => {
7004
+ } }), lf = (e) => new Promise((t) => setTimeout(t, e)), uf = (e) => {
7005
+ let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? lf, i = e.spawnImpl ?? Zt, 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 () => {
6992
7006
  try {
6993
7007
  let n = await t(e.healthUrl);
6994
7008
  return d(n);
@@ -7042,11 +7056,11 @@ behind quietly.`;
7042
7056
  },
7043
7057
  stop: m
7044
7058
  };
7045
- }, af = async (e) => {
7059
+ }, df = async (e) => {
7046
7060
  if (e.signals.connectedClients() > 0 || e.signals.inFlightRequests() > 0 || e.signals.activeWorkflowExecutions() > 0) return !1;
7047
- let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Nu(e.store);
7061
+ let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await zu(e.store);
7048
7062
  return !(n !== null && n.wakeAt.getTime() <= t);
7049
- }, of = (e, t = Date.now) => {
7063
+ }, ff = (e, t = Date.now) => {
7050
7064
  let n;
7051
7065
  return {
7052
7066
  update: (r) => {
@@ -7058,7 +7072,7 @@ behind quietly.`;
7058
7072
  n = void 0;
7059
7073
  }
7060
7074
  };
7061
- }, sf = () => {
7075
+ }, pf = () => {
7062
7076
  let e = 0, t = 0;
7063
7077
  return {
7064
7078
  onRequestStart: () => {
@@ -7076,7 +7090,7 @@ behind quietly.`;
7076
7090
  inFlightRequests: () => e,
7077
7091
  openConnections: () => t
7078
7092
  };
7079
- }, cf = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), lf = (e, t, n, r) => new Promise((i, a) => {
7093
+ }, mf = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), hf = (e, t, n, r) => new Promise((i, a) => {
7080
7094
  let o = xt.request({
7081
7095
  host: n,
7082
7096
  port: r,
@@ -7087,7 +7101,7 @@ behind quietly.`;
7087
7101
  t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
7088
7102
  });
7089
7103
  o.on("error", a), e.pipe(o);
7090
- }), uf = (e, t, n, r, i) => new Promise((a, o) => {
7104
+ }), gf = (e, t, n, r, i) => new Promise((a, o) => {
7091
7105
  let s = xt.request({
7092
7106
  host: r,
7093
7107
  port: i,
@@ -7102,21 +7116,21 @@ behind quietly.`;
7102
7116
  };
7103
7117
  t.on("close", s), r.on("close", s), r.on("error", o);
7104
7118
  }), s.on("error", o), s.end();
7105
- }), df = (e) => {
7106
- let t = cf({
7119
+ }), _f = (e) => {
7120
+ let t = mf({
7107
7121
  ensureAwake: () => e.supervisor.start(),
7108
7122
  ...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
7109
7123
  }), n = e.activity, r = xt.createServer((r, i) => {
7110
- n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => lf(r, i, e.targetHost, e.targetPort)).catch((t) => {
7124
+ n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => hf(r, i, e.targetHost, e.targetPort)).catch((t) => {
7111
7125
  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");
7112
7126
  });
7113
7127
  });
7114
7128
  return r.on("upgrade", (r, i, a) => {
7115
- n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => uf(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
7129
+ n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => gf(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
7116
7130
  e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
7117
7131
  });
7118
7132
  }), r;
7119
- }, ff = async (e) => {
7133
+ }, vf = async (e) => {
7120
7134
  try {
7121
7135
  return (await e.query({
7122
7136
  table: "_voltro_workflow_runs",
@@ -7133,15 +7147,15 @@ behind quietly.`;
7133
7147
  } catch {
7134
7148
  return 0;
7135
7149
  }
7136
- }, pf = async (e) => {
7137
- let t = tf(e.supervisor), n = await $d({
7150
+ }, yf = async (e) => {
7151
+ let t = cf(e.supervisor), n = await of({
7138
7152
  store: e.store,
7139
7153
  adapter: t,
7140
7154
  ...e.now === void 0 ? {} : { now: e.now },
7141
7155
  ...e.log === void 0 ? {} : { log: e.log }
7142
7156
  });
7143
7157
  n > 0 && e.idleGate.reset();
7144
- let r = await af({
7158
+ let r = await df({
7145
7159
  store: e.store,
7146
7160
  signals: e.signals,
7147
7161
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
@@ -7151,12 +7165,12 @@ behind quietly.`;
7151
7165
  woke: n,
7152
7166
  stopped: i
7153
7167
  };
7154
- }, mf = async (e) => {
7155
- let t = of(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = sf(), i = 0, a = e.signals === void 0, o = e.signals ?? {
7168
+ }, bf = async (e) => {
7169
+ let t = ff(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = pf(), i = 0, a = e.signals === void 0, o = e.signals ?? {
7156
7170
  connectedClients: () => r.openConnections(),
7157
7171
  inFlightRequests: () => r.inFlightRequests(),
7158
7172
  activeWorkflowExecutions: () => i
7159
- }, s = df({
7173
+ }, s = _f({
7160
7174
  supervisor: e.supervisor,
7161
7175
  targetHost: e.targetHost,
7162
7176
  targetPort: e.targetPort,
@@ -7175,7 +7189,7 @@ behind quietly.`;
7175
7189
  let l = !1, u, d = e.firedRetentionMs ?? 10 * 6e4, f = 0, p = async () => {
7176
7190
  if (!l) {
7177
7191
  try {
7178
- if (a && (i = await ff(e.store)), await pf({
7192
+ if (a && (i = await vf(e.store)), await yf({
7179
7193
  store: e.store,
7180
7194
  supervisor: e.supervisor,
7181
7195
  signals: o,
@@ -7183,7 +7197,7 @@ behind quietly.`;
7183
7197
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
7184
7198
  ...e.log === void 0 ? {} : { log: e.log }
7185
7199
  }), f++ % 60 == 0) {
7186
- let t = await Fu(e.store, { firedOlderThan: new Date(Date.now() - d) });
7200
+ let t = await Vu(e.store, { firedOlderThan: new Date(Date.now() - d) });
7187
7201
  t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
7188
7202
  }
7189
7203
  } catch (t) {
@@ -7198,14 +7212,14 @@ behind quietly.`;
7198
7212
  l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
7199
7213
  }
7200
7214
  };
7201
- }, hf = (e) => e, gf = class extends y.TaggedError()("AnalyticsError", {
7215
+ }, xf = (e) => e, Sf = class extends y.TaggedError()("AnalyticsError", {
7202
7216
  provider: y.String,
7203
7217
  operation: y.String,
7204
7218
  cause: y.String
7205
- }) {}, _f = class extends y.TaggedError()("AnalyticsCapabilityNotSupported", {
7219
+ }) {}, Cf = class extends y.TaggedError()("AnalyticsCapabilityNotSupported", {
7206
7220
  provider: y.String,
7207
7221
  capability: y.String
7208
- }) {}, vf = class extends n.Tag("@voltro/AnalyticsSink")() {}, yf = (e, t) => ({
7222
+ }) {}, wf = class extends n.Tag("@voltro/AnalyticsSink")() {}, Tf = (e, t) => ({
7209
7223
  info: e.info,
7210
7224
  track: (n) => e.track(n.tenantId === void 0 ? {
7211
7225
  ...n,
@@ -7224,20 +7238,20 @@ behind quietly.`;
7224
7238
  tenantId: t
7225
7239
  } : n),
7226
7240
  ...e.mirror === void 0 ? {} : { mirror: e.mirror }
7227
- }), bf = () => o.gen(function* () {
7228
- let e = yield* vf, t = yield* o.serviceOption(et), n = h.match(t, {
7241
+ }), Ef = () => o.gen(function* () {
7242
+ let e = yield* wf, t = yield* o.serviceOption(et), n = h.match(t, {
7229
7243
  onNone: () => null,
7230
7244
  onSome: (e) => e.tenantId ?? null
7231
7245
  });
7232
- return n === null ? e : yf(e, n);
7233
- }), xf = "noop", Sf = () => {
7234
- let e = (e) => o.fail(new _f({
7235
- provider: xf,
7246
+ return n === null ? e : Tf(e, n);
7247
+ }), Df = "noop", Of = () => {
7248
+ let e = (e) => o.fail(new Cf({
7249
+ provider: Df,
7236
7250
  capability: e
7237
7251
  }));
7238
7252
  return {
7239
7253
  info: {
7240
- provider: xf,
7254
+ provider: Df,
7241
7255
  capabilities: {
7242
7256
  track: !0,
7243
7257
  aggregate: !1,
@@ -7251,8 +7265,8 @@ behind quietly.`;
7251
7265
  timeseries: () => e("timeseries"),
7252
7266
  topN: () => e("topN")
7253
7267
  };
7254
- }, Cf = (e) => {
7255
- if (e.length === 0) return Sf();
7268
+ }, kf = (e) => {
7269
+ if (e.length === 0) return Of();
7256
7270
  if (e.length === 1) return e[0];
7257
7271
  let t = {
7258
7272
  provider: "compose",
@@ -7269,7 +7283,7 @@ behind quietly.`;
7269
7283
  discard: !0
7270
7284
  }), r = (t, n) => {
7271
7285
  let r = e.find((e) => e.info.capabilities[t]);
7272
- return r === void 0 ? o.fail(new _f({
7286
+ return r === void 0 ? o.fail(new Cf({
7273
7287
  provider: "compose",
7274
7288
  capability: t
7275
7289
  })) : n(r);
@@ -7292,11 +7306,11 @@ behind quietly.`;
7292
7306
  topN: (e) => r("topN", (t) => t.topN(e)),
7293
7307
  ...a === void 0 ? {} : { mirror: a }
7294
7308
  };
7295
- }, wf = (e) => {
7309
+ }, Af = (e) => {
7296
7310
  let t = e.filter((e) => e.dispose !== void 0);
7297
7311
  return {
7298
7312
  kind: "compose",
7299
- build: (t) => Cf(e.map((e) => e.build(t))),
7313
+ build: (t) => kf(e.map((e) => e.build(t))),
7300
7314
  tables: e.flatMap((e) => e.tables ?? []),
7301
7315
  initialize: (t) => o.forEach(e, (e) => e.initialize ? e.initialize(t) : o.void, {
7302
7316
  concurrency: 1,
@@ -7307,15 +7321,15 @@ behind quietly.`;
7307
7321
  discard: !0
7308
7322
  }) } : {}
7309
7323
  };
7310
- }, Tf = {
7324
+ }, jf = {
7311
7325
  kind: "noop",
7312
- build: () => Sf()
7313
- }, Ef = {
7326
+ build: () => Of()
7327
+ }, Mf = {
7314
7328
  tables: [],
7315
7329
  detach: () => {}
7316
- }, Df = (e) => {
7330
+ }, Nf = (e) => {
7317
7331
  let { store: t, sink: n, log: r } = e, i = n.mirror;
7318
- if (i === void 0 || i.tables.length === 0) return Ef;
7332
+ if (i === void 0 || i.tables.length === 0) return Mf;
7319
7333
  let a = e.run ?? ((e) => o.runPromise(e)), s = i.primaryKey ?? "id", c = new Set(i.tables), l = (e) => {
7320
7334
  if (e.op === "delete") {
7321
7335
  let t = e.old;
@@ -7339,11 +7353,11 @@ behind quietly.`;
7339
7353
  tables: i.tables,
7340
7354
  detach: u
7341
7355
  };
7342
- }, Of = (e) => {
7356
+ }, Pf = (e) => {
7343
7357
  let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
7344
7358
  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`);
7345
7359
  if (e.incremental !== void 0) {
7346
- let t = Md({
7360
+ let t = Rd({
7347
7361
  aggregations: [{
7348
7362
  op: e.incremental.op,
7349
7363
  ...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
@@ -7365,47 +7379,51 @@ behind quietly.`;
7365
7379
  build: e.build,
7366
7380
  ...e.incremental === void 0 ? {} : { incremental: e.incremental }
7367
7381
  };
7368
- }, kf = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Af = class extends y.TaggedError()("AggregateStale", {
7382
+ }, Ff = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, If = class extends y.TaggedError()("AggregateStale", {
7369
7383
  name: y.String,
7370
7384
  ageMs: y.Number,
7371
7385
  maxAgeMs: y.Number
7372
- }) {}, jf = class extends y.TaggedError()("AggregateNotFound", { name: y.String }) {}, Mf = class extends y.TaggedError()("AggregateError", {
7386
+ }) {}, Lf = class extends y.TaggedError()("AggregateNotFound", { name: y.String }) {}, Rf = class extends y.TaggedError()("AggregateError", {
7373
7387
  name: y.String,
7374
7388
  operation: y.String,
7375
7389
  cause: y.String
7376
- }) {}, Nf = class extends n.Tag("@voltro/AggregateRegistry")() {}, Pf = (e) => o.gen(function* () {
7377
- return (yield* Nf).getHandle(e);
7378
- }), Ff = (e, t, n) => {
7390
+ }) {}, zf = class extends n.Tag("@voltro/AggregateRegistry")() {}, Bf = (e) => o.gen(function* () {
7391
+ return (yield* zf).getHandle(e);
7392
+ }), Vf = (e, t, n) => {
7379
7393
  if (e.crossTenant || !t.has(e.table) || n == null) return e;
7380
7394
  let r = O("tenantId", n);
7381
7395
  return {
7382
7396
  ...e,
7383
7397
  predicate: e.predicate ? C(e.predicate, r) : r
7384
7398
  };
7385
- }, If = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Lf = (e) => e?.type === "user" && e.tenantId === "", Rf = (e, t) => {
7399
+ }, Hf = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Uf = (e) => e?.type === "user" && e.tenantId === "", Wf = (e, t) => {
7386
7400
  if (e.includeDeleted || !t.has(e.table)) return e;
7387
7401
  let n = de("deletedAt");
7388
7402
  return {
7389
7403
  ...e,
7390
7404
  predicate: e.predicate ? C(e.predicate, n) : n
7391
7405
  };
7392
- }, zf = (e, t) => t, Bf = (t) => o.runPromiseExit(t).then((t) => {
7406
+ }, Gf = (e) => (t, n) => {
7407
+ e.observe?.beforeScope?.({ ...t }, n);
7408
+ let r = Wf(Vf(t, e.tenantScopedTables, n.tenantId), e.softDeleteScopedTables);
7409
+ return e.observe?.afterScope?.({ ...r }), r;
7410
+ }, Kf = (e, t) => t, qf = (t) => o.runPromiseExit(t).then((t) => {
7393
7411
  if (c.isSuccess(t)) return t.value;
7394
7412
  let n = e.failureOption(t.cause);
7395
7413
  throw h.isSome(n) ? n.value : e.squash(t.cause);
7396
- }), Vf = (e, t) => e.pipe(o.provideService(et, t)), Hf = async (e, t, n) => {
7414
+ }), Jf = (e, t) => e.pipe(o.provideService(et, t)), Yf = async (e, t, n) => {
7397
7415
  let r = await o.runPromise(ot(t, e.guards, n));
7398
7416
  if (r) throw r;
7399
- }, Uf = async (e) => {
7417
+ }, Xf = async (e) => {
7400
7418
  if (Dr() === void 0) return e;
7401
- let t = await Bf(kr(e.subject, (e) => {
7419
+ let t = await qf(kr(e.subject, (e) => {
7402
7420
  console.error("[voltro] row filter failed to load", e);
7403
7421
  }));
7404
7422
  return {
7405
7423
  ...e,
7406
7424
  rowFilter: t
7407
7425
  };
7408
- }, Wf = async (t) => {
7426
+ }, Zf = async (t) => {
7409
7427
  let n = `${t.kind}.${t.name}`, r = Date.now(), i = "ok";
7410
7428
  try {
7411
7429
  if (t.interceptor) {
@@ -7434,28 +7452,28 @@ behind quietly.`;
7434
7452
  status: i
7435
7453
  });
7436
7454
  }
7437
- }, Gf = /* @__PURE__ */ new Set([1213, 1205]), Kf = /* @__PURE__ */ new Set([
7455
+ }, Qf = /* @__PURE__ */ new Set([1213, 1205]), $f = /* @__PURE__ */ new Set([
7438
7456
  "ER_LOCK_DEADLOCK",
7439
7457
  "ER_LOCK_WAIT_TIMEOUT",
7440
7458
  "40001",
7441
7459
  "40P01"
7442
- ]), qf = (e) => {
7460
+ ]), ep = (e) => {
7443
7461
  let t = e;
7444
7462
  for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
7445
7463
  let e = t;
7446
- if (typeof e.errno == "number" && Gf.has(e.errno) || typeof e.code == "string" && Kf.has(e.code) || typeof e.sqlState == "string" && Kf.has(e.sqlState)) return !0;
7464
+ if (typeof e.errno == "number" && Qf.has(e.errno) || typeof e.code == "string" && $f.has(e.code) || typeof e.sqlState == "string" && $f.has(e.sqlState)) return !0;
7447
7465
  t = e.cause;
7448
7466
  }
7449
7467
  return !1;
7450
- }, Jf = 3, Yf = (e) => new Promise((t) => setTimeout(t, e)), Xf = async (e, t) => {
7451
- let n = t?.delay ?? ((e) => Yf(e * 20 + Math.floor(Math.random() * 30)));
7468
+ }, tp = 3, np = (e) => new Promise((t) => setTimeout(t, e)), rp = async (e, t) => {
7469
+ let n = t?.delay ?? ((e) => np(e * 20 + Math.floor(Math.random() * 30)));
7452
7470
  for (let t = 1;; t++) try {
7453
7471
  return await e();
7454
7472
  } catch (e) {
7455
- if (t >= Jf || !qf(e)) throw e;
7473
+ if (t >= tp || !ep(e)) throw e;
7456
7474
  await n(t);
7457
7475
  }
7458
- }, Zf = (e) => (t, n, r) => Wf({
7476
+ }, ip = (e) => (t, n, r) => Zf({
7459
7477
  name: t.descriptor.name,
7460
7478
  kind: "mutation",
7461
7479
  input: n,
@@ -7463,11 +7481,11 @@ behind quietly.`;
7463
7481
  ...e.interceptor ? { interceptor: e.interceptor } : {},
7464
7482
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
7465
7483
  runExecutor: async () => {
7466
- await Hf(t.descriptor, r.subject, n);
7467
- let i = await Uf(r), a = [], s = await Xf(async () => (a.length = 0, e.store.transactional(async (s) => {
7484
+ await Yf(t.descriptor, r.subject, n);
7485
+ let i = await Xf(r), a = [], s = await rp(async () => (a.length = 0, e.store.transactional(async (s) => {
7468
7486
  let c = e.undoCapture?.(s), l = c ? c.tx : s, u = e.buildContext(i, l, { afterCommit: (e) => {
7469
7487
  a.push(e);
7470
- } }), d = t.executor(n, u), f = o.isEffect(d) ? await e.runEffect(Vf(d, r.subject), u.store) : await d;
7488
+ } }), d = t.executor(n, u), f = o.isEffect(d) ? await e.runEffect(Jf(d, r.subject), u.store) : await d;
7471
7489
  return c && await c.persist(u.store, {
7472
7490
  tag: t.descriptor.name,
7473
7491
  subject: r.subject,
@@ -7477,30 +7495,30 @@ behind quietly.`;
7477
7495
  for (let e of a) await e();
7478
7496
  return s;
7479
7497
  }
7480
- }), Qf = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, $f = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, ep = (e) => {
7498
+ }), ap = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, op = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, sp = (e) => {
7481
7499
  let t = e.descriptor.source;
7482
7500
  return t == null ? [] : typeof t == "string" ? [t] : [...t];
7483
- }, tp = (e, t) => (n) => () => {
7501
+ }, cp = (e, t) => (n) => () => {
7484
7502
  let r = e.descriptor.guards;
7485
7503
  return !r || r.length === 0 ? Promise.resolve(null) : o.runPromise(ot(n, r, t));
7486
- }, np = (e) => (t, n) => (r) => {
7487
- let i = e.buildContext(r), a = tp(t, n)(r.subject), s = async () => {
7504
+ }, lp = (e) => (t, n) => (r) => {
7505
+ let i = e.buildContext(r), a = cp(t, n)(r.subject), s = async () => {
7488
7506
  let i = await a();
7489
7507
  if (i) throw i;
7490
- let s = e.buildContext(await Uf(r)), c = t.executor(n, s);
7491
- return o.isEffect(c) ? o.runPromise(e.provideEffect(Vf(c, r.subject), s.store)) : Qf(await Promise.resolve(c));
7508
+ let s = e.buildContext(await Xf(r)), c = t.executor(n, s);
7509
+ return o.isEffect(c) ? o.runPromise(e.provideEffect(Jf(c, r.subject), s.store)) : ap(await Promise.resolve(c));
7492
7510
  }, c = (n) => {
7493
- let i = Qf(n);
7494
- return $f(i) ? e.finalize(i, r) : {
7511
+ let i = ap(n);
7512
+ return op(i) ? e.finalize(i, r) : {
7495
7513
  __voltroComputed: !0,
7496
7514
  value: i,
7497
- dependentTables: ep(t),
7515
+ dependentTables: sp(t),
7498
7516
  tenantId: r.subject?.tenantId ?? null,
7499
7517
  recompute: s
7500
7518
  };
7501
7519
  }, l = () => {
7502
7520
  let a = t.executor(n, i);
7503
- return o.isEffect(a) ? e.provideEffect(Vf(a, r.subject), i.store).pipe(o.map(c)) : a instanceof Promise ? o.promise(() => a).pipe(o.map(c)) : c(a);
7521
+ return o.isEffect(a) ? e.provideEffect(Jf(a, r.subject), i.store).pipe(o.map(c)) : a instanceof Promise ? o.promise(() => a).pipe(o.map(c)) : c(a);
7504
7522
  }, u = () => {
7505
7523
  let e = t.descriptor.guards;
7506
7524
  return !e || e.length === 0 ? l() : ot(r.subject, e, n).pipe(o.flatMap((e) => {
@@ -7522,14 +7540,14 @@ behind quietly.`;
7522
7540
  traceId: r.traceId,
7523
7541
  ...r.spanId === void 0 ? {} : { spanId: r.spanId }
7524
7542
  });
7525
- }, rp = (e) => async (t, n, r) => {
7526
- let i = await Uf(r), a = np(e)(t, n)(i), s = o.isEffect(a) ? await Bf(a) : a;
7543
+ }, up = (e) => async (t, n, r) => {
7544
+ let i = await Xf(r), a = lp(e)(t, n)(i), s = o.isEffect(a) ? await qf(a) : a;
7527
7545
  return zr(s) ? s.value : e.queryRows(s);
7528
- }, ip = (e) => (t, n, r, i) => {
7546
+ }, dp = (e) => (t, n, r, i) => {
7529
7547
  let a = !1, s;
7530
7548
  return (async () => {
7531
7549
  try {
7532
- let c = await Uf(r), l = np(e)(t, n)(c), u = o.isEffect(l) ? await Bf(l) : l, d = (e) => i(e), f = zr(u) ? await e.subscribeComputed(u, d, c) : await e.subscribeDescriptor(u, d, c);
7550
+ let c = await Xf(r), l = lp(e)(t, n)(c), u = o.isEffect(l) ? await qf(l) : l, d = (e) => i(e), f = zr(u) ? await e.subscribeComputed(u, d, c) : await e.subscribeDescriptor(u, d, c);
7533
7551
  a ? f() : s = f;
7534
7552
  } catch (e) {
7535
7553
  i({
@@ -7540,7 +7558,7 @@ behind quietly.`;
7540
7558
  })(), () => {
7541
7559
  a = !0, s?.();
7542
7560
  };
7543
- }, ap = (e) => (t, n, r) => Wf({
7561
+ }, fp = (e) => (t, n, r) => Zf({
7544
7562
  name: t.descriptor.name,
7545
7563
  kind: "action",
7546
7564
  input: n,
@@ -7548,16 +7566,16 @@ behind quietly.`;
7548
7566
  ...e.interceptor ? { interceptor: e.interceptor } : {},
7549
7567
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
7550
7568
  runExecutor: async () => {
7551
- await Hf(t.descriptor, r.subject, n);
7552
- let i = e.buildContext(await Uf(r)), a = t.executor(n, i);
7553
- return o.isEffect(a) ? e.runEffect(Vf(a, r.subject), i.store) : a;
7569
+ await Yf(t.descriptor, r.subject, n);
7570
+ let i = e.buildContext(await Xf(r)), a = t.executor(n, i);
7571
+ return o.isEffect(a) ? e.runEffect(Jf(a, r.subject), i.store) : a;
7554
7572
  }
7555
- }), op = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, sp = (e) => typeof e == "string" && e.length > 0 ? e : null, cp = [
7573
+ }), pp = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, mp = (e) => typeof e == "string" && e.length > 0 ? e : null, hp = [
7556
7574
  "updatedAt",
7557
7575
  "createdAt",
7558
7576
  "updatedBy",
7559
7577
  "createdBy"
7560
- ], lp = (e) => cp.some((t) => t in e), up = (e, t, n) => {
7578
+ ], gp = (e) => hp.some((t) => t in e), _p = (e, t, n) => {
7561
7579
  let r = {
7562
7580
  table: t.table,
7563
7581
  id: t.id,
@@ -7572,14 +7590,14 @@ behind quietly.`;
7572
7590
  found: !1
7573
7591
  };
7574
7592
  let i = t.column === void 0 ? void 0 : e[t.column];
7575
- if (!lp(e)) return {
7593
+ if (!gp(e)) return {
7576
7594
  ...r,
7577
7595
  value: i,
7578
7596
  lastWrite: null,
7579
7597
  attribution: "none",
7580
7598
  found: !0
7581
7599
  };
7582
- let a = sp(e.updatedBy) ?? sp(e.createdBy), o = op(e.updatedAt) ?? op(e.createdAt);
7600
+ let a = mp(e.updatedBy) ?? mp(e.createdBy), o = pp(e.updatedAt) ?? pp(e.createdAt);
7583
7601
  return {
7584
7602
  ...r,
7585
7603
  value: i,
@@ -7591,12 +7609,12 @@ behind quietly.`;
7591
7609
  attribution: "audit",
7592
7610
  found: !0
7593
7611
  };
7594
- }, dp = (e, t) => {
7612
+ }, vp = (e, t) => {
7595
7613
  let n = e.map((e) => {
7596
7614
  let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
7597
7615
  return {
7598
- actor: { id: sp(e.actor) ?? sp(e.changedBy) },
7599
- at: op(e.at) ?? op(e.changedAt),
7616
+ actor: { id: mp(e.actor) ?? mp(e.changedBy) },
7617
+ at: pp(e.at) ?? pp(e.changedAt),
7600
7618
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
7601
7619
  value: r
7602
7620
  };
@@ -7611,12 +7629,12 @@ behind quietly.`;
7611
7629
  history: n,
7612
7630
  found: n.length > 0
7613
7631
  };
7614
- }, fp = (e) => {
7632
+ }, yp = (e) => {
7615
7633
  let t = e.new?.id;
7616
7634
  if (typeof t == "string") return t;
7617
7635
  let n = e.old?.id;
7618
7636
  return typeof n == "string" ? n : void 0;
7619
- }, pp = (e) => {
7637
+ }, bp = (e) => {
7620
7638
  let t = {};
7621
7639
  if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
7622
7640
  from: void 0,
@@ -7636,11 +7654,11 @@ behind quietly.`;
7636
7654
  return {
7637
7655
  table: e.table,
7638
7656
  op: e.op,
7639
- id: fp(e),
7657
+ id: yp(e),
7640
7658
  fields: t
7641
7659
  };
7642
- }, mp = (e) => {
7643
- let t = e.map(pp);
7660
+ }, xp = (e) => {
7661
+ let t = e.map(bp);
7644
7662
  return {
7645
7663
  rows: t,
7646
7664
  summary: {
@@ -7649,21 +7667,21 @@ behind quietly.`;
7649
7667
  deletes: t.filter((e) => e.op === "delete").length
7650
7668
  }
7651
7669
  };
7652
- }, hp = class extends Error {
7670
+ }, Sp = class extends Error {
7653
7671
  constructor() {
7654
7672
  super("voltro:preview-rollback"), this.name = "PreviewRollback";
7655
7673
  }
7656
- }, gp = async (e, t) => {
7674
+ }, Cp = async (e, t) => {
7657
7675
  let n, r = !1;
7658
7676
  try {
7659
7677
  await e.transactional(async (e) => {
7660
- throw n = await t(e), r = !0, new hp();
7678
+ throw n = await t(e), r = !0, new Sp();
7661
7679
  });
7662
7680
  } catch (e) {
7663
- if (!(e instanceof hp)) throw e;
7681
+ if (!(e instanceof Sp)) throw e;
7664
7682
  }
7665
7683
  if (!r) throw Error("preview: handler did not complete");
7666
7684
  return n;
7667
- }, _p = "framework-runtime";
7685
+ }, wp = "framework-runtime";
7668
7686
  //#endregion
7669
- export { To as API_KEYS_TABLE, Xc as AccessDenied, Mf as AggregateError, Bd as AggregateMaintainer, jf as AggregateNotFound, Nf as AggregateRegistry, Af as AggregateStale, _f as AnalyticsCapabilityNotSupported, gf as AnalyticsError, vf as AnalyticsSink, X as CONNECTIONS_TABLE, Ys as CONNECTION_GRANTS_TABLE, su as CircuitBreaker, au as CircuitOpen, vc as ConnectionNotConnected, ja as DEFAULT_MAX_RPC_BODY_BYTES, gc as DEFAULT_REFRESH_SKEW_MS, wr as DEFAULT_ROW_FILTER_RETRY, Lu as DORMANCY_WAKEUP_TENANT, Pi as DeleteBuilder, Ir as Dispatcher, Cs as EVENT_CLIENT_QUEUE_SIZE, ws as EVENT_LATEST_QUEUE_SIZE, Bo as EffectStore, vs as EventBus, Ac as GRANT_TTL_MS, yn as InMemoryDataStore, sn as IndexedMatcher, As as InstanceMembership, $t as LinearScanMatcher, p as MetricBoundaries, xf as NOOP_ANALYTICS_PROVIDER, Or as NO_ROW_FILTER, Di as NoRowFound, Ps as OUTBOX_ATTEMPTS_TABLE, Vs as OUTBOX_ATTEMPT_LOG_CAP, Y as OUTBOX_TABLE, Oi as OptimisticLockError, Yc as REBAC_ADMIN_SCOPE, _c as REFRESH_LEASE_MS, _p as RUNTIME_NAME, Xd as ReactionRateLimiter, ta as ReplicatedDataStore, Cr as RowFilterUnavailable, Iu as SCHEDULE_SUBJECT, zo as SYSTEM_SUBJECT, Mi as SelectBuilder, xl as SsrfBlockedError, Li as StoreOperationFailed, un as SubscriptionRegistry, Ri as TableValidationFailed, Ii as TenantScopeViolation, Ed as TimelineRecorder, ad as UndoBoundaryError, sd as UndoStack, Ni as UpdateBuilder, Ol as VOLTRO_AUDIT_MIXIN_ID, Al as VOLTRO_EXPIRES_MIXIN_ID, kl as VOLTRO_SOFT_DELETE_MIXIN_ID, jl as VOLTRO_TENANT_MIXIN_ID, Xo as WorkflowPayloadError, Zr as _connectionStreamCount, Qr as _resetConnectionSubjectsForTest, Zs as _voltroConnectionGrantsTable, Js as _voltroConnectionsTable, Vd as _voltroRebacTuplesTable, Ju as _voltroScheduleClaimsTable, qu as _voltroScheduleRunsTable, Yu as _voltroTracesTable, Xu as _voltroUndoLogTable, Qd as _voltroWakeupsTable, fs as _voltroWorkflowEventDeliveriesTable, ds as _voltroWorkflowEventsTable, Wi as actingUserId, Ro as apiKeyManagementRoutes, Vi as applyDefined, Rd as applyDelta, ld as applyInverse, ud as applyInverses, ru as applyPluginRefRules, Mr as applyRowFilter, Nr as applyRowFilterToDescriptor, Rf as applySoftDeleteScope, Ff as applyTenantScope, vd as applyUndoInvocation, ol as assertCan, tc as assertConnectionCipherConfigured, Df as attachAnalyticsMirror, Ua as awaitServerListening, Bs as backoffMs, Pc as beginOAuthConnect, Wr as bindConnectionSubject, Ds as bindEvent, Aa as bindMutation, ya as bindStream, va as bindSubscription, pa as bindSubscriptionUntyped, Id as buildIvmState, mp as buildPreview, Wd as buildRebacInterceptor, Kd as buildRebacReadFilter, Yi as buildSubjectKey, Ja as buildTracingLayer, Xl as cacheScopeLeaks, lo as cachedBackend, al as can, Tu as cancelWakeup, cn as canonicalize, Md as classifyShape, Sc as clearConnectionRefreshFlights, tl as clearResourcePolicies, ee as clearRetentions, uu as clearSystemStoreHandle, iu as collectPluginRefRules, bu as compileCron, Fc as completeOAuthConnect, wf as composeAnalytics, Cf as composeAnalyticsSinks, jc as connectionCallbackPath, ec as connectionLabel, $r as connectionSubjectsSnapshot, ff as countRunningWorkflows, _r as counter, Gl as crud, dl as currentRequestLoader, ea as currentRoutingContext, oi as currentTraceContext, Fo as dataStoreApiKeyStore, _o as dataStoreIdempotencyStore, So as dataStoreKvStore, mi as decryptField, Of as defineAggregate, $s as defineConnection, os as defineEventTrigger, zf as defineExecutor, Ls as defineOutboxHandler, qd as defineReaction, Qc as defineResourcePolicy, yu as defineSchedule, hf as defineSubscriber, Pr as deliveredRowCount, si as deriveKey, pp as diffChange, Va as drainForShutdown, Gs as drainOutbox, Mu as dueWakeups, il as effectiveRelations, Il as emptySchemaRegistry, bi as enableGraphObservation, pi as encryptField, ul as enterRequestLoader, ro as envSecretsBackend, ar as eventMetricTagCacheSizeForTests, mc as exchangeAuthorizationCode, ri as externalSpanFromTraceparent, xn as extractDbCause, ln as fingerprintFor, uc as forgetCredential, Zl as formatCacheScopeLeaks, Yl as formatServerOnlyLeaks, ti as formatTraceparent, eu as formatUnresolvedSources, cd as forwardChangeFromCdc, Io as frameworkApiKeyStrategy, vr as gauge, Do as generateApiKeyToken, zc as getConnectionResolver, Gr as getConnectionSubject, q as getFieldCipher, $c as getResourcePolicy, Dr as getRowFilter, du as getSystemStoreHandle, Od as getTimelineRecorder, gl as getTupleSource, $ as groupKeyOf, yr as histogramMetric, dp as historyProvenance, uo as httpSecretsBackend, Xt as inspectWorkflow, _l as installPolicyGuardResolver, Xr as interruptConnectionStreams, rd as invertChange, kf as isAggregateDefinition, If as isEmptyTenantScopedRead, Sn as isForeignKeyViolation, af as isIdleNow, Ta as isInfraError, xi as isObservingGraph, Lf as isOrglessUserSubject, Cn as isQueryTimeout, od as isSafeToApply, _u as isScheduleDefinition, tu as isSoftDelete, ss as isWorkflowEventTriggerDefinition, Fd as ivmValue, up as lastWriteProvenance, dc as listConnectionStates, el as listResourcePolicies, pe as listRetentions, Hd as loadResourceTuples, Gd as loadSubjectTuples, pu as localityAwareSelector, ap as makeActionRunner, Bu as makeAdvisoryLockCoordinator, ci as makeAesCipher, Ao as makeApiKeyService, Dl as makeApiKeyUsageBuffer, Po as makeApiKeyUsageFlusher, wn as makeAppAccess, Co as makeAsyncKv, Es as makeBufferGapDetector, no as makeBufferingSpanProcessor, nc as makeConnectionRegistry, Vc as makeConnectionResolver, Hc as makeConnectionsFacade, Ku as makeCoordinatedScheduler, yl as makeDataLoader, Jc as makeDisconnectConnectionExecutor, Uo as makeEffectStoreLayer, Ss as makeEventPublisher, ps as makeEventsFacade, li as makeFieldCipher, Fi as makeFluentStore, of as makeIdleGate, ns as makeLazyWorkflowFacade, Gc as makeListConnectionsExecutor, Oa as makeMutationOutputCodec, Zf as makeMutationRunner, rp as makeOneShotQueryRunner, zs as makeOutboxFacade, es as makePostCommitWorkflowFacade, tf as makeProcessAdapter, np as makeQueryDescriptorProducer, tp as makeQueryReauthorizer, ip as makeQuerySubscriber, sf as makeRouterActivity, Ml as makeSchemaRegistry, Kc as makeStartConnectionExecutor, qc as makeSubmitTokenExecutor, td as makeUndoCapture, cf as makeWakeGate, df as makeWakeProxyServer, $o as makeWorkflowFacade, ts as makeWorkflowFacadeWithCallerContext, rs as makeWorkflowHandlers, is as makeWorkflowLayers, Ko as makeWorkflowRunHandle, Eu as markWakeupFired, Ld as materializeIvm, jo as memoryApiKeyStore, hu as memoryReplicationAdapter, Ji as memoryRywPositionStore, xu as nextFiring, Nu as nextWakeup, rf as nodeProcessSupervisor, Sf as noopAnalytics, Tf as noopAnalyticsSpec, wo as noopKv, Ei as observeStore, wi as observedGraph, qr as onBindConnectionSubject, Ia as onProcessShutdown, Is as outboxAttemptsTable, Ns as outboxTable, ni as parseTraceparent, Zo as payloadPropertyNames, Ki as powerOfTwoSelector, gp as previewInRollback, oc as projectConnectionState, Fu as pruneWakeups, bs as publishEvent, nl as rebacPolicyGraph, sr as recordEventDelivered, cr as recordEventDropped, or as recordEventPublished, lr as recordEventSubscribers, ur as recordSample, hr as recordScheduleRun, mr as recordSubscriptionActive, fr as recordSubscriptionDelivery, Ci as recordTableAccess, Ad as recordTimelineEvent, gr as recordWorkflowRun, Vl as redactColumns, Cd as redactRow, Xi as redisRywPositionStore, yd as redoUndoInvocation, hc as refreshAccessToken, Yr as registerConnectionStream, Ce as registerRetention, wu as registerWakeup, ku as releaseWakeup, qi as replicaHealth, ha as resetComputedQueryCacheWarnings, ir as resetEventMetricTagCacheForTests, Ti as resetObservedGraph, oo as resetSecretsBackend, Tc as resolveConnection, Bc as resolveConnectionForSubject, mu as resolveCurrentRegion, Tn as resolveDependentTables, Nc as resolveRedirectUri, zd as resolveRescan, kr as resolveRowFilterScope, Ar as resolveRowFilterScopeFor, so as resolveSecret, co as resolveSecretSync, fo as resolveSecretsBackend, bd as resolveTimelineMode, Te as retentionTtlMsFromEnv, Td as reverseEventOverRows, cl as revokedIds, nu as rulesFor, fu as runAsSystem, pf as runOrchestratorTick, Bf as runProvidedEffect, Zd as runReaction, mf as runSingleNodeOrchestrator, ef as runWakeLoop, Xf as runWithDeadlockRetry, Si as runWithObservedProcedure, fl as runWithRequestLoader, $i as runWithRoutingContext, ai as runWithTraceContext, Mc as sanitizeRedirectTo, Gu as scheduleCoordinated, Kl as schemaPropertyNames, Jl as serverOnlyLeaks, Rc as setConnectionResolver, di as setFieldCipher, Er as setRowFilter, ao as setSecretsBackend, lu as setSystemStoreHandle, kd as setTimelineRecorderForTest, hl as setTupleSource, Qt as settleHandlerBody, Eo as sha256Hex, Ba as shutdownGraceMsFromEnv, Ru as singleCoordinator, xr as snapshotMetrics, Sr as snapshotMetricsSync, El as ssrfGuardHttpClientLayer, Tl as ssrfReason, Ma as startRpcServer, Hu as startScheduler, cc as storeCredential, Ic as sweepExpiredGrants, Me as sweepRetention, id as synthesizeInverse, bl as tracingHttpClientLayer, as as triggerWorkflow, Ou as tryClaimWakeup, Kr as unbindConnectionSubject, Zu as undoCaptureEnabled, gd as undoLogExecutor, $l as unresolvedSources, Pf as useAggregate, bf as useAnalytics, sl as visibleRows, $d as wakeDueOnce, Uf as withRowFilter, Wo as workflowToRpc, ed as wrapCaptureStore, Rl as wrapStoreWithBootCodec, Gi as wrapStoreWithMixinBehaviour };
7687
+ export { Oo as API_KEYS_TABLE, $c as AccessDenied, Rf as AggregateError, Kd as AggregateMaintainer, Lf as AggregateNotFound, zf as AggregateRegistry, If as AggregateStale, Cf as AnalyticsCapabilityNotSupported, Sf as AnalyticsError, wf as AnalyticsSink, X as CONNECTIONS_TABLE, Qs as CONNECTION_GRANTS_TABLE, pu as CircuitBreaker, du as CircuitOpen, xc as ConnectionNotConnected, Pa as DEFAULT_MAX_RPC_BODY_BYTES, yc as DEFAULT_REFRESH_SKEW_MS, wr as DEFAULT_ROW_FILTER_RETRY, Uu as DORMANCY_WAKEUP_TENANT, Li as DeleteBuilder, Ir as Dispatcher, Es as EVENT_CLIENT_QUEUE_SIZE, Ds as EVENT_LATEST_QUEUE_SIZE, Uo as EffectStore, xs as EventBus, Nc as GRANT_TTL_MS, yn as InMemoryDataStore, sn as IndexedMatcher, Ns as InstanceMembership, $t as LinearScanMatcher, p as MetricBoundaries, Df as NOOP_ANALYTICS_PROVIDER, Or as NO_ROW_FILTER, Ai as NoRowFound, Ls as OUTBOX_ATTEMPTS_TABLE, Ws as OUTBOX_ATTEMPT_LOG_CAP, Y as OUTBOX_TABLE, ji as OptimisticLockError, Qc as REBAC_ADMIN_SCOPE, bc as REFRESH_LEASE_MS, wp as RUNTIME_NAME, nf as ReactionRateLimiter, ia as ReplicatedDataStore, Cr as RowFilterUnavailable, Hu as SCHEDULE_SUBJECT, Ho as SYSTEM_SUBJECT, Fi as SelectBuilder, wl as SsrfBlockedError, Bi as StoreOperationFailed, un as SubscriptionRegistry, Vi as TableValidationFailed, zi as TenantScopeViolation, Md as TimelineRecorder, dd as UndoBoundaryError, pd as UndoStack, Ii as UpdateBuilder, jl as VOLTRO_AUDIT_MIXIN_ID, Nl as VOLTRO_EXPIRES_MIXIN_ID, Ml as VOLTRO_SOFT_DELETE_MIXIN_ID, Pl as VOLTRO_TENANT_MIXIN_ID, $o as WorkflowPayloadError, ei as _connectionStreamCount, ti as _resetConnectionSubjectsForTest, ec as _voltroConnectionGrantsTable, Zs as _voltroConnectionsTable, qd as _voltroRebacTuplesTable, ed as _voltroScheduleClaimsTable, $u as _voltroScheduleRunsTable, td as _voltroTracesTable, nd as _voltroUndoLogTable, af as _voltroWakeupsTable, hs as _voltroWorkflowEventDeliveriesTable, ms as _voltroWorkflowEventsTable, qi as actingUserId, Vo as apiKeyManagementRoutes, Wi as applyDefined, Wd as applyDelta, hd as applyInverse, gd as applyInverses, lu as applyPluginRefRules, Mr as applyRowFilter, Nr as applyRowFilterToDescriptor, Wf as applySoftDeleteScope, Vf as applyTenantScope, wd as applyUndoInvocation, ll as assertCan, ic as assertConnectionCipherConfigured, Nf as attachAnalyticsMirror, Ka as awaitServerListening, Us as backoffMs, Lc as beginOAuthConnect, qr as bindConnectionSubject, As as bindEvent, Na as bindMutation, Sa as bindStream, xa as bindSubscription, ga as bindSubscriptionUntyped, Hd as buildIvmState, xp as buildPreview, Xd as buildRebacInterceptor, Qd as buildRebacReadFilter, Qi as buildSubjectKey, Za as buildTracingLayer, $l as cacheScopeLeaks, po as cachedBackend, cl as can, ju as cancelWakeup, cn as canonicalize, Rd as classifyShape, Tc as clearConnectionRefreshFlights, il as clearResourcePolicies, ee as clearRetentions, gu as clearSystemStoreHandle, uu as collectPluginRefRules, Eu as compileCron, Rc as completeOAuthConnect, Af as composeAnalytics, kf as composeAnalyticsSinks, Pc as connectionCallbackPath, rc as connectionLabel, ni as connectionSubjectsSnapshot, vf as countRunningWorkflows, _r as counter, Jl as crud, ml as currentRequestLoader, ra as currentRoutingContext, li as currentTraceContext, Ro as dataStoreApiKeyStore, bo as dataStoreIdempotencyStore, To as dataStoreKvStore, _i as decryptField, Pf as defineAggregate, nc as defineConnection, ls as defineEventTrigger, Kf as defineExecutor, Bs as defineOutboxHandler, $d as defineReaction, tl as defineResourcePolicy, Tu as defineSchedule, xf as defineSubscriber, Pr as deliveredRowCount, ui as deriveKey, bp as diffChange, Wa as drainForShutdown, Js as drainOutbox, Ru as dueWakeups, sl as effectiveRelations, zl as emptySchemaRegistry, Ci as enableGraphObservation, gi as encryptField, pl as enterRequestLoader, oo as envSecretsBackend, ar as eventMetricTagCacheSizeForTests, _c as exchangeAuthorizationCode, oi as externalSpanFromTraceparent, xn as extractDbCause, ln as fingerprintFor, pc as forgetCredential, eu as formatCacheScopeLeaks, Ql as formatServerOnlyLeaks, ii as formatTraceparent, ru as formatUnresolvedSources, md as forwardChangeFromCdc, zo as frameworkApiKeyStrategy, vr as gauge, Ao as generateApiKeyToken, Hc as getConnectionResolver, Jr as getConnectionSubject, Kr as getCredentialExpiry, q as getFieldCipher, nl as getResourcePolicy, Dr as getRowFilter, _u as getSystemStoreHandle, Pd as getTimelineRecorder, yl as getTupleSource, $ as groupKeyOf, yr as histogramMetric, vp as historyProvenance, mo as httpSecretsBackend, Xt as inspectWorkflow, bl as installPolicyGuardResolver, $r as interruptConnectionStreams, ld as invertChange, Ff as isAggregateDefinition, Hf as isEmptyTenantScopedRead, Sn as isForeignKeyViolation, df as isIdleNow, Oa as isInfraError, wi as isObservingGraph, Uf as isOrglessUserSubject, Cn as isQueryTimeout, fd as isSafeToApply, Cu as isScheduleDefinition, su as isSoftDelete, us as isWorkflowEventTriggerDefinition, Vd as ivmValue, _p as lastWriteProvenance, mc as listConnectionStates, rl as listResourcePolicies, pe as listRetentions, Jd as loadResourceTuples, Zd as loadSubjectTuples, yu as localityAwareSelector, fp as makeActionRunner, Ku as makeAdvisoryLockCoordinator, di as makeAesCipher, No as makeApiKeyService, Al as makeApiKeyUsageBuffer, Lo as makeApiKeyUsageFlusher, wn as makeAppAccess, Eo as makeAsyncKv, ks as makeBufferGapDetector, ao as makeBufferingSpanProcessor, ac as makeConnectionRegistry, Wc as makeConnectionResolver, Gc as makeConnectionsFacade, Qu as makeCoordinatedScheduler, Sl as makeDataLoader, Zc as makeDisconnectConnectionExecutor, Ko as makeEffectStoreLayer, Ts as makeEventPublisher, gs as makeEventsFacade, fi as makeFieldCipher, Ri as makeFluentStore, ff as makeIdleGate, as as makeLazyWorkflowFacade, Jc as makeListConnectionsExecutor, ja as makeMutationOutputCodec, ip as makeMutationRunner, up as makeOneShotQueryRunner, Hs as makeOutboxFacade, rs as makePostCommitWorkflowFacade, cf as makeProcessAdapter, lp as makeQueryDescriptorProducer, Gf as makeQueryFinalizer, cp as makeQueryReauthorizer, dp as makeQuerySubscriber, pf as makeRouterActivity, Fl as makeSchemaRegistry, Yc as makeStartConnectionExecutor, Xc as makeSubmitTokenExecutor, sd as makeUndoCapture, mf as makeWakeGate, _f as makeWakeProxyServer, ns as makeWorkflowFacade, is as makeWorkflowFacadeWithCallerContext, os as makeWorkflowHandlers, ss as makeWorkflowLayers, Yo as makeWorkflowRunHandle, Mu as markWakeupFired, Ud as materializeIvm, Po as memoryApiKeyStore, xu as memoryReplicationAdapter, Zi as memoryRywPositionStore, Du as nextFiring, zu as nextWakeup, uf as nodeProcessSupervisor, Of as noopAnalytics, jf as noopAnalyticsSpec, Do as noopKv, ki as observeStore, Di as observedGraph, Xr as onBindConnectionSubject, za as onProcessShutdown, zs as outboxAttemptsTable, Is as outboxTable, ai as parseTraceparent, es as payloadPropertyNames, Yi as powerOfTwoSelector, Cp as previewInRollback, lc as projectConnectionState, Vu as pruneWakeups, Cs as publishEvent, al as rebacPolicyGraph, Gr as recordCredentialExpiry, sr as recordEventDelivered, cr as recordEventDropped, or as recordEventPublished, lr as recordEventSubscribers, ur as recordSample, hr as recordScheduleRun, mr as recordSubscriptionActive, fr as recordSubscriptionDelivery, Ei as recordTableAccess, Id as recordTimelineEvent, gr as recordWorkflowRun, Wl as redactColumns, kd as redactRow, $i as redisRywPositionStore, Td as redoUndoInvocation, vc as refreshAccessToken, Qr as registerConnectionStream, Ce as registerRetention, Au as registerWakeup, Fu as releaseWakeup, Xi as replicaHealth, va as resetComputedQueryCacheWarnings, ir as resetEventMetricTagCacheForTests, Oi as resetObservedGraph, lo as resetSecretsBackend, Oc as resolveConnection, Uc as resolveConnectionForSubject, bu as resolveCurrentRegion, Tn as resolveDependentTables, Ic as resolveRedirectUri, Gd as resolveRescan, kr as resolveRowFilterScope, Ar as resolveRowFilterScopeFor, uo as resolveSecret, fo as resolveSecretSync, ho as resolveSecretsBackend, Ed as resolveTimelineMode, Te as retentionTtlMsFromEnv, jd as reverseEventOverRows, dl as revokedIds, cu as rulesFor, vu as runAsSystem, yf as runOrchestratorTick, qf as runProvidedEffect, rf as runReaction, bf as runSingleNodeOrchestrator, sf as runWakeLoop, rp as runWithDeadlockRetry, Ti as runWithObservedProcedure, hl as runWithRequestLoader, na as runWithRoutingContext, ci as runWithTraceContext, Fc as sanitizeRedirectTo, Zu as scheduleCoordinated, Yl as schemaPropertyNames, Zl as serverOnlyLeaks, Vc as setConnectionResolver, mi as setFieldCipher, Er as setRowFilter, co as setSecretsBackend, hu as setSystemStoreHandle, Fd as setTimelineRecorderForTest, vl as setTupleSource, Qt as settleHandlerBody, ko as sha256Hex, Ua as shutdownGraceMsFromEnv, Wu as singleCoordinator, xr as snapshotMetrics, Sr as snapshotMetricsSync, kl as ssrfGuardHttpClientLayer, Ol as ssrfReason, Fa as startRpcServer, Ju as startScheduler, dc as storeCredential, zc as sweepExpiredGrants, Me as sweepRetention, ud as synthesizeInverse, Cl as tracingHttpClientLayer, cs as triggerWorkflow, Pu as tryClaimWakeup, Yr as unbindConnectionSubject, rd as undoCaptureEnabled, Sd as undoLogExecutor, nu as unresolvedSources, Bf as useAggregate, Ef as useAnalytics, ul as visibleRows, of as wakeDueOnce, Xf as withRowFilter, qo as workflowToRpc, od as wrapCaptureStore, Vl as wrapStoreWithBootCodec, Ji as wrapStoreWithMixinBehaviour };