@voltro/database 0.43.2 → 0.44.1

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/dist/index.js +522 -505
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -143,7 +143,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
143
143
  let t = e;
144
144
  for (let e = 0; e < 4 && At.isFiberFailure(t); e++) t = Tt.squash(t[At.FiberFailureCauseId]);
145
145
  return t;
146
- }, nn = (e) => {
146
+ }, nn = (e, t = 0) => {
147
+ if (t >= 4 || !At.isFiberFailure(e)) return [e];
148
+ let n = e[At.FiberFailureCauseId], r = [...Tt.failures(n), ...Tt.defects(n)];
149
+ if (r.length === 0) return [Tt.squash(n)];
150
+ let i = [];
151
+ for (let e of r.slice(0, 8)) i.push(...nn(e, t + 1));
152
+ return i;
153
+ }, rn = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, an = (e) => {
147
154
  let t = {}, n = [], r = tn(e);
148
155
  for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
149
156
  let e = r;
@@ -154,12 +161,22 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
154
161
  (o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = e.cause;
155
162
  }
156
163
  return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
157
- }, rn = /^[A-Za-z_][A-Za-z0-9_$]*$/, j = (e) => e !== void 0 && e.length <= 128 && rn.test(e) ? e : void 0, an = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, M = (e, ...t) => {
164
+ }, on = (e) => {
165
+ let t = nn(e).map(an);
166
+ if (t.length <= 1) return t[0] ?? {};
167
+ let n = t.find(rn) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
168
+ if (r.length === 0) return n;
169
+ let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
170
+ return {
171
+ ...n,
172
+ dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
173
+ };
174
+ }, sn = /^[A-Za-z_][A-Za-z0-9_$]*$/, j = (e) => e !== void 0 && e.length <= 128 && sn.test(e) ? e : void 0, cn = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, M = (e, ...t) => {
158
175
  for (let n of t) {
159
176
  let t = n.exec(e);
160
177
  if (t?.[1] !== void 0) return t[1];
161
178
  }
162
- }, on = (e, t) => {
179
+ }, ln = (e, t) => {
163
180
  let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
164
181
  if (n === "23503") {
165
182
  let t = j(e.dbConstraint);
@@ -197,7 +214,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
197
214
  };
198
215
  }
199
216
  if (r === 1062) {
200
- let e = j(an(M(o, /for key '([^']+)'/)));
217
+ let e = j(cn(M(o, /for key '([^']+)'/)));
201
218
  return {
202
219
  kind: "unique",
203
220
  ...e === void 0 ? {} : { constraint: e }
@@ -248,14 +265,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
248
265
  }
249
266
  if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
250
267
  if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
251
- let e = j(an(M(o, /UNIQUE constraint failed: ([^,\s]+)/)));
268
+ let e = j(cn(M(o, /UNIQUE constraint failed: ([^,\s]+)/)));
252
269
  return {
253
270
  kind: "unique",
254
271
  ...e === void 0 ? {} : { column: e }
255
272
  };
256
273
  }
257
274
  if (n === "SQLITE_CONSTRAINT_NOTNULL") {
258
- let e = j(an(M(o, /NOT NULL constraint failed: ([^,\s]+)/)));
275
+ let e = j(cn(M(o, /NOT NULL constraint failed: ([^,\s]+)/)));
259
276
  return {
260
277
  kind: "notNull",
261
278
  ...e === void 0 ? {} : { column: e }
@@ -268,14 +285,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
268
285
  ...e === void 0 ? {} : { constraint: e }
269
286
  };
270
287
  }
271
- }, sn = (e) => {
272
- let t = on(e)?.kind;
288
+ }, un = (e) => {
289
+ let t = ln(e)?.kind;
273
290
  return t === "foreignKey" || t === "foreignKeyInUse";
274
- }, cn = (e) => {
291
+ }, dn = (e) => {
275
292
  let t = e.dbCode, n = e.dbErrno;
276
293
  return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
277
- }, ln = (e) => {
278
- let t = nn(e), n = [
294
+ }, fn = (e) => {
295
+ let t = on(e), n = [
279
296
  t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
280
297
  t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
281
298
  t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
@@ -283,7 +300,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
283
300
  t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}`
284
301
  ].filter((e) => e !== void 0), r = typeof e?.message == "string" ? e.message : void 0, i = typeof t.dbMessage == "string" ? t.dbMessage : void 0, a = i === void 0 ? void 0 : n.length > 0 || i !== r && i !== `Error: ${String(r)}` ? i : void 0;
285
302
  if (a !== void 0 || n.length !== 0) return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ");
286
- }, un = (e) => {
303
+ }, pn = (e) => {
287
304
  let t = (() => {
288
305
  switch (e.type) {
289
306
  case "id":
@@ -304,41 +321,41 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
304
321
  }
305
322
  })();
306
323
  return e.nullable === !0 ? k.NullOr(t) : t;
307
- }, dn = (e, t) => {
324
+ }, mn = (e, t) => {
308
325
  let n = new Set(t?.omit ?? []), r = {};
309
- for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = un(i));
326
+ for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = pn(i));
310
327
  return k.Struct(r);
311
- }, fn = (e) => typeof e == "function" ? e : () => e, pn = (e, t) => ({
328
+ }, hn = (e) => typeof e == "function" ? e : () => e, gn = (e, t) => ({
312
329
  kind: "one",
313
- target: fn(e),
330
+ target: hn(e),
314
331
  ...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
315
332
  ...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
316
- }), mn = (e, t) => ({
333
+ }), _n = (e, t) => ({
317
334
  kind: "many",
318
- target: fn(e),
335
+ target: hn(e),
319
336
  ...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
320
337
  ...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
321
- }), hn = (e, t) => ({
338
+ }), vn = (e, t) => ({
322
339
  kind: "manyToMany",
323
- target: fn(e),
324
- through: fn(t.through),
340
+ target: hn(e),
341
+ through: hn(t.through),
325
342
  sourceKey: t.sourceKey,
326
343
  targetKey: t.targetKey
327
- }), gn = {
328
- one: pn,
329
- many: mn,
330
- manyToMany: hn
331
- }, _n = (e, t) => {
344
+ }), yn = {
345
+ one: gn,
346
+ many: _n,
347
+ manyToMany: vn
348
+ }, bn = (e, t) => {
332
349
  let n = typeof e == "function" ? e : () => e;
333
350
  return {
334
351
  source: n,
335
- relations: t(gn, n())
352
+ relations: t(yn, n())
336
353
  };
337
- }, vn = (e) => {
354
+ }, xn = (e) => {
338
355
  if (typeof e != "object" || !e) return !1;
339
356
  let t = e;
340
357
  return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
341
- }, yn = (e) => {
358
+ }, Sn = (e) => {
342
359
  if (typeof e != "object" || !e) return !1;
343
360
  let t = e;
344
361
  if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
@@ -347,32 +364,32 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
347
364
  let t = e?.kind;
348
365
  return t === "one" || t === "many" || t === "manyToMany";
349
366
  });
350
- }, bn = pn, xn = mn, Sn = hn, N = (e, t, n) => {
367
+ }, Cn = gn, wn = _n, Tn = vn, N = (e, t, n) => {
351
368
  let r = [];
352
369
  for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
353
370
  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>' }.`);
354
371
  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.`);
355
372
  return r[0];
356
- }, Cn = (e) => Object.keys(e.fields), wn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Tn = (e) => {
357
- let t = Cn(e);
373
+ }, En = (e) => Object.keys(e.fields), Dn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), On = (e) => {
374
+ let t = En(e);
358
375
  return t.length === 0 ? "<none>" : t.join(", ");
359
- }, En = (e, t, n) => {
376
+ }, kn = (e, t, n) => {
360
377
  let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
361
378
  if (n.kind === "manyToMany") {
362
379
  let t = n.through();
363
- for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!wn(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}': ${Tn(t)}.`);
380
+ for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!Dn(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}': ${On(t)}.`);
364
381
  return;
365
382
  }
366
383
  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.`);
367
- if (n.sourceKey !== void 0 && !wn(e, n.sourceKey)) {
368
- let t = wn(i, n.sourceKey);
369
- 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}': ${Tn(e)}.`));
384
+ if (n.sourceKey !== void 0 && !Dn(e, n.sourceKey)) {
385
+ let t = Dn(i, n.sourceKey);
386
+ 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}': ${On(e)}.`));
370
387
  }
371
- if (n.foreignKey !== void 0 && !wn(i, n.foreignKey)) {
372
- let t = wn(e, n.foreignKey);
373
- 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}': ${Tn(i)}.`));
388
+ if (n.foreignKey !== void 0 && !Dn(i, n.foreignKey)) {
389
+ let t = Dn(e, n.foreignKey);
390
+ 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}': ${On(i)}.`));
374
391
  }
375
- }, Dn = Symbol.for("@voltro/database/relationsRegistry"), On = globalThis, P = On[Dn] ?? (On[Dn] = /* @__PURE__ */ new Map()), kn = (e) => {
392
+ }, An = Symbol.for("@voltro/database/relationsRegistry"), jn = globalThis, P = jn[An] ?? (jn[An] = /* @__PURE__ */ new Map()), Mn = (e) => {
376
393
  let t = e.source(), n = P.get(t.tableName);
377
394
  if (n === void 0) {
378
395
  P.set(t.tableName, new Map(Object.entries(e.relations)));
@@ -385,14 +402,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
385
402
  n.set(r, i);
386
403
  }
387
404
  }
