@nongt/visql 0.9.0 → 0.10.1
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/{PipelineEditor-C10lng6j.js → PipelineEditor-CGTZGbmf.js} +310 -317
- package/dist/core.js +83 -80
- package/dist/explain.js +325 -134
- package/dist/index.js +91 -88
- package/dist/{issueLocation-BOSdd1JX.js → issueLocation-BlQ280IE.js} +176 -174
- package/dist/mui.js +1 -1
- package/dist/{params-MMOdKWnW.js → params-DkVFbMQn.js} +501 -495
- package/dist/{schema-dP_ISylQ.js → schema-CgL10bid.js} +333 -295
- package/dist/sql-import.js +1 -1
- package/dist/{sqlGen-B7-2-i9V.js → sqlGen-C1kZwvWI.js} +56 -56
- package/dist/types/core/existsMenu.d.ts +4 -3
- package/dist/types/core/pipelineFlow.d.ts +1 -1
- package/dist/types/core/schema.d.ts +56 -22
- package/dist/types/core-api.d.ts +1 -1
- package/dist/types/explain/explainQuery.d.ts +12 -6
- package/dist/types/explain/mySqlPlan.d.ts +4 -0
- package/dist/types/explain/planPlaces.d.ts +27 -0
- package/dist/types/explain/postgresPlan.d.ts +2 -10
- package/dist/types/explain/sqlServerPlan.d.ts +4 -0
- package/dist/types/explain/xml.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function k(e) {
|
|
2
2
|
switch (e.type) {
|
|
3
3
|
case "function":
|
|
4
4
|
return e.orderBy ? [...e.args, ...e.orderBy.map((t) => t.expression)] : e.args;
|
|
@@ -31,100 +31,100 @@ function x(e) {
|
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
function
|
|
34
|
+
const le = ["inner", "left", "right", "full", "cross"];
|
|
35
|
+
function M(e) {
|
|
36
36
|
return "union" in e;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
38
|
+
function ie(e) {
|
|
39
|
+
return M(e) ? e.union : [e];
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
41
|
+
function ue(e) {
|
|
42
|
+
return M(e) ? e.union[0] : e;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
if (!
|
|
46
|
-
const
|
|
47
|
-
return
|
|
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 };
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function oe(e, t) {
|
|
50
50
|
if (!e.shared) return e;
|
|
51
|
-
let
|
|
52
|
-
const
|
|
53
|
-
const a = t(
|
|
54
|
-
return a ===
|
|
51
|
+
let n = !1;
|
|
52
|
+
const r = e.shared.map((i) => {
|
|
53
|
+
const a = t(i.query, i);
|
|
54
|
+
return a === i.query ? i : (n = !0, { ...i, query: a });
|
|
55
55
|
});
|
|
56
|
-
return
|
|
56
|
+
return n ? { ...e, shared: r } : e;
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function fe(e) {
|
|
59
59
|
return "from" in e;
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
function
|
|
61
|
+
const ce = 63;
|
|
62
|
+
function K(e) {
|
|
63
63
|
return e.alias || e.table || "";
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function pe(e) {
|
|
66
66
|
return e.alias ? e.alias : e.expression.type === "field" ? e.expression.column : void 0;
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function Q(e) {
|
|
69
69
|
return [e.from, ...e.joins];
|
|
70
70
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
71
|
+
function de(e) {
|
|
72
|
+
return Q(e).flatMap((t) => t.table === void 0 ? [] : [t.table]);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const
|
|
74
|
+
function $(e, t) {
|
|
75
|
+
const n = t;
|
|
76
76
|
switch (e.type) {
|
|
77
77
|
case "function":
|
|
78
78
|
return {
|
|
79
79
|
...e,
|
|
80
|
-
args: e.args.map(
|
|
81
|
-
...e.orderBy ? { orderBy: e.orderBy.map((
|
|
80
|
+
args: e.args.map(n),
|
|
81
|
+
...e.orderBy ? { orderBy: e.orderBy.map((r) => ({ ...r, expression: n(r.expression) })) } : {}
|
|
82
82
|
};
|
|
83
83
|
case "binary":
|
|
84
84
|
return {
|
|
85
85
|
...e,
|
|
86
|
-
left:
|
|
87
|
-
...e.right ? { right:
|
|
86
|
+
left: n(e.left),
|
|
87
|
+
...e.right ? { right: n(e.right) } : {}
|
|
88
88
|
};
|
|
89
89
|
case "logical":
|
|
90
|
-
return { ...e, operands: e.operands.map(
|
|
90
|
+
return { ...e, operands: e.operands.map(n) };
|
|
91
91
|
case "list":
|
|
92
|
-
return { ...e, items: e.items.map(
|
|
92
|
+
return { ...e, items: e.items.map(n) };
|
|
93
93
|
case "not":
|
|
94
|
-
return { ...e, operand:
|
|
94
|
+
return { ...e, operand: n(e.operand) };
|
|
95
95
|
case "if":
|
|
96
96
|
return {
|
|
97
97
|
...e,
|
|
98
|
-
condition: e.condition &&
|
|
99
|
-
then: e.then &&
|
|
100
|
-
else: e.else &&
|
|
98
|
+
condition: e.condition && n(e.condition),
|
|
99
|
+
then: e.then && n(e.then),
|
|
100
|
+
else: e.else && n(e.else)
|
|
101
101
|
};
|
|
102
102
|
case "case":
|
|
103
103
|
return {
|
|
104
104
|
...e,
|
|
105
|
-
subject: e.subject &&
|
|
106
|
-
branches: e.branches.map((
|
|
107
|
-
else: e.else &&
|
|
105
|
+
subject: e.subject && n(e.subject),
|
|
106
|
+
branches: e.branches.map((r) => ({ when: n(r.when), then: n(r.then) })),
|
|
107
|
+
else: e.else && n(e.else)
|
|
108
108
|
};
|
|
109
109
|
case "exists":
|
|
110
110
|
return {
|
|
111
111
|
...e,
|
|
112
|
-
link:
|
|
112
|
+
link: n(e.link),
|
|
113
113
|
query: {
|
|
114
114
|
...e.query,
|
|
115
|
-
joins: e.query.joins.map((
|
|
116
|
-
...e.query.where ? { where:
|
|
115
|
+
joins: e.query.joins.map((r) => r.on ? { ...r, on: n(r.on) } : r),
|
|
116
|
+
...e.query.where ? { where: n(e.query.where) } : {}
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
default:
|
|
120
120
|
return e;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
return
|
|
123
|
+
function j(e, t) {
|
|
124
|
+
const n = $(e, (r) => j(r, t));
|
|
125
|
+
return n === e ? t(e) : n;
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function me(e) {
|
|
128
128
|
return [
|
|
129
129
|
...e.where ? [e.where] : [],
|
|
130
130
|
...e.joins.flatMap((t) => t.on ? [t.on] : []),
|
|
@@ -134,42 +134,42 @@ function ae(e) {
|
|
|
134
134
|
...(e.orderBy ?? []).map((t) => t.expression)
|
|
135
135
|
];
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
var a,
|
|
139
|
-
const
|
|
137
|
+
function _(e, t, n = (r) => _(r, t)) {
|
|
138
|
+
var a, l;
|
|
139
|
+
const r = t, { shared: i } = e;
|
|
140
140
|
return {
|
|
141
141
|
...e,
|
|
142
|
-
...
|
|
143
|
-
shared:
|
|
142
|
+
...i ? {
|
|
143
|
+
shared: i.map((s) => ({ ...s, query: w(s.query, n) }))
|
|
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: (a = e.groupBy) == null ? void 0 : a.map((
|
|
150
|
-
having: e.having &&
|
|
151
|
-
orderBy: (
|
|
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) }))
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
|
-
function
|
|
155
|
-
const
|
|
156
|
-
return
|
|
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
157
|
}
|
|
158
|
-
function
|
|
159
|
-
return new Set([e.from, ...e.joins].map(
|
|
158
|
+
function z(e) {
|
|
159
|
+
return new Set([e.from, ...e.joins].map(K));
|
|
160
160
|
}
|
|
161
|
-
function
|
|
162
|
-
return e !== void 0 && (e.type === "exists" ||
|
|
161
|
+
function Z(e) {
|
|
162
|
+
return e !== void 0 && (e.type === "exists" || k(e).some(Z));
|
|
163
163
|
}
|
|
164
|
-
function
|
|
165
|
-
const t =
|
|
166
|
-
return
|
|
164
|
+
function q(e) {
|
|
165
|
+
const t = z(e.query), n = (r) => r.type === "field" ? [r] : k(r).flatMap(n);
|
|
166
|
+
return n(e.link).filter((r) => r.table !== void 0 && !t.has(r.table));
|
|
167
167
|
}
|
|
168
|
-
const
|
|
168
|
+
const ge = {
|
|
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" }, ee = [
|
|
173
173
|
"YEAR",
|
|
174
174
|
"QUARTER",
|
|
175
175
|
"MONTH",
|
|
@@ -180,20 +180,20 @@ const se = {
|
|
|
180
180
|
"SECOND",
|
|
181
181
|
"MILLISECOND"
|
|
182
182
|
];
|
|
183
|
-
function
|
|
183
|
+
function be(e, t) {
|
|
184
184
|
if (t < e.args.length) return e.args[t];
|
|
185
|
-
const
|
|
186
|
-
return
|
|
185
|
+
const n = e.args[e.args.length - 1];
|
|
186
|
+
return n != null && n.variadic ? n : void 0;
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function he(e) {
|
|
189
189
|
return e.args.map((t) => t.default ?? { type: "literal", value: "" });
|
|
190
190
|
}
|
|
191
|
-
const
|
|
191
|
+
const T = (e, t = "DAY") => ({
|
|
192
192
|
label: e,
|
|
193
193
|
kind: "unit",
|
|
194
|
-
choices:
|
|
194
|
+
choices: ee,
|
|
195
195
|
default: { type: "literal", value: t }
|
|
196
|
-
}),
|
|
196
|
+
}), A = {
|
|
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 b = (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
|
+
T("unit")
|
|
262
262
|
]
|
|
263
263
|
},
|
|
264
264
|
DATE_SUB: {
|
|
@@ -267,7 +267,7 @@ const b = (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
|
+
T("unit")
|
|
271
271
|
]
|
|
272
272
|
},
|
|
273
273
|
// ---- Date diff ----
|
|
@@ -277,7 +277,7 @@ const b = (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
|
+
T("unit")
|
|
281
281
|
]
|
|
282
282
|
},
|
|
283
283
|
// ---- Date extract / trunc ----
|
|
@@ -286,7 +286,7 @@ const b = (e, t = "DAY") => ({
|
|
|
286
286
|
returns: "integer",
|
|
287
287
|
args: [
|
|
288
288
|
{ label: "date", kind: "date-expr", default: u },
|
|
289
|
-
|
|
289
|
+
T("unit", "YEAR")
|
|
290
290
|
]
|
|
291
291
|
},
|
|
292
292
|
DATE_TRUNC: {
|
|
@@ -294,7 +294,7 @@ const b = (e, t = "DAY") => ({
|
|
|
294
294
|
returns: "arg",
|
|
295
295
|
args: [
|
|
296
296
|
{ label: "date", kind: "date-expr", default: u },
|
|
297
|
-
|
|
297
|
+
T("unit")
|
|
298
298
|
]
|
|
299
299
|
},
|
|
300
300
|
// ---- Type cast ----
|
|
@@ -577,307 +577,345 @@ const b = (e, t = "DAY") => ({
|
|
|
577
577
|
]
|
|
578
578
|
}
|
|
579
579
|
};
|
|
580
|
-
function
|
|
580
|
+
function D(e, t = A) {
|
|
581
581
|
return t[e.toUpperCase()];
|
|
582
582
|
}
|
|
583
|
-
function
|
|
584
|
-
const
|
|
585
|
-
return
|
|
586
|
-
var
|
|
587
|
-
return (
|
|
583
|
+
function xe(e, t) {
|
|
584
|
+
const n = e.toUpperCase();
|
|
585
|
+
return D(e, t) ?? Object.values(t).find((r) => {
|
|
586
|
+
var i;
|
|
587
|
+
return (i = r.aliases) == null ? void 0 : i.some((a) => a.toUpperCase() === n);
|
|
588
588
|
});
|
|
589
589
|
}
|
|
590
|
-
function
|
|
590
|
+
function te(e = A) {
|
|
591
591
|
return Object.keys(e).sort();
|
|
592
592
|
}
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
function
|
|
593
|
+
te(A);
|
|
594
|
+
const Te = A;
|
|
595
|
+
function ve(e) {
|
|
596
596
|
return Object.fromEntries(Object.values(e).map((t) => {
|
|
597
|
-
const
|
|
598
|
-
return [
|
|
597
|
+
const n = t.name.toUpperCase();
|
|
598
|
+
return [n, { ...t, name: n }];
|
|
599
599
|
}));
|
|
600
600
|
}
|
|
601
|
-
function
|
|
601
|
+
function ke(e) {
|
|
602
602
|
return Object.fromEntries(Object.entries(e).filter(([, t]) => !t.aggregate));
|
|
603
603
|
}
|
|
604
|
-
function
|
|
605
|
-
return Object.fromEntries(Object.entries(e).filter(([,
|
|
604
|
+
function Ee(e, t) {
|
|
605
|
+
return Object.fromEntries(Object.entries(e).filter(([, n]) => !n.dialects || n.dialects.includes(t)));
|
|
606
606
|
}
|
|
607
|
-
function
|
|
607
|
+
function U(e, t) {
|
|
608
608
|
if (e === t) return !0;
|
|
609
609
|
if (e instanceof Date && t instanceof Date) return e.getTime() === t.getTime();
|
|
610
610
|
if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
|
|
611
|
-
const
|
|
612
|
-
return
|
|
611
|
+
const n = e, r = t, i = Object.keys(n).filter((l) => n[l] !== void 0), a = Object.keys(r).filter((l) => r[l] !== void 0);
|
|
612
|
+
return i.length === a.length && i.every((l) => U(n[l], r[l]));
|
|
613
613
|
}
|
|
614
|
-
function
|
|
614
|
+
function ne() {
|
|
615
615
|
const e = globalThis.crypto.getRandomValues(new Uint8Array(12));
|
|
616
616
|
return Array.from(e, (t) => t.toString(16).padStart(2, "0")).join("");
|
|
617
617
|
}
|
|
618
|
-
function
|
|
619
|
-
var
|
|
620
|
-
return e.type === "function" && ((
|
|
618
|
+
function F(e, t) {
|
|
619
|
+
var n;
|
|
620
|
+
return e.type === "function" && ((n = D(e.name, t)) == null ? void 0 : n.aggregate) === !0;
|
|
621
621
|
}
|
|
622
|
-
function
|
|
623
|
-
return e ?
|
|
622
|
+
function x(e, t) {
|
|
623
|
+
return e ? F(e, t) || k(e).some((n) => x(n, t)) : !1;
|
|
624
624
|
}
|
|
625
|
-
function
|
|
626
|
-
return e.type === "function" && e.name.trim() !== "" &&
|
|
625
|
+
function H(e, t) {
|
|
626
|
+
return e.type === "function" && e.name.trim() !== "" && D(e.name, t) === void 0;
|
|
627
627
|
}
|
|
628
|
-
function
|
|
629
|
-
return e ?
|
|
628
|
+
function P(e, t) {
|
|
629
|
+
return e ? H(e, t) || k(e).some((n) => P(n, t)) : !1;
|
|
630
630
|
}
|
|
631
|
-
function
|
|
632
|
-
return t.some((
|
|
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));
|
|
633
633
|
}
|
|
634
|
-
function
|
|
635
|
-
return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((
|
|
634
|
+
function W(e, t) {
|
|
635
|
+
return (e.groupBy ?? []).length > 0 || e.having !== void 0 || [...e.select, ...e.orderBy ?? []].some((n) => x(n.expression, t));
|
|
636
636
|
}
|
|
637
|
-
function
|
|
638
|
-
if (
|
|
639
|
-
return (e.groupBy ?? []).flatMap(({ expression:
|
|
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}`] : []);
|
|
640
640
|
}
|
|
641
|
-
function
|
|
642
|
-
return
|
|
641
|
+
function re(e, t) {
|
|
642
|
+
return x(e.having, t) || [...e.select, ...e.orderBy ?? []].some((n) => x(n.expression, t));
|
|
643
643
|
}
|
|
644
|
-
function
|
|
645
|
-
return e.select.some((
|
|
644
|
+
function Ae(e, t) {
|
|
645
|
+
return e.select.some((n) => x(n.expression, t));
|
|
646
646
|
}
|
|
647
|
-
function
|
|
648
|
-
const
|
|
649
|
-
|
|
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) => {
|
|
650
650
|
if (o.fromSelect === void 0) {
|
|
651
651
|
c.push(o);
|
|
652
652
|
return;
|
|
653
653
|
}
|
|
654
|
-
const
|
|
655
|
-
|
|
654
|
+
const p = l.find((m) => m.id === o.fromSelect);
|
|
655
|
+
p && c.push(U(o.expression, p.expression) ? o : { ...o, expression: p.expression });
|
|
656
656
|
});
|
|
657
|
-
const
|
|
658
|
-
id:
|
|
657
|
+
const h = l.filter((o) => !s.has(o.id)).map((o) => ({
|
|
658
|
+
id: ne(),
|
|
659
659
|
expression: o.expression,
|
|
660
660
|
fromSelect: o.id
|
|
661
|
-
})),
|
|
662
|
-
return
|
|
661
|
+
})), g = [...c, ...h];
|
|
662
|
+
return g.length === n.length && g.every((o, p) => o === n[p]) ? e : { ...e, groupBy: g };
|
|
663
663
|
}
|
|
664
|
-
function
|
|
665
|
-
const
|
|
666
|
-
if (!
|
|
664
|
+
function Ce(e, t) {
|
|
665
|
+
const n = (e.groupBy ?? []).map((a) => a.expression), r = e.orderBy ?? [];
|
|
666
|
+
if (!W(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 i = (a) => a.filter((l) => !v(l.expression, n, t)).map((l) => l.id);
|
|
674
674
|
return {
|
|
675
|
-
select:
|
|
675
|
+
select: i(e.select),
|
|
676
676
|
selectAll: e.select.length === 0,
|
|
677
|
-
orderBy:
|
|
678
|
-
having: e.having !== void 0 && !
|
|
677
|
+
orderBy: i(r),
|
|
678
|
+
having: e.having !== void 0 && !v(e.having, n, t)
|
|
679
679
|
};
|
|
680
680
|
}
|
|
681
|
-
const
|
|
682
|
-
function
|
|
683
|
-
if (!t && !
|
|
684
|
-
const
|
|
681
|
+
const Oe = { tables: [], relations: [] };
|
|
682
|
+
function ye(e, t, n) {
|
|
683
|
+
if (!t && !n) return e;
|
|
684
|
+
const r = e.tables.filter((a) => !t || t(a)).map((a) => n ? { ...a, columns: a.columns.filter((l) => n(a, l)) } : a), i = new Set(r.map((a) => a.name));
|
|
685
685
|
return {
|
|
686
|
-
tables:
|
|
687
|
-
relations: e.relations.filter((a) =>
|
|
686
|
+
tables: r,
|
|
687
|
+
relations: e.relations.filter((a) => i.has(a.fromTable) && i.has(a.toTable))
|
|
688
688
|
};
|
|
689
689
|
}
|
|
690
|
-
function
|
|
691
|
-
return [...e.tables].sort((t,
|
|
690
|
+
function we(e) {
|
|
691
|
+
return [...e.tables].sort((t, n) => t.label.localeCompare(n.label));
|
|
692
692
|
}
|
|
693
|
-
function
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
const
|
|
697
|
-
|
|
693
|
+
function Ne(e, t = (r) => r.group, n = e) {
|
|
694
|
+
const r = /* @__PURE__ */ new Map();
|
|
695
|
+
n.forEach((a) => {
|
|
696
|
+
const l = t(a) || void 0;
|
|
697
|
+
l !== void 0 && !r.has(l) && r.set(l, []);
|
|
698
698
|
}), e.forEach((a) => {
|
|
699
|
-
const
|
|
700
|
-
|
|
699
|
+
const l = t(a) || void 0;
|
|
700
|
+
r.set(l, [...r.get(l) ?? [], a]);
|
|
701
701
|
});
|
|
702
|
-
const
|
|
702
|
+
const i = (a) => [...a].sort((l, s) => l.label.localeCompare(s.label));
|
|
703
703
|
return [
|
|
704
|
-
...[...
|
|
705
|
-
...[...
|
|
706
|
-
].filter(([, a]) => a.length > 0).map(([a,
|
|
704
|
+
...[...r].filter(([a]) => a !== void 0),
|
|
705
|
+
...[...r].filter(([a]) => a === void 0)
|
|
706
|
+
].filter(([, a]) => a.length > 0).map(([a, l]) => ({ group: a, tables: i(l) }));
|
|
707
707
|
}
|
|
708
|
-
function
|
|
709
|
-
return e.tables.find((
|
|
708
|
+
function V(e, t) {
|
|
709
|
+
return e.tables.find((n) => n.name === t);
|
|
710
710
|
}
|
|
711
|
-
function
|
|
712
|
-
return e.relations.find((
|
|
711
|
+
function N(e, t, n) {
|
|
712
|
+
return e.relations.find((r) => r.fromTable === t && r.toTable === n || r.fromTable === n && r.toTable === t);
|
|
713
713
|
}
|
|
714
|
-
const
|
|
715
|
-
var
|
|
716
|
-
return ((
|
|
714
|
+
const R = (e, t) => {
|
|
715
|
+
var n;
|
|
716
|
+
return ((n = V(e, t)) == null ? void 0 : n.passThrough) !== !1;
|
|
717
717
|
};
|
|
718
|
-
function
|
|
719
|
-
const
|
|
720
|
-
return
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
!
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
718
|
+
function I(e, t) {
|
|
719
|
+
const n = t.filter((r) => R(e, r));
|
|
720
|
+
return n.length > 0 ? n : [...t];
|
|
721
|
+
}
|
|
722
|
+
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);
|
|
726
|
+
if (!l) return;
|
|
727
|
+
(l.r.fromTable === l.earlier && l.r.toTable === r || n.has(l.earlier)) && n.add(r);
|
|
728
|
+
}), n;
|
|
729
|
+
}
|
|
730
|
+
const X = (e, t) => e.fanOuts - t.fanOuts || e.steps - t.steps || e.order - t.order, 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();
|
|
739
|
+
t.forEach((m, d) => {
|
|
740
|
+
const b = S(m, l.has(m));
|
|
741
|
+
s.has(b) || s.set(b, {
|
|
742
|
+
table: m,
|
|
743
|
+
climbed: l.has(m),
|
|
744
|
+
fanOuts: 0,
|
|
745
|
+
steps: 0,
|
|
746
|
+
order: d
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
const c = new Set([...s].filter(([, m]) => !a.has(m.table)).map(([m]) => m));
|
|
750
|
+
let h = t.length;
|
|
751
|
+
const g = (m) => {
|
|
752
|
+
const d = s.get(m);
|
|
753
|
+
d.steps > 0 && !R(e, d.table) || e.relations.forEach((b) => {
|
|
754
|
+
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),
|
|
761
|
+
steps: d.steps + 1,
|
|
762
|
+
order: h,
|
|
763
|
+
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);
|
|
748
766
|
});
|
|
749
767
|
};
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
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);
|
|
771
|
+
if (f === void 0) return;
|
|
772
|
+
const o = [];
|
|
773
|
+
let p = s.get(f);
|
|
774
|
+
for (; p.from !== void 0; )
|
|
775
|
+
o.unshift(p.table), p = s.get(p.from);
|
|
776
|
+
return { start: p.table, tables: o };
|
|
777
|
+
}
|
|
778
|
+
function Me(e, t, n, r = {}) {
|
|
779
|
+
var i;
|
|
780
|
+
return t.includes(n) ? [] : (i = ae(e, t, n, r)) == null ? void 0 : i.tables;
|
|
781
|
+
}
|
|
782
|
+
function De(e, t, n = {}) {
|
|
783
|
+
const r = /* @__PURE__ */ new Map(), i = (f, o, p) => r.set(f, [
|
|
784
|
+
...r.get(f) ?? [],
|
|
785
|
+
{ table: o, up: p }
|
|
786
|
+
]);
|
|
787
|
+
e.relations.forEach((f) => {
|
|
788
|
+
i(f.fromTable, f.toTable, !0), i(f.toTable, f.fromTable, !1);
|
|
762
789
|
});
|
|
763
|
-
const l = new Set(t),
|
|
764
|
-
for (let
|
|
765
|
-
|
|
766
|
-
|
|
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)));
|
|
791
|
+
for (let f = h.shift(); f !== void 0; f = h.shift()) {
|
|
792
|
+
const o = f;
|
|
793
|
+
(r.get(o.table) ?? []).forEach(({ table: p, up: m }) => {
|
|
794
|
+
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);
|
|
796
|
+
g.has(b) || (g.add(b), c.add(p), R(e, p) && h.push(d));
|
|
767
797
|
});
|
|
768
|
-
|
|
798
|
+
}
|
|
799
|
+
return c;
|
|
769
800
|
}
|
|
770
|
-
function
|
|
771
|
-
var
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
801
|
+
function Ue(e, t, n, r = {}) {
|
|
802
|
+
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);
|
|
806
|
+
};
|
|
807
|
+
let c = R(e, n) ? I(e, t) : t;
|
|
808
|
+
i !== void 0 && s(i) && (c = [i]);
|
|
809
|
+
const h = c.find(s);
|
|
810
|
+
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 = {
|
|
775
812
|
type: "binary",
|
|
776
813
|
operator: "=",
|
|
777
|
-
left: { type: "field", table:
|
|
778
|
-
right: { type: "field", table:
|
|
814
|
+
left: { type: "field", table: g.fromTable, column: g.fromColumn },
|
|
815
|
+
right: { type: "field", table: g.toTable, column: g.toColumn }
|
|
779
816
|
};
|
|
780
|
-
return { joinType:
|
|
817
|
+
return { joinType: o, on: p };
|
|
781
818
|
}
|
|
782
|
-
const
|
|
783
|
-
function
|
|
819
|
+
const Y = (e, t) => `${e}.${t}`;
|
|
820
|
+
function se({ type: e, format: t }) {
|
|
784
821
|
if (t === void 0) return;
|
|
785
822
|
if (e !== "date" && e !== "dateTime" && e !== "time")
|
|
786
823
|
return `a format is for a date, date-and-time or time column, not ${e}`;
|
|
787
|
-
const
|
|
788
|
-
if (
|
|
789
|
-
if (e === "time" &&
|
|
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"))
|
|
790
827
|
return `a time has no day: format "${t}" can't be written from one`;
|
|
791
828
|
}
|
|
792
|
-
function
|
|
793
|
-
const t = [],
|
|
829
|
+
function Ie(e) {
|
|
830
|
+
const t = [], n = /* @__PURE__ */ new Map();
|
|
794
831
|
e.tables.forEach((a) => {
|
|
795
|
-
|
|
832
|
+
n.has(a.name) && t.push({
|
|
796
833
|
kind: "duplicateTable",
|
|
797
834
|
message: `Table "${a.name}" is declared more than once`
|
|
798
|
-
}),
|
|
799
|
-
const
|
|
800
|
-
a.columns.forEach((
|
|
801
|
-
|
|
835
|
+
}), n.set(a.name, a);
|
|
836
|
+
const l = /* @__PURE__ */ new Set();
|
|
837
|
+
a.columns.forEach((s) => {
|
|
838
|
+
l.has(s.name) && t.push({
|
|
802
839
|
kind: "duplicateColumn",
|
|
803
|
-
message: `Column "${a.name}.${
|
|
804
|
-
}),
|
|
805
|
-
const c =
|
|
840
|
+
message: `Column "${a.name}.${s.name}" is declared more than once`
|
|
841
|
+
}), l.add(s.name);
|
|
842
|
+
const c = se(s);
|
|
806
843
|
c && t.push({
|
|
807
844
|
kind: "invalidFormat",
|
|
808
|
-
message: `Column "${a.name}.${
|
|
845
|
+
message: `Column "${a.name}.${s.name}": ${c}`
|
|
809
846
|
});
|
|
810
847
|
});
|
|
811
848
|
});
|
|
812
|
-
const
|
|
813
|
-
const
|
|
814
|
-
|
|
849
|
+
const r = (a, l) => {
|
|
850
|
+
const s = n.get(a);
|
|
851
|
+
s ? s.columns.some((c) => c.name === l) || t.push({
|
|
815
852
|
kind: "unknownColumn",
|
|
816
|
-
message: `Relation references unknown column "${a}.${
|
|
853
|
+
message: `Relation references unknown column "${a}.${l}"`
|
|
817
854
|
}) : t.push({
|
|
818
855
|
kind: "unknownTable",
|
|
819
856
|
message: `Relation references unknown table "${a}"`
|
|
820
857
|
});
|
|
821
|
-
},
|
|
858
|
+
}, i = /* @__PURE__ */ new Set();
|
|
822
859
|
return e.relations.forEach((a) => {
|
|
823
|
-
|
|
824
|
-
const
|
|
825
|
-
|
|
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(" <-> ");
|
|
862
|
+
i.has(c) && t.push({
|
|
826
863
|
kind: "duplicateRelation",
|
|
827
|
-
message: `Relation ${
|
|
828
|
-
}),
|
|
864
|
+
message: `Relation ${l} -> ${s} is declared more than once (declare each foreign key once)`
|
|
865
|
+
}), i.add(c);
|
|
829
866
|
}), t;
|
|
830
867
|
}
|
|
831
868
|
export {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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,
|
|
882
|
+
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,
|
|
898
|
+
U as d,
|
|
899
|
+
_ as e,
|
|
900
|
+
ye as f,
|
|
901
|
+
w as g,
|
|
902
|
+
fe as h,
|
|
903
|
+
M as i,
|
|
904
|
+
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,
|
|
915
|
+
x as u,
|
|
916
|
+
Ie as v,
|
|
917
|
+
re as w,
|
|
918
|
+
Re as x,
|
|
919
|
+
k as y,
|
|
920
|
+
we as z
|
|
883
921
|
};
|