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