388
- }, An = (e) => {
405
+ }, Nn = (e) => {
389
406
  let t = 0;
390
- for (let n of Object.values(e)) yn(n) && (kn(n), t += 1);
407
+ for (let n of Object.values(e)) Sn(n) && (Mn(n), t += 1);
391
408
  return t;
392
- }, jn = (e) => {
409
+ }, Pn = (e) => {
393
410
  let t = P.get(e);
394
411
  if (t !== void 0) return Object.fromEntries(t);
395
- }, Mn = (e, t) => P.get(e)?.get(t), Nn = () => {
412
+ }, Fn = (e, t) => P.get(e)?.get(t), In = () => {
396
413
  let e = [];
397
414
  for (let [t, n] of P) for (let [r, i] of n) e.push({
398
415
  source: t,
@@ -400,18 +417,18 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
400
417
  relation: i
401
418
  });
402
419
  return e;
403
- }, Pn = () => {
420
+ }, Ln = () => {
404
421
  for (let [e, t] of P) {
405
422
  let n = p(e);
406
- if (n !== void 0) for (let [e, r] of t) En(n, e, r);
423
+ if (n !== void 0) for (let [e, r] of t) kn(n, e, r);
407
424
  }
408
- }, Fn = () => {
425
+ }, Rn = () => {
409
426
  P.clear();
410
- }, In = 4, Ln = (e) => Object.keys(e.fields), Rn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), zn = (e, t) => {
427
+ }, zn = 4, Bn = (e) => Object.keys(e.fields), Vn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Hn = (e, t) => {
411
428
  let n = [];
412
429
  for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
413
430
  return n;
414
- }, Bn = (e, t) => {
431
+ }, Un = (e, t) => {
415
432
  let n = [];
416
433
  for (let r of t) {
417
434
  if (r.source !== e) continue;
@@ -428,7 +445,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
428
445
  } catch {
429
446
  continue;
430
447
  }
431
- if (!Rn(e, t.sourceKey)) continue;
448
+ if (!Vn(e, t.sourceKey)) continue;
432
449
  n.push({
433
450
  table: e.tableName,
434
451
  foreignKey: t.sourceKey,
@@ -437,24 +454,24 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
437
454
  continue;
438
455
  }
439
456
  if (t.sourceKey !== void 0) continue;
440
- let a = zn(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
441
- o === void 0 || !Rn(i, o) || n.push({
457
+ let a = Hn(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
458
+ o === void 0 || !Vn(i, o) || n.push({
442
459
  table: i.tableName,
443
460
  foreignKey: o,
444
461
  parentKey: "id"
445
462
  });
446
463
  }
447
464
  return n;
448
- }, Vn = (e, t) => {
465
+ }, Wn = (e, t) => {
449
466
  let n = [];
450
- for (let r of t) if (r.tableName !== e) for (let t of zn(r, e)) n.push({
467
+ for (let r of t) if (r.tableName !== e) for (let t of Hn(r, e)) n.push({
451
468
  table: r.tableName,
452
469
  foreignKey: t,
453
470
  parentKey: "id"
454
471
  });
455
472
  return n;
456
- }, Hn = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Un = (e) => {
457
- let t = e.tables ?? h(), n = e.relations ?? Nn(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
473
+ }, Gn = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Kn = (e) => {
474
+ let t = e.tables ?? h(), n = e.relations ?? In(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
458
475
  if (!a.has(e.subjectTable)) return {
459
476
  subjectTable: e.subjectTable,
460
477
  paths: [],
@@ -469,11 +486,11 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
469
486
  hops: [],
470
487
  depth: 0,
471
488
  via: "relation"
472
- }, c = [s], l = /* @__PURE__ */ new Set([Hn(s)]), u = /* @__PURE__ */ new Set(), d = [s];
489
+ }, c = [s], l = /* @__PURE__ */ new Set([Gn(s)]), u = /* @__PURE__ */ new Set(), d = [s];
473
490
  for (let e = 1; e <= r; e++) {
474
491
  let r = [];
475
492
  for (let a of d) {
476
- let s = Bn(a.table, n), d = Vn(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
493
+ let s = Un(a.table, n), d = Wn(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
477
494
  for (let [t, n] of f) {
478
495
  if (i.has(t.table)) {
479
496
  o.push({
@@ -491,7 +508,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
491
508
  hops: [...a.hops, t],
492
509
  depth: e,
493
510
  via: n
494
- }, f = Hn(d);
511
+ }, f = Gn(d);
495
512
  l.has(f) || (l.add(f), c.push(d), r.push(d));
496
513
  }
497
514
  }
@@ -501,7 +518,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
501
518
  }
502
519
  d = r;
503
520
  }
504
- for (let e of d) (Bn(e.table, n).length > 0 || Vn(e.table, t).length > 0) && o.push({
521
+ for (let e of d) (Un(e.table, n).length > 0 || Wn(e.table, t).length > 0) && o.push({
505
522
  kind: "depth-truncated",
506
523
  table: e.table,
507
524
  detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
@@ -510,14 +527,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
510
527
  for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
511
528
  kind: "unreachable",
512
529
  table: n.tableName,
513
- detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${Ln(n).join(", ")}`
530
+ detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${Bn(n).join(", ")}`
514
531
  });
515
532
  return {
516
533
  subjectTable: e.subjectTable,
517
534
  paths: c,
518
535
  limitations: o
519
536
  };
520
- }, Wn = (e) => {
537
+ }, qn = (e) => {
521
538
  let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
522
539
  for (let n of e.paths) {
523
540
  let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
@@ -525,7 +542,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
525
542
  }
526
543
  let n = e.limitations.filter((e) => e.kind === "depth-truncated"), r = e.limitations.filter((e) => e.kind === "unreachable"), i = e.limitations.filter((e) => e.kind === "excluded");
527
544
  return t.push(""), t.push(" WHAT THIS CANNOT SEE — a DSAR is only as complete as this list is short:"), n.length > 0 && t.push(` depth-truncated (${n.length}): ${n.map((e) => e.table).join(", ")}`), i.length > 0 && t.push(` excluded (${i.length}): ${[...new Set(i.map((e) => e.table))].join(", ")}`), t.push(r.length === 0 ? " unreachable: none — every registered table is linked to the subject." : ` unreachable (${r.length}): ${r.map((e) => e.table).join(", ")}`), t.push(" Always outside this graph: object storage / uploaded files, external processors,"), t.push(" log and metric sinks, backups, and any subject id embedded in JSON or free text."), t.join("\n");
528
- }, Gn = (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, Kn = (e) => {
545
+ }, Jn = (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, Yn = (e) => {
529
546
  if (e == null || typeof e != "string") return e;
530
547
  let t = e.trim();
531
548
  if (t.length === 0) return e;
@@ -536,7 +553,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
536
553
  } catch {
537
554
  return e;
538
555
  }
539
- }, qn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Jn = (e) => {
556
+ }, Xn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Zn = (e) => {
540
557
  if (e == null || e instanceof Date) return e;
541
558
  if (typeof e == "string") {
542
559
  let t = new Date(e);
@@ -547,19 +564,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
547
564
  return isNaN(t.getTime()) ? e : t;
548
565
  }
549
566
  return e;
550
- }, Yn = (e, t, n) => {
567
+ }, Qn = (e, t, n) => {
551
568
  if (e == null) return e;
552
569
  switch (t) {
553
- case "boolean": return n === "postgres" ? e : Gn(e);
570
+ case "boolean": return n === "postgres" ? e : Jn(e);
554
571
  case "json":
555
- case "array": return n === "postgres" ? e : Kn(e);
572
+ case "array": return n === "postgres" ? e : Yn(e);
556
573
  case "timestamp":
557
- case "date": return n === "sqlite" || n === "turso" ? Jn(e) : e;
574
+ case "date": return n === "sqlite" || n === "turso" ? Zn(e) : e;
558
575
  case "decimal":
559
- case "bigint": return qn(e);
576
+ case "bigint": return Xn(e);
560
577
  default: return e;
561
578
  }
562
- }, Xn = (e, t, n) => {
579
+ }, $n = (e, t, n) => {
563
580
  if (e.length === 0) return e;
564
581
  let r = p(t);
565
582
  if (r === void 0) return e;
@@ -570,36 +587,36 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
570
587
  });
571
588
  return e.map((e) => {
572
589
  let t = { ...e };
573
- for (let { key: e, type: r } of a) e in t && (t[e] = Yn(t[e], r, n));
590
+ for (let { key: e, type: r } of a) e in t && (t[e] = Qn(t[e], r, n));
574
591
  return t;
575
592
  });
576
- }, Zn = (e, t) => {
593
+ }, er = (e, t) => {
577
594
  if (e == null) return e;
578
595
  switch (t) {
579
596
  case "json":
580
597
  case "array": return typeof e == "string" ? e : JSON.stringify(e);
581
598
  default: return e;
582
599
  }
583
- }, Qn = (e, t, n = ["json", "array"]) => {
600
+ }, tr = (e, t, n = ["json", "array"]) => {
584
601
  let r = p(t);
585
602
  if (r === void 0) return e;
586
603
  let i = r.fields, a = null;
587
604
  for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
588
- let n = Zn(e[t], r.type);
605
+ let n = er(e[t], r.type);
589
606
  n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
590
607
  }
591
608
  return a ?? e;
592
- }, $n = class extends Error {
609
+ }, nr = class extends Error {
593
610
  _tag = "EagerCardinalityError";
594
611
  constructor(e) {
595
612
  super(e), this.name = "EagerCardinalityError";
596
613
  }
597
- }, er = (e) => {
614
+ }, rr = (e) => {
598
615
  let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
599
616
  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.");
600
- }, tr = async (e, t, n, r) => {
617
+ }, ir = async (e, t, n, r) => {
601
618
  if (e.length === 0) return e;
602
- let i = jn(n.tableName);
619
+ let i = Pn(n.tableName);
603
620
  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?`);
604
621
  let a = e.map((e) => ({ ...e }));
605
622
  for (let [e, o] of Object.entries(t)) {
@@ -608,36 +625,36 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
608
625
  let t = Object.keys(i).join(", ") || "<none>";
609
626
  throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
610
627
  }
611
- En(n, e, t), await nr(a, e, t, o === !0 ? {} : o, n, r);
628
+ kn(n, e, t), await ar(a, e, t, o === !0 ? {} : o, n, r);
612
629
  }
613
630
  return a;
614
- }, nr = async (e, t, n, r, i, a) => {
631
+ }, ar = async (e, t, n, r, i, a) => {
615
632
  switch (n.kind) {
616
633
  case "one":
617
- await rr(e, t, n, r, i, a);
634
+ await or(e, t, n, r, i, a);
618
635
  return;
619
636
  case "many":
620
- await ir(e, t, n, r, i, a);
637
+ await sr(e, t, n, r, i, a);
621
638
  return;
622
639
  case "manyToMany":
623
- await or(e, t, n, r, i, a);
640
+ await lr(e, t, n, r, i, a);
624
641
  return;
625
642
  }
626
- }, rr = async (e, t, n, r, i, a) => {
627
- let o = n.target(), s = n.sourceKey ?? sr(i, o.tableName);
643
+ }, or = async (e, t, n, r, i, a) => {
644
+ let o = n.target(), s = n.sourceKey ?? ur(i, o.tableName);
628
645
  if (s !== void 0) {
629
- let n = cr(e, s), i = n.length === 0 ? [] : await lr(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
646
+ let n = dr(e, s), i = n.length === 0 ? [] : await fr(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
630
647
  for (let n of e) {
631
648
  let e = n[s];
632
649
  n[t] = e == null ? null : c.get(e) ?? null;
633
650
  }
634
- await ur(i, r.with, o, a);
651
+ await pr(i, r.with, o, a);
635
652
  return;
636
653
  }
637
- let c = n.foreignKey ?? N(o, i.tableName, t), l = n.sourceKey ?? "id", u = cr(e, l), d = u.length === 0 ? [] : await lr(o, c, u, r, a), f = /* @__PURE__ */ new Map();
654
+ let c = n.foreignKey ?? N(o, i.tableName, t), l = n.sourceKey ?? "id", u = dr(e, l), d = u.length === 0 ? [] : await fr(o, c, u, r, a), f = /* @__PURE__ */ new Map();
638
655
  for (let e of d) {
639
656
  let n = e[c];
640
- if (f.has(n)) throw new $n(er({
657
+ if (f.has(n)) throw new nr(rr({
641
658
  relationName: t,
642
659
  sourceTableName: i.tableName,
643
660
  targetTableName: o.tableName,
@@ -650,9 +667,9 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
650
667
  let e = n[l];
651
668
  n[t] = e == null ? null : f.get(e) ?? null;
652
669
  }
653
- await ur(d, r.with, o, a);
654
- }, ir = async (e, t, n, r, i, a) => {
655
- let o = n.target(), s = n.foreignKey ?? N(o, i.tableName, t), c = n.sourceKey ?? "id", l = cr(e, c), u = ar(r), d = l.length === 0 ? [] : await lr(o, s, l, u, a), f = /* @__PURE__ */ new Map();
670
+ await pr(d, r.with, o, a);
671
+ }, sr = async (e, t, n, r, i, a) => {
672
+ let o = n.target(), s = n.foreignKey ?? N(o, i.tableName, t), c = n.sourceKey ?? "id", l = dr(e, c), u = cr(r), d = l.length === 0 ? [] : await fr(o, s, l, u, a), f = /* @__PURE__ */ new Map();
656
673
  for (let e of d) {
657
674
  let t = e[s], n = f.get(t);
658
675
  n ? n.push(e) : f.set(t, [e]);
@@ -668,12 +685,12 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
668
685
  let e = n[c];
669
686
  n[t] = f.get(e) ?? [];
670
687
  }
671
- await ur(d, r.with, o, a);
672
- }, ar = (e) => {
688
+ await pr(d, r.with, o, a);
689
+ }, cr = (e) => {
673
690
  let { limit: t, offset: n, ...r } = e;
674
691
  return r;
675
- }, or = async (e, t, n, r, i, a) => {
676
- let o = n.target(), s = n.through(), c = cr(e, "id");
692
+ }, lr = async (e, t, n, r, i, a) => {
693
+ let o = n.target(), s = n.through(), c = dr(e, "id");
677
694
  if (c.length === 0) {
678
695
  for (let n of e) n[t] = [];
679
696
  return;
@@ -694,8 +711,8 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
694
711
  for (let n of e) n[t] = [];
695
712
  return;
696
713
  }
697
- let f = await lr(o, "id", cr(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
698
- await ur(f, r.with, o, a);
714
+ let f = await fr(o, "id", dr(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
715
+ await pr(f, r.with, o, a);
699
716
  let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
700
717
  for (let e of d) {
701
718
  let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
@@ -707,16 +724,16 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
707
724
  o ? o.push(a) : h.set(t, [a]);
708
725
  }
709
726
  for (let n of e) n[t] = h.get(n.id) ?? [];
710
- }, sr = (e, t) => {
727
+ }, ur = (e, t) => {
711
728
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
712
- }, cr = (e, t) => {
729
+ }, dr = (e, t) => {
713
730
  let n = /* @__PURE__ */ new Set();
714
731
  for (let r of e) {
715
732
  let e = r[t];
716
733
  e != null && n.add(e);
717
734
  }
718
735
  return [...n];
719
- }, lr = (e, t, n, r, i) => {
736
+ }, fr = (e, t, n, r, i) => {
720
737
  let a = {
721
738
  column: t,
722
739
  op: "in",
@@ -730,50 +747,50 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
730
747
  skip: r.offset,
731
748
  projection: void 0
732
749
  });
733
- }, ur = async (e, t, n, r) => {
734
- t !== void 0 && e.length !== 0 && (await tr(e, t, n, r)).forEach((t, n) => {
750
+ }, pr = async (e, t, n, r) => {
751
+ t !== void 0 && e.length !== 0 && (await ir(e, t, n, r)).forEach((t, n) => {
735
752
  let r = e[n];
736
753
  for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
737
754
  });
738
- }, dr = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, fr = class extends Error {
755
+ }, mr = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, hr = class extends Error {
739
756
  _tag = "TenantNamespaceUnresolved";
740
757
  constructor(e) {
741
758
  super(e), this.name = "TenantNamespaceUnresolved";
742
759
  }
743
- }, pr = class extends Error {
760
+ }, gr = class extends Error {
744
761
  _tag = "TenantNamespaceInvalid";
745
762
  constructor(e) {
746
763
  super(e), this.name = "TenantNamespaceInvalid";
747
764
  }
748
- }, mr = 63, hr = "tenant_", gr = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), _r = (e) => {
749
- if (e == null || e === "") throw new fr("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.");
750
- let t = gr(e);
751
- if (t.replace(/_/g, "") === "") throw new pr(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
752
- let n = `${hr}${t}`;
753
- if (n.length > mr) throw new pr(`namespace '${n}' for tenant '${e}' exceeds the ${mr}-byte identifier limit. Use a shorter tenant id.`);
765
+ }, _r = 63, vr = "tenant_", yr = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), br = (e) => {
766
+ if (e == null || e === "") throw new hr("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.");
767
+ let t = yr(e);
768
+ if (t.replace(/_/g, "") === "") throw new gr(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
769
+ let n = `${vr}${t}`;
770
+ if (n.length > _r) throw new gr(`namespace '${n}' for tenant '${e}' exceeds the ${_r}-byte identifier limit. Use a shorter tenant id.`);
754
771
  return n;
755
- }, vr = (e, t) => e === null ? t : `${e}.${t}`, yr = /* @__PURE__ */ new Set(["timestamp", "date"]), br = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, xr = (e, t) => {
756
- if (e === void 0 || t == null || !yr.has(e) || t instanceof Date) return t;
772
+ }, xr = (e, t) => e === null ? t : `${e}.${t}`, Sr = /* @__PURE__ */ new Set(["timestamp", "date"]), Cr = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, wr = (e, t) => {
773
+ if (e === void 0 || t == null || !Sr.has(e) || t instanceof Date) return t;
757
774
  if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
758
- if (typeof t == "string" && br.test(t)) {
775
+ if (typeof t == "string" && Cr.test(t)) {
759
776
  let e = new Date(t);
760
777
  return Number.isNaN(e.getTime()) ? t : e;
761
778
  }
762
779
  return t;
763
- }, Sr = (e, t) => e === void 0 || !yr.has(e) ? t : t.map((t) => xr(e, t)), Cr = (e, t) => {
780
+ }, Tr = (e, t) => e === void 0 || !Sr.has(e) ? t : t.map((t) => wr(e, t)), Er = (e, t) => {
764
781
  let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
765
782
  for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
766
783
  return t`${i}`;
767
- }, wr = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), F = (e, t, n = null, r) => {
784
+ }, Dr = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), F = (e, t, n = null, r) => {
768
785
  if ("not" in e) return t`NOT (${F(e.not, t, n, r)})`;
769
786
  if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => F(e, t, n, r)));
770
787
  if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => F(e, t, n, r)));
771
788
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
772
- let r = e, i = Fr(r.subquery, t, n);
789
+ let r = e, i = Rr(r.subquery, t, n);
773
790
  return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
774
791
  }
775
792
  if (e.op === "exists" || e.op === "not-exists") {
776
- let r = e, i = Fr(r.subquery, t, n);
793
+ let r = e, i = Rr(r.subquery, t, n);
777
794
  return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
778
795
  }
779
796
  let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
@@ -786,7 +803,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
786
803
  mssql: () => t.unsafe(w(i.column, o, "mssql", { numeric: !0 })),
787
804
  sqlite: () => t.unsafe(w(i.column, o, "sqlite", { numeric: !0 })),
788
805
  orElse: () => t.unsafe(w(i.column, o, "postgres", { numeric: !0 }))
789
- }), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, m = (e) => s ? Number(e) : e, h = s || r === void 0 ? void 0 : p(r)?.fields?.[i.column]?.type, g = (e) => xr(h, e);
806
+ }), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, m = (e) => s ? Number(e) : e, h = s || r === void 0 ? void 0 : p(r)?.fields?.[i.column]?.type, g = (e) => wr(h, e);
790
807
  switch (i.op) {
791
808
  case "eq": return t`${u} = ${f(g(i.value))}`;
792
809
  case "neq": return t`${u} <> ${f(g(i.value))}`;
@@ -803,7 +820,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
803
820
  return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
804
821
  }
805
822
  case "contains": {
806
- let e = `%${wr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
823
+ let e = `%${Dr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
807
824
  return t.onDialectOrElse({
808
825
  mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
809
826
  mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
@@ -812,7 +829,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
812
829
  });
813
830
  }
814
831
  case "startsWith": {
815
- let e = `${wr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
832
+ let e = `${Dr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
816
833
  return t.onDialectOrElse({
817
834
  mysql: () => t`${u} LIKE ${e}`,
818
835
  orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
@@ -860,13 +877,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
860
877
  });
861
878
  }
862
879
  }
863
- }, Tr = (e, t) => {
880
+ }, Or = (e, t) => {
864
881
  let n = [];
865
882
  return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
866
- }, Er = (e, t) => t.csv(e.map((e) => {
883
+ }, kr = (e, t) => t.csv(e.map((e) => {
867
884
  let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
868
885
  if (e.op.startsWith("window-")) {
869
- let r = Tr(e.window ?? {}, t);
886
+ let r = Or(e.window ?? {}, t);
870
887
  switch (e.op) {
871
888
  case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
872
889
  case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
@@ -890,43 +907,43 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
890
907
  return t`${t(e.column)} AS ${t(e.alias)}`;
891
908
  default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
892
909
  }
893
- })), Dr = (e) => `[${e.join(",")}]`, Or = (e, t) => {
910
+ })), Ar = (e) => `[${e.join(",")}]`, jr = (e, t) => {
894
911
  if (e.queryVector === void 0) return null;
895
- let n = t(e.column), r = Dr(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
912
+ let n = t(e.column), r = Ar(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
896
913
  return t.onDialectOrElse({
897
914
  mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
898
915
  mssql: () => t`NULL`,
899
916
  sqlite: () => t`NULL`,
900
917
  orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
901
918
  });
902
- }, kr = (e, t) => {
919
+ }, Mr = (e, t) => {
903
920
  let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
904
921
  return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
905
- }, Ar = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, jr = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Mr = (e, t) => `${t}_${e.indexName}_fts`, Nr = (e, t, n) => {
906
- let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${wr(e.query)}%`;
922
+ }, Nr = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Pr = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Fr = (e, t) => `${t}_${e.indexName}_fts`, Ir = (e, t, n) => {
923
+ let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${Dr(e.query)}%`;
907
924
  return n.onDialectOrElse({
908
925
  mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
909
926
  sqlite: () => {
910
- let r = n(Mr(e, t));
927
+ let r = n(Fr(e, t));
911
928
  return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
912
929
  },
913
930
  mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
914
- orElse: () => n`${jr(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
931
+ orElse: () => n`${Pr(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
915
932
  });
916
- }, Pr = (e, t, n) => {
917
- let r = `%${wr(e.query)}%`;
933
+ }, Lr = (e, t, n) => {
934
+ let r = `%${Dr(e.query)}%`;
918
935
  return n.onDialectOrElse({
919
936
  mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
920
937
  sqlite: () => {
921
- let r = n(Mr(e, t));
938
+ let r = n(Fr(e, t));
922
939
  return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
923
940
  },
924
941
  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}`),
925
- orElse: () => n`ts_rank(${jr(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
942
+ orElse: () => n`ts_rank(${Pr(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
926
943
  });
927
- }, Fr = (e, t, n = null) => {
944
+ }, Rr = (e, t, n = null) => {
928
945
  if (e.setOp && e.setOp.queries.length >= 2) {
929
- 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`(${Fr(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
946
+ 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`(${Rr(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
930
947
  if (C(e).length > 0 && a.push(t` ORDER BY ${t.csv(C(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
931
948
  if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
932
949
  a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
@@ -937,7 +954,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
937
954
  }
938
955
  return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
939
956
  }
940
- let r = e.annClause === void 0 ? null : Or(e.annClause, t);
957
+ let r = e.annClause === void 0 ? null : jr(e.annClause, t);
941
958
  e.spatialClause !== void 0 && t.onDialectOrElse({
942
959
  mysql: () => {
943
960
  throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
@@ -950,16 +967,16 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
950
967
  },
951
968
  orElse: () => t``
952
969
  });
953
- let i = e.spatialClause?.projectAs === void 0 ? null : kr(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Er(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Pr(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
970
+ let i = e.spatialClause?.projectAs === void 0 ? null : Mr(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? kr(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Lr(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
954
971
  orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
955
972
  mysql: () => t`DISTINCT `,
956
973
  mssql: () => t`DISTINCT `,
957
974
  sqlite: () => t`DISTINCT `
958
- }) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(vr(n, e.table))}` : t`${t(vr(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
975
+ }) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(xr(n, e.table))}` : t`${t(xr(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
959
976
  let r = e.kind === "inner" ? "INNER" : "LEFT";
960
- return t` ${t.unsafe(r)} JOIN ${t(vr(n, e.table))} AS ${t(e.alias)} ON ${F(e.on, t, n)}`;
961
- }), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Nr(c, e.table, t), ee = [e.predicate ? F(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), te = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, _ = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, v = e.having ? t` HAVING ${F(e.having, t, n, e.table)}` : t``, ne = e.skip !== void 0, y = [];
962
- r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${Ar(e.spatialClause, t)} DESC` : t`${Ar(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
977
+ return t` ${t.unsafe(r)} JOIN ${t(xr(n, e.table))} AS ${t(e.alias)} ON ${F(e.on, t, n)}`;
978
+ }), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Ir(c, e.table, t), ee = [e.predicate ? F(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), te = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, _ = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, v = e.having ? t` HAVING ${F(e.having, t, n, e.table)}` : t``, ne = e.skip !== void 0, y = [];
979
+ r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${Nr(e.spatialClause, t)} DESC` : t`${Nr(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
963
980
  for (let n of C(e)) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
964
981
  let re = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : ne ? t.onDialectOrElse({
965
982
  mssql: () => t` ORDER BY (SELECT NULL)`,
@@ -967,7 +984,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
967
984
  }) : t``, b = (e) => {
968
985
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
969
986
  return t.unsafe(String(e));
970
- }, ie = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${Fr(e.descriptor, t, n)})`), ae = (e.ctes ?? []).some((e) => e.recursive === !0), oe = ie.length > 0 ? t`WITH ${t.unsafe(ae ? "RECURSIVE " : "")}${t.csv(ie)} ` : t``;
987
+ }, ie = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${Rr(e.descriptor, t, n)})`), ae = (e.ctes ?? []).some((e) => e.recursive === !0), oe = ie.length > 0 ? t`WITH ${t.unsafe(ae ? "RECURSIVE " : "")}${t.csv(ie)} ` : t``;
971
988
  return t.onDialectOrElse({
972
989
  mssql: () => {
973
990
  let n = e.take !== void 0 && !ne ? t`TOP ${b(e.take)} ` : t``, r = ne ? t` OFFSET ${b(e.skip)} ROWS FETCH NEXT ${b(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
@@ -978,29 +995,29 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
978
995
  return t`${oe}SELECT ${f}${d} FROM ${h}${te}${_}${v}${re}${n}${r}`;
979
996
  }
980
997
  });
981
- }, Ir = (e, t, n) => {
998
+ }, zr = (e, t, n) => {
982
999
  if (e.eager === void 0) return null;
983
- let r = zr(e.table, e.eager, e.sourceTable);
1000
+ let r = Hr(e.table, e.eager, e.sourceTable);
984
1001
  if (r === null) return null;
985
- let i = Kr(n, e, r, Gr(t, n));
1002
+ let i = Yr(n, e, r, Jr(t, n));
986
1003
  return i === null ? null : {
987
1004
  fragment: i,
988
- decode: Yr(r, n)
1005
+ decode: Qr(r, n)
989
1006
  };
990
- }, Lr = (e) => e.relation.kind === "one" && e.fkSide === "target", Rr = (e) => ({
1007
+ }, Br = (e) => e.relation.kind === "one" && e.fkSide === "target", Vr = (e) => ({
991
1008
  ...e,
992
1009
  branch: {
993
1010
  ...e.branch,
994
1011
  limit: 2
995
1012
  }
996
- }), zr = (e, t, n) => {
997
- let r = n ?? _(e), i = jn(e);
1013
+ }), Hr = (e, t, n) => {
1014
+ let r = n ?? _(e), i = Pn(e);
998
1015
  if (i === void 0) return null;
999
1016
  let a = [];
1000
1017
  for (let [e, n] of Object.entries(t)) {
1001
1018
  let t = i[e];
1002
1019
  if (t === void 0) return null;
1003
- let o = Br(e, t, r, n === !0 ? {} : n);
1020
+ let o = Ur(e, t, r, n === !0 ? {} : n);
1004
1021
  if (o === null) return null;
1005
1022
  a.push(o);
1006
1023
  }
@@ -1008,11 +1025,11 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1008
1025
  table: r,
1009
1026
  children: a
1010
1027
  };
1011
- }, Br = (e, t, n, r) => {
1028
+ }, Ur = (e, t, n, r) => {
1012
1029
  let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
1013
1030
  if (t.kind === "manyToMany") o = t.targetKey, s = "target";
1014
1031
  else if (t.kind === "one") {
1015
- let r = t.sourceKey ?? Wr(n, i.tableName);
1032
+ let r = t.sourceKey ?? qr(n, i.tableName);
1016
1033
  if (r !== void 0) o = r, s = "source";
1017
1034
  else try {
1018
1035
  o = t.foreignKey ?? N(i, n.tableName, e), s = "target";
@@ -1025,13 +1042,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1025
1042
  return null;
1026
1043
  }
1027
1044
  let c = r.with === void 0 ? [] : (() => {
1028
- let e = jn(i.tableName);
1045
+ let e = Pn(i.tableName);
1029
1046
  if (e === void 0 && Object.keys(r.with).length > 0) return null;
1030
1047
  let t = [];
1031
1048
  for (let [n, a] of Object.entries(r.with)) {
1032
1049
  let r = e?.[n];
1033
1050
  if (r === void 0) return null;
1034
- let o = Br(n, r, i, a === !0 ? {} : a);
1051
+ let o = Ur(n, r, i, a === !0 ? {} : a);
1035
1052
  if (o === null) return null;
1036
1053
  t.push(o);
1037
1054
  }
@@ -1047,9 +1064,9 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1047
1064
  fkSide: s,
1048
1065
  branch: r,
1049
1066
  children: c,
1050
- junction: Vr(t, r)
1067
+ junction: Wr(t, r)
1051
1068
  };
1052
- }, Vr = (e, t) => {
1069
+ }, Wr = (e, t) => {
1053
1070
  if (e.kind !== "manyToMany" || t.junction === void 0) return;
1054
1071
  let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
1055
1072
  return {
@@ -1061,35 +1078,35 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1061
1078
  return t !== void 0 && (t.type === "timestamp" || t.type === "date");
1062
1079
  })
1063
1080
  };
1064
- }, Hr = (e) => `__j_${e}`, Ur = "__j", Wr = (e, t) => {
1081
+ }, Gr = (e) => `__j_${e}`, Kr = "__j", qr = (e, t) => {
1065
1082
  for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
1066
- }, Gr = (e, t) => {
1083
+ }, Jr = (e, t) => {
1067
1084
  let n = 0;
1068
1085
  return {
1069
1086
  sql: e,
1070
1087
  dialect: t,
1071
1088
  nextAlias: () => `__a${n++}`
1072
1089
  };
1073
- }, Kr = (e, t, n, r) => {
1090
+ }, Yr = (e, t, n, r) => {
1074
1091
  switch (e) {
1075
- case "postgres": return Qr(t, n, r);
1092
+ case "postgres": return ti(t, n, r);
1076
1093
  case "sqlite":
1077
- case "turso": return oi(t, n, r);
1094
+ case "turso": return li(t, n, r);
1078
1095
  case "mysql":
1079
- case "mariadb": return gi(t, n, r);
1080
- case "mssql": return Ci(t, n, r);
1096
+ case "mariadb": return yi(t, n, r);
1097
+ case "mssql": return Ei(t, n, r);
1081
1098
  }
1082
- }, qr = (e, t) => t === "mssql" && !Jr.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), Jr = /(?:Z|[+-]\d{2}:?\d{2})$/, Yr = (e, t) => {
1083
- let n = Xr(e.table, e.children, t);
1099
+ }, Xr = (e, t) => t === "mssql" && !Zr.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), Zr = /(?:Z|[+-]\d{2}:?\d{2})$/, Qr = (e, t) => {
1100
+ let n = $r(e.table, e.children, t);
1084
1101
  return (e) => e.map((e) => {
1085
1102
  let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
1086
1103
  return n(r);
1087
1104
  });
1088
- }, Xr = (e, t, n) => {
1105
+ }, $r = (e, t, n) => {
1089
1106
  let r = [];
1090
1107
  for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
1091
1108
  let i = t.map((e) => {
1092
- let t = Xr(e.target, e.children, n), r = e.relation.kind === "one", i = Lr(e), a = i ? er({
1109
+ let t = $r(e.target, e.children, n), r = e.relation.kind === "one", i = Br(e), a = i ? rr({
1093
1110
  relationName: e.relationName,
1094
1111
  sourceTableName: e.source.tableName,
1095
1112
  targetTableName: e.target.tableName,
@@ -1102,14 +1119,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1102
1119
  isSingle: r,
1103
1120
  fromOverFetch: i,
1104
1121
  cardinalityMessage: a,
1105
- junction: Zr(e.junction, n)
1122
+ junction: ei(e.junction, n)
1106
1123
  };
1107
1124
  });
1108
1125
  return (e) => {
1109
1126
  let t = { ...e };
1110
1127
  for (let e of r) {
1111
1128
  let r = t[e];
1112
- typeof r == "string" && (t[e] = qr(r, n));
1129
+ typeof r == "string" && (t[e] = Xr(r, n));
1113
1130
  }
1114
1131
  for (let e of i) {
1115
1132
  let n = t[e.name];
@@ -1119,7 +1136,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1119
1136
  }
1120
1137
  if (e.fromOverFetch) {
1121
1138
  let r = n;
1122
- if (r.length > 1) throw new $n(e.cardinalityMessage);
1139
+ if (r.length > 1) throw new nr(e.cardinalityMessage);
1123
1140
  t[e.name] = r.length === 0 ? null : e.decode(r[0]);
1124
1141
  continue;
1125
1142
  }
@@ -1131,104 +1148,104 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1131
1148
  }
1132
1149
  return t;
1133
1150
  };
1134
- }, Zr = (e, t) => {
1151
+ }, ei = (e, t) => {
1135
1152
  if (e === void 0) return;
1136
1153
  let n = new Set(e.dateColumns), r = e.requested;
1137
1154
  return (e) => {
1138
1155
  let i = e._junction ?? {}, a = {};
1139
1156
  for (let e of r) {
1140
1157
  let r = i[e];
1141
- a[e] = n.has(e) && typeof r == "string" ? qr(r, t) : r;
1158
+ a[e] = n.has(e) && typeof r == "string" ? Xr(r, t) : r;
1142
1159
  }
1143
1160
  return {
1144
1161
  ...e,
1145
1162
  _junction: a
1146
1163
  };
1147
1164
  };
1148
- }, Qr = (e, t, n) => {
1149
- let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = $r(i, t.children, n);
1165
+ }, ti = (e, t, n) => {
1166
+ let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = ni(i, t.children, n);
1150
1167
  return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``}${C(e).length > 0 ? r` ORDER BY ${r.csv(C(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`}`;
1151
- }, $r = (e, t, n, r) => {
1152
- let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${z(Ur, i)}::text)`;
1168
+ }, ni = (e, t, n, r) => {
1169
+ let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${z(Kr, i)}::text)`;
1153
1170
  if (t.length === 0 && r === void 0) return a;
1154
1171
  let o = [];
1155
- r !== void 0 && o.push(i`${z("_junction", i)}, ${R(e, Ur, i)}`);
1172
+ r !== void 0 && o.push(i`${z("_junction", i)}, ${R(e, Kr, i)}`);
1156
1173
  for (let r of t) {
1157
- let t = ei(r, e, n);
1174
+ let t = ri(r, e, n);
1158
1175
  if (t === null) return null;
1159
1176
  o.push(i`${z(r.relationName, i)}, ${t}`);
1160
1177
  }
1161
1178
  return i`${a} || jsonb_build_object(${i.csv(o)})`;
1162
- }, ei = (e, t, n) => {
1179
+ }, ri = (e, t, n) => {
1163
1180
  switch (e.relation.kind) {
1164
- case "one": return Lr(e) ? ni(Rr(e), t, n) : ti(e, t, n);
1165
- case "many": return ni(e, t, n);
1166
- case "manyToMany": return ri(e, t, n);
1181
+ case "one": return Br(e) ? ai(Vr(e), t, n) : ii(e, t, n);
1182
+ case "many": return ai(e, t, n);
1183
+ case "manyToMany": return oi(e, t, n);
1167
1184
  }
1168
- }, ti = (e, t, n) => {
1169
- let r = n.sql, i = n.nextAlias(), a = $r(i, e.children, n);
1185
+ }, ii = (e, t, n) => {
1186
+ let r = n.sql, i = n.nextAlias(), a = ni(i, e.children, n);
1170
1187
  if (a === null) return null;
1171
1188
  let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, c = I(i, e.branch.orderBy, r);
1172
1189
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
1173
- }, ni = (e, t, n) => {
1174
- let r = n.sql, i = n.nextAlias(), a = $r(i, e.children, n);
1190
+ }, ai = (e, t, n) => {
1191
+ let r = n.sql, i = n.nextAlias(), a = ni(i, e.children, n);
1175
1192
  if (a === null) return null;
1176
- let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, c = ai(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
1193
+ let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, c = ci(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
1177
1194
  return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
1178
- }, ri = (e, t, n) => {
1179
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = $r(o, e.children, n, e.junction);
1195
+ }, oi = (e, t, n) => {
1196
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ni(o, e.children, n, e.junction);
1180
1197
  if (c === null) return null;
1181
- let l = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, u = ji(e, s, r), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${ii(e.junction, s, r)} AS ${r(Ur)}`;
1198
+ let l = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, u = Pi(e, s, r), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${si(e.junction, s, r)} AS ${r(Kr)}`;
1182
1199
  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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
1183
- }, ii = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${z(e, n)}, ${R(t, e, n)}`))})`, I = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${R(e, t.column, n)} DESC` : n`${R(e, t.column, n)} ASC`))}`, ai = (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`))}`, oi = (e, t, n) => {
1184
- let r = n.sql, i = n.nextAlias(), a = si(i, t.table, t.children, n);
1200
+ }, si = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${z(e, n)}, ${R(t, e, n)}`))})`, I = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${R(e, t.column, n)} DESC` : n`${R(e, t.column, n)} ASC`))}`, ci = (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`))}`, li = (e, t, n) => {
1201
+ let r = n.sql, i = n.nextAlias(), a = ui(i, t.table, t.children, n);
1185
1202
  if (a === null) return null;
1186
1203
  let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = C(e).length > 0 ? r` ORDER BY ${r.csv(C(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`;
1187
1204
  return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
1188
- }, si = (e, t, n, r, i) => {
1205
+ }, ui = (e, t, n, r, i) => {
1189
1206
  let a = r.sql, o = [];
1190
1207
  for (let n of Object.keys(t.fields)) o.push(a`${z(n, a)}, ${R(e, n, a)}`);
1191
1208
  if (i !== void 0) {
1192
- let e = ci(i.projection, i.source, a);
1209
+ let e = di(i.projection, i.source, a);
1193
1210
  o.push(a`${z("_junction", a)}, json_object(${e})`);
1194
1211
  }
1195
1212
  for (let t of n) {
1196
- let n = fi(t, e, r);
1213
+ let n = hi(t, e, r);
1197
1214
  if (n === null) return null;
1198
1215
  o.push(a`${z(t.relationName, a)}, ${n}`);
1199
1216
  }
1200
1217
  return a`json_object(${a.csv(o)})`;
1201
- }, ci = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${z(e, n)}, ${R(t.alias, t.physical(e), n)}`)), li = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${R(t, e, n)} AS ${n(Hr(e))}`))}`, ui = (e) => ({
1218
+ }, di = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${z(e, n)}, ${R(t.alias, t.physical(e), n)}`)), fi = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${R(t, e, n)} AS ${n(Gr(e))}`))}`, pi = (e) => ({
1202
1219
  alias: e,
1203
- physical: Hr
1204
- }), di = (e) => ({
1220
+ physical: Gr
1221
+ }), mi = (e) => ({
1205
1222
  alias: e,
1206
1223
  physical: (e) => e
1207
- }), fi = (e, t, n) => {
1224
+ }), hi = (e, t, n) => {
1208
1225
  switch (e.relation.kind) {
1209
- case "one": return Lr(e) ? mi(Rr(e), t, n) : pi(e, t, n);
1210
- case "many": return mi(e, t, n);
1211
- case "manyToMany": return hi(e, t, n);
1226
+ case "one": return Br(e) ? _i(Vr(e), t, n) : gi(e, t, n);
1227
+ case "many": return _i(e, t, n);
1228
+ case "manyToMany": return vi(e, t, n);
1212
1229
  }
1213
- }, pi = (e, t, n) => {
1214
- let r = n.sql, i = n.nextAlias(), a = si(i, e.target, e.children, n);
1230
+ }, gi = (e, t, n) => {
1231
+ let r = n.sql, i = n.nextAlias(), a = ui(i, e.target, e.children, n);
1215
1232
  if (a === null) return null;
1216
1233
  let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
1217
1234
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
1218
- }, mi = (e, t, n) => {
1219
- let r = n.sql, i = n.nextAlias(), a = si(i, e.target, e.children, n);
1235
+ }, _i = (e, t, n) => {
1236
+ let r = n.sql, i = n.nextAlias(), a = ui(i, e.target, e.children, n);
1220
1237
  if (a === null) return null;
1221
- let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = ai(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
1238
+ let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = ci(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
1222
1239
  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('[]'))`;
