@voltro/database 0.17.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,50 +413,50 @@ 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}`;
449
- }, Tn = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), I = (e, t, n = null, r) => {
450
- if ("not" in e) return t`NOT (${I(e.not, t, n, r)})`;
451
- if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => I(e, t, n, r)));
452
- if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => I(e, t, n, r)));
450
+ }, I = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), L = (e, t, n = null, r) => {
451
+ if ("not" in e) return t`NOT (${L(e.not, t, n, r)})`;
452
+ if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => L(e, t, n, r)));
453
+ if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => L(e, t, n, r)));
453
454
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
454
- let r = e, i = L(r.subquery, t, n);
455
+ let r = e, i = R(r.subquery, t, n);
455
456
  return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
456
457
  }
457
458
  if (e.op === "exists" || e.op === "not-exists") {
458
- let r = e, i = L(r.subquery, t, n);
459
+ let r = e, i = R(r.subquery, t, n);
459
460
  return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
460
461
  }
461
462
  let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
@@ -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))}`;
@@ -485,7 +486,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
485
486
  return e.length === 0 ? t`TRUE` : t`${d} NOT IN ${t.in(s ? e.map((e) => p(e)) : e)}`;
486
487
  }
487
488
  case "contains": {
488
- let e = `%${Tn(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
489
+ let e = `%${I(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
489
490
  return t.onDialectOrElse({
490
491
  mysql: () => t`LOWER(${d}) LIKE LOWER(${e})`,
491
492
  mssql: () => t`LOWER(${d}) LIKE LOWER(${e})`,
@@ -493,6 +494,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
493
494
  orElse: () => t`${d} ILIKE ${e} ESCAPE '\\'`
494
495
  });
495
496
  }
497
+ case "startsWith": {
498
+ let e = `${I(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
499
+ return t.onDialectOrElse({
500
+ mysql: () => t`${d} LIKE ${e}`,
501
+ orElse: () => t`${d} LIKE ${e} ESCAPE '\\'`
502
+ });
503
+ }
496
504
  case "arrayContains": {
497
505
  let e = i.value ?? [];
498
506
  return e.length === 0 ? t`TRUE` : t.onDialectOrElse({
@@ -578,7 +586,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
578
586
  let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
579
587
  return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
580
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) => {
581
- let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${Tn(e.query)}%`;
589
+ let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${I(e.query)}%`;
582
590
  return n.onDialectOrElse({
583
591
  mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
584
592
  sqlite: () => {
@@ -589,7 +597,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
589
597
  orElse: () => n`${Mn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
590
598
  });
591
599
  }, Fn = (e, t, n) => {
592
- let r = `%${Tn(e.query)}%`;
600
+ let r = `%${I(e.query)}%`;
593
601
  return n.onDialectOrElse({
594
602
  mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
595
603
  sqlite: () => {
@@ -599,9 +607,9 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
599
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}`),
600
608
  orElse: () => n`ts_rank(${Mn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
601
609
  });
602
- }, L = (e, t, n = null) => {
610
+ }, R = (e, t, n = null) => {
603
611
  if (e.setOp && e.setOp.queries.length >= 2) {
604
- let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${L(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
612
+ let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${R(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
605
613
  if (e.order.length > 0 && a.push(t` ORDER BY ${t.csv(e.order.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
606
614
  if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
607
615
  a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
@@ -630,10 +638,10 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
630
638
  mysql: () => t`DISTINCT `,
631
639
  mssql: () => t`DISTINCT `,
632
640
  sqlite: () => t`DISTINCT `
633
- }) : 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) => {
634
642
  let r = e.kind === "inner" ? "INNER" : "LEFT";
635
- return t` ${t.unsafe(r)} JOIN ${t(yn(n, e.table))} AS ${t(e.alias)} ON ${I(e.on, t, n)}`;
636
- }), 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 ? I(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 ${I(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
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 = [];
637
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`);
638
646
  for (let n of e.order) x.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
639
647
  let te = x.length > 0 ? t` ORDER BY ${t.csv(x)}` : b ? t.onDialectOrElse({
@@ -642,7 +650,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
642
650
  }) : t``, S = (e) => {
643
651
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
644
652
  return t.unsafe(String(e));
645
- }, ne = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${L(e.descriptor, t, n)})`), re = (e.ctes ?? []).some((e) => e.recursive === !0), C = ne.length > 0 ? t`WITH ${t.unsafe(re ? "RECURSIVE " : "")}${t.csv(ne)} ` : t``;
653
+ }, ne = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${R(e.descriptor, t, n)})`), re = (e.ctes ?? []).some((e) => e.recursive === !0), C = ne.length > 0 ? t`WITH ${t.unsafe(re ? "RECURSIVE " : "")}${t.csv(ne)} ` : t``;
646
654
  return t.onDialectOrElse({
647
655
  mssql: () => {
648
656
  let n = e.take !== void 0 && !b ? t`TOP ${S(e.take)} ` : t``, r = b ? t` OFFSET ${S(e.skip)} ROWS FETCH NEXT ${S(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
@@ -655,27 +663,27 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
655
663
  });
656
664
  }, In = (e, t, n) => {
657
665
  if (e.eager === void 0) return null;
658
- let r = Ln(e.table, e.eager, e.sourceTable);
666
+ let r = Rn(e.table, e.eager, e.sourceTable);
659
667
  if (r === null) return null;
660
- let i = Wn(n, e, r, Un(t, n));
668
+ let i = Gn(n, e, r, Wn(t, n));
661
669
  return i === null ? null : {
662
670
  fragment: i,
663
- decode: qn(r, n)
671
+ decode: Jn(r, n)
664
672
  };
665
- }, R = (e) => e.relation.kind === "one" && e.fkSide === "target", z = (e) => ({
673
+ }, z = (e) => e.relation.kind === "one" && e.fkSide === "target", Ln = (e) => ({
666
674
  ...e,
667
675
  branch: {
668
676
  ...e.branch,
669
677
  limit: 2
670
678
  }
671
- }), Ln = (e, t, n) => {
672
- let r = n ?? ne(e), i = Vt(e);
679
+ }), Rn = (e, t, n) => {
680
+ let r = n ?? ne(e), i = Ht(e);
673
681
  if (i === void 0) return null;
674
682
  let a = [];
675
683
  for (let [e, n] of Object.entries(t)) {
676
684
  let t = i[e];
677
685
  if (t === void 0) return null;
678
- let o = Rn(e, t, r, n === !0 ? {} : n);
686
+ let o = zn(e, t, r, n === !0 ? {} : n);
679
687
  if (o === null) return null;
680
688
  a.push(o);
681
689
  }
@@ -683,11 +691,11 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
683
691
  table: r,
684
692
  children: a
685
693
  };
686
- }, Rn = (e, t, n, r) => {
694
+ }, zn = (e, t, n, r) => {
687
695
  let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
688
696
  if (t.kind === "manyToMany") o = t.targetKey, s = "target";
689
697
  else if (t.kind === "one") {
690
- let r = t.sourceKey ?? Hn(n, i.tableName);
698
+ let r = t.sourceKey ?? Un(n, i.tableName);
691
699
  if (r !== void 0) o = r, s = "source";
692
700
  else try {
693
701
  o = t.foreignKey ?? M(i, n.tableName, e), s = "target";
@@ -700,13 +708,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
700
708
  return null;
701
709
  }
702
710
  let c = r.with === void 0 ? [] : (() => {
703
- let e = Vt(i.tableName);
711
+ let e = Ht(i.tableName);
704
712
  if (e === void 0 && Object.keys(r.with).length > 0) return null;
705
713
  let t = [];
706
714
  for (let [n, a] of Object.entries(r.with)) {
707
715
  let r = e?.[n];
708
716
  if (r === void 0) return null;
709
- let o = Rn(n, r, i, a === !0 ? {} : a);
717
+ let o = zn(n, r, i, a === !0 ? {} : a);
710
718
  if (o === null) return null;
711
719
  t.push(o);
712
720
  }
@@ -722,9 +730,9 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
722
730
  fkSide: s,
723
731
  branch: r,
724
732
  children: c,
725
- junction: zn(t, r)
733
+ junction: Bn(t, r)
726
734
  };
727
- }, zn = (e, t) => {
735
+ }, Bn = (e, t) => {
728
736
  if (e.kind !== "manyToMany" || t.junction === void 0) return;
729
737
  let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
730
738
  return {
@@ -736,35 +744,35 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
736
744
  return t !== void 0 && (t.type === "timestamp" || t.type === "date");
737
745
  })
738
746
  };
739
- }, Bn = (e) => `__j_${e}`, Vn = "__j", Hn = (e, t) => {
747
+ }, Vn = (e) => `__j_${e}`, Hn = "__j", Un = (e, t) => {
740
748
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
741
- }, Un = (e, t) => {
749
+ }, Wn = (e, t) => {
742
750
  let n = 0;
743
751
  return {
744
752
  sql: e,
745
753
  dialect: t,
746
754
  nextAlias: () => `__a${n++}`
747
755
  };
748
- }, Wn = (e, t, n, r) => {
756
+ }, Gn = (e, t, n, r) => {
749
757
  switch (e) {
750
- case "postgres": return Xn(t, n, r);
758
+ case "postgres": return Zn(t, n, r);
751
759
  case "sqlite":
752
- case "turso": return ir(t, n, r);
760
+ case "turso": return ar(t, n, r);
753
761
  case "mysql":
754
- case "mariadb": return mr(t, n, r);
755
- case "mssql": return xr(t, n, r);
762
+ case "mariadb": return hr(t, n, r);
763
+ case "mssql": return Sr(t, n, r);
756
764
  }
757
- }, 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) => {
758
- 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);
759
767
  return (e) => e.map((e) => {
760
768
  let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
761
769
  return n(r);
762
770
  });
763
- }, Jn = (e, t, n) => {
771
+ }, Yn = (e, t, n) => {
764
772
  let r = [];
765
773
  for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
766
774
  let i = t.map((e) => {
767
- let t = Jn(e.target, e.children, n), r = e.relation.kind === "one", i = R(e), a = i ? tn({
775
+ let t = Yn(e.target, e.children, n), r = e.relation.kind === "one", i = z(e), a = i ? nn({
768
776
  relationName: e.relationName,
769
777
  sourceTableName: e.source.tableName,
770
778
  targetTableName: e.target.tableName,
@@ -777,14 +785,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
777
785
  isSingle: r,
778
786
  fromOverFetch: i,
779
787
  cardinalityMessage: a,
780
- junction: Yn(e.junction, n)
788
+ junction: Xn(e.junction, n)
781
789
  };
782
790
  });
783
791
  return (e) => {
784
792
  let t = { ...e };
785
793
  for (let e of r) {
786
794
  let r = t[e];
787
- typeof r == "string" && (t[e] = Gn(r, n));
795
+ typeof r == "string" && (t[e] = Kn(r, n));
788
796
  }
789
797
  for (let e of i) {
790
798
  let n = t[e.name];
@@ -794,7 +802,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
794
802
  }
795
803
  if (e.fromOverFetch) {
796
804
  let r = n;
797
- if (r.length > 1) throw new en(e.cardinalityMessage);
805
+ if (r.length > 1) throw new tn(e.cardinalityMessage);
798
806
  t[e.name] = r.length === 0 ? null : e.decode(r[0]);
799
807
  continue;
800
808
  }
@@ -806,104 +814,104 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
806
814
  }
807
815
  return t;
808
816
  };
809
- }, Yn = (e, t) => {
817
+ }, Xn = (e, t) => {
810
818
  if (e === void 0) return;
811
819
  let n = new Set(e.dateColumns), r = e.requested;
812
820
  return (e) => {
813
821
  let i = e._junction ?? {}, a = {};
814
822
  for (let e of r) {
815
823
  let r = i[e];
816
- 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;
817
825
  }
818
826
  return {
819
827
  ...e,
820
828
  _junction: a
821
829
  };
822
830
  };
823
- }, Xn = (e, t, n) => {
824
- 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);
825
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)}`}`;
826
- }, Zn = (e, t, n, r) => {
827
- 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)`;
828
836
  if (t.length === 0 && r === void 0) return a;
829
837
  let o = [];
830
- 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)}`);
831
839
  for (let r of t) {
832
- let t = Qn(r, e, n);
840
+ let t = $n(r, e, n);
833
841
  if (t === null) return null;
834
842
  o.push(i`${U(r.relationName, i)}, ${t}`);
835
843
  }
836
844
  return i`${a} || jsonb_build_object(${i.csv(o)})`;
837
- }, Qn = (e, t, n) => {
845
+ }, $n = (e, t, n) => {
838
846
  switch (e.relation.kind) {
839
- case "one": return R(e) ? er(z(e), t, n) : $n(e, t, n);
840
- case "many": return er(e, t, n);
841
- 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);
842
850
  }
843
- }, $n = (e, t, n) => {
844
- 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);
845
853
  if (a === null) return null;
846
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);
847
855
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
848
- }, er = (e, t, n) => {
849
- 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);
850
858
  if (a === null) return null;
851
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(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)}`;
852
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)`;
853
- }, tr = (e, t, n) => {
854
- 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);
855
863
  if (c === null) return null;
856
- let l = e.branch.where === void 0 ? r`` : r` AND ${I(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)}`;
857
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)`;
858
- }, 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) => {
859
- 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);
860
868
  if (a === null) return null;
861
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)}`;
862
870
  return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
863
- }, ar = (e, t, n, r, i) => {
871
+ }, or = (e, t, n, r, i) => {
864
872
  let a = r.sql, o = [];
865
873
  for (let n of Object.keys(t.fields)) o.push(a`${U(n, a)}, ${H(e, n, a)}`);
866
874
  if (i !== void 0) {
867
- let e = or(i.projection, i.source, a);
875
+ let e = sr(i.projection, i.source, a);
868
876
  o.push(a`${U("_junction", a)}, json_object(${e})`);
869
877
  }
870
878
  for (let t of n) {
871
- let n = ur(t, e, r);
879
+ let n = dr(t, e, r);
872
880
  if (n === null) return null;
873
881
  o.push(a`${U(t.relationName, a)}, ${n}`);
874
882
  }
875
883
  return a`json_object(${a.csv(o)})`;
876
- }, 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) => ({
877
885
  alias: e,
878
- physical: Bn
879
- }), lr = (e) => ({
886
+ physical: Vn
887
+ }), ur = (e) => ({
880
888
  alias: e,
881
889
  physical: (e) => e
882
- }), ur = (e, t, n) => {
890
+ }), dr = (e, t, n) => {
883
891
  switch (e.relation.kind) {
884
- case "one": return R(e) ? fr(z(e), t, n) : dr(e, t, n);
885
- case "many": return fr(e, t, n);
886
- 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);
887
895
  }
888
- }, dr = (e, t, n) => {
889
- 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);
890
898
  if (a === null) return null;
891
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)}`;
892
900
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
893
- }, fr = (e, t, n) => {
894
- 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);
895
903
  if (a === null) return null;
896
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(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)}`;
897
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('[]'))`;
898
- }, pr = (e, t, n) => {
899
- 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 : {
900
908
  projection: e.junction,
901
- source: cr(o)
909
+ source: lr(o)
902
910
  });
