@voltro/database 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -446,16 +446,16 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
446
446
  let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
447
447
  for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
448
448
  return t`${i}`;
449
- }, Tn = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), I = (e, t, n = null, r) => {
450
- if ("not" in e) return t`NOT (${I(e.not, t, n, r)})`;
451
- if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => I(e, t, n, r)));
452
- if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => I(e, t, n, r)));
449
+ }, I = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), L = (e, t, n = null, r) => {
450
+ if ("not" in e) return t`NOT (${L(e.not, t, n, r)})`;
451
+ if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => L(e, t, n, r)));
452
+ if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => L(e, t, n, r)));
453
453
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
454
- let r = e, i = L(r.subquery, t, n);
454
+ let r = e, i = R(r.subquery, t, n);
455
455
  return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
456
456
  }
457
457
  if (e.op === "exists" || e.op === "not-exists") {
458
- let r = e, i = L(r.subquery, t, n);
458
+ let r = e, i = R(r.subquery, t, n);
459
459
  return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
460
460
  }
461
461
  let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
@@ -485,7 +485,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
485
485
  return e.length === 0 ? t`TRUE` : t`${d} NOT IN ${t.in(s ? e.map((e) => p(e)) : e)}`;
486
486
  }
487
487
  case "contains": {
488
- let e = `%${Tn(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
488
+ let e = `%${I(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
489
489
  return t.onDialectOrElse({
490
490
  mysql: () => t`LOWER(${d}) LIKE LOWER(${e})`,
491
491
  mssql: () => t`LOWER(${d}) LIKE LOWER(${e})`,
@@ -493,6 +493,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
493
493
  orElse: () => t`${d} ILIKE ${e} ESCAPE '\\'`
494
494
  });
495
495
  }
496
+ case "startsWith": {
497
+ let e = `${I(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
498
+ return t.onDialectOrElse({
499
+ mysql: () => t`${d} LIKE ${e}`,
500
+ orElse: () => t`${d} LIKE ${e} ESCAPE '\\'`
501
+ });
502
+ }
496
503
  case "arrayContains": {
497
504
  let e = i.value ?? [];
498
505
  return e.length === 0 ? t`TRUE` : t.onDialectOrElse({
@@ -535,13 +542,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
535
542
  });
536
543
  }
537
544
  }
538
- }, En = (e, t) => {
545
+ }, Tn = (e, t) => {
539
546
  let n = [];
540
547
  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}`);
541
- }, Dn = (e, t) => t.csv(e.map((e) => {
548
+ }, En = (e, t) => t.csv(e.map((e) => {
542
549
  let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
543
550
  if (e.op.startsWith("window-")) {
544
- let r = En(e.window ?? {}, t);
551
+ let r = Tn(e.window ?? {}, t);
545
552
  switch (e.op) {
546
553
  case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
547
554
  case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
@@ -565,43 +572,43 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
565
572
  return t`${t(e.column)} AS ${t(e.alias)}`;
566
573
  default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
567
574
  }
568
- })), On = (e) => `[${e.join(",")}]`, kn = (e, t) => {
575
+ })), Dn = (e) => `[${e.join(",")}]`, On = (e, t) => {
569
576
  if (e.queryVector === void 0) return null;
570
- let n = t(e.column), r = On(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
577
+ let n = t(e.column), r = Dn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
571
578
  return t.onDialectOrElse({
572
579
  mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
573
580
  mssql: () => t`NULL`,
574
581
  sqlite: () => t`NULL`,
575
582
  orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
576
583
  });
577
- }, An = (e, t) => {
584
+ }, kn = (e, t) => {
578
585
  let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
579
586
  return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
580
- }, jn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Mn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Nn = (e, t) => `${t}_${e.indexName}_fts`, Pn = (e, t, n) => {
581
- let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${Tn(e.query)}%`;
587
+ }, An = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, jn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Mn = (e, t) => `${t}_${e.indexName}_fts`, Nn = (e, t, n) => {
588
+ let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${I(e.query)}%`;
582
589
  return n.onDialectOrElse({
583
590
  mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
584
591
  sqlite: () => {
585
- let r = n(Nn(e, t));
592
+ let r = n(Mn(e, t));
586
593
  return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
587
594
  },
588
595
  mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
589
- orElse: () => n`${Mn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
596
+ orElse: () => n`${jn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
590
597
  });
591
- }, Fn = (e, t, n) => {
592
- let r = `%${Tn(e.query)}%`;
598
+ }, Pn = (e, t, n) => {
599
+ let r = `%${I(e.query)}%`;
593
600
  return n.onDialectOrElse({
594
601
  mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
595
602
  sqlite: () => {
596
- let r = n(Nn(e, t));
603
+ let r = n(Mn(e, t));
597
604
  return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
598
605
  },
599
606
  mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
600
- orElse: () => n`ts_rank(${Mn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
607
+ orElse: () => n`ts_rank(${jn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
601
608
  });
602
- }, L = (e, t, n = null) => {
609
+ }, R = (e, t, n = null) => {
603
610
  if (e.setOp && e.setOp.queries.length >= 2) {
604
- let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${L(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
611
+ let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${R(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
605
612
  if (e.order.length > 0 && a.push(t` ORDER BY ${t.csv(e.order.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
606
613
  if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
607
614
  a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
@@ -612,7 +619,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
612
619
  }
613
620
  return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
614
621
  }
615
- let r = e.annClause === void 0 ? null : kn(e.annClause, t);
622
+ let r = e.annClause === void 0 ? null : On(e.annClause, t);
616
623
  e.spatialClause !== void 0 && t.onDialectOrElse({
617
624
  mysql: () => {
618
625
  throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
@@ -625,16 +632,16 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
625
632
  },
626
633
  orElse: () => t``
627
634
  });
628
- let i = e.spatialClause?.projectAs === void 0 ? null : An(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Dn(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Fn(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
635
+ let i = e.spatialClause?.projectAs === void 0 ? null : kn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? En(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Pn(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
629
636
  orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
630
637
  mysql: () => t`DISTINCT `,
631
638
  mssql: () => t`DISTINCT `,
632
639
  sqlite: () => t`DISTINCT `
633
640
  }) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(yn(n, e.table))}` : t`${t(yn(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
634
641
  let r = e.kind === "inner" ? "INNER" : "LEFT";
635
- return t` ${t.unsafe(r)} JOIN ${t(yn(n, e.table))} AS ${t(e.alias)} ON ${I(e.on, t, n)}`;
636
- }), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Pn(c, e.table, t), ee = [e.predicate ? I(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), _ = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, v = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, y = e.having ? t` HAVING ${I(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
637
- r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${jn(e.spatialClause, t)} DESC` : t`${jn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
642
+ return t` ${t.unsafe(r)} JOIN ${t(yn(n, e.table))} AS ${t(e.alias)} ON ${L(e.on, t, n)}`;
643
+ }), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Nn(c, e.table, t), ee = [e.predicate ? L(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), _ = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, v = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, y = e.having ? t` HAVING ${L(e.having, t, n, e.table)}` : t``, b = e.skip !== void 0, x = [];
644
+ r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${An(e.spatialClause, t)} DESC` : t`${An(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
638
645
  for (let n of e.order) x.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
639
646
  let te = x.length > 0 ? t` ORDER BY ${t.csv(x)}` : b ? t.onDialectOrElse({
640
647
  mssql: () => t` ORDER BY (SELECT NULL)`,
@@ -642,7 +649,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
642
649
  }) : t``, S = (e) => {
643
650
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
644
651
  return t.unsafe(String(e));
645
- }, ne = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${L(e.descriptor, t, n)})`), re = (e.ctes ?? []).some((e) => e.recursive === !0), C = ne.length > 0 ? t`WITH ${t.unsafe(re ? "RECURSIVE " : "")}${t.csv(ne)} ` : t``;
652
+ }, ne = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${R(e.descriptor, t, n)})`), re = (e.ctes ?? []).some((e) => e.recursive === !0), C = ne.length > 0 ? t`WITH ${t.unsafe(re ? "RECURSIVE " : "")}${t.csv(ne)} ` : t``;
646
653
  return t.onDialectOrElse({
647
654
  mssql: () => {
648
655
  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``;
@@ -653,7 +660,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
653
660
  return t`${C}SELECT ${f}${d} FROM ${h}${_}${v}${y}${te}${n}${r}`;
654
661
  }
655
662
  });
656
- }, In = (e, t, n) => {
663
+ }, Fn = (e, t, n) => {
657
664
  if (e.eager === void 0) return null;
658
665
  let r = Ln(e.table, e.eager, e.sourceTable);
659
666
  if (r === null) return null;
@@ -662,7 +669,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
662
669
  fragment: i,
663
670
  decode: qn(r, n)
664
671
  };
665
- }, R = (e) => e.relation.kind === "one" && e.fkSide === "target", z = (e) => ({
672
+ }, z = (e) => e.relation.kind === "one" && e.fkSide === "target", In = (e) => ({
666
673
  ...e,
667
674
  branch: {
668
675
  ...e.branch,
@@ -764,7 +771,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
764
771
  let r = [];
765
772
  for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
766
773
  let i = t.map((e) => {
767
- let t = Jn(e.target, e.children, n), r = e.relation.kind === "one", i = R(e), a = i ? tn({
774
+ let t = Jn(e.target, e.children, n), r = e.relation.kind === "one", i = z(e), a = i ? tn({
768
775
  relationName: e.relationName,
769
776
  sourceTableName: e.source.tableName,
770
777
  targetTableName: e.target.tableName,
@@ -836,7 +843,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
836
843
  return i`${a} || jsonb_build_object(${i.csv(o)})`;
837
844
  }, Qn = (e, t, n) => {
838
845
  switch (e.relation.kind) {
839
- case "one": return R(e) ? er(z(e), t, n) : $n(e, t, n);
846
+ case "one": return z(e) ? er(In(e), t, n) : $n(e, t, n);
840
847
  case "many": return er(e, t, n);
841
848
  case "manyToMany": return tr(e, t, n);
842
849
  }
@@ -848,12 +855,12 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
848
855
  }, er = (e, t, n) => {
849
856
  let r = n.sql, i = n.nextAlias(), a = Zn(i, e.children, n);
850
857
  if (a === null) return null;
851
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
858
+ let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
852
859
  return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
853
860
  }, tr = (e, t, n) => {
854
861
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Zn(o, e.children, n, e.junction);
855
862
  if (c === null) return null;
856
- let l = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, u = K(e, s, r), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${nr(e.junction, s, r)} AS ${r(Vn)}`;
863
+ let l = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, u = K(e, s, r), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${nr(e.junction, s, r)} AS ${r(Vn)}`;
857
864
  return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
858
865
  }, nr = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${U(e, n)}, ${H(t, e, n)}`))})`, B = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${H(e, t.column, n)} DESC` : n`${H(e, t.column, n)} ASC`))}`, rr = (e, t) => e === void 0 || e.length === 0 ? t`` : t` ORDER BY ${t.csv(e.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`, ir = (e, t, n) => {
859
866
  let r = n.sql, i = n.nextAlias(), a = ar(i, t.table, t.children, n);
@@ -881,7 +888,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
881
888
  physical: (e) => e
882
889
  }), ur = (e, t, n) => {
883
890
  switch (e.relation.kind) {
884
- case "one": return R(e) ? fr(z(e), t, n) : dr(e, t, n);
891
+ case "one": return z(e) ? fr(In(e), t, n) : dr(e, t, n);
885
892
  case "many": return fr(e, t, n);
886
893
  case "manyToMany": return pr(e, t, n);
887
894
  }
@@ -893,7 +900,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
893
900
  }, fr = (e, t, n) => {
894
901
  let r = n.sql, i = n.nextAlias(), a = ar(i, e.target, e.children, n);
895
902
  if (a === null) return null;
896
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
903
+ let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
897
904
  return r`COALESCE((SELECT json_group_array(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), json('[]'))`;
898
905
  }, pr = (e, t, n) => {
899
906
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ar(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
@@ -901,7 +908,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
901
908
  source: cr(o)
902
909
  });
903
910
  if (c === null) return null;
904
- let l = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : sr(e.junction, s, r);
911
+ let l = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : sr(e.junction, s, r);
905
912
  return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
906
913
  }, mr = (e, t, n) => {
907
914
  let r = n.sql, i = n.nextAlias(), a = V(i, t.table, t.children, n);
@@ -924,8 +931,8 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
924
931
  }, hr = (e, t, n) => {
925
932
  switch (e.relation.kind) {
926
933
  case "one":
927
- if (R(e)) {
928
- let r = z(e);
934
+ if (z(e)) {
935
+ let r = In(e);
929
936
  return n.dialect === "mariadb" ? yr(r, t, n) : _r(r, t, n);
930
937
  }
931
938
  return gr(e, t, n);
@@ -940,7 +947,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
940
947
  }, _r = (e, t, n) => {
941
948
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
942
949
  if (a === null) return null;
943
- let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
950
+ let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = rr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`;
944
951
  return r`COALESCE((SELECT JSON_ARRAYAGG(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), JSON_ARRAY())`;
945
952
  }, vr = (e, t, n) => {
946
953
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = V(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
@@ -948,12 +955,12 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
948
955
  source: cr(o)
949
956
  });
950
957
  if (c === null) return null;
951
- let l = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : sr(e.junction, s, r);
958
+ let l = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = B(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : sr(e.junction, s, r);
952
959
  return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
953
960
  }, yr = (e, t, n) => {
954
961
  let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
955
962
  if (a === null) return null;
956
- let o = r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
963
+ let o = r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
957
964
  if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
958
965
  let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${H(i, "rn", r)} > ${W(d, r)} AND ${H(i, "rn", r)} <= ${W(d + u, r)}` : u === void 0 ? r` AND ${H(i, "rn", r)} > ${W(d, r)}` : r` AND ${H(i, "rn", r)} <= ${W(u, r)}`;
959
966
  return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${H(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
@@ -961,7 +968,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
961
968
  let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
962
969
  projection: e.junction,
963
970
  source: t
964
- }, l = r`${H(s, i.sourceKey, r)} = ${H(t, "id", r)}`, u = r`${H(o, "id", r)} = ${H(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${I(q(e.branch.where), r)}`, f = K(e, s, r, !0), p = e.branch.orderBy ?? [];
971
+ }, l = r`${H(s, i.sourceKey, r)} = ${H(t, "id", r)}`, u = r`${H(o, "id", r)} = ${H(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${L(q(e.branch.where), r)}`, f = K(e, s, r, !0), p = e.branch.orderBy ?? [];
965
972
  if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
966
973
  let t = V(o, e.target, e.children, n, c(lr(s)));
967
974
  return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${H(o, e.column, r)} DESC` : r`${H(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
@@ -992,7 +999,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
992
999
  return a.csv(o);
993
1000
  }, Cr = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), wr = (e, t, n) => {
994
1001
  switch (e.relation.kind) {
995
- case "one": return R(e) ? Dr(z(e), t, n) : Tr(e, t, n);
1002
+ case "one": return z(e) ? Dr(In(e), t, n) : Tr(e, t, n);
996
1003
  case "many": return Dr(e, t, n);
997
1004
  case "manyToMany": return Or(e, t, n);
998
1005
  }
@@ -1031,7 +1038,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1031
1038
  }, H = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, U = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), W = (e, t) => {
1032
1039
  if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
1033
1040
  return t.unsafe(String(e));
1034
- }, G = (e, t, n) => I(kr(e, t), n), K = (e, t, n, r = !1) => {
1041
+ }, G = (e, t, n) => L(kr(e, t), n), K = (e, t, n, r = !1) => {
1035
1042
  let i = e.branch.onJunction;
1036
1043
  return i === void 0 ? n`` : n` AND ${G(r ? q(i) : i, t, n)}`;
1037
1044
  }, kr = (e, t) => {
@@ -1115,27 +1122,31 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1115
1122
  value: t
1116
1123
  }), Jr = (e, t) => ({
1117
1124
  column: e,
1118
- op: "arrayContains",
1125
+ op: "startsWith",
1119
1126
  value: t
1120
1127
  }), Yr = (e, t) => ({
1121
1128
  column: e,
1122
- op: "arrayOverlaps",
1129
+ op: "arrayContains",
1123
1130
  value: t
1124
1131
  }), Xr = (e, t) => ({
1132
+ column: e,
1133
+ op: "arrayOverlaps",
1134
+ value: t
1135
+ }), Zr = (e, t) => ({
1125
1136
  column: e,
1126
1137
  op: "arrayHas",
1127
1138
  value: t
1128
- }), Zr = (e) => ({
1139
+ }), Qr = (e) => ({
1129
1140
  column: e,
1130
1141
  op: "isNull"
1131
- }), Qr = (e) => ({
1142
+ }), $r = (e) => ({
1132
1143
  column: e,
1133
1144
  op: "isNotNull"
1134
- }), $r = (e, t) => ({
1145
+ }), ei = (e, t) => ({
1135
1146
  column: e,
1136
1147
  op: "spatial",
1137
1148
  value: t
1138
- }), ei = (...e) => ({ and: e }), ti = (...e) => ({ or: e }), ni = (e) => ({ not: e }), ri = (e, ...t) => {
1149
+ }), ti = (...e) => ({ and: e }), ni = (...e) => ({ or: e }), ri = (e) => ({ not: e }), ii = (e, ...t) => {
1139
1150
  if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
1140
1151
  let n = (n, r) => ({
1141
1152
  column: e,
@@ -1153,32 +1164,33 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1153
1164
  inSet: (e) => n("in", e),
1154
1165
  notInSet: (e) => n("notIn", e),
1155
1166
  contains: (e) => n("contains", e),
1167
+ startsWith: (e) => n("startsWith", e),
1156
1168
  isNull: () => n("isNull"),
1157
1169
  isNotNull: () => n("isNotNull")
1158
1170
  };
1159
- }, ii = (e) => "descriptor" in e ? e.descriptor : e, ai = (e, t) => ({
1171
+ }, ai = (e) => "descriptor" in e ? e.descriptor : e, oi = (e, t) => ({
1160
1172
  column: e,
1161
1173
  op: "subquery-in",
1162
- subquery: ii(t)
1163
- }), oi = (e, t) => ({
1174
+ subquery: ai(t)
1175
+ }), si = (e, t) => ({
1164
1176
  column: e,
1165
1177
  op: "subquery-not-in",
1166
- subquery: ii(t)
1167
- }), si = (e) => ({
1168
- op: "exists",
1169
- subquery: ii(e)
1178
+ subquery: ai(t)
1170
1179
  }), ci = (e) => ({
1180
+ op: "exists",
1181
+ subquery: ai(e)
1182
+ }), li = (e) => ({
1171
1183
  op: "not-exists",
1172
- subquery: ii(e)
1173
- }), li = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, ui = (e, t, n = null) => {
1184
+ subquery: ai(e)
1185
+ }), ui = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, di = (e, t, n = null) => {
1174
1186
  if (!t) return !1;
1175
- if ("not" in e) return !ui(e.not, t, n);
1187
+ if ("not" in e) return !di(e.not, t, n);
1176
1188
  if ("and" in e) {
1177
- for (let r of e.and) if (!ui(r, t, n)) return !1;
1189
+ for (let r of e.and) if (!di(r, t, n)) return !1;
1178
1190
  return !0;
1179
1191
  }
1180
1192
  if ("or" in e) {
1181
- for (let r of e.or) if (ui(r, t, n)) return !0;
1193
+ for (let r of e.or) if (di(r, t, n)) return !0;
1182
1194
  return !1;
1183
1195
  }
1184
1196
  if (e.op === "subquery-in" || e.op === "subquery-not-in") {
@@ -1197,13 +1209,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1197
1209
  switch (r.op) {
1198
1210
  case "eq": return i === r.value;
1199
1211
  case "neq": return i !== r.value;
1200
- case "gt": return (li(i, r.value) ?? -1) > 0;
1201
- case "gte": return (li(i, r.value) ?? -1) >= 0;
1202
- case "lt": return (li(i, r.value) ?? 1) < 0;
1203
- case "lte": return (li(i, r.value) ?? 1) <= 0;
1212
+ case "gt": return (ui(i, r.value) ?? -1) > 0;
1213
+ case "gte": return (ui(i, r.value) ?? -1) >= 0;
1214
+ case "lt": return (ui(i, r.value) ?? 1) < 0;
1215
+ case "lte": return (ui(i, r.value) ?? 1) <= 0;
1204
1216
  case "in": return Array.isArray(r.value) && r.value.includes(i);
1205
1217
  case "notIn": return Array.isArray(r.value) && !r.value.includes(i);
1206
1218
  case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
1219
+ case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
1207
1220
  case "arrayContains": {
1208
1221
  let e = Array.isArray(i) ? i : [];
1209
1222
  return (Array.isArray(r.value) ? r.value : []).every((t) => e.includes(t));
@@ -1217,17 +1230,17 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1217
1230
  case "isNotNull": return i != null;
1218
1231
  case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
1219
1232
  }
1220
- }, di = function* (e) {
1233
+ }, fi = function* (e) {
1221
1234
  if ("not" in e) {
1222
- yield* di(e.not);
1235
+ yield* fi(e.not);
1223
1236
  return;
1224
1237
  }
1225
1238
  if ("and" in e) {
1226
- for (let t of e.and) yield* di(t);
1239
+ for (let t of e.and) yield* fi(t);
1227
1240
  return;
1228
1241
  }
1229
1242
  if ("or" in e) {
1230
- for (let t of e.or) yield* di(t);
1243
+ for (let t of e.or) yield* fi(t);
1231
1244
  return;
1232
1245
  }
1233
1246
  e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
@@ -1237,27 +1250,27 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1237
1250
  kind: "exists",
1238
1251
  descriptor: e.subquery
1239
1252
  });
1240
- }, fi = function* (e, t = !0) {
1253
+ }, pi = function* (e, t = !0) {
1241
1254
  if ("not" in e) {
1242
- yield* fi(e.not, !1);
1255
+ yield* pi(e.not, !1);
1243
1256
  return;
1244
1257
  }
1245
1258
  if ("and" in e) {
1246
- for (let n of e.and) yield* fi(n, t);
1259
+ for (let n of e.and) yield* pi(n, t);
1247
1260
  return;
1248
1261
  }
1249
1262
  if ("or" in e) {
1250
- for (let t of e.or) yield* fi(t, !1);
1263
+ for (let t of e.or) yield* pi(t, !1);
1251
1264
  return;
1252
1265
  }
1253
1266
  e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists" || (yield {
1254
1267
  ...e,
1255
1268
  conjunctive: t
1256
1269
  });
1257
- }, pi = class extends st.TaggedError("TableStreamError") {}, mi = 1e3, hi = (e, t, n, r) => {
1270
+ }, mi = class extends st.TaggedError("TableStreamError") {}, hi = 1e3, gi = (e, t, n, r) => {
1258
1271
  let i = k.match(r, {
1259
1272
  onNone: () => e.where,
1260
- onSome: (n) => e.where ? ei(e.where, Vr(t, n)) : Vr(t, n)
1273
+ onSome: (n) => e.where ? ti(e.where, Vr(t, n)) : Vr(t, n)
1261
1274
  });
1262
1275
  return {
1263
1276
  table: e.table,
@@ -1272,19 +1285,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1272
1285
  ...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
1273
1286
  ...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
1274
1287
  };
1275
- }, gi = (e, t) => {
1276
- let n = t.pk ?? "id", r = t.chunkSize ?? mi;
1288
+ }, _i = (e, t) => {
1289
+ let n = t.pk ?? "id", r = t.chunkSize ?? hi;
1277
1290
  return lt.paginateChunkEffect(k.none(), (i) => {
1278
1291
  let a = ct.tryPromise({
1279
- try: () => e.query(hi(t, n, r, i)),
1280
- catch: (e) => new pi({
1292
+ try: () => e.query(gi(t, n, r, i)),
1293
+ catch: (e) => new mi({
1281
1294
  table: t.table,
1282
1295
  cause: e
1283
1296
  })
1284
1297
  });
1285
1298
  return (t.retry ? a.pipe(ct.retry(t.retry)) : a).pipe(ct.map((e) => [ot.fromIterable(e), e.length === r && e.length > 0 ? k.some(k.some(e[e.length - 1][n])) : k.none()]));
1286
1299
  });
1287
- }, _i = (e) => {
1300
+ }, vi = (e) => {
1288
1301
  let t = e.alpha ?? .5;
1289
1302
  if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
1290
1303
  return (n) => {
@@ -1311,14 +1324,14 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1311
1324
  }
1312
1325
  };
1313
1326
  };
1314
- }, vi = async (e, t) => {
1327
+ }, yi = async (e, t) => {
1315
1328
  let n = e.as ?? "embedding", r = t.row[e.from];
1316
1329
  if (typeof r != "string" || r.length === 0) return {};
1317
1330
  let i = await t.embed(r);
1318
1331
  return { [n]: i };
1319
- }, yi = (e) => {
1332
+ }, bi = (e) => {
1320
1333
  if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
1321
- let t = e.as ?? "embedding", n = (t) => vi(e, t);
1334
+ let t = e.as ?? "embedding", n = (t) => yi(e, t);
1322
1335
  return d({
1323
1336
  id: "voltro/vectorEmbedding",
1324
1337
  fields: { [t]: y(e.dimensions) },
@@ -1336,19 +1349,19 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1336
1349
  beforeUpdate: n
1337
1350
  }
1338
1351
  });
1339
- }, bi = 63, xi = "br_pr", J = class extends Error {
1352
+ }, xi = 63, Si = "br_pr", J = class extends Error {
1340
1353
  _tag = "BranchNameInvalid";
1341
1354
  constructor(e) {
1342
1355
  super(e), this.name = "BranchNameInvalid";
1343
1356
  }
1344
- }, Si = (e, t) => {
1357
+ }, Ci = (e, t) => {
1345
1358
  if (!Number.isInteger(t) || t < 0) throw new J(`prNumber must be a non-negative integer, got ${String(t)}`);
1346
1359
  let n = _n(e);
1347
1360
  if (n.replace(/_/g, "") === "") throw new J(`app slug '${e}' has no usable identifier characters`);
1348
- let r = `${xi}${t}_${n}`;
1349
- if (r.length > bi) throw new J(`branch namespace '${r}' exceeds the ${bi}-byte identifier limit — use a shorter app slug`);
1361
+ let r = `${Si}${t}_${n}`;
1362
+ if (r.length > xi) throw new J(`branch namespace '${r}' exceeds the ${xi}-byte identifier limit — use a shorter app slug`);
1350
1363
  return r;
1351
- }, Ci = (e) => e.startsWith(xi), wi = {
1364
+ }, wi = (e) => e.startsWith(Si), Ti = {
1352
1365
  requested: {
1353
1366
  provision: "provisioning",
1354
1367
  destroy: "destroying"
@@ -1367,18 +1380,18 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1367
1380
  fail: "failed"
1368
1381
  },
1369
1382
  destroyed: {}
1370
- }, Ti = class extends Error {
1383
+ }, Ei = class extends Error {
1371
1384
  from;
1372
1385
  event;
1373
1386
  _tag = "BranchTransitionInvalid";
1374
1387
  constructor(e, t) {
1375
1388
  super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
1376
1389
  }
1377
- }, Ei = (e, t) => {
1378
- let n = wi[e][t];
1379
- if (n === void 0) throw new Ti(e, t);
1390
+ }, Di = (e, t) => {
1391
+ let n = Ti[e][t];
1392
+ if (n === void 0) throw new Ei(e, t);
1380
1393
  return n;
1381
- }, Di = (e, t, n, r) => {
1394
+ }, Oi = (e, t, n, r) => {
1382
1395
  if (n === "copy" && (r === void 0 || r === "")) throw new J("seed 'copy' requires a parentNamespace to snapshot from");
1383
1396
  let i = [{
1384
1397
  kind: "create-namespace",
@@ -1399,13 +1412,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1399
1412
  detail: `run boot seeds into ${e}`
1400
1413
  });
1401
1414
  return i;
1402
- }, Oi = (e) => {
1403
- if (!Ci(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
1415
+ }, ki = (e) => {
1416
+ if (!wi(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
1404
1417
  return [{
1405
1418
  kind: "drop-namespace",
1406
1419
  detail: e
1407
1420
  }];
1408
- }, ki = (e) => {
1421
+ }, Ai = (e) => {
1409
1422
  if (e === void 0 || e === "") return !1;
1410
1423
  try {
1411
1424
  let t = new URL(e).hostname.toLowerCase();
@@ -1413,27 +1426,27 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1413
1426
  } catch {
1414
1427
  return /\bneon\.(tech|build)\b/i.test(e);
1415
1428
  }
1416
- }, Ai = (e) => e.prefer === void 0 ? e.seed === "copy" && ki(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, ji = (e, t = {}) => [{
1429
+ }, ji = (e) => e.prefer === void 0 ? e.seed === "copy" && Ai(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Mi = (e, t = {}) => [{
1417
1430
  kind: "neon-branch-create",
1418
1431
  detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
1419
- }], Mi = (e) => {
1420
- if (!Ci(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
1432
+ }], Ni = (e) => {
1433
+ if (!wi(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
1421
1434
  return [{
1422
1435
  kind: "neon-branch-delete",
1423
1436
  detail: e
1424
1437
  }];
1425
- }, Ni = (e) => e.mechanism === "neon-cow" ? ji(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Di(e.branchId, e.tableNames, e.seed, e.parentNamespace), Pi = (e, t) => e === "neon-cow" ? Mi(t) : Oi(t), Fi = (e, t, n) => {
1438
+ }, Pi = (e) => e.mechanism === "neon-cow" ? Mi(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Oi(e.branchId, e.tableNames, e.seed, e.parentNamespace), Fi = (e, t) => e === "neon-cow" ? Ni(t) : ki(t), Ii = (e, t, n) => {
1426
1439
  let r = e.filter((e) => e.state !== "destroyed" && e.state !== "destroying"), i = r.filter((e) => n - e.createdAtMs > t.ttlMs).map((e) => e.namespace), a = new Set(i);
1427
1440
  return {
1428
1441
  evict: i,
1429
1442
  rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
1430
1443
  };
1431
- }, Ii = async (e, t) => {
1432
- let n = Si(e.appSlug, e.prNumber), r = Ai({
1444
+ }, Li = async (e, t) => {
1445
+ let n = Ci(e.appSlug, e.prNumber), r = ji({
1433
1446
  seed: e.seed,
1434
1447
  ...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
1435
1448
  ...e.prefer === void 0 ? {} : { prefer: e.prefer }
1436
- }), i = Ni({
1449
+ }), i = Pi({
1437
1450
  mechanism: r,
1438
1451
  branchId: n,
1439
1452
  tableNames: e.tableNames,
@@ -1458,10 +1471,10 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1458
1471
  mechanism: r,
1459
1472
  steps: i
1460
1473
  };
1461
- }, Li = async (e, t, n) => {
1462
- let r = Pi(t, e);
1474
+ }, Ri = async (e, t, n) => {
1475
+ let r = Fi(t, e);
1463
1476
  return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
1464
- }, Ri = (e, t, n) => Fi(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, zi = (e) => {
1477
+ }, zi = (e, t, n) => Ii(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, Bi = (e) => {
1465
1478
  let t = () => {
1466
1479
  throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
1467
1480
  };
@@ -1473,18 +1486,18 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1473
1486
  neonBranchCreate: t,
1474
1487
  neonBranchDelete: t
1475
1488
  };
1476
- }, Bi = class extends Error {
1489
+ }, Vi = class extends Error {
1477
1490
  _tag = "TenantResidencyUnresolved";
1478
1491
  constructor(e) {
1479
1492
  super(e), this.name = "TenantResidencyUnresolved";
1480
1493
  }
1481
- }, Vi = class extends Error {
1494
+ }, Hi = class extends Error {
1482
1495
  region;
1483
1496
  _tag = "TenantRegionUnavailable";
1484
1497
  constructor(e, t) {
1485
1498
  super(t), this.region = e, this.name = "TenantRegionUnavailable";
1486
1499
  }
1487
- }, Hi, Ui = (e) => {
1500
+ }, Ui, Wi = (e) => {
1488
1501
  if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
1489
1502
  if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
1490
1503
  let t = /* @__PURE__ */ new Map();
@@ -1493,32 +1506,32 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1493
1506
  if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
1494
1507
  t.set(n.tenantId, n.region);
1495
1508
  }
1496
- return Hi = e, e;
1497
- }, Wi = () => Hi, Gi = () => {
1498
- Hi = void 0;
1499
- }, Ki = (e, t) => {
1500
- if (e == null || e === "") throw new Bi("residency is on but the request has no resolvable tenant — refusing to bind a store");
1509
+ return Ui = e, e;
1510
+ }, Gi = () => Ui, Ki = () => {
1511
+ Ui = void 0;
1512
+ }, qi = (e, t) => {
1513
+ if (e == null || e === "") throw new Vi("residency is on but the request has no resolvable tenant — refusing to bind a store");
1501
1514
  let n = t.homes.find((t) => t.tenantId === e);
1502
- if (n === void 0) throw new Bi(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
1515
+ if (n === void 0) throw new Vi(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
1503
1516
  return n;
1504
- }, qi = (e, t) => t.servableRegions.includes(e), Ji = (e, t) => {
1505
- let n = Ki(e.tenantId, t), r = vn(n.tenantId);
1517
+ }, Ji = (e, t) => t.servableRegions.includes(e), Yi = (e, t) => {
1518
+ let n = qi(e.tenantId, t), r = vn(n.tenantId);
1506
1519
  return {
1507
1520
  region: n.region,
1508
1521
  namespace: r,
1509
1522
  ...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
1510
1523
  };
1511
- }, Yi = (e, t, n) => {
1512
- let r = Ji(e, t);
1513
- if (!qi(r.region, t)) throw new Vi(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
1524
+ }, Xi = (e, t, n) => {
1525
+ let r = Yi(e, t);
1526
+ if (!Ji(r.region, t)) throw new Hi(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
1514
1527
  let i = n.get(r.region);
1515
- if (i === void 0) throw new Vi(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
1528
+ if (i === void 0) throw new Hi(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
1516
1529
  return {
1517
1530
  store: i,
1518
1531
  placement: r
1519
1532
  };
1520
- }, Xi = async (e, t, n, r) => {
1521
- let { store: i, placement: a } = Yi(e, t, n);
1533
+ }, Zi = async (e, t, n, r) => {
1534
+ let { store: i, placement: a } = Xi(e, t, n);
1522
1535
  return await r(i, a), a;
1523
1536
  }, X = (e) => {
1524
1537
  if (typeof e == "string") return e;
@@ -1527,21 +1540,21 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1527
1540
  return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
1528
1541
  }
1529
1542
  return `(${e.expr})`;
1530
- }, Z = (e) => e.map(X), Zi = (e, t) => {
1543
+ }, Z = (e) => e.map(X), Qi = (e, t) => {
1531
1544
  if (e.length !== t.length) return !1;
1532
1545
  for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
1533
1546
  return !0;
1534
- }, Qi = (e, t) => {
1547
+ }, $i = (e, t) => {
1535
1548
  if (e.length >= t.length) return !1;
1536
1549
  for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
1537
1550
  return !0;
1538
- }, $i = (e) => {
1551
+ }, ea = (e) => {
1539
1552
  let t = [], n = e.appliedIndexes, r = e.tableName;
1540
1553
  for (let e = 0; e < n.length; e++) {
1541
1554
  let i = n[e];
1542
1555
  for (let a = e + 1; a < n.length; a++) {
1543
1556
  let e = n[a];
1544
- if (Zi(i.fields, e.fields)) {
1557
+ if (Qi(i.fields, e.fields)) {
1545
1558
  let [n, a] = i.name < e.name ? [i, e] : [e, i];
1546
1559
  t.push({
1547
1560
  kind: "duplicate-fields",
@@ -1552,13 +1565,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1552
1565
  });
1553
1566
  continue;
1554
1567
  }
1555
- Qi(i.fields, e.fields) ? t.push({
1568
+ $i(i.fields, e.fields) ? t.push({
1556
1569
  kind: "redundant-prefix",
1557
1570
  table: r,
1558
1571
  redundant: i,
1559
1572
  coveredBy: e,
1560
1573
  message: `'${r}' index '${i.name}' on [${Z(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Z(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
1561
- }) : Qi(e.fields, i.fields) && t.push({
1574
+ }) : $i(e.fields, i.fields) && t.push({
1562
1575
  kind: "redundant-prefix",
1563
1576
  table: r,
1564
1577
  redundant: e,
@@ -1568,23 +1581,23 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1568
1581
  }
1569
1582
  }
1570
1583
  return t;
1571
- }, ea = (e) => {
1584
+ }, ta = (e) => {
1572
1585
  let t = [];
1573
- for (let n of e) t.push(...$i(n));
1586
+ for (let n of e) t.push(...ea(n));
1574
1587
  return t;
1575
- }, ta = "\x1B[", na = `${ta}38;2;245;158;11m`, ra = `${ta}38;2;16;185;129m`, ia = (e, t) => `${e}${t}${j.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : ia(t, n) : n, aa = (e, t = {}) => {
1576
- let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, j.dim, e.padEnd(11)), a = (e) => Q(n, (e) => j.bold(j.brand(e)), e), o = (e) => Q(n, j.brightRed24, e), s = (e) => Q(n, ra, e), c = (e) => Q(n, na, e), l = (e) => Q(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
1588
+ }, na = "\x1B[", ra = `${na}38;2;245;158;11m`, ia = `${na}38;2;16;185;129m`, aa = (e, t) => `${e}${t}${j.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : aa(t, n) : n, oa = (e, t = {}) => {
1589
+ let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, j.dim, e.padEnd(11)), a = (e) => Q(n, (e) => j.bold(j.brand(e)), e), o = (e) => Q(n, j.brightRed24, e), s = (e) => Q(n, ia, e), c = (e) => Q(n, ra, e), l = (e) => Q(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
1577
1590
  let n = e.slice(0, t), r = e.slice(t), i = [];
1578
1591
  return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
1579
1592
  }, m = [];
1580
1593
  return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${Q(n, j.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
1581
- }, oa = (e, t) => ({
1594
+ }, sa = (e, t) => ({
1582
1595
  name: e,
1583
1596
  body: t
1584
- }), sa = (e) => {
1597
+ }), ca = (e) => {
1585
1598
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
1586
1599
  if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
1587
- let t = e.steps({ step: oa });
1600
+ let t = e.steps({ step: sa });
1588
1601
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
1589
1602
  return {
1590
1603
  __seed: !0,
@@ -1596,13 +1609,13 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1596
1609
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
1597
1610
  steps: t
1598
1611
  };
1599
- }, ca = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, la = (e, { apply: t, undo: n }) => ({
1612
+ }, la = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, ua = (e, { apply: t, undo: n }) => ({
1600
1613
  name: e,
1601
1614
  apply: t,
1602
1615
  undo: n
1603
- }), ua = (e) => {
1616
+ }), da = (e) => {
1604
1617
  if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
1605
- let t = e.steps({ step: la });
1618
+ let t = e.steps({ step: ua });
1606
1619
  if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
1607
1620
  return {
1608
1621
  __migration: !0,
@@ -1610,7 +1623,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1610
1623
  name: e.name,
1611
1624
  steps: t
1612
1625
  };
1613
- }, da = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, fa = w("_voltro_migrations", {
1626
+ }, fa = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, pa = w("_voltro_migrations", {
1614
1627
  id: O({ prefix: "mig" }),
1615
1628
  name: E(),
1616
1629
  hash: E(),
@@ -1622,7 +1635,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1622
1635
  workflowRunId: E().nullable(),
1623
1636
  createdAt: _().default("now"),
1624
1637
  updatedAt: _().default("now").onUpdate("now")
1625
- }).index(["status"]), pa = w("_voltro_seeds", {
1638
+ }).index(["status"]), ma = w("_voltro_seeds", {
1626
1639
  id: O({ prefix: "seed" }),
1627
1640
  name: E(),
1628
1641
  lifecycle: E(),
@@ -1638,7 +1651,7 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1638
1651
  workflowRunId: E().nullable(),
1639
1652
  createdAt: _().default("now"),
1640
1653
  updatedAt: _().default("now").onUpdate("now")
1641
- }).index(["lifecycle"]).index(["nextRunAt"]), ma = w("_voltro_migration_plans", {
1654
+ }).index(["lifecycle"]).index(["nextRunAt"]), ha = w("_voltro_migration_plans", {
1642
1655
  id: O({ prefix: "plan" }),
1643
1656
  fingerprint: E(),
1644
1657
  operations: D(),
@@ -1653,21 +1666,21 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1653
1666
  appliedAt: _().default("now"),
1654
1667
  createdAt: _().default("now"),
1655
1668
  updatedAt: _().default("now").onUpdate("now")
1656
- }).index(["fingerprint"]).index(["environment"]), ha = w("_voltro_idempotency", {
1669
+ }).index(["fingerprint"]).index(["environment"]), ga = w("_voltro_idempotency", {
1657
1670
  id: O({ prefix: "idem" }),
1658
1671
  scope: E(),
1659
1672
  key: E(),
1660
1673
  status: E(),
1661
1674
  response: D().nullable(),
1662
1675
  createdAt: _().default("now")
1663
- }).unique(["scope", "key"]).index(["createdAt"]), ga = w("_voltro_kv", {
1676
+ }).unique(["scope", "key"]).index(["createdAt"]), _a = w("_voltro_kv", {
1664
1677
  id: O({ prefix: "kv" }),
1665
1678
  key: E().unique(),
1666
1679
  value: E().nullable(),
1667
1680
  expiresAt: _().nullable(),
1668
1681
  createdAt: _().default("now"),
1669
1682
  updatedAt: _().default("now").onUpdate("now")
1670
- }).index(["expiresAt"]), _a = w("_voltro_api_keys", {
1683
+ }).index(["expiresAt"]), va = w("_voltro_api_keys", {
1671
1684
  id: O({ prefix: "apikey" }),
1672
1685
  tenantId: E().nullable(),
1673
1686
  name: E(),
@@ -1682,11 +1695,11 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1682
1695
  onBehalfOf: E().nullable(),
1683
1696
  metadata: D().nullable(),
1684
1697
  createdAt: _().default("now")
1685
- }).index("byTenant", ["tenantId"]), va = [
1686
- fa,
1698
+ }).index("byTenant", ["tenantId"]), ya = [
1687
1699
  pa,
1688
- ma
1689
- ], $ = "id", ya = (e, t) => {
1700
+ ma,
1701
+ ha
1702
+ ], $ = "id", ba = (e, t) => {
1690
1703
  let n = u(e);
1691
1704
  if (n === void 0) return t;
1692
1705
  let r = n.fields[$]?.idScheme;
@@ -1701,53 +1714,53 @@ var dt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
1701
1714
  ...t,
1702
1715
  [$]: i
1703
1716
  };
1704
- }, ba = (e, t) => t.map((t) => ya(e, t)), xa = (e, t) => {
1717
+ }, xa = (e, t) => t.map((t) => ba(e, t)), Sa = (e, t) => {
1705
1718
  let n = [], r = t;
1706
1719
  for (let [t, i] of Object.entries(e.fields)) {
1707
1720
  let e = i;
1708
1721
  e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
1709
1722
  }
1710
1723
  return n;
1711
- }, Sa = (e, t) => {
1724
+ }, Ca = (e, t) => {
1712
1725
  let n = t;
1713
1726
  return e.filter((e) => n[e] === void 0 || n[e] === null);
1714
- }, Ca = (e, t, n) => e.insert(t.tableName, n), wa = (e, t, n, r) => e.upsert(t.tableName, n, {
1727
+ }, wa = (e, t, n) => e.insert(t.tableName, n), Ta = (e, t, n, r) => e.upsert(t.tableName, n, {
1715
1728
  conflictColumns: r.conflictColumns,
1716
1729
  ...r.update === void 0 ? {} : { update: r.update }
1717
- }), Ta = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Ea = 512, Da = (e) => {
1730
+ }), Ea = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Da = 512, Oa = (e) => {
1718
1731
  e.setMaxListeners(512);
1719
- }, Oa = (e, t, n) => ({
1732
+ }, ka = (e, t, n) => ({
1720
1733
  _tag: "PrimaryKeyConflictError",
1721
1734
  table: e,
1722
1735
  key: t,
1723
1736
  cause: n
1724
- }), ka = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Aa = /* @__PURE__ */ new Map(), ja = (e) => {
1737
+ }), Aa = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", ja = /* @__PURE__ */ new Map(), Ma = (e) => {
1725
1738
  if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
1726
1739
  if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
1727
- Aa.set(e.table, e);
1728
- }, Ma = () => [...Aa.values()], Na = () => Aa.clear(), Pa = async (e, t, n, r = 2e4) => {
1740
+ ja.set(e.table, e);
1741
+ }, Na = () => [...ja.values()], Pa = () => ja.clear(), Fa = async (e, t, n, r = 2e4) => {
1729
1742
  let i = new Date(t - e.ttlMs), a = 0;
1730
1743
  for (;;) {
1731
1744
  let t = await n(e.table, e.timeColumn, i, r, e.where);
1732
1745
  if (a += t, t < r) break;
1733
1746
  }
1734
1747
  return a;
1735
- }, Fa = (e, t) => {
1748
+ }, Ia = (e, t) => {
1736
1749
  let n = Number(e ?? String(t));
1737
1750
  return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
1738
- }, Ia = "_voltro_cdc_offsets", La = w(Ia, {
1751
+ }, La = "_voltro_cdc_offsets", Ra = w(La, {
1739
1752
  id: O({ prefix: "cdcoff" }),
1740
1753
  replicaId: E(),
1741
1754
  streamName: E(),
1742
1755
  binlogFile: E(),
1743
1756
  binlogPosition: E(),
1744
1757
  updatedAt: _()
1745
- }).index(["replicaId"]), Ra = w(Ia, {
1758
+ }).index(["replicaId"]), za = w(La, {
1746
1759
  id: O({ prefix: "cdcoff" }),
1747
1760
  replicaId: E(),
1748
1761
  streamName: E(),
1749
1762
  ctVersion: E(),
1750
1763
  updatedAt: _()
1751
- }).index(["replicaId"]), za = "postgres";
1764
+ }).index(["replicaId"]), Ba = "postgres";
1752
1765
  //#endregion
1753
- export { oe as AUTO_FILLED_COLUMNS, J as BranchNameInvalid, Ti as BranchTransitionInvalid, Ia as CDC_OFFSETS_TABLE, Ea as CHANGE_LISTENER_CEILING, Xe as ColumnBuilder, ht as ENCRYPTED_PREFIX, za as ENGINE, en as EagerCardinalityError, qe as FILE_MIGRATION_PATTERN, gt as FieldDecryptionError, e as MAX_IDENTIFIER_LENGTH, ut as SqlClient, pi as TableStreamError, mn as TenantNamespaceInvalid, pn as TenantNamespaceUnresolved, Vi as TenantRegionUnavailable, Bi as TenantResidencyUnresolved, xe as WARN_IDENTIFIER_LENGTH, _a as _voltroApiKeysTable, La as _voltroCdcOffsetsTable, ha as _voltroIdempotencyTable, ga as _voltroKvTable, ma as _voltroMigrationPlansTable, fa as _voltroMigrationsTable, Ra as _voltroMssqlCdcOffsetsTable, pa as _voltroSeedsTable, Rr as actorsTable, Ri as admitBranch, ze as allEnumRenames, Ut as allRegisteredRelations, ee as allRegisteredTables, ei as and, be as array, Jr as arrayContains, Xr as arrayHas, Yr as arrayOverlaps, nn as attachEagerLoads, ea as auditAllTableIndexes, $i as auditTableIndexes, Me as avg, Ye as avgOver, Ce as bigint, Yi as bindResidentStore, Ve as boolean, Si as branchNamespaceName, Fe as bytes, Ke as clearEnumRenames, Gt as clearRelationsRegistry, Gi as clearResidencyConfig, Na as clearRetentions, v as clearTableRegistry, Sn as coercePredicateValue, Cn as coercePredicateValues, di as collectSubqueries, ye as column, St as columnSchema, In as compileEagerJson, I as compilePredicate, wn as compileRawFragment, L as compileSelect, vi as computeEmbedding, qr as contains, Se as count, Be as countDistinct, Pe as databaseHandle, De as date, Te as dbEnum, fe as decimal, ve as declareEnumRename, Zt as decodeRowsFromSchema, xt as decryptFieldsOnRead, ua as defineMigration, d as defineMixin, sa as defineSeed, Ee as denseRank, m as deriveTypeIdPrefix, mt as deserializeArraysOnRead, Je as drainIdentifierWarnings, Qe as dropped, $t as encodeRowForSchema, bt as encryptFieldsForWrite, yt as encryptedColumnsOf, Fi as enforceBranchLimits, te as ensureTableRegistered, zr as eq, Tn as escapeLike, ui as evaluatePredicate, we as except, si as exists, aa as formatIndexAuditIssue, va as frameworkTables, le as generateId, ue as generateSnowflake, nt as geography, ge as geometry, Ne as getEnumRenames, Ht as getRelation, Vt as getRelations, Wi as getResidencyConfig, u as getTable, Vr as gt, Hr as gte, fn as hasEagerLoads, _i as hybridSearch, O as id, Gr as inSet, ai as inSubquery, M as inferForeignKey, Ca as insertRow, C as integer, de as intersect, a as interval, Ci as isBranchNamespace, vt as isEncrypted, _t as isFieldDecryptionError, Ie as isFileMigration, da as isMigrationDefinition, ki as isNeonConnection, Qr as isNotNull, Zr as isNull, ka as isPrimaryKeyConflictError, qi as isRegionServable, At as isRelationsSpec, ca as isSeedDefinition, rt as isSqliteFamily, p as isTableReactive, pe as isView, D as json, ri as jsonField, f as jsonIndex, Ze as lag, tt as lead, Ma as listRetentions, Ur as lt, Wr as lte, zi as makeNamespaceBranchExecutor, Mt as many, Nt as manyToMany, ae as materializeFields, he as max, Ue as migration, et as min, Sa as missingConflictColumns, xa as missingRequiredColumns, h as mixin, Br as neq, Ei as nextBranchState, ni as not, ci as notExists, Kr as notInSet, oi as notInSubquery, l as numeric, jt as one, tn as oneCardinalityMessage, ti as or, re as paginateBy, i as paginateById, Ni as planBranch, Di as planBranchProvision, Oi as planBranchTeardown, Pi as planBranchTeardownFor, ji as planNeonBranchProvision, Mi as planNeonBranchTeardown, Oa as primaryKeyConflictError, Ii as provisionBranch, Xi as provisionResidentTenant, yn as qualifyTable, $e as queryFor, Re as queryForView, r as quoteIdent, Da as raiseChangeListenerCeiling, ie as rank, s as raw, x as real, je as reference, Pr as registerCoreTables, Bt as registerDiscoveredRelations, zt as registerRelations, ja as registerRetention, g as registerTable, kt as relations, Ir as requireActors, ne as requireTable, Lr as requireTenants, S as resetSnowflake, Ji as residentPlacement, Ai as resolveBranchMechanism, c as resolveFullTextIndex, ce as resolveIdScheme, He as resolveMixinGraph, Ki as resolveTenantHome, vn as resolveTenantNamespace, Fa as retentionTtlMsFromEnv, o as rowNumber, Ct as rowSchema, _n as sanitizeIdentifierFragment, pt as serializeArraysForWrite, n as serverOnlyColumns, Ui as setResidencyConfig, $r as spatialPredicate, ya as stampGeneratedId, ba as stampGeneratedIds, gi as streamTable, b as sum, Ae as sumOver, Pa as sweepRetention, w as table, Li as teardownBranch, E as text, _ as timestamp, it as timestampMs, at as timestampMsOrNull, t as union, ke as unionAll, Ta as updateManyRow, wa as upsertRow, Le as validateColumnName, We as validateIndexName, Wt as validateRegisteredRelations, It as validateRelationConfig, Oe as validateTableName, me as validateTypeIdPrefix, y as vector, se as vectorDistanceToOpclass, yi as vectorEmbedding, Ge as view, _e as viewSql, fi as walkLeaves };
1766
+ export { oe as AUTO_FILLED_COLUMNS, J as BranchNameInvalid, Ei as BranchTransitionInvalid, La as CDC_OFFSETS_TABLE, Da as CHANGE_LISTENER_CEILING, Xe as ColumnBuilder, ht as ENCRYPTED_PREFIX, Ba as ENGINE, en as EagerCardinalityError, qe as FILE_MIGRATION_PATTERN, gt as FieldDecryptionError, e as MAX_IDENTIFIER_LENGTH, ut as SqlClient, mi as TableStreamError, mn as TenantNamespaceInvalid, pn as TenantNamespaceUnresolved, Hi as TenantRegionUnavailable, Vi as TenantResidencyUnresolved, xe as WARN_IDENTIFIER_LENGTH, va as _voltroApiKeysTable, Ra as _voltroCdcOffsetsTable, ga as _voltroIdempotencyTable, _a as _voltroKvTable, ha as _voltroMigrationPlansTable, pa as _voltroMigrationsTable, za as _voltroMssqlCdcOffsetsTable, ma as _voltroSeedsTable, Rr as actorsTable, zi as admitBranch, ze as allEnumRenames, Ut as allRegisteredRelations, ee as allRegisteredTables, ti as and, be as array, Yr as arrayContains, Zr as arrayHas, Xr as arrayOverlaps, nn as attachEagerLoads, ta as auditAllTableIndexes, ea as auditTableIndexes, Me as avg, Ye as avgOver, Ce as bigint, Xi as bindResidentStore, Ve as boolean, Ci as branchNamespaceName, Fe as bytes, Ke as clearEnumRenames, Gt as clearRelationsRegistry, Ki as clearResidencyConfig, Pa as clearRetentions, v as clearTableRegistry, Sn as coercePredicateValue, Cn as coercePredicateValues, fi as collectSubqueries, ye as column, St as columnSchema, Fn as compileEagerJson, L as compilePredicate, wn as compileRawFragment, R as compileSelect, yi as computeEmbedding, qr as contains, Se as count, Be as countDistinct, Pe as databaseHandle, De as date, Te as dbEnum, fe as decimal, ve as declareEnumRename, Zt as decodeRowsFromSchema, xt as decryptFieldsOnRead, da as defineMigration, d as defineMixin, ca as defineSeed, Ee as denseRank, m as deriveTypeIdPrefix, mt as deserializeArraysOnRead, Je as drainIdentifierWarnings, Qe as dropped, $t as encodeRowForSchema, bt as encryptFieldsForWrite, yt as encryptedColumnsOf, Ii as enforceBranchLimits, te as ensureTableRegistered, zr as eq, I as escapeLike, di as evaluatePredicate, we as except, ci as exists, oa as formatIndexAuditIssue, ya as frameworkTables, le as generateId, ue as generateSnowflake, nt as geography, ge as geometry, Ne as getEnumRenames, Ht as getRelation, Vt as getRelations, Gi as getResidencyConfig, u as getTable, Vr as gt, Hr as gte, fn as hasEagerLoads, vi as hybridSearch, O as id, Gr as inSet, oi as inSubquery, M as inferForeignKey, wa as insertRow, C as integer, de as intersect, a as interval, wi as isBranchNamespace, vt as isEncrypted, _t as isFieldDecryptionError, Ie as isFileMigration, fa as isMigrationDefinition, Ai as isNeonConnection, $r as isNotNull, Qr as isNull, Aa as isPrimaryKeyConflictError, Ji as isRegionServable, At as isRelationsSpec, la as isSeedDefinition, rt as isSqliteFamily, p as isTableReactive, pe as isView, D as json, ii as jsonField, f as jsonIndex, Ze as lag, tt as lead, Na as listRetentions, Ur as lt, Wr as lte, Bi as makeNamespaceBranchExecutor, Mt as many, Nt as manyToMany, ae as materializeFields, he as max, Ue as migration, et as min, Ca as missingConflictColumns, Sa as missingRequiredColumns, h as mixin, Br as neq, Di as nextBranchState, ri as not, li as notExists, Kr as notInSet, si as notInSubquery, l as numeric, jt as one, tn as oneCardinalityMessage, ni as or, re as paginateBy, i as paginateById, Pi as planBranch, Oi as planBranchProvision, ki as planBranchTeardown, Fi as planBranchTeardownFor, Mi as planNeonBranchProvision, Ni as planNeonBranchTeardown, ka as primaryKeyConflictError, Li as provisionBranch, Zi as provisionResidentTenant, yn as qualifyTable, $e as queryFor, Re as queryForView, r as quoteIdent, Oa as raiseChangeListenerCeiling, ie as rank, s as raw, x as real, je as reference, Pr as registerCoreTables, Bt as registerDiscoveredRelations, zt as registerRelations, Ma as registerRetention, g as registerTable, kt as relations, Ir as requireActors, ne as requireTable, Lr as requireTenants, S as resetSnowflake, Yi as residentPlacement, ji as resolveBranchMechanism, c as resolveFullTextIndex, ce as resolveIdScheme, He as resolveMixinGraph, qi as resolveTenantHome, vn as resolveTenantNamespace, Ia as retentionTtlMsFromEnv, o as rowNumber, Ct as rowSchema, _n as sanitizeIdentifierFragment, pt as serializeArraysForWrite, n as serverOnlyColumns, Wi as setResidencyConfig, ei as spatialPredicate, ba as stampGeneratedId, xa as stampGeneratedIds, Jr as startsWith, _i as streamTable, b as sum, Ae as sumOver, Fa as sweepRetention, w as table, Ri as teardownBranch, E as text, _ as timestamp, it as timestampMs, at as timestampMsOrNull, t as union, ke as unionAll, Ea as updateManyRow, Ta as upsertRow, Le as validateColumnName, We as validateIndexName, Wt as validateRegisteredRelations, It as validateRelationConfig, Oe as validateTableName, me as validateTypeIdPrefix, y as vector, se as vectorDistanceToOpclass, bi as vectorEmbedding, Ge as view, _e as viewSql, pi as walkLeaves };