1223
- }, hi = (e, t, n) => {
1224
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = si(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1240
+ }, vi = (e, t, n) => {
1241
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ui(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1225
1242
  projection: e.junction,
1226
- source: ui(o)
1243
+ source: pi(o)
1227
1244
  });
1228
1245
  if (c === null) return null;
1229
- let l = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, u = ji(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : li(e.junction, s, r);
1246
+ let l = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, u = Pi(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : fi(e.junction, s, r);
1230
1247
  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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
1231
- }, gi = (e, t, n) => {
1248
+ }, yi = (e, t, n) => {
1232
1249
  let r = n.sql, i = n.nextAlias(), a = L(i, t.table, t.children, n);
1233
1250
  if (a === null) return null;
1234
1251
  let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = C(e).length > 0 ? r` ORDER BY ${r.csv(C(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`;
@@ -1237,66 +1254,66 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1237
1254
  let a = r.sql, o = [];
1238
1255
  for (let n of Object.keys(t.fields)) o.push(a`${z(n, a)}, ${R(e, n, a)}`);
1239
1256
  if (i !== void 0) {
1240
- let e = ci(i.projection, i.source, a);
1257
+ let e = di(i.projection, i.source, a);
1241
1258
  o.push(a`${z("_junction", a)}, JSON_OBJECT(${e})`);
1242
1259
  }
1243
1260
  for (let t of n) {
1244
- let n = _i(t, e, r);
1261
+ let n = bi(t, e, r);
1245
1262
  if (n === null) return null;
1246
1263
  o.push(a`${z(t.relationName, a)}, ${n}`);
1247
1264
  }
1248
1265
  return a`JSON_OBJECT(${a.csv(o)})`;
1249
- }, _i = (e, t, n) => {
1266
+ }, bi = (e, t, n) => {
1250
1267
  switch (e.relation.kind) {
1251
1268
  case "one":
1252
- if (Lr(e)) {
1253
- let r = Rr(e);
1254
- return n.dialect === "mariadb" ? xi(r, t, n) : yi(r, t, n);
1269
+ if (Br(e)) {
1270
+ let r = Vr(e);
1271
+ return n.dialect === "mariadb" ? wi(r, t, n) : Si(r, t, n);
1255
1272
  }
1256
- return vi(e, t, n);
1257
- case "many": return n.dialect === "mariadb" ? xi(e, t, n) : yi(e, t, n);
1258
- case "manyToMany": return n.dialect === "mariadb" ? Si(e, t, n) : bi(e, t, n);
1273
+ return xi(e, t, n);
1274
+ case "many": return n.dialect === "mariadb" ? wi(e, t, n) : Si(e, t, n);
1275
+ case "manyToMany": return n.dialect === "mariadb" ? Ti(e, t, n) : Ci(e, t, n);
1259
1276
  }
1260
- }, vi = (e, t, n) => {
1277
+ }, xi = (e, t, n) => {
1261
1278
  let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
1262
1279
  if (a === null) return null;
1263
1280
  let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
1264
1281
  return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
1265
- }, yi = (e, t, n) => {
1282
+ }, Si = (e, t, n) => {
1266
1283
  let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
1267
1284
  if (a === null) return null;
1268
- let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = ai(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
1285
+ let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = ci(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
1269
1286
  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())`;
1270
- }, bi = (e, t, n) => {
1287
+ }, Ci = (e, t, n) => {
1271
1288
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = L(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1272
1289
  projection: e.junction,
1273
- source: ui(o)
1290
+ source: pi(o)
1274
1291
  });
1275
1292
  if (c === null) return null;
1276
- let l = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, u = ji(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : li(e.junction, s, r);
1293
+ let l = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, u = Pi(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : fi(e.junction, s, r);
1277
1294
  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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
1278
- }, xi = (e, t, n) => {
1295
+ }, wi = (e, t, n) => {
1279
1296
  let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
1280
1297
  if (a === null) return null;
1281
1298
  let o = r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
1282
1299
  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`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
1283
1300
  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 ${R(i, "rn", r)} > ${B(d, r)} AND ${R(i, "rn", r)} <= ${B(d + u, r)}` : u === void 0 ? r` AND ${R(i, "rn", r)} > ${B(d, r)}` : r` AND ${R(i, "rn", r)} <= ${B(u, r)}`;
1284
1301
  return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${R(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())`;
1285
- }, Si = (e, t, n) => {
1302
+ }, Ti = (e, t, n) => {
1286
1303
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
1287
1304
  projection: e.junction,
1288
1305
  source: t
1289
- }, l = r`${R(s, i.sourceKey, r)} = ${R(t, "id", r)}`, u = r`${R(o, "id", r)} = ${R(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, f = ji(e, s, r, !0), p = e.branch.orderBy ?? [];
1306
+ }, l = r`${R(s, i.sourceKey, r)} = ${R(t, "id", r)}`, u = r`${R(o, "id", r)} = ${R(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, f = Pi(e, s, r, !0), p = e.branch.orderBy ?? [];
1290
1307
  if (e.branch.limit === void 0 && e.branch.offset === void 0) {
1291
- let t = L(o, e.target, e.children, n, c(di(s)));
1308
+ let t = L(o, e.target, e.children, n, c(mi(s)));
1292
1309
  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`${R(o, e.column, r)} DESC` : r`${R(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())`;
1293
1310
  }
1294
- let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${R(o, e.column, r)} DESC` : r`${R(o, e.column, r)} ASC`))}` : r` ORDER BY ${R(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)} AND ${R(o, "rn", r)} <= ${B(g + h, r)}` : h === void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)}` : r` AND ${R(o, "rn", r)} <= ${B(h, r)}`, te = e.branch.onJunction === void 0 ? r`` : r` WHERE ${V(H(e.branch.onJunction), s, r)}`, _ = L(o, e.target, e.children, n, c(ui(o)));
1311
+ let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${R(o, e.column, r)} DESC` : r`${R(o, e.column, r)} ASC`))}` : r` ORDER BY ${R(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)} AND ${R(o, "rn", r)} <= ${B(g + h, r)}` : h === void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)}` : r` AND ${R(o, "rn", r)} <= ${B(h, r)}`, te = e.branch.onJunction === void 0 ? r`` : r` WHERE ${V(H(e.branch.onJunction), s, r)}`, _ = L(o, e.target, e.children, n, c(pi(o)));
1295
1312
  if (_ === null) return null;
1296
- let v = e.junction === void 0 ? r`` : li(e.junction, s, r);
1313
+ let v = e.junction === void 0 ? r`` : fi(e.junction, s, r);
1297
1314
  return r`COALESCE((SELECT JSON_ARRAYAGG(${_} ORDER BY ${R(o, "rn", r)}) FROM (SELECT ${r(o)}.*${v}, ${R(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${R(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}${te}) AS ${r(o)} WHERE ${R(o, `__src_${i.sourceKey}`, r)} = ${R(t, "id", r)}${d}${ee}), JSON_ARRAY())`;
1298
- }, Ci = (e, t, n) => {
1299
- let r = n.sql, i = n.nextAlias(), a = wi(i, t.table, t.children, n);
1315
+ }, Ei = (e, t, n) => {
1316
+ let r = n.sql, i = n.nextAlias(), a = Di(i, t.table, t.children, n);
1300
1317
  if (a === null) return null;
1301
1318
  let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = C(e).length > 0 ? r` ORDER BY ${r.csv(C(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
1302
1319
  if (e.skip !== void 0) {
@@ -1305,28 +1322,28 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1305
1322
  } else e.take !== void 0 && (c = r`TOP ${B(e.take, r)} `);
1306
1323
  let u = e.skip === void 0 ? s : r``;
1307
1324
  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}`;
1308
- }, wi = (e, t, n, r, i) => {
1325
+ }, Di = (e, t, n, r, i) => {
1309
1326
  let a = r.sql, o = [];
1310
1327
  for (let n of Object.keys(t.fields)) o.push(a`${R(e, n, a)} AS ${a(n)}`);
1311
- if (i !== void 0) for (let e of i.projection.present) o.push(a`${R(i.source.alias, i.source.physical(e), a)} AS ${Ti(`_junction.${e}`, a)}`);
1328
+ if (i !== void 0) for (let e of i.projection.present) o.push(a`${R(i.source.alias, i.source.physical(e), a)} AS ${Oi(`_junction.${e}`, a)}`);
1312
1329
  for (let t of n) {
1313
- let n = Ei(t, e, r);
1330
+ let n = ki(t, e, r);
1314
1331
  if (n === null) return null;
1315
1332
  o.push(n);
1316
1333
  }
1317
1334
  return a.csv(o);
1318
- }, Ti = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Ei = (e, t, n) => {
1335
+ }, Oi = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), ki = (e, t, n) => {
1319
1336
  switch (e.relation.kind) {
1320
- case "one": return Lr(e) ? ki(Rr(e), t, n) : Di(e, t, n);
1321
- case "many": return ki(e, t, n);
1322
- case "manyToMany": return Ai(e, t, n);
1337
+ case "one": return Br(e) ? Mi(Vr(e), t, n) : Ai(e, t, n);
1338
+ case "many": return Mi(e, t, n);
1339
+ case "manyToMany": return Ni(e, t, n);
1323
1340
  }
1324
- }, Di = (e, t, n) => {
1325
- let r = n.sql, i = n.nextAlias(), a = wi(i, e.target, e.children, n);
1341
+ }, Ai = (e, t, n) => {
1342
+ let r = n.sql, i = n.nextAlias(), a = Di(i, e.target, e.children, n);
1326
1343
  if (a === null) return null;
1327
1344
  let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
1328
1345
  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)}`;
1329
- }, Oi = (e, t, n) => {
1346
+ }, ji = (e, t, n) => {
1330
1347
  if (e.offset !== void 0) {
1331
1348
  let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${B(e.offset, n)} ROWS` : n`${r} OFFSET ${B(e.offset, n)} ROWS FETCH NEXT ${B(e.limit, n)} ROWS ONLY`;