903
911
  if (c === null) return null;
904
- let l = e.branch.where === void 0 ? r`` : r` AND ${I(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);
905
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('[]'))`;
906
- }, mr = (e, t, n) => {
914
+ }, hr = (e, t, n) => {
907
915
  let r = n.sql, i = n.nextAlias(), a = V(i, t.table, t.children, n);
908
916
  if (a === null) return null;
909
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)}`;
@@ -912,66 +920,66 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
912
920
  let a = r.sql, o = [];
913
921
  for (let n of Object.keys(t.fields)) o.push(a`${U(n, a)}, ${H(e, n, a)}`);
914
922
  if (i !== void 0) {
915
- let e = or(i.projection, i.source, a);
923
+ let e = sr(i.projection, i.source, a);
916
924
  o.push(a`${U("_junction", a)}, JSON_OBJECT(${e})`);
917
925
  }
918
926
  for (let t of n) {
919
- let n = hr(t, e, r);
927
+ let n = gr(t, e, r);
920
928
  if (n === null) return null;
921
929
  o.push(a`${U(t.relationName, a)}, ${n}`);
922
930
  }
923
931
  return a`JSON_OBJECT(${a.csv(o)})`;
924
- }, hr = (e, t, n) => {
932
+ }, gr = (e, t, n) => {
925
933
  switch (e.relation.kind) {
926
934
  case "one":
927
- if (R(e)) {
928
- let r = z(e);
929
- return n.dialect === "mariadb" ? yr(r, t, n) : _r(r, t, n);
935
+ if (z(e)) {
936
+ let r = Ln(e);
937
+ return n.dialect === "mariadb" ? br(r, t, n) : vr(r, t, n);
930
938
  }
931
- return gr(e, t, n);
932
- case "many": return n.dialect === "mariadb" ? yr(e, t, n) : _r(e, t, n);
933
- 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);
934
942
  }
935
- }, gr = (e, t, n) => {
943
+ }, _r = (e, t, n) => {
936
944
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
937
945
  if (a === null) return null;
938
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)}`;
939
947
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
940
- }, _r = (e, t, n) => {
948
+ }, vr = (e, t, n) => {
941
949
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
942
950
  if (a === null) return null;
943
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(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)}`;
944
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())`;
945
- }, vr = (e, t, n) => {
953
+ }, yr = (e, t, n) => {
946
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 : {
947
955
  projection: e.junction,
948
- source: cr(o)
956
+ source: lr(o)
949
957
  });
