@voltro/runtime 0.2.2 → 0.4.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
@@ -1,24 +1,24 @@
1
- import { ENCRYPTED_PREFIX as e, and as t, attachEagerLoads as n, boolean as r, clearRetentions as i, collectSubqueries as a, contains as o, decryptFieldsOnRead as s, deserializeArraysOnRead as c, encryptFieldsForWrite as l, eq as u, evaluatePredicate as d, generateId as f, getRelations as p, getTable as m, gt as h, gte as g, hasEagerLoads as _, id as v, inSet as y, integer as b, isNull as x, json as S, listRetentions as C, lt as w, lte as ee, neq as te, or as T, queryFor as ne, registerRetention as re, requireTable as ie, retentionTtlMsFromEnv as ae, serializeArraysForWrite as oe, sweepRetention as se, table as E, text as D, timestamp as O, walkLeaves as ce } from "@voltro/database";
2
- import { createCipheriv as le, createDecipheriv as ue, createHash as de, randomBytes as fe, randomUUID as pe, scryptSync as me } from "node:crypto";
3
- import { EventEmitter as he } from "node:events";
4
- import { createLogger as ge } from "@voltro/logger";
5
- import { ADMIN_SCOPE as _e, ConnectionInfo as ve, SubjectService as ye, UndoConflict as be, UndoForbidden as xe, UndoNotFound as Se, WorkflowRunHandleSchema as Ce, diffRows as we, isIdKeyed as Te, publishServerError as Ee, systemSubject as De, tsMs as Oe } from "@voltro/protocol";
6
- import { Cause as k, Clock as ke, Context as Ae, Cron as A, Deferred as je, Duration as Me, Effect as j, Either as Ne, Exit as Pe, Layer as M, ManagedRuntime as Fe, Metric as N, MetricBoundaries as Ie, MetricState as Le, Option as P, Ref as F, Schema as I, Stream as L, Tracer as Re } from "effect";
7
- import * as ze from "node:http";
8
- import { createServer as Be } from "node:http";
9
- import { HttpClient as Ve, HttpClientRequest as He, HttpLayerRouter as R, HttpServer as Ue, HttpServerRequest as z, HttpServerResponse as B } from "@effect/platform";
10
- import { NodeContext as We, NodeHttpServer as Ge, NodeRuntime as Ke } from "@effect/platform-node";
11
- import { Rpc as qe, RpcSerialization as Je, RpcServer as V } from "@effect/rpc";
12
- import { defineRestRoute as Ye, dispatchSharedPath as Xe, requireScope as Ze } from "@voltro/protocol/rest";
13
- import { AsyncLocalStorage as Qe } from "node:async_hooks";
14
- import { SpanKind as H, SpanStatusCode as $e } from "@opentelemetry/api";
15
- import { Kv as et, KvError as tt, KvStore as nt, layerConnections as rt, layerMemory as it, layerRedis as at } from "@voltro/kv";
16
- import { apiKeyStrategy as ot } from "@voltro/protocol/apikey";
17
- import { getCurrentWorkflowExecutionId as st, inspectWorkflow as ct } from "@voltro/workflow";
18
- import { ArrayFormatter as lt } from "effect/ParseResult";
19
- import { spawn as ut } from "node:child_process";
1
+ import { ENCRYPTED_PREFIX as e, and as t, attachEagerLoads as n, boolean as r, clearRetentions as i, collectSubqueries as a, contains as o, decryptFieldsOnRead as s, deserializeArraysOnRead as c, encryptFieldsForWrite as l, eq as u, evaluatePredicate as d, generateId as f, getRelations as p, getTable as m, gt as h, gte as g, hasEagerLoads as _, id as v, inSet as y, integer as b, isEncrypted as x, isNull as S, json as C, listRetentions as ee, lt as te, lte as ne, neq as w, or as re, queryFor as ie, registerRetention as ae, requireTable as oe, retentionTtlMsFromEnv as se, serializeArraysForWrite as ce, sweepRetention as le, table as T, text as E, timestamp as D, walkLeaves as ue } from "@voltro/database";
2
+ import { createCipheriv as de, createDecipheriv as fe, createHash as pe, randomBytes as me, randomUUID as he, scryptSync as ge } from "node:crypto";
3
+ import { EventEmitter as _e } from "node:events";
4
+ import { ADMIN_SCOPE as ve, ConnectionInfo as ye, SubjectService as O, UndoConflict as be, UndoForbidden as xe, UndoNotFound as Se, WorkflowRunHandleSchema as Ce, checkGuardsEffect as we, diffRows as Te, effectiveScopes as Ee, hasEffectiveScope as De, isIdKeyed as Oe, publishServerError as ke, requireScope as Ae, systemSubject as je, tsMs as Me } from "@voltro/protocol";
5
+ import { createLogger as Ne } from "@voltro/logger";
6
+ import { Cause as k, Clock as Pe, Context as Fe, Cron as A, Deferred as Ie, Duration as Le, Effect as j, Either as Re, Exit as ze, Layer as M, ManagedRuntime as Be, Metric as N, MetricBoundaries as Ve, MetricState as He, Option as P, Ref as F, Schema as I, Stream as L, Tracer as Ue } from "effect";
7
+ import * as We from "node:http";
8
+ import { createServer as Ge } from "node:http";
9
+ import { HttpClient as Ke, HttpClientRequest as qe, HttpLayerRouter as R, HttpServer as Je, HttpServerRequest as z, HttpServerResponse as B } from "@effect/platform";
10
+ import { NodeContext as Ye, NodeHttpServer as Xe, NodeRuntime as Ze } from "@effect/platform-node";
11
+ import { Rpc as Qe, RpcSerialization as $e, RpcServer as et } from "@effect/rpc";
12
+ import { defineRestRoute as tt, dispatchSharedPath as nt, requireScope as rt } from "@voltro/protocol/rest";
13
+ import { AsyncLocalStorage as it } from "node:async_hooks";
14
+ import { SpanKind as at, SpanStatusCode as ot } from "@opentelemetry/api";
15
+ import { Kv as st, KvError as ct, KvStore as lt, layerConnections as ut, layerMemory as dt, layerRedis as ft } from "@voltro/kv";
16
+ import { apiKeyStrategy as pt } from "@voltro/protocol/apikey";
17
+ import { getCurrentWorkflowExecutionId as mt, inspectWorkflow as ht } from "@voltro/workflow";
18
+ import { ArrayFormatter as gt } from "effect/ParseResult";
19
+ import { spawn as _t } from "node:child_process";
20
20
  //#region src/matcher.ts
