@voltro/database 0.18.0 → 0.19.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,16 +1,17 @@
1
1
  import { $ as e, A as t, At as n, B as r, C as i, Ct as a, D as o, Dt as s, E as c, Et as l, F as u, G as d, H as f, I as p, J as m, K as h, L as g, M as ee, Mt as _, N as v, Nt as y, O as b, Ot as x, P as te, Q as S, R as ne, S as re, St as C, T as ie, Tt as ae, U as w, V as oe, W as se, X as ce, Y as le, Z as ue, _ as de, _t as fe, a as pe, at as me, b as he, bt as ge, c as _e, ct as ve, d as ye, dt as be, et as xe, f as Se, ft as Ce, g as we, gt as Te, h as Ee, ht as De, i as T, it as Oe, j as ke, jt as E, k as Ae, kt as je, l as Me, lt as Ne, m as Pe, mt as Fe, n as Ie, nt as Le, o as Re, ot as ze, p as Be, pt as Ve, q as He, r as Ue, rt as We, s as Ge, st as Ke, t as qe, tt as Je, u as Ye, ut as Xe, v as Ze, vt as Qe, w as $e, wt as D, x as et, xt as O, y as tt, yt as nt, z as rt } from "./fileBased-Dfuv6JWP.js";
2
2
  import { timestampMs as it, timestampMsOrNull as at } from "./wire.js";
3
3
  import { Chunk as ot, Data as st, Effect as ct, Option as k, Schema as A, Stream as lt } from "effect";
4
+ import { AsyncLocalStorage as ut } from "node:async_hooks";
4
5
  import { ansi as j } from "@voltro/logger";
5
- import { SqlClient as ut } from "@effect/sql";
6
+ import { SqlClient as dt } from "@effect/sql";
6
7
  //#region src/arrayCodec.ts
7
- var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", ft = (e) => {
8
+ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", pt = (e) => {
8
9
  let t = [];
9
10
  for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
10
11
  return t;
11
- }, pt = (e, t, n) => {
12
- if (!dt(n) || !t) return e;
13
- let r = ft(t);
12
+ }, mt = (e, t, n) => {
13
+ if (!ft(n) || !t) return e;
14
+ let r = pt(t);
14
15
  if (r.length === 0) return e;
15
16
  let i = { ...e };
16
17
  for (let e of r) {
@@ -18,9 +19,9 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
18
19
  Array.isArray(t) && (i[e] = JSON.stringify(t));
19
20
  }
20
21
  return i;
21
- }, mt = (e, t, n) => {
22
- if (!dt(n) || !t) return e;
23
- let r = ft(t);
22
+ }, ht = (e, t, n) => {
23
+ if (!ft(n) || !t) return e;
24
+ let r = pt(t);
24
25
  return r.length === 0 ? e : e.map((e) => {
25
26
  let t;
26
27
  for (let n of r) {
@@ -32,7 +33,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
32
33
  }
33
34
  return t ?? e;
34
35
  });
35
- }, ht = "enc:v1:", gt = class extends Error {
36
+ }, gt = "enc:v1:", _t = class extends Error {
36
37
  _tag = "FieldDecryptionError";
37
38
  table;
38
39
  column;
@@ -40,33 +41,33 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
40
41
  constructor(e) {
41
42
  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;
42
43
  }
43
- }, _t = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", vt = (e) => typeof e == "string" && e.startsWith("enc:v1:"), yt = (e) => {
44
+ }, vt = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", yt = (e) => typeof e == "string" && e.startsWith("enc:v1:"), bt = (e) => {
44
45
  let t = [];
45
46
  for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
46
47
  return t;
47
- }, bt = (e, t, n) => {
48
+ }, xt = (e, t, n) => {
48
49
  if (!t) return e;
49
- let r = yt(t);
50
+ let r = bt(t);
50
51
  if (r.length === 0) return e;
51
52
  let i = { ...e };
52
53
  for (let e of r) {
53
54
  let r = i[e];
54
- if (!(r == null || vt(r))) {
55
+ if (!(r == null || yt(r))) {
55
56
  if (!n) throw Error(`column "${t.tableName ?? "?"}.${e}" is .encrypted() but no field cipher is registered — wire @voltro/plugin-governance's fieldEncryption (key via the Secrets-Resolver)`);
56
57
  i[e] = n.encrypt(JSON.stringify(r));
57
58
  }
58
59
  }
59
60
  return i;
60
- }, xt = (e, t, n, r) => {
61
+ }, St = (e, t, n, r) => {
61
62
  if (!t) return e;
62
- let i = yt(t);
63
+ let i = bt(t);
63
64
  if (i.length === 0 || !n) return e;
64
65
  let a = r?.onError ?? "throw", o = t.tableName ?? "?";
65
66
  return e.map((e) => {
66
67
  let t;
67
68
  for (let s of i) {
68
69
  let i = e[s];
69
- if (vt(i)) {
70
+ if (yt(i)) {
70
71
  t ??= { ...e };
71
72
  try {
72
73
  t[s] = JSON.parse(n.decrypt(i));
@@ -80,7 +81,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
80
81
  });
81
82
  continue;
82
83
  }
83
- throw new gt({
84
+ throw new _t({
84
85
  table: o,
85
86
  column: s,
86
87
  reason: n
@@ -90,7 +91,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
90
91
  }
91
92
  return t ?? e;
92
93
  });
93
- }, St = (e) => {
94
+ }, Ct = (e) => {
94
95
  let t = (() => {
95
96
  switch (e.type) {
96
97
  case "id":
@@ -111,37 +112,37 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
111
112
  }
112
113
  })();
113
114
  return e.nullable === !0 ? A.NullOr(t) : t;
114
- }, Ct = (e, t) => {
115
+ }, wt = (e, t) => {
115
116
  let n = new Set(t?.omit ?? []), r = {};
116
- for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = St(i));
117
+ for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Ct(i));
117
118
  return A.Struct(r);
118
- }, wt = (e) => typeof e == "function" ? e : () => e, Tt = (e, t) => ({
119
+ }, Tt = (e) => typeof e == "function" ? e : () => e, Et = (e, t) => ({
119
120
  kind: "one",
120
- target: wt(e),
121
+ target: Tt(e),
121
122
  ...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
122
123
  ...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
123
- }), Et = (e, t) => ({
124
+ }), Dt = (e, t) => ({
124
125
  kind: "many",
125
- target: wt(e),
126
+ target: Tt(e),
126
127
  ...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
127
128
  ...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
128
- }), Dt = (e, t) => ({
129
+ }), Ot = (e, t) => ({
129
130
  kind: "manyToMany",
130
- target: wt(e),
131
- through: wt(t.through),
131
+ target: Tt(e),
132
+ through: Tt(t.through),
132
133
  sourceKey: t.sourceKey,
133
134
  targetKey: t.targetKey
134
- }), Ot = {
135
- one: Tt,
136
- many: Et,
137
- manyToMany: Dt
138
- }, kt = (e, t) => {
135
+ }), kt = {
136
+ one: Et,
137
+ many: Dt,
138
+ manyToMany: Ot
139
+ }, At = (e, t) => {
139
140
  let n = typeof e == "function" ? e : () => e;
140
141
  return {
141
142
  source: n,
142
- relations: t(Ot, n())
143
+ relations: t(kt, n())
143
144
  };
144
- }, At = (e) => {
145
+ }, jt = (e) => {
145
146
  if (typeof e != "object" || !e) return !1;
146
147
  let t = e;
147
148
  if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
@@ -150,32 +151,32 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
150
151
  let t = e?.kind;
151
152
  return t === "one" || t === "many" || t === "manyToMany";
152
153
  });
153
- }, jt = Tt, Mt = Et, Nt = Dt, M = (e, t, n) => {
154
+ }, Mt = Et, Nt = Dt, Pt = Ot, M = (e, t, n) => {
154
155
  let r = [];
155
156
  for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
156
157
  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>' }.`);
157
158
  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.`);
158
159
  return r[0];
159
- }, Pt = (e) => Object.keys(e.fields), N = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Ft = (e) => {
160
- let t = Pt(e);
160
+ }, Ft = (e) => Object.keys(e.fields), N = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), It = (e) => {
161
+ let t = Ft(e);
161
162
  return t.length === 0 ? "<none>" : t.join(", ");
162
- }, It = (e, t, n) => {
163
+ }, Lt = (e, t, n) => {
163
164
  let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
164
165
  if (n.kind === "manyToMany") {
165
166
  let t = n.through();
166
- for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!N(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}': ${Ft(t)}.`);
167
+ for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!N(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}': ${It(t)}.`);
167
168
  return;
168
169
  }
169
170
  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.`);
170
171
  if (n.sourceKey !== void 0 && !N(e, n.sourceKey)) {
171
172
  let t = N(i, n.sourceKey);
172
- 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}': ${Ft(e)}.`));
173
+ 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}': ${It(e)}.`));
173
174
  }
174
175
  if (n.foreignKey !== void 0 && !N(i, n.foreignKey)) {
175
176
  let t = N(e, n.foreignKey);
176
- 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}': ${Ft(i)}.`));
177
+ 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}': ${It(i)}.`));
177
178
  }
178
- }, Lt = Symbol.for("@voltro/database/relationsRegistry"), Rt = globalThis, P = Rt[Lt] ?? (Rt[Lt] = /* @__PURE__ */ new Map()), zt = (e) => {
179
+ }, Rt = Symbol.for("@voltro/database/relationsRegistry"), zt = globalThis, P = zt[Rt] ?? (zt[Rt] = /* @__PURE__ */ new Map()), Bt = (e) => {
179
180
  let t = e.source(), n = P.get(t.tableName);
180
181
  if (n === void 0) {
181
182
  P.set(t.tableName, new Map(Object.entries(e.relations)));
@@ -185,14 +186,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
185
186
  if (n.has(r)) throw Error(`duplicate relation '${r}' on '${t.tableName}': two relations() blocks both declare it. Pick distinct names or merge them into one block.`);
186
187
  n.set(r, i);
187
188
  }
188
- }, Bt = (e) => {
189
+ }, Vt = (e) => {
189
190
  let t = 0;
190
- for (let n of Object.values(e)) At(n) && (zt(n), t += 1);
191
+ for (let n of Object.values(e)) jt(n) && (Bt(n), t += 1);
191
192
  return t;
192
- }, Vt = (e) => {
193
+ }, Ht = (e) => {
193
194
  let t = P.get(e);
194
195
  if (t !== void 0) return Object.fromEntries(t);
195
- }, Ht = (e, t) => P.get(e)?.get(t), Ut = () => {
196
+ }, Ut = (e, t) => P.get(e)?.get(t), Wt = () => {
196
197
  let e = [];
197
198
  for (let [t, n] of P) for (let [r, i] of n) e.push({
198
199
  source: t,
@@ -200,14 +201,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
200
201
  relation: i
201
202
  });
202
203
  return e;
203
- }, Wt = () => {
204
+ }, Gt = () => {
204
205
  for (let [e, t] of P) {
205
206
  let n = u(e);
206
- if (n !== void 0) for (let [e, r] of t) It(n, e, r);
207
+ if (n !== void 0) for (let [e, r] of t) Lt(n, e, r);
207
208
  }
208
- }, Gt = () => {
209
+ }, Kt = () => {
209
210
  P.clear();
210
- }, Kt = (e) => e == null || typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "bigint" ? e !== 0n : typeof e == "string" ? e === "1" || e.toLowerCase() === "true" : e, qt = (e) => {
211
+ }, qt = (e) => e == null || typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "bigint" ? e !== 0n : typeof e == "string" ? e === "1" || e.toLowerCase() === "true" : e, Jt = (e) => {
211
212
  if (e == null || typeof e != "string") return e;
212
213
  let t = e.trim();
213
214
  if (t.length === 0) return e;
@@ -218,7 +219,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
218
219
  } catch {
219
220
  return e;
220
221
  }
221
- }, Jt = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Yt = (e) => {
222
+ }, Yt = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Xt = (e) => {
222
223
  if (e == null || e instanceof Date) return e;
223
224
  if (typeof e == "string") {
224
225
  let t = new Date(e);
@@ -229,19 +230,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
229
230
  return isNaN(t.getTime()) ? e : t;
230
231
  }
231
232
  return e;
232
- }, Xt = (e, t, n) => {
233
+ }, Zt = (e, t, n) => {
233
234
  if (e == null) return e;
234
235
  switch (t) {
235
- case "boolean": return n === "postgres" ? e : Kt(e);
236
+ case "boolean": return n === "postgres" ? e : qt(e);
236
237
  case "json":
237
- case "array": return n === "postgres" ? e : qt(e);
238
+ case "array": return n === "postgres" ? e : Jt(e);
238
239
  case "timestamp":
239
- case "date": return n === "sqlite" || n === "turso" ? Yt(e) : e;
240
+ case "date": return n === "sqlite" || n === "turso" ? Xt(e) : e;
240
241
  case "decimal":
241
- case "bigint": return Jt(e);
242
+ case "bigint": return Yt(e);
242
243
  default: return e;
243
244
  }
244
- }, Zt = (e, t, n) => {
245
+ }, Qt = (e, t, n) => {
245
246
  if (e.length === 0) return e;
246
247
  let r = u(t);
247
248
  if (r === void 0) return e;
@@ -252,36 +253,36 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
252
253
  });