1332
1349
  return {
@@ -1340,29 +1357,29 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1340
1357
  pagination: n``,
1341
1358
  finalOrder: t
1342
1359
  };
1343
- }, ki = (e, t, n) => {
1344
- let r = n.sql, i = n.nextAlias(), a = wi(i, e.target, e.children, n);
1360
+ }, Mi = (e, t, n) => {
1361
+ let r = n.sql, i = n.nextAlias(), a = Di(i, e.target, e.children, n);
1345
1362
  if (a === null) return null;
1346
- let o = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, s = I(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Oi(e.branch, s, r);
1363
+ let o = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, s = I(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = ji(e.branch, s, r);
1347
1364
  return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1348
- }, Ai = (e, t, n) => {
1349
- let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = wi(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1365
+ }, Ni = (e, t, n) => {
1366
+ let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Di(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
1350
1367
  projection: e.junction,
1351
- source: di(s)
1368
+ source: mi(s)
1352
1369
  });
1353
1370
  if (c === null) return null;
1354
- let l = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, o, r)}`, u = ji(e, s, r), d = I(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Oi(e.branch, d, r);
1371
+ let l = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, o, r)}`, u = Pi(e, s, r), d = I(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = ji(e.branch, d, r);
1355
1372
  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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
1356
1373
  }, R = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, z = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), B = (e, t) => {
1357
1374
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
1358
1375
  return t.unsafe(String(e));
1359
- }, V = (e, t, n) => F(Mi(e, t), n), ji = (e, t, n, r = !1) => {
1376
+ }, V = (e, t, n) => F(Fi(e, t), n), Pi = (e, t, n, r = !1) => {
1360
1377
  let i = e.branch.onJunction;
1361
1378
  return i === void 0 ? n`` : n` AND ${V(r ? H(i) : i, t, n)}`;
1362
- }, Mi = (e, t) => {
1363
- if ("not" in e) return { not: Mi(e.not, t) };
1364
- if ("and" in e) return { and: e.and.map((e) => Mi(e, t)) };
1365
- if ("or" in e) return { or: e.or.map((e) => Mi(e, t)) };
1379
+ }, Fi = (e, t) => {
1380
+ if ("not" in e) return { not: Fi(e.not, t) };
1381
+ if ("and" in e) return { and: e.and.map((e) => Fi(e, t)) };
1382
+ if ("or" in e) return { or: e.or.map((e) => Fi(e, t)) };
1366
1383
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
1367
1384
  let n = e;
1368
1385
  return {
@@ -1384,15 +1401,15 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1384
1401
  let t = e;
1385
1402
  return {
1386
1403
  ...t,
1387
- value: Ni(t.value)
1404
+ value: Ii(t.value)
1388
1405
  };
1389
- }, Ni = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Ni(e)) : e, Pi = Symbol.for("@voltro/database/coreTablesRegistry"), Fi = globalThis, Ii = Fi[Pi] ?? (Fi[Pi] = {}), Li = (e) => {
1390
- e.actors !== void 0 && (Ii.actors = e.actors), e.tenants !== void 0 && (Ii.tenants = e.tenants);
1391
- }, Ri = (e, t) => () => {
1406
+ }, Ii = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Ii(e)) : e, Li = Symbol.for("@voltro/database/coreTablesRegistry"), Ri = globalThis, zi = Ri[Li] ?? (Ri[Li] = {}), Bi = (e) => {
1407
+ e.actors !== void 0 && (zi.actors = e.actors), e.tenants !== void 0 && (zi.tenants = e.tenants);
1408
+ }, Vi = (e, t) => () => {
1392
1409
  let n = e();
1393
1410
  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`);
1394
1411
  return n();
1395
- }, zi = () => Ri(() => Ii.actors, "actors"), Bi = () => Ri(() => Ii.tenants, "tenants"), Vi = T("actors", {
1412
+ }, Hi = () => Vi(() => zi.actors, "actors"), Ui = () => Vi(() => zi.tenants, "tenants"), Wi = T("actors", {
1396
1413
  id: b(),
1397
1414
  kind: v().oneOf([
1398
1415
  "user",
@@ -1402,73 +1419,73 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1402
1419
  ]),
1403
1420
  displayName: v().nullable(),
1404
1421
  createdAt: S().default("now")
1405
- }), Hi = (e, t) => ({
1422
+ }), Gi = (e, t) => ({
1406
1423
  column: e,
1407
1424
  op: "eq",
1408
1425
  value: t
1409
- }), Ui = (e, t) => ({
1426
+ }), Ki = (e, t) => ({
1410
1427
  column: e,
1411
1428
  op: "neq",
1412
1429
  value: t
1413
- }), Wi = (e, t) => ({
1430
+ }), qi = (e, t) => ({
1414
1431
  column: e,
1415
1432
  op: "gt",
1416
1433
  value: t
1417
- }), Gi = (e, t) => ({
1434
+ }), Ji = (e, t) => ({
1418
1435
  column: e,
1419
1436
  op: "gte",
1420
1437
  value: t
1421
- }), Ki = (e, t) => ({
1438
+ }), Yi = (e, t) => ({
1422
1439
  column: e,
1423
1440
  op: "lt",
1424
1441
  value: t
1425
- }), qi = (e, t) => ({
1442
+ }), Xi = (e, t) => ({
1426
1443
  column: e,
1427
1444
  op: "lte",
1428
1445
  value: t
1429
- }), Ji = (e, t) => ({
1446
+ }), Zi = (e, t) => ({
1430
1447
  column: e,
1431
1448
  op: "in",
1432
1449
  value: t
1433
- }), Yi = (e, t) => ({
1450
+ }), Qi = (e, t) => ({
1434
1451
  column: e,
1435
1452
  op: "notIn",
1436
1453
  value: t
1437
- }), Xi = (e, t) => ({
1454
+ }), $i = (e, t) => ({
1438
1455
  column: e,
1439
1456
  op: "contains",
1440
1457
  value: t
1441
- }), Zi = (e, t) => ({
1458
+ }), ea = (e, t) => ({
1442
1459
  column: e,
1443
1460
  op: "startsWith",
1444
1461
  value: t
1445
- }), Qi = (e, t) => ({
1462
+ }), ta = (e, t) => ({
1446
1463
  column: e,
1447
1464
  op: "arrayContains",
1448
1465
  value: t
1449
- }), $i = (e, t) => ({
1466
+ }), na = (e, t) => ({
1450
1467
  column: e,
1451
1468
  op: "arrayOverlaps",
1452
1469
  value: t
1453
- }), ea = (e, t) => ({
1470
+ }), ra = (e, t) => ({
1454
1471
  column: e,
1455
1472
  op: "arrayHas",
1456
1473
  value: t
1457
- }), ta = {
1474
+ }), ia = {
1458
1475
  column: "id",
1459
1476
  op: "in",
1460
1477
  value: []
1461
- }, na = (e) => ({
1478
+ }, aa = (e) => ({
1462
1479
  column: e,
1463
1480
  op: "isNull"
1464
- }), ra = (e) => ({
1481
+ }), oa = (e) => ({
1465
1482
  column: e,
1466
1483
  op: "isNotNull"
1467
- }), ia = (e, t) => ({
1484
+ }), sa = (e, t) => ({
1468
1485
  column: e,
1469
1486
  op: "spatial",
1470
1487
  value: t
1471
- }), aa = (...e) => ({ and: e }), oa = (...e) => ({ or: e }), sa = (e) => ({ not: e }), ca = (e, ...t) => {
1488
+ }), ca = (...e) => ({ and: e }), la = (...e) => ({ or: e }), ua = (e) => ({ not: e }), da = (e, ...t) => {
1472
1489
  if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
1473
1490
  let n = (n, r) => ({
1474
1491
  column: e,
@@ -1490,33 +1507,33 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1490
1507
  isNull: () => n("isNull"),
1491
1508
  isNotNull: () => n("isNotNull")
1492
1509
  };
1493
- }, la = (e) => "descriptor" in e ? e.descriptor : e, ua = (e, t) => ({
1510
+ }, fa = (e) => "descriptor" in e ? e.descriptor : e, pa = (e, t) => ({
1494
1511
  column: e,
1495
1512
  op: "subquery-in",
1496
- subquery: la(t)
1497
- }), da = (e, t) => ({
1513
+ subquery: fa(t)
1514
+ }), ma = (e, t) => ({
1498
1515
  column: e,
1499
1516
  op: "subquery-not-in",
1500
- subquery: la(t)
1501
- }), fa = (e) => ({
1517
+ subquery: fa(t)
1518
+ }), ha = (e) => ({
1502
1519
  op: "exists",
1503
- subquery: la(e)
1504
- }), pa = (e) => ({
1520
+ subquery: fa(e)
1521
+ }), ga = (e) => ({
1505
1522
  op: "not-exists",
1506
- subquery: la(e)
1507
- }), ma = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), ha = (e, t) => {
1523
+ subquery: fa(e)
1524
+ }), _a = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), va = (e, t) => {
1508
1525
  if (e == null || t == null) return null;
1509
1526
  let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
1510
1527
  return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
1511
- }, ga = (e, t, n = null) => {
1528
+ }, ya = (e, t, n = null) => {
1512
1529
  if (!t) return !1;
1513
- if ("not" in e) return !ga(e.not, t, n);
1530
+ if ("not" in e) return !ya(e.not, t, n);
1514
1531
  if ("and" in e) {
1515
- for (let r of e.and) if (!ga(r, t, n)) return !1;
1532
+ for (let r of e.and) if (!ya(r, t, n)) return !1;
1516
1533
  return !0;
1517
1534
  }
1518
1535
  if ("or" in e) {
1519
- for (let r of e.or) if (ga(r, t, n)) return !0;
1536
+ for (let r of e.or) if (ya(r, t, n)) return !0;
1520
1537
  return !1;
1521
1538
  }
1522
1539
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
@@ -1533,14 +1550,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1533
1550
  }
1534
1551
  let r = e, i = t[r.column];
1535
1552
  switch (r.op) {
1536
- case "eq": return ma(i, r.value);
1537
- case "neq": return !ma(i, r.value);
1538
- case "gt": return (ha(i, r.value) ?? -1) > 0;
1539
- case "gte": return (ha(i, r.value) ?? -1) >= 0;
1540
- case "lt": return (ha(i, r.value) ?? 1) < 0;
1541
- case "lte": return (ha(i, r.value) ?? 1) <= 0;
1542
- case "in": return Array.isArray(r.value) && r.value.some((e) => ma(i, e));
1543
- case "notIn": return Array.isArray(r.value) && !r.value.some((e) => ma(i, e));
1553
+ case "eq": return _a(i, r.value);
1554
+ case "neq": return !_a(i, r.value);
1555
+ case "gt": return (va(i, r.value) ?? -1) > 0;
1556
+ case "gte": return (va(i, r.value) ?? -1) >= 0;
1557
+ case "lt": return (va(i, r.value) ?? 1) < 0;
1558
+ case "lte": return (va(i, r.value) ?? 1) <= 0;
1559
+ case "in": return Array.isArray(r.value) && r.value.some((e) => _a(i, e));
1560
+ case "notIn": return Array.isArray(r.value) && !r.value.some((e) => _a(i, e));
1544
1561
  case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
1545
1562
  case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
1546
1563
  case "arrayContains": {
@@ -1556,17 +1573,17 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1556
1573
  case "isNotNull": return i != null;
1557
1574
  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.");
1558
1575
  }
1559
- }, _a = function* (e) {
1576
+ }, ba = function* (e) {
1560
1577
  if ("not" in e) {
1561
- yield* _a(e.not);
1578
+ yield* ba(e.not);
1562
1579
  return;
1563
1580
  }
1564
1581
  if ("and" in e) {
1565
- for (let t of e.and) yield* _a(t);
1582
+ for (let t of e.and) yield* ba(t);
1566
1583
  return;
1567
1584
  }
1568
1585
  if ("or" in e) {
1569
- for (let t of e.or) yield* _a(t);
1586
+ for (let t of e.or) yield* ba(t);
1570
1587
  return;
1571
1588
  }
1572
1589
  e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
@@ -1576,46 +1593,46 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1576
1593
  kind: "exists",
1577
1594
  descriptor: e.subquery
1578
1595
  });
1579
- }, va = function* (e, t = !0) {
1596
+ }, xa = function* (e, t = !0) {
1580
1597
  if ("not" in e) {
1581
- yield* va(e.not, !1);
1598
+ yield* xa(e.not, !1);
1582
1599
  return;
1583
1600
  }
1584
1601
  if ("and" in e) {
1585
- for (let n of e.and) yield* va(n, t);
1602
+ for (let n of e.and) yield* xa(n, t);
1586
1603
  return;
1587
1604
  }
1588
1605
  if ("or" in e) {
1589
- for (let t of e.or) yield* va(t, !1);
1606
+ for (let t of e.or) yield* xa(t, !1);
1590
1607
  return;
1591
1608
  }
1592
1609
  e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
1593
1610
  ...e,
1594
1611
  conjunctive: t
1595
1612
  });
1596
- }, ya = (e, t) => ({
1613
+ }, Sa = (e, t) => ({
1597
1614
  ...t,
1598
1615
  ...e,
1599
1616
  origin: e.origin ?? "injected"
1600
- }), ba = (e, t, n = {}) => ({
1617
+ }), Ca = (e, t, n = {}) => ({
1601
1618
  table: e,
1602
1619
  op: "insert",
1603
1620
  old: null,
1604
1621
  new: t,
1605
1622
  ...n
1606
- }), xa = (e, t, n, r = {}) => ({
1623
+ }), wa = (e, t, n, r = {}) => ({
1607
1624
  table: e,
1608
1625
  op: "update",
1609
1626
  old: t,
1610
1627
  new: n,
1611
1628
  ...r
1612
- }), Sa = (e, t, n = {}) => ({
1629
+ }), Ta = (e, t, n = {}) => ({
1613
1630
  table: e,
1614
1631
  op: "delete",
1615
1632
  old: t,
1616
1633
  new: null,
1617
1634
  ...n
1618
- }), Ca = (e, t, n = {}) => {
1635
+ }), Ea = (e, t, n = {}) => {
1619
1636
  let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
1620
1637
  return {
1621
1638
  table: e,
@@ -1630,26 +1647,26 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1630
1647
  },
1631
1648
  ...a
1632
1649
  };
1633
- }, wa = new Nt(), Ta = (e, t) => wa.run(e, t), Ea = () => wa.getStore(), Da = (e) => {
1634
- let t = e ?? wa.getStore();
1650
+ }, Da = new Nt(), Oa = (e, t) => Da.run(e, t), ka = () => Da.getStore(), Aa = (e) => {
1651
+ let t = e ?? Da.getStore();
1635
1652
  return t === void 0 ? {} : {
1636
1653
  ...t.traceId === void 0 ? {} : { traceId: t.traceId },
1637
1654
  ...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
1638
1655
  ...t.procedure === void 0 ? {} : { procedure: t.procedure },
1639
1656
  ...t.via === void 0 ? {} : { via: t.via }
1640
1657
  };
1641
- }, Oa = (e) => {
1642
- let t = wa.getStore();
1643
- return t === void 0 ? e(void 0) : wa.run(t, () => e(t));
1644
- }, ka = 3e4, Aa = 1e4, U = /* @__PURE__ */ new Map(), W = 0, ja = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Ma = (e) => {
1658
+ }, ja = (e) => {
1659
+ let t = Da.getStore();
1660
+ return t === void 0 ? e(void 0) : Da.run(t, () => e(t));
1661
+ }, Ma = 3e4, Na = 1e4, U = /* @__PURE__ */ new Map(), W = 0, Pa = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Fa = (e) => {
1645
1662
  for (let [t, n] of U) {
1646
- let r = n.filter((t) => e - t.at < ka);
1663
+ let r = n.filter((t) => e - t.at < Ma);
1647
1664
  W -= n.length - r.length, r.length === 0 ? U.delete(t) : r.length !== n.length && U.set(t, r);
1648
1665
  }
1649
- }, Na = (e, t) => {
1666
+ }, Ia = (e, t) => {
1650
1667
  if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
1651
1668
  let n = Date.now();
1652
- if (W >= Aa && Ma(n), W >= Aa) return;
1669
+ if (W >= Na && Fa(n), W >= Na) return;
1653
1670
  let r = U.get(e);
1654
1671
  r === void 0 ? U.set(e, [{
1655
1672
  attribution: t,
@@ -1658,38 +1675,38 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1658
1675
  attribution: t,
1659
1676
  at: n
1660
1677
  }), W += 1;
1661
- }, Pa = (e) => {
1678
+ }, La = (e) => {
1662
1679
  let t = U.get(e);
1663
1680
  if (t === void 0 || t.length === 0) return;
1664
1681
  let n = t.shift();
1665
- if (--W, t.length === 0 && U.delete(e), !(Date.now() - n.at >= ka)) return n.attribution;
1666
- }, Fa = (e) => (U.get(e)?.length ?? 0) > 0, G = /* @__PURE__ */ new Map(), Ia = /* @__PURE__ */ new Map(), La = /* @__PURE__ */ new Map(), Ra = 250, za = (e) => {
1667
- let t = Ia.get(e);
1682
+ if (--W, t.length === 0 && U.delete(e), !(Date.now() - n.at >= Ma)) return n.attribution;
1683
+ }, Ra = (e) => (U.get(e)?.length ?? 0) > 0, G = /* @__PURE__ */ new Map(), za = /* @__PURE__ */ new Map(), Ba = /* @__PURE__ */ new Map(), Va = 250, Ha = (e) => {
1684
+ let t = za.get(e);
1668
1685
  if (t === void 0) return;
1669
- Ia.delete(e);
1670
- let n = La.get(e);
1671
- n !== void 0 && (clearTimeout(n), La.delete(e));
1686
+ za.delete(e);
1687
+ let n = Ba.get(e);
1688
+ n !== void 0 && (clearTimeout(n), Ba.delete(e));
1672
1689
  for (let e of t) e();
1673
- }, Ba = (e) => {
1690
+ }, Ua = (e) => {
1674
1691
  G.set(e, (G.get(e) ?? 0) + 1);
1675
- }, Va = (e) => {
1692
+ }, Wa = (e) => {
1676
1693
  let t = (G.get(e) ?? 0) - 1;
1677
1694
  if (t > 0) {
1678
1695
  G.set(e, t);
1679
1696
  return;
1680
1697
  }
1681
- G.delete(e), za(e);
1682
- }, Ha = (e, t, n, r) => {
1683
- let i = n == null ? void 0 : ja(e, t, n), a = () => r(i === void 0 ? void 0 : Pa(i));
1698
+ G.delete(e), Ha(e);
1699
+ }, Ga = (e, t, n, r) => {
1700
+ let i = n == null ? void 0 : Pa(e, t, n), a = () => r(i === void 0 ? void 0 : La(i));
1684
1701
  if (i === void 0) {
1685
1702
  a();
1686
1703
  return;
1687
1704
  }
1688
- if (Fa(i)) {
1705
+ if (Ra(i)) {
1689
1706
  a();
1690
1707
  return;
1691
1708
  }
1692
- let o = Ia.get(e);
1709
+ let o = za.get(e);
1693
1710
  if (o === void 0 && (G.get(e) ?? 0) === 0) {
1694
1711
  a();
1695
1712
  return;
@@ -1698,82 +1715,82 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1698
1715
  o.push(a);
1699
1716
  return;
1700
1717
  }
1701
- Ia.set(e, [a]);
1702
- let s = setTimeout(() => za(e), Ra);
1703
- typeof s == "object" && typeof s.unref == "function" && s.unref(), La.set(e, s);
1704
- }, Ua = () => {
1718
+ za.set(e, [a]);
1719
+ let s = setTimeout(() => Ha(e), Va);
1720
+ typeof s == "object" && typeof s.unref == "function" && s.unref(), Ba.set(e, s);
1721
+ }, Ka = () => {
1705
1722
  U.clear(), W = 0, G.clear();
1706
- for (let e of La.values()) clearTimeout(e);
1707
- La.clear(), Ia.clear();
1708
- }, Wa = () => W, K = /* @__PURE__ */ new Map(), Ga = (e, t) => {
1723
+ for (let e of Ba.values()) clearTimeout(e);
1724
+ Ba.clear(), za.clear();
1725
+ }, qa = () => W, K = /* @__PURE__ */ new Map(), Ja = (e, t) => {
1709
1726
  K.set(e, {
1710
1727
  recorder: t.recorder,
1711
1728
  tables: new Set(t.tables),
1712
1729
  ownTables: new Set(t.ownTables)
1713
1730
  });
1714
- }, Ka = (e) => {
1731
+ }, Ya = (e) => {
1715
1732
  K.delete(e);
1716
- }, qa = () => K.clear(), Ja = (e) => {
1733
+ }, Xa = () => K.clear(), Za = (e) => {
1717
1734
  if (K.size === 0) return !1;
1718
1735
  for (let t of K.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
1719
1736
  return !1;
1720
- }, Ya = async (e, t) => {
1737
+ }, Qa = async (e, t) => {
1721
1738
  if (K.size !== 0) {
1722
1739
  for (let [n, r] of K.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
1723
1740
  await r.recorder(e, t);
1724
1741
  } catch (e) {
1725
- let r = ln(e);
1742
+ let r = fn(e);
1726
1743
  throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
1727
1744
  }
1728
1745
  }
1729
- }, Xa = kt.exponential({
1746
+ }, $a = kt.exponential({
1730
1747
  start: 5e-4,
1731
1748
  factor: 2,
1732
1749
  count: 16
1733
- }), Za = D.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), Qa = D.histogram("voltro_db_query_duration_seconds", Xa, "Database operation duration in seconds, by dialect and operation kind."), $a = D.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), eo = D.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), to = D.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), no = [], ro = /* @__PURE__ */ new Map(), io = /* @__PURE__ */ new Map(), ao = /* @__PURE__ */ new Map(), oo = (e, t) => {
1734
- let n = `${e}\u0000${t}`, r = ro.get(n);
1750
+ }), eo = D.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), to = D.histogram("voltro_db_query_duration_seconds", $a, "Database operation duration in seconds, by dialect and operation kind."), no = D.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), ro = D.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), io = D.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), ao = [], oo = /* @__PURE__ */ new Map(), so = /* @__PURE__ */ new Map(), co = /* @__PURE__ */ new Map(), lo = (e, t) => {
1751
+ let n = `${e}\u0000${t}`, r = oo.get(n);
1735
1752
  if (r !== void 0) return r;
1736
1753
  let i = (n) => D.tagged(D.tagged(n, "dialect", e), "op", t), a = {
1737
- count: i(Za),
1738
- duration: i(Qa),
1739
- errors: i($a)
1754
+ count: i(eo),
1755
+ duration: i(to),
1756
+ errors: i(no)
1740
1757
  };
1741
- return ro.set(n, a), a;
1742
- }, so = () => {
1743
- ro.clear(), io.clear(), ao.clear();
1744
- }, co = () => ro.size + io.size + ao.size, lo = /* @__PURE__ */ new Map(), uo = (e, t) => {
1745
- let n = Math.max(0, (lo.get(e) ?? 0) + t);
1746
- n === 0 ? lo.delete(e) : lo.set(e, n);
1747
- let r = io.get(e);
1748
- r === void 0 && (r = D.tagged(eo, "dialect", e), io.set(e, r)), r.unsafeUpdate(n, no);
1749
- }, fo = (e) => lo.get(e) ?? 0, po = (e) => {
1750
- let t = oo(String(e.dialect), e.op);
1751
- t.count.unsafeUpdate(1, no), t.duration.unsafeUpdate(e.durationMs / 1e3, no), e.status === "error" && t.errors.unsafeUpdate(1, no);
1752
- }, mo = async (e, t, n) => {
1758
+ return oo.set(n, a), a;
1759
+ }, uo = () => {
1760
+ oo.clear(), so.clear(), co.clear();
1761
+ }, fo = () => oo.size + so.size + co.size, po = /* @__PURE__ */ new Map(), mo = (e, t) => {
1762
+ let n = Math.max(0, (po.get(e) ?? 0) + t);
1763
+ n === 0 ? po.delete(e) : po.set(e, n);
1764
+ let r = so.get(e);
1765
+ r === void 0 && (r = D.tagged(ro, "dialect", e), so.set(e, r)), r.unsafeUpdate(n, ao);
1766
+ }, ho = (e) => po.get(e) ?? 0, go = (e) => {
1767
+ let t = lo(String(e.dialect), e.op);
1768
+ t.count.unsafeUpdate(1, ao), t.duration.unsafeUpdate(e.durationMs / 1e3, ao), e.status === "error" && t.errors.unsafeUpdate(1, ao);
1769
+ }, _o = async (e, t, n) => {
1753
1770
  let r = performance.now(), i = String(e);
1754
- uo(i, 1);
1771
+ mo(i, 1);
1755
1772
  let a = "ok";
1756
1773
  try {
1757
1774
  return await n();
1758
1775
  } catch (e) {
1759
1776
  throw a = "error", e;
1760
1777
  } finally {
1761
- uo(i, -1), po({
1778
+ mo(i, -1), go({
1762
1779
  dialect: e,
1763
1780
  op: t,
1764
1781
  durationMs: performance.now() - r,
1765
1782
  status: a
1766
1783
  });
1767
1784
  }
1768
- }, ho = 3e5, go = (e) => {
1785
+ }, vo = 3e5, yo = (e) => {
1769
1786
  if (e == null || e === "") return;
1770
1787
  let t = Number(e);
1771
1788
  return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
1772
- }, _o = (e, t = process.env) => go(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? go(e) ?? 3e5, vo = (e, t = {}) => {
1773
- let n = _o(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
1789
+ }, bo = (e, t = process.env) => yo(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? yo(e) ?? 3e5, xo = (e, t = {}) => {
1790
+ let n = bo(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
1774
1791
  return (t) => {
1775
- let a = `${t.dialect} ${t.reason}`, o = ao.get(a);
1776
- o === void 0 && (o = D.tagged(D.tagged(to, "dialect", String(t.dialect)), "reason", t.reason), ao.set(a, o)), o.unsafeUpdate(1, no);
1792
+ let a = `${t.dialect} ${t.reason}`, o = co.get(a);
1793
+ o === void 0 && (o = D.tagged(D.tagged(io, "dialect", String(t.dialect)), "reason", t.reason), co.set(a, o)), o.unsafeUpdate(1, ao);
1777
1794
  let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
1778
1795
  table: t.table,
1779
1796
  dialect: String(t.dialect),
@@ -1787,10 +1804,10 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1787
1804
  }
1788
1805
  i.set(s, r()), e.warn(t.reason === "execute-failed" ? "eager-load JSON-agg statement FAILED and was re-run on the multi-query walker — this query pays both paths on every call. Counted as voltro_db_eager_fallback_total{reason=\"execute-failed\"}." : "eager-load could not be compiled to a single JSON-agg roundtrip and is running on the multi-query walker — one round trip per relation level, on every call. Counted as voltro_db_eager_fallback_total{reason=\"not-compilable\"}.", u);
1789
1806
  };
1790
- }, yo = (e) => {
1807
+ }, So = (e) => {
1791
1808
  if (Ot.isSuccess(e)) return e.value;
1792
1809
  throw Tt.squash(e.cause);
1793
- }, bo = "10 millis", xo = 3, So = async (e) => {
1810
+ }, Co = "10 millis", wo = 3, To = async (e) => {
1794
1811
  let t = 0, n = E.suspend(() => {
1795
1812
  let n = ++t;
1796
1813
  return e.withTransaction(E.flatMap(E.serviceOption(Pt), (t) => {
@@ -1801,10 +1818,10 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1801
1818
  });
1802
1819
  return e.prepare === void 0 ? i : E.flatMap(e.prepare(r), () => i);
1803
1820
  })).pipe(E.catchAllDefect((t) => e.isRetryable(t) ? E.fail(t) : E.die(t)));
1804
- }), r = jt.exponential(bo).pipe(jt.compose(jt.recurs(xo)), jt.whileInput(e.isRetryable)), i = n.pipe(E.retry(r), E.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
1805
- return mo(e.dialect, "transaction", async () => yo(await e.runPromiseExit(e.wrapProgram === void 0 ? i : e.wrapProgram(i))));
1806
- }, Co = async (e) => {
1807
- let t = Ea(), n = t === void 0 ? (e) => e() : (e) => Ta(t, e), r = await So({
1821
+ }), r = jt.exponential(Co).pipe(jt.compose(jt.recurs(wo)), jt.whileInput(e.isRetryable)), i = n.pipe(E.retry(r), E.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
1822
+ return _o(e.dialect, "transaction", async () => So(await e.runPromiseExit(e.wrapProgram === void 0 ? i : e.wrapProgram(i))));
1823
+ }, Eo = async (e) => {
1824
+ let t = ka(), n = t === void 0 ? (e) => e() : (e) => Oa(t, e), r = await To({
1808
1825
  ...e,
1809
1826
  body: (r) => {
1810
1827
  let i = e.makeView(r, t);
@@ -1815,14 +1832,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1815
1832
  }
1816
1833
  });
1817
1834
  return r.view.commitEvents(), r.result;
1818
- }, wo = class extends k.TaggedError()("VersionConflict", {
1835
+ }, Do = class extends k.TaggedError()("VersionConflict", {
1819
1836
  table: k.String,
1820
1837
  id: k.String,
1821
1838
  expected: k.Number,
1822
1839
  actual: k.NullOr(k.Number)
1823
- }) {}, To = (e) => {
1840
+ }) {}, Oo = (e) => {
1824
1841
  for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
1825
- }, Eo = (e) => {
1842
+ }, ko = (e) => {
1826
1843
  let { versionColumn: t, patch: n } = e;
1827
1844
  if (t === void 0) return {
1828
1845
  nextVersion: void 0,
@@ -1835,28 +1852,28 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1835
1852
  expected: i,
1836
1853
  patch: a
1837
1854
  };
1838
- }, Do = (e) => {
1839
- if (e.expected !== void 0 && (e.current === null || e.current !== e.expected)) return new wo({
1855
+ }, Ao = (e) => {
1856
+ if (e.expected !== void 0 && (e.current === null || e.current !== e.expected)) return new Do({
1840
1857
  table: e.table,
1841
1858
  id: e.id,
1842
1859
  expected: e.expected,
1843
1860
  actual: e.current
1844
1861
  });
1845
- }, Oo = 1, ko = "voltro/expires", Ao = () => st({
1846
- id: ko,
1862
+ }, jo = 1, Mo = "voltro/expires", No = () => st({
1863
+ id: Mo,
1847
1864
  fields: { expiresAt: S().nullable() },
1848
1865
  behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
1849
- }), jo = "voltro/localFirst", Mo = () => st({
1850
- id: jo,
1866
+ }), Po = "voltro/localFirst", Fo = () => st({
1867
+ id: Po,
1851
1868
  fields: {}
1852
- }), No = (e) => e.appliedMixins.some((e) => e.id === jo), Po = (e) => {
1869
+ }), Io = (e) => e.appliedMixins.some((e) => e.id === Po), Lo = (e) => {
1853
1870
  let t = [];
1854
- for (let n of Object.values(e)) No(n) && t.push(n.tableName);
1871
+ for (let n of Object.values(e)) Io(n) && t.push(n.tableName);
1855
1872
  return t;
1856
- }, Fo = class extends Dt.TaggedError("TableStreamError") {}, Io = 1e3, Lo = (e, t, n, r) => {
1873
+ }, Ro = class extends Dt.TaggedError("TableStreamError") {}, zo = 1e3, Bo = (e, t, n, r) => {
1857
1874
  let i = O.match(r, {
1858
1875
  onNone: () => e.where,
1859
- onSome: (n) => e.where ? aa(e.where, Wi(t, n)) : Wi(t, n)
1876
+ onSome: (n) => e.where ? ca(e.where, qi(t, n)) : qi(t, n)
1860
1877
  });
1861
1878
  return {
1862
1879
  table: e.table,
@@ -1871,19 +1888,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1871
1888
  ...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
1872
1889
  ...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
1873
1890
  };
1874
- }, Ro = (e, t) => {
1875
- let n = t.pk ?? "id", r = t.chunkSize ?? Io;
1891
+ }, Vo = (e, t) => {
1892
+ let n = t.pk ?? "id", r = t.chunkSize ?? zo;
1876
1893
  return Mt.paginateChunkEffect(O.none(), (i) => {
1877
1894
  let a = E.tryPromise({
1878
- try: () => e.query(Lo(t, n, r, i)),
1879
- catch: (e) => new Fo({
1895
+ try: () => e.query(Bo(t, n, r, i)),
1896
+ catch: (e) => new Ro({
1880
1897
  table: t.table,
1881
1898
  cause: e
1882
1899
  })
1883
1900
  });
1884
1901
  return (t.retry ? a.pipe(E.retry(t.retry)) : a).pipe(E.map((e) => [Et.fromIterable(e), e.length === r && e.length > 0 ? O.some(O.some(e[e.length - 1][n])) : O.none()]));
1885
1902
  });
1886
- }, zo = (e) => {
1903
+ }, Ho = (e) => {
1887
1904
  let t = e.alpha ?? .5;
1888
1905
  if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
1889
1906
  return (n) => {
@@ -1910,14 +1927,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1910
1927
  }
1911
1928
  };
1912
1929
  };
1913
- }, Bo = async (e, t) => {
1930
+ }, Uo = async (e, t) => {
1914
1931
  let n = e.as ?? "embedding", r = t.row[e.from];
1915
1932
  if (typeof r != "string" || r.length === 0) return {};
1916
1933
  let i = await t.embed(r);
1917
1934
  return { [n]: i };
1918
- }, Vo = (e) => {
1935
+ }, Wo = (e) => {
1919
1936
  if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
1920
- let t = e.as ?? "embedding", n = (t) => Bo(e, t);
1937
+ let t = e.as ?? "embedding", n = (t) => Uo(e, t);
1921
1938
  return st({
1922
1939
  id: "voltro/vectorEmbedding",
1923
1940
  fields: { [t]: Te(e.dimensions) },
@@ -1935,19 +1952,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1935
1952
  beforeUpdate: n
1936
1953
  }
1937
1954
  });
1938
- }, Ho = 63, Uo = "br_pr", q = class extends Error {
1955
+ }, Go = 63, Ko = "br_pr", q = class extends Error {
1939
1956
  _tag = "BranchNameInvalid";
1940
1957
  constructor(e) {
1941
1958
  super(e), this.name = "BranchNameInvalid";
1942
1959
  }
1943
- }, Wo = (e, t) => {
1960
+ }, qo = (e, t) => {
1944
1961
  if (!Number.isInteger(t) || t < 0) throw new q(`prNumber must be a non-negative integer, got ${String(t)}`);
1945
- let n = gr(e);
1962
+ let n = yr(e);
1946
1963
  if (n.replace(/_/g, "") === "") throw new q(`app slug '${e}' has no usable identifier characters`);
1947
- let r = `${Uo}${t}_${n}`;
1948
- if (r.length > Ho) throw new q(`branch namespace '${r}' exceeds the ${Ho}-byte identifier limit — use a shorter app slug`);
1964
+ let r = `${Ko}${t}_${n}`;
1965
+ if (r.length > Go) throw new q(`branch namespace '${r}' exceeds the ${Go}-byte identifier limit — use a shorter app slug`);
1949
1966
  return r;
1950
- }, Go = (e) => e.startsWith(Uo), Ko = {
1967
+ }, Jo = (e) => e.startsWith(Ko), Yo = {
1951
1968
  requested: {
1952
1969
  provision: "provisioning",
1953
1970
  destroy: "destroying"
@@ -1966,18 +1983,18 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
1966
1983
  fail: "failed"
1967
1984
  },
1968
1985
  destroyed: {}
1969
- }, qo = class extends Error {
1986
+ }, Xo = class extends Error {
1970
1987
  from;
1971
1988
  event;
1972
1989
  _tag = "BranchTransitionInvalid";
1973
1990
  constructor(e, t) {
1974
1991
  super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
1975
1992
  }
1976
- }, Jo = (e, t) => {
1977
- let n = Ko[e][t];
1978
- if (n === void 0) throw new qo(e, t);
1993
+ }, Zo = (e, t) => {
1994
+ let n = Yo[e][t];
1995
+ if (n === void 0) throw new Xo(e, t);
1979
1996
  return n;
1980
- }, Yo = (e, t, n, r, i = [], a = []) => {
1997
+ }, Qo = (e, t, n, r, i = [], a = []) => {
1981
1998
  if (n === "copy" && (r === void 0 || r === "")) throw new q("seed 'copy' requires a parentNamespace to snapshot from");
1982
1999
  let o = [{
1983
2000
  kind: "create-namespace",
@@ -2007,13 +2024,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
2007
2024
  kind: "seed",
2008
2025
  detail: `run boot seeds into ${e}`
2009
2026
  }), o;
2010
- }, Xo = (e) => {
2011
- if (!Go(e)) throw new q(`refusing to plan teardown of '${e}' — not a branch namespace`);
2027
+ }, $o = (e) => {
2028
+ if (!Jo(e)) throw new q(`refusing to plan teardown of '${e}' — not a branch namespace`);
2012
2029
  return [{
2013
2030
  kind: "drop-namespace",
2014
2031
  detail: e
2015
2032
  }];
2016
- }, Zo = (e) => {
2033
+ }, es = (e) => {
2017
2034
  if (e === void 0 || e === "") return !1;
2018
2035
  try {
2019
2036
  let t = new URL(e).hostname.toLowerCase();
@@ -2021,27 +2038,27 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
2021
2038
  } catch {
2022
2039
  return /\bneon\.(tech|build)\b/i.test(e);
2023
2040
  }
2024
- }, Qo = (e) => e.prefer === void 0 ? e.seed === "copy" && Zo(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, $o = (e, t = {}) => [{
2041
+ }, ts = (e) => e.prefer === void 0 ? e.seed === "copy" && es(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, ns = (e, t = {}) => [{
2025
2042
  kind: "neon-branch-create",
2026
2043
  detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
2027
- }], es = (e) => {
2028
- if (!Go(e)) throw new q(`refusing to plan teardown of '${e}' — not a branch namespace`);
2044
+ }], rs = (e) => {
2045
+ if (!Jo(e)) throw new q(`refusing to plan teardown of '${e}' — not a branch namespace`);
2029
2046
  return [{
2030
2047
  kind: "neon-branch-delete",
2031
2048
  detail: e
2032
2049
  }];
2033
- }, ts = (e) => e.mechanism === "neon-cow" ? $o(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Yo(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), ns = (e, t) => e === "neon-cow" ? es(t) : Xo(t), rs = (e, t, n) => {
2050
+ }, is = (e) => e.mechanism === "neon-cow" ? ns(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Qo(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), as = (e, t) => e === "neon-cow" ? rs(t) : $o(t), os = (e, t, n) => {
2034
2051
  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);
2035
2052
  return {
2036
2053
  evict: i,
2037
2054
  rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
2038
2055
  };
2039
- }, is = async (e, t) => {
2040
- let n = Wo(e.appSlug, e.prNumber), r = Qo({
2056
+ }, ss = async (e, t) => {
2057
+ let n = qo(e.appSlug, e.prNumber), r = ts({
2041
2058
  seed: e.seed,
2042
2059
  ...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
2043
2060
  ...e.prefer === void 0 ? {} : { prefer: e.prefer }
2044
- }), i = ts({
2061
+ }), i = is({
2045
2062
  mechanism: r,
2046
2063
  branchId: n,
2047
2064
  tableNames: e.tableNames,
@@ -2070,15 +2087,15 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
2070
2087
  mechanism: r,
2071
2088
  steps: i
2072
2089
  };
2073
- }, as = async (e, t, n) => {
2074
- let r = ns(t, e);
2090
+ }, cs = async (e, t, n) => {
2091
+ let r = as(t, e);
2075
2092
  return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
2076
- }, os = (e, t, n) => rs(e, t, n), J = (e) => `"${e.replace(/"/g, "\"\"")}"`, ss = {
2093
+ }, ls = (e, t, n) => os(e, t, n), J = (e) => `"${e.replace(/"/g, "\"\"")}"`, us = {
2077
2094
  cascade: "CASCADE",
2078
2095
  restrict: "RESTRICT",
2079
2096
  setNull: "SET NULL",
2080
2097
  noAction: "NO ACTION"
2081
- }, Y = (e) => `'${e.replace(/'/g, "''")}'`, cs = (e, t) => {
2098
+ }, Y = (e) => `'${e.replace(/'/g, "''")}'`, ds = (e, t) => {
2082
2099
  let n = t.columns.map(Y).join(", ");
2083
2100
  return `DO $voltro_branch$
2084
2101
  DECLARE derived name;
@@ -2105,10 +2122,10 @@ BEGIN
2105
2122
  END IF;
2106
2123
  END
2107
2124
  $voltro_branch$`;
2108
- }, ls = (e, t) => {
2109
- let n = t.onDelete === void 0 ? "" : ` ON DELETE ${ss[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${ss[t.onUpdate]}`;
2125
+ }, fs = (e, t) => {
2126
+ let n = t.onDelete === void 0 ? "" : ` ON DELETE ${us[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${us[t.onUpdate]}`;
2110
2127
  return `ALTER TABLE ${J(e)}.${J(t.table)} ADD FOREIGN KEY (${J(t.column)}) REFERENCES ${J(e)}.${J(t.targetTable)} (${J(t.targetColumn)})${n}${r}`;
2111
- }, us = (e) => {
2128
+ }, ps = (e) => {
2112
2129
  let t = () => {
2113
2130
  throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
2114
2131
  };
@@ -2116,24 +2133,24 @@ $voltro_branch$`;
2116
2133
  createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${J(t)}`),
