@nongt/visql-core 0.10.1 → 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/dist/core.js +137 -119
- package/dist/explain.js +3 -3
- package/dist/fixtures.js +1 -1
- package/dist/issueLocation-Yn71qJyP.js +1141 -0
- package/dist/{params-DkVFbMQn.js → params-DVkfcD6D.js} +245 -229
- package/dist/{schema-CgL10bid.js → schema-CzKt6cN2.js} +230 -152
- package/dist/sql-import.js +855 -821
- package/dist/{sqlGen-C1kZwvWI.js → sqlGen-BoJXaULd.js} +331 -309
- package/dist/types/core/ast.d.ts +9 -1
- package/dist/types/core/functionRegistry.d.ts +15 -2
- package/dist/types/core/i18n/defaultMessages.d.ts +16 -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/storedQuery.d.ts +1 -1
- package/dist/types/sqlImport/syntax.d.ts +11 -2
- package/package.json +1 -1
- package/dist/issueLocation-BlQ280IE.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":
|
|
@@ -120,11 +126,11 @@ function $(e, t) {
|
|
|
120
126
|
return e;
|
|
121
127
|
}
|
|
122
128
|
}
|
|
123
|
-
function
|
|
124
|
-
const n =
|
|
129
|
+
function $(e, t) {
|
|
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,18 +186,20 @@ 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 ----
|
|
@@ -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,41 +681,45 @@ 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
699
|
function P(e, t) {
|
|
629
|
-
return e
|
|
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));
|
|
700
|
+
return e.type === "function" && e.name.trim() !== "" && M(e.name, t) === void 0;
|
|
633
701
|
}
|
|
634
702
|
function W(e, t) {
|
|
703
|
+
return e ? P(e, t) || v(e).some((n) => W(n, t)) : !1;
|
|
704
|
+
}
|
|
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);
|
|
@@ -655,31 +729,31 @@ function Re(e, t) {
|
|
|
655
729
|
p && c.push(U(o.expression, p.expression) ? o : { ...o, expression: p.expression });
|
|
656
730
|
});
|
|
657
731
|
const h = l.filter((o) => !s.has(o.id)).map((o) => ({
|
|
658
|
-
id:
|
|
732
|
+
id: ae(),
|
|
659
733
|
expression: o.expression,
|
|
660
734
|
fromSelect: o.id
|
|
661
735
|
})), g = [...c, ...h];
|
|
662
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;
|
|
@@ -715,11 +789,11 @@ const R = (e, t) => {
|
|
|
715
789
|
var n;
|
|
716
790
|
return ((n = V(e, t)) == null ? void 0 : n.passThrough) !== !1;
|
|
717
791
|
};
|
|
718
|
-
function
|
|
792
|
+
function B(e, t) {
|
|
719
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
799
|
const l = t.slice(0, i).map((c) => ({ earlier: c, r: N(e, c, r) })).find(({ r: c }) => c !== void 0);
|
|
@@ -727,17 +801,17 @@ function B(e, t) {
|
|
|
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(
|
|
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();
|
|
739
813
|
t.forEach((m, d) => {
|
|
740
|
-
const b =
|
|
814
|
+
const b = w(m, l.has(m));
|
|
741
815
|
s.has(b) || s.set(b, {
|
|
742
816
|
table: m,
|
|
743
817
|
climbed: l.has(m),
|
|
@@ -752,22 +826,22 @@ function ae(e, t, n, r = {}) {
|
|
|
752
826
|
const d = s.get(m);
|
|
753
827
|
d.steps > 0 && !R(e, d.table) || e.relations.forEach((b) => {
|
|
754
828
|
if (b.fromTable !== d.table && b.toTable !== d.table) return;
|
|
755
|
-
const
|
|
756
|
-
if (i.has(
|
|
757
|
-
const
|
|
758
|
-
table:
|
|
759
|
-
climbed: !r.anyShape && (d.climbed ||
|
|
760
|
-
fanOuts: d.fanOuts + (
|
|
829
|
+
const k = b.fromTable === d.table, S = k ? b.toTable : b.fromTable;
|
|
830
|
+
if (i.has(S) || !k && d.climbed) return;
|
|
831
|
+
const y = {
|
|
832
|
+
table: S,
|
|
833
|
+
climbed: !r.anyShape && (d.climbed || k),
|
|
834
|
+
fanOuts: d.fanOuts + (k ? 0 : 1),
|
|
761
835
|
steps: d.steps + 1,
|
|
762
836
|
order: h,
|
|
763
837
|
from: m
|
|
764
|
-
},
|
|
765
|
-
c.has(
|
|
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 f =
|
|
842
|
+
let f = Y(s, c);
|
|
769
843
|
for (; f !== void 0 && s.get(f).table !== n; )
|
|
770
|
-
c.add(f), g(f), f =
|
|
844
|
+
c.add(f), g(f), f = Y(s, c);
|
|
771
845
|
if (f === void 0) return;
|
|
772
846
|
const o = [];
|
|
773
847
|
let p = s.get(f);
|
|
@@ -775,11 +849,11 @@ function ae(e, t, n, r = {}) {
|
|
|
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
|
|
856
|
+
function Le(e, t, n = {}) {
|
|
783
857
|
const r = /* @__PURE__ */ new Map(), i = (f, o, p) => r.set(f, [
|
|
784
858
|
...r.get(f) ?? [],
|
|
785
859
|
{ table: o, up: p }
|
|
@@ -787,24 +861,24 @@ function De(e, t, n = {}) {
|
|
|
787
861
|
e.relations.forEach((f) => {
|
|
788
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() :
|
|
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)));
|
|
791
865
|
for (let f = h.shift(); f !== void 0; f = h.shift()) {
|
|
792
866
|
const o = f;
|
|
793
867
|
(r.get(o.table) ?? []).forEach(({ table: p, up: m }) => {
|
|
794
868
|
if (s.has(p) || a.has(p) || !m && o.climbed) return;
|
|
795
|
-
const d = { table: p, climbed: !n.anyShape && (o.climbed || m) }, b =
|
|
869
|
+
const d = { table: p, climbed: !n.anyShape && (o.climbed || m) }, b = w(p, d.climbed);
|
|
796
870
|
g.has(b) || (g.add(b), c.add(p), R(e, p) && h.push(d));
|
|
797
871
|
});
|
|
798
872
|
}
|
|
799
873
|
return c;
|
|
800
874
|
}
|
|
801
|
-
function
|
|
875
|
+
function Ge(e, t, n, r = {}) {
|
|
802
876
|
var m;
|
|
803
|
-
const { after: i, leftJoined: a = [] } = r, l = r.anyShape ? /* @__PURE__ */ new Set() :
|
|
877
|
+
const { after: i, leftJoined: a = [] } = r, l = r.anyShape ? /* @__PURE__ */ new Set() : L(e, t), s = (d) => {
|
|
804
878
|
const b = N(e, d, n);
|
|
805
879
|
return b !== void 0 && !(l.has(d) && b.toTable === d && b.fromTable === n);
|
|
806
880
|
};
|
|
807
|
-
let c = R(e, n) ?
|
|
881
|
+
let c = R(e, n) ? B(e, t) : t;
|
|
808
882
|
i !== void 0 && s(i) && (c = [i]);
|
|
809
883
|
const h = c.find(s);
|
|
810
884
|
if (h === void 0) return;
|
|
@@ -816,8 +890,8 @@ function Ue(e, t, n, r = {}) {
|
|
|
816
890
|
};
|
|
817
891
|
return { joinType: o, on: p };
|
|
818
892
|
}
|
|
819
|
-
const
|
|
820
|
-
function
|
|
893
|
+
const _ = (e, t) => `${e}.${t}`;
|
|
894
|
+
function ue({ type: e, format: t }) {
|
|
821
895
|
if (t === void 0) return;
|
|
822
896
|
if (e !== "date" && e !== "dateTime" && e !== "time")
|
|
823
897
|
return `a format is for a date, date-and-time or time column, not ${e}`;
|
|
@@ -826,7 +900,7 @@ function se({ type: e, format: t }) {
|
|
|
826
900
|
if (e === "time" && n.some((r) => r === "YYYY" || r === "MM" || r === "DD"))
|
|
827
901
|
return `a time has no day: format "${t}" can't be written from one`;
|
|
828
902
|
}
|
|
829
|
-
function
|
|
903
|
+
function Ye(e) {
|
|
830
904
|
const t = [], n = /* @__PURE__ */ new Map();
|
|
831
905
|
e.tables.forEach((a) => {
|
|
832
906
|
n.has(a.name) && t.push({
|
|
@@ -839,7 +913,7 @@ function Ie(e) {
|
|
|
839
913
|
kind: "duplicateColumn",
|
|
840
914
|
message: `Column "${a.name}.${s.name}" is declared more than once`
|
|
841
915
|
}), l.add(s.name);
|
|
842
|
-
const c =
|
|
916
|
+
const c = ue(s);
|
|
843
917
|
c && t.push({
|
|
844
918
|
kind: "invalidFormat",
|
|
845
919
|
message: `Column "${a.name}.${s.name}": ${c}`
|
|
@@ -858,7 +932,7 @@ function Ie(e) {
|
|
|
858
932
|
}, i = /* @__PURE__ */ new Set();
|
|
859
933
|
return e.relations.forEach((a) => {
|
|
860
934
|
r(a.fromTable, a.fromColumn), r(a.toTable, a.toColumn);
|
|
861
|
-
const l =
|
|
935
|
+
const l = _(a.fromTable, a.fromColumn), s = _(a.toTable, a.toColumn), c = [l, s].sort().join(" <-> ");
|
|
862
936
|
i.has(c) && t.push({
|
|
863
937
|
kind: "duplicateRelation",
|
|
864
938
|
message: `Relation ${l} -> ${s} is declared more than once (declare each foreign key once)`
|
|
@@ -866,56 +940,60 @@ function Ie(e) {
|
|
|
866
940
|
}), t;
|
|
867
941
|
}
|
|
868
942
|
export {
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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,
|
|
882
957
|
Z as N,
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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,
|
|
898
976
|
U as d,
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
977
|
+
F as e,
|
|
978
|
+
Me as f,
|
|
979
|
+
O as g,
|
|
980
|
+
de as h,
|
|
981
|
+
D as i,
|
|
904
982
|
V as j,
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
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,
|
|
915
993
|
x as u,
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
994
|
+
Ye as v,
|
|
995
|
+
le as w,
|
|
996
|
+
Oe as x,
|
|
997
|
+
v as y,
|
|
998
|
+
Ue as z
|
|
921
999
|
};
|