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