950
958
  if (c === null) return null;
951
- let l = e.branch.where === void 0 ? r`` : r` AND ${I(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);
952
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())`;
953
- }, yr = (e, t, n) => {
961
+ }, br = (e, t, n) => {
954
962
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
955
963
  if (a === null) return null;
956
- let o = r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
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 ?? [];
957
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())`;
958
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)}`;
959
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())`;
960
- }, br = (e, t, n) => {
968
+ }, xr = (e, t, n) => {
961
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 : {
962
970
  projection: e.junction,
963
971
  source: t
964
- }, 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 ${I(q(e.branch.where), r)}`, f = K(e, s, r, !0), p = e.branch.orderBy ?? [];
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 ?? [];
965
973
  if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
966
- 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)));
967
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())`;
968
976
  }
969
- 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)));
970
978
  if (v === null) return null;
971
- 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);
972
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())`;
973
- }, xr = (e, t, n) => {
974
- 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);
975
983
  if (a === null) return null;
976
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``;
977
985
  if (e.skip !== void 0) {
@@ -980,28 +988,28 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
980
988
  } else e.take !== void 0 && (c = r`TOP ${W(e.take, r)} `);
981
989
  let u = e.skip === void 0 ? s : r``;
982
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}`;
983
- }, Sr = (e, t, n, r, i) => {
991
+ }, Cr = (e, t, n, r, i) => {
984
992
  let a = r.sql, o = [];
985
993
  for (let n of Object.keys(t.fields)) o.push(a`${H(e, n, a)} AS ${a(n)}`);
986
- 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)}`);
987
995
  for (let t of n) {
988
- let n = wr(t, e, r);
996
+ let n = Tr(t, e, r);
989
997
  if (n === null) return null;
990
998
  o.push(n);
991
999
  }
992
1000
  return a.csv(o);
993
- }, 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) => {
994
1002
  switch (e.relation.kind) {
995
- case "one": return R(e) ? Dr(z(e), t, n) : Tr(e, t, n);
996
- case "many": return Dr(e, t, n);
997
- 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);
998
1006
  }
999
- }, Tr = (e, t, n) => {
1000
- 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);
1001
1009
  if (a === null) return null;
1002
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)}`;
1003
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)}`;
1004
- }, Er = (e, t, n) => {
1012
+ }, Dr = (e, t, n) => {
1005
1013
  if (e.offset !== void 0) {
1006
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`;
1007
1015
  return {
@@ -1015,29 +1023,29 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1015
1023
  pagination: n``,
1016
1024
  finalOrder: t
1017
1025
  };
1018
- }, Dr = (e, t, n) => {
1019
- 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);
1020
1028
  if (a === null) return null;
1021
- 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);
1022
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)}`;
1023
- }, Or = (e, t, n) => {
1024
- 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 : {
1025
1033
  projection: e.junction,
1026
- source: lr(s)
1034
+ source: ur(s)
1027
1035
  });
1028
1036
  if (c === null) return null;
1029
- 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);
1030
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)}`;
1031
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) => {
1032
1040
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
1033
1041
  return t.unsafe(String(e));
1034
- }, G = (e, t, n) => I(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) => {
1035
1043
  let i = e.branch.onJunction;
1036
1044
  return i === void 0 ? n`` : n` AND ${G(r ? q(i) : i, t, n)}`;
1037
- }, kr = (e, t) => {
1038
- if ("not" in e) return { not: kr(e.not, t) };
1039
- if ("and" in e) return { and: e.and.map((e) => kr(e, t)) };
1040
- 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)) };
1041
1049
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
1042
1050
  let n = e;
1043
1051
  return {
@@ -1059,15 +1067,15 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1059
1067
  let t = e;
1060
1068
  return {
1061
1069
  ...t,
1062
- value: Ar(t.value)
1070
+ value: jr(t.value)
1063
1071
  };
1064
- }, 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) => {
1065
- e.actors !== void 0 && (Nr.actors = e.actors), e.tenants !== void 0 && (Nr.tenants = e.tenants);
1066
- }, 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) => () => {
1067
1075
  let n = e();
1068
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`);
1069
1077
  return n();
