@nongt/visql 0.8.0 → 0.10.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 (48) hide show
  1. package/README.md +23 -360
  2. package/dist/{MuiTimePicker-BjywwrRm.js → MuiTimePicker-DRqT6ByZ.js} +1 -1
  3. package/dist/PipelineEditor-Ch_i6OAc.js +10537 -0
  4. package/dist/core.js +339 -78
  5. package/dist/explain.js +356 -0
  6. package/dist/index.js +119 -100
  7. package/dist/issueLocation-Y1iaP_Cs.js +1108 -0
  8. package/dist/mui-date-pickers-host.js +1 -1
  9. package/dist/mui-date-pickers.js +1 -1
  10. package/dist/mui.js +95 -84
  11. package/dist/params-kc6eNrpu.js +2223 -0
  12. package/dist/{schema-DFC26AhZ.js → schema-KDJ1rpG5.js} +334 -271
  13. package/dist/sql-import.js +1 -1
  14. package/dist/sqlGen-Crgheqys.js +903 -0
  15. package/dist/style.css +1 -1
  16. package/dist/tokens-DV5rTGMj.js +171 -0
  17. package/dist/types/core/components/flow/NodeActionFrame.d.ts +20 -0
  18. package/dist/types/core/components/flow/useNodeActions.d.ts +18 -0
  19. package/dist/types/core/existsMenu.d.ts +4 -3
  20. package/dist/types/core/i18n/defaultMessages.d.ts +15 -0
  21. package/dist/types/core/i18n/messages.d.ts +11 -0
  22. package/dist/types/core/pipelineFlow.d.ts +1 -1
  23. package/dist/types/core/planFindings.d.ts +27 -0
  24. package/dist/types/core/queryHelpers.d.ts +1 -1
  25. package/dist/types/core/schema.d.ts +68 -24
  26. package/dist/types/core/scopeQuery.d.ts +2 -2
  27. package/dist/types/core/theme/appearance.d.ts +27 -0
  28. package/dist/types/core/theme/looks.d.ts +14 -0
  29. package/dist/types/core/theme/tokens.d.ts +9 -1
  30. package/dist/types/core-api.d.ts +2 -1
  31. package/dist/types/explain/explainQuery.d.ts +59 -0
  32. package/dist/types/explain/mySqlPlan.d.ts +4 -0
  33. package/dist/types/explain/planPlaces.d.ts +27 -0
  34. package/dist/types/explain/postgresPlan.d.ts +4 -0
  35. package/dist/types/explain/sqlServerPlan.d.ts +4 -0
  36. package/dist/types/explain/xml.d.ts +7 -0
  37. package/dist/types/explain.d.ts +2 -0
  38. package/dist/types/features/queryEditor/CanvasBackground.d.ts +2 -0
  39. package/dist/types/features/queryEditor/ExplainButton.d.ts +13 -0
  40. package/dist/types/features/queryEditor/IssuesButton.d.ts +14 -6
  41. package/dist/types/features/queryEditor/PipelineEditor.d.ts +15 -0
  42. package/dist/types/features/queryEditor/planText.d.ts +8 -0
  43. package/dist/types/index.d.ts +2 -0
  44. package/package.json +14 -1
  45. package/dist/PipelineEditor-DtT1TPgd.js +0 -10214
  46. package/dist/core-api-jaQDPXVK.js +0 -1171
  47. package/dist/issueLocation-DEIwB1DW.js +0 -3290
  48. package/dist/tokens-BTaVMSOx.js +0 -95