2117
2134
  createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${J(t)}.${J(n)} (LIKE ${J(n)} INCLUDING ALL)`),
2118
2135
  copyTable: (t, n, r) => e.run(`INSERT INTO ${J(n)}.${J(r)} SELECT * FROM ${J(t)}.${J(r)}`),
2119
- addForeignKey: (t, n) => e.run(ls(t, n)),
2120
- restoreIndexName: (t, n) => e.run(cs(t, n)),
2136
+ addForeignKey: (t, n) => e.run(fs(t, n)),
2137
+ restoreIndexName: (t, n) => e.run(ds(t, n)),
2121
2138
  dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${J(t)} CASCADE`),
2122
2139
  neonBranchCreate: t,
2123
2140
  neonBranchDelete: t
2124
2141
  };
2125
- }, ds = class extends Error {
2142
+ }, ms = class extends Error {
2126
2143
  _tag = "TenantResidencyUnresolved";
2127
2144
  constructor(e) {
2128
2145
  super(e), this.name = "TenantResidencyUnresolved";
2129
2146
  }
2130
- }, fs = class extends Error {
2147
+ }, hs = class extends Error {
2131
2148
  region;
2132
2149
  _tag = "TenantRegionUnavailable";
2133
2150
  constructor(e, t) {
2134
2151
  super(t), this.region = e, this.name = "TenantRegionUnavailable";
2135
2152
  }
2136
- }, ps, ms = (e) => {
2153
+ }, gs, _s = (e) => {
2137
2154
  if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
2138
2155
  if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
2139
2156
  let t = /* @__PURE__ */ new Map();
@@ -2142,32 +2159,32 @@ $voltro_branch$`;
2142
2159
  if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
2143
2160
  t.set(n.tenantId, n.region);
2144
2161
  }
2145
- return ps = e, e;
2146
- }, hs = () => ps, gs = () => {
2147
- ps = void 0;
2148
- }, _s = (e, t) => {
2149
- if (e == null || e === "") throw new ds("residency is on but the request has no resolvable tenant — refusing to bind a store");
2162
+ return gs = e, e;
2163
+ }, vs = () => gs, ys = () => {
2164
+ gs = void 0;
2165
+ }, bs = (e, t) => {
2166
+ if (e == null || e === "") throw new ms("residency is on but the request has no resolvable tenant — refusing to bind a store");
2150
2167
  let n = t.homes.find((t) => t.tenantId === e);
2151
- if (n === void 0) throw new ds(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
2168
+ if (n === void 0) throw new ms(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
2152
2169
  return n;
2153
- }, vs = (e, t) => t.servableRegions.includes(e), ys = (e, t) => {
2154
- let n = _s(e.tenantId, t), r = _r(n.tenantId);
2170
+ }, xs = (e, t) => t.servableRegions.includes(e), Ss = (e, t) => {
2171
+ let n = bs(e.tenantId, t), r = br(n.tenantId);
2155
2172
  return {
2156
2173
  region: n.region,
2157
2174
  namespace: r,
2158
2175
  ...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
2159
2176
  };
2160
- }, bs = (e, t, n) => {
2161
- let r = ys(e, t);
2162
- if (!vs(r.region, t)) throw new fs(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
2177
+ }, Cs = (e, t, n) => {
2178
+ let r = Ss(e, t);
2179
+ if (!xs(r.region, t)) throw new hs(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
2163
2180
  let i = n.get(r.region);
2164
- if (i === void 0) throw new fs(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
2181
+ if (i === void 0) throw new hs(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
2165
2182
  return {
2166
2183
  store: i,
2167
2184
  placement: r
2168
2185
  };
2169
- }, xs = async (e, t, n, r) => {
2170
- let { store: i, placement: a } = bs(e, t, n);
2186
+ }, ws = async (e, t, n, r) => {
2187
+ let { store: i, placement: a } = Cs(e, t, n);
2171
2188
  return await r(i, a), a;
2172
2189
  }, X = (e) => {
2173
2190
  if (typeof e == "string") return e;
@@ -2176,21 +2193,21 @@ $voltro_branch$`;
2176
2193
  return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
2177
2194
  }
