@nongt/visql 0.7.0 → 0.9.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.
Files changed (46) hide show
  1. package/README.md +23 -359
  2. package/dist/{MuiTimePicker-BjywwrRm.js → MuiTimePicker-DRqT6ByZ.js} +1 -1
  3. package/dist/PipelineEditor-C10lng6j.js +10544 -0
  4. package/dist/core.js +336 -78
  5. package/dist/explain.js +165 -0
  6. package/dist/fixtures.js +1 -1
  7. package/dist/index.js +114 -98
  8. package/dist/issueLocation-BOSdd1JX.js +1106 -0
  9. package/dist/mui-date-pickers-host.js +1 -1
  10. package/dist/mui-date-pickers.js +1 -1
  11. package/dist/mui.js +95 -84
  12. package/dist/params-MMOdKWnW.js +2217 -0
  13. package/dist/{schema-DFC26AhZ.js → schema-dP_ISylQ.js} +270 -242
  14. package/dist/sql-import.js +613 -627
  15. package/dist/sqlGen-B7-2-i9V.js +903 -0
  16. package/dist/style.css +1 -1
  17. package/dist/tokens-DV5rTGMj.js +171 -0
  18. package/dist/types/core/ast.d.ts +1 -1
  19. package/dist/types/core/components/flow/NodeActionFrame.d.ts +20 -0
  20. package/dist/types/core/components/flow/useNodeActions.d.ts +18 -0
  21. package/dist/types/core/i18n/defaultMessages.d.ts +15 -0
  22. package/dist/types/core/i18n/messages.d.ts +11 -0
  23. package/dist/types/core/params.d.ts +10 -0
  24. package/dist/types/core/planFindings.d.ts +27 -0
  25. package/dist/types/core/queryHelpers.d.ts +1 -1
  26. package/dist/types/core/schema.d.ts +35 -20
  27. package/dist/types/core/scopeQuery.d.ts +2 -2
  28. package/dist/types/core/sqlGen.d.ts +10 -0
  29. package/dist/types/core/theme/appearance.d.ts +27 -0
  30. package/dist/types/core/theme/looks.d.ts +14 -0
  31. package/dist/types/core/theme/tokens.d.ts +9 -1
  32. package/dist/types/core-api.d.ts +3 -2
  33. package/dist/types/explain/explainQuery.d.ts +53 -0
  34. package/dist/types/explain/postgresPlan.d.ts +12 -0
  35. package/dist/types/explain.d.ts +2 -0
  36. package/dist/types/features/queryEditor/CanvasBackground.d.ts +2 -0
  37. package/dist/types/features/queryEditor/ExplainButton.d.ts +13 -0
  38. package/dist/types/features/queryEditor/IssuesButton.d.ts +14 -6
  39. package/dist/types/features/queryEditor/PipelineEditor.d.ts +15 -0
  40. package/dist/types/features/queryEditor/planText.d.ts +8 -0
  41. package/dist/types/index.d.ts +2 -0
  42. package/package.json +14 -1
  43. package/dist/PipelineEditor-9-9xOJcB.js +0 -10214
  44. package/dist/core-api-BsEMnDQ1.js +0 -1141
  45. package/dist/issueLocation-732-e0B8.js +0 -3281
  46. package/dist/tokens-BTaVMSOx.js +0 -95