1070
- }, 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", {
1071
1079
  id: O(),
1072
1080
  kind: E().oneOf([
1073
1081
  "user",
@@ -1077,65 +1085,73 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1077
1085
  ]),
1078
1086
  displayName: E().nullable(),
1079
1087
  createdAt: _().default("now")
1080
- }), zr = (e, t) => ({
1088
+ }), Br = (e, t) => ({
1081
1089
  column: e,
1082
1090
  op: "eq",
1083
1091
  value: t
1084
- }), Br = (e, t) => ({
1092
+ }), Vr = (e, t) => ({
1085
1093
  column: e,
1086
1094
  op: "neq",
1087
1095
  value: t
1088
- }), Vr = (e, t) => ({
1096
+ }), Hr = (e, t) => ({
1089
1097
  column: e,
1090
1098
  op: "gt",
1091
1099
  value: t
1092
- }), Hr = (e, t) => ({
1100
+ }), Ur = (e, t) => ({
1093
1101
  column: e,
1094
1102
  op: "gte",
1095
1103
  value: t
1096
- }), Ur = (e, t) => ({
1104
+ }), Wr = (e, t) => ({
1097
1105
  column: e,
1098
1106
  op: "lt",
1099
1107
  value: t
1100
- }), Wr = (e, t) => ({
1108
+ }), Gr = (e, t) => ({
1101
1109
  column: e,
1102
1110
  op: "lte",
1103
1111
  value: t
1104
- }), Gr = (e, t) => ({
1112
+ }), Kr = (e, t) => ({
1105
1113
  column: e,
1106
1114
  op: "in",
1107
1115
  value: t
1108
- }), Kr = (e, t) => ({
1116
+ }), qr = (e, t) => ({
1109
1117
  column: e,
1110
1118
  op: "notIn",
1111
1119
  value: t
1112
- }), qr = (e, t) => ({
1120
+ }), Jr = (e, t) => ({
1113
1121
  column: e,
1114
1122
  op: "contains",
1115
1123
  value: t
1116
- }), Jr = (e, t) => ({
1124
+ }), Yr = (e, t) => ({
1125
+ column: e,
1126
+ op: "startsWith",
1127
+ value: t
1128
+ }), Xr = (e, t) => ({
1117
1129
  column: e,
1118
1130
  op: "arrayContains",
1119
1131
  value: t
1120
- }), Yr = (e, t) => ({
1132
+ }), Zr = (e, t) => ({
1121
1133
  column: e,
1122
1134
  op: "arrayOverlaps",
1123
1135
  value: t
1124
- }), Xr = (e, t) => ({
1136
+ }), Qr = (e, t) => ({
1125
1137
  column: e,
1126
1138
  op: "arrayHas",
1127
1139
  value: t
1128
- }), Zr = (e) => ({
1140
+ }), $r = {
1141
+ column: "id",
1142
+ op: "in",
1143
+ value: []
1144
+ }, ei = (e) => ({
1129
1145
  column: e,
1130
1146
  op: "isNull"
1131
- }), Qr = (e) => ({
1147
+ }), ti = (e) => ({
1132
1148
  column: e,
1133
1149
  op: "isNotNull"
1134
- }), $r = (e, t) => ({
1150
+ }), ni = (e, t) => ({
1135
1151
  column: e,
1136
1152
  op: "spatial",
1137
1153
  value: t
1138
- }), ei = (...e) => ({ and: e }), ti = (...e) => ({ or: e }), ni = (e) => ({ not: e }), ri = (e, ...t) => {
1154
+ }), ri = (...e) => ({ and: e }), ii = (...e) => ({ or: e }), ai = (e) => ({ not: e }), oi = (e, ...t) => {
1139
1155
  if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
1140
1156
  let n = (n, r) => ({
1141
1157
  column: e,
@@ -1153,32 +1169,33 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1153
1169
  inSet: (e) => n("in", e),
1154
1170
  notInSet: (e) => n("notIn", e),
1155
1171
  contains: (e) => n("contains", e),
1172
+ startsWith: (e) => n("startsWith", e),
1156
1173
  isNull: () => n("isNull"),
1157
1174
  isNotNull: () => n("isNotNull")
1158
1175
  };
1159
- }, ii = (e) => "descriptor" in e ? e.descriptor : e, ai = (e, t) => ({
1176
+ }, si = (e) => "descriptor" in e ? e.descriptor : e, ci = (e, t) => ({
1160
1177
  column: e,
1161
1178
  op: "subquery-in",
1162
- subquery: ii(t)
1163
- }), oi = (e, t) => ({
1179
+ subquery: si(t)
1180
+ }), li = (e, t) => ({
1164
1181
  column: e,
1165
1182
  op: "subquery-not-in",
1166
- subquery: ii(t)
1167
- }), si = (e) => ({
1183
+ subquery: si(t)
1184
+ }), ui = (e) => ({
1168
1185
  op: "exists",
1169
- subquery: ii(e)
1170
- }), ci = (e) => ({
1186
+ subquery: si(e)
1187
+ }), di = (e) => ({
1171
1188
  op: "not-exists",
1172
- subquery: ii(e)
1173
- }), li = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, ui = (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) => {
1174
1191
  if (!t) return !1;
1175
- if ("not" in e) return !ui(e.not, t, n);
1192
+ if ("not" in e) return !pi(e.not, t, n);
1176
1193
  if ("and" in e) {
1177
- for (let r of e.and) if (!ui(r, t, n)) return !1;
1194
+ for (let r of e.and) if (!pi(r, t, n)) return !1;
1178
1195
  return !0;
1179
1196
  }
1180
1197
  if ("or" in e) {
1181
- for (let r of e.or) if (ui(r, t, n)) return !0;
1198
+ for (let r of e.or) if (pi(r, t, n)) return !0;
1182
1199
  return !1;
1183
1200
  }
1184
1201
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
@@ -1197,13 +1214,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1197
1214
  switch (r.op) {
1198
1215
  case "eq": return i === r.value;
1199
1216
  case "neq": return i !== r.value;
1200
- case "gt": return (li(i, r.value) ?? -1) > 0;
1201
- case "gte": return (li(i, r.value) ?? -1) >= 0;
1202
- case "lt": return (li(i, r.value) ?? 1) < 0;
1203
- case "lte": return (li(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;
1204
1221
  case "in": return Array.isArray(r.value) && r.value.includes(i);
1205
1222
  case "notIn": return Array.isArray(r.value) && !r.value.includes(i);
1206
1223
  case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
1224
+ case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
1207
1225
  case "arrayContains": {
1208
1226
  let e = Array.isArray(i) ? i : [];
1209
1227
  return (Array.isArray(r.value) ? r.value : []).every((t) => e.includes(t));
@@ -1217,17 +1235,17 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1217
1235
  case "isNotNull": return i != null;
1218
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.");
1219
1237
  }
1220
- }, di = function* (e) {
1238
+ }, mi = function* (e) {
1221
1239
  if ("not" in e) {
1222
- yield* di(e.not);
1240
+ yield* mi(e.not);
1223
1241
  return;
1224
1242
  }
1225
1243
  if ("and" in e) {
1226
- for (let t of e.and) yield* di(t);
1244
+ for (let t of e.and) yield* mi(t);
1227
1245
  return;
1228
1246
  }
1229
1247
  if ("or" in e) {
1230
- for (let t of e.or) yield* di(t);
1248
+ for (let t of e.or) yield* mi(t);
1231
1249
  return;
1232
1250
  }
1233
1251
  e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
@@ -1237,27 +1255,47 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1237
1255
  kind: "exists",
1238
1256
  descriptor: e.subquery
1239
1257
  });
1240
- }, fi = function* (e, t = !0) {
1258
+ }, hi = function* (e, t = !0) {
1241
1259
  if ("not" in e) {
1242
- yield* fi(e.not, !1);
1260
+ yield* hi(e.not, !1);
1243
1261
  return;
1244
1262
  }
1245
1263
  if ("and" in e) {
1246
- for (let n of e.and) yield* fi(n, t);
1264
+ for (let n of e.and) yield* hi(n, t);
1247
1265
  return;
1248
1266
  }
1249
1267
  if ("or" in e) {
1250
- for (let t of e.or) yield* fi(t, !1);
1268
+ for (let t of e.or) yield* hi(t, !1);
1251
1269
  return;
1252
1270
  }
1253
1271
  e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists" || (yield {
1254
1272
  ...e,
1255
1273
  conjunctive: t
1256
1274
  });
1257
- }, pi = class extends st.TaggedError("TableStreamError") {}, mi = 1e3, hi = (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) => {
1258
1296
  let i = k.match(r, {
1259
1297
  onNone: () => e.where,
1260
- onSome: (n) => e.where ? ei(e.where, Vr(t, n)) : Vr(t, n)
1298
+ onSome: (n) => e.where ? ri(e.where, Hr(t, n)) : Hr(t, n)
1261
1299
  });
1262
1300
  return {
1263
1301
  table: e.table,
@@ -1272,19 +1310,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1272
1310
  ...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
1273
1311
  ...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
1274
1312
  };
1275
- }, gi = (e, t) => {
1276
- let n = t.pk ?? "id", r = t.chunkSize ?? mi;
1313
+ }, Oi = (e, t) => {
1314
+ let n = t.pk ?? "id", r = t.chunkSize ?? Ei;
1277
1315
  return lt.paginateChunkEffect(k.none(), (i) => {
1278
1316
  let a = ct.tryPromise({
1279
- try: () => e.query(hi(t, n, r, i)),
1280
- catch: (e) => new pi({
1317
+ try: () => e.query(Di(t, n, r, i)),
1318
+ catch: (e) => new Ti({
1281
1319
  table: t.table,
1282
1320
  cause: e
1283
1321
  })
1284
1322
  });
1285
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()]));
1286
1324
  });
1287
- }, _i = (e) => {
1325
+ }, ki = (e) => {
1288
1326
  let t = e.alpha ?? .5;
1289
1327
  if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
1290
1328
  return (n) => {
@@ -1311,14 +1349,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1311
1349
  }
1312
1350
  };
