@voltro/runtime 0.21.0 → 0.22.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
@@ -3,22 +3,22 @@ import { createCipheriv as _e, createDecipheriv as ve, createHash as ye, randomB
3
3
  import { EventEmitter as Ce } from "node:events";
4
4
  import { ADMIN_SCOPE as we, APIKEY_ISSUE_ORG_SCOPE as Te, APIKEY_ISSUE_OTHER_SCOPE as Ee, APIKEY_ISSUE_SELF_SCOPE as De, ConnectionHandshakeFailed as j, ConnectionInfo as Oe, ConnectionKindMismatch as ke, ConnectionNotDeclared as Ae, ConnectionSubjectRequired as je, ScopeError as Me, SubjectService as Ne, UndoConflict as Pe, UndoForbidden as Fe, UndoNotFound as Ie, WorkflowRunHandleSchema as Le, checkGuardsEffect as Re, diffRows as ze, effectiveScopes as Be, hasEffectiveScope as Ve, isIdKeyed as He, publishServerError as Ue, requireScope as We, setPolicyGuardResolver as Ge, systemSubject as Ke, tsMs as qe } from "@voltro/protocol";
5
5
  import { createLogger as M } from "@voltro/logger";
6
- import { Cause as N, Clock as Je, Context as Ye, Cron as P, Deferred as Xe, Duration as Ze, Effect as F, Either as Qe, Exit as $e, Fiber as et, Layer as I, ManagedRuntime as tt, Metric as L, MetricBoundaries as nt, MetricState as rt, Option as it, Ref as R, Schedule as at, Schema as z, Stream as B, Tracer as ot } from "effect";
7
- import * as st from "node:http";
8
- import { createServer as ct } from "node:http";
9
- import { HttpClient as lt, HttpClientRequest as ut, HttpLayerRouter as V, HttpServer as dt, HttpServerRequest as ft, HttpServerResponse as H } from "@effect/platform";
10
- import { NodeContext as pt, NodeHttpServer as mt } from "@effect/platform-node";
11
- import { Rpc as ht, RpcSerialization as gt, RpcServer as _t } from "@effect/rpc";
12
- import { defineRestRoute as vt, dispatchSharedPath as yt, requireAnyScope as bt, requireScope as xt } from "@voltro/protocol/rest";
13
- import { AsyncLocalStorage as St } from "node:async_hooks";
14
- import { ArrayFormatter as Ct, TreeFormatter as wt } from "effect/ParseResult";
15
- import { SpanKind as Tt, SpanStatusCode as Et } from "@opentelemetry/api";
16
- import { Kv as Dt, KvError as Ot, KvStore as kt, layerConnections as At, layerMemory as jt, layerRedis as Mt } from "@voltro/kv";
17
- import { apiKeyStrategy as Nt } from "@voltro/protocol/apikey";
18
- import { getCurrentWorkflowExecutionId as Pt, inspectWorkflow as Ft } from "@voltro/workflow";
19
- import { spawn as It } from "node:child_process";
6
+ import { Cause as N, Clock as Je, Context as Ye, Cron as Xe, Deferred as Ze, Duration as Qe, Effect as P, Either as $e, Exit as et, Fiber as tt, Layer as F, ManagedRuntime as nt, Metric as I, MetricBoundaries as rt, MetricState as it, Option as at, Ref as L, Schedule as ot, Schema as R, Stream as z, Tracer as st } from "effect";
7
+ import * as ct from "node:http";
8
+ import { createServer as lt } from "node:http";
9
+ import { HttpClient as ut, HttpClientRequest as dt, HttpLayerRouter as B, HttpServer as ft, HttpServerRequest as pt, HttpServerResponse as V } from "@effect/platform";
10
+ import { NodeContext as mt, NodeHttpServer as ht } from "@effect/platform-node";
11
+ import { Rpc as gt, RpcSerialization as _t, RpcServer as vt } from "@effect/rpc";
12
+ import { defineRestRoute as yt, dispatchSharedPath as bt, requireAnyScope as xt, requireScope as St } from "@voltro/protocol/rest";
13
+ import { AsyncLocalStorage as Ct } from "node:async_hooks";
14
+ import { ArrayFormatter as wt, TreeFormatter as Tt } from "effect/ParseResult";
15
+ import { SpanKind as Et, SpanStatusCode as Dt } from "@opentelemetry/api";
16
+ import { Kv as Ot, KvError as kt, KvStore as At, layerConnections as jt, layerMemory as Mt, layerRedis as Nt } from "@voltro/kv";
17
+ import { apiKeyStrategy as Pt } from "@voltro/protocol/apikey";
18
+ import { getCurrentWorkflowExecutionId as Ft, inspectWorkflow as It } from "@voltro/workflow";
19
+ import { spawn as Lt } from "node:child_process";
20
20
  //#region src/matcher.ts
21
- var Lt = class {
21
+ var Rt = class {
22
22
  byTable = /* @__PURE__ */ new Map();
23
23
  register(e) {
24
24
  let t = this.byTable.get(e.table);
@@ -59,7 +59,7 @@ var Lt = class {
59
59
  });
60
60
  return { perTable: e };
61
61
  }
62
- }, Rt = (e) => {
62
+ }, zt = (e) => {
63
63
  let t = [];
64
64
  for (let n of ge(e)) n.conjunctive && n.path === void 0 && (n.op === "eq" && t.push({
65
65
  column: n.column,
@@ -69,7 +69,7 @@ var Lt = class {
69
69
  values: n.value
70
70
  }));
71
71
  return t;
72
- }, zt = (e) => {
72
+ }, Bt = (e) => {
73
73
  let t = [];
74
74
  for (let n of ge(e)) n.conjunctive && n.path === void 0 && (n.op === "gt" || n.op === "gte" || n.op === "lt" || n.op === "lte") && t.push({
75
75
  column: n.column,
@@ -77,10 +77,10 @@ var Lt = class {
77
77
  threshold: n.value
78
78
  });
79
79
  return t;
80
- }, Bt = (e, t) => {
80
+ }, Vt = (e, t) => {
81
81
  for (let n of ge(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
82
82
  return null;
83
- }, Vt = (e, t) => {
83
+ }, Ht = (e, t) => {
84
84
  let n = [];
85
85
  for (let r of e) {
86
86
  let e = t(r);
@@ -88,8 +88,8 @@ var Lt = class {
88
88
  n.push(`${typeof e}:${String(e)}`);
89
89
  }
90
90
  return n.join("|");
91
- }, Ht = (e, t) => e === null || t === null ? null : e === t ? 0 : typeof e == typeof t ? e > t ? 1 : -1 : null, Ut = (e, t, n) => {
92
- let r = Ht(e, n);
91
+ }, Ut = (e, t) => e === null || t === null ? null : e === t ? 0 : typeof e == typeof t ? e > t ? 1 : -1 : null, Wt = (e, t, n) => {
92
+ let r = Ut(e, n);
93
93
  if (r === null) return !1;
94
94
  switch (t) {
95
95
  case "gt": return r > 0;
@@ -97,7 +97,7 @@ var Lt = class {
97
97
  case "lt": return r < 0;
98
98
  case "lte": return r <= 0;
99
99
  }
100
- }, Wt = class {
100
+ }, Gt = class {
101
101
  columnByTable = /* @__PURE__ */ new Map();
102
102
  rangeByTable = /* @__PURE__ */ new Map();
103
103
  tupleByTable = /* @__PURE__ */ new Map();
@@ -105,9 +105,9 @@ var Lt = class {
105
105
  subscriptions = /* @__PURE__ */ new Map();
106
106
  register(e) {
107
107
  this.columnByTable.has(e.table) || this.columnByTable.set(e.table, /* @__PURE__ */ new Map()), this.rangeByTable.has(e.table) || this.rangeByTable.set(e.table, /* @__PURE__ */ new Map()), this.tupleByTable.has(e.table) || this.tupleByTable.set(e.table, /* @__PURE__ */ new Map()), this.unindexedByTable.has(e.table) || this.unindexedByTable.set(e.table, /* @__PURE__ */ new Set());
108
- let t = Rt(e.predicate), n = zt(e.predicate);
108
+ let t = zt(e.predicate), n = Bt(e.predicate);
109
109
  if (e.usingIndex !== void 0) {
110
- let r = e.usingIndex, i = Vt(r.fields, (t) => Bt(e.predicate, t));
110
+ let r = e.usingIndex, i = Ht(r.fields, (t) => Vt(e.predicate, t));
111
111
  if (i !== null) {
112
112
  let a = `${r.name}|${i}`, o = this.tupleByTable.get(e.table), s = o.get(a);
113
113
  s || (s = /* @__PURE__ */ new Set(), o.set(a, s)), s.add(e.id), this.subscriptions.set(e.id, {
@@ -252,7 +252,7 @@ var Lt = class {
252
252
  }
253
253
  }
254
254
  for (let [e, a] of i) {
255
- let i = Vt(a, (e) => t[e]);
255
+ let i = Ht(a, (e) => t[e]);
256
256
  if (i === null) continue;
257
257
  let o = r.get(`${e}|${i}`);
258
258
  if (o) for (let e of o) n.add(e);
@@ -266,7 +266,7 @@ var Lt = class {
266
266
  let a = this.rangeByTable.get(e);
267
267
  if (a) for (let [e, r] of a) {
268
268
  let i = t[e];
269
- if (i !== null) for (let [e, t] of r) for (let r of t) Ut(i, e, r.threshold) && n.add(r.subId);
269
+ if (i !== null) for (let [e, t] of r) for (let r of t) Wt(i, e, r.threshold) && n.add(r.subId);
270
270
  }
271
271
  return n;
272
272
  }
@@ -275,7 +275,7 @@ var Lt = class {
275
275
  let e = t[n.column];
276
276
  if (n.kind === "eq") {
277
277
  if (e !== n.value) return !1;
278
- } else if (!Ut(e, n.op, n.threshold)) return !1;
278
+ } else if (!Wt(e, n.op, n.threshold)) return !1;
279
279
  }
280
280
  return !0;
281
281
  }
@@ -297,23 +297,23 @@ var Lt = class {
297
297
  }
298
298
  return i;
299
299
  }
300
- }, Gt = (e) => {
300
+ }, Kt = (e) => {
301
301
  if (e == null) return null;
302
- if (Array.isArray(e)) return e.map(Gt);
302
+ if (Array.isArray(e)) return e.map(Kt);
303
303
  if (typeof e == "object") {
304
304
  let t = e, n = Object.keys(t).sort(), r = {};
305
- for (let e of n) r[e] = Gt(t[e]);
305
+ for (let e of n) r[e] = Kt(t[e]);
306
306
  return r;
307
307
  }
308
308
  return e;
309
- }, Kt = (e, t, n) => {
310
- let r = Gt({
309
+ }, qt = (e, t, n) => {
310
+ let r = Kt({
311
311
  table: e,
312
312
  predicate: t,
313
313
  indexHint: n ?? null
314
314
  });
315
315
  return ye("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
316
- }, qt = class {
316
+ }, Jt = class {
317
317
  matcher;
318
318
  byFingerprint = /* @__PURE__ */ new Map();
319
319
  byClient = /* @__PURE__ */ new Map();
@@ -332,7 +332,7 @@ var Lt = class {
332
332
  } catch {}
333
333
  }
334
334
  subscribe(e, t, n, r) {
335
- let i = Kt(t, n, r?.name), a = this.byFingerprint.get(i);
335
+ let i = qt(t, n, r?.name), a = this.byFingerprint.get(i);
336
336
  return a ? (a.subscribers.add(e), this.byClient.set(e, i), this.notifyChange(), {
337
337
  fingerprint: i,
338
338
  deduplicated: !0
@@ -390,7 +390,7 @@ var Lt = class {
390
390
  });
391
391
  return e;
392
392
  }
393
- }, Jt = (e, t) => t.length === 0 ? e : [...e].sort((e, n) => {
393
+ }, Yt = (e, t) => t.length === 0 ? e : [...e].sort((e, n) => {
394
394
  for (let r of t) {
395
395
  let t = e[r.column], i = n[r.column];
396
396
  if (t === i) continue;
@@ -400,7 +400,7 @@ var Lt = class {
400
400
  return r.direction === "asc" ? a : -a;
401
401
  }
402
402
  return 0;
403
- }), Yt = (e, t, n) => {
403
+ }), Xt = (e, t, n) => {
404
404
  let r = t.split("."), i = r[0], a = r.slice(1), o = (e) => typeof e == "object" && !!e && !Array.isArray(e), s = e[i], c;
405
405
  if (a.length === 0) c = o(s) && o(n) ? {
406
406
  ...s,
@@ -418,11 +418,11 @@ var Lt = class {
418
418
  ...e,
419
419
  [i]: c
420
420
  };
421
- }, Xt = (e, t, n) => !e || f(e, t, n), U = (e, t) => {
421
+ }, Zt = (e, t, n) => !e || f(e, t, n), H = (e, t) => {
422
422
  let n = /* @__PURE__ */ new Map();
423
423
  if (!e) return n;
424
424
  for (let r of o(e)) {
425
- let e = t.get(r.descriptor.table) ?? /* @__PURE__ */ new Map(), i = U(r.descriptor.predicate, t), a = Zt(r.descriptor, e, t, i);
425
+ let e = t.get(r.descriptor.table) ?? /* @__PURE__ */ new Map(), i = H(r.descriptor.predicate, t), a = Qt(r.descriptor, e, t, i);
426
426
  if (r.kind === "exists") n.set(r.descriptor, a.length);
427
427
  else {
428
428
  let e = r.descriptor.projection, t = /* @__PURE__ */ new Set();
@@ -437,15 +437,15 @@ var Lt = class {
437
437
  }
438
438
  }
439
439
  return n;
440
- }, Zt = (e, t, n = /* @__PURE__ */ new Map(), r = null) => {
441
- let i = r ?? U(e.predicate, n), a = [...t.values()].filter((t) => Xt(e.predicate, t, i));
440
+ }, Qt = (e, t, n = /* @__PURE__ */ new Map(), r = null) => {
441
+ let i = r ?? H(e.predicate, n), a = [...t.values()].filter((t) => Zt(e.predicate, t, i));
442
442
  if (e.aggregations && e.aggregations.length > 0) {
443
- let t = Qt(a, e.aggregations, e.groupBy);
443
+ let t = $t(a, e.aggregations, e.groupBy);
444
444
  if (!e.having) return t;
445
- let r = U(e.having, n);
446
- return t.filter((t) => Xt(e.having, t, r));
445
+ let r = H(e.having, n);
446
+ return t.filter((t) => Zt(e.having, t, r));
447
447
  }
448
- let o = Jt(a, e.order), s = e.skip ? o.slice(e.skip) : o, c = e.take === void 0 ? s : s.slice(0, e.take);
448
+ let o = Yt(a, e.order), s = e.skip ? o.slice(e.skip) : o, c = e.take === void 0 ? s : s.slice(0, e.take);
449
449
  if (!e.projection) return c;
450
450
  let l = e.projection;
451
451
  return c.map((e) => {
@@ -453,7 +453,7 @@ var Lt = class {
453
453
  for (let n of l) t[n] = e[n];
454
454
  return t;
455
455
  });
456
- }, Qt = (e, t, n) => {
456
+ }, $t = (e, t, n) => {
457
457
  let r = /* @__PURE__ */ new Map();
458
458
  for (let t of e) {
459
459
  let e = {};
@@ -471,11 +471,11 @@ var Lt = class {
471
471
  let i = [];
472
472
  for (let e of r.values()) {
473
473
  let n = { ...e.keyVals };
474
- for (let r of t) n[r.alias] = $t(r, e.rows);
474
+ for (let r of t) n[r.alias] = en(r, e.rows);
475
475
  i.push(n);
476
476
  }
477
477
  return i;
478
- }, $t = (e, t) => {
478
+ }, en = (e, t) => {
479
479
  switch (e.op) {
480
480
  case "count": return e.column === void 0 ? t.length : t.reduce((t, n) => t + +(n[e.column] !== null && n[e.column] !== void 0), 0);
481
481
  case "count-distinct": {
@@ -519,7 +519,7 @@ var Lt = class {
519
519
  }
520
520
  default: throw Error(`computeAggregates: unknown op '${e.op}'`);
521
521
  }
522
- }, en = "\0", tn = (e, t) => e === null ? t : `${e}${en}${t}`, nn = class e {
522
+ }, tn = "\0", nn = (e, t) => e === null ? t : `${e}${tn}${t}`, rn = class e {
523
523
  #e;
524
524
  #t;
525
525
  #n(e) {
@@ -541,7 +541,7 @@ var Lt = class {
541
541
  let n = t.id;
542
542
  n && e.set(n, t);
543
543
  }
544
- this.#e.set(tn(t, n), e);
544
+ this.#e.set(nn(t, n), e);
545
545
  }
546
546
  }
547
547
  withNamespace(t) {
@@ -552,11 +552,11 @@ var Lt = class {
552
552
  }, t);
553
553
  }
554
554
  #o(e) {
555
- return tn(this.#i, e);
555
+ return nn(this.#i, e);
556
556
  }
557
557
  #s() {
558
- let e = /* @__PURE__ */ new Map(), t = this.#i === null ? null : `${this.#i}${en}`;
559
- for (let [n, r] of this.#e) t === null ? n.includes(en) || e.set(n, r) : n.startsWith(t) && e.set(n.slice(t.length), r);
558
+ let e = /* @__PURE__ */ new Map(), t = this.#i === null ? null : `${this.#i}${tn}`;
559
+ for (let [n, r] of this.#e) t === null ? n.includes(tn) || e.set(n, r) : n.startsWith(t) && e.set(n.slice(t.length), r);
560
560
  return e;
561
561
  }
562
562
  #c(e) {
@@ -564,7 +564,7 @@ var Lt = class {
564
564
  return n || (n = /* @__PURE__ */ new Map(), this.#e.set(t, n)), n;
565
565
  }
566
566
  async query(e) {
567
- let t = Zt(e, this.#e.get(this.#o(e.table)) ?? /* @__PURE__ */ new Map(), this.#s());
567
+ let t = Qt(e, this.#e.get(this.#o(e.table)) ?? /* @__PURE__ */ new Map(), this.#s());
568
568
  return v(e) ? n(t, e.eager, ce(e.table), (e) => this.query(e)) : t;
569
569
  }
570
570
  async insert(e, t) {
@@ -595,7 +595,7 @@ var Lt = class {
595
595
  if (!i) return null;
596
596
  let a = i.get(t);
597
597
  if (!a) return null;
598
- let o = Yt(a, n, r);
598
+ let o = Xt(a, n, r);
599
599
  return i.set(t, o), this.#n({
600
600
  table: e,
601
601
  op: "update",
@@ -637,7 +637,7 @@ var Lt = class {
637
637
  async updateMany(e, t, n) {
638
638
  let r = this.#e.get(this.#o(e));
639
639
  if (!r) return 0;
640
- let i = U(n.where, this.#s()), a = 0;
640
+ let i = H(n.where, this.#s()), a = 0;
641
641
  for (let [o, s] of r) {
642
642
  if (!f(n.where, s, i)) continue;
643
643
  let c = {
@@ -656,7 +656,7 @@ var Lt = class {
656
656
  async deleteMany(e, t) {
657
657
  let n = this.#e.get(this.#o(e));
658
658
  if (!n) return 0;
659
- let r = U(t.where, this.#s()), i = [];
659
+ let r = H(t.where, this.#s()), i = [];
660
660
  for (let [e, a] of n) f(t.where, a, r) && i.push([e, a]);
661
661
  for (let [t, r] of i) n.delete(t), this.#n({
662
662
  table: e,
@@ -695,7 +695,7 @@ var Lt = class {
695
695
  }
696
696
  }
697
697
  async transactional(e) {
698
- let t = new rn(this.#d());
698
+ let t = new an(this.#d());
699
699
  try {
700
700
  let n = await e(t);
701
701
  return t.commit(), n;
@@ -731,7 +731,7 @@ var Lt = class {
731
731
  allocateNumericId: (e) => this.#l(e)
732
732
  };
733
733
  }
734
- }, rn = class {
734
+ }, an = class {
735
735
  parent;
736
736
  overlay = /* @__PURE__ */ new Map();
737
737
  tombstones = /* @__PURE__ */ new Map();
@@ -761,7 +761,7 @@ var Lt = class {
761
761
  return t || (t = /* @__PURE__ */ new Map(), this.overlay.set(e, t)), t;
762
762
  }
763
763
  async query(e) {
764
- let t = this.buildTablesView(e), r = Zt(e, this.materialise(e.table), t);
764
+ let t = this.buildTablesView(e), r = Qt(e, this.materialise(e.table), t);
765
765
  return v(e) ? n(r, e.eager, ce(e.table), (e) => this.query(e)) : r;
766
766
  }
767
767
  async insert(e, t) {
@@ -801,7 +801,7 @@ var Lt = class {
801
801
  async patchJson(e, t, n, r) {
802
802
  let i = this.materialise(e).get(t);
803
803
  if (!i) return null;
804
- let a = Yt(i, n, r);
804
+ let a = Xt(i, n, r);
805
805
  return this.getOrCreateOverlay(e).set(t, a), this.events.push({
806
806
  table: e,
807
807
  op: "update",
@@ -822,7 +822,7 @@ var Lt = class {
822
822
  }), !0;
823
823
  }
824
824
  async updateMany(e, t, n) {
825
- let r = this.materialise(e), i = U(n.where, this.buildTablesViewForPred(n.where)), a = 0;
825
+ let r = this.materialise(e), i = H(n.where, this.buildTablesViewForPred(n.where)), a = 0;
826
826
  for (let [o, s] of r) {
827
827
  if (!f(n.where, s, i)) continue;
828
828
  let r = {
@@ -839,7 +839,7 @@ var Lt = class {
839
839
  return a;
840
840
  }
841
841
  async deleteMany(e, t) {
842
- let n = this.materialise(e), r = U(t.where, this.buildTablesViewForPred(t.where)), i = 0, a = this.tombstones.get(e);
842
+ let n = this.materialise(e), r = H(t.where, this.buildTablesViewForPred(t.where)), i = 0, a = this.tombstones.get(e);
843
843
  for (let [o, s] of n) f(t.where, s, r) && (this.overlay.get(e)?.delete(o), a || (a = /* @__PURE__ */ new Set(), this.tombstones.set(e, a)), a.add(o), this.events.push({
844
844
  table: e,
845
845
  op: "delete",
@@ -902,7 +902,7 @@ var Lt = class {
902
902
  discard() {
903
903
  this.settled || (this.settled = !0, this.overlay.clear(), this.tombstones.clear(), this.events.length = 0);
904
904
  }
905
- }, an = (e) => {
905
+ }, on = (e) => {
906
906
  let t = {}, n = [], r = e;
907
907
  for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
908
908
  let e = r;
@@ -913,23 +913,23 @@ var Lt = class {
913
913
  (o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = e.cause;
914
914
  }
915
915
  return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
916
- }, on = (e) => {
916
+ }, sn = (e) => {
917
917
  let t = e.dbCode;
918
918
  return t === "23503" || e.dbErrno === 1452 || t === 547 || t === "SQLITE_CONSTRAINT_FOREIGNKEY";
919
- }, sn = (e) => ({
919
+ }, cn = (e) => ({
920
920
  has: (t) => Ve(e, t),
921
921
  hasAny: (t) => t.some((t) => Ve(e, t)),
922
922
  require: (t) => We(e, t),
923
923
  get scopes() {
924
924
  return Be(e);
925
925
  }
926
- }), cn = (e) => {
926
+ }), ln = (e) => {
927
927
  let t = /* @__PURE__ */ new Set();
928
- return ln(e, t), t;
929
- }, ln = (e, t) => {
930
- if (t.add(e.table), e.eager !== void 0 && un(e.table, e.eager, t), e.setOp !== void 0) for (let n of e.setOp.queries) ln(n, t);
931
- if (e.ctes !== void 0) for (let n of e.ctes) ln(n.descriptor, t);
932
- }, un = (e, t, n) => {
928
+ return un(e, t), t;
929
+ }, un = (e, t) => {
930
+ if (t.add(e.table), e.eager !== void 0 && dn(e.table, e.eager, t), e.setOp !== void 0) for (let n of e.setOp.queries) un(n, t);
931
+ if (e.ctes !== void 0) for (let n of e.ctes) un(n.descriptor, t);
932
+ }, dn = (e, t, n) => {
933
933
  let r = m(e);
934
934
  if (r !== void 0) for (let [e, i] of Object.entries(t)) {
935
935
  let t = r[e];
@@ -937,24 +937,24 @@ var Lt = class {
937
937
  let a = i === !0 ? {} : i;
938
938
  if (t.kind === "manyToMany") {
939
939
  let e = t.through().tableName, r = t.target().tableName;
940
- n.add(e), n.add(r), a.with !== void 0 && un(r, a.with, n);
940
+ n.add(e), n.add(r), a.with !== void 0 && dn(r, a.with, n);
941
941
  } else {
942
942
  let e = t.target().tableName;
943
- n.add(e), a.with !== void 0 && un(e, a.with, n);
943
+ n.add(e), a.with !== void 0 && dn(e, a.with, n);
944
944
  }
945
945
  }
946
- }, dn = (e) => e.setOp !== void 0 || e.ctes !== void 0 && e.ctes.length > 0 || e.aggregations !== void 0 && e.aggregations.some((e) => e.op.startsWith("window-")), fn = /* @__PURE__ */ new Set(["*"]), pn = (e, t) => {
946
+ }, fn = (e) => e.setOp !== void 0 || e.ctes !== void 0 && e.ctes.length > 0 || e.aggregations !== void 0 && e.aggregations.some((e) => e.op.startsWith("window-")), pn = /* @__PURE__ */ new Set(["*"]), mn = (e, t) => {
947
947
  if (e !== void 0) {
948
948
  if ("not" in e) {
949
- pn(e.not, t);
949
+ mn(e.not, t);
950
950
  return;
951
951
  }
952
952
  if ("and" in e) {
953
- for (let n of e.and) pn(n, t);
953
+ for (let n of e.and) mn(n, t);
954
954
  return;
955
955
  }
956
956
  if ("or" in e) {
957
- for (let n of e.or) pn(n, t);
957
+ for (let n of e.or) mn(n, t);
958
958
  return;
959
959
  }
960
960
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
@@ -963,11 +963,11 @@ var Lt = class {
963
963
  }
964
964
  e.op === "exists" || e.op === "not-exists" || t.add(e.column);
965
965
  }
966
- }, W = (e, t, n) => {
966
+ }, U = (e, t, n) => {
967
967
  let r = e.get(t);
968
968
  r === void 0 && (r = /* @__PURE__ */ new Set(), e.set(t, r));
969
969
  for (let e of n) r.add(e);
970
- }, mn = (e, t, n) => {
970
+ }, hn = (e, t, n) => {
971
971
  let r = m(e);
972
972
  if (r !== void 0) for (let [i, a] of Object.entries(t)) {
973
973
  let t = r[i];
@@ -975,65 +975,65 @@ var Lt = class {
975
975
  let o = a === !0 ? {} : a;
976
976
  if (t.kind === "manyToMany") {
977
977
  let r = t.through(), i = t.target();
978
- W(n, r.tableName, [t.sourceKey, t.targetKey]), W(n, e, ["id"]), W(n, i.tableName, ["id"]), hn(i.tableName, o, n), o.with !== void 0 && mn(i.tableName, o.with, n);
978
+ U(n, r.tableName, [t.sourceKey, t.targetKey]), U(n, e, ["id"]), U(n, i.tableName, ["id"]), gn(i.tableName, o, n), o.with !== void 0 && hn(i.tableName, o.with, n);
979
979
  continue;
980
980
  }
981
981
  let s = t.target();
982
- t.foreignKey !== void 0 && W(n, s.tableName, [t.foreignKey]), t.sourceKey === void 0 ? W(n, e, ["id"]) : W(n, e, [t.sourceKey]), W(n, s.tableName, ["id"]), hn(s.tableName, o, n), o.with !== void 0 && mn(s.tableName, o.with, n);
982
+ t.foreignKey !== void 0 && U(n, s.tableName, [t.foreignKey]), t.sourceKey === void 0 ? U(n, e, ["id"]) : U(n, e, [t.sourceKey]), U(n, s.tableName, ["id"]), gn(s.tableName, o, n), o.with !== void 0 && hn(s.tableName, o.with, n);
983
983
  }
984
- }, hn = (e, t, n) => {
984
+ }, gn = (e, t, n) => {
985
985
  if (t.where !== void 0) {
986
986
  let r = /* @__PURE__ */ new Set();
987
- pn(t.where, r), W(n, e, r);
987
+ mn(t.where, r), U(n, e, r);
988
988
  }
989
- t.orderBy !== void 0 && W(n, e, t.orderBy.map((e) => e.column));
989
+ t.orderBy !== void 0 && U(n, e, t.orderBy.map((e) => e.column));
990
990
  let r = h(e);
991
- r === void 0 ? W(n, e, ["*"]) : W(n, e, Object.keys(r.fields));
992
- }, gn = (e) => {
991
+ r === void 0 ? U(n, e, ["*"]) : U(n, e, Object.keys(r.fields));
992
+ }, _n = (e) => {
993
993
  let t = /* @__PURE__ */ new Map();
994
- if (dn(e)) {
995
- for (let n of cn(e)) W(t, n, ["*"]);
994
+ if (fn(e)) {
995
+ for (let n of ln(e)) U(t, n, ["*"]);
996
996
  return t;
997
997
  }
998
998
  let n = /* @__PURE__ */ new Set();
999
999
  if (e.projection !== void 0) for (let t of e.projection) n.add(t);
1000
1000
  else n.add("*");
1001
- pn(e.predicate, n);
1001
+ mn(e.predicate, n);
1002
1002
  for (let t of e.order) n.add(t.column);
1003
- return W(t, e.table, n), e.eager !== void 0 && mn(e.table, e.eager, t), t;
1004
- }, _n = (e) => {
1005
- if (e.op === "insert" || e.op === "delete" || e.old === null || e.new === null) return fn;
1003
+ return U(t, e.table, n), e.eager !== void 0 && hn(e.table, e.eager, t), t;
1004
+ }, vn = (e) => {
1005
+ if (e.op === "insert" || e.op === "delete" || e.old === null || e.new === null) return pn;
1006
1006
  let t = /* @__PURE__ */ new Set(), n = e.old, r = e.new, i = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
1007
1007
  for (let e of i) Object.is(n[e], r[e]) || t.add(e);
1008
1008
  return t;
1009
- }, vn = (e, t) => {
1009
+ }, yn = (e, t) => {
1010
1010
  let n = t.get(e.table);
1011
1011
  if (n === void 0) return !1;
1012
1012
  if (n.has("*")) return !0;
1013
- let r = _n(e);
1013
+ let r = vn(e);
1014
1014
  if (r.has("*")) return !0;
1015
1015
  for (let e of r) if (n.has(e)) return !0;
1016
1016
  return !1;
1017
- }, yn = nt.exponential({
1017
+ }, bn = rt.exponential({
1018
1018
  start: .001,
1019
1019
  factor: 2,
1020
1020
  count: 16
1021
- }), bn = L.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), xn = L.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), Sn = L.histogram("voltro_rpc_duration_seconds", yn, "RPC handler duration in seconds."), Cn = L.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), wn = L.histogram("voltro_http_duration_seconds", yn, "HTTP route duration in seconds."), Tn = L.histogram("voltro_plugin_hook_duration_seconds", yn, "Plugin interceptor duration in seconds."), En = L.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), Dn = L.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), On = L.histogram("voltro_subscription_delivery_seconds", yn, "Subscription delivery produce→push latency in seconds."), kn = L.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), An = (e) => {
1022
- let t = e.durationMs / 1e3, n = e.kind === "rpc" ? F.zipRight(L.increment(bn).pipe(F.tagMetrics("tag", e.tag), F.tagMetrics("status", e.status)), F.zipRight(L.update(Sn, t).pipe(F.tagMetrics("tag", e.tag)), e.status === "error" ? L.increment(xn).pipe(F.tagMetrics("tag", e.tag)) : F.void)) : e.kind === "request" ? F.zipRight(L.increment(Cn).pipe(F.tagMetrics("route", e.tag), F.tagMetrics("status", e.status)), L.update(wn, t).pipe(F.tagMetrics("route", e.tag))) : F.zipRight(L.update(Tn, t).pipe(F.tagMetrics("hook", e.tag)), e.status === "error" ? L.increment(En).pipe(F.tagMetrics("hook", e.tag)) : F.void);
1023
- F.runSync(n);
1024
- }, jn = (e) => e.startsWith("subscription.") ? e.slice(13) : e, Mn = (e) => {
1025
- let t = jn(e.label);
1026
- F.runSync(F.zipRight(L.increment(Dn).pipe(F.tagMetrics("tag", t), F.tagMetrics("kind", e.kind)), L.update(On, e.durationMs / 1e3).pipe(F.tagMetrics("tag", t), F.tagMetrics("kind", e.kind))));
1027
- }, Nn = /* @__PURE__ */ new Map(), Pn = (e, t) => {
1028
- let n = jn(e), r = Math.max(0, (Nn.get(n) ?? 0) + t);
1029
- r === 0 ? Nn.delete(n) : Nn.set(n, r), F.runSync(L.set(kn, r).pipe(F.tagMetrics("tag", n)));
1030
- }, Fn = (e, t) => L.counter(e, t === void 0 ? {} : { description: t }), In = (e, t) => L.gauge(e, t === void 0 ? {} : { description: t }), Ln = (e, t = yn, n) => L.histogram(e, t, n), Rn = (e) => {
1021
+ }), xn = I.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), Sn = I.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), Cn = I.histogram("voltro_rpc_duration_seconds", bn, "RPC handler duration in seconds."), wn = I.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), Tn = I.histogram("voltro_http_duration_seconds", bn, "HTTP route duration in seconds."), En = I.histogram("voltro_plugin_hook_duration_seconds", bn, "Plugin interceptor duration in seconds."), Dn = I.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), On = I.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), kn = I.histogram("voltro_subscription_delivery_seconds", bn, "Subscription delivery produce→push latency in seconds."), An = I.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), jn = (e) => {
1022
+ let t = e.durationMs / 1e3, n = e.kind === "rpc" ? P.zipRight(I.increment(xn).pipe(P.tagMetrics("tag", e.tag), P.tagMetrics("status", e.status)), P.zipRight(I.update(Cn, t).pipe(P.tagMetrics("tag", e.tag)), e.status === "error" ? I.increment(Sn).pipe(P.tagMetrics("tag", e.tag)) : P.void)) : e.kind === "request" ? P.zipRight(I.increment(wn).pipe(P.tagMetrics("route", e.tag), P.tagMetrics("status", e.status)), I.update(Tn, t).pipe(P.tagMetrics("route", e.tag))) : P.zipRight(I.update(En, t).pipe(P.tagMetrics("hook", e.tag)), e.status === "error" ? I.increment(Dn).pipe(P.tagMetrics("hook", e.tag)) : P.void);
1023
+ P.runSync(n);
1024
+ }, Mn = (e) => e.startsWith("subscription.") ? e.slice(13) : e, Nn = (e) => {
1025
+ let t = Mn(e.label);
1026
+ P.runSync(P.zipRight(I.increment(On).pipe(P.tagMetrics("tag", t), P.tagMetrics("kind", e.kind)), I.update(kn, e.durationMs / 1e3).pipe(P.tagMetrics("tag", t), P.tagMetrics("kind", e.kind))));
1027
+ }, Pn = /* @__PURE__ */ new Map(), W = (e, t) => {
1028
+ let n = Mn(e), r = Math.max(0, (Pn.get(n) ?? 0) + t);
1029
+ r === 0 ? Pn.delete(n) : Pn.set(n, r), P.runSync(I.set(An, r).pipe(P.tagMetrics("tag", n)));
1030
+ }, Fn = (e, t) => I.counter(e, t === void 0 ? {} : { description: t }), In = (e, t) => I.gauge(e, t === void 0 ? {} : { description: t }), Ln = (e, t = bn, n) => I.histogram(e, t, n), Rn = (e) => {
1031
1031
  let t = {};
1032
1032
  for (let n of e) t[n.key] = n.value;
1033
1033
  return t;
1034
- }, zn = L.snapshot.pipe(F.map((e) => e.map((e) => {
1035
- let t = e.metricKey.name, n = Rn(e.metricKey.tags), r = it.getOrUndefined(e.metricKey.description), i = r === void 0 ? {} : { description: r }, a = e.metricState;
1036
- if (rt.isHistogramState(a)) return {
1034
+ }, zn = I.snapshot.pipe(P.map((e) => e.map((e) => {
1035
+ let t = e.metricKey.name, n = Rn(e.metricKey.tags), r = at.getOrUndefined(e.metricKey.description), i = r === void 0 ? {} : { description: r }, a = e.metricState;
1036
+ if (it.isHistogramState(a)) return {
1037
1037
  name: t,
1038
1038
  labels: n,
1039
1039
  ...i,
@@ -1045,14 +1045,14 @@ var Lt = class {
1045
1045
  sum: a.sum,
1046
1046
  count: a.count
1047
1047
  };
1048
- if (rt.isGaugeState(a)) return {
1048
+ if (it.isGaugeState(a)) return {
1049
1049
  name: t,
1050
1050
  labels: n,
1051
1051
  ...i,
1052
1052
  type: "gauge",
1053
1053
  value: Number(a.value)
1054
1054
  };
1055
- if (rt.isSummaryState(a)) return {
1055
+ if (it.isSummaryState(a)) return {
1056
1056
  name: t,
1057
1057
  labels: n,
1058
1058
  ...i,
@@ -1064,7 +1064,7 @@ var Lt = class {
1064
1064
  value: t.value
1065
1065
  }] : [])
1066
1066
  };
1067
- if (rt.isFrequencyState(a)) {
1067
+ if (it.isFrequencyState(a)) {
1068
1068
  let e = {};
1069
1069
  for (let [t, n] of a.occurrences) e[t] = n;
1070
1070
  return {
@@ -1082,12 +1082,12 @@ var Lt = class {
1082
1082
  type: "counter",
1083
1083
  value: Number(a.count)
1084
1084
  };
1085
- }))), Bn = () => F.runSync(zn), Vn = class extends z.TaggedError()("RowFilterUnavailable", { cause: z.String }) {}, Hn = at.exponential("20 millis").pipe(at.intersect(at.recurs(2))), Un, Wn = (e) => {
1085
+ }))), Bn = () => P.runSync(zn), Vn = class extends R.TaggedError()("RowFilterUnavailable", { cause: R.String }) {}, Hn = ot.exponential("20 millis").pipe(ot.intersect(ot.recurs(2))), Un, Wn = (e) => {
1086
1086
  Un = e;
1087
1087
  }, Gn = () => Un, Kn = () => void 0, qn = (e, t) => Jn(Un, e, t), Jn = (e, t, n) => {
1088
- if (e === void 0 || t.type === "system") return F.succeed(Kn);
1088
+ if (e === void 0 || t.type === "system") return P.succeed(Kn);
1089
1089
  let r = e.retry ?? Hn, i = e.load(t);
1090
- return (r === !1 ? i : F.retry(i, r)).pipe(F.map((t) => (n) => e.predicate(t, n)), F.catchAll((t) => F.suspend(() => (n?.(t), e.onLoadError === "deny" ? F.succeed(Yn) : F.fail(new Vn({ cause: String(t) }))))));
1090
+ return (r === !1 ? i : P.retry(i, r)).pipe(P.map((t) => (n) => e.predicate(t, n)), P.catchAll((t) => P.suspend(() => (n?.(t), e.onLoadError === "deny" ? P.succeed(Yn) : P.fail(new Vn({ cause: String(t) }))))));
1091
1091
  }, Yn = () => ({
1092
1092
  column: "id",
1093
1093
  op: "isNull"
@@ -1110,12 +1110,12 @@ var Lt = class {
1110
1110
  computedSubs = /* @__PURE__ */ new Map();
1111
1111
  computedByTable = /* @__PURE__ */ new Map();
1112
1112
  constructor(e) {
1113
- this.deps = e, this.matcher = new Wt(), this.subscriptionRegistry = new qt(this.matcher), this.unsubscribeChange = e.store.onChange((e) => {
1113
+ this.deps = e, this.matcher = new Gt(), this.subscriptionRegistry = new Jt(this.matcher), this.unsubscribeChange = e.store.onChange((e) => {
1114
1114
  this.handleChange(e);
1115
1115
  });
1116
1116
  }
1117
1117
  async subscribe(e, t, n, r, i, a, o, s) {
1118
- let c = `sub_${xe()}`, l = i ?? `subscription.${e.table}`, u = cn(e), d = gn(e);
1118
+ let c = `sub_${xe()}`, l = i ?? `subscription.${e.table}`, u = ln(e), d = _n(e);
1119
1119
  e.predicate !== void 0 && this.subscriptionRegistry.subscribe(c, e.table, e.predicate, r);
1120
1120
  for (let e of u) {
1121
1121
  let t = this.dependentByTable.get(e);
@@ -1146,7 +1146,7 @@ var Lt = class {
1146
1146
  cacheBinding: a,
1147
1147
  reauthorize: o,
1148
1148
  refilter: s
1149
- }), Pn(l, 1), t({
1149
+ }), W(l, 1), t({
1150
1150
  _tag: "snapshot",
1151
1151
  revision: 0,
1152
1152
  data: g
@@ -1162,11 +1162,11 @@ var Lt = class {
1162
1162
  durationMs: _ - f,
1163
1163
  rowCount: g.length
1164
1164
  }), () => {
1165
- this.subscriptions.delete(c), Pn(l, -1), m();
1165
+ this.subscriptions.delete(c), W(l, -1), m();
1166
1166
  };
1167
1167
  }
1168
1168
  revokeSubscription(e, t, n = "guards no longer satisfied") {
1169
- this.subscriptions.delete(e.id), Pn(e.label, -1), this.subscriptionRegistry.unsubscribe(e.id);
1169
+ this.subscriptions.delete(e.id), W(e.label, -1), this.subscriptionRegistry.unsubscribe(e.id);
1170
1170
  for (let t of e.dependentTables) {
1171
1171
  let n = this.dependentByTable.get(t);
1172
1172
  n !== void 0 && (n.delete(e.id), n.size === 0 && this.dependentByTable.delete(t));
@@ -1181,7 +1181,7 @@ var Lt = class {
1181
1181
  });
1182
1182
  }
1183
1183
  revokeComputed(e, t) {
1184
- this.computedSubs.delete(e.id), Pn(e.label, -1);
1184
+ this.computedSubs.delete(e.id), W(e.label, -1);
1185
1185
  for (let t of e.tables) {
1186
1186
  let n = this.computedByTable.get(t);
1187
1187
  n !== void 0 && (n.delete(e.id), n.size === 0 && this.computedByTable.delete(t));
@@ -1207,7 +1207,7 @@ var Lt = class {
1207
1207
  lastJson: tr(e.value),
1208
1208
  revision: 0
1209
1209
  };
1210
- this.computedSubs.set(i, o), Pn(o.label, 1);
1210
+ this.computedSubs.set(i, o), W(o.label, 1);
1211
1211
  for (let e of a) {
1212
1212
  let t = this.computedByTable.get(e);
1213
1213
  t === void 0 && (t = /* @__PURE__ */ new Set(), this.computedByTable.set(e, t)), t.add(i);
@@ -1227,7 +1227,7 @@ var Lt = class {
1227
1227
  durationMs: Date.now() - s,
1228
1228
  rowCount: Qn(e.value)
1229
1229
  }), () => {
1230
- this.computedSubs.delete(i), Pn(o.label, -1);
1230
+ this.computedSubs.delete(i), W(o.label, -1);
1231
1231
  for (let e of a) {
1232
1232
  let t = this.computedByTable.get(e);
1233
1233
  t !== void 0 && (t.delete(i), t.size === 0 && this.computedByTable.delete(e));
@@ -1309,7 +1309,7 @@ var Lt = class {
1309
1309
  G.trace("missing subscription", { subscriberId: t });
1310
1310
  continue;
1311
1311
  }
1312
- if (!vn(e, n.relevantFields)) {
1312
+ if (!yn(e, n.relevantFields)) {
1313
1313
  o++;
1314
1314
  continue;
1315
1315
  }
@@ -1441,12 +1441,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1441
1441
  };
1442
1442
  }, xr = (e) => {
1443
1443
  let t = br(e);
1444
- if (t !== null) return ot.externalSpan({
1444
+ if (t !== null) return st.externalSpan({
1445
1445
  traceId: t.traceId,
1446
1446
  spanId: t.spanId,
1447
1447
  sampled: t.sampled
1448
1448
  });
1449
- }, Sr = new St(), Cr = (e, t) => Sr.run(e, t), wr = () => Sr.getStore(), Tr = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : Se(e, "voltro:field-encryption:v1", 32), Er = (t) => {
1449
+ }, Sr = new Ct(), Cr = (e, t) => Sr.run(e, t), wr = () => Sr.getStore(), Tr = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : Se(e, "voltro:field-encryption:v1", 32), Er = (t) => {
1450
1450
  if (t.length !== 32) throw Error(`field cipher key must be 32 bytes, got ${t.length}`);
1451
1451
  return {
1452
1452
  encrypt: (n) => {
@@ -1471,7 +1471,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1471
1471
  let t = q();
1472
1472
  if (!t) throw Error(`decryptField: ${Ar}`);
1473
1473
  return t.decrypt(e);
1474
- }, Nr = new St(), Pr = /* @__PURE__ */ new Set(), Fr = /* @__PURE__ */ new Set(), Ir = "\0", Lr = process.env.VOLTRO_OBSERVE_GRAPH === "1", Rr = () => {
1474
+ }, Nr = new Ct(), Pr = /* @__PURE__ */ new Set(), Fr = /* @__PURE__ */ new Set(), Ir = "\0", Lr = process.env.VOLTRO_OBSERVE_GRAPH === "1", Rr = () => {
1475
1475
  Lr = !0;
1476
1476
  }, zr = () => Lr, Br = (e, t) => Lr ? (Fr.add(e.tag), Nr.run(e, t)) : t(), Vr = (e, t) => {
1477
1477
  if (!Lr) return;
@@ -1514,16 +1514,16 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1514
1514
  t.transactional = (t) => n.call(e, (e) => t(Wr(e)));
1515
1515
  }
1516
1516
  return t;
1517
- }, Gr = class extends z.TaggedError()("NoRowFound", {
1518
- table: z.String,
1519
- found: z.Number
1517
+ }, Gr = class extends R.TaggedError()("NoRowFound", {
1518
+ table: R.String,
1519
+ found: R.Number
1520
1520
  }) {
1521
1521
  get message() {
1522
1522
  return this.found === 0 ? `expected exactly one row in '${this.table}', found none` : `expected exactly one row in '${this.table}', found more than one`;
1523
1523
  }
1524
- }, Kr = class extends z.TaggedError()("OptimisticLockError", {
1525
- table: z.String,
1526
- expected: z.Number
1524
+ }, Kr = class extends R.TaggedError()("OptimisticLockError", {
1525
+ table: R.String,
1526
+ expected: R.Number
1527
1527
  }) {
1528
1528
  get message() {
1529
1529
  return `optimistic lock failed on '${this.table}': expected version ${this.expected}`;
@@ -1713,19 +1713,19 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1713
1713
  select: (n) => new Xr(e, t, n, Yr(n)),
1714
1714
  updateWhere: (n) => new Zr(e, t, n),
1715
1715
  deleteWhere: (n) => new Qr(e, t, n)
1716
- }), ei = class extends z.TaggedError()("TenantScopeViolation", {
1717
- table: z.String,
1718
- reason: z.String
1719
- }) {}, ti = class extends z.TaggedError()("StoreOperationFailed", {
1720
- operation: z.String,
1721
- table: z.String,
1722
- cause: z.String
1723
- }) {}, ni = class extends z.TaggedError()("TableValidationFailed", {
1724
- table: z.String,
1725
- summary: z.String,
1726
- issues: z.Array(z.Struct({
1727
- path: z.String,
1728
- message: z.String
1716
+ }), ei = class extends R.TaggedError()("TenantScopeViolation", {
1717
+ table: R.String,
1718
+ reason: R.String
1719
+ }) {}, ti = class extends R.TaggedError()("StoreOperationFailed", {
1720
+ operation: R.String,
1721
+ table: R.String,
1722
+ cause: R.String
1723
+ }) {}, ni = class extends R.TaggedError()("TableValidationFailed", {
1724
+ table: R.String,
1725
+ summary: R.String,
1726
+ issues: R.Array(R.Struct({
1727
+ path: R.String,
1728
+ message: R.String
1729
1729
  }))
1730
1730
  }) {}, ri = "id", ii = (e) => "descriptor" in e ? e.descriptor : e, ai = (e, t) => {
1731
1731
  let n = {};
@@ -1769,8 +1769,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1769
1769
  try {
1770
1770
  return await r();
1771
1771
  } catch (n) {
1772
- let r = an(n);
1773
- if (on(r)) {
1772
+ let r = on(n);
1773
+ if (sn(r)) {
1774
1774
  let n = t.tenantId, i = `${r.dbConstraint ?? ""} ${r.dbColumn ?? ""} ${r.dbMessage ?? ""} ${r.dbCauseChain ?? ""}`.toLowerCase();
1775
1775
  if (i.includes("tenantid") || /\btenants\b/.test(i) || n != null && i.includes(String(n).toLowerCase())) throw new ei({
1776
1776
  table: e,
@@ -1791,9 +1791,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1791
1791
  }, _ = (e, t) => {
1792
1792
  let r = n.schemaRegistry.validatePatchSchema(e);
1793
1793
  if (r === void 0) return t;
1794
- let i = z.decodeUnknownEither(r)(t);
1794
+ let i = R.decodeUnknownEither(r)(t);
1795
1795
  if (i._tag === "Right") return t;
1796
- let a = Ct.formatErrorSync(i.left).map((e) => ({
1796
+ let a = wt.formatErrorSync(i.left).map((e) => ({
1797
1797
  path: e.path.length === 0 ? "<root>" : e.path.join("."),
1798
1798
  message: e.message
1799
1799
  })), o = a[0];
@@ -1830,9 +1830,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
1830
1830
  }
1831
1831
  let i = n.schemaRegistry.insertSchema(e);
1832
1832
  if (i === void 0) return t;
1833
- let a = z.decodeUnknownEither(i)(t);
1833
+ let a = R.decodeUnknownEither(i)(t);
1834
1834
  if (a._tag === "Right") return t;
1835
- let o = Ct.formatErrorSync(a.left).map((e) => ({
1835
+ let o = wt.formatErrorSync(a.left).map((e) => ({
1836
1836
  path: e.path.length === 0 ? "<root>" : e.path.join("."),
1837
1837
  message: e.message
1838
1838
  })), s = o[0];
@@ -2194,7 +2194,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2194
2194
  return o.size;
2195
2195
  }
2196
2196
  };
2197
- }, hi = M({ scope: "voltro:replication" }), gi = new St(), _i = (e, t) => gi.run(e, t), vi = () => gi.getStore(), yi = class {
2197
+ }, hi = M({ scope: "voltro:replication" }), gi = new Ct(), _i = (e, t) => gi.run(e, t), vi = () => gi.getStore(), yi = class {
2198
2198
  primary;
2199
2199
  replicas;
2200
2200
  adapter;
@@ -2431,36 +2431,36 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2431
2431
  }, Si = (e, t) => {
2432
2432
  let n = xi(e);
2433
2433
  return n === void 0 ? t() : Br(n, t);
2434
- }, Ci = (e, t) => F.async((n) => {
2435
- let r = ue(t, () => F.runFork(e));
2434
+ }, Ci = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, wi = (e, t) => P.async((n) => {
2435
+ let r = ue(t, () => P.runFork(e));
2436
2436
  return r.addObserver((e) => {
2437
2437
  n(e);
2438
- }), F.asVoid(et.interrupt(r));
2439
- }), wi = (e, t, n) => ({
2438
+ }), P.asVoid(tt.interrupt(r));
2439
+ }), Ti = (e, t, n) => ({
2440
2440
  subject: e,
2441
2441
  traceId: t?.traceId ?? xe(),
2442
2442
  ...t?.spanId === void 0 ? {} : { spanId: t.spanId },
2443
2443
  ...n === void 0 ? {} : { clientId: n }
2444
- }), Ti = F.currentSpan.pipe(F.catchAll(() => F.succeed(void 0))), Ei = (e) => ({
2444
+ }), Ei = P.currentSpan.pipe(P.catchAll(() => P.succeed(void 0))), Di = (e) => ({
2445
2445
  traceId: e.traceId,
2446
2446
  ...e.spanId === void 0 ? {} : { spanId: e.spanId }
2447
- }), Di = (e, t, n) => {
2447
+ }), Oi = (e, t, n) => {
2448
2448
  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));
2449
- }, Oi = (e) => {
2449
+ }, ki = (e) => {
2450
2450
  if (Gn() !== void 0) return async () => {
2451
- let t = await F.runPromise(F.either(qn(e, (e) => {
2451
+ let t = await P.runPromise(P.either(qn(e, (e) => {
2452
2452
  console.error("[voltro] row filter failed to load — subscription", e);
2453
2453
  })));
2454
2454
  if (t._tag === "Left") throw t.left;
2455
2455
  return t.right;
2456
2456
  };
2457
- }, ki = (e, t, n, r, i, a, o, s) => B.asyncScoped((c) => F.gen(function* () {
2458
- let l = yield* F.tryPromise(() => t.subscribe(e, (e) => {
2457
+ }, Ai = (e, t, n, r, i, a, o, s) => z.asyncScoped((c) => P.gen(function* () {
2458
+ let l = yield* P.tryPromise(() => t.subscribe(e, (e) => {
2459
2459
  c.single(e);
2460
- }, n, r, i, a, o, s)).pipe(F.matchCause({
2461
- onFailure: (e) => (Ri(`subscription.${i}`, n.traceId, e), {
2460
+ }, n, r, i, a, o, s)).pipe(P.matchCause({
2461
+ onFailure: (e) => (zi(`subscription.${i}`, n.traceId, e), {
2462
2462
  ok: !1,
2463
- error: Hi(e)
2463
+ error: Ui(e)
2464
2464
  }),
2465
2465
  onSuccess: (e) => ({
2466
2466
  ok: !0,
@@ -2475,26 +2475,26 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2475
2475
  return;
2476
2476
  }
2477
2477
  let u = l.unsubscribe;
2478
- if (yield* F.addFinalizer(() => F.sync(() => u())), n.clientId !== void 0) {
2478
+ if (yield* P.addFinalizer(() => P.sync(() => u())), n.clientId !== void 0) {
2479
2479
  let e = pr(n.clientId, () => {
2480
2480
  c.end();
2481
2481
  });
2482
- yield* F.addFinalizer(() => F.sync(() => e()));
2483
- }
2484
- })), Ai = /* @__PURE__ */ new Set(), ji = () => {
2485
- Ai.clear();
2486
- }, Mi = (e) => {
2487
- Ai.has(e) || (Ai.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`));
2488
- }, Ni = (e, t, n, r) => B.asyncScoped((i) => F.gen(function* () {
2489
- let a = yield* F.tryPromise(() => t.subscribeComputed(e, (e) => {
2482
+ yield* P.addFinalizer(() => P.sync(() => e()));
2483
+ }
2484
+ })), ji = /* @__PURE__ */ new Set(), Mi = () => {
2485
+ ji.clear();
2486
+ }, Ni = (e) => {
2487
+ ji.has(e) || (ji.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`));
2488
+ }, Pi = (e, t, n, r) => z.asyncScoped((i) => P.gen(function* () {
2489
+ let a = yield* P.tryPromise(() => t.subscribeComputed(e, (e) => {
2490
2490
  i.single(e._tag === "snapshot" ? {
2491
2491
  ...e,
2492
2492
  computed: !0
2493
2493
  } : e);
2494
- }, n, r)).pipe(F.matchCause({
2495
- onFailure: (e) => (Ri(`subscription.${r}`, n.traceId, e), {
2494
+ }, n, r)).pipe(P.matchCause({
2495
+ onFailure: (e) => (zi(`subscription.${r}`, n.traceId, e), {
2496
2496
  ok: !1,
2497
- error: Hi(e)
2497
+ error: Ui(e)
2498
2498
  }),
2499
2499
  onSuccess: (e) => ({
2500
2500
  ok: !0,
@@ -2509,22 +2509,22 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2509
2509
  return;
2510
2510
  }
2511
2511
  let o = a.unsubscribe;
2512
- if (yield* F.addFinalizer(() => F.sync(() => o())), n.clientId !== void 0) {
2512
+ if (yield* P.addFinalizer(() => P.sync(() => o())), n.clientId !== void 0) {
2513
2513
  let e = pr(n.clientId, () => {
2514
2514
  i.end();
2515
2515
  });
2516
- yield* F.addFinalizer(() => F.sync(() => e()));
2516
+ yield* P.addFinalizer(() => P.sync(() => e()));
2517
2517
  }
2518
- })), Pi = (e, t, n = "rpc.subscription", r, i, a, o) => B.unwrap(F.gen(function* () {
2519
- let s = yield* Ne, c = yield* Oe, l = yield* Ti;
2520
- Di(l, n, s);
2521
- let u = wi(s, l, c.clientId), d = pi(s.id, c.clientId), f = _i({ subjectKey: d }, () => Cr({
2518
+ })), Fi = (e, t, n = "rpc.subscription", r, i, a, o) => z.unwrap(P.gen(function* () {
2519
+ let s = yield* Ne, c = yield* Oe, l = yield* Ei;
2520
+ Oi(l, n, s);
2521
+ let u = Ti(s, l, c.clientId), d = pi(s.id, c.clientId), f = _i({ subjectKey: d }, () => Cr({
2522
2522
  traceId: u.traceId,
2523
2523
  ...u.spanId === void 0 ? {} : { spanId: u.spanId }
2524
- }, () => Si(n, () => e(u)))), p = F.isEffect(f) ? yield* f.pipe(F.matchCause({
2525
- onFailure: (e) => (Ri(`subscription.${n}`, u.traceId, e), {
2524
+ }, () => Si(n, () => e(u)))), p = P.isEffect(f) ? yield* f.pipe(P.matchCause({
2525
+ onFailure: (e) => (zi(`subscription.${n}`, u.traceId, e), {
2526
2526
  ok: !1,
2527
- error: Hi(e)
2527
+ error: Ui(e)
2528
2528
  }),
2529
2529
  onSuccess: (e) => ({
2530
2530
  ok: !0,
@@ -2534,49 +2534,49 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2534
2534
  ok: !0,
2535
2535
  value: f
2536
2536
  };
2537
- if (!p.ok) return B.make({
2537
+ if (!p.ok) return z.make({
2538
2538
  _tag: "error",
2539
2539
  error: p.error
2540
2540
  });
2541
2541
  let m = p.value;
2542
- if (rr(m)) return i !== void 0 && Mi(n), Ni(m, t, u, n);
2543
- let h = m, g = r?.(h);
2544
- return ki(h, t, u, g, n, i === void 0 ? void 0 : {
2545
- key: i.scope === "subject" ? `${i.baseKey}:s:${d}` : `${i.baseKey}:global`,
2542
+ if (rr(m)) return i !== void 0 && Ni(n), Pi(m, t, u, n);
2543
+ let h = m, g = r?.(h), _ = i === void 0 ? void 0 : Ci(i.scope, i.baseKey, d, s);
2544
+ return Ai(h, t, u, g, n, i === void 0 || _ === void 0 ? void 0 : {
2545
+ key: _,
2546
2546
  ttlMs: i.ttlMs,
2547
2547
  swrMs: i.swrMs
2548
- }, a?.(s), o?.(s) ?? Oi(s));
2549
- }).pipe(F.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), Fi = (e, t = "rpc.stream") => B.unwrap(F.gen(function* () {
2550
- let n = yield* Ne, r = yield* Oe, i = yield* Ti;
2551
- Di(i, t, n);
2552
- let a = wi(n, i, r.clientId), o = Si(t, () => e(a)), s = F.isEffect(o) ? yield* o.pipe(F.orDie) : o;
2548
+ }, a?.(s), o?.(s) ?? ki(s));
2549
+ }).pipe(P.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), Ii = (e, t = "rpc.stream") => z.unwrap(P.gen(function* () {
2550
+ let n = yield* Ne, r = yield* Oe, i = yield* Ei;
2551
+ Oi(i, t, n);
2552
+ let a = Ti(n, i, r.clientId), o = Si(t, () => e(a)), s = P.isEffect(o) ? yield* o.pipe(P.orDie) : o;
2553
2553
  if (a.clientId === void 0) return s;
2554
2554
  let c = a.clientId;
2555
- return B.unwrapScoped(F.gen(function* () {
2556
- let e = yield* Xe.make(), t = pr(c, () => {
2557
- Xe.unsafeDone(e, F.void);
2555
+ return z.unwrapScoped(P.gen(function* () {
2556
+ let e = yield* Ze.make(), t = pr(c, () => {
2557
+ Ze.unsafeDone(e, P.void);
2558
2558
  });
2559
- return yield* F.addFinalizer(() => F.sync(() => t())), s.pipe(B.interruptWhen(Xe.await(e)));
2559
+ return yield* P.addFinalizer(() => P.sync(() => t())), s.pipe(z.interruptWhen(Ze.await(e)));
2560
2560
  }));
2561
- }).pipe(F.withSpan(t, { attributes: { "framework.kind": "stream" } }))), Ii = M({ scope: "voltro:rpc" }), Li = M({ scope: "voltro:http" }), Ri = (e, t, n) => {
2561
+ }).pipe(P.withSpan(t, { attributes: { "framework.kind": "stream" } }))), Li = M({ scope: "voltro:rpc" }), Ri = M({ scope: "voltro:http" }), zi = (e, t, n) => {
2562
2562
  if (N.isInterruptedOnly(n)) return;
2563
- let r = N.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = N.dieOption(n)._tag === "Some", s = an(r), c = {
2563
+ let r = N.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = N.dieOption(n)._tag === "Some", s = on(r), c = {
2564
2564
  traceId: t,
2565
2565
  ...i === void 0 ? {} : { errorTag: i },
2566
2566
  ...s
2567
2567
  }, l = a === "Failed to execute statement" && typeof s.dbMessage == "string" ? s.dbMessage : a;
2568
- o ? Ii.error(`${e} failed: ${l}`, c) : Ii.warn(`${e} failed: ${l}`, c);
2569
- }, zi = /* @__PURE__ */ new Set([
2568
+ o ? Li.error(`${e} failed: ${l}`, c) : Li.warn(`${e} failed: ${l}`, c);
2569
+ }, Bi = /* @__PURE__ */ new Set([
2570
2570
  "SqlError",
2571
2571
  "ResultLengthMismatch",
2572
2572
  "FieldDecryptionError"
2573
- ]), Bi = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && zi.has(e._tag), Vi = (e) => ({
2573
+ ]), Vi = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && Bi.has(e._tag), Hi = (e) => ({
2574
2574
  _tag: "InternalError",
2575
2575
  message: "internal server error",
2576
2576
  traceId: e
2577
- }), Hi = (e) => {
2577
+ }), Ui = (e) => {
2578
2578
  let t = N.squash(e);
2579
- if (t && typeof t == "object" && t._tag === "UnknownException" && (t = t.error ?? t.cause ?? t), Bi(t)) return {
2579
+ if (t && typeof t == "object" && t._tag === "UnknownException" && (t = t.error ?? t.cause ?? t), Vi(t)) return {
2580
2580
  _tag: "InternalError",
2581
2581
  message: "internal server error"
2582
2582
  };
@@ -2588,46 +2588,47 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2588
2588
  ...typeof i == "string" ? { _tag: i } : {},
2589
2589
  message: typeof a == "string" ? a : String(t)
2590
2590
  };
2591
- }, Ui = (e, t, n = "rpc.mutation") => F.gen(function* () {
2592
- let r = yield* Ne, i = yield* Oe, a = yield* Ti;
2593
- Di(a, n, r);
2594
- let o = wi(r, a, i.clientId), s = pi(r.id, i.clientId), c = {
2591
+ }, Wi = (e, t, n = "rpc.mutation") => P.gen(function* () {
2592
+ let r = yield* Ne, i = yield* Oe, a = yield* Ei;
2593
+ Oi(a, n, r);
2594
+ let o = Ti(r, a, i.clientId), s = pi(r.id, i.clientId), c = {
2595
2595
  traceId: o.traceId,
2596
- subjectId: ci(r)
2596
+ subjectId: ci(r),
2597
+ procedure: n
2597
2598
  }, l = _i({ subjectKey: s }, () => Cr({
2598
2599
  traceId: o.traceId,
2599
2600
  ...o.spanId === void 0 ? {} : { spanId: o.spanId }
2600
2601
  }, () => ue(c, () => Si(n, () => e(t, o)))));
2601
- return yield* (F.isEffect(l) ? Ci(l, c) : F.tryPromise({
2602
+ return yield* (P.isEffect(l) ? wi(l, c) : P.tryPromise({
2602
2603
  try: () => Promise.resolve(l),
2603
2604
  catch: (e) => e
2604
- })).pipe(F.tapErrorCause((e) => F.sync(() => Ri(n, o.traceId, e))), F.catchIf(Bi, () => F.die(Vi(o.traceId))), F.annotateLogs(Ei(o)));
2605
- }).pipe(F.withSpan(n, { attributes: { "framework.kind": "mutation" } })), Wi = 8 * 1024 * 1024, Gi = (e) => {
2606
- let t = e.port ?? 4e3, n = e.path ?? "/ws", r = ct(), i = (t) => ft.HttpServerRequest.pipe(F.flatMap((t) => F.gen(function* () {
2607
- if (!e.inspectRoute) return H.text("inspect route not configured", { status: 404 });
2605
+ })).pipe(P.tapErrorCause((e) => P.sync(() => zi(n, o.traceId, e))), P.catchIf(Vi, () => P.die(Hi(o.traceId))), P.annotateLogs(Di(o)));
2606
+ }).pipe(P.withSpan(n, { attributes: { "framework.kind": "mutation" } })), Gi = 8 * 1024 * 1024, Ki = (e) => {
2607
+ let t = e.port ?? 4e3, n = e.path ?? "/ws", r = lt(), i = (t) => pt.HttpServerRequest.pipe(P.flatMap((t) => P.gen(function* () {
2608
+ if (!e.inspectRoute) return V.text("inspect route not configured", { status: 404 });
2608
2609
  let n = {};
2609
2610
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
2610
2611
  let r;
2611
- t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(F.orElseSucceed(() => "")));
2612
- let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield* F.promise(() => i) : i;
2613
- return a === null ? H.text("inspect route not found", { status: 404 }) : H.text(a.body, {
2612
+ t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(P.orElseSucceed(() => "")));
2613
+ let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield* P.promise(() => i) : i;
2614
+ return a === null ? V.text("inspect route not found", { status: 404 }) : V.text(a.body, {
2614
2615
  status: a.status,
2615
2616
  contentType: a.contentType,
2616
2617
  headers: a.headers ?? {}
2617
2618
  });
2618
- }))), a = () => ft.HttpServerRequest.pipe(F.flatMap((t) => {
2619
+ }))), a = () => pt.HttpServerRequest.pipe(P.flatMap((t) => {
2619
2620
  let n = e.inspectStream;
2620
- if (!n) return F.succeed(H.text("inspect stream not configured", { status: 404 }));
2621
+ if (!n) return P.succeed(V.text("inspect stream not configured", { status: 404 }));
2621
2622
  let r = {};
2622
2623
  for (let [e, n] of Object.entries(t.headers)) n !== void 0 && (r[e.toLowerCase()] = Array.isArray(n) ? n.join(", ") : n);
2623
2624
  let i = n.corsHeaders(r.origin);
2624
- if (n.isDisabled()) return F.succeed(H.text(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }), {
2625
+ if (n.isDisabled()) return P.succeed(V.text(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }), {
2625
2626
  status: 503,
2626
2627
  contentType: "application/json; charset=utf-8",
2627
2628
  headers: i
2628
2629
  }));
2629
2630
  let a = n.authorize(r);
2630
- if (!a.ok) return F.succeed(H.text(JSON.stringify({
2631
+ if (!a.ok) return P.succeed(V.text(JSON.stringify({
2631
2632
  error: "unauthorized",
2632
2633
  reason: a.reason
2633
2634
  }), {
@@ -2639,18 +2640,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2639
2640
  if (!f || e.indexOf("event: ") !== 0) return !0;
2640
2641
  let t = e.indexOf("\n", 7);
2641
2642
  return t < 0 || f.has(e.slice(7, t).trim());
2642
- }, m = B.asyncScoped((e) => F.gen(function* () {
2643
+ }, m = z.asyncScoped((e) => P.gen(function* () {
2643
2644
  if (e.single(o.encode("retry: 5000\n\n")), !u) for (let t of n.replay()) p(t) && e.single(o.encode(t));
2644
2645
  let t = n.subscribe((t) => {
2645
2646
  p(t) && e.single(o.encode(t));
2646
2647
  }), r = setInterval(() => {
2647
2648
  e.single(o.encode(n.keepAlive()));
2648
2649
  }, s);
2649
- yield* F.addFinalizer(() => F.sync(() => {
2650
+ yield* P.addFinalizer(() => P.sync(() => {
2650
2651
  clearInterval(r), t();
2651
2652
  }));
2652
2653
  }));
2653
- return F.succeed(H.stream(m, {
2654
+ return P.succeed(V.stream(m, {
2654
2655
  status: 200,
2655
2656
  headers: {
2656
2657
  "content-type": "text/event-stream; charset=utf-8",
@@ -2660,58 +2661,58 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2660
2661
  ...i
2661
2662
  }
2662
2663
  }));
2663
- })), o = V.add("*", "/_voltro/inspect/*", ft.HttpServerRequest.pipe(F.flatMap((t) => F.gen(function* () {
2664
- if (!e.inspectRoute) return H.text("inspect route not configured", { status: 404 });
2664
+ })), o = B.add("*", "/_voltro/inspect/*", pt.HttpServerRequest.pipe(P.flatMap((t) => P.gen(function* () {
2665
+ if (!e.inspectRoute) return V.text("inspect route not configured", { status: 404 });
2665
2666
  let n = {};
2666
2667
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
2667
2668
  let r;
2668
- t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(F.orElseSucceed(() => "")));
2669
- let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield* F.promise(() => i) : i;
2670
- return a === null ? H.text("inspect route not found", { status: 404 }) : H.text(a.body, {
2669
+ t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(P.orElseSucceed(() => "")));
2670
+ let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield* P.promise(() => i) : i;
2671
+ return a === null ? V.text("inspect route not found", { status: 404 }) : V.text(a.body, {
2671
2672
  status: a.status,
2672
2673
  contentType: a.contentType,
2673
2674
  headers: a.headers ?? {}
2674
2675
  });
2675
- })))), s = I.empty;
2676
- e.inspectRoute !== void 0 && (s = e.inspectStream === void 0 ? I.mergeAll(V.add("*", "/_voltro/inspect", i(!0)), o) : I.mergeAll(V.add("GET", "/_voltro/inspect/stream", a()), V.add("*", "/_voltro/inspect", i(!0)), o));
2677
- let c = I.empty;
2676
+ })))), s = F.empty;
2677
+ e.inspectRoute !== void 0 && (s = e.inspectStream === void 0 ? F.mergeAll(B.add("*", "/_voltro/inspect", i(!0)), o) : F.mergeAll(B.add("GET", "/_voltro/inspect/stream", a()), B.add("*", "/_voltro/inspect", i(!0)), o));
2678
+ let c = F.empty;
2678
2679
  if (e.webhookRoutes !== void 0 && e.webhookRoutes.size > 0) {
2679
- let t = (e) => ft.HttpServerRequest.pipe(F.flatMap((t) => F.gen(function* () {
2680
+ let t = (e) => pt.HttpServerRequest.pipe(P.flatMap((t) => P.gen(function* () {
2680
2681
  let n = {};
2681
2682
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
2682
- let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(F.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o = xr(n.traceparent), s = yield* F.promise(() => e.handle({
2683
+ let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(P.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o = xr(n.traceparent), s = yield* P.promise(() => e.handle({
2683
2684
  method: t.method,
2684
2685
  path: a,
2685
2686
  headers: n,
2686
2687
  rawBody: i
2687
- })).pipe(F.withSpan(`webhook${a}`, {
2688
+ })).pipe(P.withSpan(`webhook${a}`, {
2688
2689
  attributes: {
2689
2690
  "framework.kind": "webhook",
2690
2691
  "http.route": a
2691
2692
  },
2692
2693
  ...o ? { parent: o } : {}
2693
2694
  }));
2694
- return H.text(s.body, {
2695
+ return V.text(s.body, {
2695
2696
  status: s.status,
2696
2697
  contentType: s.contentType
2697
2698
  });
2698
- }))), n = Array.from(e.webhookRoutes.entries()).map(([e, n]) => V.add("*", e, t(n)));
2699
- c = I.mergeAll(...n);
2699
+ }))), n = Array.from(e.webhookRoutes.entries()).map(([e, n]) => B.add("*", e, t(n)));
2700
+ c = F.mergeAll(...n);
2700
2701
  }
2701
- let l = I.empty;
2702
+ let l = F.empty;
2702
2703
  if (e.httpRoutes !== void 0 && e.httpRoutes.length > 0) {
2703
- let t = (t) => ft.HttpServerRequest.pipe(F.flatMap((n) => F.gen(function* () {
2704
+ let t = (t) => pt.HttpServerRequest.pipe(P.flatMap((n) => P.gen(function* () {
2704
2705
  let r = {};
2705
2706
  for (let [e, t] of Object.entries(n.headers)) t !== void 0 && (r[e.toLowerCase()] = Array.isArray(t) ? t.join(", ") : t);
2706
- let i = n.url.indexOf("?"), a = i >= 0 ? n.url.slice(0, i) : n.url, o = i >= 0 ? n.url.slice(i + 1) : "", s = n.method !== "GET" && n.method !== "HEAD" ? new Uint8Array(yield* n.arrayBuffer.pipe(F.orElseSucceed(() => /* @__PURE__ */ new ArrayBuffer(0)))) : /* @__PURE__ */ new Uint8Array(), c = e.getStore?.(), l = {
2707
+ let i = n.url.indexOf("?"), a = i >= 0 ? n.url.slice(0, i) : n.url, o = i >= 0 ? n.url.slice(i + 1) : "", s = n.method !== "GET" && n.method !== "HEAD" ? new Uint8Array(yield* n.arrayBuffer.pipe(P.orElseSucceed(() => /* @__PURE__ */ new ArrayBuffer(0)))) : /* @__PURE__ */ new Uint8Array(), c = e.getStore?.(), l = {
2707
2708
  method: n.method,
2708
2709
  path: a,
2709
2710
  query: o,
2710
2711
  headers: r,
2711
2712
  rawBody: s,
2712
2713
  ...c === void 0 ? {} : { store: c }
2713
- }, u = yield* F.promise(() => yt(t, l));
2714
- u.status >= 500 && Li.warn(`${n.method} ${a} → ${u.status}`, {
2714
+ }, u = yield* P.promise(() => bt(t, l));
2715
+ u.status >= 500 && Ri.warn(`${n.method} ${a} → ${u.status}`, {
2715
2716
  method: n.method,
2716
2717
  path: a,
2717
2718
  status: u.status,
@@ -2723,18 +2724,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2723
2724
  headers: d
2724
2725
  };
2725
2726
  if (u.stream !== void 0) {
2726
- let { subscribe: e, keepAliveMs: t } = u.stream, n = new TextEncoder(), r = t ?? 15e3, i = B.asyncScoped((t) => F.gen(function* () {
2727
+ let { subscribe: e, keepAliveMs: t } = u.stream, n = new TextEncoder(), r = t ?? 15e3, i = z.asyncScoped((t) => P.gen(function* () {
2727
2728
  t.single(n.encode("retry: 5000\n\n"));
2728
2729
  let i = e((e) => {
2729
2730
  t.single(n.encode(e));
2730
2731
  }), a = r > 0 ? setInterval(() => {
2731
2732
  t.single(n.encode(": keep-alive\n\n"));
2732
2733
  }, r) : void 0;
2733
- yield* F.addFinalizer(() => F.sync(() => {
2734
+ yield* P.addFinalizer(() => P.sync(() => {
2734
2735
  a !== void 0 && clearInterval(a), i();
2735
2736
  }));
2736
2737
  }));
2737
- return H.stream(i, {
2738
+ return V.stream(i, {
2738
2739
  status: u.status,
2739
2740
  headers: {
2740
2741
  ...d,
@@ -2745,45 +2746,45 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2745
2746
  }
2746
2747
  });
2747
2748
  }
2748
- return u.body instanceof Uint8Array ? H.uint8Array(u.body, f) : H.text(u.body ?? "", f);
2749
- })), F.tapErrorCause((e) => N.isInterruptedOnly(e) ? F.void : F.sync(() => Li.error(`${t.map((e) => e.method).join("|")} ${t[0].path} threw`, { path: t[0].path }, N.squash(e))))), n = /* @__PURE__ */ new Map();
2749
+ return u.body instanceof Uint8Array ? V.uint8Array(u.body, f) : V.text(u.body ?? "", f);
2750
+ })), P.tapErrorCause((e) => N.isInterruptedOnly(e) ? P.void : P.sync(() => Ri.error(`${t.map((e) => e.method).join("|")} ${t[0].path} threw`, { path: t[0].path }, N.squash(e))))), n = /* @__PURE__ */ new Map();
2750
2751
  for (let t of e.httpRoutes) {
2751
2752
  let e = n.get(t.path);
2752
2753
  e ? e.push(t) : n.set(t.path, [t]);
2753
2754
  }
2754
2755
  let r = [...n.entries()].flatMap(([e, n]) => {
2755
2756
  let r = n.length === 1 ? n[0].method : "*", i = t(n);
2756
- return [V.add(r, e, i), V.add(r, `${e}/*`, i)];
2757
+ return [B.add(r, e, i), B.add(r, `${e}/*`, i)];
2757
2758
  });
2758
- l = I.mergeAll(...r);
2759
+ l = F.mergeAll(...r);
2759
2760
  }
2760
- let u = _t.layerProtocolWebsocketRouter({ path: n }), d = _t.layer(e.group), f = _t.layer(e.group).pipe(I.provide(_t.layerProtocolHttpRouter({ path: "/rpc" })), I.provide(gt.layerJson), I.provide(e.httpHandlersLayer ?? e.handlersLayer)), p = I.scopedDiscard(F.gen(function* () {
2761
- let e = yield* _t.Protocol;
2762
- yield* F.forkScoped(F.gen(function* () {
2761
+ let u = vt.layerProtocolWebsocketRouter({ path: n }), d = vt.layer(e.group), f = vt.layer(e.group).pipe(F.provide(vt.layerProtocolHttpRouter({ path: "/rpc" })), F.provide(_t.layerJson), F.provide(e.httpHandlersLayer ?? e.handlersLayer)), p = F.scopedDiscard(P.gen(function* () {
2762
+ let e = yield* vt.Protocol;
2763
+ yield* P.forkScoped(P.gen(function* () {
2763
2764
  let t = yield* e.disconnects.take;
2764
2765
  ur(t), mr(t);
2765
- }).pipe(F.forever));
2766
- })), m = I.mergeAll(d, p).pipe(I.provide(u), I.provide(gt.layerJson), I.provide(e.handlersLayer)), h = I.mergeAll(m, f, s, c, l), g = e.pluginHttpInterceptor, _ = e.healthCheck, v = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), y = e.maxRpcBodyBytes ?? (Number.isFinite(v) && v > 0 ? v : 8388608), b = { "cache-control": "no-store" }, x = (e) => F.gen(function* () {
2767
- let t = yield* ft.HttpServerRequest, n = {};
2766
+ }).pipe(P.forever));
2767
+ })), m = F.mergeAll(d, p).pipe(F.provide(u), F.provide(_t.layerJson), F.provide(e.handlersLayer)), h = F.mergeAll(m, f, s, c, l), g = e.pluginHttpInterceptor, _ = e.healthCheck, v = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), y = e.maxRpcBodyBytes ?? (Number.isFinite(v) && v > 0 ? v : 8388608), b = { "cache-control": "no-store" }, x = (e) => P.gen(function* () {
2768
+ let t = yield* pt.HttpServerRequest, n = {};
2768
2769
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
2769
2770
  let r = t.url.indexOf("?"), i = r === -1 ? t.url : t.url.slice(0, r);
2770
2771
  if (t.method === "POST" && i === "/rpc") {
2771
2772
  let e = n["content-length"];
2772
- if (e !== void 0 && Number(e) > y) return H.text("rpc payload too large", {
2773
+ if (e !== void 0 && Number(e) > y) return V.text("rpc payload too large", {
2773
2774
  status: 413,
2774
2775
  headers: b
2775
2776
  });
2776
2777
  }
2777
- if (_ && (i === "/internal/liveness" || i === "/internal/readiness")) return i === "/internal/liveness" ? H.text("ok", {
2778
+ if (_ && (i === "/internal/liveness" || i === "/internal/readiness")) return i === "/internal/liveness" ? V.text("ok", {
2778
2779
  status: 200,
2779
2780
  headers: b
2780
- }) : _.isReady() ? _.ping && !(yield* F.tryPromise(() => _.ping()).pipe(F.orElseSucceed(() => !1))) ? H.text("not-ready: dependency", {
2781
+ }) : _.isReady() ? _.ping && !(yield* P.tryPromise(() => _.ping()).pipe(P.orElseSucceed(() => !1))) ? V.text("not-ready: dependency", {
2781
2782
  status: 503,
2782
2783
  headers: b
2783
- }) : H.text("ready", {
2784
+ }) : V.text("ready", {
2784
2785
  status: 200,
2785
2786
  headers: b
2786
- }) : H.text("not-ready", {
2787
+ }) : V.text("not-ready", {
2787
2788
  status: 503,
2788
2789
  headers: b
2789
2790
  });
@@ -2794,36 +2795,48 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2794
2795
  } catch {
2795
2796
  s = void 0;
2796
2797
  }
2797
- let c = o ?? s, l = yield* F.tryPromise(() => g(async () => null, {
2798
+ let c = o ?? s, l = yield* P.tryPromise(() => g(async () => null, {
2798
2799
  method: t.method,
2799
2800
  path: i,
2800
2801
  headers: n,
2801
2802
  remoteAddr: c
2802
- })).pipe(F.orElseSucceed(() => null));
2803
- return l === null ? yield* e : H.text(l.body ?? "", {
2803
+ })).pipe(P.orElseSucceed(() => null));
2804
+ return l === null ? yield* e : V.text(l.body ?? "", {
2804
2805
  status: l.status,
2805
2806
  ...l.headers ? { headers: l.headers } : {}
2806
2807
  });
2807
- }), S = I.unwrapEffect(V.toHttpEffect(h).pipe(F.map((e) => dt.serve(x(e))))).pipe(I.provide(mt.layer(() => r, { port: t })), I.provide(pt.layer));
2808
- e.tracerLayer && (S = S.pipe(I.provide(e.tracerLayer)));
2809
- let C = M({ scope: "voltro:rpc" }), w = I.launch(S).pipe(F.catchAllCause((e) => F.sync(() => {
2808
+ }), S = F.unwrapEffect(B.toHttpEffect(h).pipe(P.map((e) => ft.serve(x(e))))).pipe(F.provide(ht.layer(() => r, { port: t })), F.provide(mt.layer));
2809
+ e.tracerLayer && (S = S.pipe(F.provide(e.tracerLayer)));
2810
+ let C = M({ scope: "voltro:rpc" }), w = F.launch(S).pipe(P.catchAllCause((e) => P.sync(() => {
2810
2811
  C.error("rpc server crashed", {}, N.squash(e)), process.exit(1);
2811
- }))), T = F.runFork(w);
2812
- return Ki.add(T), Ji(), {
2812
+ }))), T = P.runFork(w);
2813
+ return qi.add(T), $i(), {
2813
2814
  server: r,
2814
2815
  shutdown: async () => {
2815
- Ki.delete(T), await F.runPromise(et.interrupt(T)).then(() => void 0, () => void 0);
2816
+ qi.delete(T), await P.runPromise(tt.interrupt(T)).then(() => void 0, () => void 0);
2816
2817
  }
2817
2818
  };
2818
- }, Ki = /* @__PURE__ */ new Set(), qi = !1, Ji = () => {
2819
- if (qi) return;
2820
- qi = !0;
2819
+ }, qi = /* @__PURE__ */ new Set(), Ji = /* @__PURE__ */ new Set(), Yi = !1, Xi = (e) => (Ji.add(e), () => {
2820
+ Ji.delete(e);
2821
+ }), Zi = 1e4, Qi = (e) => {
2822
+ let t = !1, n = () => {
2823
+ t || (t = !0, clearTimeout(r), e.exit());
2824
+ }, r = setTimeout(n, e.deadlineMs);
2825
+ r.unref?.(), Promise.all(e.hooks.map((e) => Promise.resolve().then(e).then(() => void 0, () => void 0))).then(() => Promise.all(e.fibers.map((e) => P.runPromise(tt.interrupt(e)).then(() => void 0, () => void 0)))).then(n, n);
2826
+ }, $i = () => {
2827
+ if (Yi) return;
2828
+ Yi = !0;
2821
2829
  let e = () => {
2822
- let e = [...Ki];
2823
- Ki.clear(), Promise.all(e.map((e) => F.runPromise(et.interrupt(e)).then(() => void 0, () => void 0))).then(() => process.exit(0), () => process.exit(0));
2830
+ let e = [...qi], t = [...Ji];
2831
+ qi.clear(), Ji.clear(), Qi({
2832
+ fibers: e,
2833
+ hooks: t,
2834
+ deadlineMs: Zi,
2835
+ exit: () => process.exit(0)
2836
+ });
2824
2837
  };
2825
2838
  process.once("SIGINT", e), process.once("SIGTERM", e);
2826
- }, Yi = (e, t = 1e4) => new Promise((n, r) => {
2839
+ }, ea = (e, t = 1e4) => new Promise((n, r) => {
2827
2840
  if (e.listening) {
2828
2841
  n();
2829
2842
  return;
@@ -2839,13 +2852,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2839
2852
  o(e);
2840
2853
  }
2841
2854
  a = setTimeout(() => o(/* @__PURE__ */ Error(`rpc server did not bind within ${t}ms`)), t), e.on("listening", s), e.on("error", c);
2842
- }), Xi = () => {
2855
+ }), ta = () => {
2843
2856
  let e = process.env.FRAMEWORK_TRACING?.toLowerCase();
2844
2857
  return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ? "otlp" : "off";
2845
- }, Zi = () => {
2858
+ }, na = () => {
2846
2859
  let e = process.env.FRAMEWORK_METRICS?.toLowerCase();
2847
2860
  return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ? "otlp" : "off";
2848
- }, Qi = async () => {
2861
+ }, ra = async () => {
2849
2862
  let [e, t, n, r, i] = await Promise.all([
2850
2863
  import("@opentelemetry/sdk-trace-base"),
2851
2864
  import("@opentelemetry/sdk-metrics"),
@@ -2860,7 +2873,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2860
2873
  otlpMetrics: r,
2861
2874
  nodeSdk: i
2862
2875
  };
2863
- }, $i = (e, t, n) => {
2876
+ }, ia = (e, t, n) => {
2864
2877
  let { PeriodicExportingMetricReader: r, ConsoleMetricExporter: i, InMemoryMetricExporter: a, AggregationTemporality: o } = e.sdkMetrics;
2865
2878
  if (t === "off") return {
2866
2879
  reader: void 0,
@@ -2883,23 +2896,23 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2883
2896
  }),
2884
2897
  inMemory: void 0
2885
2898
  };
2886
- }, ea = async (e = {}) => {
2887
- let t = e.mode ?? Xi(), n = e.metricsMode ?? Zi(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
2899
+ }, aa = async (e = {}) => {
2900
+ let t = e.mode ?? ta(), n = e.metricsMode ?? na(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
2888
2901
  if (t === "off" && e.traceSink === void 0 && n === "off" && r.length === 0 && i.length === 0) return {
2889
- layer: I.empty,
2902
+ layer: F.empty,
2890
2903
  mode: t,
2891
2904
  bufferOnly: !1,
2892
2905
  inMemoryExporter: void 0,
2893
2906
  metricsMode: n,
2894
2907
  inMemoryMetricExporter: void 0
2895
2908
  };
2896
- let a = await Qi(), { ConsoleSpanExporter: o, InMemorySpanExporter: s, SimpleSpanProcessor: c, BatchSpanProcessor: l } = a.sdkTrace, u = t === "off", d = e.serviceName ?? process.env.OTEL_SERVICE_NAME ?? "voltro-app", f, p;
2909
+ let a = await ra(), { ConsoleSpanExporter: o, InMemorySpanExporter: s, SimpleSpanProcessor: c, BatchSpanProcessor: l } = a.sdkTrace, u = t === "off", d = e.serviceName ?? process.env.OTEL_SERVICE_NAME ?? "voltro-app", f, p;
2897
2910
  e.spanProcessor ? p = e.spanProcessor : u ? p = void 0 : t === "memory" ? (f = new s(), p = new c(f)) : p = t === "console" ? new c(new o()) : new l(new a.otlpTrace.OTLPTraceExporter());
2898
2911
  let m = [
2899
2912
  ...e.traceSink ? [e.traceSink] : [],
2900
2913
  ...p ? [p] : [],
2901
2914
  ...r
2902
- ], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = $i(a, n, e.metricExportIntervalMillis ?? (process.env.OTEL_METRIC_EXPORT_INTERVAL ? Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) : 6e4)), v = [...g ? [g] : [], ...i], y = v.length === 0 ? void 0 : v.length === 1 ? v[0] : v, b = {
2915
+ ], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = ia(a, n, e.metricExportIntervalMillis ?? (process.env.OTEL_METRIC_EXPORT_INTERVAL ? Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) : 6e4)), v = [...g ? [g] : [], ...i], y = v.length === 0 ? void 0 : v.length === 1 ? v[0] : v, b = {
2903
2916
  serviceName: d,
2904
2917
  ...e.serviceVersion ? { serviceVersion: e.serviceVersion } : {},
2905
2918
  ...e.resourceAttributes ? { attributes: e.resourceAttributes } : {}
@@ -2917,18 +2930,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2917
2930
  metricsMode: n,
2918
2931
  inMemoryMetricExporter: _
2919
2932
  };
2920
- }, ta = {
2921
- [Tt.INTERNAL]: "internal",
2922
- [Tt.SERVER]: "server",
2923
- [Tt.CLIENT]: "client",
2924
- [Tt.PRODUCER]: "producer",
2925
- [Tt.CONSUMER]: "consumer"
2926
- }, na = (e) => e[0] * 1e3 + e[1] / 1e6, ra = 512, ia = 48, aa = (e) => {
2933
+ }, oa = {
2934
+ [Et.INTERNAL]: "internal",
2935
+ [Et.SERVER]: "server",
2936
+ [Et.CLIENT]: "client",
2937
+ [Et.PRODUCER]: "producer",
2938
+ [Et.CONSUMER]: "consumer"
2939
+ }, sa = (e) => e[0] * 1e3 + e[1] / 1e6, ca = 512, la = 48, ua = (e) => {
2927
2940
  let t = {}, n = 0;
2928
2941
  for (let r in e) {
2929
- if (n >= ia) break;
2942
+ if (n >= la) break;
2930
2943
  let i = e[r];
2931
- if (typeof i == "string") t[r] = i.length > ra ? `${i.slice(0, ra)}…` : i;
2944
+ if (typeof i == "string") t[r] = i.length > ca ? `${i.slice(0, ca)}…` : i;
2932
2945
  else if (typeof i == "number" || typeof i == "boolean" || i == null) t[r] = i;
2933
2946
  else {
2934
2947
  let e;
@@ -2937,49 +2950,49 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2937
2950
  } catch {
2938
2951
  e = String(i);
2939
2952
  }
2940
- t[r] = e.length > ra ? `${e.slice(0, ra)}…` : e;
2953
+ t[r] = e.length > ca ? `${e.slice(0, ca)}…` : e;
2941
2954
  }
2942
2955
  n++;
2943
2956
  }
2944
2957
  return t;
2945
- }, oa = {
2946
- [Et.UNSET]: "unset",
2947
- [Et.OK]: "ok",
2948
- [Et.ERROR]: "error"
2949
- }, sa = (e) => {
2958
+ }, da = {
2959
+ [Dt.UNSET]: "unset",
2960
+ [Dt.OK]: "ok",
2961
+ [Dt.ERROR]: "error"
2962
+ }, fa = (e) => {
2950
2963
  let t = e.spanContext(), n = e.events.length > 0 ? e.events.slice(0, 16).map((e) => ({
2951
2964
  name: e.name,
2952
- tsMs: na(e.time),
2953
- ...e.attributes ? { attributes: aa(e.attributes) } : {}
2965
+ tsMs: sa(e.time),
2966
+ ...e.attributes ? { attributes: ua(e.attributes) } : {}
2954
2967
  })) : void 0;
2955
2968
  return {
2956
2969
  traceId: t.traceId,
2957
2970
  spanId: t.spanId,
2958
2971
  parentSpanId: e.parentSpanContext?.spanId ?? null,
2959
2972
  name: e.name,
2960
- kind: ta[e.kind] ?? "internal",
2961
- attributes: aa(e.attributes),
2962
- startMs: na(e.startTime),
2963
- endMs: na(e.endTime),
2964
- durationMs: na(e.duration),
2965
- status: oa[e.status.code] ?? "unset",
2973
+ kind: oa[e.kind] ?? "internal",
2974
+ attributes: ua(e.attributes),
2975
+ startMs: sa(e.startTime),
2976
+ endMs: sa(e.endTime),
2977
+ durationMs: sa(e.duration),
2978
+ status: da[e.status.code] ?? "unset",
2966
2979
  ...e.status.message ? { statusMessage: e.status.message } : {},
2967
2980
  ...n ? { events: n } : {}
2968
2981
  };
2969
- }, ca = (e) => ({
2982
+ }, pa = (e) => ({
2970
2983
  onStart: () => {},
2971
2984
  onEnd: (t) => {
2972
2985
  try {
2973
- e(sa(t));
2986
+ e(fa(t));
2974
2987
  } catch {}
2975
2988
  },
2976
2989
  forceFlush: () => Promise.resolve(),
2977
2990
  shutdown: () => Promise.resolve()
2978
- }), la = { get: (e) => Promise.resolve(process.env[e]) }, ua = la, da = (e) => {
2979
- ua = e;
2980
- }, fa = () => {
2981
- ua = la;
2982
- }, pa = async (e) => await ua.get(e) ?? process.env[e], ma = (e) => process.env[e], ha = (e, t = 6e4, n = () => Date.now()) => {
2991
+ }), ma = { get: (e) => Promise.resolve(process.env[e]) }, ha = ma, ga = (e) => {
2992
+ ha = e;
2993
+ }, _a = () => {
2994
+ ha = ma;
2995
+ }, va = async (e) => await ha.get(e) ?? process.env[e], ya = (e) => process.env[e], ba = (e, t = 6e4, n = () => Date.now()) => {
2983
2996
  let r = /* @__PURE__ */ new Map();
2984
2997
  return { get: async (i) => {
2985
2998
  let a = r.get(i);
@@ -2990,12 +3003,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
2990
3003
  at: n()
2991
3004
  }), o;
2992
3005
  } };
2993
- }, ga = (e) => {
3006
+ }, xa = (e) => {
2994
3007
  let t = {
2995
3008
  accept: "application/json",
2996
3009
  ...e.headers ?? {}
2997
3010
  };
2998
- if (e.perKey) return ha({ get: async (n) => {
3011
+ if (e.perKey) return ba({ get: async (n) => {
2999
3012
  let r = await fetch(`${e.url.replace(/\/$/, "")}/${encodeURIComponent(n)}`, { headers: t });
3000
3013
  if (!r.ok) return;
3001
3014
  let i = await r.json();
@@ -3006,34 +3019,34 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3006
3019
  let t = (await a())[e];
3007
3020
  return typeof t == "string" ? t : void 0;
3008
3021
  } };
3009
- }, _a = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? la : e.kind === "custom" ? e.backend : e.kind === "http" ? ga(e) : la, va = "_voltro_idempotency", ya = (e) => {
3022
+ }, Sa = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? ma : e.kind === "custom" ? e.backend : e.kind === "http" ? xa(e) : ma, Ca = "_voltro_idempotency", wa = (e) => {
3010
3023
  if (e == null) return null;
3011
3024
  let t = typeof e == "string" ? JSON.parse(e) : e;
3012
3025
  return t && typeof t == "object" && "status" in t ? t : null;
3013
- }, ba = (e) => ({
3026
+ }, Ta = (e) => ({
3014
3027
  scope: e.scope,
3015
3028
  key: e.key,
3016
3029
  status: e.status === "completed" ? "completed" : "in_flight",
3017
- response: ya(e.response),
3030
+ response: wa(e.response),
3018
3031
  createdAt: qe(e.createdAt)
3019
- }), xa = async (e, n, r) => (await e.query({
3020
- table: va,
3032
+ }), Ea = async (e, n, r) => (await e.query({
3033
+ table: Ca,
3021
3034
  predicate: t(d("scope", n), d("key", r)),
3022
3035
  order: [],
3023
3036
  take: 1,
3024
3037
  skip: void 0,
3025
3038
  projection: void 0
3026
- }))[0] ?? null, Sa = (e) => ({
3039
+ }))[0] ?? null, Da = (e) => ({
3027
3040
  get: async (t, n) => {
3028
- let r = await xa(e, t, n);
3029
- return r ? ba(r) : null;
3041
+ let r = await Ea(e, t, n);
3042
+ return r ? Ta(r) : null;
3030
3043
  },
3031
3044
  claim: async (t, n, r, i) => {
3032
3045
  for (let a = 0; a < 2; a++) {
3033
3046
  let a = p({
3034
3047
  kind: "typeid",
3035
3048
  prefix: "idem"
3036
- }, va), o = await e.insertIgnore(va, {
3049
+ }, Ca), o = await e.insertIgnore(Ca, {
3037
3050
  id: a,
3038
3051
  scope: t,
3039
3052
  key: n,
@@ -3042,11 +3055,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3042
3055
  createdAt: new Date(r)
3043
3056
  }, { conflictColumns: ["scope", "key"] });
3044
3057
  if (o.id === a) return "claimed";
3045
- if (r - qe(o.createdAt) < i) return ba(o);
3046
- await e.delete(va, o.id);
3058
+ if (r - qe(o.createdAt) < i) return Ta(o);
3059
+ await e.delete(Ca, o.id);
3047
3060
  }
3048
- let a = await xa(e, t, n);
3049
- return a ? ba(a) : {
3061
+ let a = await Ea(e, t, n);
3062
+ return a ? Ta(a) : {
3050
3063
  scope: t,
3051
3064
  key: n,
3052
3065
  status: "in_flight",
@@ -3055,36 +3068,36 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3055
3068
  };
3056
3069
  },
3057
3070
  complete: async (t, n, r, i) => {
3058
- let a = await xa(e, t, n);
3059
- a && await e.update(va, a.id, {
3071
+ let a = await Ea(e, t, n);
3072
+ a && await e.update(Ca, a.id, {
3060
3073
  status: "completed",
3061
3074
  response: r
3062
3075
  });
3063
3076
  },
3064
3077
  release: async (t, n) => {
3065
- let r = await xa(e, t, n);
3066
- r && await e.delete(va, r.id);
3078
+ let r = await Ea(e, t, n);
3079
+ r && await e.delete(Ca, r.id);
3067
3080
  }
3068
- }), J = "_voltro_kv", Ca = (e) => {
3081
+ }), J = "_voltro_kv", Oa = (e) => {
3069
3082
  if (e == null) return null;
3070
3083
  if (e instanceof Date) return e.getTime();
3071
3084
  if (typeof e == "number") return e;
3072
3085
  let t = Date.parse(String(e));
3073
3086
  return Number.isNaN(t) ? null : t;
3074
- }, wa = (e, t) => {
3075
- let n = Ca(e.expiresAt);
3087
+ }, ka = (e, t) => {
3088
+ let n = Oa(e.expiresAt);
3076
3089
  return n !== null && n <= t;
3077
- }, Ta = (e) => e === null ? null : JSON.parse(e), Ea = async (e, t) => (await e.query({
3090
+ }, Aa = (e) => e === null ? null : JSON.parse(e), ja = async (e, t) => (await e.query({
3078
3091
  table: J,
3079
3092
  predicate: d("key", t),
3080
3093
  order: [],
3081
3094
  take: 1,
3082
3095
  skip: void 0,
3083
3096
  projection: void 0
3084
- }))[0] ?? null, Da = (e) => {
3085
- let n = (e, t, n) => F.tryPromise({
3097
+ }))[0] ?? null, Ma = (e) => {
3098
+ let n = (e, t, n) => P.tryPromise({
3086
3099
  try: n,
3087
- catch: (n) => new Ot({
3100
+ catch: (n) => new kt({
3088
3101
  operation: e,
3089
3102
  key: t,
3090
3103
  cause: String(n)
@@ -3092,8 +3105,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3092
3105
  });
3093
3106
  return {
3094
3107
  get: (t) => n("get", t, async () => {
3095
- let n = await Ea(e, t);
3096
- return n === null ? it.none() : wa(n, Date.now()) ? (await e.delete(J, n.id), it.none()) : it.some(Ta(n.value));
3108
+ let n = await ja(e, t);
3109
+ return n === null ? at.none() : ka(n, Date.now()) ? (await e.delete(J, n.id), at.none()) : at.some(Aa(n.value));
3097
3110
  }),
3098
3111
  set: (t, r, i) => n("set", t, async () => {
3099
3112
  let n = Date.now(), a = i?.ttlMs !== void 0 && i.ttlMs > 0 ? new Date(n + i.ttlMs) : null, o = p({
@@ -3116,14 +3129,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3116
3129
  });
3117
3130
  }),
3118
3131
  delete: (t) => n("delete", t, async () => {
3119
- let n = await Ea(e, t);
3132
+ let n = await ja(e, t);
3120
3133
  if (n === null) return !1;
3121
- let r = !wa(n, Date.now());
3134
+ let r = !ka(n, Date.now());
3122
3135
  return await e.delete(J, n.id), r;
3123
3136
  }),
3124
3137
  has: (t) => n("has", t, async () => {
3125
- let n = await Ea(e, t);
3126
- return n === null ? !1 : wa(n, Date.now()) ? (await e.delete(J, n.id), !1) : !0;
3138
+ let n = await ja(e, t);
3139
+ return n === null ? !1 : ka(n, Date.now()) ? (await e.delete(J, n.id), !1) : !0;
3127
3140
  }),
3128
3141
  list: (r) => n("list", "", async () => {
3129
3142
  let n = Date.now(), i = ie(C("expiresAt"), g("expiresAt", new Date(n))), a = r === "" ? i : t(s("key", r), i), o = await e.query({
@@ -3134,7 +3147,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3134
3147
  skip: void 0,
3135
3148
  projection: void 0
3136
3149
  }), c = [];
3137
- for (let e of o) wa(e, n) || (r === "" || e.key.startsWith(r)) && c.push(e.key);
3150
+ for (let e of o) ka(e, n) || (r === "" || e.key.startsWith(r)) && c.push(e.key);
3138
3151
  return c;
3139
3152
  }),
3140
3153
  clear: () => n("clear", "", async () => {
@@ -3144,11 +3157,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3144
3157
  } });
3145
3158
  })
3146
3159
  };
3147
- }, Oa = async ({ store: e, env: t = process.env }) => {
3148
- let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? Mt(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(I.provide(At)) : r === "memory" ? jt() : I.succeed(kt, kt.of(Da(e))), a = tt.make(Dt.Default.pipe(I.provide(i))), o = await a.runPromise(Dt);
3160
+ }, Na = async ({ store: e, env: t = process.env }) => {
3161
+ let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? Nt(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(F.provide(jt)) : r === "memory" ? Mt() : F.succeed(At, At.of(Ma(e))), a = nt.make(Ot.Default.pipe(F.provide(i))), o = await a.runPromise(Ot);
3149
3162
  return {
3150
3163
  kv: {
3151
- get: (e) => a.runPromise(o.get(e)).then((e) => it.getOrUndefined(e)),
3164
+ get: (e) => a.runPromise(o.get(e)).then((e) => at.getOrUndefined(e)),
3152
3165
  getOrElse: (e, t) => a.runPromise(o.getOrElse(e, t)),
3153
3166
  set: (e, t, n) => a.runPromise(o.set(e, t, n)),
3154
3167
  delete: (e) => a.runPromise(o.delete(e)),
@@ -3160,7 +3173,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3160
3173
  backend: r,
3161
3174
  dispose: () => a.dispose()
3162
3175
  };
3163
- }, ka = {
3176
+ }, Pa = {
3164
3177
  get: () => Promise.resolve(void 0),
3165
3178
  getOrElse: (e, t) => Promise.resolve(t()),
3166
3179
  set: () => Promise.resolve(),
@@ -3168,7 +3181,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3168
3181
  has: () => Promise.resolve(!1),
3169
3182
  list: () => Promise.resolve([]),
3170
3183
  clear: () => Promise.resolve()
3171
- }, Aa = "_voltro_api_keys", ja = (e) => ye("sha256").update(e, "utf8").digest("hex"), Ma = (e = "voltro_") => `${e}${be(30).toString("base64url")}`, Na = (e) => ({
3184
+ }, Fa = "_voltro_api_keys", Ia = (e) => ye("sha256").update(e, "utf8").digest("hex"), La = (e = "voltro_") => `${e}${be(30).toString("base64url")}`, Ra = (e) => ({
3172
3185
  id: e.id,
3173
3186
  name: e.name,
3174
3187
  keyPrefix: e.keyPrefix,
@@ -3181,18 +3194,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3181
3194
  createdBy: e.createdBy ?? null,
3182
3195
  onBehalfOf: e.onBehalfOf ?? null,
3183
3196
  ...e.metadata == null ? {} : { metadata: e.metadata }
3184
- }), Pa = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), Fa = (e, t = {}) => {
3197
+ }), za = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), Ba = (e, t = {}) => {
3185
3198
  let n = t.prefix ?? "voltro_", r = t.usage, i = async (t) => {
3186
- let r = Ma(n), i = p({
3199
+ let r = La(n), i = p({
3187
3200
  kind: "typeid",
3188
3201
  prefix: "apikey"
3189
- }, Aa), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
3202
+ }, Fa), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
3190
3203
  return await e.insert({
3191
3204
  id: i,
3192
3205
  tenantId: t.tenantId ?? null,
3193
3206
  name: t.name,
3194
3207
  onBehalfOf: t.onBehalfOf ?? null,
3195
- hashedKey: ja(r),
3208
+ hashedKey: Ia(r),
3196
3209
  keyPrefix: r.slice(0, n.length + 6),
3197
3210
  scopes: a,
3198
3211
  lastUsedAt: null,
@@ -3211,7 +3224,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3211
3224
  };
3212
3225
  }, a = async (t, n = Date.now()) => {
3213
3226
  let i = await e.findByHash(t);
3214
- return !i || !Pa(i, n) ? null : (r === void 0 ? await e.patch(i.id, { lastUsedAt: n }) : r.touch(i.id, n), {
3227
+ return !i || !za(i, n) ? null : (r === void 0 ? await e.patch(i.id, { lastUsedAt: n }) : r.touch(i.id, n), {
3215
3228
  id: i.id,
3216
3229
  tenantId: i.tenantId ?? "",
3217
3230
  createdBy: i.createdBy ?? null,
@@ -3223,7 +3236,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3223
3236
  return {
3224
3237
  issue: i,
3225
3238
  resolveByHash: a,
3226
- verify: (e, t) => a(ja(e), t),
3239
+ verify: (e, t) => a(Ia(e), t),
3227
3240
  revoke: async (t, n, r = Date.now()) => {
3228
3241
  let i = await e.findById(t);
3229
3242
  return !i || (i.tenantId ?? null) !== n ? !1 : (await e.patch(t, { revokedAt: r }), !0);
@@ -3239,9 +3252,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3239
3252
  ...a.metadata == null ? {} : { metadata: a.metadata }
3240
3253
  }));
3241
3254
  },
3242
- list: async (t) => (await e.listByTenant(t)).map(Na)
3255
+ list: async (t) => (await e.listByTenant(t)).map(Ra)
3243
3256
  };
3244
- }, Ia = () => {
3257
+ }, Va = () => {
3245
3258
  let e = /* @__PURE__ */ new Map();
3246
3259
  return {
3247
3260
  insert: async (t) => {
@@ -3258,21 +3271,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3258
3271
  });
3259
3272
  }
3260
3273
  };
3261
- }, La = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, Ra = (e) => ({
3274
+ }, Ha = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, Ua = (e) => ({
3262
3275
  id: String(e.id),
3263
3276
  tenantId: e.tenantId ?? null,
3264
3277
  name: String(e.name),
3265
3278
  hashedKey: String(e.hashedKey),
3266
3279
  keyPrefix: String(e.keyPrefix),
3267
3280
  scopes: e.scopes ?? null,
3268
- lastUsedAt: La(e.lastUsedAt),
3269
- expiresAt: La(e.expiresAt),
3270
- revokedAt: La(e.revokedAt),
3281
+ lastUsedAt: Ha(e.lastUsedAt),
3282
+ expiresAt: Ha(e.expiresAt),
3283
+ revokedAt: Ha(e.revokedAt),
3271
3284
  createdBy: e.createdBy ?? null,
3272
3285
  onBehalfOf: e.onBehalfOf ?? null,
3273
- createdAt: La(e.createdAt) ?? 0,
3286
+ createdAt: Ha(e.createdAt) ?? 0,
3274
3287
  ...e.metadata == null ? {} : { metadata: e.metadata }
3275
- }), za = (e) => async (t, n) => {
3288
+ }), Wa = (e) => async (t, n) => {
3276
3289
  let r = await e.findById(t);
3277
3290
  if (r === null) return;
3278
3291
  let i = r.requestCount ?? 0, a = r.lastUsedAt ?? 0;
@@ -3280,9 +3293,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3280
3293
  requestCount: i + n.requests,
3281
3294
  lastUsedAt: Math.max(a, n.lastUsedAt)
3282
3295
  });
3283
- }, Ba = (e) => {
3296
+ }, Ga = (e) => {
3284
3297
  let t = async (t) => await e.query({
3285
- table: Aa,
3298
+ table: Fa,
3286
3299
  predicate: t,
3287
3300
  order: [],
3288
3301
  take: void 0,
@@ -3300,74 +3313,74 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3300
3313
  };
3301
3314
  return {
3302
3315
  insert: async (t) => {
3303
- await e.insert(Aa, n(t));
3316
+ await e.insert(Fa, n(t));
3304
3317
  },
3305
3318
  findByHash: async (e) => {
3306
3319
  let n = await t(d("hashedKey", e));
3307
- return n[0] ? Ra(n[0]) : null;
3320
+ return n[0] ? Ua(n[0]) : null;
3308
3321
  },
3309
3322
  findById: async (e) => {
3310
3323
  let n = await t(d("id", e));
3311
- return n[0] ? Ra(n[0]) : null;
3324
+ return n[0] ? Ua(n[0]) : null;
3312
3325
  },
3313
- listByTenant: async (e) => (await t(e === null ? void 0 : d("tenantId", e))).map(Ra).filter((t) => e === null || t.tenantId === e),
3326
+ listByTenant: async (e) => (await t(e === null ? void 0 : d("tenantId", e))).map(Ua).filter((t) => e === null || t.tenantId === e),
3314
3327
  patch: async (t, r) => {
3315
- await e.update(Aa, t, n(r));
3328
+ await e.update(Fa, t, n(r));
3316
3329
  }
3317
3330
  };
3318
- }, Va = (e, t = {}) => Nt({
3331
+ }, Ka = (e, t = {}) => Pt({
3319
3332
  id: "voltro-apikey",
3320
3333
  ...t.prefix ? { prefix: t.prefix } : {},
3321
3334
  resolveKey: (t) => e.resolveByHash(t)
3322
- }), Ha = (e) => {
3335
+ }), qa = (e) => {
3323
3336
  let t = e.subject;
3324
3337
  return {
3325
3338
  id: t.id ?? null,
3326
3339
  tenantId: t.tenantId ?? null,
3327
3340
  scopes: t.scopes ?? []
3328
3341
  };
3329
- }, Ua = (e, t = "/v1/api-keys") => {
3330
- let n = z.Struct({
3331
- id: z.String,
3332
- name: z.String,
3333
- keyPrefix: z.String,
3334
- tenantId: z.NullOr(z.String),
3335
- scopes: z.Array(z.String),
3336
- lastUsedAt: z.NullOr(z.Number),
3337
- expiresAt: z.NullOr(z.Number),
3338
- revokedAt: z.NullOr(z.Number),
3339
- createdAt: z.Number,
3340
- createdBy: z.NullOr(z.String),
3341
- onBehalfOf: z.NullOr(z.String),
3342
- metadata: z.optional(z.NullOr(z.Record({
3343
- key: z.String,
3344
- value: z.Unknown
3342
+ }, Ja = (e, t = "/v1/api-keys") => {
3343
+ let n = R.Struct({
3344
+ id: R.String,
3345
+ name: R.String,
3346
+ keyPrefix: R.String,
3347
+ tenantId: R.NullOr(R.String),
3348
+ scopes: R.Array(R.String),
3349
+ lastUsedAt: R.NullOr(R.Number),
3350
+ expiresAt: R.NullOr(R.Number),
3351
+ revokedAt: R.NullOr(R.Number),
3352
+ createdAt: R.Number,
3353
+ createdBy: R.NullOr(R.String),
3354
+ onBehalfOf: R.NullOr(R.String),
3355
+ metadata: R.optional(R.NullOr(R.Record({
3356
+ key: R.String,
3357
+ value: R.Unknown
3345
3358
  })))
3346
3359
  });
3347
3360
  return [
3348
- vt({
3361
+ yt({
3349
3362
  method: "POST",
3350
3363
  path: `${t}/issue`,
3351
3364
  summary: "Issue an API key (the token is returned ONCE).",
3352
- guards: [bt([
3365
+ guards: [xt([
3353
3366
  we,
3354
3367
  De,
3355
3368
  Te,
3356
3369
  Ee
3357
3370
  ])],
3358
- input: z.Struct({ body: z.Struct({
3359
- name: z.String,
3360
- scopes: z.optional(z.Array(z.String)),
3361
- expiresInDays: z.optional(z.Number),
3362
- onBehalfOf: z.optional(z.NullOr(z.String))
3371
+ input: R.Struct({ body: R.Struct({
3372
+ name: R.String,
3373
+ scopes: R.optional(R.Array(R.String)),
3374
+ expiresInDays: R.optional(R.Number),
3375
+ onBehalfOf: R.optional(R.NullOr(R.String))
3363
3376
  }) }),
3364
- output: z.Struct({
3365
- id: z.String,
3366
- token: z.String,
3367
- keyPrefix: z.String
3377
+ output: R.Struct({
3378
+ id: R.String,
3379
+ token: R.String,
3380
+ keyPrefix: R.String
3368
3381
  }),
3369
3382
  handler: async (t, n) => {
3370
- let r = t.body, i = Ha(n), a = new Set(i.scopes), o = (e) => a.has(we) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
3383
+ let r = t.body, i = qa(n), a = new Set(i.scopes), o = (e) => a.has(we) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
3371
3384
  if (s === null) {
3372
3385
  if (!o(Te)) throw new Me({
3373
3386
  required: Te,
@@ -3405,58 +3418,58 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3405
3418
  };
3406
3419
  }
3407
3420
  }),
3408
- vt({
3421
+ yt({
3409
3422
  method: "GET",
3410
3423
  path: t,
3411
3424
  summary: "List the caller tenant's API keys (no secrets).",
3412
- guards: [xt(we)],
3413
- input: z.Struct({}),
3414
- output: z.Struct({ keys: z.Array(n) }),
3415
- handler: async (t, n) => ({ keys: [...await e.list(Ha(n).tenantId)] })
3425
+ guards: [St(we)],
3426
+ input: R.Struct({}),
3427
+ output: R.Struct({ keys: R.Array(n) }),
3428
+ handler: async (t, n) => ({ keys: [...await e.list(qa(n).tenantId)] })
3416
3429
  }),
3417
- vt({
3430
+ yt({
3418
3431
  method: "POST",
3419
3432
  path: `${t}/revoke`,
3420
3433
  summary: "Revoke an API key by id.",
3421
- guards: [xt(we)],
3422
- input: z.Struct({ body: z.Struct({ id: z.String }) }),
3423
- output: z.Struct({ ok: z.Boolean }),
3424
- handler: async (t, n) => ({ ok: await e.revoke(t.body.id, Ha(n).tenantId) })
3434
+ guards: [St(we)],
3435
+ input: R.Struct({ body: R.Struct({ id: R.String }) }),
3436
+ output: R.Struct({ ok: R.Boolean }),
3437
+ handler: async (t, n) => ({ ok: await e.revoke(t.body.id, qa(n).tenantId) })
3425
3438
  })
3426
3439
  ];
3427
- }, Wa = {
3440
+ }, Ya = {
3428
3441
  type: "anonymous",
3429
3442
  id: null,
3430
3443
  tenantId: null
3431
- }, Ga = class extends Ye.Tag("@voltro/EffectStore")() {}, Ka = (e, t) => (n) => n instanceof ei ? n : new ti({
3444
+ }, Xa = class extends Ye.Tag("@voltro/EffectStore")() {}, Za = (e, t) => (n) => n instanceof ei ? n : new ti({
3432
3445
  operation: e,
3433
3446
  table: t,
3434
3447
  cause: String(n)
3435
- }), qa = (e, t, n) => F.tryPromise({
3448
+ }), Qa = (e, t, n) => P.tryPromise({
3436
3449
  try: n,
3437
- catch: Ka(e, t)
3438
- }), Ja = (e) => I.succeed(Ga, {
3439
- query: ((t) => qa("query", t.table, () => e.query(t))),
3440
- insert: (t, n) => qa("insert", t, () => e.insert(t, n)),
3441
- update: (t, n, r) => qa("update", t, () => e.update(t, n, r)),
3442
- delete: (t, n) => qa("delete", t, () => e.delete(t, n)),
3443
- hardDelete: (t, n) => qa("hardDelete", t, () => e.hardDelete(t, n))
3444
- }), Ya = (e) => ht.make(e.name, {
3450
+ catch: Za(e, t)
3451
+ }), $a = (e) => F.succeed(Xa, {
3452
+ query: ((t) => Qa("query", t.table, () => e.query(t))),
3453
+ insert: (t, n) => Qa("insert", t, () => e.insert(t, n)),
3454
+ update: (t, n, r) => Qa("update", t, () => e.update(t, n, r)),
3455
+ delete: (t, n) => Qa("delete", t, () => e.delete(t, n)),
3456
+ hardDelete: (t, n) => Qa("hardDelete", t, () => e.hardDelete(t, n))
3457
+ }), eo = (e) => gt.make(e.name, {
3445
3458
  payload: e.payloadSchema,
3446
3459
  success: Le,
3447
3460
  error: e.errorSchema
3448
- }), Xa = (e, t) => ({
3461
+ }), to = (e, t) => ({
3449
3462
  id: t,
3450
3463
  workflowName: e,
3451
3464
  executionId: t,
3452
3465
  status: "running"
3453
- }), Za = Xa, Qa = (e) => {
3466
+ }), no = to, ro = (e) => {
3454
3467
  let t = N.failureOption(e), n = t._tag === "Some" ? t.value : N.squash(e);
3455
3468
  return {
3456
3469
  tag: n && typeof n == "object" && "_tag" in n ? String(n._tag) : null,
3457
3470
  message: n?.message ?? String(n)
3458
3471
  };
3459
- }, $a = (e, t, n) => {
3472
+ }, io = (e, t, n) => {
3460
3473
  if (n === void 0) return {
3461
3474
  id: t,
3462
3475
  workflowName: e,
@@ -3471,7 +3484,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3471
3484
  };
3472
3485
  if (typeof n == "object" && n && n._tag === "Complete") {
3473
3486
  let r = n.exit;
3474
- return $e.isSuccess(r) ? {
3487
+ return et.isSuccess(r) ? {
3475
3488
  id: t,
3476
3489
  workflowName: e,
3477
3490
  executionId: t,
@@ -3482,7 +3495,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3482
3495
  workflowName: e,
3483
3496
  executionId: t,
3484
3497
  status: "failed",
3485
- error: Qa(r.cause)
3498
+ error: ro(r.cause)
3486
3499
  };
3487
3500
  }
3488
3501
  return {
@@ -3491,7 +3504,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3491
3504
  executionId: t,
3492
3505
  status: "running"
3493
3506
  };
3494
- }, eo = (e) => new Promise((t) => setTimeout(t, e)), to = class extends Error {
3507
+ }, ao = (e) => new Promise((t) => setTimeout(t, e)), oo = class extends Error {
3495
3508
  workflowName;
3496
3509
  missingFields;
3497
3510
  detail;
@@ -3500,7 +3513,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3500
3513
  let r = t.length > 0 ? ` missing required field(s): ${t.join(", ")}.` : "";
3501
3514
  super(`Workflow "${e}" was started with an invalid payload.${r} ${n}`), this.workflowName = e, this.missingFields = t, this.detail = n, this.name = "WorkflowPayloadError";
3502
3515
  }
3503
- }, no = (e) => {
3516
+ }, so = (e) => {
3504
3517
  let t = e.ast;
3505
3518
  if (!Array.isArray(t.propertySignatures)) return {
3506
3519
  required: [],
@@ -3511,10 +3524,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3511
3524
  required: n.filter((e) => !e.isOptional).map((e) => String(e.name)),
3512
3525
  optional: n.filter((e) => e.isOptional).map((e) => String(e.name))
3513
3526
  };
3514
- }, ro = (e) => {
3527
+ }, co = (e) => {
3515
3528
  let t = e.ast;
3516
3529
  return Array.isArray(t.propertySignatures) ? t.propertySignatures.filter((e) => !e.isOptional && typeof e.name == "string").map((e) => String(e.name)) : [];
3517
- }, io = (e) => {
3530
+ }, lo = (e) => {
3518
3531
  let t = new Map(e.workflows.map((e) => [e.definition.name, e.definition])), n = (e) => {
3519
3532
  let n = t.get(e);
3520
3533
  if (!n) {
@@ -3523,19 +3536,19 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3523
3536
  }
3524
3537
  return n;
3525
3538
  }, r = (e, t) => {
3526
- let n = z.validateEither(e.payloadSchema)(t);
3539
+ let n = R.validateEither(e.payloadSchema)(t);
3527
3540
  if (n._tag === "Right") return;
3528
- let r = typeof t == "object" && t ? Object.keys(t) : [], i = ro(e.payloadSchema).filter((e) => !r.includes(e));
3529
- throw new to(e.name, i, wt.formatErrorSync(n.left));
3541
+ let r = typeof t == "object" && t ? Object.keys(t) : [], i = co(e.payloadSchema).filter((e) => !r.includes(e));
3542
+ throw new oo(e.name, i, Tt.formatErrorSync(n.left));
3530
3543
  }, i = (e, t) => {
3531
3544
  let i = n(e);
3532
3545
  return r(i, t), i;
3533
3546
  }, a = async (t, r) => {
3534
3547
  let i = n(t);
3535
- return $a(t, r, await e.runEffect(i.poll(r)));
3536
- }, o = async () => e.runEffect(Pt()), s = async (t, n, r) => {
3548
+ return io(t, r, await e.runEffect(i.poll(r)));
3549
+ }, o = async () => e.runEffect(Ft()), s = async (t, n, r) => {
3537
3550
  let a = i(t, n), o;
3538
- return r?.callerContext !== void 0 && (o = await e.runEffect(a.executionId(n)), await e.rememberStartContext?.(t, o, r.callerContext)), r?.wait ? (await e.runEffect(a.execute(n)), Xa(t, o ?? await e.runEffect(a.executionId(n)))) : Xa(t, await e.runEffect(a.execute(n, { discard: !0 })));
3551
+ return r?.callerContext !== void 0 && (o = await e.runEffect(a.executionId(n)), await e.rememberStartContext?.(t, o, r.callerContext)), r?.wait ? (await e.runEffect(a.execute(n)), to(t, o ?? await e.runEffect(a.executionId(n)))) : to(t, await e.runEffect(a.execute(n, { discard: !0 })));
3539
3552
  };
3540
3553
  return {
3541
3554
  start: s,
@@ -3573,7 +3586,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3573
3586
  let e = await a(r, i);
3574
3587
  if (e.status === "succeeded" || e.status === "failed" || e.status === "cancelled") return e;
3575
3588
  if (o?.timeoutMs !== void 0 && Date.now() - s >= o.timeoutMs) throw Error(`Timed out waiting for workflow '${r}' run '${i}'`);
3576
- await eo(c);
3589
+ await ao(c);
3577
3590
  }
3578
3591
  }),
3579
3592
  cancel: async (t, r) => {
@@ -3611,22 +3624,22 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3611
3624
  return e.retry(t, n);
3612
3625
  }
3613
3626
  };
3614
- }, ao = (e, t) => ({
3627
+ }, uo = (e, t) => ({
3615
3628
  ...e,
3616
3629
  start: async (n, r, i) => {
3617
3630
  if (i?.wait) throw Error("ctx.workflows.start(..., { wait: true }) is not allowed inside a mutation transaction; start the workflow and wait after commit.");
3618
3631
  let a = await e.executionId(n, r);
3619
- return t(() => e.start(n, r)), Xa(n, a);
3632
+ return t(() => e.start(n, r)), to(n, a);
3620
3633
  },
3621
3634
  child: async (n, r, i) => {
3622
3635
  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.");
3623
3636
  let a = await e.executionId(n, r);
3624
- return t(() => e.child(n, r, i)), Xa(n, a);
3637
+ return t(() => e.child(n, r, i)), to(n, a);
3625
3638
  },
3626
3639
  run: async () => {
3627
3640
  throw Error("ctx.workflows.run(...) is not allowed inside a mutation transaction; use ctx.workflows.start(...) so the workflow starts after commit.");
3628
3641
  }
3629
- }), oo = (e, t) => ({
3642
+ }), fo = (e, t) => ({
3630
3643
  ...e,
3631
3644
  start: (n, r, i) => e.start(n, r, {
3632
3645
  ...i,
@@ -3640,7 +3653,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3640
3653
  ...i,
3641
3654
  callerContext: t
3642
3655
  })
3643
- }), so = (e) => {
3656
+ }), po = (e) => {
3644
3657
  let t = () => {
3645
3658
  let t = e();
3646
3659
  if (!t) throw Error("Workflow runtime is not ready yet");
@@ -3661,32 +3674,32 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3661
3674
  listRuns: ((e) => t().listRuns(e)),
3662
3675
  retry: (e, n) => t().retry(e, n)
3663
3676
  };
3664
- }, co = (e, t) => {
3677
+ }, mo = (e, t) => {
3665
3678
  let n = {};
3666
- for (let r of e) n[r.definition.name] = (e) => (t ? F.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(F.map((e) => Xa(r.definition.name, e)))).pipe(F.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
3679
+ for (let r of e) n[r.definition.name] = (e) => (t ? P.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(P.map((e) => to(r.definition.name, e)))).pipe(P.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
3667
3680
  return n;
3668
- }, lo = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
3681
+ }, ho = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
3669
3682
  let a = t.resolveStartContext?.(e.definition.name, i);
3670
- return (a === void 0 ? F.succeed(void 0) : F.promise(() => Promise.resolve(a))).pipe(F.flatMap((a) => {
3683
+ return (a === void 0 ? P.succeed(void 0) : P.promise(() => Promise.resolve(a))).pipe(P.flatMap((a) => {
3671
3684
  let o = {
3672
3685
  ...a,
3673
- subject: a?.subject ?? Wa,
3686
+ subject: a?.subject ?? Ya,
3674
3687
  traceId: a?.traceId ?? "workflow-bootstrap"
3675
3688
  }, s = t.buildContext(o, {
3676
3689
  workflowName: e.definition.name,
3677
3690
  executionId: i,
3678
3691
  parentExecutionId: a?.parentExecutionId ?? null,
3679
3692
  parentClosePolicy: a?.parentClosePolicy ?? null
3680
- }), c = e.buildExecute(s), l = (n?.(e, c, o) ?? c)(r, i), u = I.succeed(Ne, o.subject), d = s?.store, f = d === void 0 ? l : F.provide(l, Ja(d));
3681
- return F.provide(f, u);
3693
+ }), c = e.buildExecute(s), l = (n?.(e, c, o) ?? c)(r, i), u = F.succeed(Ne, o.subject), d = s?.store, f = d === void 0 ? l : P.provide(l, $a(d));
3694
+ return P.provide(f, u);
3682
3695
  }));
3683
- }))), uo = (e) => ({
3696
+ }))), go = (e) => ({
3684
3697
  _tag: "workflowEventTrigger",
3685
3698
  ...e
3686
- }), fo = uo, po = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", mo = () => {
3699
+ }), _o = go, vo = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", yo = () => {
3687
3700
  let e = globalThis.crypto;
3688
3701
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
3689
- }, ho = (e) => `${e}_${mo()}`, go = (e) => e.id ?? `${e.event}->${e.workflow}`, _o = O("_voltro_workflow_events", {
3702
+ }, bo = (e) => `${e}_${yo()}`, xo = (e) => e.id ?? `${e.event}->${e.workflow}`, So = O("_voltro_workflow_events", {
3690
3703
  id: y({ prefix: "wfe" }),
3691
3704
  name: k(),
3692
3705
  payload: T(),
@@ -3694,7 +3707,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3694
3707
  subject: T().nullable(),
3695
3708
  traceId: k().nullable(),
3696
3709
  occurredAt: A().default("now")
3697
- }).index(["name"]).index(["source"]).index(["occurredAt"]), vo = O("_voltro_workflow_event_deliveries", {
3710
+ }).index(["name"]).index(["source"]).index(["occurredAt"]), Co = O("_voltro_workflow_event_deliveries", {
3698
3711
  id: y({ prefix: "wfed" }),
3699
3712
  eventId: k(),
3700
3713
  eventName: k(),
@@ -3712,8 +3725,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3712
3725
  errorMessage: k().nullable(),
3713
3726
  createdAt: A().default("now"),
3714
3727
  completedAt: A().nullable()
3715
- }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]), yo = (e) => {
3716
- let t = e.makeId ?? ho, n = /* @__PURE__ */ new Map();
3728
+ }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]), wo = (e) => {
3729
+ let t = e.makeId ?? bo, n = /* @__PURE__ */ new Map();
3717
3730
  for (let t of e.triggers) {
3718
3731
  let e = n.get(t.event);
3719
3732
  e ? e.push(t) : n.set(t.event, [t]);
@@ -3754,7 +3767,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3754
3767
  });
3755
3768
  let p = o(n), m = [];
3756
3769
  for (let o of p) {
3757
- let s = go(o), l = o.workflow, u;
3770
+ let s = xo(o), l = o.workflow, u;
3758
3771
  try {
3759
3772
  let p = o.idempotencyKey?.(f) ?? `${c}:${s}`;
3760
3773
  if (o.filter && !await o.filter(f)) {
@@ -3857,10 +3870,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3857
3870
  triggered: m
3858
3871
  };
3859
3872
  } };
3860
- }, bo = M({ scope: "voltro:outbox" }), Y = "_voltro_outbox", xo = {
3873
+ }, To = M({ scope: "voltro:outbox" }), Y = "_voltro_outbox", Eo = {
3861
3874
  kind: "typeid",
3862
3875
  prefix: "obx"
3863
- }, So = O(Y, {
3876
+ }, Do = O(Y, {
3864
3877
  id: y({ prefix: "obx" }),
3865
3878
  effect: k(),
3866
3879
  payload: T(),
@@ -3878,10 +3891,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3878
3891
  resendRequestedBy: k().nullable(),
3879
3892
  resendReason: k().nullable(),
3880
3893
  resendCount: x()
3881
- }), Co = "_voltro_outbox_attempts", wo = {
3894
+ }), Oo = "_voltro_outbox_attempts", ko = {
3882
3895
  kind: "typeid",
3883
3896
  prefix: "obxa"
3884
- }, To = O(Co, {
3897
+ }, Ao = O(Oo, {
3885
3898
  id: y({ prefix: "obxa" }),
3886
3899
  outboxId: k(),
3887
3900
  effect: k(),
@@ -3902,11 +3915,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3902
3915
  subjectId: k().nullable(),
3903
3916
  tenantId: k().nullable(),
3904
3917
  traceId: k().nullable()
3905
- }).index(["outboxId", "attempt"]).index(["startedAt"]).index(["outcome"]), Eo = (e) => {
3918
+ }).index(["outboxId", "attempt"]).index(["startedAt"]).index(["outcome"]), jo = (e) => {
3906
3919
  if (e.effect.trim() === "") throw Error("defineOutboxHandler: `effect` must be a non-empty name");
3907
3920
  if (e.maxAttempts !== void 0 && e.maxAttempts < 1) throw Error(`defineOutboxHandler("${e.effect}"): maxAttempts must be >= 1`);
3908
3921
  return e;
3909
- }, Do = 8, Oo = (e) => ({
3922
+ }, Mo = 8, No = (e) => ({
3910
3923
  enqueue: async (n, r, i) => {
3911
3924
  let a = (e.now ?? (() => /* @__PURE__ */ new Date()))(), o = i?.idempotencyKey;
3912
3925
  if (o !== void 0) {
@@ -3921,12 +3934,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3921
3934
  if (n !== void 0) return n.id;
3922
3935
  }
3923
3936
  let s = {
3924
- id: p(xo, Y),
3937
+ id: p(Eo, Y),
3925
3938
  effect: n,
3926
3939
  payload: r,
3927
3940
  status: "pending",
3928
3941
  attempts: 0,
3929
- maxAttempts: i?.maxAttempts ?? Do,
3942
+ maxAttempts: i?.maxAttempts ?? Mo,
3930
3943
  nextAttemptAt: new Date(a.getTime() + (i?.delayMs ?? 0)),
3931
3944
  idempotencyKey: o ?? null,
3932
3945
  lastError: null,
@@ -3973,7 +3986,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3973
3986
  });
3974
3987
  } else e.nudge?.();
3975
3988
  }
3976
- }), ko = (e) => Math.min(1e3 * 2 ** Math.max(0, e - 1), 5 * 6e4), Ao = 50, jo = (e, t) => e.length <= t ? e : `${e.slice(0, t)}… [clipped]`, Mo = (e) => {
3989
+ }), Po = (e) => Math.min(1e3 * 2 ** Math.max(0, e - 1), 5 * 6e4), Fo = 50, Io = (e, t) => e.length <= t ? e : `${e.slice(0, t)}… [clipped]`, Lo = (e) => {
3977
3990
  if (e == null) return null;
3978
3991
  let t = typeof e == "object" && !Array.isArray(e) ? e : { value: e }, n;
3979
3992
  try {
@@ -3983,13 +3996,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
3983
3996
  }
3984
3997
  return n.length > 8192 ? {
3985
3998
  truncated: !0,
3986
- preview: jo(n, 8192)
3999
+ preview: Io(n, 8192)
3987
4000
  } : t;
3988
- }, No = async (e, t, n) => {
4001
+ }, Ro = async (e, t, n) => {
3989
4002
  let r = t.outboxRow, i = r.id, a = r.resendRequestedBy ?? null;
3990
4003
  try {
3991
- await e.insert(Co, {
3992
- id: p(wo, Co),
4004
+ await e.insert(Oo, {
4005
+ id: p(ko, Oo),
3993
4006
  outboxId: i,
3994
4007
  effect: r.effect,
3995
4008
  attempt: t.attempt,
@@ -4000,14 +4013,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4000
4013
  startedAt: t.startedAt,
4001
4014
  finishedAt: t.finishedAt,
4002
4015
  durationMs: Math.max(0, t.finishedAt.getTime() - t.startedAt.getTime()),
4003
- error: t.error === null ? null : jo(t.error, 4e3),
4004
- response: Mo(t.response),
4016
+ error: t.error === null ? null : Io(t.error, 4e3),
4017
+ response: Lo(t.response),
4005
4018
  subjectId: r.subjectId ?? null,
4006
4019
  tenantId: r.tenantId ?? null,
4007
4020
  traceId: r.traceId ?? null
4008
4021
  });
4009
4022
  } catch (e) {
4010
- bo.warn("outbox: could not record delivery attempt (delivery itself is unaffected)", {
4023
+ To.warn("outbox: could not record delivery attempt (delivery itself is unaffected)", {
4011
4024
  outboxId: i,
4012
4025
  attempt: t.attempt
4013
4026
  }, e);
@@ -4015,7 +4028,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4015
4028
  }
4016
4029
  if (!(t.attempt <= n)) try {
4017
4030
  let t = await e.query({
4018
- table: Co,
4031
+ table: Oo,
4019
4032
  predicate: d("outboxId", i),
4020
4033
  order: [{
4021
4034
  column: "attempt",
@@ -4025,11 +4038,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4025
4038
  skip: void 0,
4026
4039
  projection: ["id"]
4027
4040
  });
4028
- for (let r of t.slice(0, Math.max(0, t.length - n))) await e.delete(Co, r.id);
4041
+ for (let r of t.slice(0, Math.max(0, t.length - n))) await e.delete(Oo, r.id);
4029
4042
  } catch (e) {
4030
- bo.warn("outbox: attempt-log trim failed; the log may exceed its cap", { outboxId: i }, e);
4043
+ To.warn("outbox: attempt-log trim failed; the log may exceed its cap", { outboxId: i }, e);
4031
4044
  }
4032
- }, Po = async (e) => {
4045
+ }, zo = async (e) => {
4033
4046
  let n = (e.now ?? (() => /* @__PURE__ */ new Date()))(), r = await e.store.query({
4034
4047
  table: Y,
4035
4048
  predicate: t(d("status", "pending"), te("nextAttemptAt", n)),
@@ -4047,7 +4060,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4047
4060
  s++;
4048
4061
  continue;
4049
4062
  }
4050
- let u = t.attempts + 1, d = t.maxAttempts ?? Do, f = /* @__PURE__ */ new Date(), p = e.attemptLogCap ?? 50;
4063
+ let u = t.attempts + 1, d = t.maxAttempts ?? Mo, f = /* @__PURE__ */ new Date(), p = e.attemptLogCap ?? 50;
4051
4064
  try {
4052
4065
  let n = await l.handler({
4053
4066
  payload: t.payload ?? {},
@@ -4056,7 +4069,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4056
4069
  tenantId: t.tenantId ?? null,
4057
4070
  traceId: t.traceId ?? null
4058
4071
  });
4059
- await No(e.store, {
4072
+ await Ro(e.store, {
4060
4073
  outboxRow: t,
4061
4074
  attempt: u,
4062
4075
  outcome: "delivered",
@@ -4074,7 +4087,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4074
4087
  }), i++;
4075
4088
  } catch (i) {
4076
4089
  let s = i instanceof Error ? i.message : String(i), l = u >= d;
4077
- await No(e.store, {
4090
+ await Ro(e.store, {
4078
4091
  outboxRow: t,
4079
4092
  attempt: u,
4080
4093
  outcome: l ? "dead" : "failed",
@@ -4086,20 +4099,20 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4086
4099
  status: l ? "dead" : "pending",
4087
4100
  attempts: u,
4088
4101
  lastError: s,
4089
- nextAttemptAt: new Date(n.getTime() + ko(u)),
4102
+ nextAttemptAt: new Date(n.getTime() + Po(u)),
4090
4103
  resendRequestedBy: null,
4091
4104
  resendReason: null
4092
- }), l ? (o++, bo.error("outbox effect dead-lettered after exhausting attempts", {
4105
+ }), l ? (o++, To.error("outbox effect dead-lettered after exhausting attempts", {
4093
4106
  id: r,
4094
4107
  effect: c,
4095
4108
  attempts: u,
4096
4109
  maxAttempts: d
4097
- }, i)) : (a++, bo.warn("outbox delivery failed; will retry", {
4110
+ }, i)) : (a++, To.warn("outbox delivery failed; will retry", {
4098
4111
  id: r,
4099
4112
  effect: c,
4100
4113
  attempt: u,
4101
4114
  maxAttempts: d,
4102
- retryInMs: ko(u)
4115
+ retryInMs: Po(u)
4103
4116
  }));
4104
4117
  }
4105
4118
  }
@@ -4109,10 +4122,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4109
4122
  dead: o,
4110
4123
  skipped: s
4111
4124
  };
4112
- }, Fo = M({ scope: "voltro:connections" }), X = "_voltro_connections", Io = {
4125
+ }, Bo = M({ scope: "voltro:connections" }), X = "_voltro_connections", Vo = {
4113
4126
  kind: "typeid",
4114
4127
  prefix: "conn"
4115
- }, Lo = O(X, {
4128
+ }, Ho = O(X, {
4116
4129
  id: y({ prefix: "conn" }),
4117
4130
  connectionId: k(),
4118
4131
  subjectId: k(),
@@ -4135,10 +4148,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4135
4148
  metadata: T().nullable(),
4136
4149
  connectedAt: A(),
4137
4150
  updatedAt: A()
4138
- }).unique("byConnectionSubject", ["connectionId", "subjectId"]).index(["subjectId"]), Ro = "_voltro_connection_grants", zo = {
4151
+ }).unique("byConnectionSubject", ["connectionId", "subjectId"]).index(["subjectId"]), Uo = "_voltro_connection_grants", Wo = {
4139
4152
  kind: "typeid",
4140
4153
  prefix: "cgrant"
4141
- }, Bo = O(Ro, {
4154
+ }, Go = O(Uo, {
4142
4155
  id: y({ prefix: "cgrant" }),
4143
4156
  state: k().unique(),
4144
4157
  connectionId: k(),
@@ -4148,8 +4161,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4148
4161
  redirectTo: k(),
4149
4162
  createdAt: A(),
4150
4163
  expiresAt: A()
4151
- }).index(["expiresAt"]), Vo = /^[a-z][a-z0-9-]*$/, Ho = (e) => {
4152
- if (!Vo.test(e.id)) throw Error(`defineConnection: id "${e.id}" must be lowercase kebab-case (it becomes a URL path segment).`);
4164
+ }).index(["expiresAt"]), Ko = /^[a-z][a-z0-9-]*$/, qo = (e) => {
4165
+ if (!Ko.test(e.id)) throw Error(`defineConnection: id "${e.id}" must be lowercase kebab-case (it becomes a URL path segment).`);
4153
4166
  if (e.kind === "oauth2") {
4154
4167
  for (let t of [
4155
4168
  "authorizeUrl",
@@ -4159,9 +4172,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4159
4172
  ]) if (typeof e[t] != "string" || e[t].length === 0) throw Error(`defineConnection("${e.id}"): \`${t}\` is required for kind 'oauth2'.`);
4160
4173
  }
4161
4174
  return e;
4162
- }, Uo = (e) => e.label ?? e.id, Wo = (e) => {
4175
+ }, Jo = (e) => e.label ?? e.id, Yo = (e) => {
4163
4176
  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).`);
4164
- }, Go = (e) => {
4177
+ }, Xo = (e) => {
4165
4178
  let t = /* @__PURE__ */ new Map();
4166
4179
  for (let n of e) {
4167
4180
  if (t.has(n.id)) throw Error(`connections: duplicate connection id "${n.id}" — each *.connection.ts must declare a distinct id.`);
@@ -4171,14 +4184,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4171
4184
  get: (e) => t.get(e),
4172
4185
  list: () => [...t.values()]
4173
4186
  };
4174
- }, Ko = (e) => {
4187
+ }, Zo = (e) => {
4175
4188
  if (e == null) return null;
4176
4189
  let t = e instanceof Date ? e : new Date(String(e));
4177
4190
  return Number.isNaN(t.getTime()) ? null : t;
4178
- }, qo = (e) => Ko(e)?.toISOString() ?? null, Jo = (e) => String(e ?? "").split(" ").filter((e) => e.length > 0), Yo = (e, t) => t === void 0 ? {
4191
+ }, Qo = (e) => Zo(e)?.toISOString() ?? null, $o = (e) => String(e ?? "").split(" ").filter((e) => e.length > 0), es = (e, t) => t === void 0 ? {
4179
4192
  connectionId: e.id,
4180
4193
  kind: e.kind,
4181
- label: Uo(e),
4194
+ label: Jo(e),
4182
4195
  status: "disconnected",
4183
4196
  accountId: null,
4184
4197
  accountLabel: null,
@@ -4189,24 +4202,24 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4189
4202
  } : {
4190
4203
  connectionId: e.id,
4191
4204
  kind: e.kind,
4192
- label: Uo(e),
4205
+ label: Jo(e),
4193
4206
  status: String(t.status ?? "connected"),
4194
4207
  accountId: t.accountId ?? null,
4195
4208
  accountLabel: t.accountLabel ?? null,
4196
- scopes: Jo(t.scopes),
4197
- expiresAt: qo(t.expiresAt),
4209
+ scopes: $o(t.scopes),
4210
+ expiresAt: Qo(t.expiresAt),
4198
4211
  lastError: t.lastError ?? null,
4199
- connectedAt: qo(t.connectedAt)
4200
- }, Xo = async (e, n, r) => (await e.query({
4212
+ connectedAt: Qo(t.connectedAt)
4213
+ }, ts = async (e, n, r) => (await e.query({
4201
4214
  table: X,
4202
4215
  predicate: t(d("connectionId", n), d("subjectId", r)),
4203
4216
  order: [],
4204
4217
  take: 1,
4205
4218
  skip: void 0,
4206
4219
  projection: void 0
4207
- }))[0], Zo = async (e) => {
4220
+ }))[0], ns = async (e) => {
4208
4221
  let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), n = e.tokens.expiresAt === void 0 ? null : new Date(e.tokens.expiresAt), r = {
4209
- id: p(Io, X),
4222
+ id: p(Vo, X),
4210
4223
  connectionId: e.definition.id,
4211
4224
  subjectId: e.subjectId,
4212
4225
  tenantId: e.tenantId,
@@ -4224,8 +4237,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4224
4237
  connectedAt: t,
4225
4238
  updatedAt: t
4226
4239
  };
4227
- return Qo(e.store, r);
4228
- }, Qo = (e, t) => e.upsert(X, t, {
4240
+ return rs(e.store, r);
4241
+ }, rs = (e, t) => e.upsert(X, t, {
4229
4242
  conflictColumns: ["connectionId", "subjectId"],
4230
4243
  update: [
4231
4244
  "kind",
@@ -4241,10 +4254,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4241
4254
  "metadata",
4242
4255
  "updatedAt"
4243
4256
  ]
4244
- }), $o = async (e, t, n) => {
4245
- let r = await Xo(e, t, n);
4257
+ }), is = async (e, t, n) => {
4258
+ let r = await ts(e, t, n);
4246
4259
  return r !== void 0 && e.delete(X, r.id);
4247
- }, es = async (e, t, n) => {
4260
+ }, as = async (e, t, n) => {
4248
4261
  let r = await e.query({
4249
4262
  table: X,
4250
4263
  predicate: d("subjectId", n),
@@ -4253,9 +4266,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4253
4266
  skip: void 0,
4254
4267
  projection: void 0
4255
4268
  }), i = new Map(r.map((e) => [String(e.connectionId), e]));
4256
- return t.list().map((e) => Yo(e, i.get(e.id)));
4257
- }, ts = (e, t) => globalThis.fetch(e, t), ns = async (e, t, n) => {
4258
- let r = e.fetchImpl ?? ts, i, a;
4269
+ return t.list().map((e) => es(e, i.get(e.id)));
4270
+ }, os = (e, t) => globalThis.fetch(e, t), ss = async (e, t, n) => {
4271
+ let r = e.fetchImpl ?? os, i, a;
4259
4272
  try {
4260
4273
  let n = await r(e.tokenUrl, {
4261
4274
  method: "POST",
@@ -4295,62 +4308,62 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4295
4308
  ...Number.isFinite(o.expires_in) ? { expiresAt: n() + o.expires_in * 1e3 } : {},
4296
4309
  scopes: (o.scope ?? e.scopes?.join(" ") ?? "").split(" ").filter(Boolean)
4297
4310
  };
4298
- }, rs = (e, t, n = Date.now) => ns(e, {
4311
+ }, cs = (e, t, n = Date.now) => ss(e, {
4299
4312
  grant_type: "authorization_code",
4300
4313
  client_id: e.clientId,
4301
4314
  client_secret: e.clientSecret,
4302
4315
  code: t.code,
4303
4316
  redirect_uri: t.redirectUri,
4304
4317
  ...t.codeVerifier ? { code_verifier: t.codeVerifier } : {}
4305
- }, n), is = (e, t, n = Date.now) => ns(e, {
4318
+ }, n), ls = (e, t, n = Date.now) => ss(e, {
4306
4319
  grant_type: "refresh_token",
4307
4320
  client_id: e.clientId,
4308
4321
  client_secret: e.clientSecret,
4309
4322
  refresh_token: t
4310
- }, n), as = 6e4, os = 3e4, ss = class extends Error {
4323
+ }, n), us = 6e4, ds = 3e4, fs = class extends Error {
4311
4324
  connectionId;
4312
4325
  subjectId;
4313
4326
  _tag = "ConnectionNotConnected";
4314
4327
  constructor(e, t) {
4315
4328
  super(`connection "${e}" is not connected for this subject`), this.connectionId = e, this.subjectId = t, this.name = "ConnectionNotConnected";
4316
4329
  }
4317
- }, cs = (e) => new Promise((t) => {
4330
+ }, ps = (e) => new Promise((t) => {
4318
4331
  setTimeout(t, e);
4319
- }), ls = /* @__PURE__ */ new Map(), us = (e, t) => `${e}\u0000${t}`, ds = () => {
4320
- ls.clear();
4321
- }, fs = (e, t) => ({
4332
+ }), ms = /* @__PURE__ */ new Map(), hs = (e, t) => `${e}\u0000${t}`, gs = () => {
4333
+ ms.clear();
4334
+ }, _s = (e, t) => ({
4322
4335
  connectionId: e.id,
4323
4336
  kind: e.kind,
4324
4337
  accessToken: Mr(String(t.accessToken)),
4325
- expiresAt: Ko(t.expiresAt),
4326
- scopes: Jo(t.scopes),
4338
+ expiresAt: Zo(t.expiresAt),
4339
+ scopes: $o(t.scopes),
4327
4340
  accountId: t.accountId ?? null,
4328
4341
  accountLabel: t.accountLabel ?? null
4329
- }), ps = (e, t, n) => {
4330
- let r = Ko(e.expiresAt);
4342
+ }), vs = (e, t, n) => {
4343
+ let r = Zo(e.expiresAt);
4331
4344
  return r !== null && r.getTime() - n < t;
4332
- }, ms = async (e) => {
4333
- let t = e.now ?? Date.now, { store: n, definition: r, subjectId: i } = e, a = await Xo(n, r.id, i);
4334
- if (a === void 0) throw new ss(r.id, i);
4335
- if (r.kind === "pat" || !ps(a, r.refreshSkewMs ?? 6e4, t())) return fs(r, a);
4336
- let o = us(r.id, i), s = ls.get(o);
4345
+ }, ys = async (e) => {
4346
+ let t = e.now ?? Date.now, { store: n, definition: r, subjectId: i } = e, a = await ts(n, r.id, i);
4347
+ if (a === void 0) throw new fs(r.id, i);
4348
+ if (r.kind === "pat" || !vs(a, r.refreshSkewMs ?? 6e4, t())) return _s(r, a);
4349
+ let o = hs(r.id, i), s = ms.get(o);
4337
4350
  if (s !== void 0) return s;
4338
- let c = hs({
4351
+ let c = bs({
4339
4352
  ...e,
4340
4353
  now: t,
4341
4354
  row: a
4342
4355
  }).finally(() => {
4343
- ls.delete(o);
4356
+ ms.delete(o);
4344
4357
  });
4345
- return ls.set(o, c), c;
4346
- }, hs = async (e) => {
4347
- let { store: n, subjectId: r, now: i } = e, a = e.definition, o = e.sleep ?? cs, s = a.refreshSkewMs ?? 6e4, c = e.row.id;
4358
+ return ms.set(o, c), c;
4359
+ }, bs = async (e) => {
4360
+ let { store: n, subjectId: r, now: i } = e, a = e.definition, o = e.sleep ?? ps, s = a.refreshSkewMs ?? 6e4, c = e.row.id;
4348
4361
  if (await n.updateMany("_voltro_connections", { refreshLockedUntil: new Date(i() + 3e4) }, { where: t(d("id", c), te("refreshLockedUntil", new Date(i()))) }) === 0) {
4349
4362
  for (let e = 0; e < 10; e++) {
4350
4363
  await o(200);
4351
- let e = await Xo(n, a.id, r);
4352
- if (e === void 0) throw new ss(a.id, r);
4353
- if (!ps(e, s, i())) return fs(a, e);
4364
+ let e = await ts(n, a.id, r);
4365
+ if (e === void 0) throw new fs(a.id, r);
4366
+ if (!vs(e, s, i())) return _s(a, e);
4354
4367
  }
4355
4368
  throw new j({
4356
4369
  connectionId: a.id,
@@ -4371,7 +4384,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4371
4384
  });
4372
4385
  let u;
4373
4386
  try {
4374
- u = await is(a, Mr(String(l)), i);
4387
+ u = await ls(a, Mr(String(l)), i);
4375
4388
  } catch (e) {
4376
4389
  let t = e instanceof j ? e : new j({
4377
4390
  connectionId: a.id,
@@ -4388,7 +4401,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4388
4401
  refreshToken: null,
4389
4402
  expiresAt: null
4390
4403
  }
4391
- }), Fo.warn("connection refresh failed", {
4404
+ }), Bo.warn("connection refresh failed", {
4392
4405
  connectionId: a.id,
4393
4406
  transient: t.transient,
4394
4407
  reason: t.reason
@@ -4404,32 +4417,32 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4404
4417
  refreshLockedUntil: /* @__PURE__ */ new Date(0),
4405
4418
  updatedAt: new Date(i())
4406
4419
  };
4407
- return fs(a, await n.update(X, c, f) ?? {
4420
+ return _s(a, await n.update(X, c, f) ?? {
4408
4421
  ...e.row,
4409
4422
  ...f
4410
4423
  });
4411
- }, gs = (e = 32) => {
4424
+ }, xs = (e = 32) => {
4412
4425
  let t = new Uint8Array(e);
4413
4426
  return globalThis.crypto.getRandomValues(t), Array.from(t, (e) => e.toString(16).padStart(2, "0")).join("");
4414
- }, _s = (e) => {
4427
+ }, Ss = (e) => {
4415
4428
  let t = "";
4416
4429
  for (let n of e) t += String.fromCharCode(n);
4417
4430
  return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
4418
- }, vs = async (e) => {
4431
+ }, Cs = async (e) => {
4419
4432
  let t = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
4420
- return _s(new Uint8Array(t));
4421
- }, ys = 10 * 6e4, bs = (e) => `/_voltro/connections/${e}/callback`, xs = (e) => e === void 0 || e.length === 0 || !e.startsWith("/") || e.startsWith("//") || e.startsWith("/\\") ? "/" : e, Ss = (e, t) => e.redirectUri ?? `${t.replace(/\/+$/, "")}${bs(e.id)}`, Cs = async (e) => {
4422
- let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), { definition: n } = e, r = gs(), i = n.pkce === !1 ? null : gs(48), a = Ss(n, e.publicUrl);
4423
- await e.store.insert(Ro, {
4424
- id: p(zo, Ro),
4433
+ return Ss(new Uint8Array(t));
4434
+ }, ws = 10 * 6e4, Ts = (e) => `/_voltro/connections/${e}/callback`, Es = (e) => e === void 0 || e.length === 0 || !e.startsWith("/") || e.startsWith("//") || e.startsWith("/\\") ? "/" : e, Ds = (e, t) => e.redirectUri ?? `${t.replace(/\/+$/, "")}${Ts(e.id)}`, Os = async (e) => {
4435
+ let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), { definition: n } = e, r = xs(), i = n.pkce === !1 ? null : xs(48), a = Ds(n, e.publicUrl);
4436
+ await e.store.insert(Uo, {
4437
+ id: p(Wo, Uo),
4425
4438
  state: r,
4426
4439
  connectionId: n.id,
4427
4440
  subjectId: e.subjectId,
4428
4441
  tenantId: e.tenantId,
4429
4442
  codeVerifier: i === null ? null : jr(i),
4430
- redirectTo: xs(e.redirectTo),
4443
+ redirectTo: Es(e.redirectTo),
4431
4444
  createdAt: t,
4432
- expiresAt: new Date(t.getTime() + ys)
4445
+ expiresAt: new Date(t.getTime() + ws)
4433
4446
  });
4434
4447
  let o = new URLSearchParams({
4435
4448
  response_type: "code",
@@ -4439,15 +4452,15 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4439
4452
  ...n.scopes && n.scopes.length > 0 ? { scope: n.scopes.join(" ") } : {},
4440
4453
  ...n.authorizeParams ?? {}
4441
4454
  });
4442
- i !== null && (o.set("code_challenge", await vs(i)), o.set("code_challenge_method", "S256"));
4455
+ i !== null && (o.set("code_challenge", await Cs(i)), o.set("code_challenge_method", "S256"));
4443
4456
  let s = n.authorizeUrl.includes("?") ? "&" : "?";
4444
4457
  return {
4445
4458
  authorizeUrl: `${n.authorizeUrl}${s}${o.toString()}`,
4446
4459
  state: r
4447
4460
  };
4448
- }, ws = async (e) => {
4461
+ }, ks = async (e) => {
4449
4462
  let t = (e.now ?? (() => /* @__PURE__ */ new Date()))(), n = (await e.store.query({
4450
- table: Ro,
4463
+ table: Uo,
4451
4464
  predicate: d("state", e.state),
4452
4465
  order: [],
4453
4466
  take: 1,
@@ -4459,8 +4472,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4459
4472
  reason: "unknown or already-used handshake state",
4460
4473
  transient: !1
4461
4474
  });
4462
- await e.store.delete(Ro, n.id);
4463
- let r = String(n.connectionId), i = Ko(n.expiresAt);
4475
+ await e.store.delete(Uo, n.id);
4476
+ let r = String(n.connectionId), i = Zo(n.expiresAt);
4464
4477
  if (i !== null && i.getTime() < t.getTime()) throw new j({
4465
4478
  connectionId: r,
4466
4479
  reason: "handshake expired — start again",
@@ -4472,17 +4485,17 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4472
4485
  reason: "no oauth2 connection is declared under that id",
4473
4486
  transient: !1
4474
4487
  });
4475
- let o = n.codeVerifier === null || n.codeVerifier === void 0 ? null : Mr(String(n.codeVerifier)), s = await rs(a, {
4488
+ let o = n.codeVerifier === null || n.codeVerifier === void 0 ? null : Mr(String(n.codeVerifier)), s = await cs(a, {
4476
4489
  code: e.code,
4477
- redirectUri: Ss(a, e.publicUrl),
4490
+ redirectUri: Ds(a, e.publicUrl),
4478
4491
  codeVerifier: o
4479
4492
  }, () => t.getTime()), c = a.identify === void 0 ? void 0 : await a.identify(s).catch((e) => {
4480
- Fo.warn("connection identify failed; storing without account details", {
4493
+ Bo.warn("connection identify failed; storing without account details", {
4481
4494
  connectionId: r,
4482
4495
  reason: String(e)
4483
4496
  });
4484
4497
  });
4485
- return await Zo({
4498
+ return await ns({
4486
4499
  store: e.store,
4487
4500
  definition: a,
4488
4501
  subjectId: String(n.subjectId),
@@ -4492,11 +4505,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4492
4505
  now: () => t
4493
4506
  }), {
4494
4507
  connectionId: r,
4495
- redirectTo: xs(String(n.redirectTo ?? "/"))
4508
+ redirectTo: Es(String(n.redirectTo ?? "/"))
4496
4509
  };
4497
- }, Ts = async (e, t = /* @__PURE__ */ new Date()) => {
4510
+ }, As = async (e, t = /* @__PURE__ */ new Date()) => {
4498
4511
  let n = await e.query({
4499
- table: Ro,
4512
+ table: Uo,
4500
4513
  predicate: te("expiresAt", t),
4501
4514
  order: [],
4502
4515
  take: void 0,
@@ -4505,27 +4518,27 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4505
4518
  }), r = 0;
4506
4519
  for (let t of n) await e.delete("_voltro_connection_grants", t.id) && r++;
4507
4520
  return r;
4508
- }, Es, Ds = (e) => {
4509
- Es = e;
4510
- }, Os = () => Es, ks = (e, t) => {
4511
- let n = Es;
4521
+ }, js, Ms = (e) => {
4522
+ js = e;
4523
+ }, Ns = () => js, Ps = (e, t) => {
4524
+ let n = js;
4512
4525
  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);
4513
- }, As = (e) => async (t, n) => {
4526
+ }, Fs = (e) => async (t, n) => {
4514
4527
  let r = e.registry.get(n);
4515
4528
  if (r === void 0) throw Error(`connection "${n}" is not declared. Declared: ${e.registry.list().map((e) => e.id).join(", ") || "(none)"}.`);
4516
4529
  let i = t.id ?? null;
4517
- if (i === null || i === "") throw new ss(n, "<anonymous>");
4518
- return ms({
4530
+ if (i === null || i === "") throw new fs(n, "<anonymous>");
4531
+ return ys({
4519
4532
  store: e.store,
4520
4533
  definition: r,
4521
4534
  subjectId: i
4522
4535
  });
4523
- }, js = (e) => {
4536
+ }, Is = (e) => {
4524
4537
  let t = e.subject.id ?? null, n = async (n) => {
4525
4538
  let r = e.registry.get(n);
4526
4539
  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)"}.`);
4527
- if (t === null || t === "") throw new ss(n, "<anonymous>");
4528
- return ms({
4540
+ if (t === null || t === "") throw new fs(n, "<anonymous>");
4541
+ return ys({
4529
4542
  store: e.store,
4530
4543
  definition: r,
4531
4544
  subjectId: t
@@ -4537,7 +4550,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4537
4550
  try {
4538
4551
  return await n(e);
4539
4552
  } catch (e) {
4540
- if (e instanceof ss) return null;
4553
+ if (e instanceof fs) return null;
4541
4554
  throw e;
4542
4555
  }
4543
4556
  },
@@ -4552,17 +4565,17 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4552
4565
  expiresAt: null,
4553
4566
  lastError: null,
4554
4567
  connectedAt: null
4555
- })) : es(e.store, e.registry, t)
4568
+ })) : as(e.store, e.registry, t)
4556
4569
  };
4557
- }, Ms = (e, t) => {
4570
+ }, Ls = (e, t) => {
4558
4571
  let n = e.request?.subject?.id ?? null;
4559
4572
  if (n === null || n === "") throw new je({ connectionId: t });
4560
4573
  return n;
4561
- }, Ns = (e, t) => {
4574
+ }, Rs = (e, t) => {
4562
4575
  let n = e.registry.get(t);
4563
4576
  if (n === void 0) throw new Ae({ connectionId: t });
4564
4577
  return n;
4565
- }, Ps = (e) => async (t, n) => {
4578
+ }, zs = (e) => async (t, n) => {
4566
4579
  let r = n.request?.subject?.id ?? null;
4567
4580
  return r === null || r === "" ? e.registry.list().map((e) => ({
4568
4581
  connectionId: e.id,
@@ -4575,15 +4588,15 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4575
4588
  expiresAt: null,
4576
4589
  lastError: null,
4577
4590
  connectedAt: null
4578
- })) : es(n.store, e.registry, r);
4579
- }, Fs = (e) => async (t, n) => {
4580
- let r = Ns(e, t.connectionId), i = Ms(n, t.connectionId);
4591
+ })) : as(n.store, e.registry, r);
4592
+ }, Bs = (e) => async (t, n) => {
4593
+ let r = Rs(e, t.connectionId), i = Ls(n, t.connectionId);
4581
4594
  if (r.kind !== "oauth2") throw new ke({
4582
4595
  connectionId: t.connectionId,
4583
4596
  expected: "oauth2",
4584
4597
  actual: r.kind
4585
4598
  });
4586
- return Cs({
4599
+ return Os({
4587
4600
  store: n.store,
4588
4601
  definition: r,
4589
4602
  subjectId: i,
@@ -4591,8 +4604,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4591
4604
  publicUrl: e.publicUrl,
4592
4605
  ...t.redirectTo === void 0 ? {} : { redirectTo: t.redirectTo }
4593
4606
  });
4594
- }, Is = (e) => async (t, n) => {
4595
- let r = Ns(e, t.connectionId), i = Ms(n, t.connectionId);
4607
+ }, Vs = (e) => async (t, n) => {
4608
+ let r = Rs(e, t.connectionId), i = Ls(n, t.connectionId);
4596
4609
  if (r.kind !== "pat") throw new ke({
4597
4610
  connectionId: t.connectionId,
4598
4611
  expected: "pat",
@@ -4614,7 +4627,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4614
4627
  transient: !1
4615
4628
  });
4616
4629
  }
4617
- return await Zo({
4630
+ return await ns({
4618
4631
  store: n.store,
4619
4632
  definition: r,
4620
4633
  subjectId: i,
@@ -4625,20 +4638,20 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4625
4638
  },
4626
4639
  ...o === void 0 ? {} : { account: o }
4627
4640
  }), { ok: !0 };
4628
- }, Ls = (e) => async (t, n) => {
4629
- Ns(e, t.connectionId);
4630
- let r = Ms(n, t.connectionId);
4631
- return { ok: await $o(n.store, t.connectionId, r) };
4632
- }, Rs = "admin:full", zs = class extends z.TaggedError()("AccessDenied", {
4633
- action: z.String,
4634
- resourceType: z.String,
4635
- resourceId: z.String
4636
- }) {}, Bs = /* @__PURE__ */ new Map(), Vs = (e) => {
4641
+ }, Hs = (e) => async (t, n) => {
4642
+ Rs(e, t.connectionId);
4643
+ let r = Ls(n, t.connectionId);
4644
+ return { ok: await is(n.store, t.connectionId, r) };
4645
+ }, Us = "admin:full", Ws = class extends R.TaggedError()("AccessDenied", {
4646
+ action: R.String,
4647
+ resourceType: R.String,
4648
+ resourceId: R.String
4649
+ }) {}, Gs = /* @__PURE__ */ new Map(), Ks = (e) => {
4637
4650
  if (typeof e.resourceType != "string" || e.resourceType.length === 0) throw Error("defineResourcePolicy: a non-empty `resourceType` is required");
4638
4651
  if (e.actions === void 0 || Object.keys(e.actions).length === 0) throw Error(`resource policy '${e.resourceType}': at least one action is required`);
4639
- if (Bs.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
4640
- return Bs.set(e.resourceType, e), e;
4641
- }, Hs = (e) => Bs.get(e), Us = () => [...Bs.values()], Ws = () => Bs.clear(), Gs = () => Us().map((e) => {
4652
+ if (Gs.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
4653
+ return Gs.set(e.resourceType, e), e;
4654
+ }, qs = (e) => Gs.get(e), Js = () => [...Gs.values()], Ys = () => Gs.clear(), Xs = () => Js().map((e) => {
4642
4655
  let t = /* @__PURE__ */ new Set();
4643
4656
  for (let n of Object.values(e.actions)) for (let e of n) t.add(e);
4644
4657
  for (let [n, r] of Object.entries(e.implies ?? {})) {
@@ -4651,7 +4664,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4651
4664
  relations: [...t],
4652
4665
  implies: e.implies ?? {}
4653
4666
  };
4654
- }), Ks = (e, t) => {
4667
+ }), Zs = (e, t) => {
4655
4668
  let n = new Set(e);
4656
4669
  if (t === void 0) return n;
4657
4670
  let r = [...e];
@@ -4660,52 +4673,55 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4660
4673
  for (let i of t[e] ?? []) n.has(i) || (n.add(i), r.push(i));
4661
4674
  }
4662
4675
  return n;
4663
- }, qs = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : Ks(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), Js = (e, t, n, r) => {
4676
+ }, Qs = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : Zs(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), $s = (e, t, n, r) => {
4664
4677
  if (e.scopes?.includes("admin:full")) return !0;
4665
4678
  if (e.id === null || n.tenantId != null && e.tenantId !== n.tenantId) return !1;
4666
4679
  let i = r.policy.actions[t];
4667
4680
  if (i === void 0 || i.length === 0) return !1;
4668
- let a = qs(e, n, r.tuples, r.policy);
4681
+ let a = Qs(e, n, r.tuples, r.policy);
4669
4682
  return i.some((e) => a.has(e));
4670
- }, Ys = (e, t, n, r) => {
4671
- if (!Js(e, t, n, r)) throw new zs({
4683
+ }, ec = (e, t, n, r) => {
4684
+ if (!$s(e, t, n, r)) throw new Ws({
4672
4685
  action: t,
4673
4686
  resourceType: n.type,
4674
4687
  resourceId: n.id
4675
4688
  });
4676
- }, Xs = (e, t, n, r, i) => r.filter((r) => Js(e, t, {
4689
+ }, tc = (e, t, n, r, i) => r.filter((r) => $s(e, t, {
4677
4690
  type: n,
4678
4691
  id: r.id,
4679
4692
  ...r.tenantId === void 0 ? {} : { tenantId: r.tenantId }
4680
- }, i)), Zs = (e, t) => {
4693
+ }, i)), nc = (e, t) => {
4681
4694
  let n = new Set(t.map((e) => e.id));
4682
4695
  return e.filter((e) => !n.has(e.id)).map((e) => e.id);
4683
- }, Qs = M({ scope: "voltro:policy" }), $s, ec = (e) => {
4684
- $s = e;
4685
- }, tc = () => $s, nc = () => {
4686
- Ge((e) => F.gen(function* () {
4687
- let t = Hs(e.resourceType);
4688
- if (t === void 0) return Qs.warn("policy guard denied — no resource policy registered for this type", {
4696
+ }, rc = new Ct(), ic = (e) => {
4697
+ rc.enterWith(e);
4698
+ }, ac = () => rc.getStore(), oc = (e, t) => rc.run(e, t), sc = M({ scope: "voltro:policy" }), cc, lc = (e) => {
4699
+ cc = e;
4700
+ }, uc = () => cc, dc = () => {
4701
+ Ge((e) => P.gen(function* () {
4702
+ let t = qs(e.resourceType);
4703
+ if (t === void 0) return sc.warn("policy guard denied — no resource policy registered for this type", {
4689
4704
  resourceType: e.resourceType,
4690
4705
  action: e.action
4691
4706
  }), !1;
4692
- let n = $s;
4693
- if (n === void 0) return Qs.warn("policy guard denied — no tuple source registered (call setTupleSource at boot)", {
4707
+ let n = cc;
4708
+ if (n === void 0) return sc.warn("policy guard denied — no tuple source registered (call setTupleSource at boot)", {
4694
4709
  resourceType: e.resourceType,
4695
4710
  action: e.action
4696
4711
  }), !1;
4697
- let r = yield* F.tryPromise({
4712
+ let r = yield* P.tryPromise({
4698
4713
  try: async () => n({
4699
4714
  subjectId: e.subject.id,
4700
4715
  resourceType: e.resourceType,
4701
- resourceId: e.resourceId
4716
+ resourceId: e.resourceId,
4717
+ load: ac()
4702
4718
  }),
4703
4719
  catch: (e) => e
4704
- }).pipe(F.catchAll((t) => (Qs.error("policy guard denied — tuple source failed", {
4720
+ }).pipe(P.catchAll((t) => (sc.error("policy guard denied — tuple source failed", {
4705
4721
  resourceType: e.resourceType,
4706
4722
  resourceId: e.resourceId
4707
- }, t), F.succeed([])))), i = e.subject;
4708
- return Js({
4723
+ }, t), P.succeed([])))), i = e.subject;
4724
+ return $s({
4709
4725
  id: e.subject.id,
4710
4726
  tenantId: i.tenantId ?? null,
4711
4727
  ...i.scopes === void 0 ? {} : { scopes: i.scopes }
@@ -4718,10 +4734,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4718
4734
  tuples: r
4719
4735
  });
4720
4736
  }));
4721
- }, rc = (e) => {
4737
+ }, fc = (e) => {
4722
4738
  Promise.resolve().then(e);
4723
- }, ic = (e) => {
4724
- let t = e.schedule ?? rc, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => `${e}\u0000${t}`, a = async (t) => {
4739
+ }, pc = (e) => {
4740
+ let t = e.schedule ?? fc, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = (e, t) => `${e}\u0000${t}`, a = async (t) => {
4725
4741
  let a = r.get(t);
4726
4742
  if (a === void 0) return;
4727
4743
  r.delete(t);
@@ -4767,23 +4783,23 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4767
4783
  load: async (e, t) => (await o(e, [t]))[0] ?? null,
4768
4784
  loadMany: (e, t) => o(e, t)
4769
4785
  };
4770
- }, ac = I.effect(lt.HttpClient, F.map(lt.HttpClient, (e) => e.pipe(lt.mapRequestEffect((e) => F.currentSpan.pipe(F.map((t) => e.headers.traceparent === void 0 ? ut.setHeader(e, "traceparent", yr({
4786
+ }, mc = F.effect(ut.HttpClient, P.map(ut.HttpClient, (e) => e.pipe(ut.mapRequestEffect((e) => P.currentSpan.pipe(P.map((t) => e.headers.traceparent === void 0 ? dt.setHeader(e, "traceparent", yr({
4771
4787
  traceId: t.traceId,
4772
4788
  spanId: t.spanId,
4773
4789
  sampled: t.sampled
4774
- })) : e), F.catchAll(() => F.succeed(e))))))), oc = class extends Error {
4790
+ })) : e), P.catchAll(() => P.succeed(e))))))), hc = class extends Error {
4775
4791
  url;
4776
4792
  reason;
4777
4793
  _tag = "SsrfBlockedError";
4778
4794
  constructor(e, t) {
4779
4795
  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";
4780
4796
  }
4781
- }, sc = (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, cc = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), lc = (e, t, n) => n.some((n) => {
4797
+ }, gc = (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, _c = (e) => e === "::" || e === "::1" || e.startsWith("fc") || e.startsWith("fd") || e.startsWith("fe80") || e.startsWith("::ffff:"), vc = (e, t, n) => n.some((n) => {
4782
4798
  let r = n.trim().toLowerCase();
4783
4799
  if (r === "") return !1;
4784
4800
  let i = t === "" ? e : `${e}:${t}`;
4785
4801
  return r === e || r === i ? !0 : r.startsWith("*.") ? e.endsWith(r.slice(1)) : !1;
4786
- }), uc = (e, t = {}) => {
4802
+ }), yc = (e, t = {}) => {
4787
4803
  let n;
4788
4804
  try {
4789
4805
  n = new URL(e);
@@ -4792,25 +4808,25 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4792
4808
  }
4793
4809
  if (n.protocol !== "http:" && n.protocol !== "https:") return `blocked scheme "${n.protocol}"`;
4794
4810
  let r = n.hostname.replace(/^\[|\]$/g, "").toLowerCase();
4795
- if (lc(r, n.port, t.allowHosts ?? [])) return null;
4811
+ if (vc(r, n.port, t.allowHosts ?? [])) return null;
4796
4812
  if (r === "localhost" || r.endsWith(".localhost") || r.endsWith(".internal") || r.endsWith(".local")) return `blocked host "${r}"`;
4797
4813
  let i = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.exec(r);
4798
4814
  if (i) {
4799
4815
  let e = Number(i[1]), t = Number(i[2]);
4800
- return e > 255 || t > 255 || Number(i[3]) > 255 || Number(i[4]) > 255 ? "malformed ipv4 literal" : sc(e, t) ? `blocked private/reserved address ${r}` : null;
4816
+ return e > 255 || t > 255 || Number(i[3]) > 255 || Number(i[4]) > 255 ? "malformed ipv4 literal" : gc(e, t) ? `blocked private/reserved address ${r}` : null;
4801
4817
  }
4802
4818
  if (r.includes(":")) {
4803
4819
  let e = /^::ffff:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/.exec(r);
4804
- return e ? uc(`${n.protocol}//${e[1]}`, t) : cc(r) ? `blocked private/reserved address ${r}` : null;
4820
+ return e ? yc(`${n.protocol}//${e[1]}`, t) : _c(r) ? `blocked private/reserved address ${r}` : null;
4805
4821
  }
4806
4822
  return null;
4807
- }, dc = (e = {}) => I.effect(lt.HttpClient, F.map(lt.HttpClient, (t) => {
4808
- let n = lt.transform(t, (t, n) => F.suspend(() => {
4809
- let r = uc(n.url, e);
4810
- return r === null ? t : F.die(new oc(n.url, r));
4823
+ }, bc = (e = {}) => F.effect(ut.HttpClient, P.map(ut.HttpClient, (t) => {
4824
+ let n = ut.transform(t, (t, n) => P.suspend(() => {
4825
+ let r = yc(n.url, e);
4826
+ return r === null ? t : P.die(new hc(n.url, r));
4811
4827
  }));
4812
- return lt.followRedirects(n, e.maxRedirects ?? 5);
4813
- })), fc = (e) => {
4828
+ return ut.followRedirects(n, e.maxRedirects ?? 5);
4829
+ })), xc = (e) => {
4814
4830
  let t = e.now ?? Date.now, n = e.intervalMs ?? 3e4, r = e.maxPending ?? 500, i = /* @__PURE__ */ new Map(), a = !1, o = async () => {
4815
4831
  if (i.size === 0) return;
4816
4832
  let t = i;
@@ -4839,7 +4855,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4839
4855
  },
4840
4856
  pending: () => i.size
4841
4857
  };
4842
- }, pc = "voltro/audit", mc = "voltro/softDelete", hc = "voltro/tenant", gc = (e) => {
4858
+ }, Sc = "voltro/audit", Cc = "voltro/softDelete", wc = "voltro/tenant", Tc = (e) => {
4843
4859
  let t = /* @__PURE__ */ new Map();
4844
4860
  for (let n of e) {
4845
4861
  let e = /* @__PURE__ */ new Set();
@@ -4883,16 +4899,16 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4883
4899
  return !1;
4884
4900
  },
4885
4901
  idScheme: (e) => t.get(e)?.idScheme,
4886
- defaultFactories: (e) => t.get(e)?.defaultFactories ?? _c,
4887
- computedFields: (e) => t.get(e)?.computedFields ?? vc,
4888
- generatedColumns: (e) => t.get(e)?.generatedColumns ?? yc,
4902
+ defaultFactories: (e) => t.get(e)?.defaultFactories ?? Ec,
4903
+ computedFields: (e) => t.get(e)?.computedFields ?? Dc,
4904
+ generatedColumns: (e) => t.get(e)?.generatedColumns ?? Oc,
4889
4905
  insertSchema: (e) => t.get(e)?.insertSchema,
4890
4906
  validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
4891
4907
  };
4892
- }, _c = /* @__PURE__ */ new Map(), vc = /* @__PURE__ */ new Map(), yc = /* @__PURE__ */ new Set(), bc = gc([]), xc = M({ scope: "store.fieldEncryption" }), Sc = (e, t) => {
4908
+ }, Ec = /* @__PURE__ */ new Map(), Dc = /* @__PURE__ */ new Map(), Oc = /* @__PURE__ */ new Set(), kc = Tc([]), Ac = M({ scope: "store.fieldEncryption" }), jc = (e, t) => {
4893
4909
  let n = t, r = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", i = /* @__PURE__ */ new Set(), a = (e) => {
4894
4910
  let t = `${e.table}.${e.column}`;
4895
- i.has(t) || (i.add(t), xc.warn("encrypted column degraded to null — could not decrypt with the active key", {
4911
+ i.has(t) || (i.add(t), Ac.warn("encrypted column degraded to null — could not decrypt with the active key", {
4896
4912
  table: e.table,
4897
4913
  column: e.column,
4898
4914
  reason: e.reason,
@@ -4916,7 +4932,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4916
4932
  e.injectExternalChange(t);
4917
4933
  },
4918
4934
  ...e.changeScope === void 0 ? {} : { changeScope: e.changeScope },
4919
- ...e.withNamespace === void 0 ? {} : { withNamespace: (n) => Sc(e.withNamespace(n), t) },
4935
+ ...e.withNamespace === void 0 ? {} : { withNamespace: (n) => jc(e.withNamespace(n), t) },
4920
4936
  ...e.raw === void 0 ? {} : { raw: ((...t) => e.raw(...t)) },
4921
4937
  ...e.close === void 0 ? {} : { close: (t) => e.close(t) },
4922
4938
  ...e.ping === void 0 ? {} : { ping: () => e.ping() },
@@ -4928,24 +4944,24 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4928
4944
  upsert: async (t, n, r) => d(t, await e.upsert(t, o(t, n), r)),
4929
4945
  insertIgnore: async (t, n, r) => d(t, await e.insertIgnore(t, o(t, n), r)),
4930
4946
  patchJson: async (t, n, r, i) => d(t, await e.patchJson(t, n, r, i)),
4931
- transactional: (n) => e.transactional((e) => n(Sc(e, t)))
4947
+ transactional: (n) => e.transactional((e) => n(jc(e, t)))
4932
4948
  };
4933
- }, Cc = (e, t) => {
4949
+ }, Mc = (e, t) => {
4934
4950
  if (t === void 0 || t.length === 0) return e;
4935
4951
  let n = { ...e };
4936
4952
  for (let e of t) delete n[e];
4937
4953
  return n;
4938
- }, wc = (e, t) => {
4954
+ }, Nc = (e, t) => {
4939
4955
  let n = h(e), r = n === void 0 ? [] : fe(n);
4940
4956
  return r.length === 0 ? t ?? [] : t === void 0 ? r : [...t, ...r];
4941
- }, Tc = (e, t) => t.length === 0 ? e : e.map((e) => Cc(e, t)), Ec = (e, t, n, r, i) => {
4957
+ }, Pc = (e, t) => t.length === 0 ? e : e.map((e) => Mc(e, t)), Fc = (e, t, n, r, i) => {
4942
4958
  let a = {
4943
4959
  ...t?.(r) ?? {},
4944
4960
  ...n?.(i) ?? {}
4945
4961
  }, o = e;
4946
4962
  for (let [e, t] of Object.entries(a)) t !== void 0 && (o = o.where(e, t));
4947
4963
  return o;
4948
- }, Dc = 1e3, Oc = (e, t = Dc) => {
4964
+ }, Ic = 1e3, Lc = (e, t = Ic) => {
4949
4965
  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);
4950
4966
  if (i !== void 0) {
4951
4967
  let t = r(n(e.pageSize) ?? 100);
@@ -4958,35 +4974,35 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
4958
4974
  limit: r(n(e.limit) ?? 100),
4959
4975
  offset: Math.max(0, Math.floor(n(e.offset) ?? 0))
4960
4976
  };
4961
- }, kc = {
4977
+ }, Rc = {
4962
4978
  list: (e, t = {}) => async (n, r) => {
4963
4979
  let i = n ?? {}, a = r.store.select(e);
4964
4980
  if (t.columns !== void 0 && t.columns.length > 0) {
4965
- let n = new Set(wc(e, void 0)), r = t.columns.filter((e) => !n.has(e));
4981
+ let n = new Set(Nc(e, void 0)), r = t.columns.filter((e) => !n.has(e));
4966
4982
  r.length > 0 && (a = a.select(...r));
4967
4983
  }
4968
- t.include !== void 0 && (a = a.with(t.include)), a = Ec(a, t.filter, t.scope, i, r);
4984
+ t.include !== void 0 && (a = a.with(t.include)), a = Fc(a, t.filter, t.scope, i, r);
4969
4985
  for (let e of t.sort ?? []) a = a.orderBy(e.column, e.direction ?? "asc");
4970
4986
  if (t.paginate === !0) {
4971
- let { limit: e, offset: n } = Oc(i, t.maxPageSize);
4987
+ let { limit: e, offset: n } = Lc(i, t.maxPageSize);
4972
4988
  a = a.limit(e).offset(n);
4973
4989
  }
4974
- return Tc(await a.all(), wc(e, t.redact));
4990
+ return Pc(await a.all(), Nc(e, t.redact));
4975
4991
  },
4976
4992
  getById: (e, t = {}) => async (n, r) => {
4977
4993
  let i = r.store.select(e).where("id", n.id);
4978
4994
  t.include !== void 0 && (i = i.with(t.include));
4979
4995
  let a = await i.first();
4980
- return a === null ? null : Cc(a, wc(e, t.redact));
4996
+ return a === null ? null : Mc(a, Nc(e, t.redact));
4981
4997
  },
4982
- create: (e, t = {}) => async (n, r) => Cc(await r.store.insert(e, n), wc(e, t.redact)),
4998
+ create: (e, t = {}) => async (n, r) => Mc(await r.store.insert(e, n), Nc(e, t.redact)),
4983
4999
  update: (e, t = {}) => async (n, r) => {
4984
5000
  let { id: i, ...a } = n, o = await r.store.update(e, i, a);
4985
- return o === null ? null : Cc(o, wc(e, t.redact));
5001
+ return o === null ? null : Mc(o, Nc(e, t.redact));
4986
5002
  },
4987
- count: (e, t = {}) => async (n, r) => Ec(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
5003
+ count: (e, t = {}) => async (n, r) => Fc(r.store.select(e), t.filter, t.scope, n ?? {}, r).count(),
4988
5004
  remove: (e) => async (t, n) => ({ deleted: await n.store.delete(e, t.id) })
4989
- }, Ac = (e) => {
5005
+ }, zc = (e) => {
4990
5006
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = (e) => {
4991
5007
  if (!n.has(e)) switch (n.add(e), e._tag) {
4992
5008
  case "TypeLiteral":
@@ -5013,7 +5029,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5013
5029
  }
5014
5030
  };
5015
5031
  return r(e.ast), t;
5016
- }, jc = (e) => {
5032
+ }, Bc = (e) => {
5017
5033
  let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = (e) => {
5018
5034
  switch (e._tag) {
5019
5035
  case "Literal": return e.literal === null;
@@ -5048,42 +5064,47 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5048
5064
  }
5049
5065
  };
5050
5066
  return i(e.ast), t;
5051
- }, Mc = (e, t) => {
5067
+ }, Vc = (e, t) => {
5052
5068
  let n = e.source === void 0 ? [] : Array.isArray(e.source) ? e.source : [e.source];
5053
5069
  if (n.length === 0) return [];
5054
- let r = Ac(e.output), i = jc(e.output), a = [];
5070
+ let r = zc(e.output), i = Bc(e.output), a = [];
5055
5071
  for (let o of n) for (let n of t.get(o) ?? []) r.has(n) && !i.has(n) && a.push({
5056
5072
  query: e.name,
5057
5073
  table: o,
5058
5074
  column: n
5059
5075
  });
5060
5076
  return a;
5061
- }, Nc = (e) => {
5077
+ }, Hc = (e) => {
5062
5078
  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.`;
5063
- }, Pc = class extends z.TaggedError()("CircuitOpen", {
5064
- name: z.String,
5065
- retryAfterMs: z.Number
5066
- }) {}, Fc = {
5079
+ }, Uc = (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) => ({
5080
+ query: e.name,
5081
+ table: t
5082
+ })) : [], Wc = (e) => {
5083
+ 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.`;
5084
+ }, Gc = class extends R.TaggedError()("CircuitOpen", {
5085
+ name: R.String,
5086
+ retryAfterMs: R.Number
5087
+ }) {}, Kc = {
5067
5088
  tag: "closed",
5068
5089
  failureCount: 0,
5069
5090
  halfOpenSuccesses: 0,
5070
5091
  openedAt: 0
5071
- }, Ic = { make: (e) => F.gen(function* () {
5072
- let t = e.name ?? "circuit", n = Ze.toMillis(Ze.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* R.make(Fc), o = F.gen(function* () {
5073
- let e = yield* R.get(a);
5092
+ }, qc = { make: (e) => P.gen(function* () {
5093
+ let t = e.name ?? "circuit", n = Qe.toMillis(Qe.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* L.make(Kc), o = P.gen(function* () {
5094
+ let e = yield* L.get(a);
5074
5095
  if (e.tag === "half-open") {
5075
5096
  let t = e.halfOpenSuccesses + 1;
5076
- yield* R.set(a, t >= r ? Fc : {
5097
+ yield* L.set(a, t >= r ? Kc : {
5077
5098
  ...e,
5078
5099
  halfOpenSuccesses: t
5079
5100
  });
5080
5101
  return;
5081
5102
  }
5082
- e.failureCount !== 0 && (yield* R.set(a, Fc));
5083
- }), s = F.gen(function* () {
5084
- let t = yield* Je.currentTimeMillis, n = yield* R.get(a);
5103
+ e.failureCount !== 0 && (yield* L.set(a, Kc));
5104
+ }), s = P.gen(function* () {
5105
+ let t = yield* Je.currentTimeMillis, n = yield* L.get(a);
5085
5106
  if (n.tag === "half-open" || n.tag === "open") {
5086
- yield* R.set(a, {
5107
+ yield* L.set(a, {
5087
5108
  tag: "open",
5088
5109
  failureCount: e.failureThreshold,
5089
5110
  halfOpenSuccesses: 0,
@@ -5092,7 +5113,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5092
5113
  return;
5093
5114
  }
5094
5115
  let r = n.failureCount + 1;
5095
- yield* R.set(a, r >= e.failureThreshold ? {
5116
+ yield* L.set(a, r >= e.failureThreshold ? {
5096
5117
  tag: "open",
5097
5118
  failureCount: r,
5098
5119
  halfOpenSuccesses: 0,
@@ -5101,40 +5122,40 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5101
5122
  ...n,
5102
5123
  failureCount: r
5103
5124
  });
5104
- }), c = F.gen(function* () {
5105
- let e = yield* R.get(a);
5125
+ }), c = P.gen(function* () {
5126
+ let e = yield* L.get(a);
5106
5127
  if (e.tag !== "open") return null;
5107
5128
  let t = (yield* Je.currentTimeMillis) - e.openedAt;
5108
- return t >= n ? (yield* R.set(a, {
5129
+ return t >= n ? (yield* L.set(a, {
5109
5130
  tag: "half-open",
5110
5131
  failureCount: 0,
5111
5132
  halfOpenSuccesses: 0,
5112
5133
  openedAt: e.openedAt
5113
5134
  }), null) : n - t;
5114
- }), l = (e) => F.gen(function* () {
5135
+ }), l = (e) => P.gen(function* () {
5115
5136
  let n = yield* c;
5116
- return n === null ? yield* e.pipe(F.tap(() => o), F.tapErrorCause((e) => {
5117
- if (N.isInterruptedOnly(e)) return F.void;
5137
+ return n === null ? yield* e.pipe(P.tap(() => o), P.tapErrorCause((e) => {
5138
+ if (N.isInterruptedOnly(e)) return P.void;
5118
5139
  let t = N.failureOption(e), n = t._tag === "Some" ? t.value : void 0;
5119
- return i(n) ? s : F.void;
5120
- })) : yield* F.fail(new Pc({
5140
+ return i(n) ? s : P.void;
5141
+ })) : yield* P.fail(new Gc({
5121
5142
  name: t,
5122
5143
  retryAfterMs: n
5123
5144
  }));
5124
5145
  }), u = ((e) => l(e));
5125
5146
  return Object.defineProperty(u, "state", {
5126
- value: R.get(a).pipe(F.map((e) => e.tag)),
5147
+ value: L.get(a).pipe(P.map((e) => e.tag)),
5127
5148
  enumerable: !0
5128
5149
  }), Object.defineProperty(u, "reset", {
5129
- value: R.set(a, Fc),
5150
+ value: L.set(a, Kc),
5130
5151
  enumerable: !0
5131
5152
  }), u;
5132
- }) }, Lc, Rc = (e) => {
5133
- Lc = e;
5134
- }, zc = () => {
5135
- Lc = void 0;
5136
- }, Bc = () => Lc, Vc = async (e, t = {}) => {
5137
- let n = t.scopes === void 0 ? Ke(t.id ?? "system") : Ke(t.id ?? "system", t.scopes), r = t.store ?? Lc?.dataStore, i = t.schemaRegistry ?? Lc?.schemaRegistry, a = t.dialect ?? Lc?.dialect;
5153
+ }) }, Jc, Yc = (e) => {
5154
+ Jc = e;
5155
+ }, Xc = () => {
5156
+ Jc = void 0;
5157
+ }, Zc = () => Jc, Qc = async (e, t = {}) => {
5158
+ let n = t.scopes === void 0 ? Ke(t.id ?? "system") : Ke(t.id ?? "system", t.scopes), r = t.store ?? Jc?.dataStore, i = t.schemaRegistry ?? Jc?.schemaRegistry, a = t.dialect ?? Jc?.dialect;
5138
5159
  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.");
5139
5160
  return e({
5140
5161
  subject: n,
@@ -5144,7 +5165,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5144
5165
  ...a === void 0 ? {} : { dialect: a }
5145
5166
  })
5146
5167
  });
5147
- }, Hc = (e) => {
5168
+ }, $c = (e) => {
5148
5169
  let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
5149
5170
  if (t === void 0) return {
5150
5171
  sameRegion: [],
@@ -5172,7 +5193,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5172
5193
  return r.loadSnapshot();
5173
5194
  }
5174
5195
  };
5175
- }, Uc = (e = process.env) => {
5196
+ }, el = (e = process.env) => {
5176
5197
  for (let t of [
5177
5198
  "VOLTRO_REGION",
5178
5199
  "AWS_REGION",
@@ -5184,7 +5205,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5184
5205
  let n = e[t];
5185
5206
  if (typeof n == "string" && n.length > 0) return n;
5186
5207
  }
5187
- }, Wc = () => {
5208
+ }, tl = () => {
5188
5209
  let e = {
5189
5210
  primary: 0,
5190
5211
  lagByReplica: /* @__PURE__ */ new Map()
@@ -5209,27 +5230,27 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5209
5230
  e.lagByReplica.set(t, n);
5210
5231
  }
5211
5232
  };
5212
- }, Gc = Symbol.for("@voltro/ScheduleDefinition"), Kc = (e) => typeof e == "object" && !!e && Gc in e, qc = 30 * 6e4, Jc = (e) => {
5213
- let t = P.parse(e.cron, e.timezone);
5214
- if (Qe.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
5233
+ }, nl = Symbol.for("@voltro/ScheduleDefinition"), rl = (e) => typeof e == "object" && !!e && nl in e, il = 30 * 6e4, al = (e) => {
5234
+ let t = Xe.parse(e.cron, e.timezone);
5235
+ if ($e.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
5215
5236
  if (!e.timezone || e.timezone.trim() === "") throw Error(`defineSchedule("${e.name}"): timezone is required (e.g. "UTC", "Europe/Berlin")`);
5216
5237
  if (e.handler === void 0 && e.workflow === void 0) throw Error(`defineSchedule("${e.name}"): define either handler or workflow`);
5217
5238
  return {
5218
5239
  ...e,
5219
5240
  onOverlap: e.onOverlap ?? "skip",
5220
5241
  backfill: e.backfill ?? "skip",
5221
- maxRuntimeMs: e.maxRuntimeMs ?? qc,
5222
- [Gc]: !0
5242
+ maxRuntimeMs: e.maxRuntimeMs ?? il,
5243
+ [nl]: !0
5223
5244
  };
5224
- }, Yc = (e) => P.unsafeParse(e.cron, e.timezone), Xc = (e, t = /* @__PURE__ */ new Date()) => P.next(Yc(e), t), Z = "_voltro_wakeups", Zc = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Qc = (e) => ({
5245
+ }, ol = (e) => Xe.unsafeParse(e.cron, e.timezone), sl = (e, t = /* @__PURE__ */ new Date()) => Xe.next(ol(e), t), Z = "_voltro_wakeups", cl = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, ll = (e) => ({
5225
5246
  tenantId: String(e.tenantId),
5226
5247
  kind: String(e.kind),
5227
5248
  refId: String(e.refId),
5228
5249
  wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
5229
5250
  status: e.status === "fired" ? "fired" : "pending"
5230
- }), $c = async (e, t) => {
5251
+ }), ul = async (e, t) => {
5231
5252
  await e.upsert(Z, {
5232
- id: Zc(t),
5253
+ id: cl(t),
5233
5254
  tenantId: t.tenantId,
5234
5255
  kind: t.kind,
5235
5256
  refId: t.refId,
@@ -5239,7 +5260,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5239
5260
  conflictColumns: ["id"],
5240
5261
  update: ["wakeAt", "status"]
5241
5262
  });
5242
- }, el = async (e, t) => e.delete(Z, Zc(t)), tl = async (e, t) => await e.update(Z, Zc(t), { status: "fired" }) !== null, nl = (e, t) => ({ and: [{
5263
+ }, dl = async (e, t) => e.delete(Z, cl(t)), fl = async (e, t) => await e.update(Z, cl(t), { status: "fired" }) !== null, pl = (e, t) => ({ and: [{
5243
5264
  column: "id",
5244
5265
  op: "eq",
5245
5266
  value: e
@@ -5247,16 +5268,16 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5247
5268
  column: "status",
5248
5269
  op: "eq",
5249
5270
  value: t
5250
- }] }), rl = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: nl(Zc(t), "pending") }) > 0, il = async (e, t) => {
5251
- await e.updateMany(Z, { status: "pending" }, { where: nl(Zc(t), "fired") });
5252
- }, al = {
5271
+ }] }), ml = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: pl(cl(t), "pending") }) > 0, hl = async (e, t) => {
5272
+ await e.updateMany(Z, { status: "pending" }, { where: pl(cl(t), "fired") });
5273
+ }, gl = {
5253
5274
  column: "status",
5254
5275
  op: "eq",
5255
5276
  value: "pending"
5256
- }, ol = async (e, t) => {
5277
+ }, _l = async (e, t) => {
5257
5278
  let n = {
5258
5279
  table: Z,
5259
- predicate: al,
5280
+ predicate: gl,
5260
5281
  order: [{
5261
5282
  column: "wakeAt",
5262
5283
  direction: "asc"
@@ -5265,18 +5286,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5265
5286
  skip: void 0,
5266
5287
  projection: void 0
5267
5288
  };
5268
- return (await e.query(n)).map(Qc);
5269
- }, sl = async (e, t, n = 500) => {
5270
- let r = await ol(e, n), i = t.getTime();
5289
+ return (await e.query(n)).map(ll);
5290
+ }, vl = async (e, t, n = 500) => {
5291
+ let r = await _l(e, n), i = t.getTime();
5271
5292
  return r.filter((e) => e.wakeAt.getTime() <= i);
5272
- }, cl = async (e) => (await ol(e, 1))[0] ?? null, ll = {
5293
+ }, yl = async (e) => (await _l(e, 1))[0] ?? null, bl = {
5273
5294
  column: "status",
5274
5295
  op: "eq",
5275
5296
  value: "fired"
5276
- }, ul = async (e, t = {}) => {
5297
+ }, xl = async (e, t = {}) => {
5277
5298
  let n = {
5278
5299
  table: Z,
5279
- predicate: ll,
5300
+ predicate: bl,
5280
5301
  order: [{
5281
5302
  column: "wakeAt",
5282
5303
  direction: "asc"
@@ -5287,12 +5308,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5287
5308
  }, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
5288
5309
  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++;
5289
5310
  return a;
5290
- }, dl = Wa, fl = "default", pl = {
5311
+ }, Sl = Ya, Cl = "default", wl = {
5291
5312
  kind: "single",
5292
5313
  tryClaim: async () => !0
5293
- }, ml = "_voltro_schedule_claims", hl = (e, t, n) => {
5314
+ }, Tl = "_voltro_schedule_claims", El = (e, t, n) => {
5294
5315
  let r = async (t) => (await e.query({
5295
- table: ml,
5316
+ table: Tl,
5296
5317
  order: [],
5297
5318
  predicate: void 0,
5298
5319
  projection: ["id"],
@@ -5307,7 +5328,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5307
5328
  if (await r(s)) return !1;
5308
5329
  } catch {}
5309
5330
  try {
5310
- return await e.insert(ml, {
5331
+ return await e.insert(Tl, {
5311
5332
  id: s,
5312
5333
  scheduleName: i,
5313
5334
  bucket: o,
@@ -5325,12 +5346,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5325
5346
  }
5326
5347
  }
5327
5348
  };
5328
- }, gl = "_voltro_schedule_runs", _l = async (e, t) => {
5349
+ }, Dl = "_voltro_schedule_runs", Ol = async (e, t) => {
5329
5350
  let { store: n, coordinator: r, buildContext: i, replicaId: a, log: o, onRunEvent: s, interceptFire: c } = t, l = t.dormancy === "sleep", u = t.dormancyTenantId ?? "default", d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), m = !1, h = new Map(e.map((e) => [e.name, e])), g = (e, t) => {
5330
- s?.(e, yl(t));
5351
+ s?.(e, Al(t));
5331
5352
  }, _ = async (e, t, r, i, s, c) => {
5332
5353
  try {
5333
- let o = `sr_${xe()}`, l = await n.insert(gl, {
5354
+ let o = `sr_${xe()}`, l = await n.insert(Dl, {
5334
5355
  id: o,
5335
5356
  name: e.name,
5336
5357
  status: i,
@@ -5355,7 +5376,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5355
5376
  }
5356
5377
  }, v = async (e, t) => {
5357
5378
  try {
5358
- let r = await n.update(gl, e, t);
5379
+ let r = await n.update(Dl, e, t);
5359
5380
  r && g("update", r);
5360
5381
  } catch (t) {
5361
5382
  o.warn("schedule: failed to record run finish", {
@@ -5366,7 +5387,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5366
5387
  }, y = async (e) => {
5367
5388
  try {
5368
5389
  let t = await n.query({
5369
- table: gl,
5390
+ table: Dl,
5370
5391
  predicate: {
5371
5392
  _tag: "leaf",
5372
5393
  column: "status",
@@ -5401,7 +5422,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5401
5422
  scheduleName: e.name,
5402
5423
  trigger: n,
5403
5424
  runId: s,
5404
- subject: dl
5425
+ subject: Sl
5405
5426
  })
5406
5427
  };
5407
5428
  try {
@@ -5429,10 +5450,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5429
5450
  durationMs: Date.now() - l
5430
5451
  });
5431
5452
  } catch (t) {
5432
- let n = Q(t).includes("exceeded maxRuntimeMs"), r = an(t).dbMessage, i = typeof r == "string" && r !== "" ? `${Q(t)} — ${r}` : Q(t);
5453
+ let n = Q(t).includes("exceeded maxRuntimeMs"), r = on(t).dbMessage, i = typeof r == "string" && r !== "" ? `${Q(t)} — ${r}` : Q(t);
5433
5454
  s && await v(s, {
5434
5455
  status: "failed",
5435
- errorTag: n ? "timeout" : vl(t),
5456
+ errorTag: n ? "timeout" : kl(t),
5436
5457
  errorMessage: i,
5437
5458
  completedAt: /* @__PURE__ */ new Date(),
5438
5459
  durationMs: Date.now() - l
@@ -5441,7 +5462,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5441
5462
  name: e.name,
5442
5463
  reason: Q(t),
5443
5464
  timeout: n,
5444
- ...an(t)
5465
+ ...on(t)
5445
5466
  };
5446
5467
  o.error ? o.error("schedule: handler failed", a) : o.warn("schedule: handler failed", a), Ue({
5447
5468
  error: t,
@@ -5492,8 +5513,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5492
5513
  }
5493
5514
  }, C = async (e) => {
5494
5515
  try {
5495
- let t = P.next(Yc(e), /* @__PURE__ */ new Date());
5496
- await $c(n, {
5516
+ let t = Xe.next(ol(e), /* @__PURE__ */ new Date());
5517
+ await ul(n, {
5497
5518
  tenantId: u,
5498
5519
  kind: "schedule",
5499
5520
  refId: e.name,
@@ -5507,7 +5528,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5507
5528
  }
5508
5529
  }, w = 2147483647, T = (e) => {
5509
5530
  if (m) return;
5510
- let n = Yc(e), r = P.next(n, /* @__PURE__ */ new Date()), i = () => {
5531
+ let n = ol(e), r = Xe.next(n, /* @__PURE__ */ new Date()), i = () => {
5511
5532
  if (m) return;
5512
5533
  let n = r.getTime() - Date.now();
5513
5534
  if (n > w) {
@@ -5529,7 +5550,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5529
5550
  let r;
5530
5551
  try {
5531
5552
  let t = (await n.query({
5532
- table: gl,
5553
+ table: Dl,
5533
5554
  order: [{
5534
5555
  column: "scheduledAt",
5535
5556
  direction: "desc"
@@ -5548,8 +5569,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5548
5569
  return;
5549
5570
  }
5550
5571
  if (!r) return;
5551
- let i = Yc(e), a = [], s = P.next(i, r), c = Date.now();
5552
- for (; s.getTime() < c && a.length < 1e3;) a.push(s), s = P.next(i, s);
5572
+ let i = ol(e), a = [], s = Xe.next(i, r), c = Date.now();
5573
+ for (; s.getTime() < c && a.length < 1e3;) a.push(s), s = Xe.next(i, s);
5553
5574
  if (a.length !== 0) if (o.info("schedule: backfill", {
5554
5575
  name: e.name,
5555
5576
  missed: a.length,
@@ -5593,11 +5614,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5593
5614
  d.clear(), o.info("scheduler: stopped");
5594
5615
  }
5595
5616
  };
5596
- }, Q = (e) => e?.message ?? String(e), vl = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, yl = (e) => {
5617
+ }, Q = (e) => e?.message ?? String(e), kl = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Al = (e) => {
5597
5618
  let t = {};
5598
5619
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
5599
5620
  return t;
5600
- }, bl = (e, t, n, r) => {
5621
+ }, jl = (e, t, n, r) => {
5601
5622
  let i = !1, a, o = async () => {
5602
5623
  if (i) return;
5603
5624
  let a = new Date(Math.floor(Date.now() / t) * t), o = !1;
@@ -5627,7 +5648,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5627
5648
  i || (i = !0, a && clearInterval(a), a = void 0);
5628
5649
  }
5629
5650
  };
5630
- }, xl = (e) => (t, n, r) => bl(t, n, r, e), Sl = O("_voltro_schedule_runs", {
5651
+ }, Ml = (e) => (t, n, r) => jl(t, n, r, e), Nl = O("_voltro_schedule_runs", {
5631
5652
  id: y({ prefix: "schrun" }),
5632
5653
  name: k(),
5633
5654
  status: k().oneOf([
@@ -5657,13 +5678,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5657
5678
  ]).nullable(),
5658
5679
  replicaId: k().nullable(),
5659
5680
  result: T().nullable()
5660
- }).index(["name", "scheduledAt"]).index(["status"]), Cl = O("_voltro_schedule_claims", {
5681
+ }).index(["name", "scheduledAt"]).index(["status"]), Pl = O("_voltro_schedule_claims", {
5661
5682
  id: y({ prefix: "schclaim" }),
5662
5683
  scheduleName: k(),
5663
5684
  bucket: k(),
5664
5685
  claimedBy: k(),
5665
5686
  claimedAt: A()
5666
- }).index(["scheduleName", "bucket"]).index(["claimedAt"]), wl = O("_voltro_traces", {
5687
+ }).index(["scheduleName", "bucket"]).index(["claimedAt"]), Fl = O("_voltro_traces", {
5667
5688
  id: y({ prefix: "span" }),
5668
5689
  traceId: k(),
5669
5690
  spanId: k(),
@@ -5687,7 +5708,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5687
5708
  durationMs: x(),
5688
5709
  attributes: T().nullable(),
5689
5710
  events: T().nullable()
5690
- }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Tl = O("_voltro_undo_log", {
5711
+ }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Il = O("_voltro_undo_log", {
5691
5712
  id: y({ prefix: "undo" }),
5692
5713
  tag: k(),
5693
5714
  label: k().nullable(),
@@ -5698,25 +5719,25 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5698
5719
  crossesAction: i().default(!1),
5699
5720
  undone: i().default(!1),
5700
5721
  createdAt: A().default("now")
5701
- }).index(["subjectId", "createdAt"]), El = (e = process.env) => {
5722
+ }).index(["subjectId", "createdAt"]), Ll = (e = process.env) => {
5702
5723
  let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
5703
5724
  return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
5704
- }, Dl = (e) => e.startsWith("_voltro"), Ol = async (e, t, n) => (await e.query({
5725
+ }, Rl = (e) => e.startsWith("_voltro"), zl = async (e, t, n) => (await e.query({
5705
5726
  table: t,
5706
5727
  predicate: d("id", n),
5707
5728
  order: []
5708
- }))[0] ?? null, kl = (e, t) => new Proxy(e, { get(e, n, r) {
5729
+ }))[0] ?? null, Bl = (e, t) => new Proxy(e, { get(e, n, r) {
5709
5730
  if (n === "insert") return async (n, r) => {
5710
5731
  let i = await e.insert(n, r);
5711
- return Dl(n) || t({
5732
+ return Rl(n) || t({
5712
5733
  table: n,
5713
5734
  op: "insert",
5714
5735
  next: i
5715
5736
  }), i;
5716
5737
  };
5717
5738
  if (n === "update") return async (n, r, i) => {
5718
- let a = Dl(n) ? null : await Ol(e, n, r), o = await e.update(n, r, i);
5719
- return Dl(n) || t({
5739
+ let a = Rl(n) ? null : await zl(e, n, r), o = await e.update(n, r, i);
5740
+ return Rl(n) || t({
5720
5741
  table: n,
5721
5742
  op: "update",
5722
5743
  id: r,
@@ -5725,8 +5746,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5725
5746
  }), o;
5726
5747
  };
5727
5748
  if (n === "delete") return async (n, r) => {
5728
- let i = Dl(n) ? null : await Ol(e, n, r), a = await e.delete(n, r);
5729
- return !Dl(n) && a && t({
5749
+ let i = Rl(n) ? null : await zl(e, n, r), a = await e.delete(n, r);
5750
+ return !Rl(n) && a && t({
5730
5751
  table: n,
5731
5752
  op: "delete",
5732
5753
  id: r,
@@ -5735,10 +5756,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5735
5756
  };
5736
5757
  let i = Reflect.get(e, n, r);
5737
5758
  return typeof i == "function" ? i.bind(e) : i;
5738
- } }), Al = (e) => {
5759
+ } }), Vl = (e) => {
5739
5760
  let t = [];
5740
5761
  return {
5741
- tx: kl(e, (e) => t.push(e)),
5762
+ tx: Bl(e, (e) => t.push(e)),
5742
5763
  persist: async (e, n) => {
5743
5764
  if (t.length === 0 || n.tag.startsWith("__voltro")) return;
5744
5765
  let r = n.subject;
@@ -5754,14 +5775,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5754
5775
  });
5755
5776
  }
5756
5777
  };
5757
- }, jl = (e) => {
5778
+ }, Hl = (e) => {
5758
5779
  if (e.id !== void 0) return e.id;
5759
5780
  let t = e.next?.id;
5760
5781
  if (typeof t == "string") return t;
5761
5782
  let n = e.prev?.id;
5762
5783
  return typeof n == "string" ? n : void 0;
5763
- }, Ml = (e) => {
5764
- let t = jl(e);
5784
+ }, Ul = (e) => {
5785
+ let t = Hl(e);
5765
5786
  switch (e.op) {
5766
5787
  case "insert": return t === void 0 ? null : {
5767
5788
  table: e.table,
@@ -5785,28 +5806,28 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5785
5806
  row: e.prev
5786
5807
  };
5787
5808
  }
5788
- }, Nl = (e) => {
5789
- if (e.crossesAction) throw new Pl(e.invocationId, "action");
5809
+ }, Wl = (e) => {
5810
+ if (e.crossesAction) throw new Gl(e.invocationId, "action");
5790
5811
  let t = [];
5791
5812
  for (let n = e.changes.length - 1; n >= 0; --n) {
5792
- let r = Ml(e.changes[n]);
5813
+ let r = Ul(e.changes[n]);
5793
5814
  r !== null && t.push(r);
5794
5815
  }
5795
5816
  return t;
5796
- }, Pl = class extends Error {
5817
+ }, Gl = class extends Error {
5797
5818
  invocationId;
5798
5819
  boundary;
5799
5820
  _tag = "UndoBoundaryError";
5800
5821
  constructor(e, t) {
5801
5822
  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";
5802
5823
  }
5803
- }, Fl = (e, t, n = ["updatedAt", "updatedBy"]) => {
5824
+ }, Kl = (e, t, n = ["updatedAt", "updatedBy"]) => {
5804
5825
  if (t == null) return e == null;
5805
5826
  if (e == null) return !1;
5806
5827
  let r = new Set(n);
5807
5828
  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;
5808
5829
  return !0;
5809
- }, Il = class {
5830
+ }, ql = class {
5810
5831
  capacity;
5811
5832
  done = [];
5812
5833
  undone = [];
@@ -5842,7 +5863,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5842
5863
  redo: [...this.undone]
5843
5864
  };
5844
5865
  }
5845
- }, Ll = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
5866
+ }, Jl = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
5846
5867
  table: e.table,
5847
5868
  op: "insert",
5848
5869
  next: e.new ?? null
@@ -5859,7 +5880,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5859
5880
  table: e.table,
5860
5881
  op: "delete",
5861
5882
  prev: e.old ?? null
5862
- }, Rl = async (e, t) => {
5883
+ }, Yl = async (e, t) => {
5863
5884
  switch (t.op) {
5864
5885
  case "delete":
5865
5886
  await e.delete(t.table, t.id);
@@ -5877,21 +5898,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5877
5898
  await e.insert(t.table, t.row);
5878
5899
  return;
5879
5900
  }
5880
- }, zl = async (e, t) => {
5881
- for (let n of t) await Rl(e, n);
5882
- }, Bl = (e) => e.request?.subject?.id ?? null, Vl = (e) => e === !0 || e === 1, Hl = async (e, t, n) => (await e.query({
5901
+ }, Xl = async (e, t) => {
5902
+ for (let n of t) await Yl(e, n);
5903
+ }, Zl = (e) => e.request?.subject?.id ?? null, Ql = (e) => e === !0 || e === 1, $l = async (e, t, n) => (await e.query({
5883
5904
  table: t,
5884
5905
  predicate: d("id", n),
5885
5906
  order: []
5886
- }))[0] ?? null, Ul = (e) => {
5907
+ }))[0] ?? null, eu = (e) => {
5887
5908
  try {
5888
5909
  let t = JSON.parse(String(e ?? "[]"));
5889
5910
  return Array.isArray(t) ? t : [];
5890
5911
  } catch {
5891
5912
  return [];
5892
5913
  }
5893
- }, Wl = (e) => e.id ?? e.next?.id ?? e.prev?.id, Gl = async (e, t) => {
5894
- let n = Bl(t);
5914
+ }, tu = (e) => e.id ?? e.next?.id ?? e.prev?.id, nu = async (e, t) => {
5915
+ let n = Zl(t);
5895
5916
  return [...await t.store.query({
5896
5917
  table: "_voltro_undo_log",
5897
5918
  predicate: d("subjectId", n),
@@ -5900,68 +5921,68 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5900
5921
  id: String(e.id),
5901
5922
  tag: String(e.tag ?? ""),
5902
5923
  label: e.label ?? null,
5903
- undone: Vl(e.undone),
5904
- crossesAction: Vl(e.crossesAction),
5924
+ undone: Ql(e.undone),
5925
+ crossesAction: Ql(e.crossesAction),
5905
5926
  createdAt: String(e.createdAt ?? "")
5906
5927
  }));
5907
- }, Kl = async (e, t) => {
5908
- let n = await Hl(t.store, "_voltro_undo_log", e.invocationId);
5928
+ }, ru = async (e, t) => {
5929
+ let n = await $l(t.store, "_voltro_undo_log", e.invocationId);
5909
5930
  if (!n) throw new Ie({ invocationId: e.invocationId });
5910
- if ((n.subjectId ?? null) !== Bl(t)) throw new Fe({ invocationId: e.invocationId });
5931
+ if ((n.subjectId ?? null) !== Zl(t)) throw new Fe({ invocationId: e.invocationId });
5911
5932
  return n;
5912
- }, ql = async (e, t) => {
5913
- let n = await Kl(e, t);
5914
- if (Vl(n.undone)) return { ok: !0 };
5915
- if (Vl(n.crossesAction)) throw new Pe({
5933
+ }, iu = async (e, t) => {
5934
+ let n = await ru(e, t);
5935
+ if (Ql(n.undone)) return { ok: !0 };
5936
+ if (Ql(n.crossesAction)) throw new Pe({
5916
5937
  invocationId: e.invocationId,
5917
5938
  reason: "action"
5918
5939
  });
5919
- let r = Ul(n.changes);
5940
+ let r = eu(n.changes);
5920
5941
  for (let n of r) {
5921
- let r = Wl(n);
5922
- if (r !== void 0 && !Fl(await Hl(t.store, n.table, r), n.next ?? null)) throw new Pe({
5942
+ let r = tu(n);
5943
+ if (r !== void 0 && !Kl(await $l(t.store, n.table, r), n.next ?? null)) throw new Pe({
5923
5944
  invocationId: e.invocationId,
5924
5945
  reason: "conflict"
5925
5946
  });
5926
5947
  }
5927
5948
  let i = {
5928
5949
  invocationId: e.invocationId,
5929
- subject: Bl(t),
5950
+ subject: Zl(t),
5930
5951
  changes: r,
5931
5952
  crossesAction: !1
5932
5953
  };
5933
- return await zl(t.store, Nl(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
5934
- }, Jl = async (e, t) => {
5935
- let n = await Kl(e, t);
5936
- if (!Vl(n.undone)) return { ok: !0 };
5937
- for (let e of Ul(n.changes)) {
5938
- let n = Wl(e);
5954
+ return await Xl(t.store, Wl(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
5955
+ }, au = async (e, t) => {
5956
+ let n = await ru(e, t);
5957
+ if (!Ql(n.undone)) return { ok: !0 };
5958
+ for (let e of eu(n.changes)) {
5959
+ let n = tu(e);
5939
5960
  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);
5940
5961
  }
5941
5962
  return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
5942
- }, Yl = (e = process.env) => {
5963
+ }, ou = (e = process.env) => {
5943
5964
  let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
5944
5965
  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";
5945
- }, Xl = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, Zl = "«redacted»", Ql = (e) => {
5966
+ }, su = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, cu = "«redacted»", lu = (e) => {
5946
5967
  if (e == null) return null;
5947
5968
  let t = {};
5948
- for (let [n, r] of Object.entries(e)) t[n] = Xl.test(n) ? Zl : r;
5969
+ for (let [n, r] of Object.entries(e)) t[n] = su.test(n) ? cu : r;
5949
5970
  return t;
5950
- }, $l = (e) => {
5971
+ }, uu = (e) => {
5951
5972
  let t = e?.id;
5952
5973
  return typeof t == "string" ? t : void 0;
5953
- }, eu = (e, t) => {
5974
+ }, du = (e, t) => {
5954
5975
  if (t.op === "insert") {
5955
- let n = $l(t.new);
5976
+ let n = uu(t.new);
5956
5977
  return n === void 0 ? e : e.filter((e) => e.id !== n);
5957
5978
  }
5958
5979
  if (t.op === "update") {
5959
5980
  if (t.old == null) return e;
5960
- let n = $l(t.new) ?? $l(t.old);
5981
+ let n = uu(t.new) ?? uu(t.old);
5961
5982
  return e.map((e) => e.id === n ? t.old : e);
5962
5983
  }
5963
5984
  return t.old == null ? e : [...e, t.old];
5964
- }, tu = class {
5985
+ }, fu = class {
5965
5986
  mode;
5966
5987
  capacity;
5967
5988
  now;
@@ -5981,8 +6002,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5981
6002
  ts: this.now(),
5982
6003
  table: e.table,
5983
6004
  op: e.op,
5984
- old: Ql(e.old),
5985
- new: Ql(e.new),
6005
+ old: lu(e.old),
6006
+ new: lu(e.new),
5986
6007
  tenantId: n
5987
6008
  }), this.ring.length > this.capacity && this.ring.shift(), t;
5988
6009
  }
@@ -5995,23 +6016,23 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
5995
6016
  }
5996
6017
  replay(e, t, n) {
5997
6018
  let r = this.ring.filter((n) => n.table === e && n.seq > t).sort((e, t) => t.seq - e.seq), i = n;
5998
- for (let e of r) i = eu(i, e);
6019
+ for (let e of r) i = du(i, e);
5999
6020
  return i;
6000
6021
  }
6001
- }, nu, ru = () => (nu === void 0 && (nu = new tu(Yl())), nu), iu = (e) => {
6002
- nu = e;
6003
- }, au = (e) => {
6004
- let t = ru();
6022
+ }, pu, mu = () => (pu === void 0 && (pu = new fu(ou())), pu), hu = (e) => {
6023
+ pu = e;
6024
+ }, gu = (e) => {
6025
+ let t = mu();
6005
6026
  if (t.enabled) try {
6006
6027
  t.record(e);
6007
6028
  } catch {}
6008
- }, ou = /* @__PURE__ */ new Set([
6029
+ }, _u = /* @__PURE__ */ new Set([
6009
6030
  "count",
6010
6031
  "sum",
6011
6032
  "avg",
6012
6033
  "min",
6013
6034
  "max"
6014
- ]), su = (e) => {
6035
+ ]), vu = (e) => {
6015
6036
  if (e.joins !== void 0 && e.joins.length > 0) return {
6016
6037
  maintainable: !1,
6017
6038
  reason: "joins are not maintainable in v1"
@@ -6033,7 +6054,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6033
6054
  reason: "v1 maintains exactly one aggregation"
6034
6055
  };
6035
6056
  let t = e.aggregations[0];
6036
- return ou.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
6057
+ return _u.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
6037
6058
  maintainable: !1,
6038
6059
  reason: `op '${t.op}' requires a column`
6039
6060
  } : {
@@ -6047,7 +6068,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6047
6068
  maintainable: !1,
6048
6069
  reason: `op '${t.op}' is not maintainable`
6049
6070
  };
6050
- }, cu = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(cu), lu = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), uu = (e, t) => {
6071
+ }, yu = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(yu), bu = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), xu = (e, t) => {
6051
6072
  switch (e.op) {
6052
6073
  case "count": return t.count;
6053
6074
  case "sum": return t.sum ?? 0;
@@ -6055,10 +6076,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6055
6076
  case "min":
6056
6077
  case "max": return t.count > 0 ? t.extreme ?? null : null;
6057
6078
  }
6058
- }, du = (e, t) => {
6079
+ }, Su = (e, t) => {
6059
6080
  let n = /* @__PURE__ */ new Map();
6060
6081
  for (let r of t) {
6061
- let t = $(r, e.groupBy), i = n.get(t), a = lu(r, e.column);
6082
+ let t = $(r, e.groupBy), i = n.get(t), a = bu(r, e.column);
6062
6083
  if (i === void 0) n.set(t, {
6063
6084
  count: 1,
6064
6085
  ...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
@@ -6074,10 +6095,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6074
6095
  }
6075
6096
  }
6076
6097
  return n;
6077
- }, fu = (e, t) => [...t.entries()].map(([t, n]) => ({
6098
+ }, Cu = (e, t) => [...t.entries()].map(([t, n]) => ({
6078
6099
  groupKey: t,
6079
- value: uu(e, n)
6080
- })), pu = (e, t, n) => {
6100
+ value: xu(e, n)
6101
+ })), wu = (e, t, n) => {
6081
6102
  let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
6082
6103
  let n = $(t, e.groupBy), a = r.get(n);
6083
6104
  if (a === void 0) return;
@@ -6086,7 +6107,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6086
6107
  r.delete(n);
6087
6108
  return;
6088
6109
  }
6089
- let s = lu(t, e.column);
6110
+ let s = bu(t, e.column);
6090
6111
  e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
6091
6112
  count: o,
6092
6113
  ...a.extreme === void 0 ? {} : { extreme: a.extreme }
@@ -6095,7 +6116,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6095
6116
  ...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
6096
6117
  });
6097
6118
  }, o = (t) => {
6098
- let n = $(t, e.groupBy), i = r.get(n), a = lu(t, e.column);
6119
+ let n = $(t, e.groupBy), i = r.get(n), a = bu(t, e.column);
6099
6120
  if (i === void 0) {
6100
6121
  r.set(n, {
6101
6122
  count: 1,
@@ -6115,15 +6136,15 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6115
6136
  state: r,
6116
6137
  rescanGroups: [...i]
6117
6138
  };
6118
- }, mu = (e, t, n, r) => {
6139
+ }, Tu = (e, t, n, r) => {
6119
6140
  if (n.length === 0) return t;
6120
- let i = new Set(n), a = du(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
6141
+ let i = new Set(n), a = Su(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
6121
6142
  for (let e of i) {
6122
6143
  let t = a.get(e);
6123
6144
  t === void 0 ? o.delete(e) : o.set(e, t);
6124
6145
  }
6125
6146
  return o;
6126
- }, hu = class {
6147
+ }, Eu = class {
6127
6148
  shape;
6128
6149
  state = /* @__PURE__ */ new Map();
6129
6150
  groups = /* @__PURE__ */ new Map();
@@ -6131,7 +6152,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6131
6152
  this.shape = e;
6132
6153
  }
6133
6154
  seed(e) {
6134
- this.state = du(this.shape, e), this.groups.clear();
6155
+ this.state = Su(this.shape, e), this.groups.clear();
6135
6156
  for (let t of e) {
6136
6157
  let e = $(t, this.shape.groupBy);
6137
6158
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
@@ -6143,14 +6164,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6143
6164
  let e = $(t, this.shape.groupBy);
6144
6165
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
6145
6166
  }
6146
- let n = pu(this.shape, this.state, e);
6167
+ let n = wu(this.shape, this.state, e);
6147
6168
  this.state = n.state;
6148
6169
  for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
6149
6170
  return n.rescanGroups;
6150
6171
  }
6151
6172
  resolveRescan(e, t) {
6152
6173
  if (e.length === 0) return;
6153
- this.state = mu(this.shape, this.state, e, t);
6174
+ this.state = Tu(this.shape, this.state, e, t);
6154
6175
  let n = new Set(e);
6155
6176
  for (let e of t) {
6156
6177
  let t = $(e, this.shape.groupBy);
@@ -6159,7 +6180,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6159
6180
  for (let e of n) this.state.has(e) || this.groups.delete(e);
6160
6181
  }
6161
6182
  materialize() {
6162
- return fu(this.shape, this.state).map((e) => ({
6183
+ return Cu(this.shape, this.state).map((e) => ({
6163
6184
  groupKey: e.groupKey,
6164
6185
  group: this.groups.get(e.groupKey) ?? {},
6165
6186
  value: e.value
@@ -6172,7 +6193,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6172
6193
  for (let r of t) n[r] = e[r];
6173
6194
  return n;
6174
6195
  }
6175
- }, gu = O("_voltro_rebac_tuples", {
6196
+ }, Du = O("_voltro_rebac_tuples", {
6176
6197
  id: y({ prefix: "rbct" }),
6177
6198
  subjectId: k(),
6178
6199
  relation: k(),
@@ -6184,7 +6205,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6184
6205
  "subjectId",
6185
6206
  "resourceType",
6186
6207
  "resourceId"
6187
- ]), _u = async (e, n, r, i) => n === null ? [] : (await e.query({
6208
+ ]), Ou = async (e, n, r, i) => n === null ? [] : (await e.query({
6188
6209
  table: "_voltro_rebac_tuples",
6189
6210
  predicate: t(d("subjectId", n), d("resourceType", r), d("resourceId", i)),
6190
6211
  order: [],
@@ -6196,16 +6217,16 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6196
6217
  relation: e.relation,
6197
6218
  resourceType: e.resourceType,
6198
6219
  resourceId: e.resourceId
6199
- })), vu = (e) => ({
6220
+ })), ku = (e) => ({
6200
6221
  id: e.id,
6201
6222
  tenantId: e.tenantId,
6202
6223
  ...e.scopes === void 0 ? {} : { scopes: e.scopes }
6203
- }), yu = (e, t) => {
6204
- let n = t.getPolicy ?? Hs;
6224
+ }), Au = (e, t) => {
6225
+ let n = t.getPolicy ?? qs;
6205
6226
  return (r, i) => {
6206
6227
  let a = e[i.tag];
6207
6228
  if (a === void 0) return r;
6208
- let o = n(a.resourceType), s = (e) => F.fail(new zs({
6229
+ let o = n(a.resourceType), s = (e) => P.fail(new Ws({
6209
6230
  action: a.action,
6210
6231
  resourceType: a.resourceType,
6211
6232
  resourceId: e
@@ -6213,17 +6234,17 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6213
6234
  if (o === void 0) return s("");
6214
6235
  let c = a.resourceId(i.input);
6215
6236
  if (c === null || c === "") return s("");
6216
- let l = vu(i.subject), u = {
6237
+ let l = ku(i.subject), u = {
6217
6238
  type: a.resourceType,
6218
6239
  id: c,
6219
6240
  tenantId: i.subject.tenantId
6220
6241
  };
6221
- return F.flatMap(F.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) => Js(l, a.action, u, {
6242
+ return P.flatMap(P.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) => $s(l, a.action, u, {
6222
6243
  policy: o,
6223
6244
  tuples: e
6224
6245
  }) ? r : s(c));
6225
6246
  };
6226
- }, bu = async (e, n, r) => n === null ? [] : (await e.query({
6247
+ }, ju = async (e, n, r) => n === null ? [] : (await e.query({
6227
6248
  table: "_voltro_rebac_tuples",
6228
6249
  predicate: t(d("subjectId", n), d("resourceType", r)),
6229
6250
  order: [],
@@ -6235,18 +6256,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6235
6256
  relation: e.relation,
6236
6257
  resourceType: e.resourceType,
6237
6258
  resourceId: e.resourceId
6238
- })), xu = (e) => {
6239
- let t = e.getPolicy ?? Hs;
6259
+ })), Mu = (e) => {
6260
+ let t = e.getPolicy ?? qs;
6240
6261
  return async (n, r, i, a) => {
6241
6262
  let o = t(r);
6242
6263
  if (o === void 0) return [];
6243
- let s = vu(n);
6244
- return Xs(s, i, r, a, {
6264
+ let s = ku(n);
6265
+ return tc(s, i, r, a, {
6245
6266
  policy: o,
6246
6267
  tuples: await e.loadSubjectTuples(s.id, r)
6247
6268
  });
6248
6269
  };
6249
- }, Su = (e) => {
6270
+ }, Nu = (e) => {
6250
6271
  if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
6251
6272
  if (e.watch === void 0 || typeof e.watch.table != "string" || e.watch.table.length === 0) throw Error(`reaction '${e.name}': watch.table is required`);
6252
6273
  if (e.act === void 0 || e.act.kind !== "agent" && e.act.kind !== "workflow") throw Error(`reaction '${e.name}': act must be { kind: 'agent' | 'workflow', … }`);
@@ -6254,14 +6275,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6254
6275
  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`);
6255
6276
  if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
6256
6277
  return e;
6257
- }, Cu = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, wu = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, Tu = class {
6278
+ }, Pu = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, Fu = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, Iu = class {
6258
6279
  hits = /* @__PURE__ */ new Map();
6259
6280
  allow(e, t, n, r) {
6260
6281
  let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
6261
6282
  return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
6262
6283
  }
6263
- }, Eu = async (e, t, n) => {
6264
- if (t.table !== e.watch.table || !Cu(e.watch.on, t.op)) return "skipped-op";
6284
+ }, Lu = async (e, t, n) => {
6285
+ if (t.table !== e.watch.table || !Pu(e.watch.on, t.op)) return "skipped-op";
6265
6286
  if (e.when !== void 0 && !e.when(t)) return "skipped-when";
6266
6287
  let r = `${e.name}:${e.guards.dedupeKey(t)}`;
6267
6288
  if (await n.dedupe.has(r)) return "skipped-dedupe";
@@ -6270,26 +6291,26 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6270
6291
  let t = n.now?.() ?? Date.now();
6271
6292
  if (!n.rateLimiter.allow(e.name, i.limit, i.windowMs, t)) return "skipped-ratelimit";
6272
6293
  }
6273
- let a = wu(t);
6294
+ let a = Fu(t);
6274
6295
  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, {
6275
6296
  id: a,
6276
6297
  via: "agent"
6277
6298
  }), await n.dedupe.add(r), "acted");
6278
- }, Du = O("_voltro_wakeups", {
6299
+ }, Ru = O("_voltro_wakeups", {
6279
6300
  id: y({ prefix: "wakeup" }),
6280
6301
  tenantId: k(),
6281
6302
  kind: k(),
6282
6303
  refId: k(),
6283
6304
  wakeAt: A(),
6284
6305
  status: k()
6285
- }).index(["status", "wakeAt"]).index(["tenantId"]), Ou = async (e) => {
6286
- let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await sl(e.store, t, e.batchLimit ?? 100);
6306
+ }).index(["status", "wakeAt"]).index(["tenantId"]), zu = async (e) => {
6307
+ let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await vl(e.store, t, e.batchLimit ?? 100);
6287
6308
  if (n.length === 0) return 0;
6288
6309
  let r = 0;
6289
- for (let t of n) if (await rl(e.store, t)) try {
6310
+ for (let t of n) if (await ml(e.store, t)) try {
6290
6311
  await e.adapter.wake(t), r++;
6291
6312
  } catch (n) {
6292
- await il(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
6313
+ await hl(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
6293
6314
  tenantId: t.tenantId,
6294
6315
  kind: t.kind,
6295
6316
  refId: t.refId,
@@ -6297,11 +6318,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6297
6318
  });
6298
6319
  }
6299
6320
  return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
6300
- }, ku = (e, t = 1e3) => {
6321
+ }, Bu = (e, t = 1e3) => {
6301
6322
  let n = !1, r, i = async () => {
6302
6323
  if (!n) {
6303
6324
  try {
6304
- await Ou(e);
6325
+ await zu(e);
6305
6326
  } catch (t) {
6306
6327
  e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
6307
6328
  }
@@ -6311,10 +6332,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6311
6332
  return i(), { stop: () => {
6312
6333
  n = !0, r !== void 0 && clearTimeout(r);
6313
6334
  } };
6314
- }, Au = (e) => ({ wake: async () => {
6335
+ }, Vu = (e) => ({ wake: async () => {
6315
6336
  await e.start();
6316
- } }), ju = (e) => new Promise((t) => setTimeout(t, e)), Mu = (e) => {
6317
- let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? ju, i = e.spawnImpl ?? It, 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 () => {
6337
+ } }), Hu = (e) => new Promise((t) => setTimeout(t, e)), Uu = (e) => {
6338
+ let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? Hu, i = e.spawnImpl ?? Lt, 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 () => {
6318
6339
  try {
6319
6340
  let n = await t(e.healthUrl);
6320
6341
  return d(n);
@@ -6368,11 +6389,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6368
6389
  },
6369
6390
  stop: m
6370
6391
  };
6371
- }, Nu = async (e) => {
6392
+ }, Wu = async (e) => {
6372
6393
  if (e.signals.connectedClients() > 0 || e.signals.inFlightRequests() > 0 || e.signals.activeWorkflowExecutions() > 0) return !1;
6373
- let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await cl(e.store);
6394
+ let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await yl(e.store);
6374
6395
  return !(n !== null && n.wakeAt.getTime() <= t);
6375
- }, Pu = (e, t = Date.now) => {
6396
+ }, Gu = (e, t = Date.now) => {
6376
6397
  let n;
6377
6398
  return {
6378
6399
  update: (r) => {
@@ -6384,7 +6405,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6384
6405
  n = void 0;
6385
6406
  }
6386
6407
  };
6387
- }, Fu = () => {
6408
+ }, Ku = () => {
6388
6409
  let e = 0, t = 0;
6389
6410
  return {
6390
6411
  onRequestStart: () => {
@@ -6402,8 +6423,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6402
6423
  inFlightRequests: () => e,
6403
6424
  openConnections: () => t
6404
6425
  };
6405
- }, Iu = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), Lu = (e, t, n, r) => new Promise((i, a) => {
6406
- let o = st.request({
6426
+ }, qu = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), Ju = (e, t, n, r) => new Promise((i, a) => {
6427
+ let o = ct.request({
6407
6428
  host: n,
6408
6429
  port: r,
6409
6430
  method: e.method,
@@ -6413,8 +6434,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6413
6434
  t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
6414
6435
  });
6415
6436
  o.on("error", a), e.pipe(o);
6416
- }), Ru = (e, t, n, r, i) => new Promise((a, o) => {
6417
- let s = st.request({
6437
+ }), Yu = (e, t, n, r, i) => new Promise((a, o) => {
6438
+ let s = ct.request({
6418
6439
  host: r,
6419
6440
  port: i,
6420
6441
  method: e.method,
@@ -6428,21 +6449,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6428
6449
  };
6429
6450
  t.on("close", s), r.on("close", s), r.on("error", o);
6430
6451
  }), s.on("error", o), s.end();
6431
- }), zu = (e) => {
6432
- let t = Iu({
6452
+ }), Xu = (e) => {
6453
+ let t = qu({
6433
6454
  ensureAwake: () => e.supervisor.start(),
6434
6455
  ...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
6435
- }), n = e.activity, r = st.createServer((r, i) => {
6436
- n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => Lu(r, i, e.targetHost, e.targetPort)).catch((t) => {
6456
+ }), n = e.activity, r = ct.createServer((r, i) => {
6457
+ n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => Ju(r, i, e.targetHost, e.targetPort)).catch((t) => {
6437
6458
  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");
6438
6459
  });
6439
6460
  });
6440
6461
  return r.on("upgrade", (r, i, a) => {
6441
- n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Ru(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
6462
+ n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Yu(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
6442
6463
  e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
6443
6464
  });
6444
6465
  }), r;
6445
- }, Bu = async (e) => {
6466
+ }, Zu = async (e) => {
6446
6467
  try {
6447
6468
  return (await e.query({
6448
6469
  table: "_voltro_workflow_runs",
@@ -6459,15 +6480,15 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6459
6480
  } catch {
6460
6481
  return 0;
6461
6482
  }
6462
- }, Vu = async (e) => {
6463
- let t = Au(e.supervisor), n = await Ou({
6483
+ }, Qu = async (e) => {
6484
+ let t = Vu(e.supervisor), n = await zu({
6464
6485
  store: e.store,
6465
6486
  adapter: t,
6466
6487
  ...e.now === void 0 ? {} : { now: e.now },
6467
6488
  ...e.log === void 0 ? {} : { log: e.log }
6468
6489
  });
6469
6490
  n > 0 && e.idleGate.reset();
6470
- let r = await Nu({
6491
+ let r = await Wu({
6471
6492
  store: e.store,
6472
6493
  signals: e.signals,
6473
6494
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
@@ -6477,12 +6498,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6477
6498
  woke: n,
6478
6499
  stopped: i
6479
6500
  };
6480
- }, Hu = async (e) => {
6481
- let t = Pu(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = Fu(), i = 0, a = e.signals === void 0, o = e.signals ?? {
6501
+ }, $u = async (e) => {
6502
+ let t = Gu(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = Ku(), i = 0, a = e.signals === void 0, o = e.signals ?? {
6482
6503
  connectedClients: () => r.openConnections(),
6483
6504
  inFlightRequests: () => r.inFlightRequests(),
6484
6505
  activeWorkflowExecutions: () => i
6485
- }, s = zu({
6506
+ }, s = Xu({
6486
6507
  supervisor: e.supervisor,
6487
6508
  targetHost: e.targetHost,
6488
6509
  targetPort: e.targetPort,
@@ -6501,7 +6522,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6501
6522
  let l = !1, u, d = e.firedRetentionMs ?? 10 * 6e4, f = 0, p = async () => {
6502
6523
  if (!l) {
6503
6524
  try {
6504
- if (a && (i = await Bu(e.store)), await Vu({
6525
+ if (a && (i = await Zu(e.store)), await Qu({
6505
6526
  store: e.store,
6506
6527
  supervisor: e.supervisor,
6507
6528
  signals: o,
@@ -6509,7 +6530,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6509
6530
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
6510
6531
  ...e.log === void 0 ? {} : { log: e.log }
6511
6532
  }), f++ % 60 == 0) {
6512
- let t = await ul(e.store, { firedOlderThan: new Date(Date.now() - d) });
6533
+ let t = await xl(e.store, { firedOlderThan: new Date(Date.now() - d) });
6513
6534
  t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
6514
6535
  }
6515
6536
  } catch (t) {
@@ -6524,14 +6545,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6524
6545
  l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
6525
6546
  }
6526
6547
  };
6527
- }, Uu = (e) => e, Wu = class extends z.TaggedError()("AnalyticsError", {
6528
- provider: z.String,
6529
- operation: z.String,
6530
- cause: z.String
6531
- }) {}, Gu = class extends z.TaggedError()("AnalyticsCapabilityNotSupported", {
6532
- provider: z.String,
6533
- capability: z.String
6534
- }) {}, Ku = class extends Ye.Tag("@voltro/AnalyticsSink")() {}, qu = (e, t) => ({
6548
+ }, ed = (e) => e, td = class extends R.TaggedError()("AnalyticsError", {
6549
+ provider: R.String,
6550
+ operation: R.String,
6551
+ cause: R.String
6552
+ }) {}, nd = class extends R.TaggedError()("AnalyticsCapabilityNotSupported", {
6553
+ provider: R.String,
6554
+ capability: R.String
6555
+ }) {}, rd = class extends Ye.Tag("@voltro/AnalyticsSink")() {}, id = (e, t) => ({
6535
6556
  info: e.info,
6536
6557
  track: (n) => e.track(n.tenantId === void 0 ? {
6537
6558
  ...n,
@@ -6550,20 +6571,20 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6550
6571
  tenantId: t
6551
6572
  } : n),
6552
6573
  ...e.mirror === void 0 ? {} : { mirror: e.mirror }
6553
- }), Ju = () => F.gen(function* () {
6554
- let e = yield* Ku, t = yield* F.serviceOption(Ne), n = it.match(t, {
6574
+ }), ad = () => P.gen(function* () {
6575
+ let e = yield* rd, t = yield* P.serviceOption(Ne), n = at.match(t, {
6555
6576
  onNone: () => null,
6556
6577
  onSome: (e) => e.tenantId ?? null
6557
6578
  });
6558
- return n === null ? e : qu(e, n);
6559
- }), Yu = "noop", Xu = () => {
6560
- let e = (e) => F.fail(new Gu({
6561
- provider: Yu,
6579
+ return n === null ? e : id(e, n);
6580
+ }), od = "noop", sd = () => {
6581
+ let e = (e) => P.fail(new nd({
6582
+ provider: od,
6562
6583
  capability: e
6563
6584
  }));
6564
6585
  return {
6565
6586
  info: {
6566
- provider: Yu,
6587
+ provider: od,
6567
6588
  capabilities: {
6568
6589
  track: !0,
6569
6590
  aggregate: !1,
@@ -6572,13 +6593,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6572
6593
  mirror: !1
6573
6594
  }
6574
6595
  },
6575
- track: () => F.void,
6596
+ track: () => P.void,
6576
6597
  aggregate: () => e("aggregate"),
6577
6598
  timeseries: () => e("timeseries"),
6578
6599
  topN: () => e("topN")
6579
6600
  };
6580
- }, Zu = (e) => {
6581
- if (e.length === 0) return Xu();
6601
+ }, cd = (e) => {
6602
+ if (e.length === 0) return sd();
6582
6603
  if (e.length === 1) return e[0];
6583
6604
  let t = {
6584
6605
  provider: "compose",
@@ -6590,22 +6611,22 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6590
6611
  mirror: e.some((e) => e.info.capabilities.mirror)
6591
6612
  },
6592
6613
  detail: { members: e.map((e) => e.info) }
6593
- }, n = (t) => F.forEach(e, (e) => e.track(t).pipe(F.catchAll((t) => F.logWarning(`analytics-sink ${e.info.provider} track failed`, { err: t }))), {
6614
+ }, n = (t) => P.forEach(e, (e) => e.track(t).pipe(P.catchAll((t) => P.logWarning(`analytics-sink ${e.info.provider} track failed`, { err: t }))), {
6594
6615
  concurrency: "unbounded",
6595
6616
  discard: !0
6596
6617
  }), r = (t, n) => {
6597
6618
  let r = e.find((e) => e.info.capabilities[t]);
6598
- return r === void 0 ? F.fail(new Gu({
6619
+ return r === void 0 ? P.fail(new nd({
6599
6620
  provider: "compose",
6600
6621
  capability: t
6601
6622
  })) : n(r);
6602
6623
  }, i = e.filter((e) => e.mirror !== void 0), a = i.length === 0 ? void 0 : {
6603
6624
  tables: Array.from(new Set(i.flatMap((e) => e.mirror.tables))),
6604
- upsert: (e, t) => F.forEach(i.filter((t) => t.mirror.tables.includes(e)), (n) => n.mirror.upsert(e, t), {
6625
+ upsert: (e, t) => P.forEach(i.filter((t) => t.mirror.tables.includes(e)), (n) => n.mirror.upsert(e, t), {
6605
6626
  concurrency: "unbounded",
6606
6627
  discard: !0
6607
6628
  }),
6608
- remove: (e, t) => F.forEach(i.filter((t) => t.mirror.tables.includes(e)), (n) => n.mirror.remove(e, t), {
6629
+ remove: (e, t) => P.forEach(i.filter((t) => t.mirror.tables.includes(e)), (n) => n.mirror.remove(e, t), {
6609
6630
  concurrency: "unbounded",
6610
6631
  discard: !0
6611
6632
  })
@@ -6618,42 +6639,42 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6618
6639
  topN: (e) => r("topN", (t) => t.topN(e)),
6619
6640
  ...a === void 0 ? {} : { mirror: a }
6620
6641
  };
6621
- }, Qu = (e) => {
6642
+ }, ld = (e) => {
6622
6643
  let t = e.filter((e) => e.dispose !== void 0);
6623
6644
  return {
6624
6645
  kind: "compose",
6625
- build: (t) => Zu(e.map((e) => e.build(t))),
6646
+ build: (t) => cd(e.map((e) => e.build(t))),
6626
6647
  tables: e.flatMap((e) => e.tables ?? []),
6627
- initialize: (t) => F.forEach(e, (e) => e.initialize ? e.initialize(t) : F.void, {
6648
+ initialize: (t) => P.forEach(e, (e) => e.initialize ? e.initialize(t) : P.void, {
6628
6649
  concurrency: 1,
6629
6650
  discard: !0
6630
6651
  }),
6631
- ...t.length > 0 ? { dispose: (e) => F.forEach(t, (t) => t.dispose(e), {
6652
+ ...t.length > 0 ? { dispose: (e) => P.forEach(t, (t) => t.dispose(e), {
6632
6653
  concurrency: 1,
6633
6654
  discard: !0
6634
6655
  }) } : {}
6635
6656
  };
6636
- }, $u = {
6657
+ }, ud = {
6637
6658
  kind: "noop",
6638
- build: () => Xu()
6639
- }, ed = {
6659
+ build: () => sd()
6660
+ }, dd = {
6640
6661
  tables: [],
6641
6662
  detach: () => {}
6642
- }, td = (e) => {
6663
+ }, fd = (e) => {
6643
6664
  let { store: t, sink: n, log: r } = e, i = n.mirror;
6644
- if (i === void 0 || i.tables.length === 0) return ed;
6645
- let a = e.run ?? ((e) => F.runPromise(e)), o = i.primaryKey ?? "id", s = new Set(i.tables), c = (e) => {
6665
+ if (i === void 0 || i.tables.length === 0) return dd;
6666
+ let a = e.run ?? ((e) => P.runPromise(e)), o = i.primaryKey ?? "id", s = new Set(i.tables), c = (e) => {
6646
6667
  if (e.op === "delete") {
6647
6668
  let t = e.old;
6648
- if (t === null) return F.void;
6669
+ if (t === null) return P.void;
6649
6670
  let n = t[o];
6650
- return n === void 0 ? F.void : i.remove(e.table, n);
6671
+ return n === void 0 ? P.void : i.remove(e.table, n);
6651
6672
  }
6652
6673
  let t = e.new;
6653
- return t === null ? F.void : i.upsert(e.table, t);
6674
+ return t === null ? P.void : i.upsert(e.table, t);
6654
6675
  }, l = t.onChange((e) => {
6655
6676
  if (!s.has(e.table)) return;
6656
- let t = c(e).pipe(F.catchAll((t) => F.sync(() => r.warn("analytics-mirror: change forward failed", {
6677
+ let t = c(e).pipe(P.catchAll((t) => P.sync(() => r.warn("analytics-mirror: change forward failed", {
6657
6678
  provider: n.info.provider,
6658
6679
  table: e.table,
6659
6680
  op: e.op,
@@ -6665,11 +6686,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6665
6686
  tables: i.tables,
6666
6687
  detach: l
6667
6688
  };
6668
- }, nd = (e) => {
6689
+ }, pd = (e) => {
6669
6690
  let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
6670
6691
  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`);
6671
6692
  if (e.incremental !== void 0) {
6672
- let t = su({
6693
+ let t = vu({
6673
6694
  aggregations: [{
6674
6695
  op: e.incremental.op,
6675
6696
  ...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
@@ -6691,51 +6712,51 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6691
6712
  build: e.build,
6692
6713
  ...e.incremental === void 0 ? {} : { incremental: e.incremental }
6693
6714
  };
6694
- }, rd = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, id = class extends z.TaggedError()("AggregateStale", {
6695
- name: z.String,
6696
- ageMs: z.Number,
6697
- maxAgeMs: z.Number
6698
- }) {}, ad = class extends z.TaggedError()("AggregateNotFound", { name: z.String }) {}, od = class extends z.TaggedError()("AggregateError", {
6699
- name: z.String,
6700
- operation: z.String,
6701
- cause: z.String
6702
- }) {}, sd = class extends Ye.Tag("@voltro/AggregateRegistry")() {}, cd = (e) => F.gen(function* () {
6703
- return (yield* sd).getHandle(e);
6704
- }), ld = (e, n, r) => {
6715
+ }, md = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, hd = class extends R.TaggedError()("AggregateStale", {
6716
+ name: R.String,
6717
+ ageMs: R.Number,
6718
+ maxAgeMs: R.Number
6719
+ }) {}, gd = class extends R.TaggedError()("AggregateNotFound", { name: R.String }) {}, _d = class extends R.TaggedError()("AggregateError", {
6720
+ name: R.String,
6721
+ operation: R.String,
6722
+ cause: R.String
6723
+ }) {}, vd = class extends Ye.Tag("@voltro/AggregateRegistry")() {}, yd = (e) => P.gen(function* () {
6724
+ return (yield* vd).getHandle(e);
6725
+ }), bd = (e, n, r) => {
6705
6726
  if (e.crossTenant || !n.has(e.table) || r == null) return e;
6706
6727
  let i = d("tenantId", r);
6707
6728
  return {
6708
6729
  ...e,
6709
6730
  predicate: e.predicate ? t(e.predicate, i) : i
6710
6731
  };
6711
- }, ud = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), dd = (e) => e?.type === "user" && e.tenantId === "", fd = (e, n) => {
6732
+ }, xd = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Sd = (e) => e?.type === "user" && e.tenantId === "", Cd = (e, n) => {
6712
6733
  if (e.includeDeleted || !n.has(e.table)) return e;
6713
6734
  let r = C("deletedAt");
6714
6735
  return {
6715
6736
  ...e,
6716
6737
  predicate: e.predicate ? t(e.predicate, r) : r
6717
6738
  };
6718
- }, pd = (e, t) => t, md = (e) => F.runPromiseExit(e).then((e) => {
6719
- if ($e.isSuccess(e)) return e.value;
6739
+ }, wd = (e, t) => t, Td = (e) => P.runPromiseExit(e).then((e) => {
6740
+ if (et.isSuccess(e)) return e.value;
6720
6741
  let t = N.failureOption(e.cause);
6721
- throw it.isSome(t) ? t.value : N.squash(e.cause);
6722
- }), hd = (e, t) => e.pipe(F.provideService(Ne, t)), gd = async (e, t, n) => {
6723
- let r = await F.runPromise(Re(t, e.guards, n));
6742
+ throw at.isSome(t) ? t.value : N.squash(e.cause);
6743
+ }), Ed = (e, t) => e.pipe(P.provideService(Ne, t)), Dd = async (e, t, n) => {
6744
+ let r = await P.runPromise(Re(t, e.guards, n));
6724
6745
  if (r) throw r;
6725
- }, _d = async (e) => {
6746
+ }, Od = async (e) => {
6726
6747
  if (Gn() === void 0) return e;
6727
- let t = await md(qn(e.subject, (e) => {
6748
+ let t = await Td(qn(e.subject, (e) => {
6728
6749
  console.error("[voltro] row filter failed to load", e);
6729
6750
  }));
6730
6751
  return {
6731
6752
  ...e,
6732
6753
  rowFilter: t
6733
6754
  };
6734
- }, vd = async (e) => {
6755
+ }, kd = async (e) => {
6735
6756
  let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
6736
6757
  try {
6737
6758
  if (e.interceptor) {
6738
- let t = F.tryPromise({
6759
+ let t = P.tryPromise({
6739
6760
  try: () => e.runExecutor(),
6740
6761
  catch: (e) => e
6741
6762
  }), n = e.interceptor(t, {
@@ -6745,8 +6766,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6745
6766
  subject: e.requestContext.subject,
6746
6767
  traceId: e.requestContext.traceId,
6747
6768
  ...e.requestContext.spanId === void 0 ? {} : { spanId: e.requestContext.spanId }
6748
- }), r = await F.runPromiseExit(n);
6749
- if ($e.isSuccess(r)) return r.value;
6769
+ }), r = await P.runPromiseExit(n);
6770
+ if (et.isSuccess(r)) return r.value;
6750
6771
  throw N.squash(r.cause);
6751
6772
  }
6752
6773
  return await e.runExecutor();
@@ -6760,28 +6781,28 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6760
6781
  status: r
6761
6782
  });
6762
6783
  }
6763
- }, yd = /* @__PURE__ */ new Set([1213, 1205]), bd = /* @__PURE__ */ new Set([
6784
+ }, Ad = /* @__PURE__ */ new Set([1213, 1205]), jd = /* @__PURE__ */ new Set([
6764
6785
  "ER_LOCK_DEADLOCK",
6765
6786
  "ER_LOCK_WAIT_TIMEOUT",
6766
6787
  "40001",
6767
6788
  "40P01"
6768
- ]), xd = (e) => {
6789
+ ]), Md = (e) => {
6769
6790
  let t = e;
6770
6791
  for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
6771
6792
  let e = t;
6772
- if (typeof e.errno == "number" && yd.has(e.errno) || typeof e.code == "string" && bd.has(e.code) || typeof e.sqlState == "string" && bd.has(e.sqlState)) return !0;
6793
+ if (typeof e.errno == "number" && Ad.has(e.errno) || typeof e.code == "string" && jd.has(e.code) || typeof e.sqlState == "string" && jd.has(e.sqlState)) return !0;
6773
6794
  t = e.cause;
6774
6795
  }
6775
6796
  return !1;
6776
- }, Sd = 3, Cd = (e) => new Promise((t) => setTimeout(t, e)), wd = async (e, t) => {
6777
- let n = t?.delay ?? ((e) => Cd(e * 20 + Math.floor(Math.random() * 30)));
6797
+ }, Nd = 3, Pd = (e) => new Promise((t) => setTimeout(t, e)), Fd = async (e, t) => {
6798
+ let n = t?.delay ?? ((e) => Pd(e * 20 + Math.floor(Math.random() * 30)));
6778
6799
  for (let t = 1;; t++) try {
6779
6800
  return await e();
6780
6801
  } catch (e) {
6781
- if (t >= Sd || !xd(e)) throw e;
6802
+ if (t >= Nd || !Md(e)) throw e;
6782
6803
  await n(t);
6783
6804
  }
6784
- }, Td = (e) => (t, n, r) => vd({
6805
+ }, Id = (e) => (t, n, r) => kd({
6785
6806
  name: t.descriptor.name,
6786
6807
  kind: "mutation",
6787
6808
  input: n,
@@ -6789,11 +6810,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6789
6810
  ...e.interceptor ? { interceptor: e.interceptor } : {},
6790
6811
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
6791
6812
  runExecutor: async () => {
6792
- await gd(t.descriptor, r.subject, n);
6793
- let i = await _d(r), a = [], o = await wd(async () => (a.length = 0, e.store.transactional(async (o) => {
6813
+ await Dd(t.descriptor, r.subject, n);
6814
+ let i = await Od(r), a = [], o = await Fd(async () => (a.length = 0, e.store.transactional(async (o) => {
6794
6815
  let s = e.undoCapture?.(o), c = s ? s.tx : o, l = e.buildContext(i, c, { afterCommit: (e) => {
6795
6816
  a.push(e);
6796
- } }), u = t.executor(n, l), d = F.isEffect(u) ? await e.runEffect(hd(u, r.subject), l.store) : await u;
6817
+ } }), u = t.executor(n, l), d = P.isEffect(u) ? await e.runEffect(Ed(u, r.subject), l.store) : await u;
6797
6818
  return s && await s.persist(l.store, {
6798
6819
  tag: t.descriptor.name,
6799
6820
  subject: r.subject,
@@ -6803,42 +6824,42 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6803
6824
  for (let e of a) await e();
6804
6825
  return o;
6805
6826
  }
6806
- }), Ed = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, Dd = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, Od = (e) => {
6827
+ }), Ld = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, Rd = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, zd = (e) => {
6807
6828
  let t = e.descriptor.source;
6808
6829
  return t == null ? [] : typeof t == "string" ? [t] : [...t];
6809
- }, kd = (e, t) => (n) => () => {
6830
+ }, Bd = (e, t) => (n) => () => {
6810
6831
  let r = e.descriptor.guards;
6811
- return !r || r.length === 0 ? Promise.resolve(null) : F.runPromise(Re(n, r, t));
6812
- }, Ad = (e) => (t, n) => (r) => {
6813
- let i = e.buildContext(r), a = kd(t, n)(r.subject), o = async () => {
6832
+ return !r || r.length === 0 ? Promise.resolve(null) : P.runPromise(Re(n, r, t));
6833
+ }, Vd = (e) => (t, n) => (r) => {
6834
+ let i = e.buildContext(r), a = Bd(t, n)(r.subject), o = async () => {
6814
6835
  let i = await a();
6815
6836
  if (i) throw i;
6816
- let o = e.buildContext(await _d(r)), s = t.executor(n, o);
6817
- return F.isEffect(s) ? F.runPromise(e.provideEffect(hd(s, r.subject), o.store)) : Ed(await Promise.resolve(s));
6837
+ let o = e.buildContext(await Od(r)), s = t.executor(n, o);
6838
+ return P.isEffect(s) ? P.runPromise(e.provideEffect(Ed(s, r.subject), o.store)) : Ld(await Promise.resolve(s));
6818
6839
  }, s = (n) => {
6819
- let i = Ed(n);
6820
- return Dd(i) ? e.finalize(i, r) : {
6840
+ let i = Ld(n);
6841
+ return Rd(i) ? e.finalize(i, r) : {
6821
6842
  __voltroComputed: !0,
6822
6843
  value: i,
6823
- dependentTables: Od(t),
6844
+ dependentTables: zd(t),
6824
6845
  tenantId: r.subject?.tenantId ?? null,
6825
6846
  recompute: o
6826
6847
  };
6827
6848
  }, c = () => {
6828
6849
  let a = t.executor(n, i);
6829
- return F.isEffect(a) ? e.provideEffect(hd(a, r.subject), i.store).pipe(F.map(s)) : a instanceof Promise ? F.promise(() => a).pipe(F.map(s)) : s(a);
6850
+ return P.isEffect(a) ? e.provideEffect(Ed(a, r.subject), i.store).pipe(P.map(s)) : a instanceof Promise ? P.promise(() => a).pipe(P.map(s)) : s(a);
6830
6851
  }, l = () => {
6831
6852
  let e = t.descriptor.guards;
6832
- return !e || e.length === 0 ? c() : Re(r.subject, e, n).pipe(F.flatMap((e) => {
6833
- if (e) return F.fail(e);
6853
+ return !e || e.length === 0 ? c() : Re(r.subject, e, n).pipe(P.flatMap((e) => {
6854
+ if (e) return P.fail(e);
6834
6855
  let t = c();
6835
- return F.isEffect(t) ? t : F.succeed(t);
6856
+ return P.isEffect(t) ? t : P.succeed(t);
6836
6857
  }));
6837
6858
  };
6838
6859
  if (!e.interceptor) return l();
6839
- let u = F.suspend(() => {
6860
+ let u = P.suspend(() => {
6840
6861
  let e = l();
6841
- return F.isEffect(e) ? e : F.succeed(e);
6862
+ return P.isEffect(e) ? e : P.succeed(e);
6842
6863
  });
6843
6864
  return e.interceptor(u, {
6844
6865
  tag: t.descriptor.name,
@@ -6848,14 +6869,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6848
6869
  traceId: r.traceId,
6849
6870
  ...r.spanId === void 0 ? {} : { spanId: r.spanId }
6850
6871
  });
6851
- }, jd = (e) => async (t, n, r) => {
6852
- let i = await _d(r), a = Ad(e)(t, n)(i), o = F.isEffect(a) ? await md(a) : a;
6872
+ }, Hd = (e) => async (t, n, r) => {
6873
+ let i = await Od(r), a = Vd(e)(t, n)(i), o = P.isEffect(a) ? await Td(a) : a;
6853
6874
  return rr(o) ? o.value : e.queryRows(o);
6854
- }, Md = (e) => (t, n, r, i) => {
6875
+ }, Ud = (e) => (t, n, r, i) => {
6855
6876
  let a = !1, o;
6856
6877
  return (async () => {
6857
6878
  try {
6858
- let s = await _d(r), c = Ad(e)(t, n)(s), l = F.isEffect(c) ? await md(c) : c, u = (e) => i(e), d = rr(l) ? await e.subscribeComputed(l, u, s) : await e.subscribeDescriptor(l, u, s);
6879
+ let s = await Od(r), c = Vd(e)(t, n)(s), l = P.isEffect(c) ? await Td(c) : c, u = (e) => i(e), d = rr(l) ? await e.subscribeComputed(l, u, s) : await e.subscribeDescriptor(l, u, s);
6859
6880
  a ? d() : o = d;
6860
6881
  } catch (e) {
6861
6882
  i({
@@ -6866,7 +6887,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6866
6887
  })(), () => {
6867
6888
  a = !0, o?.();
6868
6889
  };
6869
- }, Nd = (e) => (t, n, r) => vd({
6890
+ }, Wd = (e) => (t, n, r) => kd({
6870
6891
  name: t.descriptor.name,
6871
6892
  kind: "action",
6872
6893
  input: n,
@@ -6874,16 +6895,16 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6874
6895
  ...e.interceptor ? { interceptor: e.interceptor } : {},
6875
6896
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
6876
6897
  runExecutor: async () => {
6877
- await gd(t.descriptor, r.subject, n);
6878
- let i = e.buildContext(await _d(r)), a = t.executor(n, i);
6879
- return F.isEffect(a) ? e.runEffect(hd(a, r.subject), i.store) : a;
6898
+ await Dd(t.descriptor, r.subject, n);
6899
+ let i = e.buildContext(await Od(r)), a = t.executor(n, i);
6900
+ return P.isEffect(a) ? e.runEffect(Ed(a, r.subject), i.store) : a;
6880
6901
  }
6881
- }), Pd = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, Fd = (e) => typeof e == "string" && e.length > 0 ? e : null, Id = [
6902
+ }), Gd = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, Kd = (e) => typeof e == "string" && e.length > 0 ? e : null, qd = [
6882
6903
  "updatedAt",
6883
6904
  "createdAt",
6884
6905
  "updatedBy",
6885
6906
  "createdBy"
6886
- ], Ld = (e) => Id.some((t) => t in e), Rd = (e, t, n) => {
6907
+ ], Jd = (e) => qd.some((t) => t in e), Yd = (e, t, n) => {
6887
6908
  let r = {
6888
6909
  table: t.table,
6889
6910
  id: t.id,
@@ -6898,14 +6919,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6898
6919
  found: !1
6899
6920
  };
6900
6921
  let i = t.column === void 0 ? void 0 : e[t.column];
6901
- if (!Ld(e)) return {
6922
+ if (!Jd(e)) return {
6902
6923
  ...r,
6903
6924
  value: i,
6904
6925
  lastWrite: null,
6905
6926
  attribution: "none",
6906
6927
  found: !0
6907
6928
  };
6908
- let a = Fd(e.updatedBy) ?? Fd(e.createdBy), o = Pd(e.updatedAt) ?? Pd(e.createdAt);
6929
+ let a = Kd(e.updatedBy) ?? Kd(e.createdBy), o = Gd(e.updatedAt) ?? Gd(e.createdAt);
6909
6930
  return {
6910
6931
  ...r,
6911
6932
  value: i,
@@ -6917,12 +6938,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6917
6938
  attribution: "audit",
6918
6939
  found: !0
6919
6940
  };
6920
- }, zd = (e, t) => {
6941
+ }, Xd = (e, t) => {
6921
6942
  let n = e.map((e) => {
6922
6943
  let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
6923
6944
  return {
6924
- actor: { id: Fd(e.actor) ?? Fd(e.changedBy) },
6925
- at: Pd(e.at) ?? Pd(e.changedAt),
6945
+ actor: { id: Kd(e.actor) ?? Kd(e.changedBy) },
6946
+ at: Gd(e.at) ?? Gd(e.changedAt),
6926
6947
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
6927
6948
  value: r
6928
6949
  };
@@ -6937,12 +6958,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6937
6958
  history: n,
6938
6959
  found: n.length > 0
6939
6960
  };
6940
- }, Bd = (e) => {
6961
+ }, Zd = (e) => {
6941
6962
  let t = e.new?.id;
6942
6963
  if (typeof t == "string") return t;
6943
6964
  let n = e.old?.id;
6944
6965
  return typeof n == "string" ? n : void 0;
6945
- }, Vd = (e) => {
6966
+ }, Qd = (e) => {
6946
6967
  let t = {};
6947
6968
  if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
6948
6969
  from: void 0,
@@ -6962,11 +6983,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6962
6983
  return {
6963
6984
  table: e.table,
6964
6985
  op: e.op,
6965
- id: Bd(e),
6986
+ id: Zd(e),
6966
6987
  fields: t
6967
6988
  };
6968
- }, Hd = (e) => {
6969
- let t = e.map(Vd);
6989
+ }, $d = (e) => {
6990
+ let t = e.map(Qd);
6970
6991
  return {
6971
6992
  rows: t,
6972
6993
  summary: {
@@ -6975,21 +6996,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
6975
6996
  deletes: t.filter((e) => e.op === "delete").length
6976
6997
  }
6977
6998
  };
6978
- }, Ud = class extends Error {
6999
+ }, ef = class extends Error {
6979
7000
  constructor() {
6980
7001
  super("voltro:preview-rollback"), this.name = "PreviewRollback";
6981
7002
  }
6982
- }, Wd = async (e, t) => {
7003
+ }, tf = async (e, t) => {
6983
7004
  let n, r = !1;
6984
7005
  try {
6985
7006
  await e.transactional(async (e) => {
6986
- throw n = await t(e), r = !0, new Ud();
7007
+ throw n = await t(e), r = !0, new ef();
6987
7008
  });
6988
7009
  } catch (e) {
6989
- if (!(e instanceof Ud)) throw e;
7010
+ if (!(e instanceof ef)) throw e;
6990
7011
  }
6991
7012
  if (!r) throw Error("preview: handler did not complete");
6992
7013
  return n;
6993
- }, Gd = "framework-runtime";
7014
+ }, nf = "framework-runtime";
6994
7015
  //#endregion
6995
- export { Aa as API_KEYS_TABLE, zs as AccessDenied, od as AggregateError, hu as AggregateMaintainer, ad as AggregateNotFound, sd as AggregateRegistry, id as AggregateStale, Gu as AnalyticsCapabilityNotSupported, Wu as AnalyticsError, Ku as AnalyticsSink, X as CONNECTIONS_TABLE, Ro as CONNECTION_GRANTS_TABLE, Ic as CircuitBreaker, Pc as CircuitOpen, ss as ConnectionNotConnected, Wi as DEFAULT_MAX_RPC_BODY_BYTES, as as DEFAULT_REFRESH_SKEW_MS, Hn as DEFAULT_ROW_FILTER_RETRY, fl as DORMANCY_WAKEUP_TENANT, Qr as DeleteBuilder, er as Dispatcher, Ga as EffectStore, ys as GRANT_TTL_MS, nn as InMemoryDataStore, Wt as IndexedMatcher, Lt as LinearScanMatcher, nt as MetricBoundaries, Yu as NOOP_ANALYTICS_PROVIDER, Kn as NO_ROW_FILTER, Gr as NoRowFound, Co as OUTBOX_ATTEMPTS_TABLE, Ao as OUTBOX_ATTEMPT_LOG_CAP, Y as OUTBOX_TABLE, Kr as OptimisticLockError, Rs as REBAC_ADMIN_SCOPE, os as REFRESH_LEASE_MS, Gd as RUNTIME_NAME, Tu as ReactionRateLimiter, yi as ReplicatedDataStore, Vn as RowFilterUnavailable, dl as SCHEDULE_SUBJECT, Wa as SYSTEM_SUBJECT, Xr as SelectBuilder, oc as SsrfBlockedError, ti as StoreOperationFailed, qt as SubscriptionRegistry, ni as TableValidationFailed, ei as TenantScopeViolation, tu as TimelineRecorder, Pl as UndoBoundaryError, Il as UndoStack, Zr as UpdateBuilder, pc as VOLTRO_AUDIT_MIXIN_ID, mc as VOLTRO_SOFT_DELETE_MIXIN_ID, hc as VOLTRO_TENANT_MIXIN_ID, to as WorkflowPayloadError, hr as _connectionStreamCount, gr as _resetConnectionSubjectsForTest, Bo as _voltroConnectionGrantsTable, Lo as _voltroConnectionsTable, gu as _voltroRebacTuplesTable, Cl as _voltroScheduleClaimsTable, Sl as _voltroScheduleRunsTable, wl as _voltroTracesTable, Tl as _voltroUndoLogTable, Du as _voltroWakeupsTable, vo as _voltroWorkflowEventDeliveriesTable, _o as _voltroWorkflowEventsTable, ci as actingUserId, Ua as apiKeyManagementRoutes, ai as applyDefined, pu as applyDelta, Rl as applyInverse, zl as applyInverses, Xn as applyRowFilter, Zn as applyRowFilterToDescriptor, fd as applySoftDeleteScope, ld as applyTenantScope, ql as applyUndoInvocation, Ys as assertCan, Wo as assertConnectionCipherConfigured, td as attachAnalyticsMirror, Yi as awaitServerListening, ko as backoffMs, Cs as beginOAuthConnect, cr as bindConnectionSubject, Ui as bindMutation, Fi as bindStream, Pi as bindSubscription, ki as bindSubscriptionUntyped, du as buildIvmState, Hd as buildPreview, yu as buildRebacInterceptor, xu as buildRebacReadFilter, pi as buildSubjectKey, ea as buildTracingLayer, ha as cachedBackend, Js as can, el as cancelWakeup, su as classifyShape, ds as clearConnectionRefreshFlights, Ws as clearResourcePolicies, a as clearRetentions, zc as clearSystemStoreHandle, Yc as compileCron, ws as completeOAuthConnect, Qu as composeAnalytics, Zu as composeAnalyticsSinks, bs as connectionCallbackPath, Uo as connectionLabel, _r as connectionSubjectsSnapshot, Bu as countRunningWorkflows, Fn as counter, kc as crud, vi as currentRoutingContext, wr as currentTraceContext, Ba as dataStoreApiKeyStore, Sa as dataStoreIdempotencyStore, Da as dataStoreKvStore, Mr as decryptField, nd as defineAggregate, Ho as defineConnection, fo as defineEventTrigger, pd as defineExecutor, Eo as defineOutboxHandler, Su as defineReaction, Vs as defineResourcePolicy, Jc as defineSchedule, Uu as defineSubscriber, Qn as deliveredRowCount, Tr as deriveKey, Vd as diffChange, Po as drainOutbox, sl as dueWakeups, qs as effectiveRelations, bc as emptySchemaRegistry, Rr as enableGraphObservation, jr as encryptField, la as envSecretsBackend, rs as exchangeAuthorizationCode, xr as externalSpanFromTraceparent, an as extractDbCause, Kt as fingerprintFor, $o as forgetCredential, Nc as formatServerOnlyLeaks, yr as formatTraceparent, Ll as forwardChangeFromCdc, Va as frameworkApiKeyStrategy, In as gauge, Ma as generateApiKeyToken, Os as getConnectionResolver, lr as getConnectionSubject, q as getFieldCipher, Hs as getResourcePolicy, Gn as getRowFilter, Bc as getSystemStoreHandle, ru as getTimelineRecorder, tc as getTupleSource, $ as groupKeyOf, Ln as histogramMetric, zd as historyProvenance, ga as httpSecretsBackend, Ft as inspectWorkflow, nc as installPolicyGuardResolver, mr as interruptConnectionStreams, Ml as invertChange, rd as isAggregateDefinition, ud as isEmptyTenantScopedRead, on as isForeignKeyViolation, Nu as isIdleNow, Bi as isInfraError, zr as isObservingGraph, dd as isOrglessUserSubject, Fl as isSafeToApply, Kc as isScheduleDefinition, po as isWorkflowEventTriggerDefinition, uu as ivmValue, Rd as lastWriteProvenance, es as listConnectionStates, Us as listResourcePolicies, ee as listRetentions, _u as loadResourceTuples, bu as loadSubjectTuples, Hc as localityAwareSelector, Nd as makeActionRunner, hl as makeAdvisoryLockCoordinator, Er as makeAesCipher, Fa as makeApiKeyService, fc as makeApiKeyUsageBuffer, za as makeApiKeyUsageFlusher, sn as makeAppAccess, Oa as makeAsyncKv, ca as makeBufferingSpanProcessor, Go as makeConnectionRegistry, As as makeConnectionResolver, js as makeConnectionsFacade, xl as makeCoordinatedScheduler, ic as makeDataLoader, Ls as makeDisconnectConnectionExecutor, Ja as makeEffectStoreLayer, yo as makeEventsFacade, Dr as makeFieldCipher, $r as makeFluentStore, Pu as makeIdleGate, so as makeLazyWorkflowFacade, Ps as makeListConnectionsExecutor, Td as makeMutationRunner, jd as makeOneShotQueryRunner, Oo as makeOutboxFacade, ao as makePostCommitWorkflowFacade, Au as makeProcessAdapter, Ad as makeQueryDescriptorProducer, kd as makeQueryReauthorizer, Md as makeQuerySubscriber, Fu as makeRouterActivity, gc as makeSchemaRegistry, Fs as makeStartConnectionExecutor, Is as makeSubmitTokenExecutor, Al as makeUndoCapture, Iu as makeWakeGate, zu as makeWakeProxyServer, io as makeWorkflowFacade, oo as makeWorkflowFacadeWithCallerContext, co as makeWorkflowHandlers, lo as makeWorkflowLayers, Za as makeWorkflowRunHandle, tl as markWakeupFired, fu as materializeIvm, Ia as memoryApiKeyStore, Wc as memoryReplicationAdapter, fi as memoryRywPositionStore, Xc as nextFiring, cl as nextWakeup, Mu as nodeProcessSupervisor, Xu as noopAnalytics, $u as noopAnalyticsSpec, ka as noopKv, Wr as observeStore, Hr as observedGraph, dr as onBindConnectionSubject, To as outboxAttemptsTable, So as outboxTable, br as parseTraceparent, no as payloadPropertyNames, ui as powerOfTwoSelector, Wd as previewInRollback, Yo as projectConnectionState, ul as pruneWakeups, Gs as rebacPolicyGraph, An as recordSample, Pn as recordSubscriptionActive, Mn as recordSubscriptionDelivery, Vr as recordTableAccess, au as recordTimelineEvent, Tc as redactColumns, Ql as redactRow, mi as redisRywPositionStore, Jl as redoUndoInvocation, is as refreshAccessToken, pr as registerConnectionStream, se as registerRetention, $c as registerWakeup, il as releaseWakeup, di as replicaHealth, ji as resetComputedQueryCacheWarnings, Ur as resetObservedGraph, fa as resetSecretsBackend, ms as resolveConnection, ks as resolveConnectionForSubject, Uc as resolveCurrentRegion, cn as resolveDependentTables, Ss as resolveRedirectUri, mu as resolveRescan, qn as resolveRowFilterScope, Jn as resolveRowFilterScopeFor, pa as resolveSecret, ma as resolveSecretSync, _a as resolveSecretsBackend, Yl as resolveTimelineMode, le as retentionTtlMsFromEnv, eu as reverseEventOverRows, Zs as revokedIds, Vc as runAsSystem, Vu as runOrchestratorTick, md as runProvidedEffect, Eu as runReaction, Hu as runSingleNodeOrchestrator, ku as runWakeLoop, wd as runWithDeadlockRetry, Br as runWithObservedProcedure, _i as runWithRoutingContext, Cr as runWithTraceContext, xs as sanitizeRedirectTo, bl as scheduleCoordinated, Ac as schemaPropertyNames, Mc as serverOnlyLeaks, Ds as setConnectionResolver, kr as setFieldCipher, Wn as setRowFilter, da as setSecretsBackend, Rc as setSystemStoreHandle, iu as setTimelineRecorderForTest, ec as setTupleSource, ja as sha256Hex, pl as singleCoordinator, zn as snapshotMetrics, Bn as snapshotMetricsSync, dc as ssrfGuardHttpClientLayer, uc as ssrfReason, Gi as startRpcServer, _l as startScheduler, Zo as storeCredential, Ts as sweepExpiredGrants, he as sweepRetention, Nl as synthesizeInverse, ac as tracingHttpClientLayer, uo as triggerWorkflow, rl as tryClaimWakeup, ur as unbindConnectionSubject, El as undoCaptureEnabled, Gl as undoLogExecutor, cd as useAggregate, Ju as useAnalytics, Xs as visibleRows, Ou as wakeDueOnce, _d as withRowFilter, Ya as workflowToRpc, kl as wrapCaptureStore, Sc as wrapStoreWithBootCodec, li as wrapStoreWithMixinBehaviour };
7016
+ export { Fa as API_KEYS_TABLE, Ws as AccessDenied, _d as AggregateError, Eu as AggregateMaintainer, gd as AggregateNotFound, vd as AggregateRegistry, hd as AggregateStale, nd as AnalyticsCapabilityNotSupported, td as AnalyticsError, rd as AnalyticsSink, X as CONNECTIONS_TABLE, Uo as CONNECTION_GRANTS_TABLE, qc as CircuitBreaker, Gc as CircuitOpen, fs as ConnectionNotConnected, Gi as DEFAULT_MAX_RPC_BODY_BYTES, us as DEFAULT_REFRESH_SKEW_MS, Hn as DEFAULT_ROW_FILTER_RETRY, Cl as DORMANCY_WAKEUP_TENANT, Qr as DeleteBuilder, er as Dispatcher, Xa as EffectStore, ws as GRANT_TTL_MS, rn as InMemoryDataStore, Gt as IndexedMatcher, Rt as LinearScanMatcher, rt as MetricBoundaries, od as NOOP_ANALYTICS_PROVIDER, Kn as NO_ROW_FILTER, Gr as NoRowFound, Oo as OUTBOX_ATTEMPTS_TABLE, Fo as OUTBOX_ATTEMPT_LOG_CAP, Y as OUTBOX_TABLE, Kr as OptimisticLockError, Us as REBAC_ADMIN_SCOPE, ds as REFRESH_LEASE_MS, nf as RUNTIME_NAME, Iu as ReactionRateLimiter, yi as ReplicatedDataStore, Vn as RowFilterUnavailable, Sl as SCHEDULE_SUBJECT, Ya as SYSTEM_SUBJECT, Xr as SelectBuilder, hc as SsrfBlockedError, ti as StoreOperationFailed, Jt as SubscriptionRegistry, ni as TableValidationFailed, ei as TenantScopeViolation, fu as TimelineRecorder, Gl as UndoBoundaryError, ql as UndoStack, Zr as UpdateBuilder, Sc as VOLTRO_AUDIT_MIXIN_ID, Cc as VOLTRO_SOFT_DELETE_MIXIN_ID, wc as VOLTRO_TENANT_MIXIN_ID, oo as WorkflowPayloadError, hr as _connectionStreamCount, gr as _resetConnectionSubjectsForTest, Go as _voltroConnectionGrantsTable, Ho as _voltroConnectionsTable, Du as _voltroRebacTuplesTable, Pl as _voltroScheduleClaimsTable, Nl as _voltroScheduleRunsTable, Fl as _voltroTracesTable, Il as _voltroUndoLogTable, Ru as _voltroWakeupsTable, Co as _voltroWorkflowEventDeliveriesTable, So as _voltroWorkflowEventsTable, ci as actingUserId, Ja as apiKeyManagementRoutes, ai as applyDefined, wu as applyDelta, Yl as applyInverse, Xl as applyInverses, Xn as applyRowFilter, Zn as applyRowFilterToDescriptor, Cd as applySoftDeleteScope, bd as applyTenantScope, iu as applyUndoInvocation, ec as assertCan, Yo as assertConnectionCipherConfigured, fd as attachAnalyticsMirror, ea as awaitServerListening, Po as backoffMs, Os as beginOAuthConnect, cr as bindConnectionSubject, Wi as bindMutation, Ii as bindStream, Fi as bindSubscription, Ai as bindSubscriptionUntyped, Su as buildIvmState, $d as buildPreview, Au as buildRebacInterceptor, Mu as buildRebacReadFilter, pi as buildSubjectKey, aa as buildTracingLayer, Uc as cacheScopeLeaks, ba as cachedBackend, $s as can, dl as cancelWakeup, vu as classifyShape, gs as clearConnectionRefreshFlights, Ys as clearResourcePolicies, a as clearRetentions, Xc as clearSystemStoreHandle, ol as compileCron, ks as completeOAuthConnect, ld as composeAnalytics, cd as composeAnalyticsSinks, Ts as connectionCallbackPath, Jo as connectionLabel, _r as connectionSubjectsSnapshot, Zu as countRunningWorkflows, Fn as counter, Rc as crud, ac as currentRequestLoader, vi as currentRoutingContext, wr as currentTraceContext, Ga as dataStoreApiKeyStore, Da as dataStoreIdempotencyStore, Ma as dataStoreKvStore, Mr as decryptField, pd as defineAggregate, qo as defineConnection, _o as defineEventTrigger, wd as defineExecutor, jo as defineOutboxHandler, Nu as defineReaction, Ks as defineResourcePolicy, al as defineSchedule, ed as defineSubscriber, Qn as deliveredRowCount, Tr as deriveKey, Qd as diffChange, Qi as drainForShutdown, zo as drainOutbox, vl as dueWakeups, Qs as effectiveRelations, kc as emptySchemaRegistry, Rr as enableGraphObservation, jr as encryptField, ic as enterRequestLoader, ma as envSecretsBackend, cs as exchangeAuthorizationCode, xr as externalSpanFromTraceparent, on as extractDbCause, qt as fingerprintFor, is as forgetCredential, Wc as formatCacheScopeLeaks, Hc as formatServerOnlyLeaks, yr as formatTraceparent, Jl as forwardChangeFromCdc, Ka as frameworkApiKeyStrategy, In as gauge, La as generateApiKeyToken, Ns as getConnectionResolver, lr as getConnectionSubject, q as getFieldCipher, qs as getResourcePolicy, Gn as getRowFilter, Zc as getSystemStoreHandle, mu as getTimelineRecorder, uc as getTupleSource, $ as groupKeyOf, Ln as histogramMetric, Xd as historyProvenance, xa as httpSecretsBackend, It as inspectWorkflow, dc as installPolicyGuardResolver, mr as interruptConnectionStreams, Ul as invertChange, md as isAggregateDefinition, xd as isEmptyTenantScopedRead, sn as isForeignKeyViolation, Wu as isIdleNow, Vi as isInfraError, zr as isObservingGraph, Sd as isOrglessUserSubject, Kl as isSafeToApply, rl as isScheduleDefinition, vo as isWorkflowEventTriggerDefinition, xu as ivmValue, Yd as lastWriteProvenance, as as listConnectionStates, Js as listResourcePolicies, ee as listRetentions, Ou as loadResourceTuples, ju as loadSubjectTuples, $c as localityAwareSelector, Wd as makeActionRunner, El as makeAdvisoryLockCoordinator, Er as makeAesCipher, Ba as makeApiKeyService, xc as makeApiKeyUsageBuffer, Wa as makeApiKeyUsageFlusher, cn as makeAppAccess, Na as makeAsyncKv, pa as makeBufferingSpanProcessor, Xo as makeConnectionRegistry, Fs as makeConnectionResolver, Is as makeConnectionsFacade, Ml as makeCoordinatedScheduler, pc as makeDataLoader, Hs as makeDisconnectConnectionExecutor, $a as makeEffectStoreLayer, wo as makeEventsFacade, Dr as makeFieldCipher, $r as makeFluentStore, Gu as makeIdleGate, po as makeLazyWorkflowFacade, zs as makeListConnectionsExecutor, Id as makeMutationRunner, Hd as makeOneShotQueryRunner, No as makeOutboxFacade, uo as makePostCommitWorkflowFacade, Vu as makeProcessAdapter, Vd as makeQueryDescriptorProducer, Bd as makeQueryReauthorizer, Ud as makeQuerySubscriber, Ku as makeRouterActivity, Tc as makeSchemaRegistry, Bs as makeStartConnectionExecutor, Vs as makeSubmitTokenExecutor, Vl as makeUndoCapture, qu as makeWakeGate, Xu as makeWakeProxyServer, lo as makeWorkflowFacade, fo as makeWorkflowFacadeWithCallerContext, mo as makeWorkflowHandlers, ho as makeWorkflowLayers, no as makeWorkflowRunHandle, fl as markWakeupFired, Cu as materializeIvm, Va as memoryApiKeyStore, tl as memoryReplicationAdapter, fi as memoryRywPositionStore, sl as nextFiring, yl as nextWakeup, Uu as nodeProcessSupervisor, sd as noopAnalytics, ud as noopAnalyticsSpec, Pa as noopKv, Wr as observeStore, Hr as observedGraph, dr as onBindConnectionSubject, Xi as onProcessShutdown, Ao as outboxAttemptsTable, Do as outboxTable, br as parseTraceparent, so as payloadPropertyNames, ui as powerOfTwoSelector, tf as previewInRollback, es as projectConnectionState, xl as pruneWakeups, Xs as rebacPolicyGraph, jn as recordSample, W as recordSubscriptionActive, Nn as recordSubscriptionDelivery, Vr as recordTableAccess, gu as recordTimelineEvent, Pc as redactColumns, lu as redactRow, mi as redisRywPositionStore, au as redoUndoInvocation, ls as refreshAccessToken, pr as registerConnectionStream, se as registerRetention, ul as registerWakeup, hl as releaseWakeup, di as replicaHealth, Mi as resetComputedQueryCacheWarnings, Ur as resetObservedGraph, _a as resetSecretsBackend, ys as resolveConnection, Ps as resolveConnectionForSubject, el as resolveCurrentRegion, ln as resolveDependentTables, Ds as resolveRedirectUri, Tu as resolveRescan, qn as resolveRowFilterScope, Jn as resolveRowFilterScopeFor, va as resolveSecret, ya as resolveSecretSync, Sa as resolveSecretsBackend, ou as resolveTimelineMode, le as retentionTtlMsFromEnv, du as reverseEventOverRows, nc as revokedIds, Qc as runAsSystem, Qu as runOrchestratorTick, Td as runProvidedEffect, Lu as runReaction, $u as runSingleNodeOrchestrator, Bu as runWakeLoop, Fd as runWithDeadlockRetry, Br as runWithObservedProcedure, oc as runWithRequestLoader, _i as runWithRoutingContext, Cr as runWithTraceContext, Es as sanitizeRedirectTo, jl as scheduleCoordinated, zc as schemaPropertyNames, Vc as serverOnlyLeaks, Ms as setConnectionResolver, kr as setFieldCipher, Wn as setRowFilter, ga as setSecretsBackend, Yc as setSystemStoreHandle, hu as setTimelineRecorderForTest, lc as setTupleSource, Ia as sha256Hex, wl as singleCoordinator, zn as snapshotMetrics, Bn as snapshotMetricsSync, bc as ssrfGuardHttpClientLayer, yc as ssrfReason, Ki as startRpcServer, Ol as startScheduler, ns as storeCredential, As as sweepExpiredGrants, he as sweepRetention, Wl as synthesizeInverse, mc as tracingHttpClientLayer, go as triggerWorkflow, ml as tryClaimWakeup, ur as unbindConnectionSubject, Ll as undoCaptureEnabled, nu as undoLogExecutor, yd as useAggregate, ad as useAnalytics, tc as visibleRows, zu as wakeDueOnce, Od as withRowFilter, eo as workflowToRpc, Bl as wrapCaptureStore, jc as wrapStoreWithBootCodec, li as wrapStoreWithMixinBehaviour };