@nongt/visql-core 0.13.0 → 0.14.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.
@@ -1,4 +1,4 @@
1
- function v(e) {
1
+ function E(e) {
2
2
  switch (e.type) {
3
3
  // In the order the SQL writes them: arguments, PARTITION BY, ORDER BY.
4
4
  case "function":
@@ -38,14 +38,14 @@ function v(e) {
38
38
  return [];
39
39
  }
40
40
  }
41
- const oe = ["inner", "left", "right", "full", "cross"];
41
+ const ce = ["inner", "left", "right", "full", "cross"];
42
42
  function D(e) {
43
43
  return "union" in e;
44
44
  }
45
- function fe(e) {
45
+ function pe(e) {
46
46
  return D(e) ? e.union : [e];
47
47
  }
48
- function ce(e) {
48
+ function me(e) {
49
49
  return D(e) ? e.union[0] : e;
50
50
  }
51
51
  function O(e, t) {
@@ -53,7 +53,7 @@ function O(e, t) {
53
53
  const r = e.union.map((n, i) => t(n, i));
54
54
  return r.every((n, i) => n === e.union[i]) ? e : { ...e, union: r };
55
55
  }
56
- function pe(e, t) {
56
+ function de(e, t) {
57
57
  if (!e.shared) return e;
58
58
  let r = !1;
59
59
  const n = e.shared.map((i) => {
@@ -62,21 +62,21 @@ function pe(e, t) {
62
62
  });
63
63
  return r ? { ...e, shared: n } : e;
64
64
  }
65
- function de(e) {
65
+ function ge(e) {
66
66
  return "from" in e;
67
67
  }
68
- const me = 63;
69
- function Q(e) {
68
+ const be = 63;
69
+ function J(e) {
70
70
  return e.alias || e.table || "";
71
71
  }
72
- function ge(e) {
72
+ function he(e) {
73
73
  return e.alias ? e.alias : e.expression.type === "field" ? e.expression.column : void 0;
74
74
  }
75
- function J(e) {
75
+ function z(e) {
76
76
  return [e.from, ...e.joins];
77
77
  }
78
- function be(e) {
79
- return J(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
78
+ function xe(e) {
79
+ return z(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
80
80
  }
81
81
  function j(e, t) {
82
82
  const r = t;
@@ -134,7 +134,7 @@ function $(e, t) {
134
134
  const r = j(e, (n) => $(n, t));
135
135
  return r === e ? t(e) : r;
136
136
  }
137
- function he(e) {
137
+ function ve(e) {
138
138
  return [
139
139
  ...e.where ? [e.where] : [],
140
140
  ...e.joins.flatMap((t) => t.on ? [t.on] : []),
@@ -161,25 +161,25 @@ function F(e, t, r = (n) => F(n, t)) {
161
161
  orderBy: (l = e.orderBy) == null ? void 0 : l.map((s) => ({ ...s, expression: n(s.expression) }))
162
162
  };
163
163
  }
164
- function z(e, t) {
165
- const r = (n) => n.type === "subquery" ? { ...n, query: z(n.query, t) } : j(n, r);
164
+ function Z(e, t) {
165
+ const r = (n) => n.type === "subquery" ? { ...n, query: Z(n.query, t) } : j(n, r);
166
166
  return F(e, (n) => $(r(n), t));
167
167
  }
168
- function Z(e) {
169
- return new Set([e.from, ...e.joins].map(Q));
170
- }
171
168
  function q(e) {
172
- return e !== void 0 && (e.type === "exists" || v(e).some(q));
169
+ return new Set([e.from, ...e.joins].map(J));
173
170
  }
174
171
  function ee(e) {
175
- const t = Z(e.query), r = (n) => n.type === "field" ? [n] : v(n).flatMap(r);
172
+ return e !== void 0 && (e.type === "exists" || E(e).some(ee));
173
+ }
174
+ function te(e) {
175
+ const t = q(e.query), r = (n) => n.type === "field" ? [n] : E(n).flatMap(r);
176
176
  return r(e.link).filter((n) => n.table !== void 0 && !t.has(n.table));
177
177
  }
178
- const xe = {
178
+ const Te = {
179
179
  "date-expr": ["date", "dateTime"],
180
180
  "num-expr": ["integer", "decimal"],
181
181
  "str-expr": ["varchar"]
182
- }, u = { type: "field" }, te = [
182
+ }, u = { type: "field" }, re = [
183
183
  "YEAR",
184
184
  "QUARTER",
185
185
  "MONTH",
@@ -190,22 +190,22 @@ const xe = {
190
190
  "SECOND",
191
191
  "MILLISECOND"
192
192
  ];
193
- function ve(e, t) {
193
+ function Ee(e, t) {
194
194
  if (t < e.args.length) return e.args[t];
195
195
  const r = e.args[e.args.length - 1];
196
196
  return r != null && r.variadic ? r : void 0;
197
197
  }
198
- function re(e) {
198
+ function ne(e) {
199
199
  let t = e.args.length;
200
200
  for (; t > 0 && e.args[t - 1].optional && !e.args[t - 1].default; ) t -= 1;
201
201
  return e.args.slice(0, t).map((r) => r.default ?? { type: "literal", value: "" });
202
202
  }
203
- const T = (e, t = "DAY") => ({
203
+ const k = (e, t = "DAY") => ({
204
204
  label: e,
205
205
  kind: "unit",
206
- choices: te,
206
+ choices: re,
207
207
  default: { type: "literal", value: t }
208
- }), A = {
208
+ }), R = {
209
209
  // ---- Aggregate ----
210
210
  // COUNT with no argument is COUNT(*), and `distinct` on the call makes it
211
211
  // COUNT(DISTINCT x) — see the function sub-canvas's count choice.
@@ -321,7 +321,7 @@ const T = (e, t = "DAY") => ({
321
321
  args: [
322
322
  { label: "date", kind: "date-expr", default: u },
323
323
  { label: "amount", kind: "num-expr", default: { type: "literal", value: 1 } },
324
- T("unit")
324
+ k("unit")
325
325
  ]
326
326
  },
327
327
  DATE_SUB: {
@@ -330,7 +330,7 @@ const T = (e, t = "DAY") => ({
330
330
  args: [
331
331
  { label: "date", kind: "date-expr", default: u },
332
332
  { label: "amount", kind: "num-expr", default: { type: "literal", value: 1 } },
333
- T("unit")
333
+ k("unit")
334
334
  ]
335
335
  },
336
336
  // ---- Date diff ----
@@ -340,7 +340,7 @@ const T = (e, t = "DAY") => ({
340
340
  args: [
341
341
  { label: "start", kind: "date-expr", default: u },
342
342
  { label: "end", kind: "date-expr", default: u },
343
- T("unit")
343
+ k("unit")
344
344
  ]
345
345
  },
346
346
  // ---- Date extract / trunc ----
@@ -349,7 +349,7 @@ const T = (e, t = "DAY") => ({
349
349
  returns: "integer",
350
350
  args: [
351
351
  { label: "date", kind: "date-expr", default: u },
352
- T("unit", "YEAR")
352
+ k("unit", "YEAR")
353
353
  ]
354
354
  },
355
355
  DATE_TRUNC: {
@@ -357,7 +357,7 @@ const T = (e, t = "DAY") => ({
357
357
  returns: "arg",
358
358
  args: [
359
359
  { label: "date", kind: "date-expr", default: u },
360
- T("unit")
360
+ k("unit")
361
361
  ]
362
362
  },
363
363
  // ---- Type cast ----
@@ -640,42 +640,42 @@ const T = (e, t = "DAY") => ({
640
640
  ]
641
641
  }
642
642
  };
643
- function M(e, t = A) {
643
+ function M(e, t = R) {
644
644
  return t[e.toUpperCase()];
645
645
  }
646
- function Te(e, t) {
646
+ function ke(e, t) {
647
647
  const r = e.toUpperCase();
648
648
  return M(e, t) ?? Object.values(t).find((n) => {
649
649
  var i;
650
650
  return (i = n.aliases) == null ? void 0 : i.some((a) => a.toUpperCase() === r);
651
651
  });
652
652
  }
653
- function ne(e = A) {
653
+ function ae(e = R) {
654
654
  return Object.keys(e).sort();
655
655
  }
656
- ne(A);
657
- const Ee = A;
658
- function ke(e) {
656
+ ae(R);
657
+ const Ae = R;
658
+ function we(e) {
659
659
  return Object.fromEntries(Object.values(e).map((t) => {
660
660
  const r = t.name.toUpperCase();
661
661
  return [r, { ...t, name: r }];
662
662
  }));
663
663
  }
664
- function we(e) {
664
+ function Re(e) {
665
665
  return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.aggregate));
666
666
  }
667
- function Ae(e, t) {
667
+ function Ce(e, t) {
668
668
  return {
669
669
  type: "function",
670
670
  name: t,
671
- args: re(e),
671
+ args: ne(e),
672
672
  ...e.window && { over: !0 }
673
673
  };
674
674
  }
675
- function Re(e) {
675
+ function Se(e) {
676
676
  return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.window));
677
677
  }
678
- function Se(e, t) {
678
+ function ye(e, t) {
679
679
  return Object.fromEntries(Object.entries(e).filter(([, r]) => !r.dialects || r.dialects.includes(t)));
680
680
  }
681
681
  function U(e, t) {
@@ -685,7 +685,7 @@ function U(e, t) {
685
685
  const r = e, n = t, i = Object.keys(r).filter((l) => r[l] !== void 0), a = Object.keys(n).filter((l) => n[l] !== void 0);
686
686
  return i.length === a.length && i.every((l) => U(r[l], n[l]));
687
687
  }
688
- function ae() {
688
+ function se() {
689
689
  const e = globalThis.crypto.getRandomValues(new Uint8Array(12));
690
690
  return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
691
691
  }
@@ -693,37 +693,37 @@ function H(e, t) {
693
693
  var r;
694
694
  return e.type === "function" && ((r = M(e.name, t)) == null ? void 0 : r.aggregate) === !0;
695
695
  }
696
- function x(e, t) {
697
- return e ? H(e, t) || v(e).some((r) => x(r, t)) : !1;
696
+ function T(e, t) {
697
+ return e ? H(e, t) || E(e).some((r) => T(r, t)) : !1;
698
698
  }
699
- const se = (e) => e.type === "function" && e.over === !0;
699
+ const le = (e) => e.type === "function" && e.over === !0;
700
700
  function I(e) {
701
- return e ? se(e) || v(e).some(I) : !1;
701
+ return e ? le(e) || E(e).some(I) : !1;
702
702
  }
703
703
  function P(e, t) {
704
704
  return e.type === "function" && e.name.trim() !== "" && M(e.name, t) === void 0;
705
705
  }
706
706
  function W(e, t) {
707
- return e ? P(e, t) || v(e).some((r) => W(r, t)) : !1;
707
+ return e ? P(e, t) || E(e).some((r) => W(r, t)) : !1;
708
708
  }
709
- function E(e, t, r) {
710
- return t.some((n) => U(n, e)) ? !0 : e.type === "field" ? !e.column : e.type === "exists" ? ee(e).every((n) => E(n, t, r)) : H(e, r) || P(e, r) ? !0 : v(e).every((n) => E(n, t, r));
709
+ function A(e, t, r) {
710
+ return t.some((n) => U(n, e)) ? !0 : e.type === "field" ? !e.column : e.type === "exists" ? te(e).every((n) => A(n, t, r)) : H(e, r) || P(e, r) ? !0 : E(e).every((n) => A(n, t, r));
711
711
  }
712
712
  function K(e, t) {
713
- return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((r) => x(r.expression, t));
713
+ return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((r) => T(r.expression, t));
714
714
  }
715
- function ye(e, t) {
715
+ function Oe(e, t) {
716
716
  if (K(e, t))
717
717
  return (e.groupBy ?? []).flatMap(({ expression: r }) => r.type === "field" && r.table && r.column ? [`${r.table}.${r.column}`] : []);
718
718
  }
719
- function le(e, t) {
720
- return x(e.having, t) || [...e.select, ...e.orderBy ?? []].some((r) => x(r.expression, t));
719
+ function ie(e, t) {
720
+ return T(e.having, t) || [...e.select, ...e.orderBy ?? []].some((r) => T(r.expression, t));
721
721
  }
722
- function Ce(e, t) {
723
- return e.select.some((r) => x(r.expression, t));
722
+ function Ne(e, t) {
723
+ return e.select.some((r) => T(r.expression, t));
724
724
  }
725
- function Oe(e, t) {
726
- const r = e.groupBy ?? [], n = r.filter((o) => o.fromSelect === void 0), i = le(e, t), a = n.map((o) => o.expression), l = i ? e.select.filter((o) => x(o.expression, t) || I(o.expression) || W(o.expression, t) || E(o.expression, a, t) ? !1 : (a.push(o.expression), !0)) : [], s = new Map(r.filter((o) => o.fromSelect !== void 0).map((o) => [o.fromSelect, o])), c = [];
725
+ function De(e, t) {
726
+ const r = e.groupBy ?? [], n = r.filter((o) => o.fromSelect === void 0), i = ie(e, t), a = n.map((o) => o.expression), l = i ? e.select.filter((o) => T(o.expression, t) || I(o.expression) || W(o.expression, t) || A(o.expression, a, t) ? !1 : (a.push(o.expression), !0)) : [], s = new Map(r.filter((o) => o.fromSelect !== void 0).map((o) => [o.fromSelect, o])), c = [];
727
727
  r.forEach((o) => {
728
728
  if (o.fromSelect === void 0) {
729
729
  c.push(o);
@@ -732,14 +732,14 @@ function Oe(e, t) {
732
732
  const p = l.find((m) => m.id === o.fromSelect);
733
733
  p && c.push(U(o.expression, p.expression) ? o : { ...o, expression: p.expression });
734
734
  });
735
- const h = l.filter((o) => !s.has(o.id)).map((o) => ({
736
- id: ae(),
735
+ const d = l.filter((o) => !s.has(o.id)).map((o) => ({
736
+ id: se(),
737
737
  expression: o.expression,
738
738
  fromSelect: o.id
739
- })), g = [...c, ...h];
740
- return g.length === r.length && g.every((o, p) => o === r[p]) ? e : { ...e, groupBy: g };
739
+ })), x = [...c, ...d];
740
+ return x.length === r.length && x.every((o, p) => o === r[p]) ? e : { ...e, groupBy: x };
741
741
  }
742
- function Ne(e, t) {
742
+ function Me(e, t) {
743
743
  const r = (e.groupBy ?? []).map((a) => a.expression), n = e.orderBy ?? [];
744
744
  if (!K(e, t))
745
745
  return {
@@ -748,16 +748,22 @@ function Ne(e, t) {
748
748
  orderBy: [],
749
749
  having: !1
750
750
  };
751
- const i = (a) => a.filter((l) => !I(l.expression) && !E(l.expression, r, t)).map((l) => l.id);
751
+ const i = (a) => a.filter((l) => !I(l.expression) && !A(l.expression, r, t)).map((l) => l.id);
752
752
  return {
753
753
  select: i(e.select),
754
754
  selectAll: e.select.length === 0,
755
755
  orderBy: i(n),
756
- having: e.having !== void 0 && !E(e.having, r, t)
756
+ having: e.having !== void 0 && !A(e.having, r, t)
757
757
  };
758
758
  }
759
- const De = { tables: [], relations: [] };
760
- function Me(e, t, r) {
759
+ function V(e) {
760
+ return [{ fromColumn: e.fromColumn, toColumn: e.toColumn }, ...e.also ?? []];
761
+ }
762
+ function ue(e) {
763
+ return e.length === 1 ? e[0] : { type: "logical", operator: "AND", operands: e };
764
+ }
765
+ const Ue = { tables: [], relations: [] };
766
+ function Ie(e, t, r) {
761
767
  if (!t && !r) return e;
762
768
  const n = e.tables.filter((a) => !t || t(a)).map((a) => r ? { ...a, columns: a.columns.filter((l) => r(a, l)) } : a), i = new Set(n.map((a) => a.name));
763
769
  return {
@@ -765,10 +771,10 @@ function Me(e, t, r) {
765
771
  relations: e.relations.filter((a) => i.has(a.fromTable) && i.has(a.toTable))
766
772
  };
767
773
  }
768
- function Ue(e) {
774
+ function Be(e) {
769
775
  return [...e.tables].sort((t, r) => t.label.localeCompare(r.label));
770
776
  }
771
- function Ie(e, t = (n) => n.group, r = e) {
777
+ function Le(e, t = (n) => n.group, r = e) {
772
778
  const n = /* @__PURE__ */ new Map();
773
779
  r.forEach((a) => {
774
780
  const l = t(a) || void 0;
@@ -783,18 +789,18 @@ function Ie(e, t = (n) => n.group, r = e) {
783
789
  ...[...n].filter(([a]) => a === void 0)
784
790
  ].filter(([, a]) => a.length > 0).map(([a, l]) => ({ group: a, tables: i(l) }));
785
791
  }
786
- function V(e, t) {
792
+ function X(e, t) {
787
793
  return e.tables.find((r) => r.name === t);
788
794
  }
789
795
  function N(e, t, r) {
790
796
  return e.relations.find((n) => n.fromTable === t && n.toTable === r || n.fromTable === r && n.toTable === t);
791
797
  }
792
- const R = (e, t) => {
798
+ const C = (e, t) => {
793
799
  var r;
794
- return ((r = V(e, t)) == null ? void 0 : r.passThrough) !== !1;
800
+ return ((r = X(e, t)) == null ? void 0 : r.passThrough) !== !1;
795
801
  };
796
802
  function B(e, t) {
797
- const r = t.filter((n) => R(e, n));
803
+ const r = t.filter((n) => C(e, n));
798
804
  return r.length > 0 ? r : [...t];
799
805
  }
800
806
  function L(e, t) {
@@ -805,47 +811,47 @@ function L(e, t) {
805
811
  (l.r.fromTable === l.earlier && l.r.toTable === n || r.has(l.earlier)) && r.add(n);
806
812
  }), r;
807
813
  }
808
- const X = (e, t) => e.fanOuts - t.fanOuts || e.steps - t.steps || e.order - t.order, w = (e, t) => `${t ? "^" : "_"}${e}`;
814
+ const Q = (e, t) => e.fanOuts - t.fanOuts || e.steps - t.steps || e.order - t.order, w = (e, t) => `${t ? "^" : "_"}${e}`;
809
815
  function Y(e, t) {
810
816
  let r;
811
817
  return e.forEach((n, i) => {
812
- !t.has(i) && (r === void 0 || X(n, e.get(r)) < 0) && (r = i);
818
+ !t.has(i) && (r === void 0 || Q(n, e.get(r)) < 0) && (r = i);
813
819
  }), r;
814
820
  }
815
- function ie(e, t, r, n = {}) {
821
+ function oe(e, t, r, n = {}) {
816
822
  const i = new Set(t), a = new Set(B(e, t)), l = n.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = /* @__PURE__ */ new Map();
817
- t.forEach((m, d) => {
818
- const b = w(m, l.has(m));
819
- s.has(b) || s.set(b, {
823
+ t.forEach((m, g) => {
824
+ const h = w(m, l.has(m));
825
+ s.has(h) || s.set(h, {
820
826
  table: m,
821
827
  climbed: l.has(m),
822
828
  fanOuts: 0,
823
829
  steps: 0,
824
- order: d
830
+ order: g
825
831
  });
826
832
  });
827
833
  const c = new Set([...s].filter(([, m]) => !a.has(m.table)).map(([m]) => m));
828
- let h = t.length;
829
- const g = (m) => {
830
- const d = s.get(m);
831
- d.steps > 0 && !R(e, d.table) || e.relations.forEach((b) => {
832
- if (b.fromTable !== d.table && b.toTable !== d.table) return;
833
- const k = b.fromTable === d.table, S = k ? b.toTable : b.fromTable;
834
- if (i.has(S) || !k && d.climbed) return;
835
- const y = {
836
- table: S,
837
- climbed: !n.anyShape && (d.climbed || k),
838
- fanOuts: d.fanOuts + (k ? 0 : 1),
839
- steps: d.steps + 1,
840
- order: h,
834
+ let d = t.length;
835
+ const x = (m) => {
836
+ const g = s.get(m);
837
+ g.steps > 0 && !C(e, g.table) || e.relations.forEach((h) => {
838
+ if (h.fromTable !== g.table && h.toTable !== g.table) return;
839
+ const b = h.fromTable === g.table, v = b ? h.toTable : h.fromTable;
840
+ if (i.has(v) || !b && g.climbed) return;
841
+ const S = {
842
+ table: v,
843
+ climbed: !n.anyShape && (g.climbed || b),
844
+ fanOuts: g.fanOuts + (b ? 0 : 1),
845
+ steps: g.steps + 1,
846
+ order: d,
841
847
  from: m
842
- }, C = w(S, y.climbed), G = s.get(C);
843
- c.has(C) || G && X(y, { ...G, order: h }) >= 0 || (s.set(C, y), h += 1);
848
+ }, y = w(v, S.climbed), G = s.get(y);
849
+ c.has(y) || G && Q(S, { ...G, order: d }) >= 0 || (s.set(y, S), d += 1);
844
850
  });
845
851
  };
846
852
  let f = Y(s, c);
847
853
  for (; f !== void 0 && s.get(f).table !== r; )
848
- c.add(f), g(f), f = Y(s, c);
854
+ c.add(f), x(f), f = Y(s, c);
849
855
  if (f === void 0) return;
850
856
  const o = [];
851
857
  let p = s.get(f);
@@ -853,11 +859,11 @@ function ie(e, t, r, n = {}) {
853
859
  o.unshift(p.table), p = s.get(p.from);
854
860
  return { start: p.table, tables: o };
855
861
  }
856
- function Be(e, t, r, n = {}) {
862
+ function Ge(e, t, r, n = {}) {
857
863
  var i;
858
- return t.includes(r) ? [] : (i = ie(e, t, r, n)) == null ? void 0 : i.tables;
864
+ return t.includes(r) ? [] : (i = oe(e, t, r, n)) == null ? void 0 : i.tables;
859
865
  }
860
- function Le(e, t, r = {}) {
866
+ function Ye(e, t, r = {}) {
861
867
  const n = /* @__PURE__ */ new Map(), i = (f, o, p) => n.set(f, [
862
868
  ...n.get(f) ?? [],
863
869
  { table: o, up: p }
@@ -865,37 +871,37 @@ function Le(e, t, r = {}) {
865
871
  e.relations.forEach((f) => {
866
872
  i(f.fromTable, f.toTable, !0), i(f.toTable, f.fromTable, !1);
867
873
  });
868
- const { skip: a = /* @__PURE__ */ new Set() } = r, l = r.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = new Set(t), c = new Set(t), h = B(e, t).map((f) => ({ table: f, climbed: l.has(f) })), g = new Set(h.map((f) => w(f.table, f.climbed)));
869
- for (let f = h.shift(); f !== void 0; f = h.shift()) {
874
+ const { skip: a = /* @__PURE__ */ new Set() } = r, l = r.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = new Set(t), c = new Set(t), d = B(e, t).map((f) => ({ table: f, climbed: l.has(f) })), x = new Set(d.map((f) => w(f.table, f.climbed)));
875
+ for (let f = d.shift(); f !== void 0; f = d.shift()) {
870
876
  const o = f;
871
877
  (n.get(o.table) ?? []).forEach(({ table: p, up: m }) => {
872
878
  if (s.has(p) || a.has(p) || !m && o.climbed) return;
873
- const d = { table: p, climbed: !r.anyShape && (o.climbed || m) }, b = w(p, d.climbed);
874
- g.has(b) || (g.add(b), c.add(p), R(e, p) && h.push(d));
879
+ const g = { table: p, climbed: !r.anyShape && (o.climbed || m) }, h = w(p, g.climbed);
880
+ x.has(h) || (x.add(h), c.add(p), C(e, p) && d.push(g));
875
881
  });
876
882
  }
877
883
  return c;
878
884
  }
879
- function Ge(e, t, r, n = {}) {
880
- var m;
881
- const { after: i, leftJoined: a = [] } = n, l = n.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = (d) => {
882
- const b = N(e, d, r);
883
- return b !== void 0 && !(l.has(d) && b.toTable === d && b.fromTable === r);
885
+ function _e(e, t, r, n = {}) {
886
+ var h;
887
+ const { after: i, leftJoined: a = [] } = n, l = n.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = (b) => {
888
+ const v = N(e, b, r);
889
+ return v !== void 0 && !(l.has(b) && v.toTable === b && v.fromTable === r);
884
890
  };
885
- let c = R(e, r) ? B(e, t) : t;
891
+ let c = C(e, r) ? B(e, t) : t;
886
892
  i !== void 0 && s(i) && (c = [i]);
887
- const h = c.find(s);
888
- if (h === void 0) return;
889
- const g = N(e, h, r), f = (m = V(e, g.fromTable)) == null ? void 0 : m.columns.find((d) => d.name === g.fromColumn), o = f != null && f.nullable || a.includes(h) ? "left" : "inner", p = {
893
+ const d = c.find(s);
894
+ if (d === void 0) return;
895
+ const x = N(e, d, r), f = V(x), o = (h = X(e, x.fromTable)) == null ? void 0 : h.columns.filter((b) => f.some((v) => v.fromColumn === b.name)), m = (o == null ? void 0 : o.some((b) => b.nullable)) || a.includes(d) ? "left" : "inner", g = ue(f.map((b) => ({
890
896
  type: "binary",
891
897
  operator: "=",
892
- left: { type: "field", table: g.fromTable, column: g.fromColumn },
893
- right: { type: "field", table: g.toTable, column: g.toColumn }
894
- };
895
- return { joinType: o, on: p };
898
+ left: { type: "field", table: x.fromTable, column: b.fromColumn },
899
+ right: { type: "field", table: x.toTable, column: b.toColumn }
900
+ })));
901
+ return { joinType: m, on: g };
896
902
  }
897
903
  const _ = (e, t) => `${e}.${t}`;
898
- function ue({ type: e, format: t }) {
904
+ function fe({ type: e, format: t }) {
899
905
  if (t === void 0) return;
900
906
  if (e !== "date" && e !== "dateTime" && e !== "time")
901
907
  return `a format is for a date, date-and-time or time column, not ${e}`;
@@ -904,7 +910,7 @@ function ue({ type: e, format: t }) {
904
910
  if (e === "time" && r.some((n) => n === "YYYY" || n === "MM" || n === "DD"))
905
911
  return `a time has no day: format "${t}" can't be written from one`;
906
912
  }
907
- function Ye(e) {
913
+ function je(e) {
908
914
  const t = [], r = /* @__PURE__ */ new Map();
909
915
  e.tables.forEach((a) => {
910
916
  r.has(a.name) && t.push({
@@ -917,7 +923,7 @@ function Ye(e) {
917
923
  kind: "duplicateColumn",
918
924
  message: `Column "${a.name}.${s.name}" is declared more than once`
919
925
  }), l.add(s.name);
920
- const c = ue(s);
926
+ const c = fe(s);
921
927
  c && t.push({
922
928
  kind: "invalidFormat",
923
929
  message: `Column "${a.name}.${s.name}": ${c}`
@@ -935,7 +941,9 @@ function Ye(e) {
935
941
  });
936
942
  }, i = /* @__PURE__ */ new Set();
937
943
  return e.relations.forEach((a) => {
938
- n(a.fromTable, a.fromColumn), n(a.toTable, a.toColumn);
944
+ V(a).forEach((d) => {
945
+ n(a.fromTable, d.fromColumn), n(a.toTable, d.toColumn);
946
+ });
939
947
  const l = _(a.fromTable, a.fromColumn), s = _(a.toTable, a.toColumn), c = [l, s].sort().join(" <-> ");
940
948
  i.has(c) && t.push({
941
949
  kind: "duplicateRelation",
@@ -944,60 +952,62 @@ function Ye(e) {
944
952
  }), t;
945
953
  }
946
954
  export {
947
- se as $,
948
- ke as A,
955
+ ne as $,
956
+ we as A,
949
957
  K as B,
950
- oe as C,
951
- Ee as D,
952
- De as E,
953
- Ne as F,
954
- ve as G,
958
+ ce as C,
959
+ Ae as D,
960
+ Ue as E,
961
+ Me as F,
962
+ Ee as G,
955
963
  I as H,
956
964
  W as I,
957
965
  M as J,
958
- he as K,
959
- pe as L,
960
- me as M,
961
- Z as N,
962
- q as O,
963
- be as P,
964
- ie as Q,
965
- $ as R,
966
- z as S,
967
- Re as T,
968
- we as U,
969
- ne as V,
970
- xe as W,
971
- Ae as X,
972
- Ie as Y,
973
- re as Z,
974
- H as _,
975
- Be as a,
976
- ye as a0,
977
- Ce as a1,
978
- fe as b,
979
- Se as c,
966
+ V as K,
967
+ ue as L,
968
+ be as M,
969
+ ve as N,
970
+ de as O,
971
+ q as P,
972
+ ee as Q,
973
+ xe as R,
974
+ oe as S,
975
+ $ as T,
976
+ Z as U,
977
+ Se as V,
978
+ Re as W,
979
+ ae as X,
980
+ Te as Y,
981
+ Ce as Z,
982
+ Le as _,
983
+ Ge as a,
984
+ H as a0,
985
+ le as a1,
986
+ Oe as a2,
987
+ Ne as a3,
988
+ pe as b,
989
+ ye as c,
980
990
  U as d,
981
991
  F as e,
982
- Me as f,
992
+ Ie as f,
983
993
  O as g,
984
- de as h,
994
+ ge as h,
985
995
  D as i,
986
- V as j,
987
- te as k,
988
- ae as l,
996
+ X as j,
997
+ re as k,
998
+ se as l,
989
999
  j as m,
990
- ce as n,
991
- ge as o,
992
- Te as p,
993
- J as q,
994
- Le as r,
995
- Ge as s,
996
- Q as t,
997
- x as u,
998
- Ye as v,
999
- le as w,
1000
- Oe as x,
1001
- v as y,
1002
- Ue as z
1000
+ me as n,
1001
+ he as o,
1002
+ ke as p,
1003
+ z as q,
1004
+ Ye as r,
1005
+ _e as s,
1006
+ J as t,
1007
+ T as u,
1008
+ je as v,
1009
+ ie as w,
1010
+ De as x,
1011
+ E as y,
1012
+ Be as z
1003
1013
  };
@@ -1,7 +1,7 @@
1
1
  var Dt = Object.defineProperty;
2
2
  var Ut = (i, y, M) => y in i ? Dt(i, y, { enumerable: !0, configurable: !0, writable: !0, value: M }) : i[y] = M;
3
3
  var gt = (i, y, M) => Ut(i, typeof y != "symbol" ? y + "" : y, M);
4
- import { k as Mt, l as st, p as bt, D as qt, n as Nt, d as Rt, o as xt, q as Bt, j as At, u as kt, w as Ft, x as $t, t as Wt, m as Pt, y as Gt } from "./schema-DsMO9oFE.js";
4
+ import { k as Mt, l as st, p as bt, D as qt, n as Nt, d as Rt, o as xt, q as Bt, j as At, u as kt, w as Ft, x as $t, t as Wt, m as Pt, y as Gt } from "./schema-C-CgG78X.js";
5
5
  import { t as _t, f as Ht, a as Xt } from "./calendarDate-CYlr9TvX.js";
6
6
  function Ct(i, y, M = y) {
7
7
  const D = i.slice(0, y);
@@ -1,8 +1,8 @@
1
1
  var Ut = Object.defineProperty;
2
2
  var Yt = (t, r, e) => r in t ? Ut(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
3
  var w = (t, r, e) => Yt(t, typeof r != "symbol" ? r + "" : r, e);
4
- import { q as Y, d as F, a as _t, s as jt, m as Q, e as ft, g as Ht, t as vt, j as Bt, b as Pt, i as Gt } from "./schema-DsMO9oFE.js";
5
- import { p as tt, t as rt, v as xt, w as kt, x as Xt, y as $t, z as Vt, A as Wt } from "./params-fC03h7rg.js";
4
+ import { q as Y, d as F, a as _t, s as jt, m as Q, e as ft, g as Ht, t as vt, j as Bt, b as Pt, i as Gt } from "./schema-C-CgG78X.js";
5
+ import { p as tt, t as rt, v as xt, w as kt, x as Xt, y as $t, z as Vt, A as Wt } from "./params-CXRW5B8V.js";
6
6
  import { s as lt } from "./calendarDate-CYlr9TvX.js";
7
7
  class Qt extends Error {
8
8
  constructor(e, n, s, o) {