@@ -1,4 +1,4 @@
1
- function b(e) {
1
+ function x(e) {
2
2
  switch (e.type) {
3
3
  case "function":
4
4
  return e.orderBy ? [...e.args, ...e.orderBy.map((t) => t.expression)] : e.args;
@@ -31,54 +31,54 @@ function b(e) {
31
31
  return [];
32
32
  }
33
33
  }
34
- const W = ["inner", "left", "right", "full", "cross"];
35
- function v(e) {
34
+ const J = ["inner", "left", "right", "full", "cross"];
35
+ function A(e) {
36
36
  return "union" in e;
37
37
  }
38
- function X(e) {
39
- return v(e) ? e.union : [e];
38
+ function z(e) {
39
+ return A(e) ? e.union : [e];
40
40
  }
41
- function Q(e) {
42
- return v(e) ? e.union[0] : e;
41
+ function Z(e) {
42
+ return A(e) ? e.union[0] : e;
43
43
  }
44
- function T(e, t) {
45
- if (!v(e)) return t(e, 0);
46
- const r = e.union.map((a, i) => t(a, i));
47
- return r.every((a, i) => a === e.union[i]) ? e : { ...e, union: r };
44
+ function E(e, t) {
45
+ if (!A(e)) return t(e, 0);
46
+ const r = e.union.map((n, l) => t(n, l));
47
+ return r.every((n, l) => n === e.union[l]) ? e : { ...e, union: r };
48
48
  }
49
- function K(e, t) {
49
+ function q(e, t) {
50
50
  if (!e.shared) return e;
51
51
  let r = !1;
52
- const a = e.shared.map((i) => {
53
- const n = t(i.query, i);
54
- return n === i.query ? i : (r = !0, { ...i, query: n });
52
+ const n = e.shared.map((l) => {
53
+ const a = t(l.query, l);
54
+ return a === l.query ? l : (r = !0, { ...l, query: a });
55
55
  });
56
- return r ? { ...e, shared: a } : e;
56
+ return r ? { ...e, shared: n } : e;
57
57
  }
58
- function J(e) {
58
+ function ee(e) {
59
59
  return "from" in e;
60
60
  }
61
- const z = 63;
62
- function I(e) {
61
+ const te = 63;
62
+ function Y(e) {
63
63
  return e.alias || e.table || "";
64
64
  }
65
- function Z(e) {
65
+ function re(e) {
66
66
  return e.alias ? e.alias : e.expression.type === "field" ? e.expression.column : void 0;
67
67
  }
68
- function y(e) {
68
+ function j(e) {
69
69
  return [e.from, ...e.joins];
70
70
  }
71
- function q(e) {
72
- return y(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
71
+ function ne(e) {
72
+ return j(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
73
73
  }
74
- function R(e, t) {
74
+ function M(e, t) {
75
75
  const r = t;
76
76
  switch (e.type) {
77
77
  case "function":
78
78
  return {
79
79
  ...e,
80
80
  args: e.args.map(r),
81
- ...e.orderBy ? { orderBy: e.orderBy.map((a) => ({ ...a, expression: r(a.expression) })) } : {}
81
+ ...e.orderBy ? { orderBy: e.orderBy.map((n) => ({ ...n, expression: r(n.expression) })) } : {}
82
82
  };
83
83
  case "binary":
84
84
  return {
@@ -103,7 +103,7 @@ function R(e, t) {
103
103
  return {
104
104
  ...e,
105
105
  subject: e.subject && r(e.subject),
106
- branches: e.branches.map((a) => ({ when: r(a.when), then: r(a.then) })),
106
+ branches: e.branches.map((n) => ({ when: r(n.when), then: r(n.then) })),
107
107
  else: e.else && r(e.else)
108
108
  };
109
109
  case "exists":
@@ -112,7 +112,7 @@ function R(e, t) {
112
112
  link: r(e.link),
113
113
  query: {
114
114
  ...e.query,
115
- joins: e.query.joins.map((a) => a.on ? { ...a, on: r(a.on) } : a),
115
+ joins: e.query.joins.map((n) => n.on ? { ...n, on: r(n.on) } : n),
116
116
  ...e.query.where ? { where: r(e.query.where) } : {}
117
117
  }
118
118
  };
@@ -120,11 +120,11 @@ function R(e, t) {
120
120
  return e;
121
121
  }
122
122
  }
123
- function C(e, t) {
124
- const r = R(e, (a) => C(a, t));
123
+ function D(e, t) {
124
+ const r = M(e, (n) => D(n, t));
125
125
  return r === e ? t(e) : r;
126
126
  }
127
- function ee(e) {
127
+ function ae(e) {
128
128
  return [
129
129
  ...e.where ? [e.where] : [],
130
130
  ...e.joins.flatMap((t) => t.on ? [t.on] : []),
@@ -134,42 +134,42 @@ function ee(e) {
134
134
  ...(e.orderBy ?? []).map((t) => t.expression)
135
135
  ];
136
136
  }
137
- function S(e, t, r = (a) => S(a, t)) {
138
- var n, s;
139
- const a = t, { shared: i } = e;
137
+ function y(e, t, r = (n) => y(n, t)) {
138
+ var a, s;
139
+ const n = t, { shared: l } = e;
140
140
  return {
141
141
  ...e,
142
- ...i ? {
143
- shared: i.map((l) => ({ ...l, query: T(l.query, r) }))
142
+ ...l ? {
143
+ shared: l.map((i) => ({ ...i, query: E(i.query, r) }))
144
144
  } : {},
145
- from: e.from.query ? { ...e.from, query: T(e.from.query, r) } : e.from,
146
- where: e.where && a(e.where),
147
- joins: e.joins.map((l) => l.query ? { ...l, on: l.on && a(l.on), query: T(l.query, r) } : { ...l, on: l.on && a(l.on) }),
148
- select: e.select.map((l) => ({ ...l, expression: a(l.expression) })),
149
- groupBy: (n = e.groupBy) == null ? void 0 : n.map((l) => ({ ...l, expression: a(l.expression) })),
150
- having: e.having && a(e.having),
151
- orderBy: (s = e.orderBy) == null ? void 0 : s.map((l) => ({ ...l, expression: a(l.expression) }))
145
+ from: e.from.query ? { ...e.from, query: E(e.from.query, r) } : e.from,
146
+ where: e.where && n(e.where),
147
+ joins: e.joins.map((i) => i.query ? { ...i, on: i.on && n(i.on), query: E(i.query, r) } : { ...i, on: i.on && n(i.on) }),
148
+ select: e.select.map((i) => ({ ...i, expression: n(i.expression) })),
149
+ groupBy: (a = e.groupBy) == null ? void 0 : a.map((i) => ({ ...i, expression: n(i.expression) })),
150
+ having: e.having && n(e.having),
151
+ orderBy: (s = e.orderBy) == null ? void 0 : s.map((i) => ({ ...i, expression: n(i.expression) }))
152
152
  };
153
153
  }
154
- function w(e, t) {
155
- const r = (a) => a.type === "subquery" ? { ...a, query: w(a.query, t) } : R(a, r);
156
- return S(e, (a) => C(r(a), t));
154
+ function F(e, t) {
155
+ const r = (n) => n.type === "subquery" ? { ...n, query: F(n.query, t) } : M(n, r);
156
+ return y(e, (n) => D(r(n), t));
157
157
  }
158
- function B(e) {
159
- return new Set([e.from, ...e.joins].map(I));
158
+ function H(e) {
159
+ return new Set([e.from, ...e.joins].map(Y));
160
160
  }
161
- function L(e) {
162
- return e !== void 0 && (e.type === "exists" || b(e).some(L));
161
+ function _(e) {
162
+ return e !== void 0 && (e.type === "exists" || x(e).some(_));
163
163
  }
164
- function G(e) {
165
- const t = B(e.query), r = (a) => a.type === "field" ? [a] : b(a).flatMap(r);
166
- return r(e.link).filter((a) => a.table !== void 0 && !t.has(a.table));
164
+ function $(e) {
165
+ const t = H(e.query), r = (n) => n.type === "field" ? [n] : x(n).flatMap(r);
166
+ return r(e.link).filter((n) => n.table !== void 0 && !t.has(n.table));
167
167
  }
168
- const te = {
168
+ const se = {
169
169
  "date-expr": ["date", "dateTime"],
170
170
  "num-expr": ["integer", "decimal"],
171
171
  "str-expr": ["varchar"]
172
- }, u = { type: "field" }, Y = [
172
+ }, u = { type: "field" }, P = [
173
173
  "YEAR",
174
174
  "QUARTER",
175
175
  "MONTH",
@@ -180,20 +180,20 @@ const te = {
180
180
  "SECOND",
181
181
  "MILLISECOND"
182
182
  ];
183
- function re(e, t) {
183
+ function le(e, t) {
184
184
  if (t < e.args.length) return e.args[t];
185
185
  const r = e.args[e.args.length - 1];
186
186
  return r != null && r.variadic ? r : void 0;
187
187
  }
188
- function ae(e) {
188
+ function ie(e) {
189
189
  return e.args.map((t) => t.default ?? { type: "literal", value: "" });
190
190
  }
191
- const d = (e, t = "DAY") => ({
191
+ const b = (e, t = "DAY") => ({
192
192
  label: e,
193
193
  kind: "unit",
194
- choices: Y,
194
+ choices: P,
195
195
  default: { type: "literal", value: t }
196
- }), h = {
196
+ }), v = {
197
197
  // ---- Aggregate ----
198
198
  // COUNT with no argument is COUNT(*), and `distinct` on the call makes it
199
199
  // COUNT(DISTINCT x) — see the function sub-canvas's count choice.
@@ -258,7 +258,7 @@ const d = (e, t = "DAY") => ({
258
258
  args: [
259
259
  { label: "date", kind: "date-expr", default: u },
260
260
  { label: "amount", kind: "num-expr", default: { type: "literal", value: 1 } },
261
- d("unit")
261
+ b("unit")
262
262
  ]
263
263
  },
264
264
  DATE_SUB: {
@@ -267,7 +267,7 @@ const d = (e, t = "DAY") => ({
267
267
  args: [
268
268
  { label: "date", kind: "date-expr", default: u },
269
269
  { label: "amount", kind: "num-expr", default: { type: "literal", value: 1 } },
270
- d("unit")
270
+ b("unit")
271
271
  ]
272
272
  },
273
273
  // ---- Date diff ----
@@ -277,7 +277,7 @@ const d = (e, t = "DAY") => ({
277
277
  args: [
278
278
  { label: "start", kind: "date-expr", default: u },
279
279
  { label: "end", kind: "date-expr", default: u },
280
- d("unit")
280
+ b("unit")
281
281
  ]
282
282
  },
283
283
  // ---- Date extract / trunc ----
@@ -286,7 +286,7 @@ const d = (e, t = "DAY") => ({
286
286
  returns: "integer",
287
287
  args: [
288
288
  { label: "date", kind: "date-expr", default: u },
289
- d("unit", "YEAR")
289
+ b("unit", "YEAR")
290
290
  ]
291
291
  },
292
292
  DATE_TRUNC: {
@@ -294,7 +294,7 @@ const d = (e, t = "DAY") => ({
294
294
  returns: "arg",
295
295
  args: [
296
296
  { label: "date", kind: "date-expr", default: u },
297
- d("unit")
297
+ b("unit")
298
298
  ]
299
299
  },
300
300
  // ---- Type cast ----
@@ -577,279 +577,307 @@ const d = (e, t = "DAY") => ({
577
577
  ]
578
578
  }
579
579
  };
580
- function k(e, t = h) {
580
+ function R(e, t = v) {
581
581
  return t[e.toUpperCase()];
582
582
  }
583
- function ne(e, t) {
583
+ function ue(e, t) {
584
584
  const r = e.toUpperCase();
585
- return k(e, t) ?? Object.values(t).find((a) => {
586
- var i;
587
- return (i = a.aliases) == null ? void 0 : i.some((n) => n.toUpperCase() === r);
585
+ return R(e, t) ?? Object.values(t).find((n) => {
586
+ var l;
587
+ return (l = n.aliases) == null ? void 0 : l.some((a) => a.toUpperCase() === r);
588
588
  });
589
589
  }
590
- function j(e = h) {
590
+ function W(e = v) {
591
591
  return Object.keys(e).sort();
592
592
  }
593
- j(h);
594
- const se = h;
595
- function le(e) {
593
+ W(v);
594
+ const oe = v;
595
+ function fe(e) {
596
596
  return Object.fromEntries(Object.values(e).map((t) => {
597
597
  const r = t.name.toUpperCase();
598
598
  return [r, { ...t, name: r }];
599
599
  }));
600
600
  }
601
- function ie(e) {
601
+ function ce(e) {
602
602
  return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.aggregate));
603
603
  }
604
- function ue(e, t) {
604
+ function pe(e, t) {
605
605
  return Object.fromEntries(Object.entries(e).filter(([, r]) => !r.dialects || r.dialects.includes(t)));
606
606
  }
607
- function E(e, t) {
607
+ function C(e, t) {
608
608
  if (e === t) return !0;
609
609
  if (e instanceof Date && t instanceof Date) return e.getTime() === t.getTime();
610
610
  if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
611
- const r = e, a = t, i = Object.keys(r).filter((s) => r[s] !== void 0), n = Object.keys(a).filter((s) => a[s] !== void 0);
612
- return i.length === n.length && i.every((s) => E(r[s], a[s]));
611
+ const r = e, n = t, l = Object.keys(r).filter((s) => r[s] !== void 0), a = Object.keys(n).filter((s) => n[s] !== void 0);
612
+ return l.length === a.length && l.every((s) => C(r[s], n[s]));
613
613
  }
614
- function F() {
614
+ function V() {
615
615
  const e = globalThis.crypto.getRandomValues(new Uint8Array(12));
616
616
  return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
617
617
  }
618
- function N(e, t) {
618
+ function U(e, t) {
619
619
  var r;
620
- return e.type === "function" && ((r = k(e.name, t)) == null ? void 0 : r.aggregate) === !0;
620
+ return e.type === "function" && ((r = R(e.name, t)) == null ? void 0 : r.aggregate) === !0;
621
621
  }
622
- function p(e, t) {
623
- return e ? N(e, t) || b(e).some((r) => p(r, t)) : !1;
622
+ function g(e, t) {
623
+ return e ? U(e, t) || x(e).some((r) => g(r, t)) : !1;
624
624
  }
625
- function O(e, t) {
626
- return e.type === "function" && e.name.trim() !== "" && k(e.name, t) === void 0;
625
+ function I(e, t) {
626
+ return e.type === "function" && e.name.trim() !== "" && R(e.name, t) === void 0;
627
627
  }
628
- function M(e, t) {
629
- return e ? O(e, t) || b(e).some((r) => M(r, t)) : !1;
628
+ function w(e, t) {
629
+ return e ? I(e, t) || x(e).some((r) => w(r, t)) : !1;
630
630
  }
631
- function g(e, t, r) {
632
- return t.some((a) => E(a, e)) ? !0 : e.type === "field" ? !e.column : e.type === "exists" ? G(e).every((a) => g(a, t, r)) : N(e, r) || O(e, r) ? !0 : b(e).every((a) => g(a, t, r));
631
+ function h(e, t, r) {
632
+ return t.some((n) => C(n, e)) ? !0 : e.type === "field" ? !e.column : e.type === "exists" ? $(e).every((n) => h(n, t, r)) : U(e, r) || I(e, r) ? !0 : x(e).every((n) => h(n, t, r));
633
633
  }
634
- function D(e, t) {
635
- return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((r) => p(r.expression, t));
634
+ function B(e, t) {
635
+ return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((r) => g(r.expression, t));
636
636
  }
637
- function oe(e, t) {
638
- if (D(e, t))
637
+ function me(e, t) {
638
+ if (B(e, t))
639
639
  return (e.groupBy ?? []).flatMap(({ expression: r }) => r.type === "field" && r.table && r.column ? [`${r.table}.${r.column}`] : []);
640
640
  }
641
- function H(e, t) {
642
- return p(e.having, t) || [...e.select, ...e.orderBy ?? []].some((r) => p(r.expression, t));
641
+ function X(e, t) {
642
+ return g(e.having, t) || [...e.select, ...e.orderBy ?? []].some((r) => g(r.expression, t));
643
643
  }
644
- function fe(e, t) {
645
- return e.select.some((r) => p(r.expression, t));
644
+ function de(e, t) {
645
+ return e.select.some((r) => g(r.expression, t));
646
646
  }
647
- function ce(e, t) {
648
- const r = e.groupBy ?? [], a = r.filter((o) => o.fromSelect === void 0), i = H(e, t), n = a.map((o) => o.expression), s = i ? e.select.filter((o) => p(o.expression, t) || M(o.expression, t) || g(o.expression, n, t) ? !1 : (n.push(o.expression), !0)) : [], l = new Map(r.filter((o) => o.fromSelect !== void 0).map((o) => [o.fromSelect, o])), f = [];
647
+ function ge(e, t) {
648
+ const r = e.groupBy ?? [], n = r.filter((o) => o.fromSelect === void 0), l = X(e, t), a = n.map((o) => o.expression), s = l ? e.select.filter((o) => g(o.expression, t) || w(o.expression, t) || h(o.expression, a, t) ? !1 : (a.push(o.expression), !0)) : [], i = new Map(r.filter((o) => o.fromSelect !== void 0).map((o) => [o.fromSelect, o])), c = [];
649
649
  r.forEach((o) => {
650
650
  if (o.fromSelect === void 0) {
651
- f.push(o);
651
+ c.push(o);
652
652
  return;
653
653
  }
654
- const m = s.find((U) => U.id === o.fromSelect);
655
- m && f.push(E(o.expression, m.expression) ? o : { ...o, expression: m.expression });
654
+ const m = s.find((T) => T.id === o.fromSelect);
655
+ m && c.push(C(o.expression, m.expression) ? o : { ...o, expression: m.expression });
656
656
  });
657
- const c = s.filter((o) => !l.has(o.id)).map((o) => ({
658
- id: F(),
657
+ const f = s.filter((o) => !i.has(o.id)).map((o) => ({
658
+ id: V(),
659
659
  expression: o.expression,
660
660
  fromSelect: o.id
661
- })), x = [...f, ...c];
662
- return x.length === r.length && x.every((o, m) => o === r[m]) ? e : { ...e, groupBy: x };
661
+ })), p = [...c, ...f];
662
+ return p.length === r.length && p.every((o, m) => o === r[m]) ? e : { ...e, groupBy: p };
663
663
  }
664
- function pe(e, t) {
665
- const r = (e.groupBy ?? []).map((n) => n.expression), a = e.orderBy ?? [];
666
- if (!D(e, t))
664
+ function be(e, t) {
665
+ const r = (e.groupBy ?? []).map((a) => a.expression), n = e.orderBy ?? [];
666
+ if (!B(e, t))
667
667
  return {
668
668
  select: [],
669
669
  selectAll: !1,
670
670
  orderBy: [],
671
671
  having: !1
672
672
  };
673
- const i = (n) => n.filter((s) => !g(s.expression, r, t)).map((s) => s.id);
673
+ const l = (a) => a.filter((s) => !h(s.expression, r, t)).map((s) => s.id);
674
674
  return {
675
- select: i(e.select),
675
+ select: l(e.select),
676
676
  selectAll: e.select.length === 0,
677
- orderBy: i(a),
678
- having: e.having !== void 0 && !g(e.having, r, t)
677
+ orderBy: l(n),
678
+ having: e.having !== void 0 && !h(e.having, r, t)
679
679
  };
680
680
  }
681
- const me = { tables: [], relations: [] };
682
- function de(e, t, r) {
681
+ const he = { tables: [], relations: [] };
682
+ function xe(e, t, r) {
683
683
  if (!t && !r) return e;
684
- const a = e.tables.filter((n) => !t || t(n)).map((n) => r ? { ...n, columns: n.columns.filter((s) => r(n, s)) } : n), i = new Set(a.map((n) => n.name));
684
+ const n = e.tables.filter((a) => !t || t(a)).map((a) => r ? { ...a, columns: a.columns.filter((s) => r(a, s)) } : a), l = new Set(n.map((a) => a.name));
685
685
  return {
686
- tables: a,
687
- relations: e.relations.filter((n) => i.has(n.fromTable) && i.has(n.toTable))
686
+ tables: n,
687
+ relations: e.relations.filter((a) => l.has(a.fromTable) && l.has(a.toTable))
688
688
  };
689
689
  }
690
- function ge(e) {
690
+ function Te(e) {
691
691
  return [...e.tables].sort((t, r) => t.label.localeCompare(r.label));
692
692
  }
693
- function be(e, t = (a) => a.group, r = e) {
694
- const a = /* @__PURE__ */ new Map();
695
- r.forEach((n) => {
696
- const s = t(n) || void 0;
697
- s !== void 0 && !a.has(s) && a.set(s, []);
698
- }), e.forEach((n) => {
699
- const s = t(n) || void 0;
700
- a.set(s, [...a.get(s) ?? [], n]);
693
+ function ve(e, t = (n) => n.group, r = e) {
694
+ const n = /* @__PURE__ */ new Map();
695
+ r.forEach((a) => {
696
+ const s = t(a) || void 0;
697
+ s !== void 0 && !n.has(s) && n.set(s, []);
698
+ }), e.forEach((a) => {
699
+ const s = t(a) || void 0;
700
+ n.set(s, [...n.get(s) ?? [], a]);
701
701
  });
702
- const i = (n) => [...n].sort((s, l) => s.label.localeCompare(l.label));
702
+ const l = (a) => [...a].sort((s, i) => s.label.localeCompare(i.label));
703
703
  return [
704
- ...[...a].filter(([n]) => n !== void 0),
705
- ...[...a].filter(([n]) => n === void 0)
706
- ].filter(([, n]) => n.length > 0).map(([n, s]) => ({ group: n, tables: i(s) }));
704
+ ...[...n].filter(([a]) => a !== void 0),
705
+ ...[...n].filter(([a]) => a === void 0)
706
+ ].filter(([, a]) => a.length > 0).map(([a, s]) => ({ group: a, tables: l(s) }));
707
707
  }
708
- function _(e, t) {
708
+ function L(e, t) {
709
709
  return e.tables.find((r) => r.name === t);
710
710
  }
711
- function $(e, t, r) {
712
- return e.relations.find((a) => a.fromTable === t && a.toTable === r || a.fromTable === r && a.toTable === t);
711
+ function Q(e, t, r) {
712
+ return e.relations.find((n) => n.fromTable === t && n.toTable === r || n.fromTable === r && n.toTable === t);
713
713
  }
714
- function he(e, t, r) {
714
+ const k = (e, t) => {
715
+ var r;
716
+ return ((r = L(e, t)) == null ? void 0 : r.passThrough) !== !1;
717
+ };
718
+ function O(e, t) {
719
+ const r = t.filter((n) => k(e, n));
720
+ return r.length > 0 ? r : t;
721
+ }
722
+ const G = (e, t) => e.fanOuts - t.fanOuts || e.steps - t.steps || e.order - t.order;
723
+ function S(e, t) {
724
+ let r;
725
+ return e.forEach((n, l) => {
726
+ !t.has(l) && (r === void 0 || G(n, e.get(r)) < 0) && (r = l);
727
+ }), r;
728
+ }
729
+ function ke(e, t, r) {
715
730
  if (t.includes(r)) return [];
716
- const a = /* @__PURE__ */ new Map(), i = new Set(t), n = [...t];
717
- for (; n.length > 0 && !i.has(r); ) {
718
- const f = n.shift();
719
- e.relations.filter((c) => c.fromTable === f || c.toTable === f).map((c) => c.fromTable === f ? c.toTable : c.fromTable).forEach((c) => {
720
- i.has(c) || (i.add(c), a.set(c, f), n.push(c));
731
+ const n = O(e, t), l = new Map(t.map((f, p) => [f, {
732
+ fanOuts: 0,
733
+ steps: 0,
734
+ order: p
735
+ }])), a = new Set(t.filter((f) => !n.includes(f)));
736
+ let s = t.length;
737
+ const i = (f) => {
738
+ const p = l.get(f);
739
+ p.steps > 0 && !k(e, f) || e.relations.forEach((d) => {
740
+ if (d.fromTable !== f && d.toTable !== f) return;
741
+ const o = d.fromTable === f ? d.toTable : d.fromTable, m = {
742
+ fanOuts: p.fanOuts + (d.fromTable === f ? 0 : 1),
743
+ steps: p.steps + 1,
744
+ order: s,
745
+ from: f
746
+ }, T = l.get(o);
747
+ a.has(o) || T && G(m, { ...T, order: s }) >= 0 || (l.set(o, m), s += 1);
721
748
  });
722
- }
723
- if (!i.has(r)) return;
724
- const s = [];
725
- let l = r;
726
- for (; !t.includes(l); )
727
- s.unshift(l), l = a.get(l);
728
- return s;
729
- }
730
- function xe(e, t) {
731
- const r = /* @__PURE__ */ new Map(), a = (s, l) => r.set(s, [...r.get(s) ?? [], l]);
749
+ };
750
+ for (let f = S(l, a); f !== void 0 && f !== r; f = S(l, a))
751
+ a.add(f), i(f);
752
+ if (!l.has(r)) return;
753
+ const c = [];
754
+ for (let f = r; !t.includes(f); f = l.get(f).from)
755
+ c.unshift(f);
756
+ return c;
757
+ }
758
+ function Ee(e, t) {
759
+ const r = /* @__PURE__ */ new Map(), n = (s, i) => r.set(s, [...r.get(s) ?? [], i]);
732
760
  e.relations.forEach((s) => {
733
- a(s.fromTable, s.toTable), a(s.toTable, s.fromTable);
761
+ n(s.fromTable, s.toTable), n(s.toTable, s.fromTable);
734
762
  });
735
- const i = new Set(t), n = [...t];
736
- for (let s = n.shift(); s !== void 0; s = n.shift())
737
- (r.get(s) ?? []).forEach((l) => {
738
- i.has(l) || (i.add(l), n.push(l));
763
+ const l = new Set(t), a = O(e, t);
764
+ for (let s = a.shift(); s !== void 0; s = a.shift())
765
+ (r.get(s) ?? []).forEach((i) => {
766
+ l.has(i) || (l.add(i), k(e, i) && a.push(i));
739
767
  });
740
- return i;
768
+ return l;
741
769
  }
742
- function Te(e, t, r) {
743
- var l;
744
- const a = t.map((f) => $(e, f, r)).find((f) => f !== void 0);
745
- if (!a) return;
746
- const i = (l = _(e, a.fromTable)) == null ? void 0 : l.columns.find((f) => f.name === a.fromColumn), n = i != null && i.nullable ? "left" : "inner", s = {
770
+ function Ae(e, t, r) {
771
+ var c;
772
+ const l = (k(e, r) ? O(e, t) : t).map((f) => Q(e, f, r)).find((f) => f !== void 0);
773
+ if (!l) return;
774
+ const a = (c = L(e, l.fromTable)) == null ? void 0 : c.columns.find((f) => f.name === l.fromColumn), s = a != null && a.nullable ? "left" : "inner", i = {
747
775
  type: "binary",
748
776
  operator: "=",
749
- left: { type: "field", table: a.fromTable, column: a.fromColumn },
750
- right: { type: "field", table: a.toTable, column: a.toColumn }
777
+ left: { type: "field", table: l.fromTable, column: l.fromColumn },
778
+ right: { type: "field", table: l.toTable, column: l.toColumn }
751
779
  };
752
- return { joinType: n, on: s };
780
+ return { joinType: s, on: i };
753
781
  }
754
- const A = (e, t) => `${e}.${t}`;
755
- function P({ type: e, format: t }) {
782
+ const N = (e, t) => `${e}.${t}`;
783
+ function K({ type: e, format: t }) {
756
784
  if (t === void 0) return;
757
785
  if (e !== "date" && e !== "dateTime" && e !== "time")
758
786
  return `a format is for a date, date-and-time or time column, not ${e}`;
759
787
  const r = t.match(/YYYY|MM|DD|HH|mm|ss/g) ?? [];
760
788
  if (r.length === 0) return `format "${t}" has none of YYYY, MM, DD, HH, mm, ss`;
761
- if (e === "time" && r.some((a) => a === "YYYY" || a === "MM" || a === "DD"))
789
+ if (e === "time" && r.some((n) => n === "YYYY" || n === "MM" || n === "DD"))
762
790
  return `a time has no day: format "${t}" can't be written from one`;
763
791
  }
764
- function ve(e) {
792
+ function Re(e) {
765
793
  const t = [], r = /* @__PURE__ */ new Map();
766
- e.tables.forEach((n) => {
767
- r.has(n.name) && t.push({
794
+ e.tables.forEach((a) => {
795
+ r.has(a.name) && t.push({
768
796
  kind: "duplicateTable",
769
- message: `Table "${n.name}" is declared more than once`
770
- }), r.set(n.name, n);
797
+ message: `Table "${a.name}" is declared more than once`
798
+ }), r.set(a.name, a);
771
799
  const s = /* @__PURE__ */ new Set();
772
- n.columns.forEach((l) => {
773
- s.has(l.name) && t.push({
800
+ a.columns.forEach((i) => {
801
+ s.has(i.name) && t.push({
774
802
  kind: "duplicateColumn",
775
- message: `Column "${n.name}.${l.name}" is declared more than once`
776
- }), s.add(l.name);
777
- const f = P(l);
778
- f && t.push({
803
+ message: `Column "${a.name}.${i.name}" is declared more than once`
804
+ }), s.add(i.name);
805
+ const c = K(i);
806
+ c && t.push({
779
807
  kind: "invalidFormat",
780
- message: `Column "${n.name}.${l.name}": ${f}`
808
+ message: `Column "${a.name}.${i.name}": ${c}`
781
809
  });
782
810
  });
783
811
  });
784
- const a = (n, s) => {
785
- const l = r.get(n);
786
- l ? l.columns.some((f) => f.name === s) || t.push({
812
+ const n = (a, s) => {
813
+ const i = r.get(a);
814
+ i ? i.columns.some((c) => c.name === s) || t.push({
787
815
  kind: "unknownColumn",
788
- message: `Relation references unknown column "${n}.${s}"`
816
+ message: `Relation references unknown column "${a}.${s}"`
789
817
  }) : t.push({
790
818
  kind: "unknownTable",
791
- message: `Relation references unknown table "${n}"`
819
+ message: `Relation references unknown table "${a}"`
792
820
  });
793
- }, i = /* @__PURE__ */ new Set();
794
- return e.relations.forEach((n) => {
795
- a(n.fromTable, n.fromColumn), a(n.toTable, n.toColumn);
796
- const s = A(n.fromTable, n.fromColumn), l = A(n.toTable, n.toColumn), f = [s, l].sort().join(" <-> ");
797
- i.has(f) && t.push({
821
+ }, l = /* @__PURE__ */ new Set();
822
+ return e.relations.forEach((a) => {
823
+ n(a.fromTable, a.fromColumn), n(a.toTable, a.toColumn);
824
+ const s = N(a.fromTable, a.fromColumn), i = N(a.toTable, a.toColumn), c = [s, i].sort().join(" <-> ");
825
+ l.has(c) && t.push({
798
826
  kind: "duplicateRelation",
799
- message: `Relation ${s} -> ${l} is declared more than once (declare each foreign key once)`
800
- }), i.add(f);
827
+ message: `Relation ${s} -> ${i} is declared more than once (declare each foreign key once)`
828
+ }), l.add(c);
801
829
  }), t;
802
830
  }
803
831
  export {
804
- q as A,
805
- ge as B,
806
- xe as C,
807
- se as D,
808
- me as E,
809
- he as F,
810
- Te as G,
811
- T as H,
812
- C as I,
813
- k as J,
814
- w as K,
815
- le as L,
816
- z as M,
817
- D as N,
818
- W as O,
819
- re as P,
820
- M as Q,
821
- ie as R,
822
- j as S,
823
- te as T,
824
- ae as U,
825
- be as V,
826
- N as W,
827
- oe as X,
828
- fe as Y,
829
- ue as a,
830
- X as b,
831
- Y as c,
832
- F as d,
833
- Q as e,
834
- de as f,
835
- E as g,
836
- J as h,
837
- v as i,
838
- Z as j,
839
- _ as k,
840
- p as l,
841
- H as m,
842
- ce as n,
843
- R as o,
844
- ne as p,
845
- y as q,
846
- b as r,
847
- ee as s,
848
- I as t,
849
- pe as u,
850
- ve as v,
851
- S as w,
852
- K as x,
853
- B as y,
854
- L as z
832
+ B as A,
833
+ J as B,
834
+ be as C,
835
+ oe as D,
836
+ he as E,
837
+ le as F,
838
+ w as G,
839
+ R as H,
840
+ ae as I,
841
+ q as J,
842
+ H as K,
843
+ _ as L,
844
+ te as M,
845
+ ne as N,
846
+ Ee as O,
847
+ D as P,
848
+ F as Q,
849
+ ce as R,
850
+ W as S,
851
+ se as T,
852
+ ie as U,
853
+ ve as V,
854
+ U as W,
855
+ me as X,
856
+ de as Y,
857
+ x as a,
858
+ z as b,
859
+ pe as c,
860
+ C as d,
861
+ ke as e,
862
+ xe as f,
863
+ y as g,
864
+ ee as h,
865
+ A as i,
866
+ E as j,
867
+ L as k,
868
+ P as l,
869
+ M as m,
870
+ V as n,
871
+ Z as o,
872
+ ue as p,
873
+ j as q,
874
+ re as r,
875
+ Ae as s,
876
+ Y as t,
877
+ g as u,
878
+ Re as v,
879
+ X as w,
880
+ ge as x,
881
+ Te as y,
882
+ fe as z
855
883
  };