@voltro/database 0.78.0 → 0.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -200,7 +200,7 @@ function f(e) {
200
200
  idSchemeInput: e
201
201
  });
202
202
  }
203
- var p = () => d("text"), m = () => d("integer"), h = () => d("real"), ee = (e, t = 0) => {
203
+ var p = () => d("text"), m = () => d("integer"), ee = () => d("real"), h = (e, t = 0) => {
204
204
  if (!Number.isInteger(e) || e <= 0) throw Error(`decimal(${String(e)}, ${String(t)}): precision must be a positive integer (the total number of significant digits, e.g. decimal(12, 2)).`);
205
205
  if (!Number.isInteger(t) || t < 0 || t > e) throw Error(`decimal(${String(e)}, ${String(t)}): scale must be an integer between 0 and precision (${e}).`);
206
206
  return new u({
@@ -211,7 +211,7 @@ var p = () => d("text"), m = () => d("integer"), h = () => d("real"), ee = (e, t
211
211
  precision: e,
212
212
  scale: t
213
213
  });
214
- }, te = ee, ne = () => d("bigint"), re = (e, t) => {
214
+ }, te = h, ne = () => d("bigint"), re = (e, t) => {
215
215
  if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
216
216
  return {
217
217
  name: e,
@@ -511,6 +511,12 @@ var ce = () => new u({
511
511
  let t = e.dbCode, n = e.dbErrno;
512
512
  return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
513
513
  }, Le = (e) => {
514
+ if (e.dbErrno !== 1366) return;
515
+ let t = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${typeof e.dbMessage == "string" ? e.dbMessage : ""}`;
516
+ if (/Incorrect string value: '\\x(F[0-4])/i.exec(t) === null) return;
517
+ let n = D(t, /for column [`']?(?:[^`'.]+[`']?\.[`']?)*([^`'.]+)[`']? at row/);
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
+ }, Re = (e) => {
514
520
  let t = Te(e), n = [
515
521
  t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
516
522
  t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
@@ -519,8 +525,10 @@ var ce = () => new u({
519
525
  t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}`,
520
526
  t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
521
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)}…`}` : "";
522
- if (a !== void 0 || n.length !== 0) return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + s + o;
523
- }, Re = (e) => Object.entries(e).map(([e, t]) => `${e}:${ze(t)}`).join(" "), ze = (e) => {
528
+ if (a === void 0 && n.length === 0) return;
529
+ let c = Le(t), l = c === void 0 ? "" : `\n hint: ${c}`;
530
+ return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + l + s + o;
531
+ }, ze = (e) => Object.entries(e).map(([e, t]) => `${e}:${Be(t)}`).join(" "), Be = (e) => {
524
532
  if (e === null) return "null";
525
533
  if (e === void 0) return "undefined";
526
534
  if (typeof e == "bigint") return "bigint";
@@ -530,22 +538,22 @@ var ce = () => new u({
530
538
  if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
531
539
  let t = e.constructor?.name;
532
540
  return typeof t == "string" && t !== "" ? t : "Object";
533
- }, Be = 63, Ve = 60, O = [], k = (e) => {
541
+ }, Ve = 63, He = 60, O = [], k = (e) => {
534
542
  O.includes(e) || O.push(e);
535
- }, He = () => {
543
+ }, Ue = () => {
536
544
  let e = O.slice();
537
545
  return O.length = 0, e;
538
- }, Ue = /^[a-zA-Z_][a-zA-Z0-9_]*$/, We = (e, t) => {
546
+ }, We = /^[a-zA-Z_][a-zA-Z0-9_]*$/, Ge = (e, t) => {
539
547
  if (t.length === 0) throw Error(`${e} cannot be empty.`);
540
- 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_]*$/.`);
541
549
  }, A = (e) => {
542
- 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.`);
543
551
  e.length > 60 && k(`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.`);
544
552
  }, j = (e, t) => {
545
- 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.`);
546
554
  t.length > 60 && k(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
547
555
  }, M = (e, t, n, r) => {
548
- 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.`);
549
557
  t.length > 60 && k(`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.` : ""}`);
550
558
  }, N = (e, t) => {
551
559
  if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
@@ -558,29 +566,29 @@ var ce = () => new u({
558
566
  throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
559
567
  }
560
568
  e.length > 60 && k(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — close to the 63-byte limit. Generated ids will be even longer (prefix + '_' + 26).`);
561
- }, Ge = 1704067200000n, Ke = 10n, qe = 12n, Je = (1n << Ke) - 1n, Ye = (1n << qe) - 1n, Xe = qe, Ze = 22n, Qe = () => {
569
+ }, Ke = 1704067200000n, qe = 10n, Je = 12n, Ye = (1n << qe) - 1n, Xe = (1n << Je) - 1n, Ze = Je, Qe = 22n, $e = () => {
562
570
  let e = process.env.SNOWFLAKE_MACHINE_ID;
563
571
  if (e === void 0 || e === "") return 0n;
564
572
  let t = BigInt(e);
565
- if (t < 0n || t > Je) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${Je}.`);
573
+ if (t < 0n || t > Ye) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${Ye}.`);
566
574
  return t;