1313
1351
  };
1314
- }, vi = async (e, t) => {
1352
+ }, Ai = async (e, t) => {
1315
1353
  let n = e.as ?? "embedding", r = t.row[e.from];
1316
1354
  if (typeof r != "string" || r.length === 0) return {};
1317
1355
  let i = await t.embed(r);
1318
1356
  return { [n]: i };
1319
- }, yi = (e) => {
1357
+ }, ji = (e) => {
1320
1358
  if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
1321
- let t = e.as ?? "embedding", n = (t) => vi(e, t);
1359
+ let t = e.as ?? "embedding", n = (t) => Ai(e, t);
1322
1360
  return d({
1323
1361
  id: "voltro/vectorEmbedding",
1324
1362
  fields: { [t]: y(e.dimensions) },
@@ -1336,19 +1374,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1336
1374
  beforeUpdate: n
1337
1375
  }
1338
1376
  });
1339
- }, bi = 63, xi = "br_pr", J = class extends Error {
1377
+ }, Mi = 63, Ni = "br_pr", Y = class extends Error {
1340
1378
  _tag = "BranchNameInvalid";
1341
1379
  constructor(e) {
1342
1380
  super(e), this.name = "BranchNameInvalid";
1343
1381
  }
1344
- }, Si = (e, t) => {
1345
- if (!Number.isInteger(t) || t < 0) throw new J(`prNumber must be a non-negative integer, got ${String(t)}`);
1346
- let n = _n(e);
1347
- if (n.replace(/_/g, "") === "") throw new J(`app slug '${e}' has no usable identifier characters`);
1348
- let r = `${xi}${t}_${n}`;
1349
- if (r.length > bi) throw new J(`branch namespace '${r}' exceeds the ${bi}-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`);
1350
1388
  return r;
1351
- }, Ci = (e) => e.startsWith(xi), wi = {
1389
+ }, Fi = (e) => e.startsWith(Ni), Ii = {
1352
1390
  requested: {
1353
1391
  provision: "provisioning",
1354
1392
  destroy: "destroying"
@@ -1367,19 +1405,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1367
1405
  fail: "failed"
1368
1406
  },
1369
1407
  destroyed: {}
1370
- }, Ti = class extends Error {
1408
+ }, Li = class extends Error {
1371
1409
  from;
1372
1410
  event;
1373
1411
  _tag = "BranchTransitionInvalid";
1374
1412
  constructor(e, t) {
1375
1413
  super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
1376
1414
  }
1377
- }, Ei = (e, t) => {
1378
- let n = wi[e][t];
1379
- if (n === void 0) throw new Ti(e, t);
1415
+ }, Ri = (e, t) => {
1416
+ let n = Ii[e][t];
1417
+ if (n === void 0) throw new Li(e, t);
1380
1418
  return n;
1381
- }, Di = (e, t, n, r) => {
1382
- 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");
1383
1421
  let i = [{
1384
1422
  kind: "create-namespace",
1385
1423
  detail: e
@@ -1399,13 +1437,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1399
1437
  detail: `run boot seeds into ${e}`
1400
1438
  });
1401
1439
  return i;
1402
- }, Oi = (e) => {
1403
- if (!Ci(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`);
1404
1442
  return [{
1405
1443
  kind: "drop-namespace",
1406
1444
  detail: e
1407
1445
  }];
1408
- }, ki = (e) => {
1446
+ }, Vi = (e) => {
1409
1447
  if (e === void 0 || e === "") return !1;
1410
1448
  try {
1411
1449
  let t = new URL(e).hostname.toLowerCase();
@@ -1413,27 +1451,27 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1413
1451
  } catch {
1414
1452
  return /\bneon\.(tech|build)\b/i.test(e);
1415
1453
  }
1416
- }, Ai = (e) => e.prefer === void 0 ? e.seed === "copy" && ki(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, ji = (e, t = {}) => [{
1454
+ }, Hi = (e) => e.prefer === void 0 ? e.seed === "copy" && Vi(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Ui = (e, t = {}) => [{
1417
1455
  kind: "neon-branch-create",
1418
1456
  detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
1419
- }], Mi = (e) => {
1420
- if (!Ci(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`);
1421
1459
  return [{
1422
1460
  kind: "neon-branch-delete",
1423
1461
  detail: e
1424
1462
  }];
1425
- }, Ni = (e) => e.mechanism === "neon-cow" ? ji(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Di(e.branchId, e.tableNames, e.seed, e.parentNamespace), Pi = (e, t) => e === "neon-cow" ? Mi(t) : Oi(t), Fi = (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) => {
1426
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);
1427
1465
  return {
1428
1466
  evict: i,
1429
1467
  rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
1430
1468
  };
1431
- }, Ii = async (e, t) => {
1432
- let n = Si(e.appSlug, e.prNumber), r = Ai({
1469
+ }, Ji = async (e, t) => {
1470
+ let n = Pi(e.appSlug, e.prNumber), r = Hi({
1433
1471
  seed: e.seed,
1434
1472
  ...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
1435
1473
  ...e.prefer === void 0 ? {} : { prefer: e.prefer }
1436
- }), i = Ni({
1474
+ }), i = Gi({
1437
1475
  mechanism: r,
1438
1476
  branchId: n,
1439
1477
  tableNames: e.tableNames,
@@ -1458,33 +1496,33 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1458
1496
  mechanism: r,
1459
1497
  steps: i
1460
1498
  };
1461
- }, Li = async (e, t, n) => {
1462
- let r = Pi(t, e);
1499
+ }, Yi = async (e, t, n) => {
1500
+ let r = Ki(t, e);
1463
1501
  return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
1464
- }, Ri = (e, t, n) => Fi(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, zi = (e) => {
1502
+ }, Xi = (e, t, n) => qi(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, Zi = (e) => {
1465
1503
  let t = () => {
1466
1504
  throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
1467
1505
  };
1468
1506
  return {
1469
- createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${Y(t)}`),
1470
- createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${Y(t)}.${Y(n)} (LIKE ${Y(n)} INCLUDING ALL)`),
1471
- copyTable: (t, n, r) => e.run(`INSERT INTO ${Y(n)}.${Y(r)} SELECT * FROM ${Y(t)}.${Y(r)}`),
1472
- 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`),
1473
1511
  neonBranchCreate: t,
1474
1512
  neonBranchDelete: t
1475
1513
  };
1476
- }, Bi = class extends Error {
1514
+ }, Qi = class extends Error {
1477
1515
  _tag = "TenantResidencyUnresolved";
1478
1516
  constructor(e) {
1479
1517
  super(e), this.name = "TenantResidencyUnresolved";
1480
1518
  }
1481
- }, Vi = class extends Error {
1519
+ }, $i = class extends Error {
1482
1520
  region;
1483
1521
  _tag = "TenantRegionUnavailable";
1484
1522
  constructor(e, t) {
1485
1523
  super(t), this.region = e, this.name = "TenantRegionUnavailable";
1486
1524
  }
1487
- }, Hi, Ui = (e) => {
1525
+ }, ea, ta = (e) => {
1488
1526
  if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
1489
1527
  if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
1490
1528
  let t = /* @__PURE__ */ new Map();
@@ -1493,98 +1531,98 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1493
1531
  if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
1494
1532
  t.set(n.tenantId, n.region);
1495
1533
  }
1496
- return Hi = e, e;
1497
- }, Wi = () => Hi, Gi = () => {
1498
- Hi = void 0;
1499
- }, Ki = (e, t) => {
1500
- if (e == null || e === "") throw new Bi("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");
1501
1539
  let n = t.homes.find((t) => t.tenantId === e);
1502
- if (n === void 0) throw new Bi(`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)`);
1503
1541
  return n;
1504
- }, qi = (e, t) => t.servableRegions.includes(e), Ji = (e, t) => {
1505
- let n = Ki(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);
1506
1544
  return {
1507
1545
  region: n.region,
1508
1546
  namespace: r,
1509
1547
  ...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
1510
1548
  };
1511
- }, Yi = (e, t, n) => {
1512
- let r = Ji(e, t);
1513
- if (!qi(r.region, t)) throw new Vi(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`);
1514
1552
  let i = n.get(r.region);
1515
- if (i === void 0) throw new Vi(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`);
1516
1554
  return {
1517
1555
  store: i,
1518
1556
  placement: r
1519
1557
  };
1520
- }, Xi = async (e, t, n, r) => {
1521
- let { store: i, placement: a } = Yi(e, t, n);
1558
+ }, ca = async (e, t, n, r) => {
1559
+ let { store: i, placement: a } = sa(e, t, n);
1522
1560
  return await r(i, a), a;
1523
- }, X = (e) => {
1561
+ }, Z = (e) => {
1524
1562
  if (typeof e == "string") return e;
1525
1563
  if ("jsonPath" in e) {
1526
1564
  let { column: t, path: n, numeric: r } = e.jsonPath;
1527
1565
  return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
1528
1566
  }
1529
1567
  return `(${e.expr})`;
1530
- }, Z = (e) => e.map(X), Zi = (e, t) => {
1568
+ }, Q = (e) => e.map(Z), la = (e, t) => {
1531
1569
  if (e.length !== t.length) return !1;
1532
- 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;
1533
1571
  return !0;
1534
- }, Qi = (e, t) => {
1572
+ }, ua = (e, t) => {
1535
1573
  if (e.length >= t.length) return !1;
1536
- 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;
1537
1575
  return !0;
1538
- }, $i = (e) => {
1576
+ }, da = (e) => {
1539
1577
  let t = [], n = e.appliedIndexes, r = e.tableName;
1540
1578
  for (let e = 0; e < n.length; e++) {
1541
1579
  let i = n[e];
1542
1580
  for (let a = e + 1; a < n.length; a++) {
1543
1581
  let e = n[a];
1544
- if (Zi(i.fields, e.fields)) {
1582
+ if (la(i.fields, e.fields)) {
1545
1583
  let [n, a] = i.name < e.name ? [i, e] : [e, i];
1546
1584
  t.push({
1547
1585
  kind: "duplicate-fields",
1548
1586
  table: r,
1549
1587
  redundant: n,
1550
1588
  coveredBy: a,
1551
- 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).`
1552
1590
  });
1553
1591
  continue;
1554
1592
  }
1555
- Qi(i.fields, e.fields) ? t.push({
1593
+ ua(i.fields, e.fields) ? t.push({
1556
1594
  kind: "redundant-prefix",
1557
1595
  table: r,
1558
1596
  redundant: i,
1559
1597
  coveredBy: e,
1560
- 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).`
1561
- }) : Qi(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({
1562
1600
  kind: "redundant-prefix",
1563
1601
  table: r,
1564
1602
  redundant: e,
1565
1603
  coveredBy: i,
1566
- 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).`
1567
1605
  });
1568
1606
  }
1569
1607
  }
1570
1608
  return t;
1571
- }, ea = (e) => {
1609
+ }, fa = (e) => {
1572
1610
  let t = [];
1573
- for (let n of e) t.push(...$i(n));
1611
+ for (let n of e) t.push(...da(n));
1574
1612
  return t;
1575
- }, ta = "\x1B[", na = `${ta}38;2;245;158;11m`, ra = `${ta}38;2;16;185;129m`, ia = (e, t) => `${e}${t}${j.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : ia(t, n) : n, aa = (e, t = {}) => {
1576
- 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, ra, e), c = (e) => Q(n, na, 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) => {
1577
1615
  let n = e.slice(0, t), r = e.slice(t), i = [];
1578
1616
  return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
1579
1617
  }, m = [];
1580
- 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");
1581
- }, oa = (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) => ({
1582
1620
  name: e,
1583
1621
  body: t
1584
- }), sa = (e) => {
1622
+ }), ya = (e) => {
1585
1623
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
1586
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'`);
1587
- let t = e.steps({ step: oa });
1625
+ let t = e.steps({ step: va });
1588
1626
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
1589
1627
  return {
1590
1628
  __seed: !0,
@@ -1596,13 +1634,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1596
1634
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
1597
1635
  steps: t
1598
1636
  };