253
254
  return e.map((e) => {
254
255
  let t = { ...e };
255
- for (let { key: e, type: r } of a) e in t && (t[e] = Xt(t[e], r, n));
256
+ for (let { key: e, type: r } of a) e in t && (t[e] = Zt(t[e], r, n));
256
257
  return t;
257
258
  });
258
- }, Qt = (e, t) => {
259
+ }, $t = (e, t) => {
259
260
  if (e == null) return e;
260
261
  switch (t) {
261
262
  case "json":
262
263
  case "array": return typeof e == "string" ? e : JSON.stringify(e);
263
264
  default: return e;
264
265
  }
265
- }, $t = (e, t, n = ["json", "array"]) => {
266
+ }, en = (e, t, n = ["json", "array"]) => {
266
267
  let r = u(t);
267
268
  if (r === void 0) return e;
268
269
  let i = r.fields, a = null;
269
270
  for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
270
- let n = Qt(e[t], r.type);
271
+ let n = $t(e[t], r.type);
271
272
  n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
272
273
  }
273
274
  return a ?? e;
274
- }, en = class extends Error {
275
+ }, tn = class extends Error {
275
276
  _tag = "EagerCardinalityError";
276
277
  constructor(e) {
277
278
  super(e), this.name = "EagerCardinalityError";
278
279
  }
279
- }, tn = (e) => {
280
+ }, nn = (e) => {
280
281
  let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
281
282
  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.");
282
- }, nn = async (e, t, n, r) => {
283
+ }, rn = async (e, t, n, r) => {
283
284
  if (e.length === 0) return e;
284
- let i = Vt(n.tableName);
285
+ let i = Ht(n.tableName);
285
286
  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?`);
286
287
  let a = e.map((e) => ({ ...e }));
287
288
  for (let [e, o] of Object.entries(t)) {
@@ -290,36 +291,36 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
290
291
  let t = Object.keys(i).join(", ") || "<none>";
291
292
  throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
292
293
  }
293
- It(n, e, t), await rn(a, e, t, o === !0 ? {} : o, n, r);
294
+ Lt(n, e, t), await an(a, e, t, o === !0 ? {} : o, n, r);
294
295
  }
295
296
  return a;
296
- }, rn = async (e, t, n, r, i, a) => {
297
+ }, an = async (e, t, n, r, i, a) => {
297
298
  switch (n.kind) {
298
299
  case "one":
299
- await an(e, t, n, r, i, a);
300
+ await on(e, t, n, r, i, a);
300
301
  return;
301
302
  case "many":
302
- await on(e, t, n, r, i, a);
303
+ await sn(e, t, n, r, i, a);
303
304
  return;
304
305
  case "manyToMany":
305
- await cn(e, t, n, r, i, a);
306
+ await ln(e, t, n, r, i, a);
306
307
  return;
307
308
  }
308
- }, an = async (e, t, n, r, i, a) => {
309
- let o = n.target(), s = n.sourceKey ?? ln(i, o.tableName);
309
+ }, on = async (e, t, n, r, i, a) => {
310
+ let o = n.target(), s = n.sourceKey ?? un(i, o.tableName);
310
311
  if (s !== void 0) {
311
- let n = F(e, s), i = n.length === 0 ? [] : await un(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
312
+ let n = F(e, s), i = n.length === 0 ? [] : await dn(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
312
313
  for (let n of e) {
313
314
  let e = n[s];
314
315
  n[t] = e == null ? null : c.get(e) ?? null;
315
316
  }
316
- await dn(i, r.with, o, a);
317
+ await fn(i, r.with, o, a);
317
318
  return;
318
319
  }
319
- let c = n.foreignKey ?? M(o, i.tableName, t), l = n.sourceKey ?? "id", u = F(e, l), d = u.length === 0 ? [] : await un(o, c, u, r, a), f = /* @__PURE__ */ new Map();
320
+ let c = n.foreignKey ?? M(o, i.tableName, t), l = n.sourceKey ?? "id", u = F(e, l), d = u.length === 0 ? [] : await dn(o, c, u, r, a), f = /* @__PURE__ */ new Map();
320
321
  for (let e of d) {
321
322
  let n = e[c];
322
- if (f.has(n)) throw new en(tn({
323
+ if (f.has(n)) throw new tn(nn({
323
324
  relationName: t,
324
325
  sourceTableName: i.tableName,
325
326
  targetTableName: o.tableName,
@@ -332,9 +333,9 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
332
333
  let e = n[l];
333
334
  n[t] = e == null ? null : f.get(e) ?? null;
334
335
  }
335
- await dn(d, r.with, o, a);
336
- }, on = async (e, t, n, r, i, a) => {
337
- let o = n.target(), s = n.foreignKey ?? M(o, i.tableName, t), c = n.sourceKey ?? "id", l = F(e, c), u = sn(r), d = l.length === 0 ? [] : await un(o, s, l, u, a), f = /* @__PURE__ */ new Map();
336
+ await fn(d, r.with, o, a);
337
+ }, sn = async (e, t, n, r, i, a) => {
338
+ let o = n.target(), s = n.foreignKey ?? M(o, i.tableName, t), c = n.sourceKey ?? "id", l = F(e, c), u = cn(r), d = l.length === 0 ? [] : await dn(o, s, l, u, a), f = /* @__PURE__ */ new Map();
338
339
  for (let e of d) {
339
340
  let t = e[s], n = f.get(t);
340
341
  n ? n.push(e) : f.set(t, [e]);
@@ -350,11 +351,11 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
350
351
  let e = n[c];
351
352
  n[t] = f.get(e) ?? [];
352
353
  }
353
- await dn(d, r.with, o, a);
354
- }, sn = (e) => {
354
+ await fn(d, r.with, o, a);
355
+ }, cn = (e) => {
355
356
  let { limit: t, offset: n, ...r } = e;
356
357
  return r;
357
- }, cn = async (e, t, n, r, i, a) => {
358
+ }, ln = async (e, t, n, r, i, a) => {
358
359
  let o = n.target(), s = n.through(), c = F(e, "id");
359
360
  if (c.length === 0) {
360
361
  for (let n of e) n[t] = [];
@@ -376,8 +377,8 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
376
377
  for (let n of e) n[t] = [];
377
378
  return;
378
379
  }
379
- let f = await un(o, "id", F(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
380
- await dn(f, r.with, o, a);
380
+ let f = await dn(o, "id", F(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
381
+ await fn(f, r.with, o, a);
381
382
  let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
382
383
  for (let e of d) {
383
384
  let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
@@ -389,7 +390,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
389
390
  o ? o.push(a) : h.set(t, [a]);
390
391
  }
391
392
  for (let n of e) n[t] = h.get(n.id) ?? [];
392
- }, ln = (e, t) => {
393
+ }, un = (e, t) => {
393
394
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
394
395
  }, F = (e, t) => {
395
396
  let n = /* @__PURE__ */ new Set();
@@ -398,7 +399,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
398
399
  e != null && n.add(e);
399
400
  }
400
401
  return [...n];
401
- }, un = (e, t, n, r, i) => {
402
+ }, dn = (e, t, n, r, i) => {
402
403
  let a = {
403
404
  column: t,
404
405
  op: "in",
@@ -412,37 +413,37 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
412
413
  skip: r.offset,
413
414
  projection: void 0
414
415
  });
415
- }, dn = async (e, t, n, r) => {
416
- t !== void 0 && e.length !== 0 && (await nn(e, t, n, r)).forEach((t, n) => {
416
+ }, fn = async (e, t, n, r) => {
417
+ t !== void 0 && e.length !== 0 && (await rn(e, t, n, r)).forEach((t, n) => {
417
418
  let r = e[n];
418
419
  for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
419
420
  });
420
- }, fn = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, pn = class extends Error {
421
+ }, pn = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, mn = class extends Error {
421
422
  _tag = "TenantNamespaceUnresolved";
422
423
  constructor(e) {
423
424
  super(e), this.name = "TenantNamespaceUnresolved";
424
425
  }
425
- }, mn = class extends Error {
426
+ }, hn = class extends Error {
426
427
  _tag = "TenantNamespaceInvalid";
427
428
  constructor(e) {
428
429
  super(e), this.name = "TenantNamespaceInvalid";
429
430
  }
430
- }, hn = 63, gn = "tenant_", _n = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), vn = (e) => {
431
- if (e == null || e === "") throw new pn("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
432
- let t = _n(e);
433
- if (t.replace(/_/g, "") === "") throw new mn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
434
- let n = `${gn}${t}`;
435
- if (n.length > hn) throw new mn(`namespace '${n}' for tenant '${e}' exceeds the ${hn}-byte identifier limit. Use a shorter tenant id.`);
431
+ }, gn = 63, _n = "tenant_", vn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), yn = (e) => {
432
+ if (e == null || e === "") throw new mn("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
433
+ let t = vn(e);
434
+ if (t.replace(/_/g, "") === "") throw new hn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
435
+ let n = `${_n}${t}`;
436
+ if (n.length > gn) throw new hn(`namespace '${n}' for tenant '${e}' exceeds the ${gn}-byte identifier limit. Use a shorter tenant id.`);
436
437
  return n;
437
- }, yn = (e, t) => e === null ? t : `${e}.${t}`, bn = /* @__PURE__ */ new Set(["timestamp", "date"]), xn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Sn = (e, t) => {
438
- if (e === void 0 || t == null || !bn.has(e) || t instanceof Date) return t;
438
+ }, bn = (e, t) => e === null ? t : `${e}.${t}`, xn = /* @__PURE__ */ new Set(["timestamp", "date"]), Sn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Cn = (e, t) => {
439
+ if (e === void 0 || t == null || !xn.has(e) || t instanceof Date) return t;
439
440
  if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
440
- if (typeof t == "string" && xn.test(t)) {
441
+ if (typeof t == "string" && Sn.test(t)) {
441
442
  let e = new Date(t);
442
443
  return Number.isNaN(e.getTime()) ? t : e;
443
444
  }
444
445
  return t;
445
- }, Cn = (e, t) => e === void 0 || !bn.has(e) ? t : t.map((t) => Sn(e, t)), wn = (e, t) => {
446
+ }, wn = (e, t) => e === void 0 || !xn.has(e) ? t : t.map((t) => Cn(e, t)), Tn = (e, t) => {
446
447
  let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
447
448
  for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
448
449
  return t`${i}`;
@@ -468,7 +469,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
468
469
  mssql: () => t.unsafe(T(i.column, o, "mssql", { numeric: !0 })),
469
470
  sqlite: () => t.unsafe(T(i.column, o, "sqlite", { numeric: !0 })),
470
471
  orElse: () => t.unsafe(T(i.column, o, "postgres", { numeric: !0 }))
471
- }), d = s ? c() : a, f = s ? l() : a, p = (e) => s && e != null ? String(e) : e, m = (e) => s ? Number(e) : e, h = s || r === void 0 ? void 0 : u(r)?.fields?.[i.column]?.type, g = (e) => Sn(h, e);
472
+ }), d = s ? c() : a, f = s ? l() : a, p = (e) => s && e != null ? String(e) : e, m = (e) => s ? Number(e) : e, h = s || r === void 0 ? void 0 : u(r)?.fields?.[i.column]?.type, g = (e) => Cn(h, e);
472
473
  switch (i.op) {
473
474
  case "eq": return t`${d} = ${p(g(i.value))}`;
474
475
  case "neq": return t`${d} <> ${p(g(i.value))}`;
@@ -542,13 +543,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
542
543
  });
543
544
  }
544
545
  }
545
- }, Tn = (e, t) => {
546
+ }, En = (e, t) => {
546
547
  let n = [];
547
548
  return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
548
- }, En = (e, t) => t.csv(e.map((e) => {
549
+ }, Dn = (e, t) => t.csv(e.map((e) => {
549
550
  let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
550
551
  if (e.op.startsWith("window-")) {
551
- let r = Tn(e.window ?? {}, t);
552
+ let r = En(e.window ?? {}, t);
552
553
  switch (e.op) {
553
554
  case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
554
555
  case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
@@ -572,39 +573,39 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
572
573
  return t`${t(e.column)} AS ${t(e.alias)}`;
573
574
  default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
574
575
  }
575
- })), Dn = (e) => `[${e.join(",")}]`, On = (e, t) => {
576
+ })), On = (e) => `[${e.join(",")}]`, kn = (e, t) => {
576
577
  if (e.queryVector === void 0) return null;
577
- let n = t(e.column), r = Dn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
578
+ let n = t(e.column), r = On(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
578
579
  return t.onDialectOrElse({
579
580
  mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
580
581
  mssql: () => t`NULL`,
581
582
  sqlite: () => t`NULL`,
582
583
  orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
583
584
  });
584
- }, kn = (e, t) => {
585
+ }, An = (e, t) => {
585
586
  let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
586
587
  return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
587
- }, An = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, jn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Mn = (e, t) => `${t}_${e.indexName}_fts`, Nn = (e, t, n) => {
588
+ }, jn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Mn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Nn = (e, t) => `${t}_${e.indexName}_fts`, Pn = (e, t, n) => {
588
589
  let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${I(e.query)}%`;
589
590
  return n.onDialectOrElse({
590
591
  mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
591
592
  sqlite: () => {
592
- let r = n(Mn(e, t));
593
+ let r = n(Nn(e, t));
593
594
  return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
594
595
  },
595
596
  mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
596
- orElse: () => n`${jn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
597
+ orElse: () => n`${Mn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
597
598
  });
598
- }, Pn = (e, t, n) => {
599
+ }, Fn = (e, t, n) => {
599
600
  let r = `%${I(e.query)}%`;
600
601
  return n.onDialectOrElse({
601
602
  mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
602
603
  sqlite: () => {
603
- let r = n(Mn(e, t));
604
+ let r = n(Nn(e, t));
604
605
  return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
605
606
  },
606
607
  mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
607
- orElse: () => n`ts_rank(${jn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
608
+ orElse: () => n`ts_rank(${Mn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
608
609
  });
609
610
  }, R = (e, t, n = null) => {
610
611
  if (e.setOp && e.setOp.queries.length >= 2) {
@@ -619,7 +620,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
619
620
  }
620
621
  return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
621
622
  }
622
- let r = e.annClause === void 0 ? null : On(e.annClause, t);
623
+ let r = e.annClause === void 0 ? null : kn(e.annClause, t);
623
624
  e.spatialClause !== void 0 && t.onDialectOrElse({
624
625
  mysql: () => {
625
626
  throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
@@ -632,16 +633,16 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
632
633
  },
633
634
  orElse: () => t``
634
635
  });
635
- let i = e.spatialClause?.projectAs === void 0 ? null : kn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? En(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Pn(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
636
+ let i = e.spatialClause?.projectAs === void 0 ? null : An(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Dn(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Fn(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
636
637
  orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
637
638
  mysql: () => t`DISTINCT `,
638
639
  mssql: () => t`DISTINCT `,
639
640
  sqlite: () => t`DISTINCT `
640
- }) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(yn(n, e.table))}` : t`${t(yn(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
641
+ }) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(bn(n, e.table))}` : t`${t(bn(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
641
642
  let r = e.kind === "inner" ? "INNER" : "LEFT";
642
- return t` ${t.unsafe(r)} JOIN ${t(yn(n, e.table))} AS ${t(e.alias)} ON ${L(e.on, t, n)}`;
643
- }), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Nn(c, e.table, t), ee = [e.predicate ? L(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), _ = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, v = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, y = e.having ? t` HAVING ${L(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
644
- r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${An(e.spatialClause, t)} DESC` : t`${An(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
643
+ return t` ${t.unsafe(r)} JOIN ${t(bn(n, e.table))} AS ${t(e.alias)} ON ${L(e.on, t, n)}`;
644
+ }), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Pn(c, e.table, t), ee = [e.predicate ? L(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), _ = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, v = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, y = e.having ? t` HAVING ${L(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
645
+ r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${jn(e.spatialClause, t)} DESC` : t`${jn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
645
646
  for (let n of e.order) x.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
646
647
  let te = x.length > 0 ? t` ORDER BY ${t.csv(x)}` : b ? t.onDialectOrElse({
647
648
  mssql: () => t` ORDER BY (SELECT NULL)`,
@@ -660,29 +661,29 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
660
661
  return t`${C}SELECT ${f}${d} FROM ${h}${_}${v}${y}${te}${n}${r}`;
661
662
  }
662
663
  });
663
- }, Fn = (e, t, n) => {
664
+ }, In = (e, t, n) => {
664
665
  if (e.eager === void 0) return null;
665
- let r = Ln(e.table, e.eager, e.sourceTable);
666
+ let r = Rn(e.table, e.eager, e.sourceTable);
666
667
  if (r === null) return null;
667
- let i = Wn(n, e, r, Un(t, n));
668
+ let i = Gn(n, e, r, Wn(t, n));
668
669
  return i === null ? null : {
669
670
  fragment: i,
670
- decode: qn(r, n)
671
+ decode: Jn(r, n)
671
672
  };
672
- }, z = (e) => e.relation.kind === "one" && e.fkSide === "target", In = (e) => ({
673
+ }, z = (e) => e.relation.kind === "one" && e.fkSide === "target", Ln = (e) => ({
673
674
  ...e,
674
675
  branch: {
675
676
  ...e.branch,
676
677
  limit: 2
677
678
  }
678
- }), Ln = (e, t, n) => {
679
- let r = n ?? ne(e), i = Vt(e);
679
+ }), Rn = (e, t, n) => {
680
+ let r = n ?? ne(e), i = Ht(e);
680
681
  if (i === void 0) return null;
681
682
  let a = [];
682
683
  for (let [e, n] of Object.entries(t)) {
683
684
  let t = i[e];
684
685
  if (t === void 0) return null;
685
- let o = Rn(e, t, r, n === !0 ? {} : n);
686
+ let o = zn(e, t, r, n === !0 ? {} : n);
686
687
  if (o === null) return null;
687
688
  a.push(o);
688
689
  }
@@ -690,11 +691,11 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
690
691
  table: r,
691
692
  children: a
692
693
  };
693
- }, Rn = (e, t, n, r) => {
694
+ }, zn = (e, t, n, r) => {
694
695
  let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
695
696
  if (t.kind === "manyToMany") o = t.targetKey, s = "target";
696
697
  else if (t.kind === "one") {
697
- let r = t.sourceKey ?? Hn(n, i.tableName);
698
+ let r = t.sourceKey ?? Un(n, i.tableName);
698
699
  if (r !== void 0) o = r, s = "source";
699
700
  else try {
700
701
  o = t.foreignKey ?? M(i, n.tableName, e), s = "target";
@@ -707,13 +708,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
707
708
  return null;
708
709
  }
709
710
  let c = r.with === void 0 ? [] : (() => {
710
- let e = Vt(i.tableName);
711
+ let e = Ht(i.tableName);
711
712
  if (e === void 0 && Object.keys(r.with).length > 0) return null;
712
713
  let t = [];
713
714
  for (let [n, a] of Object.entries(r.with)) {
714
715
  let r = e?.[n];
715
716
  if (r === void 0) return null;
716
- let o = Rn(n, r, i, a === !0 ? {} : a);
717
+ let o = zn(n, r, i, a === !0 ? {} : a);
717
718
  if (o === null) return null;
718
719
  t.push(o);
719
720
  }
@@ -729,9 +730,9 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
729
730
  fkSide: s,
730
731
  branch: r,
731
732
  children: c,
732
- junction: zn(t, r)
733
+ junction: Bn(t, r)
733
734
  };
734
- }, zn = (e, t) => {
735
+ }, Bn = (e, t) => {
735
736
  if (e.kind !== "manyToMany" || t.junction === void 0) return;
736
737
  let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
737
738
  return {
@@ -743,35 +744,35 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
743
744
  return t !== void 0 && (t.type === "timestamp" || t.type === "date");
744
745
  })
745
746
  };
746
- }, Bn = (e) => `__j_${e}`, Vn = "__j", Hn = (e, t) => {
747
+ }, Vn = (e) => `__j_${e}`, Hn = "__j", Un = (e, t) => {
747
748
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
748
- }, Un = (e, t) => {
749
+ }, Wn = (e, t) => {
749
750
  let n = 0;
750
751
  return {
751
752
  sql: e,
752
753
  dialect: t,
753
754
  nextAlias: () => `__a${n++}`
754
755
  };
755
- }, Wn = (e, t, n, r) => {
756
+ }, Gn = (e, t, n, r) => {
756
757
  switch (e) {
757
- case "postgres": return Xn(t, n, r);
758
+ case "postgres": return Zn(t, n, r);
758
759
  case "sqlite":
759
- case "turso": return ir(t, n, r);
760
+ case "turso": return ar(t, n, r);
760
761
  case "mysql":
761
- case "mariadb": return mr(t, n, r);
762
- case "mssql": return xr(t, n, r);
762
+ case "mariadb": return hr(t, n, r);
763
+ case "mssql": return Sr(t, n, r);
763
764
  }
764
- }, Gn = (e, t) => t === "mssql" && !Kn.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), Kn = /(?:Z|[+-]\d{2}:?\d{2})$/, qn = (e, t) => {
765
- let n = Jn(e.table, e.children, t);
765
+ }, Kn = (e, t) => t === "mssql" && !qn.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), qn = /(?:Z|[+-]\d{2}:?\d{2})$/, Jn = (e, t) => {
766
+ let n = Yn(e.table, e.children, t);
766
767
  return (e) => e.map((e) => {
767
768
  let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
768
769
  return n(r);
769
770
  });
770
- }, Jn = (e, t, n) => {
771
+ }, Yn = (e, t, n) => {
771
772
  let r = [];
772
773
  for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
773
774
  let i = t.map((e) => {
774
- let t = Jn(e.target, e.children, n), r = e.relation.kind === "one", i = z(e), a = i ? tn({
775
+ let t = Yn(e.target, e.children, n), r = e.relation.kind === "one", i = z(e), a = i ? nn({
775
776
  relationName: e.relationName,
776
777
  sourceTableName: e.source.tableName,
777
778
  targetTableName: e.target.tableName,
@@ -784,14 +785,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
784
785
  isSingle: r,
785
786
  fromOverFetch: i,
786
787
  cardinalityMessage: a,
787
- junction: Yn(e.junction, n)
788
+ junction: Xn(e.junction, n)
788
789
  };
789
790
  });
790
791
  return (e) => {
791
792
  let t = { ...e };
792
793
  for (let e of r) {
793
794
  let r = t[e];
794
- typeof r == "string" && (t[e] = Gn(r, n));
795
+ typeof r == "string" && (t[e] = Kn(r, n));
795
796
  }
796
797
  for (let e of i) {
797
798
  let n = t[e.name];
@@ -801,7 +802,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
801
802
  }
802
803
  if (e.fromOverFetch) {
803
804
  let r = n;
804
- if (r.length > 1) throw new en(e.cardinalityMessage);
805
+ if (r.length > 1) throw new tn(e.cardinalityMessage);
805
806
  t[e.name] = r.length === 0 ? null : e.decode(r[0]);
806
807
  continue;
807
808
  }
@@ -813,104 +814,104 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
813
814
  }
814
815
  return t;
815
816
  };
816
- }, Yn = (e, t) => {
817
+ }, Xn = (e, t) => {
817
818
  if (e === void 0) return;
818
819
  let n = new Set(e.dateColumns), r = e.requested;
819
820
  return (e) => {
820
821
  let i = e._junction ?? {}, a = {};
821
822
  for (let e of r) {
822
823
  let r = i[e];
823
- a[e] = n.has(e) && typeof r == "string" ? Gn(r, t) : r;
824
+ a[e] = n.has(e) && typeof r == "string" ? Kn(r, t) : r;
824
825
  }
825
826
  return {
826
827
  ...e,
827
828
  _junction: a
828
829
  };
829
830
  };
830
- }, Xn = (e, t, n) => {
831
- let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = Zn(i, t.children, n);
831
+ }, Zn = (e, t, n) => {
832
+ let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = Qn(i, t.children, n);
832
833
  return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``}${e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${W(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${W(e.skip, r)}`}`;
833
- }, Zn = (e, t, n, r) => {
834
- let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${U(Vn, i)}::text)`;
834
+ }, Qn = (e, t, n, r) => {
835
+ let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${U(Hn, i)}::text)`;
835
836
  if (t.length === 0 && r === void 0) return a;
836
837
  let o = [];
837
- r !== void 0 && o.push(i`${U("_junction", i)}, ${H(e, Vn, i)}`);
838
+ r !== void 0 && o.push(i`${U("_junction", i)}, ${H(e, Hn, i)}`);
838
839
  for (let r of t) {
839
- let t = Qn(r, e, n);
840
+ let t = $n(r, e, n);
840
841
  if (t === null) return null;
841
842
  o.push(i`${U(r.relationName, i)}, ${t}`);
842
843
  }
843
844
  return i`${a} || jsonb_build_object(${i.csv(o)})`;
844
- }, Qn = (e, t, n) => {
845
+ }, $n = (e, t, n) => {
845
846
  switch (e.relation.kind) {
846
- case "one": return z(e) ? er(In(e), t, n) : $n(e, t, n);
847
- case "many": return er(e, t, n);
848
- case "manyToMany": return tr(e, t, n);
847
+ case "one": return z(e) ? tr(Ln(e), t, n) : er(e, t, n);
848
+ case "many": return tr(e, t, n);
849
+ case "manyToMany": return nr(e, t, n);
849
850
  }
850
- }, $n = (e, t, n) => {
851
- let r = n.sql, i = n.nextAlias(), a = Zn(i, e.children, n);
851
+ }, er = (e, t, n) => {
852
+ let r = n.sql, i = n.nextAlias(), a = Qn(i, e.children, n);
852
853
  if (a === null) return null;
853
854
  let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, i, r)}`, c = B(i, e.branch.orderBy, r);
854
855
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
855
- }, er = (e, t, n) => {
856
- let r = n.sql, i = n.nextAlias(), a = Zn(i, e.children, n);
856
+ }, tr = (e, t, n) => {
857
+ let r = n.sql, i = n.nextAlias(), a = Qn(i, e.children, n);
857
858
  if (a === null) return null;
858
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
859
+ let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, c = ir(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
859
860
  return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
860
- }, tr = (e, t, n) => {
861
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Zn(o, e.children, n, e.junction);
861
+ }, nr = (e, t, n) => {
862
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Qn(o, e.children, n, e.junction);
862
863
  if (c === null) return null;
863
- let l = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, u = K(e, s, r), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${nr(e.junction, s, r)} AS ${r(Vn)}`;
864
+ let l = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, u = K(e, s, r), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${rr(e.junction, s, r)} AS ${r(Hn)}`;
864
865
  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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
865
- }, nr = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${U(e, n)}, ${H(t, e, n)}`))})`, B = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${H(e, t.column, n)} DESC` : n`${H(e, t.column, n)} ASC`))}`, rr = (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`))}`, ir = (e, t, n) => {
866
- let r = n.sql, i = n.nextAlias(), a = ar(i, t.table, t.children, n);
866
+ }, rr = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${U(e, n)}, ${H(t, e, n)}`))})`, B = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${H(e, t.column, n)} DESC` : n`${H(e, t.column, n)} ASC`))}`, ir = (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`))}`, ar = (e, t, n) => {
867
+ let r = n.sql, i = n.nextAlias(), a = or(i, t.table, t.children, n);
867
868
  if (a === null) return null;
868
869
  let o = e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${W(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${W(e.skip, r)}`;
