@voltro/runtime 0.26.0 → 0.27.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,11 +5687,11 @@ 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.op === "update" && (e.old?.deletedAt ?? null) === null && (e.new?.deletedAt ?? null) !== null, au = (e, t) => {
5691
+ let n = iu(t);
5679
5692
  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);
5693
+ }, ou = async (e, t, n) => {
5694
+ let r = au(t, n);
5682
5695
  if (r.length === 0) return [];
5683
5696
  let i = [];
5684
5697
  for (let t of r) {
@@ -5704,47 +5717,45 @@ behind quietly.`;
5704
5717
  });
5705
5718
  }
5706
5719
  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;
5720
+ }, su = (e, t) => {
5721
+ let n = [];
5722
+ for (let r of e) for (let e of r.appliedPluginRefs ?? []) {
5723
+ let i = e.column, a;
5713
5724
  try {
5714
- s = o.target()?.name;
5725
+ a = e.target()?.tableName;
5715
5726
  } 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
5727
+ a = void 0;
5728
+ }
5729
+ 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.`);
5730
+ n.push({
5731
+ table: r.name,
5732
+ column: i,
5733
+ targetTable: a,
5734
+ policy: e.orphanPolicy,
5735
+ onSoftDelete: e.onSoftDelete
5725
5736
  });
5726
5737
  }