1599
- }, ca = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, la = (e, { apply: t, undo: n }) => ({
1637
+ }, ba = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, xa = (e, { apply: t, undo: n }) => ({
1600
1638
  name: e,
1601
1639
  apply: t,
1602
1640
  undo: n
1603
- }), ua = (e) => {
1641
+ }), Sa = (e) => {
1604
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>)`);
1605
- let t = e.steps({ step: la });
1643
+ let t = e.steps({ step: xa });
1606
1644
  if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
1607
1645
  return {
1608
1646
  __migration: !0,
@@ -1610,7 +1648,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1610
1648
  name: e.name,
1611
1649
  steps: t
1612
1650
  };
1613
- }, da = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, fa = w("_voltro_migrations", {
1651
+ }, Ca = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, wa = w("_voltro_migrations", {
1614
1652
  id: O({ prefix: "mig" }),
1615
1653
  name: E(),
1616
1654
  hash: E(),
@@ -1622,7 +1660,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1622
1660
  workflowRunId: E().nullable(),
1623
1661
  createdAt: _().default("now"),
1624
1662
  updatedAt: _().default("now").onUpdate("now")
1625
- }).index(["status"]), pa = w("_voltro_seeds", {
1663
+ }).index(["status"]), Ta = w("_voltro_seeds", {
1626
1664
  id: O({ prefix: "seed" }),
1627
1665
  name: E(),
1628
1666
  lifecycle: E(),
@@ -1638,7 +1676,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1638
1676
  workflowRunId: E().nullable(),
1639
1677
  createdAt: _().default("now"),
1640
1678
  updatedAt: _().default("now").onUpdate("now")
1641
- }).index(["lifecycle"]).index(["nextRunAt"]), ma = w("_voltro_migration_plans", {
1679
+ }).index(["lifecycle"]).index(["nextRunAt"]), Ea = w("_voltro_migration_plans", {
1642
1680
  id: O({ prefix: "plan" }),
1643
1681
  fingerprint: E(),
1644
1682
  operations: D(),
@@ -1653,21 +1691,21 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1653
1691
  appliedAt: _().default("now"),
1654
1692
  createdAt: _().default("now"),
1655
1693
  updatedAt: _().default("now").onUpdate("now")
1656
- }).index(["fingerprint"]).index(["environment"]), ha = w("_voltro_idempotency", {
1694
+ }).index(["fingerprint"]).index(["environment"]), Da = w("_voltro_idempotency", {
1657
1695
  id: O({ prefix: "idem" }),
1658
1696
  scope: E(),
1659
1697
  key: E(),
1660
1698
  status: E(),
1661
1699
  response: D().nullable(),
1662
1700
  createdAt: _().default("now")
1663
- }).unique(["scope", "key"]).index(["createdAt"]), ga = w("_voltro_kv", {
1701
+ }).unique(["scope", "key"]).index(["createdAt"]), Oa = w("_voltro_kv", {
1664
1702
  id: O({ prefix: "kv" }),
1665
1703
  key: E().unique(),
1666
1704
  value: E().nullable(),
1667
1705
  expiresAt: _().nullable(),
1668
1706
  createdAt: _().default("now"),
1669
1707
  updatedAt: _().default("now").onUpdate("now")
1670
- }).index(["expiresAt"]), _a = w("_voltro_api_keys", {
1708
+ }).index(["expiresAt"]), ka = w("_voltro_api_keys", {
1671
1709
  id: O({ prefix: "apikey" }),
1672
1710
  tenantId: E().nullable(),
1673
1711
  name: E(),
@@ -1682,72 +1720,72 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1682
1720
  onBehalfOf: E().nullable(),
1683
1721
  metadata: D().nullable(),
1684
1722
  createdAt: _().default("now")
1685
- }).index("byTenant", ["tenantId"]), va = [
1686
- fa,
1687
- pa,
1688
- ma
1689
- ], $ = "id", ya = (e, t) => {
1723
+ }).index("byTenant", ["tenantId"]), Aa = [
1724
+ wa,
1725
+ Ta,
1726
+ Ea
1727
+ ], ja = "id", Ma = (e, t) => {
1690
1728
  let n = u(e);
1691
1729
  if (n === void 0) return t;
1692
- let r = n.fields[$]?.idScheme;
1693
- 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;
1694
1732
  if (r.kind === "numeric") {
1695
- if (!($ in t)) return t;
1733
+ if (!(ja in t)) return t;
1696
1734
  let e = { ...t };
1697
- return delete e[$], e;
1735
+ return delete e[ja], e;
1698
1736
  }
1699
1737
  let i = le(r, e);
1700
1738
  return i === null ? t : {
1701
1739
  ...t,
1702
- [$]: i
1740
+ [ja]: i
1703
1741
  };
1704
- }, ba = (e, t) => t.map((t) => ya(e, t)), xa = (e, t) => {
1742
+ }, Na = (e, t) => t.map((t) => Ma(e, t)), Pa = (e, t) => {
1705
1743
  let n = [], r = t;
1706
1744
  for (let [t, i] of Object.entries(e.fields)) {
1707
1745
  let e = i;
1708
1746
  e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
1709
1747
  }
1710
1748
  return n;
1711
- }, Sa = (e, t) => {
1749
+ }, Fa = (e, t) => {
1712
1750
  let n = t;
1713
1751
  return e.filter((e) => n[e] === void 0 || n[e] === null);
1714
- }, Ca = (e, t, n) => e.insert(t.tableName, n), wa = (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, {
1715
1753
  conflictColumns: r.conflictColumns,
1716
1754
  ...r.update === void 0 ? {} : { update: r.update }
1717
- }), Ta = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Ea = 512, Da = (e) => {
1755
+ }), Ra = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), za = 512, Ba = (e) => {
1718
1756
  e.setMaxListeners(512);
1719
- }, Oa = (e, t, n) => ({
1757
+ }, Va = (e, t, n) => ({
1720
1758
  _tag: "PrimaryKeyConflictError",
1721
1759
  table: e,
1722
1760
  key: t,
1723
1761
  cause: n
1724
- }), ka = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Aa = /* @__PURE__ */ new Map(), ja = (e) => {
1762
+ }), Ha = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Ua = /* @__PURE__ */ new Map(), Wa = (e) => {
1725
1763
  if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
1726
1764
  if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
1727
- Aa.set(e.table, e);
1728
- }, Ma = () => [...Aa.values()], Na = () => Aa.clear(), Pa = 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) => {
1729
1767
  let i = new Date(t - e.ttlMs), a = 0;
1730
1768
  for (;;) {
1731
1769
  let t = await n(e.table, e.timeColumn, i, r, e.where);
1732
1770
  if (a += t, t < r) break;
1733
1771
  }
1734
1772
  return a;
1735
- }, Fa = (e, t) => {
1773
+ }, Ja = (e, t) => {
1736
1774
  let n = Number(e ?? String(t));
1737
1775
  return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
1738
- }, Ia = "_voltro_cdc_offsets", La = w(Ia, {
1776
+ }, Ya = "_voltro_cdc_offsets", Xa = w(Ya, {
1739
1777
  id: O({ prefix: "cdcoff" }),
1740
1778
  replicaId: E(),
1741
1779
  streamName: E(),
1742
1780
  binlogFile: E(),
1743
1781
  binlogPosition: E(),
1744
1782
  updatedAt: _()
1745
- }).index(["replicaId"]), Ra = w(Ia, {
1783
+ }).index(["replicaId"]), Za = w(Ya, {
1746
1784
  id: O({ prefix: "cdcoff" }),
1747
1785
  replicaId: E(),
1748
1786
  streamName: E(),
1749
1787
  ctVersion: E(),
1750
1788
  updatedAt: _()
1751
- }).index(["replicaId"]), za = "postgres";
1789
+ }).index(["replicaId"]), Qa = "postgres";
1752
1790
  //#endregion
1753
- export { oe as AUTO_FILLED_COLUMNS, J as BranchNameInvalid, Ti as BranchTransitionInvalid, Ia as CDC_OFFSETS_TABLE, Ea as CHANGE_LISTENER_CEILING, Xe as ColumnBuilder, ht as ENCRYPTED_PREFIX, za as ENGINE, en as EagerCardinalityError, qe as FILE_MIGRATION_PATTERN, gt as FieldDecryptionError, e as MAX_IDENTIFIER_LENGTH, ut as SqlClient, pi as TableStreamError, mn as TenantNamespaceInvalid, pn as TenantNamespaceUnresolved, Vi as TenantRegionUnavailable, Bi as TenantResidencyUnresolved, xe as WARN_IDENTIFIER_LENGTH, _a as _voltroApiKeysTable, La as _voltroCdcOffsetsTable, ha as _voltroIdempotencyTable, ga as _voltroKvTable, ma as _voltroMigrationPlansTable, fa as _voltroMigrationsTable, Ra as _voltroMssqlCdcOffsetsTable, pa as _voltroSeedsTable, Rr as actorsTable, Ri as admitBranch, ze as allEnumRenames, Ut as allRegisteredRelations, ee as allRegisteredTables, ei as and, be as array, Jr as arrayContains, Xr as arrayHas, Yr as arrayOverlaps, nn as attachEagerLoads, ea as auditAllTableIndexes, $i as auditTableIndexes, Me as avg, Ye as avgOver, Ce as bigint, Yi as bindResidentStore, Ve as boolean, Si as branchNamespaceName, Fe as bytes, Ke as clearEnumRenames, Gt as clearRelationsRegistry, Gi as clearResidencyConfig, Na as clearRetentions, v as clearTableRegistry, Sn as coercePredicateValue, Cn as coercePredicateValues, di as collectSubqueries, ye as column, St as columnSchema, In as compileEagerJson, I as compilePredicate, wn as compileRawFragment, L as compileSelect, vi 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, ua as defineMigration, d as defineMixin, sa 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, Fi as enforceBranchLimits, te as ensureTableRegistered, zr as eq, Tn as escapeLike, ui as evaluatePredicate, we as except, si as exists, aa as formatIndexAuditIssue, va as frameworkTables, le as generateId, ue as generateSnowflake, nt as geography, ge as geometry, Ne as getEnumRenames, Ht as getRelation, Vt as getRelations, Wi as getResidencyConfig, u as getTable, Vr as gt, Hr as gte, fn as hasEagerLoads, _i as hybridSearch, O as id, Gr as inSet, ai as inSubquery, M as inferForeignKey, Ca as insertRow, C as integer, de as intersect, a as interval, Ci as isBranchNamespace, vt as isEncrypted, _t as isFieldDecryptionError, Ie as isFileMigration, da as isMigrationDefinition, ki as isNeonConnection, Qr as isNotNull, Zr as isNull, ka as isPrimaryKeyConflictError, qi as isRegionServable, At as isRelationsSpec, ca as isSeedDefinition, rt as isSqliteFamily, p as isTableReactive, pe as isView, D as json, ri as jsonField, f as jsonIndex, Ze as lag, tt as lead, Ma as listRetentions, Ur as lt, Wr as lte, zi as makeNamespaceBranchExecutor, Mt as many, Nt as manyToMany, ae as materializeFields, he as max, Ue as migration, et as min, Sa as missingConflictColumns, xa as missingRequiredColumns, h as mixin, Br as neq, Ei as nextBranchState, ni as not, ci as notExists, Kr as notInSet, oi as notInSubquery, l as numeric, jt as one, tn as oneCardinalityMessage, ti as or, re as paginateBy, i as paginateById, Ni as planBranch, Di as planBranchProvision, Oi as planBranchTeardown, Pi as planBranchTeardownFor, ji as planNeonBranchProvision, Mi as planNeonBranchTeardown, Oa as primaryKeyConflictError, Ii as provisionBranch, Xi as provisionResidentTenant, yn as qualifyTable, $e as queryFor, Re as queryForView, r as quoteIdent, Da as raiseChangeListenerCeiling, ie as rank, s as raw, x as real, je as reference, Pr as registerCoreTables, Bt as registerDiscoveredRelations, zt as registerRelations, ja as registerRetention, g as registerTable, kt as relations, Ir as requireActors, ne as requireTable, Lr as requireTenants, S as resetSnowflake, Ji as residentPlacement, Ai as resolveBranchMechanism, c as resolveFullTextIndex, ce as resolveIdScheme, He as resolveMixinGraph, Ki as resolveTenantHome, vn as resolveTenantNamespace, Fa as retentionTtlMsFromEnv, o as rowNumber, Ct as rowSchema, _n as sanitizeIdentifierFragment, pt as serializeArraysForWrite, n as serverOnlyColumns, Ui as setResidencyConfig, $r as spatialPredicate, ya as stampGeneratedId, ba as stampGeneratedIds, gi as streamTable, b as sum, Ae as sumOver, Pa as sweepRetention, w as table, Li as teardownBranch, E as text, _ as timestamp, it as timestampMs, at as timestampMsOrNull, t as union, ke as unionAll, Ta as updateManyRow, wa 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, yi as vectorEmbedding, Ge as view, _e as viewSql, fi 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 };