869
870
  return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
870
- }, ar = (e, t, n, r, i) => {
871
+ }, or = (e, t, n, r, i) => {
871
872
  let a = r.sql, o = [];
872
873
  for (let n of Object.keys(t.fields)) o.push(a`${U(n, a)}, ${H(e, n, a)}`);
873
874
  if (i !== void 0) {
874
- let e = or(i.projection, i.source, a);
875
+ let e = sr(i.projection, i.source, a);
875
876
  o.push(a`${U("_junction", a)}, json_object(${e})`);
876
877
  }
877
878
  for (let t of n) {
878
- let n = ur(t, e, r);
879
+ let n = dr(t, e, r);
879
880
  if (n === null) return null;
880
881
  o.push(a`${U(t.relationName, a)}, ${n}`);
881
882
  }
882
883
  return a`json_object(${a.csv(o)})`;
883
- }, or = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${U(e, n)}, ${H(t.alias, t.physical(e), n)}`)), sr = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${H(t, e, n)} AS ${n(Bn(e))}`))}`, cr = (e) => ({
884
+ }, sr = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${U(e, n)}, ${H(t.alias, t.physical(e), n)}`)), cr = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${H(t, e, n)} AS ${n(Vn(e))}`))}`, lr = (e) => ({
884
885
  alias: e,
885
- physical: Bn
886
- }), lr = (e) => ({
886
+ physical: Vn
887
+ }), ur = (e) => ({
887
888
  alias: e,
888
889
  physical: (e) => e
889
- }), ur = (e, t, n) => {
890
+ }), dr = (e, t, n) => {
890
891
  switch (e.relation.kind) {
891
- case "one": return z(e) ? fr(In(e), t, n) : dr(e, t, n);
892
- case "many": return fr(e, t, n);
893
- case "manyToMany": return pr(e, t, n);
892
+ case "one": return z(e) ? pr(Ln(e), t, n) : fr(e, t, n);
893
+ case "many": return pr(e, t, n);
894
+ case "manyToMany": return mr(e, t, n);
894
895
  }
895
- }, dr = (e, t, n) => {
896
- let r = n.sql, i = n.nextAlias(), a = ar(i, e.target, e.children, n);
896
+ }, fr = (e, t, n) => {
897
+ let r = n.sql, i = n.nextAlias(), a = or(i, e.target, e.children, n);
897
898
  if (a === null) return null;
898
899
  let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`;
899
900
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
900
- }, fr = (e, t, n) => {
901
- let r = n.sql, i = n.nextAlias(), a = ar(i, e.target, e.children, n);
901
+ }, pr = (e, t, n) => {
902
+ let r = n.sql, i = n.nextAlias(), a = or(i, e.target, e.children, n);
902
903
  if (a === null) return null;
903
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
904
+ let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = ir(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
904
905
  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('[]'))`;
905
- }, pr = (e, t, n) => {
906
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ar(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
906
+ }, mr = (e, t, n) => {
907
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = or(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
907
908
  projection: e.junction,
908
- source: cr(o)
909
+ source: lr(o)
909
910
  });
910
911
  if (c === null) return null;
911
- let l = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : sr(e.junction, s, r);
912
+ let l = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : cr(e.junction, s, r);
912
913
  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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
913
- }, mr = (e, t, n) => {
914
+ }, hr = (e, t, n) => {
914
915
  let r = n.sql, i = n.nextAlias(), a = V(i, t.table, t.children, n);
915
916
  if (a === null) return null;
916
917
  let o = e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${W(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${W(e.skip, r)}`;
@@ -919,66 +920,66 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
919
920
  let a = r.sql, o = [];
920
921
  for (let n of Object.keys(t.fields)) o.push(a`${U(n, a)}, ${H(e, n, a)}`);
921
922
  if (i !== void 0) {
922
- let e = or(i.projection, i.source, a);
923
+ let e = sr(i.projection, i.source, a);
923
924
  o.push(a`${U("_junction", a)}, JSON_OBJECT(${e})`);
924
925
  }
925
926
  for (let t of n) {
926
- let n = hr(t, e, r);
927
+ let n = gr(t, e, r);
927
928
  if (n === null) return null;
928
929
  o.push(a`${U(t.relationName, a)}, ${n}`);
929
930
  }
930
931
  return a`JSON_OBJECT(${a.csv(o)})`;
931
- }, hr = (e, t, n) => {
932
+ }, gr = (e, t, n) => {
932
933
  switch (e.relation.kind) {
933
934
  case "one":
934
935
  if (z(e)) {
935
- let r = In(e);
936
- return n.dialect === "mariadb" ? yr(r, t, n) : _r(r, t, n);
936
+ let r = Ln(e);
937
+ return n.dialect === "mariadb" ? br(r, t, n) : vr(r, t, n);
937
938
  }
938
- return gr(e, t, n);
939
- case "many": return n.dialect === "mariadb" ? yr(e, t, n) : _r(e, t, n);
940
- case "manyToMany": return n.dialect === "mariadb" ? br(e, t, n) : vr(e, t, n);
939
+ return _r(e, t, n);
940
+ case "many": return n.dialect === "mariadb" ? br(e, t, n) : vr(e, t, n);
941
+ case "manyToMany": return n.dialect === "mariadb" ? xr(e, t, n) : yr(e, t, n);
941
942
  }
942
- }, gr = (e, t, n) => {
943
+ }, _r = (e, t, n) => {
943
944
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
944
945
  if (a === null) return null;
945
946
  let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`;
946
947
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
947
- }, _r = (e, t, n) => {
948
+ }, vr = (e, t, n) => {
948
949
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
949
950
  if (a === null) return null;
950
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
951
+ let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = ir(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
951
952
  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())`;
952
- }, vr = (e, t, n) => {
953
+ }, yr = (e, t, n) => {
953
954
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = V(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
954
955
  projection: e.junction,
955
- source: cr(o)
956
+ source: lr(o)
956
957
  });
957
958
  if (c === null) return null;
958
- let l = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : sr(e.junction, s, r);
959
+ let l = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : cr(e.junction, s, r);
959
960
  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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
960
- }, yr = (e, t, n) => {
961
+ }, br = (e, t, n) => {
961
962
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
962
963
  if (a === null) return null;
963
964
  let o = r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
964
965
  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`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
965
966
  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 ${H(i, "rn", r)} > ${W(d, r)} AND ${H(i, "rn", r)} <= ${W(d + u, r)}` : u === void 0 ? r` AND ${H(i, "rn", r)} > ${W(d, r)}` : r` AND ${H(i, "rn", r)} <= ${W(u, r)}`;
966
967
  return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${H(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())`;
967
- }, br = (e, t, n) => {
968
+ }, xr = (e, t, n) => {
968
969
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
969
970
  projection: e.junction,
970
971
  source: t
971
972
  }, l = r`${H(s, i.sourceKey, r)} = ${H(t, "id", r)}`, u = r`${H(o, "id", r)} = ${H(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, f = K(e, s, r, !0), p = e.branch.orderBy ?? [];
972
973
  if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
973
- let t = V(o, e.target, e.children, n, c(lr(s)));
974
+ let t = V(o, e.target, e.children, n, c(ur(s)));
974
975
  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`${H(o, e.column, r)} DESC` : r`${H(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())`;
975
976
  }
976
- let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${H(o, e.column, r)} DESC` : r`${H(o, e.column, r)} ASC`))}` : r` ORDER BY ${H(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)} AND ${H(o, "rn", r)} <= ${W(g + h, r)}` : h === void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)}` : r` AND ${H(o, "rn", r)} <= ${W(h, r)}`, _ = e.branch.onJunction === void 0 ? r`` : r` WHERE ${G(q(e.branch.onJunction), s, r)}`, v = V(o, e.target, e.children, n, c(cr(o)));
977
+ let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${H(o, e.column, r)} DESC` : r`${H(o, e.column, r)} ASC`))}` : r` ORDER BY ${H(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)} AND ${H(o, "rn", r)} <= ${W(g + h, r)}` : h === void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)}` : r` AND ${H(o, "rn", r)} <= ${W(h, r)}`, _ = e.branch.onJunction === void 0 ? r`` : r` WHERE ${G(q(e.branch.onJunction), s, r)}`, v = V(o, e.target, e.children, n, c(lr(o)));
977
978
  if (v === null) return null;
978
- let y = e.junction === void 0 ? r`` : sr(e.junction, s, r);
979
+ let y = e.junction === void 0 ? r`` : cr(e.junction, s, r);
979
980
  return r`COALESCE((SELECT JSON_ARRAYAGG(${v} ORDER BY ${H(o, "rn", r)}) FROM (SELECT ${r(o)}.*${y}, ${H(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${H(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 ${H(o, `__src_${i.sourceKey}`, r)} = ${H(t, "id", r)}${d}${ee}), JSON_ARRAY())`;
980
- }, xr = (e, t, n) => {
981
- let r = n.sql, i = n.nextAlias(), a = Sr(i, t.table, t.children, n);
981
+ }, Sr = (e, t, n) => {
982
+ let r = n.sql, i = n.nextAlias(), a = Cr(i, t.table, t.children, n);
982
983
  if (a === null) return null;
983
984
  let o = e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
984
985
  if (e.skip !== void 0) {
@@ -987,28 +988,28 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
987
988
  } else e.take !== void 0 && (c = r`TOP ${W(e.take, r)} `);
988
989
  let u = e.skip === void 0 ? s : r``;
989
990
  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}`;
990
- }, Sr = (e, t, n, r, i) => {
991
+ }, Cr = (e, t, n, r, i) => {
991
992
  let a = r.sql, o = [];
992
993
  for (let n of Object.keys(t.fields)) o.push(a`${H(e, n, a)} AS ${a(n)}`);
993
- if (i !== void 0) for (let e of i.projection.present) o.push(a`${H(i.source.alias, i.source.physical(e), a)} AS ${Cr(`_junction.${e}`, a)}`);
994
+ if (i !== void 0) for (let e of i.projection.present) o.push(a`${H(i.source.alias, i.source.physical(e), a)} AS ${wr(`_junction.${e}`, a)}`);
994
995
  for (let t of n) {
995
- let n = wr(t, e, r);
996
+ let n = Tr(t, e, r);
996
997
  if (n === null) return null;
997
998
  o.push(n);
998
999
  }
999
1000
  return a.csv(o);
1000
- }, Cr = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), wr = (e, t, n) => {
1001
+ }, wr = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Tr = (e, t, n) => {
1001
1002
  switch (e.relation.kind) {
1002
- case "one": return z(e) ? Dr(In(e), t, n) : Tr(e, t, n);
1003
- case "many": return Dr(e, t, n);
1004
- case "manyToMany": return Or(e, t, n);
1003
+ case "one": return z(e) ? Or(Ln(e), t, n) : Er(e, t, n);
1004
+ case "many": return Or(e, t, n);
1005
+ case "manyToMany": return kr(e, t, n);
1005
1006
  }
1006
- }, Tr = (e, t, n) => {
1007
- let r = n.sql, i = n.nextAlias(), a = Sr(i, e.target, e.children, n);
1007
+ }, Er = (e, t, n) => {
1008
+ let r = n.sql, i = n.nextAlias(), a = Cr(i, e.target, e.children, n);
1008
1009
  if (a === null) return null;
1009
1010
  let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`;
1010
1011
  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)}`;
1011
- }, Er = (e, t, n) => {
1012
+ }, Dr = (e, t, n) => {
1012
1013
  if (e.offset !== void 0) {
1013
1014
  let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${W(e.offset, n)} ROWS` : n`${r} OFFSET ${W(e.offset, n)} ROWS FETCH NEXT ${W(e.limit, n)} ROWS ONLY`;
1014
1015
  return {
@@ -1022,29 +1023,29 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1022
1023
  pagination: n``,
1023
1024
  finalOrder: t
1024
1025
  };
1025
- }, Dr = (e, t, n) => {
1026
- let r = n.sql, i = n.nextAlias(), a = Sr(i, e.target, e.children, n);
1026
+ }, Or = (e, t, n) => {
1027
+ let r = n.sql, i = n.nextAlias(), a = Cr(i, e.target, e.children, n);
1027
1028
  if (a === null) return null;
1028
- let o = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, i, r)}`, s = B(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Er(e.branch, s, r);
1029
+ let o = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, i, r)}`, s = B(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Dr(e.branch, s, r);
1029
1030
  return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1030
- }, Or = (e, t, n) => {
1031
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Sr(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1031
+ }, kr = (e, t, n) => {
1032
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Cr(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1032
1033
  projection: e.junction,
1033
- source: lr(s)
1034
+ source: ur(s)
1034
1035
  });
1035
1036
  if (c === null) return null;
1036
- let l = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, o, r)}`, u = K(e, s, r), d = B(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Er(e.branch, d, r);
1037
+ let l = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, o, r)}`, u = K(e, s, r), d = B(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Dr(e.branch, d, r);
1037
1038
  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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1038
1039
  }, H = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, U = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), W = (e, t) => {
1039
1040
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
1040
1041
  return t.unsafe(String(e));
1041
- }, G = (e, t, n) => L(kr(e, t), n), K = (e, t, n, r = !1) => {
1042
+ }, G = (e, t, n) => L(Ar(e, t), n), K = (e, t, n, r = !1) => {
1042
1043
  let i = e.branch.onJunction;
1043
1044
  return i === void 0 ? n`` : n` AND ${G(r ? q(i) : i, t, n)}`;
1044
- }, kr = (e, t) => {
1045
- if ("not" in e) return { not: kr(e.not, t) };
1046
- if ("and" in e) return { and: e.and.map((e) => kr(e, t)) };
1047
- if ("or" in e) return { or: e.or.map((e) => kr(e, t)) };
1045
+ }, Ar = (e, t) => {
1046
+ if ("not" in e) return { not: Ar(e.not, t) };
1047
+ if ("and" in e) return { and: e.and.map((e) => Ar(e, t)) };
1048
+ if ("or" in e) return { or: e.or.map((e) => Ar(e, t)) };
1048
1049
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
1049
1050
  let n = e;
1050
1051
  return {
@@ -1066,15 +1067,15 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1066
1067
  let t = e;
1067
1068
  return {
1068
1069
  ...t,
1069
- value: Ar(t.value)
1070
+ value: jr(t.value)
1070
1071
  };
1071
- }, Ar = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Ar(e)) : e, jr = Symbol.for("@voltro/database/coreTablesRegistry"), Mr = globalThis, Nr = Mr[jr] ?? (Mr[jr] = {}), Pr = (e) => {
1072
- e.actors !== void 0 && (Nr.actors = e.actors), e.tenants !== void 0 && (Nr.tenants = e.tenants);
1073
- }, Fr = (e, t) => () => {
1072
+ }, jr = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => jr(e)) : e, Mr = Symbol.for("@voltro/database/coreTablesRegistry"), Nr = globalThis, Pr = Nr[Mr] ?? (Nr[Mr] = {}), Fr = (e) => {
1073
+ e.actors !== void 0 && (Pr.actors = e.actors), e.tenants !== void 0 && (Pr.tenants = e.tenants);
1074
+ }, Ir = (e, t) => () => {
1074
1075
  let n = e();
1075
1076
  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`);
1076
1077
  return n();
1077
- }, Ir = () => Fr(() => Nr.actors, "actors"), Lr = () => Fr(() => Nr.tenants, "tenants"), Rr = w("actors", {
1078
+ }, Lr = () => Ir(() => Pr.actors, "actors"), Rr = () => Ir(() => Pr.tenants, "tenants"), zr = w("actors", {
1078
1079
  id: O(),
1079
1080
  kind: E().oneOf([
1080
1081
  "user",
@@ -1084,69 +1085,73 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1084
1085
  ]),
1085
1086
  displayName: E().nullable(),
1086
1087
  createdAt: _().default("now")
1087
- }), zr = (e, t) => ({
1088
+ }), Br = (e, t) => ({
1088
1089
  column: e,
1089
1090
  op: "eq",
1090
1091
  value: t
1091
- }), Br = (e, t) => ({
1092
+ }), Vr = (e, t) => ({
1092
1093
  column: e,
1093
1094
  op: "neq",
1094
1095
  value: t
1095
- }), Vr = (e, t) => ({
1096
+ }), Hr = (e, t) => ({
1096
1097
  column: e,
1097
1098
  op: "gt",
1098
1099
  value: t
1099
- }), Hr = (e, t) => ({
1100
+ }), Ur = (e, t) => ({
1100
1101
  column: e,
1101
1102
  op: "gte",
1102
1103
  value: t
1103
- }), Ur = (e, t) => ({
1104
+ }), Wr = (e, t) => ({
1104
1105
  column: e,
1105
1106
  op: "lt",
1106
1107
  value: t
1107
- }), Wr = (e, t) => ({
1108
+ }), Gr = (e, t) => ({
1108
1109
  column: e,
1109
1110
  op: "lte",
1110
1111
  value: t
1111
- }), Gr = (e, t) => ({
1112
+ }), Kr = (e, t) => ({
1112
1113
  column: e,
1113
1114
  op: "in",
1114
1115
  value: t
1115
- }), Kr = (e, t) => ({
1116
+ }), qr = (e, t) => ({
1116
1117
  column: e,
1117
1118
  op: "notIn",
1118
1119
  value: t
1119
- }), qr = (e, t) => ({
1120
+ }), Jr = (e, t) => ({
1120
1121
  column: e,
1121
1122
  op: "contains",
1122
1123
  value: t
1123
- }), Jr = (e, t) => ({
1124
+ }), Yr = (e, t) => ({
1124
1125
  column: e,
1125
1126
  op: "startsWith",
1126
1127
  value: t
1127
- }), Yr = (e, t) => ({
1128
+ }), Xr = (e, t) => ({
1128
1129
  column: e,
1129
1130
  op: "arrayContains",
1130
1131
  value: t
1131
- }), Xr = (e, t) => ({
1132
+ }), Zr = (e, t) => ({
1132
1133
  column: e,
1133
1134
  op: "arrayOverlaps",
1134
1135
  value: t
1135
- }), Zr = (e, t) => ({
1136
+ }), Qr = (e, t) => ({
1136
1137
  column: e,
1137
1138
  op: "arrayHas",
1138
1139
  value: t
1139
- }), Qr = (e) => ({
1140
+ }), $r = {
1141
+ column: "id",
1142
+ op: "in",
1143
+ value: []
1144
+ }, ei = (e) => ({
1140
1145
  column: e,
1141
1146
  op: "isNull"
1142
- }), $r = (e) => ({
1147
+ }), ti = (e) => ({
1143
1148
  column: e,
1144
1149
  op: "isNotNull"
1145
- }), ei = (e, t) => ({
1150
+ }), ni = (e, t) => ({
1146
1151
  column: e,
1147
1152
  op: "spatial",
1148
1153
  value: t
1149
- }), ti = (...e) => ({ and: e }), ni = (...e) => ({ or: e }), ri = (e) => ({ not: e }), ii = (e, ...t) => {
1154
+ }), ri = (...e) => ({ and: e }), ii = (...e) => ({ or: e }), ai = (e) => ({ not: e }), oi = (e, ...t) => {
1150
1155
  if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
1151
1156
  let n = (n, r) => ({
1152
1157
  column: e,
@@ -1168,29 +1173,29 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1168
1173
  isNull: () => n("isNull"),
1169
1174
  isNotNull: () => n("isNotNull")
1170
1175
  };
1171
- }, ai = (e) => "descriptor" in e ? e.descriptor : e, oi = (e, t) => ({
1176
+ }, si = (e) => "descriptor" in e ? e.descriptor : e, ci = (e, t) => ({
1172
1177
  column: e,
1173
1178
  op: "subquery-in",
1174
- subquery: ai(t)
1175
- }), si = (e, t) => ({
1179
+ subquery: si(t)
1180
+ }), li = (e, t) => ({
1176
1181
  column: e,
1177
1182
  op: "subquery-not-in",
1178
- subquery: ai(t)
1179
- }), ci = (e) => ({
1183
+ subquery: si(t)
1184
+ }), ui = (e) => ({
1180
1185
  op: "exists",
1181
- subquery: ai(e)
1182
- }), li = (e) => ({
1186
+ subquery: si(e)
1187
+ }), di = (e) => ({
1183
1188
  op: "not-exists",
1184
- subquery: ai(e)
1185
- }), ui = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, di = (e, t, n = null) => {
1189
+ subquery: si(e)
1190
+ }), fi = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, pi = (e, t, n = null) => {
1186
1191
  if (!t) return !1;
1187
- if ("not" in e) return !di(e.not, t, n);
1192
+ if ("not" in e) return !pi(e.not, t, n);
1188
1193
  if ("and" in e) {
1189
- for (let r of e.and) if (!di(r, t, n)) return !1;
1194
+ for (let r of e.and) if (!pi(r, t, n)) return !1;
1190
1195
  return !0;
1191
1196
  }
1192
1197
  if ("or" in e) {
1193
- for (let r of e.or) if (di(r, t, n)) return !0;
1198
+ for (let r of e.or) if (pi(r, t, n)) return !0;
1194
1199
  return !1;
1195
1200
  }
1196
1201
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
@@ -1209,10 +1214,10 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1209
1214
  switch (r.op) {
1210
1215
  case "eq": return i === r.value;
1211
1216
  case "neq": return i !== r.value;
1212
- case "gt": return (ui(i, r.value) ?? -1) > 0;
1213
- case "gte": return (ui(i, r.value) ?? -1) >= 0;
1214
- case "lt": return (ui(i, r.value) ?? 1) < 0;
1215
- case "lte": return (ui(i, r.value) ?? 1) <= 0;
1217
+ case "gt": return (fi(i, r.value) ?? -1) > 0;
1218
+ case "gte": return (fi(i, r.value) ?? -1) >= 0;
1219
+ case "lt": return (fi(i, r.value) ?? 1) < 0;
1220
+ case "lte": return (fi(i, r.value) ?? 1) <= 0;
1216
1221
  case "in": return Array.isArray(r.value) && r.value.includes(i);
1217
1222
  case "notIn": return Array.isArray(r.value) && !r.value.includes(i);
1218
1223
  case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
@@ -1230,17 +1235,17 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1230
1235
  case "isNotNull": return i != null;
1231
1236
  case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
1232
1237
  }
1233
- }, fi = function* (e) {
1238
+ }, mi = function* (e) {
1234
1239
  if ("not" in e) {
1235
- yield* fi(e.not);
1240
+ yield* mi(e.not);
1236
1241
  return;
1237
1242
  }
1238
1243
  if ("and" in e) {
1239
- for (let t of e.and) yield* fi(t);
1244
+ for (let t of e.and) yield* mi(t);
1240
1245
  return;
1241
1246
  }
1242
1247
  if ("or" in e) {
1243
- for (let t of e.or) yield* fi(t);
1248
+ for (let t of e.or) yield* mi(t);
1244
1249
  return;
1245
1250
  }
1246
1251
  e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
@@ -1250,27 +1255,47 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1250
1255
  kind: "exists",
1251
1256
  descriptor: e.subquery
1252
1257
  });
1253
- }, pi = function* (e, t = !0) {
1258
+ }, hi = function* (e, t = !0) {
1254
1259
  if ("not" in e) {
1255
- yield* pi(e.not, !1);
1260
+ yield* hi(e.not, !1);
1256
1261
  return;
1257
1262
  }
1258
1263
  if ("and" in e) {
1259
- for (let n of e.and) yield* pi(n, t);
1264
+ for (let n of e.and) yield* hi(n, t);
1260
1265
  return;
1261
1266
  }
1262
1267
  if ("or" in e) {
1263
- for (let t of e.or) yield* pi(t, !1);
1268
+ for (let t of e.or) yield* hi(t, !1);
1264
1269
  return;
1265
1270
  }
1266
1271
  e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists" || (yield {
1267
1272
  ...e,
1268
1273
  conjunctive: t
1269
1274
  });
