@voltro/database 0.76.0 → 0.77.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,13 +1,13 @@
1
- import { $ as e, $n as t, $t as n, A as r, An as i, At as a, B as o, Bn as s, Bt as c, C as l, Cn as u, Cr as d, D as f, Dn as p, Dt as m, E as h, En as g, Et as ee, F as _, Fn as te, Ft as ne, G as re, Gn as ie, Gt as v, H as ae, Hn as oe, Ht as se, I as ce, In as le, It as ue, J as de, Jn as fe, Jt as pe, K as me, Kn as he, Kt as ge, L as _e, Ln as ve, Lt as ye, M as be, Mn as xe, Mt as Se, N as Ce, Nn as we, Nt as Te, O as Ee, On as De, Ot as Oe, P as ke, Pn as Ae, Pt as je, Q as Me, Qn as Ne, Qt as Pe, R as Fe, Rn as Ie, Rt as Le, S as Re, Sn as ze, Sr as y, St as Be, T as Ve, Tn as He, Tt as Ue, U as We, Un as Ge, Ut as Ke, V as qe, Vn as Je, Vt as Ye, W as Xe, Wn as Ze, Wt as Qe, X as $e, Xn as et, Xt as tt, Y as nt, Yn as rt, Yt as it, Z as at, Zn as ot, Zt as st, _ as ct, _n as lt, _r as ut, _t as dt, a as ft, an as pt, ar as mt, at as ht, b as gt, bn as _t, br as vt, bt as yt, c as bt, cn as xt, cr as St, ct as Ct, d as wt, dn as Tt, dr as Et, dt as Dt, en as Ot, er as kt, et as At, f as jt, fn as Mt, fr as Nt, ft as b, g as Pt, gn as x, gr as Ft, gt as It, h as Lt, hn as Rt, hr as zt, ht as Bt, i as Vt, in as Ht, ir as Ut, it as Wt, j as Gt, jn as Kt, jt as qt, k as Jt, kn as Yt, kt as Xt, l as Zt, ln as Qt, lr as S, lt as $t, m as en, mn as tn, mr as nn, mt as rn, n as an, nn as on, nr as sn, nt as cn, o as ln, on as un, or as dn, ot as fn, p as pn, pn as mn, pr as hn, pt as gn, q as _n, qn as vn, qt as yn, r as bn, rn as xn, rr as Sn, rt as Cn, s as wn, sn as Tn, sr as En, st as Dn, t as On, tn as kn, tr as An, tt as jn, u as Mn, un as Nn, ur as Pn, ut as Fn, v as In, vn as Ln, vr as Rn, vt as zn, w as Bn, wn as Vn, wt as Hn, x as Un, xn as Wn, xr as C, xt as Gn, yn as Kn, yr as qn, yt as Jn, z as Yn, zn as Xn, zt as Zn } from "./frameworkTables-CSY95jCs.js";
2
- import { a as Qn, i as $n, n as er, o as tr, r as nr, s as rr, t as ir } from "./wire-B28cPjEp.js";
3
- import { Cause as ar, Chunk as or, Data as sr, Effect as w, Exit as cr, Metric as T, MetricBoundaries as lr, Option as E, Schedule as ur, Schema as D, Stream as dr } from "effect";
4
- import { createHash as fr } from "node:crypto";
5
- import { AsyncLocalStorage as pr } from "node:async_hooks";
6
- import { TransactionConnection as mr } from "@effect/sql/SqlClient";
7
- import { ansi as O } from "@voltro/logger";
8
- import { SqlClient as hr } from "@effect/sql";
1
+ import { $ as e, $n as t, $t as n, A as r, An as i, Ar as a, At as o, B as s, Bn as c, Bt as l, C as u, Cn as d, Cr as f, Ct as p, Dn as m, Dr as h, Dt as g, E as _, En as v, Er as ee, Et as te, F as ne, Fn as re, Ft as ie, G as ae, Gn as oe, Gt as se, H as ce, Hn as y, Ht as le, I as ue, In as de, It as fe, J as pe, Jn as me, Jt as he, K as ge, Kn as _e, Kt as ve, L as ye, Ln as be, Lt as xe, M as Se, Mn as Ce, Mr as b, N as we, Nn as Te, Nr as x, Nt as Ee, O as De, On as Oe, Or as ke, Ot as Ae, P as je, Pn as Me, Pr as Ne, Pt as Pe, Q as Fe, Qn as Ie, Qt as Le, R as Re, Rn as ze, Rt as Be, S as Ve, Sn as He, Sr as Ue, St as We, T as Ge, Tn as S, Tr as Ke, Tt as qe, U as Je, Un as Ye, Ut as Xe, V as Ze, Vn as Qe, Vt as $e, W as et, Wn as tt, Wt as nt, X as rt, Xn as it, Xt as at, Y as ot, Yn as st, Yt as ct, Z as lt, Zn as ut, Zt as dt, _ as ft, _n as pt, _r as mt, _t as ht, a as gt, an as _t, ar as vt, at as yt, b as bt, bn as xt, br as C, bt as St, c as Ct, cn as wt, cr as Tt, ct as Et, d as Dt, dn as Ot, dr as kt, dt as At, en as w, er as jt, et as Mt, f as Nt, fn as Pt, fr as Ft, ft as It, g as Lt, gn as Rt, gr as zt, gt as Bt, h as Vt, hn as Ht, hr as Ut, ht as Wt, i as Gt, in as Kt, ir as qt, it as Jt, j as Yt, jn as Xt, jr as Zt, jt as Qt, k as $t, kn as en, kr as tn, kt as nn, l as rn, ln as an, lr as on, lt as sn, m as cn, mn as ln, mr as un, mt as dn, n as fn, nn as pn, nr as mn, nt as hn, o as gn, on as _n, or as vn, ot as yn, p as bn, pn as xn, pr as Sn, pt as Cn, q as wn, qn as Tn, qt as En, r as Dn, rn as On, rr as kn, rt as An, s as jn, sn as Mn, sr as Nn, st as Pn, t as Fn, tn as In, tr as Ln, tt as Rn, u as zn, un as Bn, ur as Vn, ut as Hn, v as Un, vn as Wn, vr as Gn, vt as Kn, w as qn, wn as Jn, wr as Yn, wt as Xn, x as Zn, xn as Qn, xr as $n, xt as T, y as er, yn as tr, yr as nr, yt as rr, z as ir, zn as ar, zt as or } from "./replaceInProgress-DdjHyYFT.js";
2
+ import { a as sr, i as cr, n as lr, o as ur, r as dr, s as fr, t as pr } from "./wire-B28cPjEp.js";
3
+ import { Cause as mr, Chunk as hr, Data as gr, Effect as E, Exit as _r, Metric as D, MetricBoundaries as vr, Option as O, Schedule as yr, Schema as k, Stream as br } from "effect";
4
+ import { createHash as xr } from "node:crypto";
5
+ import { AsyncLocalStorage as Sr } from "node:async_hooks";
6
+ import { TransactionConnection as Cr } from "@effect/sql/SqlClient";
7
+ import { ansi as A } from "@voltro/logger";
8
+ import { SqlClient as wr } from "@effect/sql";
9
9
  //#region src/actorSnapshot.ts
