@nongt/visql 0.10.1 → 0.12.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 (42) hide show
  1. package/dist/{MuiTimePicker-DRqT6ByZ.js → MuiTimePicker-CROJXSCL.js} +1 -1
  2. package/dist/{PipelineEditor-CGTZGbmf.js → PipelineEditor-DHfbOSzT.js} +4342 -4039
  3. package/dist/core.js +163 -136
  4. package/dist/explain.js +3 -3
  5. package/dist/fixtures.js +3 -3
  6. package/dist/index.js +102 -110
  7. package/dist/issueLocation-DY-vvgFF.js +1155 -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 +2 -2
  11. package/dist/{params-DkVFbMQn.js → params-Btjlj45_.js} +255 -226
  12. package/dist/{schema-CgL10bid.js → schema-DsMO9oFE.js} +327 -245
  13. package/dist/sql-import.js +829 -786
  14. package/dist/sqlGen-DGXVba3D.js +941 -0
  15. package/dist/{tokens-DV5rTGMj.js → tokens-3SURLAkL.js} +15 -14
  16. package/dist/types/core/FunctionsContext.d.ts +8 -2
  17. package/dist/types/core/absolutePath.d.ts +3 -0
  18. package/dist/types/core/ast.d.ts +24 -2
  19. package/dist/types/core/components/expression/ExpressionTypeSelector.d.ts +1 -1
  20. package/dist/types/core/components/flow/CalculationFlowNode.d.ts +5 -0
  21. package/dist/types/core/components/flow/WindowKeys.d.ts +10 -0
  22. package/dist/types/core/expressionFlow.d.ts +48 -5
  23. package/dist/types/core/formula.d.ts +4 -1
  24. package/dist/types/core/functionRegistry.d.ts +15 -2
  25. package/dist/types/core/grouping.d.ts +6 -1
  26. package/dist/types/core/i18n/defaultMessages.d.ts +23 -0
  27. package/dist/types/core/i18n/messages.d.ts +17 -0
  28. package/dist/types/core/issueLocation.d.ts +6 -1
  29. package/dist/types/core/queryHelpers.d.ts +12 -1
  30. package/dist/types/core/queryValidation.d.ts +11 -1
  31. package/dist/types/core/sqlGen.d.ts +12 -0
  32. package/dist/types/core/storedQuery.d.ts +1 -1
  33. package/dist/types/core/theme/appearance.d.ts +4 -1
  34. package/dist/types/core/theme/looks.d.ts +6 -5
  35. package/dist/types/core/theme/tokens.d.ts +6 -3
  36. package/dist/types/core/valueTypes.d.ts +2 -2
  37. package/dist/types/core-api.d.ts +2 -2
  38. package/dist/types/sqlImport/context.d.ts +2 -2
  39. package/dist/types/sqlImport/syntax.d.ts +11 -2
  40. package/package.json +1 -1
  41. package/dist/issueLocation-BlQ280IE.js +0 -1108
  42. package/dist/sqlGen-C1kZwvWI.js +0 -903