5727
- return r.filter((e) => e.policy !== "keep");
5728
- }, au = class extends y.TaggedError()("CircuitOpen", {
5738
+ return n.filter((e) => e.policy !== "keep");
5739
+ }, cu = class extends y.TaggedError()("CircuitOpen", {
5729
5740
  name: y.String,
5730
5741
  retryAfterMs: y.Number
5731
- }) {}, ou = {
5742
+ }) {}, lu = {
5732
5743
  tag: "closed",
5733
5744
  failureCount: 0,
5734
5745
  halfOpenSuccesses: 0,
5735
5746
  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* () {
5747
+ }, uu = { make: (n) => o.gen(function* () {
5748
+ let r = n.name ?? "circuit", i = a.toMillis(a.decode(n.resetTimeout)), s = n.halfOpenSuccessThreshold ?? 1, c = n.isFailure ?? (() => !0), l = yield* _.make(lu), u = o.gen(function* () {
5738
5749
  let e = yield* _.get(l);
5739
5750
  if (e.tag === "half-open") {
5740
5751
  let t = e.halfOpenSuccesses + 1;
5741
- yield* _.set(l, t >= s ? ou : {
5752
+ yield* _.set(l, t >= s ? lu : {
5742
5753
  ...e,
5743
5754
  halfOpenSuccesses: t
5744
5755
  });
5745
5756
  return;
5746
5757
  }
5747
- e.failureCount !== 0 && (yield* _.set(l, ou));
5758
+ e.failureCount !== 0 && (yield* _.set(l, lu));
5748
5759
  }), d = o.gen(function* () {
5749
5760
  let e = yield* t.currentTimeMillis, r = yield* _.get(l);
5750
5761
  if (r.tag === "half-open" || r.tag === "open") {
@@ -5782,7 +5793,7 @@ behind quietly.`;
5782
5793
  if (e.isInterruptedOnly(t)) return o.void;
5783
5794
  let n = e.failureOption(t), r = n._tag === "Some" ? n.value : void 0;
5784
5795
  return c(r) ? d : o.void;
5785
- })) : yield* o.fail(new au({
5796
+ })) : yield* o.fail(new cu({
5786
5797
  name: r,
5787
5798
  retryAfterMs: n
5788
5799
  }));
@@ -5791,25 +5802,25 @@ behind quietly.`;
5791
5802
  value: _.get(l).pipe(o.map((e) => e.tag)),
5792
5803
  enumerable: !0
5793
5804
  }), Object.defineProperty(m, "reset", {
5794
- value: _.set(l, ou),
5805
+ value: _.set(l, lu),
5795
5806
  enumerable: !0
5796
5807
  }), 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;
5808
+ }) }, du, fu = (e) => {
5809
+ du = e;
5810
+ }, pu = () => {
5811
+ du = void 0;
5812
+ }, mu = () => du, hu = async (e, t = {}) => {
5813
+ let n = t.scopes === void 0 ? vt(t.id ?? "system") : vt(t.id ?? "system", t.scopes), r = t.store ?? du?.dataStore, i = t.schemaRegistry ?? du?.schemaRegistry, a = t.dialect ?? du?.dialect;
5803
5814
  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
5815
  return e({
5805
5816
  subject: n,
5806
- store: Gi(r, {
5817
+ store: Ji(r, {
5807
5818
  subject: n,
5808
5819
  schemaRegistry: i,
5809
5820
  ...a === void 0 ? {} : { dialect: a }
5810
5821
  })
5811
5822
  });
5812
- }, pu = (e) => {
5823
+ }, gu = (e) => {
5813
5824
  let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
5814
5825
  if (t === void 0) return {
5815
5826
  sameRegion: [],
@@ -5837,7 +5848,7 @@ behind quietly.`;
5837
5848
  return r.loadSnapshot();
5838
5849
  }
5839
5850
  };
5840
- }, mu = (e = process.env) => {
5851
+ }, _u = (e = process.env) => {
5841
5852
  for (let t of [
5842
5853
  "VOLTRO_REGION",
5843
5854
  "AWS_REGION",
@@ -5849,7 +5860,7 @@ behind quietly.`;
5849
5860
  let n = e[t];
5850
5861
  if (typeof n == "string" && n.length > 0) return n;
5851
5862
  }
5852
- }, hu = () => {
5863
+ }, vu = () => {
5853
5864
  let e = {
5854
5865
  primary: 0,
5855
5866
  lagByReplica: /* @__PURE__ */ new Map()
@@ -5874,7 +5885,7 @@ behind quietly.`;
5874
5885
  e.lagByReplica.set(t, n);
5875
5886
  }
5876
5887
  };
5877
- }, gu = Symbol.for("@voltro/ScheduleDefinition"), _u = (e) => typeof e == "object" && !!e && gu in e, vu = 30 * 6e4, yu = (e) => {
5888
+ }, yu = Symbol.for("@voltro/ScheduleDefinition"), bu = (e) => typeof e == "object" && !!e && yu in e, xu = 30 * 6e4, Su = (e) => {
5878
5889
  let t = r.parse(e.cron, e.timezone);
5879
5890
  if (s.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
5880
5891
  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 +5894,18 @@ behind quietly.`;
5883
5894
  ...e,
5884
5895
  onOverlap: e.onOverlap ?? "skip",
5885
5896
  backfill: e.backfill ?? "skip",
5886
- maxRuntimeMs: e.maxRuntimeMs ?? vu,
5887
- [gu]: !0
5897
+ maxRuntimeMs: e.maxRuntimeMs ?? xu,
5898
+ [yu]: !0
5888
5899
  };
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) => ({
5900
+ }, Cu = (e) => r.unsafeParse(e.cron, e.timezone), wu = (e, t = /* @__PURE__ */ new Date()) => r.next(Cu(e), t), Z = "_voltro_wakeups", Tu = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Eu = (e) => ({
5890
5901
  tenantId: String(e.tenantId),
5891
5902
  kind: String(e.kind),
5892
5903
  refId: String(e.refId),
5893
5904
  wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
5894
5905
  status: e.status === "fired" ? "fired" : "pending"
5895
- }), wu = async (e, t) => {
5906
+ }), Du = async (e, t) => {
5896
5907
  await e.upsert(Z, {
5897
- id: Su(t),
5908
+ id: Tu(t),
5898
5909
  tenantId: t.tenantId,
5899
5910
  kind: t.kind,
5900
5911
  refId: t.refId,
@@ -5904,7 +5915,7 @@ behind quietly.`;
5904
5915
  conflictColumns: ["id"],
5905
5916
  update: ["wakeAt", "status"]
5906
5917
  });
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: [{
5918
+ }, Ou = async (e, t) => e.delete(Z, Tu(t)), ku = async (e, t) => await e.update(Z, Tu(t), { status: "fired" }) !== null, Au = (e, t) => ({ and: [{
5908
5919
  column: "id",
5909
5920
  op: "eq",
5910
5921
  value: e
@@ -5912,16 +5923,16 @@ behind quietly.`;
5912
5923
  column: "status",
5913
5924
  op: "eq",
5914
5925
  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 = {
5926
+ }] }), ju = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: Au(Tu(t), "pending") }) > 0, Mu = async (e, t) => {
5927
+ await e.updateMany(Z, { status: "pending" }, { where: Au(Tu(t), "fired") });
5928
+ }, Nu = {
5918
5929
  column: "status",
5919
5930
  op: "eq",
5920
5931
  value: "pending"
5921
- }, ju = async (e, t) => {
5932
+ }, Pu = async (e, t) => {
5922
5933
  let n = {
5923
5934
  table: Z,
5924
- predicate: Au,
5935
+ predicate: Nu,
5925
5936
  order: [{
5926
5937
  column: "wakeAt",
5927
5938
  direction: "asc"
@@ -5930,18 +5941,18 @@ behind quietly.`;
5930
5941
  skip: void 0,
5931
5942
  projection: void 0
5932
5943
  };
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();
5944
+ return (await e.query(n)).map(Eu);
5945
+ }, Fu = async (e, t, n = 500) => {
5946
+ let r = await Pu(e, n), i = t.getTime();
5936
5947
  return r.filter((e) => e.wakeAt.getTime() <= i);
5937
- }, Nu = async (e) => (await ju(e, 1))[0] ?? null, Pu = {
5948
+ }, Iu = async (e) => (await Pu(e, 1))[0] ?? null, Lu = {
5938
5949
  column: "status",
5939
5950
  op: "eq",
5940
5951
  value: "fired"
5941
- }, Fu = async (e, t = {}) => {
5952
+ }, Ru = async (e, t = {}) => {
5942
5953
  let n = {
5943
5954
  table: Z,
5944
- predicate: Pu,
5955
+ predicate: Lu,
5945
5956
  order: [{
5946
5957
  column: "wakeAt",
5947
5958
  direction: "asc"
@@ -5952,12 +5963,12 @@ behind quietly.`;
5952
5963
  }, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
5953
5964
  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
5965
  return a;
5955
- }, Iu = zo, Lu = "default", Ru = {
5966
+ }, zu = Ho, Bu = "default", Vu = {
5956
5967
  kind: "single",
5957
5968
  tryClaim: async () => !0
5958
- }, zu = "_voltro_schedule_claims", Bu = (e, t, n) => {
5969
+ }, Hu = "_voltro_schedule_claims", Uu = (e, t, n) => {
5959
5970
  let r = async (t) => (await e.query({
5960
- table: zu,
5971
+ table: Hu,
5961
5972
  order: [],
5962
5973
  predicate: void 0,
5963
5974
  projection: ["id"],
@@ -5972,7 +5983,7 @@ behind quietly.`;
5972
5983
  if (await r(s)) return !1;
5973
5984
  } catch {}
5974
5985
  try {
5975
- return await e.insert(zu, {
5986
+ return await e.insert(Hu, {
5976
5987
  id: s,
5977
5988
  scheduleName: i,
5978
5989
  bucket: o,
@@ -5990,12 +6001,12 @@ behind quietly.`;
5990
6001
  }
5991
6002
  }
5992
6003
  };
5993
- }, Vu = "_voltro_schedule_runs", Hu = async (e, t) => {
6004
+ }, Wu = "_voltro_schedule_runs", Gu = async (e, t) => {
5994
6005
  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));
6006
+ c?.(e, qu(t));
5996
6007
  }, v = async (e, t, r, i, a, c) => {
5997
6008
  try {
5998
- let s = `sr_${Re()}`, l = await n.insert(Vu, {
6009
+ let s = `sr_${Re()}`, l = await n.insert(Wu, {
5999
6010
  id: s,
6000
6011
  name: e.name,
6001
6012
  status: i,
@@ -6020,7 +6031,7 @@ behind quietly.`;
6020
6031
  }
6021
6032
  }, y = async (e, t) => {
6022
6033
  try {
6023
- let r = await n.update(Vu, e, t);
6034
+ let r = await n.update(Wu, e, t);
6024
6035
  r && _("update", r);
6025
6036
  } catch (t) {
6026
6037
  s.warn("schedule: failed to record run finish", {
@@ -6031,7 +6042,7 @@ behind quietly.`;
6031
6042
  }, b = async (e) => {
6032
6043
  try {
6033
6044
  let t = await n.query({
6034
- table: Vu,
6045
+ table: Wu,
6035
6046
  predicate: {
6036
6047
  _tag: "leaf",
6037
6048
  column: "status",
@@ -6066,7 +6077,7 @@ behind quietly.`;
6066
6077
  scheduleName: e.name,
6067
6078
  trigger: n,
6068
6079
  runId: o,
6069
- subject: Iu
6080
+ subject: zu
6070
6081
  })
6071
6082
  };
6072
6083
  try {
@@ -6102,7 +6113,7 @@ behind quietly.`;
6102
6113
  let n = Q(t).includes("exceeded maxRuntimeMs"), r = xn(t).dbMessage, i = typeof r == "string" && r !== "" ? `${Q(t)} — ${r}` : Q(t);
6103
6114
  o && await y(o, {
6104
6115
  status: "failed",
6105
- errorTag: n ? "timeout" : Uu(t),
6116
+ errorTag: n ? "timeout" : Ku(t),
6106
6117
  errorMessage: i,
6107
6118
  completedAt: /* @__PURE__ */ new Date(),
6108
6119
  durationMs: Date.now() - c
@@ -6166,8 +6177,8 @@ behind quietly.`;
6166
6177
  }
6167
6178
  }, w = async (e) => {
6168
6179
  try {
6169
- let t = r.next(bu(e), /* @__PURE__ */ new Date());
6170
- await wu(n, {
6180
+ let t = r.next(Cu(e), /* @__PURE__ */ new Date());
6181
+ await Du(n, {
6171
6182
  tenantId: d,
6172
6183
  kind: "schedule",
6173
6184
  refId: e.name,
@@ -6181,7 +6192,7 @@ behind quietly.`;
6181
6192
  }
6182
6193
  }, T = 2147483647, E = (e) => {
6183
6194
  if (h) return;
6184
- let n = bu(e), i = r.next(n, /* @__PURE__ */ new Date()), a = () => {
6195
+ let n = Cu(e), i = r.next(n, /* @__PURE__ */ new Date()), a = () => {
6185
6196
  if (h) return;
6186
6197
  let n = i.getTime() - Date.now();
6187
6198
  if (n > T) {
@@ -6203,7 +6214,7 @@ behind quietly.`;
6203
6214
  let i;
6204
6215
  try {
6205
6216
  let t = (await n.query({
6206
- table: Vu,
6217
+ table: Wu,
6207
6218
  order: [{
6208
6219
  column: "scheduledAt",
6209
6220
  direction: "desc"
@@ -6222,7 +6233,7 @@ behind quietly.`;
6222
6233
  return;
6223
6234
  }
6224
6235
  if (!i) return;
6225
- let a = bu(e), o = [], c = r.next(a, i), l = Date.now();
6236
+ let a = Cu(e), o = [], c = r.next(a, i), l = Date.now();
6226
6237
  for (; c.getTime() < l && o.length < 1e3;) o.push(c), c = r.next(a, c);
6227
6238
  if (o.length !== 0) if (s.info("schedule: backfill", {
6228
6239
  name: e.name,
@@ -6267,11 +6278,11 @@ behind quietly.`;
6267
6278
  f.clear(), s.info("scheduler: stopped");
6268
6279
  }
6269
6280
  };
6270
- }, Q = (e) => e?.message ?? String(e), Uu = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Wu = (e) => {
6281
+ }, Q = (e) => e?.message ?? String(e), Ku = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, qu = (e) => {
6271
6282
  let t = {};
6272
6283
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
6273
6284
  return t;
6274
- }, Gu = (e, t, n, r) => {
6285
+ }, Ju = (e, t, n, r) => {
6275
6286
  let i = !1, a, o = async () => {
6276
6287
  if (i) return;
6277
6288
  let a = new Date(Math.floor(Date.now() / t) * t), o = !1;
@@ -6301,7 +6312,7 @@ behind quietly.`;
6301
6312
  i || (i = !0, a && clearInterval(a), a = void 0);
6302
6313
  }
6303
6314
  };
6304
- }, Ku = (e) => (t, n, r) => Gu(t, n, r, e), qu = F("_voltro_schedule_runs", {
6315
+ }, Yu = (e) => (t, n, r) => Ju(t, n, r, e), Xu = F("_voltro_schedule_runs", {
6305
6316
  id: M({ prefix: "schrun" }),
6306
6317
  name: I(),
6307
6318
  status: I().oneOf([
@@ -6331,13 +6342,13 @@ behind quietly.`;
6331
6342
  ]).nullable(),
6332
6343
  replicaId: I().nullable(),
6333
6344
  result: P().nullable()
6334
- }).index(["name", "scheduledAt"]).index(["status"]), Ju = F("_voltro_schedule_claims", {
6345
+ }).index(["name", "scheduledAt"]).index(["status"]), Zu = F("_voltro_schedule_claims", {
6335
6346
  id: M({ prefix: "schclaim" }),
6336
6347
  scheduleName: I(),
6337
6348
  bucket: I(),
6338
6349
  claimedBy: I(),
6339
6350
  claimedAt: L()
6340
- }).index(["scheduleName", "bucket"]).index(["claimedAt"]), Yu = F("_voltro_traces", {
6351
+ }).index(["scheduleName", "bucket"]).index(["claimedAt"]), Qu = F("_voltro_traces", {
6341
6352
  id: M({ prefix: "span" }),
6342
6353
  traceId: I(),
6343
6354
  spanId: I(),
@@ -6361,7 +6372,7 @@ behind quietly.`;
6361
6372
  durationMs: N(),
6362
6373
  attributes: P().nullable(),
6363
6374
  events: P().nullable()
6364
- }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Xu = F("_voltro_undo_log", {
6375
+ }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), $u = F("_voltro_undo_log", {
6365
6376
  id: M({ prefix: "undo" }),
6366
6377
  tag: I(),
6367
6378
  label: I().nullable(),
@@ -6372,25 +6383,25 @@ behind quietly.`;
6372
6383
  crossesAction: E().default(!1),
6373
6384
  undone: E().default(!1),
6374
6385
  createdAt: L().default("now")
6375
- }).index(["subjectId", "createdAt"]), Zu = (e = process.env) => {
6386
+ }).index(["subjectId", "createdAt"]), ed = (e = process.env) => {
6376
6387
  let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
6377
6388
  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({
6389
+ }, td = (e) => e.startsWith("_voltro"), nd = async (e, t, n) => (await e.query({
6379
6390
  table: t,
6380
6391
  predicate: O("id", n),
6381
6392
  order: []
6382
- }))[0] ?? null, ed = (e, t) => new Proxy(e, { get(e, n, r) {
6393
+ }))[0] ?? null, rd = (e, t) => new Proxy(e, { get(e, n, r) {
6383
6394
  if (n === "insert") return async (n, r) => {
6384
6395
  let i = await e.insert(n, r);
6385
- return Qu(n) || t({
6396
+ return td(n) || t({
6386
6397
  table: n,
6387
6398
  op: "insert",
6388
6399
  next: i
6389
6400
  }), i;
6390
6401
  };
6391
6402
  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({
6403
+ let a = td(n) ? null : await nd(e, n, r), o = await e.update(n, r, i);
6404
+ return td(n) || t({
6394
6405
  table: n,
6395
6406
  op: "update",
6396
6407
  id: r,
@@ -6399,8 +6410,8 @@ behind quietly.`;
6399
6410
  }), o;
6400
6411
  };
6401
6412
  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({
6413
+ let i = td(n) ? null : await nd(e, n, r), a = await e.delete(n, r);
6414
+ return !td(n) && a && t({
6404
6415
  table: n,
6405
6416
  op: "delete",
6406
6417
  id: r,
@@ -6409,10 +6420,10 @@ behind quietly.`;
6409
6420
  };
6410
6421
  let i = Reflect.get(e, n, r);
6411
6422
  return typeof i == "function" ? i.bind(e) : i;
6412
- } }), td = (e) => {
6423
+ } }), id = (e) => {
6413
6424
  let t = [];
6414
6425
  return {
6415
- tx: ed(e, (e) => t.push(e)),
6426
+ tx: rd(e, (e) => t.push(e)),
6416
6427
  persist: async (e, n) => {
6417
6428
  if (t.length === 0 || n.tag.startsWith("__voltro")) return;
6418
6429
  let r = n.subject;
@@ -6428,14 +6439,14 @@ behind quietly.`;
6428
6439
  });
6429
6440
  }
6430
6441
  };
6431
- }, nd = (e) => {
6442
+ }, ad = (e) => {
6432
6443
  if (e.id !== void 0) return e.id;
6433
6444
  let t = e.next?.id;
6434
6445
  if (typeof t == "string") return t;
6435
6446
  let n = e.prev?.id;
6436
6447
  return typeof n == "string" ? n : void 0;
6437
- }, rd = (e) => {
6438
- let t = nd(e);
6448
+ }, od = (e) => {
6449
+ let t = ad(e);
6439
6450
  switch (e.op) {
6440
6451
  case "insert": return t === void 0 ? null : {
6441
6452
  table: e.table,
@@ -6459,28 +6470,28 @@ behind quietly.`;
6459
6470
  row: e.prev
6460
6471
  };
6461
6472
  }
6462
- }, id = (e) => {
6463
- if (e.crossesAction) throw new ad(e.invocationId, "action");
6473
+ }, sd = (e) => {
6474
+ if (e.crossesAction) throw new cd(e.invocationId, "action");
6464
6475
  let t = [];
6465
6476
  for (let n = e.changes.length - 1; n >= 0; --n) {
6466
- let r = rd(e.changes[n]);
6477
+ let r = od(e.changes[n]);
6467
6478
  r !== null && t.push(r);
6468
6479
  }
6469
6480
  return t;
6470
- }, ad = class extends Error {
6481
+ }, cd = class extends Error {
6471
6482
  invocationId;
6472
6483
  boundary;
6473
6484
  _tag = "UndoBoundaryError";
6474
6485
  constructor(e, t) {
6475
6486
  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
6487
  }
6477
- }, od = (e, t, n = ["updatedAt", "updatedBy"]) => {
6488
+ }, ld = (e, t, n = ["updatedAt", "updatedBy"]) => {
6478
6489
  if (t == null) return e == null;
6479
6490
  if (e == null) return !1;
6480
6491
  let r = new Set(n);
6481
6492
  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
6493
  return !0;
6483
- }, sd = class {
6494
+ }, ud = class {
6484
6495
  capacity;
6485
6496
  done = [];
6486
6497
  undone = [];
@@ -6516,7 +6527,7 @@ behind quietly.`;
6516
6527
  redo: [...this.undone]
6517
6528
  };
6518
6529
  }
6519
- }, cd = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
6530
+ }, dd = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
6520
6531
  table: e.table,
6521
6532
  op: "insert",
6522
6533
  next: e.new ?? null
@@ -6533,7 +6544,7 @@ behind quietly.`;
6533
6544
  table: e.table,
6534
6545
  op: "delete",
6535
6546
  prev: e.old ?? null
6536
- }, ld = async (e, t) => {
6547
+ }, fd = async (e, t) => {
6537
6548
  switch (t.op) {
6538
6549
  case "delete":
6539
6550
  await e.delete(t.table, t.id);
@@ -6551,21 +6562,21 @@ behind quietly.`;
6551
6562
  await e.insert(t.table, t.row);
6552
6563
  return;
6553
6564
  }
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({
6565
+ }, pd = async (e, t) => {
6566
+ for (let n of t) await fd(e, n);
6567
+ }, md = (e) => e.request?.subject?.id ?? null, hd = (e) => e === !0 || e === 1, gd = async (e, t, n) => (await e.query({
6557
6568
  table: t,
6558
6569
  predicate: O("id", n),
6559
6570
  order: []
6560
- }))[0] ?? null, md = (e) => {
6571
+ }))[0] ?? null, _d = (e) => {
6561
6572
  try {
6562
6573
  let t = JSON.parse(String(e ?? "[]"));
6563
6574
  return Array.isArray(t) ? t : [];
6564
6575
  } catch {
6565
6576
  return [];
6566
6577
  }
6567
- }, hd = (e) => e.id ?? e.next?.id ?? e.prev?.id, gd = async (e, t) => {
6568
- let n = dd(t);
6578
+ }, vd = (e) => e.id ?? e.next?.id ?? e.prev?.id, yd = async (e, t) => {
6579
+ let n = md(t);
6569
6580
  return [...await t.store.query({
6570
6581
  table: "_voltro_undo_log",
6571
6582
  predicate: O("subjectId", n),
@@ -6574,68 +6585,68 @@ behind quietly.`;
6574
6585
  id: String(e.id),
6575
6586
  tag: String(e.tag ?? ""),
6576
6587
  label: e.label ?? null,
6577
- undone: fd(e.undone),
6578
- crossesAction: fd(e.crossesAction),
6588
+ undone: hd(e.undone),
6589
+ crossesAction: hd(e.crossesAction),
6579
6590
  createdAt: String(e.createdAt ?? "")
6580
6591
  }));
6581
- }, _d = async (e, t) => {
6582
- let n = await pd(t.store, "_voltro_undo_log", e.invocationId);
6592
+ }, bd = async (e, t) => {
6593
+ let n = await gd(t.store, "_voltro_undo_log", e.invocationId);
6583
6594
  if (!n) throw new rt({ invocationId: e.invocationId });
6584
- if ((n.subjectId ?? null) !== dd(t)) throw new nt({ invocationId: e.invocationId });
6595
+ if ((n.subjectId ?? null) !== md(t)) throw new nt({ invocationId: e.invocationId });
6585
6596
  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({
6597
+ }, xd = async (e, t) => {
6598
+ let n = await bd(e, t);
6599
+ if (hd(n.undone)) return { ok: !0 };
6600
+ if (hd(n.crossesAction)) throw new tt({
6590
6601
  invocationId: e.invocationId,
6591
6602
  reason: "action"
6592
6603
  });
6593
- let r = md(n.changes);
6604
+ let r = _d(n.changes);
6594
6605
  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({
6606
+ let r = vd(n);
6607
+ if (r !== void 0 && !ld(await gd(t.store, n.table, r), n.next ?? null)) throw new tt({
6597
6608
  invocationId: e.invocationId,
6598
6609
  reason: "conflict"
6599
6610
  });
6600
6611
  }
6601
6612
  let i = {
6602
6613
  invocationId: e.invocationId,
6603
- subject: dd(t),
6614
+ subject: md(t),
6604
6615
  changes: r,
6605
6616
  crossesAction: !1
6606
6617
  };
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);
6618
+ return await pd(t.store, sd(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
6619
+ }, Sd = async (e, t) => {
6620
+ let n = await bd(e, t);
6621
+ if (!hd(n.undone)) return { ok: !0 };
6622
+ for (let e of _d(n.changes)) {
6623
+ let n = vd(e);
6613
6624
  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
6625
  }
6615
6626
  return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
6616
- }, bd = (e = process.env) => {
6627
+ }, Cd = (e = process.env) => {
6617
6628
  let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
6618
6629
  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) => {
6630
+ }, wd = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, Td = "«redacted»", Ed = (e) => {
6620
6631
  if (e == null) return null;
6621
6632
  let t = {};
6622
- for (let [n, r] of Object.entries(e)) t[n] = xd.test(n) ? Sd : r;
6633
+ for (let [n, r] of Object.entries(e)) t[n] = wd.test(n) ? Td : r;
6623
6634
  return t;
6624
- }, wd = (e) => {
6635
+ }, Dd = (e) => {
6625
6636
  let t = e?.id;
6626
6637
  return typeof t == "string" ? t : void 0;
6627
- }, Td = (e, t) => {
6638
+ }, Od = (e, t) => {
6628
6639
  if (t.op === "insert") {
6629
- let n = wd(t.new);
6640
+ let n = Dd(t.new);
6630
6641
  return n === void 0 ? e : e.filter((e) => e.id !== n);
6631
6642
  }
6632
6643
  if (t.op === "update") {
6633
6644
  if (t.old == null) return e;
6634
- let n = wd(t.new) ?? wd(t.old);
6645
+ let n = Dd(t.new) ?? Dd(t.old);
6635
6646
  return e.map((e) => e.id === n ? t.old : e);
6636
6647
  }
6637
6648
  return t.old == null ? e : [...e, t.old];
6638
- }, Ed = class {
6649
+ }, kd = class {
6639
6650
  mode;
6640
6651
  capacity;
6641
6652
  now;
@@ -6655,8 +6666,8 @@ behind quietly.`;
6655
6666
  ts: this.now(),
6656
6667
  table: e.table,
6657
6668
  op: e.op,
6658
- old: Cd(e.old),
6659
- new: Cd(e.new),
6669
+ old: Ed(e.old),
6670
+ new: Ed(e.new),
6660
6671
  tenantId: n
6661
6672
  }), this.ring.length > this.capacity && this.ring.shift(), t;
6662
6673
  }
@@ -6669,23 +6680,23 @@ behind quietly.`;
6669
6680
  }
6670
6681
  replay(e, t, n) {
6671
6682
  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);
6683
+ for (let e of r) i = Od(i, e);
6673
6684
  return i;
6674
6685
  }
6675
- }, Dd, Od = () => (Dd === void 0 && (Dd = new Ed(bd())), Dd), kd = (e) => {
6676
- Dd = e;
6677
- }, Ad = (e) => {
6678
- let t = Od();
6686
+ }, Ad, jd = () => (Ad === void 0 && (Ad = new kd(Cd())), Ad), Md = (e) => {
6687
+ Ad = e;
6688
+ }, Nd = (e) => {
6689
+ let t = jd();
6679
6690
  if (t.enabled) try {
6680
6691
  t.record(e);
6681
6692
  } catch {}
6682
- }, jd = /* @__PURE__ */ new Set([
6693
+ }, Pd = /* @__PURE__ */ new Set([
6683
6694
  "count",
6684
6695
  "sum",
6685
6696
  "avg",
6686
6697
  "min",
6687
6698
  "max"
6688
- ]), Md = (e) => {
6699
+ ]), Fd = (e) => {
6689
6700
  if (e.joins !== void 0 && e.joins.length > 0) return {
6690
6701
  maintainable: !1,
6691
6702
  reason: "joins are not maintainable in v1"
@@ -6707,7 +6718,7 @@ behind quietly.`;
6707
6718
  reason: "v1 maintains exactly one aggregation"
6708
6719
  };
6709
6720
  let t = e.aggregations[0];
6710
- return jd.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
6721
+ return Pd.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
6711
6722
  maintainable: !1,
6712
6723
  reason: `op '${t.op}' requires a column`
6713
6724
  } : {
@@ -6721,7 +6732,7 @@ behind quietly.`;
6721
6732
  maintainable: !1,
6722
6733
  reason: `op '${t.op}' is not maintainable`
6723
6734
  };
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) => {
6735
+ }, Id = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(Id), Ld = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Rd = (e, t) => {
6725
6736
  switch (e.op) {
6726
6737
  case "count": return t.count;
6727
6738
  case "sum": return t.sum ?? 0;
@@ -6729,10 +6740,10 @@ behind quietly.`;
6729
6740
  case "min":
6730
6741
  case "max": return t.count > 0 ? t.extreme ?? null : null;
6731
6742
  }
6732
- }, Id = (e, t) => {
6743
+ }, zd = (e, t) => {
6733
6744
  let n = /* @__PURE__ */ new Map();
6734
6745
  for (let r of t) {
6735
- let t = $(r, e.groupBy), i = n.get(t), a = Pd(r, e.column);
6746
+ let t = $(r, e.groupBy), i = n.get(t), a = Ld(r, e.column);
6736
6747
  if (i === void 0) n.set(t, {
6737
6748
  count: 1,
6738
6749
  ...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
@@ -6748,10 +6759,10 @@ behind quietly.`;
6748
6759
  }
6749
6760
  }
6750
6761
  return n;
6751
- }, Ld = (e, t) => [...t.entries()].map(([t, n]) => ({
6762
+ }, Bd = (e, t) => [...t.entries()].map(([t, n]) => ({
6752
6763
  groupKey: t,
6753
- value: Fd(e, n)
6754
- })), Rd = (e, t, n) => {
6764
+ value: Rd(e, n)
6765
+ })), Vd = (e, t, n) => {
6755
6766
  let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
6756
6767
  let n = $(t, e.groupBy), a = r.get(n);
6757
6768
  if (a === void 0) return;
@@ -6760,7 +6771,7 @@ behind quietly.`;
6760
6771
  r.delete(n);
6761
6772
  return;
6762
6773
  }
6763
- let s = Pd(t, e.column);
6774
+ let s = Ld(t, e.column);
6764
6775
  e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
6765
6776
  count: o,
6766
6777
  ...a.extreme === void 0 ? {} : { extreme: a.extreme }
@@ -6769,7 +6780,7 @@ behind quietly.`;
6769
6780
  ...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
6770
6781
  });
6771
6782
  }, o = (t) => {
6772
- let n = $(t, e.groupBy), i = r.get(n), a = Pd(t, e.column);
6783
+ let n = $(t, e.groupBy), i = r.get(n), a = Ld(t, e.column);
6773
6784
  if (i === void 0) {
6774
6785
  r.set(n, {
6775
6786
  count: 1,
@@ -6789,15 +6800,15 @@ behind quietly.`;
6789
6800
  state: r,
6790
6801
  rescanGroups: [...i]
6791
6802
  };
6792
- }, zd = (e, t, n, r) => {
6803
+ }, Hd = (e, t, n, r) => {
6793
6804
  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);
6805
+ let i = new Set(n), a = zd(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
6795
6806
  for (let e of i) {
6796
6807
  let t = a.get(e);
6797
6808
  t === void 0 ? o.delete(e) : o.set(e, t);
6798
6809
  }
6799
6810
  return o;
6800
- }, Bd = class {
6811
+ }, Ud = class {
6801
6812
  shape;
6802
6813
  state = /* @__PURE__ */ new Map();
6803
6814
  groups = /* @__PURE__ */ new Map();
@@ -6805,7 +6816,7 @@ behind quietly.`;
6805
6816
  this.shape = e;
6806
6817
  }
6807
6818
  seed(e) {
6808
- this.state = Id(this.shape, e), this.groups.clear();
6819
+ this.state = zd(this.shape, e), this.groups.clear();
6809
6820
  for (let t of e) {
6810
6821
  let e = $(t, this.shape.groupBy);
6811
6822
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
@@ -6817,14 +6828,14 @@ behind quietly.`;
6817
6828
  let e = $(t, this.shape.groupBy);
6818
6829
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
6819
6830
  }
6820
- let n = Rd(this.shape, this.state, e);
6831
+ let n = Vd(this.shape, this.state, e);
6821
6832
  this.state = n.state;
6822
6833
  for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
6823
6834
  return n.rescanGroups;
6824
6835
  }
6825
6836
  resolveRescan(e, t) {
6826
6837
  if (e.length === 0) return;
6827
- this.state = zd(this.shape, this.state, e, t);
6838
+ this.state = Hd(this.shape, this.state, e, t);
6828
6839
  let n = new Set(e);
6829
6840
  for (let e of t) {
6830
6841
  let t = $(e, this.shape.groupBy);
@@ -6833,7 +6844,7 @@ behind quietly.`;
6833
6844
  for (let e of n) this.state.has(e) || this.groups.delete(e);
6834
6845
  }
6835
6846
  materialize() {
6836
- return Ld(this.shape, this.state).map((e) => ({
6847
+ return Bd(this.shape, this.state).map((e) => ({
6837
6848
  groupKey: e.groupKey,
6838
6849
  group: this.groups.get(e.groupKey) ?? {},
6839
6850
  value: e.value
@@ -6846,7 +6857,7 @@ behind quietly.`;
6846
6857
  for (let r of t) n[r] = e[r];
6847
6858
  return n;
6848
6859
  }
6849
- }, Vd = F("_voltro_rebac_tuples", {
6860
+ }, Wd = F("_voltro_rebac_tuples", {
6850
6861
  id: M({ prefix: "rbct" }),
6851
6862
  subjectId: I(),
6852
6863
  relation: I(),
@@ -6858,7 +6869,7 @@ behind quietly.`;
6858
6869
  "subjectId",
6859
6870
  "resourceType",
6860
6871
  "resourceId"
6861
- ]), Hd = async (e, t, n, r) => t === null ? [] : (await e.query({
6872
+ ]), Gd = async (e, t, n, r) => t === null ? [] : (await e.query({
6862
6873
  table: "_voltro_rebac_tuples",
6863
6874
  predicate: C(O("subjectId", t), O("resourceType", n), O("resourceId", r)),
6864
6875
  order: [],
@@ -6870,16 +6881,16 @@ behind quietly.`;
6870
6881
  relation: e.relation,
6871
6882
  resourceType: e.resourceType,
6872
6883
  resourceId: e.resourceId
6873
- })), Ud = (e) => ({
6884
+ })), Kd = (e) => ({
6874
6885
  id: e.id,
6875
6886
  tenantId: e.tenantId,
6876
6887
  ...e.scopes === void 0 ? {} : { scopes: e.scopes }
6877
- }), Wd = (e, t) => {
6878
- let n = t.getPolicy ?? $c;
6888
+ }), qd = (e, t) => {
6889
+ let n = t.getPolicy ?? nl;
6879
6890
  return (r, i) => {
6880
6891
  let a = e[i.tag];
6881
6892
  if (a === void 0) return r;
6882
- let s = n(a.resourceType), c = (e) => o.fail(new Xc({
6893
+ let s = n(a.resourceType), c = (e) => o.fail(new $c({
6883
6894
  action: a.action,
6884
6895
  resourceType: a.resourceType,
6885
6896
  resourceId: e
@@ -6887,17 +6898,17 @@ behind quietly.`;
6887
6898
  if (s === void 0) return c("");
6888
6899
  let l = a.resourceId(i.input);
6889
6900
  if (l === null || l === "") return c("");
6890
- let u = Ud(i.subject), d = {
6901
+ let u = Kd(i.subject), d = {
6891
6902
  type: a.resourceType,
6892
6903
  id: l,
6893
6904
  tenantId: i.subject.tenantId
6894
6905
  };
6895
- return o.flatMap(o.promise(async () => t.loadTuples(u.id, a.resourceType, l)), (e) => al(u, a.action, d, {
6906
+ return o.flatMap(o.promise(async () => t.loadTuples(u.id, a.resourceType, l)), (e) => cl(u, a.action, d, {
6896
6907
  policy: s,
6897
6908
  tuples: e
6898
6909
  }) ? r : c(l));
6899
6910
  };
6900
- }, Gd = async (e, t, n) => t === null ? [] : (await e.query({
6911
+ }, Jd = async (e, t, n) => t === null ? [] : (await e.query({
6901
6912
  table: "_voltro_rebac_tuples",
6902
6913
  predicate: C(O("subjectId", t), O("resourceType", n)),
6903
6914
  order: [],
@@ -6909,18 +6920,18 @@ behind quietly.`;
6909
6920
  relation: e.relation,
6910
6921
  resourceType: e.resourceType,
6911
6922
  resourceId: e.resourceId
6912
- })), Kd = (e) => {
6913
- let t = e.getPolicy ?? $c;
6923
+ })), Yd = (e) => {
6924
+ let t = e.getPolicy ?? nl;
6914
6925
  return async (n, r, i, a) => {
6915
6926
  let o = t(r);
6916
6927
  if (o === void 0) return [];
6917
- let s = Ud(n);
6918
- return sl(s, i, r, a, {
6928
+ let s = Kd(n);
6929
+ return ul(s, i, r, a, {
6919
6930
  policy: o,
6920
6931
  tuples: await e.loadSubjectTuples(s.id, r)
6921
6932
  });
6922
6933
  };
6923
- }, qd = (e) => {
6934
+ }, Xd = (e) => {
6924
6935
  if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
6925
6936
  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
6937
  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 +6939,14 @@ behind quietly.`;
6928
6939
  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
6940
  if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
6930
6941
  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 {
6942
+ }, Zd = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, Qd = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, $d = class {
6932
6943
  hits = /* @__PURE__ */ new Map();
6933
6944
  allow(e, t, n, r) {
6934
6945
  let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
6935
6946
  return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
6936
6947
  }
6937
- }, Zd = async (e, t, n) => {
6938
- if (t.table !== e.watch.table || !Jd(e.watch.on, t.op)) return "skipped-op";
6948
+ }, ef = async (e, t, n) => {
6949
+ if (t.table !== e.watch.table || !Zd(e.watch.on, t.op)) return "skipped-op";
6939
6950
  if (e.when !== void 0 && !e.when(t)) return "skipped-when";
6940
6951
  let r = `${e.name}:${e.guards.dedupeKey(t)}`;
6941
6952
  if (await n.dedupe.has(r)) return "skipped-dedupe";
@@ -6944,26 +6955,26 @@ behind quietly.`;
6944
6955
  let t = n.now?.() ?? Date.now();
6945
6956
  if (!n.rateLimiter.allow(e.name, i.limit, i.windowMs, t)) return "skipped-ratelimit";
6946
6957
  }
6947
- let a = Yd(t);
6958
+ let a = Qd(t);
6948
6959
  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
6960
  id: a,
6950
6961
  via: "agent"
6951
6962
  }), await n.dedupe.add(r), "acted");
6952
- }, Qd = F("_voltro_wakeups", {
6963
+ }, tf = F("_voltro_wakeups", {
6953
6964
  id: M({ prefix: "wakeup" }),
6954
6965
  tenantId: I(),
6955
6966
  kind: I(),
6956
6967
  refId: I(),
6957
6968
  wakeAt: L(),
6958
6969
  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);
6970
+ }).index(["status", "wakeAt"]).index(["tenantId"]), nf = async (e) => {
6971
+ let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Fu(e.store, t, e.batchLimit ?? 100);
6961
6972
  if (n.length === 0) return 0;
6962
6973
  let r = 0;
6963
- for (let t of n) if (await Ou(e.store, t)) try {
6974
+ for (let t of n) if (await ju(e.store, t)) try {
6964
6975
  await e.adapter.wake(t), r++;
6965
6976
  } catch (n) {
6966
- await ku(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
6977
+ await Mu(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
6967
6978
  tenantId: t.tenantId,
6968
6979
  kind: t.kind,
6969
6980
  refId: t.refId,
@@ -6971,11 +6982,11 @@ behind quietly.`;
6971
6982
  });
6972
6983
  }
6973
6984
  return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
6974
- }, ef = (e, t = 1e3) => {
6985
+ }, rf = (e, t = 1e3) => {
6975
6986
  let n = !1, r, i = async () => {
6976
6987
  if (!n) {
6977
6988
  try {
6978
- await $d(e);
6989
+ await nf(e);
6979
6990
  } catch (t) {
6980
6991
  e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
6981
6992
  }
@@ -6985,10 +6996,10 @@ behind quietly.`;
6985
6996
  return i(), { stop: () => {
6986
6997
  n = !0, r !== void 0 && clearTimeout(r);
6987
6998
  } };
6988
- }, tf = (e) => ({ wake: async () => {
6999
+ }, af = (e) => ({ wake: async () => {
6989
7000
  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 () => {
7001
+ } }), of = (e) => new Promise((t) => setTimeout(t, e)), sf = (e) => {
7002
+ let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? of, 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
7003
  try {
6993
7004
  let n = await t(e.healthUrl);
6994
7005
  return d(n);
@@ -7042,11 +7053,11 @@ behind quietly.`;
7042
7053
  },
7043
7054
  stop: m
7044
7055
  };
7045
- }, af = async (e) => {
7056
+ }, cf = async (e) => {
7046
7057
  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);
7058
+ let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Iu(e.store);
7048
7059
  return !(n !== null && n.wakeAt.getTime() <= t);
7049
- }, of = (e, t = Date.now) => {
7060
+ }, lf = (e, t = Date.now) => {
7050
7061
  let n;
7051
7062
  return {
7052
7063
  update: (r) => {
@@ -7058,7 +7069,7 @@ behind quietly.`;
7058
7069
  n = void 0;
7059
7070
  }
7060
7071
  };
7061
- }, sf = () => {
7072
+ }, uf = () => {
7062
7073
  let e = 0, t = 0;
7063
7074
  return {
7064
7075
  onRequestStart: () => {
@@ -7076,7 +7087,7 @@ behind quietly.`;
7076
7087
  inFlightRequests: () => e,
7077
7088
  openConnections: () => t
7078
7089
  };
7079
- }, cf = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), lf = (e, t, n, r) => new Promise((i, a) => {
7090
+ }, df = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), ff = (e, t, n, r) => new Promise((i, a) => {
7080
7091
  let o = xt.request({
7081
7092
  host: n,
7082
7093
  port: r,
@@ -7087,7 +7098,7 @@ behind quietly.`;
7087
7098
  t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
7088
7099
  });
7089
7100
  o.on("error", a), e.pipe(o);
7090
- }), uf = (e, t, n, r, i) => new Promise((a, o) => {
7101
+ }), pf = (e, t, n, r, i) => new Promise((a, o) => {
7091
7102
  let s = xt.request({
7092
7103
  host: r,
7093
7104
  port: i,
@@ -7102,21 +7113,21 @@ behind quietly.`;
7102
7113
  };
7103
7114
  t.on("close", s), r.on("close", s), r.on("error", o);
7104
7115
  }), s.on("error", o), s.end();
7105
- }), df = (e) => {
7106
- let t = cf({
7116
+ }), mf = (e) => {
7117
+ let t = df({
7107
7118
  ensureAwake: () => e.supervisor.start(),
7108
7119
  ...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
7109
7120
  }), 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) => {
7121
+ n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => ff(r, i, e.targetHost, e.targetPort)).catch((t) => {
7111
7122
  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
7123
  });
7113
7124
  });
7114
7125
  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) => {
7126
+ n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => pf(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
7116
7127
  e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
7117
7128
  });
7118
7129
  }), r;
7119
- }, ff = async (e) => {
7130
+ }, hf = async (e) => {
7120
7131
  try {
7121
7132
  return (await e.query({
7122
7133
  table: "_voltro_workflow_runs",
@@ -7133,15 +7144,15 @@ behind quietly.`;
7133
7144
  } catch {
7134
7145
  return 0;
7135
7146
  }
7136
- }, pf = async (e) => {
7137
- let t = tf(e.supervisor), n = await $d({
7147
+ }, gf = async (e) => {
7148
+ let t = af(e.supervisor), n = await nf({
7138
7149
  store: e.store,
7139
7150
  adapter: t,
7140
7151
  ...e.now === void 0 ? {} : { now: e.now },
7141
7152
  ...e.log === void 0 ? {} : { log: e.log }
7142
7153
  });
7143
7154
  n > 0 && e.idleGate.reset();
7144
- let r = await af({
7155
+ let r = await cf({
7145
7156
  store: e.store,
7146
7157
  signals: e.signals,
7147
7158
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
@@ -7151,12 +7162,12 @@ behind quietly.`;
7151
7162
  woke: n,
7152
7163
  stopped: i
7153
7164
  };
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 ?? {
7165
+ }, _f = async (e) => {
7166
+ let t = lf(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = uf(), i = 0, a = e.signals === void 0, o = e.signals ?? {
7156
7167
  connectedClients: () => r.openConnections(),
7157
7168
  inFlightRequests: () => r.inFlightRequests(),
7158
7169
  activeWorkflowExecutions: () => i
7159
- }, s = df({
7170
+ }, s = mf({
7160
7171
  supervisor: e.supervisor,
7161
7172
  targetHost: e.targetHost,
7162
7173
  targetPort: e.targetPort,
@@ -7175,7 +7186,7 @@ behind quietly.`;
7175
7186
  let l = !1, u, d = e.firedRetentionMs ?? 10 * 6e4, f = 0, p = async () => {
7176
7187
  if (!l) {
7177
7188
  try {
7178
- if (a && (i = await ff(e.store)), await pf({
7189
+ if (a && (i = await hf(e.store)), await gf({
7179
7190
  store: e.store,
7180
7191
  supervisor: e.supervisor,
7181
7192
  signals: o,
@@ -7183,7 +7194,7 @@ behind quietly.`;
7183
7194
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
7184
7195
  ...e.log === void 0 ? {} : { log: e.log }
7185
7196
  }), f++ % 60 == 0) {
7186
- let t = await Fu(e.store, { firedOlderThan: new Date(Date.now() - d) });
7197
+ let t = await Ru(e.store, { firedOlderThan: new Date(Date.now() - d) });
7187
7198
  t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
7188
7199
  }
7189
7200
  } catch (t) {
@@ -7198,14 +7209,14 @@ behind quietly.`;
7198
7209
  l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
7199
7210
  }
7200
7211
  };
7201
- }, hf = (e) => e, gf = class extends y.TaggedError()("AnalyticsError", {
7212
+ }, vf = (e) => e, yf = class extends y.TaggedError()("AnalyticsError", {
7202
7213
  provider: y.String,
7203
7214
  operation: y.String,
7204
7215
  cause: y.String
7205
- }) {}, _f = class extends y.TaggedError()("AnalyticsCapabilityNotSupported", {
7216
+ }) {}, bf = class extends y.TaggedError()("AnalyticsCapabilityNotSupported", {
7206
7217
  provider: y.String,
7207
7218
  capability: y.String
7208
- }) {}, vf = class extends n.Tag("@voltro/AnalyticsSink")() {}, yf = (e, t) => ({
7219
+ }) {}, xf = class extends n.Tag("@voltro/AnalyticsSink")() {}, Sf = (e, t) => ({
7209
7220
  info: e.info,
7210
7221
  track: (n) => e.track(n.tenantId === void 0 ? {
7211
7222
  ...n,
@@ -7224,20 +7235,20 @@ behind quietly.`;
7224
7235
  tenantId: t
7225
7236
  } : n),
7226
7237
  ...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, {
7238
+ }), Cf = () => o.gen(function* () {
7239
+ let e = yield* xf, t = yield* o.serviceOption(et), n = h.match(t, {
7229
7240
  onNone: () => null,
7230
7241
  onSome: (e) => e.tenantId ?? null
7231
7242
  });
7232
- return n === null ? e : yf(e, n);
7233
- }), xf = "noop", Sf = () => {
7234
- let e = (e) => o.fail(new _f({
7235
- provider: xf,
7243
+ return n === null ? e : Sf(e, n);
7244
+ }), wf = "noop", Tf = () => {
7245
+ let e = (e) => o.fail(new bf({
7246
+ provider: wf,
7236
7247
  capability: e
7237
7248
  }));
7238
7249
  return {
7239
7250
  info: {
7240
- provider: xf,
7251
+ provider: wf,
7241
7252
  capabilities: {
7242
7253
  track: !0,
7243
7254
  aggregate: !1,
@@ -7251,8 +7262,8 @@ behind quietly.`;
7251
7262
  timeseries: () => e("timeseries"),
7252
7263
  topN: () => e("topN")
7253
7264
  };
7254
- }, Cf = (e) => {
7255
- if (e.length === 0) return Sf();
7265
+ }, Ef = (e) => {
7266
+ if (e.length === 0) return Tf();
7256
7267
  if (e.length === 1) return e[0];
7257
7268
  let t = {
7258
7269
  provider: "compose",
@@ -7269,7 +7280,7 @@ behind quietly.`;
7269
7280
  discard: !0
7270
7281
  }), r = (t, n) => {
7271
7282
  let r = e.find((e) => e.info.capabilities[t]);
7272
- return r === void 0 ? o.fail(new _f({
7283
+ return r === void 0 ? o.fail(new bf({
7273
7284
  provider: "compose",
7274
7285
  capability: t
7275
7286
  })) : n(r);
@@ -7292,11 +7303,11 @@ behind quietly.`;
7292
7303
  topN: (e) => r("topN", (t) => t.topN(e)),
7293
7304
  ...a === void 0 ? {} : { mirror: a }
7294
7305
  };
7295
- }, wf = (e) => {
7306
+ }, Df = (e) => {
7296
7307
  let t = e.filter((e) => e.dispose !== void 0);
7297
7308
  return {
7298
7309
  kind: "compose",
7299
- build: (t) => Cf(e.map((e) => e.build(t))),
7310
+ build: (t) => Ef(e.map((e) => e.build(t))),
7300
7311
  tables: e.flatMap((e) => e.tables ?? []),
7301
7312
  initialize: (t) => o.forEach(e, (e) => e.initialize ? e.initialize(t) : o.void, {
7302
7313
  concurrency: 1,
@@ -7307,15 +7318,15 @@ behind quietly.`;
7307
7318
  discard: !0
7308
7319
  }) } : {}
7309
7320
  };
7310
- }, Tf = {
7321
+ }, Of = {
7311
7322
  kind: "noop",
7312
- build: () => Sf()
7313
- }, Ef = {
7323
+ build: () => Tf()
7324
+ }, kf = {
7314
7325
  tables: [],
7315
7326
  detach: () => {}
7316
- }, Df = (e) => {
7327
+ }, Af = (e) => {
7317
7328
  let { store: t, sink: n, log: r } = e, i = n.mirror;
7318
- if (i === void 0 || i.tables.length === 0) return Ef;
7329
+ if (i === void 0 || i.tables.length === 0) return kf;
7319
7330
  let a = e.run ?? ((e) => o.runPromise(e)), s = i.primaryKey ?? "id", c = new Set(i.tables), l = (e) => {
7320
7331
  if (e.op === "delete") {
7321
7332
  let t = e.old;
@@ -7339,11 +7350,11 @@ behind quietly.`;
7339
7350
  tables: i.tables,
7340
7351
  detach: u
7341
7352
  };
7342
- }, Of = (e) => {
7353
+ }, jf = (e) => {
7343
7354
  let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
7344
7355
  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
7356
  if (e.incremental !== void 0) {
7346
- let t = Md({
7357
+ let t = Fd({
7347
7358
  aggregations: [{
7348
7359
  op: e.incremental.op,
7349
7360
  ...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
@@ -7365,47 +7376,47 @@ behind quietly.`;
7365
7376
  build: e.build,
7366
7377
  ...e.incremental === void 0 ? {} : { incremental: e.incremental }
7367
7378
  };
7368
- }, kf = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Af = class extends y.TaggedError()("AggregateStale", {
7379
+ }, Mf = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Nf = class extends y.TaggedError()("AggregateStale", {
7369
7380
  name: y.String,
7370
7381
  ageMs: y.Number,
7371
7382
  maxAgeMs: y.Number
7372
- }) {}, jf = class extends y.TaggedError()("AggregateNotFound", { name: y.String }) {}, Mf = class extends y.TaggedError()("AggregateError", {
7383
+ }) {}, Pf = class extends y.TaggedError()("AggregateNotFound", { name: y.String }) {}, Ff = class extends y.TaggedError()("AggregateError", {
7373
7384
  name: y.String,
7374
7385
  operation: y.String,
7375
7386
  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) => {
7387
+ }) {}, If = class extends n.Tag("@voltro/AggregateRegistry")() {}, Lf = (e) => o.gen(function* () {
7388
+ return (yield* If).getHandle(e);
7389
+ }), Rf = (e, t, n) => {
7379
7390
  if (e.crossTenant || !t.has(e.table) || n == null) return e;
7380
7391
  let r = O("tenantId", n);
7381
7392
  return {
7382
7393
  ...e,
7383
7394
  predicate: e.predicate ? C(e.predicate, r) : r
7384
7395
  };
7385
- }, If = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Lf = (e) => e?.type === "user" && e.tenantId === "", Rf = (e, t) => {
7396
+ }, zf = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Bf = (e) => e?.type === "user" && e.tenantId === "", Vf = (e, t) => {
7386
7397
  if (e.includeDeleted || !t.has(e.table)) return e;
7387
7398
  let n = de("deletedAt");
7388
7399
  return {
7389
7400
  ...e,
7390
7401
  predicate: e.predicate ? C(e.predicate, n) : n
7391
7402
  };
7392
- }, zf = (e, t) => t, Bf = (t) => o.runPromiseExit(t).then((t) => {
7403
+ }, Hf = (e, t) => t, Uf = (t) => o.runPromiseExit(t).then((t) => {
7393
7404
  if (c.isSuccess(t)) return t.value;
7394
7405
  let n = e.failureOption(t.cause);
7395
7406
  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) => {
7407
+ }), Wf = (e, t) => e.pipe(o.provideService(et, t)), Gf = async (e, t, n) => {
7397
7408
  let r = await o.runPromise(ot(t, e.guards, n));
7398
7409
  if (r) throw r;
7399
- }, Uf = async (e) => {
7410
+ }, Kf = async (e) => {
7400
7411
  if (Dr() === void 0) return e;
7401
- let t = await Bf(kr(e.subject, (e) => {
7412
+ let t = await Uf(kr(e.subject, (e) => {
7402
7413
  console.error("[voltro] row filter failed to load", e);
7403
7414
  }));
7404
7415
  return {
7405
7416
  ...e,
7406
7417
  rowFilter: t
7407
7418
  };
7408
- }, Wf = async (t) => {
7419
+ }, qf = async (t) => {
7409
7420
  let n = `${t.kind}.${t.name}`, r = Date.now(), i = "ok";
7410
7421
  try {
7411
7422
  if (t.interceptor) {
@@ -7434,28 +7445,28 @@ behind quietly.`;
7434
7445
  status: i
7435
7446
  });
7436
7447
  }
7437
- }, Gf = /* @__PURE__ */ new Set([1213, 1205]), Kf = /* @__PURE__ */ new Set([
7448
+ }, Jf = /* @__PURE__ */ new Set([1213, 1205]), Yf = /* @__PURE__ */ new Set([
7438
7449
  "ER_LOCK_DEADLOCK",
7439
7450
  "ER_LOCK_WAIT_TIMEOUT",
7440
7451
  "40001",
7441
7452
  "40P01"
7442
- ]), qf = (e) => {
7453
+ ]), Xf = (e) => {
7443
7454
  let t = e;
7444
7455
  for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
7445
7456
  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;
7457
+ if (typeof e.errno == "number" && Jf.has(e.errno) || typeof e.code == "string" && Yf.has(e.code) || typeof e.sqlState == "string" && Yf.has(e.sqlState)) return !0;
7447
7458
  t = e.cause;
7448
7459
  }
7449
7460
  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)));
7461
+ }, Zf = 3, Qf = (e) => new Promise((t) => setTimeout(t, e)), $f = async (e, t) => {
7462
+ let n = t?.delay ?? ((e) => Qf(e * 20 + Math.floor(Math.random() * 30)));
7452
7463
  for (let t = 1;; t++) try {
7453
7464
  return await e();
7454
7465
  } catch (e) {
7455
- if (t >= Jf || !qf(e)) throw e;
7466
+ if (t >= Zf || !Xf(e)) throw e;
7456
7467
  await n(t);
7457
7468
  }
7458
- }, Zf = (e) => (t, n, r) => Wf({
7469
+ }, ep = (e) => (t, n, r) => qf({
7459
7470
  name: t.descriptor.name,
7460
7471
  kind: "mutation",
7461
7472
  input: n,
@@ -7463,11 +7474,11 @@ behind quietly.`;
7463
7474
  ...e.interceptor ? { interceptor: e.interceptor } : {},
7464
7475
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
7465
7476
  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) => {
7477
+ await Gf(t.descriptor, r.subject, n);
7478
+ let i = await Kf(r), a = [], s = await $f(async () => (a.length = 0, e.store.transactional(async (s) => {
7468
7479
  let c = e.undoCapture?.(s), l = c ? c.tx : s, u = e.buildContext(i, l, { afterCommit: (e) => {
7469
7480
  a.push(e);
7470
- } }), d = t.executor(n, u), f = o.isEffect(d) ? await e.runEffect(Vf(d, r.subject), u.store) : await d;
7481
+ } }), d = t.executor(n, u), f = o.isEffect(d) ? await e.runEffect(Wf(d, r.subject), u.store) : await d;
7471
7482
  return c && await c.persist(u.store, {
7472
7483
  tag: t.descriptor.name,
7473
7484
  subject: r.subject,
@@ -7477,30 +7488,30 @@ behind quietly.`;
7477
7488
  for (let e of a) await e();
7478
7489
  return s;
7479
7490
  }
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) => {
7491
+ }), tp = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, np = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, rp = (e) => {
7481
7492
  let t = e.descriptor.source;
7482
7493
  return t == null ? [] : typeof t == "string" ? [t] : [...t];
7483
- }, tp = (e, t) => (n) => () => {
7494
+ }, ip = (e, t) => (n) => () => {
7484
7495
  let r = e.descriptor.guards;
7485
7496
  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 () => {
7497
+ }, ap = (e) => (t, n) => (r) => {
7498
+ let i = e.buildContext(r), a = ip(t, n)(r.subject), s = async () => {
7488
7499
  let i = await a();
7489
7500
  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));
7501
+ let s = e.buildContext(await Kf(r)), c = t.executor(n, s);
7502
+ return o.isEffect(c) ? o.runPromise(e.provideEffect(Wf(c, r.subject), s.store)) : tp(await Promise.resolve(c));
7492
7503
  }, c = (n) => {
7493
- let i = Qf(n);
7494
- return $f(i) ? e.finalize(i, r) : {
7504
+ let i = tp(n);
7505
+ return np(i) ? e.finalize(i, r) : {
7495
7506
  __voltroComputed: !0,
7496
7507
  value: i,
7497
- dependentTables: ep(t),
7508
+ dependentTables: rp(t),
7498
7509
  tenantId: r.subject?.tenantId ?? null,
7499
7510
  recompute: s
7500
7511
  };
7501
7512
  }, l = () => {
7502
7513
  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);
7514
+ return o.isEffect(a) ? e.provideEffect(Wf(a, r.subject), i.store).pipe(o.map(c)) : a instanceof Promise ? o.promise(() => a).pipe(o.map(c)) : c(a);
7504
7515
  }, u = () => {
7505
7516
  let e = t.descriptor.guards;
7506
7517
  return !e || e.length === 0 ? l() : ot(r.subject, e, n).pipe(o.flatMap((e) => {
@@ -7522,14 +7533,14 @@ behind quietly.`;
7522
7533
  traceId: r.traceId,
7523
7534
  ...r.spanId === void 0 ? {} : { spanId: r.spanId }
7524
7535
  });
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;
7536
+ }, op = (e) => async (t, n, r) => {
7537
+ let i = await Kf(r), a = ap(e)(t, n)(i), s = o.isEffect(a) ? await Uf(a) : a;
7527
7538
  return zr(s) ? s.value : e.queryRows(s);
7528
- }, ip = (e) => (t, n, r, i) => {
7539
+ }, sp = (e) => (t, n, r, i) => {
7529
7540
  let a = !1, s;
7530
7541
  return (async () => {
7531
7542
  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);
7543
+ let c = await Kf(r), l = ap(e)(t, n)(c), u = o.isEffect(l) ? await Uf(l) : l, d = (e) => i(e), f = zr(u) ? await e.subscribeComputed(u, d, c) : await e.subscribeDescriptor(u, d, c);
7533
7544
  a ? f() : s = f;
7534
7545
  } catch (e) {
7535
7546
  i({
@@ -7540,7 +7551,7 @@ behind quietly.`;
7540
7551
  })(), () => {
7541
7552
  a = !0, s?.();
7542
7553
  };
7543
- }, ap = (e) => (t, n, r) => Wf({
7554
+ }, cp = (e) => (t, n, r) => qf({
7544
7555
  name: t.descriptor.name,
7545
7556
  kind: "action",
7546
7557
  input: n,
@@ -7548,16 +7559,16 @@ behind quietly.`;
7548
7559
  ...e.interceptor ? { interceptor: e.interceptor } : {},
7549
7560
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
7550
7561
  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;
7562
+ await Gf(t.descriptor, r.subject, n);
7563
+ let i = e.buildContext(await Kf(r)), a = t.executor(n, i);
7564
+ return o.isEffect(a) ? e.runEffect(Wf(a, r.subject), i.store) : a;
7554
7565
  }
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 = [
7566
+ }), lp = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, up = (e) => typeof e == "string" && e.length > 0 ? e : null, dp = [
7556
7567
  "updatedAt",
7557
7568
  "createdAt",
7558
7569
  "updatedBy",
7559
7570
  "createdBy"
7560
- ], lp = (e) => cp.some((t) => t in e), up = (e, t, n) => {
7571
+ ], fp = (e) => dp.some((t) => t in e), pp = (e, t, n) => {
7561
7572
  let r = {
7562
7573
  table: t.table,
7563
7574
  id: t.id,
@@ -7572,14 +7583,14 @@ behind quietly.`;
7572
7583
  found: !1
7573
7584
  };
7574
7585
  let i = t.column === void 0 ? void 0 : e[t.column];
7575
- if (!lp(e)) return {
7586
+ if (!fp(e)) return {
7576
7587
  ...r,
7577
7588
  value: i,
7578
7589
  lastWrite: null,
7579
7590
  attribution: "none",
7580
7591
  found: !0
7581
7592
  };
7582
- let a = sp(e.updatedBy) ?? sp(e.createdBy), o = op(e.updatedAt) ?? op(e.createdAt);
7593
+ let a = up(e.updatedBy) ?? up(e.createdBy), o = lp(e.updatedAt) ?? lp(e.createdAt);
7583
7594
  return {
7584
7595
  ...r,
7585
7596
  value: i,
@@ -7591,12 +7602,12 @@ behind quietly.`;
7591
7602
  attribution: "audit",
7592
7603
  found: !0
7593
7604
  };
7594
- }, dp = (e, t) => {
7605
+ }, mp = (e, t) => {
7595
7606
  let n = e.map((e) => {
7596
7607
  let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
7597
7608
  return {
7598
- actor: { id: sp(e.actor) ?? sp(e.changedBy) },
7599
- at: op(e.at) ?? op(e.changedAt),
7609
+ actor: { id: up(e.actor) ?? up(e.changedBy) },
7610
+ at: lp(e.at) ?? lp(e.changedAt),
7600
7611
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
7601
7612
  value: r
7602
7613
  };
@@ -7611,12 +7622,12 @@ behind quietly.`;
7611
7622
  history: n,
7612
7623
  found: n.length > 0
7613
7624
  };
7614
- }, fp = (e) => {
7625
+ }, hp = (e) => {
7615
7626
  let t = e.new?.id;
7616
7627
  if (typeof t == "string") return t;
7617
7628
  let n = e.old?.id;
7618
7629
  return typeof n == "string" ? n : void 0;
7619
- }, pp = (e) => {
7630
+ }, gp = (e) => {
7620
7631
  let t = {};
7621
7632
  if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
7622
7633
  from: void 0,
@@ -7636,11 +7647,11 @@ behind quietly.`;
7636
7647
  return {
7637
7648
  table: e.table,
7638
7649
  op: e.op,
7639
- id: fp(e),
7650
+ id: hp(e),
7640
7651
  fields: t
7641
7652
  };
7642
- }, mp = (e) => {
7643
- let t = e.map(pp);
7653
+ }, _p = (e) => {
7654
+ let t = e.map(gp);
7644
7655
  return {
7645
7656
  rows: t,
7646
7657
  summary: {
@@ -7649,21 +7660,21 @@ behind quietly.`;
7649
7660
  deletes: t.filter((e) => e.op === "delete").length
7650
7661
  }
7651
7662
  };
7652
- }, hp = class extends Error {
7663
+ }, vp = class extends Error {
7653
7664
  constructor() {
7654
7665
  super("voltro:preview-rollback"), this.name = "PreviewRollback";
7655
7666
  }
7656
- }, gp = async (e, t) => {
7667
+ }, yp = async (e, t) => {
7657
7668
  let n, r = !1;
7658
7669
  try {
7659
7670
  await e.transactional(async (e) => {
7660
- throw n = await t(e), r = !0, new hp();
7671
+ throw n = await t(e), r = !0, new vp();
7661
7672
  });
7662
7673
  } catch (e) {
7663
- if (!(e instanceof hp)) throw e;
7674
+ if (!(e instanceof vp)) throw e;
7664
7675
  }
7665
7676
  if (!r) throw Error("preview: handler did not complete");
7666
7677
  return n;
7667
- }, _p = "framework-runtime";
7678
+ }, bp = "framework-runtime";
7668
7679
  //#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 };
7680
+ export { Oo as API_KEYS_TABLE, $c as AccessDenied, Ff as AggregateError, Ud as AggregateMaintainer, Pf as AggregateNotFound, If as AggregateRegistry, Nf as AggregateStale, bf as AnalyticsCapabilityNotSupported, yf as AnalyticsError, xf as AnalyticsSink, X as CONNECTIONS_TABLE, Qs as CONNECTION_GRANTS_TABLE, uu as CircuitBreaker, cu as CircuitOpen, xc as ConnectionNotConnected, Pa as DEFAULT_MAX_RPC_BODY_BYTES, yc as DEFAULT_REFRESH_SKEW_MS, wr as DEFAULT_ROW_FILTER_RETRY, Bu 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, wf 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, bp as RUNTIME_NAME, $d as ReactionRateLimiter, ia as ReplicatedDataStore, Cr as RowFilterUnavailable, zu 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, kd as TimelineRecorder, cd as UndoBoundaryError, ud 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, Wd as _voltroRebacTuplesTable, Zu as _voltroScheduleClaimsTable, Xu as _voltroScheduleRunsTable, Qu as _voltroTracesTable, $u as _voltroUndoLogTable, tf as _voltroWakeupsTable, hs as _voltroWorkflowEventDeliveriesTable, ms as _voltroWorkflowEventsTable, qi as actingUserId, Vo as apiKeyManagementRoutes, Wi as applyDefined, Vd as applyDelta, fd as applyInverse, pd as applyInverses, ou as applyPluginRefRules, Mr as applyRowFilter, Nr as applyRowFilterToDescriptor, Vf as applySoftDeleteScope, Rf as applyTenantScope, xd as applyUndoInvocation, ll as assertCan, ic as assertConnectionCipherConfigured, Af 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, zd as buildIvmState, _p as buildPreview, qd as buildRebacInterceptor, Yd as buildRebacReadFilter, Qi as buildSubjectKey, Za as buildTracingLayer, $l as cacheScopeLeaks, po as cachedBackend, cl as can, Ou as cancelWakeup, cn as canonicalize, Fd as classifyShape, Tc as clearConnectionRefreshFlights, il as clearResourcePolicies, ee as clearRetentions, pu as clearSystemStoreHandle, su as collectPluginRefRules, Cu as compileCron, Rc as completeOAuthConnect, Df as composeAnalytics, Ef as composeAnalyticsSinks, Pc as connectionCallbackPath, rc as connectionLabel, ni as connectionSubjectsSnapshot, hf 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, jf as defineAggregate, nc as defineConnection, ls as defineEventTrigger, Hf as defineExecutor, Bs as defineOutboxHandler, Xd as defineReaction, tl as defineResourcePolicy, Su as defineSchedule, vf as defineSubscriber, Pr as deliveredRowCount, ui as deriveKey, gp as diffChange, Wa as drainForShutdown, Js as drainOutbox, Fu 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, dd 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, mu as getSystemStoreHandle, jd as getTimelineRecorder, yl as getTupleSource, $ as groupKeyOf, yr as histogramMetric, mp as historyProvenance, mo as httpSecretsBackend, Xt as inspectWorkflow, bl as installPolicyGuardResolver, $r as interruptConnectionStreams, od as invertChange, Mf as isAggregateDefinition, zf as isEmptyTenantScopedRead, Sn as isForeignKeyViolation, cf as isIdleNow, Oa as isInfraError, wi as isObservingGraph, Bf as isOrglessUserSubject, Cn as isQueryTimeout, ld as isSafeToApply, bu as isScheduleDefinition, iu as isSoftDelete, us as isWorkflowEventTriggerDefinition, Rd as ivmValue, pp as lastWriteProvenance, mc as listConnectionStates, rl as listResourcePolicies, pe as listRetentions, Gd as loadResourceTuples, Jd as loadSubjectTuples, gu as localityAwareSelector, cp as makeActionRunner, Uu 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, Yu as makeCoordinatedScheduler, Sl as makeDataLoader, Zc as makeDisconnectConnectionExecutor, Ko as makeEffectStoreLayer, Ts as makeEventPublisher, gs as makeEventsFacade, fi as makeFieldCipher, Ri as makeFluentStore, lf as makeIdleGate, as as makeLazyWorkflowFacade, Jc as makeListConnectionsExecutor, ja as makeMutationOutputCodec, ep as makeMutationRunner, op as makeOneShotQueryRunner, Hs as makeOutboxFacade, rs as makePostCommitWorkflowFacade, af as makeProcessAdapter, ap as makeQueryDescriptorProducer, ip as makeQueryReauthorizer, sp as makeQuerySubscriber, uf as makeRouterActivity, Fl as makeSchemaRegistry, Yc as makeStartConnectionExecutor, Xc as makeSubmitTokenExecutor, id as makeUndoCapture, df as makeWakeGate, mf as makeWakeProxyServer, ns as makeWorkflowFacade, is as makeWorkflowFacadeWithCallerContext, os as makeWorkflowHandlers, ss as makeWorkflowLayers, Yo as makeWorkflowRunHandle, ku as markWakeupFired, Bd as materializeIvm, Po as memoryApiKeyStore, vu as memoryReplicationAdapter, Zi as memoryRywPositionStore, wu as nextFiring, Iu as nextWakeup, sf as nodeProcessSupervisor, Tf as noopAnalytics, Of 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, yp as previewInRollback, lc as projectConnectionState, Ru 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, Nd as recordTimelineEvent, gr as recordWorkflowRun, Wl as redactColumns, Ed as redactRow, $i as redisRywPositionStore, Sd as redoUndoInvocation, vc as refreshAccessToken, Qr as registerConnectionStream, Ce as registerRetention, Du as registerWakeup, Mu as releaseWakeup, Xi as replicaHealth, va as resetComputedQueryCacheWarnings, ir as resetEventMetricTagCacheForTests, Oi as resetObservedGraph, lo as resetSecretsBackend, Oc as resolveConnection, Uc as resolveConnectionForSubject, _u as resolveCurrentRegion, Tn as resolveDependentTables, Ic as resolveRedirectUri, Hd as resolveRescan, kr as resolveRowFilterScope, Ar as resolveRowFilterScopeFor, uo as resolveSecret, fo as resolveSecretSync, ho as resolveSecretsBackend, Cd as resolveTimelineMode, Te as retentionTtlMsFromEnv, Od as reverseEventOverRows, dl as revokedIds, au as rulesFor, hu as runAsSystem, gf as runOrchestratorTick, Uf as runProvidedEffect, ef as runReaction, _f as runSingleNodeOrchestrator, rf as runWakeLoop, $f as runWithDeadlockRetry, Ti as runWithObservedProcedure, hl as runWithRequestLoader, na as runWithRoutingContext, ci as runWithTraceContext, Fc as sanitizeRedirectTo, Ju as scheduleCoordinated, Yl as schemaPropertyNames, Zl as serverOnlyLeaks, Vc as setConnectionResolver, mi as setFieldCipher, Er as setRowFilter, co as setSecretsBackend, fu as setSystemStoreHandle, Md as setTimelineRecorderForTest, vl as setTupleSource, Qt as settleHandlerBody, ko as sha256Hex, Ua as shutdownGraceMsFromEnv, Vu as singleCoordinator, xr as snapshotMetrics, Sr as snapshotMetricsSync, kl as ssrfGuardHttpClientLayer, Ol as ssrfReason, Fa as startRpcServer, Gu as startScheduler, dc as storeCredential, zc as sweepExpiredGrants, Me as sweepRetention, sd as synthesizeInverse, Cl as tracingHttpClientLayer, cs as triggerWorkflow, ju as tryClaimWakeup, Yr as unbindConnectionSubject, ed as undoCaptureEnabled, yd as undoLogExecutor, nu as unresolvedSources, Lf as useAggregate, Cf as useAnalytics, ul as visibleRows, nf as wakeDueOnce, Kf as withRowFilter, qo as workflowToRpc, rd as wrapCaptureStore, Vl as wrapStoreWithBootCodec, Ji as wrapStoreWithMixinBehaviour };