2178
2195
  return `(${e.expr})`;
2179
- }, Z = (e) => e.map(X), Ss = (e, t) => {
2196
+ }, Z = (e) => e.map(X), Ts = (e, t) => {
2180
2197
  if (e.length !== t.length) return !1;
2181
2198
  for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
2182
2199
  return !0;
2183
- }, Cs = (e, t) => {
2200
+ }, Es = (e, t) => {
2184
2201
  if (e.length >= t.length) return !1;
2185
2202
  for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
2186
2203
  return !0;
2187
- }, ws = (e) => {
2204
+ }, Ds = (e) => {
2188
2205
  let t = [], n = e.appliedIndexes, r = e.tableName;
2189
2206
  for (let e = 0; e < n.length; e++) {
2190
2207
  let i = n[e];
2191
2208
  for (let a = e + 1; a < n.length; a++) {
2192
2209
  let e = n[a];
2193
- if (Ss(i.fields, e.fields)) {
2210
+ if (Ts(i.fields, e.fields)) {
2194
2211
  let [n, a] = i.name < e.name ? [i, e] : [e, i];
2195
2212
  t.push({
2196
2213
  kind: "duplicate-fields",
@@ -2201,13 +2218,13 @@ $voltro_branch$`;
2201
2218
  });
2202
2219
  continue;
2203
2220
  }
2204
- Cs(i.fields, e.fields) ? t.push({
2221
+ Es(i.fields, e.fields) ? t.push({
2205
2222
  kind: "redundant-prefix",
2206
2223
  table: r,
2207
2224
  redundant: i,
2208
2225
  coveredBy: e,
2209
2226
  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).`
2210
- }) : Cs(e.fields, i.fields) && t.push({
2227
+ }) : Es(e.fields, i.fields) && t.push({
2211
2228
  kind: "redundant-prefix",
2212
2229
  table: r,
2213
2230
  redundant: e,
@@ -2217,23 +2234,23 @@ $voltro_branch$`;
2217
2234
  }
2218
2235
  }
2219
2236
  return t;
2220
- }, Ts = (e) => {
2237
+ }, Os = (e) => {
2221
2238
  let t = [];
2222
- for (let n of e) t.push(...ws(n));
2239
+ for (let n of e) t.push(...Ds(n));
2223
2240
  return t;
2224
- }, Es = "\x1B[", Ds = `${Es}38;2;245;158;11m`, Os = `${Es}38;2;16;185;129m`, ks = (e, t) => `${e}${t}${A.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : ks(t, n) : n, As = (e, t = {}) => {
2225
- let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, A.dim, e.padEnd(11)), a = (e) => Q(n, (e) => A.bold(A.brand(e)), e), o = (e) => Q(n, A.brightRed24, e), s = (e) => Q(n, Os, e), c = (e) => Q(n, Ds, e), l = (e) => Q(n, A.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, A.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
2241
+ }, ks = "\x1B[", As = `${ks}38;2;245;158;11m`, js = `${ks}38;2;16;185;129m`, Ms = (e, t) => `${e}${t}${A.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : Ms(t, n) : n, Ns = (e, t = {}) => {
2242
+ let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, A.dim, e.padEnd(11)), a = (e) => Q(n, (e) => A.bold(A.brand(e)), e), o = (e) => Q(n, A.brightRed24, e), s = (e) => Q(n, js, e), c = (e) => Q(n, As, e), l = (e) => Q(n, A.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, A.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
2226
2243
  let n = e.slice(0, t), r = e.slice(t), i = [];
2227
2244
  return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
2228
2245
  }, m = [];
2229
2246
  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, A.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
2230
- }, js = (e, { apply: t, undo: n }) => ({
2247
+ }, Ps = (e, { apply: t, undo: n }) => ({
2231
2248
  name: e,
2232
2249
  apply: t,
2233
2250
  undo: n
2234
- }), Ms = (e) => {
2251
+ }), Fs = (e) => {
2235
2252
  if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
2236
- let t = e.steps({ step: js });
2253
+ let t = e.steps({ step: Ps });
2237
2254
  if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
2238
2255
  return {
2239
2256
  __migration: !0,
@@ -2241,7 +2258,7 @@ $voltro_branch$`;
2241
2258
  name: e.name,
2242
2259
  steps: t
2243
2260
  };
2244
- }, Ns = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Ps = T("_voltro_migrations", {
2261
+ }, Is = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Ls = T("_voltro_migrations", {
2245
2262
  id: b({ prefix: "mig" }),
2246
2263
  name: v(),
2247
2264
  hash: v(),
@@ -2253,7 +2270,7 @@ $voltro_branch$`;
2253
2270
  workflowRunId: v().nullable(),
2254
2271
  createdAt: S().default("now"),
2255
2272
  updatedAt: S().default("now").onUpdate("now")
2256
- }).index(["status"]), Fs = T("_voltro_seeds", {
2273
+ }).index(["status"]), Rs = T("_voltro_seeds", {
2257
2274
  id: b({ prefix: "seed" }),
2258
2275
  name: v(),
2259
2276
  lifecycle: v(),
@@ -2269,7 +2286,7 @@ $voltro_branch$`;
2269
2286
  workflowRunId: v().nullable(),
2270
2287
  createdAt: S().default("now"),
2271
2288
  updatedAt: S().default("now").onUpdate("now")
2272
- }).index(["lifecycle"]).index(["nextRunAt"]), Is = T("_voltro_migration_plans", {
2289
+ }).index(["lifecycle"]).index(["nextRunAt"]), zs = T("_voltro_migration_plans", {
2273
2290
  id: b({ prefix: "plan" }),
2274
2291
  fingerprint: v(),
2275
2292
  liveFingerprint: v().nullable(),
@@ -2285,21 +2302,21 @@ $voltro_branch$`;
2285
2302
  appliedAt: S().default("now"),
2286
2303
  createdAt: S().default("now"),
2287
2304
  updatedAt: S().default("now").onUpdate("now")
2288
- }).index(["fingerprint"]).index(["environment"]), Ls = T("_voltro_idempotency", {
2305
+ }).index(["fingerprint"]).index(["environment"]), Bs = T("_voltro_idempotency", {
2289
2306
  id: b({ prefix: "idem" }),
2290
2307
  scope: v(),
2291
2308
  key: v(),
2292
2309
  status: v(),
2293
2310
  response: i().nullable(),
2294
2311
  createdAt: S().default("now")
2295
- }).unique(["scope", "key"]).index(["createdAt"]), Rs = T("_voltro_kv", {
2312
+ }).unique(["scope", "key"]).index(["createdAt"]), Vs = T("_voltro_kv", {
2296
2313
  id: b({ prefix: "kv" }),
2297
2314
  key: v().unique(),
2298
2315
  value: v().nullable(),
2299
2316
  expiresAt: S().nullable(),
2300
2317
  createdAt: S().default("now"),
2301
2318
  updatedAt: S().default("now").onUpdate("now")
2302
- }).index(["expiresAt"]), zs = T("_voltro_api_keys", {
2319
+ }).index(["expiresAt"]), Hs = T("_voltro_api_keys", {
2303
2320
  id: b({ prefix: "apikey" }),
2304
2321
  tenantId: v().nullable(),
2305
2322
  name: v(),
@@ -2314,11 +2331,11 @@ $voltro_branch$`;
2314
2331
  onBehalfOf: v().nullable(),
2315
2332
  metadata: i().nullable(),
2316
2333
  createdAt: S().default("now")
2317
- }).index("byApiKeyTenant", ["tenantId"]), Bs = [
2318
- Ps,
2319
- Fs,
2320
- Is
2321
- ], $ = "id", Vs = (e, t) => {
2334
+ }).index("byApiKeyTenant", ["tenantId"]), Us = [
2335
+ Ls,
2336
+ Rs,
2337
+ zs
2338
+ ], $ = "id", Ws = (e, t) => {
2322
2339
  let n = p(e);
2323
2340
  if (n === void 0) return t;
2324
2341
  let r = n.fields[$]?.idScheme;
@@ -2333,7 +2350,7 @@ $voltro_branch$`;
2333
2350
  ...t,
2334
2351
  [$]: i
2335
2352
  };
2336
- }, Hs = (e, t) => t.map((t) => Vs(e, t)), Us = {
2353
+ }, Gs = (e, t) => t.map((t) => Ws(e, t)), Ks = {
2337
2354
  postgres: { maxBindParameters: 65535 },
2338
2355
  mysql: { maxBindParameters: 65535 },
2339
2356
  mariadb: { maxBindParameters: 65535 },
@@ -2343,49 +2360,49 @@ $voltro_branch$`;
2343
2360
  },
2344
2361
  sqlite: { maxBindParameters: 32766 },
2345
2362
  turso: { maxBindParameters: 32766 }
2346
- }, Ws = (e) => Us[e], Gs = (e) => {
2363
+ }, qs = (e) => Ks[e], Js = (e) => {
2347
2364
  let t = /* @__PURE__ */ new Set();
2348
2365
  for (let n of e) for (let e of Object.keys(n)) t.add(e);
2349
2366
  return t.size;
2350
- }, Ks = (e, t) => {
2367
+ }, Ys = (e, t) => {
2351
2368
  if (t === void 0 || e.length === 0) return [e];
2352
- let n = Math.max(1, Gs(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
2369
+ let n = Math.max(1, Js(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
2353
2370
  if (e.length <= a) return [e];
2354
2371
  let o = [];
2355
2372
  for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
2356
2373
  return o;
2357
- }, qs = (e, t) => {
2374
+ }, Xs = (e, t) => {
2358
2375
  let n = [], r = t;
2359
2376
  for (let [t, i] of Object.entries(e.fields)) {
2360
2377
  let e = i;
2361
2378
  e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
2362
2379
  }
2363
2380
  return n;
2364
- }, Js = (e, t) => {
2381
+ }, Zs = (e, t) => {
2365
2382
  let n = t;
2366
2383
  return e.filter((e) => n[e] === void 0 || n[e] === null);
2367
- }, Ys = (e, t, n) => e.insert(t.tableName, n), Xs = (e, t, n, r) => e.upsert(t.tableName, n, {
2384
+ }, Qs = (e, t, n) => e.insert(t.tableName, n), $s = (e, t, n, r) => e.upsert(t.tableName, n, {
2368
2385
  conflictColumns: r.conflictColumns,
2369
2386
  ...r.update === void 0 ? {} : { update: r.update }
2370
- }), Zs = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Qs = 512, $s = (e) => {
2387
+ }), ec = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), tc = 512, nc = (e) => {
2371
2388
  e.setMaxListeners(512);
2372
- }, ec = (e, t, n) => ({
2389
+ }, rc = (e, t, n) => ({
2373
2390
  _tag: "PrimaryKeyConflictError",
2374
2391
  table: e,
2375
2392
  key: t,
2376
2393
  cause: n
2377
- }), tc = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", nc = {
2394
+ }), ic = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", ac = {
2378
2395
  postgres: 5432,
2379
2396
  mysql: 3306,
2380
2397
  mariadb: 3306,
2381
2398
  mssql: 1433
2382
- }, rc = /* @__PURE__ */ new Set([
2399
+ }, oc = /* @__PURE__ */ new Set([
2383
2400
  "localhost",
2384
2401
  "127.0.0.1",
2385
2402
  "::1",
2386
2403
  "[::1]",
2387
2404
  "0.0.0.0"
2388
- ]), ic = (e) => {
2405
+ ]), sc = (e) => {
2389
2406
  let t = e.host, n = e.port, r = e.database;
2390
2407
  if (e.url !== void 0 && e.url !== "") try {
2391
2408
  let i = new URL(e.url);
@@ -2394,29 +2411,29 @@ $voltro_branch$`;
2394
2411
  return;
2395
2412
  }
2396
2413
  if (t === void 0 || t === "" || r === void 0 || r === "") return;
2397
- let i = n ?? nc[(e.dialect ?? "").toLowerCase()];
2414
+ let i = n ?? ac[(e.dialect ?? "").toLowerCase()];
2398
2415
  if (i === void 0 || !Number.isFinite(i)) return;
2399
2416
  let a = t.toLowerCase();
2400
2417
  return {
2401
- host: rc.has(a) ? "localhost" : a,
2418
+ host: oc.has(a) ? "localhost" : a,
2402
2419
  port: i,
2403
2420
  database: r.toLowerCase()
2404
2421
  };
2405
- }, ac = (e) => {
2406
- let t = ic(e);
2422
+ }, cc = (e) => {
2423
+ let t = sc(e);
2407
2424
  if (t !== void 0) return It("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
2408
- }, oc = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", sc = {
2425
+ }, lc = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", uc = {
2409
2426
  app: 3,
2410
2427
  plugin: 2,
2411
2428
  framework: 1
2412
- }, cc = /* @__PURE__ */ new Map(), lc = [], uc = () => [...lc], dc = (e) => {
2429
+ }, dc = /* @__PURE__ */ new Map(), fc = [], pc = () => [...fc], mc = (e) => {
2413
2430
  if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
2414
2431
  if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
2415
- let t = e.source ?? "app", n = cc.get(e.table);
2432
+ let t = e.source ?? "app", n = dc.get(e.table);
2416
2433
  if (n !== void 0) {
2417
2434
  let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
2418
- if (sc[t] < sc[r]) {
2419
- i && lc.push({
2435
+ if (uc[t] < uc[r]) {
2436
+ i && fc.push({
2420
2437
  table: e.table,
2421
2438
  kept: {
2422
2439
  source: r,
@@ -2429,7 +2446,7 @@ $voltro_branch$`;
2429
2446
  });
2430
2447
  return;
2431
2448
  }
2432
- i && r !== t && lc.push({
2449
+ i && r !== t && fc.push({
2433
2450
  table: e.table,
2434
2451
  kept: {
2435
2452
  source: t,
@@ -2441,35 +2458,35 @@ $voltro_branch$`;
2441
2458
  }
2442
2459
  });
2443
2460
  }
2444
- cc.set(e.table, {
2461
+ dc.set(e.table, {
2445
2462
  ...e,
2446
2463
  source: t
2447
2464
  });
2448
- }, fc = () => [...cc.values()], pc = () => {
2449
- cc.clear(), lc.length = 0;
2450
- }, mc = async (e, t, n, r = 2e4) => {
2465
+ }, hc = () => [...dc.values()], gc = () => {
2466
+ dc.clear(), fc.length = 0;
2467
+ }, _c = async (e, t, n, r = 2e4) => {
2451
2468
  let i = new Date(t - e.ttlMs), a = 0;
2452
2469
  for (;;) {
2453
2470
  let t = await n(e.table, e.timeColumn, i, r, e.where);
2454
2471
  if (a += t, t < r) break;
2455
2472
  }
2456
2473
  return a;
2457
- }, hc = (e, t) => {
2474
+ }, vc = (e, t) => {
2458
2475
  let n = Number(e ?? String(t));
2459
2476
  return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
2460
- }, gc = "_voltro_cdc_offsets", _c = T(gc, {
2477
+ }, yc = "_voltro_cdc_offsets", bc = T(yc, {
2461
2478
  id: b({ prefix: "cdcoff" }),
2462
2479
  replicaId: v(),
2463
2480
  streamName: v(),
2464
2481
  binlogFile: v(),
2465
2482
  binlogPosition: v(),
2466
2483
  updatedAt: S()
2467
- }).index(["replicaId"]), vc = T(gc, {
2484
+ }).index(["replicaId"]), xc = T(yc, {
2468
2485
  id: b({ prefix: "cdcoff" }),
2469
2486
  replicaId: v(),
2470
2487
  streamName: v(),
2471
2488
  ctVersion: v(),
2472
2489
  updatedAt: S()
2473
- }).index(["replicaId"]), yc = "postgres";
2490
+ }).index(["replicaId"]), Sc = "postgres";
2474
2491
  //#endregion
2475
- export { e as AUTO_FILLED_COLUMNS, Us as BULK_INSERT_LIMITS, q as BranchNameInvalid, qo as BranchTransitionInvalid, gc as CDC_OFFSETS_TABLE, Qs as CHANGE_LISTENER_CEILING, gt as ColumnBuilder, Ee as DEFAULT_ACQUIRE_TIMEOUT_MS, ho as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, In as DEFAULT_SUBJECT_GRAPH_DEPTH, Ut as ENCRYPTED_PREFIX, yc as ENGINE, $n as EagerCardinalityError, Ge as FILE_MIGRATION_PATTERN, ut as FRAMEWORK_LIVE_TABLES, Wt as FieldDecryptionError, Oo as INITIAL_VERSION, ta as MATCHES_NO_ROWS, Le as MAX_IDENTIFIER_LENGTH, Ft as SqlClient, Fo as TableStreamError, pr as TenantNamespaceInvalid, fr as TenantNamespaceUnresolved, fs as TenantRegionUnavailable, ds as TenantResidencyUnresolved, ko as VOLTRO_EXPIRES_MIXIN_ID, jo as VOLTRO_LOCAL_FIRST_MIXIN_ID, wo as VersionConflict, Be as WARN_IDENTIFIER_LENGTH, zs as _voltroApiKeysTable, _c as _voltroCdcOffsetsTable, Ls as _voltroIdempotencyTable, Rs as _voltroKvTable, Is as _voltroMigrationPlansTable, Ps as _voltroMigrationsTable, vc as _voltroMssqlCdcOffsetsTable, Fs as _voltroSeedsTable, Vi as actorsTable, os as admitBranch, mt as allEnumRenames, Nn as allRegisteredRelations, h as allRegisteredTables, aa as and, _e as array, Qi as arrayContains, ea as arrayHas, $i as arrayOverlaps, tr as attachEagerLoads, Da as attributionFields, ja as attributionKey, Ts as auditAllTableIndexes, ws as auditTableIndexes, pt as avg, yt as avgOver, Ba as beginLocalWrite, u as bigint, bs as bindResidentStore, c as boolean, Wo as branchNamespaceName, Ws as bulkInsertLimitsFor, le as bytes, Sa as changeDelete, ba as changeInsert, Ca as changeSoftDelete, xa as changeUpdate, Ks as chunkRowsForInsert, Pa as claimPendingAttribution, on as classifyConstraintViolation, bt as clearEnumRenames, Ua as clearPendingAttribution, Fn as clearRelationsRegistry, gs as clearResidencyConfig, pc as clearRetentions, ve as clearTableRegistry, qa as clearWriteRecorders, xr as coercePredicateValue, Sr as coercePredicateValues, _a as collectSubqueries, Me as column, un as columnSchema, Gs as columnsPerRow, Ir as compileEagerJson, F as compilePredicate, Cr as compileRawFragment, Fr as compileSelect, Bo as computeEmbedding, ac as connectionIdentity, Xi as contains, _t as count, me as countDistinct, Ye as crdtManagedColumns, n as crdtText, Ea as currentWriteAttribution, a as databaseHandle, qe as date, ae as dbEnum, co as dbMetricTagCacheSizeForTests, fo as dbOperationsInFlight, se as decimal, Ne as declareEnumRename, Yt as decodeFieldValue, Xn as decodeRowsFromSchema, en as decryptFieldsOnRead, Ms as defineMigration, st as defineMixin, ct as defineSeed, ht as denseRank, Un as deriveSubjectGraph, rt as deriveTypeIdPrefix, ln as describeDriverError, Ht as deserializeArraysOnRead, it as drainIdentifierWarnings, de as dropped, qt as encodeFieldValue, Qn as encodeRowForSchema, $t as encryptFieldsForWrite, Qt as encryptedColumnsOf, Va as endLocalWrite, rs as enforceBranchLimits, Se as ensureTableRegistered, Hi as eq, wr as escapeLike, ga as evaluatePredicate, ge as except, fa as exists, Ao as expires, ya as externalChangeEvent, nn as extractDbCause, Pe as fireSchemaChangeSeeds, Xe as fireTenantCreateSeeds, As as formatIndexAuditIssue, Wn as formatSubjectGraph, Bs as frameworkTables, lt as generateId, Ze as generateSnowflake, f as geography, te as geometry, vt as getEnumRenames, Mn as getRelation, jn as getRelations, hs as getResidencyConfig, p as getTable, Wi as gt, Gi as gte, dr as hasEagerLoads, zo as hybridSearch, b as id, Ji as inSet, ua as inSubquery, N as inferForeignKey, Ys as insertRow, x as integer, l as intersect, St as interval, Go as isBranchNamespace, vn as isEmptyRelationsSpec, Kt as isEncrypted, Gt as isFieldDecryptionError, Ae as isFileMigration, sn as isForeignKeyViolation, et as isFrameworkOwnedLiveTable, No as isLocalFirst, Ns as isMigrationDefinition, we as isMysqlFamily, Zo as isNeonConnection, ra as isNotNull, na as isNull, tc as isPrimaryKeyConflictError, cn as isQueryTimeout, Xt as isRawEncoding, vs as isRegionServable, yn as isRelationsSpec, dt as isSeedDefinition, De as isSqliteFamily, ne as isTableReactive, Qe as isView, i as json, ca as jsonField, Re as jsonIndex, s as lag, ce as lead, uc as listRetentionConflicts, fc as listRetentions, Mo as localFirst, Po as localFirstTables, Ki as lt, qi as lte, vo as makeEagerFallbackReporter, us as makeNamespaceBranchExecutor, xn as many, Sn as manyToMany, xe as materializeFields, Je as max, nt as migration, t as min, Js as missingConflictColumns, qs as missingRequiredColumns, Ke as mixin, Ui as neq, Jo as nextBranchState, ic as normaliseTarget, sa as not, pa as notExists, Yi as notInSet, da as notInSubquery, g as numeric, mo as observeDbOp, bn as one, er as oneCardinalityMessage, oa as or, C as orderClausesOf, ie as paginateBy, oe as paginateById, Wa as pendingAttributionCount, ts as planBranch, Yo as planBranchProvision, Xo as planBranchTeardown, ns as planBranchTeardownFor, $o as planNeonBranchProvision, es as planNeonBranchTeardown, Eo as planVersionedUpdate, he as pluginRef, o as pluginRefSpecOf, ec as primaryKeyConflictError, is as provisionBranch, xs as provisionResidentTenant, vr as qualifyTable, ue as queryFor, Ue as queryForView, fe as quoteIdent, $s as raiseChangeListenerCeiling, d as rank, ye as raw, Ce as readableByColumns, m as real, po as recordDbOp, Ja as recordsTable, y as reference, Li as registerCoreTables, An as registerDiscoveredRelations, Na as registerPendingAttribution, kn as registerRelations, dc as registerRetention, at as registerTable, Ga as registerWriteRecorder, _n as relations, zi as requireActors, _ as requireTable, Bi as requireTenants, so as resetDbMetricTagCacheForTests, ft as resetSnowflake, ys as residentPlacement, Rt as resolveActorSnapshot, Qo as resolveBranchMechanism, _o as resolveEagerFallbackWarnIntervalMs, Ha as resolveEchoAttribution, ee as resolveFullTextIndex, Fe as resolveIdScheme, je as resolveMixinGraph, _s as resolveTenantHome, _r as resolveTenantNamespace, hc as retentionTtlMsFromEnv, re as rowNumber, dn as rowSchema, So as runRetryingTransaction, Co as runStoreTransaction, Ta as runWithWriteAttribution, Ya as runWriteRecorders, oc as sameDatabase, gr as sanitizeIdentifierFragment, Vt as serializeArraysForWrite, ot as serverOnlyColumns, ms as setResidencyConfig, Ie as setSchemaChangeSeedHook, ze as setTenantCreateSeedHook, yo as settleTransactionExit, Do as settleVersionedUpdate, ia as spatialPredicate, Vs as stampGeneratedId, Hs as stampGeneratedIds, Zi as startsWith, Ro as streamTable, pe as sum, xt as sumOver, mc as sweepRetention, T as table, as as teardownBranch, v as text, S as timestamp, Ct as timestampMs, wt as timestampMsOrNull, r as union, be as unionAll, Ka as unregisterWriteRecorder, Zs as updateManyRow, Xs as upsertRow, $e as validateColumnName, We as validateIndexName, Pn as validateRegisteredRelations, En as validateRelationConfig, He as validateTableName, ke as validateTypeIdPrefix, Te as vector, tt as vectorDistanceToOpclass, Vo as vectorEmbedding, To as versionColumnOf, Ve as view, Oe as viewSql, va as walkLeaves, Oa as withCapturedAttribution };
2492
+ export { e as AUTO_FILLED_COLUMNS, Ks as BULK_INSERT_LIMITS, q as BranchNameInvalid, Xo as BranchTransitionInvalid, yc as CDC_OFFSETS_TABLE, tc as CHANGE_LISTENER_CEILING, gt as ColumnBuilder, Ee as DEFAULT_ACQUIRE_TIMEOUT_MS, vo as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, zn as DEFAULT_SUBJECT_GRAPH_DEPTH, Ut as ENCRYPTED_PREFIX, Sc as ENGINE, nr as EagerCardinalityError, Ge as FILE_MIGRATION_PATTERN, ut as FRAMEWORK_LIVE_TABLES, Wt as FieldDecryptionError, jo as INITIAL_VERSION, ia as MATCHES_NO_ROWS, Le as MAX_IDENTIFIER_LENGTH, Ft as SqlClient, Ro as TableStreamError, gr as TenantNamespaceInvalid, hr as TenantNamespaceUnresolved, hs as TenantRegionUnavailable, ms as TenantResidencyUnresolved, Mo as VOLTRO_EXPIRES_MIXIN_ID, Po as VOLTRO_LOCAL_FIRST_MIXIN_ID, Do as VersionConflict, Be as WARN_IDENTIFIER_LENGTH, Hs as _voltroApiKeysTable, bc as _voltroCdcOffsetsTable, Bs as _voltroIdempotencyTable, Vs as _voltroKvTable, zs as _voltroMigrationPlansTable, Ls as _voltroMigrationsTable, xc as _voltroMssqlCdcOffsetsTable, Rs as _voltroSeedsTable, Wi as actorsTable, ls as admitBranch, mt as allEnumRenames, In as allRegisteredRelations, h as allRegisteredTables, ca as and, _e as array, ta as arrayContains, ra as arrayHas, na as arrayOverlaps, ir as attachEagerLoads, Aa as attributionFields, Pa as attributionKey, Os as auditAllTableIndexes, Ds as auditTableIndexes, pt as avg, yt as avgOver, Ua as beginLocalWrite, u as bigint, Cs as bindResidentStore, c as boolean, qo as branchNamespaceName, qs as bulkInsertLimitsFor, le as bytes, Ta as changeDelete, Ca as changeInsert, Ea as changeSoftDelete, wa as changeUpdate, Ys as chunkRowsForInsert, La as claimPendingAttribution, ln as classifyConstraintViolation, bt as clearEnumRenames, Ka as clearPendingAttribution, Rn as clearRelationsRegistry, ys as clearResidencyConfig, gc as clearRetentions, ve as clearTableRegistry, Xa as clearWriteRecorders, wr as coercePredicateValue, Tr as coercePredicateValues, ba as collectSubqueries, Me as column, pn as columnSchema, Js as columnsPerRow, zr as compileEagerJson, F as compilePredicate, Er as compileRawFragment, Rr as compileSelect, Uo as computeEmbedding, cc as connectionIdentity, $i as contains, _t as count, me as countDistinct, Ye as crdtManagedColumns, n as crdtText, ka as currentWriteAttribution, a as databaseHandle, qe as date, ae as dbEnum, fo as dbMetricTagCacheSizeForTests, ho as dbOperationsInFlight, se as decimal, Ne as declareEnumRename, Yt as decodeFieldValue, $n as decodeRowsFromSchema, en as decryptFieldsOnRead, Fs as defineMigration, st as defineMixin, ct as defineSeed, ht as denseRank, Kn as deriveSubjectGraph, rt as deriveTypeIdPrefix, fn as describeDriverError, Ht as deserializeArraysOnRead, it as drainIdentifierWarnings, de as dropped, qt as encodeFieldValue, tr as encodeRowForSchema, $t as encryptFieldsForWrite, Qt as encryptedColumnsOf, Wa as endLocalWrite, os as enforceBranchLimits, Se as ensureTableRegistered, Gi as eq, Dr as escapeLike, ya as evaluatePredicate, ge as except, ha as exists, No as expires, Sa as externalChangeEvent, on as extractDbCause, Pe as fireSchemaChangeSeeds, Xe as fireTenantCreateSeeds, Ns as formatIndexAuditIssue, qn as formatSubjectGraph, Us as frameworkTables, lt as generateId, Ze as generateSnowflake, f as geography, te as geometry, vt as getEnumRenames, Fn as getRelation, Pn as getRelations, vs as getResidencyConfig, p as getTable, qi as gt, Ji as gte, mr as hasEagerLoads, Ho as hybridSearch, b as id, Zi as inSet, pa as inSubquery, N as inferForeignKey, Qs as insertRow, x as integer, l as intersect, St as interval, Jo as isBranchNamespace, xn as isEmptyRelationsSpec, Kt as isEncrypted, Gt as isFieldDecryptionError, Ae as isFileMigration, un as isForeignKeyViolation, et as isFrameworkOwnedLiveTable, Io as isLocalFirst, Is as isMigrationDefinition, we as isMysqlFamily, es as isNeonConnection, oa as isNotNull, aa as isNull, ic as isPrimaryKeyConflictError, dn as isQueryTimeout, Xt as isRawEncoding, xs as isRegionServable, Sn as isRelationsSpec, dt as isSeedDefinition, De as isSqliteFamily, ne as isTableReactive, Qe as isView, i as json, da as jsonField, Re as jsonIndex, s as lag, ce as lead, pc as listRetentionConflicts, hc as listRetentions, Fo as localFirst, Lo as localFirstTables, Yi as lt, Xi as lte, xo as makeEagerFallbackReporter, ps as makeNamespaceBranchExecutor, wn as many, Tn as manyToMany, xe as materializeFields, Je as max, nt as migration, t as min, Zs as missingConflictColumns, Xs as missingRequiredColumns, Ke as mixin, Ki as neq, Zo as nextBranchState, sc as normaliseTarget, ua as not, ga as notExists, Qi as notInSet, ma as notInSubquery, g as numeric, _o as observeDbOp, Cn as one, rr as oneCardinalityMessage, la as or, C as orderClausesOf, ie as paginateBy, oe as paginateById, qa as pendingAttributionCount, is as planBranch, Qo as planBranchProvision, $o as planBranchTeardown, as as planBranchTeardownFor, ns as planNeonBranchProvision, rs as planNeonBranchTeardown, ko as planVersionedUpdate, he as pluginRef, o as pluginRefSpecOf, rc as primaryKeyConflictError, ss as provisionBranch, ws as provisionResidentTenant, xr as qualifyTable, ue as queryFor, Ue as queryForView, fe as quoteIdent, nc as raiseChangeListenerCeiling, d as rank, ye as raw, Ce as readableByColumns, m as real, go as recordDbOp, Za as recordsTable, y as reference, Bi as registerCoreTables, Nn as registerDiscoveredRelations, Ia as registerPendingAttribution, Mn as registerRelations, mc as registerRetention, at as registerTable, Ja as registerWriteRecorder, bn as relations, Hi as requireActors, _ as requireTable, Ui as requireTenants, uo as resetDbMetricTagCacheForTests, ft as resetSnowflake, Ss as residentPlacement, Rt as resolveActorSnapshot, ts as resolveBranchMechanism, bo as resolveEagerFallbackWarnIntervalMs, Ga as resolveEchoAttribution, ee as resolveFullTextIndex, Fe as resolveIdScheme, je as resolveMixinGraph, bs as resolveTenantHome, br as resolveTenantNamespace, vc as retentionTtlMsFromEnv, re as rowNumber, mn as rowSchema, To as runRetryingTransaction, Eo as runStoreTransaction, Oa as runWithWriteAttribution, Qa as runWriteRecorders, lc as sameDatabase, yr as sanitizeIdentifierFragment, Vt as serializeArraysForWrite, ot as serverOnlyColumns, _s as setResidencyConfig, Ie as setSchemaChangeSeedHook, ze as setTenantCreateSeedHook, So as settleTransactionExit, Ao as settleVersionedUpdate, sa as spatialPredicate, Ws as stampGeneratedId, Gs as stampGeneratedIds, ea as startsWith, Vo as streamTable, pe as sum, xt as sumOver, _c as sweepRetention, T as table, cs as teardownBranch, v as text, S as timestamp, Ct as timestampMs, wt as timestampMsOrNull, r as union, be as unionAll, Ya as unregisterWriteRecorder, ec as updateManyRow, $s as upsertRow, $e as validateColumnName, We as validateIndexName, Ln as validateRegisteredRelations, kn as validateRelationConfig, He as validateTableName, ke as validateTypeIdPrefix, Te as vector, tt as vectorDistanceToOpclass, Wo as vectorEmbedding, Oo as versionColumnOf, Ve as view, Oe as viewSql, xa as walkLeaves, ja as withCapturedAttribution };