10
- var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n) => {
10
+ var Tr = (e) => typeof e == "string" && e !== "" ? e : null, Er = async (e, t, n) => {
11
11
  if (t != null && t !== "") try {
12
12
  let r = (await e.query({
13
13
  table: "actors",
@@ -23,20 +23,20 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
23
23
  }))[0];
24
24
  return r === void 0 ? void 0 : {
25
25
  id: t,
26
- type: gr(r.kind) ?? n,
27
- displayName: gr(r.displayName),
28
- email: gr(r.email)
26
+ type: Tr(r.kind) ?? n,
27
+ displayName: Tr(r.displayName),
28
+ email: Tr(r.email)
29
29
  };
30
30
  } catch {
31
31
  return;
32
32
  }
33
- }, vr = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", yr = (e) => {
33
+ }, Dr = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Or = (e) => {
34
34
  let t = [];
35
35
  for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
36
36
  return t;
37
- }, br = (e, t, n) => {
38
- if (!vr(n) || !t) return e;
39
- let r = yr(t);
37
+ }, kr = (e, t, n) => {
38
+ if (!Dr(n) || !t) return e;
39
+ let r = Or(t);
40
40
  if (r.length === 0) return e;
41
41
  let i = { ...e };
42
42
  for (let e of r) {
@@ -44,9 +44,9 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
44
44
  Array.isArray(t) && (i[e] = JSON.stringify(t));
45
45
  }
46
46
  return i;
47
- }, xr = (e, t, n) => {
48
- if (!vr(n) || !t) return e;
49
- let r = yr(t);
47
+ }, Ar = (e, t, n) => {
48
+ if (!Dr(n) || !t) return e;
49
+ let r = Or(t);
50
50
  return r.length === 0 ? e : e.map((e) => {
51
51
  let t;
52
52
  for (let n of r) {
@@ -58,13 +58,13 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
58
58
  }
59
59
  return t ?? e;
60
60
  });
61
- }, Sr = "enc:v1:", Cr = "enc:v2:", wr = (e, t, n) => {
61
+ }, jr = "enc:v1:", Mr = "enc:v2:", Nr = (e, t, n) => {
62
62
  let r = `${e}:${t}`, i = n == null || n === "" ? void 0 : String(n);
63
63
  return i === void 0 ? { column: r } : {
64
64
  column: r,
65
65
  row: `${r}:${i}`
66
66
  };
67
- }, Tr = (e) => typeof e == "string" && e.startsWith("enc:v2:"), Er = class extends Error {
67
+ }, Pr = (e) => typeof e == "string" && e.startsWith("enc:v2:"), Fr = class extends Error {
68
68
  _tag = "FieldDecryptionError";
69
69
  table;
70
70
  column;
@@ -72,7 +72,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
72
72
  constructor(e) {
73
73
  super(`column "${e.table}.${e.column}" is .encrypted() but could not be decrypted (${e.reason}) — the stored value was most likely encrypted under a different key`), this.name = "FieldDecryptionError", this.table = e.table, this.column = e.column, this.reason = e.reason;
74
74
  }
75
- }, Dr = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Or = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), kr = (e, t, n) => e.encrypt(JSON.stringify(t), n), Ar = /* @__PURE__ */ new Set([
75
+ }, Ir = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Lr = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), Rr = (e, t, n) => e.encrypt(JSON.stringify(t), n), zr = /* @__PURE__ */ new Set([
76
76
  "text",
77
77
  "id",
78
78
  "reference",
@@ -80,51 +80,51 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
80
80
  "uuid",
81
81
  "email",
82
82
  "url"
83
- ]), jr = (e, t, n, r) => {
83
+ ]), Br = (e, t, n, r) => {
84
84
  let i = e.decrypt(t, r), a;
85
85
  try {
86
86
  a = JSON.parse(i);
87
87
  } catch {
88
88
  return i;
89
89
  }
90
- return typeof a == "string" ? a : n === void 0 || Ar.has(n) ? i : a;
91
- }, Mr = (e, t, n, r) => {
90
+ return typeof a == "string" ? a : n === void 0 || zr.has(n) ? i : a;
91
+ }, Vr = (e, t, n, r) => {
92
92
  let i = e.decrypt(t, r);
93
93
  try {
94
- return typeof JSON.parse(i) == "string" ? !1 : n === void 0 || Ar.has(n) ? !0 : void 0;
94
+ return typeof JSON.parse(i) == "string" ? !1 : n === void 0 || zr.has(n) ? !0 : void 0;
95
95
  } catch {
96
96
  return !0;
97
97
  }
98
- }, Nr = (e, t) => e.fields[t]?.type, Pr = (e) => {
98
+ }, Hr = (e, t) => e.fields[t]?.type, Ur = (e) => {
99
99
  let t = [];
100
100
  for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
101
101
  return t;
102
- }, Fr = "id", Ir = (e, t, n, r) => {
102
+ }, Wr = "id", Gr = (e, t, n, r) => {
103
103
  if (!t) return e;
104
- let i = Pr(t);
104
+ let i = Ur(t);
105
105
  if (i.length === 0) return e;
106
- let a = t.tableName ?? "?", o = r ?? e[Fr], s = { ...e };
106
+ let a = t.tableName ?? "?", o = r ?? e[Wr], s = { ...e };
107
107
  for (let e of i) {
108
108
  let t = s[e];
109
- if (!(t == null || Or(t))) {
109
+ if (!(t == null || Lr(t))) {
110
110
  if (!n) throw Error(`column "${a}.${e}" is .encrypted() but no field cipher is registered — set VOLTRO_FIELD_ENCRYPTION_KEY (\`voltro dev\` mints one; \`voltro serve\` refuses to boot without it); in a test, pass \`fieldEncryptionKey\` to makeTestContext`);
111
- s[e] = kr(n, t, wr(a, e, o));
111
+ s[e] = Rr(n, t, Nr(a, e, o));
112
112
  }
113
113
  }
114
114
  return s;
115
- }, Lr = (e, t, n, r) => {
115
+ }, Kr = (e, t, n, r) => {
116
116
  if (!t) return e;
117
- let i = Pr(t);
117
+ let i = Ur(t);
118
118
  if (i.length === 0 || !n) return e;
119
119
  let a = r?.onError ?? "throw", o = t.tableName ?? "?";
120
120
  return e.map((e) => {
121
121
  let s;
122
122
  for (let c of i) {
123
123
  let i = e[c];
124
- if (Or(i)) {
124
+ if (Lr(i)) {
125
125
  s ??= { ...e };
126
126
  try {
127
- s[c] = jr(n, i, Nr(t, c), wr(o, c, r?.rowId ?? e[Fr]));
127
+ s[c] = Br(n, i, Hr(t, c), Nr(o, c, r?.rowId ?? e[Wr]));
128
128
  } catch (e) {
129
129
  let t = String(e?.message ?? e);
130
130
  if (a === "null") {
@@ -135,7 +135,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
135
135
  });
136
136
  continue;
137
137
  }
138
- throw new Er({
138
+ throw new Fr({
139
139
  table: o,
140
140
  column: c,
141
141
  reason: t
@@ -145,77 +145,77 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
145
145
  }
146
146
  return s ?? e;
147
147
  });
148
- }, Rr = Symbol.for("@voltro/database/storeRefusal"), zr = (e) => {
149
- let t = Error(e.detail);
150
- return Object.defineProperty(t, Rr, {
148
+ }, qr = Symbol.for("@voltro/database/storeRefusal"), Jr = (e) => {
149
+ let t = y(e.detail);
150
+ return Object.defineProperty(t, qr, {
151
151
  value: e,
152
152
  enumerable: !1
153
153
  }), t;
154
- }, Br = (e) => {
155
- for (let t of we(e)) {
154
+ }, Yr = (e) => {
155
+ for (let t of tt(e)) {
156
156
  let e = t;
157
157
  for (let t = 0; e != null && t < 8; t += 1) {
158
- let t = e[Rr];
158
+ let t = e[qr];
159
159
  if (t !== void 0) return t;
160
160
  e = e.cause;
161
161
  }
162
162
  }
163
- }, Vr = (e) => {
163
+ }, Xr = (e) => {
164
164
  let t = (() => {
165
165
  switch (e.type) {
166
- case "id": return e.idScheme?.kind === "numeric" ? D.Number : D.String;
166
+ case "id": return e.idScheme?.kind === "numeric" ? k.Number : k.String;
167
167
  case "text":
168
- case "enum": return D.String;
169
- case "reference": return e.referenceStorage === "numeric" ? D.Number : D.String;
168
+ case "enum": return k.String;
169
+ case "reference": return e.referenceStorage === "numeric" ? k.Number : k.String;
170
170
  case "integer":
171
171
  case "real":
172
- case "decimal": return D.Number;
173
- case "boolean": return D.Boolean;
172
+ case "decimal": return k.Number;
173
+ case "boolean": return k.Boolean;
174
174
  case "timestamp":
175
- case "date": return ir;
176
- case "bigint": return D.BigInt;
177
- case "bytes": return D.Uint8ArrayFromBase64;
178
- case "array": return D.Array(D.Unknown);
179
- case "interval": return D.String;
180
- default: return D.Unknown;
175
+ case "date": return pr;
176
+ case "bigint": return k.BigInt;
177
+ case "bytes": return k.Uint8ArrayFromBase64;
178
+ case "array": return k.Array(k.Unknown);
179
+ case "interval": return k.String;
180
+ default: return k.Unknown;
181
181
  }
182
182
  })();
183
- return e.nullable === !0 ? D.NullOr(t) : t;
184
- }, Hr = (e, t) => {
183
+ return e.nullable === !0 ? k.NullOr(t) : t;
184
+ }, Zr = (e, t) => {
185
185
  let n = new Set(t?.omit ?? []), r = {};
186
- for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Vr(i));
187
- return D.Struct(r);
188
- }, Ur = (e) => typeof e == "function" ? e : () => e, Wr = (e, t) => ({
186
+ for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Xr(i));
187
+ return k.Struct(r);
188
+ }, Qr = (e) => typeof e == "function" ? e : () => e, $r = (e, t) => ({
189
189
  kind: "one",
190
- target: Ur(e),
190
+ target: Qr(e),
191
191
  ...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
192
192
  ...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
193
- }), Gr = (e, t) => ({
193
+ }), ei = (e, t) => ({
194
194
  kind: "many",
195
- target: Ur(e),
195
+ target: Qr(e),
196
196
  ...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
197
197
  ...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
198
- }), Kr = (e, t) => ({
198
+ }), ti = (e, t) => ({
199
199
  kind: "manyToMany",
200
- target: Ur(e),
201
- through: Ur(t.through),
200
+ target: Qr(e),
201
+ through: Qr(t.through),
202
202
  sourceKey: t.sourceKey,
203
203
  targetKey: t.targetKey
204
- }), qr = {
205
- one: Wr,
206
- many: Gr,
207
- manyToMany: Kr
208
- }, Jr = (e, t) => {
204
+ }), ni = {
205
+ one: $r,
206
+ many: ei,
207
+ manyToMany: ti
208
+ }, ri = (e, t) => {
209
209
  let n = typeof e == "function" ? e : () => e;
210
210
  return {
211
211
  source: n,
212
- relations: t(qr, n())
212
+ relations: t(ni, n())
213
213
  };
214
- }, Yr = (e) => {
214
+ }, ii = (e) => {
215
215
  if (typeof e != "object" || !e) return !1;
216
216
  let t = e;
217
217
  return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
218
- }, Xr = (e) => {
218
+ }, ai = (e) => {
219
219
  if (typeof e != "object" || !e) return !1;
220
220
  let t = e;
221
221
  if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
@@ -224,32 +224,32 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
224
224
  let t = e?.kind;
225
225
  return t === "one" || t === "many" || t === "manyToMany";
226
226
  });
227
- }, Zr = Wr, Qr = Gr, $r = Kr, k = (e, t, n) => {
227
+ }, oi = $r, si = ei, ci = ti, li = (e, t, n) => {
228
228
  let r = [];
229
229
  for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
230
- if (r.length === 0) throw Error(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
231
- if (r.length > 1) throw Error(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
230
+ if (r.length === 0) throw y(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
231
+ if (r.length > 1) throw y(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
232
232
  return r[0];
233
- }, ei = (e) => Object.keys(e.fields), A = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), ti = (e) => {
234
- let t = ei(e);
233
+ }, ui = (e) => Object.keys(e.fields), di = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), fi = (e) => {
234
+ let t = ui(e);
235
235
  return t.length === 0 ? "<none>" : t.join(", ");
236
- }, ni = (e, t, n) => {
236
+ }, pi = (e, t, n) => {
237
237
  let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
238
238
  if (n.kind === "manyToMany") {
239
239
  let t = n.through();
240
- for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!A(t, o)) throw Error(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${ti(t)}.`);
240
+ for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!di(t, o)) throw y(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${fi(t)}.`);
241
241
  return;
242
242
  }
243
- if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw Error(`${r}: pass EITHER sourceKey OR foreignKey, not both. sourceKey '${n.sourceKey}' names a column on the source ('${e.tableName}') holding the target's id; foreignKey '${n.foreignKey}' names a column on the target ('${i.tableName}') holding the source's id. With both, foreignKey is ignored.`);
244
- if (n.sourceKey !== void 0 && !A(e, n.sourceKey)) {
245
- let t = A(i, n.sourceKey);
246
- throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${ti(e)}.`));
243
+ if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw y(`${r}: pass EITHER sourceKey OR foreignKey, not both. sourceKey '${n.sourceKey}' names a column on the source ('${e.tableName}') holding the target's id; foreignKey '${n.foreignKey}' names a column on the target ('${i.tableName}') holding the source's id. With both, foreignKey is ignored.`);
244
+ if (n.sourceKey !== void 0 && !di(e, n.sourceKey)) {
245
+ let t = di(i, n.sourceKey);
246
+ throw y(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${fi(e)}.`));
247
247
  }
248
- if (n.foreignKey !== void 0 && !A(i, n.foreignKey)) {
249
- let t = A(e, n.foreignKey);
250
- throw Error(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${ti(i)}.`));
248
+ if (n.foreignKey !== void 0 && !di(i, n.foreignKey)) {
249
+ let t = di(e, n.foreignKey);
250
+ throw y(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${fi(i)}.`));
251
251
  }
252
- }, ri = Symbol.for("@voltro/database/relationsRegistry"), ii = globalThis, j = ii[ri] ?? (ii[ri] = /* @__PURE__ */ new Map()), ai = (e) => {
252
+ }, mi = Symbol.for("@voltro/database/relationsRegistry"), hi = globalThis, j = hi[mi] ?? (hi[mi] = /* @__PURE__ */ new Map()), gi = (e) => {
253
253
  let t = e.source(), n = j.get(t.tableName);
254
254
  if (n === void 0) {
255
255
  j.set(t.tableName, new Map(Object.entries(e.relations)));
@@ -262,14 +262,14 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
262
262
  n.set(r, i);
263
263
  }
264
264
  }
265
- }, oi = (e) => {
265
+ }, _i = (e) => {
266
266
  let t = 0;
267
- for (let n of Object.values(e)) Xr(n) && (ai(n), t += 1);
267
+ for (let n of Object.values(e)) ai(n) && (gi(n), t += 1);
268
268
  return t;
269
- }, si = (e) => {
269
+ }, vi = (e) => {
270
270
  let t = j.get(e);
271
271
  if (t !== void 0) return Object.fromEntries(t);
272
- }, ci = (e, t) => j.get(e)?.get(t), li = () => {
272
+ }, yi = (e, t) => j.get(e)?.get(t), bi = () => {
273
273
  let e = [];
274
274
  for (let [t, n] of j) for (let [r, i] of n) e.push({
275
275
  source: t,
@@ -277,18 +277,18 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
277
277
  relation: i
278
278
  });
279
279
  return e;
280
- }, ui = () => {
280
+ }, xi = () => {
281
281
  for (let [e, t] of j) {
282
- let n = pt(e);
283
- if (n !== void 0) for (let [e, r] of t) ni(n, e, r);
282
+ let n = ln(e);
283
+ if (n !== void 0) for (let [e, r] of t) pi(n, e, r);
284
284
  }
285
- }, di = () => {
285
+ }, Si = () => {
286
286
  j.clear();
287
- }, fi = 4, pi = (e) => Object.keys(e.fields), mi = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), hi = (e, t) => {
287
+ }, Ci = 4, wi = (e) => Object.keys(e.fields), Ti = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Ei = (e, t) => {
288
288
  let n = [];
289
289
  for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
290
290
  return n;
291
- }, gi = (e, t) => {
291
+ }, Di = (e, t) => {
292
292
  let n = [];
293
293
  for (let r of t) {
294
294
  if (r.source !== e) continue;
@@ -305,7 +305,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
305
305
  } catch {
306
306
  continue;
307
307
  }
308
- if (!mi(e, t.sourceKey)) continue;
308
+ if (!Ti(e, t.sourceKey)) continue;
309
309
  n.push({
310
310
  table: e.tableName,
311
311
  foreignKey: t.sourceKey,
@@ -314,8 +314,8 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
314
314
  continue;
315
315
  }
316
316
  if (t.sourceKey !== void 0) continue;
317
- let a = hi(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
318
- if (o === void 0 || !mi(i, o)) continue;
317
+ let a = Ei(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
318
+ if (o === void 0 || !Ti(i, o)) continue;
319
319
  let s = i.fields[o];
320
320
  n.push({
321
321
  table: i.tableName,
@@ -324,9 +324,9 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
324
324
  });
325
325
  }
326
326
  return n;
327
- }, _i = (e, t) => {
327
+ }, Oi = (e, t) => {
328
328
  let n = [];
329
- for (let r of t) if (r.tableName !== e) for (let t of hi(r, e)) {
329
+ for (let r of t) if (r.tableName !== e) for (let t of Ei(r, e)) {
330
330
  let e = r.fields[t];
331
331
  n.push({
332
332
  table: r.tableName,
@@ -335,8 +335,8 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
335
335
  });
336
336
  }
337
337
  return n;
338
- }, vi = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, yi = (e) => {
339
- let t = e.tables ?? on(), n = e.relations ?? li(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
338
+ }, ki = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Ai = (e) => {
339
+ let t = e.tables ?? Ot(), n = e.relations ?? bi(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
340
340
  if (!a.has(e.subjectTable)) return {
341
341
  subjectTable: e.subjectTable,
342
342
  paths: [],
@@ -351,11 +351,11 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
351
351
  hops: [],
352
352
  depth: 0,
353
353
  via: "relation"
354
- }, c = [s], l = /* @__PURE__ */ new Set([vi(s)]), u = /* @__PURE__ */ new Set(), d = [s];
354
+ }, c = [s], l = /* @__PURE__ */ new Set([ki(s)]), u = /* @__PURE__ */ new Set(), d = [s];
355
355
  for (let e = 1; e <= r; e++) {
356
356
  let r = [];
357
357
  for (let a of d) {
358
- let s = gi(a.table, n), d = _i(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
358
+ let s = Di(a.table, n), d = Oi(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
359
359
  for (let [t, n] of f) {
360
360
  if (i.has(t.table)) {
361
361
  o.push({
@@ -373,7 +373,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
373
373
  hops: [...a.hops, t],
374
374
  depth: e,
375
375
  via: n
376
- }, f = vi(d);
376
+ }, f = ki(d);
377
377
  l.has(f) || (l.add(f), c.push(d), r.push(d));
378
378
  }
379
379
  }
@@ -383,7 +383,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
383
383
  }
384
384
  d = r;
385
385
  }
386
- for (let e of d) (gi(e.table, n).length > 0 || _i(e.table, t).length > 0) && o.push({
386
+ for (let e of d) (Di(e.table, n).length > 0 || Oi(e.table, t).length > 0) && o.push({
387
387
  kind: "depth-truncated",
388
388
  table: e.table,
389
389
  detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
@@ -392,14 +392,14 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
392
392
  for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
393
393
  kind: "unreachable",
394
394
  table: n.tableName,
395
- detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${pi(n).join(", ")}`
395
+ detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${wi(n).join(", ")}`
396
396
  });
397
397
  return {
398
398
  subjectTable: e.subjectTable,
399
399
  paths: c,
400
400
  limitations: o
401
401
  };
402
- }, bi = (e) => {
402
+ }, ji = (e) => {
403
403
  let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
404
404
  for (let n of e.paths) {
405
405
  let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
@@ -407,12 +407,12 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
407
407
  }
408
408
  let n = e.limitations.filter((e) => e.kind === "depth-truncated"), r = e.limitations.filter((e) => e.kind === "unreachable"), i = e.limitations.filter((e) => e.kind === "excluded");
409
409
  return t.push(""), t.push(" WHAT THIS CANNOT SEE — a DSAR is only as complete as this list is short:"), n.length > 0 && t.push(` depth-truncated (${n.length}): ${n.map((e) => e.table).join(", ")}`), i.length > 0 && t.push(` excluded (${i.length}): ${[...new Set(i.map((e) => e.table))].join(", ")}`), t.push(r.length === 0 ? " unreachable: none — every registered table is linked to the subject." : ` unreachable (${r.length}): ${r.map((e) => e.table).join(", ")}`), t.push(" Always outside this graph: object storage / uploaded files, external processors,"), t.push(" log and metric sinks, backups, and any subject id embedded in JSON or free text."), t.join("\n");
410
- }, xi = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
410
+ }, Mi = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
411
411
  if (n === void 0) return !1;
412
- if (t === "id" || e.conflictColumns.includes(t)) throw Error(`upsert: updateValues cannot rewrite row identity column '${t}'`);
412
+ if (t === "id" || e.conflictColumns.includes(t)) throw y(`upsert: updateValues cannot rewrite row identity column '${t}'`);
413
413
  return !0;
414
- })), Si = (e, t, n) => {
415
- let r = xi(n);
414
+ })), Ni = (e, t, n) => {
415
+ let r = Mi(n);
416
416
  if (typeof n.update == "function") return {
417
417
  ...n.update(t),
418
418
  ...r
@@ -422,21 +422,21 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
422
422
  ...Object.fromEntries(i.filter((t) => t in e).map((t) => [t, e[t]])),
423
423
  ...r
424
424
  };
425
- }, Ci = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), wi = (e) => {
425
+ }, Pi = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), Fi = (e) => {
426
426
  if (typeof e == "string") return e;
427
427
  let t = Object.entries(e);
428
428
  return t.length === 1 ? String(t[0][1]) : t.slice().sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${e}=${String(t)}`).join("\0");
429
- }, Ti = (e) => typeof e != "string", Ei = (e, t, n) => {
430
- let r = new Set(Ci(e).map(([e]) => e)), i = t.split(".")[0];
429
+ }, Ii = (e) => typeof e != "string", Li = (e, t, n) => {
430
+ let r = new Set(Pi(e).map(([e]) => e)), i = t.split(".")[0];
431
431
  return Object.fromEntries(Object.entries(n ?? {}).filter(([e, t]) => {
432
432
  if (t === void 0) return !1;
433
- if (r.has(e) || e === i) throw Error(`patchJson: additionalPatch cannot rewrite the primary key or patched JSON column '${e}'`);
433
+ if (r.has(e) || e === i) throw y(`patchJson: additionalPatch cannot rewrite the primary key or patched JSON column '${e}'`);
434
434
  return !0;
435
435
  }));
436
- }, Di = (e) => typeof e == "object" && !!e && !Array.isArray(e), Oi = (e) => JSON.parse(JSON.stringify(e ?? null)), ki = (e, t, n) => {
437
- let [r, ...i] = t.split("."), a = Oi(n), o = e[r], s = (e, t) => {
436
+ }, Ri = (e) => typeof e == "object" && !!e && !Array.isArray(e), zi = (e) => JSON.parse(JSON.stringify(e ?? null)), Bi = (e, t, n) => {
437
+ let [r, ...i] = t.split("."), a = zi(n), o = e[r], s = (e, t) => {
438
438
  if (t === i.length) return a;
439
- let n = Di(e) ? e : {}, r = i[t], o = Object.hasOwn(n, r) ? n[r] : void 0;
439
+ let n = Ri(e) ? e : {}, r = i[t], o = Object.hasOwn(n, r) ? n[r] : void 0;
440
440
  return {
441
441
  ...n,
442
442
  [r]: s(o, t + 1)
@@ -444,14 +444,14 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
444
444
  };
445
445
  return {
446
446
  ...e,
447
- [r]: i.length === 0 ? Di(o) && Di(a) ? {
447
+ [r]: i.length === 0 ? Ri(o) && Ri(a) ? {
448
448
  ...o,
449
449
  ...a
450
450
  } : a : s(o, 0)
451
451
  };
452
- }, Ai = (e, t, n, r, i) => {
453
- let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = Oi(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
454
- if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && Di(c) && Object.keys(c).some(l))) {
452
+ }, Vi = (e, t, n, r, i) => {
453
+ let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = zi(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
454
+ if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && Ri(c) && Object.keys(c).some(l))) {
455
455
  let t = 0, n = (t) => e`CASE WHEN (SELECT _voltro_json_escape_probe.key FROM json_each(${String.raw`{"\u0061":0}`}) AS _voltro_json_escape_probe) = ${String.raw`\u0061`}
456
456
  THEN json_extract('"' || replace(${t}.key, '"', ${String.raw`\"`}) || '"', '$')
457
457
  ELSE ${t}.key END`, r = (r) => {
@@ -487,75 +487,75 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
487
487
  }, g = (n) => {
488
488
  let r = JSON.stringify(n);
489
489
  return t === "postgres" ? e`${r}::jsonb` : e`${r}`;
490
- }, ee = (n, r, i, a) => {
490
+ }, _ = (n, r, i, a) => {
491
491
  if (t === "postgres") return e`jsonb_set(${n}, ${d(r)}, ${i}, true)`;
492
492
  let o = u(r);
493
493
  return t === "mysql" || t === "mariadb" ? e`JSON_SET(${n}, ${o}, JSON_EXTRACT(${i}, '$'))` : t === "mssql" ? a === null ? e`JSON_MODIFY(JSON_MODIFY(${n}, ${o}, 0), ${`strict ${o}`}, NULL)` : typeof a == "boolean" ? e`JSON_MODIFY(${n}, ${o}, CAST(${+!!a} AS bit))` : typeof a == "string" || typeof a == "number" ? e`JSON_MODIFY(${n}, ${o}, ${a})` : e`JSON_MODIFY(${n}, ${o}, JSON_QUERY(${i}))` : e`json_set(${n}, ${o}, json(${i}))`;
494
- }, _;
494
+ }, v;
495
495
  if (o.length === 0) {
496
- if (!Di(c)) _ = g(c);
496
+ if (!Ri(c)) v = g(c);
497
497
  else {
498
- _ = h([]);
499
- for (let [e, t] of Object.entries(c)) _ = ee(_, [e], g(t), t);
498
+ v = h([]);
499
+ for (let [e, t] of Object.entries(c)) v = _(v, [e], g(t), t);
500
500
  }
501
501
  } else {
502
- _ = h([]);
502
+ v = h([]);
503
503
  for (let e = 1; e < o.length; e++) {
504
504
  let t = o.slice(0, e);
505
- _ = ee(_, t, h(t));
505
+ v = _(v, t, h(t));
506
506
  }
507
- _ = ee(_, o, g(c), c);
507
+ v = _(v, o, g(c), c);
508
508
  }
509
- return e`${e(a)} = ${_}`;
510
- }, ji = class extends Error {
509
+ return e`${e(a)} = ${v}`;
510
+ }, Hi = class extends Error {
511
511
  _tag = "EagerCardinalityError";
512
512
  constructor(e) {
513
513
  super(e), this.name = "EagerCardinalityError";
514
514
  }
515
- }, Mi = (e) => {
515
+ }, Ui = (e) => {
516
516
  let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
517
517
  return `relation '${t}' on '${n}' is declared \`one\`, but ${r}.${i} matches MORE than one row for the same ${n}.${a} — so there is no single related row to return.` + (o ? ` Because this relation is self-referential, check which side the key is on: \`foreignKey: '${i}'\` means "rows whose ${i} points AT me" (my children — there can be many). If you meant "the row my ${i} points to" (my parent), that is \`sourceKey: '${i}'\`.` : " Use `many(...)` if several are expected, or narrow the key.");
518
- }, Ni = async (e, t, n, r) => {
518
+ }, Wi = async (e, t, n, r) => {
519
519
  if (e.length === 0) return e;
520
- let i = si(n.tableName);
521
- if (i === void 0) throw Error(`cannot eager-load on '${n.tableName}': no relations registered. Did you forget to declare \`relations(${n.tableName}, ...)\` or import the file that does?`);
520
+ let i = vi(n.tableName);
521
+ if (i === void 0) throw y(`cannot eager-load on '${n.tableName}': no relations registered. Did you forget to declare \`relations(${n.tableName}, ...)\` or import the file that does?`);
522
522
  let a = e.map((e) => ({ ...e }));
523
523
  for (let [e, o] of Object.entries(t)) {
524
524
  let t = i[e];
525
525
  if (t === void 0) {
526
526
  let t = Object.keys(i).join(", ") || "<none>";
527
- throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
527
+ throw y(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
528
528
  }
529
- ni(n, e, t), await Pi(a, e, t, o === !0 ? {} : o, n, r);
529
+ pi(n, e, t), await Gi(a, e, t, o === !0 ? {} : o, n, r);
530
530
  }
531
531
  return a;
532
- }, Pi = async (e, t, n, r, i, a) => {
532
+ }, Gi = async (e, t, n, r, i, a) => {
533
533
  switch (n.kind) {
534
534
  case "one":
535
- await Fi(e, t, n, r, i, a);
535
+ await Ki(e, t, n, r, i, a);
536
536
  return;
537
537
  case "many":
538
- await Ii(e, t, n, r, i, a);
538
+ await qi(e, t, n, r, i, a);
539
539
  return;
540
540
  case "manyToMany":
541
- await Ri(e, t, n, r, i, a);
541
+ await Yi(e, t, n, r, i, a);
542
542
  return;
543
543
  }
544
- }, Fi = async (e, t, n, r, i, a) => {
545
- let o = n.target(), s = n.sourceKey ?? zi(i, o.tableName);
544
+ }, Ki = async (e, t, n, r, i, a) => {
545
+ let o = n.target(), s = n.sourceKey ?? Xi(i, o.tableName);
546
546
  if (s !== void 0) {
547
- let n = Bi(e, s), i = n.length === 0 ? [] : await Vi(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
547
+ let n = M(e, s), i = n.length === 0 ? [] : await Zi(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
548
548
  for (let n of e) {
549
549
  let e = n[s];
550
550
  n[t] = e == null ? null : c.get(e) ?? null;
551
551
  }
552
- await Hi(i, r.with, o, a);
552
+ await Qi(i, r.with, o, a);
553
553
  return;
554
554
  }
555
- let c = n.foreignKey ?? k(o, i.tableName, t), l = n.sourceKey ?? "id", u = Bi(e, l), d = u.length === 0 ? [] : await Vi(o, c, u, r, a), f = /* @__PURE__ */ new Map();
555
+ let c = n.foreignKey ?? li(o, i.tableName, t), l = n.sourceKey ?? "id", u = M(e, l), d = u.length === 0 ? [] : await Zi(o, c, u, r, a), f = /* @__PURE__ */ new Map();
556
556
  for (let e of d) {
557
557
  let n = e[c];
558
- if (f.has(n)) throw new ji(Mi({
558
+ if (f.has(n)) throw new Hi(Ui({
559
559
  relationName: t,
560
560
  sourceTableName: i.tableName,
561
561
  targetTableName: o.tableName,
@@ -568,9 +568,9 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
568
568
  let e = n[l];
569
569
  n[t] = e == null ? null : f.get(e) ?? null;
570
570
  }
571
- await Hi(d, r.with, o, a);
572
- }, Ii = async (e, t, n, r, i, a) => {
573
- let o = n.target(), s = n.foreignKey ?? k(o, i.tableName, t), c = n.sourceKey ?? "id", l = Bi(e, c), u = Li(r), d = l.length === 0 ? [] : await Vi(o, s, l, u, a), f = /* @__PURE__ */ new Map();
571
+ await Qi(d, r.with, o, a);
572
+ }, qi = async (e, t, n, r, i, a) => {
573
+ let o = n.target(), s = n.foreignKey ?? li(o, i.tableName, t), c = n.sourceKey ?? "id", l = M(e, c), u = Ji(r), d = l.length === 0 ? [] : await Zi(o, s, l, u, a), f = /* @__PURE__ */ new Map();
574
574
  for (let e of d) {
575
575
  let t = e[s], n = f.get(t);
576
576
  n ? n.push(e) : f.set(t, [e]);
@@ -586,12 +586,12 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
586
586
  let e = n[c];
587
587
  n[t] = f.get(e) ?? [];
588
588
  }
589
- await Hi(d, r.with, o, a);
590
- }, Li = (e) => {
589
+ await Qi(d, r.with, o, a);
590
+ }, Ji = (e) => {
591
591
  let { limit: t, offset: n, ...r } = e;
592
592
  return r;
593
- }, Ri = async (e, t, n, r, i, a) => {
594
- let o = n.target(), s = n.through(), c = Bi(e, "id");
593
+ }, Yi = async (e, t, n, r, i, a) => {
594
+ let o = n.target(), s = n.through(), c = M(e, "id");
595
595
  if (c.length === 0) {
596
596
  for (let n of e) n[t] = [];
597
597
  return;
@@ -612,8 +612,8 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
612
612
  for (let n of e) n[t] = [];
613
613
  return;
614
614
  }
615
- let f = await Vi(o, "id", Bi(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
616
- await Hi(f, r.with, o, a);
615
+ let f = await Zi(o, "id", M(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
616
+ await Qi(f, r.with, o, a);
617
617
  let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
618
618
  for (let e of d) {
619
619
  let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
@@ -625,16 +625,16 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
625
625
  o ? o.push(a) : h.set(t, [a]);
626
626
  }
627
627
  for (let n of e) n[t] = h.get(n.id) ?? [];
628
- }, zi = (e, t) => {
628
+ }, Xi = (e, t) => {
629
629
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
630
- }, Bi = (e, t) => {
630
+ }, M = (e, t) => {
631
631
  let n = /* @__PURE__ */ new Set();
632
632
  for (let r of e) {
633
633
  let e = r[t];
634
634
  e != null && n.add(e);
635
635
  }
636
636
  return [...n];
637
- }, Vi = (e, t, n, r, i) => {
637
+ }, Zi = (e, t, n, r, i) => {
638
638
  let a = {
639
639
  column: t,
640
640
  op: "in",
@@ -648,34 +648,34 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
648
648
  skip: r.offset,
649
649
  projection: void 0
650
650
  });
651
- }, Hi = async (e, t, n, r) => {
652
- t !== void 0 && e.length !== 0 && (await Ni(e, t, n, r)).forEach((t, n) => {
651
+ }, Qi = async (e, t, n, r) => {
652
+ t !== void 0 && e.length !== 0 && (await Wi(e, t, n, r)).forEach((t, n) => {
653
653
  let r = e[n];
654
654
  for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
655
655
  });
656
- }, Ui = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, Wi = (e, t, n) => {
656
+ }, $i = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, ea = (e, t, n) => {
657
657
  if (e.eager === void 0) return null;
658
- let r = Ki(e.table, e.eager, e.sourceTable);
658
+ let r = na(e.table, e.eager, e.sourceTable);
659
659
  if (r === null) return null;
660
- let i = $i(n, e, r, Qi(t, n));
660
+ let i = la(n, e, r, ca(t, n));
661
661
  return i === null ? null : {
662
662
  fragment: i,
663
- decode: na(r, n)
663
+ decode: fa(r, n)
664
664
  };
665
- }, M = (e) => e.relation.kind === "one" && e.fkSide === "target", Gi = (e) => ({
665
+ }, N = (e) => e.relation.kind === "one" && e.fkSide === "target", ta = (e) => ({
666
666
  ...e,
667
667
  branch: {
668
668
  ...e.branch,
669
669
  limit: 2
670
670
  }
671
- }), Ki = (e, t, n) => {
672
- let r = n ?? xt(e), i = si(e);
671
+ }), na = (e, t, n) => {
672
+ let r = n ?? pt(e), i = vi(e);
673
673
  if (i === void 0) return null;
674
674
  let a = [];
675
675
  for (let [e, n] of Object.entries(t)) {
676
676
  let t = i[e];
677
677
  if (t === void 0) return null;
678
- let o = qi(e, t, r, n === !0 ? {} : n);
678
+ let o = ra(e, t, r, n === !0 ? {} : n);
679
679
  if (o === null) return null;
680
680
  a.push(o);
681
681
  }
@@ -683,30 +683,30 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
683
683
  table: r,
684
684
  children: a
685
685
  };
686
- }, qi = (e, t, n, r) => {
686
+ }, ra = (e, t, n, r) => {
687
687
  let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
688
688
  if (t.kind === "manyToMany") o = t.targetKey, s = "target";
689
689
  else if (t.kind === "one") {
690
- let r = t.sourceKey ?? Zi(n, i.tableName);
690
+ let r = t.sourceKey ?? sa(n, i.tableName);
691
691
  if (r !== void 0) o = r, s = "source";
692
692
  else try {
693
- o = t.foreignKey ?? k(i, n.tableName, e), s = "target";
693
+ o = t.foreignKey ?? li(i, n.tableName, e), s = "target";
694
694
  } catch {
695
695
  return null;
696
696
  }
697
697
  } else try {
698
- o = t.foreignKey ?? k(i, n.tableName, e), s = "target";
698
+ o = t.foreignKey ?? li(i, n.tableName, e), s = "target";
699
699
  } catch {
700
700
  return null;
701
701
  }
702
702
  let c = r.with === void 0 ? [] : (() => {
703
- let e = si(i.tableName);
703
+ let e = vi(i.tableName);
704
704
  if (e === void 0 && Object.keys(r.with).length > 0) return null;
705
705
  let t = [];
706
706
  for (let [n, a] of Object.entries(r.with)) {
707
707
  let r = e?.[n];
708
708
  if (r === void 0) return null;
709
- let o = qi(n, r, i, a === !0 ? {} : a);
709
+ let o = ra(n, r, i, a === !0 ? {} : a);
710
710
  if (o === null) return null;
711
711
  t.push(o);
712
712
  }
@@ -722,9 +722,9 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
722
722
  fkSide: s,
723
723
  branch: r,
724
724
  children: c,
725
- junction: Ji(t, r)
725
+ junction: ia(t, r)
726
726
  };
727
- }, Ji = (e, t) => {
727
+ }, ia = (e, t) => {
728
728
  if (e.kind !== "manyToMany" || t.junction === void 0) return;
729
729
  let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
730
730
  return {
@@ -736,35 +736,35 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
736
736
  return t !== void 0 && (t.type === "timestamp" || t.type === "date");
737
737
  })
738
738
  };
739
- }, Yi = (e) => `__j_${e}`, Xi = "__j", Zi = (e, t) => {
739
+ }, aa = (e) => `__j_${e}`, oa = "__j", sa = (e, t) => {
740
740
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
741
- }, Qi = (e, t) => {
741
+ }, ca = (e, t) => {
742
742
  let n = 0;
743
743
  return {
744
744
  sql: e,
745
745
  dialect: t,
746
746
  nextAlias: () => `__a${n++}`
747
747
  };
748
- }, $i = (e, t, n, r) => {
748
+ }, la = (e, t, n, r) => {
749
749
  switch (e) {
750
- case "postgres": return aa(t, n, r);
750
+ case "postgres": return ha(t, n, r);
751
751
  case "sqlite":
752
- case "turso": return pa(t, n, r);
752
+ case "turso": return Ca(t, n, r);
753
753
  case "mysql":
754
- case "mariadb": return Ca(t, n, r);
755
- case "mssql": return Aa(t, n, r);
754
+ case "mariadb": return Na(t, n, r);
755
+ case "mssql": return Ba(t, n, r);
756
756
  }
757
- }, ea = (e, t) => t === "mssql" && !ta.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), ta = /(?:Z|[+-]\d{2}:?\d{2})$/, na = (e, t) => {
758
- let n = ra(e.table, e.children, t);
757
+ }, ua = (e, t) => t === "mssql" && !da.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), da = /(?:Z|[+-]\d{2}:?\d{2})$/, fa = (e, t) => {
758
+ let n = pa(e.table, e.children, t);
759
759
  return (e) => e.map((e) => {
760
760
  let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
761
761
  return n(r);
762
762
  });
763
- }, ra = (e, t, n) => {
763
+ }, pa = (e, t, n) => {
764
764
  let r = [], i = [];
765
765
  for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t), n.type === "vector" && i.push(t);
766
766
  let a = t.map((e) => {
767
- let t = ra(e.target, e.children, n), r = e.relation.kind === "one", i = M(e), a = i ? Mi({
767
+ let t = pa(e.target, e.children, n), r = e.relation.kind === "one", i = N(e), a = i ? Ui({
768
768
  relationName: e.relationName,
769
769
  sourceTableName: e.source.tableName,
770
770
  targetTableName: e.target.tableName,
@@ -777,15 +777,15 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
777
777
  isSingle: r,
778
778
  fromOverFetch: i,
779
779
  cardinalityMessage: a,
780
- junction: ia(e.junction, n)
780
+ junction: ma(e.junction, n)
781
781
  };
782
782
  });
783
783
  return (e) => {
784
784
  let t = { ...e };
785
- for (let e of i) e in t && (t[e] = Hn(t[e], "vector", n));
785
+ for (let e of i) e in t && (t[e] = Ee(t[e], "vector", n));
786
786
  for (let e of r) {
787
787
  let r = t[e];
788
- typeof r == "string" && (t[e] = ea(r, n));
788
+ typeof r == "string" && (t[e] = ua(r, n));
789
789
  }
790
790
  for (let e of a) {
791
791
  let n = t[e.name];
@@ -795,7 +795,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
795
795
  }
796
796
  if (e.fromOverFetch) {
797
797
  let r = n;
798
- if (r.length > 1) throw new ji(e.cardinalityMessage);
798
+ if (r.length > 1) throw new Hi(e.cardinalityMessage);
799
799
  t[e.name] = r.length === 0 ? null : e.decode(r[0]);
800
800
  continue;
801
801
  }
@@ -807,204 +807,204 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
807
807
  }
808
808
  return t;
809
809
  };
810
- }, ia = (e, t) => {
810
+ }, ma = (e, t) => {
811
811
  if (e === void 0) return;
812
812
  let n = new Set(e.dateColumns), r = e.requested;
813
813
  return (e) => {
814
814
  let i = e._junction ?? {}, a = {};
815
815
  for (let e of r) {
816
816
  let r = i[e];
817
- a[e] = n.has(e) && typeof r == "string" ? ea(r, t) : r;
817
+ a[e] = n.has(e) && typeof r == "string" ? ua(r, t) : r;
818
818
  }
819
819
  return {
820
820
  ...e,
821
821
  _junction: a
822
822
  };
823
823
  };
824
- }, aa = (e, t, n) => {
825
- let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = oa(i, t.children, n);
826
- return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${R(e.predicate, i, r)}` : r``}${v(e).length > 0 ? r` ORDER BY ${r.csv(v(e).map((e) => e.direction === "desc" ? r`${F(i, e.column, r)} DESC` : r`${F(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${L(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${L(e.skip, r)}`}`;
827
- }, oa = (e, t, n, r) => {
828
- let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${I(Xi, i)}::text)`;
824
+ }, ha = (e, t, n) => {
825
+ let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = ga(i, t.children, n);
826
+ return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``}${w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${R(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${R(e.skip, r)}`}`;
827
+ }, ga = (e, t, n, r) => {
828
+ let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${L(oa, i)}::text)`;
829
829
  if (t.length === 0 && r === void 0) return a;
830
830
  let o = [];
831
- r !== void 0 && o.push(i`${I("_junction", i)}, ${F(e, Xi, i)}`);
831
+ r !== void 0 && o.push(i`${L("_junction", i)}, ${I(e, oa, i)}`);
832
832
  for (let r of t) {
833
- let t = sa(r, e, n);
833
+ let t = _a(r, e, n);
834
834
  if (t === null) return null;
835
- o.push(i`${I(r.relationName, i)}, ${t}`);
835
+ o.push(i`${L(r.relationName, i)}, ${t}`);
836
836
  }
837
837
  return i`${a} || jsonb_build_object(${i.csv(o)})`;
838
- }, sa = (e, t, n) => {
838
+ }, _a = (e, t, n) => {
839
839
  switch (e.relation.kind) {
840
- case "one": return M(e) ? la(Gi(e), t, n) : ca(e, t, n);
841
- case "many": return la(e, t, n);
842
- case "manyToMany": return ua(e, t, n);
840
+ case "one": return N(e) ? ya(ta(e), t, n) : va(e, t, n);
841
+ case "many": return ya(e, t, n);
842
+ case "manyToMany": return ba(e, t, n);
843
843
  }
844
- }, ca = (e, t, n) => {
845
- let r = n.sql, i = n.nextAlias(), a = oa(i, e.children, n);
844
+ }, va = (e, t, n) => {
845
+ let r = n.sql, i = n.nextAlias(), a = ga(i, e.children, n);
846
846
  if (a === null) return null;
847
- let o = e.fkSide === "source" ? r`${F(i, "id", r)} = ${F(t, e.foreignKey, r)}` : r`${F(i, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${R(e.branch.where, i, r)}`, c = N(i, e.branch.orderBy, r);
847
+ let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${z(e.branch.where, i, r)}`, c = P(i, e.branch.orderBy, r);
848
848
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
849
- }, la = (e, t, n) => {
850
- let r = n.sql, i = n.nextAlias(), a = oa(i, e.children, n);
849
+ }, ya = (e, t, n) => {
850
+ let r = n.sql, i = n.nextAlias(), a = ga(i, e.children, n);
851
851
  if (a === null) return null;
852
- let o = r`${F(void 0, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${b(e.branch.where, r)}`, c = fa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${L(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${L(e.branch.offset, r)}`;
852
+ let o = r`${I(void 0, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(e.branch.where, r)}`, c = Sa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`;
853
853
  return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
854
- }, ua = (e, t, n) => {
855
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = oa(o, e.children, n, e.junction);
854
+ }, ba = (e, t, n) => {
855
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ga(o, e.children, n, e.junction);
856
856
  if (c === null) return null;
857
- let l = e.branch.where === void 0 ? r`` : r` AND ${b(e.branch.where, r)}`, u = z(e, s, r), d = N(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${L(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${L(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${da(e.junction, s, r)} AS ${r(Xi)}`;
858
- return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${F(o, "id", r)} = ${F(s, i.targetKey, r)} WHERE ${F(s, i.sourceKey, r)} = ${F(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
859
- }, da = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${I(e, n)}, ${F(t, e, n)}`))})`, N = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${F(e, t.column, n)} DESC` : n`${F(e, t.column, n)} ASC`))}`, fa = (e, t) => e === void 0 || e.length === 0 ? t`` : t` ORDER BY ${t.csv(e.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`, pa = (e, t, n) => {
860
- let r = n.sql, i = n.nextAlias(), a = ma(i, t.table, t.children, n);
857
+ let l = e.branch.where === void 0 ? r`` : r` AND ${T(e.branch.where, r)}`, u = B(e, s, r), d = P(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${xa(e.junction, s, r)} AS ${r(oa)}`;
858
+ return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
859
+ }, xa = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${L(e, n)}, ${I(t, e, n)}`))})`, P = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${I(e, t.column, n)} DESC` : n`${I(e, t.column, n)} ASC`))}`, Sa = (e, t) => e === void 0 || e.length === 0 ? t`` : t` ORDER BY ${t.csv(e.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`, Ca = (e, t, n) => {
860
+ let r = n.sql, i = n.nextAlias(), a = wa(i, t.table, t.children, n);
861
861
  if (a === null) return null;
862
- let o = e.predicate ? r` WHERE ${R(e.predicate, i, r)}` : r``, s = v(e).length > 0 ? r` ORDER BY ${r.csv(v(e).map((e) => e.direction === "desc" ? r`${F(i, e.column, r)} DESC` : r`${F(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${L(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${L(e.skip, r)}`;
862
+ let o = e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${R(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${R(e.skip, r)}`;
863
863
  return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
864
- }, ma = (e, t, n, r, i) => {
864
+ }, wa = (e, t, n, r, i) => {
865
865
  let a = r.sql, o = [];
866
- for (let n of Object.keys(t.fields)) o.push(a`${I(n, a)}, ${F(e, n, a)}`);
866
+ for (let n of Object.keys(t.fields)) o.push(a`${L(n, a)}, ${I(e, n, a)}`);
867
867
  if (i !== void 0) {
868
- let e = ha(i.projection, i.source, a);
869
- o.push(a`${I("_junction", a)}, json_object(${e})`);
868
+ let e = Ta(i.projection, i.source, a);
869
+ o.push(a`${L("_junction", a)}, json_object(${e})`);
870
870
  }
871
871
  for (let t of n) {
872
- let n = ya(t, e, r);
872
+ let n = ka(t, e, r);
873
873
  if (n === null) return null;
874
- o.push(a`${I(t.relationName, a)}, ${n}`);
874
+ o.push(a`${L(t.relationName, a)}, ${n}`);
875
875
  }
876
876
  return a`json_object(${a.csv(o)})`;
877
- }, ha = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${I(e, n)}, ${F(t.alias, t.physical(e), n)}`)), ga = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${F(t, e, n)} AS ${n(Yi(e))}`))}`, _a = (e) => ({
877
+ }, Ta = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${L(e, n)}, ${I(t.alias, t.physical(e), n)}`)), Ea = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${I(t, e, n)} AS ${n(aa(e))}`))}`, Da = (e) => ({
878
878
  alias: e,
879
- physical: Yi
880
- }), va = (e) => ({
879
+ physical: aa
880
+ }), Oa = (e) => ({
881
881
  alias: e,
882
882
  physical: (e) => e
883
- }), ya = (e, t, n) => {
883
+ }), ka = (e, t, n) => {
884
884
  switch (e.relation.kind) {
885
- case "one": return M(e) ? xa(Gi(e), t, n) : ba(e, t, n);
886
- case "many": return xa(e, t, n);
887
- case "manyToMany": return Sa(e, t, n);
885
+ case "one": return N(e) ? ja(ta(e), t, n) : Aa(e, t, n);
886
+ case "many": return ja(e, t, n);
887
+ case "manyToMany": return Ma(e, t, n);
888
888
  }
889
- }, ba = (e, t, n) => {
890
- let r = n.sql, i = n.nextAlias(), a = ma(i, e.target, e.children, n);
889
+ }, Aa = (e, t, n) => {
890
+ let r = n.sql, i = n.nextAlias(), a = wa(i, e.target, e.children, n);
891
891
  if (a === null) return null;
892
- let o = e.fkSide === "source" ? r`${F(i, "id", r)} = ${F(t, e.foreignKey, r)}` : r`${F(i, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`;
892
+ let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`;
893
893
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
894
- }, xa = (e, t, n) => {
895
- let r = n.sql, i = n.nextAlias(), a = ma(i, e.target, e.children, n);
894
+ }, ja = (e, t, n) => {
895
+ let r = n.sql, i = n.nextAlias(), a = wa(i, e.target, e.children, n);
896
896
  if (a === null) return null;
897
- let o = r`${F(void 0, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${b(B(e.branch.where), r)}`, c = fa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${L(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${L(e.branch.offset, r)}`;
897
+ let o = r`${I(void 0, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, c = Sa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`;
898
898
  return r`COALESCE((SELECT json_group_array(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), json('[]'))`;
899
- }, Sa = (e, t, n) => {
900
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ma(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
899
+ }, Ma = (e, t, n) => {
900
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = wa(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
901
901
  projection: e.junction,
902
- source: _a(o)
902
+ source: Da(o)
903
903
  });
904
904
  if (c === null) return null;
905
- let l = e.branch.where === void 0 ? r`` : r` AND ${b(B(e.branch.where), r)}`, u = z(e, s, r, !0), d = N(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${L(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${L(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : ga(e.junction, s, r);
906
- return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${F(o, "id", r)} = ${F(s, i.targetKey, r)} WHERE ${F(s, i.sourceKey, r)} = ${F(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
907
- }, Ca = (e, t, n) => {
908
- let r = n.sql, i = n.nextAlias(), a = P(i, t.table, t.children, n);
905
+ let l = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, u = B(e, s, r, !0), d = P(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Ea(e.junction, s, r);
906
+ return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
907
+ }, Na = (e, t, n) => {
908
+ let r = n.sql, i = n.nextAlias(), a = F(i, t.table, t.children, n);
909
909
  if (a === null) return null;
910
- let o = e.predicate ? r` WHERE ${R(e.predicate, i, r)}` : r``, s = v(e).length > 0 ? r` ORDER BY ${r.csv(v(e).map((e) => e.direction === "desc" ? r`${F(i, e.column, r)} DESC` : r`${F(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${L(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${L(e.skip, r)}`;
910
+ let o = e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${R(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${R(e.skip, r)}`;
911
911
  return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
912
- }, P = (e, t, n, r, i) => {
912
+ }, F = (e, t, n, r, i) => {
913
913
  let a = r.sql, o = [];
914
- for (let n of Object.keys(t.fields)) o.push(a`${I(n, a)}, ${F(e, n, a)}`);
914
+ for (let n of Object.keys(t.fields)) o.push(a`${L(n, a)}, ${I(e, n, a)}`);
915
915
  if (i !== void 0) {
916
- let e = ha(i.projection, i.source, a);
917
- o.push(a`${I("_junction", a)}, JSON_OBJECT(${e})`);
916
+ let e = Ta(i.projection, i.source, a);
917
+ o.push(a`${L("_junction", a)}, JSON_OBJECT(${e})`);
918
918
  }
919
919
  for (let t of n) {
920
- let n = wa(t, e, r);
920
+ let n = Pa(t, e, r);
921
921
  if (n === null) return null;
922
- o.push(a`${I(t.relationName, a)}, ${n}`);
922
+ o.push(a`${L(t.relationName, a)}, ${n}`);
923
923
  }
924
924
  return a`JSON_OBJECT(${a.csv(o)})`;
925
- }, wa = (e, t, n) => {
925
+ }, Pa = (e, t, n) => {
926
926
  switch (e.relation.kind) {
927
927
  case "one":
928
- if (M(e)) {
929
- let r = Gi(e);
930
- return n.dialect === "mariadb" ? Oa(r, t, n) : Ea(r, t, n);
928
+ if (N(e)) {
929
+ let r = ta(e);
930
+ return n.dialect === "mariadb" ? Ra(r, t, n) : Ia(r, t, n);
931
931
  }
932
- return Ta(e, t, n);
933
- case "many": return n.dialect === "mariadb" ? Oa(e, t, n) : Ea(e, t, n);
934
- case "manyToMany": return n.dialect === "mariadb" ? ka(e, t, n) : Da(e, t, n);
932
+ return Fa(e, t, n);
933
+ case "many": return n.dialect === "mariadb" ? Ra(e, t, n) : Ia(e, t, n);
934
+ case "manyToMany": return n.dialect === "mariadb" ? za(e, t, n) : La(e, t, n);
935
935
  }
936
- }, Ta = (e, t, n) => {
937
- let r = n.sql, i = n.nextAlias(), a = P(i, e.target, e.children, n);
936
+ }, Fa = (e, t, n) => {
937
+ let r = n.sql, i = n.nextAlias(), a = F(i, e.target, e.children, n);
938
938
  if (a === null) return null;
939
- let o = e.fkSide === "source" ? r`${F(i, "id", r)} = ${F(t, e.foreignKey, r)}` : r`${F(i, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`;
939
+ let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`;
940
940
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
941
- }, Ea = (e, t, n) => {
942
- let r = n.sql, i = n.nextAlias(), a = P(i, e.target, e.children, n);
941
+ }, Ia = (e, t, n) => {
942
+ let r = n.sql, i = n.nextAlias(), a = F(i, e.target, e.children, n);
943
943
  if (a === null) return null;
944
- let o = r`${F(void 0, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${b(B(e.branch.where), r)}`, c = fa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${L(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${L(e.branch.offset, r)}`;
944
+ let o = r`${I(void 0, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, c = Sa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`;
945
945
  return r`COALESCE((SELECT JSON_ARRAYAGG(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), JSON_ARRAY())`;
946
- }, Da = (e, t, n) => {
947
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = P(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
946
+ }, La = (e, t, n) => {
947
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = F(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
948
948
  projection: e.junction,
949
- source: _a(o)
949
+ source: Da(o)
950
950
  });
951
951
  if (c === null) return null;
952
- let l = e.branch.where === void 0 ? r`` : r` AND ${b(B(e.branch.where), r)}`, u = z(e, s, r, !0), d = N(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${L(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${L(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : ga(e.junction, s, r);
953
- return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${F(o, "id", r)} = ${F(s, i.targetKey, r)} WHERE ${F(s, i.sourceKey, r)} = ${F(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
954
- }, Oa = (e, t, n) => {
955
- let r = n.sql, i = n.nextAlias(), a = P(i, e.target, e.children, n);
952
+ let l = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, u = B(e, s, r, !0), d = P(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Ea(e.junction, s, r);
953
+ return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
954
+ }, Ra = (e, t, n) => {
955
+ let r = n.sql, i = n.nextAlias(), a = F(i, e.target, e.children, n);
956
956
  if (a === null) return null;
957
- let o = r`${F(i, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${b(B(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
958
- if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${F(i, e.column, r)} DESC` : r`${F(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
959
- let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${F(i, "rn", r)} > ${L(d, r)} AND ${F(i, "rn", r)} <= ${L(d + u, r)}` : u === void 0 ? r` AND ${F(i, "rn", r)} > ${L(d, r)}` : r` AND ${F(i, "rn", r)} <= ${L(u, r)}`;
960
- return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${F(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
961
- }, ka = (e, t, n) => {
957
+ let o = r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
958
+ if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
959
+ let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${I(i, "rn", r)} > ${R(d, r)} AND ${I(i, "rn", r)} <= ${R(d + u, r)}` : u === void 0 ? r` AND ${I(i, "rn", r)} > ${R(d, r)}` : r` AND ${I(i, "rn", r)} <= ${R(u, r)}`;
960
+ return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${I(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
961
+ }, za = (e, t, n) => {
962
962
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
963
963
  projection: e.junction,
964
964
  source: t
965
- }, l = r`${F(s, i.sourceKey, r)} = ${F(t, "id", r)}`, u = r`${F(o, "id", r)} = ${F(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${b(B(e.branch.where), r)}`, f = z(e, s, r, !0), p = e.branch.orderBy ?? [];
965
+ }, l = r`${I(s, i.sourceKey, r)} = ${I(t, "id", r)}`, u = r`${I(o, "id", r)} = ${I(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, f = B(e, s, r, !0), p = e.branch.orderBy ?? [];
966
966
  if (e.branch.limit === void 0 && e.branch.offset === void 0) {
967
- let t = P(o, e.target, e.children, n, c(va(s)));
968
- return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${F(o, e.column, r)} DESC` : r`${F(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
969
- }
970
- let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${F(o, e.column, r)} DESC` : r`${F(o, e.column, r)} ASC`))}` : r` ORDER BY ${F(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${F(o, "rn", r)} > ${L(g, r)} AND ${F(o, "rn", r)} <= ${L(g + h, r)}` : h === void 0 ? r` AND ${F(o, "rn", r)} > ${L(g, r)}` : r` AND ${F(o, "rn", r)} <= ${L(h, r)}`, _ = e.branch.onJunction === void 0 ? r`` : r` WHERE ${R(B(e.branch.onJunction), s, r)}`, te = P(o, e.target, e.children, n, c(_a(o)));
971
- if (te === null) return null;
972
- let ne = e.junction === void 0 ? r`` : ga(e.junction, s, r);
973
- return r`COALESCE((SELECT JSON_ARRAYAGG(${te} ORDER BY ${F(o, "rn", r)}) FROM (SELECT ${r(o)}.*${ne}, ${F(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${F(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${_}) AS ${r(o)} WHERE ${F(o, `__src_${i.sourceKey}`, r)} = ${F(t, "id", r)}${d}${ee}), JSON_ARRAY())`;
974
- }, Aa = (e, t, n) => {
975
- let r = n.sql, i = n.nextAlias(), a = ja(i, t.table, t.children, n);
967
+ let t = F(o, e.target, e.children, n, c(Oa(s)));
968
+ return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${I(o, e.column, r)} DESC` : r`${I(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
969
+ }
970
+ let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${I(o, e.column, r)} DESC` : r`${I(o, e.column, r)} ASC`))}` : r` ORDER BY ${I(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${I(o, "rn", r)} > ${R(g, r)} AND ${I(o, "rn", r)} <= ${R(g + h, r)}` : h === void 0 ? r` AND ${I(o, "rn", r)} > ${R(g, r)}` : r` AND ${I(o, "rn", r)} <= ${R(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${z(V(e.branch.onJunction), s, r)}`, ee = F(o, e.target, e.children, n, c(Da(o)));
971
+ if (ee === null) return null;
972
+ let te = e.junction === void 0 ? r`` : Ea(e.junction, s, r);
973
+ return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${I(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${I(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${I(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${v}) AS ${r(o)} WHERE ${I(o, `__src_${i.sourceKey}`, r)} = ${I(t, "id", r)}${d}${_}), JSON_ARRAY())`;
974
+ }, Ba = (e, t, n) => {
975
+ let r = n.sql, i = n.nextAlias(), a = Va(i, t.table, t.children, n);
976
976
  if (a === null) return null;
977
- let o = e.predicate ? r` WHERE ${R(e.predicate, i, r)}` : r``, s = v(e).length > 0 ? r` ORDER BY ${r.csv(v(e).map((e) => e.direction === "desc" ? r`${F(i, e.column, r)} DESC` : r`${F(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
977
+ let o = e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
978
978
  if (e.skip !== void 0) {
979
- let t = v(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
980
- l = e.take === void 0 ? r`${t} OFFSET ${L(e.skip, r)} ROWS` : r`${t} OFFSET ${L(e.skip, r)} ROWS FETCH NEXT ${L(e.take, r)} ROWS ONLY`;
981
- } else e.take !== void 0 && (c = r`TOP ${L(e.take, r)} `);
979
+ let t = w(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
980
+ l = e.take === void 0 ? r`${t} OFFSET ${R(e.skip, r)} ROWS` : r`${t} OFFSET ${R(e.skip, r)} ROWS FETCH NEXT ${R(e.take, r)} ROWS ONLY`;
981
+ } else e.take !== void 0 && (c = r`TOP ${R(e.take, r)} `);
982
982
  let u = e.skip === void 0 ? s : r``;
983
983
  return r`SELECT ${c}(SELECT ${a} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER) AS ${r("__row")} FROM ${r(t.table.tableName)} AS ${r(i)}${o}${u}${l}`;
984
- }, ja = (e, t, n, r, i) => {
984
+ }, Va = (e, t, n, r, i) => {
985
985
  let a = r.sql, o = [];
986
- for (let n of Object.keys(t.fields)) o.push(a`${F(e, n, a)} AS ${a(n)}`);
987
- if (i !== void 0) for (let e of i.projection.present) o.push(a`${F(i.source.alias, i.source.physical(e), a)} AS ${Ma(`_junction.${e}`, a)}`);
986
+ for (let n of Object.keys(t.fields)) o.push(a`${I(e, n, a)} AS ${a(n)}`);
987
+ if (i !== void 0) for (let e of i.projection.present) o.push(a`${I(i.source.alias, i.source.physical(e), a)} AS ${Ha(`_junction.${e}`, a)}`);
988
988
  for (let t of n) {
989
- let n = Na(t, e, r);
989
+ let n = Ua(t, e, r);
990
990
  if (n === null) return null;
991
991
  o.push(n);
992
992
  }
993
993
  return a.csv(o);
994
- }, Ma = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Na = (e, t, n) => {
994
+ }, Ha = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Ua = (e, t, n) => {
995
995
  switch (e.relation.kind) {
996
- case "one": return M(e) ? Ia(Gi(e), t, n) : Pa(e, t, n);
997
- case "many": return Ia(e, t, n);
998
- case "manyToMany": return La(e, t, n);
996
+ case "one": return N(e) ? Ka(ta(e), t, n) : Wa(e, t, n);
997
+ case "many": return Ka(e, t, n);
998
+ case "manyToMany": return qa(e, t, n);
999
999
  }
1000
- }, Pa = (e, t, n) => {
1001
- let r = n.sql, i = n.nextAlias(), a = ja(i, e.target, e.children, n);
1000
+ }, Wa = (e, t, n) => {
1001
+ let r = n.sql, i = n.nextAlias(), a = Va(i, e.target, e.children, n);
1002
1002
  if (a === null) return null;
1003
- let o = e.fkSide === "source" ? r`${F(i, "id", r)} = ${F(t, e.foreignKey, r)}` : r`${F(i, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}`;
1003
+ let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`;
1004
1004
  return r`JSON_QUERY((SELECT TOP 1 ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)) AS ${r(e.relationName)}`;
1005
- }, Fa = (e, t, n) => {
1005
+ }, Ga = (e, t, n) => {
1006
1006
  if (e.offset !== void 0) {
1007
- let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${L(e.offset, n)} ROWS` : n`${r} OFFSET ${L(e.offset, n)} ROWS FETCH NEXT ${L(e.limit, n)} ROWS ONLY`;
1007
+ let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${R(e.offset, n)} ROWS` : n`${r} OFFSET ${R(e.offset, n)} ROWS FETCH NEXT ${R(e.limit, n)} ROWS ONLY`;
1008
1008
  return {
1009
1009
  top: n``,
1010
1010
  pagination: i,
@@ -1012,36 +1012,36 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1012
1012
  };
1013
1013
  }
1014
1014
  return {
1015
- top: e.limit === void 0 ? n`` : n`TOP ${L(e.limit, n)} `,
1015
+ top: e.limit === void 0 ? n`` : n`TOP ${R(e.limit, n)} `,
1016
1016
  pagination: n``,
1017
1017
  finalOrder: t
1018
1018
  };
1019
- }, Ia = (e, t, n) => {
1020
- let r = n.sql, i = n.nextAlias(), a = ja(i, e.target, e.children, n);
1019
+ }, Ka = (e, t, n) => {
1020
+ let r = n.sql, i = n.nextAlias(), a = Va(i, e.target, e.children, n);
1021
1021
  if (a === null) return null;
1022
- let o = e.branch.where === void 0 ? r`` : r` AND ${R(e.branch.where, i, r)}`, s = N(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Fa(e.branch, s, r);
1023
- return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${F(i, e.foreignKey, r)} = ${F(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1024
- }, La = (e, t, n) => {
1025
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ja(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1022
+ let o = e.branch.where === void 0 ? r`` : r` AND ${z(e.branch.where, i, r)}`, s = P(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Ga(e.branch, s, r);
1023
+ return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1024
+ }, qa = (e, t, n) => {
1025
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Va(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1026
1026
  projection: e.junction,
1027
- source: va(s)
1027
+ source: Oa(s)
1028
1028
  });
1029
1029
  if (c === null) return null;
1030
- let l = e.branch.where === void 0 ? r`` : r` AND ${R(e.branch.where, o, r)}`, u = z(e, s, r), d = N(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Fa(e.branch, d, r);
1031
- return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${F(o, "id", r)} = ${F(s, i.targetKey, r)} WHERE ${F(s, i.sourceKey, r)} = ${F(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1032
- }, F = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, I = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), L = (e, t) => {
1033
- if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
1030
+ let l = e.branch.where === void 0 ? r`` : r` AND ${z(e.branch.where, o, r)}`, u = B(e, s, r), d = P(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Ga(e.branch, d, r);
1031
+ return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1032
+ }, I = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, L = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), R = (e, t) => {
1033
+ if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw y(`literalInt: expected non-negative integer, got ${e}`);
1034
1034
  return t.unsafe(String(e));
1035
- }, R = (e, t, n) => {
1036
- let r = Ra(e, t);
1037
- return b(r, n);
1038
- }, z = (e, t, n, r = !1) => {
1035
+ }, z = (e, t, n) => {
1036
+ let r = Ja(e, t);
1037
+ return T(r, n);
1038
+ }, B = (e, t, n, r = !1) => {
1039
1039
  let i = e.branch.onJunction;
1040
- return i === void 0 ? n`` : n` AND ${R(r ? B(i) : i, t, n)}`;
1041
- }, Ra = (e, t) => {
1042
- if ("not" in e) return { not: Ra(e.not, t) };
1043
- if ("and" in e) return { and: e.and.map((e) => Ra(e, t)) };
1044
- if ("or" in e) return { or: e.or.map((e) => Ra(e, t)) };
1040
+ return i === void 0 ? n`` : n` AND ${z(r ? V(i) : i, t, n)}`;
1041
+ }, Ja = (e, t) => {
1042
+ if ("not" in e) return { not: Ja(e.not, t) };
1043
+ if ("and" in e) return { and: e.and.map((e) => Ja(e, t)) };
1044
+ if ("or" in e) return { or: e.or.map((e) => Ja(e, t)) };
1045
1045
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
1046
1046
  let n = e;
1047
1047
  return {
@@ -1055,55 +1055,55 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1055
1055
  ...n,
1056
1056
  column: `${t}.${n.column}`
1057
1057
  };
1058
- }, B = (e) => {
1059
- if ("not" in e) return { not: B(e.not) };
1060
- if ("and" in e) return { and: e.and.map((e) => B(e)) };
1061
- if ("or" in e) return { or: e.or.map((e) => B(e)) };
1058
+ }, V = (e) => {
1059
+ if ("not" in e) return { not: V(e.not) };
1060
+ if ("and" in e) return { and: e.and.map((e) => V(e)) };
1061
+ if ("or" in e) return { or: e.or.map((e) => V(e)) };
1062
1062
  if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
1063
1063
  let t = e;
1064
1064
  return {
1065
1065
  ...t,
1066
- value: za(t.value)
1066
+ value: Ya(t.value)
1067
1067
  };
1068
- }, za = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => za(e)) : e, Ba = Symbol.for("@voltro/database/coreTablesRegistry"), Va = globalThis, Ha = Va[Ba] ?? (Va[Ba] = {}), Ua = (e) => {
1069
- e.actors !== void 0 && (Ha.actors = e.actors), e.tenants !== void 0 && (Ha.tenants = e.tenants);
1070
- }, Wa = (e, t) => () => {
1068
+ }, Ya = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Ya(e)) : e, Xa = Symbol.for("@voltro/database/coreTablesRegistry"), Za = globalThis, Qa = Za[Xa] ?? (Za[Xa] = {}), $a = (e) => {
1069
+ e.actors !== void 0 && (Qa.actors = e.actors), e.tenants !== void 0 && (Qa.tenants = e.tenants);
1070
+ }, eo = (e, t) => () => {
1071
1071
  let n = e();
1072
1072
  if (n === void 0) throw Error(`core '${t}' table not registered; expected the framework CLI or your migrate step to call registerCoreTables({ ${t}: () => ${t}Table }) before the database handle is constructed`);
1073
1073
  return n();
1074
- }, Ga = () => Wa(() => Ha.actors, "actors"), Ka = () => Wa(() => Ha.tenants, "tenants"), qa = x("actors", {
1075
- id: S(),
1076
- kind: C().oneOf([
1074
+ }, to = () => eo(() => Qa.actors, "actors"), no = () => eo(() => Qa.tenants, "tenants"), ro = S("actors", {
1075
+ id: C(),
1076
+ kind: b().oneOf([
1077
1077
  "user",
1078
1078
  "serviceAccount",
1079
1079
  "apiKey",
1080
1080
  "system"
1081
1081
  ]).safe(),
1082
- displayName: C().nullable().sensitive("fullName"),
1083
- createdAt: y().default("now")
1084
- }), Ja = (e, t) => ({
1082
+ displayName: b().nullable().sensitive("fullName"),
1083
+ createdAt: x().default("now")
1084
+ }), io = (e, t) => ({
1085
1085
  ...t,
1086
1086
  ...e,
1087
1087
  origin: e.origin ?? "injected"
1088
- }), Ya = (e, t, n = {}) => ({
1088
+ }), ao = (e, t, n = {}) => ({
1089
1089
  table: e,
1090
1090
  op: "insert",
1091
1091
  old: null,
1092
1092
  new: t,
1093
1093
  ...n
1094
- }), Xa = (e, t, n, r = {}) => ({
1094
+ }), oo = (e, t, n, r = {}) => ({
1095
1095
  table: e,
1096
1096
  op: "update",
1097
1097
  old: t,
1098
1098
  new: n,
1099
1099
  ...r
1100
- }), Za = (e, t, n = {}) => ({
1100
+ }), so = (e, t, n = {}) => ({
1101
1101
  table: e,
1102
1102
  op: "delete",
1103
1103
  old: t,
1104
1104
  new: null,
1105
1105
  ...n
1106
- }), Qa = (e, t, n = {}) => {
1106
+ }), co = (e, t, n = {}) => {
1107
1107
  let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
1108
1108
  return {
1109
1109
  table: e,
@@ -1118,13 +1118,13 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1118
1118
  },
1119
1119
  ...a
1120
1120
  };
1121
- }, $a = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map($a).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${$a(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", eo = (e) => fr("sha256").update([
1121
+ }, lo = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(lo).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${lo(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", uo = (e) => xr("sha256").update([
1122
1122
  e.pipe,
1123
1123
  e.op,
1124
1124
  e.key,
1125
- $a(e.next),
1126
- $a(e.prev)
1127
- ].join("\0")).digest("hex").slice(0, 32), to = (e, t) => `${e}:${t}`, no = (e) => {
1125
+ lo(e.next),
1126
+ lo(e.prev)
1127
+ ].join("\0")).digest("hex").slice(0, 32), fo = (e, t) => `${e}:${t}`, po = (e) => {
1128
1128
  let t = e.lastIndexOf(":");
1129
1129
  if (t <= 0) return null;
1130
1130
  let n = Number(e.slice(t + 1));
@@ -1132,7 +1132,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1132
1132
  digest: e.slice(0, t),
1133
1133
  occurrence: n
1134
1134
  };
1135
- }, ro = class {
1135
+ }, mo = class {
1136
1136
  #e = /* @__PURE__ */ new Map();
1137
1137
  #t;
1138
1138
  #n;
@@ -1154,7 +1154,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1154
1154
  }
1155
1155
  seedFromChangeKeys(e, t) {
1156
1156
  for (let n of e) {
1157
- let e = no(n);
1157
+ let e = po(n);
1158
1158
  if (e === null) continue;
1159
1159
  let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
1160
1160
  this.#e.set(e.digest, {
@@ -1175,70 +1175,70 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1175
1175
  this.#e.delete(e.value);
1176
1176
  }
1177
1177
  }
1178
- }, io = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", ao = 1, oo = (e = process.env) => {
1179
- let t = Number(e[io]);
1178
+ }, ho = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", go = 1, _o = (e = process.env) => {
1179
+ let t = Number(e[ho]);
1180
1180
  return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
1181
- }, so = new pr(), co = (e, t) => so.run(e, t), lo = () => so.getStore(), uo = (e) => {
1182
- let t = e ?? so.getStore();
1181
+ }, H = new Sr(), vo = (e, t) => H.run(e, t), yo = () => H.getStore(), bo = (e) => {
1182
+ let t = e ?? H.getStore();
1183
1183
  return t === void 0 ? {} : {
1184
1184
  ...t.traceId === void 0 ? {} : { traceId: t.traceId },
1185
1185
  ...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
1186
1186
  ...t.procedure === void 0 ? {} : { procedure: t.procedure },
1187
1187
  ...t.via === void 0 ? {} : { via: t.via }
1188
1188
  };
1189
- }, fo = (e) => {
1190
- let t = so.getStore();
1191
- return t === void 0 ? e(void 0) : so.run(t, () => e(t));
1192
- }, po = 3e4, mo = 1e4, V = /* @__PURE__ */ new Map(), H = 0, ho = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, go = (e) => {
1193
- for (let [t, n] of V) {
1194
- let r = n.filter((t) => e - t.at < po);
1195
- H -= n.length - r.length, r.length === 0 ? V.delete(t) : r.length !== n.length && V.set(t, r);
1196
- }
1197
- }, _o = (e, t) => {
1189
+ }, xo = (e) => {
1190
+ let t = H.getStore();
1191
+ return t === void 0 ? e(void 0) : H.run(t, () => e(t));
1192
+ }, So = 3e4, Co = 1e4, U = /* @__PURE__ */ new Map(), W = 0, wo = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, To = (e) => {
1193
+ for (let [t, n] of U) {
1194
+ let r = n.filter((t) => e - t.at < So);
1195
+ W -= n.length - r.length, r.length === 0 ? U.delete(t) : r.length !== n.length && U.set(t, r);
1196
+ }
1197
+ }, Eo = (e, t) => {
1198
1198
  if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
1199
1199
  let n = Date.now();
1200
- if (H >= mo && go(n), H >= mo) return;
1201
- let r = V.get(e);
1202
- r === void 0 ? V.set(e, [{
1200
+ if (W >= Co && To(n), W >= Co) return;
1201
+ let r = U.get(e);
1202
+ r === void 0 ? U.set(e, [{
1203
1203
  attribution: t,
1204
1204
  at: n
1205
1205
  }]) : r.push({
1206
1206
  attribution: t,
1207
1207
  at: n
1208
- }), H += 1;
1209
- }, vo = (e) => {
1210
- let t = V.get(e);
1208
+ }), W += 1;
1209
+ }, Do = (e) => {
1210
+ let t = U.get(e);
1211
1211
  if (t === void 0 || t.length === 0) return;
1212
1212
  let n = t.shift();
1213
- if (--H, t.length === 0 && V.delete(e), !(Date.now() - n.at >= po)) return n.attribution;
1214
- }, yo = (e) => (V.get(e)?.length ?? 0) > 0, U = /* @__PURE__ */ new Map(), W = /* @__PURE__ */ new Map(), G = /* @__PURE__ */ new Map(), bo = 250, xo = (e) => {
1215
- let t = W.get(e);
1213
+ if (--W, t.length === 0 && U.delete(e), !(Date.now() - n.at >= So)) return n.attribution;
1214
+ }, Oo = (e) => (U.get(e)?.length ?? 0) > 0, G = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), ko = 250, Ao = (e) => {
1215
+ let t = K.get(e);
1216
1216
  if (t === void 0) return;
1217
- W.delete(e);
1218
- let n = G.get(e);
1219
- n !== void 0 && (clearTimeout(n), G.delete(e));
1217
+ K.delete(e);
1218
+ let n = q.get(e);
1219
+ n !== void 0 && (clearTimeout(n), q.delete(e));
1220
1220
  for (let e of t) e();
1221
- }, So = (e) => {
1222
- U.set(e, (U.get(e) ?? 0) + 1);
1223
- }, Co = (e) => {
1224
- let t = (U.get(e) ?? 0) - 1;
1221
+ }, jo = (e) => {
1222
+ G.set(e, (G.get(e) ?? 0) + 1);
1223
+ }, Mo = (e) => {
1224
+ let t = (G.get(e) ?? 0) - 1;
1225
1225
  if (t > 0) {
1226
- U.set(e, t);
1226
+ G.set(e, t);
1227
1227
  return;
1228
1228
  }
1229
- U.delete(e), xo(e);
1230
- }, wo = (e, t, n, r) => {
1231
- let i = n == null ? void 0 : ho(e, t, n), a = () => r(i === void 0 ? void 0 : vo(i));
1229
+ G.delete(e), Ao(e);
1230
+ }, No = (e, t, n, r) => {
1231
+ let i = n == null ? void 0 : wo(e, t, n), a = () => r(i === void 0 ? void 0 : Do(i));
1232
1232
  if (i === void 0) {
1233
1233
  a();
1234
1234
  return;
1235
1235
  }
1236
- if (yo(i)) {
1236
+ if (Oo(i)) {
1237
1237
  a();
1238
1238
  return;
1239
1239
  }
1240
- let o = W.get(e);
1241
- if (o === void 0 && (U.get(e) ?? 0) === 0) {
1240
+ let o = K.get(e);
1241
+ if (o === void 0 && (G.get(e) ?? 0) === 0) {
1242
1242
  a();
1243
1243
  return;
1244
1244
  }
@@ -1246,91 +1246,91 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1246
1246
  o.push(a);
1247
1247
  return;
1248
1248
  }
1249
- W.set(e, [a]);
1250
- let s = setTimeout(() => xo(e), bo);
1251
- typeof s == "object" && typeof s.unref == "function" && s.unref(), G.set(e, s);
1252
- }, To = () => {
1253
- V.clear(), H = 0, U.clear();
1254
- for (let e of G.values()) clearTimeout(e);
1255
- G.clear(), W.clear();
1256
- }, Eo = () => H, Do = 64, Oo = "\0", ko = 32, Ao = (e, ...t) => `${e}_${fr("sha256").update(t.map(String).join(Oo)).digest("hex").slice(0, ko)}`, jo = (e) => e.length + 1 + ko, K = /* @__PURE__ */ new Map(), Mo = (e, t) => {
1257
- K.set(e, {
1249
+ K.set(e, [a]);
1250
+ let s = setTimeout(() => Ao(e), ko);
1251
+ typeof s == "object" && typeof s.unref == "function" && s.unref(), q.set(e, s);
1252
+ }, Po = () => {
1253
+ U.clear(), W = 0, G.clear();
1254
+ for (let e of q.values()) clearTimeout(e);
1255
+ q.clear(), K.clear();
1256
+ }, Fo = () => W, Io = 64, Lo = "\0", Ro = 32, zo = (e, ...t) => `${e}_${xr("sha256").update(t.map(String).join(Lo)).digest("hex").slice(0, Ro)}`, Bo = (e) => e.length + 1 + Ro, J = /* @__PURE__ */ new Map(), Vo = (e, t) => {
1257
+ J.set(e, {
1258
1258
  recorder: t.recorder,
1259
1259
  tables: new Set(t.tables),
1260
1260
  ownTables: new Set(t.ownTables)
1261
1261
  });
1262
- }, No = (e) => {
1263
- K.delete(e);
1264
- }, Po = () => K.clear(), q = new pr(), Fo = (e) => q.run({ n: 1 }, e), Io = (e) => w.suspend(() => {
1265
- let t = q.getStore();
1266
- if (t !== void 0) return t.n += 1, w.ensuring(e, w.sync(() => {
1262
+ }, Ho = (e) => {
1263
+ J.delete(e);
1264
+ }, Uo = () => J.clear(), Wo = new Sr(), Go = (e) => Wo.run({ n: 1 }, e), Ko = (e) => E.suspend(() => {
1265
+ let t = Wo.getStore();
1266
+ if (t !== void 0) return t.n += 1, E.ensuring(e, E.sync(() => {
1267
1267
  --t.n;
1268
1268
  }));
1269
1269
  let n = { n: 1 };
1270
- return q.enterWith(n), w.ensuring(e, w.sync(() => {
1270
+ return Wo.enterWith(n), E.ensuring(e, E.sync(() => {
1271
1271
  --n.n;
1272
1272
  }));
1273
- }), Lo = () => (q.getStore()?.n ?? 0) > 0, Ro = (e) => {
1274
- if (K.size === 0 || (q.getStore()?.n ?? 0) > 0) return !1;
1275
- for (let t of K.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
1273
+ }), qo = () => (Wo.getStore()?.n ?? 0) > 0, Jo = (e) => {
1274
+ if (J.size === 0 || (Wo.getStore()?.n ?? 0) > 0) return !1;
1275
+ for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
1276
1276
  return !1;
1277
- }, zo = async (e, t) => {
1278
- if (K.size !== 0) {
1279
- for (let [n, r] of K.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
1277
+ }, Yo = async (e, t) => {
1278
+ if (J.size !== 0) {
1279
+ for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
1280
1280
  await r.recorder(e, t);
1281
1281
  } catch (e) {
1282
- let r = te(e);
1282
+ let r = _e(e);
1283
1283
  throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
1284
1284
  }
1285
1285
  }
1286
- }, Bo = lr.exponential({
1286
+ }, Xo = vr.exponential({
1287
1287
  start: 5e-4,
1288
1288
  factor: 2,
1289
1289
  count: 16
1290
- }), Vo = T.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), Ho = T.histogram("voltro_db_query_duration_seconds", Bo, "Database operation duration in seconds, by dialect and operation kind."), Uo = T.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), Wo = T.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), Go = T.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), J = [], Ko = /* @__PURE__ */ new Map(), qo = /* @__PURE__ */ new Map(), Jo = /* @__PURE__ */ new Map(), Yo = (e, t) => {
1291
- let n = `${e}\u0000${t}`, r = Ko.get(n);
1290
+ }), Zo = D.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), Qo = D.histogram("voltro_db_query_duration_seconds", Xo, "Database operation duration in seconds, by dialect and operation kind."), $o = D.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), es = D.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), ts = D.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), ns = [], rs = /* @__PURE__ */ new Map(), is = /* @__PURE__ */ new Map(), as = /* @__PURE__ */ new Map(), os = (e, t) => {
1291
+ let n = `${e}\u0000${t}`, r = rs.get(n);
1292
1292
  if (r !== void 0) return r;
1293
- let i = (n) => T.tagged(T.tagged(n, "dialect", e), "op", t), a = {
1294
- count: i(Vo),
1295
- duration: i(Ho),
1296
- errors: i(Uo)
1293
+ let i = (n) => D.tagged(D.tagged(n, "dialect", e), "op", t), a = {
1294
+ count: i(Zo),
1295
+ duration: i(Qo),
1296
+ errors: i($o)
1297
1297
  };
1298
- return Ko.set(n, a), a;
1299
- }, Xo = () => {
1300
- Ko.clear(), qo.clear(), Jo.clear();
1301
- }, Zo = () => Ko.size + qo.size + Jo.size, Qo = /* @__PURE__ */ new Map(), $o = (e, t) => {
1302
- let n = Math.max(0, (Qo.get(e) ?? 0) + t);
1303
- n === 0 ? Qo.delete(e) : Qo.set(e, n);
1304
- let r = qo.get(e);
1305
- r === void 0 && (r = T.tagged(Wo, "dialect", e), qo.set(e, r)), r.unsafeUpdate(n, J);
1306
- }, es = (e) => Qo.get(e) ?? 0, ts = (e) => {
1307
- let t = Yo(String(e.dialect), e.op);
1308
- t.count.unsafeUpdate(1, J), t.duration.unsafeUpdate(e.durationMs / 1e3, J), e.status === "error" && t.errors.unsafeUpdate(1, J);
1309
- }, ns = async (e, t, n) => {
1298
+ return rs.set(n, a), a;
1299
+ }, ss = () => {
1300
+ rs.clear(), is.clear(), as.clear();
1301
+ }, cs = () => rs.size + is.size + as.size, ls = /* @__PURE__ */ new Map(), us = (e, t) => {
1302
+ let n = Math.max(0, (ls.get(e) ?? 0) + t);
1303
+ n === 0 ? ls.delete(e) : ls.set(e, n);
1304
+ let r = is.get(e);
1305
+ r === void 0 && (r = D.tagged(es, "dialect", e), is.set(e, r)), r.unsafeUpdate(n, ns);
1306
+ }, ds = (e) => ls.get(e) ?? 0, fs = (e) => {
1307
+ let t = os(String(e.dialect), e.op);
1308
+ t.count.unsafeUpdate(1, ns), t.duration.unsafeUpdate(e.durationMs / 1e3, ns), e.status === "error" && t.errors.unsafeUpdate(1, ns);
1309
+ }, ps = async (e, t, n) => {
1310
1310
  let r = performance.now(), i = String(e);
1311
- $o(i, 1);
1311
+ us(i, 1);
1312
1312
  let a = "ok";
1313
1313
  try {
1314
1314
  return await n();
1315
1315
  } catch (e) {
1316
1316
  throw a = "error", e;
1317
1317
  } finally {
1318
- $o(i, -1), ts({
1318
+ us(i, -1), fs({
1319
1319
  dialect: e,
1320
1320
  op: t,
1321
1321
  durationMs: performance.now() - r,
1322
1322
  status: a
1323
1323
  });
1324
1324
  }
1325
- }, rs = 3e5, is = (e) => {
1325
+ }, ms = 3e5, hs = (e) => {
1326
1326
  if (e == null || e === "") return;
1327
1327
  let t = Number(e);
1328
1328
  return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
1329
- }, as = (e, t = process.env) => is(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? is(e) ?? 3e5, os = (e, t = {}) => {
1330
- let n = as(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
1329
+ }, gs = (e, t = process.env) => hs(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? hs(e) ?? 3e5, _s = (e, t = {}) => {
1330
+ let n = gs(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
1331
1331
  return (t) => {
1332
- let a = `${t.dialect} ${t.reason}`, o = Jo.get(a);
1333
- o === void 0 && (o = T.tagged(T.tagged(Go, "dialect", String(t.dialect)), "reason", t.reason), Jo.set(a, o)), o.unsafeUpdate(1, J);
1332
+ let a = `${t.dialect} ${t.reason}`, o = as.get(a);
1333
+ o === void 0 && (o = D.tagged(D.tagged(ts, "dialect", String(t.dialect)), "reason", t.reason), as.set(a, o)), o.unsafeUpdate(1, ns);
1334
1334
  let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
1335
1335
  table: t.table,
1336
1336
  dialect: String(t.dialect),
@@ -1344,37 +1344,37 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1344
1344
  }
1345
1345
  i.set(s, r()), e.warn(t.reason === "execute-failed" ? "eager-load JSON-agg statement FAILED and was re-run on the multi-query walker — this query pays both paths on every call. Counted as voltro_db_eager_fallback_total{reason=\"execute-failed\"}." : "eager-load could not be compiled to a single JSON-agg roundtrip and is running on the multi-query walker — one round trip per relation level, on every call. Counted as voltro_db_eager_fallback_total{reason=\"not-compilable\"}.", u);
1346
1346
  };
1347
- }, ss = (e) => {
1348
- if (cr.isSuccess(e)) return e.value;
1349
- throw ar.squash(e.cause);
1350
- }, cs = "10 millis", ls = 3, us = (e) => ur.exponential(cs).pipe(ur.compose(ur.recurs(ls)), ur.whileInput(e)), ds = async (e) => {
1351
- let t = 0, n = w.suspend(() => {
1347
+ }, vs = (e) => {
1348
+ if (_r.isSuccess(e)) return e.value;
1349
+ throw mr.squash(e.cause);
1350
+ }, ys = "10 millis", bs = 3, xs = (e) => yr.exponential(ys).pipe(yr.compose(yr.recurs(bs)), yr.whileInput(e)), Ss = async (e) => {
1351
+ let t = 0, n = E.suspend(() => {
1352
1352
  let n = ++t;
1353
- return e.withTransaction(w.flatMap(w.serviceOption(mr), (t) => {
1354
- if (E.isNone(t)) return w.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
1355
- let r = t.value, i = w.tryPromise({
1353
+ return e.withTransaction(E.flatMap(E.serviceOption(Cr), (t) => {
1354
+ if (O.isNone(t)) return E.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
1355
+ let r = t.value, i = E.tryPromise({
1356
1356
  try: () => e.body(r, n),
1357
1357
  catch: (e) => e
1358
1358
  });
1359
- return e.prepare === void 0 ? i : w.flatMap(e.prepare(r), () => i);
1360
- })).pipe(w.catchAllDefect((t) => e.isRetryable(t) ? w.fail(t) : w.die(t)));
1361
- }).pipe(w.retry(us(e.isRetryable)), w.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
1362
- return ns(e.dialect, "transaction", async () => ss(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
1363
- }, fs = class extends Error {
1359
+ return e.prepare === void 0 ? i : E.flatMap(e.prepare(r), () => i);
1360
+ })).pipe(E.catchAllDefect((t) => e.isRetryable(t) ? E.fail(t) : E.die(t)));
1361
+ }).pipe(E.retry(xs(e.isRetryable)), E.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
1362
+ return ps(e.dialect, "transaction", async () => vs(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
1363
+ }, Cs = class extends Error {
1364
1364
  swallowed;
1365
1365
  _tag = "TransactionAborted";
1366
1366
  constructor(e, t) {
1367
1367
  super(`${e}: a statement failed inside this transaction and the error was caught, but the database had already aborted the transaction — every later statement was refused, and COMMIT would have rolled back ALL of its writes, including the ones that succeeded. Nothing was committed.
1368
- the caught failure: ${gs(t)}\n to tolerate a failing statement and keep the rest, run it inside \`tx.savepoint(() => …)\` — only that statement is rolled back. To keep all-or-nothing, let the error propagate.`, { cause: t }), this.swallowed = t, this.name = "TransactionAbortedError";
1368
+ the caught failure: ${Ds(t)}\n to tolerate a failing statement and keep the rest, run it inside \`tx.savepoint(() => …)\` — only that statement is rolled back. To keep all-or-nothing, let the error propagate.`, { cause: t }), this.swallowed = t, this.name = "TransactionAbortedError";
1369
1369
  }
1370
- }, ps = (e, t = "transactional()") => {
1370
+ }, ws = (e, t = "transactional()") => {
1371
1371
  let n = 0, r, i = (e) => {
1372
1372
  r === void 0 && (r = { error: e });
1373
1373
  };
1374
1374
  return {
1375
1375
  track: (a) => r === void 0 ? n > 0 ? a() : a().catch((t) => {
1376
1376
  throw e(t) && i(t), t;
1377
- }) : Promise.reject(new fs(t, r.error)),
1377
+ }) : Promise.reject(new Cs(t, r.error)),
1378
1378
  inSavepoint: async (e) => {
1379
1379
  n++;
1380
1380
  try {
@@ -1386,7 +1386,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1386
1386
  record: i,
1387
1387
  abortedBy: () => r
1388
1388
  };
1389
- }, ms = async (e, t) => {
1389
+ }, Ts = async (e, t) => {
1390
1390
  let { tracker: n, name: r, exec: i, spelling: a } = e;
1391
1391
  await n.track(() => i(a === "mssql" ? `SAVE TRANSACTION ${r}` : `SAVEPOINT ${r}`));
1392
1392
  try {
@@ -1395,8 +1395,8 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1395
1395
  } catch (e) {
1396
1396
  throw await i(a === "mssql" ? `ROLLBACK TRANSACTION ${r}` : `ROLLBACK TO SAVEPOINT ${r}`).catch((e) => n.record(e)), a === "standard" && await i(`RELEASE SAVEPOINT ${r}`).catch(() => void 0), e;
1397
1397
  }
1398
- }, hs = (e) => e instanceof fs || typeof e == "object" && !!e && e._tag === "TransactionAborted", gs = (e) => {
1399
- for (let t of we(e)) {
1398
+ }, Es = (e) => e instanceof Cs || typeof e == "object" && !!e && e._tag === "TransactionAborted", Ds = (e) => {
1399
+ for (let t of tt(e)) {
1400
1400
  let e = t;
1401
1401
  for (let t = 0; t < 5 && typeof e == "object" && e; t++) {
1402
1402
  let t = e.code, n = e.message;
@@ -1405,14 +1405,14 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1405
1405
  }
1406
1406
  }
1407
1407
  return e instanceof Error ? e.message : String(e);
1408
- }, _s = async (e) => {
1409
- let t = lo(), n = t === void 0 ? (e) => e() : (e) => co(t, e), r = await ds({
1408
+ }, Os = async (e) => {
1409
+ let t = yo(), n = t === void 0 ? (e) => e() : (e) => vo(t, e), r = await Ss({
1410
1410
  ...e,
1411
1411
  body: (r) => {
1412
1412
  let i = e.makeView(r, t);
1413
1413
  return n(() => e.work(i)).then((t) => {
1414
1414
  let n = i.abortedBy?.();
1415
- if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new fs(e.label, n.error);
1415
+ if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new Cs(e.label, n.error);
1416
1416
  return {
1417
1417
  result: t,
1418
1418
  view: i
@@ -1424,50 +1424,50 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1424
1424
  }
1425
1425
  });
1426
1426
  return r.view.commitEvents(), r.result;
1427
- }, vs = /* @__PURE__ */ new Set([
1427
+ }, ks = /* @__PURE__ */ new Set([
1428
1428
  "1213",
1429
1429
  "ER_LOCK_DEADLOCK",
1430
1430
  "1205",
1431
1431
  "ER_LOCK_WAIT_TIMEOUT",
1432
1432
  "1020",
1433
1433
  "ER_CHECKREAD"
1434
- ]), ys = /* @__PURE__ */ new Set(["40001", "40P01"]), bs = /* @__PURE__ */ new Set(["1205"]), xs = /* @__PURE__ */ new Set([
1434
+ ]), As = /* @__PURE__ */ new Set(["40001", "40P01"]), js = /* @__PURE__ */ new Set(["1205"]), Ms = /* @__PURE__ */ new Set([
1435
1435
  "SQLITE_BUSY",
1436
1436
  "5",
1437
1437
  "SQLITE_LOCKED",
1438
1438
  "6"
1439
- ]), Ss = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, Cs = /* @__PURE__ */ new Set([
1439
+ ]), Ns = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, Ps = /* @__PURE__ */ new Set([
1440
1440
  1213,
1441
1441
  1205,
1442
1442
  1020
1443
- ]), ws = /* @__PURE__ */ new Set([
1444
- ...vs,
1445
- ...ys,
1446
- ...bs,
1447
- ...xs
1448
- ]), Ts = (e) => we(e).some(Es), Es = (e) => {
1443
+ ]), Fs = /* @__PURE__ */ new Set([
1444
+ ...ks,
1445
+ ...As,
1446
+ ...js,
1447
+ ...Ms
1448
+ ]), Is = (e) => tt(e).some(Ls), Ls = (e) => {
1449
1449
  let t = e;
1450
1450
  for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
1451
1451
  let e = t;
1452
- if (typeof e.errno == "number" && Cs.has(e.errno) || typeof e.number == "number" && bs.has(String(e.number)) || typeof e.code == "string" && ws.has(e.code) || typeof e.sqlState == "string" && ys.has(e.sqlState) || typeof e.message == "string" && Ss.test(e.message)) return !0;
1452
+ if (typeof e.errno == "number" && Ps.has(e.errno) || typeof e.number == "number" && js.has(String(e.number)) || typeof e.code == "string" && Fs.has(e.code) || typeof e.sqlState == "string" && As.has(e.sqlState) || typeof e.message == "string" && Ns.test(e.message)) return !0;
1453
1453
  t = e.cause;
1454
1454
  }
1455
1455
  return !1;
1456
- }, Ds = "voltro/expires", Os = () => Ln({
1457
- id: Ds,
1458
- fields: { expiresAt: y().nullable() },
1456
+ }, Rs = "voltro/expires", zs = () => m({
1457
+ id: Rs,
1458
+ fields: { expiresAt: x().nullable() },
1459
1459
  behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
1460
- }), ks = "voltro/localFirst", As = () => Ln({
1461
- id: ks,
1460
+ }), Bs = "voltro/localFirst", Vs = () => m({
1461
+ id: Bs,
1462
1462
  fields: {}
1463
- }), js = (e) => e.appliedMixins.some((e) => e.id === ks), Ms = (e) => {
1463
+ }), Hs = (e) => e.appliedMixins.some((e) => e.id === Bs), Us = (e) => {
1464
1464
  let t = [];
1465
- for (let n of Object.values(e)) js(n) && t.push(n.tableName);
1465
+ for (let n of Object.values(e)) Hs(n) && t.push(n.tableName);
1466
1466
  return t;
1467
- }, Ns = class extends sr.TaggedError("TableStreamError") {}, Ps = 1e3, Fs = (e, t, n, r) => {
1468
- let i = E.match(r, {
1467
+ }, Ws = class extends gr.TaggedError("TableStreamError") {}, Gs = 1e3, Ks = (e, t, n, r) => {
1468
+ let i = O.match(r, {
1469
1469
  onNone: () => e.where,
1470
- onSome: (n) => e.where ? Fe(e.where, _n(t, n)) : _n(t, n)
1470
+ onSome: (n) => e.where ? wn(e.where, hn(t, n)) : hn(t, n)
1471
1471
  });
1472
1472
  return {
1473
1473
  table: e.table,
@@ -1482,19 +1482,19 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1482
1482
  ...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
1483
1483
  ...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
1484
1484
  };
1485
- }, Is = (e, t) => {
1486
- let n = t.pk ?? "id", r = t.chunkSize ?? Ps;
1487
- return dr.paginateChunkEffect(E.none(), (i) => {
1488
- let a = w.tryPromise({
1489
- try: () => e.query(Fs(t, n, r, i)),
1490
- catch: (e) => new Ns({
1485
+ }, qs = (e, t) => {
1486
+ let n = t.pk ?? "id", r = t.chunkSize ?? Gs;
1487
+ return br.paginateChunkEffect(O.none(), (i) => {
1488
+ let a = E.tryPromise({
1489
+ try: () => e.query(Ks(t, n, r, i)),
1490
+ catch: (e) => new Ws({
1491
1491
  table: t.table,
1492
1492
  cause: e
1493
1493
  })
1494
1494
  });
1495
- return (t.retry ? a.pipe(w.retry(t.retry)) : a).pipe(w.map((e) => [or.fromIterable(e), e.length === r && e.length > 0 ? E.some(E.some(e[e.length - 1][n])) : E.none()]));
1495
+ return (t.retry ? a.pipe(E.retry(t.retry)) : a).pipe(E.map((e) => [hr.fromIterable(e), e.length === r && e.length > 0 ? O.some(O.some(e[e.length - 1][n])) : O.none()]));
1496
1496
  });
1497
- }, Ls = (e) => {
1497
+ }, Js = (e) => {
1498
1498
  let t = e.alpha ?? .5;
1499
1499
  if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
1500
1500
  return (n) => {
@@ -1508,7 +1508,7 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1508
1508
  queryText: e.vector.query,
1509
1509
  distance: e.vector.distance ?? "cosine",
1510
1510
  alpha: t
1511
- }, i = tt(n.table, e.fts.indexName, n.fullTextIndexes);
1511
+ }, i = _t(n.table, e.fts.indexName, n.fullTextIndexes);
1512
1512
  return {
1513
1513
  ...n,
1514
1514
  annClause: r,
@@ -1521,17 +1521,17 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1521
1521
  }
1522
1522
  };
1523
1523
  };
1524
- }, Rs = async (e, t) => {
1524
+ }, Ys = async (e, t) => {
1525
1525
  let n = e.as ?? "embedding", r = t.row[e.from];
1526
1526
  if (typeof r != "string" || r.length === 0) return {};
1527
1527
  let i = await t.embed(r);
1528
1528
  return { [n]: i };
1529
- }, zs = (e) => {
1529
+ }, Xs = (e) => {
1530
1530
  if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
1531
- let t = e.as ?? "embedding", n = (t) => Rs(e, t);
1532
- return Ln({
1531
+ let t = e.as ?? "embedding", n = (t) => Ys(e, t);
1532
+ return m({
1533
1533
  id: "voltro/vectorEmbedding",
1534
- fields: { [t]: d(e.dimensions) },
1534
+ fields: { [t]: Ne(e.dimensions) },
1535
1535
  ...e.index === !1 ? {} : { indexes: [{
1536
1536
  fields: [t],
1537
1537
  kind: "hnsw",
@@ -1546,19 +1546,19 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1546
1546
  beforeUpdate: n
1547
1547
  }
1548
1548
  });
1549
- }, Bs = 63, Vs = "br_pr", Y = class extends Error {
1549
+ }, Zs = 63, Qs = "br_pr", Y = class extends Error {
1550
1550
  _tag = "BranchNameInvalid";
1551
1551
  constructor(e) {
1552
1552
  super(e), this.name = "BranchNameInvalid";
1553
1553
  }
1554
- }, Hs = (e, t) => {
1554
+ }, $s = (e, t) => {
1555
1555
  if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
1556
- let n = Be(e);
1556
+ let n = Qt(e);
1557
1557
  if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
1558
- let r = `${Vs}${t}_${n}`;
1559
- if (r.length > Bs) throw new Y(`branch namespace '${r}' exceeds the ${Bs}-byte identifier limit — use a shorter app slug`);
1558
+ let r = `${Qs}${t}_${n}`;
1559
+ if (r.length > Zs) throw new Y(`branch namespace '${r}' exceeds the ${Zs}-byte identifier limit — use a shorter app slug`);
1560
1560
  return r;
1561
- }, Us = (e) => e.startsWith(Vs), Ws = {
1561
+ }, ec = (e) => e.startsWith(Qs), tc = {
1562
1562
  requested: {
1563
1563
  provision: "provisioning",
1564
1564
  destroy: "destroying"
@@ -1577,18 +1577,18 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1577
1577
  fail: "failed"
1578
1578
  },
1579
1579
  destroyed: {}
1580
- }, Gs = class extends Error {
1580
+ }, nc = class extends Error {
1581
1581
  from;
1582
1582
  event;
1583
1583
  _tag = "BranchTransitionInvalid";
1584
1584
  constructor(e, t) {
1585
1585
  super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
1586
1586
  }
1587
- }, Ks = (e, t) => {
1588
- let n = Ws[e][t];
1589
- if (n === void 0) throw new Gs(e, t);
1587
+ }, rc = (e, t) => {
1588
+ let n = tc[e][t];
1589
+ if (n === void 0) throw new nc(e, t);
1590
1590
  return n;
1591
- }, qs = (e, t, n, r, i = [], a = []) => {
1591
+ }, ic = (e, t, n, r, i = [], a = []) => {
1592
1592
  if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
1593
1593
  let o = [{
1594
1594
  kind: "create-namespace",
@@ -1618,13 +1618,13 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1618
1618
  kind: "seed",
1619
1619
  detail: `run boot seeds into ${e}`
1620
1620
  }), o;
1621
- }, Js = (e) => {
1622
- if (!Us(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
1621
+ }, ac = (e) => {
1622
+ if (!ec(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
1623
1623
  return [{
1624
1624
  kind: "drop-namespace",
1625
1625
  detail: e
1626
1626
  }];
1627
- }, Ys = (e) => {
1627
+ }, oc = (e) => {
1628
1628
  if (e === void 0 || e === "") return !1;
1629
1629
  try {
1630
1630
  let t = new URL(e).hostname.toLowerCase();
@@ -1632,27 +1632,27 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1632
1632
  } catch {
1633
1633
  return /\bneon\.(tech|build)\b/i.test(e);
1634
1634
  }
1635
- }, Xs = (e) => e.prefer === void 0 ? e.seed === "copy" && Ys(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Zs = (e, t = {}) => [{
1635
+ }, sc = (e) => e.prefer === void 0 ? e.seed === "copy" && oc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, cc = (e, t = {}) => [{
1636
1636
  kind: "neon-branch-create",
1637
1637
  detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
1638
- }], Qs = (e) => {
1639
- if (!Us(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
1638
+ }], lc = (e) => {
1639
+ if (!ec(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
1640
1640
  return [{
1641
1641
  kind: "neon-branch-delete",
1642
1642
  detail: e
1643
1643
  }];
1644
- }, $s = (e) => e.mechanism === "neon-cow" ? Zs(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : qs(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), ec = (e, t) => e === "neon-cow" ? Qs(t) : Js(t), tc = (e, t, n) => {
1644
+ }, uc = (e) => e.mechanism === "neon-cow" ? cc(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : ic(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), dc = (e, t) => e === "neon-cow" ? lc(t) : ac(t), fc = (e, t, n) => {
1645
1645
  let r = e.filter((e) => e.state !== "destroyed" && e.state !== "destroying"), i = r.filter((e) => n - e.createdAtMs > t.ttlMs).map((e) => e.namespace), a = new Set(i);
1646
1646
  return {
1647
1647
  evict: i,
1648
1648
  rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
1649
1649
  };
1650
- }, nc = async (e, t) => {
1651
- let n = Hs(e.appSlug, e.prNumber), r = Xs({
1650
+ }, pc = async (e, t) => {
1651
+ let n = $s(e.appSlug, e.prNumber), r = sc({
1652
1652
  seed: e.seed,
1653
1653
  ...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
1654
1654
  ...e.prefer === void 0 ? {} : { prefer: e.prefer }
1655
- }), i = $s({
1655
+ }), i = uc({
1656
1656
  mechanism: r,
1657
1657
  branchId: n,
1658
1658
  tableNames: e.tableNames,
@@ -1681,15 +1681,15 @@ var gr = (e) => typeof e == "string" && e !== "" ? e : null, _r = async (e, t, n
1681
1681
  mechanism: r,
1682
1682
  steps: i
1683
1683
  };
1684
- }, rc = async (e, t, n) => {
1685
- let r = ec(t, e);
1684
+ }, mc = async (e, t, n) => {
1685
+ let r = dc(t, e);
1686
1686
  return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
1687
- }, ic = (e, t, n) => tc(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, ac = {
1687
+ }, hc = (e, t, n) => fc(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, gc = {
1688
1688
  cascade: "CASCADE",
1689
1689
  restrict: "RESTRICT",
1690
1690
  setNull: "SET NULL",
1691
1691
  noAction: "NO ACTION"
1692
- }, Z = (e) => `'${e.replace(/'/g, "''")}'`, oc = (e, t) => {
1692
+ }, Z = (e) => `'${e.replace(/'/g, "''")}'`, _c = (e, t) => {
1693
1693
  let n = t.columns.map(Z).join(", ");
1694
1694
  return `DO $voltro_branch$
1695
1695
  DECLARE derived name;
@@ -1716,10 +1716,10 @@ BEGIN
1716
1716
  END IF;
1717
1717
  END
1718
1718
  $voltro_branch$`;
1719
- }, sc = (e, t) => {
1720
- let n = t.onDelete === void 0 ? "" : ` ON DELETE ${ac[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${ac[t.onUpdate]}`;
1719
+ }, vc = (e, t) => {
1720
+ let n = t.onDelete === void 0 ? "" : ` ON DELETE ${gc[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${gc[t.onUpdate]}`;
1721
1721
  return `ALTER TABLE ${X(e)}.${X(t.table)} ADD FOREIGN KEY (${X(t.column)}) REFERENCES ${X(e)}.${X(t.targetTable)} (${X(t.targetColumn)})${n}${r}`;
1722
- }, cc = (e) => {
1722
+ }, yc = (e) => {
1723
1723
  let t = () => {
1724
1724
  throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
1725
1725
  };
@@ -1727,24 +1727,24 @@ $voltro_branch$`;
1727
1727
  createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
1728
1728
  createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
1729
1729
  copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
1730
- addForeignKey: (t, n) => e.run(sc(t, n)),
1731
- restoreIndexName: (t, n) => e.run(oc(t, n)),
1730
+ addForeignKey: (t, n) => e.run(vc(t, n)),
1731
+ restoreIndexName: (t, n) => e.run(_c(t, n)),
1732
1732
  dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
1733
1733
  neonBranchCreate: t,
1734
1734
  neonBranchDelete: t
1735
1735
  };
1736
- }, lc = class extends Error {
1736
+ }, bc = class extends Error {
1737
1737
  _tag = "TenantResidencyUnresolved";
1738
1738
  constructor(e) {
1739
1739
  super(e), this.name = "TenantResidencyUnresolved";
1740
1740
  }
1741
- }, uc = class extends Error {
1741
+ }, xc = class extends Error {
1742
1742
  region;
1743
1743
  _tag = "TenantRegionUnavailable";
1744
1744
  constructor(e, t) {
1745
1745
  super(t), this.region = e, this.name = "TenantRegionUnavailable";
1746
1746
  }
1747
- }, dc, fc = (e) => {
1747
+ }, Sc, Cc = (e) => {
1748
1748
  if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
1749
1749
  if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
1750
1750
  let t = /* @__PURE__ */ new Map();
@@ -1753,55 +1753,55 @@ $voltro_branch$`;
1753
1753
  if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
1754
1754
  t.set(n.tenantId, n.region);
1755
1755
  }
1756
- return dc = e, e;
1757
- }, pc = () => dc, mc = () => {
1758
- dc = void 0;
1759
- }, hc = (e, t) => {
1760
- if (e == null || e === "") throw new lc("residency is on but the request has no resolvable tenant — refusing to bind a store");
1756
+ return Sc = e, e;
1757
+ }, wc = () => Sc, Tc = () => {
1758
+ Sc = void 0;
1759
+ }, Ec = (e, t) => {
1760
+ if (e == null || e === "") throw new bc("residency is on but the request has no resolvable tenant — refusing to bind a store");
1761
1761
  let n = t.homes.find((t) => t.tenantId === e);
1762
- if (n === void 0) throw new lc(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
1762
+ if (n === void 0) throw new bc(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
1763
1763
  return n;
1764
- }, gc = (e, t) => t.servableRegions.includes(e), _c = (e, t) => {
1765
- let n = hc(e.tenantId, t), r = Gn(n.tenantId);
1764
+ }, Dc = (e, t) => t.servableRegions.includes(e), Oc = (e, t) => {
1765
+ let n = Ec(e.tenantId, t), r = o(n.tenantId);
1766
1766
  return {
1767
1767
  region: n.region,
1768
1768
  namespace: r,
1769
1769
  ...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
1770
1770
  };
1771
- }, vc = (e, t, n) => {
1772
- let r = _c(e, t);
1773
- if (!gc(r.region, t)) throw new uc(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
1771
+ }, kc = (e, t, n) => {
1772
+ let r = Oc(e, t);
1773
+ if (!Dc(r.region, t)) throw new xc(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
1774
1774
  let i = n.get(r.region);
1775
- if (i === void 0) throw new uc(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
1775
+ if (i === void 0) throw new xc(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
1776
1776
  return {
1777
1777
  store: i,
1778
1778
  placement: r
1779
1779
  };
1780
- }, yc = async (e, t, n, r) => {
1781
- let { store: i, placement: a } = vc(e, t, n);
1780
+ }, Ac = async (e, t, n, r) => {
1781
+ let { store: i, placement: a } = kc(e, t, n);
1782
1782
  return await r(i, a), a;
1783
- }, bc = (e) => {
1783
+ }, jc = (e) => {
1784
1784
  if (typeof e == "string") return e;
1785
1785
  if ("jsonPath" in e) {
1786
1786
  let { column: t, path: n, numeric: r } = e.jsonPath;
1787
1787
  return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
1788
1788
  }
1789
1789
  return `(${e.expr})`;
1790
- }, Q = (e) => e.map(bc), xc = (e, t) => {
1790
+ }, Q = (e) => e.map(jc), Mc = (e, t) => {
1791
1791
  if (e.length !== t.length) return !1;
1792
- for (let n = 0; n < e.length; n++) if (bc(e[n]) !== bc(t[n])) return !1;
1792
+ for (let n = 0; n < e.length; n++) if (jc(e[n]) !== jc(t[n])) return !1;
1793
1793
  return !0;
1794
- }, Sc = (e, t) => {
1794
+ }, Nc = (e, t) => {
1795
1795
  if (e.length >= t.length) return !1;
1796
- for (let n = 0; n < e.length; n++) if (bc(e[n]) !== bc(t[n])) return !1;
1796
+ for (let n = 0; n < e.length; n++) if (jc(e[n]) !== jc(t[n])) return !1;
1797
1797
  return !0;
1798
- }, Cc = (e) => {
1798
+ }, Pc = (e) => {
1799
1799
  let t = [], n = e.appliedIndexes, r = e.tableName;
1800
1800
  for (let e = 0; e < n.length; e++) {
1801
1801
  let i = n[e];
1802
1802
  for (let a = e + 1; a < n.length; a++) {
1803
1803
  let e = n[a];
1804
- if (xc(i.fields, e.fields)) {
1804
+ if (Mc(i.fields, e.fields)) {
1805
1805
  let [n, a] = i.name < e.name ? [i, e] : [e, i];
1806
1806
  t.push({
1807
1807
  kind: "duplicate-fields",
@@ -1812,13 +1812,13 @@ $voltro_branch$`;
1812
1812
  });
1813
1813
  continue;
1814
1814
  }
1815
- Sc(i.fields, e.fields) ? t.push({
1815
+ Nc(i.fields, e.fields) ? t.push({
1816
1816
  kind: "redundant-prefix",
1817
1817
  table: r,
1818
1818
  redundant: i,
1819
1819
  coveredBy: e,
1820
1820
  message: `'${r}' index '${i.name}' on [${Q(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Q(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
1821
- }) : Sc(e.fields, i.fields) && t.push({
1821
+ }) : Nc(e.fields, i.fields) && t.push({
1822
1822
  kind: "redundant-prefix",
1823
1823
  table: r,
1824
1824
  redundant: e,
@@ -1828,23 +1828,23 @@ $voltro_branch$`;
1828
1828
  }
1829
1829
  }
1830
1830
  return t;
1831
- }, wc = (e) => {
1831
+ }, Fc = (e) => {
1832
1832
  let t = [];
1833
- for (let n of e) t.push(...Cc(n));
1833
+ for (let n of e) t.push(...Pc(n));
1834
1834
  return t;
1835
- }, Tc = "\x1B[", Ec = `${Tc}38;2;245;158;11m`, Dc = `${Tc}38;2;16;185;129m`, Oc = (e, t) => `${e}${t}${O.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : Oc(t, n) : n, kc = (e, t = {}) => {
1836
- let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, O.dim, e.padEnd(11)), a = (e) => $(n, (e) => O.bold(O.brand(e)), e), o = (e) => $(n, O.brightRed24, e), s = (e) => $(n, Dc, e), c = (e) => $(n, Ec, e), l = (e) => $(n, O.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, O.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
1835
+ }, Ic = "\x1B[", Lc = `${Ic}38;2;245;158;11m`, Rc = `${Ic}38;2;16;185;129m`, zc = (e, t) => `${e}${t}${A.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : zc(t, n) : n, Bc = (e, t = {}) => {
1836
+ let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, A.dim, e.padEnd(11)), a = (e) => $(n, (e) => A.bold(A.brand(e)), e), o = (e) => $(n, A.brightRed24, e), s = (e) => $(n, Rc, e), c = (e) => $(n, Lc, e), l = (e) => $(n, A.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, A.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
1837
1837
  let n = e.slice(0, t), r = e.slice(t), i = [];
1838
1838
  return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
1839
1839
  }, m = [];
1840
- return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n, O.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
1841
- }, Ac = (e, { apply: t, undo: n }) => ({
1840
+ return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n, A.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
1841
+ }, Vc = (e, { apply: t, undo: n }) => ({
1842
1842
  name: e,
1843
1843
  apply: t,
1844
1844
  undo: n
1845
- }), jc = (e) => {
1845
+ }), Hc = (e) => {
1846
1846
  if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
1847
- let t = e.steps({ step: Ac });
1847
+ let t = e.steps({ step: Vc });
1848
1848
  if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
1849
1849
  return {
1850
1850
  __migration: !0,
@@ -1852,89 +1852,42 @@ $voltro_branch$`;
1852
1852
  name: e.name,
1853
1853
  steps: t
1854
1854
  };
1855
- }, Mc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Nc = Zt.tableName, Pc = (e) => fr("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), Fc = async (e, t) => {
1856
- let [n] = await e.query({
1857
- table: Nc,
1858
- predicate: Xe("id", Pc(t)),
1855
+ }, Uc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Wc = ft.tableName, Gc = (e) => xr("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), Kc = async (t, n) => {
1856
+ let [r] = await t.query({
1857
+ table: Wc,
1858
+ predicate: e("id", Gc(n)),
1859
1859
  order: [],
1860
1860
  take: 1,
1861
1861
  skip: void 0,
1862
1862
  projection: void 0
1863
- }), r = n?.tenantId;
1864
- return typeof r == "string" ? r : null;
1865
- }, Ic = async (e, t, n) => {
1866
- await e.upsert(Nc, {
1867
- id: Pc(t),
1863
+ }), i = r?.tenantId;
1864
+ return typeof i == "string" ? i : null;
1865
+ }, qc = async (e, t, n) => {
1866
+ await e.upsert(Wc, {
1867
+ id: Gc(t),
1868
1868
  subjectType: t.type,
1869
1869
  subjectId: t.id,
1870
1870
  tenantId: n,
1871
1871
  selectedAt: /* @__PURE__ */ new Date()
1872
1872
  }, { conflictColumns: ["id"] });
1873
- }, Lc = async (e, t) => {
1874
- await e.delete(Nc, Pc(t));
1875
- }, Rc = "_voltro_replace_in_progress", zc = x(Rc, {
1876
- id: S({ prefix: "repl" }),
1877
- startedAt: y().default("now"),
1878
- kind: C().default("replace"),
1879
- tables: C().nullable(),
1880
- capture: C().nullable(),
1881
- via: C(),
1882
- staging: C().nullable(),
1883
- heartbeatAt: y().nullable(),
1884
- resumable: ot().nullable()
1885
- }), Bc = 30, Vc = (e, t) => {
1886
- let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
1887
- return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
1888
- }, Hc = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), Uc = (e) => {
1889
- let t = e.filter((e) => e.kind !== "staging");
1890
- if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
1891
- ${t.map((e) => {
1892
- let t = Number.isFinite(e.startedAt.getTime()) ? `${Math.max(0, Math.round((Date.now() - e.startedAt.getTime()) / 6e4))} minute(s) ago` : "at an unknown time";
1893
- if (e.kind === "restore") return ` - a native \`restore\` over ${e.via} began loading an artefact over this database ${t}\n and never reported finishing.\n` + (e.capture === null ? " The artefact it was loading was not recorded. Re-run the restore from your backup\n directory, or restore from another backup." : ` The artefact it was loading:\n ${e.capture}\n Re-run it to completion with: voltro data restore ${e.capture} --allow-live`);
1894
- let n = e.tables === null ? "this database" : `${e.tables} table(s)`;
1895
- return ` - a \`replace\` over ${e.via} began emptying ${n} ${t} and never reported finishing.\n` + (e.capture === null ? " NO capture was taken for that run, so the previous rows are not recoverable from here.\n Restore from your own backup." : ` The target's previous rows were captured first:\n ${e.capture}\n Restore them with: voltro data import ${e.capture} --mode replace`);
1896
- }).join("\n")}\n
1897
- A half-replaced database is indistinguishable from an empty one from the inside — every table
1898
- exists, every constraint holds, and every query returns nothing without erroring. That is why
1899
- this is a refusal and not a warning.
1900
-
1901
- When the data is back, or you have decided the current state is correct, clear the marker:
1902
- voltro data clear-replace-marker --yes`;
1903
- }, Wc = (e, t, n) => {
1904
- let r = e.filter((e) => e.kind === "staging");
1905
- return {
1906
- all: r,
1907
- droppable: r.filter((e) => {
1908
- if (e.resumable) return !1;
1909
- let r = (e.heartbeatAt ?? e.startedAt).getTime();
1910
- return Number.isFinite(r) ? t - r >= n : !1;
1911
- })
1912
- };
1913
- }, Gc = (e, t) => {
1914
- if (e.all.length === 0) return;
1915
- let n = new Set(e.droppable.map((e) => e.id));
1916
- return `staged data-import leftovers:
1917
- ${e.all.map((e) => {
1918
- let r = e.heartbeatAt ?? e.startedAt, i = Number.isFinite(r.getTime()) ? `${Math.max(0, Math.round((t - r.getTime()) / 6e4))} minute(s) ago` : "at an unknown time", a = `${e.staging.length} staging table(s) from a \`replace\` over ${e.via}, last active ${i}`;
1919
- return n.has(e.id) ? ` - ${a} — DROPPED: the run is not resumable and has been silent long enough that nothing is loading into them.` : e.resumable ? ` - ${a} — KEPT: the run was started \`--no-atomic\`, so these ARE its resume point. Re-run the same\n bundle to continue from them, or drop them with: voltro data clear-staging --yes` : ` - ${a} — KEPT: still beating, so an import is loading into them right now.`;
1920
- }).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
1921
- a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
1922
- }, Kc = "id", qc = (e, t) => {
1923
- let n = pt(e);
1873
+ }, Jc = async (e, t) => {
1874
+ await e.delete(Wc, Gc(t));
1875
+ }, Yc = "id", Xc = (e, t) => {
1876
+ let n = ln(e);
1924
1877
  if (n === void 0) return t;
1925
- let r = n.fields[Kc]?.idScheme;
1926
- if (r === void 0 || t[Kc] != null) return t;
1878
+ let r = n.fields[Yc]?.idScheme;
1879
+ if (r === void 0 || t[Yc] != null) return t;
1927
1880
  if (r.kind === "numeric") {
1928
- if (!(Kc in t)) return t;
1881
+ if (!(Yc in t)) return t;
1929
1882
  let e = { ...t };
1930
- return delete e[Kc], e;
1883
+ return delete e[Yc], e;
1931
1884
  }
1932
- let i = ze(r, e);
1885
+ let i = Xt(r, e);
1933
1886
  return i === null ? t : {
1934
1887
  ...t,
1935
- [Kc]: i
1888
+ [Yc]: i
1936
1889
  };
1937
- }, Jc = (e, t) => t.map((t) => qc(e, t)), Yc = {
1890
+ }, Zc = (e, t) => t.map((t) => Xc(e, t)), Qc = {
1938
1891
  postgres: { maxBindParameters: 65535 },
1939
1892
  mysql: { maxBindParameters: 65535 },
1940
1893
  mariadb: { maxBindParameters: 65535 },
@@ -1944,25 +1897,25 @@ ${e.all.map((e) => {
1944
1897
  },
1945
1898
  sqlite: { maxBindParameters: 32766 },
1946
1899
  turso: { maxBindParameters: 32766 }
1947
- }, Xc = (e) => Yc[e], Zc = (e) => {
1900
+ }, $c = (e) => Qc[e], el = (e) => {
1948
1901
  let t = /* @__PURE__ */ new Set();
1949
1902
  for (let n of e) for (let e of Object.keys(n)) t.add(e);
1950
1903
  return t.size;
1951
- }, Qc = (e, t) => {
1904
+ }, tl = (e, t) => {
1952
1905
  if (t === void 0 || e.length === 0) return [e];
1953
- let n = Math.max(1, Zc(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
1906
+ let n = Math.max(1, el(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
1954
1907
  if (e.length <= a) return [e];
1955
1908
  let o = [];
1956
1909
  for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
1957
1910
  return o;
1958
- }, $c = (e, t) => {
1911
+ }, nl = (e, t) => {
1959
1912
  let n = [], r = t;
1960
1913
  for (let [t, i] of Object.entries(e.fields)) {
1961
1914
  let e = i;
1962
1915
  e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
1963
1916
  }
1964
1917
  return n;
1965
- }, el = (e, t, n) => {
1918
+ }, rl = (e, t, n) => {
1966
1919
  let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
1967
1920
  for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
1968
1921
  column: e,
@@ -1972,36 +1925,36 @@ ${e.all.map((e) => {
1972
1925
  reason: "null"
1973
1926
  }));
1974
1927
  return a;
1975
- }, tl = (e, t, n) => e.insert(t.tableName, n), nl = (e, t, n) => e.insertMany(t.tableName, n), rl = (e, t, n, r) => e.upsert(t.tableName, n, {
1928
+ }, il = (e, t, n) => e.insert(t.tableName, n), al = (e, t, n) => e.insertMany(t.tableName, n), ol = (e, t, n, r) => e.upsert(t.tableName, n, {
1976
1929
  conflictColumns: r.conflictColumns,
1977
1930
  ...r.update === void 0 ? {} : { update: r.update },
1978
1931
  ...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
1979
- }), il = async (e, t, n, r) => {
1980
- if (e.upsertWithOutcome === void 0) throw Error("upsertRowOutcome: this store does not implement `upsertWithOutcome`. It is provided by the framework's store wrapper, so `ctx.store` has it; a hand-written DataStore must add it.");
1932
+ }), sl = async (e, t, n, r) => {
1933
+ if (e.upsertWithOutcome === void 0) throw y("upsertRowOutcome: this store does not implement `upsertWithOutcome`. It is provided by the framework's store wrapper, so `ctx.store` has it; a hand-written DataStore must add it.");
1981
1934
  return e.upsertWithOutcome(t.tableName, n, {
1982
1935
  conflictColumns: r.conflictColumns,
1983
1936
  ...r.update === void 0 ? {} : { update: r.update },
1984
1937
  ...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
1985
1938
  });
1986
- }, al = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), ol = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), sl = 512, cl = (e) => {
1939
+ }, cl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), ll = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), ul = 512, dl = (e) => {
1987
1940
  e.setMaxListeners(512);
1988
- }, ll = (e, t, n) => ({
1941
+ }, fl = (e, t, n) => ({
1989
1942
  _tag: "PrimaryKeyConflictError",
1990
1943
  table: e,
1991
1944
  key: t,
1992
1945
  cause: n
1993
- }), ul = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", dl = {
1946
+ }), pl = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", ml = {
1994
1947
  postgres: 5432,
1995
1948
  mysql: 3306,
1996
1949
  mariadb: 3306,
1997
1950
  mssql: 1433
1998
- }, fl = /* @__PURE__ */ new Set([
1951
+ }, hl = /* @__PURE__ */ new Set([
1999
1952
  "localhost",
2000
1953
  "127.0.0.1",
2001
1954
  "::1",
2002
1955
  "[::1]",
2003
1956
  "0.0.0.0"
2004
- ]), pl = (e) => {
1957
+ ]), gl = (e) => {
2005
1958
  let t = e.host, n = e.port, r = e.database;
2006
1959
  if (e.url !== void 0 && e.url !== "") try {
2007
1960
  let i = new URL(e.url);
@@ -2010,29 +1963,29 @@ ${e.all.map((e) => {
2010
1963
  return;
2011
1964
  }
2012
1965
  if (t === void 0 || t === "" || r === void 0 || r === "") return;
2013
- let i = n ?? dl[(e.dialect ?? "").toLowerCase()];
1966
+ let i = n ?? ml[(e.dialect ?? "").toLowerCase()];
2014
1967
  if (i === void 0 || !Number.isFinite(i)) return;
2015
1968
  let a = t.toLowerCase();
2016
1969
  return {
2017
- host: fl.has(a) ? "localhost" : a,
1970
+ host: hl.has(a) ? "localhost" : a,
2018
1971
  port: i,
2019
1972
  database: r.toLowerCase()
2020
1973
  };
2021
- }, ml = (e) => {
2022
- let t = pl(e);
2023
- if (t !== void 0) return fr("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
2024
- }, hl = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", gl = {
1974
+ }, _l = (e) => {
1975
+ let t = gl(e);
1976
+ if (t !== void 0) return xr("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
1977
+ }, vl = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", yl = {
2025
1978
  app: 3,
2026
1979
  plugin: 2,
2027
1980
  framework: 1
2028
- }, _l = /* @__PURE__ */ new Map(), vl = [], yl = () => [...vl], bl = (e) => {
1981
+ }, bl = /* @__PURE__ */ new Map(), xl = [], Sl = () => [...xl], Cl = (e) => {
2029
1982
  if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
2030
1983
  if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
2031
- let t = e.source ?? "app", n = _l.get(e.table);
1984
+ let t = e.source ?? "app", n = bl.get(e.table);
2032
1985
  if (n !== void 0) {
2033
1986
  let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
2034
- if (gl[t] < gl[r]) {
2035
- i && vl.push({
1987
+ if (yl[t] < yl[r]) {
1988
+ i && xl.push({
2036
1989
  table: e.table,
2037
1990
  kept: {
2038
1991
  source: r,
@@ -2045,7 +1998,7 @@ ${e.all.map((e) => {
2045
1998
  });
2046
1999
  return;
2047
2000
  }
2048
- i && r !== t && vl.push({
2001
+ i && r !== t && xl.push({
2049
2002
  table: e.table,
2050
2003
  kept: {
2051
2004
  source: t,
@@ -2057,13 +2010,13 @@ ${e.all.map((e) => {
2057
2010
  }
2058
2011
  });
2059
2012
  }
2060
- _l.set(e.table, {
2013
+ bl.set(e.table, {
2061
2014
  ...e,
2062
2015
  source: t
2063
2016
  });
2064
- }, xl = () => [..._l.values()], Sl = () => {
2065
- _l.clear(), vl.length = 0;
2066
- }, Cl = async (e, t, n, r = 2e4) => {
2017
+ }, wl = () => [...bl.values()], Tl = () => {
2018
+ bl.clear(), xl.length = 0;
2019
+ }, El = async (e, t, n, r = 2e4) => {
2067
2020
  let i = new Date(t - e.ttlMs), a = 0;
2068
2021
  try {
2069
2022
  for (;;) {
@@ -2071,45 +2024,45 @@ ${e.all.map((e) => {
2071
2024
  if (a += t, t < r) break;
2072
2025
  }
2073
2026
  } catch (t) {
2074
- throw w.runSync(T.increment(T.tagged(Tl, "table", e.table))), t;
2027
+ throw E.runSync(D.increment(D.tagged(Ol, "table", e.table))), t;
2075
2028
  }
2076
- return a > 0 && w.runSync(T.incrementBy(T.tagged(wl, "table", e.table), a)), a;
2077
- }, wl = T.counter("voltro_retention_swept_rows_total"), Tl = T.counter("voltro_retention_sweep_errors_total"), El = (e, t) => {
2029
+ return a > 0 && E.runSync(D.incrementBy(D.tagged(Dl, "table", e.table), a)), a;
2030
+ }, Dl = D.counter("voltro_retention_swept_rows_total"), Ol = D.counter("voltro_retention_sweep_errors_total"), kl = (e, t) => {
2078
2031
  let n = Number(e ?? String(t));
2079
2032
  return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
2080
- }, Dl = "_voltro_cdc_offsets", Ol = x(Dl, {
2081
- id: S({ prefix: "cdcoff" }),
2082
- replicaId: C(),
2083
- streamName: C(),
2084
- binlogFile: C(),
2085
- binlogPosition: C(),
2086
- updatedAt: y()
2087
- }).index(["replicaId"]), kl = x(Dl, {
2088
- id: S({ prefix: "cdcoff" }),
2089
- replicaId: C(),
2090
- streamName: C(),
2091
- ctVersion: C(),
2092
- updatedAt: y()
2093
- }).index(["replicaId"]), Al = "_voltro_data_transfers", jl = x(Al, {
2094
- id: S({ prefix: "dimp" }),
2095
- startedAt: y().default("now"),
2096
- finishedAt: y().nullable(),
2097
- direction: C().default("import"),
2098
- mode: C(),
2099
- via: C(),
2100
- bundle: C().nullable(),
2101
- sourceFingerprint: C().nullable(),
2102
- tablesWritten: Pn().default(0),
2103
- rowsWritten: Pn().default(0),
2104
- failure: C().nullable(),
2105
- staged: ot().nullable()
2106
- }).renamedFrom("_voltro_data_imports").nonReactive(), Ml = (e) => {
2033
+ }, Al = "_voltro_cdc_offsets", jl = S(Al, {
2034
+ id: C({ prefix: "cdcoff" }),
2035
+ replicaId: b(),
2036
+ streamName: b(),
2037
+ binlogFile: b(),
2038
+ binlogPosition: b(),
2039
+ updatedAt: x()
2040
+ }).index(["replicaId"]), Ml = S(Al, {
2041
+ id: C({ prefix: "cdcoff" }),
2042
+ replicaId: b(),
2043
+ streamName: b(),
2044
+ ctVersion: b(),
2045
+ updatedAt: x()
2046
+ }).index(["replicaId"]), Nl = "_voltro_data_transfers", Pl = S(Nl, {
2047
+ id: C({ prefix: "dimp" }),
2048
+ startedAt: x().default("now"),
2049
+ finishedAt: x().nullable(),
2050
+ direction: b().default("import"),
2051
+ mode: b(),
2052
+ via: b(),
2053
+ bundle: b().nullable(),
2054
+ sourceFingerprint: b().nullable(),
2055
+ tablesWritten: $n().default(0),
2056
+ rowsWritten: $n().default(0),
2057
+ failure: b().nullable(),
2058
+ staged: Tt().nullable()
2059
+ }).renamedFrom("_voltro_data_imports").nonReactive(), Fl = (e) => {
2107
2060
  let t = Number.isFinite(e.startedAt.getTime()) ? e.startedAt.toISOString() : "an unknown time", n = e.direction === "import" ? e.mode : `${e.direction} ${e.mode}`, r = e.failure === null ? e.finishedAt === null ? `${n} — started and never reported finishing` : e.direction === "backup" || e.direction === "restore" ? `${n} — finished${e.rowsWritten > 0 ? ` (${e.rowsWritten} blob(s))` : ""}` : `${n} — ${e.rowsWritten} row(s) across ${e.tablesWritten} table(s)` : `FAILED ${n} — ${e.failure}`, i = e.staged === null ? "" : e.staged ? " · staged (target untouched until the swap)" : " · NOT staged (target emptied first)";
2108
2061
  return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
2109
- }, Nl = 255, Pl = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(Pl).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${Pl(t)}`).join(",")}}` : JSON.stringify(String(e)), Fl = (e) => {
2062
+ }, Il = 255, Ll = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(Ll).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${Ll(t)}`).join(",")}}` : JSON.stringify(String(e)), Rl = (e) => {
2110
2063
  if (e == null) return null;
2111
- let t = typeof e == "string" ? e : Pl(e);
2064
+ let t = typeof e == "string" ? e : Ll(e);
2112
2065
  return t.length > 255 ? t.slice(0, 255) : t;
2113
- }, Il = "postgres";
2066
+ }, zl = "postgres";
2114
2067
  //#endregion
2115
- export { tn as AUTO_FILLED_COLUMNS, Cr as BOUND_ENCRYPTED_PREFIX, Yc as BULK_INSERT_LIMITS, Y as BranchNameInvalid, Gs as BranchTransitionInvalid, Dl as CDC_OFFSETS_TABLE, io as CHANGE_CLAIM_TTL_ENV, sl as CHANGE_LISTENER_CEILING, vn as ColumnBuilder, Al as DATA_TRANSFERS_TABLE, Nn as DEFAULT_ACQUIRE_TIMEOUT_MS, ao as DEFAULT_CHANGE_CLAIM_TTL_HOURS, rs as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, wt as DEFAULT_SOFT_DROP_RETENTION_DAYS, fi as DEFAULT_SUBJECT_GRAPH_DEPTH, Sr as ENCRYPTED_PREFIX, Il as ENGINE, ji as EagerCardinalityError, Un as FILE_MIGRATION_PATTERN, jt as FRAMEWORK_LIVE_TABLES, Er as FieldDecryptionError, Do as ID_COLUMN_MAX_LENGTH, nr as INITIAL_VERSION, Re as IrreversibleMigrationError, _e as MATCHES_NO_ROWS, g as MAX_IDENTIFIER_LENGTH, bs as MSSQL_TRANSIENT_NUMBERS, vs as MYSQL_TRANSIENT_CODES, l as MigrationExpectationFailed, Bn as MigrationSkipped, ro as OccurrenceCounter, ys as POSTGRES_TRANSIENT_STATES, Rc as REPLACE_IN_PROGRESS_TABLE, Ve as RewriteUnstableError, Nl as SCOPE_KEY_MAX_LENGTH, fe as SELF_REFERENCE_TARGET, xs as SQLITE_TRANSIENT_CODES, Bc as STAGING_STALE_MINUTES, pn as STAGING_TABLE_PREFIX, hr as SqlClient, Nc as TENANT_SELECTIONS_TABLE, Ss as TURSO_TRANSIENT_MESSAGE, Ns as TableStreamError, zn as TenantNamespaceInvalid, Jn as TenantNamespaceUnresolved, uc as TenantRegionUnavailable, lc as TenantResidencyUnresolved, fs as TransactionAbortedError, h as TransactionBrokenByBodyError, Ds as VOLTRO_EXPIRES_MIXIN_ID, ks as VOLTRO_LOCAL_FIRST_MIXIN_ID, $n as VersionConflict, p as WARN_IDENTIFIER_LENGTH, On as _voltroApiKeysTable, Ol as _voltroCdcOffsetsTable, jl as _voltroDataTransfersTable, an as _voltroDevicesTable, bn as _voltroIdempotencyTable, Vt as _voltroKvTable, ft as _voltroMigrationPlansTable, ln as _voltroMigrationsTable, kl as _voltroMssqlCdcOffsetsTable, zc as _voltroReplaceInProgressTable, wn as _voltroReplicaObservationsTable, bt as _voltroSeedsTable, Zt as _voltroTenantSelectionsTable, qa as actorsTable, ic as admitBranch, en as agedSoftDropSnapshots, Je as allEnumRenames, li as allRegisteredRelations, on as allRegisteredTables, Fe as and, ki as applyJsonPatch, rt as array, Yn as arrayContains, o as arrayHas, qe as arrayOverlaps, Ni as attachEagerLoads, uo as attributionFields, ho as attributionKey, wc as auditAllTableIndexes, Cc as auditTableIndexes, Se as avg, Te as avgOver, So as beginLocalWrite, et as bigint, vc as bindResidentStore, ot as boolean, Hs as branchNamespaceName, Xc as bulkInsertLimitsFor, Ne as bytes, we as causeBranches, Za as changeDelete, eo as changeDigest, Ya as changeInsert, Qa as changeSoftDelete, Xa as changeUpdate, Qc as chunkRowsForInsert, vo as claimPendingAttribution, Ae as classifyConstraintViolation, oe as clearEnumRenames, To as clearPendingAttribution, di as clearRelationsRegistry, mc as clearResidencyConfig, Sl as clearRetentions, xn as clearTableRegistry, Po as clearWriteRecorders, B as coercePredicateForSqlite, It as coercePredicateValue, dt as coercePredicateValues, za as coerceValueForSqlite, ae as collectSubqueries, je as column, Vr as columnSchema, Zc as columnsPerRow, Dt as compareDecimal, Wi as compileEagerJson, Ai as compileJsonPatch, b as compilePredicate, gn as compileRawFragment, rn as compileSelect, to as composeChangeKey, Rs as computeEmbedding, ml as connectionIdentity, We as contains, ne as count, ue as countDistinct, t as crdtDoc, kt as crdtManagedColumns, An as crdtManagedColumnsOf, sn as crdtText, lo as currentWriteAttribution, ye as databaseHandle, Sn as date, Ut as dbEnum, Zo as dbMetricTagCacheSizeForTests, es as dbOperationsInFlight, mt as decimal, Ge as declareEnumRename, jr as decodeFieldValue, Ue as decodeRowsForTable, ee as decodeRowsFromSchema, Lr as decryptFieldsOnRead, jc as defineMigration, Ln as defineMixin, Gt as defineSeed, Lc as deleteTenantSelection, Le as denseRank, yi as deriveSubjectGraph, Wn as deriveTypeIdPrefix, Ao as derivedRowId, jo as derivedRowIdLength, Lt as describeAgedSoftDropSnapshots, te as describeDriverError, le as describeRowBindings, Ml as describeTransferRun, xr as deserializeArraysOnRead, De as drainIdentifierWarnings, dn as dropped, kr as encodeFieldValue, m as encodeRowForSchema, Ir as encryptFieldsForWrite, Pr as encryptedColumnsOf, Co as endLocalWrite, tc as enforceBranchLimits, Ht as ensureTableRegistered, Xe as eq, Bt as escapeLike, re as evaluatePredicate, Zn as except, me as exists, Os as expires, Ja as externalChangeEvent, ve as extractDbCause, wr as fieldBinding, be as fireSchemaChangeSeeds, Ce as fireTenantCreateSeeds, kc as formatIndexAuditIssue, bi as formatSubjectGraph, Mn as frameworkTables, ze as generateId, Vn as generateSnowflake, En as geography, St as geometry, Ze as getEnumRenames, ci as getRelation, si as getRelations, pc as getResidencyConfig, pt as getTable, _n as gt, de as gte, Ui as hasEagerLoads, Ls as hybridSearch, S as id, nt as inSet, $e as inSubquery, k as inferForeignKey, al as insertIgnoreRowOutcome, nl as insertManyRows, tl as insertRow, Pn as integer, Uc as interruptedReplaceRefusal, c as intersect, Et as interval, f as irreversible, Ee as irreversibleReason, Tr as isBoundCiphertext, Us as isBranchNamespace, Ti as isCompositeRowKey, Yr as isEmptyRelationsSpec, Or as isEncrypted, Dr as isFieldDecryptionError, Jt as isFileMigration, Ie as isForeignKeyViolation, Pt as isFrameworkOwnedLiveTable, js as isLocalFirst, Mc as isMigrationDefinition, Tt as isMysqlFamily, Ys as isNeonConnection, at as isNotNull, Me as isNull, ul as isPrimaryKeyConflictError, Xn as isQueryTimeout, Mr as isRawEncoding, gc as isRegionServable, Xr as isRelationsSpec, ke as isSeedDefinition, ct as isSoftDropSnapshotName, Mt as isSqliteFamily, In as isStagingTableName, un as isTableReactive, hs as isTransactionAbortedError, Ts as isTransientContention, Oe as isView, Nt as json, e as jsonField, Rt as jsonIndex, Ei as jsonPatchAssignments, Ye as lag, se as lead, yl as listRetentionConflicts, xl as listRetentions, As as localFirst, Ms as localFirstTables, At as lt, jn as lte, os as makeEagerFallbackReporter, cc as makeNamespaceBranchExecutor, ps as makeTransactionAbortTracker, Qr as many, $r as manyToMany, hn as materializeFields, Ke as max, r as migration, Qe as min, el as missingConflictColumns, $c as missingRequiredColumns, Kn as mixin, cn as neq, Ks as nextBranchState, pl as normaliseTarget, Oi as normalizeJsonPatchValue, Cn as not, Wt as notExists, ht as notInSet, fn as notInSubquery, nn as numeric, ns as observeDbOp, oo as occurrenceWindowMs, Zr as one, Mi as oneCardinalityMessage, Dn as or, v as orderClausesOf, ge as paginateBy, yn as paginateById, no as parseChangeKey, Eo as pendingAttributionCount, $s as planBranch, qs as planBranchProvision, Js as planBranchTeardown, ec as planBranchTeardownFor, Zs as planNeonBranchProvision, Qs as planNeonBranchTeardown, Qn as planVersionedUpdate, ie as pluginRef, he as pluginRefSpecOf, ll as primaryKeyConflictError, nc as provisionBranch, yc as provisionResidentTenant, yt as qualifyTable, pe as queryFor, Xt as queryForView, mn as quoteIdent, cl as raiseChangeListenerCeiling, it as rank, zt as raw, Fc as readTenantSelection, Ft as readableByColumns, ut as real, ts as recordDbOp, Ro as recordsTable, Rn as reference, zr as refuseWrite, Ua as registerCoreTables, oi as registerDiscoveredRelations, _o as registerPendingAttribution, ai as registerRelations, bl as registerRetention, Tn as registerTable, Mo as registerWriteRecorder, Jr as relations, Ga as requireActors, xt as requireTable, Ka as requireTenants, Xo as resetDbMetricTagCacheForTests, He as resetSnowflake, _c as residentPlacement, _r as resolveActorSnapshot, Xs as resolveBranchMechanism, as as resolveEagerFallbackWarnIntervalMs, wo as resolveEchoAttribution, tt as resolveFullTextIndex, u as resolveIdScheme, _t as resolveMixinGraph, hc as resolveTenantHome, Gn as resolveTenantNamespace, El as retentionTtlMsFromEnv, Ci as rowKeyColumns, wi as rowKeyIdentity, st as rowNumber, Hr as rowSchema, ds as runRetryingTransaction, ms as runSavepoint, _s as runStoreTransaction, co as runWithWriteAttribution, zo as runWriteRecorders, hl as sameDatabase, Be as sanitizeIdentifierFragment, Fl as scopeKeyOf, qn as selfReference, br as serializeArraysForWrite, vt as serverOnlyColumns, fc as setResidencyConfig, _ as setSchemaChangeSeedHook, ce as setTenantCreateSeedHook, ss as settleTransactionExit, tr as settleVersionedUpdate, gt as softDropSnapshotStamp, Ct as spatialPredicate, Gc as stagingLeftoverReport, Wc as stagingLeftovers, Hc as stagingNamesOf, Vc as stagingStaleAfterMs, qc as stampGeneratedId, Jc as stampGeneratedIds, $t as startsWith, Br as storeRefusalOf, Is as streamTable, Pe as sum, n as sumOver, Fo as suspendWriteRecorders, Io as suspendWriteRecordersEffect, Cl as sweepRetention, x as table, rc as teardownBranch, Pc as tenantSelectionId, C as text, y as timestamp, ir as timestampMs, er as timestampMsOrNull, us as transactionRetrySchedule, Ot as union, kn as unionAll, Qt as unregisterTable, No as unregisterWriteRecorder, ol as updateManyRow, rl as upsertRow, il as upsertRowOutcome, Si as upsertUpdatePatch, xi as upsertUpdateValues, Yt as validateColumnName, i as validateIndexName, ui as validateRegisteredRelations, ni as validateRelationConfig, Kt as validateTableName, xe as validateTypeIdPrefix, d as vector, lt as vectorDistanceToOpclass, zs as vectorEmbedding, rr as versionColumnOf, a as view, qt as viewSql, Fn as walkLeaves, s as wireSafeCause, fo as withCapturedAttribution, Lo as writeRecordersSuspended, Ic as writeTenantSelection };
2068
+ export { d as AUTO_FILLED_COLUMNS, Mr as BOUND_ENCRYPTED_PREFIX, Qc as BULK_INSERT_LIMITS, Y as BranchNameInvalid, nc as BranchTransitionInvalid, Al as CDC_OFFSETS_TABLE, ho as CHANGE_CLAIM_TTL_ENV, ul as CHANGE_LISTENER_CEILING, qt as ColumnBuilder, Nl as DATA_TRANSFERS_TABLE, tr as DEFAULT_ACQUIRE_TIMEOUT_MS, go as DEFAULT_CHANGE_CLAIM_TTL_HOURS, ms as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, er as DEFAULT_SOFT_DROP_RETENTION_DAYS, Ci as DEFAULT_SUBJECT_GRAPH_DEPTH, jr as ENCRYPTED_PREFIX, zl as ENGINE, Hi as EagerCardinalityError, $t as FILE_MIGRATION_PATTERN, bt as FRAMEWORK_LIVE_TABLES, Fr as FieldDecryptionError, Io as ID_COLUMN_MAX_LENGTH, dr as INITIAL_VERSION, r as IrreversibleMigrationError, ge as MATCHES_NO_ROWS, re as MAX_IDENTIFIER_LENGTH, js as MSSQL_TRANSIENT_NUMBERS, ks as MYSQL_TRANSIENT_CODES, Yt as MigrationExpectationFailed, Se as MigrationNeedsSqlClient, we as MigrationSkipped, mo as OccurrenceCounter, As as POSTGRES_TRANSIENT_STATES, Fn as REPLACE_IN_PROGRESS_TABLE, je as RewriteUnstableError, Il as SCOPE_KEY_MAX_LENGTH, vt as SELF_REFERENCE_TARGET, Ms as SQLITE_TRANSIENT_CODES, fn as STAGING_STALE_MINUTES, Zn as STAGING_TABLE_PREFIX, wr as SqlClient, Wc as TENANT_SELECTIONS_TABLE, Ns as TURSO_TRANSIENT_MESSAGE, Ws as TableStreamError, g as TenantNamespaceInvalid, Ae as TenantNamespaceUnresolved, xc as TenantRegionUnavailable, bc as TenantResidencyUnresolved, Cs as TransactionAbortedError, ne as TransactionBrokenByBodyError, Rs as VOLTRO_EXPIRES_MIXIN_ID, Bs as VOLTRO_LOCAL_FIRST_MIXIN_ID, cr as VersionConflict, de as WARN_IDENTIFIER_LENGTH, rn as _voltroApiKeysTable, jl as _voltroCdcOffsetsTable, Pl as _voltroDataTransfersTable, zn as _voltroDevicesTable, Dt as _voltroIdempotencyTable, Nt as _voltroKvTable, bn as _voltroMigrationPlansTable, cn as _voltroMigrationsTable, Ml as _voltroMssqlCdcOffsetsTable, Dn as _voltroReplaceInProgressTable, Vt as _voltroReplicaObservationsTable, Lt as _voltroSeedsTable, ft as _voltroTenantSelectionsTable, ro as actorsTable, hc as admitBranch, Ve as agedSoftDropSnapshots, Ie as allEnumRenames, bi as allRegisteredRelations, Ot as allRegisteredTables, wn as and, Bi as applyJsonPatch, vn as array, pe as arrayContains, ot as arrayHas, rt as arrayOverlaps, Wi as attachEagerLoads, bo as attributionFields, wo as attributionKey, Fc as auditAllTableIndexes, Pc as auditTableIndexes, y as authoredError, Ye as authoredMessageOf, $e as avg, le as avgOver, jo as beginLocalWrite, Nn as bigint, kc as bindResidentStore, Tt as boolean, $s as branchNamespaceName, $c as bulkInsertLimitsFor, on as bytes, tt as causeBranches, so as changeDelete, uo as changeDigest, ao as changeInsert, co as changeSoftDelete, oo as changeUpdate, tl as chunkRowsForInsert, Do as claimPendingAttribution, oe as classifyConstraintViolation, t as clearEnumRenames, Po as clearPendingAttribution, Si as clearRelationsRegistry, Tc as clearResidencyConfig, Tl as clearRetentions, Pt as clearTableRegistry, Uo as clearWriteRecorders, V as coercePredicateForSqlite, qe as coercePredicateValue, te as coercePredicateValues, Ya as coerceValueForSqlite, lt as collectSubqueries, Xe as column, Xr as columnSchema, el as columnsPerRow, St as compareDecimal, ea as compileEagerJson, Vi as compileJsonPatch, T as compilePredicate, We as compileRawFragment, p as compileSelect, fo as composeChangeKey, Ys as computeEmbedding, _l as connectionIdentity, Fe as contains, nt as count, se as countDistinct, Vn as crdtDoc, kt as crdtManagedColumns, Ft as crdtManagedColumnsOf, Sn as crdtText, yo as currentWriteAttribution, ve as databaseHandle, un as date, Ut as dbEnum, cs as dbMetricTagCacheSizeForTests, ds as dbOperationsInFlight, zt as decimal, jt as declareEnumRename, Br as decodeFieldValue, Pe as decodeRowsForTable, ie as decodeRowsFromSchema, Kr as decryptFieldsOnRead, Hc as defineMigration, m as defineMixin, s as defineSeed, Jc as deleteTenantSelection, En as denseRank, Ai as deriveSubjectGraph, i as deriveTypeIdPrefix, zo as derivedRowId, Bo as derivedRowIdLength, u as describeAgedSoftDropSnapshots, _e as describeDriverError, Tn as describeRowBindings, Fl as describeTransferRun, Ar as deserializeArraysOnRead, be as drainIdentifierWarnings, mt as dropped, Rr as encodeFieldValue, fe as encodeRowForSchema, Gr as encryptFieldsForWrite, Ur as encryptedColumnsOf, Mo as endLocalWrite, fc as enforceBranchLimits, xn as ensureTableRegistered, e as eq, Xn as escapeLike, Mt as evaluatePredicate, he as except, Rn as exists, zs as expires, io as externalChangeEvent, me as extractDbCause, Nr as fieldBinding, Ze as fireSchemaChangeSeeds, ce as fireTenantCreateSeeds, Bc as formatIndexAuditIssue, ji as formatSubjectGraph, Un as frameworkTables, Xt as generateId, Te as generateSnowflake, Gn as geography, nr as geometry, Ln as getEnumRenames, yi as getRelation, vi as getRelations, wc as getResidencyConfig, ln as getTable, hn as gt, An as gte, $i as hasEagerLoads, Js as hybridSearch, C as id, Jt as inSet, yt as inSubquery, li as inferForeignKey, cl as insertIgnoreRowOutcome, al as insertManyRows, il as insertRow, $n as integer, Gt as interruptedReplaceRefusal, ct as intersect, Ue as interval, ue as irreversible, ye as irreversibleReason, Pr as isBoundCiphertext, ec as isBranchNamespace, Ii as isCompositeRowKey, ii as isEmptyRelationsSpec, Lr as isEncrypted, Ir as isFieldDecryptionError, Re as isFileMigration, st as isForeignKeyViolation, qn as isFrameworkOwnedLiveTable, Hs as isLocalFirst, Uc as isMigrationDefinition, xt as isMysqlFamily, oc as isNeonConnection, yn as isNotNull, Pn as isNull, pl as isPrimaryKeyConflictError, it as isQueryTimeout, Vr as isRawEncoding, Dc as isRegionServable, ai as isRelationsSpec, Je as isSeedDefinition, Ge as isSoftDropSnapshotName, Qn as isSqliteFamily, _ as isStagingTableName, Ht as isTableReactive, Es as isTransactionAbortedError, Is as isTransientContention, xe as isView, f as json, Et as jsonField, Jn as jsonIndex, Li as jsonPatchAssignments, at as lag, dt as lead, Sl as listRetentionConflicts, wl as listRetentions, Vs as localFirst, Us as localFirstTables, sn as lt, Hn as lte, _s as makeEagerFallbackReporter, yc as makeNamespaceBranchExecutor, ws as makeTransactionAbortTracker, si as many, ci as manyToMany, Yn as materializeFields, Le as max, ir as migration, n as min, rl as missingConflictColumns, nl as missingRequiredColumns, Oe as mixin, At as neq, rc as nextBranchState, gl as normaliseTarget, zi as normalizeJsonPatchValue, It as not, Cn as notExists, dn as notInSet, Wt as notInSubquery, Ke as numeric, ps as observeDbOp, _o as occurrenceWindowMs, oi as one, Ui as oneCardinalityMessage, Bt as or, w as orderClausesOf, In as paginateBy, pn as paginateById, po as parseChangeKey, Fo as pendingAttributionCount, uc as planBranch, ic as planBranchProvision, ac as planBranchTeardown, dc as planBranchTeardownFor, cc as planNeonBranchProvision, lc as planNeonBranchTeardown, sr as planVersionedUpdate, mn as pluginRef, kn as pluginRefSpecOf, fl as primaryKeyConflictError, pc as provisionBranch, Ac as provisionResidentTenant, nn as qualifyTable, On as queryFor, Be as queryForView, He as quoteIdent, dl as raiseChangeListenerCeiling, Kt as rank, ee as raw, Kc as readTenantSelection, h as readableByColumns, ke as real, fs as recordDbOp, Jo as recordsTable, tn as reference, Jr as refuseWrite, $a as registerCoreTables, _i as registerDiscoveredRelations, Eo as registerPendingAttribution, gi as registerRelations, Cl as registerRetention, Rt as registerTable, Vo as registerWriteRecorder, ri as relations, to as requireActors, pt as requireTable, no as requireTenants, ss as resetDbMetricTagCacheForTests, Me as resetSnowflake, Oc as residentPlacement, Er as resolveActorSnapshot, sc as resolveBranchMechanism, gs as resolveEagerFallbackWarnIntervalMs, No as resolveEchoAttribution, _t as resolveFullTextIndex, Ce as resolveIdScheme, en as resolveMixinGraph, Ec as resolveTenantHome, o as resolveTenantNamespace, kl as retentionTtlMsFromEnv, Pi as rowKeyColumns, Fi as rowKeyIdentity, _n as rowNumber, Zr as rowSchema, Ss as runRetryingTransaction, Ts as runSavepoint, Os as runStoreTransaction, vo as runWithWriteAttribution, Yo as runWriteRecorders, vl as sameDatabase, Qt as sanitizeIdentifierFragment, Rl as scopeKeyOf, a as selfReference, kr as serializeArraysForWrite, Zt as serverOnlyColumns, Cc as setResidencyConfig, et as setSchemaChangeSeedHook, ae as setTenantCreateSeedHook, vs as settleTransactionExit, ur as settleVersionedUpdate, De as softDropSnapshotStamp, ht as spatialPredicate, gt as stagingLeftoverReport, gn as stagingLeftovers, jn as stagingNamesOf, Ct as stagingStaleAfterMs, Xc as stampGeneratedId, Zc as stampGeneratedIds, Kn as startsWith, Yr as storeRefusalOf, qs as streamTable, Mn as sum, wt as sumOver, Go as suspendWriteRecorders, Ko as suspendWriteRecordersEffect, El as sweepRetention, S as table, mc as teardownBranch, Gc as tenantSelectionId, b as text, x as timestamp, pr as timestampMs, lr as timestampMsOrNull, xs as transactionRetrySchedule, an as union, Bn as unionAll, Wn as unregisterTable, Ho as unregisterWriteRecorder, ll as updateManyRow, ol as upsertRow, sl as upsertRowOutcome, Ni as upsertUpdatePatch, Mi as upsertUpdateValues, ze as validateColumnName, ar as validateIndexName, xi as validateRegisteredRelations, pi as validateRelationConfig, c as validateTableName, Qe as validateTypeIdPrefix, Ne as vector, v as vectorDistanceToOpclass, Xs as vectorEmbedding, fr as versionColumnOf, or as view, l as viewSql, rr as walkLeaves, ut as wireSafeCause, xo as withCapturedAttribution, qo as writeRecordersSuspended, qc as writeTenantSelection };