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