@@ -1,9 +1,16 @@
1
- function k(e) {
1
+ function v(e) {
2
2
  switch (e.type) {
3
+ // In the order the SQL writes them: arguments, PARTITION BY, ORDER BY.
3
4
  case "function":
4
- return e.orderBy ? [...e.args, ...e.orderBy.map((t) => t.expression)] : e.args;
5
+ return e.orderBy || e.partitionBy ? [
6
+ ...e.args,
7
+ ...e.partitionBy ?? [],
8
+ ...(e.orderBy ?? []).map((t) => t.expression)
9
+ ] : e.args;
5
10
  case "binary":
6
11
  return e.right ? [e.left, e.right] : [e.left];
12
+ case "arithmetic":
13
+ return [e.left, e.right];
7
14
  case "logical":
8
15
  return e.operands;
9
16
  case "list":
@@ -31,100 +38,103 @@ function k(e) {
31
38
  return [];
32
39
  }
33
40
  }
34
- const le = ["inner", "left", "right", "full", "cross"];
35
- function M(e) {
41
+ const oe = ["inner", "left", "right", "full", "cross"];
42
+ function D(e) {
36
43
  return "union" in e;
37
44
  }
38
- function ie(e) {
39
- return M(e) ? e.union : [e];
45
+ function fe(e) {
46
+ return D(e) ? e.union : [e];
40
47
  }
41
- function ue(e) {
42
- return M(e) ? e.union[0] : e;
48
+ function ce(e) {
49
+ return D(e) ? e.union[0] : e;
43
50
  }
44
- function w(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 };
51
+ function O(e, t) {
52
+ if (!D(e)) return t(e, 0);
53
+ const r = e.union.map((n, i) => t(n, i));
54
+ return r.every((n, i) => n === e.union[i]) ? e : { ...e, union: r };
48
55
  }
49
- function oe(e, t) {
56
+ function pe(e, t) {
50
57
  if (!e.shared) return e;
51
- let n = !1;
52
- const r = e.shared.map((i) => {
58
+ let r = !1;
59
+ const n = e.shared.map((i) => {
53
60
  const a = t(i.query, i);
54
- return a === i.query ? i : (n = !0, { ...i, query: a });
61
+ return a === i.query ? i : (r = !0, { ...i, query: a });
55
62
  });
56
- return n ? { ...e, shared: r } : e;
63
+ return r ? { ...e, shared: n } : e;
57
64
  }
58
- function fe(e) {
65
+ function de(e) {
59
66
  return "from" in e;
60
67
  }
61
- const ce = 63;
62
- function K(e) {
68
+ const me = 63;
69
+ function Q(e) {
63
70
  return e.alias || e.table || "";
64
71
  }
65
- function pe(e) {
72
+ function ge(e) {
66
73
  return e.alias ? e.alias : e.expression.type === "field" ? e.expression.column : void 0;
67
74
  }
68
- function Q(e) {
75
+ function J(e) {
69
76
  return [e.from, ...e.joins];
70
77
  }
71
- function de(e) {
72
- return Q(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
78
+ function be(e) {
79
+ return J(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
73
80
  }
74
- function $(e, t) {
75
- const n = t;
81
+ function j(e, t) {
82
+ const r = t;
76
83
  switch (e.type) {
77
84
  case "function":
78
85
  return {
79
86
  ...e,
80
- args: e.args.map(n),
81
- ...e.orderBy ? { orderBy: e.orderBy.map((r) => ({ ...r, expression: n(r.expression) })) } : {}
87
+ args: e.args.map(r),
88
+ ...e.partitionBy ? { partitionBy: e.partitionBy.map(r) } : {},
89
+ ...e.orderBy ? { orderBy: e.orderBy.map((n) => ({ ...n, expression: r(n.expression) })) } : {}
82
90
  };
83
91
  case "binary":
84
92
  return {
85
93
  ...e,
86
- left: n(e.left),
87
- ...e.right ? { right: n(e.right) } : {}
94
+ left: r(e.left),
95
+ ...e.right ? { right: r(e.right) } : {}
88
96
  };
97
+ case "arithmetic":
98
+ return { ...e, left: r(e.left), right: r(e.right) };
89
99
  case "logical":
90
- return { ...e, operands: e.operands.map(n) };
100
+ return { ...e, operands: e.operands.map(r) };
91
101
  case "list":
92
- return { ...e, items: e.items.map(n) };
102
+ return { ...e, items: e.items.map(r) };
93
103
  case "not":
94
- return { ...e, operand: n(e.operand) };
104
+ return { ...e, operand: r(e.operand) };
95
105
  case "if":
96
106
  return {
97
107
  ...e,
98
- condition: e.condition && n(e.condition),
99
- then: e.then && n(e.then),
100
- else: e.else && n(e.else)
108
+ condition: e.condition && r(e.condition),
109
+ then: e.then && r(e.then),
110
+ else: e.else && r(e.else)
101
111
  };
102
112
  case "case":
103
113
  return {
104
114
  ...e,
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)
115
+ subject: e.subject && r(e.subject),
116
+ branches: e.branches.map((n) => ({ when: r(n.when), then: r(n.then) })),
117
+ else: e.else && r(e.else)
108
118
  };
109
119
  case "exists":
110
120
  return {
111
121
  ...e,
112
- link: n(e.link),
122
+ link: r(e.link),
113
123
  query: {
114
124
  ...e.query,
115
- joins: e.query.joins.map((r) => r.on ? { ...r, on: n(r.on) } : r),
116
- ...e.query.where ? { where: n(e.query.where) } : {}
125
+ joins: e.query.joins.map((n) => n.on ? { ...n, on: r(n.on) } : n),
126
+ ...e.query.where ? { where: r(e.query.where) } : {}
117
127
  }
118
128
  };
119
129
  default:
120
130
  return e;
121
131
  }
122
132
  }
123
- function j(e, t) {
124
- const n = $(e, (r) => j(r, t));
125
- return n === e ? t(e) : n;
133
+ function $(e, t) {
134
+ const r = j(e, (n) => $(n, t));
135
+ return r === e ? t(e) : r;
126
136
  }
127
- function me(e) {
137
+ function he(e) {
128
138
  return [
129
139
  ...e.where ? [e.where] : [],
130
140
  ...e.joins.flatMap((t) => t.on ? [t.on] : []),
@@ -134,42 +144,42 @@ function me(e) {
134
144
  ...(e.orderBy ?? []).map((t) => t.expression)
135
145
  ];
136
146
  }
137
- function _(e, t, n = (r) => _(r, t)) {
147
+ function F(e, t, r = (n) => F(n, t)) {
138
148
  var a, l;
139
- const r = t, { shared: i } = e;
149
+ const n = t, { shared: i } = e;
140
150
  return {
141
151
  ...e,
142
152
  ...i ? {
143
- shared: i.map((s) => ({ ...s, query: w(s.query, n) }))
153
+ shared: i.map((s) => ({ ...s, query: O(s.query, r) }))
144
154
  } : {},
145
- from: e.from.query ? { ...e.from, query: w(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: w(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) }))
155
+ from: e.from.query ? { ...e.from, query: O(e.from.query, r) } : e.from,
156
+ where: e.where && n(e.where),
157
+ joins: e.joins.map((s) => s.query ? { ...s, on: s.on && n(s.on), query: O(s.query, r) } : { ...s, on: s.on && n(s.on) }),
158
+ select: e.select.map((s) => ({ ...s, expression: n(s.expression) })),
159
+ groupBy: (a = e.groupBy) == null ? void 0 : a.map((s) => ({ ...s, expression: n(s.expression) })),
160
+ having: e.having && n(e.having),
161
+ orderBy: (l = e.orderBy) == null ? void 0 : l.map((s) => ({ ...s, expression: n(s.expression) }))
152
162
  };
153
163
  }
154
- function J(e, t) {
155
- const n = (r) => r.type === "subquery" ? { ...r, query: J(r.query, t) } : $(r, n);
156
- return _(e, (r) => j(n(r), t));
157
- }
158
- function z(e) {
159
- return new Set([e.from, ...e.joins].map(K));
164
+ function z(e, t) {
165
+ const r = (n) => n.type === "subquery" ? { ...n, query: z(n.query, t) } : j(n, r);
166
+ return F(e, (n) => $(r(n), t));
160
167
  }
161
168
  function Z(e) {
162
- return e !== void 0 && (e.type === "exists" || k(e).some(Z));
169
+ return new Set([e.from, ...e.joins].map(Q));
163
170
  }
164
171
  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));
172
+ return e !== void 0 && (e.type === "exists" || v(e).some(q));
167
173
  }
168
- const ge = {
174
+ function ee(e) {
175
+ const t = Z(e.query), r = (n) => n.type === "field" ? [n] : v(n).flatMap(r);
176
+ return r(e.link).filter((n) => n.table !== void 0 && !t.has(n.table));
177
+ }
178
+ const xe = {
169
179
  "date-expr": ["date", "dateTime"],
170
180
  "num-expr": ["integer", "decimal"],
171
181
  "str-expr": ["varchar"]
172
- }, u = { type: "field" }, ee = [
182
+ }, u = { type: "field" }, te = [
173
183
  "YEAR",
174
184
  "QUARTER",
175
185
  "MONTH",
@@ -180,18 +190,20 @@ const ge = {
180
190
  "SECOND",
181
191
  "MILLISECOND"
182
192
  ];
183
- function be(e, t) {
193
+ function ve(e, t) {
184
194
  if (t < e.args.length) return e.args[t];
185
- const n = e.args[e.args.length - 1];
186
- return n != null && n.variadic ? n : void 0;
195
+ const r = e.args[e.args.length - 1];
196
+ return r != null && r.variadic ? r : void 0;
187
197
  }
188
- function he(e) {
189
- return e.args.map((t) => t.default ?? { type: "literal", value: "" });
198
+ function re(e) {
199
+ let t = e.args.length;
200
+ for (; t > 0 && e.args[t - 1].optional && !e.args[t - 1].default; ) t -= 1;
201
+ return e.args.slice(0, t).map((r) => r.default ?? { type: "literal", value: "" });
190
202
  }
191
203
  const T = (e, t = "DAY") => ({
192
204
  label: e,
193
205
  kind: "unit",
194
- choices: ee,
206
+ choices: te,
195
207
  default: { type: "literal", value: t }
196
208
  }), A = {
197
209
  // ---- Aggregate ----
@@ -251,6 +263,57 @@ const T = (e, t = "DAY") => ({
251
263
  }
252
264
  ]
253
265
  },
266
+ // ---- Window (issue 20) ----
267
+ // Each is written with OVER (PARTITION BY … ORDER BY …): see sqlGen.
268
+ // LAG / LEAD's offset is written into the SQL, MySQL taking nothing else.
269
+ LAG: {
270
+ name: "LAG",
271
+ returns: "arg",
272
+ window: !0,
273
+ args: [
274
+ { label: "value", kind: "expr", default: u },
275
+ {
276
+ label: "rows back",
277
+ kind: "fixed-count",
278
+ optional: !0,
279
+ default: { type: "literal", value: 1 }
280
+ },
281
+ { label: "default", kind: "expr", optional: !0 }
282
+ ]
283
+ },
284
+ LEAD: {
285
+ name: "LEAD",
286
+ returns: "arg",
287
+ window: !0,
288
+ args: [
289
+ { label: "value", kind: "expr", default: u },
290
+ {
291
+ label: "rows ahead",
292
+ kind: "fixed-count",
293
+ optional: !0,
294
+ default: { type: "literal", value: 1 }
295
+ },
296
+ { label: "default", kind: "expr", optional: !0 }
297
+ ]
298
+ },
299
+ ROW_NUMBER: {
300
+ name: "ROW_NUMBER",
301
+ returns: "integer",
302
+ window: !0,
303
+ args: []
304
+ },
305
+ RANK: {
306
+ name: "RANK",
307
+ returns: "integer",
308
+ window: !0,
309
+ args: []
310
+ },
311
+ DENSE_RANK: {
312
+ name: "DENSE_RANK",
313
+ returns: "integer",
314
+ window: !0,
315
+ args: []
316
+ },
254
317
  // ---- Date arithmetic ----
255
318
  DATE_ADD: {
256
319
  name: "DATE_ADD",
@@ -577,76 +640,91 @@ const T = (e, t = "DAY") => ({
577
640
  ]
578
641
  }
579
642
  };
580
- function D(e, t = A) {
643
+ function M(e, t = A) {
581
644
  return t[e.toUpperCase()];
582
645
  }
583
- function xe(e, t) {
584
- const n = e.toUpperCase();
585
- return D(e, t) ?? Object.values(t).find((r) => {
646
+ function Te(e, t) {
647
+ const r = e.toUpperCase();
648
+ return M(e, t) ?? Object.values(t).find((n) => {
586
649
  var i;
587
- return (i = r.aliases) == null ? void 0 : i.some((a) => a.toUpperCase() === n);
650
+ return (i = n.aliases) == null ? void 0 : i.some((a) => a.toUpperCase() === r);
588
651
  });
589
652
  }
590
- function te(e = A) {
653
+ function ne(e = A) {
591
654
  return Object.keys(e).sort();
592
655
  }
593
- te(A);
594
- const Te = A;
595
- function ve(e) {
656
+ ne(A);
657
+ const Ee = A;
658
+ function ke(e) {
596
659
  return Object.fromEntries(Object.values(e).map((t) => {
597
- const n = t.name.toUpperCase();
598
- return [n, { ...t, name: n }];
660
+ const r = t.name.toUpperCase();
661
+ return [r, { ...t, name: r }];
599
662
  }));
600
663
  }
601
- function ke(e) {
664
+ function we(e) {
602
665
  return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.aggregate));
603
666
  }
604
- function Ee(e, t) {
605
- return Object.fromEntries(Object.entries(e).filter(([, n]) => !n.dialects || n.dialects.includes(t)));
667
+ function Ae(e, t) {
668
+ return {
669
+ type: "function",
670
+ name: t,
671
+ args: re(e),
672
+ ...e.window && { over: !0 }
673
+ };
674
+ }
675
+ function Re(e) {
676
+ return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.window));
677
+ }
678
+ function Se(e, t) {
679
+ return Object.fromEntries(Object.entries(e).filter(([, r]) => !r.dialects || r.dialects.includes(t)));
606
680
  }
607
681
  function U(e, t) {
608
682
  if (e === t) return !0;
609
683
  if (e instanceof Date && t instanceof Date) return e.getTime() === t.getTime();
610
684
  if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
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]));
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
+ return i.length === a.length && i.every((l) => U(r[l], n[l]));
613
687
  }
614
- function ne() {
688
+ function ae() {
615
689
  const e = globalThis.crypto.getRandomValues(new Uint8Array(12));
616
690
  return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
617
691
  }
618
- function F(e, t) {
619
- var n;
620
- return e.type === "function" && ((n = D(e.name, t)) == null ? void 0 : n.aggregate) === !0;
692
+ function H(e, t) {
693
+ var r;
694
+ return e.type === "function" && ((r = M(e.name, t)) == null ? void 0 : r.aggregate) === !0;
621
695
  }
622
696
  function x(e, t) {
623
- return e ? F(e, t) || k(e).some((n) => x(n, t)) : !1;
697
+ return e ? H(e, t) || v(e).some((r) => x(r, t)) : !1;
624
698
  }
625
- function H(e, t) {
626
- return e.type === "function" && e.name.trim() !== "" && D(e.name, t) === void 0;
699
+ const se = (e) => e.type === "function" && e.over === !0;
700
+ function I(e) {
701
+ return e ? se(e) || v(e).some(I) : !1;
627
702
  }
628
703
  function P(e, t) {
629
- return e ? H(e, t) || k(e).some((n) => P(n, t)) : !1;
630
- }
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)) : F(e, n) || H(e, n) ? !0 : k(e).every((r) => v(r, t, n));
704
+ return e.type === "function" && e.name.trim() !== "" && M(e.name, t) === void 0;
633
705
  }
634
706
  function W(e, t) {
635
- return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((n) => x(n.expression, t));
707
+ return e ? P(e, t) || v(e).some((r) => W(r, t)) : !1;
636
708
  }
637
- function Se(e, t) {
638
- if (W(e, t))
639
- return (e.groupBy ?? []).flatMap(({ expression: n }) => n.type === "field" && n.table && n.column ? [`${n.table}.${n.column}`] : []);
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));
640
711
  }
641
- function re(e, t) {
642
- return x(e.having, t) || [...e.select, ...e.orderBy ?? []].some((n) => x(n.expression, t));
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));
643
714
  }
644
- function Ae(e, t) {
645
- return e.select.some((n) => x(n.expression, t));
715
+ function ye(e, t) {
716
+ if (K(e, t))
717
+ return (e.groupBy ?? []).flatMap(({ expression: r }) => r.type === "field" && r.table && r.column ? [`${r.table}.${r.column}`] : []);
646
718
  }
647
- function Re(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) || P(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])), c = [];
649
- n.forEach((o) => {
719
+ function le(e, t) {
720
+ return x(e.having, t) || [...e.select, ...e.orderBy ?? []].some((r) => x(r.expression, t));
721
+ }
722
+ function Ce(e, t) {
723
+ return e.select.some((r) => x(r.expression, t));
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 = [];
727
+ r.forEach((o) => {
650
728
  if (o.fromSelect === void 0) {
651
729
  c.push(o);
652
730
  return;
@@ -655,89 +733,89 @@ function Re(e, t) {
655
733
  p && c.push(U(o.expression, p.expression) ? o : { ...o, expression: p.expression });
656
734
  });
657
735
  const h = l.filter((o) => !s.has(o.id)).map((o) => ({
658
- id: ne(),
736
+ id: ae(),
659
737
  expression: o.expression,
660
738
  fromSelect: o.id
661
739
  })), g = [...c, ...h];
662
- return g.length === n.length && g.every((o, p) => o === n[p]) ? e : { ...e, groupBy: g };
740
+ return g.length === r.length && g.every((o, p) => o === r[p]) ? e : { ...e, groupBy: g };
663
741
  }
664
- function Ce(e, t) {
665
- const n = (e.groupBy ?? []).map((a) => a.expression), r = e.orderBy ?? [];
666
- if (!W(e, t))
742
+ function Ne(e, t) {
743
+ const r = (e.groupBy ?? []).map((a) => a.expression), n = e.orderBy ?? [];
744
+ if (!K(e, t))
667
745
  return {
668
746
  select: [],
669
747
  selectAll: !1,
670
748
  orderBy: [],
671
749
  having: !1
672
750
  };
673
- const i = (a) => a.filter((l) => !v(l.expression, n, t)).map((l) => l.id);
751
+ const i = (a) => a.filter((l) => !I(l.expression) && !E(l.expression, r, t)).map((l) => l.id);
674
752
  return {
675
753
  select: i(e.select),
676
754
  selectAll: e.select.length === 0,
677
- orderBy: i(r),
678
- having: e.having !== void 0 && !v(e.having, n, t)
755
+ orderBy: i(n),
756
+ having: e.having !== void 0 && !E(e.having, r, t)
679
757
  };
680
758
  }
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));
759
+ const De = { tables: [], relations: [] };
760
+ function Me(e, t, r) {
761
+ if (!t && !r) return e;
762
+ 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));
685
763
  return {
686
- tables: r,
764
+ tables: n,
687
765
  relations: e.relations.filter((a) => i.has(a.fromTable) && i.has(a.toTable))
688
766
  };
689
767
  }
690
- function we(e) {
691
- return [...e.tables].sort((t, n) => t.label.localeCompare(n.label));
768
+ function Ue(e) {
769
+ return [...e.tables].sort((t, r) => t.label.localeCompare(r.label));
692
770
  }
693
- function Ne(e, t = (r) => r.group, n = e) {
694
- const r = /* @__PURE__ */ new Map();
695
- n.forEach((a) => {
771
+ function Ie(e, t = (n) => n.group, r = e) {
772
+ const n = /* @__PURE__ */ new Map();
773
+ r.forEach((a) => {
696
774
  const l = t(a) || void 0;
697
- l !== void 0 && !r.has(l) && r.set(l, []);
775
+ l !== void 0 && !n.has(l) && n.set(l, []);
698
776
  }), e.forEach((a) => {
699
777
  const l = t(a) || void 0;
700
- r.set(l, [...r.get(l) ?? [], a]);
778
+ n.set(l, [...n.get(l) ?? [], a]);
701
779
  });
702
780
  const i = (a) => [...a].sort((l, s) => l.label.localeCompare(s.label));
703
781
  return [
704
- ...[...r].filter(([a]) => a !== void 0),
705
- ...[...r].filter(([a]) => a === void 0)
782
+ ...[...n].filter(([a]) => a !== void 0),
783
+ ...[...n].filter(([a]) => a === void 0)
706
784
  ].filter(([, a]) => a.length > 0).map(([a, l]) => ({ group: a, tables: i(l) }));
707
785
  }
708
786
  function V(e, t) {
709
- return e.tables.find((n) => n.name === t);
787
+ return e.tables.find((r) => r.name === t);
710
788
  }
711
- function N(e, t, n) {
712
- return e.relations.find((r) => r.fromTable === t && r.toTable === n || r.fromTable === n && r.toTable === t);
789
+ function N(e, t, r) {
790
+ return e.relations.find((n) => n.fromTable === t && n.toTable === r || n.fromTable === r && n.toTable === t);
713
791
  }
714
792
  const R = (e, t) => {
715
- var n;
716
- return ((n = V(e, t)) == null ? void 0 : n.passThrough) !== !1;
793
+ var r;
794
+ return ((r = V(e, t)) == null ? void 0 : r.passThrough) !== !1;
717
795
  };
718
- function I(e, t) {
719
- const n = t.filter((r) => R(e, r));
720
- return n.length > 0 ? n : [...t];
721
- }
722
796
  function B(e, t) {
723
- const n = /* @__PURE__ */ new Set();
724
- return t.forEach((r, i) => {
725
- const l = t.slice(0, i).map((c) => ({ earlier: c, r: N(e, c, r) })).find(({ r: c }) => c !== void 0);
797
+ const r = t.filter((n) => R(e, n));
798
+ return r.length > 0 ? r : [...t];
799
+ }
800
+ function L(e, t) {
801
+ const r = /* @__PURE__ */ new Set();
802
+ return t.forEach((n, i) => {
803
+ const l = t.slice(0, i).map((c) => ({ earlier: c, r: N(e, c, n) })).find(({ r: c }) => c !== void 0);
726
804
  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, S = (e, t) => `${t ? "^" : "_"}${e}`;
731
- function G(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() : B(e, t), s = /* @__PURE__ */ new Map();
805
+ (l.r.fromTable === l.earlier && l.r.toTable === n || r.has(l.earlier)) && r.add(n);
806
+ }), r;
807
+ }
808
+ const X = (e, t) => e.fanOuts - t.fanOuts || e.steps - t.steps || e.order - t.order, w = (e, t) => `${t ? "^" : "_"}${e}`;
809
+ function Y(e, t) {
810
+ let r;
811
+ return e.forEach((n, i) => {
812
+ !t.has(i) && (r === void 0 || X(n, e.get(r)) < 0) && (r = i);
813
+ }), r;
814
+ }
815
+ function ie(e, t, r, n = {}) {
816
+ const i = new Set(t), a = new Set(B(e, t)), l = n.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = /* @__PURE__ */ new Map();
739
817
  t.forEach((m, d) => {
740
- const b = S(m, l.has(m));
818
+ const b = w(m, l.has(m));
741
819
  s.has(b) || s.set(b, {
742
820
  table: m,
743
821
  climbed: l.has(m),
@@ -752,22 +830,22 @@ function ae(e, t, n, r = {}) {
752
830
  const d = s.get(m);
753
831
  d.steps > 0 && !R(e, d.table) || e.relations.forEach((b) => {
754
832
  if (b.fromTable !== d.table && b.toTable !== d.table) return;
755
- const E = b.fromTable === d.table, C = E ? b.toTable : b.fromTable;
756
- if (i.has(C) || !E && d.climbed) return;
757
- const O = {
758
- table: C,
759
- climbed: !r.anyShape && (d.climbed || E),
760
- fanOuts: d.fanOuts + (E ? 0 : 1),
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),
761
839
  steps: d.steps + 1,
762
840
  order: h,
763
841
  from: m
764
- }, y = S(C, O.climbed), L = s.get(y);
765
- c.has(y) || L && X(O, { ...L, order: h }) >= 0 || (s.set(y, O), h += 1);
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);
766
844
  });
767
845
  };
768
- let f = G(s, c);
769
- for (; f !== void 0 && s.get(f).table !== n; )
770
- c.add(f), g(f), f = G(s, c);
846
+ let f = Y(s, c);
847
+ for (; f !== void 0 && s.get(f).table !== r; )
848
+ c.add(f), g(f), f = Y(s, c);
771
849
  if (f === void 0) return;
772
850
  const o = [];
773
851
  let p = s.get(f);
@@ -775,40 +853,40 @@ function ae(e, t, n, r = {}) {
775
853
  o.unshift(p.table), p = s.get(p.from);
776
854
  return { start: p.table, tables: o };
777
855
  }
778
- function Me(e, t, n, r = {}) {
856
+ function Be(e, t, r, n = {}) {
779
857
  var i;
780
- return t.includes(n) ? [] : (i = ae(e, t, n, r)) == null ? void 0 : i.tables;
858
+ return t.includes(r) ? [] : (i = ie(e, t, r, n)) == null ? void 0 : i.tables;
781
859
  }
782
- function De(e, t, n = {}) {
783
- const r = /* @__PURE__ */ new Map(), i = (f, o, p) => r.set(f, [
784
- ...r.get(f) ?? [],
860
+ function Le(e, t, r = {}) {
861
+ const n = /* @__PURE__ */ new Map(), i = (f, o, p) => n.set(f, [
862
+ ...n.get(f) ?? [],
785
863
  { table: o, up: p }
786
864
  ]);
787
865
  e.relations.forEach((f) => {
788
866
  i(f.fromTable, f.toTable, !0), i(f.toTable, f.fromTable, !1);
789
867
  });
790
- const { skip: a = /* @__PURE__ */ new Set() } = n, l = n.anyShape ? /* @__PURE__ */ new Set() : B(e, t), s = new Set(t), c = new Set(t), h = I(e, t).map((f) => ({ table: f, climbed: l.has(f) })), g = new Set(h.map((f) => S(f.table, f.climbed)));
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)));
791
869
  for (let f = h.shift(); f !== void 0; f = h.shift()) {
792
870
  const o = f;
793
- (r.get(o.table) ?? []).forEach(({ table: p, up: m }) => {
871
+ (n.get(o.table) ?? []).forEach(({ table: p, up: m }) => {
794
872
  if (s.has(p) || a.has(p) || !m && o.climbed) return;
795
- const d = { table: p, climbed: !n.anyShape && (o.climbed || m) }, b = S(p, d.climbed);
873
+ const d = { table: p, climbed: !r.anyShape && (o.climbed || m) }, b = w(p, d.climbed);
796
874
  g.has(b) || (g.add(b), c.add(p), R(e, p) && h.push(d));
797
875
  });
798
876
  }
799
877
  return c;
800
878
  }
801
- function Ue(e, t, n, r = {}) {
879
+ function Ge(e, t, r, n = {}) {
802
880
  var m;
803
- const { after: i, leftJoined: a = [] } = r, l = r.anyShape ? /* @__PURE__ */ new Set() : B(e, t), s = (d) => {
804
- const b = N(e, d, n);
805
- return b !== void 0 && !(l.has(d) && b.toTable === d && b.fromTable === n);
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);
806
884
  };
807
- let c = R(e, n) ? I(e, t) : t;
885
+ let c = R(e, r) ? B(e, t) : t;
808
886
  i !== void 0 && s(i) && (c = [i]);
809
887
  const h = c.find(s);
810
888
  if (h === void 0) return;
811
- const g = N(e, h, n), 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 = {
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 = {
812
890
  type: "binary",
813
891
  operator: "=",
814
892
  left: { type: "field", table: g.fromTable, column: g.fromColumn },
@@ -816,38 +894,38 @@ function Ue(e, t, n, r = {}) {
816
894
  };
817
895
  return { joinType: o, on: p };
818
896
  }
819
- const Y = (e, t) => `${e}.${t}`;
820
- function se({ type: e, format: t }) {
897
+ const _ = (e, t) => `${e}.${t}`;
898
+ function ue({ type: e, format: t }) {
821
899
  if (t === void 0) return;
822
900
  if (e !== "date" && e !== "dateTime" && e !== "time")
823
901
  return `a format is for a date, date-and-time or time column, not ${e}`;
824
- const n = t.match(/YYYY|MM|DD|HH|mm|ss/g) ?? [];
825
- if (n.length === 0) return `format "${t}" has none of YYYY, MM, DD, HH, mm, ss`;
826
- if (e === "time" && n.some((r) => r === "YYYY" || r === "MM" || r === "DD"))
902
+ const r = t.match(/YYYY|MM|DD|HH|mm|ss/g) ?? [];
903
+ if (r.length === 0) return `format "${t}" has none of YYYY, MM, DD, HH, mm, ss`;
904
+ if (e === "time" && r.some((n) => n === "YYYY" || n === "MM" || n === "DD"))
827
905
  return `a time has no day: format "${t}" can't be written from one`;
828
906
  }
829
- function Ie(e) {
830
- const t = [], n = /* @__PURE__ */ new Map();
907
+ function Ye(e) {
908
+ const t = [], r = /* @__PURE__ */ new Map();
831
909
  e.tables.forEach((a) => {
832
- n.has(a.name) && t.push({
910
+ r.has(a.name) && t.push({
833
911
  kind: "duplicateTable",
834
912
  message: `Table "${a.name}" is declared more than once`
835
- }), n.set(a.name, a);
913
+ }), r.set(a.name, a);
836
914
  const l = /* @__PURE__ */ new Set();
837
915
  a.columns.forEach((s) => {
838
916
  l.has(s.name) && t.push({
839
917
  kind: "duplicateColumn",
840
918
  message: `Column "${a.name}.${s.name}" is declared more than once`
841
919
  }), l.add(s.name);
842
- const c = se(s);
920
+ const c = ue(s);
843
921
  c && t.push({
844
922
  kind: "invalidFormat",
845
923
  message: `Column "${a.name}.${s.name}": ${c}`
846
924
  });
847
925
  });
848
926
  });
849
- const r = (a, l) => {
850
- const s = n.get(a);
927
+ const n = (a, l) => {
928
+ const s = r.get(a);
851
929
  s ? s.columns.some((c) => c.name === l) || t.push({
852
930
  kind: "unknownColumn",
853
931
  message: `Relation references unknown column "${a}.${l}"`
@@ -857,8 +935,8 @@ function Ie(e) {
857
935
  });
858
936
  }, i = /* @__PURE__ */ new Set();
859
937
  return e.relations.forEach((a) => {
860
- r(a.fromTable, a.fromColumn), r(a.toTable, a.toColumn);
861
- const l = Y(a.fromTable, a.fromColumn), s = Y(a.toTable, a.toColumn), c = [l, s].sort().join(" <-> ");
938
+ n(a.fromTable, a.fromColumn), n(a.toTable, a.toColumn);
939
+ const l = _(a.fromTable, a.fromColumn), s = _(a.toTable, a.toColumn), c = [l, s].sort().join(" <-> ");
862
940
  i.has(c) && t.push({
863
941
  kind: "duplicateRelation",
864
942
  message: `Relation ${l} -> ${s} is declared more than once (declare each foreign key once)`
@@ -866,56 +944,60 @@ function Ie(e) {
866
944
  }), t;
867
945
  }
868
946
  export {
869
- ve as A,
870
- W as B,
871
- le as C,
872
- Te as D,
873
- Oe as E,
874
- Ce as F,
875
- be as G,
876
- P as H,
877
- D as I,
878
- me as J,
879
- oe as K,
880
- z as L,
881
- ce as M,
947
+ se as $,
948
+ ke as A,
949
+ K as B,
950
+ oe as C,
951
+ Ee as D,
952
+ De as E,
953
+ Ne as F,
954
+ ve as G,
955
+ I as H,
956
+ W as I,
957
+ M as J,
958
+ he as K,
959
+ pe as L,
960
+ me as M,
882
961
  Z as N,
883
- de as O,
884
- ae as P,
885
- j as Q,
886
- J as R,
887
- ke as S,
888
- te as T,
889
- ge as U,
890
- he as V,
891
- Ne as W,
892
- F as X,
893
- Se as Y,
894
- Ae as Z,
895
- Me as a,
896
- ie as b,
897
- Ee as c,
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,
898
980
  U as d,
899
- _ as e,
900
- ye as f,
901
- w as g,
902
- fe as h,
903
- M as i,
981
+ F as e,
982
+ Me as f,
983
+ O as g,
984
+ de as h,
985
+ D as i,
904
986
  V as j,
905
- ee as k,
906
- ne as l,
907
- $ as m,
908
- ue as n,
909
- pe as o,
910
- xe as p,
911
- Q as q,
912
- De as r,
913
- Ue as s,
914
- K as t,
987
+ te as k,
988
+ ae as l,
989
+ 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,
915
997
  x as u,
916
- Ie as v,
917
- re as w,
918
- Re as x,
919
- k as y,
920
- we as z
998
+ Ye as v,
999
+ le as w,
1000
+ Oe as x,
1001
+ v as y,
1002
+ Ue as z
921
1003
  };