@@ -1,4 +1,4 @@
1
- function b(e) {
1
+ function k(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,100 +31,100 @@ function b(e) {
31
31
  return [];
32
32
  }
33
33
  }
34
- const W = ["inner", "left", "right", "full", "cross"];
35
- function v(e) {
34
+ const le = ["inner", "left", "right", "full", "cross"];
35
+ function M(e) {
36
36
  return "union" in e;
37
37
  }
38
- function X(e) {
39
- return v(e) ? e.union : [e];
38
+ function ie(e) {
39
+ return M(e) ? e.union : [e];
40
40
  }
41
- function Q(e) {
42
- return v(e) ? e.union[0] : e;
41
+ function ue(e) {
42
+ return M(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 N(e, t) {
45
+ if (!M(e)) return t(e, 0);
46
+ const n = e.union.map((r, i) => t(r, i));
47
+ return n.every((r, i) => r === e.union[i]) ? e : { ...e, union: n };
48
48
  }
49
- function K(e, t) {
49
+ function oe(e, t) {
50
50
  if (!e.shared) return e;
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 });
51
+ let n = !1;
52
+ const r = e.shared.map((i) => {
53
+ const a = t(i.query, i);
54
+ return a === i.query ? i : (n = !0, { ...i, query: a });
55
55
  });
56
- return r ? { ...e, shared: a } : e;
56
+ return n ? { ...e, shared: r } : e;
57
57
  }
58
- function J(e) {
58
+ function fe(e) {
59
59
  return "from" in e;
60
60
  }
61
- const z = 63;
62
- function I(e) {
61
+ const ce = 63;
62
+ function K(e) {
63
63
  return e.alias || e.table || "";
64
64
  }
65
- function Z(e) {
65
+ function pe(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 Q(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 de(e) {
72
+ return Q(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
73
73
  }
74
- function R(e, t) {
75
- const r = t;
74
+ function Y(e, t) {
75
+ const n = t;
76
76
  switch (e.type) {
77
77
  case "function":
78
78
  return {
79
79
  ...e,
80
- args: e.args.map(r),
81
- ...e.orderBy ? { orderBy: e.orderBy.map((a) => ({ ...a, expression: r(a.expression) })) } : {}
80
+ args: e.args.map(n),
81
+ ...e.orderBy ? { orderBy: e.orderBy.map((r) => ({ ...r, expression: n(r.expression) })) } : {}
82
82
  };
83
83
  case "binary":
84
84
  return {
85
85
  ...e,
86
- left: r(e.left),
87
- ...e.right ? { right: r(e.right) } : {}
86
+ left: n(e.left),
87
+ ...e.right ? { right: n(e.right) } : {}
88
88
  };
89
89
  case "logical":
90
- return { ...e, operands: e.operands.map(r) };
90
+ return { ...e, operands: e.operands.map(n) };
91
91
  case "list":
92
- return { ...e, items: e.items.map(r) };
92
+ return { ...e, items: e.items.map(n) };
93
93
  case "not":
94
- return { ...e, operand: r(e.operand) };
94
+ return { ...e, operand: n(e.operand) };
95
95
  case "if":
96
96
  return {
97
97
  ...e,
98
- condition: e.condition && r(e.condition),
99
- then: e.then && r(e.then),
100
- else: e.else && r(e.else)
98
+ condition: e.condition && n(e.condition),
99
+ then: e.then && n(e.then),
100
+ else: e.else && n(e.else)
101
101
  };
102
102
  case "case":
103
103
  return {
104
104
  ...e,
105
- subject: e.subject && r(e.subject),
106
- branches: e.branches.map((a) => ({ when: r(a.when), then: r(a.then) })),
107
- else: e.else && r(e.else)
105
+ subject: e.subject && n(e.subject),
106
+ branches: e.branches.map((r) => ({ when: n(r.when), then: n(r.then) })),
107
+ else: e.else && n(e.else)
108
108
  };
109
109
  case "exists":
110
110
  return {
111
111
  ...e,
112
- link: r(e.link),
112
+ link: n(e.link),
113
113
  query: {
114
114
  ...e.query,
115
- joins: e.query.joins.map((a) => a.on ? { ...a, on: r(a.on) } : a),
116
- ...e.query.where ? { where: r(e.query.where) } : {}
115
+ joins: e.query.joins.map((r) => r.on ? { ...r, on: n(r.on) } : r),
116
+ ...e.query.where ? { where: n(e.query.where) } : {}
117
117
  }
118
118
  };
119
119
  default:
120
120
  return e;
121
121
  }
122
122
  }
123
- function C(e, t) {
124
- const r = R(e, (a) => C(a, t));
125
- return r === e ? t(e) : r;
123
+ function $(e, t) {
124
+ const n = Y(e, (r) => $(r, t));
125
+ return n === e ? t(e) : n;
126
126
  }
127
- function ee(e) {
127
+ function me(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 j(e, t, n = (r) => j(r, t)) {
138
+ var a, l;
139
+ const r = t, { shared: i } = e;
140
140
  return {
141
141
  ...e,
142
142
  ...i ? {
143
- shared: i.map((l) => ({ ...l, query: T(l.query, r) }))
143
+ shared: i.map((s) => ({ ...s, query: N(s.query, n) }))
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: N(e.from.query, n) } : e.from,
146
+ where: e.where && r(e.where),
147
+ joins: e.joins.map((s) => s.query ? { ...s, on: s.on && r(s.on), query: N(s.query, n) } : { ...s, on: s.on && r(s.on) }),
148
+ select: e.select.map((s) => ({ ...s, expression: r(s.expression) })),
149
+ groupBy: (a = e.groupBy) == null ? void 0 : a.map((s) => ({ ...s, expression: r(s.expression) })),
150
+ having: e.having && r(e.having),
151
+ orderBy: (l = e.orderBy) == null ? void 0 : l.map((s) => ({ ...s, expression: r(s.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 J(e, t) {
155
+ const n = (r) => r.type === "subquery" ? { ...r, query: J(r.query, t) } : Y(r, n);
156
+ return j(e, (r) => $(n(r), t));
157
157
  }
158
- function B(e) {
159
- return new Set([e.from, ...e.joins].map(I));
158
+ function z(e) {
159
+ return new Set([e.from, ...e.joins].map(K));
160
160
  }
161
- function L(e) {
162
- return e !== void 0 && (e.type === "exists" || b(e).some(L));
161
+ function Z(e) {
162
+ return e !== void 0 && (e.type === "exists" || k(e).some(Z));
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 q(e) {
165
+ const t = z(e.query), n = (r) => r.type === "field" ? [r] : k(r).flatMap(n);
166
+ return n(e.link).filter((r) => r.table !== void 0 && !t.has(r.table));
167
167
  }
168
- const te = {
168
+ const ge = {
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" }, ee = [
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 be(e, t) {
184
184
  if (t < e.args.length) return e.args[t];
185
- const r = e.args[e.args.length - 1];
186
- return r != null && r.variadic ? r : void 0;
185
+ const n = e.args[e.args.length - 1];
186
+ return n != null && n.variadic ? n : void 0;
187
187
  }
188
- function ae(e) {
188
+ function he(e) {
189
189
  return e.args.map((t) => t.default ?? { type: "literal", value: "" });
190
190
  }
191
- const d = (e, t = "DAY") => ({
191
+ const T = (e, t = "DAY") => ({
192
192
  label: e,
193
193
  kind: "unit",
194
- choices: Y,
194
+ choices: ee,
195
195
  default: { type: "literal", value: t }
196
- }), h = {
196
+ }), S = {
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
+ T("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
+ T("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
+ T("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
+ T("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
+ T("unit")
298
298
  ]
299
299
  },
300
300
  // ---- Type cast ----
@@ -577,279 +577,342 @@ const d = (e, t = "DAY") => ({
577
577
  ]
578
578
  }
579
579
  };
580
- function k(e, t = h) {
580
+ function D(e, t = S) {
581
581
  return t[e.toUpperCase()];
582
582
  }
583
- function ne(e, t) {
584
- const r = e.toUpperCase();
585
- return k(e, t) ?? Object.values(t).find((a) => {
583
+ function xe(e, t) {
584
+ const n = e.toUpperCase();
585
+ return D(e, t) ?? Object.values(t).find((r) => {
586
586
  var i;
587
- return (i = a.aliases) == null ? void 0 : i.some((n) => n.toUpperCase() === r);
587
+ return (i = r.aliases) == null ? void 0 : i.some((a) => a.toUpperCase() === n);
588
588
  });
589
589
  }
590
- function j(e = h) {
590
+ function te(e = S) {
591
591
  return Object.keys(e).sort();
592
592
  }
593
- j(h);
594
- const se = h;
595
- function le(e) {
593
+ te(S);
594
+ const Te = S;
595
+ function ve(e) {
596
596
  return Object.fromEntries(Object.values(e).map((t) => {
597
- const r = t.name.toUpperCase();
598
- return [r, { ...t, name: r }];
597
+ const n = t.name.toUpperCase();
598
+ return [n, { ...t, name: n }];
599
599
  }));
600
600
  }
601
- function ie(e) {
601
+ function ke(e) {
602
602
  return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.aggregate));
603
603
  }
604
- function ue(e, t) {
605
- return Object.fromEntries(Object.entries(e).filter(([, r]) => !r.dialects || r.dialects.includes(t)));
604
+ function Ee(e, t) {
605
+ return Object.fromEntries(Object.entries(e).filter(([, n]) => !n.dialects || n.dialects.includes(t)));
606
606
  }
607
- function E(e, t) {
607
+ function U(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 n = e, r = t, i = Object.keys(n).filter((l) => n[l] !== void 0), a = Object.keys(r).filter((l) => r[l] !== void 0);
612
+ return i.length === a.length && i.every((l) => U(n[l], r[l]));
613
613
  }
614
- function F() {
614
+ function ne() {
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) {
619
- var r;
620
- return e.type === "function" && ((r = k(e.name, t)) == null ? void 0 : r.aggregate) === !0;
618
+ function _(e, t) {
619
+ var n;
620
+ return e.type === "function" && ((n = D(e.name, t)) == null ? void 0 : n.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 x(e, t) {
623
+ return e ? _(e, t) || k(e).some((n) => x(n, 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 F(e, t) {
626
+ return e.type === "function" && e.name.trim() !== "" && D(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 H(e, t) {
629
+ return e ? F(e, t) || k(e).some((n) => H(n, 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 v(e, t, n) {
632
+ return t.some((r) => U(r, e)) ? !0 : e.type === "field" ? !e.column : e.type === "exists" ? q(e).every((r) => v(r, t, n)) : _(e, n) || F(e, n) ? !0 : k(e).every((r) => v(r, t, n));
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 P(e, t) {
635
+ return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((n) => x(n.expression, t));
636
636
  }
637
- function oe(e, t) {
638
- if (D(e, t))
639
- return (e.groupBy ?? []).flatMap(({ expression: r }) => r.type === "field" && r.table && r.column ? [`${r.table}.${r.column}`] : []);
637
+ function Ae(e, t) {
638
+ if (P(e, t))
639
+ return (e.groupBy ?? []).flatMap(({ expression: n }) => n.type === "field" && n.table && n.column ? [`${n.table}.${n.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 re(e, t) {
642
+ return x(e.having, t) || [...e.select, ...e.orderBy ?? []].some((n) => x(n.expression, t));
643
643
  }
644
- function fe(e, t) {
645
- return e.select.some((r) => p(r.expression, t));
644
+ function Re(e, t) {
645
+ return e.select.some((n) => x(n.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 = [];
649
- r.forEach((o) => {
647
+ function Se(e, t) {
648
+ const n = e.groupBy ?? [], r = n.filter((o) => o.fromSelect === void 0), i = re(e, t), a = r.map((o) => o.expression), l = i ? e.select.filter((o) => x(o.expression, t) || H(o.expression, t) || v(o.expression, a, t) ? !1 : (a.push(o.expression), !0)) : [], s = new Map(n.filter((o) => o.fromSelect !== void 0).map((o) => [o.fromSelect, o])), f = [];
649
+ n.forEach((o) => {
650
650
  if (o.fromSelect === void 0) {
651
651
  f.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 p = l.find((d) => d.id === o.fromSelect);
655
+ p && f.push(U(o.expression, p.expression) ? o : { ...o, expression: p.expression });
656
656
  });
657
- const c = s.filter((o) => !l.has(o.id)).map((o) => ({
658
- id: F(),
657
+ const m = l.filter((o) => !s.has(o.id)).map((o) => ({
658
+ id: ne(),
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
+ })), h = [...f, ...m];
662
+ return h.length === n.length && h.every((o, p) => o === n[p]) ? e : { ...e, groupBy: h };
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 Ce(e, t) {
665
+ const n = (e.groupBy ?? []).map((a) => a.expression), r = e.orderBy ?? [];
666
+ if (!P(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 i = (a) => a.filter((l) => !v(l.expression, n, t)).map((l) => l.id);
674
674
  return {
675
675
  select: i(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: i(r),
678
+ having: e.having !== void 0 && !v(e.having, n, t)
679
679
  };
680
680
  }
681
- const me = { tables: [], relations: [] };
682
- function de(e, t, r) {
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));
681
+ const Oe = { tables: [], relations: [] };
682
+ function ye(e, t, n) {
683
+ if (!t && !n) return e;
684
+ const r = e.tables.filter((a) => !t || t(a)).map((a) => n ? { ...a, columns: a.columns.filter((l) => n(a, l)) } : a), i = new Set(r.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: r,
687
+ relations: e.relations.filter((a) => i.has(a.fromTable) && i.has(a.toTable))
688
688
  };
689
689
  }
690
- function ge(e) {
691
- return [...e.tables].sort((t, r) => t.label.localeCompare(r.label));
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]);
690
+ function we(e) {
691
+ return [...e.tables].sort((t, n) => t.label.localeCompare(n.label));
692
+ }
693
+ function Ne(e, t = (r) => r.group, n = e) {
694
+ const r = /* @__PURE__ */ new Map();
695
+ n.forEach((a) => {
696
+ const l = t(a) || void 0;
697
+ l !== void 0 && !r.has(l) && r.set(l, []);
698
+ }), e.forEach((a) => {
699
+ const l = t(a) || void 0;
700
+ r.set(l, [...r.get(l) ?? [], a]);
701
701
  });
702
- const i = (n) => [...n].sort((s, l) => s.label.localeCompare(l.label));
702
+ const i = (a) => [...a].sort((l, s) => l.label.localeCompare(s.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
+ ...[...r].filter(([a]) => a !== void 0),
705
+ ...[...r].filter(([a]) => a === void 0)
706
+ ].filter(([, a]) => a.length > 0).map(([a, l]) => ({ group: a, tables: i(l) }));
707
707
  }
708
- function _(e, t) {
709
- return e.tables.find((r) => r.name === t);
710
- }
711
- function $(e, t, r) {
712
- return e.relations.find((a) => a.fromTable === t && a.toTable === r || a.fromTable === r && a.toTable === t);
713
- }
714
- function he(e, t, r) {
715
- 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));
721
- });
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;
708
+ function W(e, t) {
709
+ return e.tables.find((n) => n.name === t);
729
710
  }
730
- function xe(e, t) {
731
- const r = /* @__PURE__ */ new Map(), a = (s, l) => r.set(s, [...r.get(s) ?? [], l]);
732
- e.relations.forEach((s) => {
733
- a(s.fromTable, s.toTable), a(s.toTable, s.fromTable);
711
+ function A(e, t, n) {
712
+ return e.relations.find((r) => r.fromTable === t && r.toTable === n || r.fromTable === n && r.toTable === t);
713
+ }
714
+ const C = (e, t) => {
715
+ var n;
716
+ return ((n = W(e, t)) == null ? void 0 : n.passThrough) !== !1;
717
+ };
718
+ function I(e, t) {
719
+ const n = t.filter((r) => C(e, r));
720
+ return n.length > 0 ? n : [...t];
721
+ }
722
+ function V(e, t) {
723
+ const n = /* @__PURE__ */ new Set();
724
+ return t.forEach((r, i) => {
725
+ const l = t.slice(0, i).map((f) => ({ earlier: f, r: A(e, f, r) })).find(({ r: f }) => f !== void 0);
726
+ if (!l) return;
727
+ (l.r.fromTable === l.earlier && l.r.toTable === r || n.has(l.earlier)) && n.add(r);
728
+ }), n;
729
+ }
730
+ const X = (e, t) => e.fanOuts - t.fanOuts || e.steps - t.steps || e.order - t.order, R = (e, t) => `${t ? "^" : "_"}${e}`;
731
+ function L(e, t) {
732
+ let n;
733
+ return e.forEach((r, i) => {
734
+ !t.has(i) && (n === void 0 || X(r, e.get(n)) < 0) && (n = i);
735
+ }), n;
736
+ }
737
+ function ae(e, t, n, r = {}) {
738
+ const i = new Set(t), a = new Set(I(e, t)), l = r.anyShape ? /* @__PURE__ */ new Set() : V(e, t), s = /* @__PURE__ */ new Map();
739
+ t.forEach((d, g) => {
740
+ const b = R(d, l.has(d));
741
+ s.has(b) || s.set(b, {
742
+ table: d,
743
+ climbed: l.has(d),
744
+ fanOuts: 0,
745
+ steps: 0,
746
+ order: g
747
+ });
734
748
  });
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));
749
+ const f = new Set([...s].filter(([, d]) => !a.has(d.table)).map(([d]) => d));
750
+ let m = t.length;
751
+ const h = (d) => {
752
+ const g = s.get(d);
753
+ g.steps > 0 && !C(e, g.table) || e.relations.forEach((b) => {
754
+ if (b.fromTable !== g.table && b.toTable !== g.table) return;
755
+ const E = b.fromTable === g.table, O = E ? b.toTable : b.fromTable;
756
+ if (i.has(O) || !E && g.climbed) return;
757
+ const y = {
758
+ table: O,
759
+ climbed: !r.anyShape && (g.climbed || E),
760
+ fanOuts: g.fanOuts + (E ? 0 : 1),
761
+ steps: g.steps + 1,
762
+ order: m,
763
+ from: d
764
+ }, w = R(O, y.climbed), B = s.get(w);
765
+ f.has(w) || B && X(y, { ...B, order: m }) >= 0 || (s.set(w, y), m += 1);
739
766
  });
740
- return i;
741
- }
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 = {
767
+ };
768
+ let c = L(s, f);
769
+ for (; c !== void 0 && s.get(c).table !== n; )
770
+ f.add(c), h(c), c = L(s, f);
771
+ if (c === void 0) return;
772
+ const o = [];
773
+ let p = s.get(c);
774
+ for (; p.from !== void 0; )
775
+ o.unshift(p.table), p = s.get(p.from);
776
+ return { start: p.table, tables: o };
777
+ }
778
+ function Me(e, t, n, r = {}) {
779
+ var i;
780
+ return t.includes(n) ? [] : (i = ae(e, t, n, r)) == null ? void 0 : i.tables;
781
+ }
782
+ function De(e, t, n = {}) {
783
+ const r = /* @__PURE__ */ new Map(), i = (c, o, p) => r.set(c, [
784
+ ...r.get(c) ?? [],
785
+ { table: o, up: p }
786
+ ]);
787
+ e.relations.forEach((c) => {
788
+ i(c.fromTable, c.toTable, !0), i(c.toTable, c.fromTable, !1);
789
+ });
790
+ const { skip: a = /* @__PURE__ */ new Set() } = n, l = n.anyShape ? /* @__PURE__ */ new Set() : V(e, t), s = new Set(t), f = new Set(t), m = I(e, t).map((c) => ({ table: c, climbed: l.has(c) })), h = new Set(m.map((c) => R(c.table, c.climbed)));
791
+ for (let c = m.shift(); c !== void 0; c = m.shift()) {
792
+ const o = c;
793
+ (r.get(o.table) ?? []).forEach(({ table: p, up: d }) => {
794
+ if (s.has(p) || a.has(p) || !d && o.climbed) return;
795
+ const g = { table: p, climbed: !n.anyShape && (o.climbed || d) }, b = R(p, g.climbed);
796
+ h.has(b) || (h.add(b), f.add(p), C(e, p) && m.push(g));
797
+ });
798
+ }
799
+ return f;
800
+ }
801
+ function Ue(e, t, n, r = {}) {
802
+ var o;
803
+ const { after: i, leftJoined: a = [] } = r;
804
+ let l = C(e, n) ? I(e, t) : t;
805
+ i !== void 0 && A(e, i, n) && (l = [i]);
806
+ const s = l.find((p) => A(e, p, n) !== void 0);
807
+ if (s === void 0) return;
808
+ const f = A(e, s, n), m = (o = W(e, f.fromTable)) == null ? void 0 : o.columns.find((p) => p.name === f.fromColumn), h = m != null && m.nullable || a.includes(s) ? "left" : "inner", c = {
747
809
  type: "binary",
748
810
  operator: "=",
749
- left: { type: "field", table: a.fromTable, column: a.fromColumn },
750
- right: { type: "field", table: a.toTable, column: a.toColumn }
811
+ left: { type: "field", table: f.fromTable, column: f.fromColumn },
812
+ right: { type: "field", table: f.toTable, column: f.toColumn }
751
813
  };
752
- return { joinType: n, on: s };
814
+ return { joinType: h, on: c };
753
815
  }
754
- const A = (e, t) => `${e}.${t}`;
755
- function P({ type: e, format: t }) {
816
+ const G = (e, t) => `${e}.${t}`;
817
+ function se({ type: e, format: t }) {
756
818
  if (t === void 0) return;
757
819
  if (e !== "date" && e !== "dateTime" && e !== "time")
758
820
  return `a format is for a date, date-and-time or time column, not ${e}`;
759
- const r = t.match(/YYYY|MM|DD|HH|mm|ss/g) ?? [];
760
- 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"))
821
+ const n = t.match(/YYYY|MM|DD|HH|mm|ss/g) ?? [];
822
+ if (n.length === 0) return `format "${t}" has none of YYYY, MM, DD, HH, mm, ss`;
823
+ if (e === "time" && n.some((r) => r === "YYYY" || r === "MM" || r === "DD"))
762
824
  return `a time has no day: format "${t}" can't be written from one`;
763
825
  }
764
- function ve(e) {
765
- const t = [], r = /* @__PURE__ */ new Map();
766
- e.tables.forEach((n) => {
767
- r.has(n.name) && t.push({
826
+ function Ie(e) {
827
+ const t = [], n = /* @__PURE__ */ new Map();
828
+ e.tables.forEach((a) => {
829
+ n.has(a.name) && t.push({
768
830
  kind: "duplicateTable",
769
- message: `Table "${n.name}" is declared more than once`
770
- }), r.set(n.name, n);
771
- const s = /* @__PURE__ */ new Set();
772
- n.columns.forEach((l) => {
773
- s.has(l.name) && t.push({
831
+ message: `Table "${a.name}" is declared more than once`
832
+ }), n.set(a.name, a);
833
+ const l = /* @__PURE__ */ new Set();
834
+ a.columns.forEach((s) => {
835
+ l.has(s.name) && t.push({
774
836
  kind: "duplicateColumn",
775
- message: `Column "${n.name}.${l.name}" is declared more than once`
776
- }), s.add(l.name);
777
- const f = P(l);
837
+ message: `Column "${a.name}.${s.name}" is declared more than once`
838
+ }), l.add(s.name);
839
+ const f = se(s);
778
840
  f && t.push({
779
841
  kind: "invalidFormat",
780
- message: `Column "${n.name}.${l.name}": ${f}`
842
+ message: `Column "${a.name}.${s.name}": ${f}`
781
843
  });
782
844
  });
783
845
  });
784
- const a = (n, s) => {
785
- const l = r.get(n);
786
- l ? l.columns.some((f) => f.name === s) || t.push({
846
+ const r = (a, l) => {
847
+ const s = n.get(a);
848
+ s ? s.columns.some((f) => f.name === l) || t.push({
787
849
  kind: "unknownColumn",
788
- message: `Relation references unknown column "${n}.${s}"`
850
+ message: `Relation references unknown column "${a}.${l}"`
789
851
  }) : t.push({
790
852
  kind: "unknownTable",
791
- message: `Relation references unknown table "${n}"`
853
+ message: `Relation references unknown table "${a}"`
792
854
  });
793
855
  }, 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(" <-> ");
856
+ return e.relations.forEach((a) => {
857
+ r(a.fromTable, a.fromColumn), r(a.toTable, a.toColumn);
858
+ const l = G(a.fromTable, a.fromColumn), s = G(a.toTable, a.toColumn), f = [l, s].sort().join(" <-> ");
797
859
  i.has(f) && t.push({
798
860
  kind: "duplicateRelation",
799
- message: `Relation ${s} -> ${l} is declared more than once (declare each foreign key once)`
861
+ message: `Relation ${l} -> ${s} is declared more than once (declare each foreign key once)`
800
862
  }), i.add(f);
801
863
  }), t;
802
864
  }
803
865
  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,
866
+ ve as A,
867
+ P as B,
868
+ le as C,
869
+ Te as D,
870
+ Oe as E,
871
+ Ce as F,
872
+ be as G,
873
+ H,
874
+ D as I,
875
+ me as J,
876
+ oe as K,
877
+ z as L,
878
+ ce as M,
879
+ Z as N,
880
+ de as O,
881
+ ae as P,
882
+ $ as Q,
883
+ J as R,
884
+ ke as S,
823
885
  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
886
+ ge as U,
887
+ he as V,
888
+ Ne as W,
889
+ _ as X,
890
+ Ae as Y,
891
+ Re as Z,
892
+ Me as a,
893
+ ie as b,
894
+ Ee as c,
895
+ U as d,
896
+ j as e,
897
+ ye as f,
898
+ N as g,
899
+ fe as h,
900
+ M as i,
901
+ W as j,
902
+ ee as k,
903
+ ne as l,
904
+ Y as m,
905
+ ue as n,
906
+ pe as o,
907
+ xe as p,
908
+ Q as q,
909
+ De as r,
910
+ Ue as s,
911
+ K as t,
912
+ x as u,
913
+ Ie as v,
914
+ re as w,
915
+ Se as x,
916
+ k as y,
917
+ we as z
855
918
  };