@voltro/database 0.83.0 → 0.83.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.
@@ -265,7 +265,7 @@ var se = () => new u({
265
265
  unique: !1,
266
266
  hasDefault: !1,
267
267
  dropped: !0
268
- }), ce = (e, t) => {
268
+ }), ce = (e) => Object.keys(e.fields).filter((t) => e.fields[t]?.dropped !== !0), le = (e, t) => {
269
269
  if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
270
270
  return new u({
271
271
  type: "vector",
@@ -275,13 +275,13 @@ var se = () => new u({
275
275
  vectorDim: e,
276
276
  vectorPrecision: t?.precision ?? "float32"
277
277
  });
278
- }, le = (e) => new u({
278
+ }, ue = (e) => new u({
279
279
  type: "array",
280
280
  nullable: !1,
281
281
  unique: !1,
282
282
  hasDefault: !1,
283
283
  arrayElement: e.__definition().type
284
- }), ue = () => d("interval"), de = (e, t = 4326) => new u({
284
+ }), de = () => d("interval"), fe = (e, t = 4326) => new u({
285
285
  type: "text",
286
286
  nullable: !1,
287
287
  unique: !1,
@@ -291,7 +291,7 @@ var se = () => new u({
291
291
  geomKind: e,
292
292
  srid: t
293
293
  }
294
- }), fe = (e, t = 4326) => new u({
294
+ }), pe = (e, t = 4326) => new u({
295
295
  type: "text",
296
296
  nullable: !1,
297
297
  unique: !1,
@@ -301,7 +301,7 @@ var se = () => new u({
301
301
  geomKind: e,
302
302
  srid: t
303
303
  }
304
- }), pe = (e) => new u({
304
+ }), me = (e) => new u({
305
305
  type: "raw",
306
306
  nullable: !1,
307
307
  unique: !1,
@@ -311,14 +311,14 @@ var se = () => new u({
311
311
  let t = {};
312
312
  for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
313
313
  return t;
314
- }, me = /* @__PURE__ */ new WeakMap(), he = (e) => typeof e == "object" && e ? me.get(e) : void 0, ge = (e, t = {}) => {
314
+ }, he = /* @__PURE__ */ new WeakMap(), ge = (e) => typeof e == "object" && e ? he.get(e) : void 0, _e = (e, t = {}) => {
315
315
  let n = p();
316
- return me.set(n, {
316
+ return he.set(n, {
317
317
  target: e,
318
318
  orphanPolicy: t.orphanPolicy ?? "keep",
319
319
  onSoftDelete: t.onSoftDelete ?? !1
320
320
  }), n;
321
- }, w = /* @__PURE__ */ new Map(), _e = (e, t) => {
321
+ }, w = /* @__PURE__ */ new Map(), ve = (e, t) => {
322
322
  if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
323
323
  let n = w.get(e) ?? [];
324
324
  for (let r of n) {
@@ -326,9 +326,9 @@ var se = () => new u({
326
326
  if (r.from === t.from && r.to !== t.to) throw Error(`declareEnumRename('${e}'): value '${t.from}' is already declared as renamed to '${r.to}', cannot also rename it to '${t.to}'.`);
327
327
  }
328
328
  n.push(t), w.set(e, n);
329
- }, ve = (e) => w.get(e) ?? [], ye = () => w, be = () => {
329
+ }, ye = (e) => w.get(e) ?? [], be = () => w, xe = () => {
330
330
  w.clear();
331
- }, xe = (t) => {
331
+ }, Se = (t) => {
332
332
  let r = t;
333
333
  for (let t = 0; t < 4 && n.isFiberFailure(r); t++) r = e.squash(r[n.FiberFailureCauseId]);
334
334
  return r;
@@ -339,63 +339,63 @@ var se = () => new u({
339
339
  let o = [];
340
340
  for (let e of a.slice(0, 8)) o.push(...T(e, r + 1));
341
341
  return o;
342
- }, Se = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, Ce = (e) => {
343
- let t = {}, n = [], r = xe(e);
342
+ }, Ce = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, we = (e) => {
343
+ let t = {}, n = [], r = Se(e);
344
344
  for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
345
345
  let e = r;
346
346
  t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
347
347
  let i = e.sqlMessage ?? e.detail;
348
348
  t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
349
349
  let a = typeof e.constructor == "function" ? e.constructor.name : void 0, o = typeof e._tag == "string" && e._tag || typeof e.name == "string" && e.name || (typeof a == "string" && a !== "Object" ? a : void 0), s = typeof e.message == "string" ? e.message : void 0;
350
- (o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = xe(e.cause);
350
+ (o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = Se(e.cause);
351
351
  }
352
352
  return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
353
- }, we = (e) => {
354
- let t = T(e).map(Ce);
353
+ }, Te = (e) => {
354
+ let t = T(e).map(we);
355
355
  if (t.length <= 1) return t[0] ?? {};
356
- let n = t.find(Se) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
356
+ let n = t.find(Ce) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
357
357
  if (r.length === 0) return n;
358
358
  let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
359
359
  return {
360
360
  ...n,
361
361
  dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
362
362
  };
363
- }, Te = (e, t) => {
364
- let n = De(e);
363
+ }, Ee = (e, t) => {
364
+ let n = Oe(e);
365
365
  if (n !== void 0) return n;
366
- let r = we(e), i = Ne(r, t);
366
+ let r = Te(e), i = Pe(r, t);
367
367
  if (i !== void 0) {
368
368
  let e = i.constraint ?? i.column;
369
369
  return e === void 0 ? i.kind : `${i.kind}: ${e}`;
370
370
  }
371
- let a = r.dbCode ?? r.dbSqlState ?? r.dbErrno ?? r.dbNumber, o = Ae(e);
372
- return a !== void 0 && Oe.test(String(a)) ? `${o} (${String(a)})` : o;
373
- }, Ee = Symbol.for("@voltro/database/authoredMessage"), E = (e, t) => {
371
+ let a = r.dbCode ?? r.dbSqlState ?? r.dbErrno ?? r.dbNumber, o = je(e);
372
+ return a !== void 0 && ke.test(String(a)) ? `${o} (${String(a)})` : o;
373
+ }, De = Symbol.for("@voltro/database/authoredMessage"), E = (e, t) => {
374
374
  let n = t === void 0 ? Error(e) : Error(e, t);
375
- return Object.defineProperty(n, Ee, {
375
+ return Object.defineProperty(n, De, {
376
376
  value: !0,
377
377
  enumerable: !1
378
378
  }), n;
379
- }, De = (e) => {
379
+ }, Oe = (e) => {
380
380
  for (let t of T(e)) {
381
381
  let e = t;
382
382
  for (let t = 0; typeof e == "object" && e && t < 8; t += 1) {
383
- if (e[Ee] === !0) {
383
+ if (e[De] === !0) {
384
384
  let t = e.message;
385
385
  if (typeof t == "string" && t.length > 0) return t;
386
386
  }
387
387
  e = e.cause;
388
388
  }
389
389
  }
390
- }, Oe = /^[A-Za-z0-9_]{1,32}$/, ke = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, Ae = (e) => {
390
+ }, ke = /^[A-Za-z0-9_]{1,32}$/, Ae = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, je = (e) => {
391
391
  let t = e?._tag, n = e?.name, r = (typeof t == "string" ? t : typeof n == "string" ? n : "").split(/[^A-Za-z0-9_]+/).filter(Boolean).pop();
392
- return r !== void 0 && ke.test(r) ? r : "unknown";
393
- }, je = /^[A-Za-z_][A-Za-z0-9_$]*$/, D = (e) => e !== void 0 && e.length <= 128 && je.test(e) ? e : void 0, Me = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, O = (e, ...t) => {
392
+ return r !== void 0 && Ae.test(r) ? r : "unknown";
393
+ }, Me = /^[A-Za-z_][A-Za-z0-9_$]*$/, D = (e) => e !== void 0 && e.length <= 128 && Me.test(e) ? e : void 0, Ne = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, O = (e, ...t) => {
394
394
  for (let n of t) {
395
395
  let t = n.exec(e);
396
396
  if (t?.[1] !== void 0) return t[1];
397
397
  }
398
- }, Ne = (e, t) => {
398
+ }, Pe = (e, t) => {
399
399
  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}`;
400
400
  if (n === "23503") {
401
401
  let t = D(e.dbConstraint);
@@ -433,7 +433,7 @@ var se = () => new u({
433
433
  };
434
434
  }
435
435
  if (r === 1062) {
436
- let e = D(Me(O(o, /for key '([^']+)'/)));
436
+ let e = D(Ne(O(o, /for key '([^']+)'/)));
437
437
  return {
438
438
  kind: "unique",
439
439
  ...e === void 0 ? {} : { constraint: e }
@@ -484,14 +484,14 @@ var se = () => new u({
484
484
  }
485
485
  if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
486
486
  if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
487
- let e = D(Me(O(o, /UNIQUE constraint failed: ([^,\s]+)/)));
487
+ let e = D(Ne(O(o, /UNIQUE constraint failed: ([^,\s]+)/)));
488
488
  return {
489
489
  kind: "unique",
490
490
  ...e === void 0 ? {} : { column: e }
491
491
  };
492
492
  }
493
493
  if (n === "SQLITE_CONSTRAINT_NOTNULL") {
494
- let e = D(Me(O(o, /NOT NULL constraint failed: ([^,\s]+)/)));
494
+ let e = D(Ne(O(o, /NOT NULL constraint failed: ([^,\s]+)/)));
495
495
  return {
496
496
  kind: "notNull",
497
497
  ...e === void 0 ? {} : { column: e }
@@ -504,20 +504,20 @@ var se = () => new u({
504
504
  ...e === void 0 ? {} : { constraint: e }
505
505
  };
506
506
  }
507
- }, Pe = (e) => {
508
- let t = Ne(e)?.kind;
509
- return t === "foreignKey" || t === "foreignKeyInUse";
510
507
  }, Fe = (e) => {
508
+ let t = Pe(e)?.kind;
509
+ return t === "foreignKey" || t === "foreignKeyInUse";
510
+ }, Ie = (e) => {
511
511
  let t = e.dbCode, n = e.dbErrno;
512
512
  return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
513
- }, Ie = (e) => {
513
+ }, Le = (e) => {
514
514
  if (e.dbErrno !== 1366) return;
515
515
  let t = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${typeof e.dbMessage == "string" ? e.dbMessage : ""}`;
516
516
  if (/Incorrect string value: '\\x(F[0-4])/i.exec(t) === null) return;
517
517
  let n = O(t, /for column [`']?(?:[^`'.]+[`']?\.[`']?)*([^`'.]+)[`']? at row/);
518
518
  return `${n === void 0 ? "the column" : `column '${n}'`} is stored in a character set that cannot hold a 4-byte character (utf8mb3). Declare the store's character set in app.config.ts — store: { dialect: 'mariadb' | 'mysql', charset: 'utf8mb4' } — and run \`voltro db plan\`: every declared table is created with it and converted to it.`;
519
- }, Le = (e) => {
520
- let t = we(e), n = [
519
+ }, Re = (e) => {
520
+ let t = Te(e), n = [
521
521
  t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
522
522
  t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
523
523
  t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
@@ -526,9 +526,9 @@ var se = () => new u({
526
526
  t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
527
527
  ].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, o = typeof t.dbBindings == "string" ? `\n bindings: ${t.dbBindings}` : "", s = typeof t.dbStatement == "string" ? `\n statement: ${t.dbStatement.length <= 400 ? t.dbStatement : `${t.dbStatement.slice(0, 400)}…`}` : "";
528
528
  if (a === void 0 && n.length === 0) return;
529
- let c = Ie(t), l = c === void 0 ? "" : `\n hint: ${c}`;
529
+ let c = Le(t), l = c === void 0 ? "" : `\n hint: ${c}`;
530
530
  return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + l + s + o;
531
- }, Re = (e) => Object.entries(e).map(([e, t]) => `${e}:${ze(t)}`).join(" "), ze = (e) => {
531
+ }, ze = (e) => Object.entries(e).map(([e, t]) => `${e}:${Be(t)}`).join(" "), Be = (e) => {
532
532
  if (e === null) return "null";
533
533
  if (e === void 0) return "undefined";
534
534
  if (typeof e == "bigint") return "bigint";
@@ -538,24 +538,24 @@ var se = () => new u({
538
538
  if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
539
539
  let t = e.constructor?.name;
540
540
  return typeof t == "string" && t !== "" ? t : "Object";
541
- }, Be = 63, Ve = 60, k = [], A = (e) => {
541
+ }, Ve = 63, He = 60, k = [], A = (e) => {
542
542
  k.includes(e) || k.push(e);
543
- }, He = () => {
543
+ }, Ue = () => {
544
544
  let e = k.slice();
545
545
  return k.length = 0, e;
546
- }, Ue = /^[a-zA-Z_][a-zA-Z0-9_]*$/, We = (e, t) => {
546
+ }, We = /^[a-zA-Z_][a-zA-Z0-9_]*$/, Ge = (e, t) => {
547
547
  if (t.length === 0) throw Error(`${e} cannot be empty.`);
548
- if (!Ue.test(t)) throw Error(`${e} '${t}' contains characters outside [A-Za-z0-9_] or starts with a digit. Dialect-portable identifiers must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
548
+ if (!We.test(t)) throw Error(`${e} '${t}' contains characters outside [A-Za-z0-9_] or starts with a digit. Dialect-portable identifiers must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
549
549
  }, j = (e) => {
550
- if (We("table name", e), e.length > 63) throw Error(`table name '${e}' is ${e.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten the name; long table names also cascade into auto-named indexes and FK constraints that would themselves exceed the limit.`);
550
+ if (Ge("table name", e), e.length > 63) throw Error(`table name '${e}' is ${e.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten the name; long table names also cascade into auto-named indexes and FK constraints that would themselves exceed the limit.`);
551
551
  e.length > 60 && A(`table name '${e}' is ${e.length} chars — ${63 - e.length} from the Postgres 63-byte limit. Auto-named indexes on this table will run out of room fast.`);
552
552
  }, M = (e, t) => {
553
- if (We("column name", t), t.length > 63) throw Error(`column '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Rename it.`);
553
+ if (Ge("column name", t), t.length > 63) throw Error(`column '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Rename it.`);
554
554
  t.length > 60 && A(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
555
555
  }, N = (e, t, n, r) => {
556
- if (We("index name", t), t.length > 63) throw Error(n ? `auto-named index '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Supply an explicit short name: .index('<shortName>', ${JSON.stringify([...r])}).` : `index name '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten it.`);
556
+ if (Ge("index name", t), t.length > 63) throw Error(n ? `auto-named index '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Supply an explicit short name: .index('<shortName>', ${JSON.stringify([...r])}).` : `index name '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten it.`);
557
557
  t.length > 60 && A(`index '${t}' on table '${e}' is ${t.length} chars — ${63 - t.length} from the 63-byte limit. ${n ? `Consider .index('<shortName>', ${JSON.stringify([...r])}) before it grows.` : ""}`);
558
- }, Ge = (e, t) => {
558
+ }, P = (e, t) => {
559
559
  if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
560
560
  if (!/^[a-z][a-z0-9_]*$/.test(e)) {
561
561
  let n = t.kind === "derived" ? "the derived prefix doesn't match typeid's required shape — supply an explicit one via id({ prefix: '...' })." : "the prefix must match typeid's required shape /^[a-z][a-z0-9_]*$/.";
@@ -576,33 +576,33 @@ var se = () => new u({
576
576
  lastMs: 0n,
577
577
  sequence: 0n,
578
578
  machineId: $e()
579
- }), tt, nt = () => (tt === void 0 && (tt = et()), tt), rt = () => {
580
- tt = et();
581
- }, it = () => BigInt(Date.now()), at = (e) => {
582
- let t = it();
583
- for (; t <= e;) t = it();
579
+ }), F, tt = () => (F === void 0 && (F = et()), F), nt = () => {
580
+ F = et();
581
+ }, rt = () => BigInt(Date.now()), it = (e) => {
582
+ let t = rt();
583
+ for (; t <= e;) t = rt();
584
584
  return t;
585
- }, ot = () => {
586
- let e = nt(), t = it();
587
- t === e.lastMs ? (e.sequence = e.sequence + 1n & Xe, e.sequence === 0n && (t = at(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
585
+ }, at = () => {
586
+ let e = tt(), t = rt();
587
+ t === e.lastMs ? (e.sequence = e.sequence + 1n & Xe, e.sequence === 0n && (t = it(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
588
588
  let n = t - Ke;
589
589
  if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
590
590
  return (n << Qe | e.machineId << Ze | e.sequence).toString();
591
- }, st = (e) => {
591
+ }, ot = (e) => {
592
592
  let t = e.toLowerCase();
593
593
  if (t.startsWith("_")) throw Error(`cannot derive a typeid prefix for table '${e}' (table names starting with '_' are not valid typeid prefixes). Pick an explicit prefix via id({ prefix: '...' }) or use a different scheme like id({ scheme: 'numeric' }) for internal tables.`);
594
594
  if (!/^[a-z][a-z0-9_]*$/.test(t)) throw Error(`cannot derive a typeid prefix from table name '${e}' (must match [a-z][a-z0-9_]*). Pick an explicit prefix via id({ prefix: '...' }).`);
595
595
  let n = t.endsWith("ies") && t.length > 3 ? t.slice(0, -3) + "y" : t.endsWith("ses") || t.endsWith("xes") || t.endsWith("zes") || t.endsWith("shes") || t.endsWith("ches") ? t.slice(0, -2) : t.endsWith("s") && t.length > 1 ? t.slice(0, -1) : t;
596
- return Ge(n, {
596
+ return P(n, {
597
597
  kind: "derived",
598
598
  tableName: e
599
599
  }), n;
600
- }, ct = (e, t) => {
600
+ }, st = (e, t) => {
601
601
  if (e === void 0) return {
602
602
  kind: "typeid",
603
- prefix: st(t)
603
+ prefix: ot(t)
604
604
  };
605
- if ("prefix" in e && !("scheme" in e)) return Ge(e.prefix, {
605
+ if ("prefix" in e && !("scheme" in e)) return P(e.prefix, {
606
606
  kind: "explicit",
607
607
  tableName: t
608
608
  }), {
@@ -612,8 +612,8 @@ var se = () => new u({
612
612
  if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
613
613
  switch (e.scheme) {
614
614
  case "typeid": {
615
- let n = e.prefix ?? st(t);
616
- return e.prefix !== void 0 && Ge(e.prefix, {
615
+ let n = e.prefix ?? ot(t);
616
+ return e.prefix !== void 0 && P(e.prefix, {
617
617
  kind: "explicit",
618
618
  tableName: t
619
619
  }), {
@@ -629,22 +629,22 @@ var se = () => new u({
629
629
  generate: e.generate
630
630
  };
631
631
  }
632
- }, lt = (e, t) => {
632
+ }, ct = (e, t) => {
633
633
  switch (e.kind) {
634
634
  case "typeid": return i(e.prefix).toString();
635
635
  case "ulid": return a();
636
636
  case "numeric": return null;
637
- case "snowflake": return ot();
637
+ case "snowflake": return at();
638
638
  case "custom": return e.generate(t);
639
639
  }
640
- }, ut = (e) => ({
640
+ }, lt = (e) => ({
641
641
  fields: C(e.fields),
642
642
  ...e.id === void 0 ? {} : { id: e.id },
643
643
  ...e.requires === void 0 ? {} : { requires: e.requires },
644
644
  ...e.indexes === void 0 ? {} : { indexes: e.indexes },
645
645
  ...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
646
646
  ...e.policies === void 0 ? {} : { policies: e.policies }
647
- }), dt = ut, ft = (e) => {
647
+ }), ut = lt, dt = (e) => {
648
648
  let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
649
649
  let i = e.id ?? e;
650
650
  if (!t.has(i)) {
@@ -654,7 +654,7 @@ var se = () => new u({
654
654
  };
655
655
  for (let t of e) r(t);
656
656
  return n;
657
- }, pt = (e, ...t) => {
657
+ }, ft = (e, ...t) => {
658
658
  if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
659
659
  let n = (r) => ({
660
660
  jsonPath: {
@@ -665,14 +665,14 @@ var se = () => new u({
665
665
  numeric: () => n(!0)
666
666
  });
667
667
  return n(!1);
668
- }, mt = (e = "cosine", t = "float32") => {
668
+ }, pt = (e = "cosine", t = "float32") => {
669
669
  let n = t === "half" ? "halfvec" : "vector";
670
670
  switch (e) {
671
671
  case "cosine": return `${n}_cosine_ops`;
672
672
  case "l2": return `${n}_l2_ops`;
673
673
  case "inner": return `${n}_ip_ops`;
674
674
  }
675
- }, ht = [
675
+ }, mt = [
676
676
  "id",
677
677
  "tenantId",
678
678
  "createdAt",
@@ -681,7 +681,7 @@ var se = () => new u({
681
681
  "updatedBy",
682
682
  "deletedAt",
683
683
  "deletedBy"
684
- ], gt = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, _t = (e, t) => `${e}_${t.join("_")}_idx`, vt = (e, t) => `${e}_${t.join("_")}_uq`, yt = (e, t, n, r, i) => {
684
+ ], ht = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, gt = (e, t) => `${e}_${t.join("_")}_idx`, _t = (e, t) => `${e}_${t.join("_")}_uq`, vt = (e, t, n, r, i) => {
685
685
  if (n !== "hnsw") return;
686
686
  if (r.length !== 1) throw Error(`hnsw index '${t}' on table '${e}' must cover exactly one vector column — got ${r.length} fields. pgvector's HNSW access method indexes a single vector column.`);
687
687
  let a = r[0];
@@ -689,14 +689,14 @@ var se = () => new u({
689
689
  let o = i[a];
690
690
  if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
691
691
  if (o.type !== "vector") throw Error(`hnsw index '${t}' on table '${e}' requires a vector() column — column '${a}' is '${o.type}'. HNSW is the pgvector approximate-nearest-neighbour method and only applies to vectors.`);
692
- }, bt = (e, t) => {
692
+ }, yt = (e, t) => {
693
693
  let n;
694
694
  for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
695
695
  ...i,
696
- idScheme: ct(i.idSchemeInput, t)
696
+ idScheme: st(i.idSchemeInput, t)
697
697
  });
698
698
  return n ?? e;
699
- }, P = (e) => {
699
+ }, I = (e) => {
700
700
  let t = e.appliedPrimaryKey ?? [];
701
701
  return {
702
702
  tableName: e.tableName,
@@ -716,7 +716,7 @@ var se = () => new u({
716
716
  fullTextIndex: ((t, n, r) => {
717
717
  if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
718
718
  if (N(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
719
- return P({
719
+ return I({
720
720
  ...e,
721
721
  tableName: e.tableName,
722
722
  fields: e.fields,
@@ -737,27 +737,27 @@ var se = () => new u({
737
737
  });
738
738
  }),
739
739
  with: ((...t) => {
740
- let n = ft(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
740
+ let n = dt(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
741
741
  for (let e of Object.keys(r)) i.set(e, {
742
742
  id: "<table>",
743
743
  fields: {}
744
744
  });
745
745
  for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
746
746
  let o = i.get(n);
747
- if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${gt(o)}' and '${gt(t)}' both define it. If they're the same mixin reached via different paths, set a shared 'id' on both. If they're genuinely different concerns, rename one of the columns.`);
747
+ if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${ht(o)}' and '${ht(t)}' both define it. If they're the same mixin reached via different paths, set a shared 'id' on both. If they're genuinely different concerns, rename one of the columns.`);
748
748
  M(e.tableName, n), r[n] = a, i.set(n, t);
749
749
  }
750
750
  let a = [...e.appliedIndexes];
751
751
  for (let t of n) for (let n of t.indexes ?? []) {
752
- let t = n.name ?? _t(e.tableName, n.fields);
753
- a.some((e) => e.name === t) || (N(e.tableName, t, n.name === void 0, n.fields), yt(e.tableName, t, n.kind, n.fields, r), a.push({
752
+ let t = n.name ?? gt(e.tableName, n.fields);
753
+ a.some((e) => e.name === t) || (N(e.tableName, t, n.name === void 0, n.fields), vt(e.tableName, t, n.kind, n.fields, r), a.push({
754
754
  name: t,
755
755
  fields: n.fields,
756
756
  ...n.kind === void 0 ? {} : { kind: n.kind },
757
757
  ...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
758
758
  }));
759
759
  }
760
- return P({
760
+ return I({
761
761
  ...e,
762
762
  tableName: e.tableName,
763
763
  fields: r,
@@ -774,10 +774,10 @@ var se = () => new u({
774
774
  }),
775
775
  index: ((...t) => {
776
776
  let n, r, i, a = Array.isArray(t[0]);
777
- if (a ? (r = t[0], i = t[1], n = _t(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`index '${n}' on table '${e.tableName}' has no fields — an index must cover at least one column.`);
777
+ if (a ? (r = t[0], i = t[1], n = gt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`index '${n}' on table '${e.tableName}' has no fields — an index must cover at least one column.`);
778
778
  let o = r.filter((e) => typeof e == "string");
779
- if (N(e.tableName, n, a, o), yt(e.tableName, n, i?.kind, r, e.fields), e.appliedIndexes.some((e) => e.name === n)) throw t.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${e.tableName}' — you've called .index(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (rare).`) : Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table.`);
780
- return P({
779
+ if (N(e.tableName, n, a, o), vt(e.tableName, n, i?.kind, r, e.fields), e.appliedIndexes.some((e) => e.name === n)) throw t.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${e.tableName}' — you've called .index(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (rare).`) : Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table.`);
780
+ return I({
781
781
  ...e,
782
782
  tableName: e.tableName,
783
783
  fields: e.fields,
@@ -801,8 +801,8 @@ var se = () => new u({
801
801
  expressionIndex: ((t, n, r) => {
802
802
  if (n.length === 0) throw Error(`expressionIndex '${t}' on table '${e.tableName}' has no fields — an index must cover at least one column or expression.`);
803
803
  let i = n.filter((e) => typeof e == "string");
804
- if (N(e.tableName, t, !1, i), yt(e.tableName, t, r?.kind, n, e.fields), e.appliedIndexes.some((e) => e.name === t)) throw Error(`duplicate index '${t}' on table '${e.tableName}': each index name must be unique within a table.`);
805
- return P({
804
+ if (N(e.tableName, t, !1, i), vt(e.tableName, t, r?.kind, n, e.fields), e.appliedIndexes.some((e) => e.name === t)) throw Error(`duplicate index '${t}' on table '${e.tableName}': each index name must be unique within a table.`);
805
+ return I({
806
806
  ...e,
807
807
  tableName: e.tableName,
808
808
  fields: e.fields,
@@ -825,9 +825,9 @@ var se = () => new u({
825
825
  }),
826
826
  unique: ((...t) => {
827
827
  let n, r, i, a = Array.isArray(t[0]);
828
- if (a ? (r = t[0], i = t[1], n = vt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`unique '${n}' on table '${e.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
828
+ if (a ? (r = t[0], i = t[1], n = _t(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`unique '${n}' on table '${e.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
829
829
  if (N(e.tableName, n, a, r), e.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${e.tableName}' — you've called .unique(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (very rare).` : `duplicate UNIQUE '${n}' on table '${e.tableName}': each constraint name must be unique within a table.`);
830
- return P({
830
+ return I({
831
831
  ...e,
832
832
  tableName: e.tableName,
833
833
  fields: e.fields,
@@ -848,10 +848,10 @@ var se = () => new u({
848
848
  }),
849
849
  uniqueActive: ((...t) => {
850
850
  let n, r, i, a = Array.isArray(t[0]);
851
- if (a ? (r = t[0], i = t[1], n = _t(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${e.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
851
+ if (a ? (r = t[0], i = t[1], n = gt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${e.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
852
852
  if (N(e.tableName, n, a, r), e.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
853
853
  let o = i?.where ?? "\"deletedAt\" IS NULL";
854
- return P({
854
+ return I({
855
855
  ...e,
856
856
  tableName: e.tableName,
857
857
  fields: e.fields,
@@ -874,7 +874,7 @@ var se = () => new u({
874
874
  check: ((t, n) => {
875
875
  if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
876
876
  if (N(e.tableName, t, !1, []), e.appliedChecks.some((e) => e.name === t)) throw Error(`duplicate CHECK '${t}' on table '${e.tableName}': each constraint name must be unique within a table.`);
877
- return P({
877
+ return I({
878
878
  ...e,
879
879
  tableName: e.tableName,
880
880
  fields: e.fields,
@@ -896,7 +896,7 @@ var se = () => new u({
896
896
  if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
897
897
  let i = e.appliedRules ?? [];
898
898
  if (i.some((e) => e.name === t)) throw Error(`duplicate rule '${t}' on table '${e.tableName}': each rule name must be unique within a table.`);
899
- return P({
899
+ return I({
900
900
  ...e,
901
901
  appliedRules: [...i, {
902
902
  name: t,
@@ -907,7 +907,7 @@ var se = () => new u({
907
907
  }),
908
908
  renamedFrom: ((t) => {
909
909
  if (t === e.tableName) throw Error(`renamedFrom('${t}') on table '${e.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
910
- return j(t), P({
910
+ return j(t), I({
911
911
  ...e,
912
912
  previousTableName: t
913
913
  });
@@ -922,7 +922,7 @@ var se = () => new u({
922
922
  }
923
923
  if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
924
924
  for (let [t, r] of Object.entries(e.fields)) if (r.type === "id" && !n.includes(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' conflicts with the id() column '${t}'. The explicit primary key IS the key — drop the id() column, or include '${t}' in the composite key.`);
925
- return P({
925
+ return I({
926
926
  ...e,
927
927
  tableName: e.tableName,
928
928
  fields: e.fields,
@@ -937,7 +937,7 @@ var se = () => new u({
937
937
  ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
938
938
  });
939
939
  }),
940
- nonReactive: (() => P({
940
+ nonReactive: (() => I({
941
941
  ...e,
942
942
  tableName: e.tableName,
943
943
  fields: e.fields,
@@ -951,7 +951,7 @@ var se = () => new u({
951
951
  ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
952
952
  ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
953
953
  })),
954
- validate: ((t) => P({
954
+ validate: ((t) => I({
955
955
  ...e,
956
956
  tableName: e.tableName,
957
957
  fields: e.fields,
@@ -965,7 +965,7 @@ var se = () => new u({
965
965
  insertSchema: t,
966
966
  ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
967
967
  })),
968
- validatePatch: ((t) => P({
968
+ validatePatch: ((t) => I({
969
969
  ...e,
970
970
  tableName: e.tableName,
971
971
  fields: e.fields,
@@ -980,22 +980,22 @@ var se = () => new u({
980
980
  validatePatchSchema: r.partial(t)
981
981
  }))
982
982
  };
983
- }, F = (e, t) => {
983
+ }, L = (e, t) => {
984
984
  j(e);
985
985
  let n = Object.entries(t).flatMap(([e, t]) => {
986
- let n = he(t);
986
+ let n = ge(t);
987
987
  return n === void 0 ? [] : [{
988
988
  column: e,
989
989
  ...n
990
990
  }];
991
- }), r = bt(C(t), e);
991
+ }), r = yt(C(t), e);
992
992
  for (let t of Object.keys(r)) M(e, t);
993
993
  let i;
994
994
  for (let [t, n] of Object.entries(r)) n.references === S && (n.references = () => {
995
995
  if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
996
996
  return i;
997
997
  });
998
- return i = P({
998
+ return i = I({
999
999
  appliedPluginRefs: n,
1000
1000
  tableName: e,
1001
1001
  fields: r,
@@ -1007,7 +1007,7 @@ var se = () => new u({
1007
1007
  appliedChecks: [],
1008
1008
  appliedRules: []
1009
1009
  }), i;
1010
- }, xt = (e) => e === "sqlite" || e === "turso", St = (e) => e === "mysql" || e === "mariadb", I = (e, t) => {
1010
+ }, bt = (e) => e === "sqlite" || e === "turso", xt = (e) => e === "mysql" || e === "mariadb", R = (e, t) => {
1011
1011
  switch (t) {
1012
1012
  case "mysql":
1013
1013
  case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
@@ -1016,51 +1016,51 @@ var se = () => new u({
1016
1016
  case "sqlite":
1017
1017
  case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
1018
1018
  }
1019
- }, Ct = 1e4, wt = Symbol.for("@voltro/database/tableRegistry"), Tt = globalThis, L = Tt[wt] ?? (Tt[wt] = /* @__PURE__ */ new Map()), Et = (e) => {
1020
- let t = L.get(e.tableName);
1019
+ }, St = 1e4, Ct = Symbol.for("@voltro/database/tableRegistry"), wt = globalThis, z = wt[Ct] ?? (wt[Ct] = /* @__PURE__ */ new Map()), Tt = (e) => {
1020
+ let t = z.get(e.tableName);
1021
1021
  if (t === void 0) {
1022
- L.set(e.tableName, e);
1022
+ z.set(e.tableName, e);
1023
1023
  return;
1024
1024
  }
1025
1025
  if (t !== e) throw Error(`duplicate table '${e.tableName}' registration: two different table descriptors claim the same name. Rename one or import the shared module that defines it.`);
1026
- }, Dt = (e) => {
1027
- L.get(e.tableName) === void 0 && L.set(e.tableName, e);
1028
- }, R = (e) => L.get(e), Ot = (e) => {
1029
- let t = L.get(e);
1026
+ }, Et = (e) => {
1027
+ z.get(e.tableName) === void 0 && z.set(e.tableName, e);
1028
+ }, B = (e) => z.get(e), Dt = (e) => {
1029
+ let t = z.get(e);
1030
1030
  if (t === void 0) throw Error(`table '${e}' is not registered. Register it by wrapping it in \`databaseHandle({ ... })\` (the usual path) or call \`registerTable(t)\` explicitly before this runs. Note a \`queryFor(t)\` query carries its own source table, so eager-loads don't hit this — this error means a reconstructed descriptor or by-name tooling reached an unregistered table.`);
1031
1031
  return t;
1032
- }, kt = () => [...L.values()], At = (e) => L.delete(e), jt = () => {
1033
- L.clear();
1034
- }, Mt = (e) => L.get(e)?.isReactive !== !1, z = (e) => e.order ?? [], Nt = (e) => ({
1032
+ }, Ot = () => [...z.values()], kt = (e) => z.delete(e), At = () => {
1033
+ z.clear();
1034
+ }, jt = (e) => z.get(e)?.isReactive !== !1, V = (e) => e.order ?? [], Mt = (e) => ({
1035
1035
  op: "count",
1036
1036
  alias: e ?? "count"
1037
- }), Pt = (e, t) => ({
1037
+ }), Nt = (e, t) => ({
1038
1038
  op: "count-distinct",
1039
1039
  column: e,
1040
1040
  alias: t ?? `count_distinct_${e}`
1041
- }), Ft = (e, t) => ({
1041
+ }), Pt = (e, t) => ({
1042
1042
  op: "sum",
1043
1043
  column: e,
1044
1044
  alias: t ?? `sum_${e}`
1045
- }), It = (e, t) => ({
1045
+ }), Ft = (e, t) => ({
1046
1046
  op: "avg",
1047
1047
  column: e,
1048
1048
  alias: t ?? `avg_${e}`
1049
- }), Lt = (e, t) => ({
1049
+ }), It = (e, t) => ({
1050
1050
  op: "min",
1051
1051
  column: e,
1052
1052
  alias: t ?? `min_${e}`
1053
- }), Rt = (e, t) => ({
1053
+ }), Lt = (e, t) => ({
1054
1054
  op: "max",
1055
1055
  column: e,
1056
1056
  alias: t ?? `max_${e}`
1057
- }), zt = (e, t) => ({
1057
+ }), Rt = (e, t) => ({
1058
1058
  op: "column",
1059
1059
  column: e,
1060
1060
  alias: t ?? e
1061
- }), B = (e) => (...t) => {
1061
+ }), H = (e) => (...t) => {
1062
1062
  if (t.length < 2) throw Error(`${e}: requires at least two queries`);
1063
- return H({
1063
+ return W({
1064
1064
  table: t[0].descriptor.table,
1065
1065
  predicate: void 0,
1066
1066
  order: [],
@@ -1072,55 +1072,55 @@ var se = () => new u({
1072
1072
  queries: t.map((e) => e.descriptor)
1073
1073
  }
1074
1074
  });
1075
- }, Bt = B("union"), Vt = B("union-all"), Ht = B("intersect"), Ut = B("except"), V = (e) => ({ over: (t) => ({
1075
+ }, zt = H("union"), Bt = H("union-all"), Vt = H("intersect"), Ht = H("except"), U = (e) => ({ over: (t) => ({
1076
1076
  ...e,
1077
1077
  window: t
1078
- }) }), Wt = (e = "rowNumber") => V({
1078
+ }) }), Ut = (e = "rowNumber") => U({
1079
1079
  op: "window-row-number",
1080
1080
  alias: e
1081
- }), Gt = (e = "rank") => V({
1081
+ }), Wt = (e = "rank") => U({
1082
1082
  op: "window-rank",
1083
1083
  alias: e
1084
- }), Kt = (e = "denseRank") => V({
1084
+ }), Gt = (e = "denseRank") => U({
1085
1085
  op: "window-dense-rank",
1086
1086
  alias: e
1087
- }), qt = (e, t = 1, n) => V({
1087
+ }), Kt = (e, t = 1, n) => U({
1088
1088
  op: "window-lag",
1089
1089
  column: e,
1090
1090
  alias: n ?? `lag_${e}`,
1091
1091
  offset: t
1092
- }), Jt = (e, t = 1, n) => V({
1092
+ }), qt = (e, t = 1, n) => U({
1093
1093
  op: "window-lead",
1094
1094
  column: e,
1095
1095
  alias: n ?? `lead_${e}`,
1096
1096
  offset: t
1097
- }), Yt = (e, t) => V({
1097
+ }), Jt = (e, t) => U({
1098
1098
  op: "window-sum-over",
1099
1099
  column: e,
1100
1100
  alias: t ?? `sum_${e}_over`
1101
- }), Xt = (e, t) => V({
1101
+ }), Yt = (e, t) => U({
1102
1102
  op: "window-avg-over",
1103
1103
  column: e,
1104
1104
  alias: t ?? `avg_${e}_over`
1105
- }), Zt = (e, t, n) => {
1106
- let r = n?.find((e) => e.name === t) ?? R(e)?.appliedFullText?.find((e) => e.name === t);
1105
+ }), Xt = (e, t, n) => {
1106
+ let r = n?.find((e) => e.name === t) ?? B(e)?.appliedFullText?.find((e) => e.name === t);
1107
1107
  if (r === void 0) throw Error(`.matching('${t}', ...): no full-text index named '${t}' is declared on table '${e}'. Declare it with \`table(...).fullTextIndex('${t}', [columns])\` first.`);
1108
1108
  return {
1109
1109
  columns: r.columns,
1110
1110
  ...r.config === void 0 ? {} : { config: r.config },
1111
1111
  ...r.weights === void 0 ? {} : { weights: r.weights }
1112
1112
  };
1113
- }, H = (e) => ({
1113
+ }, W = (e) => ({
1114
1114
  descriptor: e,
1115
1115
  where(t) {
1116
1116
  let n = e.predicate ? { and: [e.predicate, t] } : t;
1117
- return H({
1117
+ return W({
1118
1118
  ...e,
1119
1119
  predicate: n
1120
1120
  });
1121
1121
  },
1122
1122
  orderBy(t, n = "asc") {
1123
- return H({
1123
+ return W({
1124
1124
  ...e,
1125
1125
  order: [...e.order, {
1126
1126
  column: t,
@@ -1129,43 +1129,43 @@ var se = () => new u({
1129
1129
  });
1130
1130
  },
1131
1131
  limit(t) {
1132
- return H({
1132
+ return W({
1133
1133
  ...e,
1134
1134
  take: t
1135
1135
  });
1136
1136
  },
1137
1137
  offset(t) {
1138
- return H({
1138
+ return W({
1139
1139
  ...e,
1140
1140
  skip: t
1141
1141
  });
1142
1142
  },
1143
1143
  select(...t) {
1144
- return H({
1144
+ return W({
1145
1145
  ...e,
1146
1146
  projection: t
1147
1147
  });
1148
1148
  },
1149
1149
  using(t) {
1150
- return H({
1150
+ return W({
1151
1151
  ...e,
1152
1152
  usingIndex: t
1153
1153
  });
1154
1154
  },
1155
1155
  withDeleted() {
1156
- return H({
1156
+ return W({
1157
1157
  ...e,
1158
1158
  includeDeleted: !0
1159
1159
  });
1160
1160
  },
1161
1161
  forUpdate() {
1162
- return H({
1162
+ return W({
1163
1163
  ...e,
1164
1164
  lock: "update"
1165
1165
  });
1166
1166
  },
1167
1167
  unscoped() {
1168
- return H({
1168
+ return W({
1169
1169
  ...e,
1170
1170
  crossTenant: !0
1171
1171
  });
@@ -1175,13 +1175,13 @@ var se = () => new u({
1175
1175
  ...e.eager ?? {},
1176
1176
  ...t
1177
1177
  };
1178
- return H({
1178
+ return W({
1179
1179
  ...e,
1180
1180
  eager: n
1181
1181
  });
1182
1182
  },
1183
1183
  count() {
1184
- return H({
1184
+ return W({
1185
1185
  ...e,
1186
1186
  projection: void 0,
1187
1187
  aggregations: [{
@@ -1195,15 +1195,15 @@ var se = () => new u({
1195
1195
  ...t,
1196
1196
  alias: e
1197
1197
  }));
1198
- return H({
1198
+ return W({
1199
1199
  ...e,
1200
1200
  projection: void 0,
1201
1201
  aggregations: n
1202
1202
  });
1203
1203
  },
1204
1204
  matching(t, n, r) {
1205
- let i = Zt(e.table, t, e.fullTextIndexes);
1206
- return H({
1205
+ let i = Xt(e.table, t, e.fullTextIndexes);
1206
+ return W({
1207
1207
  ...e,
1208
1208
  fullTextSearch: {
1209
1209
  indexName: t,
@@ -1218,7 +1218,7 @@ var se = () => new u({
1218
1218
  rankBy(t) {
1219
1219
  let n = e.fullTextSearch;
1220
1220
  if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
1221
- return H({
1221
+ return W({
1222
1222
  ...e,
1223
1223
  fullTextSearch: {
1224
1224
  ...n,
@@ -1237,7 +1237,7 @@ var se = () => new u({
1237
1237
  distance: r?.distance ?? "cosine",
1238
1238
  ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
1239
1239
  };
1240
- return H({
1240
+ return W({
1241
1241
  ...e,
1242
1242
  annClause: i
1243
1243
  });
@@ -1249,7 +1249,7 @@ var se = () => new u({
1249
1249
  distance: "cosine",
1250
1250
  ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
1251
1251
  };
1252
- return H({
1252
+ return W({
1253
1253
  ...e,
1254
1254
  annClause: r,
1255
1255
  take: n
@@ -1262,7 +1262,7 @@ var se = () => new u({
1262
1262
  column: "",
1263
1263
  distance: "cosine"
1264
1264
  };
1265
- return H({
1265
+ return W({
1266
1266
  ...e,
1267
1267
  annClause: {
1268
1268
  ...n,
@@ -1271,22 +1271,22 @@ var se = () => new u({
1271
1271
  });
1272
1272
  },
1273
1273
  use(t) {
1274
- return H({ ...t(e) });
1274
+ return W({ ...t(e) });
1275
1275
  },
1276
1276
  distinct() {
1277
- return H({
1277
+ return W({
1278
1278
  ...e,
1279
1279
  distinct: !0
1280
1280
  });
1281
1281
  },
1282
1282
  distinctOn(t) {
1283
- return H({
1283
+ return W({
1284
1284
  ...e,
1285
1285
  distinctOn: [...t]
1286
1286
  });
1287
1287
  },
1288
1288
  as(t) {
1289
- return H({
1289
+ return W({
1290
1290
  ...e,
1291
1291
  alias: t
1292
1292
  });
@@ -1299,7 +1299,7 @@ var se = () => new u({
1299
1299
  on: r,
1300
1300
  ...typeof t == "string" ? {} : { sourceTable: t }
1301
1301
  }];
1302
- return H({
1302
+ return W({
1303
1303
  ...e,
1304
1304
  joins: a
1305
1305
  });
@@ -1312,7 +1312,7 @@ var se = () => new u({
1312
1312
  on: r,
1313
1313
  ...typeof t == "string" ? {} : { sourceTable: t }
1314
1314
  }];
1315
- return H({
1315
+ return W({
1316
1316
  ...e,
1317
1317
  joins: a
1318
1318
  });
@@ -1322,7 +1322,7 @@ var se = () => new u({
1322
1322
  outputKey: e,
1323
1323
  source: t
1324
1324
  }));
1325
- return H({
1325
+ return W({
1326
1326
  ...e,
1327
1327
  projection: void 0,
1328
1328
  joinedProjection: n
@@ -1331,7 +1331,7 @@ var se = () => new u({
1331
1331
  withCte(t, n) {
1332
1332
  let r = e.ctes ?? [];
1333
1333
  if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
1334
- return H({
1334
+ return W({
1335
1335
  ...e,
1336
1336
  ctes: [...r, {
1337
1337
  name: t,
@@ -1342,7 +1342,7 @@ var se = () => new u({
1342
1342
  recursiveCte(t, n) {
1343
1343
  let r = e.ctes ?? [];
1344
1344
  if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
1345
- return H({
1345
+ return W({
1346
1346
  ...e,
1347
1347
  ctes: [...r, {
1348
1348
  name: t,
@@ -1353,20 +1353,20 @@ var se = () => new u({
1353
1353
  },
1354
1354
  groupBy(t) {
1355
1355
  let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
1356
- return H({
1356
+ return W({
1357
1357
  ...e,
1358
1358
  groupBy: n
1359
1359
  });
1360
1360
  },
1361
1361
  having(t) {
1362
1362
  let n = e.having ? { and: [e.having, t] } : t;
1363
- return H({
1363
+ return W({
1364
1364
  ...e,
1365
1365
  having: n
1366
1366
  });
1367
1367
  },
1368
1368
  exists() {
1369
- return H({
1369
+ return W({
1370
1370
  ...e,
1371
1371
  projection: void 0,
1372
1372
  aggregations: [{
@@ -1377,8 +1377,8 @@ var se = () => new u({
1377
1377
  });
1378
1378
  }
1379
1379
  });
1380
- function Qt(e) {
1381
- return H({
1380
+ function Zt(e) {
1381
+ return W({
1382
1382
  table: e.tableName,
1383
1383
  predicate: void 0,
1384
1384
  order: [],
@@ -1389,7 +1389,7 @@ function Qt(e) {
1389
1389
  sourceTable: e
1390
1390
  });
1391
1391
  }
1392
- var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1392
+ var Qt = (e, t, n) => $t(e, "id", t, n), $t = (e, t, n, r, i = "asc") => {
1393
1393
  let a = [...e.order.filter((e) => e.column !== t), {
1394
1394
  column: t,
1395
1395
  direction: i
@@ -1404,11 +1404,11 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1404
1404
  order: a,
1405
1405
  take: r
1406
1406
  };
1407
- }, tn = (e) => {
1407
+ }, en = (e) => {
1408
1408
  let t = {};
1409
- for (let [n, r] of Object.entries(e)) Et(r), t[n] = Qt(r);
1409
+ for (let [n, r] of Object.entries(e)) Tt(r), t[n] = Zt(r);
1410
1410
  return t;
1411
- }, nn = (e) => e.isView === !0, rn = (e, t, n) => {
1411
+ }, tn = (e) => e.isView === !0, nn = (e, t, n) => {
1412
1412
  if (j(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
1413
1413
  let r = C(t);
1414
1414
  for (let t of Object.keys(r)) M(e, t);
@@ -1418,7 +1418,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1418
1418
  isView: !0,
1419
1419
  viewSelect: n
1420
1420
  };
1421
- }, an = (e) => Qt({
1421
+ }, rn = (e) => Zt({
1422
1422
  ...e,
1423
1423
  isReactive: !1,
1424
1424
  appliedMixins: [],
@@ -1426,8 +1426,8 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1426
1426
  appliedUniques: [],
1427
1427
  appliedFullText: [],
1428
1428
  appliedChecks: []
1429
- }), on = (e, t, n = null) => {
1430
- let r = n === null ? I(e.tableName, t) : `${I(n, t)}.${I(e.tableName, t)}`, i = e.viewSelect.trim();
1429
+ }), an = (e, t, n = null) => {
1430
+ let r = n === null ? R(e.tableName, t) : `${R(n, t)}.${R(e.tableName, t)}`, i = e.viewSelect.trim();
1431
1431
  switch (t) {
1432
1432
  case "postgres":
1433
1433
  case "mysql":
@@ -1436,7 +1436,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1436
1436
  case "sqlite":
1437
1437
  case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
1438
1438
  }
1439
- }, sn = (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, cn = (e) => {
1439
+ }, on = (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, sn = (e) => {
1440
1440
  if (e == null || typeof e != "string") return e;
1441
1441
  let t = e.trim();
1442
1442
  if (t.length === 0) return e;
@@ -1447,7 +1447,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1447
1447
  } catch {
1448
1448
  return e;
1449
1449
  }
1450
- }, ln = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, un = (e) => {
1450
+ }, cn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, ln = (e) => {
1451
1451
  if (e == null || e instanceof Date) return e;
1452
1452
  if (typeof e == "string") {
1453
1453
  let t = new Date(e);
@@ -1458,24 +1458,24 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1458
1458
  return isNaN(t.getTime()) ? e : t;
1459
1459
  }
1460
1460
  return e;
1461
- }, dn = (e, t, n) => {
1461
+ }, un = (e, t, n) => {
1462
1462
  if (e == null) return e;
1463
1463
  switch (t) {
1464
- case "boolean": return n === "postgres" ? e : sn(e);
1465
- case "vector": return n === "postgres" ? cn(e) : e;
1466
- case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : cn(e);
1467
- case "array": return n === "postgres" ? e : cn(e);
1464
+ case "boolean": return n === "postgres" ? e : on(e);
1465
+ case "vector": return n === "postgres" ? sn(e) : e;
1466
+ case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : sn(e);
1467
+ case "array": return n === "postgres" ? e : sn(e);
1468
1468
  case "timestamp":
1469
- case "date": return n === "sqlite" || n === "turso" ? un(e) : e;
1469
+ case "date": return n === "sqlite" || n === "turso" ? ln(e) : e;
1470
1470
  case "decimal":
1471
- case "bigint": return ln(e);
1471
+ case "bigint": return cn(e);
1472
1472
  default: return e;
1473
1473
  }
1474
- }, fn = (e, t, n) => {
1474
+ }, dn = (e, t, n) => {
1475
1475
  if (e.length === 0) return e;
1476
- let r = R(t);
1477
- return r === void 0 ? e : pn(e, r, n);
1478
- }, pn = (e, t, n) => {
1476
+ let r = B(t);
1477
+ return r === void 0 ? e : fn(e, r, n);
1478
+ }, fn = (e, t, n) => {
1479
1479
  if (e.length === 0) return e;
1480
1480
  let r = t.fields, i = [];
1481
1481
  for (let [e, t] of Object.entries(r)) i.push({
@@ -1484,10 +1484,10 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1484
1484
  });
1485
1485
  return e.map((e) => {
1486
1486
  let t = { ...e };
1487
- for (let { key: e, type: r } of i) e in t && (t[e] = dn(t[e], r, n));
1487
+ for (let { key: e, type: r } of i) e in t && (t[e] = un(t[e], r, n));
1488
1488
  return t;
1489
1489
  });
1490
- }, mn = (e, t) => {
1490
+ }, pn = (e, t) => {
1491
1491
  if (e == null) return e;
1492
1492
  switch (t) {
1493
1493
  case "json": return JSON.stringify(e);
@@ -1495,38 +1495,38 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1495
1495
  case "vector": return typeof e == "string" ? e : JSON.stringify(e);
1496
1496
  default: return e;
1497
1497
  }
1498
- }, hn = (e, t, n = ["json", "array"]) => {
1499
- let r = R(t);
1498
+ }, mn = (e, t, n = ["json", "array"]) => {
1499
+ let r = B(t);
1500
1500
  if (r === void 0) return e;
1501
1501
  let i = r.fields, a = null;
1502
1502
  for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
1503
- let n = mn(e[t], r.type);
1503
+ let n = pn(e[t], r.type);
1504
1504
  n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
1505
1505
  }
1506
1506
  return a ?? e;
1507
- }, gn = (e) => {
1507
+ }, hn = (e) => {
1508
1508
  if (e.length === 0) throw RangeError("Column reference must not be empty");
1509
1509
  return {
1510
1510
  _tag: "ColumnReference",
1511
1511
  column: e
1512
1512
  };
1513
- }, U = (e) => typeof e == "object" && !!e && "_tag" in e && e._tag === "ColumnReference" && "column" in e && typeof e.column == "string", _n = [
1513
+ }, G = (e) => typeof e == "object" && !!e && "_tag" in e && e._tag === "ColumnReference" && "column" in e && typeof e.column == "string", gn = [
1514
1514
  "eq",
1515
1515
  "neq",
1516
1516
  "gt",
1517
1517
  "gte",
1518
1518
  "lt",
1519
1519
  "lte"
1520
- ], vn = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => vn(e)) : e, yn = /^[A-Za-z_][A-Za-z0-9_]*$/, bn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : yn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), xn = (e) => "{" + e.map((e) => {
1520
+ ], _n = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => _n(e)) : e, vn = /^[A-Za-z_][A-Za-z0-9_]*$/, yn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : vn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), bn = (e) => "{" + e.map((e) => {
1521
1521
  let t = String(e);
1522
1522
  return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
1523
- }).join(",") + "}", W = (e, t, n, r = {}) => {
1524
- let i = I(e, n), a = r.numeric ?? !1;
1523
+ }).join(",") + "}", K = (e, t, n, r = {}) => {
1524
+ let i = R(e, n), a = r.numeric ?? !1;
1525
1525
  if (n === "postgres") {
1526
- let e = `(${i} #>> '${xn(t)}'::text[])`;
1526
+ let e = `(${i} #>> '${bn(t)}'::text[])`;
1527
1527
  return a ? `${e}::numeric` : e;
1528
1528
  }
1529
- let o = bn(t);
1529
+ let o = yn(t);
1530
1530
  switch (n) {
1531
1531
  case "mysql":
1532
1532
  case "mariadb": {
@@ -1543,53 +1543,53 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1543
1543
  return a ? `CAST(${e} AS REAL)` : e;
1544
1544
  }
1545
1545
  }
1546
- }, Sn = class extends Error {
1546
+ }, xn = class extends Error {
1547
1547
  _tag = "TenantNamespaceUnresolved";
1548
1548
  constructor(e) {
1549
1549
  super(e), this.name = "TenantNamespaceUnresolved";
1550
1550
  }
1551
- }, Cn = class extends Error {
1551
+ }, Sn = class extends Error {
1552
1552
  _tag = "TenantNamespaceInvalid";
1553
1553
  constructor(e) {
1554
1554
  super(e), this.name = "TenantNamespaceInvalid";
1555
1555
  }
1556
- }, wn = 63, Tn = "tenant_", En = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Dn = (e) => {
1557
- if (e == null || e === "") throw new Sn("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.");
1558
- let t = En(e);
1559
- if (t.replace(/_/g, "") === "") throw new Cn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
1560
- let n = `${Tn}${t}`;
1561
- if (n.length > wn) throw new Cn(`namespace '${n}' for tenant '${e}' exceeds the ${wn}-byte identifier limit. Use a shorter tenant id.`);
1556
+ }, Cn = 63, wn = "tenant_", Tn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), En = (e) => {
1557
+ if (e == null || e === "") throw new xn("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.");
1558
+ let t = Tn(e);
1559
+ if (t.replace(/_/g, "") === "") throw new Sn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
1560
+ let n = `${wn}${t}`;
1561
+ if (n.length > Cn) throw new Sn(`namespace '${n}' for tenant '${e}' exceeds the ${Cn}-byte identifier limit. Use a shorter tenant id.`);
1562
1562
  return n;
1563
- }, G = (e, t) => e === null ? t : `${e}.${t}`, On = /* @__PURE__ */ new Set(["timestamp", "date"]), kn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, An = (e, t) => {
1564
- if (e === void 0 || t == null || !On.has(e) || t instanceof Date) return t;
1563
+ }, q = (e, t) => e === null ? t : `${e}.${t}`, Dn = /* @__PURE__ */ new Set(["timestamp", "date"]), On = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, kn = (e, t) => {
1564
+ if (e === void 0 || t == null || !Dn.has(e) || t instanceof Date) return t;
1565
1565
  if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
1566
- if (typeof t == "string" && kn.test(t)) {
1566
+ if (typeof t == "string" && On.test(t)) {
1567
1567
  let e = new Date(t);
1568
1568
  return Number.isNaN(e.getTime()) ? t : e;
1569
1569
  }
1570
1570
  return t;
1571
- }, jn = (e, t) => e === void 0 || !On.has(e) ? t : t.map((t) => An(e, t)), Mn = (e, t) => {
1571
+ }, An = (e, t) => e === void 0 || !Dn.has(e) ? t : t.map((t) => kn(e, t)), jn = (e, t) => {
1572
1572
  let n = e.lastIndexOf("."), r = n < 0 ? e : e.slice(n + 1), i = n < 0 ? void 0 : e.slice(0, n), a = i === void 0 || i === t.alias || i === t.table, o = a ? void 0 : t.joins?.find((e) => e.alias === i), s = a ? t.table : o?.table, c = a ? t.sourceTable : o?.sourceTable;
1573
- return (c?.tableName === s ? c : s === void 0 ? void 0 : R(s))?.fields[r];
1574
- }, Nn = (e, t) => {
1573
+ return (c?.tableName === s ? c : s === void 0 ? void 0 : B(s))?.fields[r];
1574
+ }, Mn = (e, t) => {
1575
1575
  let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
1576
1576
  for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
1577
1577
  return t`${i}`;
1578
- }, K = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), q = (e, t, n = null, r) => {
1579
- if ("not" in e) return t`NOT (${q(e.not, t, n, r)})`;
1580
- if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => q(e, t, n, r)));
1581
- if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => q(e, t, n, r)));
1578
+ }, J = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), Y = (e, t, n = null, r) => {
1579
+ if ("not" in e) return t`NOT (${Y(e.not, t, n, r)})`;
1580
+ if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => Y(e, t, n, r)));
1581
+ if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => Y(e, t, n, r)));
1582
1582
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
1583
- let r = e, i = Y(r.subquery, t, n);
1583
+ let r = e, i = Z(r.subquery, t, n);
1584
1584
  return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
1585
1585
  }
1586
1586
  if (e.op === "exists" || e.op === "not-exists") {
1587
- let r = e, i = Y(r.subquery, t, n);
1587
+ let r = e, i = Z(r.subquery, t, n);
1588
1588
  return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
1589
1589
  }
1590
1590
  let i = e;
1591
- if (U(i.value)) {
1592
- if (!_n.some((e) => e === i.op) || i.path !== void 0) throw E("Column references require a scalar comparison without a JSON path");
1591
+ if (G(i.value)) {
1592
+ if (!gn.some((e) => e === i.op) || i.path !== void 0) throw E("Column references require a scalar comparison without a JSON path");
1593
1593
  let e = t(i.value.column), n = t(i.column);
1594
1594
  switch (i.op) {
1595
1595
  case "eq": return t`${n} = ${e}`;
@@ -1601,19 +1601,19 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1601
1601
  }
1602
1602
  }
1603
1603
  let a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
1604
- mysql: () => t.unsafe(W(i.column, o, "mysql")),
1605
- mssql: () => t.unsafe(W(i.column, o, "mssql")),
1606
- sqlite: () => t.unsafe(W(i.column, o, "sqlite")),
1607
- orElse: () => t.unsafe(W(i.column, o, "postgres"))
1604
+ mysql: () => t.unsafe(K(i.column, o, "mysql")),
1605
+ mssql: () => t.unsafe(K(i.column, o, "mssql")),
1606
+ sqlite: () => t.unsafe(K(i.column, o, "sqlite")),
1607
+ orElse: () => t.unsafe(K(i.column, o, "postgres"))
1608
1608
  }), l = () => t.onDialectOrElse({
1609
- mysql: () => t.unsafe(W(i.column, o, "mysql", { numeric: !0 })),
1610
- mssql: () => t.unsafe(W(i.column, o, "mssql", { numeric: !0 })),
1611
- sqlite: () => t.unsafe(W(i.column, o, "sqlite", { numeric: !0 })),
1612
- orElse: () => t.unsafe(W(i.column, o, "postgres", { numeric: !0 }))
1613
- }), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : R(r)?.fields?.[i.column]?.type, h = (e) => {
1614
- let n = An(m, e);
1609
+ mysql: () => t.unsafe(K(i.column, o, "mysql", { numeric: !0 })),
1610
+ mssql: () => t.unsafe(K(i.column, o, "mssql", { numeric: !0 })),
1611
+ sqlite: () => t.unsafe(K(i.column, o, "sqlite", { numeric: !0 })),
1612
+ orElse: () => t.unsafe(K(i.column, o, "postgres", { numeric: !0 }))
1613
+ }), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : B(r)?.fields?.[i.column]?.type, h = (e) => {
1614
+ let n = kn(m, e);
1615
1615
  return n instanceof Date ? t.onDialectOrElse({
1616
- sqlite: () => vn(n),
1616
+ sqlite: () => _n(n),
1617
1617
  orElse: () => n
1618
1618
  }) : n;
1619
1619
  };
@@ -1633,7 +1633,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1633
1633
  return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e.map(h))}`;
1634
1634
  }
1635
1635
  case "contains": {
1636
- let e = `%${K(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
1636
+ let e = `%${J(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
1637
1637
  return t.onDialectOrElse({
1638
1638
  mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
1639
1639
  mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
@@ -1642,7 +1642,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1642
1642
  });
1643
1643
  }
1644
1644
  case "startsWith": {
1645
- let e = `${K(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
1645
+ let e = `${J(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
1646
1646
  return t.onDialectOrElse({
1647
1647
  mysql: () => t`${u} LIKE ${e}`,
1648
1648
  orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
@@ -1690,13 +1690,13 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1690
1690
  });
1691
1691
  }
1692
1692
  }
1693
- }, Pn = (e, t) => {
1693
+ }, Nn = (e, t) => {
1694
1694
  let n = [];
1695
1695
  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}`);
1696
- }, Fn = (e, t) => t.csv(e.map((e) => {
1696
+ }, Pn = (e, t) => t.csv(e.map((e) => {
1697
1697
  let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
1698
1698
  if (e.op.startsWith("window-")) {
1699
- let r = Pn(e.window ?? {}, t);
1699
+ let r = Nn(e.window ?? {}, t);
1700
1700
  switch (e.op) {
1701
1701
  case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
1702
1702
  case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
@@ -1720,58 +1720,58 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1720
1720
  return t`${t(e.column)} AS ${t(e.alias)}`;
1721
1721
  default: throw E(`compileAggregateProjection: unknown op '${e.op}'`);
1722
1722
  }
1723
- })), In = (e) => `[${e.join(",")}]`, Ln = (e, t) => {
1723
+ })), Fn = (e) => `[${e.join(",")}]`, In = (e, t) => {
1724
1724
  if (e.queryVector === void 0) return null;
1725
- let n = t(e.column), r = In(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
1725
+ let n = t(e.column), r = Fn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
1726
1726
  return t.onDialectOrElse({
1727
1727
  mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
1728
1728
  mssql: () => t`NULL`,
1729
1729
  sqlite: () => t`NULL`,
1730
1730
  orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
1731
1731
  });
1732
- }, Rn = (e, t) => {
1732
+ }, Ln = (e, t) => {
1733
1733
  let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
1734
1734
  return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
1735
- }, zn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, J = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Bn = (e, t) => `${t}_${e.indexName}_fts`, Vn = (e) => e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((e) => e !== ""), Hn = (e) => {
1735
+ }, Rn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, X = (e, t) => t`${t(`${e.indexName}_tsv`)}`, zn = (e, t) => `${t}_${e.indexName}_fts`, Bn = (e) => e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((e) => e !== ""), Vn = (e) => {
1736
1736
  if (e.prefix !== !0) return;
1737
- let t = Vn(e.query);
1737
+ let t = Bn(e.query);
1738
1738
  if (t.length !== 0) return {
1739
1739
  pg: t.map((e) => `${e}:*`).join(" & "),
1740
1740
  mysql: t.map((e) => `+${e}*`).join(" "),
1741
1741
  sqlite: t.map((e) => `"${e}"*`).join(" ")
1742
1742
  };
1743
- }, Un = (e, t, n) => {
1744
- let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${K(e.query)}%`, a = Hn(e), o = () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`));
1743
+ }, Hn = (e, t, n) => {
1744
+ let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${J(e.query)}%`, a = Vn(e), o = () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`));
1745
1745
  return e.fallback === "like" ? o() : n.onDialectOrElse({
1746
1746
  mysql: () => a === void 0 ? n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)` : n`MATCH(${r}) AGAINST(${a.mysql} IN BOOLEAN MODE)`,
1747
1747
  sqlite: () => {
1748
- let r = n(Bn(e, t));
1748
+ let r = n(zn(e, t));
1749
1749
  return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${a?.sqlite ?? e.query})`;
1750
1750
  },
1751
1751
  mssql: o,
1752
- orElse: () => a === void 0 ? n`${J(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})` : n`${J(e, n)} @@ to_tsquery(${e.config ?? "english"}, ${a.pg})`
1752
+ orElse: () => a === void 0 ? n`${X(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})` : n`${X(e, n)} @@ to_tsquery(${e.config ?? "english"}, ${a.pg})`
1753
1753
  });
1754
- }, Wn = (e, t, n) => {
1755
- let r = `%${K(e.query)}%`, i = Hn(e), a = () => 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}`);
1754
+ }, Un = (e, t, n) => {
1755
+ let r = `%${J(e.query)}%`, i = Vn(e), a = () => 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}`);
1756
1756
  return e.fallback === "like" ? a() : n.onDialectOrElse({
1757
1757
  mysql: () => i === void 0 ? n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)` : n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${i.mysql} IN BOOLEAN MODE)`,
1758
1758
  sqlite: () => {
1759
- let r = n(Bn(e, t));
1759
+ let r = n(zn(e, t));
1760
1760
  return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${i?.sqlite ?? e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
1761
1761
  },
1762
1762
  mssql: a,
1763
- orElse: () => i === void 0 ? n`ts_rank(${J(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))` : n`ts_rank(${J(e, n)}, to_tsquery(${e.config ?? "english"}, ${i.pg}))`
1763
+ orElse: () => i === void 0 ? n`ts_rank(${X(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))` : n`ts_rank(${X(e, n)}, to_tsquery(${e.config ?? "english"}, ${i.pg}))`
1764
1764
  });
1765
- }, Gn = (e, t, n, r) => {
1765
+ }, Wn = (e, t, n, r) => {
1766
1766
  let i = (e) => t(r && !e.includes(".") ? `${r}.${e}` : e), a = () => n?.length ? t.csv(n.map((e) => t`${i(e)}`)) : r ? t`${t(r)}.*` : t`*`;
1767
1767
  return !e || !Object.values(e).some((e) => e.type === "bigint") ? a() : t.onDialectOrElse({
1768
1768
  sqlite: () => t.csv((n?.length ? n : Object.keys(e)).map((n) => e[n]?.type === "bigint" ? t`CAST(${i(n)} AS TEXT) AS ${t(n)}` : t`${i(n)}`)),
1769
1769
  orElse: a
1770
1770
  });
1771
- }, Kn = (e, t, n) => Gn(R(e)?.fields, t, n), Y = (e, t, n = null) => {
1771
+ }, Gn = (e, t, n) => Wn(B(e)?.fields, t, n), Z = (e, t, n = null) => {
1772
1772
  if (e.setOp && e.setOp.queries.length >= 2) {
1773
- 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`(${Y(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
1774
- if (z(e).length > 0 && a.push(t` ORDER BY ${t.csv(z(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
1773
+ 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`(${Z(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
1774
+ if (V(e).length > 0 && a.push(t` ORDER BY ${t.csv(V(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
1775
1775
  if (!Number.isInteger(e.take) || e.take < 0) throw E(`compileSelect: invalid take ${e.take}`);
1776
1776
  a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
1777
1777
  }
@@ -1781,7 +1781,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1781
1781
  }
1782
1782
  return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
1783
1783
  }
1784
- let r = e.annClause === void 0 ? null : Ln(e.annClause, t);
1784
+ let r = e.annClause === void 0 ? null : In(e.annClause, t);
1785
1785
  e.spatialClause !== void 0 && t.onDialectOrElse({
1786
1786
  mysql: () => {
1787
1787
  throw E("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
@@ -1794,13 +1794,13 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1794
1794
  },
1795
1795
  orElse: () => t``
1796
1796
  });
1797
- let i = e.spatialClause?.projectAs === void 0 ? null : Rn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Fn(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((n) => {
1797
+ let i = e.spatialClause?.projectAs === void 0 ? null : Ln(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Pn(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((n) => {
1798
1798
  let r = t`${t(n.source)}`;
1799
- return t`${Mn(n.source, e)?.type === "bigint" ? t.onDialectOrElse({
1799
+ return t`${jn(n.source, e)?.type === "bigint" ? t.onDialectOrElse({
1800
1800
  sqlite: () => t`CAST(${r} AS TEXT)`,
1801
1801
  orElse: () => r
1802
1802
  }) : r} AS ${t(n.outputKey)}`;
1803
- })) : Gn((e.sourceTable?.tableName === e.table ? e.sourceTable : R(e.table))?.fields, t, e.projection, (e.joins?.length ?? 0) > 0 ? e.alias ?? e.table : void 0), 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 ? Wn(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({
1803
+ })) : Wn((e.sourceTable?.tableName === e.table ? e.sourceTable : B(e.table))?.fields, t, e.projection, (e.joins?.length ?? 0) > 0 ? e.alias ?? e.table : void 0), 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 ? Un(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({
1804
1804
  orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
1805
1805
  mysql: () => t`DISTINCT `,
1806
1806
  mssql: () => t`DISTINCT `,
@@ -1812,13 +1812,13 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1812
1812
  mssql: () => t``,
1813
1813
  sqlite: () => t``,
1814
1814
  orElse: () => t` FOR UPDATE`
1815
- }) : t``, g = e.alias === void 0 ? t`${t(G(n, e.table))}${m}` : t`${t(G(n, e.table))} AS ${t(e.alias)}${m}`, ee = (e.joins ?? []).map((e) => {
1815
+ }) : t``, g = e.alias === void 0 ? t`${t(q(n, e.table))}${m}` : t`${t(q(n, e.table))} AS ${t(e.alias)}${m}`, ee = (e.joins ?? []).map((e) => {
1816
1816
  let r = e.kind === "inner" ? "INNER" : "LEFT";
1817
- return t` ${t.unsafe(r)} JOIN ${t(G(n, e.table))} AS ${t(e.alias)} ON ${q(e.on, t, n)}`;
1818
- }), te = ee.length > 0 ? ee.reduce((e, n) => t`${e}${n}`, g) : g, ne = c === void 0 ? null : Un(c, e.table, t), _ = [e.predicate ? q(e.predicate, t, n, e.table) : null, ne].filter((e) => e !== null), v = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, re = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, y = e.having ? t` HAVING ${q(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
1819
- r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${zn(e.spatialClause, t)} DESC` : t`${zn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
1820
- for (let n of z(e)) {
1821
- let r = e.joinedProjection?.find((e) => e.outputKey === n.column)?.source ?? n.column, i = !o && Mn(r, e)?.type === "bigint" ? t.onDialectOrElse({
1817
+ return t` ${t.unsafe(r)} JOIN ${t(q(n, e.table))} AS ${t(e.alias)} ON ${Y(e.on, t, n)}`;
1818
+ }), te = ee.length > 0 ? ee.reduce((e, n) => t`${e}${n}`, g) : g, ne = c === void 0 ? null : Hn(c, e.table, t), _ = [e.predicate ? Y(e.predicate, t, n, e.table) : null, ne].filter((e) => e !== null), v = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, re = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, y = e.having ? t` HAVING ${Y(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
1819
+ r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${Rn(e.spatialClause, t)} DESC` : t`${Rn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
1820
+ for (let n of V(e)) {
1821
+ let r = e.joinedProjection?.find((e) => e.outputKey === n.column)?.source ?? n.column, i = !o && jn(r, e)?.type === "bigint" ? t.onDialectOrElse({
1822
1822
  sqlite: () => t`${t(r.includes(".") ? r : `${e.alias ?? e.table}.${r}`)}`,
1823
1823
  orElse: () => t`${t(n.column)}`
1824
1824
  }) : t`${t(n.column)}`;
@@ -1830,7 +1830,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1830
1830
  }) : t``, S = (e) => {
1831
1831
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw E(`compileSelect: expected non-negative integer take/skip, got ${e}`);
1832
1832
  return t.unsafe(String(e));
1833
- }, ae = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${Y(e.descriptor, t, n)})`), oe = (e.ctes ?? []).some((e) => e.recursive === !0), se = ae.length > 0 ? t`WITH ${t.unsafe(oe ? "RECURSIVE " : "")}${t.csv(ae)} ` : t``;
1833
+ }, ae = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${Z(e.descriptor, t, n)})`), oe = (e.ctes ?? []).some((e) => e.recursive === !0), se = ae.length > 0 ? t`WITH ${t.unsafe(oe ? "RECURSIVE " : "")}${t.csv(ae)} ` : t``;
1834
1834
  return t.onDialectOrElse({
1835
1835
  mssql: () => {
1836
1836
  let n = e.take !== void 0 && !b ? t`TOP ${S(e.take)} ` : t``, r = b ? t` OFFSET ${S(e.skip)} ROWS FETCH NEXT ${S(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
@@ -1845,7 +1845,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1845
1845
  return t`${se}SELECT ${f}${d} FROM ${te}${v}${re}${y}${ie}${n}${r}${h}`;
1846
1846
  }
1847
1847
  });
1848
- }, X = (e, t) => {
1848
+ }, Q = (e, t) => {
1849
1849
  let n = (e) => {
1850
1850
  if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
1851
1851
  let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
@@ -1863,73 +1863,73 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1863
1863
  a = t === n ? 0 : t > n ? 1 : -1;
1864
1864
  }
1865
1865
  return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
1866
- }, qn = (e, t) => ({
1866
+ }, Kn = (e, t) => ({
1867
1867
  column: e,
1868
1868
  op: "eq",
1869
1869
  value: t
1870
- }), Jn = (e, t) => ({
1870
+ }), qn = (e, t) => ({
1871
1871
  column: e,
1872
1872
  op: "neq",
1873
1873
  value: t
1874
- }), Yn = (e, t) => ({
1874
+ }), Jn = (e, t) => ({
1875
1875
  column: e,
1876
1876
  op: "gt",
1877
1877
  value: t
1878
- }), Xn = (e, t) => ({
1878
+ }), Yn = (e, t) => ({
1879
1879
  column: e,
1880
1880
  op: "gte",
1881
1881
  value: t
1882
- }), Zn = (e, t) => ({
1882
+ }), Xn = (e, t) => ({
1883
1883
  column: e,
1884
1884
  op: "lt",
1885
1885
  value: t
1886
- }), Qn = (e, t) => ({
1886
+ }), Zn = (e, t) => ({
1887
1887
  column: e,
1888
1888
  op: "lte",
1889
1889
  value: t
1890
- }), $n = (e, t) => ({
1890
+ }), Qn = (e, t) => ({
1891
1891
  column: e,
1892
1892
  op: "in",
1893
1893
  value: t
1894
- }), er = (e, t) => ({
1894
+ }), $n = (e, t) => ({
1895
1895
  column: e,
1896
1896
  op: "notIn",
1897
1897
  value: t
1898
- }), tr = (e, t) => ({
1898
+ }), er = (e, t) => ({
1899
1899
  column: e,
1900
1900
  op: "contains",
1901
1901
  value: t
1902
- }), nr = (e, t) => ({
1902
+ }), tr = (e, t) => ({
1903
1903
  column: e,
1904
1904
  op: "startsWith",
1905
1905
  value: t
1906
- }), rr = (e, t) => ({
1906
+ }), nr = (e, t) => ({
1907
1907
  column: e,
1908
1908
  op: "arrayContains",
1909
1909
  value: t
1910
- }), ir = (e, t) => ({
1910
+ }), rr = (e, t) => ({
1911
1911
  column: e,
1912
1912
  op: "arrayOverlaps",
1913
1913
  value: t
1914
- }), ar = (e, t) => ({
1914
+ }), ir = (e, t) => ({
1915
1915
  column: e,
1916
1916
  op: "arrayHas",
1917
1917
  value: t
1918
- }), or = {
1918
+ }), ar = {
1919
1919
  column: "id",
1920
1920
  op: "in",
1921
1921
  value: []
1922
- }, sr = (e) => ({
1922
+ }, or = (e) => ({
1923
1923
  column: e,
1924
1924
  op: "isNull"
1925
- }), cr = (e) => ({
1925
+ }), sr = (e) => ({
1926
1926
  column: e,
1927
1927
  op: "isNotNull"
1928
- }), lr = (e, t) => ({
1928
+ }), cr = (e, t) => ({
1929
1929
  column: e,
1930
1930
  op: "spatial",
1931
1931
  value: t
1932
- }), ur = (...e) => ({ and: e }), dr = (...e) => ({ or: e }), fr = (e) => ({ not: e }), pr = (e, ...t) => {
1932
+ }), lr = (...e) => ({ and: e }), ur = (...e) => ({ or: e }), dr = (e) => ({ not: e }), fr = (e, ...t) => {
1933
1933
  if (t.length === 0) throw E(`jsonField("${e}"): at least one path segment is required`);
1934
1934
  let n = (n, r) => ({
1935
1935
  column: e,
@@ -1951,50 +1951,50 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
1951
1951
  isNull: () => n("isNull"),
1952
1952
  isNotNull: () => n("isNotNull")
1953
1953
  };
1954
- }, Z = (e) => "descriptor" in e ? e.descriptor : e, mr = (e, t) => ({
1954
+ }, $ = (e) => "descriptor" in e ? e.descriptor : e, pr = (e, t) => ({
1955
1955
  column: e,
1956
1956
  op: "subquery-in",
1957
- subquery: Z(t)
1958
- }), hr = (e, t) => ({
1957
+ subquery: $(t)
1958
+ }), mr = (e, t) => ({
1959
1959
  column: e,
1960
1960
  op: "subquery-not-in",
1961
- subquery: Z(t)
1962
- }), gr = (e) => ({
1961
+ subquery: $(t)
1962
+ }), hr = (e) => ({
1963
1963
  op: "exists",
1964
- subquery: Z(e)
1965
- }), _r = (e) => ({
1964
+ subquery: $(e)
1965
+ }), gr = (e) => ({
1966
1966
  op: "not-exists",
1967
- subquery: Z(e)
1968
- }), vr = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, yr = (e) => {
1967
+ subquery: $(e)
1968
+ }), _r = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, vr = (e) => {
1969
1969
  if (e instanceof Date) return e.getTime();
1970
- if (typeof e == "string" && vr.test(e)) {
1970
+ if (typeof e == "string" && _r.test(e)) {
1971
1971
  let t = Date.parse(e);
1972
1972
  return Number.isNaN(t) ? void 0 : t;
1973
1973
  }
1974
- }, br = (e, t) => {
1974
+ }, yr = (e, t) => {
1975
1975
  if (!(e instanceof Date) && !(t instanceof Date)) return;
1976
- let n = yr(e), r = yr(t);
1976
+ let n = vr(e), r = vr(t);
1977
1977
  return n === void 0 || r === void 0 ? void 0 : [n, r];
1978
- }, xr = (e, t) => {
1978
+ }, br = (e, t) => {
1979
1979
  if (e === t) return !0;
1980
- let n = br(e, t);
1980
+ let n = yr(e, t);
1981
1981
  return n !== void 0 && n[0] === n[1];
1982
- }, Sr = (e, t) => {
1982
+ }, xr = (e, t) => {
1983
1983
  if (e == null || t == null) return null;
1984
- let n = br(e, t);
1984
+ let n = yr(e, t);
1985
1985
  if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
1986
1986
  let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
1987
1987
  return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
1988
- }, Cr = (e, t, n = null, r = {}) => Q(e, t, n, r) === !0, Q = (e, t, n = null, r = {}) => {
1988
+ }, Sr = (e, t, n = null, r = {}) => Cr(e, t, n, r) === !0, Cr = (e, t, n = null, r = {}) => {
1989
1989
  if (!t) return !1;
1990
1990
  if ("not" in e) {
1991
- let i = Q(e.not, t, n, r);
1991
+ let i = Cr(e.not, t, n, r);
1992
1992
  return i === null ? null : !i;
1993
1993
  }
1994
1994
  if ("and" in e) {
1995
1995
  let i = !1;
1996
1996
  for (let a of e.and) {
1997
- let e = Q(a, t, n, r);
1997
+ let e = Cr(a, t, n, r);
1998
1998
  if (e === !1) return !1;
1999
1999
  e === null && (i = !0);
2000
2000
  }
@@ -2003,7 +2003,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2003
2003
  if ("or" in e) {
2004
2004
  let i = !1;
2005
2005
  for (let a of e.or) {
2006
- let e = Q(a, t, n, r);
2006
+ let e = Cr(a, t, n, r);
2007
2007
  if (e === !0) return !0;
2008
2008
  e === null && (i = !0);
2009
2009
  }
@@ -2013,7 +2013,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2013
2013
  if (!n) return !1;
2014
2014
  let i = n.get(e.subquery);
2015
2015
  if (!(i instanceof Set)) return !1;
2016
- let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => X(a, e) === 0) : i.has(a);
2016
+ let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => Q(a, e) === 0) : i.has(a);
2017
2017
  return e.op === "subquery-in" ? o : !o;
2018
2018
  }
2019
2019
  if (e.op === "exists" || e.op === "not-exists") {
@@ -2021,11 +2021,11 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2021
2021
  let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
2022
2022
  return e.op === "exists" ? r : !r;
2023
2023
  }
2024
- let i = e, a = t[i.column], o = U(i.value) ? i.value : void 0;
2025
- if (o !== void 0 && (!_n.some((e) => e === i.op) || i.path !== void 0)) throw E("Column references require a scalar comparison without a JSON path");
2024
+ let i = e, a = t[i.column], o = G(i.value) ? i.value : void 0;
2025
+ if (o !== void 0 && (!gn.some((e) => e === i.op) || i.path !== void 0)) throw E("Column references require a scalar comparison without a JSON path");
2026
2026
  let s = o === void 0 ? i.value : t[o.column];
2027
2027
  if (o !== void 0 && (a == null || s == null)) return null;
2028
- let c = r[i.column]?.type === "decimal", l = (e, t) => c && e != null && t != null ? X(e, t) === 0 : xr(e, t), u = c ? X : Sr;
2028
+ let c = r[i.column]?.type === "decimal", l = (e, t) => c && e != null && t != null ? Q(e, t) === 0 : br(e, t), u = c ? Q : xr;
2029
2029
  switch (i.op) {
2030
2030
  case "eq": return l(a, s);
2031
2031
  case "neq": return !l(a, s);
@@ -2050,17 +2050,17 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2050
2050
  case "isNotNull": return a != null;
2051
2051
  case "spatial": throw E("@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.");
2052
2052
  }
2053
- }, $ = function* (e) {
2053
+ }, wr = function* (e) {
2054
2054
  if ("not" in e) {
2055
- yield* $(e.not);
2055
+ yield* wr(e.not);
2056
2056
  return;
2057
2057
  }
2058
2058
  if ("and" in e) {
2059
- for (let t of e.and) yield* $(t);
2059
+ for (let t of e.and) yield* wr(t);
2060
2060
  return;
2061
2061
  }
2062
2062
  if ("or" in e) {
2063
- for (let t of e.or) yield* $(t);
2063
+ for (let t of e.or) yield* wr(t);
2064
2064
  return;
2065
2065
  }
2066
2066
  e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
@@ -2070,30 +2070,30 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2070
2070
  kind: "exists",
2071
2071
  descriptor: e.subquery
2072
2072
  });
2073
- }, wr = function* (e, t = !0) {
2073
+ }, Tr = function* (e, t = !0) {
2074
2074
  if ("not" in e) {
2075
- yield* wr(e.not, !1);
2075
+ yield* Tr(e.not, !1);
2076
2076
  return;
2077
2077
  }
2078
2078
  if ("and" in e) {
2079
- for (let n of e.and) yield* wr(n, t);
2079
+ for (let n of e.and) yield* Tr(n, t);
2080
2080
  return;
2081
2081
  }
2082
2082
  if ("or" in e) {
2083
- for (let t of e.or) yield* wr(t, !1);
2083
+ for (let t of e.or) yield* Tr(t, !1);
2084
2084
  return;
2085
2085
  }
2086
2086
  e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
2087
2087
  ...e,
2088
- conjunctive: t && !U(e.value)
2088
+ conjunctive: t && !G(e.value)
2089
2089
  });
2090
- }, Tr = (e, t) => ({
2090
+ }, Er = (e, t) => ({
2091
2091
  name: e,
2092
2092
  body: t
2093
- }), Er = (e) => {
2093
+ }), Dr = (e) => {
2094
2094
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
2095
2095
  if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
2096
- let t = e.steps({ step: Tr });
2096
+ let t = e.steps({ step: Er });
2097
2097
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
2098
2098
  return {
2099
2099
  __seed: !0,
@@ -2106,76 +2106,76 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2106
2106
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
2107
2107
  steps: t
2108
2108
  };
2109
- }, Dr = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Or = null, kr = null, Ar = (e) => {
2110
- Or = e;
2111
- }, jr = (e) => {
2109
+ }, Or = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, kr = null, Ar = null, jr = (e) => {
2112
2110
  kr = e;
2113
- }, Mr = async (e) => {
2114
- let t = Or;
2115
- t !== null && await t(e);
2111
+ }, Mr = (e) => {
2112
+ Ar = e;
2116
2113
  }, Nr = async (e) => {
2117
2114
  let t = kr;
2115
+ t !== null && await t(e);
2116
+ }, Pr = async (e) => {
2117
+ let t = Ar;
2118
2118
  t !== null && e.changedTables.length !== 0 && await t(e);
2119
- }, Pr = ["before-schema", "after-schema"], Fr = (e) => {
2119
+ }, Fr = ["before-schema", "after-schema"], Ir = (e) => {
2120
2120
  if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
2121
2121
  if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
2122
- if (!Pr.includes(e.phase)) throw Error(`migration ${e.id}: \`phase\` is required and must be one of ${Pr.map((e) => `'${e}'`).join(" | ")} — 'before-schema' runs before the declarative apply (a shape change the planner must not compute against), 'after-schema' runs after it (a body that needs the new shape, such as a back-fill into a table this deploy creates)`);
2122
+ if (!Fr.includes(e.phase)) throw Error(`migration ${e.id}: \`phase\` is required and must be one of ${Fr.map((e) => `'${e}'`).join(" | ")} — 'before-schema' runs before the declarative apply (a shape change the planner must not compute against), 'after-schema' runs after it (a body that needs the new shape, such as a back-fill into a table this deploy creates)`);
2123
2123
  return e;
2124
- }, Ir = Symbol.for("voltro.migration.irreversible"), Lr = class extends Error {
2124
+ }, Lr = Symbol.for("voltro.migration.irreversible"), Rr = class extends Error {
2125
2125
  migrationId;
2126
2126
  reason;
2127
2127
  _tag = "IrreversibleMigrationError";
2128
2128
  constructor(e, t) {
2129
2129
  super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
2130
2130
  }
2131
- }, Rr = (e) => {
2132
- if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
2133
- return Object.assign(() => t.fail(new Lr("<unknown>", e)), { [Ir]: e });
2134
2131
  }, zr = (e) => {
2135
- let t = e[Ir];
2132
+ if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
2133
+ return Object.assign(() => t.fail(new Rr("<unknown>", e)), { [Lr]: e });
2134
+ }, Br = (e) => {
2135
+ let t = e[Lr];
2136
2136
  return typeof t == "string" ? t : void 0;
2137
- }, Br = class {
2137
+ }, Vr = class {
2138
2138
  reason;
2139
2139
  _tag = "MigrationSkipped";
2140
2140
  constructor(e) {
2141
2141
  this.reason = e;
2142
2142
  }
2143
- }, Vr = class extends Error {
2143
+ }, Hr = class extends Error {
2144
2144
  migrationId;
2145
2145
  failed;
2146
2146
  _tag = "MigrationExpectationFailed";
2147
2147
  constructor(e, t) {
2148
2148
  super(`migration ${e}: ${t.length} post-condition(s) did not hold after up():\n` + t.map((e) => ` - ${e}`).join("\n") + "\n The migration is NOT recorded; the next run applies it again."), this.migrationId = e, this.failed = t, this.name = "MigrationExpectationFailed";
2149
2149
  }
2150
- }, Hr = class extends Error {
2150
+ }, Ur = class extends Error {
2151
2151
  migrationId;
2152
2152
  dialect;
2153
2153
  _tag = "TransactionBrokenByBodyError";
2154
2154
  constructor(e, t) {
2155
2155
  super(`migration ${e} is transactional, and its body COMMITTED the transaction from inside — on ${t} a DDL statement commits everything before it. The work is in the database and the migration is recorded; it will not run again. What did not hold is the all-or-nothing guarantee. Either mark it \`transactional: false\` (per-statement, resumable through your own idempotency) or move the schema change into \`ctx.schema\` in a migration of its own and keep this one to data.`), this.migrationId = e, this.dialect = t, this.name = "TransactionBrokenByBodyError";
2156
2156
  }
2157
- }, Ur = class extends Error {
2157
+ }, Wr = class extends Error {
2158
2158
  migrationId;
2159
2159
  operation;
2160
2160
  _tag = "MigrationNeedsSqlClient";
2161
2161
  constructor(e, t, n) {
2162
2162
  super(`migration ${e}: ${t} — ${n}`), this.migrationId = e, this.operation = t, this.name = "MigrationNeedsSqlClient";
2163
2163
  }
2164
- }, Wr = class extends Error {
2164
+ }, Gr = class extends Error {
2165
2165
  table;
2166
2166
  report;
2167
2167
  _tag = "RewriteUnstableError";
2168
2168
  constructor(e, t) {
2169
2169
  super(`rewrite of ${e} did not stabilise after ${t.passes} pass(es): ${t.rewritten} rewritten, ${t.contended} contended on the last pass. Check for concurrent writes and guard values that cannot round-trip exactly before raising maxPasses.`), this.table = e, this.report = t, this.name = "RewriteUnstableError";
2170
2170
  }
2171
- }, Gr = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Kr = (e) => typeof e == "object" && !!e && "id" in e && "up" in e && "down" in e && typeof e.id == "string" && typeof e.up == "function" && typeof e.down == "function", qr = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Jr = (e) => qr.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), Yr = "_voltro_staging_", Xr = (e) => e.startsWith(Yr), Zr = /__dropped_\d{14}$/, Qr = (e) => Zr.test(e), $r = 7, ei = (e) => {
2171
+ }, Kr = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, qr = (e) => typeof e == "object" && !!e && "id" in e && "up" in e && "down" in e && typeof e.id == "string" && typeof e.up == "function" && typeof e.down == "function", Jr = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Yr = (e) => Jr.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), Xr = "_voltro_staging_", Zr = (e) => e.startsWith(Xr), Qr = /__dropped_\d{14}$/, $r = (e) => Qr.test(e), ei = 7, ti = (e) => {
2172
2172
  let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
2173
2173
  if (t === null) return;
2174
2174
  let [, n, r, i, a, o, s] = t;
2175
2175
  return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
2176
- }, ti = (e, t = {}) => {
2176
+ }, ni = (e, t = {}) => {
2177
2177
  let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
2178
- let a = ei(e);
2178
+ let a = ti(e);
2179
2179
  if (a === void 0) return;
2180
2180
  let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
2181
2181
  o >= r && i.push({
@@ -2184,12 +2184,12 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2184
2184
  ageDays: o
2185
2185
  });
2186
2186
  };
2187
- for (let t of e.tables) if (a(t.name, t.name), !Qr(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
2187
+ for (let t of e.tables) if (a(t.name, t.name), !$r(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
2188
2188
  return i;
2189
- }, ni = (e, t) => {
2189
+ }, ri = (e, t) => {
2190
2190
  let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
2191
2191
  return `${e.length} soft-drop snapshot(s) older than ${t} day(s) still hold the dropped data (oldest: ${n.name}, ${n.ageDays}d) — ${e.map((e) => e.name).join(", ")}. Restore with \`voltro db restore-snapshot\` or reclaim with \`voltro db gc-snapshots --before ${r}\`; the window is \`database.softDropRetentionDays\` in app.config.`;
2192
- }, ri = (e, t) => e.filter((e) => !Jr(e.name) || t.has(e.name)), ii = F("_voltro_migrations", {
2192
+ }, ii = (e, t) => e.filter((e) => !Yr(e.name) || t.has(e.name)), ai = L("_voltro_migrations", {
2193
2193
  id: f({ prefix: "mig" }),
2194
2194
  name: p(),
2195
2195
  hash: p(),
@@ -2201,7 +2201,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2201
2201
  workflowRunId: p().nullable(),
2202
2202
  createdAt: v().default("now"),
2203
2203
  updatedAt: v().default("now").onUpdate("now")
2204
- }).index(["status"]), ai = F("_voltro_seeds", {
2204
+ }).index(["status"]), oi = L("_voltro_seeds", {
2205
2205
  id: f({ prefix: "seed" }),
2206
2206
  name: p(),
2207
2207
  lifecycle: p(),
@@ -2217,19 +2217,19 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2217
2217
  workflowRunId: p().nullable(),
2218
2218
  createdAt: v().default("now"),
2219
2219
  updatedAt: v().default("now").onUpdate("now")
2220
- }).index(["lifecycle"]).index(["nextRunAt"]), oi = F("_voltro_schema_owner", {
2220
+ }).index(["lifecycle"]).index(["nextRunAt"]), si = L("_voltro_schema_owner", {
2221
2221
  id: f({ prefix: "own" }),
2222
2222
  appName: p(),
2223
2223
  projectName: p().nullable(),
2224
2224
  frameworkVersion: p().nullable(),
2225
2225
  claimedAt: v().default("now")
2226
- }), si = F("_voltro_plugin_migrations", {
2226
+ }), ci = L("_voltro_plugin_migrations", {
2227
2227
  id: f({ prefix: "plm" }),
2228
2228
  plugin_name: p(),
2229
2229
  migration_id: p(),
2230
2230
  description: p().nullable(),
2231
2231
  applied_at: p()
2232
- }), ci = F("_voltro_migration_plans", {
2232
+ }), li = L("_voltro_migration_plans", {
2233
2233
  id: f({ prefix: "plan" }),
2234
2234
  fingerprint: p(),
2235
2235
  liveFingerprint: p().nullable(),
@@ -2245,14 +2245,14 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2245
2245
  appliedAt: v().default("now"),
2246
2246
  createdAt: v().default("now"),
2247
2247
  updatedAt: v().default("now").onUpdate("now")
2248
- }).index(["fingerprint"]).index(["environment"]), li = F("_voltro_idempotency", {
2248
+ }).index(["fingerprint"]).index(["environment"]), ui = L("_voltro_idempotency", {
2249
2249
  id: f({ prefix: "idem" }),
2250
2250
  scope: p(),
2251
2251
  key: p(),
2252
2252
  status: p(),
2253
2253
  response: y().nullable(),
2254
2254
  createdAt: v().default("now")
2255
- }).unique(["scope", "key"]).index(["createdAt"]), ui = F("_voltro_devices", {
2255
+ }).unique(["scope", "key"]).index(["createdAt"]), di = L("_voltro_devices", {
2256
2256
  id: f({ prefix: "device" }),
2257
2257
  tenantId: p(),
2258
2258
  name: p(),
@@ -2272,20 +2272,20 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2272
2272
  createdBy: p().nullable(),
2273
2273
  metadata: y().nullable(),
2274
2274
  createdAt: v()
2275
- }).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), di = F("_voltro_tenant_selections", {
2275
+ }).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), fi = L("_voltro_tenant_selections", {
2276
2276
  id: f({ prefix: "tsel" }),
2277
2277
  subjectType: p().maxLength(32),
2278
2278
  subjectId: p(),
2279
2279
  tenantId: p(),
2280
2280
  selectedAt: v()
2281
- }).primaryKey(["id"]).nonReactive(), fi = F("_voltro_kv", {
2281
+ }).primaryKey(["id"]).nonReactive(), pi = L("_voltro_kv", {
2282
2282
  id: f({ prefix: "kv" }),
2283
2283
  key: p().unique(),
2284
2284
  value: p().nullable(),
2285
2285
  expiresAt: v().nullable(),
2286
2286
  createdAt: v().default("now"),
2287
2287
  updatedAt: v().default("now").onUpdate("now")
2288
- }).index(["expiresAt"]), pi = F("_voltro_api_keys", {
2288
+ }).index(["expiresAt"]), mi = L("_voltro_api_keys", {
2289
2289
  id: f({ prefix: "apikey" }),
2290
2290
  tenantId: p().nullable(),
2291
2291
  name: p(),
@@ -2300,7 +2300,7 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2300
2300
  onBehalfOf: p().nullable(),
2301
2301
  metadata: y().nullable(),
2302
2302
  createdAt: v().default("now")
2303
- }).index("byApiKeyTenant", ["tenantId"]), mi = F("_voltro_replica_observations", {
2303
+ }).index("byApiKeyTenant", ["tenantId"]), hi = L("_voltro_replica_observations", {
2304
2304
  id: f({ prefix: "robs" }),
2305
2305
  replicaId: p().maxLength(191),
2306
2306
  startedAt: v(),
@@ -2309,11 +2309,11 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2309
2309
  payload: p().nullable(),
2310
2310
  reachableAt: p().maxLength(255).nullable(),
2311
2311
  writtenAt: v().default("now").onUpdate("now")
2312
- }).unique(["replicaId", "kind"]).index(["kind"]), hi = [
2313
- ii,
2312
+ }).unique(["replicaId", "kind"]).index(["kind"]), gi = [
2314
2313
  ai,
2315
- ci
2316
- ], gi = "_voltro_replace_in_progress", _i = F(gi, {
2314
+ oi,
2315
+ li
2316
+ ], _i = "_voltro_replace_in_progress", vi = L(_i, {
2317
2317
  id: f({ prefix: "repl" }),
2318
2318
  startedAt: v().default("now"),
2319
2319
  kind: p().default("replace"),
@@ -2323,10 +2323,10 @@ var $t = (e, t, n) => en(e, "id", t, n), en = (e, t, n, r, i = "asc") => {
2323
2323
  staging: p().nullable(),
2324
2324
  heartbeatAt: v().nullable(),
2325
2325
  resumable: _().nullable()
2326
- }).nonReactive(), vi = 30, yi = (e, t) => {
2326
+ }).nonReactive(), yi = 30, bi = (e, t) => {
2327
2327
  let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
2328
2328
  return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
2329
- }, bi = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), xi = (e) => {
2329
+ }, xi = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), Si = (e) => {
2330
2330
  let t = e.filter((e) => e.kind !== "staging");
2331
2331
  if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
2332
2332
  ${t.map((e) => {
@@ -2341,7 +2341,7 @@ ${t.map((e) => {
2341
2341
 
2342
2342
  When the data is back, or you have decided the current state is correct, clear the marker:
2343
2343
  voltro data clear-replace-marker --yes`;
2344
- }, Si = (e, t, n) => {
2344
+ }, Ci = (e, t, n) => {
2345
2345
  let r = e.filter((e) => e.kind === "staging");
2346
2346
  return {
2347
2347
  all: r,
@@ -2351,7 +2351,7 @@ ${t.map((e) => {
2351
2351
  return Number.isFinite(r) ? t - r >= n : !1;
2352
2352
  })
2353
2353
  };
2354
- }, Ci = (e, t) => {
2354
+ }, wi = (e, t) => {
2355
2355
  if (e.all.length === 0) return;
2356
2356
  let n = new Set(e.droppable.map((e) => e.id));
2357
2357
  return `staged data-import leftovers:
@@ -2362,4 +2362,4 @@ ${e.all.map((e) => {
2362
2362
  a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
2363
2363
  };
2364
2364
  //#endregion
2365
- export { ir as $, Ie as $n, tn as $t, ei as A, ht as An, ue as Ar, jn as At, zr as B, ot as Bn, p as Br, dn as Bt, Yr as C, Et as Cn, ne as Cr, X as Ct, Qr as D, St as Dn, fe as Dr, Y as Dt, Jr as E, Ct as En, de as Er, Kn as Et, Ur as F, ut as Fn, c as Fr, En as Ft, Mr as G, M as Gn, an as Gt, Fr as H, Be as Hn, ce as Hr, fn as Ht, Br as I, ft as In, h as Ir, W as It, Ar as J, Ge as Jn, It as Jt, Dr as K, N as Kn, rn as Kt, Wr as L, st as Ln, oe as Lr, vn as Lt, Lr as M, F as Mn, C as Mr, Sn as Mt, Pr as N, mt as Nn, ee as Nr, G as Nt, Xr as O, xt as On, f as Or, K as Ot, Vr as P, dt as Pn, pe as Pr, Dn as Pt, ar as Q, Ne as Qn, Pt as Qt, Hr as R, lt as Rn, ae as Rr, gn as Rt, qr as S, Mt as Sn, re as Sr, wr as St, ni as T, At as Tn, se as Tr, Nn as Tt, Er as U, Ve as Un, hn as Ut, Kr as V, rt as Vn, v as Vr, pn as Vt, Nr as W, He as Wn, nn as Wt, ur as X, De as Xn, zt as Xt, or as Y, E as Yn, Xt as Yt, rr as Z, T as Zn, Nt as Zt, oi as _, Vt as _n, b as _r, er as _t, Ci as a, Rt as an, Te as ar, Yn as at, hi as b, Dt as bn, s as br, lr as bt, yi as c, en as cn, _e as cr, mr as ct, li as d, Gt as dn, he as dr, pr as dt, Kt as en, Le as er, $ as et, fi as f, Zt as fn, u as fr, Zn as ft, mi as g, Bt as gn, _ as gr, _r as gt, si as h, Yt as hn, te as hr, fr as ht, xi as i, Jt as in, Fe as ir, gr as it, Gr as j, pt as jn, y as jr, Cn as jt, ri as k, I as kn, m as kr, An as kt, pi as l, $t as ln, ve as lr, cr as lt, ii as m, Ft as mn, le as mr, Jn as mt, vi as n, Ht as nn, we as nr, qn as nt, Si as o, Lt as on, ye as or, Xn as ot, ci as p, Wt as pn, S as pr, Qn as pt, jr as q, j as qn, on as qt, _i as r, qt as rn, Pe as rr, Cr as rt, bi as s, z as sn, be as sr, $n as st, gi as t, Ut as tn, Re as tr, tr as tt, ui as u, Qt as un, ge as ur, sr as ut, ai as v, kt as vn, ie as vr, hr as vt, ti as w, Ot as wn, g as wr, q as wt, $r as x, R as xn, x as xr, nr as xt, di as y, jt as yn, l as yr, dr as yt, Rr as z, ct as zn, o as zr, U as zt };
2365
+ export { rr as $, Le as $n, en as $t, ti as A, mt as An, de as Ar, An as At, Br as B, at as Bn, o as Br, un as Bt, Xr as C, Tt as Cn, ne as Cr, Q as Ct, $r as D, xt as Dn, pe as Dr, Z as Dt, Yr as E, St as En, fe as Er, Gn as Et, Wr as F, lt as Fn, me as Fr, Tn as Ft, Nr as G, M as Gn, rn as Gt, Ir as H, Ve as Hn, v as Hr, dn as Ht, Vr as I, dt as In, c as Ir, K as It, jr as J, P as Jn, Ft as Jt, Or as K, N as Kn, nn as Kt, Gr as L, ot as Ln, h as Lr, _n as Lt, Rr as M, L as Mn, C as Mr, xn as Mt, Fr as N, pt as Nn, ee as Nr, q as Nt, Zr as O, bt as On, f as Or, J as Ot, Hr as P, ut as Pn, ce as Pr, En as Pt, ir as Q, Pe as Qn, Nt as Qt, Ur as R, ct as Rn, oe as Rr, hn as Rt, Jr as S, jt as Sn, re as Sr, Tr as St, ri as T, kt as Tn, se as Tr, Mn as Tt, Dr as U, He as Un, le as Ur, mn as Ut, qr as V, nt as Vn, p as Vr, fn as Vt, Pr as W, Ue as Wn, tn as Wt, lr as X, Oe as Xn, Rt as Xt, ar as Y, E as Yn, Yt, nr as Z, T as Zn, Mt as Zt, si as _, Bt as _n, b as _r, $n as _t, wi as a, Lt as an, Ee as ar, Jn as at, gi as b, Et as bn, s as br, cr as bt, bi as c, $t as cn, ve as cr, pr as ct, ui as d, Wt as dn, ge as dr, fr as dt, Gt as en, Re as er, wr as et, pi as f, Xt as fn, u as fr, Xn as ft, hi as g, zt as gn, _ as gr, gr as gt, ci as h, Jt as hn, te as hr, dr as ht, Si as i, qt as in, Ie as ir, hr as it, Kr as j, ft as jn, y as jr, Sn as jt, ii as k, R as kn, m as kr, kn as kt, mi as l, Qt as ln, ye as lr, sr as lt, ai as m, Pt as mn, ue as mr, qn as mt, yi as n, Vt as nn, Te as nr, Kn as nt, Ci as o, It as on, be as or, Yn as ot, li as p, Ut as pn, S as pr, Zn as pt, Mr as q, j as qn, an as qt, vi as r, Kt as rn, Fe as rr, Sr as rt, xi as s, V as sn, xe as sr, Qn as st, _i as t, Ht as tn, ze as tr, er as tt, di as u, Zt as un, _e as ur, or as ut, oi as v, Ot as vn, ie as vr, mr as vt, ni as w, Dt as wn, g as wr, Y as wt, ei as x, B as xn, x as xr, tr as xt, fi as y, At as yn, l as yr, ur as yt, zr as z, st as zn, ae as zr, G as zt };