21
- var dt = class {
21
+ var vt = class {
22
22
  byTable = /* @__PURE__ */ new Map();
23
23
  register(e) {
24
24
  let t = this.byTable.get(e.table);
@@ -59,9 +59,9 @@ var dt = class {
59
59
  });
60
60
  return { perTable: e };
61
61
  }
62
- }, ft = (e) => {
62
+ }, yt = (e) => {
63
63
  let t = [];
64
- for (let n of ce(e)) n.conjunctive && n.path === void 0 && (n.op === "eq" && t.push({
64
+ for (let n of ue(e)) n.conjunctive && n.path === void 0 && (n.op === "eq" && t.push({
65
65
  column: n.column,
66
66
  values: [n.value]
67
67
  }), n.op === "in" && t.push({
@@ -69,18 +69,18 @@ var dt = class {
69
69
  values: n.value
70
70
  }));
71
71
  return t;
72
- }, pt = (e) => {
72
+ }, bt = (e) => {
73
73
  let t = [];
74
- for (let n of ce(e)) n.conjunctive && n.path === void 0 && (n.op === "gt" || n.op === "gte" || n.op === "lt" || n.op === "lte") && t.push({
74
+ for (let n of ue(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,
76
76
  op: n.op,
77
77
  threshold: n.value
78
78
  });
79
79
  return t;
80
- }, mt = (e, t) => {
81
- for (let n of ce(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
80
+ }, xt = (e, t) => {
81
+ for (let n of ue(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
82
82
  return null;
83
- }, ht = (e, t) => {
83
+ }, St = (e, t) => {
84
84
  let n = [];
85
85
  for (let r of e) {
86
86
  let e = t(r);
@@ -88,8 +88,8 @@ var dt = class {
88
88
  n.push(`${typeof e}:${String(e)}`);
89
89
  }
90
90
  return n.join("|");
91
- }, gt = (e, t) => e === null || t === null ? null : e === t ? 0 : typeof e == typeof t ? e > t ? 1 : -1 : null, _t = (e, t, n) => {
92
- let r = gt(e, n);
91
+ }, Ct = (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 = Ct(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 dt = class {
97
97
  case "lt": return r < 0;
98
98
  case "lte": return r <= 0;
99
99
  }
100
- }, vt = class {
100
+ }, Tt = class {
101
101
  columnByTable = /* @__PURE__ */ new Map();
102
102
  rangeByTable = /* @__PURE__ */ new Map();
103
103
  tupleByTable = /* @__PURE__ */ new Map();
@@ -105,9 +105,9 @@ var dt = 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 = ft(e.predicate), n = pt(e.predicate);
108
+ let t = yt(e.predicate), n = bt(e.predicate);
109
109
  if (e.usingIndex !== void 0) {
110
- let r = e.usingIndex, i = ht(r.fields, (t) => mt(e.predicate, t));
110
+ let r = e.usingIndex, i = St(r.fields, (t) => xt(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 dt = class {
252
252
  }
253
253
  }
254
254
  for (let [e, a] of i) {
255
- let i = ht(a, (e) => t[e]);
255
+ let i = St(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 dt = 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) _t(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 dt = 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 (!_t(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 dt = class {
297
297
  }
298
298
  return i;
299
299
  }
300
- }, yt = (e) => {
300
+ }, Et = (e) => {
301
301
  if (e == null) return null;
302
- if (Array.isArray(e)) return e.map(yt);
302
+ if (Array.isArray(e)) return e.map(Et);
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] = yt(t[e]);
305
+ for (let e of n) r[e] = Et(t[e]);
306
306
  return r;
307
307
  }
308
308
  return e;
309
- }, bt = (e, t, n) => {
310
- let r = yt({
309
+ }, Dt = (e, t, n) => {
310
+ let r = Et({
311
311
  table: e,
312
312
  predicate: t,
313
313
  indexHint: n ?? null
314
314
  });
315
- return de("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
316
- }, xt = class {
315
+ return pe("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
316
+ }, Ot = class {
317
317
  matcher;
318
318
  byFingerprint = /* @__PURE__ */ new Map();
319
319
  byClient = /* @__PURE__ */ new Map();
@@ -332,7 +332,7 @@ var dt = class {
332
332
  } catch {}
333
333
  }
334
334
  subscribe(e, t, n, r) {
335
- let i = bt(t, n, r?.name), a = this.byFingerprint.get(i);
335
+ let i = Dt(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 dt = class {
390
390
  });
391
391
  return e;
392
392
  }
393
- }, St = (e, t) => t.length === 0 ? e : [...e].sort((e, n) => {
393
+ }, kt = (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 dt = class {
400
400
  return r.direction === "asc" ? a : -a;
401
401
  }
402
402
  return 0;
403
- }), Ct = (e, t, n) => {
403
+ }), At = (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 dt = class {
418
418
  ...e,
419
419
  [i]: c
420
420
  };
421
- }, wt = (e, t, n) => !e || d(e, t, n), U = (e, t) => {
421
+ }, jt = (e, t, n) => !e || d(e, t, n), V = (e, t) => {
422
422
  let n = /* @__PURE__ */ new Map();
423
423
  if (!e) return n;
424
424
  for (let r of a(e)) {
425
- let e = t.get(r.descriptor.table) ?? /* @__PURE__ */ new Map(), i = U(r.descriptor.predicate, t), a = Tt(r.descriptor, e, t, i);
425
+ let e = t.get(r.descriptor.table) ?? /* @__PURE__ */ new Map(), i = V(r.descriptor.predicate, t), a = Mt(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 dt = class {
437
437
  }
438
438
  }
439
439
  return n;
440
- }, Tt = (e, t, n = /* @__PURE__ */ new Map(), r = null) => {
441
- let i = r ?? U(e.predicate, n), a = [...t.values()].filter((t) => wt(e.predicate, t, i));
440
+ }, Mt = (e, t, n = /* @__PURE__ */ new Map(), r = null) => {
441
+ let i = r ?? V(e.predicate, n), a = [...t.values()].filter((t) => jt(e.predicate, t, i));
442
442
  if (e.aggregations && e.aggregations.length > 0) {
443
- let t = Et(a, e.aggregations, e.groupBy);
443
+ let t = Nt(a, e.aggregations, e.groupBy);
444
444
  if (!e.having) return t;
445
- let r = U(e.having, n);
446
- return t.filter((t) => wt(e.having, t, r));
445
+ let r = V(e.having, n);
446
+ return t.filter((t) => jt(e.having, t, r));
447
447
  }
448
- let o = St(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 = kt(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 dt = class {
453
453
  for (let n of l) t[n] = e[n];
454
454
  return t;
455
455
  });
456
- }, Et = (e, t, n) => {
456
+ }, Nt = (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 dt = 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] = Dt(r, e.rows);
474
+ for (let r of t) n[r.alias] = Pt(r, e.rows);
475
475
  i.push(n);
476
476
  }
477
477
  return i;
478
- }, Dt = (e, t) => {
478
+ }, Pt = (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 dt = class {
519
519
  }
520
520
  default: throw Error(`computeAggregates: unknown op '${e.op}'`);
521
521
  }
522
- }, Ot = "\0", kt = (e, t) => e === null ? t : `${e}${Ot}${t}`, At = class e {
522
+ }, Ft = "\0", It = (e, t) => e === null ? t : `${e}${Ft}${t}`, Lt = class e {
523
523
  #e;
524
524
  #t;
525
525
  #n;
@@ -529,13 +529,13 @@ var dt = class {
529
529
  return r.#e = t.tables, r.#t = t.emitter, r.#n = t.numericCounters, r;
530
530
  }
531
531
  constructor(e, t = null) {
532
- if (this.#r = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new he(), this.#n = /* @__PURE__ */ new Map(), e) for (let [n, r] of Object.entries(e)) {
532
+ if (this.#r = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new _e(), this.#n = /* @__PURE__ */ new Map(), e) for (let [n, r] of Object.entries(e)) {
533
533
  let e = /* @__PURE__ */ new Map();
534
534
  for (let t of r) {
535
535
  let n = t.id;
536
536
  n && e.set(n, t);
537
537
  }
538
- this.#e.set(kt(t, n), e);
538
+ this.#e.set(It(t, n), e);
539
539
  }
540
540
  }
541
541
  withNamespace(t) {
@@ -546,11 +546,11 @@ var dt = class {
546
546
  }, t);
547
547
  }
548
548
  #a(e) {
549
- return kt(this.#r, e);
549
+ return It(this.#r, e);
550
550
  }
551
551
  #o() {
552
- let e = /* @__PURE__ */ new Map(), t = this.#r === null ? null : `${this.#r}${Ot}`;
553
- for (let [n, r] of this.#e) t === null ? n.includes(Ot) || e.set(n, r) : n.startsWith(t) && e.set(n.slice(t.length), r);
552
+ let e = /* @__PURE__ */ new Map(), t = this.#r === null ? null : `${this.#r}${Ft}`;
553
+ for (let [n, r] of this.#e) t === null ? n.includes(Ft) || e.set(n, r) : n.startsWith(t) && e.set(n.slice(t.length), r);
554
554
  return e;
555
555
  }
556
556
  #s(e) {
@@ -558,8 +558,8 @@ var dt = class {
558
558
  return n || (n = /* @__PURE__ */ new Map(), this.#e.set(t, n)), n;
559
559
  }
560
560
  async query(e) {
561
- let t = Tt(e, this.#e.get(this.#a(e.table)) ?? /* @__PURE__ */ new Map(), this.#o());
562
- return _(e) ? n(t, e.eager, ie(e.table), (e) => this.query(e)) : t;
561
+ let t = Mt(e, this.#e.get(this.#a(e.table)) ?? /* @__PURE__ */ new Map(), this.#o());
562
+ return _(e) ? n(t, e.eager, oe(e.table), (e) => this.query(e)) : t;
563
563
  }
564
564
  async insert(e, t) {
565
565
  let n = t;
@@ -588,7 +588,7 @@ var dt = class {
588
588
  if (!i) return null;
589
589
  let a = i.get(t);
590
590
  if (!a) return null;
591
- let o = Ct(a, n, r);
591
+ let o = At(a, n, r);
592
592
  return i.set(t, o), this.#t.emit("change", {
593
593
  table: e,
594
594
  op: "update",
@@ -630,7 +630,7 @@ var dt = class {
630
630
  async updateMany(e, t, n) {
631
631
  let r = this.#e.get(this.#a(e));
632
632
  if (!r) return 0;
633
- let i = U(n.where, this.#o()), a = 0;
633
+ let i = V(n.where, this.#o()), a = 0;
634
634
  for (let [o, s] of r) {
635
635
  if (!d(n.where, s, i)) continue;
636
636
  let c = {
@@ -649,7 +649,7 @@ var dt = class {
649
649
  async deleteMany(e, t) {
650
650
  let n = this.#e.get(this.#a(e));
651
651
  if (!n) return 0;
652
- let r = U(t.where, this.#o()), i = [];
652
+ let r = V(t.where, this.#o()), i = [];
653
653
  for (let [e, a] of n) d(t.where, a, r) && i.push([e, a]);
654
654
  for (let [t, r] of i) n.delete(t), this.#t.emit("change", {
655
655
  table: e,
@@ -688,7 +688,7 @@ var dt = class {
688
688
  }
689
689
  }
690
690
  async transactional(e) {
691
- let t = new jt(this.#u());
691
+ let t = new Rt(this.#u());
692
692
  try {
693
693
  let n = await e(t);
694
694
  return t.commit(), n;
@@ -724,7 +724,7 @@ var dt = class {
724
724
  allocateNumericId: (e) => this.#c(e)
725
725
  };
726
726
  }
727
- }, jt = class {
727
+ }, Rt = class {
728
728
  parent;
729
729
  overlay = /* @__PURE__ */ new Map();
730
730
  tombstones = /* @__PURE__ */ new Map();
@@ -754,8 +754,8 @@ var dt = class {
754
754
  return t || (t = /* @__PURE__ */ new Map(), this.overlay.set(e, t)), t;
755
755
  }
756
756
  async query(e) {
757
- let t = this.buildTablesView(e), r = Tt(e, this.materialise(e.table), t);
758
- return _(e) ? n(r, e.eager, ie(e.table), (e) => this.query(e)) : r;
757
+ let t = this.buildTablesView(e), r = Mt(e, this.materialise(e.table), t);
758
+ return _(e) ? n(r, e.eager, oe(e.table), (e) => this.query(e)) : r;
759
759
  }
760
760
  async insert(e, t) {
761
761
  let n = t;
@@ -793,7 +793,7 @@ var dt = class {
793
793
  async patchJson(e, t, n, r) {
794
794
  let i = this.materialise(e).get(t);
795
795
  if (!i) return null;
796
- let a = Ct(i, n, r);
796
+ let a = At(i, n, r);
797
797
  return this.getOrCreateOverlay(e).set(t, a), this.events.push({
798
798
  table: e,
799
799
  op: "update",
@@ -814,7 +814,7 @@ var dt = class {
814
814
  }), !0;
815
815
  }
816
816
  async updateMany(e, t, n) {
817
- let r = this.materialise(e), i = U(n.where, this.buildTablesViewForPred(n.where)), a = 0;
817
+ let r = this.materialise(e), i = V(n.where, this.buildTablesViewForPred(n.where)), a = 0;
818
818
  for (let [o, s] of r) {
819
819
  if (!d(n.where, s, i)) continue;
820
820
  let r = {
@@ -831,7 +831,7 @@ var dt = class {
831
831
  return a;
832
832
  }
833
833
  async deleteMany(e, t) {
834
- let n = this.materialise(e), r = U(t.where, this.buildTablesViewForPred(t.where)), i = 0, a = this.tombstones.get(e);
834
+ let n = this.materialise(e), r = V(t.where, this.buildTablesViewForPred(t.where)), i = 0, a = this.tombstones.get(e);
835
835
  for (let [o, s] of n) d(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({
836
836
  table: e,
837
837
  op: "delete",
@@ -894,7 +894,7 @@ var dt = class {
894
894
  discard() {
895
895
  this.settled || (this.settled = !0, this.overlay.clear(), this.tombstones.clear(), this.events.length = 0);
896
896
  }
897
- }, Mt = (e) => {
897
+ }, zt = (e) => {
898
898
  let t = {}, n = [], r = e;
899
899
  for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
900
900
  let e = r;
@@ -905,16 +905,23 @@ var dt = class {
905
905
  (o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = e.cause;
906
906
  }
907
907
  return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
908
- }, Nt = (e) => {
908
+ }, Bt = (e) => {
909
909
  let t = e.dbCode;
910
910
  return t === "23503" || e.dbErrno === 1452 || t === 547 || t === "SQLITE_CONSTRAINT_FOREIGNKEY";
911
- }, Pt = (e) => {
911
+ }, Vt = (e) => ({
912
+ has: (t) => De(e, t),
913
+ hasAny: (t) => t.some((t) => De(e, t)),
914
+ require: (t) => Ae(e, t),
915
+ get scopes() {
916
+ return Ee(e);
917
+ }
918
+ }), Ht = (e) => {
912
919
  let t = /* @__PURE__ */ new Set();
913
- return Ft(e, t), t;
914
- }, Ft = (e, t) => {
915
- if (t.add(e.table), e.eager !== void 0 && It(e.table, e.eager, t), e.setOp !== void 0) for (let n of e.setOp.queries) Ft(n, t);
916
- if (e.ctes !== void 0) for (let n of e.ctes) Ft(n.descriptor, t);
917
- }, It = (e, t, n) => {
920
+ return Ut(e, t), t;
921
+ }, Ut = (e, t) => {
922
+ if (t.add(e.table), e.eager !== void 0 && Wt(e.table, e.eager, t), e.setOp !== void 0) for (let n of e.setOp.queries) Ut(n, t);
923
+ if (e.ctes !== void 0) for (let n of e.ctes) Ut(n.descriptor, t);
924
+ }, Wt = (e, t, n) => {
918
925
  let r = p(e);
919
926
  if (r !== void 0) for (let [e, i] of Object.entries(t)) {
920
927
  let t = r[e];
@@ -922,24 +929,24 @@ var dt = class {
922
929
  let a = i === !0 ? {} : i;
923
930
  if (t.kind === "manyToMany") {
924
931
  let e = t.through().tableName, r = t.target().tableName;
925
- n.add(e), n.add(r), a.with !== void 0 && It(r, a.with, n);
932
+ n.add(e), n.add(r), a.with !== void 0 && Wt(r, a.with, n);
926
933
  } else {
927
934
  let e = t.target().tableName;
928
- n.add(e), a.with !== void 0 && It(e, a.with, n);
935
+ n.add(e), a.with !== void 0 && Wt(e, a.with, n);
929
936
  }
930
937
  }
931
- }, Lt = (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-")), Rt = /* @__PURE__ */ new Set(["*"]), zt = (e, t) => {
938
+ }, Gt = (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-")), Kt = /* @__PURE__ */ new Set(["*"]), H = (e, t) => {
932
939
  if (e !== void 0) {
933
940
  if ("not" in e) {
934
- zt(e.not, t);
941
+ H(e.not, t);
935
942
  return;
936
943
  }
937
944
  if ("and" in e) {
938
- for (let n of e.and) zt(n, t);
945
+ for (let n of e.and) H(n, t);
939
946
  return;
940
947
  }
941
948
  if ("or" in e) {
942
- for (let n of e.or) zt(n, t);
949
+ for (let n of e.or) H(n, t);
943
950
  return;
944
951
  }
945
952
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
@@ -948,11 +955,11 @@ var dt = class {
948
955
  }
949
956
  e.op === "exists" || e.op === "not-exists" || t.add(e.column);
950
957
  }
951
- }, W = (e, t, n) => {
958
+ }, U = (e, t, n) => {
952
959
  let r = e.get(t);
953
960
  r === void 0 && (r = /* @__PURE__ */ new Set(), e.set(t, r));
954
961
  for (let e of n) r.add(e);
955
- }, Bt = (e, t, n) => {
962
+ }, qt = (e, t, n) => {
956
963
  let r = p(e);
957
964
  if (r !== void 0) for (let [i, a] of Object.entries(t)) {
958
965
  let t = r[i];
@@ -960,65 +967,65 @@ var dt = class {
960
967
  let o = a === !0 ? {} : a;
961
968
  if (t.kind === "manyToMany") {
962
969
  let r = t.through(), i = t.target();
963
- W(n, r.tableName, [t.sourceKey, t.targetKey]), W(n, e, ["id"]), W(n, i.tableName, ["id"]), Vt(i.tableName, o, n), o.with !== void 0 && Bt(i.tableName, o.with, n);
970
+ U(n, r.tableName, [t.sourceKey, t.targetKey]), U(n, e, ["id"]), U(n, i.tableName, ["id"]), Jt(i.tableName, o, n), o.with !== void 0 && qt(i.tableName, o.with, n);
964
971
  continue;
965
972
  }
966
973
  let s = t.target();
967
- 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"]), Vt(s.tableName, o, n), o.with !== void 0 && Bt(s.tableName, o.with, n);
974
+ 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"]), Jt(s.tableName, o, n), o.with !== void 0 && qt(s.tableName, o.with, n);
968
975
  }
969
- }, Vt = (e, t, n) => {
976
+ }, Jt = (e, t, n) => {
970
977
  if (t.where !== void 0) {
971
978
  let r = /* @__PURE__ */ new Set();
972
- zt(t.where, r), W(n, e, r);
979
+ H(t.where, r), U(n, e, r);
973
980
  }
974
- t.orderBy !== void 0 && W(n, e, t.orderBy.map((e) => e.column));
981
+ t.orderBy !== void 0 && U(n, e, t.orderBy.map((e) => e.column));
975
982
  let r = m(e);
976
- r === void 0 ? W(n, e, ["*"]) : W(n, e, Object.keys(r.fields));
977
- }, Ht = (e) => {
983
+ r === void 0 ? U(n, e, ["*"]) : U(n, e, Object.keys(r.fields));
984
+ }, Yt = (e) => {
978
985
  let t = /* @__PURE__ */ new Map();
979
- if (Lt(e)) {
980
- for (let n of Pt(e)) W(t, n, ["*"]);
986
+ if (Gt(e)) {
987
+ for (let n of Ht(e)) U(t, n, ["*"]);
981
988
  return t;
982
989
  }
983
990
  let n = /* @__PURE__ */ new Set();
984
991
  if (e.projection !== void 0) for (let t of e.projection) n.add(t);
985
992
  else n.add("*");
986
- zt(e.predicate, n);
993
+ H(e.predicate, n);
987
994
  for (let t of e.order) n.add(t.column);
988
- return W(t, e.table, n), e.eager !== void 0 && Bt(e.table, e.eager, t), t;
989
- }, Ut = (e) => {
990
- if (e.op === "insert" || e.op === "delete" || e.old === null || e.new === null) return Rt;
995
+ return U(t, e.table, n), e.eager !== void 0 && qt(e.table, e.eager, t), t;
996
+ }, Xt = (e) => {
997
+ if (e.op === "insert" || e.op === "delete" || e.old === null || e.new === null) return Kt;
991
998
  let t = /* @__PURE__ */ new Set(), n = e.old, r = e.new, i = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
992
999
  for (let e of i) Object.is(n[e], r[e]) || t.add(e);
993
1000
  return t;
994
- }, Wt = (e, t) => {
1001
+ }, Zt = (e, t) => {
995
1002
  let n = t.get(e.table);
996
1003
  if (n === void 0) return !1;
997
1004
  if (n.has("*")) return !0;
998
- let r = Ut(e);
1005
+ let r = Xt(e);
999
1006
  if (r.has("*")) return !0;
1000
1007
  for (let e of r) if (n.has(e)) return !0;
1001
1008
  return !1;
1002
- }, Gt = Ie.exponential({
1009
+ }, W = Ve.exponential({
1003
1010
  start: .001,
1004
1011
  factor: 2,
1005
1012
  count: 16
1006
- }), Kt = N.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), qt = N.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), Jt = N.histogram("voltro_rpc_duration_seconds", Gt, "RPC handler duration in seconds."), Yt = N.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), Xt = N.histogram("voltro_http_duration_seconds", Gt, "HTTP route duration in seconds."), Zt = N.histogram("voltro_plugin_hook_duration_seconds", Gt, "Plugin interceptor duration in seconds."), Qt = N.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), $t = N.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), en = N.histogram("voltro_subscription_delivery_seconds", Gt, "Subscription delivery produce→push latency in seconds."), tn = N.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), nn = (e) => {
1007
- let t = e.durationMs / 1e3, n = e.kind === "rpc" ? j.zipRight(N.increment(Kt).pipe(j.tagMetrics("tag", e.tag), j.tagMetrics("status", e.status)), j.zipRight(N.update(Jt, t).pipe(j.tagMetrics("tag", e.tag)), e.status === "error" ? N.increment(qt).pipe(j.tagMetrics("tag", e.tag)) : j.void)) : e.kind === "request" ? j.zipRight(N.increment(Yt).pipe(j.tagMetrics("route", e.tag), j.tagMetrics("status", e.status)), N.update(Xt, t).pipe(j.tagMetrics("route", e.tag))) : j.zipRight(N.update(Zt, t).pipe(j.tagMetrics("hook", e.tag)), e.status === "error" ? N.increment(Qt).pipe(j.tagMetrics("hook", e.tag)) : j.void);
1013
+ }), Qt = N.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), $t = N.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), en = N.histogram("voltro_rpc_duration_seconds", W, "RPC handler duration in seconds."), tn = N.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), nn = N.histogram("voltro_http_duration_seconds", W, "HTTP route duration in seconds."), rn = N.histogram("voltro_plugin_hook_duration_seconds", W, "Plugin interceptor duration in seconds."), an = N.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), on = N.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), sn = N.histogram("voltro_subscription_delivery_seconds", W, "Subscription delivery produce→push latency in seconds."), cn = N.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), ln = (e) => {
1014
+ let t = e.durationMs / 1e3, n = e.kind === "rpc" ? j.zipRight(N.increment(Qt).pipe(j.tagMetrics("tag", e.tag), j.tagMetrics("status", e.status)), j.zipRight(N.update(en, t).pipe(j.tagMetrics("tag", e.tag)), e.status === "error" ? N.increment($t).pipe(j.tagMetrics("tag", e.tag)) : j.void)) : e.kind === "request" ? j.zipRight(N.increment(tn).pipe(j.tagMetrics("route", e.tag), j.tagMetrics("status", e.status)), N.update(nn, t).pipe(j.tagMetrics("route", e.tag))) : j.zipRight(N.update(rn, t).pipe(j.tagMetrics("hook", e.tag)), e.status === "error" ? N.increment(an).pipe(j.tagMetrics("hook", e.tag)) : j.void);
1008
1015
  j.runSync(n);
1009
- }, rn = (e) => e.startsWith("subscription.") ? e.slice(13) : e, an = (e) => {
1010
- let t = rn(e.label);
1011
- j.runSync(j.zipRight(N.increment($t).pipe(j.tagMetrics("tag", t), j.tagMetrics("kind", e.kind)), N.update(en, e.durationMs / 1e3).pipe(j.tagMetrics("tag", t), j.tagMetrics("kind", e.kind))));
1012
- }, on = /* @__PURE__ */ new Map(), sn = (e, t) => {
1013
- let n = rn(e), r = Math.max(0, (on.get(n) ?? 0) + t);
1014
- r === 0 ? on.delete(n) : on.set(n, r), j.runSync(N.set(tn, r).pipe(j.tagMetrics("tag", n)));
1015
- }, cn = (e, t) => N.counter(e, t === void 0 ? {} : { description: t }), ln = (e, t) => N.gauge(e, t === void 0 ? {} : { description: t }), un = (e, t = Gt, n) => N.histogram(e, t, n), dn = (e) => {
1016
+ }, un = (e) => e.startsWith("subscription.") ? e.slice(13) : e, dn = (e) => {
1017
+ let t = un(e.label);
1018
+ j.runSync(j.zipRight(N.increment(on).pipe(j.tagMetrics("tag", t), j.tagMetrics("kind", e.kind)), N.update(sn, e.durationMs / 1e3).pipe(j.tagMetrics("tag", t), j.tagMetrics("kind", e.kind))));
1019
+ }, fn = /* @__PURE__ */ new Map(), pn = (e, t) => {
1020
+ let n = un(e), r = Math.max(0, (fn.get(n) ?? 0) + t);
1021
+ r === 0 ? fn.delete(n) : fn.set(n, r), j.runSync(N.set(cn, r).pipe(j.tagMetrics("tag", n)));
1022
+ }, mn = (e, t) => N.counter(e, t === void 0 ? {} : { description: t }), hn = (e, t) => N.gauge(e, t === void 0 ? {} : { description: t }), gn = (e, t = W, n) => N.histogram(e, t, n), _n = (e) => {
1016
1023
  let t = {};
1017
1024
  for (let n of e) t[n.key] = n.value;
1018
1025
  return t;
1019
- }, fn = N.snapshot.pipe(j.map((e) => e.map((e) => {
1020
- let t = e.metricKey.name, n = dn(e.metricKey.tags), r = P.getOrUndefined(e.metricKey.description), i = r === void 0 ? {} : { description: r }, a = e.metricState;
1021
- if (Le.isHistogramState(a)) return {
1026
+ }, vn = N.snapshot.pipe(j.map((e) => e.map((e) => {
1027
+ let t = e.metricKey.name, n = _n(e.metricKey.tags), r = P.getOrUndefined(e.metricKey.description), i = r === void 0 ? {} : { description: r }, a = e.metricState;
1028
+ if (He.isHistogramState(a)) return {
1022
1029
  name: t,
1023
1030
  labels: n,
1024
1031
  ...i,
@@ -1030,14 +1037,14 @@ var dt = class {
1030
1037
  sum: a.sum,
1031
1038
  count: a.count
1032
1039
  };
1033
- if (Le.isGaugeState(a)) return {
1040
+ if (He.isGaugeState(a)) return {
1034
1041
  name: t,
1035
1042
  labels: n,
1036
1043
  ...i,
1037
1044
  type: "gauge",
1038
1045
  value: Number(a.value)
1039
1046
  };
1040
- if (Le.isSummaryState(a)) return {
1047
+ if (He.isSummaryState(a)) return {
1041
1048
  name: t,
1042
1049
  labels: n,
1043
1050
  ...i,
@@ -1049,7 +1056,7 @@ var dt = class {
1049
1056
  value: t.value
1050
1057
  }] : [])
1051
1058
  };
1052
- if (Le.isFrequencyState(a)) {
1059
+ if (He.isFrequencyState(a)) {
1053
1060
  let e = {};
1054
1061
  for (let [t, n] of a.occurrences) e[t] = n;
1055
1062
  return {
@@ -1067,7 +1074,7 @@ var dt = class {
1067
1074
  type: "counter",
1068
1075
  value: Number(a.count)
1069
1076
  };
1070
- }))), pn = () => j.runSync(fn), G = ge({ scope: "voltro:dispatcher" }), mn = class {
1077
+ }))), yn = () => j.runSync(vn), G = Ne({ scope: "voltro:dispatcher" }), bn = class {
1071
1078
  deps;
1072
1079
  subscriptionRegistry;
1073
1080
  matcher;
@@ -1077,12 +1084,12 @@ var dt = class {
1077
1084
  computedSubs = /* @__PURE__ */ new Map();
1078
1085
  computedByTable = /* @__PURE__ */ new Map();
1079
1086
  constructor(e) {
1080
- this.deps = e, this.matcher = new vt(), this.subscriptionRegistry = new xt(this.matcher), this.unsubscribeChange = e.store.onChange((e) => {
1087
+ this.deps = e, this.matcher = new Tt(), this.subscriptionRegistry = new Ot(this.matcher), this.unsubscribeChange = e.store.onChange((e) => {
1081
1088
  this.handleChange(e);
1082
1089
  });
1083
1090
  }
1084
1091
  async subscribe(e, t, n, r, i, a) {
1085
- let o = `sub_${pe()}`, s = i ?? `subscription.${e.table}`, c = Pt(e), l = Ht(e);
1092
+ let o = `sub_${he()}`, s = i ?? `subscription.${e.table}`, c = Ht(e), l = Yt(e);
1086
1093
  e.predicate !== void 0 && this.subscriptionRegistry.subscribe(o, e.table, e.predicate, r);
1087
1094
  for (let e of c) {
1088
1095
  let t = this.dependentByTable.get(e);
@@ -1099,7 +1106,7 @@ var dt = class {
1099
1106
  relevantFields: l,
1100
1107
  lastDelivered: f,
1101
1108
  cacheBinding: a
1102
- }), sn(s, 1), t({
1109
+ }), pn(s, 1), t({
1103
1110
  _tag: "snapshot",
1104
1111
  revision: 0,
1105
1112
  data: f
@@ -1115,7 +1122,7 @@ var dt = class {
1115
1122
  durationMs: p - u,
1116
1123
  rowCount: f.length
1117
1124
  }), () => {
1118
- this.subscriptions.delete(o), sn(s, -1), this.subscriptionRegistry.unsubscribe(o);
1125
+ this.subscriptions.delete(o), pn(s, -1), this.subscriptionRegistry.unsubscribe(o);
1119
1126
  for (let e of c) {
1120
1127
  let t = this.dependentByTable.get(e);
1121
1128
  t !== void 0 && (t.delete(o), t.size === 0 && this.dependentByTable.delete(e));
@@ -1123,17 +1130,17 @@ var dt = class {
1123
1130
  };
1124
1131
  }
1125
1132
  async subscribeComputed(e, t, n, r) {
1126
- let i = `csub_${pe()}`, a = e.dependentTables, o = {
1133
+ let i = `csub_${he()}`, a = e.dependentTables, o = {
1127
1134
  id: i,
1128
1135
  recompute: e.recompute,
1129
1136
  tenantId: e.tenantId,
1130
1137
  emit: t,
1131
1138
  context: n,
1132
1139
  label: r ?? "subscription.computed",
1133
- lastJson: hn(e.value),
1140
+ lastJson: xn(e.value),
1134
1141
  revision: 0
1135
1142
  };
1136
- this.computedSubs.set(i, o), sn(o.label, 1);
1143
+ this.computedSubs.set(i, o), pn(o.label, 1);
1137
1144
  for (let e of a) {
1138
1145
  let t = this.computedByTable.get(e);
1139
1146
  t === void 0 && (t = /* @__PURE__ */ new Set(), this.computedByTable.set(e, t)), t.add(i);
@@ -1153,7 +1160,7 @@ var dt = class {
1153
1160
  durationMs: Date.now() - s,
1154
1161
  rowCount: 1
1155
1162
  }), () => {
1156
- this.computedSubs.delete(i), sn(o.label, -1);
1163
+ this.computedSubs.delete(i), pn(o.label, -1);
1157
1164
  for (let e of a) {
1158
1165
  let t = this.computedByTable.get(e);
1159
1166
  t !== void 0 && (t.delete(i), t.size === 0 && this.computedByTable.delete(e));
@@ -1163,7 +1170,7 @@ var dt = class {
1163
1170
  async recomputeComputed(e) {
1164
1171
  let t = Date.now();
1165
1172
  try {
1166
- let n = await e.recompute(), r = hn(n);
1173
+ let n = await e.recompute(), r = xn(n);
1167
1174
  if (r === e.lastJson) return;
1168
1175
  e.lastJson = r, e.revision += 1;
1169
1176
  let i = Date.now();
@@ -1231,25 +1238,25 @@ var dt = class {
1231
1238
  G.trace("missing subscription", { subscriberId: t });
1232
1239
  continue;
1233
1240
  }
1234
- if (!Wt(e, n.relevantFields)) {
1241
+ if (!Zt(e, n.relevantFields)) {
1235
1242
  o++;
1236
1243
  continue;
1237
1244
  }
1238
1245
  let r = Date.now();
1239
1246
  try {
1240
1247
  let i = await this.deps.store.query(n.descriptor), o = n.lastDelivered;
1241
- if (gn(i, o)) {
1248
+ if (Sn(i, o)) {
1242
1249
  G.trace("suppressed no-op delta", {
1243
1250
  subscriberId: t,
1244
1251
  table: e.table
1245
1252
  });
1246
1253
  continue;
1247
1254
  }
1248
- n.lastDelivered = i, this.deps.cache !== void 0 && n.cacheBinding !== void 0 && this.deps.cache.put(n.cacheBinding, Array.from(n.dependentTables), i), Te(o) && Te(i) ? n.emit({
1255
+ n.lastDelivered = i, this.deps.cache !== void 0 && n.cacheBinding !== void 0 && this.deps.cache.put(n.cacheBinding, Array.from(n.dependentTables), i), Oe(o) && Oe(i) ? n.emit({
1249
1256
  _tag: "delta",
1250
1257
  revision: a,
1251
1258
  emittedAt: a,
1252
- patch: we(o, i)
1259
+ patch: Te(o, i)
1253
1260
  }) : n.emit({
1254
1261
  _tag: "snapshot",
1255
1262
  revision: a,
@@ -1281,44 +1288,44 @@ var dt = class {
1281
1288
  skipped: o
1282
1289
  });
1283
1290
  }
1284
- }, hn = (e) => {
1291
+ }, xn = (e) => {
1285
1292
  try {
1286
1293
  return JSON.stringify(e) ?? "null";
1287
1294
  } catch {
1288
1295
  return String(e);
1289
1296
  }
1290
- }, gn = (e, t) => {
1297
+ }, Sn = (e, t) => {
1291
1298
  if (e === t) return !0;
1292
1299
  if (e.length !== t.length) return !1;
1293
1300
  for (let n = 0; n < e.length; n++) if (JSON.stringify(e[n]) !== JSON.stringify(t[n])) return !1;
1294
1301
  return !0;
1295
- }, _n = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0, vn = 1440 * 60 * 1e3, yn = 3600 * 1e3, K = /* @__PURE__ */ new Map(), bn = /* @__PURE__ */ new Set(), xn = (e, t) => {
1302
+ }, Cn = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0, wn = 1440 * 60 * 1e3, Tn = 3600 * 1e3, K = /* @__PURE__ */ new Map(), En = /* @__PURE__ */ new Set(), Dn = (e, t) => {
1296
1303
  K.set(e, {
1297
1304
  subject: t,
1298
1305
  touchedAt: Date.now()
1299
1306
  });
1300
- for (let n of bn) try {
1307
+ for (let n of En) try {
1301
1308
  n(e, t);
1302
1309
  } catch {}
1303
- }, Sn = (e) => {
1310
+ }, On = (e) => {
1304
1311
  let t = K.get(e);
1305
1312
  if (t) return t.touchedAt = Date.now(), t.subject;
1306
- }, Cn = (e) => {
1313
+ }, kn = (e) => {
1307
1314
  K.delete(e);
1308
- }, wn = (e) => (bn.add(e), () => {
1309
- bn.delete(e);
1310
- }), Tn = setInterval(() => {
1311
- let e = Date.now() - vn;
1315
+ }, An = (e) => (En.add(e), () => {
1316
+ En.delete(e);
1317
+ }), jn = setInterval(() => {
1318
+ let e = Date.now() - wn;
1312
1319
  for (let [t, n] of K) n.touchedAt < e && K.delete(t);
1313
- }, yn);
1314
- typeof Tn == "object" && Tn && "unref" in Tn && Tn.unref();
1315
- var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1320
+ }, Tn);
1321
+ typeof jn == "object" && jn && "unref" in jn && jn.unref();
1322
+ var q = /* @__PURE__ */ new Map(), Mn = (e, t) => {
1316
1323
  let n = q.get(e);
1317
1324
  return n || (n = /* @__PURE__ */ new Set(), q.set(e, n)), n.add(t), () => {
1318
1325
  let n = q.get(e);
1319
1326
  n && (n.delete(t), n.size === 0 && q.delete(e));
1320
1327
  };
1321
- }, Dn = (e) => {
1328
+ }, Nn = (e) => {
1322
1329
  let t = q.get(e);
1323
1330
  if (t) {
1324
1331
  for (let e of [...t]) try {
@@ -1326,15 +1333,15 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1326
1333
  } catch {}
1327
1334
  q.delete(e);
1328
1335
  }
1329
- }, On = (e) => q.get(e)?.size ?? 0, kn = () => {
1336
+ }, Pn = (e) => q.get(e)?.size ?? 0, Fn = () => {
1330
1337
  K.clear(), q.clear();
1331
- }, An = () => [...K.entries()].map(([e, t]) => ({
1338
+ }, In = () => [...K.entries()].map(([e, t]) => ({
1332
1339
  clientId: e,
1333
1340
  subjectType: t.subject.type,
1334
1341
  tenantId: t.subject.tenantId
1335
- })), jn = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/, Mn = (e) => `00-${e.traceId}-${e.spanId}-${e.sampled ? "01" : "00"}`, Nn = (e) => {
1342
+ })), Ln = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/, Rn = (e) => `00-${e.traceId}-${e.spanId}-${e.sampled ? "01" : "00"}`, zn = (e) => {
1336
1343
  if (typeof e != "string") return null;
1337
- let t = jn.exec(e.trim().toLowerCase());
1344
+ let t = Ln.exec(e.trim().toLowerCase());
1338
1345
  if (t === null) return null;
1339
1346
  let [, n, r, i] = t;
1340
1347
  return n === "0".repeat(32) || r === "0".repeat(16) ? null : {
@@ -1342,14 +1349,14 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1342
1349
  spanId: r,
1343
1350
  sampled: (parseInt(i, 16) & 1) == 1
1344
1351
  };
1345
- }, Pn = (e) => {
1346
- let t = Nn(e);
1347
- if (t !== null) return Re.externalSpan({
1352
+ }, Bn = (e) => {
1353
+ let t = zn(e);
1354
+ if (t !== null) return Ue.externalSpan({
1348
1355
  traceId: t.traceId,
1349
1356
  spanId: t.spanId,
1350
1357
  sampled: t.sampled
1351
1358
  });
1352
- }, Fn = new Qe(), In = (e, t) => Fn.run(e, t), Ln = () => Fn.getStore(), Rn = (e = {}) => {
1359
+ }, Vn = new it(), Hn = (e, t) => Vn.run(e, t), Un = () => Vn.getStore(), Wn = (e = {}) => {
1353
1360
  let t = e.random ?? Math.random, n = /* @__PURE__ */ new Map(), r = (e) => n.get(e) ?? 0;
1354
1361
  return {
1355
1362
  pick(e) {
@@ -1374,7 +1381,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1374
1381
  }));
1375
1382
  }
1376
1383
  };
1377
- }, zn = (e = {}) => {
1384
+ }, Gn = (e = {}) => {
1378
1385
  let t = e.thresholdFailures ?? 3, n = e.windowMs ?? 1e4, r = e.blackoutMs ?? 6e4, i = e.now ?? Date.now, a = /* @__PURE__ */ new Map(), o = (e) => {
1379
1386
  let t = a.get(e);
1380
1387
  return t === void 0 && (t = {
@@ -1408,7 +1415,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1408
1415
  }));
1409
1416
  }
1410
1417
  };
1411
- }, Bn = (e = {}) => {
1418
+ }, Kn = (e = {}) => {
1412
1419
  let t = e.now ?? Date.now, n = /* @__PURE__ */ new Map();
1413
1420
  return {
1414
1421
  get(e) {
@@ -1431,7 +1438,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1431
1438
  return n.size;
1432
1439
  }
1433
1440
  };
1434
- }, Vn = (e, t) => e === null ? t === void 0 ? "anon:bg" : `anon:${t}` : `subject:${e}`, Hn = (e) => {
1441
+ }, qn = (e, t) => e === null ? t === void 0 ? "anon:bg" : `anon:${t}` : `subject:${e}`, Jn = (e) => {
1435
1442
  let t = e.now ?? Date.now, n = e.keyPrefix ?? "voltro:ryw", r = e.channel ?? `${n}:bus`, i = e.onError ?? ((e, t) => {
1436
1443
  process.stderr.write(`[voltro:ryw] redis ${t} failed: ${String(e)}\n`);
1437
1444
  }), a = `${process.pid ?? 0}:${Math.random() * 1e9 | 0}:${t()}`, o = /* @__PURE__ */ new Map(), s = (e) => {
@@ -1490,7 +1497,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1490
1497
  return o.size;
1491
1498
  }
1492
1499
  };
1493
- }, Un = ge({ scope: "voltro:replication" }), Wn = new Qe(), Gn = (e, t) => Wn.run(e, t), Kn = () => Wn.getStore(), qn = class {
1500
+ }, Yn = Ne({ scope: "voltro:replication" }), Xn = new it(), Zn = (e, t) => Xn.run(e, t), Qn = () => Xn.getStore(), $n = class {
1494
1501
  primary;
1495
1502
  replicas;
1496
1503
  adapter;
@@ -1503,10 +1510,10 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1503
1510
  recordRouting;
1504
1511
  now;
1505
1512
  constructor(e) {
1506
- this.primary = e.primary, this.replicas = e.replicas, this.adapter = e.replicationAdapter, this.policy = e.rywPolicy ?? "fallback", this.rywTtlMs = e.rywTtlMs ?? 3e4, this.rywMaxWaitMs = e.rywMaxWaitMs ?? 500, this.now = e.now ?? Date.now, this.rywStore = e.rywStore ?? Bn({ now: this.now }), this.selector = e.replicaSelector ?? Rn(), this.health = e.replicaHealth ?? zn({ now: this.now }), e.recordRouting !== void 0 && (this.recordRouting = e.recordRouting);
1513
+ this.primary = e.primary, this.replicas = e.replicas, this.adapter = e.replicationAdapter, this.policy = e.rywPolicy ?? "fallback", this.rywTtlMs = e.rywTtlMs ?? 3e4, this.rywMaxWaitMs = e.rywMaxWaitMs ?? 500, this.now = e.now ?? Date.now, this.rywStore = e.rywStore ?? Kn({ now: this.now }), this.selector = e.replicaSelector ?? Wn(), this.health = e.replicaHealth ?? Gn({ now: this.now }), e.recordRouting !== void 0 && (this.recordRouting = e.recordRouting);
1507
1514
  }
1508
1515
  async query(e) {
1509
- let t = Wn.getStore(), n = t?.subjectKey ?? "anon:bg";
1516
+ let t = Xn.getStore(), n = t?.subjectKey ?? "anon:bg";
1510
1517
  if (t?.forcePrimary === !0) return this.emitRouting({
1511
1518
  target: "primary",
1512
1519
  replicaIndex: null,
@@ -1570,7 +1577,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1570
1577
  waitMs: 0
1571
1578
  }), r;
1572
1579
  } catch (r) {
1573
- return this.health.reportFailure(i, String(r)), Un.warn("replica query failed; falling back to primary", {
1580
+ return this.health.reportFailure(i, String(r)), Yn.warn("replica query failed; falling back to primary", {
1574
1581
  idx: a,
1575
1582
  err: r
1576
1583
  }), this.emitRouting({
@@ -1639,7 +1646,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1639
1646
  fallbackReason: "wait-timeout"
1640
1647
  }), this.primary.query(e);
1641
1648
  }
1642
- await Jn(10);
1649
+ await er(10);
1643
1650
  }
1644
1651
  }
1645
1652
  async insert(e, t) {
@@ -1679,8 +1686,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1679
1686
  return await this.stampPostWrite(), r;
1680
1687
  }
1681
1688
  async transactional(e) {
1682
- let t = await Gn({
1683
- subjectKey: Wn.getStore()?.subjectKey ?? "anon:bg",
1689
+ let t = await Zn({
1690
+ subjectKey: Xn.getStore()?.subjectKey ?? "anon:bg",
1684
1691
  forcePrimary: !0
1685
1692
  }, () => this.primary.transactional(e));
1686
1693
  return await this.stampPostWrite(), t;
@@ -1696,7 +1703,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1696
1703
  }
1697
1704
  async stampPostWrite() {
1698
1705
  if (this.replicas.length === 0) return;
1699
- let e = Wn.getStore()?.subjectKey ?? "anon:bg";
1706
+ let e = Xn.getStore()?.subjectKey ?? "anon:bg";
1700
1707
  try {
1701
1708
  let t = await this.adapter.capturePrimaryPosition(this.primary);
1702
1709
  this.rywStore.set(e, {
@@ -1704,29 +1711,29 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1704
1711
  expiresAt: this.now() + this.rywTtlMs
1705
1712
  });
1706
1713
  } catch (e) {
1707
- Un.warn("failed to capture primary position; RYW skipped", { err: e });
1714
+ Yn.warn("failed to capture primary position; RYW skipped", { err: e });
1708
1715
  }
1709
1716
  }
1710
1717
  emitRouting(e) {
1711
1718
  this.recordRouting?.(e);
1712
1719
  }
1713
- }, Jn = (e) => new Promise((t) => setTimeout(t, e)), Yn = (e, t, n) => ({
1720
+ }, er = (e) => new Promise((t) => setTimeout(t, e)), tr = (e, t, n) => ({
1714
1721
  subject: e,
1715
- traceId: t?.traceId ?? pe(),
1722
+ traceId: t?.traceId ?? he(),
1716
1723
  ...t?.spanId === void 0 ? {} : { spanId: t.spanId },
1717
1724
  ...n === void 0 ? {} : { clientId: n }
1718
- }), Xn = j.currentSpan.pipe(j.catchAll(() => j.succeed(void 0))), Zn = (e) => ({
1725
+ }), nr = j.currentSpan.pipe(j.catchAll(() => j.succeed(void 0))), rr = (e) => ({
1719
1726
  traceId: e.traceId,
1720
1727
  ...e.spanId === void 0 ? {} : { spanId: e.spanId }
1721
- }), Qn = (e, t, n) => {
1728
+ }), ir = (e, t, n) => {
1722
1729
  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));
1723
- }, $n = (e, t, n, r, i, a) => L.asyncScoped((o) => j.gen(function* () {
1730
+ }, ar = (e, t, n, r, i, a) => L.asyncScoped((o) => j.gen(function* () {
1724
1731
  let s = yield* j.tryPromise(() => t.subscribe(e, (e) => {
1725
1732
  o.single(e);
1726
1733
  }, n, r, i, a)).pipe(j.matchCause({
1727
- onFailure: (e) => (ar(`subscription.${i}`, n.traceId, e), {
1734
+ onFailure: (e) => (dr(`subscription.${i}`, n.traceId, e), {
1728
1735
  ok: !1,
1729
- error: lr(e)
1736
+ error: hr(e)
1730
1737
  }),
1731
1738
  onSuccess: (e) => ({
1732
1739
  ok: !0,
@@ -1742,21 +1749,21 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1742
1749
  }
1743
1750
  let c = s.unsubscribe;
1744
1751
  if (yield* j.addFinalizer(() => j.sync(() => c())), n.clientId !== void 0) {
1745
- let e = En(n.clientId, () => {
1752
+ let e = Mn(n.clientId, () => {
1746
1753
  o.end();
1747
1754
  });
1748
1755
  yield* j.addFinalizer(() => j.sync(() => e()));
1749
1756
  }
1750
- })), er = (e, t, n, r) => L.asyncScoped((i) => j.gen(function* () {
1757
+ })), or = (e, t, n, r) => L.asyncScoped((i) => j.gen(function* () {
1751
1758
  let a = yield* j.tryPromise(() => t.subscribeComputed(e, (e) => {
1752
1759
  i.single(e._tag === "snapshot" ? {
1753
1760
  ...e,
1754
1761
  computed: !0
1755
1762
  } : e);
1756
1763
  }, n, r)).pipe(j.matchCause({
1757
- onFailure: (e) => (ar(`subscription.${r}`, n.traceId, e), {
1764
+ onFailure: (e) => (dr(`subscription.${r}`, n.traceId, e), {
1758
1765
  ok: !1,
1759
- error: lr(e)
1766
+ error: hr(e)
1760
1767
  }),
1761
1768
  onSuccess: (e) => ({
1762
1769
  ok: !0,
@@ -1772,21 +1779,21 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1772
1779
  }
1773
1780
  let o = a.unsubscribe;
1774
1781
  if (yield* j.addFinalizer(() => j.sync(() => o())), n.clientId !== void 0) {
1775
- let e = En(n.clientId, () => {
1782
+ let e = Mn(n.clientId, () => {
1776
1783
  i.end();
1777
1784
  });
1778
1785
  yield* j.addFinalizer(() => j.sync(() => e()));
1779
1786
  }
1780
- })), tr = (e, t, n = "rpc.subscription", r, i) => L.unwrap(j.gen(function* () {
1781
- let a = yield* ye, o = yield* ve, s = yield* Xn;
1782
- Qn(s, n, a);
1783
- let c = Yn(a, s, o.clientId), l = Vn(a.id, o.clientId), u = Gn({ subjectKey: l }, () => In({
1787
+ })), sr = (e, t, n = "rpc.subscription", r, i) => L.unwrap(j.gen(function* () {
1788
+ let a = yield* O, o = yield* ye, s = yield* nr;
1789
+ ir(s, n, a);
1790
+ let c = tr(a, s, o.clientId), l = qn(a.id, o.clientId), u = Zn({ subjectKey: l }, () => Hn({
1784
1791
  traceId: c.traceId,
1785
1792
  ...c.spanId === void 0 ? {} : { spanId: c.spanId }
1786
1793
  }, () => e(c))), d = j.isEffect(u) ? yield* u.pipe(j.matchCause({
1787
- onFailure: (e) => (ar(`subscription.${n}`, c.traceId, e), {
1794
+ onFailure: (e) => (dr(`subscription.${n}`, c.traceId, e), {
1788
1795
  ok: !1,
1789
- error: lr(e)
1796
+ error: hr(e)
1790
1797
  }),
1791
1798
  onSuccess: (e) => ({
1792
1799
  ok: !0,
@@ -1801,38 +1808,38 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1801
1808
  error: d.error
1802
1809
  });
1803
1810
  let f = d.value;
1804
- if (_n(f)) return er(f, t, c, n);
1811
+ if (Cn(f)) return or(f, t, c, n);
1805
1812
  let p = f, m = r?.(p);
1806
- return $n(p, t, c, m, n, i === void 0 ? void 0 : {
1813
+ return ar(p, t, c, m, n, i === void 0 ? void 0 : {
1807
1814
  key: i.scope === "subject" ? `${i.baseKey}:s:${l}` : `${i.baseKey}:global`,
1808
1815
  ttlMs: i.ttlMs,
1809
1816
  swrMs: i.swrMs
1810
1817
  });
1811
- }).pipe(j.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), nr = (e, t = "rpc.stream") => L.unwrap(j.gen(function* () {
1812
- let n = yield* ye, r = yield* ve, i = yield* Xn;
1813
- Qn(i, t, n);
1814
- let a = Yn(n, i, r.clientId), o = e(a), s = j.isEffect(o) ? yield* o.pipe(j.orDie) : o;
1818
+ }).pipe(j.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), cr = (e, t = "rpc.stream") => L.unwrap(j.gen(function* () {
1819
+ let n = yield* O, r = yield* ye, i = yield* nr;
1820
+ ir(i, t, n);
1821
+ let a = tr(n, i, r.clientId), o = e(a), s = j.isEffect(o) ? yield* o.pipe(j.orDie) : o;
1815
1822
  if (a.clientId === void 0) return s;
1816
1823
  let c = a.clientId;
1817
1824
  return L.unwrapScoped(j.gen(function* () {
1818
- let e = yield* je.make(), t = En(c, () => {
1819
- je.unsafeDone(e, j.void);
1825
+ let e = yield* Ie.make(), t = Mn(c, () => {
1826
+ Ie.unsafeDone(e, j.void);
1820
1827
  });
1821
- return yield* j.addFinalizer(() => j.sync(() => t())), s.pipe(L.interruptWhen(je.await(e)));
1828
+ return yield* j.addFinalizer(() => j.sync(() => t())), s.pipe(L.interruptWhen(Ie.await(e)));
1822
1829
  }));
1823
- }).pipe(j.withSpan(t, { attributes: { "framework.kind": "stream" } }))), rr = ge({ scope: "voltro:rpc" }), ir = ge({ scope: "voltro:http" }), ar = (e, t, n) => {
1830
+ }).pipe(j.withSpan(t, { attributes: { "framework.kind": "stream" } }))), lr = Ne({ scope: "voltro:rpc" }), ur = Ne({ scope: "voltro:http" }), dr = (e, t, n) => {
1824
1831
  if (k.isInterruptedOnly(n)) return;
1825
- let r = k.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = k.dieOption(n)._tag === "Some", s = Mt(r), c = {
1832
+ let r = k.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = k.dieOption(n)._tag === "Some", s = zt(r), c = {
1826
1833
  traceId: t,
1827
1834
  ...i === void 0 ? {} : { errorTag: i },
1828
1835
  ...s
1829
1836
  }, l = a === "Failed to execute statement" && typeof s.dbMessage == "string" ? s.dbMessage : a;
1830
- o ? rr.error(`${e} failed: ${l}`, c) : rr.warn(`${e} failed: ${l}`, c);
1831
- }, or = /* @__PURE__ */ new Set(["SqlError", "ResultLengthMismatch"]), sr = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && or.has(e._tag), cr = (e) => ({
1837
+ o ? lr.error(`${e} failed: ${l}`, c) : lr.warn(`${e} failed: ${l}`, c);
1838
+ }, fr = /* @__PURE__ */ new Set(["SqlError", "ResultLengthMismatch"]), pr = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && fr.has(e._tag), mr = (e) => ({
1832
1839
  _tag: "InternalError",
1833
1840
  message: "internal server error",
1834
1841
  traceId: e
1835
- }), lr = (e) => {
1842
+ }), hr = (e) => {
1836
1843
  let t = k.squash(e);
1837
1844
  t && typeof t == "object" && t._tag === "UnknownException" && (t = t.error ?? t.cause ?? t);
1838
1845
  let n = t && typeof t == "object" ? t : {}, r = {};
@@ -1843,19 +1850,19 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1843
1850
  ...typeof i == "string" ? { _tag: i } : {},
1844
1851
  message: typeof a == "string" ? a : String(t)
1845
1852
  };
1846
- }, ur = (e, t, n = "rpc.mutation") => j.gen(function* () {
1847
- let r = yield* ye, i = yield* ve, a = yield* Xn;
1848
- Qn(a, n, r);
1849
- let o = Yn(r, a, i.clientId), s = Gn({ subjectKey: Vn(r.id, i.clientId) }, () => In({
1853
+ }, gr = (e, t, n = "rpc.mutation") => j.gen(function* () {
1854
+ let r = yield* O, i = yield* ye, a = yield* nr;
1855
+ ir(a, n, r);
1856
+ let o = tr(r, a, i.clientId), s = Zn({ subjectKey: qn(r.id, i.clientId) }, () => Hn({
1850
1857
  traceId: o.traceId,
1851
1858
  ...o.spanId === void 0 ? {} : { spanId: o.spanId }
1852
1859
  }, () => e(t, o)));
1853
1860
  return yield* (j.isEffect(s) ? s : j.tryPromise({
1854
1861
  try: () => Promise.resolve(s),
1855
1862
  catch: (e) => e
1856
- })).pipe(j.tapErrorCause((e) => j.sync(() => ar(n, o.traceId, e))), j.catchIf(sr, () => j.die(cr(o.traceId))), j.annotateLogs(Zn(o)));
1857
- }).pipe(j.withSpan(n, { attributes: { "framework.kind": "mutation" } })), dr = 8 * 1024 * 1024, fr = (e) => {
1858
- let t = e.port ?? 4e3, n = e.path ?? "/ws", r = Be(), i = (t) => z.HttpServerRequest.pipe(j.flatMap((t) => j.gen(function* () {
1863
+ })).pipe(j.tapErrorCause((e) => j.sync(() => dr(n, o.traceId, e))), j.catchIf(pr, () => j.die(mr(o.traceId))), j.annotateLogs(rr(o)));
1864
+ }).pipe(j.withSpan(n, { attributes: { "framework.kind": "mutation" } })), _r = 8 * 1024 * 1024, vr = (e) => {
1865
+ let t = e.port ?? 4e3, n = e.path ?? "/ws", r = Ge(), i = (t) => z.HttpServerRequest.pipe(j.flatMap((t) => j.gen(function* () {
1859
1866
  if (!e.inspectRoute) return B.text("inspect route not configured", { status: 404 });
1860
1867
  let n = {};
1861
1868
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
@@ -1931,7 +1938,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1931
1938
  let t = (e) => z.HttpServerRequest.pipe(j.flatMap((t) => j.gen(function* () {
1932
1939
  let n = {};
1933
1940
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
1934
- let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(j.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o = Pn(n.traceparent), s = yield* j.promise(() => e.handle({
1941
+ let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(j.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o = Bn(n.traceparent), s = yield* j.promise(() => e.handle({
1935
1942
  method: t.method,
1936
1943
  path: a,
1937
1944
  headers: n,
@@ -1961,8 +1968,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1961
1968
  query: a,
1962
1969
  headers: n,
1963
1970
  rawBody: o
1964
- }, c = yield* j.promise(() => Xe(e, s));
1965
- c.status >= 500 && ir.warn(`${t.method} ${i} → ${c.status}`, {
1971
+ }, c = yield* j.promise(() => nt(e, s));
1972
+ c.status >= 500 && ur.warn(`${t.method} ${i} → ${c.status}`, {
1966
1973
  method: t.method,
1967
1974
  path: i,
1968
1975
  status: c.status,
@@ -1974,7 +1981,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1974
1981
  headers: l
1975
1982
  };
1976
1983
  return c.body instanceof Uint8Array ? B.uint8Array(c.body, u) : B.text(c.body ?? "", u);
1977
- })), j.tapErrorCause((t) => k.isInterruptedOnly(t) ? j.void : j.sync(() => ir.error(`${e.map((e) => e.method).join("|")} ${e[0].path} threw`, { path: e[0].path }, k.squash(t))))), n = /* @__PURE__ */ new Map();
1984
+ })), j.tapErrorCause((t) => k.isInterruptedOnly(t) ? j.void : j.sync(() => ur.error(`${e.map((e) => e.method).join("|")} ${e[0].path} threw`, { path: e[0].path }, k.squash(t))))), n = /* @__PURE__ */ new Map();
1978
1985
  for (let t of e.httpRoutes) {
1979
1986
  let e = n.get(t.path);
1980
1987
  e ? e.push(t) : n.set(t.path, [t]);
@@ -1985,13 +1992,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
1985
1992
  });
1986
1993
  l = M.mergeAll(...r);
1987
1994
  }
1988
- let u = V.layerProtocolWebsocketRouter({ path: n }), d = V.layer(e.group), f = V.layer(e.group).pipe(M.provide(V.layerProtocolHttpRouter({ path: "/rpc" })), M.provide(Je.layerJson), M.provide(e.httpHandlersLayer ?? e.handlersLayer)), p = M.scopedDiscard(j.gen(function* () {
1989
- let e = yield* V.Protocol;
1995
+ let u = et.layerProtocolWebsocketRouter({ path: n }), d = et.layer(e.group), f = et.layer(e.group).pipe(M.provide(et.layerProtocolHttpRouter({ path: "/rpc" })), M.provide($e.layerJson), M.provide(e.httpHandlersLayer ?? e.handlersLayer)), p = M.scopedDiscard(j.gen(function* () {
1996
+ let e = yield* et.Protocol;
1990
1997
  yield* j.forkScoped(j.gen(function* () {
1991
1998
  let t = yield* e.disconnects.take;
1992
- Cn(t), Dn(t);
1999
+ kn(t), Nn(t);
1993
2000
  }).pipe(j.forever));
1994
- })), m = M.mergeAll(d, p).pipe(M.provide(u), M.provide(Je.layerJson), M.provide(e.handlersLayer)), h = M.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) => j.gen(function* () {
2001
+ })), m = M.mergeAll(d, p).pipe(M.provide(u), M.provide($e.layerJson), M.provide(e.handlersLayer)), h = M.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) => j.gen(function* () {
1995
2002
  let t = yield* z.HttpServerRequest, n = {};
1996
2003
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
1997
2004
  let r = t.url.indexOf("?"), i = r === -1 ? t.url : t.url.slice(0, r);
@@ -2032,13 +2039,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2032
2039
  status: l.status,
2033
2040
  ...l.headers ? { headers: l.headers } : {}
2034
2041
  });
2035
- }), S = M.unwrapEffect(R.toHttpEffect(h).pipe(j.map((e) => Ue.serve(x(e))))).pipe(M.provide(Ge.layer(() => r, { port: t })), M.provide(We.layer));
2042
+ }), S = M.unwrapEffect(R.toHttpEffect(h).pipe(j.map((e) => Je.serve(x(e))))).pipe(M.provide(Xe.layer(() => r, { port: t })), M.provide(Ye.layer));
2036
2043
  e.tracerLayer && (S = S.pipe(M.provide(e.tracerLayer)));
2037
- let C = ge({ scope: "voltro:rpc" }), w = M.launch(S).pipe(j.catchAllCause((e) => j.sync(() => {
2044
+ let C = Ne({ scope: "voltro:rpc" }), ee = M.launch(S).pipe(j.catchAllCause((e) => j.sync(() => {
2038
2045
  C.error("rpc server crashed", {}, k.squash(e)), process.exit(1);
2039
2046
  })));
2040
- return Ke.runMain(w, { disableErrorReporting: !0 }), r;
2041
- }, pr = (e, t = 1e4) => new Promise((n, r) => {
2047
+ return Ze.runMain(ee, { disableErrorReporting: !0 }), r;
2048
+ }, yr = (e, t = 1e4) => new Promise((n, r) => {
2042
2049
  if (e.listening) {
2043
2050
  n();
2044
2051
  return;
@@ -2054,13 +2061,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2054
2061
  o(e);
2055
2062
  }
2056
2063
  a = setTimeout(() => o(/* @__PURE__ */ Error(`rpc server did not bind within ${t}ms`)), t), e.on("listening", s), e.on("error", c);
2057
- }), mr = () => {
2064
+ }), br = () => {
2058
2065
  let e = process.env.FRAMEWORK_TRACING?.toLowerCase();
2059
2066
  return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ? "otlp" : "off";
2060
- }, hr = () => {
2067
+ }, xr = () => {
2061
2068
  let e = process.env.FRAMEWORK_METRICS?.toLowerCase();
2062
2069
  return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ? "otlp" : "off";
2063
- }, gr = async () => {
2070
+ }, Sr = async () => {
2064
2071
  let [e, t, n, r, i] = await Promise.all([
2065
2072
  import("@opentelemetry/sdk-trace-base"),
2066
2073
  import("@opentelemetry/sdk-metrics"),
@@ -2075,7 +2082,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2075
2082
  otlpMetrics: r,
2076
2083
  nodeSdk: i
2077
2084
  };
2078
- }, _r = (e, t, n) => {
2085
+ }, Cr = (e, t, n) => {
2079
2086
  let { PeriodicExportingMetricReader: r, ConsoleMetricExporter: i, InMemoryMetricExporter: a, AggregationTemporality: o } = e.sdkMetrics;
2080
2087
  if (t === "off") return {
2081
2088
  reader: void 0,
@@ -2098,8 +2105,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2098
2105
  }),
2099
2106
  inMemory: void 0
2100
2107
  };
2101
- }, vr = async (e = {}) => {
2102
- let t = e.mode ?? mr(), n = e.metricsMode ?? hr(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
2108
+ }, wr = async (e = {}) => {
2109
+ let t = e.mode ?? br(), n = e.metricsMode ?? xr(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
2103
2110
  if (t === "off" && e.traceSink === void 0 && n === "off" && r.length === 0 && i.length === 0) return {
2104
2111
  layer: M.empty,
2105
2112
  mode: t,
@@ -2108,13 +2115,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2108
2115
  metricsMode: n,
2109
2116
  inMemoryMetricExporter: void 0
2110
2117
  };
2111
- let a = await gr(), { 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;
2118
+ let a = await Sr(), { 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;
2112
2119
  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());
2113
2120
  let m = [
2114
2121
  ...e.traceSink ? [e.traceSink] : [],
2115
2122
  ...p ? [p] : [],
2116
2123
  ...r
2117
- ], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = _r(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 = {
2124
+ ], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = Cr(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 = {
2118
2125
  serviceName: d,
2119
2126
  ...e.serviceVersion ? { serviceVersion: e.serviceVersion } : {},
2120
2127
  ...e.resourceAttributes ? { attributes: e.resourceAttributes } : {}
@@ -2132,18 +2139,18 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2132
2139
  metricsMode: n,
2133
2140
  inMemoryMetricExporter: _
2134
2141
  };
2135
- }, yr = {
2136
- [H.INTERNAL]: "internal",
2137
- [H.SERVER]: "server",
2138
- [H.CLIENT]: "client",
2139
- [H.PRODUCER]: "producer",
2140
- [H.CONSUMER]: "consumer"
2141
- }, br = (e) => e[0] * 1e3 + e[1] / 1e6, xr = 512, Sr = 48, Cr = (e) => {
2142
+ }, Tr = {
2143
+ [at.INTERNAL]: "internal",
2144
+ [at.SERVER]: "server",
2145
+ [at.CLIENT]: "client",
2146
+ [at.PRODUCER]: "producer",
2147
+ [at.CONSUMER]: "consumer"
2148
+ }, Er = (e) => e[0] * 1e3 + e[1] / 1e6, Dr = 512, Or = 48, kr = (e) => {
2142
2149
  let t = {}, n = 0;
2143
2150
  for (let r in e) {
2144
- if (n >= Sr) break;
2151
+ if (n >= Or) break;
2145
2152
  let i = e[r];
2146
- if (typeof i == "string") t[r] = i.length > xr ? `${i.slice(0, xr)}…` : i;
2153
+ if (typeof i == "string") t[r] = i.length > Dr ? `${i.slice(0, Dr)}…` : i;
2147
2154
  else if (typeof i == "number" || typeof i == "boolean" || i == null) t[r] = i;
2148
2155
  else {
2149
2156
  let e;
@@ -2152,49 +2159,49 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2152
2159
  } catch {
2153
2160
  e = String(i);
2154
2161
  }
2155
- t[r] = e.length > xr ? `${e.slice(0, xr)}…` : e;
2162
+ t[r] = e.length > Dr ? `${e.slice(0, Dr)}…` : e;
2156
2163
  }
2157
2164
  n++;
2158
2165
  }
2159
2166
  return t;
2160
- }, wr = {
2161
- [$e.UNSET]: "unset",
2162
- [$e.OK]: "ok",
2163
- [$e.ERROR]: "error"
2164
- }, Tr = (e) => {
2167
+ }, Ar = {
2168
+ [ot.UNSET]: "unset",
2169
+ [ot.OK]: "ok",
2170
+ [ot.ERROR]: "error"
2171
+ }, jr = (e) => {
2165
2172
  let t = e.spanContext(), n = e.events.length > 0 ? e.events.slice(0, 16).map((e) => ({
2166
2173
  name: e.name,
2167
- tsMs: br(e.time),
2168
- ...e.attributes ? { attributes: Cr(e.attributes) } : {}
2174
+ tsMs: Er(e.time),
2175
+ ...e.attributes ? { attributes: kr(e.attributes) } : {}
2169
2176
  })) : void 0;
2170
2177
  return {
2171
2178
  traceId: t.traceId,
2172
2179
  spanId: t.spanId,
2173
2180
  parentSpanId: e.parentSpanContext?.spanId ?? null,
2174
2181
  name: e.name,
2175
- kind: yr[e.kind] ?? "internal",
2176
- attributes: Cr(e.attributes),
2177
- startMs: br(e.startTime),
2178
- endMs: br(e.endTime),
2179
- durationMs: br(e.duration),
2180
- status: wr[e.status.code] ?? "unset",
2182
+ kind: Tr[e.kind] ?? "internal",
2183
+ attributes: kr(e.attributes),
2184
+ startMs: Er(e.startTime),
2185
+ endMs: Er(e.endTime),
2186
+ durationMs: Er(e.duration),
2187
+ status: Ar[e.status.code] ?? "unset",
2181
2188
  ...e.status.message ? { statusMessage: e.status.message } : {},
2182
2189
  ...n ? { events: n } : {}
2183
2190
  };
2184
- }, Er = (e) => ({
2191
+ }, Mr = (e) => ({
2185
2192
  onStart: () => {},
2186
2193
  onEnd: (t) => {
2187
2194
  try {
2188
- e(Tr(t));
2195
+ e(jr(t));
2189
2196
  } catch {}
2190
2197
  },
2191
2198
  forceFlush: () => Promise.resolve(),
2192
2199
  shutdown: () => Promise.resolve()
2193
- }), Dr = { get: (e) => Promise.resolve(process.env[e]) }, Or = Dr, kr = (e) => {
2194
- Or = e;
2195
- }, Ar = () => {
2196
- Or = Dr;
2197
- }, jr = async (e) => await Or.get(e) ?? process.env[e], Mr = (e) => process.env[e], Nr = (e, t = 6e4, n = () => Date.now()) => {
2200
+ }), Nr = { get: (e) => Promise.resolve(process.env[e]) }, Pr = Nr, Fr = (e) => {
2201
+ Pr = e;
2202
+ }, Ir = () => {
2203
+ Pr = Nr;
2204
+ }, Lr = async (e) => await Pr.get(e) ?? process.env[e], Rr = (e) => process.env[e], zr = (e, t = 6e4, n = () => Date.now()) => {
2198
2205
  let r = /* @__PURE__ */ new Map();
2199
2206
  return { get: async (i) => {
2200
2207
  let a = r.get(i);
@@ -2205,12 +2212,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2205
2212
  at: n()
2206
2213
  }), o;
2207
2214
  } };
2208
- }, Pr = (e) => {
2215
+ }, Br = (e) => {
2209
2216
  let t = {
2210
2217
  accept: "application/json",
2211
2218
  ...e.headers ?? {}
2212
2219
  };
2213
- if (e.perKey) return Nr({ get: async (n) => {
2220
+ if (e.perKey) return zr({ get: async (n) => {
2214
2221
  let r = await fetch(`${e.url.replace(/\/$/, "")}/${encodeURIComponent(n)}`, { headers: t });
2215
2222
  if (!r.ok) return;
2216
2223
  let i = await r.json();
@@ -2221,43 +2228,52 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2221
2228
  let t = (await a())[e];
2222
2229
  return typeof t == "string" ? t : void 0;
2223
2230
  } };
2224
- }, Fr = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? Dr : e.kind === "custom" ? e.backend : e.kind === "http" ? Pr(e) : Dr, Ir = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : me(e, "voltro:field-encryption:v1", 32), Lr = (t) => {
2231
+ }, Vr = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? Nr : e.kind === "custom" ? e.backend : e.kind === "http" ? Br(e) : Nr, Hr = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : ge(e, "voltro:field-encryption:v1", 32), Ur = (t) => {
2225
2232
  if (t.length !== 32) throw Error(`field cipher key must be 32 bytes, got ${t.length}`);
2226
2233
  return {
2227
2234
  encrypt: (n) => {
2228
- let r = fe(12), i = le("aes-256-gcm", t, r), a = Buffer.concat([i.update(n, "utf8"), i.final()]), o = i.getAuthTag();
2235
+ let r = me(12), i = de("aes-256-gcm", t, r), a = Buffer.concat([i.update(n, "utf8"), i.final()]), o = i.getAuthTag();
2229
2236
  return `${e}${r.toString("base64")}:${o.toString("base64")}:${a.toString("base64")}`;
2230
2237
  },
2231
2238
  decrypt: (n) => {
2232
2239
  let [r, i, a] = n.slice(e.length).split(":");
2233
2240
  if (!r || !i || a === void 0) throw Error("field cipher: malformed ciphertext");
2234
- let o = ue("aes-256-gcm", t, Buffer.from(r, "base64"));
2241
+ let o = fe("aes-256-gcm", t, Buffer.from(r, "base64"));
2235
2242
  return o.setAuthTag(Buffer.from(i, "base64")), Buffer.concat([o.update(Buffer.from(a, "base64")), o.final()]).toString("utf8");
2236
2243
  }
2237
2244
  };
2238
- }, Rr = (e) => Lr(Ir(e)), zr, Br = (e) => {
2239
- zr = e;
2240
- }, Vr = () => zr, J = "_voltro_idempotency", Hr = (e) => {
2245
+ }, Wr = (e) => Ur(Hr(e)), Gr, Kr = (e) => {
2246
+ Gr = e;
2247
+ }, qr = () => Gr, Jr = "no field cipher registered — enable `@voltro/plugin-governance` `governancePlugin({ fieldEncryption: { key } })` (or call setFieldCipher) so a key is available.", Yr = (e) => {
2248
+ let t = qr();
2249
+ if (!t) throw Error(`encryptField: ${Jr}`);
2250
+ return t.encrypt(e);
2251
+ }, Xr = (e) => {
2252
+ if (!x(e)) return e;
2253
+ let t = qr();
2254
+ if (!t) throw Error(`decryptField: ${Jr}`);
2255
+ return t.decrypt(e);
2256
+ }, J = "_voltro_idempotency", Zr = (e) => {
2241
2257
  if (e == null) return null;
2242
2258
  let t = typeof e == "string" ? JSON.parse(e) : e;
2243
2259
  return t && typeof t == "object" && "status" in t ? t : null;
2244
- }, Ur = (e) => ({
2260
+ }, Qr = (e) => ({
2245
2261
  scope: e.scope,
2246
2262
  key: e.key,
2247
2263
  status: e.status === "completed" ? "completed" : "in_flight",
2248
- response: Hr(e.response),
2249
- createdAt: Oe(e.createdAt)
2250
- }), Wr = async (e, n, r) => (await e.query({
2264
+ response: Zr(e.response),
2265
+ createdAt: Me(e.createdAt)
2266
+ }), $r = async (e, n, r) => (await e.query({
2251
2267
  table: J,
2252
2268
  predicate: t(u("scope", n), u("key", r)),
2253
2269
  order: [],
2254
2270
  take: 1,
2255
2271
  skip: void 0,
2256
2272
  projection: void 0
2257
- }))[0] ?? null, Gr = (e) => ({
2273
+ }))[0] ?? null, ei = (e) => ({
2258
2274
  get: async (t, n) => {
2259
- let r = await Wr(e, t, n);
2260
- return r ? Ur(r) : null;
2275
+ let r = await $r(e, t, n);
2276
+ return r ? Qr(r) : null;
2261
2277
  },
2262
2278
  claim: async (t, n, r, i) => {
2263
2279
  for (let a = 0; a < 2; a++) {
@@ -2273,11 +2289,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2273
2289
  createdAt: new Date(r)
2274
2290
  }, { conflictColumns: ["scope", "key"] });
2275
2291
  if (o.id === a) return "claimed";
2276
- if (r - Oe(o.createdAt) < i) return Ur(o);
2292
+ if (r - Me(o.createdAt) < i) return Qr(o);
2277
2293
  await e.delete(J, o.id);
2278
2294
  }
2279
- let a = await Wr(e, t, n);
2280
- return a ? Ur(a) : {
2295
+ let a = await $r(e, t, n);
2296
+ return a ? Qr(a) : {
2281
2297
  scope: t,
2282
2298
  key: n,
2283
2299
  status: "in_flight",
@@ -2286,36 +2302,36 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2286
2302
  };
2287
2303
  },
2288
2304
  complete: async (t, n, r, i) => {
2289
- let a = await Wr(e, t, n);
2305
+ let a = await $r(e, t, n);
2290
2306
  a && await e.update(J, a.id, {
2291
2307
  status: "completed",
2292
2308
  response: r
2293
2309
  });
2294
2310
  },
2295
2311
  release: async (t, n) => {
2296
- let r = await Wr(e, t, n);
2312
+ let r = await $r(e, t, n);
2297
2313
  r && await e.delete(J, r.id);
2298
2314
  }
2299
- }), Y = "_voltro_kv", Kr = (e) => {
2315
+ }), Y = "_voltro_kv", ti = (e) => {
2300
2316
  if (e == null) return null;
2301
2317
  if (e instanceof Date) return e.getTime();
2302
2318
  if (typeof e == "number") return e;
2303
2319
  let t = Date.parse(String(e));
2304
2320
  return Number.isNaN(t) ? null : t;
2305
- }, qr = (e, t) => {
2306
- let n = Kr(e.expiresAt);
2321
+ }, ni = (e, t) => {
2322
+ let n = ti(e.expiresAt);
2307
2323
  return n !== null && n <= t;
2308
- }, Jr = (e) => e === null ? null : JSON.parse(e), Yr = async (e, t) => (await e.query({
2324
+ }, ri = (e) => e === null ? null : JSON.parse(e), ii = async (e, t) => (await e.query({
2309
2325
  table: Y,
2310
2326
  predicate: u("key", t),
2311
2327
  order: [],
2312
2328
  take: 1,
2313
2329
  skip: void 0,
2314
2330
  projection: void 0
2315
- }))[0] ?? null, Xr = (e) => {
2331
+ }))[0] ?? null, ai = (e) => {
2316
2332
  let n = (e, t, n) => j.tryPromise({
2317
2333
  try: n,
2318
- catch: (n) => new tt({
2334
+ catch: (n) => new ct({
2319
2335
  operation: e,
2320
2336
  key: t,
2321
2337
  cause: String(n)
@@ -2323,8 +2339,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2323
2339
  });
2324
2340
  return {
2325
2341
  get: (t) => n("get", t, async () => {
2326
- let n = await Yr(e, t);
2327
- return n === null ? P.none() : qr(n, Date.now()) ? (await e.delete(Y, n.id), P.none()) : P.some(Jr(n.value));
2342
+ let n = await ii(e, t);
2343
+ return n === null ? P.none() : ni(n, Date.now()) ? (await e.delete(Y, n.id), P.none()) : P.some(ri(n.value));
2328
2344
  }),
2329
2345
  set: (t, r, i) => n("set", t, async () => {
2330
2346
  let n = Date.now(), a = i?.ttlMs !== void 0 && i.ttlMs > 0 ? new Date(n + i.ttlMs) : null, o = f({
@@ -2347,17 +2363,17 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2347
2363
  });
2348
2364
  }),
2349
2365
  delete: (t) => n("delete", t, async () => {
2350
- let n = await Yr(e, t);
2366
+ let n = await ii(e, t);
2351
2367
  if (n === null) return !1;
2352
- let r = !qr(n, Date.now());
2368
+ let r = !ni(n, Date.now());
2353
2369
  return await e.delete(Y, n.id), r;
2354
2370
  }),
2355
2371
  has: (t) => n("has", t, async () => {
2356
- let n = await Yr(e, t);
2357
- return n === null ? !1 : qr(n, Date.now()) ? (await e.delete(Y, n.id), !1) : !0;
2372
+ let n = await ii(e, t);
2373
+ return n === null ? !1 : ni(n, Date.now()) ? (await e.delete(Y, n.id), !1) : !0;
2358
2374
  }),
2359
2375
  list: (r) => n("list", "", async () => {
2360
- let n = Date.now(), i = T(x("expiresAt"), h("expiresAt", new Date(n))), a = r === "" ? i : t(o("key", r), i), s = await e.query({
2376
+ let n = Date.now(), i = re(S("expiresAt"), h("expiresAt", new Date(n))), a = r === "" ? i : t(o("key", r), i), s = await e.query({
2361
2377
  table: Y,
2362
2378
  predicate: a,
2363
2379
  order: [],
@@ -2365,7 +2381,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2365
2381
  skip: void 0,
2366
2382
  projection: void 0
2367
2383
  }), c = [];
2368
- for (let e of s) qr(e, n) || (r === "" || e.key.startsWith(r)) && c.push(e.key);
2384
+ for (let e of s) ni(e, n) || (r === "" || e.key.startsWith(r)) && c.push(e.key);
2369
2385
  return c;
2370
2386
  }),
2371
2387
  clear: () => n("clear", "", async () => {
@@ -2375,8 +2391,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2375
2391
  } });
2376
2392
  })
2377
2393
  };
2378
- }, Zr = async ({ store: e, env: t = process.env }) => {
2379
- let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? at(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(M.provide(rt)) : r === "memory" ? it() : M.succeed(nt, nt.of(Xr(e))), a = Fe.make(et.Default.pipe(M.provide(i))), o = await a.runPromise(et);
2394
+ }, oi = async ({ store: e, env: t = process.env }) => {
2395
+ let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? ft(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(M.provide(ut)) : r === "memory" ? dt() : M.succeed(lt, lt.of(ai(e))), a = Be.make(st.Default.pipe(M.provide(i))), o = await a.runPromise(st);
2380
2396
  return {
2381
2397
  kv: {
2382
2398
  get: (e) => a.runPromise(o.get(e)).then((e) => P.getOrUndefined(e)),
@@ -2391,7 +2407,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2391
2407
  backend: r,
2392
2408
  dispose: () => a.dispose()
2393
2409
  };
2394
- }, Qr = {
2410
+ }, si = {
2395
2411
  get: () => Promise.resolve(void 0),
2396
2412
  getOrElse: (e, t) => Promise.resolve(t()),
2397
2413
  set: () => Promise.resolve(),
@@ -2399,7 +2415,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2399
2415
  has: () => Promise.resolve(!1),
2400
2416
  list: () => Promise.resolve([]),
2401
2417
  clear: () => Promise.resolve()
2402
- }, $r = "_voltro_api_keys", ei = (e) => de("sha256").update(e, "utf8").digest("hex"), ti = (e = "voltro_") => `${e}${fe(30).toString("base64url")}`, ni = (e) => ({
2418
+ }, ci = "_voltro_api_keys", li = (e) => pe("sha256").update(e, "utf8").digest("hex"), ui = (e = "voltro_") => `${e}${me(30).toString("base64url")}`, di = (e) => ({
2403
2419
  id: e.id,
2404
2420
  name: e.name,
2405
2421
  keyPrefix: e.keyPrefix,
@@ -2409,17 +2425,17 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2409
2425
  expiresAt: e.expiresAt,
2410
2426
  revokedAt: e.revokedAt,
2411
2427
  createdAt: e.createdAt
2412
- }), ri = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), ii = (e, t = {}) => {
2428
+ }), fi = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), pi = (e, t = {}) => {
2413
2429
  let n = t.prefix ?? "voltro_", r = async (t) => {
2414
- let r = ti(n), i = f({
2430
+ let r = ui(n), i = f({
2415
2431
  kind: "typeid",
2416
2432
  prefix: "apikey"
2417
- }, $r), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
2433
+ }, ci), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
2418
2434
  return await e.insert({
2419
2435
  id: i,
2420
2436
  tenantId: t.tenantId ?? null,
2421
2437
  name: t.name,
2422
- hashedKey: ei(r),
2438
+ hashedKey: li(r),
2423
2439
  keyPrefix: r.slice(0, n.length + 6),
2424
2440
  scopes: a,
2425
2441
  lastUsedAt: null,
@@ -2437,7 +2453,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2437
2453
  };
2438
2454
  }, i = async (t, n = Date.now()) => {
2439
2455
  let r = await e.findByHash(t);
2440
- return !r || !ri(r, n) ? null : (await e.patch(r.id, { lastUsedAt: n }), {
2456
+ return !r || !fi(r, n) ? null : (await e.patch(r.id, { lastUsedAt: n }), {
2441
2457
  id: r.id,
2442
2458
  tenantId: r.tenantId ?? "",
2443
2459
  scopes: r.scopes ?? []
@@ -2446,7 +2462,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2446
2462
  return {
2447
2463
  issue: r,
2448
2464
  resolveByHash: i,
2449
- verify: (e, t) => i(ei(e), t),
2465
+ verify: (e, t) => i(li(e), t),
2450
2466
  revoke: async (t, n = Date.now()) => await e.findById(t) ? (await e.patch(t, { revokedAt: n }), !0) : !1,
2451
2467
  rotate: async (t, n = Date.now()) => {
2452
2468
  let i = await e.findById(t);
@@ -2457,9 +2473,9 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2457
2473
  createdBy: i.createdBy
2458
2474
  })) : null;
2459
2475
  },
2460
- list: async (t) => (await e.listByTenant(t)).map(ni)
2476
+ list: async (t) => (await e.listByTenant(t)).map(di)
2461
2477
  };
2462
- }, ai = () => {
2478
+ }, mi = () => {
2463
2479
  let e = /* @__PURE__ */ new Map();
2464
2480
  return {
2465
2481
  insert: async (t) => {
@@ -2476,21 +2492,21 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2476
2492
  });
2477
2493
  }
2478
2494
  };
2479
- }, oi = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, si = (e) => ({
2495
+ }, hi = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, gi = (e) => ({
2480
2496
  id: String(e.id),
2481
2497
  tenantId: e.tenantId ?? null,
2482
2498
  name: String(e.name),
2483
2499
  hashedKey: String(e.hashedKey),
2484
2500
  keyPrefix: String(e.keyPrefix),
2485
2501
  scopes: e.scopes ?? null,
2486
- lastUsedAt: oi(e.lastUsedAt),
2487
- expiresAt: oi(e.expiresAt),
2488
- revokedAt: oi(e.revokedAt),
2502
+ lastUsedAt: hi(e.lastUsedAt),
2503
+ expiresAt: hi(e.expiresAt),
2504
+ revokedAt: hi(e.revokedAt),
2489
2505
  createdBy: e.createdBy ?? null,
2490
- createdAt: oi(e.createdAt) ?? 0
2491
- }), ci = (e) => {
2506
+ createdAt: hi(e.createdAt) ?? 0
2507
+ }), _i = (e) => {
2492
2508
  let t = async (t) => await e.query({
2493
- table: $r,
2509
+ table: ci,
2494
2510
  predicate: t,
2495
2511
  order: [],
2496
2512
  take: void 0,
@@ -2508,32 +2524,32 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2508
2524
  };
2509
2525
  return {
2510
2526
  insert: async (t) => {
2511
- await e.insert($r, n(t));
2527
+ await e.insert(ci, n(t));
2512
2528
  },
2513
2529
  findByHash: async (e) => {
2514
2530
  let n = await t(u("hashedKey", e));
2515
- return n[0] ? si(n[0]) : null;
2531
+ return n[0] ? gi(n[0]) : null;
2516
2532
  },
2517
2533
  findById: async (e) => {
2518
2534
  let n = await t(u("id", e));
2519
- return n[0] ? si(n[0]) : null;
2535
+ return n[0] ? gi(n[0]) : null;
2520
2536
  },
2521
- listByTenant: async (e) => (await t(e === null ? void 0 : u("tenantId", e))).map(si).filter((t) => e === null || t.tenantId === e),
2537
+ listByTenant: async (e) => (await t(e === null ? void 0 : u("tenantId", e))).map(gi).filter((t) => e === null || t.tenantId === e),
2522
2538
  patch: async (t, r) => {
2523
- await e.update($r, t, n(r));
2539
+ await e.update(ci, t, n(r));
2524
2540
  }
2525
2541
  };
2526
- }, li = (e, t = {}) => ot({
2542
+ }, vi = (e, t = {}) => pt({
2527
2543
  id: "voltro-apikey",
2528
2544
  ...t.prefix ? { prefix: t.prefix } : {},
2529
2545
  resolveKey: (t) => e.resolveByHash(t)
2530
- }), ui = (e) => {
2546
+ }), yi = (e) => {
2531
2547
  let t = e.subject;
2532
2548
  return {
2533
2549
  id: t.id ?? null,
2534
2550
  tenantId: t.tenantId ?? null
2535
2551
  };
2536
- }, di = (e, t = "/v1/api-keys") => {
2552
+ }, bi = (e, t = "/v1/api-keys") => {
2537
2553
  let n = I.Struct({
2538
2554
  id: I.String,
2539
2555
  name: I.String,
@@ -2546,11 +2562,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2546
2562
  createdAt: I.Number
2547
2563
  });
2548
2564
  return [
2549
- Ye({
2565
+ tt({
2550
2566
  method: "POST",
2551
2567
  path: `${t}/issue`,
2552
2568
  summary: "Issue an API key (the token is returned ONCE).",
2553
- guards: [Ze(_e)],
2569
+ guards: [rt(ve)],
2554
2570
  input: I.Struct({ body: I.Struct({
2555
2571
  name: I.String,
2556
2572
  scopes: I.optional(I.Array(I.String)),
@@ -2562,7 +2578,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2562
2578
  keyPrefix: I.String
2563
2579
  }),
2564
2580
  handler: async (t, n) => {
2565
- let r = t.body, i = ui(n), a = await e.issue({
2581
+ let r = t.body, i = yi(n), a = await e.issue({
2566
2582
  tenantId: i.tenantId,
2567
2583
  name: r.name,
2568
2584
  ...r.scopes ? { scopes: r.scopes } : {},
@@ -2576,26 +2592,26 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2576
2592
  };
2577
2593
  }
2578
2594
  }),
2579
- Ye({
2595
+ tt({
2580
2596
  method: "GET",
2581
2597
  path: t,
2582
2598
  summary: "List the caller tenant's API keys (no secrets).",
2583
- guards: [Ze(_e)],
2599
+ guards: [rt(ve)],
2584
2600
  input: I.Struct({}),
2585
2601
  output: I.Struct({ keys: I.Array(n) }),
2586
- handler: async (t, n) => ({ keys: [...await e.list(ui(n).tenantId)] })
2602
+ handler: async (t, n) => ({ keys: [...await e.list(yi(n).tenantId)] })
2587
2603
  }),
2588
- Ye({
2604
+ tt({
2589
2605
  method: "POST",
2590
2606
  path: `${t}/revoke`,
2591
2607
  summary: "Revoke an API key by id.",
2592
- guards: [Ze(_e)],
2608
+ guards: [rt(ve)],
2593
2609
  input: I.Struct({ body: I.Struct({ id: I.String }) }),
2594
2610
  output: I.Struct({ ok: I.Boolean }),
2595
2611
  handler: async (t, n) => ({ ok: await e.revoke(t.body.id) })
2596
2612
  })
2597
2613
  ];
2598
- }, fi = (e) => qe.make(e.name, {
2614
+ }, xi = (e) => Qe.make(e.name, {
2599
2615
  payload: e.payloadSchema,
2600
2616
  success: Ce,
2601
2617
  error: e.errorSchema
@@ -2604,13 +2620,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2604
2620
  workflowName: e,
2605
2621
  executionId: t,
2606
2622
  status: "running"
2607
- }), pi = X, mi = (e) => {
2623
+ }), Si = X, Ci = (e) => {
2608
2624
  let t = k.failureOption(e), n = t._tag === "Some" ? t.value : k.squash(e);
2609
2625
  return {
2610
2626
  tag: n && typeof n == "object" && "_tag" in n ? String(n._tag) : null,
2611
2627
  message: n?.message ?? String(n)
2612
2628
  };
2613
- }, hi = (e, t, n) => {
2629
+ }, wi = (e, t, n) => {
2614
2630
  if (n === void 0) return {
2615
2631
  id: t,
2616
2632
  workflowName: e,
@@ -2625,7 +2641,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2625
2641
  };
2626
2642
  if (typeof n == "object" && n && n._tag === "Complete") {
2627
2643
  let r = n.exit;
2628
- return Pe.isSuccess(r) ? {
2644
+ return ze.isSuccess(r) ? {
2629
2645
  id: t,
2630
2646
  workflowName: e,
2631
2647
  executionId: t,
@@ -2636,7 +2652,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2636
2652
  workflowName: e,
2637
2653
  executionId: t,
2638
2654
  status: "failed",
2639
- error: mi(r.cause)
2655
+ error: Ci(r.cause)
2640
2656
  };
2641
2657
  }
2642
2658
  return {
@@ -2645,15 +2661,15 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2645
2661
  executionId: t,
2646
2662
  status: "running"
2647
2663
  };
2648
- }, gi = (e) => new Promise((t) => setTimeout(t, e)), _i = (e) => {
2664
+ }, Ti = (e) => new Promise((t) => setTimeout(t, e)), Ei = (e) => {
2649
2665
  let t = new Map(e.workflows.map((e) => [e.definition.name, e.definition])), n = (e) => {
2650
2666
  let n = t.get(e);
2651
2667
  if (!n) throw Error(`Unknown workflow: ${e}`);
2652
2668
  return n;
2653
2669
  }, r = async (t, r) => {
2654
2670
  let i = n(t);
2655
- return hi(t, r, await e.runEffect(i.poll(r)));
2656
- }, i = async () => e.runEffect(st()), a = async (t, r, i) => {
2671
+ return wi(t, r, await e.runEffect(i.poll(r)));
2672
+ }, i = async () => e.runEffect(mt()), a = async (t, r, i) => {
2657
2673
  let a = n(t), o;
2658
2674
  return i?.callerContext !== void 0 && (o = await e.runEffect(a.executionId(r)), await e.rememberStartContext?.(t, o, i.callerContext)), i?.wait ? (await e.runEffect(a.execute(r)), X(t, o ?? await e.runEffect(a.executionId(r)))) : X(t, await e.runEffect(a.execute(r, { discard: !0 })));
2659
2675
  };
@@ -2693,7 +2709,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2693
2709
  let e = await r(i, a);
2694
2710
  if (e.status === "succeeded" || e.status === "failed" || e.status === "cancelled") return e;
2695
2711
  if (o?.timeoutMs !== void 0 && Date.now() - s >= o.timeoutMs) throw Error(`Timed out waiting for workflow '${i}' run '${a}'`);
2696
- await gi(c);
2712
+ await Ti(c);
2697
2713
  }
2698
2714
  }),
2699
2715
  cancel: async (t, r) => {
@@ -2731,7 +2747,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2731
2747
  return e.retry(t, n);
2732
2748
  }
2733
2749
  };
2734
- }, vi = (e, t) => ({
2750
+ }, Di = (e, t) => ({
2735
2751
  ...e,
2736
2752
  start: async (n, r, i) => {
2737
2753
  if (i?.wait) throw Error("ctx.workflows.start(..., { wait: true }) is not allowed inside a mutation transaction; start the workflow and wait after commit.");
@@ -2746,7 +2762,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2746
2762
  run: async () => {
2747
2763
  throw Error("ctx.workflows.run(...) is not allowed inside a mutation transaction; use ctx.workflows.start(...) so the workflow starts after commit.");
2748
2764
  }
2749
- }), yi = (e, t) => ({
2765
+ }), Oi = (e, t) => ({
2750
2766
  ...e,
2751
2767
  start: (n, r, i) => e.start(n, r, {
2752
2768
  ...i,
@@ -2760,7 +2776,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2760
2776
  ...i,
2761
2777
  callerContext: t
2762
2778
  })
2763
- }), bi = (e) => {
2779
+ }), ki = (e) => {
2764
2780
  let t = () => {
2765
2781
  let t = e();
2766
2782
  if (!t) throw Error("Workflow runtime is not ready yet");
@@ -2781,11 +2797,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2781
2797
  listRuns: ((e) => t().listRuns(e)),
2782
2798
  retry: (e, n) => t().retry(e, n)
2783
2799
  };
2784
- }, xi = (e, t) => {
2800
+ }, Ai = (e, t) => {
2785
2801
  let n = {};
2786
2802
  for (let r of e) n[r.definition.name] = (e) => (t ? j.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(j.map((e) => X(r.definition.name, e)))).pipe(j.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
2787
2803
  return n;
2788
- }, Si = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
2804
+ }, ji = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
2789
2805
  let a = t.resolveStartContext?.(e.definition.name, i);
2790
2806
  return (a === void 0 ? j.succeed(void 0) : j.promise(() => Promise.resolve(a))).pipe(j.flatMap((a) => {
2791
2807
  let o = e.buildExecute(t.buildContext(a, {
@@ -2796,40 +2812,40 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2796
2812
  }));
2797
2813
  return (n?.(e, o, a) ?? o)(r, i);
2798
2814
  }));
2799
- }))), Ci = (e) => ({
2815
+ }))), Mi = (e) => ({
2800
2816
  _tag: "workflowEventTrigger",
2801
2817
  ...e
2802
- }), wi = Ci, Ti = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", Ei = () => {
2818
+ }), Ni = Mi, Pi = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", Fi = () => {
2803
2819
  let e = globalThis.crypto;
2804
2820
  return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
2805
- }, Di = (e) => `${e}_${Ei()}`, Oi = (e) => e.id ?? `${e.event}->${e.workflow}`, ki = E("_voltro_workflow_events", {
2821
+ }, Ii = (e) => `${e}_${Fi()}`, Li = (e) => e.id ?? `${e.event}->${e.workflow}`, Ri = T("_voltro_workflow_events", {
2806
2822
  id: v({ prefix: "wfe" }),
2807
- name: D(),
2808
- payload: S(),
2809
- source: D(),
2810
- subject: S().nullable(),
2811
- traceId: D().nullable(),
2812
- occurredAt: O().default("now")
2813
- }).index(["name"]).index(["source"]).index(["occurredAt"]).reactive(), Ai = E("_voltro_workflow_event_deliveries", {
2823
+ name: E(),
2824
+ payload: C(),
2825
+ source: E(),
2826
+ subject: C().nullable(),
2827
+ traceId: E().nullable(),
2828
+ occurredAt: D().default("now")
2829
+ }).index(["name"]).index(["source"]).index(["occurredAt"]).reactive(), zi = T("_voltro_workflow_event_deliveries", {
2814
2830
  id: v({ prefix: "wfed" }),
2815
- eventId: D(),
2816
- eventName: D(),
2817
- triggerId: D(),
2818
- workflowName: D(),
2819
- executionId: D().nullable(),
2820
- status: D().oneOf([
2831
+ eventId: E(),
2832
+ eventName: E(),
2833
+ triggerId: E(),
2834
+ workflowName: E(),
2835
+ executionId: E().nullable(),
2836
+ status: E().oneOf([
2821
2837
  "starting",
2822
2838
  "started",
2823
2839
  "skipped",
2824
2840
  "failed"
2825
2841
  ]).default("starting"),
2826
- idempotencyKey: D().unique(),
2842
+ idempotencyKey: E().unique(),
2827
2843
  skipped: r().default(!1),
2828
- errorMessage: D().nullable(),
2829
- createdAt: O().default("now"),
2830
- completedAt: O().nullable()
2831
- }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]).reactive(), ji = (e) => {
2832
- let t = e.makeId ?? Di, n = /* @__PURE__ */ new Map();
2844
+ errorMessage: E().nullable(),
2845
+ createdAt: D().default("now"),
2846
+ completedAt: D().nullable()
2847
+ }).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]).reactive(), Bi = (e) => {
2848
+ let t = e.makeId ?? Ii, n = /* @__PURE__ */ new Map();
2833
2849
  for (let t of e.triggers) {
2834
2850
  let e = n.get(t.event);
2835
2851
  e ? e.push(t) : n.set(t.event, [t]);
@@ -2870,7 +2886,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2870
2886
  });
2871
2887
  let p = o(n), m = [];
2872
2888
  for (let o of p) {
2873
- let s = Oi(o), l = o.workflow, d;
2889
+ let s = Li(o), l = o.workflow, d;
2874
2890
  try {
2875
2891
  let p = o.idempotencyKey?.(f) ?? `${c}:${s}`;
2876
2892
  if (o.filter && !await o.filter(f)) {
@@ -2973,11 +2989,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
2973
2989
  triggered: m
2974
2990
  };
2975
2991
  } };
2976
- }, Mi = M.effect(Ve.HttpClient, j.map(Ve.HttpClient, (e) => e.pipe(Ve.mapRequestEffect((e) => j.currentSpan.pipe(j.map((t) => e.headers.traceparent === void 0 ? He.setHeader(e, "traceparent", Mn({
2992
+ }, Vi = M.effect(Ke.HttpClient, j.map(Ke.HttpClient, (e) => e.pipe(Ke.mapRequestEffect((e) => j.currentSpan.pipe(j.map((t) => e.headers.traceparent === void 0 ? qe.setHeader(e, "traceparent", Rn({
2977
2993
  traceId: t.traceId,
2978
2994
  spanId: t.spanId,
2979
2995
  sampled: t.sampled
2980
- })) : e), j.catchAll(() => j.succeed(e))))))), Ni = "voltro/audit", Pi = "voltro/softDelete", Fi = "voltro/tenant", Ii = (e) => {
2996
+ })) : e), j.catchAll(() => j.succeed(e))))))), Hi = "voltro/audit", Ui = "voltro/softDelete", Wi = "voltro/tenant", Gi = (e) => {
2981
2997
  let t = /* @__PURE__ */ new Map();
2982
2998
  for (let n of e) {
2983
2999
  let e = /* @__PURE__ */ new Set();
@@ -3020,48 +3036,48 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3020
3036
  return !1;
3021
3037
  },
3022
3038
  idScheme: (e) => t.get(e)?.idScheme,
3023
- defaultFactories: (e) => t.get(e)?.defaultFactories ?? Li,
3024
- computedFields: (e) => t.get(e)?.computedFields ?? Ri,
3039
+ defaultFactories: (e) => t.get(e)?.defaultFactories ?? Ki,
3040
+ computedFields: (e) => t.get(e)?.computedFields ?? qi,
3025
3041
  insertSchema: (e) => t.get(e)?.insertSchema,
3026
3042
  validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
3027
3043
  };
3028
- }, Li = /* @__PURE__ */ new Map(), Ri = /* @__PURE__ */ new Map(), zi = Ii([]), Bi = class extends Error {
3044
+ }, Ki = /* @__PURE__ */ new Map(), qi = /* @__PURE__ */ new Map(), Ji = Gi([]), Yi = class extends Error {
3029
3045
  table;
3030
3046
  _tag = "NoRowFound";
3031
3047
  constructor(e) {
3032
3048
  super(`expected exactly one row in '${e}', found none`), this.table = e, this.name = "NoRowFound";
3033
3049
  }
3034
- }, Vi = class extends Error {
3050
+ }, Xi = class extends Error {
3035
3051
  table;
3036
3052
  expected;
3037
3053
  _tag = "OptimisticLockError";
3038
3054
  constructor(e, t) {
3039
3055
  super(`optimistic lock failed on '${e}': expected version ${t}`), this.table = e, this.expected = t, this.name = "OptimisticLockError";
3040
3056
  }
3041
- }, Hi = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), Ui = (e) => {
3042
- if (e.length === 1 && Hi(e[0])) return e[0];
3057
+ }, Zi = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), Qi = (e) => {
3058
+ if (e.length === 1 && Zi(e[0])) return e[0];
3043
3059
  let t = e[0];
3044
3060
  if (e.length === 2) return u(t, e[1]);
3045
3061
  let n = e[1], r = e[2];
3046
3062
  switch (n) {
3047
3063
  case "=": return u(t, r);
3048
3064
  case "!=":
3049
- case "<>": return te(t, r);
3065
+ case "<>": return w(t, r);
3050
3066
  case ">": return h(t, r);
3051
3067
  case ">=": return g(t, r);
3052
- case "<": return w(t, r);
3053
- case "<=": return ee(t, r);
3068
+ case "<": return te(t, r);
3069
+ case "<=": return ne(t, r);
3054
3070
  case "in": return y(t, r);
3055
3071
  case "like":
3056
3072
  case "contains":
3057
3073
  case "fts": return o(t, r);
3058
3074
  default: return u(t, r);
3059
3075
  }
3060
- }, Wi = (e) => {
3076
+ }, $i = (e) => {
3061
3077
  let t = m(e);
3062
3078
  if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
3063
- return ne(t);
3064
- }, Gi = class e {
3079
+ return ie(t);
3080
+ }, ea = class e {
3065
3081
  backend;
3066
3082
  scope;
3067
3083
  table;
@@ -3075,7 +3091,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3075
3091
  return new e(this.backend, this.scope, this.table, t, this.skipTenant, this.skipSoftDelete);
3076
3092
  }
3077
3093
  where(...e) {
3078
- return this.clone(this.query.where(Ui(e)));
3094
+ return this.clone(this.query.where(Qi(e)));
3079
3095
  }
3080
3096
  orderBy(e, t = "asc") {
3081
3097
  return this.clone(this.query.orderBy(e, t));
@@ -3109,7 +3125,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3109
3125
  }
3110
3126
  scopedQuery() {
3111
3127
  let e = this.query, { subject: t, schemaRegistry: n } = this.scope;
3112
- return !this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(u("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(x("deletedAt"))), e;
3128
+ return !this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(u("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(S("deletedAt"))), e;
3113
3129
  }
3114
3130
  async all() {
3115
3131
  return this.backend.query(this.scopedQuery().descriptor);
@@ -3122,7 +3138,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3122
3138
  }
3123
3139
  async one() {
3124
3140
  let e = await this.maybeOne();
3125
- if (e === null) throw new Bi(this.table);
3141
+ if (e === null) throw new Yi(this.table);
3126
3142
  return e;
3127
3143
  }
3128
3144
  async count() {
@@ -3135,7 +3151,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3135
3151
  get descriptor() {
3136
3152
  return this.scopedQuery().descriptor;
3137
3153
  }
3138
- }, Ki = class {
3154
+ }, ta = class {
3139
3155
  backend;
3140
3156
  scope;
3141
3157
  table;
@@ -3146,7 +3162,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3146
3162
  this.backend = e, this.scope = t, this.table = n;
3147
3163
  }
3148
3164
  where(...e) {
3149
- let n = Ui(e);
3165
+ let n = Qi(e);
3150
3166
  return this.predicate = this.predicate ? t(this.predicate, n) : n, this;
3151
3167
  }
3152
3168
  unscoped() {
@@ -3170,13 +3186,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3170
3186
  }
3171
3187
  async set(e) {
3172
3188
  let t = await this.backend.updateMany(this.table, e, { where: this.scopedWhere() });
3173
- if (this.expectedVersion !== void 0 && t === 0) throw new Vi(this.table, this.expectedVersion);
3189
+ if (this.expectedVersion !== void 0 && t === 0) throw new Xi(this.table, this.expectedVersion);
3174
3190
  return t;
3175
3191
  }
3176
3192
  async restore() {
3177
3193
  return this.backend.updateMany(this.table, { deletedAt: null }, { where: this.scopedWhere() });
3178
3194
  }
3179
- }, qi = class {
3195
+ }, na = class {
3180
3196
  backend;
3181
3197
  scope;
3182
3198
  table;
@@ -3186,7 +3202,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3186
3202
  this.backend = e, this.scope = t, this.table = n;
3187
3203
  }
3188
3204
  where(...e) {
3189
- let n = Ui(e);
3205
+ let n = Qi(e);
3190
3206
  return this.predicate = this.predicate ? t(this.predicate, n) : n, this;
3191
3207
  }
3192
3208
  unscoped() {
@@ -3207,42 +3223,46 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3207
3223
  async hard() {
3208
3224
  return this.backend.deleteMany(this.table, { where: this.scopedWhere() });
3209
3225
  }
3210
- }, Ji = (e, t) => ({
3211
- select: (n) => new Gi(e, t, n, Wi(n)),
3212
- updateWhere: (n) => new Ki(e, t, n),
3213
- deleteWhere: (n) => new qi(e, t, n)
3214
- }), Yi = class extends I.TaggedError()("TenantScopeViolation", {
3226
+ }, ra = (e, t) => ({
3227
+ select: (n) => new ea(e, t, n, $i(n)),
3228
+ updateWhere: (n) => new ta(e, t, n),
3229
+ deleteWhere: (n) => new na(e, t, n)
3230
+ }), ia = class extends I.TaggedError()("TenantScopeViolation", {
3215
3231
  table: I.String,
3216
3232
  reason: I.String
3217
- }) {}, Xi = class extends I.TaggedError()("StoreOperationFailed", {
3233
+ }) {}, aa = class extends I.TaggedError()("StoreOperationFailed", {
3218
3234
  operation: I.String,
3219
3235
  table: I.String,
3220
3236
  cause: I.String
3221
- }) {}, Zi = class extends I.TaggedError()("TableValidationFailed", {
3237
+ }) {}, oa = class extends I.TaggedError()("TableValidationFailed", {
3222
3238
  table: I.String,
3223
3239
  summary: I.String,
3224
3240
  issues: I.Array(I.Struct({
3225
3241
  path: I.String,
3226
3242
  message: I.String
3227
3243
  }))
3228
- }) {}, Qi = "id", $i = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", ea = (e) => {
3229
- throw new Yi({
3244
+ }) {}, sa = "id", ca = (e, t) => {
3245
+ let n = {};
3246
+ for (let r of t) e[r] !== void 0 && (n[r] = e[r]);
3247
+ return n;
3248
+ }, la = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", ua = (e) => {
3249
+ throw new ia({
3230
3250
  table: e,
3231
- reason: $i
3251
+ reason: la
3232
3252
  });
3233
- }, ta = (e, n) => {
3253
+ }, da = (e, n) => {
3234
3254
  let r = n.subject.id, i = n.subject.tenantId, a = (e, t) => {
3235
3255
  let a = { ...t }, o = n.schemaRegistry, s = o.idScheme(e);
3236
- if (s !== void 0 && a[Qi] == null) if (s.kind === "numeric") delete a[Qi];
3256
+ if (s !== void 0 && a[sa] == null) if (s.kind === "numeric") delete a[sa];
3237
3257
  else {
3238
3258
  let t = f(s, e);
3239
- t !== null && (a[Qi] = t);
3259
+ t !== null && (a[sa] = t);
3240
3260
  }
3241
3261
  if (o.hasAudit(e)) {
3242
3262
  let e = /* @__PURE__ */ new Date();
3243
3263
  "createdAt" in a || (a.createdAt = e), "updatedAt" in a || (a.updatedAt = e), r !== null && ("createdBy" in a || (a.createdBy = r), "updatedBy" in a || (a.updatedBy = r));
3244
3264
  }
3245
- o.hasTenant(e) && ("tenantId" in a || (i === null && ea(e), a.tenantId = i));
3265
+ o.hasTenant(e) && ("tenantId" in a || (i === null && ua(e), a.tenantId = i));
3246
3266
  let c = o.defaultFactories(e);
3247
3267
  if (c.size > 0) for (let [e, t] of c) (!(e in a) || a[e] === void 0) && (a[e] = t());
3248
3268
  let l = o.computedFields(e);
@@ -3257,10 +3277,10 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3257
3277
  try {
3258
3278
  return await r();
3259
3279
  } catch (n) {
3260
- let r = Mt(n);
3261
- if (Nt(r)) {
3280
+ let r = zt(n);
3281
+ if (Bt(r)) {
3262
3282
  let n = t.tenantId, i = `${r.dbConstraint ?? ""} ${r.dbColumn ?? ""} ${r.dbMessage ?? ""} ${r.dbCauseChain ?? ""}`.toLowerCase();
3263
- if (i.includes("tenantid") || /\btenants\b/.test(i) || n != null && i.includes(String(n).toLowerCase())) throw new Yi({
3283
+ if (i.includes("tenantid") || /\btenants\b/.test(i) || n != null && i.includes(String(n).toLowerCase())) throw new ia({
3264
3284
  table: e,
3265
3285
  reason: n == null ? "write references a tenant that does not exist" : `tenant '${String(n)}' does not exist — seed the row in \`tenants\`, or fix how the request resolved this tenant (subject.tenantId / the x-tenant header / the dev TENANT fallback)`
3266
3286
  });
@@ -3281,11 +3301,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3281
3301
  if (r === void 0) return t;
3282
3302
  let i = I.decodeUnknownEither(r)(t);
3283
3303
  if (i._tag === "Right") return t;
3284
- let a = lt.formatErrorSync(i.left).map((e) => ({
3304
+ let a = gt.formatErrorSync(i.left).map((e) => ({
3285
3305
  path: e.path.length === 0 ? "<root>" : e.path.join("."),
3286
3306
  message: e.message
3287
3307
  })), o = a[0];
3288
- throw new Zi({
3308
+ throw new oa({
3289
3309
  table: e,
3290
3310
  summary: o === void 0 ? "patch validation failed" : `${o.path}: ${o.message}`,
3291
3311
  issues: a
@@ -3298,29 +3318,29 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3298
3318
  if (r === void 0) return t;
3299
3319
  let i = I.decodeUnknownEither(r)(t);
3300
3320
  if (i._tag === "Right") return t;
3301
- let a = lt.formatErrorSync(i.left).map((e) => ({
3321
+ let a = gt.formatErrorSync(i.left).map((e) => ({
3302
3322
  path: e.path.length === 0 ? "<root>" : e.path.join("."),
3303
3323
  message: e.message
3304
3324
  })), o = a[0];
3305
- throw new Zi({
3325
+ throw new oa({
3306
3326
  table: e,
3307
3327
  summary: o === void 0 ? "row validation failed" : `${o.path}: ${o.message}`,
3308
3328
  issues: a
3309
3329
  });
3310
3330
  }, v = n.dialect, y = (e, t) => {
3311
3331
  let n = m(e);
3312
- return l(v ? oe(t, n, v) : t, n, Vr());
3332
+ return l(v ? ce(t, n, v) : t, n, qr());
3313
3333
  }, b = (e, t) => {
3314
- let n = m(e), r = s(t, n, Vr());
3334
+ let n = m(e), r = s(t, n, qr());
3315
3335
  return v ? c(r, n, v) : r;
3316
- }, S = (e) => {
3336
+ }, x = (e) => {
3317
3337
  let r = e.table, a = e.predicate;
3318
3338
  if (!e.crossTenant && i != null && n.schemaRegistry.hasTenant(r)) {
3319
3339
  let e = u("tenantId", i);
3320
3340
  a = a ? t(a, e) : e;
3321
3341
  }
3322
3342
  if (!e.includeDeleted && n.schemaRegistry.hasSoftDelete(r)) {
3323
- let e = x("deletedAt");
3343
+ let e = S("deletedAt");
3324
3344
  a = a ? t(a, e) : e;
3325
3345
  }
3326
3346
  return a === e.predicate ? e : {
@@ -3330,13 +3350,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3330
3350
  }, C = async (t) => {
3331
3351
  let n = await e.query(t);
3332
3352
  return b(t.table, n);
3333
- }, w = async (e) => C(S(e)), ee = async (t, r, i) => {
3353
+ }, ee = async (e) => C(x(e)), te = async (t, r, i) => {
3334
3354
  let a = o(t, i);
3335
3355
  if (n.schemaRegistry.computedFields(t).size > 0) {
3336
3356
  let n = (await e.query({
3337
3357
  table: t,
3338
3358
  predicate: {
3339
- column: Qi,
3359
+ column: sa,
3340
3360
  op: "eq",
3341
3361
  value: r
3342
3362
  },
@@ -3351,23 +3371,23 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3351
3371
  a = h(t, a);
3352
3372
  let s = await e.update(t, r, y(t, a));
3353
3373
  return s === null ? null : b(t, [s])[0];
3354
- }, te = async (t, r) => n.schemaRegistry.hasSoftDelete(t) ? await e.update(t, r, g()) !== null : e.delete(t, r), T = async (t, n, r) => e.updateMany(t, y(t, o(t, n)), r), ne = async (t, n) => e.deleteMany(t, n), re = (e, r) => i != null && n.schemaRegistry.hasTenant(e) ? t(r, u("tenantId", i)) : r, ie = async (e, t, n) => T(e, t, {
3374
+ }, ne = async (t, r) => n.schemaRegistry.hasSoftDelete(t) ? await e.update(t, r, g()) !== null : e.delete(t, r), w = async (t, n, r) => e.updateMany(t, y(t, o(t, n)), r), re = async (t, n) => e.deleteMany(t, n), ie = (e, r) => i != null && n.schemaRegistry.hasTenant(e) ? t(r, u("tenantId", i)) : r, ae = async (e, t, n) => w(e, t, {
3355
3375
  ...n,
3356
- where: re(e, n.where)
3357
- }), ae = async (e, t) => ne(e, {
3376
+ where: ie(e, n.where)
3377
+ }), oe = async (e, t) => re(e, {
3358
3378
  ...t,
3359
- where: re(e, t.where)
3360
- }), se = Ji({
3379
+ where: ie(e, t.where)
3380
+ }), se = ra({
3361
3381
  query: C,
3362
- updateMany: T,
3363
- deleteMany: ne,
3382
+ updateMany: w,
3383
+ deleteMany: re,
3364
3384
  delete: (t, n) => e.delete(t, n)
3365
3385
  }, {
3366
3386
  subject: n.subject,
3367
3387
  schemaRegistry: n.schemaRegistry
3368
3388
  });
3369
3389
  return {
3370
- query: w,
3390
+ query: ee,
3371
3391
  insert: async (t, n) => {
3372
3392
  let r = a(t, n), i = await d(t, r, () => e.insert(t, y(t, _(t, r))));
3373
3393
  return b(t, [i])[0];
@@ -3381,11 +3401,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3381
3401
  return a === null ? null : b(t, [a])[0];
3382
3402
  },
3383
3403
  select: se.select,
3384
- update: ((e, t, n) => t === void 0 ? se.updateWhere(e) : ee(e, t, n)),
3385
- delete: ((e, t) => t === void 0 ? se.deleteWhere(e) : te(e, t)),
3404
+ update: ((e, t, n) => t === void 0 ? se.updateWhere(e) : te(e, t, n)),
3405
+ delete: ((e, t) => t === void 0 ? se.deleteWhere(e) : ne(e, t)),
3406
+ applyDefined: ca,
3386
3407
  hardDelete: async (t, n) => e.delete(t, n),
3387
- updateMany: ie,
3388
- deleteMany: ae,
3408
+ updateMany: ae,
3409
+ deleteMany: oe,
3389
3410
  upsert: async (t, n, r) => {
3390
3411
  let i = a(t, n), o = await d(t, i, () => e.upsert(t, y(t, _(t, i)), r));
3391
3412
  return b(t, [o])[0];
@@ -3394,34 +3415,34 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3394
3415
  let i = a(t, n), o = await d(t, i, () => e.insertIgnore(t, y(t, _(t, i)), r));
3395
3416
  return b(t, [o])[0];
3396
3417
  },
3397
- transactional: (t) => e.transactional(async (e) => t(ta(e, n))),
3418
+ transactional: (t) => e.transactional(async (e) => t(da(e, n))),
3398
3419
  ...e.raw ? { raw: e.raw.bind(e) } : {},
3399
3420
  onChange: (t) => e.onChange(t),
3400
3421
  injectExternalChange: (t) => e.injectExternalChange(t),
3401
3422
  ...e.changeScope === void 0 ? {} : { changeScope: e.changeScope }
3402
3423
  };
3403
- }, na = class extends I.TaggedError()("CircuitOpen", {
3424
+ }, fa = class extends I.TaggedError()("CircuitOpen", {
3404
3425
  name: I.String,
3405
3426
  retryAfterMs: I.Number
3406
- }) {}, ra = {
3427
+ }) {}, pa = {
3407
3428
  tag: "closed",
3408
3429
  failureCount: 0,
3409
3430
  halfOpenSuccesses: 0,
3410
3431
  openedAt: 0
3411
- }, ia = { make: (e) => j.gen(function* () {
3412
- let t = e.name ?? "circuit", n = Me.toMillis(Me.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* F.make(ra), o = j.gen(function* () {
3432
+ }, ma = { make: (e) => j.gen(function* () {
3433
+ let t = e.name ?? "circuit", n = Le.toMillis(Le.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* F.make(pa), o = j.gen(function* () {
3413
3434
  let e = yield* F.get(a);
3414
3435
  if (e.tag === "half-open") {
3415
3436
  let t = e.halfOpenSuccesses + 1;
3416
- yield* F.set(a, t >= r ? ra : {
3437
+ yield* F.set(a, t >= r ? pa : {
3417
3438
  ...e,
3418
3439
  halfOpenSuccesses: t
3419
3440
  });
3420
3441
  return;
3421
3442
  }
3422
- e.failureCount !== 0 && (yield* F.set(a, ra));
3443
+ e.failureCount !== 0 && (yield* F.set(a, pa));
3423
3444
  }), s = j.gen(function* () {
3424
- let t = yield* ke.currentTimeMillis, n = yield* F.get(a);
3445
+ let t = yield* Pe.currentTimeMillis, n = yield* F.get(a);
3425
3446
  if (n.tag === "half-open" || n.tag === "open") {
3426
3447
  yield* F.set(a, {
3427
3448
  tag: "open",
@@ -3444,7 +3465,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3444
3465
  }), c = j.gen(function* () {
3445
3466
  let e = yield* F.get(a);
3446
3467
  if (e.tag !== "open") return null;
3447
- let t = (yield* ke.currentTimeMillis) - e.openedAt;
3468
+ let t = (yield* Pe.currentTimeMillis) - e.openedAt;
3448
3469
  return t >= n ? (yield* F.set(a, {
3449
3470
  tag: "half-open",
3450
3471
  failureCount: 0,
@@ -3457,7 +3478,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3457
3478
  if (k.isInterruptedOnly(e)) return j.void;
3458
3479
  let t = k.failureOption(e), n = t._tag === "Some" ? t.value : void 0;
3459
3480
  return i(n) ? s : j.void;
3460
- })) : yield* j.fail(new na({
3481
+ })) : yield* j.fail(new fa({
3461
3482
  name: t,
3462
3483
  retryAfterMs: n
3463
3484
  }));
@@ -3466,38 +3487,38 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3466
3487
  value: F.get(a).pipe(j.map((e) => e.tag)),
3467
3488
  enumerable: !0
3468
3489
  }), Object.defineProperty(u, "reset", {
3469
- value: F.set(a, ra),
3490
+ value: F.set(a, pa),
3470
3491
  enumerable: !0
3471
3492
  }), u;
3472
- }) }, aa, oa = (e) => {
3473
- aa = e;
3474
- }, sa = () => {
3475
- aa = void 0;
3476
- }, ca = async (e, t = {}) => {
3477
- let n = t.scopes === void 0 ? De(t.id ?? "system") : De(t.id ?? "system", t.scopes), r = t.store ?? aa?.dataStore, i = t.schemaRegistry ?? aa?.schemaRegistry, a = t.dialect ?? aa?.dialect;
3493
+ }) }, ha, ga = (e) => {
3494
+ ha = e;
3495
+ }, _a = () => {
3496
+ ha = void 0;
3497
+ }, va = async (e, t = {}) => {
3498
+ let n = t.scopes === void 0 ? je(t.id ?? "system") : je(t.id ?? "system", t.scopes), r = t.store ?? ha?.dataStore, i = t.schemaRegistry ?? ha?.schemaRegistry, a = t.dialect ?? ha?.dialect;
3478
3499
  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.");
3479
3500
  return e({
3480
3501
  subject: n,
3481
- store: ta(r, {
3502
+ store: da(r, {
3482
3503
  subject: n,
3483
3504
  schemaRegistry: i,
3484
3505
  ...a === void 0 ? {} : { dialect: a }
3485
3506
  })
3486
3507
  });
3487
- }, la = class extends Ae.Tag("@voltro/EffectStore")() {}, ua = (e, t) => (n) => n instanceof Yi ? n : new Xi({
3508
+ }, ya = class extends Fe.Tag("@voltro/EffectStore")() {}, ba = (e, t) => (n) => n instanceof ia ? n : new aa({
3488
3509
  operation: e,
3489
3510
  table: t,
3490
3511
  cause: String(n)
3491
- }), da = (e, t, n) => j.tryPromise({
3512
+ }), xa = (e, t, n) => j.tryPromise({
3492
3513
  try: n,
3493
- catch: ua(e, t)
3494
- }), fa = (e) => M.succeed(la, {
3495
- query: (t) => da("query", t.table, () => e.query(t)),
3496
- insert: (t, n) => da("insert", t, () => e.insert(t, n)),
3497
- update: (t, n, r) => da("update", t, () => e.update(t, n, r)),
3498
- delete: (t, n) => da("delete", t, () => e.delete(t, n)),
3499
- hardDelete: (t, n) => da("hardDelete", t, () => e.hardDelete(t, n))
3500
- }), pa = (e) => {
3514
+ catch: ba(e, t)
3515
+ }), Sa = (e) => M.succeed(ya, {
3516
+ query: (t) => xa("query", t.table, () => e.query(t)),
3517
+ insert: (t, n) => xa("insert", t, () => e.insert(t, n)),
3518
+ update: (t, n, r) => xa("update", t, () => e.update(t, n, r)),
3519
+ delete: (t, n) => xa("delete", t, () => e.delete(t, n)),
3520
+ hardDelete: (t, n) => xa("hardDelete", t, () => e.hardDelete(t, n))
3521
+ }), Ca = (e) => {
3501
3522
  let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
3502
3523
  if (t === void 0) return {
3503
3524
  sameRegion: [],
@@ -3525,7 +3546,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3525
3546
  return r.loadSnapshot();
3526
3547
  }
3527
3548
  };
3528
- }, ma = (e = process.env) => {
3549
+ }, wa = (e = process.env) => {
3529
3550
  for (let t of [
3530
3551
  "VOLTRO_REGION",
3531
3552
  "AWS_REGION",
@@ -3537,7 +3558,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3537
3558
  let n = e[t];
3538
3559
  if (typeof n == "string" && n.length > 0) return n;
3539
3560
  }
3540
- }, ha = () => {
3561
+ }, Ta = () => {
3541
3562
  let e = {
3542
3563
  primary: 0,
3543
3564
  lagByReplica: /* @__PURE__ */ new Map()
@@ -3562,27 +3583,27 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3562
3583
  e.lagByReplica.set(t, n);
3563
3584
  }
3564
3585
  };
3565
- }, ga = Symbol.for("@voltro/ScheduleDefinition"), _a = (e) => typeof e == "object" && !!e && ga in e, va = 30 * 6e4, ya = (e) => {
3586
+ }, Ea = Symbol.for("@voltro/ScheduleDefinition"), Da = (e) => typeof e == "object" && !!e && Ea in e, Oa = 30 * 6e4, ka = (e) => {
3566
3587
  let t = A.parse(e.cron, e.timezone);
3567
- if (Ne.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
3588
+ if (Re.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
3568
3589
  if (!e.timezone || e.timezone.trim() === "") throw Error(`defineSchedule("${e.name}"): timezone is required (e.g. "UTC", "Europe/Berlin")`);
3569
3590
  if (e.handler === void 0 && e.workflow === void 0) throw Error(`defineSchedule("${e.name}"): define either handler or workflow`);
3570
3591
  return {
3571
3592
  ...e,
3572
3593
  onOverlap: e.onOverlap ?? "skip",
3573
3594
  backfill: e.backfill ?? "skip",
3574
- maxRuntimeMs: e.maxRuntimeMs ?? va,
3575
- [ga]: !0
3595
+ maxRuntimeMs: e.maxRuntimeMs ?? Oa,
3596
+ [Ea]: !0
3576
3597
  };
3577
- }, ba = (e) => A.unsafeParse(e.cron, e.timezone), xa = (e, t = /* @__PURE__ */ new Date()) => A.next(ba(e), t), Z = "_voltro_wakeups", Sa = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Ca = (e) => ({
3598
+ }, Aa = (e) => A.unsafeParse(e.cron, e.timezone), ja = (e, t = /* @__PURE__ */ new Date()) => A.next(Aa(e), t), Z = "_voltro_wakeups", Ma = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Na = (e) => ({
3578
3599
  tenantId: String(e.tenantId),
3579
3600
  kind: String(e.kind),
3580
3601
  refId: String(e.refId),
3581
3602
  wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
3582
3603
  status: e.status === "fired" ? "fired" : "pending"
3583
- }), wa = async (e, t) => {
3604
+ }), Pa = async (e, t) => {
3584
3605
  await e.upsert(Z, {
3585
- id: Sa(t),
3606
+ id: Ma(t),
3586
3607
  tenantId: t.tenantId,
3587
3608
  kind: t.kind,
3588
3609
  refId: t.refId,
@@ -3592,7 +3613,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3592
3613
  conflictColumns: ["id"],
3593
3614
  update: ["wakeAt", "status"]
3594
3615
  });
3595
- }, Ta = async (e, t) => e.delete(Z, Sa(t)), Ea = async (e, t) => await e.update(Z, Sa(t), { status: "fired" }) !== null, Da = (e, t) => ({ and: [{
3616
+ }, Fa = async (e, t) => e.delete(Z, Ma(t)), Ia = async (e, t) => await e.update(Z, Ma(t), { status: "fired" }) !== null, La = (e, t) => ({ and: [{
3596
3617
  column: "id",
3597
3618
  op: "eq",
3598
3619
  value: e
@@ -3600,16 +3621,16 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3600
3621
  column: "status",
3601
3622
  op: "eq",
3602
3623
  value: t
3603
- }] }), Oa = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: Da(Sa(t), "pending") }) > 0, ka = async (e, t) => {
3604
- await e.updateMany(Z, { status: "pending" }, { where: Da(Sa(t), "fired") });
3605
- }, Aa = {
3624
+ }] }), Ra = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: La(Ma(t), "pending") }) > 0, za = async (e, t) => {
3625
+ await e.updateMany(Z, { status: "pending" }, { where: La(Ma(t), "fired") });
3626
+ }, Ba = {
3606
3627
  column: "status",
3607
3628
  op: "eq",
3608
3629
  value: "pending"
3609
- }, ja = async (e, t) => {
3630
+ }, Va = async (e, t) => {
3610
3631
  let n = {
3611
3632
  table: Z,
3612
- predicate: Aa,
3633
+ predicate: Ba,
3613
3634
  order: [{
3614
3635
  column: "wakeAt",
3615
3636
  direction: "asc"
@@ -3618,18 +3639,18 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3618
3639
  skip: void 0,
3619
3640
  projection: void 0
3620
3641
  };
3621
- return (await e.query(n)).map(Ca);
3622
- }, Ma = async (e, t, n = 500) => {
3623
- let r = await ja(e, n), i = t.getTime();
3642
+ return (await e.query(n)).map(Na);
3643
+ }, Ha = async (e, t, n = 500) => {
3644
+ let r = await Va(e, n), i = t.getTime();
3624
3645
  return r.filter((e) => e.wakeAt.getTime() <= i);
3625
- }, Na = async (e) => (await ja(e, 1))[0] ?? null, Pa = {
3646
+ }, Ua = async (e) => (await Va(e, 1))[0] ?? null, Wa = {
3626
3647
  column: "status",
3627
3648
  op: "eq",
3628
3649
  value: "fired"
3629
- }, Fa = async (e, t = {}) => {
3650
+ }, Ga = async (e, t = {}) => {
3630
3651
  let n = {
3631
3652
  table: Z,
3632
- predicate: Pa,
3653
+ predicate: Wa,
3633
3654
  order: [{
3634
3655
  column: "wakeAt",
3635
3656
  direction: "asc"
@@ -3640,12 +3661,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3640
3661
  }, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
3641
3662
  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++;
3642
3663
  return a;
3643
- }, Ia = {
3664
+ }, Ka = {
3644
3665
  kind: "single",
3645
3666
  tryClaim: async () => !0
3646
- }, La = "_voltro_schedule_claims", Ra = (e, t, n) => {
3667
+ }, qa = "_voltro_schedule_claims", Ja = (e, t, n) => {
3647
3668
  let r = async (t) => (await e.query({
3648
- table: La,
3669
+ table: qa,
3649
3670
  order: [],
3650
3671
  predicate: void 0,
3651
3672
  projection: ["id"],
@@ -3660,7 +3681,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3660
3681
  if (await r(s)) return !1;
3661
3682
  } catch {}
3662
3683
  try {
3663
- return await e.insert(La, {
3684
+ return await e.insert(qa, {
3664
3685
  id: s,
3665
3686
  scheduleName: i,
3666
3687
  bucket: o,
@@ -3678,12 +3699,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3678
3699
  }
3679
3700
  }
3680
3701
  };
3681
- }, za = "_voltro_schedule_runs", Ba = async (e, t) => {
3702
+ }, Ya = "_voltro_schedule_runs", Xa = async (e, t) => {
3682
3703
  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) => {
3683
- s?.(e, Ha(t));
3704
+ s?.(e, Qa(t));
3684
3705
  }, _ = async (e, t, r, i, s, c) => {
3685
3706
  try {
3686
- let o = `sr_${pe()}`, l = await n.insert(za, {
3707
+ let o = `sr_${he()}`, l = await n.insert(Ya, {
3687
3708
  id: o,
3688
3709
  name: e.name,
3689
3710
  status: i,
@@ -3708,7 +3729,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3708
3729
  }
3709
3730
  }, v = async (e, t) => {
3710
3731
  try {
3711
- let r = await n.update(za, e, t);
3732
+ let r = await n.update(Ya, e, t);
3712
3733
  r && g("update", r);
3713
3734
  } catch (t) {
3714
3735
  o.warn("schedule: failed to record run finish", {
@@ -3719,7 +3740,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3719
3740
  }, y = async (e) => {
3720
3741
  try {
3721
3742
  let t = await n.query({
3722
- table: za,
3743
+ table: Ya,
3723
3744
  predicate: {
3724
3745
  _tag: "leaf",
3725
3746
  column: "status",
@@ -3784,7 +3805,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3784
3805
  let n = Q(t).includes("exceeded maxRuntimeMs");
3785
3806
  s && await v(s, {
3786
3807
  status: "failed",
3787
- errorTag: n ? "timeout" : Va(t),
3808
+ errorTag: n ? "timeout" : Za(t),
3788
3809
  errorMessage: Q(t),
3789
3810
  completedAt: /* @__PURE__ */ new Date(),
3790
3811
  durationMs: Date.now() - l
@@ -3792,7 +3813,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3792
3813
  name: e.name,
3793
3814
  reason: Q(t),
3794
3815
  timeout: n
3795
- }), Ee({
3816
+ }), ke({
3796
3817
  error: t,
3797
3818
  source: "schedule",
3798
3819
  name: e.name,
@@ -3841,8 +3862,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3841
3862
  }
3842
3863
  }, C = async (e) => {
3843
3864
  try {
3844
- let t = A.next(ba(e), /* @__PURE__ */ new Date());
3845
- await wa(n, {
3865
+ let t = A.next(Aa(e), /* @__PURE__ */ new Date());
3866
+ await Pa(n, {
3846
3867
  tenantId: u,
3847
3868
  kind: "schedule",
3848
3869
  refId: e.name,
@@ -3854,13 +3875,13 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3854
3875
  reason: Q(t)
3855
3876
  });
3856
3877
  }
3857
- }, w = 2147483647, ee = (e) => {
3878
+ }, ee = 2147483647, te = (e) => {
3858
3879
  if (m) return;
3859
- let n = ba(e), r = A.next(n, /* @__PURE__ */ new Date()), i = () => {
3880
+ let n = Aa(e), r = A.next(n, /* @__PURE__ */ new Date()), i = () => {
3860
3881
  if (m) return;
3861
3882
  let n = r.getTime() - Date.now();
3862
- if (n > w) {
3863
- let t = setTimeout(i, w);
3883
+ if (n > ee) {
3884
+ let t = setTimeout(i, ee);
3864
3885
  d.set(e.name, t);
3865
3886
  return;
3866
3887
  }
@@ -3868,17 +3889,17 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3868
3889
  x(e, r, e.trigger ?? t.defaultTrigger).catch((t) => o.warn("schedule: fire rejected", {
3869
3890
  name: e.name,
3870
3891
  reason: Q(t)
3871
- })).finally(() => ee(e));
3892
+ })).finally(() => te(e));
3872
3893
  }, Math.max(0, n));
3873
3894
  d.set(e.name, a);
3874
3895
  };
3875
3896
  i();
3876
- }, te = async (e) => {
3897
+ }, ne = async (e) => {
3877
3898
  if (e.backfill === "skip") return;
3878
3899
  let r;
3879
3900
  try {
3880
3901
  let t = (await n.query({
3881
- table: za,
3902
+ table: Ya,
3882
3903
  order: [{
3883
3904
  column: "scheduledAt",
3884
3905
  direction: "desc"
@@ -3897,7 +3918,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3897
3918
  return;
3898
3919
  }
3899
3920
  if (!r) return;
3900
- let i = ba(e), a = [], s = A.next(i, r), c = Date.now();
3921
+ let i = Aa(e), a = [], s = A.next(i, r), c = Date.now();
3901
3922
  for (; s.getTime() < c && a.length < 1e3;) a.push(s), s = A.next(i, s);
3902
3923
  if (a.length !== 0) if (o.info("schedule: backfill", {
3903
3924
  name: e.name,
@@ -3908,20 +3929,20 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3908
3929
  let n = a[a.length - 1];
3909
3930
  await x(e, n, e.trigger ?? t.defaultTrigger);
3910
3931
  } else for (let n of a) await x(e, n, e.trigger ?? t.defaultTrigger);
3911
- }, T = e.filter((e) => (e.trigger ?? t.defaultTrigger) === "self");
3932
+ }, w = e.filter((e) => (e.trigger ?? t.defaultTrigger) === "self");
3912
3933
  o.info("scheduler: starting", {
3913
3934
  total: e.length,
3914
- self: T.length,
3915
- external: e.length - T.length,
3935
+ self: w.length,
3936
+ external: e.length - w.length,
3916
3937
  coordinator: r.kind
3917
3938
  });
3918
- let ne = (t.armSelf ?? !0) && !l;
3939
+ let re = (t.armSelf ?? !0) && !l;
3919
3940
  if (l) {
3920
- o.info("scheduler: sleep mode — registering wakeups, not arming timers", { count: T.length });
3921
- for (let e of T) await C(e);
3922
- } else if (ne) {
3923
- for (let e of T) await te(e);
3924
- for (let e of T) ee(e);
3941
+ o.info("scheduler: sleep mode — registering wakeups, not arming timers", { count: w.length });
3942
+ for (let e of w) await C(e);
3943
+ } else if (re) {
3944
+ for (let e of w) await ne(e);
3945
+ for (let e of w) te(e);
3925
3946
  }
3926
3947
  return {
3927
3948
  fireNow: async (e, t) => {
@@ -3942,11 +3963,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3942
3963
  d.clear(), o.info("scheduler: stopped");
3943
3964
  }
3944
3965
  };
3945
- }, Q = (e) => e?.message ?? String(e), Va = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Ha = (e) => {
3966
+ }, Q = (e) => e?.message ?? String(e), Za = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Qa = (e) => {
3946
3967
  let t = {};
3947
3968
  for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
3948
3969
  return t;
3949
- }, Ua = (e, t, n, r) => {
3970
+ }, $a = (e, t, n, r) => {
3950
3971
  let i = !1, a, o = async () => {
3951
3972
  if (i) return;
3952
3973
  let a = new Date(Math.floor(Date.now() / t) * t), o = !1;
@@ -3976,96 +3997,96 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
3976
3997
  i || (i = !0, a && clearInterval(a), a = void 0);
3977
3998
  }
3978
3999
  };
3979
- }, Wa = (e) => (t, n, r) => Ua(t, n, r, e), Ga = E("_voltro_schedule_runs", {
4000
+ }, eo = (e) => (t, n, r) => $a(t, n, r, e), to = T("_voltro_schedule_runs", {
3980
4001
  id: v({ prefix: "schrun" }),
3981
- name: D(),
3982
- status: D().oneOf([
4002
+ name: E(),
4003
+ status: E().oneOf([
3983
4004
  "running",
3984
4005
  "succeeded",
3985
4006
  "failed",
3986
4007
  "skipped",
3987
4008
  "missed"
3988
4009
  ]).default("running"),
3989
- trigger: D().oneOf([
4010
+ trigger: E().oneOf([
3990
4011
  "self",
3991
4012
  "external",
3992
4013
  "manual"
3993
4014
  ]).default("self"),
3994
- scheduledAt: O(),
3995
- firedAt: O().nullable(),
3996
- completedAt: O().nullable(),
4015
+ scheduledAt: D(),
4016
+ firedAt: D().nullable(),
4017
+ completedAt: D().nullable(),
3997
4018
  durationMs: b().nullable(),
3998
- errorTag: D().nullable(),
3999
- errorMessage: D().nullable(),
4000
- coordinationOutcome: D().oneOf([
4019
+ errorTag: E().nullable(),
4020
+ errorMessage: E().nullable(),
4021
+ coordinationOutcome: E().oneOf([
4001
4022
  "single",
4002
4023
  "wonLock",
4003
4024
  "lostLock",
4004
4025
  "external",
4005
4026
  "cluster"
4006
4027
  ]).nullable(),
4007
- replicaId: D().nullable(),
4008
- result: S().nullable()
4009
- }).index(["name", "scheduledAt"]).index(["status"]), Ka = E("_voltro_schedule_claims", {
4028
+ replicaId: E().nullable(),
4029
+ result: C().nullable()
4030
+ }).index(["name", "scheduledAt"]).index(["status"]), no = T("_voltro_schedule_claims", {
4010
4031
  id: v({ prefix: "schclaim" }),
4011
- scheduleName: D(),
4012
- bucket: D(),
4013
- claimedBy: D(),
4014
- claimedAt: O()
4015
- }).index(["scheduleName", "bucket"]).index(["claimedAt"]), qa = E("_voltro_traces", {
4032
+ scheduleName: E(),
4033
+ bucket: E(),
4034
+ claimedBy: E(),
4035
+ claimedAt: D()
4036
+ }).index(["scheduleName", "bucket"]).index(["claimedAt"]), ro = T("_voltro_traces", {
4016
4037
  id: v({ prefix: "span" }),
4017
- traceId: D(),
4018
- spanId: D(),
4019
- parentSpanId: D().nullable(),
4020
- name: D(),
4021
- kind: D().oneOf([
4038
+ traceId: E(),
4039
+ spanId: E(),
4040
+ parentSpanId: E().nullable(),
4041
+ name: E(),
4042
+ kind: E().oneOf([
4022
4043
  "internal",
4023
4044
  "server",
4024
4045
  "client",
4025
4046
  "producer",
4026
4047
  "consumer"
4027
4048
  ]).default("internal"),
4028
- status: D().oneOf([
4049
+ status: E().oneOf([
4029
4050
  "ok",
4030
4051
  "error",
4031
4052
  "unset"
4032
4053
  ]).default("unset"),
4033
- statusMessage: D().nullable(),
4034
- startedAt: O(),
4035
- endedAt: O(),
4054
+ statusMessage: E().nullable(),
4055
+ startedAt: D(),
4056
+ endedAt: D(),
4036
4057
  durationMs: b(),
4037
- attributes: S().nullable(),
4038
- events: S().nullable()
4039
- }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Ja = E("_voltro_undo_log", {
4058
+ attributes: C().nullable(),
4059
+ events: C().nullable()
4060
+ }).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), io = T("_voltro_undo_log", {
4040
4061
  id: v({ prefix: "undo" }),
4041
- tag: D(),
4042
- label: D().nullable(),
4043
- subjectId: D().nullable(),
4044
- tenantId: D().nullable(),
4045
- traceId: D().nullable(),
4046
- changes: D(),
4062
+ tag: E(),
4063
+ label: E().nullable(),
4064
+ subjectId: E().nullable(),
4065
+ tenantId: E().nullable(),
4066
+ traceId: E().nullable(),
4067
+ changes: E(),
4047
4068
  crossesAction: r().default(!1),
4048
4069
  undone: r().default(!1),
4049
- createdAt: O().default("now")
4050
- }).index(["subjectId", "createdAt"]).reactive(), Ya = (e = process.env) => {
4070
+ createdAt: D().default("now")
4071
+ }).index(["subjectId", "createdAt"]).reactive(), ao = (e = process.env) => {
4051
4072
  let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
4052
4073
  return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
4053
- }, Xa = (e) => e.startsWith("_voltro"), Za = async (e, t, n) => (await e.query({
4074
+ }, oo = (e) => e.startsWith("_voltro"), so = async (e, t, n) => (await e.query({
4054
4075
  table: t,
4055
4076
  predicate: u("id", n),
4056
4077
  order: []
4057
- }))[0] ?? null, Qa = (e, t) => new Proxy(e, { get(e, n, r) {
4078
+ }))[0] ?? null, co = (e, t) => new Proxy(e, { get(e, n, r) {
4058
4079
  if (n === "insert") return async (n, r) => {
4059
4080
  let i = await e.insert(n, r);
4060
- return Xa(n) || t({
4081
+ return oo(n) || t({
4061
4082
  table: n,
4062
4083
  op: "insert",
4063
4084
  next: i
4064
4085
  }), i;
4065
4086
  };
4066
4087
  if (n === "update") return async (n, r, i) => {
4067
- let a = Xa(n) ? null : await Za(e, n, r), o = await e.update(n, r, i);
4068
- return Xa(n) || t({
4088
+ let a = oo(n) ? null : await so(e, n, r), o = await e.update(n, r, i);
4089
+ return oo(n) || t({
4069
4090
  table: n,
4070
4091
  op: "update",
4071
4092
  id: r,
@@ -4074,8 +4095,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4074
4095
  }), o;
4075
4096
  };
4076
4097
  if (n === "delete") return async (n, r) => {
4077
- let i = Xa(n) ? null : await Za(e, n, r), a = await e.delete(n, r);
4078
- return !Xa(n) && a && t({
4098
+ let i = oo(n) ? null : await so(e, n, r), a = await e.delete(n, r);
4099
+ return !oo(n) && a && t({
4079
4100
  table: n,
4080
4101
  op: "delete",
4081
4102
  id: r,
@@ -4084,10 +4105,10 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4084
4105
  };
4085
4106
  let i = Reflect.get(e, n, r);
4086
4107
  return typeof i == "function" ? i.bind(e) : i;
4087
- } }), $a = (e) => {
4108
+ } }), lo = (e) => {
4088
4109
  let t = [];
4089
4110
  return {
4090
- tx: Qa(e, (e) => t.push(e)),
4111
+ tx: co(e, (e) => t.push(e)),
4091
4112
  persist: async (e, n) => {
4092
4113
  if (t.length === 0 || n.tag.startsWith("__voltro")) return;
4093
4114
  let r = n.subject;
@@ -4103,14 +4124,14 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4103
4124
  });
4104
4125
  }
4105
4126
  };
4106
- }, eo = (e) => {
4127
+ }, uo = (e) => {
4107
4128
  if (e.id !== void 0) return e.id;
4108
4129
  let t = e.next?.id;
4109
4130
  if (typeof t == "string") return t;
4110
4131
  let n = e.prev?.id;
4111
4132
  return typeof n == "string" ? n : void 0;
4112
- }, to = (e) => {
4113
- let t = eo(e);
4133
+ }, fo = (e) => {
4134
+ let t = uo(e);
4114
4135
  switch (e.op) {
4115
4136
  case "insert": return t === void 0 ? null : {
4116
4137
  table: e.table,
@@ -4134,28 +4155,28 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4134
4155
  row: e.prev
4135
4156
  };
4136
4157
  }
4137
- }, no = (e) => {
4138
- if (e.crossesAction) throw new ro(e.invocationId, "action");
4158
+ }, po = (e) => {
4159
+ if (e.crossesAction) throw new mo(e.invocationId, "action");
4139
4160
  let t = [];
4140
4161
  for (let n = e.changes.length - 1; n >= 0; --n) {
4141
- let r = to(e.changes[n]);
4162
+ let r = fo(e.changes[n]);
4142
4163
  r !== null && t.push(r);
4143
4164
  }
4144
4165
  return t;
4145
- }, ro = class extends Error {
4166
+ }, mo = class extends Error {
4146
4167
  invocationId;
4147
4168
  boundary;
4148
4169
  _tag = "UndoBoundaryError";
4149
4170
  constructor(e, t) {
4150
4171
  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";
4151
4172
  }
4152
- }, io = (e, t, n = ["updatedAt", "updatedBy"]) => {
4173
+ }, ho = (e, t, n = ["updatedAt", "updatedBy"]) => {
4153
4174
  if (t == null) return e == null;
4154
4175
  if (e == null) return !1;
4155
4176
  let r = new Set(n);
4156
4177
  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;
4157
4178
  return !0;
4158
- }, ao = class {
4179
+ }, go = class {
4159
4180
  capacity;
4160
4181
  done = [];
4161
4182
  undone = [];
@@ -4191,7 +4212,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4191
4212
  redo: [...this.undone]
4192
4213
  };
4193
4214
  }
4194
- }, oo = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
4215
+ }, _o = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
4195
4216
  table: e.table,
4196
4217
  op: "insert",
4197
4218
  next: e.new ?? null
@@ -4208,7 +4229,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4208
4229
  table: e.table,
4209
4230
  op: "delete",
4210
4231
  prev: e.old ?? null
4211
- }, so = async (e, t) => {
4232
+ }, vo = async (e, t) => {
4212
4233
  switch (t.op) {
4213
4234
  case "delete":
4214
4235
  await e.delete(t.table, t.id);
@@ -4226,21 +4247,21 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4226
4247
  await e.insert(t.table, t.row);
4227
4248
  return;
4228
4249
  }
4229
- }, co = async (e, t) => {
4230
- for (let n of t) await so(e, n);
4231
- }, lo = (e) => e.request?.subject?.id ?? null, uo = (e) => e === !0 || e === 1, fo = async (e, t, n) => (await e.query({
4250
+ }, yo = async (e, t) => {
4251
+ for (let n of t) await vo(e, n);
4252
+ }, bo = (e) => e.request?.subject?.id ?? null, xo = (e) => e === !0 || e === 1, So = async (e, t, n) => (await e.query({
4232
4253
  table: t,
4233
4254
  predicate: u("id", n),
4234
4255
  order: []
4235
- }))[0] ?? null, po = (e) => {
4256
+ }))[0] ?? null, Co = (e) => {
4236
4257
  try {
4237
4258
  let t = JSON.parse(String(e ?? "[]"));
4238
4259
  return Array.isArray(t) ? t : [];
4239
4260
  } catch {
4240
4261
  return [];
4241
4262
  }
4242
- }, mo = (e) => e.id ?? e.next?.id ?? e.prev?.id, ho = async (e, t) => {
4243
- let n = lo(t);
4263
+ }, wo = (e) => e.id ?? e.next?.id ?? e.prev?.id, To = async (e, t) => {
4264
+ let n = bo(t);
4244
4265
  return [...await t.store.query({
4245
4266
  table: "_voltro_undo_log",
4246
4267
  predicate: u("subjectId", n),
@@ -4249,68 +4270,68 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4249
4270
  id: String(e.id),
4250
4271
  tag: String(e.tag ?? ""),
4251
4272
  label: e.label ?? null,
4252
- undone: uo(e.undone),
4253
- crossesAction: uo(e.crossesAction),
4273
+ undone: xo(e.undone),
4274
+ crossesAction: xo(e.crossesAction),
4254
4275
  createdAt: String(e.createdAt ?? "")
4255
4276
  }));
4256
- }, go = async (e, t) => {
4257
- let n = await fo(t.store, "_voltro_undo_log", e.invocationId);
4277
+ }, Eo = async (e, t) => {
4278
+ let n = await So(t.store, "_voltro_undo_log", e.invocationId);
4258
4279
  if (!n) throw new Se({ invocationId: e.invocationId });
4259
- if ((n.subjectId ?? null) !== lo(t)) throw new xe({ invocationId: e.invocationId });
4280
+ if ((n.subjectId ?? null) !== bo(t)) throw new xe({ invocationId: e.invocationId });
4260
4281
  return n;
4261
- }, _o = async (e, t) => {
4262
- let n = await go(e, t);
4263
- if (uo(n.undone)) return { ok: !0 };
4264
- if (uo(n.crossesAction)) throw new be({
4282
+ }, Do = async (e, t) => {
4283
+ let n = await Eo(e, t);
4284
+ if (xo(n.undone)) return { ok: !0 };
4285
+ if (xo(n.crossesAction)) throw new be({
4265
4286
  invocationId: e.invocationId,
4266
4287
  reason: "action"
4267
4288
  });
4268
- let r = po(n.changes);
4289
+ let r = Co(n.changes);
4269
4290
  for (let n of r) {
4270
- let r = mo(n);
4271
- if (r !== void 0 && !io(await fo(t.store, n.table, r), n.next ?? null)) throw new be({
4291
+ let r = wo(n);
4292
+ if (r !== void 0 && !ho(await So(t.store, n.table, r), n.next ?? null)) throw new be({
4272
4293
  invocationId: e.invocationId,
4273
4294
  reason: "conflict"
4274
4295
  });
4275
4296
  }
4276
4297
  let i = {
4277
4298
  invocationId: e.invocationId,
4278
- subject: lo(t),
4299
+ subject: bo(t),
4279
4300
  changes: r,
4280
4301
  crossesAction: !1
4281
4302
  };
4282
- return await co(t.store, no(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
4283
- }, vo = async (e, t) => {
4284
- let n = await go(e, t);
4285
- if (!uo(n.undone)) return { ok: !0 };
4286
- for (let e of po(n.changes)) {
4287
- let n = mo(e);
4303
+ return await yo(t.store, po(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
4304
+ }, Oo = async (e, t) => {
4305
+ let n = await Eo(e, t);
4306
+ if (!xo(n.undone)) return { ok: !0 };
4307
+ for (let e of Co(n.changes)) {
4308
+ let n = wo(e);
4288
4309
  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);
4289
4310
  }
4290
4311
  return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
4291
- }, yo = (e = process.env) => {
4312
+ }, ko = (e = process.env) => {
4292
4313
  let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
4293
4314
  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";
4294
- }, bo = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, xo = "«redacted»", So = (e) => {
4315
+ }, Ao = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, jo = "«redacted»", Mo = (e) => {
4295
4316
  if (e == null) return null;
4296
4317
  let t = {};
4297
- for (let [n, r] of Object.entries(e)) t[n] = bo.test(n) ? xo : r;
4318
+ for (let [n, r] of Object.entries(e)) t[n] = Ao.test(n) ? jo : r;
4298
4319
  return t;
4299
- }, Co = (e) => {
4320
+ }, No = (e) => {
4300
4321
  let t = e?.id;
4301
4322
  return typeof t == "string" ? t : void 0;
4302
- }, wo = (e, t) => {
4323
+ }, Po = (e, t) => {
4303
4324
  if (t.op === "insert") {
4304
- let n = Co(t.new);
4325
+ let n = No(t.new);
4305
4326
  return n === void 0 ? e : e.filter((e) => e.id !== n);
4306
4327
  }
4307
4328
  if (t.op === "update") {
4308
4329
  if (t.old == null) return e;
4309
- let n = Co(t.new) ?? Co(t.old);
4330
+ let n = No(t.new) ?? No(t.old);
4310
4331
  return e.map((e) => e.id === n ? t.old : e);
4311
4332
  }
4312
4333
  return t.old == null ? e : [...e, t.old];
4313
- }, To = class {
4334
+ }, Fo = class {
4314
4335
  mode;
4315
4336
  capacity;
4316
4337
  now;
@@ -4330,8 +4351,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4330
4351
  ts: this.now(),
4331
4352
  table: e.table,
4332
4353
  op: e.op,
4333
- old: So(e.old),
4334
- new: So(e.new),
4354
+ old: Mo(e.old),
4355
+ new: Mo(e.new),
4335
4356
  tenantId: n
4336
4357
  }), this.ring.length > this.capacity && this.ring.shift(), t;
4337
4358
  }
@@ -4344,23 +4365,23 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4344
4365
  }
4345
4366
  replay(e, t, n) {
4346
4367
  let r = this.ring.filter((n) => n.table === e && n.seq > t).sort((e, t) => t.seq - e.seq), i = n;
4347
- for (let e of r) i = wo(i, e);
4368
+ for (let e of r) i = Po(i, e);
4348
4369
  return i;
4349
4370
  }
4350
- }, Eo, Do = () => (Eo === void 0 && (Eo = new To(yo())), Eo), Oo = (e) => {
4351
- Eo = e;
4352
- }, ko = (e) => {
4353
- let t = Do();
4371
+ }, Io, Lo = () => (Io === void 0 && (Io = new Fo(ko())), Io), Ro = (e) => {
4372
+ Io = e;
4373
+ }, zo = (e) => {
4374
+ let t = Lo();
4354
4375
  if (t.enabled) try {
4355
4376
  t.record(e);
4356
4377
  } catch {}
4357
- }, Ao = /* @__PURE__ */ new Set([
4378
+ }, Bo = /* @__PURE__ */ new Set([
4358
4379
  "count",
4359
4380
  "sum",
4360
4381
  "avg",
4361
4382
  "min",
4362
4383
  "max"
4363
- ]), jo = (e) => {
4384
+ ]), Vo = (e) => {
4364
4385
  if (e.joins !== void 0 && e.joins.length > 0) return {
4365
4386
  maintainable: !1,
4366
4387
  reason: "joins are not maintainable in v1"
@@ -4382,7 +4403,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4382
4403
  reason: "v1 maintains exactly one aggregation"
4383
4404
  };
4384
4405
  let t = e.aggregations[0];
4385
- return Ao.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
4406
+ return Bo.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
4386
4407
  maintainable: !1,
4387
4408
  reason: `op '${t.op}' requires a column`
4388
4409
  } : {
@@ -4396,7 +4417,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4396
4417
  maintainable: !1,
4397
4418
  reason: `op '${t.op}' is not maintainable`
4398
4419
  };
4399
- }, Mo = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(Mo), No = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Po = (e, t) => {
4420
+ }, Ho = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(Ho), Uo = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Wo = (e, t) => {
4400
4421
  switch (e.op) {
4401
4422
  case "count": return t.count;
4402
4423
  case "sum": return t.sum ?? 0;
@@ -4404,10 +4425,10 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4404
4425
  case "min":
4405
4426
  case "max": return t.count > 0 ? t.extreme ?? null : null;
4406
4427
  }
4407
- }, Fo = (e, t) => {
4428
+ }, Go = (e, t) => {
4408
4429
  let n = /* @__PURE__ */ new Map();
4409
4430
  for (let r of t) {
4410
- let t = $(r, e.groupBy), i = n.get(t), a = No(r, e.column);
4431
+ let t = $(r, e.groupBy), i = n.get(t), a = Uo(r, e.column);
4411
4432
  if (i === void 0) n.set(t, {
4412
4433
  count: 1,
4413
4434
  ...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
@@ -4423,10 +4444,10 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4423
4444
  }
4424
4445
  }
4425
4446
  return n;
4426
- }, Io = (e, t) => [...t.entries()].map(([t, n]) => ({
4447
+ }, Ko = (e, t) => [...t.entries()].map(([t, n]) => ({
4427
4448
  groupKey: t,
4428
- value: Po(e, n)
4429
- })), Lo = (e, t, n) => {
4449
+ value: Wo(e, n)
4450
+ })), qo = (e, t, n) => {
4430
4451
  let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
4431
4452
  let n = $(t, e.groupBy), a = r.get(n);
4432
4453
  if (a === void 0) return;
@@ -4435,7 +4456,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4435
4456
  r.delete(n);
4436
4457
  return;
4437
4458
  }
4438
- let s = No(t, e.column);
4459
+ let s = Uo(t, e.column);
4439
4460
  e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
4440
4461
  count: o,
4441
4462
  ...a.extreme === void 0 ? {} : { extreme: a.extreme }
@@ -4444,7 +4465,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4444
4465
  ...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
4445
4466
  });
4446
4467
  }, o = (t) => {
4447
- let n = $(t, e.groupBy), i = r.get(n), a = No(t, e.column);
4468
+ let n = $(t, e.groupBy), i = r.get(n), a = Uo(t, e.column);
4448
4469
  if (i === void 0) {
4449
4470
  r.set(n, {
4450
4471
  count: 1,
@@ -4464,15 +4485,15 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4464
4485
  state: r,
4465
4486
  rescanGroups: [...i]
4466
4487
  };
4467
- }, Ro = (e, t, n, r) => {
4488
+ }, Jo = (e, t, n, r) => {
4468
4489
  if (n.length === 0) return t;
4469
- let i = new Set(n), a = Fo(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
4490
+ let i = new Set(n), a = Go(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
4470
4491
  for (let e of i) {
4471
4492
  let t = a.get(e);
4472
4493
  t === void 0 ? o.delete(e) : o.set(e, t);
4473
4494
  }
4474
4495
  return o;
4475
- }, zo = class {
4496
+ }, Yo = class {
4476
4497
  shape;
4477
4498
  state = /* @__PURE__ */ new Map();
4478
4499
  groups = /* @__PURE__ */ new Map();
@@ -4480,7 +4501,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4480
4501
  this.shape = e;
4481
4502
  }
4482
4503
  seed(e) {
4483
- this.state = Fo(this.shape, e), this.groups.clear();
4504
+ this.state = Go(this.shape, e), this.groups.clear();
4484
4505
  for (let t of e) {
4485
4506
  let e = $(t, this.shape.groupBy);
4486
4507
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
@@ -4492,14 +4513,14 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4492
4513
  let e = $(t, this.shape.groupBy);
4493
4514
  this.groups.has(e) || this.groups.set(e, this.groupValues(t));
4494
4515
  }
4495
- let n = Lo(this.shape, this.state, e);
4516
+ let n = qo(this.shape, this.state, e);
4496
4517
  this.state = n.state;
4497
4518
  for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
4498
4519
  return n.rescanGroups;
4499
4520
  }
4500
4521
  resolveRescan(e, t) {
4501
4522
  if (e.length === 0) return;
4502
- this.state = Ro(this.shape, this.state, e, t);
4523
+ this.state = Jo(this.shape, this.state, e, t);
4503
4524
  let n = new Set(e);
4504
4525
  for (let e of t) {
4505
4526
  let t = $(e, this.shape.groupBy);
@@ -4508,7 +4529,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4508
4529
  for (let e of n) this.state.has(e) || this.groups.delete(e);
4509
4530
  }
4510
4531
  materialize() {
4511
- return Io(this.shape, this.state).map((e) => ({
4532
+ return Ko(this.shape, this.state).map((e) => ({
4512
4533
  groupKey: e.groupKey,
4513
4534
  group: this.groups.get(e.groupKey) ?? {},
4514
4535
  value: e.value
@@ -4521,16 +4542,16 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4521
4542
  for (let r of t) n[r] = e[r];
4522
4543
  return n;
4523
4544
  }
4524
- }, Bo = "admin:full", Vo = class extends I.TaggedError()("AccessDenied", {
4545
+ }, Xo = "admin:full", Zo = class extends I.TaggedError()("AccessDenied", {
4525
4546
  action: I.String,
4526
4547
  resourceType: I.String,
4527
4548
  resourceId: I.String
4528
- }) {}, Ho = /* @__PURE__ */ new Map(), Uo = (e) => {
4549
+ }) {}, Qo = /* @__PURE__ */ new Map(), $o = (e) => {
4529
4550
  if (typeof e.resourceType != "string" || e.resourceType.length === 0) throw Error("defineResourcePolicy: a non-empty `resourceType` is required");
4530
4551
  if (e.actions === void 0 || Object.keys(e.actions).length === 0) throw Error(`resource policy '${e.resourceType}': at least one action is required`);
4531
- if (Ho.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
4532
- return Ho.set(e.resourceType, e), e;
4533
- }, Wo = (e) => Ho.get(e), Go = () => [...Ho.values()], Ko = () => Ho.clear(), qo = () => Go().map((e) => {
4552
+ if (Qo.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
4553
+ return Qo.set(e.resourceType, e), e;
4554
+ }, es = (e) => Qo.get(e), ts = () => [...Qo.values()], ns = () => Qo.clear(), rs = () => ts().map((e) => {
4534
4555
  let t = /* @__PURE__ */ new Set();
4535
4556
  for (let n of Object.values(e.actions)) for (let e of n) t.add(e);
4536
4557
  for (let [n, r] of Object.entries(e.implies ?? {})) {
@@ -4543,7 +4564,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4543
4564
  relations: [...t],
4544
4565
  implies: e.implies ?? {}
4545
4566
  };
4546
- }), Jo = (e, t) => {
4567
+ }), is = (e, t) => {
4547
4568
  let n = new Set(e);
4548
4569
  if (t === void 0) return n;
4549
4570
  let r = [...e];
@@ -4552,39 +4573,39 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4552
4573
  for (let i of t[e] ?? []) n.has(i) || (n.add(i), r.push(i));
4553
4574
  }
4554
4575
  return n;
4555
- }, Yo = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : Jo(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), Xo = (e, t, n, r) => {
4576
+ }, as = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : is(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), os = (e, t, n, r) => {
4556
4577
  if (e.scopes?.includes("admin:full")) return !0;
4557
4578
  if (e.id === null || n.tenantId != null && e.tenantId !== n.tenantId) return !1;
4558
4579
  let i = r.policy.actions[t];
4559
4580
  if (i === void 0 || i.length === 0) return !1;
4560
- let a = Yo(e, n, r.tuples, r.policy);
4581
+ let a = as(e, n, r.tuples, r.policy);
4561
4582
  return i.some((e) => a.has(e));
4562
- }, Zo = (e, t, n, r) => {
4563
- if (!Xo(e, t, n, r)) throw new Vo({
4583
+ }, ss = (e, t, n, r) => {
4584
+ if (!os(e, t, n, r)) throw new Zo({
4564
4585
  action: t,
4565
4586
  resourceType: n.type,
4566
4587
  resourceId: n.id
4567
4588
  });
4568
- }, Qo = (e, t, n, r, i) => r.filter((r) => Xo(e, t, {
4589
+ }, cs = (e, t, n, r, i) => r.filter((r) => os(e, t, {
4569
4590
  type: n,
4570
4591
  id: r.id,
4571
4592
  ...r.tenantId === void 0 ? {} : { tenantId: r.tenantId }
4572
- }, i)), $o = (e, t) => {
4593
+ }, i)), ls = (e, t) => {
4573
4594
  let n = new Set(t.map((e) => e.id));
4574
4595
  return e.filter((e) => !n.has(e.id)).map((e) => e.id);
4575
- }, es = E("_voltro_rebac_tuples", {
4596
+ }, us = T("_voltro_rebac_tuples", {
4576
4597
  id: v({ prefix: "rbct" }),
4577
- subjectId: D(),
4578
- relation: D(),
4579
- resourceType: D(),
4580
- resourceId: D(),
4581
- tenantId: D().nullable(),
4582
- createdAt: O().default("now")
4598
+ subjectId: E(),
4599
+ relation: E(),
4600
+ resourceType: E(),
4601
+ resourceId: E(),
4602
+ tenantId: E().nullable(),
4603
+ createdAt: D().default("now")
4583
4604
  }).index([
4584
4605
  "subjectId",
4585
4606
  "resourceType",
4586
4607
  "resourceId"
4587
- ]).reactive(), ts = async (e, n, r, i) => n === null ? [] : (await e.query({
4608
+ ]).reactive(), ds = async (e, n, r, i) => n === null ? [] : (await e.query({
4588
4609
  table: "_voltro_rebac_tuples",
4589
4610
  predicate: t(u("subjectId", n), u("resourceType", r), u("resourceId", i)),
4590
4611
  order: [],
@@ -4596,16 +4617,16 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4596
4617
  relation: e.relation,
4597
4618
  resourceType: e.resourceType,
4598
4619
  resourceId: e.resourceId
4599
- })), ns = (e) => ({
4620
+ })), fs = (e) => ({
4600
4621
  id: e.id,
4601
4622
  tenantId: e.tenantId,
4602
4623
  ...e.scopes === void 0 ? {} : { scopes: e.scopes }
4603
- }), rs = (e, t) => {
4604
- let n = t.getPolicy ?? Wo;
4624
+ }), ps = (e, t) => {
4625
+ let n = t.getPolicy ?? es;
4605
4626
  return (r, i) => {
4606
4627
  let a = e[i.tag];
4607
4628
  if (a === void 0) return r;
4608
- let o = n(a.resourceType), s = (e) => j.fail(new Vo({
4629
+ let o = n(a.resourceType), s = (e) => j.fail(new Zo({
4609
4630
  action: a.action,
4610
4631
  resourceType: a.resourceType,
4611
4632
  resourceId: e
@@ -4613,17 +4634,17 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4613
4634
  if (o === void 0) return s("");
4614
4635
  let c = a.resourceId(i.input);
4615
4636
  if (c === null || c === "") return s("");
4616
- let l = ns(i.subject), u = {
4637
+ let l = fs(i.subject), u = {
4617
4638
  type: a.resourceType,
4618
4639
  id: c,
4619
4640
  tenantId: i.subject.tenantId
4620
4641
  };
4621
- return j.flatMap(j.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) => Xo(l, a.action, u, {
4642
+ return j.flatMap(j.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) => os(l, a.action, u, {
4622
4643
  policy: o,
4623
4644
  tuples: e
4624
4645
  }) ? r : s(c));
4625
4646
  };
4626
- }, is = async (e, n, r) => n === null ? [] : (await e.query({
4647
+ }, ms = async (e, n, r) => n === null ? [] : (await e.query({
4627
4648
  table: "_voltro_rebac_tuples",
4628
4649
  predicate: t(u("subjectId", n), u("resourceType", r)),
4629
4650
  order: [],
@@ -4635,18 +4656,18 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4635
4656
  relation: e.relation,
4636
4657
  resourceType: e.resourceType,
4637
4658
  resourceId: e.resourceId
4638
- })), as = (e) => {
4639
- let t = e.getPolicy ?? Wo;
4659
+ })), hs = (e) => {
4660
+ let t = e.getPolicy ?? es;
4640
4661
  return async (n, r, i, a) => {
4641
4662
  let o = t(r);
4642
4663
  if (o === void 0) return [];
4643
- let s = ns(n);
4644
- return Qo(s, i, r, a, {
4664
+ let s = fs(n);
4665
+ return cs(s, i, r, a, {
4645
4666
  policy: o,
4646
4667
  tuples: await e.loadSubjectTuples(s.id, r)
4647
4668
  });
4648
4669
  };
4649
- }, os = (e) => {
4670
+ }, gs = (e) => {
4650
4671
  if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
4651
4672
  if (e.watch === void 0 || typeof e.watch.table != "string" || e.watch.table.length === 0) throw Error(`reaction '${e.name}': watch.table is required`);
4652
4673
  if (e.act === void 0 || e.act.kind !== "agent" && e.act.kind !== "workflow") throw Error(`reaction '${e.name}': act must be { kind: 'agent' | 'workflow', … }`);
@@ -4654,14 +4675,14 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4654
4675
  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`);
4655
4676
  if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
4656
4677
  return e;
4657
- }, ss = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, cs = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, ls = class {
4678
+ }, _s = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, vs = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, ys = class {
4658
4679
  hits = /* @__PURE__ */ new Map();
4659
4680
  allow(e, t, n, r) {
4660
4681
  let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
4661
4682
  return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
4662
4683
  }
4663
- }, us = async (e, t, n) => {
4664
- if (t.table !== e.watch.table || !ss(e.watch.on, t.op)) return "skipped-op";
4684
+ }, bs = async (e, t, n) => {
4685
+ if (t.table !== e.watch.table || !_s(e.watch.on, t.op)) return "skipped-op";
4665
4686
  if (e.when !== void 0 && !e.when(t)) return "skipped-when";
4666
4687
  let r = `${e.name}:${e.guards.dedupeKey(t)}`;
4667
4688
  if (await n.dedupe.has(r)) return "skipped-dedupe";
@@ -4670,26 +4691,26 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4670
4691
  let t = n.now?.() ?? Date.now();
4671
4692
  if (!n.rateLimiter.allow(e.name, i.limit, i.windowMs, t)) return "skipped-ratelimit";
4672
4693
  }
4673
- let a = cs(t);
4694
+ let a = vs(t);
4674
4695
  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, {
4675
4696
  id: a,
4676
4697
  via: "agent"
4677
4698
  }), await n.dedupe.add(r), "acted");
4678
- }, ds = E("_voltro_wakeups", {
4699
+ }, xs = T("_voltro_wakeups", {
4679
4700
  id: v({ prefix: "wakeup" }),
4680
- tenantId: D(),
4681
- kind: D(),
4682
- refId: D(),
4683
- wakeAt: O(),
4684
- status: D()
4685
- }).index(["status", "wakeAt"]).index(["tenantId"]), fs = async (e) => {
4686
- let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Ma(e.store, t, e.batchLimit ?? 100);
4701
+ tenantId: E(),
4702
+ kind: E(),
4703
+ refId: E(),
4704
+ wakeAt: D(),
4705
+ status: E()
4706
+ }).index(["status", "wakeAt"]).index(["tenantId"]), Ss = async (e) => {
4707
+ let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Ha(e.store, t, e.batchLimit ?? 100);
4687
4708
  if (n.length === 0) return 0;
4688
4709
  let r = 0;
4689
- for (let t of n) if (await Oa(e.store, t)) try {
4710
+ for (let t of n) if (await Ra(e.store, t)) try {
4690
4711
  await e.adapter.wake(t), r++;
4691
4712
  } catch (n) {
4692
- await ka(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
4713
+ await za(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
4693
4714
  tenantId: t.tenantId,
4694
4715
  kind: t.kind,
4695
4716
  refId: t.refId,
@@ -4697,11 +4718,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4697
4718
  });
4698
4719
  }
4699
4720
  return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
4700
- }, ps = (e, t = 1e3) => {
4721
+ }, Cs = (e, t = 1e3) => {
4701
4722
  let n = !1, r, i = async () => {
4702
4723
  if (!n) {
4703
4724
  try {
4704
- await fs(e);
4725
+ await Ss(e);
4705
4726
  } catch (t) {
4706
4727
  e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
4707
4728
  }
@@ -4711,10 +4732,10 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4711
4732
  return i(), { stop: () => {
4712
4733
  n = !0, r !== void 0 && clearTimeout(r);
4713
4734
  } };
4714
- }, ms = (e) => ({ wake: async () => {
4735
+ }, ws = (e) => ({ wake: async () => {
4715
4736
  await e.start();
4716
- } }), hs = (e) => new Promise((t) => setTimeout(t, e)), gs = (e) => {
4717
- let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? hs, i = e.spawnImpl ?? ut, 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 () => {
4737
+ } }), Ts = (e) => new Promise((t) => setTimeout(t, e)), Es = (e) => {
4738
+ let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? Ts, i = e.spawnImpl ?? _t, 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 () => {
4718
4739
  try {
4719
4740
  let n = await t(e.healthUrl);
4720
4741
  return d(n);
@@ -4768,11 +4789,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4768
4789
  },
4769
4790
  stop: m
4770
4791
  };
4771
- }, _s = async (e) => {
4792
+ }, Ds = async (e) => {
4772
4793
  if (e.signals.connectedClients() > 0 || e.signals.inFlightRequests() > 0 || e.signals.activeWorkflowExecutions() > 0) return !1;
4773
- let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Na(e.store);
4794
+ let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Ua(e.store);
4774
4795
  return !(n !== null && n.wakeAt.getTime() <= t);
4775
- }, vs = (e, t = Date.now) => {
4796
+ }, Os = (e, t = Date.now) => {
4776
4797
  let n;
4777
4798
  return {
4778
4799
  update: (r) => {
@@ -4784,7 +4805,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4784
4805
  n = void 0;
4785
4806
  }
4786
4807
  };
4787
- }, ys = () => {
4808
+ }, ks = () => {
4788
4809
  let e = 0, t = 0;
4789
4810
  return {
4790
4811
  onRequestStart: () => {
@@ -4802,8 +4823,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4802
4823
  inFlightRequests: () => e,
4803
4824
  openConnections: () => t
4804
4825
  };
4805
- }, bs = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), xs = (e, t, n, r) => new Promise((i, a) => {
4806
- let o = ze.request({
4826
+ }, As = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), js = (e, t, n, r) => new Promise((i, a) => {
4827
+ let o = We.request({
4807
4828
  host: n,
4808
4829
  port: r,
4809
4830
  method: e.method,
@@ -4813,8 +4834,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4813
4834
  t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
4814
4835
  });
4815
4836
  o.on("error", a), e.pipe(o);
4816
- }), Ss = (e, t, n, r, i) => new Promise((a, o) => {
4817
- let s = ze.request({
4837
+ }), Ms = (e, t, n, r, i) => new Promise((a, o) => {
4838
+ let s = We.request({
4818
4839
  host: r,
4819
4840
  port: i,
4820
4841
  method: e.method,
@@ -4828,21 +4849,21 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4828
4849
  };
4829
4850
  t.on("close", s), r.on("close", s), r.on("error", o);
4830
4851
  }), s.on("error", o), s.end();
4831
- }), Cs = (e) => {
4832
- let t = bs({
4852
+ }), Ns = (e) => {
4853
+ let t = As({
4833
4854
  ensureAwake: () => e.supervisor.start(),
4834
4855
  ...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
4835
- }), n = e.activity, r = ze.createServer((r, i) => {
4836
- n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => xs(r, i, e.targetHost, e.targetPort)).catch((t) => {
4856
+ }), n = e.activity, r = We.createServer((r, i) => {
4857
+ n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => js(r, i, e.targetHost, e.targetPort)).catch((t) => {
4837
4858
  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");
4838
4859
  });
4839
4860
  });
4840
4861
  return r.on("upgrade", (r, i, a) => {
4841
- n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Ss(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
4862
+ n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Ms(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
4842
4863
  e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
4843
4864
  });
4844
4865
  }), r;
4845
- }, ws = async (e) => {
4866
+ }, Ps = async (e) => {
4846
4867
  try {
4847
4868
  return (await e.query({
4848
4869
  table: "_voltro_workflow_runs",
@@ -4859,15 +4880,15 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4859
4880
  } catch {
4860
4881
  return 0;
4861
4882
  }
4862
- }, Ts = async (e) => {
4863
- let t = ms(e.supervisor), n = await fs({
4883
+ }, Fs = async (e) => {
4884
+ let t = ws(e.supervisor), n = await Ss({
4864
4885
  store: e.store,
4865
4886
  adapter: t,
4866
4887
  ...e.now === void 0 ? {} : { now: e.now },
4867
4888
  ...e.log === void 0 ? {} : { log: e.log }
4868
4889
  });
4869
4890
  n > 0 && e.idleGate.reset();
4870
- let r = await _s({
4891
+ let r = await Ds({
4871
4892
  store: e.store,
4872
4893
  signals: e.signals,
4873
4894
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
@@ -4877,12 +4898,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4877
4898
  woke: n,
4878
4899
  stopped: i
4879
4900
  };
4880
- }, Es = async (e) => {
4881
- let t = vs(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = ys(), i = 0, a = e.signals === void 0, o = e.signals ?? {
4901
+ }, Is = async (e) => {
4902
+ let t = Os(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = ks(), i = 0, a = e.signals === void 0, o = e.signals ?? {
4882
4903
  connectedClients: () => r.openConnections(),
4883
4904
  inFlightRequests: () => r.inFlightRequests(),
4884
4905
  activeWorkflowExecutions: () => i
4885
- }, s = Cs({
4906
+ }, s = Ns({
4886
4907
  supervisor: e.supervisor,
4887
4908
  targetHost: e.targetHost,
4888
4909
  targetPort: e.targetPort,
@@ -4901,7 +4922,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4901
4922
  let l = !1, u, d = e.firedRetentionMs ?? 10 * 6e4, f = 0, p = async () => {
4902
4923
  if (!l) {
4903
4924
  try {
4904
- if (a && (i = await ws(e.store)), await Ts({
4925
+ if (a && (i = await Ps(e.store)), await Fs({
4905
4926
  store: e.store,
4906
4927
  supervisor: e.supervisor,
4907
4928
  signals: o,
@@ -4909,7 +4930,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4909
4930
  ...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
4910
4931
  ...e.log === void 0 ? {} : { log: e.log }
4911
4932
  }), f++ % 60 == 0) {
4912
- let t = await Fa(e.store, { firedOlderThan: new Date(Date.now() - d) });
4933
+ let t = await Ga(e.store, { firedOlderThan: new Date(Date.now() - d) });
4913
4934
  t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
4914
4935
  }
4915
4936
  } catch (t) {
@@ -4924,14 +4945,14 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4924
4945
  l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
4925
4946
  }
4926
4947
  };
4927
- }, Ds = (e) => e, Os = class extends I.TaggedError()("AnalyticsError", {
4948
+ }, Ls = (e) => e, Rs = class extends I.TaggedError()("AnalyticsError", {
4928
4949
  provider: I.String,
4929
4950
  operation: I.String,
4930
4951
  cause: I.String
4931
- }) {}, ks = class extends I.TaggedError()("AnalyticsCapabilityNotSupported", {
4952
+ }) {}, zs = class extends I.TaggedError()("AnalyticsCapabilityNotSupported", {
4932
4953
  provider: I.String,
4933
4954
  capability: I.String
4934
- }) {}, As = class extends Ae.Tag("@voltro/AnalyticsSink")() {}, js = (e, t) => ({
4955
+ }) {}, Bs = class extends Fe.Tag("@voltro/AnalyticsSink")() {}, Vs = (e, t) => ({
4935
4956
  info: e.info,
4936
4957
  track: (n) => e.track(n.tenantId === void 0 ? {
4937
4958
  ...n,
@@ -4950,20 +4971,20 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4950
4971
  tenantId: t
4951
4972
  } : n),
4952
4973
  ...e.mirror === void 0 ? {} : { mirror: e.mirror }
4953
- }), Ms = () => j.gen(function* () {
4954
- let e = yield* As, t = yield* j.serviceOption(ye), n = P.match(t, {
4974
+ }), Hs = () => j.gen(function* () {
4975
+ let e = yield* Bs, t = yield* j.serviceOption(O), n = P.match(t, {
4955
4976
  onNone: () => null,
4956
4977
  onSome: (e) => e.tenantId ?? null
4957
4978
  });
4958
- return n === null ? e : js(e, n);
4959
- }), Ns = "noop", Ps = () => {
4960
- let e = (e) => j.fail(new ks({
4961
- provider: Ns,
4979
+ return n === null ? e : Vs(e, n);
4980
+ }), Us = "noop", Ws = () => {
4981
+ let e = (e) => j.fail(new zs({
4982
+ provider: Us,
4962
4983
  capability: e
4963
4984
  }));
4964
4985
  return {
4965
4986
  info: {
4966
- provider: Ns,
4987
+ provider: Us,
4967
4988
  capabilities: {
4968
4989
  track: !0,
4969
4990
  aggregate: !1,
@@ -4977,8 +4998,8 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4977
4998
  timeseries: () => e("timeseries"),
4978
4999
  topN: () => e("topN")
4979
5000
  };
4980
- }, Fs = (e) => {
4981
- if (e.length === 0) return Ps();
5001
+ }, Gs = (e) => {
5002
+ if (e.length === 0) return Ws();
4982
5003
  if (e.length === 1) return e[0];
4983
5004
  let t = {
4984
5005
  provider: "compose",
@@ -4995,7 +5016,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
4995
5016
  discard: !0
4996
5017
  }), r = (t, n) => {
4997
5018
  let r = e.find((e) => e.info.capabilities[t]);
4998
- return r === void 0 ? j.fail(new ks({
5019
+ return r === void 0 ? j.fail(new zs({
4999
5020
  provider: "compose",
5000
5021
  capability: t
5001
5022
  })) : n(r);
@@ -5018,11 +5039,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5018
5039
  topN: (e) => r("topN", (t) => t.topN(e)),
5019
5040
  ...a === void 0 ? {} : { mirror: a }
5020
5041
  };
5021
- }, Is = (e) => {
5042
+ }, Ks = (e) => {
5022
5043
  let t = e.filter((e) => e.dispose !== void 0);
5023
5044
  return {
5024
5045
  kind: "compose",
5025
- build: (t) => Fs(e.map((e) => e.build(t))),
5046
+ build: (t) => Gs(e.map((e) => e.build(t))),
5026
5047
  tables: e.flatMap((e) => e.tables ?? []),
5027
5048
  initialize: (t) => j.forEach(e, (e) => e.initialize ? e.initialize(t) : j.void, {
5028
5049
  concurrency: 1,
@@ -5033,15 +5054,15 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5033
5054
  discard: !0
5034
5055
  }) } : {}
5035
5056
  };
5036
- }, Ls = {
5057
+ }, qs = {
5037
5058
  kind: "noop",
5038
- build: () => Ps()
5039
- }, Rs = {
5059
+ build: () => Ws()
5060
+ }, Js = {
5040
5061
  tables: [],
5041
5062
  detach: () => {}
5042
- }, zs = (e) => {
5063
+ }, Ys = (e) => {
5043
5064
  let { store: t, sink: n, log: r } = e, i = n.mirror;
5044
- if (i === void 0 || i.tables.length === 0) return Rs;
5065
+ if (i === void 0 || i.tables.length === 0) return Js;
5045
5066
  let a = e.run ?? ((e) => j.runPromise(e)), o = i.primaryKey ?? "id", s = new Set(i.tables), c = (e) => {
5046
5067
  if (e.op === "delete") {
5047
5068
  let t = e.old;
@@ -5065,11 +5086,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5065
5086
  tables: i.tables,
5066
5087
  detach: l
5067
5088
  };
5068
- }, Bs = (e) => {
5089
+ }, Xs = (e) => {
5069
5090
  let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
5070
5091
  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`);
5071
5092
  if (e.incremental !== void 0) {
5072
- let t = jo({
5093
+ let t = Vo({
5073
5094
  aggregations: [{
5074
5095
  op: e.incremental.op,
5075
5096
  ...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
@@ -5091,35 +5112,38 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5091
5112
  build: e.build,
5092
5113
  ...e.incremental === void 0 ? {} : { incremental: e.incremental }
5093
5114
  };
5094
- }, Vs = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Hs = class extends I.TaggedError()("AggregateStale", {
5115
+ }, Zs = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Qs = class extends I.TaggedError()("AggregateStale", {
5095
5116
  name: I.String,
5096
5117
  ageMs: I.Number,
5097
5118
  maxAgeMs: I.Number
5098
- }) {}, Us = class extends I.TaggedError()("AggregateNotFound", { name: I.String }) {}, Ws = class extends I.TaggedError()("AggregateError", {
5119
+ }) {}, $s = class extends I.TaggedError()("AggregateNotFound", { name: I.String }) {}, ec = class extends I.TaggedError()("AggregateError", {
5099
5120
  name: I.String,
5100
5121
  operation: I.String,
5101
5122
  cause: I.String
5102
- }) {}, Gs = class extends Ae.Tag("@voltro/AggregateRegistry")() {}, Ks = (e) => j.gen(function* () {
5103
- return (yield* Gs).getHandle(e);
5104
- }), qs = (e, n, r) => {
5123
+ }) {}, tc = class extends Fe.Tag("@voltro/AggregateRegistry")() {}, nc = (e) => j.gen(function* () {
5124
+ return (yield* tc).getHandle(e);
5125
+ }), rc = (e, n, r) => {
5105
5126
  if (e.crossTenant || !n.has(e.table) || r == null) return e;
5106
5127
  let i = u("tenantId", r);
5107
5128
  return {
5108
5129
  ...e,
5109
5130
  predicate: e.predicate ? t(e.predicate, i) : i
5110
5131
  };
5111
- }, Js = (e, n) => {
5132
+ }, ic = (e, n) => {
5112
5133
  if (e.includeDeleted || !n.has(e.table)) return e;
5113
- let r = x("deletedAt");
5134
+ let r = S("deletedAt");
5114
5135
  return {
5115
5136
  ...e,
5116
5137
  predicate: e.predicate ? t(e.predicate, r) : r
5117
5138
  };
5118
- }, Ys = (e) => j.runPromiseExit(e).then((e) => {
5119
- if (Pe.isSuccess(e)) return e.value;
5139
+ }, ac = (e) => j.runPromiseExit(e).then((e) => {
5140
+ if (ze.isSuccess(e)) return e.value;
5120
5141
  let t = k.failureOption(e.cause);
5121
5142
  throw P.isSome(t) ? t.value : k.squash(e.cause);
5122
- }), Xs = (e, t) => e.pipe(j.provideService(ye, t)), Zs = async (e) => {
5143
+ }), oc = (e, t) => e.pipe(j.provideService(O, t)), sc = async (e, t, n) => {
5144
+ let r = await j.runPromise(we(t, e.guards, n));
5145
+ if (r) throw r;
5146
+ }, cc = async (e) => {
5123
5147
  let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
5124
5148
  try {
5125
5149
  if (e.interceptor) {
@@ -5134,7 +5158,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5134
5158
  traceId: e.requestContext.traceId,
5135
5159
  ...e.requestContext.spanId === void 0 ? {} : { spanId: e.requestContext.spanId }
5136
5160
  }), r = await j.runPromiseExit(n);
5137
- if (Pe.isSuccess(r)) return r.value;
5161
+ if (ze.isSuccess(r)) return r.value;
5138
5162
  throw k.squash(r.cause);
5139
5163
  }
5140
5164
  return await e.runExecutor();
@@ -5148,27 +5172,27 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5148
5172
  status: r
5149
5173
  });
5150
5174
  }
5151
- }, Qs = /* @__PURE__ */ new Set([1213, 1205]), $s = /* @__PURE__ */ new Set([
5175
+ }, lc = /* @__PURE__ */ new Set([1213, 1205]), uc = /* @__PURE__ */ new Set([
5152
5176
  "ER_LOCK_DEADLOCK",
5153
5177
  "ER_LOCK_WAIT_TIMEOUT",
5154
5178
  "40001",
5155
5179
  "40P01"
5156
- ]), ec = (e) => {
5180
+ ]), dc = (e) => {
5157
5181
  let t = e;
5158
5182
  for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
5159
5183
  let e = t;
5160
- if (typeof e.errno == "number" && Qs.has(e.errno) || typeof e.code == "string" && $s.has(e.code) || typeof e.sqlState == "string" && $s.has(e.sqlState)) return !0;
5184
+ if (typeof e.errno == "number" && lc.has(e.errno) || typeof e.code == "string" && uc.has(e.code) || typeof e.sqlState == "string" && uc.has(e.sqlState)) return !0;
5161
5185
  t = e.cause;
5162
5186
  }
5163
5187
  return !1;
5164
- }, tc = 3, nc = (e) => new Promise((t) => setTimeout(t, e)), rc = async (e) => {
5188
+ }, fc = 3, pc = (e) => new Promise((t) => setTimeout(t, e)), mc = async (e) => {
5165
5189
  for (let t = 1;; t++) try {
5166
5190
  return await e();
5167
5191
  } catch (e) {
5168
- if (t >= tc || !ec(e)) throw e;
5169
- await nc(t * 20 + Math.floor(Math.random() * 30));
5192
+ if (t >= fc || !dc(e)) throw e;
5193
+ await pc(t * 20 + Math.floor(Math.random() * 30));
5170
5194
  }
5171
- }, ic = (e) => (t, n, r) => Zs({
5195
+ }, hc = (e) => (t, n, r) => cc({
5172
5196
  name: t.descriptor.name,
5173
5197
  kind: "mutation",
5174
5198
  input: n,
@@ -5176,10 +5200,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5176
5200
  ...e.interceptor ? { interceptor: e.interceptor } : {},
5177
5201
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
5178
5202
  runExecutor: async () => {
5179
- let i = [], a = await rc(async () => (i.length = 0, e.store.transactional(async (a) => {
5203
+ await sc(t.descriptor, r.subject, n);
5204
+ let i = [], a = await mc(async () => (i.length = 0, e.store.transactional(async (a) => {
5180
5205
  let o = e.undoCapture?.(a), s = o ? o.tx : a, c = e.buildContext(r, s, { afterCommit: (e) => {
5181
5206
  i.push(e);
5182
- } }), l = t.executor(n, c), u = j.isEffect(l) ? await e.runEffect(Xs(l, r.subject), c.store) : await l;
5207
+ } }), l = t.executor(n, c), u = j.isEffect(l) ? await e.runEffect(oc(l, r.subject), c.store) : await l;
5183
5208
  return o && await o.persist(c.store, {
5184
5209
  tag: t.descriptor.name,
5185
5210
  subject: r.subject,
@@ -5189,32 +5214,39 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5189
5214
  for (let e of i) await e();
5190
5215
  return a;
5191
5216
  }
5192
- }), ac = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, oc = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, sc = (e) => {
5217
+ }), gc = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, _c = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, vc = (e) => {
5193
5218
  let t = e.descriptor.source;
5194
5219
  return t == null ? [] : typeof t == "string" ? [t] : [...t];
5195
- }, cc = (e) => (t, n) => (r) => {
5220
+ }, yc = (e) => (t, n) => (r) => {
5196
5221
  let i = e.buildContext(r), a = async () => {
5197
5222
  let i = e.buildContext(r), a = t.executor(n, i);
5198
- return j.isEffect(a) ? j.runPromise(e.provideEffect(Xs(a, r.subject), i.store)) : ac(await Promise.resolve(a));
5223
+ return j.isEffect(a) ? j.runPromise(e.provideEffect(oc(a, r.subject), i.store)) : gc(await Promise.resolve(a));
5199
5224
  }, o = (n) => {
5200
- let i = ac(n);
5201
- return oc(i) ? e.finalize(i, r) : {
5225
+ let i = gc(n);
5226
+ return _c(i) ? e.finalize(i, r) : {
5202
5227
  __voltroComputed: !0,
5203
5228
  value: i,
5204
- dependentTables: sc(t),
5229
+ dependentTables: vc(t),
5205
5230
  tenantId: r.subject?.tenantId ?? null,
5206
5231
  recompute: a
5207
5232
  };
5208
5233
  }, s = () => {
5209
5234
  let a = t.executor(n, i);
5210
- return j.isEffect(a) ? e.provideEffect(Xs(a, r.subject), i.store).pipe(j.map(o)) : a instanceof Promise ? j.promise(() => a).pipe(j.map(o)) : o(a);
5235
+ return j.isEffect(a) ? e.provideEffect(oc(a, r.subject), i.store).pipe(j.map(o)) : a instanceof Promise ? j.promise(() => a).pipe(j.map(o)) : o(a);
5236
+ }, c = () => {
5237
+ let e = t.descriptor.guards;
5238
+ return !e || e.length === 0 ? s() : we(r.subject, e, n).pipe(j.flatMap((e) => {
5239
+ if (e) return j.fail(e);
5240
+ let t = s();
5241
+ return j.isEffect(t) ? t : j.succeed(t);
5242
+ }));
5211
5243
  };
5212
- if (!e.interceptor) return s();
5213
- let c = j.suspend(() => {
5214
- let e = s();
5244
+ if (!e.interceptor) return c();
5245
+ let l = j.suspend(() => {
5246
+ let e = c();
5215
5247
  return j.isEffect(e) ? e : j.succeed(e);
5216
5248
  });
5217
- return e.interceptor(c, {
5249
+ return e.interceptor(l, {
5218
5250
  tag: t.descriptor.name,
5219
5251
  kind: "query",
5220
5252
  input: n,
@@ -5222,7 +5254,7 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5222
5254
  traceId: r.traceId,
5223
5255
  ...r.spanId === void 0 ? {} : { spanId: r.spanId }
5224
5256
  });
5225
- }, lc = (e) => (t, n, r) => Zs({
5257
+ }, bc = (e) => (t, n, r) => cc({
5226
5258
  name: t.descriptor.name,
5227
5259
  kind: "action",
5228
5260
  input: n,
@@ -5230,15 +5262,16 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5230
5262
  ...e.interceptor ? { interceptor: e.interceptor } : {},
5231
5263
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
5232
5264
  runExecutor: async () => {
5265
+ await sc(t.descriptor, r.subject, n);
5233
5266
  let i = e.buildContext(r), a = t.executor(n, i);
5234
- return j.isEffect(a) ? e.runEffect(Xs(a, r.subject), i.store) : a;
5267
+ return j.isEffect(a) ? e.runEffect(oc(a, r.subject), i.store) : a;
5235
5268
  }
5236
- }), uc = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, dc = (e) => typeof e == "string" && e.length > 0 ? e : null, fc = [
5269
+ }), xc = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, Sc = (e) => typeof e == "string" && e.length > 0 ? e : null, Cc = [
5237
5270
  "updatedAt",
5238
5271
  "createdAt",
5239
5272
  "updatedBy",
5240
5273
  "createdBy"
5241
- ], pc = (e) => fc.some((t) => t in e), mc = (e, t, n) => {
5274
+ ], wc = (e) => Cc.some((t) => t in e), Tc = (e, t, n) => {
5242
5275
  let r = {
5243
5276
  table: t.table,
5244
5277
  id: t.id,
@@ -5253,14 +5286,14 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5253
5286
  found: !1
5254
5287
  };
5255
5288
  let i = t.column === void 0 ? void 0 : e[t.column];
5256
- if (!pc(e)) return {
5289
+ if (!wc(e)) return {
5257
5290
  ...r,
5258
5291
  value: i,
5259
5292
  lastWrite: null,
5260
5293
  attribution: "none",
5261
5294
  found: !0
5262
5295
  };
5263
- let a = dc(e.updatedBy) ?? dc(e.createdBy), o = uc(e.updatedAt) ?? uc(e.createdAt);
5296
+ let a = Sc(e.updatedBy) ?? Sc(e.createdBy), o = xc(e.updatedAt) ?? xc(e.createdAt);
5264
5297
  return {
5265
5298
  ...r,
5266
5299
  value: i,
@@ -5272,12 +5305,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5272
5305
  attribution: "audit",
5273
5306
  found: !0
5274
5307
  };
5275
- }, hc = (e, t) => {
5308
+ }, Ec = (e, t) => {
5276
5309
  let n = e.map((e) => {
5277
5310
  let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
5278
5311
  return {
5279
- actor: { id: dc(e.actor) ?? dc(e.changedBy) },
5280
- at: uc(e.at) ?? uc(e.changedAt),
5312
+ actor: { id: Sc(e.actor) ?? Sc(e.changedBy) },
5313
+ at: xc(e.at) ?? xc(e.changedAt),
5281
5314
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
5282
5315
  value: r
5283
5316
  };
@@ -5292,12 +5325,12 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5292
5325
  history: n,
5293
5326
  found: n.length > 0
5294
5327
  };
5295
- }, gc = (e) => {
5328
+ }, Dc = (e) => {
5296
5329
  let t = e.new?.id;
5297
5330
  if (typeof t == "string") return t;
5298
5331
  let n = e.old?.id;
5299
5332
  return typeof n == "string" ? n : void 0;
5300
- }, _c = (e) => {
5333
+ }, Oc = (e) => {
5301
5334
  let t = {};
5302
5335
  if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
5303
5336
  from: void 0,
@@ -5317,11 +5350,11 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5317
5350
  return {
5318
5351
  table: e.table,
5319
5352
  op: e.op,
5320
- id: gc(e),
5353
+ id: Dc(e),
5321
5354
  fields: t
5322
5355
  };
5323
- }, vc = (e) => {
5324
- let t = e.map(_c);
5356
+ }, kc = (e) => {
5357
+ let t = e.map(Oc);
5325
5358
  return {
5326
5359
  rows: t,
5327
5360
  summary: {
@@ -5330,21 +5363,21 @@ var q = /* @__PURE__ */ new Map(), En = (e, t) => {
5330
5363
  deletes: t.filter((e) => e.op === "delete").length
5331
5364
  }
5332
5365
  };
5333
- }, yc = class extends Error {
5366
+ }, Ac = class extends Error {
5334
5367
  constructor() {
5335
5368
  super("voltro:preview-rollback"), this.name = "PreviewRollback";
5336
5369
  }
5337
- }, bc = async (e, t) => {
5370
+ }, jc = async (e, t) => {
5338
5371
  let n, r = !1;
5339
5372
  try {
5340
5373
  await e.transactional(async (e) => {
5341
- throw n = await t(e), r = !0, new yc();
5374
+ throw n = await t(e), r = !0, new Ac();
5342
5375
  });
5343
5376
  } catch (e) {
5344
- if (!(e instanceof yc)) throw e;
5377
+ if (!(e instanceof Ac)) throw e;
5345
5378
  }
5346
5379
  if (!r) throw Error("preview: handler did not complete");
5347
5380
  return n;
5348
- }, xc = "framework-runtime";
5381
+ }, Mc = "framework-runtime";
5349
5382
  //#endregion
5350
- export { $r as API_KEYS_TABLE, Vo as AccessDenied, Ws as AggregateError, zo as AggregateMaintainer, Us as AggregateNotFound, Gs as AggregateRegistry, Hs as AggregateStale, ks as AnalyticsCapabilityNotSupported, Os as AnalyticsError, As as AnalyticsSink, ia as CircuitBreaker, na as CircuitOpen, dr as DEFAULT_MAX_RPC_BODY_BYTES, qi as DeleteBuilder, mn as Dispatcher, la as EffectStore, At as InMemoryDataStore, vt as IndexedMatcher, dt as LinearScanMatcher, Ie as MetricBoundaries, Ns as NOOP_ANALYTICS_PROVIDER, Bi as NoRowFound, Vi as OptimisticLockError, Bo as REBAC_ADMIN_SCOPE, xc as RUNTIME_NAME, ls as ReactionRateLimiter, qn as ReplicatedDataStore, Gi as SelectBuilder, Xi as StoreOperationFailed, xt as SubscriptionRegistry, Zi as TableValidationFailed, Yi as TenantScopeViolation, To as TimelineRecorder, ro as UndoBoundaryError, ao as UndoStack, Ki as UpdateBuilder, Ni as VOLTRO_AUDIT_MIXIN_ID, Pi as VOLTRO_SOFT_DELETE_MIXIN_ID, Fi as VOLTRO_TENANT_MIXIN_ID, On as _connectionStreamCount, kn as _resetConnectionSubjectsForTest, es as _voltroRebacTuplesTable, Ka as _voltroScheduleClaimsTable, Ga as _voltroScheduleRunsTable, qa as _voltroTracesTable, Ja as _voltroUndoLogTable, ds as _voltroWakeupsTable, Ai as _voltroWorkflowEventDeliveriesTable, ki as _voltroWorkflowEventsTable, di as apiKeyManagementRoutes, Lo as applyDelta, so as applyInverse, co as applyInverses, Js as applySoftDeleteScope, qs as applyTenantScope, _o as applyUndoInvocation, Zo as assertCan, zs as attachAnalyticsMirror, pr as awaitServerListening, xn as bindConnectionSubject, ur as bindMutation, nr as bindStream, tr as bindSubscription, $n as bindSubscriptionUntyped, Fo as buildIvmState, vc as buildPreview, rs as buildRebacInterceptor, as as buildRebacReadFilter, Vn as buildSubjectKey, vr as buildTracingLayer, Nr as cachedBackend, Xo as can, Ta as cancelWakeup, jo as classifyShape, Ko as clearResourcePolicies, i as clearRetentions, sa as clearSystemStoreHandle, ba as compileCron, Is as composeAnalytics, Fs as composeAnalyticsSinks, An as connectionSubjectsSnapshot, ws as countRunningWorkflows, cn as counter, Kn as currentRoutingContext, Ln as currentTraceContext, ci as dataStoreApiKeyStore, Gr as dataStoreIdempotencyStore, Xr as dataStoreKvStore, Bs as defineAggregate, wi as defineEventTrigger, os as defineReaction, Uo as defineResourcePolicy, ya as defineSchedule, Ds as defineSubscriber, Ir as deriveKey, _c as diffChange, Ma as dueWakeups, Yo as effectiveRelations, zi as emptySchemaRegistry, Dr as envSecretsBackend, Pn as externalSpanFromTraceparent, Mt as extractDbCause, bt as fingerprintFor, Mn as formatTraceparent, oo as forwardChangeFromCdc, li as frameworkApiKeyStrategy, ln as gauge, ti as generateApiKeyToken, Sn as getConnectionSubject, Vr as getFieldCipher, Wo as getResourcePolicy, Do as getTimelineRecorder, $ as groupKeyOf, un as histogramMetric, hc as historyProvenance, Pr as httpSecretsBackend, ct as inspectWorkflow, Dn as interruptConnectionStreams, to as invertChange, Vs as isAggregateDefinition, Nt as isForeignKeyViolation, _s as isIdleNow, sr as isInfraError, io as isSafeToApply, _a as isScheduleDefinition, Ti as isWorkflowEventTriggerDefinition, Po as ivmValue, mc as lastWriteProvenance, Go as listResourcePolicies, C as listRetentions, ts as loadResourceTuples, is as loadSubjectTuples, pa as localityAwareSelector, lc as makeActionRunner, Ra as makeAdvisoryLockCoordinator, Lr as makeAesCipher, ii as makeApiKeyService, Zr as makeAsyncKv, Er as makeBufferingSpanProcessor, Wa as makeCoordinatedScheduler, fa as makeEffectStoreLayer, ji as makeEventsFacade, Rr as makeFieldCipher, Ji as makeFluentStore, vs as makeIdleGate, bi as makeLazyWorkflowFacade, ic as makeMutationRunner, vi as makePostCommitWorkflowFacade, ms as makeProcessAdapter, cc as makeQueryDescriptorProducer, ys as makeRouterActivity, Ii as makeSchemaRegistry, $a as makeUndoCapture, bs as makeWakeGate, Cs as makeWakeProxyServer, _i as makeWorkflowFacade, yi as makeWorkflowFacadeWithCallerContext, xi as makeWorkflowHandlers, Si as makeWorkflowLayers, pi as makeWorkflowRunHandle, Ea as markWakeupFired, Io as materializeIvm, ai as memoryApiKeyStore, ha as memoryReplicationAdapter, Bn as memoryRywPositionStore, xa as nextFiring, Na as nextWakeup, gs as nodeProcessSupervisor, Ps as noopAnalytics, Ls as noopAnalyticsSpec, Qr as noopKv, wn as onBindConnectionSubject, Nn as parseTraceparent, Rn as powerOfTwoSelector, bc as previewInRollback, Fa as pruneWakeups, qo as rebacPolicyGraph, nn as recordSample, sn as recordSubscriptionActive, an as recordSubscriptionDelivery, ko as recordTimelineEvent, So as redactRow, Hn as redisRywPositionStore, vo as redoUndoInvocation, En as registerConnectionStream, re as registerRetention, wa as registerWakeup, ka as releaseWakeup, zn as replicaHealth, Ar as resetSecretsBackend, ma as resolveCurrentRegion, Pt as resolveDependentTables, Ro as resolveRescan, jr as resolveSecret, Mr as resolveSecretSync, Fr as resolveSecretsBackend, yo as resolveTimelineMode, ae as retentionTtlMsFromEnv, wo as reverseEventOverRows, $o as revokedIds, ca as runAsSystem, Ts as runOrchestratorTick, Ys as runProvidedEffect, us as runReaction, Es as runSingleNodeOrchestrator, ps as runWakeLoop, Gn as runWithRoutingContext, In as runWithTraceContext, Ua as scheduleCoordinated, Br as setFieldCipher, kr as setSecretsBackend, oa as setSystemStoreHandle, Oo as setTimelineRecorderForTest, ei as sha256Hex, Ia as singleCoordinator, fn as snapshotMetrics, pn as snapshotMetricsSync, fr as startRpcServer, Ba as startScheduler, se as sweepRetention, no as synthesizeInverse, Mi as tracingHttpClientLayer, Ci as triggerWorkflow, Oa as tryClaimWakeup, Cn as unbindConnectionSubject, Ya as undoCaptureEnabled, ho as undoLogExecutor, Ks as useAggregate, Ms as useAnalytics, Qo as visibleRows, fs as wakeDueOnce, fi as workflowToRpc, Qa as wrapCaptureStore, ta as wrapStoreWithMixinBehaviour };
5383
+ export { ci as API_KEYS_TABLE, Zo as AccessDenied, ec as AggregateError, Yo as AggregateMaintainer, $s as AggregateNotFound, tc as AggregateRegistry, Qs as AggregateStale, zs as AnalyticsCapabilityNotSupported, Rs as AnalyticsError, Bs as AnalyticsSink, ma as CircuitBreaker, fa as CircuitOpen, _r as DEFAULT_MAX_RPC_BODY_BYTES, na as DeleteBuilder, bn as Dispatcher, ya as EffectStore, Lt as InMemoryDataStore, Tt as IndexedMatcher, vt as LinearScanMatcher, Ve as MetricBoundaries, Us as NOOP_ANALYTICS_PROVIDER, Yi as NoRowFound, Xi as OptimisticLockError, Xo as REBAC_ADMIN_SCOPE, Mc as RUNTIME_NAME, ys as ReactionRateLimiter, $n as ReplicatedDataStore, ea as SelectBuilder, aa as StoreOperationFailed, Ot as SubscriptionRegistry, oa as TableValidationFailed, ia as TenantScopeViolation, Fo as TimelineRecorder, mo as UndoBoundaryError, go as UndoStack, ta as UpdateBuilder, Hi as VOLTRO_AUDIT_MIXIN_ID, Ui as VOLTRO_SOFT_DELETE_MIXIN_ID, Wi as VOLTRO_TENANT_MIXIN_ID, Pn as _connectionStreamCount, Fn as _resetConnectionSubjectsForTest, us as _voltroRebacTuplesTable, no as _voltroScheduleClaimsTable, to as _voltroScheduleRunsTable, ro as _voltroTracesTable, io as _voltroUndoLogTable, xs as _voltroWakeupsTable, zi as _voltroWorkflowEventDeliveriesTable, Ri as _voltroWorkflowEventsTable, bi as apiKeyManagementRoutes, ca as applyDefined, qo as applyDelta, vo as applyInverse, yo as applyInverses, ic as applySoftDeleteScope, rc as applyTenantScope, Do as applyUndoInvocation, ss as assertCan, Ys as attachAnalyticsMirror, yr as awaitServerListening, Dn as bindConnectionSubject, gr as bindMutation, cr as bindStream, sr as bindSubscription, ar as bindSubscriptionUntyped, Go as buildIvmState, kc as buildPreview, ps as buildRebacInterceptor, hs as buildRebacReadFilter, qn as buildSubjectKey, wr as buildTracingLayer, zr as cachedBackend, os as can, Fa as cancelWakeup, Vo as classifyShape, ns as clearResourcePolicies, i as clearRetentions, _a as clearSystemStoreHandle, Aa as compileCron, Ks as composeAnalytics, Gs as composeAnalyticsSinks, In as connectionSubjectsSnapshot, Ps as countRunningWorkflows, mn as counter, Qn as currentRoutingContext, Un as currentTraceContext, _i as dataStoreApiKeyStore, ei as dataStoreIdempotencyStore, ai as dataStoreKvStore, Xr as decryptField, Xs as defineAggregate, Ni as defineEventTrigger, gs as defineReaction, $o as defineResourcePolicy, ka as defineSchedule, Ls as defineSubscriber, Hr as deriveKey, Oc as diffChange, Ha as dueWakeups, as as effectiveRelations, Ji as emptySchemaRegistry, Yr as encryptField, Nr as envSecretsBackend, Bn as externalSpanFromTraceparent, zt as extractDbCause, Dt as fingerprintFor, Rn as formatTraceparent, _o as forwardChangeFromCdc, vi as frameworkApiKeyStrategy, hn as gauge, ui as generateApiKeyToken, On as getConnectionSubject, qr as getFieldCipher, es as getResourcePolicy, Lo as getTimelineRecorder, $ as groupKeyOf, gn as histogramMetric, Ec as historyProvenance, Br as httpSecretsBackend, ht as inspectWorkflow, Nn as interruptConnectionStreams, fo as invertChange, Zs as isAggregateDefinition, Bt as isForeignKeyViolation, Ds as isIdleNow, pr as isInfraError, ho as isSafeToApply, Da as isScheduleDefinition, Pi as isWorkflowEventTriggerDefinition, Wo as ivmValue, Tc as lastWriteProvenance, ts as listResourcePolicies, ee as listRetentions, ds as loadResourceTuples, ms as loadSubjectTuples, Ca as localityAwareSelector, bc as makeActionRunner, Ja as makeAdvisoryLockCoordinator, Ur as makeAesCipher, pi as makeApiKeyService, Vt as makeAppAccess, oi as makeAsyncKv, Mr as makeBufferingSpanProcessor, eo as makeCoordinatedScheduler, Sa as makeEffectStoreLayer, Bi as makeEventsFacade, Wr as makeFieldCipher, ra as makeFluentStore, Os as makeIdleGate, ki as makeLazyWorkflowFacade, hc as makeMutationRunner, Di as makePostCommitWorkflowFacade, ws as makeProcessAdapter, yc as makeQueryDescriptorProducer, ks as makeRouterActivity, Gi as makeSchemaRegistry, lo as makeUndoCapture, As as makeWakeGate, Ns as makeWakeProxyServer, Ei as makeWorkflowFacade, Oi as makeWorkflowFacadeWithCallerContext, Ai as makeWorkflowHandlers, ji as makeWorkflowLayers, Si as makeWorkflowRunHandle, Ia as markWakeupFired, Ko as materializeIvm, mi as memoryApiKeyStore, Ta as memoryReplicationAdapter, Kn as memoryRywPositionStore, ja as nextFiring, Ua as nextWakeup, Es as nodeProcessSupervisor, Ws as noopAnalytics, qs as noopAnalyticsSpec, si as noopKv, An as onBindConnectionSubject, zn as parseTraceparent, Wn as powerOfTwoSelector, jc as previewInRollback, Ga as pruneWakeups, rs as rebacPolicyGraph, ln as recordSample, pn as recordSubscriptionActive, dn as recordSubscriptionDelivery, zo as recordTimelineEvent, Mo as redactRow, Jn as redisRywPositionStore, Oo as redoUndoInvocation, Mn as registerConnectionStream, ae as registerRetention, Pa as registerWakeup, za as releaseWakeup, Gn as replicaHealth, Ir as resetSecretsBackend, wa as resolveCurrentRegion, Ht as resolveDependentTables, Jo as resolveRescan, Lr as resolveSecret, Rr as resolveSecretSync, Vr as resolveSecretsBackend, ko as resolveTimelineMode, se as retentionTtlMsFromEnv, Po as reverseEventOverRows, ls as revokedIds, va as runAsSystem, Fs as runOrchestratorTick, ac as runProvidedEffect, bs as runReaction, Is as runSingleNodeOrchestrator, Cs as runWakeLoop, Zn as runWithRoutingContext, Hn as runWithTraceContext, $a as scheduleCoordinated, Kr as setFieldCipher, Fr as setSecretsBackend, ga as setSystemStoreHandle, Ro as setTimelineRecorderForTest, li as sha256Hex, Ka as singleCoordinator, vn as snapshotMetrics, yn as snapshotMetricsSync, vr as startRpcServer, Xa as startScheduler, le as sweepRetention, po as synthesizeInverse, Vi as tracingHttpClientLayer, Mi as triggerWorkflow, Ra as tryClaimWakeup, kn as unbindConnectionSubject, ao as undoCaptureEnabled, To as undoLogExecutor, nc as useAggregate, Hs as useAnalytics, cs as visibleRows, Ss as wakeDueOnce, xi as workflowToRpc, co as wrapCaptureStore, da as wrapStoreWithMixinBehaviour };