1270
- }, mi = class extends st.TaggedError("TableStreamError") {}, hi = 1e3, gi = (e, t, n, r) => {
1275
+ }, gi = new ut(), _i = (e, t) => gi.run(e, t), vi = () => gi.getStore(), yi = () => {
1276
+ let e = gi.getStore();
1277
+ return e === void 0 ? {} : {
1278
+ ...e.traceId === void 0 ? {} : { traceId: e.traceId },
1279
+ ...e.subjectId === void 0 ? {} : { subjectId: e.subjectId }
1280
+ };
1281
+ }, J = /* @__PURE__ */ new Map(), bi = (e, t) => {
1282
+ J.set(e, {
1283
+ recorder: t.recorder,
1284
+ tables: new Set(t.tables),
1285
+ ownTables: new Set(t.ownTables)
1286
+ });
1287
+ }, xi = (e) => {
1288
+ J.delete(e);
1289
+ }, Si = () => J.clear(), Ci = (e) => {
1290
+ if (J.size === 0) return !1;
1291
+ for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
1292
+ return !1;
1293
+ }, wi = async (e, t) => {
1294
+ if (J.size !== 0) for (let n of J.values()) n.ownTables.has(t.table) || n.tables.has(t.table) && await n.recorder(e, t);
1295
+ }, Ti = class extends st.TaggedError("TableStreamError") {}, Ei = 1e3, Di = (e, t, n, r) => {
1271
1296
  let i = k.match(r, {
1272
1297
  onNone: () => e.where,
1273
- onSome: (n) => e.where ? ti(e.where, Vr(t, n)) : Vr(t, n)
1298
+ onSome: (n) => e.where ? ri(e.where, Hr(t, n)) : Hr(t, n)
1274
1299
  });
1275
1300
  return {
1276
1301
  table: e.table,
@@ -1285,19 +1310,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1285
1310
  ...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
1286
1311
  ...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
1287
1312
  };
1288
- }, _i = (e, t) => {
1289
- let n = t.pk ?? "id", r = t.chunkSize ?? hi;
1313
+ }, Oi = (e, t) => {
1314
+ let n = t.pk ?? "id", r = t.chunkSize ?? Ei;
1290
1315
  return lt.paginateChunkEffect(k.none(), (i) => {
1291
1316
  let a = ct.tryPromise({
1292
- try: () => e.query(gi(t, n, r, i)),
1293
- catch: (e) => new mi({
1317
+ try: () => e.query(Di(t, n, r, i)),
1318
+ catch: (e) => new Ti({
1294
1319
  table: t.table,
1295
1320
  cause: e
1296
1321
  })
1297
1322
  });
1298
1323
  return (t.retry ? a.pipe(ct.retry(t.retry)) : a).pipe(ct.map((e) => [ot.fromIterable(e), e.length === r && e.length > 0 ? k.some(k.some(e[e.length - 1][n])) : k.none()]));
1299
1324
  });
1300
- }, vi = (e) => {
1325
+ }, ki = (e) => {
1301
1326
  let t = e.alpha ?? .5;
1302
1327
  if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
1303
1328
  return (n) => {
@@ -1324,14 +1349,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1324
1349
  }
1325
1350
  };
1326
1351
  };
1327
- }, yi = async (e, t) => {
1352
+ }, Ai = async (e, t) => {
1328
1353
  let n = e.as ?? "embedding", r = t.row[e.from];
1329
1354
  if (typeof r != "string" || r.length === 0) return {};
1330
1355
  let i = await t.embed(r);
1331
1356
  return { [n]: i };
1332
- }, bi = (e) => {
1357
+ }, ji = (e) => {
1333
1358
  if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
1334
- let t = e.as ?? "embedding", n = (t) => yi(e, t);
1359
+ let t = e.as ?? "embedding", n = (t) => Ai(e, t);
1335
1360
  return d({
1336
1361
  id: "voltro/vectorEmbedding",
1337
1362
  fields: { [t]: y(e.dimensions) },
@@ -1349,19 +1374,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1349
1374
  beforeUpdate: n
1350
1375
  }
1351
1376
  });