567
- }, $e = () => ({
575
+ }, et = () => ({
568
576
  lastMs: 0n,
569
577
  sequence: 0n,
570
- machineId: Qe()
571
- }), P, et = () => (P === void 0 && (P = $e()), P), tt = () => {
572
- P = $e();
573
- }, nt = () => BigInt(Date.now()), rt = (e) => {
574
- let t = nt();
575
- for (; t <= e;) t = nt();
578
+ machineId: $e()
579
+ }), P, tt = () => (P === void 0 && (P = et()), P), nt = () => {
580
+ P = et();
581
+ }, rt = () => BigInt(Date.now()), it = (e) => {
582
+ let t = rt();
583
+ for (; t <= e;) t = rt();
576
584
  return t;
577
- }, it = () => {
578
- let e = et(), t = nt();
579
- t === e.lastMs ? (e.sequence = e.sequence + 1n & Ye, e.sequence === 0n && (t = rt(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
580
- let n = t - Ge;
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
+ let n = t - Ke;
581
589
  if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
582
- return (n << Ze | e.machineId << Xe | e.sequence).toString();
583
- }, at = (e) => {
590
+ return (n << Qe | e.machineId << Ze | e.sequence).toString();
591
+ }, ot = (e) => {
584
592
  let t = e.toLowerCase();
585
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.`);
586
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: '...' }).`);
@@ -589,10 +597,10 @@ var ce = () => new u({
589
597
  kind: "derived",
590
598
  tableName: e
591
599
  }), n;
592
- }, ot = (e, t) => {
600
+ }, st = (e, t) => {
593
601
  if (e === void 0) return {
594
602
  kind: "typeid",
595
- prefix: at(t)
603
+ prefix: ot(t)
596
604
  };
597
605
  if ("prefix" in e && !("scheme" in e)) return N(e.prefix, {
598
606
  kind: "explicit",
@@ -604,7 +612,7 @@ var ce = () => new u({
604
612
  if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
605
613
  switch (e.scheme) {
606
614
  case "typeid": {
607
- let n = e.prefix ?? at(t);
615
+ let n = e.prefix ?? ot(t);
608
616
  return e.prefix !== void 0 && N(e.prefix, {
609
617
  kind: "explicit",
610
618
  tableName: t
@@ -621,22 +629,22 @@ var ce = () => new u({
621
629
  generate: e.generate
622
630
  };
623
631
  }
624
- }, st = (e, t) => {
632
+ }, ct = (e, t) => {
625
633
  switch (e.kind) {
626
634
  case "typeid": return i(e.prefix).toString();
627
635
  case "ulid": return a();
628
636
  case "numeric": return null;
629
- case "snowflake": return it();
637
+ case "snowflake": return at();
630
638
  case "custom": return e.generate(t);
631
639
  }
632
- }, ct = (e) => ({
640
+ }, lt = (e) => ({
633
641
  fields: S(e.fields),
634
642
  ...e.id === void 0 ? {} : { id: e.id },
635
643
  ...e.requires === void 0 ? {} : { requires: e.requires },
636
644
  ...e.indexes === void 0 ? {} : { indexes: e.indexes },
637
645
  ...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
638
646
  ...e.policies === void 0 ? {} : { policies: e.policies }
639
- }), lt = ct, ut = (e) => {
647
+ }), ut = lt, dt = (e) => {
640
648
  let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
641
649
  let i = e.id ?? e;
642
650
  if (!t.has(i)) {
@@ -646,7 +654,7 @@ var ce = () => new u({
646
654
  };
647
655
  for (let t of e) r(t);
648
656
  return n;
649
- }, dt = (e, ...t) => {
657
+ }, ft = (e, ...t) => {
650
658
  if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
651
659
  let n = (r) => ({
652
660
  jsonPath: {
@@ -657,14 +665,14 @@ var ce = () => new u({
657
665
  numeric: () => n(!0)
658
666
  });
659
667
  return n(!1);
660
- }, ft = (e = "cosine", t = "float32") => {
668
+ }, pt = (e = "cosine", t = "float32") => {
661
669
  let n = t === "half" ? "halfvec" : "vector";
662
670
  switch (e) {
663
671
  case "cosine": return `${n}_cosine_ops`;
664
672
  case "l2": return `${n}_l2_ops`;
665
673
  case "inner": return `${n}_ip_ops`;
666
674
  }
667
- }, pt = [
675
+ }, mt = [
668
676
  "id",
669
677
  "tenantId",
670
678
  "createdAt",
@@ -673,7 +681,7 @@ var ce = () => new u({
673
681
  "updatedBy",
674
682
  "deletedAt",
675
683
  "deletedBy"
676
- ], mt = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, ht = (e, t) => `${e}_${t.join("_")}_idx`, gt = (e, t) => `${e}_${t.join("_")}_uq`, _t = (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) => {
677
685
  if (n !== "hnsw") return;
678
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.`);
679
687
  let a = r[0];
@@ -681,11 +689,11 @@ var ce = () => new u({
681
689
  let o = i[a];
682
690
  if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
683
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.`);
684
- }, vt = (e, t) => {
692
+ }, yt = (e, t) => {
685
693
  let n;
686
694
  for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
687
695
  ...i,
688
- idScheme: ot(i.idSchemeInput, t)
696
+ idScheme: st(i.idSchemeInput, t)
689
697
  });
690
698
  return n ?? e;
691
699
  }, F = (e) => {
@@ -729,20 +737,20 @@ var ce = () => new u({
729
737
  });
730
738
  }),
731
739
  with: ((...t) => {
732
- let n = ut(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
740
+ let n = dt(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
733
741
  for (let e of Object.keys(r)) i.set(e, {
734
742
  id: "<table>",
735
743
  fields: {}
736
744
  });
737
745
  for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
738
746
  let o = i.get(n);
739
- if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${mt(o)}' and '${mt(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.`);
740
748
  j(e.tableName, n), r[n] = a, i.set(n, t);
741
749
  }
742
750
  let a = [...e.appliedIndexes];
743
751
  for (let t of n) for (let n of t.indexes ?? []) {
744
- let t = n.name ?? ht(e.tableName, n.fields);
745
- a.some((e) => e.name === t) || (M(e.tableName, t, n.name === void 0, n.fields), _t(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) || (M(e.tableName, t, n.name === void 0, n.fields), vt(e.tableName, t, n.kind, n.fields, r), a.push({
746
754
  name: t,
747
755
  fields: n.fields,
748
756
  ...n.kind === void 0 ? {} : { kind: n.kind },
@@ -766,9 +774,9 @@ var ce = () => new u({
766
774
  }),
767
775
  index: ((...t) => {
768
776
  let n, r, i, a = Array.isArray(t[0]);
769
- if (a ? (r = t[0], i = t[1], n = ht(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.`);
770
778
  let o = r.filter((e) => typeof e == "string");
771
- if (M(e.tableName, n, a, o), _t(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.`);
779
+ if (M(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.`);
772
780
  return F({
773
781
  ...e,
774
782
  tableName: e.tableName,
@@ -793,7 +801,7 @@ var ce = () => new u({
793
801
  expressionIndex: ((t, n, r) => {
794
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.`);
795
803
  let i = n.filter((e) => typeof e == "string");
796
- if (M(e.tableName, t, !1, i), _t(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.`);
804
+ if (M(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.`);
797
805
  return F({
798
806
  ...e,
799
807
  tableName: e.tableName,
@@ -817,7 +825,7 @@ var ce = () => new u({
817
825
  }),
818
826
  unique: ((...t) => {
819
827
  let n, r, i, a = Array.isArray(t[0]);
820
- 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(`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.`);
821
829
  if (M(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.`);
822
830
  return F({
823
831
  ...e,
@@ -840,7 +848,7 @@ var ce = () => new u({
840
848
  }),
841
849
  uniqueActive: ((...t) => {
842
850
  let n, r, i, a = Array.isArray(t[0]);
843
- if (a ? (r = t[0], i = t[1], n = ht(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.`);
844
852
  if (M(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).`);
845
853
  let o = i?.where ?? "\"deletedAt\" IS NULL";
846
854
  return F({
@@ -980,7 +988,7 @@ var ce = () => new u({
980
988
  column: e,
981
989
  ...n
982
990
  }];
983
- }), r = vt(S(t), e);
991
+ }), r = yt(S(t), e);
984
992
  for (let t of Object.keys(r)) j(e, t);
985
993
  let i;
986
994
  for (let [t, n] of Object.entries(r)) n.references === x && (n.references = () => {
@@ -999,7 +1007,7 @@ var ce = () => new u({
999
1007
  appliedChecks: [],
1000
1008
  appliedRules: []
1001
1009
  }), i;
1002
- }, yt = (e) => e === "sqlite" || e === "turso", bt = (e) => e === "mysql" || e === "mariadb", L = (e, t) => {
1010
+ }, bt = (e) => e === "sqlite" || e === "turso", xt = (e) => e === "mysql" || e === "mariadb", L = (e, t) => {
1003
1011
  switch (t) {
1004
1012
  case "mysql":
1005
1013
  case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
@@ -1008,45 +1016,45 @@ var ce = () => new u({
1008
1016
  case "sqlite":
1009
1017
  case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
1010
1018
  }
1011
- }, xt = 1e4, St = Symbol.for("@voltro/database/tableRegistry"), Ct = globalThis, R = Ct[St] ?? (Ct[St] = /* @__PURE__ */ new Map()), wt = (e) => {
1019
+ }, St = 1e4, Ct = Symbol.for("@voltro/database/tableRegistry"), wt = globalThis, R = wt[Ct] ?? (wt[Ct] = /* @__PURE__ */ new Map()), Tt = (e) => {
1012
1020
  let t = R.get(e.tableName);
1013
1021
  if (t === void 0) {
1014
1022
  R.set(e.tableName, e);
1015
1023
  return;
1016
1024
  }
1017
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.`);
1018
- }, Tt = (e) => {
1026
+ }, Et = (e) => {
1019
1027
  R.get(e.tableName) === void 0 && R.set(e.tableName, e);
1020
- }, z = (e) => R.get(e), Et = (e) => {
1028
+ }, z = (e) => R.get(e), Dt = (e) => {
1021
1029
  let t = R.get(e);
1022
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.`);
1023
1031
  return t;
1024
- }, Dt = () => [...R.values()], Ot = (e) => R.delete(e), kt = () => {
1032
+ }, Ot = () => [...R.values()], kt = (e) => R.delete(e), At = () => {
1025
1033
  R.clear();
1026
- }, At = (e) => R.get(e)?.isReactive !== !1, B = (e) => e.order ?? [], jt = (e) => ({
1034
+ }, jt = (e) => R.get(e)?.isReactive !== !1, B = (e) => e.order ?? [], Mt = (e) => ({
1027
1035
  op: "count",
1028
1036
  alias: e ?? "count"
1029
- }), Mt = (e, t) => ({
1037
+ }), Nt = (e, t) => ({
1030
1038
  op: "count-distinct",
1031
1039
  column: e,
1032
1040
  alias: t ?? `count_distinct_${e}`
1033
- }), Nt = (e, t) => ({
1041
+ }), Pt = (e, t) => ({
1034
1042
  op: "sum",
1035
1043
  column: e,
1036
1044
  alias: t ?? `sum_${e}`
1037
- }), Pt = (e, t) => ({
1045
+ }), Ft = (e, t) => ({
1038
1046
  op: "avg",
1039
1047
  column: e,
1040
1048
  alias: t ?? `avg_${e}`
1041
- }), Ft = (e, t) => ({
1049
+ }), It = (e, t) => ({
1042
1050
  op: "min",
1043
1051
  column: e,
1044
1052
  alias: t ?? `min_${e}`
1045
- }), It = (e, t) => ({
1053
+ }), Lt = (e, t) => ({
1046
1054
  op: "max",
1047
1055
  column: e,
1048
1056
  alias: t ?? `max_${e}`
1049
- }), Lt = (e, t) => ({
1057
+ }), Rt = (e, t) => ({
1050
1058
  op: "column",
1051
1059
  column: e,
1052
1060
  alias: t ?? e
@@ -1064,37 +1072,37 @@ var ce = () => new u({
1064
1072
  queries: t.map((e) => e.descriptor)
1065
1073
  }
1066
1074
  });
1067
- }, Rt = V("union"), zt = V("union-all"), Bt = V("intersect"), Vt = V("except"), H = (e) => ({ over: (t) => ({
1075
+ }, zt = V("union"), Bt = V("union-all"), Vt = V("intersect"), Ht = V("except"), H = (e) => ({ over: (t) => ({
1068
1076
  ...e,
1069
1077
  window: t
1070
- }) }), Ht = (e = "rowNumber") => H({
1078
+ }) }), Ut = (e = "rowNumber") => H({
1071
1079
  op: "window-row-number",
1072
1080
  alias: e
1073
- }), Ut = (e = "rank") => H({
1081
+ }), Wt = (e = "rank") => H({
1074
1082
  op: "window-rank",
1075
1083
  alias: e
1076
- }), Wt = (e = "denseRank") => H({
1084
+ }), Gt = (e = "denseRank") => H({
1077
1085
  op: "window-dense-rank",
1078
1086
  alias: e
1079
- }), Gt = (e, t = 1, n) => H({
1087
+ }), Kt = (e, t = 1, n) => H({
1080
1088
  op: "window-lag",
1081
1089
  column: e,
1082
1090
  alias: n ?? `lag_${e}`,
1083
1091
  offset: t
1084
- }), Kt = (e, t = 1, n) => H({
1092
+ }), qt = (e, t = 1, n) => H({
1085
1093
  op: "window-lead",
1086
1094
  column: e,
1087
1095
  alias: n ?? `lead_${e}`,
1088
1096
  offset: t
1089
- }), qt = (e, t) => H({
1097
+ }), Jt = (e, t) => H({
1090
1098
  op: "window-sum-over",
1091
1099
  column: e,
1092
1100
  alias: t ?? `sum_${e}_over`
1093
- }), Jt = (e, t) => H({
1101
+ }), Yt = (e, t) => H({
1094
1102
  op: "window-avg-over",
1095
1103
  column: e,
1096
1104
  alias: t ?? `avg_${e}_over`
1097
- }), Yt = (e, t, n) => {
1105
+ }), Xt = (e, t, n) => {
1098
1106
  let r = n?.find((e) => e.name === t) ?? z(e)?.appliedFullText?.find((e) => e.name === t);
1099
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.`);
1100
1108
  return {
@@ -1194,7 +1202,7 @@ var ce = () => new u({
1194
1202
  });
1195
1203
  },
1196
1204
  matching(t, n) {
1197
- let r = Yt(e.table, t, e.fullTextIndexes);
1205
+ let r = Xt(e.table, t, e.fullTextIndexes);
1198
1206
  return U({
1199
1207
  ...e,
1200
1208
  fullTextSearch: {
@@ -1366,7 +1374,7 @@ var ce = () => new u({
1366
1374
  });
1367
1375
  }
1368
1376
  });
1369
- function Xt(e) {
1377
+ function Zt(e) {
1370
1378
  return U({
1371
1379
  table: e.tableName,
1372
1380
  predicate: void 0,
@@ -1378,7 +1386,7 @@ function Xt(e) {
1378
1386
  sourceTable: e
1379
1387
  });
1380
1388
  }
1381
- var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1389
+ var Qt = (e, t, n) => $t(e, "id", t, n), $t = (e, t, n, r, i = "asc") => {
1382
1390
  let a = [...e.order.filter((e) => e.column !== t), {
1383
1391
  column: t,
1384
1392
  direction: i
@@ -1393,11 +1401,11 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1393
1401
  order: a,
1394
1402
  take: r
1395
1403
  };
1396
- }, $t = (e) => {
1404
+ }, en = (e) => {
1397
1405
  let t = {};
1398
- for (let [n, r] of Object.entries(e)) wt(r), t[n] = Xt(r);
1406
+ for (let [n, r] of Object.entries(e)) Tt(r), t[n] = Zt(r);
1399
1407
  return t;
1400
- }, en = (e) => e.isView === !0, tn = (e, t, n) => {
1408
+ }, tn = (e) => e.isView === !0, nn = (e, t, n) => {
1401
1409
  if (A(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
1402
1410
  let r = S(t);
1403
1411
  for (let t of Object.keys(r)) j(e, t);
@@ -1407,7 +1415,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1407
1415
  isView: !0,
1408
1416
  viewSelect: n
1409
1417
  };
1410
- }, nn = (e) => Xt({
1418
+ }, rn = (e) => Zt({
1411
1419
  ...e,
1412
1420
  isReactive: !1,
1413
1421
  appliedMixins: [],
@@ -1415,7 +1423,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1415
1423
  appliedUniques: [],
1416
1424
  appliedFullText: [],
1417
1425
  appliedChecks: []
1418
- }), rn = (e, t, n = null) => {
1426
+ }), an = (e, t, n = null) => {
1419
1427
  let r = n === null ? L(e.tableName, t) : `${L(n, t)}.${L(e.tableName, t)}`, i = e.viewSelect.trim();
1420
1428
  switch (t) {
1421
1429
  case "postgres":
@@ -1425,7 +1433,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1425
1433
  case "sqlite":
1426
1434
  case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
1427
1435
  }
1428
- }, an = (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, on = (e) => {
1436
+ }, 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) => {
1429
1437
  if (e == null || typeof e != "string") return e;
1430
1438
  let t = e.trim();
1431
1439
  if (t.length === 0) return e;
@@ -1436,7 +1444,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1436
1444
  } catch {
1437
1445
  return e;
1438
1446
  }
1439
- }, sn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, cn = (e) => {
1447
+ }, cn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, ln = (e) => {
1440
1448
  if (e == null || e instanceof Date) return e;
1441
1449
  if (typeof e == "string") {
1442
1450
  let t = new Date(e);
@@ -1447,24 +1455,24 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1447
1455
  return isNaN(t.getTime()) ? e : t;
1448
1456
  }
1449
1457
  return e;
1450
- }, ln = (e, t, n) => {
1458
+ }, un = (e, t, n) => {
1451
1459
  if (e == null) return e;
1452
1460
  switch (t) {
1453
- case "boolean": return n === "postgres" ? e : an(e);
1454
- case "vector": return n === "postgres" ? on(e) : e;
1455
- case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : on(e);
1456
- case "array": return n === "postgres" ? e : on(e);
1461
+ case "boolean": return n === "postgres" ? e : on(e);
1462
+ case "vector": return n === "postgres" ? sn(e) : e;
1463
+ case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : sn(e);
1464
+ case "array": return n === "postgres" ? e : sn(e);
1457
1465
  case "timestamp":
1458
- case "date": return n === "sqlite" || n === "turso" ? cn(e) : e;
1466
+ case "date": return n === "sqlite" || n === "turso" ? ln(e) : e;
1459
1467
  case "decimal":
1460
- case "bigint": return sn(e);
1468
+ case "bigint": return cn(e);
1461
1469
  default: return e;
1462
1470
  }
1463
- }, un = (e, t, n) => {
1471
+ }, dn = (e, t, n) => {
1464
1472
  if (e.length === 0) return e;
1465
1473
  let r = z(t);
1466
- return r === void 0 ? e : dn(e, r, n);
1467
- }, dn = (e, t, n) => {
1474
+ return r === void 0 ? e : fn(e, r, n);
1475
+ }, fn = (e, t, n) => {
1468
1476
  if (e.length === 0) return e;
1469
1477
  let r = t.fields, i = [];
1470
1478
  for (let [e, t] of Object.entries(r)) i.push({
@@ -1473,10 +1481,10 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1473
1481
  });
1474
1482
  return e.map((e) => {
1475
1483
  let t = { ...e };
1476
- for (let { key: e, type: r } of i) e in t && (t[e] = ln(t[e], r, n));
1484
+ for (let { key: e, type: r } of i) e in t && (t[e] = un(t[e], r, n));
1477
1485
  return t;
1478
1486
  });
1479
- }, fn = (e, t) => {
1487
+ }, pn = (e, t) => {
1480
1488
  if (e == null) return e;
1481
1489
  switch (t) {
1482
1490
  case "json": return JSON.stringify(e);
@@ -1484,25 +1492,25 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1484
1492
  case "vector": return typeof e == "string" ? e : JSON.stringify(e);
1485
1493
  default: return e;
1486
1494
  }
1487
- }, pn = (e, t, n = ["json", "array"]) => {
1495
+ }, mn = (e, t, n = ["json", "array"]) => {
1488
1496
  let r = z(t);
1489
1497
  if (r === void 0) return e;
1490
1498
  let i = r.fields, a = null;
1491
1499
  for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
1492
- let n = fn(e[t], r.type);
1500
+ let n = pn(e[t], r.type);
1493
1501
  n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
1494
1502
  }
1495
1503
  return a ?? e;
1496
- }, mn = /^[A-Za-z_][A-Za-z0-9_]*$/, hn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : mn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), gn = (e) => "{" + e.map((e) => {
1504
+ }, hn = /^[A-Za-z_][A-Za-z0-9_]*$/, gn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : hn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), _n = (e) => "{" + e.map((e) => {
1497
1505
  let t = String(e);
1498
1506
  return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
1499
1507
  }).join(",") + "}", W = (e, t, n, r = {}) => {
1500
1508
  let i = L(e, n), a = r.numeric ?? !1;
1501
1509
  if (n === "postgres") {
1502
- let e = `(${i} #>> '${gn(t)}'::text[])`;
1510
+ let e = `(${i} #>> '${_n(t)}'::text[])`;
1503
1511
  return a ? `${e}::numeric` : e;
1504
1512
  }
1505
- let o = hn(t);
1513
+ let o = gn(t);
1506
1514
  switch (n) {
1507
1515
  case "mysql":
1508
1516
  case "mariadb": {
@@ -1519,32 +1527,32 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1519
1527
  return a ? `CAST(${e} AS REAL)` : e;
1520
1528
  }
1521
1529
  }
1522
- }, _n = class extends Error {
1530
+ }, vn = class extends Error {
1523
1531
  _tag = "TenantNamespaceUnresolved";
1524
1532
  constructor(e) {
1525
1533
  super(e), this.name = "TenantNamespaceUnresolved";
1526
1534
  }
1527
- }, vn = class extends Error {
1535
+ }, yn = class extends Error {
1528
1536
  _tag = "TenantNamespaceInvalid";
1529
1537
  constructor(e) {
1530
1538
  super(e), this.name = "TenantNamespaceInvalid";
1531
1539
  }
1532
- }, yn = 63, bn = "tenant_", xn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Sn = (e) => {
1533
- if (e == null || e === "") throw new _n("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.");
1534
- let t = xn(e);
1535
- if (t.replace(/_/g, "") === "") throw new vn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
1536
- let n = `${bn}${t}`;
1537
- if (n.length > yn) throw new vn(`namespace '${n}' for tenant '${e}' exceeds the ${yn}-byte identifier limit. Use a shorter tenant id.`);
1540
+ }, bn = 63, xn = "tenant_", Sn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Cn = (e) => {
1541
+ if (e == null || e === "") throw new vn("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.");
1542
+ let t = Sn(e);
1543
+ if (t.replace(/_/g, "") === "") throw new yn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
1544
+ let n = `${xn}${t}`;
1545
+ if (n.length > bn) throw new yn(`namespace '${n}' for tenant '${e}' exceeds the ${bn}-byte identifier limit. Use a shorter tenant id.`);
1538
1546
  return n;
1539
- }, G = (e, t) => e === null ? t : `${e}.${t}`, Cn = /* @__PURE__ */ new Set(["timestamp", "date"]), wn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Tn = (e, t) => {
1540
- if (e === void 0 || t == null || !Cn.has(e) || t instanceof Date) return t;
1547
+ }, G = (e, t) => e === null ? t : `${e}.${t}`, wn = /* @__PURE__ */ new Set(["timestamp", "date"]), Tn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, En = (e, t) => {
1548
+ if (e === void 0 || t == null || !wn.has(e) || t instanceof Date) return t;
1541
1549
  if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
1542
- if (typeof t == "string" && wn.test(t)) {
1550
+ if (typeof t == "string" && Tn.test(t)) {
1543
1551
  let e = new Date(t);
1544
1552
  return Number.isNaN(e.getTime()) ? t : e;
1545
1553
  }
1546
1554
  return t;
1547
- }, En = (e, t) => e === void 0 || !Cn.has(e) ? t : t.map((t) => Tn(e, t)), Dn = (e, t) => {
1555
+ }, Dn = (e, t) => e === void 0 || !wn.has(e) ? t : t.map((t) => En(e, t)), On = (e, t) => {
1548
1556
  let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
1549
1557
  for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
1550
1558
  return t`${i}`;
@@ -1570,10 +1578,10 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1570
1578
  mssql: () => t.unsafe(W(i.column, o, "mssql", { numeric: !0 })),
1571
1579
  sqlite: () => t.unsafe(W(i.column, o, "sqlite", { numeric: !0 })),
1572
1580
  orElse: () => t.unsafe(W(i.column, o, "postgres", { numeric: !0 }))
1573
- }), 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 : z(r)?.fields?.[i.column]?.type, h = (e) => Tn(m, e);
1581
+ }), 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 : z(r)?.fields?.[i.column]?.type, ee = (e) => En(m, e);
1574
1582
  switch (i.op) {
1575
- case "eq": return t`${u} = ${f(h(i.value))}`;
1576
- case "neq": return t`${u} <> ${f(h(i.value))}`;
1583
+ case "eq": return t`${u} = ${f(ee(i.value))}`;
1584
+ case "neq": return t`${u} <> ${f(ee(i.value))}`;
1577
1585
  case "gt": return t`${d} > ${p(i.value)}`;
1578
1586
  case "gte": return t`${d} >= ${p(i.value)}`;
1579
1587
  case "lt": return t`${d} < ${p(i.value)}`;
@@ -1644,13 +1652,13 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1644
1652
  });
1645
1653
  }
1646
1654
  }
1647
- }, On = (e, t) => {
1655
+ }, kn = (e, t) => {
1648
1656
  let n = [];
1649
1657
  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}`);
1650
- }, kn = (e, t) => t.csv(e.map((e) => {
1658
+ }, An = (e, t) => t.csv(e.map((e) => {
1651
1659
  let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
1652
1660
  if (e.op.startsWith("window-")) {
1653
- let r = On(e.window ?? {}, t);
1661
+ let r = kn(e.window ?? {}, t);
1654
1662
  switch (e.op) {
1655
1663
  case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
1656
1664
  case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
@@ -1674,39 +1682,39 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1674
1682
  return t`${t(e.column)} AS ${t(e.alias)}`;
1675
1683
  default: throw T(`compileAggregateProjection: unknown op '${e.op}'`);
1676
1684
  }
1677
- })), An = (e) => `[${e.join(",")}]`, jn = (e, t) => {
1685
+ })), jn = (e) => `[${e.join(",")}]`, Mn = (e, t) => {
1678
1686
  if (e.queryVector === void 0) return null;
1679
- let n = t(e.column), r = An(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
1687
+ let n = t(e.column), r = jn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
1680
1688
  return t.onDialectOrElse({
1681
1689
  mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
1682
1690
  mssql: () => t`NULL`,
1683
1691
  sqlite: () => t`NULL`,
1684
1692
  orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
1685
1693
  });
1686
- }, Mn = (e, t) => {
1694
+ }, Nn = (e, t) => {
1687
1695
  let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
1688
1696
  return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
1689
- }, Nn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Pn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Fn = (e, t) => `${t}_${e.indexName}_fts`, In = (e, t, n) => {
1697
+ }, Pn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Fn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, In = (e, t) => `${t}_${e.indexName}_fts`, Ln = (e, t, n) => {
1690
1698
  let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${K(e.query)}%`;
1691
1699
  return n.onDialectOrElse({
1692
1700
  mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
1693
1701
  sqlite: () => {
1694
- let r = n(Fn(e, t));
1702
+ let r = n(In(e, t));
1695
1703
  return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
1696
1704
  },
1697
1705
  mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
1698
- orElse: () => n`${Pn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
1706
+ orElse: () => n`${Fn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
1699
1707
  });
1700
- }, Ln = (e, t, n) => {
1708
+ }, Rn = (e, t, n) => {
1701
1709
  let r = `%${K(e.query)}%`;
1702
1710
  return n.onDialectOrElse({
1703
1711
  mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
1704
1712
  sqlite: () => {
1705
- let r = n(Fn(e, t));
1713
+ let r = n(In(e, t));
1706
1714
  return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
1707
1715
  },
1708
1716
  mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
1709
- orElse: () => n`ts_rank(${Pn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
1717
+ orElse: () => n`ts_rank(${Fn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
1710
1718
  });
1711
1719
  }, J = (e, t, n = null) => {
1712
1720
  if (e.setOp && e.setOp.queries.length >= 2) {
@@ -1721,7 +1729,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1721
1729
  }
1722
1730
  return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
1723
1731
  }
1724
- let r = e.annClause === void 0 ? null : jn(e.annClause, t);
1732
+ let r = e.annClause === void 0 ? null : Mn(e.annClause, t);
1725
1733
  e.spatialClause !== void 0 && t.onDialectOrElse({
1726
1734
  mysql: () => {
1727
1735
  throw T("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
@@ -1734,7 +1742,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1734
1742
  },
1735
1743
  orElse: () => t``
1736
1744
  });
1737
- let i = e.spatialClause?.projectAs === void 0 ? null : Mn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? kn(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Ln(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({
1745
+ let i = e.spatialClause?.projectAs === void 0 ? null : Nn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? An(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Rn(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({
1738
1746
  orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
1739
1747
  mysql: () => t`DISTINCT `,
1740
1748
  mssql: () => t`DISTINCT `,
@@ -1742,15 +1750,15 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1742
1750
  }) : e.distinct ? t`DISTINCT ` : t``, p = e.lock === "update", m = p ? t.onDialectOrElse({
1743
1751
  mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
1744
1752
  orElse: () => t``
1745
- }) : t``, h = p ? t.onDialectOrElse({
1753
+ }) : t``, ee = p ? t.onDialectOrElse({
1746
1754
  mssql: () => t``,
1747
1755
  sqlite: () => t``,
1748
1756
  orElse: () => t` FOR UPDATE`
1749
- }) : t``, ee = e.alias === void 0 ? t`${t(G(n, e.table))}${m}` : t`${t(G(n, e.table))} AS ${t(e.alias)}${m}`, te = (e.joins ?? []).map((e) => {
1757
+ }) : t``, h = e.alias === void 0 ? t`${t(G(n, e.table))}${m}` : t`${t(G(n, e.table))} AS ${t(e.alias)}${m}`, te = (e.joins ?? []).map((e) => {
1750
1758
  let r = e.kind === "inner" ? "INNER" : "LEFT";
1751
1759
  return t` ${t.unsafe(r)} JOIN ${t(G(n, e.table))} AS ${t(e.alias)} ON ${q(e.on, t, n)}`;
1752
- }), ne = te.length > 0 ? te.reduce((e, n) => t`${e}${n}`, ee) : ee, re = c === void 0 ? null : In(c, e.table, t), g = [e.predicate ? q(e.predicate, t, n, e.table) : null, re].filter((e) => e !== null), _ = g.length > 0 ? t` WHERE ${t.and(g)}` : t``, ie = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, v = e.having ? t` HAVING ${q(e.having, t, n, e.table)}` : t``, y = e.skip !== void 0, b = [];
1753
- r !== null && b.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && b.push(e.spatialClause.order === "desc" ? t`${Nn(e.spatialClause, t)} DESC` : t`${Nn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && b.push(t`${l} DESC`);
1760
+ }), ne = te.length > 0 ? te.reduce((e, n) => t`${e}${n}`, h) : h, re = c === void 0 ? null : Ln(c, e.table, t), g = [e.predicate ? q(e.predicate, t, n, e.table) : null, re].filter((e) => e !== null), _ = g.length > 0 ? t` WHERE ${t.and(g)}` : t``, ie = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, v = e.having ? t` HAVING ${q(e.having, t, n, e.table)}` : t``, y = e.skip !== void 0, b = [];
1761
+ r !== null && b.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && b.push(e.spatialClause.order === "desc" ? t`${Pn(e.spatialClause, t)} DESC` : t`${Pn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && b.push(t`${l} DESC`);
1754
1762
  for (let n of B(e)) b.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
1755
1763
  let ae = b.length > 0 ? t` ORDER BY ${t.csv(b)}` : y ? t.onDialectOrElse({
1756
1764
  mssql: () => t` ORDER BY (SELECT NULL)`,
@@ -1766,7 +1774,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1766
1774
  },
1767
1775
  orElse: () => {
1768
1776
  let n = e.take === void 0 ? t`` : t` LIMIT ${x(e.take)}`, r = y ? t` OFFSET ${x(e.skip)}` : t``;
1769
- return t`${ce}SELECT ${f}${d} FROM ${ne}${_}${ie}${v}${ae}${n}${r}${h}`;
1777
+ return t`${ce}SELECT ${f}${d} FROM ${ne}${_}${ie}${v}${ae}${n}${r}${ee}`;
1770
1778
  }
1771
1779
  });
1772
1780
  }, Y = (e, t) => {
@@ -1787,73 +1795,73 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1787
1795
  a = t === n ? 0 : t > n ? 1 : -1;
1788
1796
  }
1789
1797
  return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
1790
- }, Rn = (e, t) => ({
1798
+ }, zn = (e, t) => ({
1791
1799
  column: e,
1792
1800
  op: "eq",
1793
1801
  value: t
1794
- }), zn = (e, t) => ({
1802
+ }), Bn = (e, t) => ({
1795
1803
  column: e,
1796
1804
  op: "neq",
1797
1805
  value: t
1798
- }), Bn = (e, t) => ({
1806
+ }), Vn = (e, t) => ({
1799
1807
  column: e,
1800
1808
  op: "gt",
1801
1809
  value: t
1802
- }), Vn = (e, t) => ({
1810
+ }), Hn = (e, t) => ({
1803
1811
  column: e,
1804
1812
  op: "gte",
1805
1813
  value: t
1806
- }), Hn = (e, t) => ({
1814
+ }), Un = (e, t) => ({
1807
1815
  column: e,
1808
1816
  op: "lt",
1809
1817
  value: t
1810
- }), Un = (e, t) => ({
1818
+ }), Wn = (e, t) => ({
1811
1819
  column: e,
1812
1820
  op: "lte",
1813
1821
  value: t
1814
- }), Wn = (e, t) => ({
1822
+ }), Gn = (e, t) => ({
1815
1823
  column: e,
1816
1824
  op: "in",
1817
1825
  value: t
1818
- }), Gn = (e, t) => ({
1826
+ }), Kn = (e, t) => ({
1819
1827
  column: e,
1820
1828
  op: "notIn",
1821
1829
  value: t
1822
- }), Kn = (e, t) => ({
1830
+ }), qn = (e, t) => ({
1823
1831
  column: e,
1824
1832
  op: "contains",
1825
1833
  value: t
1826
- }), qn = (e, t) => ({
1834
+ }), Jn = (e, t) => ({
1827
1835
  column: e,
1828
1836
  op: "startsWith",
1829
1837
  value: t
1830
- }), Jn = (e, t) => ({
1838
+ }), Yn = (e, t) => ({
1831
1839
  column: e,
1832
1840
  op: "arrayContains",
1833
1841
  value: t
1834
- }), Yn = (e, t) => ({
1842
+ }), Xn = (e, t) => ({
1835
1843
  column: e,
1836
1844
  op: "arrayOverlaps",
1837
1845
  value: t
1838
- }), Xn = (e, t) => ({
1846
+ }), Zn = (e, t) => ({
1839
1847
  column: e,
1840
1848
  op: "arrayHas",
1841
1849
  value: t
1842
- }), Zn = {
1850
+ }), Qn = {
1843
1851
  column: "id",
1844
1852
  op: "in",
1845
1853
  value: []
1846
- }, Qn = (e) => ({
1854
+ }, $n = (e) => ({
1847
1855
  column: e,
1848
1856
  op: "isNull"
1849
- }), $n = (e) => ({
1857
+ }), er = (e) => ({
1850
1858
  column: e,
1851
1859
  op: "isNotNull"
1852
- }), er = (e, t) => ({
1860
+ }), tr = (e, t) => ({
1853
1861
  column: e,
1854
1862
  op: "spatial",
1855
1863
  value: t
1856
- }), tr = (...e) => ({ and: e }), nr = (...e) => ({ or: e }), rr = (e) => ({ not: e }), ir = (e, ...t) => {
1864
+ }), nr = (...e) => ({ and: e }), rr = (...e) => ({ or: e }), ir = (e) => ({ not: e }), ar = (e, ...t) => {
1857
1865
  if (t.length === 0) throw T(`jsonField("${e}"): at least one path segment is required`);
1858
1866
  let n = (n, r) => ({
1859
1867
  column: e,
@@ -1875,37 +1883,37 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1875
1883
  isNull: () => n("isNull"),
1876
1884
  isNotNull: () => n("isNotNull")
1877
1885
  };
1878
- }, X = (e) => "descriptor" in e ? e.descriptor : e, ar = (e, t) => ({
1886
+ }, X = (e) => "descriptor" in e ? e.descriptor : e, or = (e, t) => ({
1879
1887
  column: e,
1880
1888
  op: "subquery-in",
1881
1889
  subquery: X(t)
1882
- }), or = (e, t) => ({
1890
+ }), sr = (e, t) => ({
1883
1891
  column: e,
1884
1892
  op: "subquery-not-in",
1885
1893
  subquery: X(t)
1886
- }), sr = (e) => ({
1894
+ }), cr = (e) => ({
1887
1895
  op: "exists",
1888
1896
  subquery: X(e)
1889
- }), cr = (e) => ({
1897
+ }), lr = (e) => ({
1890
1898
  op: "not-exists",
1891
1899
  subquery: X(e)
1892
- }), lr = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, ur = (e) => {
1900
+ }), ur = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, dr = (e) => {
1893
1901
  if (e instanceof Date) return e.getTime();
1894
- if (typeof e == "string" && lr.test(e)) {
1902
+ if (typeof e == "string" && ur.test(e)) {
1895
1903
  let t = Date.parse(e);
1896
1904
  return Number.isNaN(t) ? void 0 : t;
1897
1905
  }
1898
- }, dr = (e, t) => {
1906
+ }, fr = (e, t) => {
1899
1907
  if (!(e instanceof Date) && !(t instanceof Date)) return;
1900
- let n = ur(e), r = ur(t);
1908
+ let n = dr(e), r = dr(t);
1901
1909
  return n === void 0 || r === void 0 ? void 0 : [n, r];
1902
- }, fr = (e, t) => {
1910
+ }, pr = (e, t) => {
1903
1911
  if (e === t) return !0;
1904
- let n = dr(e, t);
1912
+ let n = fr(e, t);
1905
1913
  return n !== void 0 && n[0] === n[1];
1906
- }, pr = (e, t) => {
1914
+ }, mr = (e, t) => {
1907
1915
  if (e == null || t == null) return null;
1908
- let n = dr(e, t);
1916
+ let n = fr(e, t);
1909
1917
  if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
1910
1918
  let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
1911
1919
  return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
@@ -1932,7 +1940,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1932
1940
  let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
1933
1941
  return e.op === "exists" ? r : !r;
1934
1942
  }
1935
- let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? Y(e, t) === 0 : fr(e, t), c = o ? Y : pr;
1943
+ let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? Y(e, t) === 0 : pr(e, t), c = o ? Y : mr;
1936
1944
  switch (i.op) {
1937
1945
  case "eq": return s(a, i.value);
1938
1946
  case "neq": return !s(a, i.value);
@@ -1994,13 +2002,13 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
1994
2002
  ...e,
1995
2003
  conjunctive: t
1996
2004
  });
1997
- }, mr = (e, t) => ({
2005
+ }, hr = (e, t) => ({
1998
2006
  name: e,
1999
2007
  body: t
2000
- }), hr = (e) => {
2008
+ }), gr = (e) => {
2001
2009
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
2002
2010
  if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
2003
- let t = e.steps({ step: mr });
2011
+ let t = e.steps({ step: hr });
2004
2012
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
2005
2013
  return {
2006
2014
  __seed: !0,
@@ -2013,76 +2021,76 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2013
2021
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
2014
2022
  steps: t
2015
2023
  };
2016
- }, gr = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, _r = null, vr = null, yr = (e) => {
2017
- _r = e;
2018
- }, br = (e) => {
2024
+ }, _r = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, vr = null, yr = null, br = (e) => {
2019
2025
  vr = e;
2020
- }, xr = async (e) => {
2021
- let t = _r;
2022
- t !== null && await t(e);
2026
+ }, xr = (e) => {
2027
+ yr = e;
2023
2028
  }, Sr = async (e) => {
2024
2029
  let t = vr;
2030
+ t !== null && await t(e);
2031
+ }, Cr = async (e) => {
2032
+ let t = yr;
2025
2033
  t !== null && e.changedTables.length !== 0 && await t(e);
2026
- }, Cr = ["before-schema", "after-schema"], wr = (e) => {
2034
+ }, wr = ["before-schema", "after-schema"], Tr = (e) => {
2027
2035
  if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
2028
2036
  if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
2029
- if (!Cr.includes(e.phase)) throw Error(`migration ${e.id}: \`phase\` is required and must be one of ${Cr.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)`);
2037
+ if (!wr.includes(e.phase)) throw Error(`migration ${e.id}: \`phase\` is required and must be one of ${wr.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)`);
2030
2038
  return e;
2031
- }, Tr = Symbol.for("voltro.migration.irreversible"), Er = class extends Error {
2039
+ }, Er = Symbol.for("voltro.migration.irreversible"), Dr = class extends Error {
2032
2040
  migrationId;
2033
2041
  reason;
2034
2042
  _tag = "IrreversibleMigrationError";
2035
2043
  constructor(e, t) {
2036
2044
  super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
2037
2045
  }
2038
- }, Dr = (e) => {
2039
- if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
2040
- return Object.assign(() => t.fail(new Er("<unknown>", e)), { [Tr]: e });
2041
2046
  }, Or = (e) => {
2042
- let t = e[Tr];
2047
+ if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
2048
+ return Object.assign(() => t.fail(new Dr("<unknown>", e)), { [Er]: e });
2049
+ }, kr = (e) => {
2050
+ let t = e[Er];
2043
2051
  return typeof t == "string" ? t : void 0;
2044
- }, kr = class {
2052
+ }, Ar = class {
2045
2053
  reason;
2046
2054
  _tag = "MigrationSkipped";
2047
2055
  constructor(e) {
2048
2056
  this.reason = e;
2049
2057
  }
2050
- }, Ar = class extends Error {
2058
+ }, jr = class extends Error {
2051
2059
  migrationId;
2052
2060
  failed;
2053
2061
  _tag = "MigrationExpectationFailed";
2054
2062
  constructor(e, t) {
2055
2063
  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";
2056
2064
  }
2057
- }, jr = class extends Error {
2065
+ }, Mr = class extends Error {
2058
2066
  migrationId;
2059
2067
  dialect;
2060
2068
  _tag = "TransactionBrokenByBodyError";
2061
2069
  constructor(e, t) {
2062
2070
  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";
2063
2071
  }
2064
- }, Mr = class extends Error {
2072
+ }, Nr = class extends Error {
2065
2073
  migrationId;
2066
2074
  operation;
2067
2075
  _tag = "MigrationNeedsSqlClient";
2068
2076
  constructor(e, t, n) {
2069
2077
  super(`migration ${e}: ${t} — ${n}`), this.migrationId = e, this.operation = t, this.name = "MigrationNeedsSqlClient";
2070
2078
  }
2071
- }, Nr = class extends Error {
2079
+ }, Pr = class extends Error {
2072
2080
  table;
2073
2081
  report;
2074
2082
  _tag = "RewriteUnstableError";
2075
2083
  constructor(e, t) {
2076
2084
  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";
2077
2085
  }
2078
- }, Pr = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Fr = (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", Ir = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Lr = (e) => Ir.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), Rr = "_voltro_staging_", zr = (e) => e.startsWith(Rr), Br = /__dropped_\d{14}$/, Vr = (e) => Br.test(e), Hr = 7, Ur = (e) => {
2086
+ }, Fr = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Ir = (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", Lr = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Rr = (e) => Lr.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), zr = "_voltro_staging_", Br = (e) => e.startsWith(zr), Vr = /__dropped_\d{14}$/, Hr = (e) => Vr.test(e), Ur = 7, Wr = (e) => {
2079
2087
  let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
2080
2088
  if (t === null) return;
2081
2089
  let [, n, r, i, a, o, s] = t;
2082
2090
  return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
2083
- }, Wr = (e, t = {}) => {
2091
+ }, Gr = (e, t = {}) => {
2084
2092
  let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
2085
- let a = Ur(e);
2093
+ let a = Wr(e);
2086
2094
  if (a === void 0) return;
2087
2095
  let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
2088
2096
  o >= r && i.push({
@@ -2091,12 +2099,12 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2091
2099
  ageDays: o
2092
2100
  });
2093
2101
  };
2094
- for (let t of e.tables) if (a(t.name, t.name), !Vr(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
2102
+ for (let t of e.tables) if (a(t.name, t.name), !Hr(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
2095
2103
  return i;
2096
- }, Gr = (e, t) => {
2104
+ }, Kr = (e, t) => {
2097
2105
  let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
2098
2106
  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.`;
2099
- }, Kr = (e, t) => e.filter((e) => !Lr(e.name) || t.has(e.name)), qr = I("_voltro_migrations", {
2107
+ }, qr = (e, t) => e.filter((e) => !Rr(e.name) || t.has(e.name)), Jr = I("_voltro_migrations", {
2100
2108
  id: f({ prefix: "mig" }),
2101
2109
  name: p(),
2102
2110
  hash: p(),
@@ -2108,7 +2116,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2108
2116
  workflowRunId: p().nullable(),
2109
2117
  createdAt: _().default("now"),
2110
2118
  updatedAt: _().default("now").onUpdate("now")
2111
- }).index(["status"]), Jr = I("_voltro_seeds", {
2119
+ }).index(["status"]), Yr = I("_voltro_seeds", {
2112
2120
  id: f({ prefix: "seed" }),
2113
2121
  name: p(),
2114
2122
  lifecycle: p(),
@@ -2124,7 +2132,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2124
2132
  workflowRunId: p().nullable(),
2125
2133
  createdAt: _().default("now"),
2126
2134
  updatedAt: _().default("now").onUpdate("now")
2127
- }).index(["lifecycle"]).index(["nextRunAt"]), Yr = I("_voltro_migration_plans", {
2135
+ }).index(["lifecycle"]).index(["nextRunAt"]), Xr = I("_voltro_migration_plans", {
2128
2136
  id: f({ prefix: "plan" }),
2129
2137
  fingerprint: p(),
2130
2138
  liveFingerprint: p().nullable(),
@@ -2140,14 +2148,14 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2140
2148
  appliedAt: _().default("now"),
2141
2149
  createdAt: _().default("now"),
2142
2150
  updatedAt: _().default("now").onUpdate("now")
2143
- }).index(["fingerprint"]).index(["environment"]), Xr = I("_voltro_idempotency", {
2151
+ }).index(["fingerprint"]).index(["environment"]), Zr = I("_voltro_idempotency", {
2144
2152
  id: f({ prefix: "idem" }),
2145
2153
  scope: p(),
2146
2154
  key: p(),
2147
2155
  status: p(),
2148
2156
  response: v().nullable(),
2149
2157
  createdAt: _().default("now")
2150
- }).unique(["scope", "key"]).index(["createdAt"]), Zr = I("_voltro_devices", {
2158
+ }).unique(["scope", "key"]).index(["createdAt"]), Qr = I("_voltro_devices", {
2151
2159
  id: f({ prefix: "device" }),
2152
2160
  tenantId: p(),
2153
2161
  name: p(),
@@ -2167,20 +2175,20 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2167
2175
  createdBy: p().nullable(),
2168
2176
  metadata: v().nullable(),
2169
2177
  createdAt: _()
2170
- }).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), Qr = I("_voltro_tenant_selections", {
2178
+ }).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), $r = I("_voltro_tenant_selections", {
2171
2179
  id: f({ prefix: "tsel" }),
2172
2180
  subjectType: p().maxLength(32),
2173
2181
  subjectId: p(),
2174
2182
  tenantId: p(),
2175
2183
  selectedAt: _()
2176
- }).primaryKey(["id"]).nonReactive(), $r = I("_voltro_kv", {
2184
+ }).primaryKey(["id"]).nonReactive(), ei = I("_voltro_kv", {
2177
2185
  id: f({ prefix: "kv" }),
2178
2186
  key: p().unique(),
2179
2187
  value: p().nullable(),
2180
2188
  expiresAt: _().nullable(),
2181
2189
  createdAt: _().default("now"),
2182
2190
  updatedAt: _().default("now").onUpdate("now")
2183
- }).index(["expiresAt"]), ei = I("_voltro_api_keys", {
2191
+ }).index(["expiresAt"]), ti = I("_voltro_api_keys", {
2184
2192
  id: f({ prefix: "apikey" }),
2185
2193
  tenantId: p().nullable(),
2186
2194
  name: p(),
@@ -2195,7 +2203,7 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2195
2203
  onBehalfOf: p().nullable(),
2196
2204
  metadata: v().nullable(),
2197
2205
  createdAt: _().default("now")
2198
- }).index("byApiKeyTenant", ["tenantId"]), ti = I("_voltro_replica_observations", {
2206
+ }).index("byApiKeyTenant", ["tenantId"]), ni = I("_voltro_replica_observations", {
2199
2207
  id: f({ prefix: "robs" }),
2200
2208
  replicaId: p().maxLength(191),
2201
2209
  startedAt: _(),
@@ -2204,11 +2212,11 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2204
2212
  payload: p().nullable(),
2205
2213
  reachableAt: p().maxLength(255).nullable(),
2206
2214
  writtenAt: _().default("now").onUpdate("now")
2207
- }).unique(["replicaId", "kind"]).index(["kind"]), ni = [
2208
- qr,
2215
+ }).unique(["replicaId", "kind"]).index(["kind"]), ri = [
2209
2216
  Jr,
2210
- Yr
2211
- ], ri = "_voltro_replace_in_progress", ii = I(ri, {
2217
+ Yr,
2218
+ Xr
2219
+ ], ii = "_voltro_replace_in_progress", ai = I(ii, {
2212
2220
  id: f({ prefix: "repl" }),
2213
2221
  startedAt: _().default("now"),
2214
2222
  kind: p().default("replace"),
@@ -2218,10 +2226,10 @@ var Zt = (e, t, n) => Qt(e, "id", t, n), Qt = (e, t, n, r, i = "asc") => {
2218
2226
  staging: p().nullable(),
2219
2227
  heartbeatAt: _().nullable(),
2220
2228
  resumable: g().nullable()
2221
- }), ai = 30, oi = (e, t) => {
2229
+ }), oi = 30, si = (e, t) => {
2222
2230
  let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
2223
2231
  return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
2224
- }, si = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), ci = (e) => {
2232
+ }, ci = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), li = (e) => {
2225
2233
  let t = e.filter((e) => e.kind !== "staging");
2226
2234
  if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
2227
2235
  ${t.map((e) => {
@@ -2236,7 +2244,7 @@ ${t.map((e) => {
2236
2244
 
2237
2245
  When the data is back, or you have decided the current state is correct, clear the marker:
2238
2246
  voltro data clear-replace-marker --yes`;
2239
- }, li = (e, t, n) => {
2247
+ }, ui = (e, t, n) => {
2240
2248
  let r = e.filter((e) => e.kind === "staging");
2241
2249
  return {
2242
2250
  all: r,
@@ -2246,7 +2254,7 @@ ${t.map((e) => {
2246
2254
  return Number.isFinite(r) ? t - r >= n : !1;
2247
2255
  })
2248
2256
  };
2249
- }, ui = (e, t) => {
2257
+ }, di = (e, t) => {
2250
2258
  if (e.all.length === 0) return;
2251
2259
  let n = new Set(e.droppable.map((e) => e.id));
2252
2260
  return `staged data-import leftovers:
@@ -2257,4 +2265,4 @@ ${e.all.map((e) => {
2257
2265
  a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
2258
2266
  };
2259
2267
  //#endregion
2260
- export { Kn as $, be as $n, It as $t, Er as A, ut as An, se as Ar, G as At, wr as B, M as Bn, tn as Bt, Gr as C, L as Cn, de as Cr, Dn as Ct, Kr as D, ft as Dn, me as Dr, En as Dt, zr as E, I as En, te as Er, Tn as Et, Nr as F, tt as Fn, le as Fr, dn as Ft, br as G, w as Gn, jt as Gt, Sr as H, N as Hn, Pt as Ht, jr as I, Be as In, un as It, tr as J, Re as Jn, Wt as Jt, yr as K, Pe as Kn, Mt as Kt, Dr as L, Ve as Ln, pn as Lt, Ar as M, st as Mn, o as Mr, xn as Mt, Mr as N, ot as Nn, p as Nr, W as Nt, Ur as O, lt as On, c as Or, vn as Ot, kr as P, it as Pn, _ as Pr, ln as Pt, Q, Ee as Qn, Kt as Qt, Or as R, He as Rn, en as Rt, Wr as S, yt as Sn, m as Sr, q as St, Vr as T, dt as Tn, S as Tr, K as Tt, xr as U, T as Un, Jt as Ut, hr as V, A as Vn, rn as Vt, gr as W, Oe as Wn, Lt as Wt, Xn as X, Fe as Xn, Bt as Xt, Jn as Y, Te as Yn, Vt as Yt, Yn as Z, Ie as Zn, Gt as Zt, Qr as _, wt as _n, ee as _r, nr as _t, ui as a, Ut as an, u as ar, Wn as at, Ir as b, xt as bn, pe as br, $ as bt, oi as c, Nt as cn, ne as cr, Qn as ct, Xr as d, zt as dn, ae as dr, Un as dt, Ft as en, xe as er, Rn as et, $r as f, Dt as fn, l as fr, zn as ft, Jr as g, At as gn, re as gr, or as gt, ti as h, z as hn, ie as hr, Gn as ht, ci as i, Xt as in, ge as ir, Vn as it, Cr as j, at as jn, oe as jr, Sn as jt, Pr as k, ct as kn, h as kr, _n as kt, ei as l, qt as ln, g as lr, ir as lt, qr as m, Tt as mn, b as mr, cr as mt, ai as n, Qt as nn, ye as nr, sr as nt, li as o, Yt as on, x as or, ar as ot, Yr as p, kt as pn, s as pr, rr as pt, Zn as q, Le as qn, $t as qt, ii as r, Zt as rn, _e as rr, Bn as rt, si as s, Ht as sn, ue as sr, $n as st, ri as t, B as tn, ve as tr, Z as tt, Zr as u, Rt as un, y as ur, Hn as ut, ni as v, Et as vn, ce as vr, er as vt, Lr as w, pt as wn, v as wr, J as wt, Rr as x, bt as xn, f as xr, Y as xt, Hr as y, Ot as yn, fe as yr, qn as yt, Fr as z, j as zn, nn as zt };
2268
+ export { qn as $, Ee as $n, Lt as $t, Dr as A, dt as An, ee as Ar, G as At, Tr as B, M as Bn, nn as Bt, Kr as C, L as Cn, m as Cr, On as Ct, qr as D, pt as Dn, te as Dr, Dn as Dt, Br as E, I as En, S as Er, En as Et, Pr as F, nt as Fn, _ as Fr, fn as Ft, xr as G, w as Gn, Mt as Gt, Cr as H, N as Hn, Ft as Ht, Mr as I, Ve as In, le as Ir, dn as It, nr as J, Re as Jn, Gt as Jt, br as K, Pe as Kn, Nt as Kt, Or as L, He as Ln, mn as Lt, jr as M, ct as Mn, oe as Mr, Sn as Mt, Nr as N, st as Nn, o as Nr, W as Nt, Wr as O, ut as On, me as Or, yn as Ot, Ar as P, at as Pn, p as Pr, un as Pt, Q, Ie as Qn, qt as Qt, kr as R, Ue as Rn, tn as Rt, Gr as S, bt as Sn, f as Sr, q as St, Hr as T, ft as Tn, v as Tr, K as Tt, Sr as U, T as Un, Yt as Ut, gr as V, A as Vn, an as Vt, _r as W, Oe as Wn, Rt as Wt, Zn as X, Te as Xn, Vt as Xt, Yn as Y, ze as Yn, Ht as Yt, Xn as Z, Fe as Zn, Kt as Zt, $r as _, Tt as _n, re as _r, rr as _t, di as a, Wt as an, ge as ar, Gn as at, Lr as b, St as bn, fe as br, $ as bt, si as c, Pt as cn, ue as cr, $n as ct, Zr as d, Bt as dn, y as dr, Wn as dt, It as en, be as er, zn as et, ei as f, Ot as fn, ae as fr, Bn as ft, Yr as g, jt as gn, ie as gr, sr as gt, ni as h, z as hn, b as hr, Kn as ht, li as i, Zt as in, _e as ir, Hn as it, wr as j, ot as jn, se as jr, Cn as jt, Fr as k, lt as kn, c as kr, vn as kt, ti as l, Jt as ln, ne as lr, ar as lt, Jr as m, Et as mn, s as mr, lr as mt, oi as n, $t as nn, ve as nr, cr as nt, ui as o, Xt as on, u as or, or as ot, Xr as p, At as pn, l as pr, ir as pt, Qn as q, Le as qn, en as qt, ai as r, Qt as rn, ye as rr, Vn as rt, ci as s, Ut as sn, x as sr, er as st, ii as t, B as tn, xe as tr, Z as tt, Qr as u, zt as un, g as ur, Un as ut, ri as v, Dt as vn, h as vr, tr as vt, Rr as w, mt as wn, de as wr, J as wt, zr as x, xt as xn, pe as xr, Y as xt, Ur as y, kt as yn, ce as yr, Jn as yt, Ir as z, j as zn, rn as zt };