@nongt/visql-core 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/core.js +163 -136
- package/dist/explain.js +3 -3
- package/dist/fixtures.js +3 -3
- package/dist/issueLocation-DY-vvgFF.js +1155 -0
- 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/types/core/ast.d.ts +24 -2
- package/dist/types/core/functionRegistry.d.ts +15 -2
- package/dist/types/core/i18n/defaultMessages.d.ts +23 -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-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,12 +1,12 @@
|
|
|
1
|
-
import { D as
|
|
2
|
-
import { c as
|
|
3
|
-
const Ot = 1e3,
|
|
4
|
-
function
|
|
1
|
+
import { D as P, h as U, q as S, t as v, i as C, K as _e, u as ne, F as jn, e as te, n as re, L as Te, j as x, y as oe, m as Q, o as A, N as Je, l as E, O as Rn, P as _, z as R, r as qn, M as D, s as Gn, Q as Fn, d as M, g as se, R as Ne, b as Y, J as Pn, x as Qn, S as We } from "./schema-DsMO9oFE.js";
|
|
2
|
+
import { c as _n, s as Jn, b as Ve } from "./calendarDate-CYlr9TvX.js";
|
|
3
|
+
const Ot = 1e3, Wn = 15, Ut = 40, Lt = 100;
|
|
4
|
+
function Vn(e) {
|
|
5
5
|
const [n] = e.replace(/^[+-]/, "").split(/e/i), [r, t = ""] = n.split(".");
|
|
6
6
|
return `${r}${t.replace(/0+$/, "")}`.replace(/^0+/, "").length;
|
|
7
7
|
}
|
|
8
8
|
function Hn(e) {
|
|
9
|
-
return Number.isFinite(e) &&
|
|
9
|
+
return Number.isFinite(e) && Vn(String(e)) <= Wn;
|
|
10
10
|
}
|
|
11
11
|
const Dt = [];
|
|
12
12
|
function O(e) {
|
|
@@ -20,39 +20,39 @@ function He(e) {
|
|
|
20
20
|
const n = [], r = (t) => {
|
|
21
21
|
t.type === "subquery" ? n.push(t) : oe(t).forEach(r);
|
|
22
22
|
};
|
|
23
|
-
return
|
|
23
|
+
return _e(e).forEach(r), n;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function Ke(e, n) {
|
|
26
26
|
let r = !1;
|
|
27
27
|
const t = (s) => {
|
|
28
|
-
if (s.type !== "subquery") return
|
|
28
|
+
if (s.type !== "subquery") return Q(s, t);
|
|
29
29
|
const i = n(s);
|
|
30
30
|
return i !== s && (r = !0), i;
|
|
31
31
|
}, o = te(e, t, (s) => s);
|
|
32
32
|
return r ? o : e;
|
|
33
33
|
}
|
|
34
34
|
const jt = (e, n) => `${e}#${n}`;
|
|
35
|
-
function
|
|
35
|
+
function Kn(e) {
|
|
36
36
|
return !("type" in e) && "of" in e;
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const Xn = (e) => ({
|
|
39
39
|
id: e.id,
|
|
40
40
|
alias: e.name,
|
|
41
41
|
query: e.query
|
|
42
42
|
});
|
|
43
|
-
function
|
|
43
|
+
function ke(e, n) {
|
|
44
44
|
var o;
|
|
45
45
|
const r = O(e).find((s) => s.id === n);
|
|
46
46
|
if (r) return r;
|
|
47
47
|
const t = (o = e.shared) == null ? void 0 : o.find((s) => s.id === n);
|
|
48
|
-
return t &&
|
|
48
|
+
return t && Xn(t);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const r =
|
|
50
|
+
function Xe(e, n) {
|
|
51
|
+
const r = ke(e, n);
|
|
52
52
|
if (r) return C(r.query) ? void 0 : r;
|
|
53
53
|
const t = He(e).find((a) => a.id === n);
|
|
54
54
|
if (t) return t;
|
|
55
|
-
const o = /^(.*)#(\d+)$/.exec(n), s = o ?
|
|
55
|
+
const o = /^(.*)#(\d+)$/.exec(n), s = o ? ke(e, o[1]) : void 0, i = Number(o == null ? void 0 : o[2]), u = s && C(s.query) ? s.query.union[i] : void 0;
|
|
56
56
|
return s && u ? {
|
|
57
57
|
id: n,
|
|
58
58
|
alias: s.alias,
|
|
@@ -84,21 +84,21 @@ function ce(e) {
|
|
|
84
84
|
...u !== void 0 ? { distinct: u } : {}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function Rt(e, n) {
|
|
88
88
|
return n.reduce((r, t) => {
|
|
89
|
-
const o = r &&
|
|
89
|
+
const o = r && Xe(r, t);
|
|
90
90
|
return o ? Ye(o) : void 0;
|
|
91
91
|
}, e);
|
|
92
92
|
}
|
|
93
93
|
function ze(e, n, r) {
|
|
94
94
|
if (n.length === 0) return r(e);
|
|
95
|
-
const [t, ...o] = n, s =
|
|
95
|
+
const [t, ...o] = n, s = Xe(e, t);
|
|
96
96
|
if (!s) return e;
|
|
97
97
|
const i = Ye(s), u = ze(i, o, r);
|
|
98
98
|
if (u === i || !U(u)) return e;
|
|
99
99
|
if ("type" in s && s.type === "subquery") {
|
|
100
100
|
const l = { ...s, query: ce(u) };
|
|
101
|
-
return
|
|
101
|
+
return Ke(e, (c) => c === s ? l : c);
|
|
102
102
|
}
|
|
103
103
|
const a = (l, c) => {
|
|
104
104
|
if (!O(e).some((f) => f.id === l.id))
|
|
@@ -109,7 +109,7 @@ function ze(e, n, r) {
|
|
|
109
109
|
joins: e.joins.map((f) => f === l ? d : f)
|
|
110
110
|
};
|
|
111
111
|
};
|
|
112
|
-
if (
|
|
112
|
+
if (Kn(s)) {
|
|
113
113
|
const { of: l, index: c } = s, { union: d } = l.query;
|
|
114
114
|
return a(l, {
|
|
115
115
|
...l.query,
|
|
@@ -132,14 +132,14 @@ function ye(e, n, r = []) {
|
|
|
132
132
|
if (t.select.length === 0)
|
|
133
133
|
return S(t).flatMap((u) => {
|
|
134
134
|
var l;
|
|
135
|
-
if (u.table !== void 0) return ((l =
|
|
135
|
+
if (u.table !== void 0) return ((l = x(e, u.table)) == null ? void 0 : l.columns) ?? [];
|
|
136
136
|
const a = pe(u, r);
|
|
137
137
|
return a ? ye(e, a, r) : [];
|
|
138
138
|
});
|
|
139
139
|
const o = new Map(S(t).map((u) => [v(u), u.table])), s = (u) => {
|
|
140
140
|
var a;
|
|
141
141
|
if (u.type === "field") {
|
|
142
|
-
const l = u.table === void 0 ? void 0 : o.get(u.table), c = l === void 0 || (a =
|
|
142
|
+
const l = u.table === void 0 ? void 0 : o.get(u.table), c = l === void 0 || (a = x(e, l)) == null ? void 0 : a.columns.find((d) => d.name === u.column);
|
|
143
143
|
return (c == null ? void 0 : c.type) ?? "varchar";
|
|
144
144
|
}
|
|
145
145
|
if (u.type === "function") {
|
|
@@ -148,17 +148,17 @@ function ye(e, n, r = []) {
|
|
|
148
148
|
if (l === "SUM" || l === "AVG") return "decimal";
|
|
149
149
|
if ((l === "MIN" || l === "MAX") && u.args[0]) return s(u.args[0]);
|
|
150
150
|
}
|
|
151
|
-
return u.type === "literal" && typeof u.value == "number" ? "decimal" : u.type === "literal" && u.as ? Yn[u.as] : "varchar";
|
|
151
|
+
return u.type === "arithmetic" ? u.operator !== "/" && s(u.left) === "integer" && s(u.right) === "integer" ? "integer" : "decimal" : u.type === "literal" && typeof u.value == "number" ? "decimal" : u.type === "literal" && u.as ? Yn[u.as] : "varchar";
|
|
152
152
|
}, i = (u) => {
|
|
153
153
|
var d, f;
|
|
154
154
|
if (u.type !== "field" || u.table === void 0) return !1;
|
|
155
155
|
const a = S(t).find((m) => v(m) === u.table);
|
|
156
156
|
if (!a) return !1;
|
|
157
|
-
const l = a.table === void 0 ? pe(a, r) : void 0, c = a.table !== void 0 ? (d =
|
|
157
|
+
const l = a.table === void 0 ? pe(a, r) : void 0, c = a.table !== void 0 ? (d = x(e, a.table)) == null ? void 0 : d.columns : l && ye(e, l, r);
|
|
158
158
|
return !!((f = c == null ? void 0 : c.find((m) => m.name === u.column)) != null && f.joinOnly);
|
|
159
159
|
};
|
|
160
160
|
return t.select.flatMap((u) => {
|
|
161
|
-
const a =
|
|
161
|
+
const a = A(u);
|
|
162
162
|
return a ? [{
|
|
163
163
|
name: a,
|
|
164
164
|
label: a,
|
|
@@ -171,23 +171,23 @@ function Ze(e, n, r = []) {
|
|
|
171
171
|
const t = pe(n, r), o = (t ? ye(e, t, r) : []).filter((s, i, u) => u.findIndex((a) => a.name === s.name) === i);
|
|
172
172
|
return { name: n.alias, label: n.alias, columns: o };
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function qt(e, n, r = []) {
|
|
175
175
|
return S(n).filter((t) => t.table === void 0).map((t) => Ze(e, t, r));
|
|
176
176
|
}
|
|
177
|
-
function Gt(e, n =
|
|
177
|
+
function Gt(e, n = P) {
|
|
178
178
|
if (C(e)) return !1;
|
|
179
179
|
const r = e;
|
|
180
180
|
return (r.groupBy ?? []).length === 0 && r.select.length > 0 && r.select.every((t) => ne(t.expression, n)) && jn(r, n).select.length === 0;
|
|
181
181
|
}
|
|
182
|
-
function
|
|
183
|
-
const t = (o) => o.type === "field" ? o.table === n ? { ...o, table: r } : o : o.type === "exists" &&
|
|
182
|
+
function Ie(e, n, r) {
|
|
183
|
+
const t = (o) => o.type === "field" ? o.table === n ? { ...o, table: r } : o : o.type === "exists" && Je(o.query).has(n) ? { ...o, link: t(o.link) } : Q(o, t);
|
|
184
184
|
return te(e, t, (o) => o);
|
|
185
185
|
}
|
|
186
186
|
function en(e, n) {
|
|
187
187
|
const r = re(n), t = S(r).flatMap((o) => o.table === void 0 ? [] : [{ table: o.table, alias: o.alias }]);
|
|
188
188
|
return r.select.length === 0 ? t.flatMap(({ table: o }) => {
|
|
189
189
|
var s;
|
|
190
|
-
return (((s =
|
|
190
|
+
return (((s = x(e, o)) == null ? void 0 : s.columns) ?? []).map((i) => ({ name: i.name, table: o, column: i.name }));
|
|
191
191
|
}) : r.select.flatMap((o) => {
|
|
192
192
|
const { expression: s } = o;
|
|
193
193
|
if (s.type !== "field" || !s.column) return [];
|
|
@@ -295,6 +295,12 @@ const et = {
|
|
|
295
295
|
// Functions
|
|
296
296
|
addArg: "Add Arg",
|
|
297
297
|
removeArg: "Remove Arg",
|
|
298
|
+
// Calculations (+ − × ÷): its two values, in order, and its operator.
|
|
299
|
+
calcFirst: "First value",
|
|
300
|
+
calcSecond: "Second value",
|
|
301
|
+
calcOperator: "Operator",
|
|
302
|
+
/** Makes a calculation the first value of a new one. */
|
|
303
|
+
wrapInCalculation: "Wrap in Calculation",
|
|
298
304
|
// Value type menu
|
|
299
305
|
typeField: "Field",
|
|
300
306
|
typeValue: "Value",
|
|
@@ -307,6 +313,8 @@ const et = {
|
|
|
307
313
|
typeDate: "Date",
|
|
308
314
|
typeBoolean: "Yes / No",
|
|
309
315
|
typeFunction: "Function",
|
|
316
|
+
/** A calculation, `a + b` (issue 26). */
|
|
317
|
+
typeCalculation: "Calculation",
|
|
310
318
|
typeExpression: "Expression",
|
|
311
319
|
/** A named param (set by the application, shown read-only). */
|
|
312
320
|
typeParam: "Parameter",
|
|
@@ -335,6 +343,9 @@ const et = {
|
|
|
335
343
|
* (which group the rows) apart from the rest. Kept short: the list is
|
|
336
344
|
* as narrow as the name box. */
|
|
337
345
|
functionGroupAggregate: "Aggregates",
|
|
346
|
+
/** Window functions (LAG, ROW_NUMBER, …): each looks at the rows around
|
|
347
|
+
* a row. */
|
|
348
|
+
functionGroupWindow: "Window",
|
|
338
349
|
functionGroupOther: "Functions",
|
|
339
350
|
typeMenuCondition: "Condition",
|
|
340
351
|
/** IN's value as a query of its own (issue 122), when offered: its type,
|
|
@@ -495,6 +506,12 @@ const et = {
|
|
|
495
506
|
addSort: "Add Sort",
|
|
496
507
|
removeSort: "Remove Sort",
|
|
497
508
|
toggleSortDirection: "Ascending / descending",
|
|
509
|
+
/** A window function's OVER (issue 20): the columns its rows are split
|
|
510
|
+
* by, and their order. */
|
|
511
|
+
windowPartitionBy: "Partition by",
|
|
512
|
+
windowOrderBy: "Order by",
|
|
513
|
+
addPartition: "Add Partition",
|
|
514
|
+
removePartition: "Remove Partition",
|
|
498
515
|
/** Opens the row-count inputs. */
|
|
499
516
|
limitRows: "Limit rows",
|
|
500
517
|
removeLimit: "Remove row limit",
|
|
@@ -570,6 +587,7 @@ const et = {
|
|
|
570
587
|
locationColumn: (e) => `column ${e}`,
|
|
571
588
|
locationGroupKey: (e) => `key ${e}`,
|
|
572
589
|
locationSortKey: (e) => `sort key ${e}`,
|
|
590
|
+
locationPartitionKey: (e) => `partition key ${e}`,
|
|
573
591
|
locationCondition: (e) => `condition ${e}`,
|
|
574
592
|
locationLeft: "left side",
|
|
575
593
|
locationRight: "right side",
|
|
@@ -613,6 +631,9 @@ const et = {
|
|
|
613
631
|
issueSharedOrder: "A shared query can use only the shared queries before it",
|
|
614
632
|
issueUnusedShared: "A shared query used nowhere",
|
|
615
633
|
issueJoinOnlyColumn: "A column for joining tables only, used as a value",
|
|
634
|
+
issueMisplacedWindow: "LAG, ROW_NUMBER and the like go only in a column or a sort key",
|
|
635
|
+
issueGroupedWindow: "LAG, ROW_NUMBER and the like can't be in a grouped query: work them out in a sub query",
|
|
636
|
+
issueUnorderedWindow: "A window function with no order: add one under Order by",
|
|
616
637
|
// What a problem is about, where the query says (issue 132); the kind's
|
|
617
638
|
// text above where it doesn't.
|
|
618
639
|
issueUnknownTableNamed: (e) => `There's no table "${e}"`,
|
|
@@ -642,6 +663,9 @@ const et = {
|
|
|
642
663
|
issueNotGroupedNamed: (e) => `${e} isn't one value per group: group by it, or sum it up`,
|
|
643
664
|
issueSelectAllGrouped: "A grouped query has to pick its columns, not all of them (*)",
|
|
644
665
|
issueMisplacedAggregateNamed: (e) => `${e} can't be used here`,
|
|
666
|
+
issueMisplacedWindowNamed: (e) => `${e} goes only in a column or a sort key`,
|
|
667
|
+
issueGroupedWindowNamed: (e) => `${e} can't be in a grouped query: work it out in a sub query`,
|
|
668
|
+
issueUnorderedWindowNamed: (e) => `${e} has no order: add one under Order by`,
|
|
645
669
|
// A collapsed expression's peek (issue 131): the whole of it, a part per
|
|
646
670
|
// line; picking a part goes to it.
|
|
647
671
|
peekHint: "Pick a part to go to it",
|
|
@@ -681,8 +705,8 @@ function de(e, n, r) {
|
|
|
681
705
|
const t = [...e], [o] = t.splice(n, 1);
|
|
682
706
|
return t.splice(r, 0, o), t;
|
|
683
707
|
}
|
|
684
|
-
const
|
|
685
|
-
function
|
|
708
|
+
const Re = (e) => e !== void 0 && Number.isSafeInteger(e) && e >= 0 ? e : void 0, fe = (e) => (e ?? "").length <= D;
|
|
709
|
+
function q(e, n, r) {
|
|
686
710
|
return e.map((t) => t.id === n ? r(t) : t);
|
|
687
711
|
}
|
|
688
712
|
function rn(e, n, r) {
|
|
@@ -716,15 +740,16 @@ function on(e, n) {
|
|
|
716
740
|
const [r, ...t] = n;
|
|
717
741
|
return { ...e, from: rt(r), joins: t };
|
|
718
742
|
}
|
|
719
|
-
function
|
|
743
|
+
function k(e) {
|
|
720
744
|
const n = /* @__PURE__ */ new Set(), r = (t) => {
|
|
721
|
-
var o;
|
|
745
|
+
var o, s;
|
|
722
746
|
if (t)
|
|
723
747
|
switch (t.type) {
|
|
724
748
|
case "field":
|
|
725
749
|
t.table && n.add(t.table);
|
|
726
750
|
break;
|
|
727
751
|
case "binary":
|
|
752
|
+
case "arithmetic":
|
|
728
753
|
r(t.left), r(t.right);
|
|
729
754
|
break;
|
|
730
755
|
case "logical":
|
|
@@ -740,19 +765,19 @@ function I(e) {
|
|
|
740
765
|
r(t.condition), r(t.then), r(t.else);
|
|
741
766
|
break;
|
|
742
767
|
case "case":
|
|
743
|
-
r(t.subject), t.branches.forEach((
|
|
744
|
-
r(
|
|
768
|
+
r(t.subject), t.branches.forEach((i) => {
|
|
769
|
+
r(i.when), r(i.then);
|
|
745
770
|
}), r(t.else);
|
|
746
771
|
break;
|
|
747
772
|
case "function":
|
|
748
|
-
t.args.forEach(r), (o = t.
|
|
773
|
+
t.args.forEach(r), (o = t.partitionBy) == null || o.forEach(r), (s = t.orderBy) == null || s.forEach((i) => r(i.expression));
|
|
749
774
|
break;
|
|
750
775
|
// Only the tables its link names on the outer query's side: its own
|
|
751
776
|
// tables are joined inside it (withExistsJoins), never to the query
|
|
752
777
|
// around it — that would repeat its rows, which EXISTS is there to avoid.
|
|
753
778
|
case "exists": {
|
|
754
|
-
const
|
|
755
|
-
|
|
779
|
+
const i = Je(t.query);
|
|
780
|
+
k(t.link).filter((u) => !i.has(u)).forEach((u) => n.add(u));
|
|
756
781
|
break;
|
|
757
782
|
}
|
|
758
783
|
}
|
|
@@ -760,7 +785,7 @@ function I(e) {
|
|
|
760
785
|
return r(e), [...n];
|
|
761
786
|
}
|
|
762
787
|
function ie(e, n, r, t, o, s) {
|
|
763
|
-
const i =
|
|
788
|
+
const i = _(n), u = t === void 0 && o === void 0, a = n.joins.flatMap((d) => (d.joinType === "left" || d.joinType === "full") && d.table !== void 0 ? [d.table] : []), l = u ? Gn(e, i, r, { after: s, leftJoined: a }) : void 0, c = {
|
|
764
789
|
id: G(),
|
|
765
790
|
table: r,
|
|
766
791
|
joinType: t ?? (l == null ? void 0 : l.joinType) ?? "inner",
|
|
@@ -770,7 +795,7 @@ function ie(e, n, r, t, o, s) {
|
|
|
770
795
|
return { ...n, joins: [...n.joins, c] };
|
|
771
796
|
}
|
|
772
797
|
function sn(e, n, r) {
|
|
773
|
-
const t =
|
|
798
|
+
const t = _(n);
|
|
774
799
|
if (t.includes(r)) return;
|
|
775
800
|
const o = Fn(e, t, r);
|
|
776
801
|
if (!o) return;
|
|
@@ -784,7 +809,7 @@ function st(e, n, r) {
|
|
|
784
809
|
return sn(e, n, r) ?? ie(e, n, r);
|
|
785
810
|
}
|
|
786
811
|
function L(e, n, r) {
|
|
787
|
-
return
|
|
812
|
+
return k(r).reduce((t, o) => S(t).some((s) => s.alias === o) || _(t).includes(o) ? t : sn(e, t, o) ?? ie(e, t, o), n);
|
|
788
813
|
}
|
|
789
814
|
function it(e, n, r, t) {
|
|
790
815
|
return {
|
|
@@ -810,7 +835,7 @@ function an(e) {
|
|
|
810
835
|
let r;
|
|
811
836
|
return e.joins.some((t) => {
|
|
812
837
|
n.add(v(t));
|
|
813
|
-
const o = t.joinType === "cross" ? void 0 : t.on, s =
|
|
838
|
+
const o = t.joinType === "cross" ? void 0 : t.on, s = k(o).find((i) => !n.has(i));
|
|
814
839
|
return s && (r = { table: t.table ?? v(t), needs: s }), s !== void 0;
|
|
815
840
|
}), r;
|
|
816
841
|
}
|
|
@@ -835,8 +860,8 @@ function lt(e, n, r, t) {
|
|
|
835
860
|
};
|
|
836
861
|
}
|
|
837
862
|
function ae(e, n) {
|
|
838
|
-
if (!n || !
|
|
839
|
-
const r = oe(n), t = r.map((a) => ae(e, a)), s = t.some((a, l) => a !== r[l]) ?
|
|
863
|
+
if (!n || !Rn(n)) return n;
|
|
864
|
+
const r = oe(n), t = r.map((a) => ae(e, a)), s = t.some((a, l) => a !== r[l]) ? Q(n, (a) => t[r.indexOf(a)]) : n;
|
|
840
865
|
if (s.type !== "exists") return s;
|
|
841
866
|
const { query: i } = s, { joins: u } = L(
|
|
842
867
|
e,
|
|
@@ -850,20 +875,20 @@ function ae(e, n) {
|
|
|
850
875
|
);
|
|
851
876
|
return u === i.joins ? s : { ...s, query: { ...i, joins: u } };
|
|
852
877
|
}
|
|
853
|
-
function
|
|
878
|
+
function Pt(e, n, r) {
|
|
854
879
|
const t = ae(e, r);
|
|
855
880
|
return { ...L(e, n, t), having: t };
|
|
856
881
|
}
|
|
857
|
-
function
|
|
882
|
+
function qe(e, n) {
|
|
858
883
|
const r = /* @__PURE__ */ new Set([
|
|
859
884
|
...n ? S(n).map(v) : [],
|
|
860
|
-
...
|
|
885
|
+
...R(e).map((o) => o.name)
|
|
861
886
|
]);
|
|
862
887
|
let t = 1;
|
|
863
888
|
for (; r.has(`sub_query_${t}`); ) t += 1;
|
|
864
889
|
return `sub_query_${t}`;
|
|
865
890
|
}
|
|
866
|
-
function
|
|
891
|
+
function Qt() {
|
|
867
892
|
return { id: E() };
|
|
868
893
|
}
|
|
869
894
|
function he(e, n, r) {
|
|
@@ -883,7 +908,7 @@ function he(e, n, r) {
|
|
|
883
908
|
...n,
|
|
884
909
|
from: {
|
|
885
910
|
id: r.id ?? G(),
|
|
886
|
-
alias:
|
|
911
|
+
alias: qe(e, n),
|
|
887
912
|
query: { from: Me(r), joins: [], select: [] }
|
|
888
913
|
}
|
|
889
914
|
};
|
|
@@ -899,7 +924,7 @@ function he(e, n, r) {
|
|
|
899
924
|
case "addDerivedJoin": {
|
|
900
925
|
const t = {
|
|
901
926
|
id: r.id ?? G(),
|
|
902
|
-
alias:
|
|
927
|
+
alias: qe(e, n),
|
|
903
928
|
joinType: "left",
|
|
904
929
|
query: { from: Me(r), joins: [], select: [] }
|
|
905
930
|
}, o = tn(e, n, t);
|
|
@@ -909,8 +934,8 @@ function he(e, n, r) {
|
|
|
909
934
|
const t = O(n).find((a) => a.id === r.derivedId), o = r.alias.trim();
|
|
910
935
|
if (!t || o === t.alias) return n;
|
|
911
936
|
const s = S(n).filter((a) => a !== t).map(v);
|
|
912
|
-
if (!o || o.length > D || s.includes(o) ||
|
|
913
|
-
const i =
|
|
937
|
+
if (!o || o.length > D || s.includes(o) || x(e, o)) return n;
|
|
938
|
+
const i = Ie(n, t.alias, o), { from: u } = i;
|
|
914
939
|
return {
|
|
915
940
|
...i,
|
|
916
941
|
from: u.query && u.id === t.id ? { ...u, alias: o } : u,
|
|
@@ -921,14 +946,14 @@ function he(e, n, r) {
|
|
|
921
946
|
const t = r.joinId === void 0 ? n.from : n.joins.find((u) => u.id === r.joinId), o = r.alias.trim();
|
|
922
947
|
if ((t == null ? void 0 : t.shared) === void 0 || o === t.alias) return n;
|
|
923
948
|
const s = S(n).filter((u) => u !== t).map(v);
|
|
924
|
-
if (!o || o.length > D || s.includes(o) ||
|
|
925
|
-
const i =
|
|
926
|
-
return r.joinId === void 0 ? { ...i, from: { ...i.from, alias: o } } : { ...i, joins:
|
|
949
|
+
if (!o || o.length > D || s.includes(o) || x(e, o)) return n;
|
|
950
|
+
const i = Ie(n, t.alias, o);
|
|
951
|
+
return r.joinId === void 0 ? { ...i, from: { ...i.from, alias: o } } : { ...i, joins: q(i.joins, r.joinId, (u) => ({ ...u, alias: o })) };
|
|
927
952
|
}
|
|
928
953
|
case "setMeasureSynced":
|
|
929
954
|
return {
|
|
930
955
|
...n,
|
|
931
|
-
joins:
|
|
956
|
+
joins: q(n.joins, r.joinId, (t) => t.query && t.drillAcross ? { ...t, drillAcross: { ...t.drillAcross, synced: r.synced } } : t)
|
|
932
957
|
};
|
|
933
958
|
case "removeJoin":
|
|
934
959
|
return { ...n, joins: n.joins.filter((t) => t.id !== r.joinId) };
|
|
@@ -936,19 +961,19 @@ function he(e, n, r) {
|
|
|
936
961
|
return {
|
|
937
962
|
...n,
|
|
938
963
|
// A CROSS JOIN uses no ON, but keeps it: switched back, it's used again.
|
|
939
|
-
joins:
|
|
964
|
+
joins: q(n.joins, r.joinId, (t) => ({ ...t, joinType: r.joinType }))
|
|
940
965
|
};
|
|
941
966
|
case "changeJoinAlias":
|
|
942
967
|
return fe(r.alias) ? {
|
|
943
968
|
...n,
|
|
944
969
|
// A derived table (or a shared query's place) goes by its alias: it
|
|
945
970
|
// can't be left without one.
|
|
946
|
-
joins:
|
|
971
|
+
joins: q(n.joins, r.joinId, (t) => t.table === void 0 ? { ...t, alias: r.alias || t.alias } : { ...t, alias: r.alias })
|
|
947
972
|
} : n;
|
|
948
973
|
case "changeJoinOn":
|
|
949
974
|
return {
|
|
950
975
|
...n,
|
|
951
|
-
joins:
|
|
976
|
+
joins: q(n.joins, r.joinId, (t) => ({
|
|
952
977
|
...t,
|
|
953
978
|
on: ae(e, r.on)
|
|
954
979
|
}))
|
|
@@ -1030,9 +1055,9 @@ function he(e, n, r) {
|
|
|
1030
1055
|
orderBy: (n.orderBy ?? []).map((t) => t.id === r.orderById ? { ...t, direction: r.direction } : t)
|
|
1031
1056
|
};
|
|
1032
1057
|
case "setLimit":
|
|
1033
|
-
return { ...n, limit:
|
|
1058
|
+
return { ...n, limit: Re(r.limit) };
|
|
1034
1059
|
case "setOffset":
|
|
1035
|
-
return { ...n, offset:
|
|
1060
|
+
return { ...n, offset: Re(r.offset) };
|
|
1036
1061
|
case "clearPaging":
|
|
1037
1062
|
return { ...n, limit: void 0, offset: void 0 };
|
|
1038
1063
|
/* v8 ignore start -- PipelineAction is a closed union; every real case is
|
|
@@ -1049,16 +1074,16 @@ const ct = {
|
|
|
1049
1074
|
full: "FULL",
|
|
1050
1075
|
cross: "CROSS"
|
|
1051
1076
|
};
|
|
1052
|
-
function
|
|
1077
|
+
function _t(e) {
|
|
1053
1078
|
return `${ct[e.joinType]} JOIN ${v(e)}`;
|
|
1054
1079
|
}
|
|
1055
|
-
function
|
|
1080
|
+
function Jt(e) {
|
|
1056
1081
|
return e.alias || "Column";
|
|
1057
1082
|
}
|
|
1058
|
-
function
|
|
1083
|
+
function Wt() {
|
|
1059
1084
|
return "Sort";
|
|
1060
1085
|
}
|
|
1061
|
-
function
|
|
1086
|
+
function Vt() {
|
|
1062
1087
|
return "Group";
|
|
1063
1088
|
}
|
|
1064
1089
|
function Ht(e, n, r) {
|
|
@@ -1067,19 +1092,19 @@ function Ht(e, n, r) {
|
|
|
1067
1092
|
const a = t.findIndex((l) => "id" in l && l.id === r);
|
|
1068
1093
|
return new Set(t.slice(0, a + 1).map(v));
|
|
1069
1094
|
}
|
|
1070
|
-
const o = new Set(
|
|
1095
|
+
const o = new Set(_(n)), s = qn(e, [...o]), i = new Set(nn(e, n).map((a) => a.table)), u = R(e).filter((a) => !o.has(a.name) && (s.has(a.name) || i.has(a.name)));
|
|
1071
1096
|
return /* @__PURE__ */ new Set([...t.map(v), ...u.map((a) => a.name)]);
|
|
1072
1097
|
}
|
|
1073
|
-
function
|
|
1098
|
+
function Kt(e, n) {
|
|
1074
1099
|
const r = S(n);
|
|
1075
|
-
return
|
|
1100
|
+
return R(e).flatMap((t) => {
|
|
1076
1101
|
const o = r.filter((s) => s.table === t.name).map(v);
|
|
1077
1102
|
return (o.length > 0 ? o : [t.name]).map((s) => ({ ref: s, table: t }));
|
|
1078
1103
|
});
|
|
1079
1104
|
}
|
|
1080
|
-
function
|
|
1081
|
-
const r = new Set(
|
|
1082
|
-
return
|
|
1105
|
+
function Xt(e, n) {
|
|
1106
|
+
const r = new Set(_(n));
|
|
1107
|
+
return R(e).filter((t) => !r.has(t.name));
|
|
1083
1108
|
}
|
|
1084
1109
|
function be(e) {
|
|
1085
1110
|
return e ? e.type === "logical" ? e.operands.reduce((n, r) => n + be(r), 0) : e.type === "not" ? be(e.operand) : 1 : 0;
|
|
@@ -1092,8 +1117,8 @@ function Yt(e, n = et) {
|
|
|
1092
1117
|
return e ? e.type === "binary" && e.left.type === "field" && ((r = e.right) == null ? void 0 : r.type) === "field" ? !e.left.column && !e.right.column ? n.setJoinCondition : `${Ge(e.left)} ${e.operator ?? "="} ${Ge(e.right)}` : n.conditionCount(be(e)) : n.setJoinCondition;
|
|
1093
1118
|
}
|
|
1094
1119
|
function zt(e, n) {
|
|
1095
|
-
const r = new Set(
|
|
1096
|
-
return
|
|
1120
|
+
const r = new Set(k(e.where));
|
|
1121
|
+
return k(e.having).forEach((t) => r.add(t)), e.joins.filter((t) => t.id !== n).forEach((t) => k(t.on).forEach((o) => r.add(o))), [...e.select, ...e.groupBy ?? [], ...e.orderBy ?? []].forEach((t) => k(t.expression).forEach((o) => r.add(o))), r;
|
|
1097
1122
|
}
|
|
1098
1123
|
function Zt(e, n, r) {
|
|
1099
1124
|
const t = ae(e, r);
|
|
@@ -1109,7 +1134,7 @@ function ln(e) {
|
|
|
1109
1134
|
n.set(r.fromTable, [...n.get(r.fromTable) ?? [], r.toTable]);
|
|
1110
1135
|
}), n;
|
|
1111
1136
|
}
|
|
1112
|
-
function
|
|
1137
|
+
function J(e, n, r = ln(e)) {
|
|
1113
1138
|
const t = /* @__PURE__ */ new Set([n]), o = [n];
|
|
1114
1139
|
for (let s = o.shift(); s !== void 0; s = o.shift())
|
|
1115
1140
|
(r.get(s) ?? []).forEach((i) => {
|
|
@@ -1120,7 +1145,7 @@ function P(e, n, r = ln(e)) {
|
|
|
1120
1145
|
const j = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [];
|
|
1121
1146
|
function cn(e, n) {
|
|
1122
1147
|
const r = new Map(S(e).map((t) => [v(t), t.table]));
|
|
1123
|
-
return
|
|
1148
|
+
return k(n).map((t) => ({
|
|
1124
1149
|
ref: t,
|
|
1125
1150
|
table: r.has(t) ? r.get(t) : t
|
|
1126
1151
|
}));
|
|
@@ -1136,26 +1161,26 @@ function Fe(e, n) {
|
|
|
1136
1161
|
}
|
|
1137
1162
|
function dn(e, n) {
|
|
1138
1163
|
const r = (n.groupBy ?? []).flatMap((o) => cn(n, o.expression)), t = ln(e);
|
|
1139
|
-
return
|
|
1140
|
-
const s =
|
|
1164
|
+
return R(e).map((o) => {
|
|
1165
|
+
const s = J(e, o.name, t), i = r.find((u) => u.table === void 0 || !s.has(u.table));
|
|
1141
1166
|
return i ? { table: o, unlinked: i.table ?? i.ref } : { table: o };
|
|
1142
1167
|
});
|
|
1143
1168
|
}
|
|
1144
1169
|
function dt(e, n, r) {
|
|
1145
|
-
const t =
|
|
1170
|
+
const t = J(e, r);
|
|
1146
1171
|
return j(n.where).filter((o) => {
|
|
1147
1172
|
const s = Ce(n, o);
|
|
1148
1173
|
return s.length > 0 && s.every((i) => i !== void 0 && t.has(i));
|
|
1149
1174
|
});
|
|
1150
1175
|
}
|
|
1151
1176
|
function nr(e, n, r) {
|
|
1152
|
-
const t =
|
|
1177
|
+
const t = J(e, r);
|
|
1153
1178
|
return j(n.where).some((o) => {
|
|
1154
1179
|
const s = Ce(n, o);
|
|
1155
1180
|
return s.some((i) => i !== void 0 && t.has(i)) && s.some((i) => i === void 0 || !t.has(i));
|
|
1156
1181
|
});
|
|
1157
1182
|
}
|
|
1158
|
-
function
|
|
1183
|
+
function K(e, n) {
|
|
1159
1184
|
let r = e;
|
|
1160
1185
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1161
1186
|
return r;
|
|
@@ -1194,7 +1219,7 @@ function ft(e, n) {
|
|
|
1194
1219
|
function mt(e, n, r) {
|
|
1195
1220
|
var s;
|
|
1196
1221
|
if (r.type !== "field" || r.table === void 0 || r.column === void 0) return !1;
|
|
1197
|
-
const t = Ce(n, r)[0], o = (s =
|
|
1222
|
+
const t = Ce(n, r)[0], o = (s = x(e, t)) == null ? void 0 : s.columns.find((i) => i.name === r.column);
|
|
1198
1223
|
return o !== void 0 && !o.nullable;
|
|
1199
1224
|
}
|
|
1200
1225
|
function fn(e, n, r, t) {
|
|
@@ -1209,7 +1234,7 @@ function fn(e, n, r, t) {
|
|
|
1209
1234
|
function mn(e, n, r, t, o, s) {
|
|
1210
1235
|
var b;
|
|
1211
1236
|
const i = n.groupBy.map((y) => Fe(n, y.expression)), u = dt(e, n, r).map((y) => Fe(n, y)), a = new Set(o.map((y) => y.alias).filter((y) => !!y)), l = i.map((y, w) => {
|
|
1212
|
-
const T =
|
|
1237
|
+
const T = K(ge(y, `key_${w + 1}`), a);
|
|
1213
1238
|
return a.add(T), T;
|
|
1214
1239
|
}), c = [...u, ...t];
|
|
1215
1240
|
let d = {
|
|
@@ -1271,7 +1296,7 @@ function tr(e, n, r) {
|
|
|
1271
1296
|
if (b)
|
|
1272
1297
|
a = b.alias;
|
|
1273
1298
|
else {
|
|
1274
|
-
a =
|
|
1299
|
+
a = K(
|
|
1275
1300
|
ge(r.value, "value"),
|
|
1276
1301
|
new Set(s.query.select.map((w) => w.alias ?? ""))
|
|
1277
1302
|
);
|
|
@@ -1282,9 +1307,9 @@ function tr(e, n, r) {
|
|
|
1282
1307
|
a = ge(r.value, "value");
|
|
1283
1308
|
const p = { id: E(), alias: a, expression: r.value }, b = mn(e, n, r.table, o, [p]), y = /* @__PURE__ */ new Set([
|
|
1284
1309
|
...S(n).map(v),
|
|
1285
|
-
...
|
|
1310
|
+
...R(e).map(($) => $.name)
|
|
1286
1311
|
]), w = `${r.table}_per_${b.keyNames.join("_and_")}`.slice(0, D - 4);
|
|
1287
|
-
u =
|
|
1312
|
+
u = K(w, y);
|
|
1288
1313
|
const T = {
|
|
1289
1314
|
id: E(),
|
|
1290
1315
|
alias: u,
|
|
@@ -1299,7 +1324,7 @@ function tr(e, n, r) {
|
|
|
1299
1324
|
type: "function",
|
|
1300
1325
|
name: "MAX",
|
|
1301
1326
|
args: [we(u, a)]
|
|
1302
|
-
}, c = new Set(n.select.map((p) => p.alias).filter((p) => !!p)), d =
|
|
1327
|
+
}, c = new Set(n.select.map((p) => p.alias).filter((p) => !!p)), d = K(`${r.table}_${a}`.slice(0, D - 4), c);
|
|
1303
1328
|
let f = r.selectId !== void 0 ? n.select.map((p) => p.id === r.selectId ? { ...p, expression: l, alias: p.alias || d } : p) : [...n.select, { id: E(), expression: l, alias: d }];
|
|
1304
1329
|
return f = [...n.groupBy.filter((p) => !f.some((b) => M(b.expression, p.expression))).map((p) => ({ id: E(), expression: p.expression })), ...f], { ...n, joins: i, select: f };
|
|
1305
1330
|
}
|
|
@@ -1394,7 +1419,7 @@ function hn(e) {
|
|
|
1394
1419
|
if (typeof n == "number") return Number.isInteger(n) ? "integer" : "number";
|
|
1395
1420
|
if (typeof n == "bigint") return "integer";
|
|
1396
1421
|
if (typeof n == "boolean") return "boolean";
|
|
1397
|
-
if (n instanceof Date) return
|
|
1422
|
+
if (n instanceof Date) return Ve(n) ? "date" : "dateTime";
|
|
1398
1423
|
}
|
|
1399
1424
|
function bn(e, n, r) {
|
|
1400
1425
|
if (!e) return;
|
|
@@ -1405,12 +1430,15 @@ function bn(e, n, r) {
|
|
|
1405
1430
|
case "literal":
|
|
1406
1431
|
return hn(e);
|
|
1407
1432
|
case "function": {
|
|
1408
|
-
const o =
|
|
1433
|
+
const o = Pn(e.name, r), s = (o == null ? void 0 : o.args.findIndex((a) => a.kind === "type-name")) ?? -1, i = s >= 0 ? e.args[s] : void 0;
|
|
1409
1434
|
if ((i == null ? void 0 : i.type) === "literal" && typeof i.value == "string")
|
|
1410
1435
|
return bt(i.value);
|
|
1411
1436
|
const u = o == null ? void 0 : o.returns;
|
|
1412
1437
|
return u === "arg" ? t(e.args[0]) : u;
|
|
1413
1438
|
}
|
|
1439
|
+
// A number: whole when both sides are and it isn't a division.
|
|
1440
|
+
case "arithmetic":
|
|
1441
|
+
return e.operator !== "/" && t(e.left) === "integer" && t(e.right) === "integer" ? "integer" : "number";
|
|
1414
1442
|
case "if":
|
|
1415
1443
|
return t(e.then) ?? t(e.else);
|
|
1416
1444
|
case "case":
|
|
@@ -1425,7 +1453,7 @@ function gn(e, n) {
|
|
|
1425
1453
|
const r = typeof e == "string" ? e.trim() : void 0;
|
|
1426
1454
|
switch (n) {
|
|
1427
1455
|
case "text":
|
|
1428
|
-
return e instanceof Date ?
|
|
1456
|
+
return e instanceof Date ? Jn(e) : String(e);
|
|
1429
1457
|
case "integer":
|
|
1430
1458
|
case "number": {
|
|
1431
1459
|
let t;
|
|
@@ -1433,10 +1461,10 @@ function gn(e, n) {
|
|
|
1433
1461
|
}
|
|
1434
1462
|
case "date":
|
|
1435
1463
|
case "dateTime": {
|
|
1436
|
-
if (e instanceof Date) return n === "date" && !
|
|
1464
|
+
if (e instanceof Date) return n === "date" && !Ve(e) ? void 0 : e;
|
|
1437
1465
|
const t = r === void 0 ? null : St.exec(r);
|
|
1438
1466
|
if (!t) return;
|
|
1439
|
-
const [, o, s, i, u, a, l] = t.map(Number), c =
|
|
1467
|
+
const [, o, s, i, u, a, l] = t.map(Number), c = _n(o, s, i);
|
|
1440
1468
|
return c.getUTCMonth() !== s - 1 || c.getUTCDate() !== i ? void 0 : t[4] === void 0 ? c : n === "date" ? void 0 : new Date(Date.UTC(o, s - 1, i, u, a, Number.isNaN(l) ? 0 : l));
|
|
1441
1469
|
}
|
|
1442
1470
|
case "time": {
|
|
@@ -1500,7 +1528,7 @@ const wn = "source", Sn = "rows_", B = (e) => e ? { type: "literal", value: null
|
|
|
1500
1528
|
);
|
|
1501
1529
|
function Se(e, n) {
|
|
1502
1530
|
const r = $e(e);
|
|
1503
|
-
return
|
|
1531
|
+
return k(n).map((t) => r.get(t) ?? t);
|
|
1504
1532
|
}
|
|
1505
1533
|
function vn(e, n) {
|
|
1506
1534
|
const r = $e(e);
|
|
@@ -1514,11 +1542,11 @@ function Z(e, n, r) {
|
|
|
1514
1542
|
const t = $e(n);
|
|
1515
1543
|
return bn(r, (o) => {
|
|
1516
1544
|
var u;
|
|
1517
|
-
const s = t.get(o.table ?? "") ?? o.table ?? "", i = (u =
|
|
1545
|
+
const s = t.get(o.table ?? "") ?? o.table ?? "", i = (u = x(e, s)) == null ? void 0 : u.columns.find((a) => a.name === o.column);
|
|
1518
1546
|
return i && ht(i.type);
|
|
1519
|
-
},
|
|
1547
|
+
}, P);
|
|
1520
1548
|
}
|
|
1521
|
-
function
|
|
1549
|
+
function Ae(e, n) {
|
|
1522
1550
|
let r = e;
|
|
1523
1551
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1524
1552
|
return r;
|
|
@@ -1526,17 +1554,17 @@ function xe(e, n) {
|
|
|
1526
1554
|
const ee = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [], Tn = (e) => {
|
|
1527
1555
|
if (e.length !== 0)
|
|
1528
1556
|
return e.length === 1 ? e[0] : { type: "logical", operator: "AND", operands: e };
|
|
1529
|
-
},
|
|
1557
|
+
}, I = (e) => e.from.table, Pe = (e, n) => x(e, n).label;
|
|
1530
1558
|
function ue(e) {
|
|
1531
1559
|
const { from: n } = e;
|
|
1532
1560
|
return n.query && C(n.query) ? n : void 0;
|
|
1533
1561
|
}
|
|
1534
|
-
function
|
|
1562
|
+
function W(e, n) {
|
|
1535
1563
|
if (n === void 0) return ue(e);
|
|
1536
1564
|
const r = O(e).find((t) => t.id === n);
|
|
1537
1565
|
return r && C(r.query) ? r : void 0;
|
|
1538
1566
|
}
|
|
1539
|
-
function
|
|
1567
|
+
function V(e, n, r) {
|
|
1540
1568
|
const t = { ...n, query: r };
|
|
1541
1569
|
return n === e.from ? { ...e, from: t } : { ...e, joins: e.joins.map((o) => o === n ? t : o) };
|
|
1542
1570
|
}
|
|
@@ -1544,7 +1572,7 @@ function le(e, n) {
|
|
|
1544
1572
|
const [r] = n;
|
|
1545
1573
|
return r.select.map((t, o) => {
|
|
1546
1574
|
var d;
|
|
1547
|
-
const s =
|
|
1575
|
+
const s = A(t) ?? "", i = n.map((f) => {
|
|
1548
1576
|
var m;
|
|
1549
1577
|
return { branch: f, expression: (m = f.select[o]) == null ? void 0 : m.expression };
|
|
1550
1578
|
}).filter((f) => f.expression !== void 0 && !F(f.expression)), a = ((d = n.map((f) => {
|
|
@@ -1576,7 +1604,7 @@ function le(e, n) {
|
|
|
1576
1604
|
type: a
|
|
1577
1605
|
};
|
|
1578
1606
|
const c = Se(l.branch, l.expression);
|
|
1579
|
-
return i.some((f) => Se(f.branch, f.expression).includes(
|
|
1607
|
+
return i.some((f) => Se(f.branch, f.expression).includes(I(f.branch))) ? {
|
|
1580
1608
|
name: s,
|
|
1581
1609
|
kind: "own",
|
|
1582
1610
|
tables: c,
|
|
@@ -1599,13 +1627,13 @@ function lr(e, n) {
|
|
|
1599
1627
|
return {
|
|
1600
1628
|
name: o.name,
|
|
1601
1629
|
kind: o.kind,
|
|
1602
|
-
filledBy: t.filter((u, a) => i[a]).map(
|
|
1603
|
-
nullIn: t.filter((u, a) => !i[a]).map(
|
|
1630
|
+
filledBy: t.filter((u, a) => i[a]).map(I),
|
|
1631
|
+
nullIn: t.filter((u, a) => !i[a]).map(I)
|
|
1604
1632
|
};
|
|
1605
1633
|
});
|
|
1606
1634
|
}
|
|
1607
1635
|
function Nn(e, n, r, t, o) {
|
|
1608
|
-
const s =
|
|
1636
|
+
const s = J(e, n), i = r.filter((c) => c.kind === "shared" && c.expression), u = (c) => c.tables.every((d) => s.has(d));
|
|
1609
1637
|
if (!i.some(u)) return `"${n}" shares no column with the union`;
|
|
1610
1638
|
const a = i.find((c) => !u(c));
|
|
1611
1639
|
if (a && o === "refuse")
|
|
@@ -1615,7 +1643,7 @@ function Nn(e, n, r, t, o) {
|
|
|
1615
1643
|
return `"${n}" can't follow a condition on ${l.tables.join(", ")}`;
|
|
1616
1644
|
}
|
|
1617
1645
|
function En(e) {
|
|
1618
|
-
const [n] = e, r = new Set(e.map(
|
|
1646
|
+
const [n] = e, r = new Set(e.map(I));
|
|
1619
1647
|
return ee(n.where).flatMap((t) => {
|
|
1620
1648
|
const o = Se(n, t), s = o.filter((i) => r.has(i));
|
|
1621
1649
|
if (s.length === 0) return [{ operand: vn(n, t), tables: o }];
|
|
@@ -1623,16 +1651,16 @@ function En(e) {
|
|
|
1623
1651
|
throw new Error("a condition naming both a branch's own table and shared ones can't be placed: split it, or put it on the union instead");
|
|
1624
1652
|
});
|
|
1625
1653
|
}
|
|
1626
|
-
function
|
|
1654
|
+
function Qe(e, n, r, t) {
|
|
1627
1655
|
const o = t.unshared ?? "refuse", s = le(e, n), i = En(n);
|
|
1628
|
-
if (!
|
|
1656
|
+
if (!x(e, r.table))
|
|
1629
1657
|
throw new Error(`addUnionTable: unknown table "${r.table}"`);
|
|
1630
|
-
if (n.some((h) =>
|
|
1658
|
+
if (n.some((h) => I(h) === r.table))
|
|
1631
1659
|
throw new Error(`addUnionTable: "${r.table}" is in the union already`);
|
|
1632
1660
|
const u = Nn(e, r.table, s, i, o);
|
|
1633
1661
|
if (u) throw new Error(`addUnionTable: ${u}`);
|
|
1634
|
-
const a =
|
|
1635
|
-
const N =
|
|
1662
|
+
const a = J(e, r.table), l = r.label ?? Pe(e, r.table), c = s.map((h) => h.kind === "source" ? { type: "literal", value: l } : h.kind === "shared" && h.expression && h.tables.every((N) => a.has(N)) ? h.expression : B(h.type)), d = new Set(s.map((h) => h.name)), f = [], m = (h) => {
|
|
1663
|
+
const N = Ae(h, d);
|
|
1636
1664
|
return d.add(N), f.push(N), N;
|
|
1637
1665
|
}, g = [], p = {
|
|
1638
1666
|
from: { table: r.table },
|
|
@@ -1644,12 +1672,12 @@ function _e(e, n, r, t) {
|
|
|
1644
1672
|
}), t.source && !s.some((h) => h.kind === "source") && g.push({
|
|
1645
1673
|
name: m(wn),
|
|
1646
1674
|
own: { type: "literal", value: l },
|
|
1647
|
-
others: (h) => ({ type: "literal", value:
|
|
1675
|
+
others: (h) => ({ type: "literal", value: Pe(e, I(h)) })
|
|
1648
1676
|
});
|
|
1649
1677
|
const b = (h) => `${Sn}${h}`;
|
|
1650
|
-
(t.rowMarkers || s.some((h) => h.kind === "rows")) && (n.filter((h) => !d.has(b(
|
|
1678
|
+
(t.rowMarkers || s.some((h) => h.kind === "rows")) && (n.filter((h) => !d.has(b(I(h)))).forEach((h) => {
|
|
1651
1679
|
g.push({
|
|
1652
|
-
name: m(b(
|
|
1680
|
+
name: m(b(I(h))),
|
|
1653
1681
|
own: B("integer"),
|
|
1654
1682
|
others: (N) => N === h ? { type: "literal", value: 1 } : B("integer")
|
|
1655
1683
|
});
|
|
@@ -1696,10 +1724,10 @@ function Cn(e) {
|
|
|
1696
1724
|
const n = (o) => new Error(`addUnionTable: ${o}`);
|
|
1697
1725
|
if (e.from.query) throw n("the query reads from a derived table");
|
|
1698
1726
|
if (e.select.length === 0) throw n("the query picks no columns (SELECT *)");
|
|
1699
|
-
if ((e.groupBy ?? []).length > 0 || e.having || e.distinct || (e.orderBy ?? []).length > 0 || e.select.some((o) => ne(o.expression,
|
|
1727
|
+
if ((e.groupBy ?? []).length > 0 || e.having || e.distinct || (e.orderBy ?? []).length > 0 || e.select.some((o) => ne(o.expression, P)))
|
|
1700
1728
|
throw n("a union is of detail rows: no aggregates, GROUP BY, HAVING, DISTINCT or ORDER BY");
|
|
1701
1729
|
const r = /* @__PURE__ */ new Set(), t = e.select.map((o, s) => {
|
|
1702
|
-
const i =
|
|
1730
|
+
const i = Ae(A(o) ?? `column_${s + 1}`, r);
|
|
1703
1731
|
return r.add(i), { ...o, alias: i };
|
|
1704
1732
|
});
|
|
1705
1733
|
return {
|
|
@@ -1712,7 +1740,7 @@ function Cn(e) {
|
|
|
1712
1740
|
function cr(e, n, r, t = {}) {
|
|
1713
1741
|
const o = ue(n);
|
|
1714
1742
|
if (o) {
|
|
1715
|
-
const { union: l, added: c } =
|
|
1743
|
+
const { union: l, added: c } = Qe(e, o.query.union, r, t), d = { ...o, query: { ...o.query, union: l } }, f = n.select.length === 0 ? [] : [
|
|
1716
1744
|
...n.select,
|
|
1717
1745
|
...c.map((m) => ({
|
|
1718
1746
|
id: E(),
|
|
@@ -1721,7 +1749,7 @@ function cr(e, n, r, t = {}) {
|
|
|
1721
1749
|
];
|
|
1722
1750
|
return { ...n, from: d, select: f };
|
|
1723
1751
|
}
|
|
1724
|
-
const s = Cn(n), { union: i } =
|
|
1752
|
+
const s = Cn(n), { union: i } = Qe(e, [s], r, t), u = t.alias ?? "stacked", a = i[0].select.map((l) => l.alias);
|
|
1725
1753
|
return {
|
|
1726
1754
|
id: n.id,
|
|
1727
1755
|
from: { id: E(), alias: u, query: { union: i, all: !0 } },
|
|
@@ -1750,7 +1778,7 @@ function dr(e, n, r = {}) {
|
|
|
1750
1778
|
return [];
|
|
1751
1779
|
}
|
|
1752
1780
|
const u = /* @__PURE__ */ new Set([
|
|
1753
|
-
...o.map(
|
|
1781
|
+
...o.map(I),
|
|
1754
1782
|
...s.flatMap((a) => a.kind === "shared" ? a.tables : [])
|
|
1755
1783
|
]);
|
|
1756
1784
|
return e.tables.map((a) => a.name).filter((a) => !u.has(a) && Nn(e, a, s, i, r.unshared ?? "refuse") === void 0);
|
|
@@ -1761,11 +1789,11 @@ function Tt(e, n, r) {
|
|
|
1761
1789
|
const o = r.union[t], s = n.union[t].select.map((a) => a.id), i = r.union.map((a, l) => {
|
|
1762
1790
|
if (l === t) return a;
|
|
1763
1791
|
const c = o.select.map((f) => {
|
|
1764
|
-
const m =
|
|
1792
|
+
const m = A(f), g = Z(e, o, f.expression), p = s.indexOf(f.id), b = p === -1 ? void 0 : a.select[p];
|
|
1765
1793
|
if (!b)
|
|
1766
1794
|
return { id: E(), ...m ? { alias: m } : {}, expression: B(g) };
|
|
1767
1795
|
let y = b;
|
|
1768
|
-
|
|
1796
|
+
A(b) !== m && (y = { ...y, alias: m });
|
|
1769
1797
|
const { expression: w } = b;
|
|
1770
1798
|
return F(w) && w.type === "literal" && w.as !== g && (y = { ...y, expression: B(g) }), y;
|
|
1771
1799
|
});
|
|
@@ -1786,7 +1814,7 @@ function Tt(e, n, r) {
|
|
|
1786
1814
|
return u.every((a, l) => a === r.union[l]) ? r : { ...r, union: u };
|
|
1787
1815
|
}
|
|
1788
1816
|
function Nt(e, n) {
|
|
1789
|
-
const r = (s) => s.union[0].select.map((i) =>
|
|
1817
|
+
const r = (s) => s.union[0].select.map((i) => A(i)), t = r(e), o = r(n);
|
|
1790
1818
|
return t.length !== o.length ? [] : t.flatMap((s, i) => {
|
|
1791
1819
|
const u = o[i];
|
|
1792
1820
|
return s && u && s !== u && !o.includes(s) && !t.includes(u) ? [{ from: s, to: u }] : [];
|
|
@@ -1796,13 +1824,13 @@ function $n(e, n, r) {
|
|
|
1796
1824
|
let t = r;
|
|
1797
1825
|
n && C(n) && C(t) && n.union.length === t.union.length && (t = Tt(e, n, t));
|
|
1798
1826
|
const o = t;
|
|
1799
|
-
return se(o, (s, i) =>
|
|
1827
|
+
return se(o, (s, i) => xe(
|
|
1800
1828
|
e,
|
|
1801
1829
|
n && C(n) === C(o) ? Y(n)[i] : void 0,
|
|
1802
1830
|
s
|
|
1803
1831
|
));
|
|
1804
1832
|
}
|
|
1805
|
-
function
|
|
1833
|
+
function xe(e, n, r) {
|
|
1806
1834
|
const t = (f) => {
|
|
1807
1835
|
var m;
|
|
1808
1836
|
return $n(
|
|
@@ -1825,7 +1853,7 @@ function Ae(e, n, r) {
|
|
|
1825
1853
|
});
|
|
1826
1854
|
if (c.length === 0) return l;
|
|
1827
1855
|
const d = (f) => {
|
|
1828
|
-
if (f.type !== "field") return
|
|
1856
|
+
if (f.type !== "field") return Q(f, d);
|
|
1829
1857
|
const m = c.find((g) => g.alias === f.table && g.from === f.column);
|
|
1830
1858
|
return m ? { ...f, column: m.to } : f;
|
|
1831
1859
|
};
|
|
@@ -1834,7 +1862,7 @@ function Ae(e, n, r) {
|
|
|
1834
1862
|
function Et(e, n, r) {
|
|
1835
1863
|
if (!U(r)) return r;
|
|
1836
1864
|
const t = n && U(n) ? n : void 0;
|
|
1837
|
-
return Te(
|
|
1865
|
+
return Te(xe(e, t, r), (o, s) => {
|
|
1838
1866
|
var i, u;
|
|
1839
1867
|
return $n(
|
|
1840
1868
|
e,
|
|
@@ -1843,10 +1871,10 @@ function Et(e, n, r) {
|
|
|
1843
1871
|
);
|
|
1844
1872
|
});
|
|
1845
1873
|
}
|
|
1846
|
-
function
|
|
1847
|
-
return e.type === "field" ? [e] : oe(e).flatMap(
|
|
1874
|
+
function An(e) {
|
|
1875
|
+
return e.type === "field" ? [e] : oe(e).flatMap(An);
|
|
1848
1876
|
}
|
|
1849
|
-
const
|
|
1877
|
+
const xn = (e, n, r) => An(e).some((t) => t.table === n && r.has(t.column ?? ""));
|
|
1850
1878
|
function Ct(e, n, r) {
|
|
1851
1879
|
const t = n.query.union.filter((a, l) => l !== r), o = [
|
|
1852
1880
|
e.where,
|
|
@@ -1855,23 +1883,23 @@ function Ct(e, n, r) {
|
|
|
1855
1883
|
...(e.groupBy ?? []).map((a) => a.expression),
|
|
1856
1884
|
...(e.orderBy ?? []).map((a) => a.expression)
|
|
1857
1885
|
].filter((a) => a !== void 0), s = (a) => o.some(
|
|
1858
|
-
(l) =>
|
|
1886
|
+
(l) => xn(l, n.alias, /* @__PURE__ */ new Set([a]))
|
|
1859
1887
|
), i = new Set(t[0].select.flatMap((a, l) => {
|
|
1860
|
-
const c = t.every((f) => f.select[l] && F(f.select[l].expression)), d =
|
|
1888
|
+
const c = t.every((f) => f.select[l] && F(f.select[l].expression)), d = A(a);
|
|
1861
1889
|
return c && !(d && s(d)) ? [l] : [];
|
|
1862
1890
|
})), u = new Set([...i].flatMap((a) => {
|
|
1863
|
-
const l =
|
|
1891
|
+
const l = A(t[0].select[a]);
|
|
1864
1892
|
return l ? [l] : [];
|
|
1865
1893
|
}));
|
|
1866
1894
|
return { at: i, names: u };
|
|
1867
1895
|
}
|
|
1868
1896
|
function fr(e, n, r) {
|
|
1869
|
-
const t =
|
|
1897
|
+
const t = W(e, r);
|
|
1870
1898
|
if (!t || !t.query.union[n] || t.query.union.length < 2) return e;
|
|
1871
1899
|
const o = Ct(e, t, n), s = t.query.union.filter((l, c) => c !== n), i = o.at.size < s[0].select.length ? o : { at: /* @__PURE__ */ new Set(), names: /* @__PURE__ */ new Set() }, u = e.select.filter(
|
|
1872
|
-
(l) => !
|
|
1900
|
+
(l) => !xn(l.expression, t.alias, i.names)
|
|
1873
1901
|
), a = s.map((l) => ({ ...l, select: l.select.filter((c, d) => !i.at.has(d)) }));
|
|
1874
|
-
return
|
|
1902
|
+
return V({ ...e, select: u }, t, { ...t.query, union: a });
|
|
1875
1903
|
}
|
|
1876
1904
|
function $t(e, n) {
|
|
1877
1905
|
const r = /* @__PURE__ */ new Set([
|
|
@@ -1892,7 +1920,7 @@ function mr(e, n, r, t) {
|
|
|
1892
1920
|
}
|
|
1893
1921
|
function pr(e, n, r) {
|
|
1894
1922
|
const t = /* @__PURE__ */ new Set(), o = e.select.map((p, b) => {
|
|
1895
|
-
const y =
|
|
1923
|
+
const y = Ae(A(p) ?? `column_${b + 1}`, t);
|
|
1896
1924
|
return t.add(y), { ...p, alias: y };
|
|
1897
1925
|
}), {
|
|
1898
1926
|
from: s,
|
|
@@ -1927,14 +1955,14 @@ function pr(e, n, r) {
|
|
|
1927
1955
|
return ["where", "groupBy", "having", "distinct"].forEach((p) => delete g[p]), g;
|
|
1928
1956
|
}
|
|
1929
1957
|
function yr(e, n, r, t) {
|
|
1930
|
-
const o =
|
|
1958
|
+
const o = W(n, r);
|
|
1931
1959
|
if (!o) return n;
|
|
1932
1960
|
const s = le(e, o.query.union).map((i) => ({
|
|
1933
1961
|
id: E(),
|
|
1934
1962
|
...i.name ? { alias: i.name } : {},
|
|
1935
1963
|
expression: B(i.type)
|
|
1936
1964
|
}));
|
|
1937
|
-
return
|
|
1965
|
+
return V(n, o, {
|
|
1938
1966
|
...o.query,
|
|
1939
1967
|
union: [...o.query.union, { from: t, joins: [], select: s }]
|
|
1940
1968
|
});
|
|
@@ -1949,34 +1977,34 @@ function hr(e, n, r, t) {
|
|
|
1949
1977
|
return { ...n, joins: [...n.joins, { ...o, on: tn(e, n, o) }] };
|
|
1950
1978
|
}
|
|
1951
1979
|
function br(e, n, r) {
|
|
1952
|
-
const t =
|
|
1953
|
-
return !t || t.query.all === r ? e :
|
|
1980
|
+
const t = W(e, n);
|
|
1981
|
+
return !t || t.query.all === r ? e : V(e, t, { ...t.query, all: r });
|
|
1954
1982
|
}
|
|
1955
1983
|
function gr(e, n, r, t, o) {
|
|
1956
|
-
const s =
|
|
1957
|
-
if (!s || !a || !l || l.length > D || i.select.some((d) =>
|
|
1958
|
-
const c =
|
|
1984
|
+
const s = W(n, r), [i, ...u] = (s == null ? void 0 : s.query.union) ?? [], a = i == null ? void 0 : i.select[t], l = o.trim();
|
|
1985
|
+
if (!s || !a || !l || l.length > D || i.select.some((d) => A(d) === l)) return n;
|
|
1986
|
+
const c = V(n, s, {
|
|
1959
1987
|
...s.query,
|
|
1960
1988
|
union: [
|
|
1961
1989
|
{ ...i, select: i.select.map((d, f) => f === t ? { ...d, alias: l } : d) },
|
|
1962
1990
|
...u
|
|
1963
1991
|
]
|
|
1964
1992
|
});
|
|
1965
|
-
return
|
|
1993
|
+
return xe(e, n, c);
|
|
1966
1994
|
}
|
|
1967
1995
|
function wr(e, n) {
|
|
1968
1996
|
var c;
|
|
1969
|
-
const r =
|
|
1997
|
+
const r = W(e, n);
|
|
1970
1998
|
if (!r || r.query.union.length !== 1) return e;
|
|
1971
1999
|
const [t] = r.query.union, o = new Map(t.select.flatMap((d) => {
|
|
1972
|
-
const f =
|
|
2000
|
+
const f = A(d);
|
|
1973
2001
|
return f ? [[f, d.expression]] : [];
|
|
1974
2002
|
})), s = (d) => d.type === "field" && d.table === r.alias && o.has(d.column ?? ""), i = (d) => Ne(d, (f) => s(f) ? o.get(f.column) : f), u = e.select.map((d) => {
|
|
1975
2003
|
const f = i(d.expression);
|
|
1976
2004
|
if (d.alias || !s(d.expression)) return { ...d, expression: f };
|
|
1977
2005
|
const m = d.expression.column;
|
|
1978
|
-
return
|
|
1979
|
-
}), a = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((d) => ne(d.expression,
|
|
2006
|
+
return A({ ...d, expression: f }) === m ? { ...d, expression: f } : { ...d, expression: f, alias: m };
|
|
2007
|
+
}), a = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((d) => ne(d.expression, P));
|
|
1980
2008
|
if (r === e.from && !a) {
|
|
1981
2009
|
const d = te({ ...e, select: u }, i, (f) => f);
|
|
1982
2010
|
return {
|
|
@@ -1996,27 +2024,27 @@ function wr(e, n) {
|
|
|
1996
2024
|
...e.orderBy ? {
|
|
1997
2025
|
orderBy: e.orderBy.map((d) => ({ ...d, expression: i(d.expression) }))
|
|
1998
2026
|
} : {}
|
|
1999
|
-
} :
|
|
2027
|
+
} : V(e, r, t);
|
|
2000
2028
|
}
|
|
2001
|
-
function
|
|
2029
|
+
function At(e, n) {
|
|
2002
2030
|
return e.select.filter((r) => ne(r.expression, n));
|
|
2003
2031
|
}
|
|
2004
|
-
function
|
|
2032
|
+
function xt(e) {
|
|
2005
2033
|
return { ...e.expression, fromSelect: e.id };
|
|
2006
2034
|
}
|
|
2007
|
-
function
|
|
2035
|
+
function X(e) {
|
|
2008
2036
|
const { fromSelect: n, ...r } = e;
|
|
2009
2037
|
return n === void 0 ? e : r;
|
|
2010
2038
|
}
|
|
2011
2039
|
function Bn(e, n) {
|
|
2012
|
-
const r = (o) => typeof o.fromSelect == "string" ? n(o, o.fromSelect) :
|
|
2040
|
+
const r = (o) => typeof o.fromSelect == "string" ? n(o, o.fromSelect) : Q(o, r), t = r(e);
|
|
2013
2041
|
return M(t, e) ? e : t;
|
|
2014
2042
|
}
|
|
2015
2043
|
function Bt(e, n) {
|
|
2016
2044
|
var u;
|
|
2017
|
-
const r = new Map(
|
|
2045
|
+
const r = new Map(At(e, n).map((a) => [a.id, a])), t = (a) => Bn(a, (l, c) => {
|
|
2018
2046
|
const d = r.get(c);
|
|
2019
|
-
return d ?
|
|
2047
|
+
return d ? xt(d) : X(l);
|
|
2020
2048
|
}), o = e.having && t(e.having);
|
|
2021
2049
|
let s = !1;
|
|
2022
2050
|
const i = (u = e.orderBy) == null ? void 0 : u.map((a) => {
|
|
@@ -2029,7 +2057,7 @@ function Sr(e, n) {
|
|
|
2029
2057
|
const r = new Set((n.groupBy ?? []).flatMap(({ expression: t }) => t.type === "field" && t.column ? [t.column.toLowerCase()] : []));
|
|
2030
2058
|
return Bn(e, (t, o) => {
|
|
2031
2059
|
const s = n.select.find((i) => i.id === o);
|
|
2032
|
-
return !(s != null && s.alias) || r.has(s.alias.toLowerCase()) || !M(
|
|
2060
|
+
return !(s != null && s.alias) || r.has(s.alias.toLowerCase()) || !M(X(t), s.expression) ? X(t) : { type: "field", column: s.alias };
|
|
2033
2061
|
});
|
|
2034
2062
|
}
|
|
2035
2063
|
function ve(e, n) {
|
|
@@ -2039,13 +2067,13 @@ function ve(e, n) {
|
|
|
2039
2067
|
if (!c.query) return c;
|
|
2040
2068
|
const d = t(c.query);
|
|
2041
2069
|
return d === c.query ? c : (i = !0, { ...c, query: d });
|
|
2042
|
-
}), a = s === e.from && !i ? e : { ...e, from: s, joins: u }, l =
|
|
2070
|
+
}), a = s === e.from && !i ? e : { ...e, from: s, joins: u }, l = Ke(a, (c) => {
|
|
2043
2071
|
const d = r(c.query);
|
|
2044
2072
|
return d === c.query ? c : { ...c, query: d };
|
|
2045
2073
|
});
|
|
2046
|
-
return
|
|
2074
|
+
return Qn(Bt(l, n), n);
|
|
2047
2075
|
}
|
|
2048
|
-
function vr(e, n, r, t =
|
|
2076
|
+
function vr(e, n, r, t = P) {
|
|
2049
2077
|
if (!U(r)) return r;
|
|
2050
2078
|
const o = Te(
|
|
2051
2079
|
ve(r, t),
|
|
@@ -2067,21 +2095,21 @@ const Tr = [
|
|
|
2067
2095
|
"REGEXP",
|
|
2068
2096
|
"IS NULL",
|
|
2069
2097
|
"IS NOT NULL"
|
|
2070
|
-
],
|
|
2098
|
+
], kt = ["IS NULL", "IS NOT NULL"];
|
|
2071
2099
|
function Nr(e) {
|
|
2072
|
-
return
|
|
2100
|
+
return kt.includes(e);
|
|
2073
2101
|
}
|
|
2074
|
-
const
|
|
2102
|
+
const Er = ["+", "-", "*", "/"], kn = (e) => {
|
|
2075
2103
|
const n = /* @__PURE__ */ new Map();
|
|
2076
|
-
return
|
|
2104
|
+
return We(e, (r) => (r.type === "param" && r.relative && (n.has(r.name) || n.set(r.name, /* @__PURE__ */ new Set()), n.get(r.name).add(JSON.stringify(r.relative))), r)), n;
|
|
2077
2105
|
};
|
|
2078
|
-
function
|
|
2106
|
+
function In(e, n) {
|
|
2079
2107
|
const r = /* @__PURE__ */ new Map(), t = (a) => (r.has(a) || r.set(a, { types: /* @__PURE__ */ new Set(), columns: /* @__PURE__ */ new Map() }), r.get(a)), o = (a, l) => {
|
|
2080
2108
|
const c = new Map(a);
|
|
2081
2109
|
return S(l).forEach((d) => c.set(v(d), d.table)), c;
|
|
2082
2110
|
}, s = (a, l) => {
|
|
2083
2111
|
if (!n || l.type !== "field" || !l.table || !l.column) return;
|
|
2084
|
-
const c = a.has(l.table) ? a.get(l.table) : l.table, d = c === void 0 ? void 0 :
|
|
2112
|
+
const c = a.has(l.table) ? a.get(l.table) : l.table, d = c === void 0 ? void 0 : x(n, c), f = d == null ? void 0 : d.columns.find((m) => m.name === l.column);
|
|
2085
2113
|
return d && f ? { table: d.name, column: f } : void 0;
|
|
2086
2114
|
}, i = (a, l) => {
|
|
2087
2115
|
if (a.type === "param" && t(a.name), a.type === "binary" && a.right) {
|
|
@@ -2100,13 +2128,13 @@ function kn(e, n) {
|
|
|
2100
2128
|
oe(a).forEach((d) => i(d, c));
|
|
2101
2129
|
}, u = (a) => {
|
|
2102
2130
|
const l = o(/* @__PURE__ */ new Map(), a);
|
|
2103
|
-
|
|
2131
|
+
_e(a).forEach((c) => i(c, l)), S(a).forEach((c) => c.query && Y(c.query).forEach(u)), He(a).forEach((c) => u(c.query));
|
|
2104
2132
|
};
|
|
2105
2133
|
return (e.shared ?? []).forEach((a) => Y(a.query).forEach(u)), u(e), r;
|
|
2106
2134
|
}
|
|
2107
|
-
function
|
|
2108
|
-
const r =
|
|
2109
|
-
return [...
|
|
2135
|
+
function Cr(e, n) {
|
|
2136
|
+
const r = kn(e);
|
|
2137
|
+
return [...In(e, n)].map(([t, { types: o, columns: s }]) => {
|
|
2110
2138
|
const i = r.get(t);
|
|
2111
2139
|
return {
|
|
2112
2140
|
name: t,
|
|
@@ -2117,15 +2145,15 @@ function Er(e, n) {
|
|
|
2117
2145
|
};
|
|
2118
2146
|
});
|
|
2119
2147
|
}
|
|
2120
|
-
function
|
|
2121
|
-
return [...
|
|
2148
|
+
function $r(e) {
|
|
2149
|
+
return [...kn(e)].filter(([, n]) => n.size > 1).map(([n]) => n);
|
|
2122
2150
|
}
|
|
2123
|
-
function
|
|
2124
|
-
return [...
|
|
2151
|
+
function Ar(e, n) {
|
|
2152
|
+
return [...In(e, n)].filter(([, r]) => r.types.size > 1).map(([r]) => r);
|
|
2125
2153
|
}
|
|
2126
2154
|
function xr(e, n) {
|
|
2127
2155
|
const r = new Map(Object.entries(n));
|
|
2128
|
-
return
|
|
2156
|
+
return We(e, (t) => {
|
|
2129
2157
|
if (t.type !== "param") return t;
|
|
2130
2158
|
if (!r.has(t.name)) throw new Error(`no value for parameter "${t.name}"`);
|
|
2131
2159
|
const o = r.get(t.name);
|
|
@@ -2133,70 +2161,71 @@ function xr(e, n) {
|
|
|
2133
2161
|
});
|
|
2134
2162
|
}
|
|
2135
2163
|
export {
|
|
2136
|
-
|
|
2164
|
+
Wt as $,
|
|
2137
2165
|
Tr as A,
|
|
2138
|
-
|
|
2139
|
-
|
|
2166
|
+
Ie as B,
|
|
2167
|
+
Rt as C,
|
|
2140
2168
|
et as D,
|
|
2141
2169
|
O as E,
|
|
2142
2170
|
ze as F,
|
|
2143
2171
|
pe as G,
|
|
2144
2172
|
Gt as H,
|
|
2145
|
-
|
|
2173
|
+
X as I,
|
|
2146
2174
|
ye as J,
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2175
|
+
Ar as K,
|
|
2176
|
+
$r as L,
|
|
2177
|
+
Wn as M,
|
|
2150
2178
|
an as N,
|
|
2151
2179
|
rr as O,
|
|
2152
2180
|
nr as P,
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2181
|
+
Er as Q,
|
|
2182
|
+
Hn as R,
|
|
2183
|
+
hn as S,
|
|
2184
|
+
bn as T,
|
|
2185
|
+
ht as U,
|
|
2186
|
+
Zn as V,
|
|
2187
|
+
Lt as W,
|
|
2188
|
+
Xe as X,
|
|
2189
|
+
_t as Y,
|
|
2190
|
+
Jt as Z,
|
|
2163
2191
|
Vt as _,
|
|
2164
2192
|
Ot as a,
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2193
|
+
jt as a0,
|
|
2194
|
+
ir as a1,
|
|
2195
|
+
or as a2,
|
|
2196
|
+
ar as a3,
|
|
2197
|
+
ur as a4,
|
|
2198
|
+
sr as a5,
|
|
2199
|
+
vt as a6,
|
|
2200
|
+
xt as a7,
|
|
2201
|
+
Vn as a8,
|
|
2202
|
+
nn as a9,
|
|
2203
|
+
Ft as aa,
|
|
2204
|
+
Xt as ab,
|
|
2205
|
+
zt as ac,
|
|
2206
|
+
Yt as ad,
|
|
2207
|
+
Ze as ae,
|
|
2208
|
+
Dt as af,
|
|
2209
|
+
er as ag,
|
|
2210
|
+
lt as ah,
|
|
2211
|
+
Pt as ai,
|
|
2212
|
+
ut as aj,
|
|
2213
|
+
it as ak,
|
|
2214
|
+
ae as al,
|
|
2215
|
+
Zt as am,
|
|
2216
|
+
qe as an,
|
|
2217
|
+
tn as ao,
|
|
2218
|
+
At as ap,
|
|
2219
|
+
qt as aq,
|
|
2220
|
+
Ht as ar,
|
|
2221
|
+
Kt as as,
|
|
2222
|
+
Kn as at,
|
|
2223
|
+
He as au,
|
|
2224
|
+
ue as av,
|
|
2225
|
+
J as aw,
|
|
2226
|
+
he as ax,
|
|
2198
2227
|
Ut as b,
|
|
2199
|
-
|
|
2228
|
+
Qt as c,
|
|
2200
2229
|
tr as d,
|
|
2201
2230
|
yr as e,
|
|
2202
2231
|
hr as f,
|
|
@@ -2210,10 +2239,10 @@ export {
|
|
|
2210
2239
|
dr as n,
|
|
2211
2240
|
lr as o,
|
|
2212
2241
|
vr as p,
|
|
2213
|
-
|
|
2242
|
+
Cr as q,
|
|
2214
2243
|
fr as r,
|
|
2215
2244
|
br as s,
|
|
2216
|
-
|
|
2245
|
+
k as t,
|
|
2217
2246
|
wr as u,
|
|
2218
2247
|
G as v,
|
|
2219
2248
|
gn as w,
|