1352
- }, xi = 63, Si = "br_pr", J = class extends Error {
1377
+ }, Mi = 63, Ni = "br_pr", Y = class extends Error {
1353
1378
  _tag = "BranchNameInvalid";
1354
1379
  constructor(e) {
1355
1380
  super(e), this.name = "BranchNameInvalid";
1356
1381
  }
1357
- }, Ci = (e, t) => {
1358
- if (!Number.isInteger(t) || t < 0) throw new J(`prNumber must be a non-negative integer, got ${String(t)}`);
1359
- let n = _n(e);
1360
- if (n.replace(/_/g, "") === "") throw new J(`app slug '${e}' has no usable identifier characters`);
1361
- let r = `${Si}${t}_${n}`;
1362
- if (r.length > xi) throw new J(`branch namespace '${r}' exceeds the ${xi}-byte identifier limit — use a shorter app slug`);
1382
+ }, Pi = (e, t) => {
1383
+ if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
1384
+ let n = vn(e);
1385
+ if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
1386
+ let r = `${Ni}${t}_${n}`;
1387
+ if (r.length > Mi) throw new Y(`branch namespace '${r}' exceeds the ${Mi}-byte identifier limit — use a shorter app slug`);
1363
1388
  return r;
1364
- }, wi = (e) => e.startsWith(Si), Ti = {
1389
+ }, Fi = (e) => e.startsWith(Ni), Ii = {
1365
1390
  requested: {
1366
1391
  provision: "provisioning",
1367
1392
  destroy: "destroying"
@@ -1380,19 +1405,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1380
1405
  fail: "failed"
1381
1406
  },
1382
1407
  destroyed: {}
1383
- }, Ei = class extends Error {
1408
+ }, Li = class extends Error {
1384
1409
  from;
1385
1410
  event;
1386
1411
  _tag = "BranchTransitionInvalid";
1387
1412
  constructor(e, t) {
1388
1413
  super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
1389
1414
  }
1390
- }, Di = (e, t) => {
1391
- let n = Ti[e][t];
1392
- if (n === void 0) throw new Ei(e, t);
1415
+ }, Ri = (e, t) => {
1416
+ let n = Ii[e][t];
1417
+ if (n === void 0) throw new Li(e, t);
1393
1418
  return n;
1394
- }, Oi = (e, t, n, r) => {
1395
- if (n === "copy" && (r === void 0 || r === "")) throw new J("seed 'copy' requires a parentNamespace to snapshot from");
1419
+ }, zi = (e, t, n, r) => {
1420
+ if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
1396
1421
  let i = [{
1397
1422
  kind: "create-namespace",
1398
1423
  detail: e
@@ -1412,13 +1437,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1412
1437
  detail: `run boot seeds into ${e}`
1413
1438
  });
1414
1439
  return i;
1415
- }, ki = (e) => {
1416
- if (!wi(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
1440
+ }, Bi = (e) => {
1441
+ if (!Fi(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
1417
1442
  return [{
1418
1443
  kind: "drop-namespace",
1419
1444
  detail: e
1420
1445
  }];
1421
- }, Ai = (e) => {
1446
+ }, Vi = (e) => {
1422
1447
  if (e === void 0 || e === "") return !1;
1423
1448
  try {
1424
1449
  let t = new URL(e).hostname.toLowerCase();
@@ -1426,27 +1451,27 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1426
1451
  } catch {
1427
1452
  return /\bneon\.(tech|build)\b/i.test(e);
1428
1453
  }
1429
- }, ji = (e) => e.prefer === void 0 ? e.seed === "copy" && Ai(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Mi = (e, t = {}) => [{
1454
+ }, Hi = (e) => e.prefer === void 0 ? e.seed === "copy" && Vi(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Ui = (e, t = {}) => [{
1430
1455
  kind: "neon-branch-create",
1431
1456
  detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
1432
- }], Ni = (e) => {
1433
- if (!wi(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
1457
+ }], Wi = (e) => {
1458
+ if (!Fi(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
1434
1459
  return [{
1435
1460
  kind: "neon-branch-delete",
1436
1461
  detail: e
1437
1462
  }];
1438
- }, Pi = (e) => e.mechanism === "neon-cow" ? Mi(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Oi(e.branchId, e.tableNames, e.seed, e.parentNamespace), Fi = (e, t) => e === "neon-cow" ? Ni(t) : ki(t), Ii = (e, t, n) => {
1463
+ }, Gi = (e) => e.mechanism === "neon-cow" ? Ui(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : zi(e.branchId, e.tableNames, e.seed, e.parentNamespace), Ki = (e, t) => e === "neon-cow" ? Wi(t) : Bi(t), qi = (e, t, n) => {
1439
1464
  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);
1440
1465
  return {
1441
1466
  evict: i,
1442
1467
  rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
1443
1468
  };
1444
- }, Li = async (e, t) => {
1445
- let n = Ci(e.appSlug, e.prNumber), r = ji({
1469
+ }, Ji = async (e, t) => {
1470
+ let n = Pi(e.appSlug, e.prNumber), r = Hi({
1446
1471
  seed: e.seed,
1447
1472
  ...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
1448
1473
  ...e.prefer === void 0 ? {} : { prefer: e.prefer }
1449
- }), i = Pi({
1474
+ }), i = Gi({
1450
1475
  mechanism: r,
1451
1476
  branchId: n,
1452
1477
  tableNames: e.tableNames,
@@ -1471,33 +1496,33 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1471
1496
  mechanism: r,
1472
1497
  steps: i
1473
1498
  };
1474
- }, Ri = async (e, t, n) => {
1475
- let r = Fi(t, e);
1499
+ }, Yi = async (e, t, n) => {
1500
+ let r = Ki(t, e);
1476
1501
  return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
1477
- }, zi = (e, t, n) => Ii(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, Bi = (e) => {
1502
+ }, Xi = (e, t, n) => qi(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, Zi = (e) => {
1478
1503
  let t = () => {
1479
1504
  throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
1480
1505
  };
1481
1506
  return {
1482
- createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${Y(t)}`),
1483
- createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${Y(t)}.${Y(n)} (LIKE ${Y(n)} INCLUDING ALL)`),
1484
- copyTable: (t, n, r) => e.run(`INSERT INTO ${Y(n)}.${Y(r)} SELECT * FROM ${Y(t)}.${Y(r)}`),
1485
- dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${Y(t)} CASCADE`),
1507
+ createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
1508
+ createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
1509
+ copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
1510
+ dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
1486
1511
  neonBranchCreate: t,
1487
1512
  neonBranchDelete: t
1488
1513
  };
1489
- }, Vi = class extends Error {
1514
+ }, Qi = class extends Error {
1490
1515
  _tag = "TenantResidencyUnresolved";
1491
1516
  constructor(e) {
1492
1517
  super(e), this.name = "TenantResidencyUnresolved";
1493
1518
  }
1494
- }, Hi = class extends Error {
1519
+ }, $i = class extends Error {
1495
1520
  region;
1496
1521
  _tag = "TenantRegionUnavailable";
1497
1522
  constructor(e, t) {
1498
1523
  super(t), this.region = e, this.name = "TenantRegionUnavailable";
1499
1524
  }
1500
- }, Ui, Wi = (e) => {
1525
+ }, ea, ta = (e) => {
1501
1526
  if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
1502
1527
  if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
1503
1528
  let t = /* @__PURE__ */ new Map();
@@ -1506,98 +1531,98 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1506
1531
  if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
1507
1532
  t.set(n.tenantId, n.region);
1508
1533
  }
1509
- return Ui = e, e;
1510
- }, Gi = () => Ui, Ki = () => {
1511
- Ui = void 0;
1512
- }, qi = (e, t) => {
1513
- if (e == null || e === "") throw new Vi("residency is on but the request has no resolvable tenant — refusing to bind a store");
1534
+ return ea = e, e;
1535
+ }, na = () => ea, ra = () => {
1536
+ ea = void 0;
1537
+ }, ia = (e, t) => {
1538
+ if (e == null || e === "") throw new Qi("residency is on but the request has no resolvable tenant — refusing to bind a store");
1514
1539
  let n = t.homes.find((t) => t.tenantId === e);
1515
- if (n === void 0) throw new Vi(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
1540
+ if (n === void 0) throw new Qi(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
1516
1541
  return n;
1517
- }, Ji = (e, t) => t.servableRegions.includes(e), Yi = (e, t) => {
1518
- let n = qi(e.tenantId, t), r = vn(n.tenantId);
1542
+ }, aa = (e, t) => t.servableRegions.includes(e), oa = (e, t) => {
1543
+ let n = ia(e.tenantId, t), r = yn(n.tenantId);
1519
1544
  return {
1520
1545
  region: n.region,
1521
1546
  namespace: r,
1522
1547
  ...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
1523
1548
  };
1524
- }, Xi = (e, t, n) => {
1525
- let r = Yi(e, t);
1526
- if (!Ji(r.region, t)) throw new Hi(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
1549
+ }, sa = (e, t, n) => {
1550
+ let r = oa(e, t);
1551
+ if (!aa(r.region, t)) throw new $i(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
1527
1552
  let i = n.get(r.region);
1528
- if (i === void 0) throw new Hi(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
1553
+ if (i === void 0) throw new $i(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
1529
1554
  return {
1530
1555
  store: i,
1531
1556
  placement: r
1532
1557
  };
1533
- }, Zi = async (e, t, n, r) => {
1534
- let { store: i, placement: a } = Xi(e, t, n);
1558
+ }, ca = async (e, t, n, r) => {
1559
+ let { store: i, placement: a } = sa(e, t, n);
1535
1560
  return await r(i, a), a;
1536
- }, X = (e) => {
1561
+ }, Z = (e) => {
1537
1562
  if (typeof e == "string") return e;
1538
1563
  if ("jsonPath" in e) {
1539
1564
  let { column: t, path: n, numeric: r } = e.jsonPath;
1540
1565
  return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
1541
1566
  }
1542
1567
  return `(${e.expr})`;
1543
- }, Z = (e) => e.map(X), Qi = (e, t) => {
1568
+ }, Q = (e) => e.map(Z), la = (e, t) => {
1544
1569
  if (e.length !== t.length) return !1;
1545
- for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
1570
+ for (let n = 0; n < e.length; n++) if (Z(e[n]) !== Z(t[n])) return !1;
1546
1571
  return !0;
1547
- }, $i = (e, t) => {
1572
+ }, ua = (e, t) => {
1548
1573
  if (e.length >= t.length) return !1;
1549
- for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
1574
+ for (let n = 0; n < e.length; n++) if (Z(e[n]) !== Z(t[n])) return !1;
1550
1575
  return !0;
1551
- }, ea = (e) => {
1576
+ }, da = (e) => {
1552
1577
  let t = [], n = e.appliedIndexes, r = e.tableName;
1553
1578
  for (let e = 0; e < n.length; e++) {
1554
1579
  let i = n[e];
1555
1580
  for (let a = e + 1; a < n.length; a++) {
1556
1581
  let e = n[a];
1557
- if (Qi(i.fields, e.fields)) {
1582
+ if (la(i.fields, e.fields)) {
1558
1583
  let [n, a] = i.name < e.name ? [i, e] : [e, i];
1559
1584
  t.push({
1560
1585
  kind: "duplicate-fields",
1561
1586
  table: r,
1562
1587
  redundant: n,
1563
1588
  coveredBy: a,
1564
- message: `'${r}' has two indexes on the same fields [${Z(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
1589
+ message: `'${r}' has two indexes on the same fields [${Q(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
1565
1590
  });
1566
1591
  continue;
1567
1592
  }
1568
- $i(i.fields, e.fields) ? t.push({
1593
+ ua(i.fields, e.fields) ? t.push({
1569
1594
  kind: "redundant-prefix",
1570
1595
  table: r,
1571
1596
  redundant: i,
1572
1597
  coveredBy: e,
1573
- message: `'${r}' index '${i.name}' on [${Z(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Z(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(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).`
1574
- }) : $i(e.fields, i.fields) && t.push({
1598
+ 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).`
1599
+ }) : ua(e.fields, i.fields) && t.push({
1575
1600
  kind: "redundant-prefix",
1576
1601
  table: r,
1577
1602
  redundant: e,
1578
1603
  coveredBy: i,
1579
- message: `'${r}' index '${e.name}' on [${Z(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Z(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
1604
+ message: `'${r}' index '${e.name}' on [${Q(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Q(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
1580
1605
  });
1581
1606
  }
1582
1607
  }
1583
1608
  return t;
1584
- }, ta = (e) => {
1609
+ }, fa = (e) => {
1585
1610
  let t = [];
1586
- for (let n of e) t.push(...ea(n));
1611
+ for (let n of e) t.push(...da(n));
1587
1612
  return t;
1588
- }, na = "\x1B[", ra = `${na}38;2;245;158;11m`, ia = `${na}38;2;16;185;129m`, aa = (e, t) => `${e}${t}${j.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : aa(t, n) : n, oa = (e, t = {}) => {
1589
- let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, j.dim, e.padEnd(11)), a = (e) => Q(n, (e) => j.bold(j.brand(e)), e), o = (e) => Q(n, j.brightRed24, e), s = (e) => Q(n, ia, e), c = (e) => Q(n, ra, e), l = (e) => Q(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
1613
+ }, pa = "\x1B[", ma = `${pa}38;2;245;158;11m`, ha = `${pa}38;2;16;185;129m`, ga = (e, t) => `${e}${t}${j.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : ga(t, n) : n, _a = (e, t = {}) => {
1614
+ let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, j.dim, e.padEnd(11)), a = (e) => $(n, (e) => j.bold(j.brand(e)), e), o = (e) => $(n, j.brightRed24, e), s = (e) => $(n, ha, e), c = (e) => $(n, ma, e), l = (e) => $(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
1590
1615
  let n = e.slice(0, t), r = e.slice(t), i = [];
1591
1616
  return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
1592
1617
  }, m = [];
1593
- 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(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(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 ${Q(n, j.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");
1594
- }, sa = (e, t) => ({
1618
+ 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, j.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");
1619
+ }, va = (e, t) => ({
1595
1620
  name: e,
1596
1621
  body: t
1597
- }), ca = (e) => {
1622
+ }), ya = (e) => {
1598
1623
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
1599
1624
  if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
1600
- let t = e.steps({ step: sa });
1625
+ let t = e.steps({ step: va });
1601
1626
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
1602
1627
  return {
1603
1628
  __seed: !0,
@@ -1609,13 +1634,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1609
1634
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
1610
1635
  steps: t
1611
1636
  };
1612
- }, la = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, ua = (e, { apply: t, undo: n }) => ({
1637
+ }, ba = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, xa = (e, { apply: t, undo: n }) => ({
1613
1638
  name: e,
1614
1639
  apply: t,
1615
1640
  undo: n
1616
- }), da = (e) => {
1641
+ }), Sa = (e) => {
1617
1642
  if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
1618
- let t = e.steps({ step: ua });
1643
+ let t = e.steps({ step: xa });
1619
1644
  if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
1620
1645
  return {
1621
1646
  __migration: !0,
@@ -1623,7 +1648,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1623
1648
  name: e.name,
1624
1649
  steps: t
1625
1650
  };
1626
- }, fa = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, pa = w("_voltro_migrations", {
1651
+ }, Ca = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, wa = w("_voltro_migrations", {
1627
1652
  id: O({ prefix: "mig" }),
1628
1653
  name: E(),
1629
1654
  hash: E(),
@@ -1635,7 +1660,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1635
1660
  workflowRunId: E().nullable(),
1636
1661
  createdAt: _().default("now"),
1637
1662
  updatedAt: _().default("now").onUpdate("now")
1638
- }).index(["status"]), ma = w("_voltro_seeds", {
1663
+ }).index(["status"]), Ta = w("_voltro_seeds", {
1639
1664
  id: O({ prefix: "seed" }),
1640
1665
  name: E(),
1641
1666
  lifecycle: E(),
@@ -1651,7 +1676,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1651
1676
  workflowRunId: E().nullable(),
1652
1677
  createdAt: _().default("now"),
1653
1678
  updatedAt: _().default("now").onUpdate("now")
1654
- }).index(["lifecycle"]).index(["nextRunAt"]), ha = w("_voltro_migration_plans", {
1679
+ }).index(["lifecycle"]).index(["nextRunAt"]), Ea = w("_voltro_migration_plans", {
1655
1680
  id: O({ prefix: "plan" }),
1656
1681
  fingerprint: E(),
1657
1682
  operations: D(),
@@ -1666,21 +1691,21 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1666
1691
  appliedAt: _().default("now"),
1667
1692
  createdAt: _().default("now"),
1668
1693
  updatedAt: _().default("now").onUpdate("now")
1669
- }).index(["fingerprint"]).index(["environment"]), ga = w("_voltro_idempotency", {
1694
+ }).index(["fingerprint"]).index(["environment"]), Da = w("_voltro_idempotency", {
1670
1695
  id: O({ prefix: "idem" }),
1671
1696
  scope: E(),
1672
1697
  key: E(),
1673
1698
  status: E(),
1674
1699
  response: D().nullable(),
1675
1700
  createdAt: _().default("now")
1676
- }).unique(["scope", "key"]).index(["createdAt"]), _a = w("_voltro_kv", {
1701
+ }).unique(["scope", "key"]).index(["createdAt"]), Oa = w("_voltro_kv", {
1677
1702
  id: O({ prefix: "kv" }),
1678
1703
  key: E().unique(),
1679
1704
  value: E().nullable(),
1680
1705
  expiresAt: _().nullable(),
1681
1706
  createdAt: _().default("now"),
1682
1707
  updatedAt: _().default("now").onUpdate("now")
1683
- }).index(["expiresAt"]), va = w("_voltro_api_keys", {
1708
+ }).index(["expiresAt"]), ka = w("_voltro_api_keys", {
1684
1709
  id: O({ prefix: "apikey" }),
1685
1710
  tenantId: E().nullable(),
1686
1711
  name: E(),
@@ -1695,72 +1720,72 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1695
1720
  onBehalfOf: E().nullable(),
1696
1721
  metadata: D().nullable(),
1697
1722
  createdAt: _().default("now")
1698
- }).index("byTenant", ["tenantId"]), ya = [
1699
- pa,
1700
- ma,
1701
- ha
1702
- ], $ = "id", ba = (e, t) => {
1723
+ }).index("byTenant", ["tenantId"]), Aa = [
1724
+ wa,
1725
+ Ta,
1726
+ Ea
1727
+ ], ja = "id", Ma = (e, t) => {
1703
1728
  let n = u(e);
1704
1729
  if (n === void 0) return t;
1705
- let r = n.fields[$]?.idScheme;
1706
- if (r === void 0 || t[$] != null) return t;
1730
+ let r = n.fields[ja]?.idScheme;
1731
+ if (r === void 0 || t[ja] != null) return t;
1707
1732
  if (r.kind === "numeric") {
1708
- if (!($ in t)) return t;
1733
+ if (!(ja in t)) return t;
1709
1734
  let e = { ...t };
1710
- return delete e[$], e;
1735
+ return delete e[ja], e;
1711
1736
  }
1712
1737
  let i = le(r, e);
1713
1738
  return i === null ? t : {
1714
1739
  ...t,
1715
- [$]: i
1740
+ [ja]: i
1716
1741
  };
1717
- }, xa = (e, t) => t.map((t) => ba(e, t)), Sa = (e, t) => {
1742
+ }, Na = (e, t) => t.map((t) => Ma(e, t)), Pa = (e, t) => {
1718
1743
  let n = [], r = t;
1719
1744
  for (let [t, i] of Object.entries(e.fields)) {
1720
1745
  let e = i;
1721
1746
  e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
1722
1747
  }
1723
1748
  return n;
1724
- }, Ca = (e, t) => {
1749
+ }, Fa = (e, t) => {
1725
1750
  let n = t;
1726
1751
  return e.filter((e) => n[e] === void 0 || n[e] === null);
1727
- }, wa = (e, t, n) => e.insert(t.tableName, n), Ta = (e, t, n, r) => e.upsert(t.tableName, n, {
1752
+ }, Ia = (e, t, n) => e.insert(t.tableName, n), La = (e, t, n, r) => e.upsert(t.tableName, n, {
1728
1753
  conflictColumns: r.conflictColumns,
1729
1754
  ...r.update === void 0 ? {} : { update: r.update }
1730
- }), Ea = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Da = 512, Oa = (e) => {
1755
+ }), Ra = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), za = 512, Ba = (e) => {
1731
1756
  e.setMaxListeners(512);
1732
- }, ka = (e, t, n) => ({
1757
+ }, Va = (e, t, n) => ({
1733
1758
  _tag: "PrimaryKeyConflictError",
1734
1759
  table: e,
1735
1760
  key: t,
1736
1761
  cause: n
1737
- }), Aa = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", ja = /* @__PURE__ */ new Map(), Ma = (e) => {
1762
+ }), Ha = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Ua = /* @__PURE__ */ new Map(), Wa = (e) => {
1738
1763
  if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
1739
1764
  if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
1740
- ja.set(e.table, e);
1741
- }, Na = () => [...ja.values()], Pa = () => ja.clear(), Fa = async (e, t, n, r = 2e4) => {
1765
+ Ua.set(e.table, e);
1766
+ }, Ga = () => [...Ua.values()], Ka = () => Ua.clear(), qa = async (e, t, n, r = 2e4) => {
1742
1767
  let i = new Date(t - e.ttlMs), a = 0;
1743
1768
  for (;;) {
1744
1769
  let t = await n(e.table, e.timeColumn, i, r, e.where);
1745
1770
  if (a += t, t < r) break;
1746
1771
  }
1747
1772
  return a;
1748
- }, Ia = (e, t) => {
1773
+ }, Ja = (e, t) => {
1749
1774
  let n = Number(e ?? String(t));
1750
1775
  return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
1751
- }, La = "_voltro_cdc_offsets", Ra = w(La, {
1776
+ }, Ya = "_voltro_cdc_offsets", Xa = w(Ya, {
1752
1777
  id: O({ prefix: "cdcoff" }),
1753
1778
  replicaId: E(),
1754
1779
  streamName: E(),
1755
1780
  binlogFile: E(),
1756
1781
  binlogPosition: E(),
1757
1782
  updatedAt: _()
1758
- }).index(["replicaId"]), za = w(La, {
1783
+ }).index(["replicaId"]), Za = w(Ya, {
1759
1784
  id: O({ prefix: "cdcoff" }),
1760
1785
  replicaId: E(),
1761
1786
  streamName: E(),
1762
1787
  ctVersion: E(),
1763
1788
  updatedAt: _()
1764
- }).index(["replicaId"]), Ba = "postgres";
1789
+ }).index(["replicaId"]), Qa = "postgres";
1765
1790
  //#endregion
1766
- export { oe as AUTO_FILLED_COLUMNS, J as BranchNameInvalid, Ei as BranchTransitionInvalid, La as CDC_OFFSETS_TABLE, Da as CHANGE_LISTENER_CEILING, Xe as ColumnBuilder, ht as ENCRYPTED_PREFIX, Ba as ENGINE, en as EagerCardinalityError, qe as FILE_MIGRATION_PATTERN, gt as FieldDecryptionError, e as MAX_IDENTIFIER_LENGTH, ut as SqlClient, mi as TableStreamError, mn as TenantNamespaceInvalid, pn as TenantNamespaceUnresolved, Hi as TenantRegionUnavailable, Vi as TenantResidencyUnresolved, xe as WARN_IDENTIFIER_LENGTH, va as _voltroApiKeysTable, Ra as _voltroCdcOffsetsTable, ga as _voltroIdempotencyTable, _a as _voltroKvTable, ha as _voltroMigrationPlansTable, pa as _voltroMigrationsTable, za as _voltroMssqlCdcOffsetsTable, ma as _voltroSeedsTable, Rr as actorsTable, zi as admitBranch, ze as allEnumRenames, Ut as allRegisteredRelations, ee as allRegisteredTables, ti as and, be as array, Yr as arrayContains, Zr as arrayHas, Xr as arrayOverlaps, nn as attachEagerLoads, ta as auditAllTableIndexes, ea as auditTableIndexes, Me as avg, Ye as avgOver, Ce as bigint, Xi as bindResidentStore, Ve as boolean, Ci as branchNamespaceName, Fe as bytes, Ke as clearEnumRenames, Gt as clearRelationsRegistry, Ki as clearResidencyConfig, Pa as clearRetentions, v as clearTableRegistry, Sn as coercePredicateValue, Cn as coercePredicateValues, fi as collectSubqueries, ye as column, St as columnSchema, Fn as compileEagerJson, L as compilePredicate, wn as compileRawFragment, R as compileSelect, yi as computeEmbedding, qr as contains, Se as count, Be as countDistinct, Pe as databaseHandle, De as date, Te as dbEnum, fe as decimal, ve as declareEnumRename, Zt as decodeRowsFromSchema, xt as decryptFieldsOnRead, da as defineMigration, d as defineMixin, ca as defineSeed, Ee as denseRank, m as deriveTypeIdPrefix, mt as deserializeArraysOnRead, Je as drainIdentifierWarnings, Qe as dropped, $t as encodeRowForSchema, bt as encryptFieldsForWrite, yt as encryptedColumnsOf, Ii as enforceBranchLimits, te as ensureTableRegistered, zr as eq, I as escapeLike, di as evaluatePredicate, we as except, ci as exists, oa as formatIndexAuditIssue, ya as frameworkTables, le as generateId, ue as generateSnowflake, nt as geography, ge as geometry, Ne as getEnumRenames, Ht as getRelation, Vt as getRelations, Gi as getResidencyConfig, u as getTable, Vr as gt, Hr as gte, fn as hasEagerLoads, vi as hybridSearch, O as id, Gr as inSet, oi as inSubquery, M as inferForeignKey, wa as insertRow, C as integer, de as intersect, a as interval, wi as isBranchNamespace, vt as isEncrypted, _t as isFieldDecryptionError, Ie as isFileMigration, fa as isMigrationDefinition, Ai as isNeonConnection, $r as isNotNull, Qr as isNull, Aa as isPrimaryKeyConflictError, Ji as isRegionServable, At as isRelationsSpec, la as isSeedDefinition, rt as isSqliteFamily, p as isTableReactive, pe as isView, D as json, ii as jsonField, f as jsonIndex, Ze as lag, tt as lead, Na as listRetentions, Ur as lt, Wr as lte, Bi as makeNamespaceBranchExecutor, Mt as many, Nt as manyToMany, ae as materializeFields, he as max, Ue as migration, et as min, Ca as missingConflictColumns, Sa as missingRequiredColumns, h as mixin, Br as neq, Di as nextBranchState, ri as not, li as notExists, Kr as notInSet, si as notInSubquery, l as numeric, jt as one, tn as oneCardinalityMessage, ni as or, re as paginateBy, i as paginateById, Pi as planBranch, Oi as planBranchProvision, ki as planBranchTeardown, Fi as planBranchTeardownFor, Mi as planNeonBranchProvision, Ni as planNeonBranchTeardown, ka as primaryKeyConflictError, Li as provisionBranch, Zi as provisionResidentTenant, yn as qualifyTable, $e as queryFor, Re as queryForView, r as quoteIdent, Oa as raiseChangeListenerCeiling, ie as rank, s as raw, x as real, je as reference, Pr as registerCoreTables, Bt as registerDiscoveredRelations, zt as registerRelations, Ma as registerRetention, g as registerTable, kt as relations, Ir as requireActors, ne as requireTable, Lr as requireTenants, S as resetSnowflake, Yi as residentPlacement, ji as resolveBranchMechanism, c as resolveFullTextIndex, ce as resolveIdScheme, He as resolveMixinGraph, qi as resolveTenantHome, vn as resolveTenantNamespace, Ia as retentionTtlMsFromEnv, o as rowNumber, Ct as rowSchema, _n as sanitizeIdentifierFragment, pt as serializeArraysForWrite, n as serverOnlyColumns, Wi as setResidencyConfig, ei as spatialPredicate, ba as stampGeneratedId, xa as stampGeneratedIds, Jr as startsWith, _i as streamTable, b as sum, Ae as sumOver, Fa as sweepRetention, w as table, Ri as teardownBranch, E as text, _ as timestamp, it as timestampMs, at as timestampMsOrNull, t as union, ke as unionAll, Ea as updateManyRow, Ta as upsertRow, Le as validateColumnName, We as validateIndexName, Wt as validateRegisteredRelations, It as validateRelationConfig, Oe as validateTableName, me as validateTypeIdPrefix, y as vector, se as vectorDistanceToOpclass, bi as vectorEmbedding, Ge as view, _e as viewSql, pi as walkLeaves };
1791
+ export { oe as AUTO_FILLED_COLUMNS, Y as BranchNameInvalid, Li as BranchTransitionInvalid, Ya as CDC_OFFSETS_TABLE, za as CHANGE_LISTENER_CEILING, Xe as ColumnBuilder, gt as ENCRYPTED_PREFIX, Qa as ENGINE, tn as EagerCardinalityError, qe as FILE_MIGRATION_PATTERN, _t as FieldDecryptionError, $r as MATCHES_NO_ROWS, e as MAX_IDENTIFIER_LENGTH, dt as SqlClient, Ti as TableStreamError, hn as TenantNamespaceInvalid, mn as TenantNamespaceUnresolved, $i as TenantRegionUnavailable, Qi as TenantResidencyUnresolved, xe as WARN_IDENTIFIER_LENGTH, ka as _voltroApiKeysTable, Xa as _voltroCdcOffsetsTable, Da as _voltroIdempotencyTable, Oa as _voltroKvTable, Ea as _voltroMigrationPlansTable, wa as _voltroMigrationsTable, Za as _voltroMssqlCdcOffsetsTable, Ta as _voltroSeedsTable, zr as actorsTable, Xi as admitBranch, ze as allEnumRenames, Wt as allRegisteredRelations, ee as allRegisteredTables, ri as and, be as array, Xr as arrayContains, Qr as arrayHas, Zr as arrayOverlaps, rn as attachEagerLoads, yi as attributionFields, fa as auditAllTableIndexes, da as auditTableIndexes, Me as avg, Ye as avgOver, Ce as bigint, sa as bindResidentStore, Ve as boolean, Pi as branchNamespaceName, Fe as bytes, Ke as clearEnumRenames, Kt as clearRelationsRegistry, ra as clearResidencyConfig, Ka as clearRetentions, v as clearTableRegistry, Si as clearWriteRecorders, Cn as coercePredicateValue, wn as coercePredicateValues, mi as collectSubqueries, ye as column, Ct as columnSchema, In as compileEagerJson, L as compilePredicate, Tn as compileRawFragment, R as compileSelect, Ai as computeEmbedding, Jr as contains, Se as count, Be as countDistinct, vi as currentWriteAttribution, Pe as databaseHandle, De as date, Te as dbEnum, fe as decimal, ve as declareEnumRename, Qt as decodeRowsFromSchema, St as decryptFieldsOnRead, Sa as defineMigration, d as defineMixin, ya as defineSeed, Ee as denseRank, m as deriveTypeIdPrefix, ht as deserializeArraysOnRead, Je as drainIdentifierWarnings, Qe as dropped, en as encodeRowForSchema, xt as encryptFieldsForWrite, bt as encryptedColumnsOf, qi as enforceBranchLimits, te as ensureTableRegistered, Br as eq, I as escapeLike, pi as evaluatePredicate, we as except, ui as exists, _a as formatIndexAuditIssue, Aa as frameworkTables, le as generateId, ue as generateSnowflake, nt as geography, ge as geometry, Ne as getEnumRenames, Ut as getRelation, Ht as getRelations, na as getResidencyConfig, u as getTable, Hr as gt, Ur as gte, pn as hasEagerLoads, ki as hybridSearch, O as id, Kr as inSet, ci as inSubquery, M as inferForeignKey, Ia as insertRow, C as integer, de as intersect, a as interval, Fi as isBranchNamespace, yt as isEncrypted, vt as isFieldDecryptionError, Ie as isFileMigration, Ca as isMigrationDefinition, Vi as isNeonConnection, ti as isNotNull, ei as isNull, Ha as isPrimaryKeyConflictError, aa as isRegionServable, jt as isRelationsSpec, ba as isSeedDefinition, rt as isSqliteFamily, p as isTableReactive, pe as isView, D as json, oi as jsonField, f as jsonIndex, Ze as lag, tt as lead, Ga as listRetentions, Wr as lt, Gr as lte, Zi as makeNamespaceBranchExecutor, Nt as many, Pt as manyToMany, ae as materializeFields, he as max, Ue as migration, et as min, Fa as missingConflictColumns, Pa as missingRequiredColumns, h as mixin, Vr as neq, Ri as nextBranchState, ai as not, di as notExists, qr as notInSet, li as notInSubquery, l as numeric, Mt as one, nn as oneCardinalityMessage, ii as or, re as paginateBy, i as paginateById, Gi as planBranch, zi as planBranchProvision, Bi as planBranchTeardown, Ki as planBranchTeardownFor, Ui as planNeonBranchProvision, Wi as planNeonBranchTeardown, Va as primaryKeyConflictError, Ji as provisionBranch, ca as provisionResidentTenant, bn as qualifyTable, $e as queryFor, Re as queryForView, r as quoteIdent, Ba as raiseChangeListenerCeiling, ie as rank, s as raw, x as real, Ci as recordsTable, je as reference, Fr as registerCoreTables, Vt as registerDiscoveredRelations, Bt as registerRelations, Wa as registerRetention, g as registerTable, bi as registerWriteRecorder, At as relations, Lr as requireActors, ne as requireTable, Rr as requireTenants, S as resetSnowflake, oa as residentPlacement, Hi as resolveBranchMechanism, c as resolveFullTextIndex, ce as resolveIdScheme, He as resolveMixinGraph, ia as resolveTenantHome, yn as resolveTenantNamespace, Ja as retentionTtlMsFromEnv, o as rowNumber, wt as rowSchema, _i as runWithWriteAttribution, wi as runWriteRecorders, vn as sanitizeIdentifierFragment, mt as serializeArraysForWrite, n as serverOnlyColumns, ta as setResidencyConfig, ni as spatialPredicate, Ma as stampGeneratedId, Na as stampGeneratedIds, Yr as startsWith, Oi as streamTable, b as sum, Ae as sumOver, qa as sweepRetention, w as table, Yi as teardownBranch, E as text, _ as timestamp, it as timestampMs, at as timestampMsOrNull, t as union, ke as unionAll, xi as unregisterWriteRecorder, Ra as updateManyRow, La as upsertRow, Le as validateColumnName, We as validateIndexName, Gt as validateRegisteredRelations, Lt as validateRelationConfig, Oe as validateTableName, me as validateTypeIdPrefix, y as vector, se as vectorDistanceToOpclass, ji as vectorEmbedding, Ge as view, _e as viewSql, hi as walkLeaves };