@nongt/visql 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{MuiTimePicker-DRqT6ByZ.js → MuiTimePicker-CROJXSCL.js} +1 -1
- package/dist/{PipelineEditor-CGTZGbmf.js → PipelineEditor-DEiKHDrr.js} +3646 -3514
- package/dist/core.js +137 -119
- package/dist/explain.js +3 -3
- package/dist/fixtures.js +1 -1
- package/dist/index.js +102 -110
- package/dist/issueLocation-Yn71qJyP.js +1141 -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-DVkfcD6D.js} +245 -229
- package/dist/{schema-CgL10bid.js → schema-CzKt6cN2.js} +230 -152
- package/dist/sql-import.js +855 -821
- package/dist/{sqlGen-C1kZwvWI.js → sqlGen-BoJXaULd.js} +331 -309
- package/dist/{tokens-DV5rTGMj.js → tokens-3SURLAkL.js} +15 -14
- package/dist/types/core/FunctionsContext.d.ts +8 -2
- package/dist/types/core/ast.d.ts +9 -1
- package/dist/types/core/components/flow/WindowKeys.d.ts +10 -0
- package/dist/types/core/expressionFlow.d.ts +8 -0
- 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 +16 -0
- package/dist/types/core/i18n/messages.d.ts +12 -0
- package/dist/types/core/issueLocation.d.ts +5 -0
- package/dist/types/core/queryHelpers.d.ts +9 -1
- package/dist/types/core/queryValidation.d.ts +11 -1
- package/dist/types/core/storedQuery.d.ts +1 -1
- package/dist/types/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/sqlImport/syntax.d.ts +11 -2
- package/package.json +1 -1
- package/dist/issueLocation-BlQ280IE.js +0 -1108
|
@@ -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 $, 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-CzKt6cN2.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 =
|
|
52
|
-
if (r) return
|
|
50
|
+
function Xe(e, n) {
|
|
51
|
+
const r = ke(e, n);
|
|
52
|
+
if (r) return $(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 && $(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") {
|
|
@@ -154,11 +154,11 @@ function ye(e, n, r = []) {
|
|
|
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 =
|
|
178
|
-
if (
|
|
177
|
+
function Gt(e, n = P) {
|
|
178
|
+
if ($(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 [];
|
|
@@ -335,6 +335,9 @@ const et = {
|
|
|
335
335
|
* (which group the rows) apart from the rest. Kept short: the list is
|
|
336
336
|
* as narrow as the name box. */
|
|
337
337
|
functionGroupAggregate: "Aggregates",
|
|
338
|
+
/** Window functions (LAG, ROW_NUMBER, …): each looks at the rows around
|
|
339
|
+
* a row. */
|
|
340
|
+
functionGroupWindow: "Window",
|
|
338
341
|
functionGroupOther: "Functions",
|
|
339
342
|
typeMenuCondition: "Condition",
|
|
340
343
|
/** IN's value as a query of its own (issue 122), when offered: its type,
|
|
@@ -495,6 +498,12 @@ const et = {
|
|
|
495
498
|
addSort: "Add Sort",
|
|
496
499
|
removeSort: "Remove Sort",
|
|
497
500
|
toggleSortDirection: "Ascending / descending",
|
|
501
|
+
/** A window function's OVER (issue 20): the columns its rows are split
|
|
502
|
+
* by, and their order. */
|
|
503
|
+
windowPartitionBy: "Partition by",
|
|
504
|
+
windowOrderBy: "Order by",
|
|
505
|
+
addPartition: "Add Partition",
|
|
506
|
+
removePartition: "Remove Partition",
|
|
498
507
|
/** Opens the row-count inputs. */
|
|
499
508
|
limitRows: "Limit rows",
|
|
500
509
|
removeLimit: "Remove row limit",
|
|
@@ -570,6 +579,7 @@ const et = {
|
|
|
570
579
|
locationColumn: (e) => `column ${e}`,
|
|
571
580
|
locationGroupKey: (e) => `key ${e}`,
|
|
572
581
|
locationSortKey: (e) => `sort key ${e}`,
|
|
582
|
+
locationPartitionKey: (e) => `partition key ${e}`,
|
|
573
583
|
locationCondition: (e) => `condition ${e}`,
|
|
574
584
|
locationLeft: "left side",
|
|
575
585
|
locationRight: "right side",
|
|
@@ -613,6 +623,9 @@ const et = {
|
|
|
613
623
|
issueSharedOrder: "A shared query can use only the shared queries before it",
|
|
614
624
|
issueUnusedShared: "A shared query used nowhere",
|
|
615
625
|
issueJoinOnlyColumn: "A column for joining tables only, used as a value",
|
|
626
|
+
issueMisplacedWindow: "LAG, ROW_NUMBER and the like go only in a column or a sort key",
|
|
627
|
+
issueGroupedWindow: "LAG, ROW_NUMBER and the like can't be in a grouped query: work them out in a sub query",
|
|
628
|
+
issueUnorderedWindow: "A window function with no order: add one under Order by",
|
|
616
629
|
// What a problem is about, where the query says (issue 132); the kind's
|
|
617
630
|
// text above where it doesn't.
|
|
618
631
|
issueUnknownTableNamed: (e) => `There's no table "${e}"`,
|
|
@@ -642,6 +655,9 @@ const et = {
|
|
|
642
655
|
issueNotGroupedNamed: (e) => `${e} isn't one value per group: group by it, or sum it up`,
|
|
643
656
|
issueSelectAllGrouped: "A grouped query has to pick its columns, not all of them (*)",
|
|
644
657
|
issueMisplacedAggregateNamed: (e) => `${e} can't be used here`,
|
|
658
|
+
issueMisplacedWindowNamed: (e) => `${e} goes only in a column or a sort key`,
|
|
659
|
+
issueGroupedWindowNamed: (e) => `${e} can't be in a grouped query: work it out in a sub query`,
|
|
660
|
+
issueUnorderedWindowNamed: (e) => `${e} has no order: add one under Order by`,
|
|
645
661
|
// A collapsed expression's peek (issue 131): the whole of it, a part per
|
|
646
662
|
// line; picking a part goes to it.
|
|
647
663
|
peekHint: "Pick a part to go to it",
|
|
@@ -681,8 +697,8 @@ function de(e, n, r) {
|
|
|
681
697
|
const t = [...e], [o] = t.splice(n, 1);
|
|
682
698
|
return t.splice(r, 0, o), t;
|
|
683
699
|
}
|
|
684
|
-
const
|
|
685
|
-
function
|
|
700
|
+
const Re = (e) => e !== void 0 && Number.isSafeInteger(e) && e >= 0 ? e : void 0, fe = (e) => (e ?? "").length <= D;
|
|
701
|
+
function q(e, n, r) {
|
|
686
702
|
return e.map((t) => t.id === n ? r(t) : t);
|
|
687
703
|
}
|
|
688
704
|
function rn(e, n, r) {
|
|
@@ -716,9 +732,9 @@ function on(e, n) {
|
|
|
716
732
|
const [r, ...t] = n;
|
|
717
733
|
return { ...e, from: rt(r), joins: t };
|
|
718
734
|
}
|
|
719
|
-
function
|
|
735
|
+
function k(e) {
|
|
720
736
|
const n = /* @__PURE__ */ new Set(), r = (t) => {
|
|
721
|
-
var o;
|
|
737
|
+
var o, s;
|
|
722
738
|
if (t)
|
|
723
739
|
switch (t.type) {
|
|
724
740
|
case "field":
|
|
@@ -740,19 +756,19 @@ function I(e) {
|
|
|
740
756
|
r(t.condition), r(t.then), r(t.else);
|
|
741
757
|
break;
|
|
742
758
|
case "case":
|
|
743
|
-
r(t.subject), t.branches.forEach((
|
|
744
|
-
r(
|
|
759
|
+
r(t.subject), t.branches.forEach((i) => {
|
|
760
|
+
r(i.when), r(i.then);
|
|
745
761
|
}), r(t.else);
|
|
746
762
|
break;
|
|
747
763
|
case "function":
|
|
748
|
-
t.args.forEach(r), (o = t.
|
|
764
|
+
t.args.forEach(r), (o = t.partitionBy) == null || o.forEach(r), (s = t.orderBy) == null || s.forEach((i) => r(i.expression));
|
|
749
765
|
break;
|
|
750
766
|
// Only the tables its link names on the outer query's side: its own
|
|
751
767
|
// tables are joined inside it (withExistsJoins), never to the query
|
|
752
768
|
// around it — that would repeat its rows, which EXISTS is there to avoid.
|
|
753
769
|
case "exists": {
|
|
754
|
-
const
|
|
755
|
-
|
|
770
|
+
const i = Je(t.query);
|
|
771
|
+
k(t.link).filter((u) => !i.has(u)).forEach((u) => n.add(u));
|
|
756
772
|
break;
|
|
757
773
|
}
|
|
758
774
|
}
|
|
@@ -760,7 +776,7 @@ function I(e) {
|
|
|
760
776
|
return r(e), [...n];
|
|
761
777
|
}
|
|
762
778
|
function ie(e, n, r, t, o, s) {
|
|
763
|
-
const i =
|
|
779
|
+
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
780
|
id: G(),
|
|
765
781
|
table: r,
|
|
766
782
|
joinType: t ?? (l == null ? void 0 : l.joinType) ?? "inner",
|
|
@@ -770,7 +786,7 @@ function ie(e, n, r, t, o, s) {
|
|
|
770
786
|
return { ...n, joins: [...n.joins, c] };
|
|
771
787
|
}
|
|
772
788
|
function sn(e, n, r) {
|
|
773
|
-
const t =
|
|
789
|
+
const t = _(n);
|
|
774
790
|
if (t.includes(r)) return;
|
|
775
791
|
const o = Fn(e, t, r);
|
|
776
792
|
if (!o) return;
|
|
@@ -784,7 +800,7 @@ function st(e, n, r) {
|
|
|
784
800
|
return sn(e, n, r) ?? ie(e, n, r);
|
|
785
801
|
}
|
|
786
802
|
function L(e, n, r) {
|
|
787
|
-
return
|
|
803
|
+
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
804
|
}
|
|
789
805
|
function it(e, n, r, t) {
|
|
790
806
|
return {
|
|
@@ -810,7 +826,7 @@ function an(e) {
|
|
|
810
826
|
let r;
|
|
811
827
|
return e.joins.some((t) => {
|
|
812
828
|
n.add(v(t));
|
|
813
|
-
const o = t.joinType === "cross" ? void 0 : t.on, s =
|
|
829
|
+
const o = t.joinType === "cross" ? void 0 : t.on, s = k(o).find((i) => !n.has(i));
|
|
814
830
|
return s && (r = { table: t.table ?? v(t), needs: s }), s !== void 0;
|
|
815
831
|
}), r;
|
|
816
832
|
}
|
|
@@ -835,8 +851,8 @@ function lt(e, n, r, t) {
|
|
|
835
851
|
};
|
|
836
852
|
}
|
|
837
853
|
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]) ?
|
|
854
|
+
if (!n || !Rn(n)) return n;
|
|
855
|
+
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
856
|
if (s.type !== "exists") return s;
|
|
841
857
|
const { query: i } = s, { joins: u } = L(
|
|
842
858
|
e,
|
|
@@ -850,20 +866,20 @@ function ae(e, n) {
|
|
|
850
866
|
);
|
|
851
867
|
return u === i.joins ? s : { ...s, query: { ...i, joins: u } };
|
|
852
868
|
}
|
|
853
|
-
function
|
|
869
|
+
function Pt(e, n, r) {
|
|
854
870
|
const t = ae(e, r);
|
|
855
871
|
return { ...L(e, n, t), having: t };
|
|
856
872
|
}
|
|
857
|
-
function
|
|
873
|
+
function qe(e, n) {
|
|
858
874
|
const r = /* @__PURE__ */ new Set([
|
|
859
875
|
...n ? S(n).map(v) : [],
|
|
860
|
-
...
|
|
876
|
+
...R(e).map((o) => o.name)
|
|
861
877
|
]);
|
|
862
878
|
let t = 1;
|
|
863
879
|
for (; r.has(`sub_query_${t}`); ) t += 1;
|
|
864
880
|
return `sub_query_${t}`;
|
|
865
881
|
}
|
|
866
|
-
function
|
|
882
|
+
function Qt() {
|
|
867
883
|
return { id: E() };
|
|
868
884
|
}
|
|
869
885
|
function he(e, n, r) {
|
|
@@ -883,7 +899,7 @@ function he(e, n, r) {
|
|
|
883
899
|
...n,
|
|
884
900
|
from: {
|
|
885
901
|
id: r.id ?? G(),
|
|
886
|
-
alias:
|
|
902
|
+
alias: qe(e, n),
|
|
887
903
|
query: { from: Me(r), joins: [], select: [] }
|
|
888
904
|
}
|
|
889
905
|
};
|
|
@@ -899,7 +915,7 @@ function he(e, n, r) {
|
|
|
899
915
|
case "addDerivedJoin": {
|
|
900
916
|
const t = {
|
|
901
917
|
id: r.id ?? G(),
|
|
902
|
-
alias:
|
|
918
|
+
alias: qe(e, n),
|
|
903
919
|
joinType: "left",
|
|
904
920
|
query: { from: Me(r), joins: [], select: [] }
|
|
905
921
|
}, o = tn(e, n, t);
|
|
@@ -909,8 +925,8 @@ function he(e, n, r) {
|
|
|
909
925
|
const t = O(n).find((a) => a.id === r.derivedId), o = r.alias.trim();
|
|
910
926
|
if (!t || o === t.alias) return n;
|
|
911
927
|
const s = S(n).filter((a) => a !== t).map(v);
|
|
912
|
-
if (!o || o.length > D || s.includes(o) ||
|
|
913
|
-
const i =
|
|
928
|
+
if (!o || o.length > D || s.includes(o) || x(e, o)) return n;
|
|
929
|
+
const i = Ie(n, t.alias, o), { from: u } = i;
|
|
914
930
|
return {
|
|
915
931
|
...i,
|
|
916
932
|
from: u.query && u.id === t.id ? { ...u, alias: o } : u,
|
|
@@ -921,14 +937,14 @@ function he(e, n, r) {
|
|
|
921
937
|
const t = r.joinId === void 0 ? n.from : n.joins.find((u) => u.id === r.joinId), o = r.alias.trim();
|
|
922
938
|
if ((t == null ? void 0 : t.shared) === void 0 || o === t.alias) return n;
|
|
923
939
|
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:
|
|
940
|
+
if (!o || o.length > D || s.includes(o) || x(e, o)) return n;
|
|
941
|
+
const i = Ie(n, t.alias, o);
|
|
942
|
+
return r.joinId === void 0 ? { ...i, from: { ...i.from, alias: o } } : { ...i, joins: q(i.joins, r.joinId, (u) => ({ ...u, alias: o })) };
|
|
927
943
|
}
|
|
928
944
|
case "setMeasureSynced":
|
|
929
945
|
return {
|
|
930
946
|
...n,
|
|
931
|
-
joins:
|
|
947
|
+
joins: q(n.joins, r.joinId, (t) => t.query && t.drillAcross ? { ...t, drillAcross: { ...t.drillAcross, synced: r.synced } } : t)
|
|
932
948
|
};
|
|
933
949
|
case "removeJoin":
|
|
934
950
|
return { ...n, joins: n.joins.filter((t) => t.id !== r.joinId) };
|
|
@@ -936,19 +952,19 @@ function he(e, n, r) {
|
|
|
936
952
|
return {
|
|
937
953
|
...n,
|
|
938
954
|
// A CROSS JOIN uses no ON, but keeps it: switched back, it's used again.
|
|
939
|
-
joins:
|
|
955
|
+
joins: q(n.joins, r.joinId, (t) => ({ ...t, joinType: r.joinType }))
|
|
940
956
|
};
|
|
941
957
|
case "changeJoinAlias":
|
|
942
958
|
return fe(r.alias) ? {
|
|
943
959
|
...n,
|
|
944
960
|
// A derived table (or a shared query's place) goes by its alias: it
|
|
945
961
|
// can't be left without one.
|
|
946
|
-
joins:
|
|
962
|
+
joins: q(n.joins, r.joinId, (t) => t.table === void 0 ? { ...t, alias: r.alias || t.alias } : { ...t, alias: r.alias })
|
|
947
963
|
} : n;
|
|
948
964
|
case "changeJoinOn":
|
|
949
965
|
return {
|
|
950
966
|
...n,
|
|
951
|
-
joins:
|
|
967
|
+
joins: q(n.joins, r.joinId, (t) => ({
|
|
952
968
|
...t,
|
|
953
969
|
on: ae(e, r.on)
|
|
954
970
|
}))
|
|
@@ -1030,9 +1046,9 @@ function he(e, n, r) {
|
|
|
1030
1046
|
orderBy: (n.orderBy ?? []).map((t) => t.id === r.orderById ? { ...t, direction: r.direction } : t)
|
|
1031
1047
|
};
|
|
1032
1048
|
case "setLimit":
|
|
1033
|
-
return { ...n, limit:
|
|
1049
|
+
return { ...n, limit: Re(r.limit) };
|
|
1034
1050
|
case "setOffset":
|
|
1035
|
-
return { ...n, offset:
|
|
1051
|
+
return { ...n, offset: Re(r.offset) };
|
|
1036
1052
|
case "clearPaging":
|
|
1037
1053
|
return { ...n, limit: void 0, offset: void 0 };
|
|
1038
1054
|
/* v8 ignore start -- PipelineAction is a closed union; every real case is
|
|
@@ -1049,16 +1065,16 @@ const ct = {
|
|
|
1049
1065
|
full: "FULL",
|
|
1050
1066
|
cross: "CROSS"
|
|
1051
1067
|
};
|
|
1052
|
-
function
|
|
1068
|
+
function _t(e) {
|
|
1053
1069
|
return `${ct[e.joinType]} JOIN ${v(e)}`;
|
|
1054
1070
|
}
|
|
1055
|
-
function
|
|
1071
|
+
function Jt(e) {
|
|
1056
1072
|
return e.alias || "Column";
|
|
1057
1073
|
}
|
|
1058
|
-
function
|
|
1074
|
+
function Wt() {
|
|
1059
1075
|
return "Sort";
|
|
1060
1076
|
}
|
|
1061
|
-
function
|
|
1077
|
+
function Vt() {
|
|
1062
1078
|
return "Group";
|
|
1063
1079
|
}
|
|
1064
1080
|
function Ht(e, n, r) {
|
|
@@ -1067,19 +1083,19 @@ function Ht(e, n, r) {
|
|
|
1067
1083
|
const a = t.findIndex((l) => "id" in l && l.id === r);
|
|
1068
1084
|
return new Set(t.slice(0, a + 1).map(v));
|
|
1069
1085
|
}
|
|
1070
|
-
const o = new Set(
|
|
1086
|
+
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
1087
|
return /* @__PURE__ */ new Set([...t.map(v), ...u.map((a) => a.name)]);
|
|
1072
1088
|
}
|
|
1073
|
-
function
|
|
1089
|
+
function Kt(e, n) {
|
|
1074
1090
|
const r = S(n);
|
|
1075
|
-
return
|
|
1091
|
+
return R(e).flatMap((t) => {
|
|
1076
1092
|
const o = r.filter((s) => s.table === t.name).map(v);
|
|
1077
1093
|
return (o.length > 0 ? o : [t.name]).map((s) => ({ ref: s, table: t }));
|
|
1078
1094
|
});
|
|
1079
1095
|
}
|
|
1080
|
-
function
|
|
1081
|
-
const r = new Set(
|
|
1082
|
-
return
|
|
1096
|
+
function Xt(e, n) {
|
|
1097
|
+
const r = new Set(_(n));
|
|
1098
|
+
return R(e).filter((t) => !r.has(t.name));
|
|
1083
1099
|
}
|
|
1084
1100
|
function be(e) {
|
|
1085
1101
|
return e ? e.type === "logical" ? e.operands.reduce((n, r) => n + be(r), 0) : e.type === "not" ? be(e.operand) : 1 : 0;
|
|
@@ -1092,8 +1108,8 @@ function Yt(e, n = et) {
|
|
|
1092
1108
|
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
1109
|
}
|
|
1094
1110
|
function zt(e, n) {
|
|
1095
|
-
const r = new Set(
|
|
1096
|
-
return
|
|
1111
|
+
const r = new Set(k(e.where));
|
|
1112
|
+
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
1113
|
}
|
|
1098
1114
|
function Zt(e, n, r) {
|
|
1099
1115
|
const t = ae(e, r);
|
|
@@ -1102,14 +1118,14 @@ function Zt(e, n, r) {
|
|
|
1102
1118
|
function er(e, n, r, t) {
|
|
1103
1119
|
return r.length === 0 ? he(e, n, t) : U(n) ? ze(n, r, (o) => he(e, o, t)) : n;
|
|
1104
1120
|
}
|
|
1105
|
-
const un = (e) => e.query !== void 0 &&
|
|
1121
|
+
const un = (e) => e.query !== void 0 && !$(e.query);
|
|
1106
1122
|
function ln(e) {
|
|
1107
1123
|
const n = /* @__PURE__ */ new Map();
|
|
1108
1124
|
return e.relations.forEach((r) => {
|
|
1109
1125
|
n.set(r.fromTable, [...n.get(r.fromTable) ?? [], r.toTable]);
|
|
1110
1126
|
}), n;
|
|
1111
1127
|
}
|
|
1112
|
-
function
|
|
1128
|
+
function J(e, n, r = ln(e)) {
|
|
1113
1129
|
const t = /* @__PURE__ */ new Set([n]), o = [n];
|
|
1114
1130
|
for (let s = o.shift(); s !== void 0; s = o.shift())
|
|
1115
1131
|
(r.get(s) ?? []).forEach((i) => {
|
|
@@ -1120,12 +1136,12 @@ function P(e, n, r = ln(e)) {
|
|
|
1120
1136
|
const j = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [];
|
|
1121
1137
|
function cn(e, n) {
|
|
1122
1138
|
const r = new Map(S(e).map((t) => [v(t), t.table]));
|
|
1123
|
-
return
|
|
1139
|
+
return k(n).map((t) => ({
|
|
1124
1140
|
ref: t,
|
|
1125
1141
|
table: r.has(t) ? r.get(t) : t
|
|
1126
1142
|
}));
|
|
1127
1143
|
}
|
|
1128
|
-
const
|
|
1144
|
+
const $e = (e, n) => cn(e, n).map((r) => r.table);
|
|
1129
1145
|
function Fe(e, n) {
|
|
1130
1146
|
const r = new Map(S(e).map((t) => [v(t), t.table]));
|
|
1131
1147
|
return Ne(n, (t) => {
|
|
@@ -1136,26 +1152,26 @@ function Fe(e, n) {
|
|
|
1136
1152
|
}
|
|
1137
1153
|
function dn(e, n) {
|
|
1138
1154
|
const r = (n.groupBy ?? []).flatMap((o) => cn(n, o.expression)), t = ln(e);
|
|
1139
|
-
return
|
|
1140
|
-
const s =
|
|
1155
|
+
return R(e).map((o) => {
|
|
1156
|
+
const s = J(e, o.name, t), i = r.find((u) => u.table === void 0 || !s.has(u.table));
|
|
1141
1157
|
return i ? { table: o, unlinked: i.table ?? i.ref } : { table: o };
|
|
1142
1158
|
});
|
|
1143
1159
|
}
|
|
1144
1160
|
function dt(e, n, r) {
|
|
1145
|
-
const t =
|
|
1161
|
+
const t = J(e, r);
|
|
1146
1162
|
return j(n.where).filter((o) => {
|
|
1147
|
-
const s =
|
|
1163
|
+
const s = $e(n, o);
|
|
1148
1164
|
return s.length > 0 && s.every((i) => i !== void 0 && t.has(i));
|
|
1149
1165
|
});
|
|
1150
1166
|
}
|
|
1151
1167
|
function nr(e, n, r) {
|
|
1152
|
-
const t =
|
|
1168
|
+
const t = J(e, r);
|
|
1153
1169
|
return j(n.where).some((o) => {
|
|
1154
|
-
const s =
|
|
1170
|
+
const s = $e(n, o);
|
|
1155
1171
|
return s.some((i) => i !== void 0 && t.has(i)) && s.some((i) => i === void 0 || !t.has(i));
|
|
1156
1172
|
});
|
|
1157
1173
|
}
|
|
1158
|
-
function
|
|
1174
|
+
function K(e, n) {
|
|
1159
1175
|
let r = e;
|
|
1160
1176
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1161
1177
|
return r;
|
|
@@ -1194,7 +1210,7 @@ function ft(e, n) {
|
|
|
1194
1210
|
function mt(e, n, r) {
|
|
1195
1211
|
var s;
|
|
1196
1212
|
if (r.type !== "field" || r.table === void 0 || r.column === void 0) return !1;
|
|
1197
|
-
const t =
|
|
1213
|
+
const t = $e(n, r)[0], o = (s = x(e, t)) == null ? void 0 : s.columns.find((i) => i.name === r.column);
|
|
1198
1214
|
return o !== void 0 && !o.nullable;
|
|
1199
1215
|
}
|
|
1200
1216
|
function fn(e, n, r, t) {
|
|
@@ -1209,7 +1225,7 @@ function fn(e, n, r, t) {
|
|
|
1209
1225
|
function mn(e, n, r, t, o, s) {
|
|
1210
1226
|
var b;
|
|
1211
1227
|
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 =
|
|
1228
|
+
const T = K(ge(y, `key_${w + 1}`), a);
|
|
1213
1229
|
return a.add(T), T;
|
|
1214
1230
|
}), c = [...u, ...t];
|
|
1215
1231
|
let d = {
|
|
@@ -1222,7 +1238,7 @@ function mn(e, n, r, t, o, s) {
|
|
|
1222
1238
|
d = L(e, d, y);
|
|
1223
1239
|
});
|
|
1224
1240
|
const f = ((b = s == null ? void 0 : s.groupBy) == null ? void 0 : b.length) ?? 0, m = [...(s == null ? void 0 : s.joins) ?? []], g = d.joins.map((y) => {
|
|
1225
|
-
const w = m.findIndex((
|
|
1241
|
+
const w = m.findIndex((C) => C.table !== void 0 && C.table === y.table);
|
|
1226
1242
|
if (w === -1) return y;
|
|
1227
1243
|
const [T] = m.splice(w, 1);
|
|
1228
1244
|
return { ...y, id: T.id };
|
|
@@ -1232,9 +1248,9 @@ function mn(e, n, r, t, o, s) {
|
|
|
1232
1248
|
joins: g,
|
|
1233
1249
|
where: c.length > 0 ? { type: "logical", operator: "AND", operands: c } : void 0,
|
|
1234
1250
|
groupBy: i.map((y, w) => {
|
|
1235
|
-
var T,
|
|
1251
|
+
var T, C;
|
|
1236
1252
|
return {
|
|
1237
|
-
id: ((
|
|
1253
|
+
id: ((C = (T = s == null ? void 0 : s.groupBy) == null ? void 0 : T[w]) == null ? void 0 : C.id) ?? E(),
|
|
1238
1254
|
expression: y
|
|
1239
1255
|
};
|
|
1240
1256
|
}),
|
|
@@ -1271,7 +1287,7 @@ function tr(e, n, r) {
|
|
|
1271
1287
|
if (b)
|
|
1272
1288
|
a = b.alias;
|
|
1273
1289
|
else {
|
|
1274
|
-
a =
|
|
1290
|
+
a = K(
|
|
1275
1291
|
ge(r.value, "value"),
|
|
1276
1292
|
new Set(s.query.select.map((w) => w.alias ?? ""))
|
|
1277
1293
|
);
|
|
@@ -1282,9 +1298,9 @@ function tr(e, n, r) {
|
|
|
1282
1298
|
a = ge(r.value, "value");
|
|
1283
1299
|
const p = { id: E(), alias: a, expression: r.value }, b = mn(e, n, r.table, o, [p]), y = /* @__PURE__ */ new Set([
|
|
1284
1300
|
...S(n).map(v),
|
|
1285
|
-
...
|
|
1301
|
+
...R(e).map((C) => C.name)
|
|
1286
1302
|
]), w = `${r.table}_per_${b.keyNames.join("_and_")}`.slice(0, D - 4);
|
|
1287
|
-
u =
|
|
1303
|
+
u = K(w, y);
|
|
1288
1304
|
const T = {
|
|
1289
1305
|
id: E(),
|
|
1290
1306
|
alias: u,
|
|
@@ -1299,7 +1315,7 @@ function tr(e, n, r) {
|
|
|
1299
1315
|
type: "function",
|
|
1300
1316
|
name: "MAX",
|
|
1301
1317
|
args: [we(u, a)]
|
|
1302
|
-
}, c = new Set(n.select.map((p) => p.alias).filter((p) => !!p)), d =
|
|
1318
|
+
}, c = new Set(n.select.map((p) => p.alias).filter((p) => !!p)), d = K(`${r.table}_${a}`.slice(0, D - 4), c);
|
|
1303
1319
|
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
1320
|
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
1321
|
}
|
|
@@ -1338,7 +1354,7 @@ function yn(e, n, r) {
|
|
|
1338
1354
|
a,
|
|
1339
1355
|
(l, c) => yn(
|
|
1340
1356
|
e,
|
|
1341
|
-
u &&
|
|
1357
|
+
u && $(u) === $(a) ? Y(u)[c] : void 0,
|
|
1342
1358
|
l
|
|
1343
1359
|
)
|
|
1344
1360
|
), s = r.from.query ? (() => {
|
|
@@ -1394,7 +1410,7 @@ function hn(e) {
|
|
|
1394
1410
|
if (typeof n == "number") return Number.isInteger(n) ? "integer" : "number";
|
|
1395
1411
|
if (typeof n == "bigint") return "integer";
|
|
1396
1412
|
if (typeof n == "boolean") return "boolean";
|
|
1397
|
-
if (n instanceof Date) return
|
|
1413
|
+
if (n instanceof Date) return Ve(n) ? "date" : "dateTime";
|
|
1398
1414
|
}
|
|
1399
1415
|
function bn(e, n, r) {
|
|
1400
1416
|
if (!e) return;
|
|
@@ -1405,7 +1421,7 @@ function bn(e, n, r) {
|
|
|
1405
1421
|
case "literal":
|
|
1406
1422
|
return hn(e);
|
|
1407
1423
|
case "function": {
|
|
1408
|
-
const o =
|
|
1424
|
+
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
1425
|
if ((i == null ? void 0 : i.type) === "literal" && typeof i.value == "string")
|
|
1410
1426
|
return bt(i.value);
|
|
1411
1427
|
const u = o == null ? void 0 : o.returns;
|
|
@@ -1425,7 +1441,7 @@ function gn(e, n) {
|
|
|
1425
1441
|
const r = typeof e == "string" ? e.trim() : void 0;
|
|
1426
1442
|
switch (n) {
|
|
1427
1443
|
case "text":
|
|
1428
|
-
return e instanceof Date ?
|
|
1444
|
+
return e instanceof Date ? Jn(e) : String(e);
|
|
1429
1445
|
case "integer":
|
|
1430
1446
|
case "number": {
|
|
1431
1447
|
let t;
|
|
@@ -1433,10 +1449,10 @@ function gn(e, n) {
|
|
|
1433
1449
|
}
|
|
1434
1450
|
case "date":
|
|
1435
1451
|
case "dateTime": {
|
|
1436
|
-
if (e instanceof Date) return n === "date" && !
|
|
1452
|
+
if (e instanceof Date) return n === "date" && !Ve(e) ? void 0 : e;
|
|
1437
1453
|
const t = r === void 0 ? null : St.exec(r);
|
|
1438
1454
|
if (!t) return;
|
|
1439
|
-
const [, o, s, i, u, a, l] = t.map(Number), c =
|
|
1455
|
+
const [, o, s, i, u, a, l] = t.map(Number), c = _n(o, s, i);
|
|
1440
1456
|
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
1457
|
}
|
|
1442
1458
|
case "time": {
|
|
@@ -1495,15 +1511,15 @@ function ur(e, n = !1) {
|
|
|
1495
1511
|
"IS NOT NULL"
|
|
1496
1512
|
] : e === "boolean" ? ["=", "!=", me, "IS NULL", "IS NOT NULL"] : ["=", "!=", me, "<", "<=", ">", ">=", "IN", "BETWEEN", "IS NULL", "IS NOT NULL"];
|
|
1497
1513
|
}
|
|
1498
|
-
const wn = "source", Sn = "rows_", B = (e) => e ? { type: "literal", value: null, as: e } : { type: "literal", value: null }, F = (e) => e.type === "literal" && e.value === null,
|
|
1514
|
+
const wn = "source", Sn = "rows_", B = (e) => e ? { type: "literal", value: null, as: e } : { type: "literal", value: null }, F = (e) => e.type === "literal" && e.value === null, Ce = (e) => new Map(
|
|
1499
1515
|
S(e).map((n) => [v(n), n.table])
|
|
1500
1516
|
);
|
|
1501
1517
|
function Se(e, n) {
|
|
1502
|
-
const r =
|
|
1503
|
-
return
|
|
1518
|
+
const r = Ce(e);
|
|
1519
|
+
return k(n).map((t) => r.get(t) ?? t);
|
|
1504
1520
|
}
|
|
1505
1521
|
function vn(e, n) {
|
|
1506
|
-
const r =
|
|
1522
|
+
const r = Ce(e);
|
|
1507
1523
|
return Ne(n, (t) => {
|
|
1508
1524
|
if (t.type !== "field" || t.table === void 0) return t;
|
|
1509
1525
|
const o = r.get(t.table);
|
|
@@ -1511,14 +1527,14 @@ function vn(e, n) {
|
|
|
1511
1527
|
});
|
|
1512
1528
|
}
|
|
1513
1529
|
function Z(e, n, r) {
|
|
1514
|
-
const t =
|
|
1530
|
+
const t = Ce(n);
|
|
1515
1531
|
return bn(r, (o) => {
|
|
1516
1532
|
var u;
|
|
1517
|
-
const s = t.get(o.table ?? "") ?? o.table ?? "", i = (u =
|
|
1533
|
+
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
1534
|
return i && ht(i.type);
|
|
1519
|
-
},
|
|
1535
|
+
}, P);
|
|
1520
1536
|
}
|
|
1521
|
-
function
|
|
1537
|
+
function Ae(e, n) {
|
|
1522
1538
|
let r = e;
|
|
1523
1539
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1524
1540
|
return r;
|
|
@@ -1526,17 +1542,17 @@ function xe(e, n) {
|
|
|
1526
1542
|
const ee = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [], Tn = (e) => {
|
|
1527
1543
|
if (e.length !== 0)
|
|
1528
1544
|
return e.length === 1 ? e[0] : { type: "logical", operator: "AND", operands: e };
|
|
1529
|
-
},
|
|
1545
|
+
}, I = (e) => e.from.table, Pe = (e, n) => x(e, n).label;
|
|
1530
1546
|
function ue(e) {
|
|
1531
1547
|
const { from: n } = e;
|
|
1532
|
-
return n.query &&
|
|
1548
|
+
return n.query && $(n.query) ? n : void 0;
|
|
1533
1549
|
}
|
|
1534
|
-
function
|
|
1550
|
+
function W(e, n) {
|
|
1535
1551
|
if (n === void 0) return ue(e);
|
|
1536
1552
|
const r = O(e).find((t) => t.id === n);
|
|
1537
|
-
return r &&
|
|
1553
|
+
return r && $(r.query) ? r : void 0;
|
|
1538
1554
|
}
|
|
1539
|
-
function
|
|
1555
|
+
function V(e, n, r) {
|
|
1540
1556
|
const t = { ...n, query: r };
|
|
1541
1557
|
return n === e.from ? { ...e, from: t } : { ...e, joins: e.joins.map((o) => o === n ? t : o) };
|
|
1542
1558
|
}
|
|
@@ -1544,7 +1560,7 @@ function le(e, n) {
|
|
|
1544
1560
|
const [r] = n;
|
|
1545
1561
|
return r.select.map((t, o) => {
|
|
1546
1562
|
var d;
|
|
1547
|
-
const s =
|
|
1563
|
+
const s = A(t) ?? "", i = n.map((f) => {
|
|
1548
1564
|
var m;
|
|
1549
1565
|
return { branch: f, expression: (m = f.select[o]) == null ? void 0 : m.expression };
|
|
1550
1566
|
}).filter((f) => f.expression !== void 0 && !F(f.expression)), a = ((d = n.map((f) => {
|
|
@@ -1576,7 +1592,7 @@ function le(e, n) {
|
|
|
1576
1592
|
type: a
|
|
1577
1593
|
};
|
|
1578
1594
|
const c = Se(l.branch, l.expression);
|
|
1579
|
-
return i.some((f) => Se(f.branch, f.expression).includes(
|
|
1595
|
+
return i.some((f) => Se(f.branch, f.expression).includes(I(f.branch))) ? {
|
|
1580
1596
|
name: s,
|
|
1581
1597
|
kind: "own",
|
|
1582
1598
|
tables: c,
|
|
@@ -1599,13 +1615,13 @@ function lr(e, n) {
|
|
|
1599
1615
|
return {
|
|
1600
1616
|
name: o.name,
|
|
1601
1617
|
kind: o.kind,
|
|
1602
|
-
filledBy: t.filter((u, a) => i[a]).map(
|
|
1603
|
-
nullIn: t.filter((u, a) => !i[a]).map(
|
|
1618
|
+
filledBy: t.filter((u, a) => i[a]).map(I),
|
|
1619
|
+
nullIn: t.filter((u, a) => !i[a]).map(I)
|
|
1604
1620
|
};
|
|
1605
1621
|
});
|
|
1606
1622
|
}
|
|
1607
1623
|
function Nn(e, n, r, t, o) {
|
|
1608
|
-
const s =
|
|
1624
|
+
const s = J(e, n), i = r.filter((c) => c.kind === "shared" && c.expression), u = (c) => c.tables.every((d) => s.has(d));
|
|
1609
1625
|
if (!i.some(u)) return `"${n}" shares no column with the union`;
|
|
1610
1626
|
const a = i.find((c) => !u(c));
|
|
1611
1627
|
if (a && o === "refuse")
|
|
@@ -1615,7 +1631,7 @@ function Nn(e, n, r, t, o) {
|
|
|
1615
1631
|
return `"${n}" can't follow a condition on ${l.tables.join(", ")}`;
|
|
1616
1632
|
}
|
|
1617
1633
|
function En(e) {
|
|
1618
|
-
const [n] = e, r = new Set(e.map(
|
|
1634
|
+
const [n] = e, r = new Set(e.map(I));
|
|
1619
1635
|
return ee(n.where).flatMap((t) => {
|
|
1620
1636
|
const o = Se(n, t), s = o.filter((i) => r.has(i));
|
|
1621
1637
|
if (s.length === 0) return [{ operand: vn(n, t), tables: o }];
|
|
@@ -1623,16 +1639,16 @@ function En(e) {
|
|
|
1623
1639
|
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
1640
|
});
|
|
1625
1641
|
}
|
|
1626
|
-
function
|
|
1642
|
+
function Qe(e, n, r, t) {
|
|
1627
1643
|
const o = t.unshared ?? "refuse", s = le(e, n), i = En(n);
|
|
1628
|
-
if (!
|
|
1644
|
+
if (!x(e, r.table))
|
|
1629
1645
|
throw new Error(`addUnionTable: unknown table "${r.table}"`);
|
|
1630
|
-
if (n.some((h) =>
|
|
1646
|
+
if (n.some((h) => I(h) === r.table))
|
|
1631
1647
|
throw new Error(`addUnionTable: "${r.table}" is in the union already`);
|
|
1632
1648
|
const u = Nn(e, r.table, s, i, o);
|
|
1633
1649
|
if (u) throw new Error(`addUnionTable: ${u}`);
|
|
1634
|
-
const a =
|
|
1635
|
-
const N =
|
|
1650
|
+
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) => {
|
|
1651
|
+
const N = Ae(h, d);
|
|
1636
1652
|
return d.add(N), f.push(N), N;
|
|
1637
1653
|
}, g = [], p = {
|
|
1638
1654
|
from: { table: r.table },
|
|
@@ -1644,12 +1660,12 @@ function _e(e, n, r, t) {
|
|
|
1644
1660
|
}), t.source && !s.some((h) => h.kind === "source") && g.push({
|
|
1645
1661
|
name: m(wn),
|
|
1646
1662
|
own: { type: "literal", value: l },
|
|
1647
|
-
others: (h) => ({ type: "literal", value:
|
|
1663
|
+
others: (h) => ({ type: "literal", value: Pe(e, I(h)) })
|
|
1648
1664
|
});
|
|
1649
1665
|
const b = (h) => `${Sn}${h}`;
|
|
1650
|
-
(t.rowMarkers || s.some((h) => h.kind === "rows")) && (n.filter((h) => !d.has(b(
|
|
1666
|
+
(t.rowMarkers || s.some((h) => h.kind === "rows")) && (n.filter((h) => !d.has(b(I(h)))).forEach((h) => {
|
|
1651
1667
|
g.push({
|
|
1652
|
-
name: m(b(
|
|
1668
|
+
name: m(b(I(h))),
|
|
1653
1669
|
own: B("integer"),
|
|
1654
1670
|
others: (N) => N === h ? { type: "literal", value: 1 } : B("integer")
|
|
1655
1671
|
});
|
|
@@ -1666,7 +1682,7 @@ function _e(e, n, r, t) {
|
|
|
1666
1682
|
...h,
|
|
1667
1683
|
select: [...h.select, ...g.map((N) => y(N.name, N.others(h)))]
|
|
1668
1684
|
})), T = Tn([...i.map((h) => h.operand), ...ee(r.where)]);
|
|
1669
|
-
let
|
|
1685
|
+
let C = {
|
|
1670
1686
|
id: "",
|
|
1671
1687
|
from: { table: r.table },
|
|
1672
1688
|
joins: [],
|
|
@@ -1676,15 +1692,15 @@ function _e(e, n, r, t) {
|
|
|
1676
1692
|
...g.map((h) => y(h.name, h.own))
|
|
1677
1693
|
]
|
|
1678
1694
|
};
|
|
1679
|
-
[T,
|
|
1680
|
-
|
|
1695
|
+
[T, ...C.select.map((h) => h.expression)].forEach((h) => {
|
|
1696
|
+
C = L(e, C, h);
|
|
1681
1697
|
});
|
|
1682
1698
|
const {
|
|
1683
1699
|
from: Mn,
|
|
1684
1700
|
joins: On,
|
|
1685
1701
|
select: Un,
|
|
1686
1702
|
where: Be
|
|
1687
|
-
} =
|
|
1703
|
+
} = C, Ln = {
|
|
1688
1704
|
from: Mn,
|
|
1689
1705
|
joins: On,
|
|
1690
1706
|
select: Un,
|
|
@@ -1692,14 +1708,14 @@ function _e(e, n, r, t) {
|
|
|
1692
1708
|
};
|
|
1693
1709
|
return { union: [...w, Ln], added: f };
|
|
1694
1710
|
}
|
|
1695
|
-
function
|
|
1711
|
+
function $n(e) {
|
|
1696
1712
|
const n = (o) => new Error(`addUnionTable: ${o}`);
|
|
1697
1713
|
if (e.from.query) throw n("the query reads from a derived table");
|
|
1698
1714
|
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,
|
|
1715
|
+
if ((e.groupBy ?? []).length > 0 || e.having || e.distinct || (e.orderBy ?? []).length > 0 || e.select.some((o) => ne(o.expression, P)))
|
|
1700
1716
|
throw n("a union is of detail rows: no aggregates, GROUP BY, HAVING, DISTINCT or ORDER BY");
|
|
1701
1717
|
const r = /* @__PURE__ */ new Set(), t = e.select.map((o, s) => {
|
|
1702
|
-
const i =
|
|
1718
|
+
const i = Ae(A(o) ?? `column_${s + 1}`, r);
|
|
1703
1719
|
return r.add(i), { ...o, alias: i };
|
|
1704
1720
|
});
|
|
1705
1721
|
return {
|
|
@@ -1712,7 +1728,7 @@ function Cn(e) {
|
|
|
1712
1728
|
function cr(e, n, r, t = {}) {
|
|
1713
1729
|
const o = ue(n);
|
|
1714
1730
|
if (o) {
|
|
1715
|
-
const { union: l, added: c } =
|
|
1731
|
+
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
1732
|
...n.select,
|
|
1717
1733
|
...c.map((m) => ({
|
|
1718
1734
|
id: E(),
|
|
@@ -1721,7 +1737,7 @@ function cr(e, n, r, t = {}) {
|
|
|
1721
1737
|
];
|
|
1722
1738
|
return { ...n, from: d, select: f };
|
|
1723
1739
|
}
|
|
1724
|
-
const s =
|
|
1740
|
+
const s = $n(n), { union: i } = Qe(e, [s], r, t), u = t.alias ?? "stacked", a = i[0].select.map((l) => l.alias);
|
|
1725
1741
|
return {
|
|
1726
1742
|
id: n.id,
|
|
1727
1743
|
from: { id: E(), alias: u, query: { union: i, all: !0 } },
|
|
@@ -1738,7 +1754,7 @@ function dr(e, n, r = {}) {
|
|
|
1738
1754
|
const t = ue(n);
|
|
1739
1755
|
let o;
|
|
1740
1756
|
try {
|
|
1741
|
-
o = t ? t.query.union : [
|
|
1757
|
+
o = t ? t.query.union : [$n(n)];
|
|
1742
1758
|
} catch {
|
|
1743
1759
|
return [];
|
|
1744
1760
|
}
|
|
@@ -1750,7 +1766,7 @@ function dr(e, n, r = {}) {
|
|
|
1750
1766
|
return [];
|
|
1751
1767
|
}
|
|
1752
1768
|
const u = /* @__PURE__ */ new Set([
|
|
1753
|
-
...o.map(
|
|
1769
|
+
...o.map(I),
|
|
1754
1770
|
...s.flatMap((a) => a.kind === "shared" ? a.tables : [])
|
|
1755
1771
|
]);
|
|
1756
1772
|
return e.tables.map((a) => a.name).filter((a) => !u.has(a) && Nn(e, a, s, i, r.unshared ?? "refuse") === void 0);
|
|
@@ -1761,11 +1777,11 @@ function Tt(e, n, r) {
|
|
|
1761
1777
|
const o = r.union[t], s = n.union[t].select.map((a) => a.id), i = r.union.map((a, l) => {
|
|
1762
1778
|
if (l === t) return a;
|
|
1763
1779
|
const c = o.select.map((f) => {
|
|
1764
|
-
const m =
|
|
1780
|
+
const m = A(f), g = Z(e, o, f.expression), p = s.indexOf(f.id), b = p === -1 ? void 0 : a.select[p];
|
|
1765
1781
|
if (!b)
|
|
1766
1782
|
return { id: E(), ...m ? { alias: m } : {}, expression: B(g) };
|
|
1767
1783
|
let y = b;
|
|
1768
|
-
|
|
1784
|
+
A(b) !== m && (y = { ...y, alias: m });
|
|
1769
1785
|
const { expression: w } = b;
|
|
1770
1786
|
return F(w) && w.type === "literal" && w.as !== g && (y = { ...y, expression: B(g) }), y;
|
|
1771
1787
|
});
|
|
@@ -1786,26 +1802,26 @@ function Tt(e, n, r) {
|
|
|
1786
1802
|
return u.every((a, l) => a === r.union[l]) ? r : { ...r, union: u };
|
|
1787
1803
|
}
|
|
1788
1804
|
function Nt(e, n) {
|
|
1789
|
-
const r = (s) => s.union[0].select.map((i) =>
|
|
1805
|
+
const r = (s) => s.union[0].select.map((i) => A(i)), t = r(e), o = r(n);
|
|
1790
1806
|
return t.length !== o.length ? [] : t.flatMap((s, i) => {
|
|
1791
1807
|
const u = o[i];
|
|
1792
1808
|
return s && u && s !== u && !o.includes(s) && !t.includes(u) ? [{ from: s, to: u }] : [];
|
|
1793
1809
|
});
|
|
1794
1810
|
}
|
|
1795
|
-
function
|
|
1811
|
+
function Cn(e, n, r) {
|
|
1796
1812
|
let t = r;
|
|
1797
|
-
n &&
|
|
1813
|
+
n && $(n) && $(t) && n.union.length === t.union.length && (t = Tt(e, n, t));
|
|
1798
1814
|
const o = t;
|
|
1799
|
-
return se(o, (s, i) =>
|
|
1815
|
+
return se(o, (s, i) => xe(
|
|
1800
1816
|
e,
|
|
1801
|
-
n &&
|
|
1817
|
+
n && $(n) === $(o) ? Y(n)[i] : void 0,
|
|
1802
1818
|
s
|
|
1803
1819
|
));
|
|
1804
1820
|
}
|
|
1805
|
-
function
|
|
1821
|
+
function xe(e, n, r) {
|
|
1806
1822
|
const t = (f) => {
|
|
1807
1823
|
var m;
|
|
1808
|
-
return
|
|
1824
|
+
return Cn(
|
|
1809
1825
|
e,
|
|
1810
1826
|
n && ((m = O(n).find((g) => g.id === f.id)) == null ? void 0 : m.query),
|
|
1811
1827
|
f.query
|
|
@@ -1821,11 +1837,11 @@ function Ae(e, n, r) {
|
|
|
1821
1837
|
const l = { ...r, from: i, joins: a }, c = O(l).flatMap((f) => {
|
|
1822
1838
|
var g;
|
|
1823
1839
|
const m = n && ((g = O(n).find((p) => p.id === f.id)) == null ? void 0 : g.query);
|
|
1824
|
-
return m &&
|
|
1840
|
+
return m && $(m) && $(f.query) ? Nt(m, f.query).map((p) => ({ ...p, alias: f.alias })) : [];
|
|
1825
1841
|
});
|
|
1826
1842
|
if (c.length === 0) return l;
|
|
1827
1843
|
const d = (f) => {
|
|
1828
|
-
if (f.type !== "field") return
|
|
1844
|
+
if (f.type !== "field") return Q(f, d);
|
|
1829
1845
|
const m = c.find((g) => g.alias === f.table && g.from === f.column);
|
|
1830
1846
|
return m ? { ...f, column: m.to } : f;
|
|
1831
1847
|
};
|
|
@@ -1834,20 +1850,20 @@ function Ae(e, n, r) {
|
|
|
1834
1850
|
function Et(e, n, r) {
|
|
1835
1851
|
if (!U(r)) return r;
|
|
1836
1852
|
const t = n && U(n) ? n : void 0;
|
|
1837
|
-
return Te(
|
|
1853
|
+
return Te(xe(e, t, r), (o, s) => {
|
|
1838
1854
|
var i, u;
|
|
1839
|
-
return
|
|
1855
|
+
return Cn(
|
|
1840
1856
|
e,
|
|
1841
1857
|
(u = (i = t == null ? void 0 : t.shared) == null ? void 0 : i.find((a) => a.id === s.id)) == null ? void 0 : u.query,
|
|
1842
1858
|
o
|
|
1843
1859
|
);
|
|
1844
1860
|
});
|
|
1845
1861
|
}
|
|
1846
|
-
function
|
|
1847
|
-
return e.type === "field" ? [e] : oe(e).flatMap(
|
|
1862
|
+
function An(e) {
|
|
1863
|
+
return e.type === "field" ? [e] : oe(e).flatMap(An);
|
|
1848
1864
|
}
|
|
1849
|
-
const
|
|
1850
|
-
function
|
|
1865
|
+
const xn = (e, n, r) => An(e).some((t) => t.table === n && r.has(t.column ?? ""));
|
|
1866
|
+
function $t(e, n, r) {
|
|
1851
1867
|
const t = n.query.union.filter((a, l) => l !== r), o = [
|
|
1852
1868
|
e.where,
|
|
1853
1869
|
e.having,
|
|
@@ -1855,25 +1871,25 @@ function Ct(e, n, r) {
|
|
|
1855
1871
|
...(e.groupBy ?? []).map((a) => a.expression),
|
|
1856
1872
|
...(e.orderBy ?? []).map((a) => a.expression)
|
|
1857
1873
|
].filter((a) => a !== void 0), s = (a) => o.some(
|
|
1858
|
-
(l) =>
|
|
1874
|
+
(l) => xn(l, n.alias, /* @__PURE__ */ new Set([a]))
|
|
1859
1875
|
), i = new Set(t[0].select.flatMap((a, l) => {
|
|
1860
|
-
const c = t.every((f) => f.select[l] && F(f.select[l].expression)), d =
|
|
1876
|
+
const c = t.every((f) => f.select[l] && F(f.select[l].expression)), d = A(a);
|
|
1861
1877
|
return c && !(d && s(d)) ? [l] : [];
|
|
1862
1878
|
})), u = new Set([...i].flatMap((a) => {
|
|
1863
|
-
const l =
|
|
1879
|
+
const l = A(t[0].select[a]);
|
|
1864
1880
|
return l ? [l] : [];
|
|
1865
1881
|
}));
|
|
1866
1882
|
return { at: i, names: u };
|
|
1867
1883
|
}
|
|
1868
1884
|
function fr(e, n, r) {
|
|
1869
|
-
const t =
|
|
1885
|
+
const t = W(e, r);
|
|
1870
1886
|
if (!t || !t.query.union[n] || t.query.union.length < 2) return e;
|
|
1871
|
-
const o =
|
|
1872
|
-
(l) => !
|
|
1887
|
+
const o = $t(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(
|
|
1888
|
+
(l) => !xn(l.expression, t.alias, i.names)
|
|
1873
1889
|
), a = s.map((l) => ({ ...l, select: l.select.filter((c, d) => !i.at.has(d)) }));
|
|
1874
|
-
return
|
|
1890
|
+
return V({ ...e, select: u }, t, { ...t.query, union: a });
|
|
1875
1891
|
}
|
|
1876
|
-
function
|
|
1892
|
+
function Ct(e, n) {
|
|
1877
1893
|
const r = /* @__PURE__ */ new Set([
|
|
1878
1894
|
...n ? S(n).map(v) : [],
|
|
1879
1895
|
...e.tables.map((o) => o.name)
|
|
@@ -1892,7 +1908,7 @@ function mr(e, n, r, t) {
|
|
|
1892
1908
|
}
|
|
1893
1909
|
function pr(e, n, r) {
|
|
1894
1910
|
const t = /* @__PURE__ */ new Set(), o = e.select.map((p, b) => {
|
|
1895
|
-
const y =
|
|
1911
|
+
const y = Ae(A(p) ?? `column_${b + 1}`, t);
|
|
1896
1912
|
return t.add(y), { ...p, alias: y };
|
|
1897
1913
|
}), {
|
|
1898
1914
|
from: s,
|
|
@@ -1927,14 +1943,14 @@ function pr(e, n, r) {
|
|
|
1927
1943
|
return ["where", "groupBy", "having", "distinct"].forEach((p) => delete g[p]), g;
|
|
1928
1944
|
}
|
|
1929
1945
|
function yr(e, n, r, t) {
|
|
1930
|
-
const o =
|
|
1946
|
+
const o = W(n, r);
|
|
1931
1947
|
if (!o) return n;
|
|
1932
1948
|
const s = le(e, o.query.union).map((i) => ({
|
|
1933
1949
|
id: E(),
|
|
1934
1950
|
...i.name ? { alias: i.name } : {},
|
|
1935
1951
|
expression: B(i.type)
|
|
1936
1952
|
}));
|
|
1937
|
-
return
|
|
1953
|
+
return V(n, o, {
|
|
1938
1954
|
...o.query,
|
|
1939
1955
|
union: [...o.query.union, { from: t, joins: [], select: s }]
|
|
1940
1956
|
});
|
|
@@ -1942,41 +1958,41 @@ function yr(e, n, r, t) {
|
|
|
1942
1958
|
function hr(e, n, r, t) {
|
|
1943
1959
|
const o = {
|
|
1944
1960
|
id: r,
|
|
1945
|
-
alias:
|
|
1961
|
+
alias: Ct(e, n),
|
|
1946
1962
|
joinType: "left",
|
|
1947
1963
|
query: { union: [{ from: t, joins: [], select: [] }], all: !0 }
|
|
1948
1964
|
};
|
|
1949
1965
|
return { ...n, joins: [...n.joins, { ...o, on: tn(e, n, o) }] };
|
|
1950
1966
|
}
|
|
1951
1967
|
function br(e, n, r) {
|
|
1952
|
-
const t =
|
|
1953
|
-
return !t || t.query.all === r ? e :
|
|
1968
|
+
const t = W(e, n);
|
|
1969
|
+
return !t || t.query.all === r ? e : V(e, t, { ...t.query, all: r });
|
|
1954
1970
|
}
|
|
1955
1971
|
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 =
|
|
1972
|
+
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();
|
|
1973
|
+
if (!s || !a || !l || l.length > D || i.select.some((d) => A(d) === l)) return n;
|
|
1974
|
+
const c = V(n, s, {
|
|
1959
1975
|
...s.query,
|
|
1960
1976
|
union: [
|
|
1961
1977
|
{ ...i, select: i.select.map((d, f) => f === t ? { ...d, alias: l } : d) },
|
|
1962
1978
|
...u
|
|
1963
1979
|
]
|
|
1964
1980
|
});
|
|
1965
|
-
return
|
|
1981
|
+
return xe(e, n, c);
|
|
1966
1982
|
}
|
|
1967
1983
|
function wr(e, n) {
|
|
1968
1984
|
var c;
|
|
1969
|
-
const r =
|
|
1985
|
+
const r = W(e, n);
|
|
1970
1986
|
if (!r || r.query.union.length !== 1) return e;
|
|
1971
1987
|
const [t] = r.query.union, o = new Map(t.select.flatMap((d) => {
|
|
1972
|
-
const f =
|
|
1988
|
+
const f = A(d);
|
|
1973
1989
|
return f ? [[f, d.expression]] : [];
|
|
1974
1990
|
})), 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
1991
|
const f = i(d.expression);
|
|
1976
1992
|
if (d.alias || !s(d.expression)) return { ...d, expression: f };
|
|
1977
1993
|
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,
|
|
1994
|
+
return A({ ...d, expression: f }) === m ? { ...d, expression: f } : { ...d, expression: f, alias: m };
|
|
1995
|
+
}), a = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((d) => ne(d.expression, P));
|
|
1980
1996
|
if (r === e.from && !a) {
|
|
1981
1997
|
const d = te({ ...e, select: u }, i, (f) => f);
|
|
1982
1998
|
return {
|
|
@@ -1996,27 +2012,27 @@ function wr(e, n) {
|
|
|
1996
2012
|
...e.orderBy ? {
|
|
1997
2013
|
orderBy: e.orderBy.map((d) => ({ ...d, expression: i(d.expression) }))
|
|
1998
2014
|
} : {}
|
|
1999
|
-
} :
|
|
2015
|
+
} : V(e, r, t);
|
|
2000
2016
|
}
|
|
2001
|
-
function
|
|
2017
|
+
function At(e, n) {
|
|
2002
2018
|
return e.select.filter((r) => ne(r.expression, n));
|
|
2003
2019
|
}
|
|
2004
|
-
function
|
|
2020
|
+
function xt(e) {
|
|
2005
2021
|
return { ...e.expression, fromSelect: e.id };
|
|
2006
2022
|
}
|
|
2007
|
-
function
|
|
2023
|
+
function X(e) {
|
|
2008
2024
|
const { fromSelect: n, ...r } = e;
|
|
2009
2025
|
return n === void 0 ? e : r;
|
|
2010
2026
|
}
|
|
2011
2027
|
function Bn(e, n) {
|
|
2012
|
-
const r = (o) => typeof o.fromSelect == "string" ? n(o, o.fromSelect) :
|
|
2028
|
+
const r = (o) => typeof o.fromSelect == "string" ? n(o, o.fromSelect) : Q(o, r), t = r(e);
|
|
2013
2029
|
return M(t, e) ? e : t;
|
|
2014
2030
|
}
|
|
2015
2031
|
function Bt(e, n) {
|
|
2016
2032
|
var u;
|
|
2017
|
-
const r = new Map(
|
|
2033
|
+
const r = new Map(At(e, n).map((a) => [a.id, a])), t = (a) => Bn(a, (l, c) => {
|
|
2018
2034
|
const d = r.get(c);
|
|
2019
|
-
return d ?
|
|
2035
|
+
return d ? xt(d) : X(l);
|
|
2020
2036
|
}), o = e.having && t(e.having);
|
|
2021
2037
|
let s = !1;
|
|
2022
2038
|
const i = (u = e.orderBy) == null ? void 0 : u.map((a) => {
|
|
@@ -2029,7 +2045,7 @@ function Sr(e, n) {
|
|
|
2029
2045
|
const r = new Set((n.groupBy ?? []).flatMap(({ expression: t }) => t.type === "field" && t.column ? [t.column.toLowerCase()] : []));
|
|
2030
2046
|
return Bn(e, (t, o) => {
|
|
2031
2047
|
const s = n.select.find((i) => i.id === o);
|
|
2032
|
-
return !(s != null && s.alias) || r.has(s.alias.toLowerCase()) || !M(
|
|
2048
|
+
return !(s != null && s.alias) || r.has(s.alias.toLowerCase()) || !M(X(t), s.expression) ? X(t) : { type: "field", column: s.alias };
|
|
2033
2049
|
});
|
|
2034
2050
|
}
|
|
2035
2051
|
function ve(e, n) {
|
|
@@ -2039,13 +2055,13 @@ function ve(e, n) {
|
|
|
2039
2055
|
if (!c.query) return c;
|
|
2040
2056
|
const d = t(c.query);
|
|
2041
2057
|
return d === c.query ? c : (i = !0, { ...c, query: d });
|
|
2042
|
-
}), a = s === e.from && !i ? e : { ...e, from: s, joins: u }, l =
|
|
2058
|
+
}), a = s === e.from && !i ? e : { ...e, from: s, joins: u }, l = Ke(a, (c) => {
|
|
2043
2059
|
const d = r(c.query);
|
|
2044
2060
|
return d === c.query ? c : { ...c, query: d };
|
|
2045
2061
|
});
|
|
2046
|
-
return
|
|
2062
|
+
return Qn(Bt(l, n), n);
|
|
2047
2063
|
}
|
|
2048
|
-
function vr(e, n, r, t =
|
|
2064
|
+
function vr(e, n, r, t = P) {
|
|
2049
2065
|
if (!U(r)) return r;
|
|
2050
2066
|
const o = Te(
|
|
2051
2067
|
ve(r, t),
|
|
@@ -2067,21 +2083,21 @@ const Tr = [
|
|
|
2067
2083
|
"REGEXP",
|
|
2068
2084
|
"IS NULL",
|
|
2069
2085
|
"IS NOT NULL"
|
|
2070
|
-
],
|
|
2086
|
+
], kt = ["IS NULL", "IS NOT NULL"];
|
|
2071
2087
|
function Nr(e) {
|
|
2072
|
-
return
|
|
2088
|
+
return kt.includes(e);
|
|
2073
2089
|
}
|
|
2074
|
-
const
|
|
2090
|
+
const kn = (e) => {
|
|
2075
2091
|
const n = /* @__PURE__ */ new Map();
|
|
2076
|
-
return
|
|
2092
|
+
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
2093
|
};
|
|
2078
|
-
function
|
|
2094
|
+
function In(e, n) {
|
|
2079
2095
|
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
2096
|
const c = new Map(a);
|
|
2081
2097
|
return S(l).forEach((d) => c.set(v(d), d.table)), c;
|
|
2082
2098
|
}, s = (a, l) => {
|
|
2083
2099
|
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 :
|
|
2100
|
+
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
2101
|
return d && f ? { table: d.name, column: f } : void 0;
|
|
2086
2102
|
}, i = (a, l) => {
|
|
2087
2103
|
if (a.type === "param" && t(a.name), a.type === "binary" && a.right) {
|
|
@@ -2100,13 +2116,13 @@ function kn(e, n) {
|
|
|
2100
2116
|
oe(a).forEach((d) => i(d, c));
|
|
2101
2117
|
}, u = (a) => {
|
|
2102
2118
|
const l = o(/* @__PURE__ */ new Map(), a);
|
|
2103
|
-
|
|
2119
|
+
_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
2120
|
};
|
|
2105
2121
|
return (e.shared ?? []).forEach((a) => Y(a.query).forEach(u)), u(e), r;
|
|
2106
2122
|
}
|
|
2107
2123
|
function Er(e, n) {
|
|
2108
|
-
const r =
|
|
2109
|
-
return [...
|
|
2124
|
+
const r = kn(e);
|
|
2125
|
+
return [...In(e, n)].map(([t, { types: o, columns: s }]) => {
|
|
2110
2126
|
const i = r.get(t);
|
|
2111
2127
|
return {
|
|
2112
2128
|
name: t,
|
|
@@ -2117,15 +2133,15 @@ function Er(e, n) {
|
|
|
2117
2133
|
};
|
|
2118
2134
|
});
|
|
2119
2135
|
}
|
|
2120
|
-
function
|
|
2121
|
-
return [...
|
|
2136
|
+
function $r(e) {
|
|
2137
|
+
return [...kn(e)].filter(([, n]) => n.size > 1).map(([n]) => n);
|
|
2122
2138
|
}
|
|
2123
|
-
function
|
|
2124
|
-
return [...
|
|
2139
|
+
function Cr(e, n) {
|
|
2140
|
+
return [...In(e, n)].filter(([, r]) => r.types.size > 1).map(([r]) => r);
|
|
2125
2141
|
}
|
|
2126
|
-
function
|
|
2142
|
+
function Ar(e, n) {
|
|
2127
2143
|
const r = new Map(Object.entries(n));
|
|
2128
|
-
return
|
|
2144
|
+
return We(e, (t) => {
|
|
2129
2145
|
if (t.type !== "param") return t;
|
|
2130
2146
|
if (!r.has(t.name)) throw new Error(`no value for parameter "${t.name}"`);
|
|
2131
2147
|
const o = r.get(t.name);
|
|
@@ -2135,18 +2151,18 @@ function xr(e, n) {
|
|
|
2135
2151
|
export {
|
|
2136
2152
|
jt as $,
|
|
2137
2153
|
Tr as A,
|
|
2138
|
-
|
|
2139
|
-
|
|
2154
|
+
Ie as B,
|
|
2155
|
+
Rt as C,
|
|
2140
2156
|
et as D,
|
|
2141
2157
|
O as E,
|
|
2142
2158
|
ze as F,
|
|
2143
2159
|
pe as G,
|
|
2144
2160
|
Gt as H,
|
|
2145
|
-
|
|
2161
|
+
X as I,
|
|
2146
2162
|
ye as J,
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2163
|
+
Cr as K,
|
|
2164
|
+
$r as L,
|
|
2165
|
+
Wn as M,
|
|
2150
2166
|
an as N,
|
|
2151
2167
|
rr as O,
|
|
2152
2168
|
nr as P,
|
|
@@ -2156,11 +2172,11 @@ export {
|
|
|
2156
2172
|
ht as T,
|
|
2157
2173
|
Zn as U,
|
|
2158
2174
|
Lt as V,
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2175
|
+
Xe as W,
|
|
2176
|
+
_t as X,
|
|
2177
|
+
Jt as Y,
|
|
2178
|
+
Vt as Z,
|
|
2179
|
+
Wt as _,
|
|
2164
2180
|
Ot as a,
|
|
2165
2181
|
ir as a0,
|
|
2166
2182
|
or as a1,
|
|
@@ -2168,42 +2184,42 @@ export {
|
|
|
2168
2184
|
ur as a3,
|
|
2169
2185
|
sr as a4,
|
|
2170
2186
|
vt as a5,
|
|
2171
|
-
|
|
2172
|
-
|
|
2187
|
+
xt as a6,
|
|
2188
|
+
Vn as a7,
|
|
2173
2189
|
nn as a8,
|
|
2174
2190
|
Ft as a9,
|
|
2175
|
-
|
|
2191
|
+
Xt as aa,
|
|
2176
2192
|
zt as ab,
|
|
2177
2193
|
Yt as ac,
|
|
2178
2194
|
Ze as ad,
|
|
2179
2195
|
Dt as ae,
|
|
2180
2196
|
er as af,
|
|
2181
2197
|
lt as ag,
|
|
2182
|
-
|
|
2198
|
+
Pt as ah,
|
|
2183
2199
|
ut as ai,
|
|
2184
2200
|
it as aj,
|
|
2185
2201
|
ae as ak,
|
|
2186
2202
|
Zt as al,
|
|
2187
|
-
|
|
2203
|
+
qe as am,
|
|
2188
2204
|
tn as an,
|
|
2189
|
-
|
|
2190
|
-
|
|
2205
|
+
At as ao,
|
|
2206
|
+
qt as ap,
|
|
2191
2207
|
Ht as aq,
|
|
2192
|
-
|
|
2193
|
-
|
|
2208
|
+
Kt as ar,
|
|
2209
|
+
Kn as as,
|
|
2194
2210
|
He as at,
|
|
2195
2211
|
ue as au,
|
|
2196
|
-
|
|
2212
|
+
J as av,
|
|
2197
2213
|
he as aw,
|
|
2198
2214
|
Ut as b,
|
|
2199
|
-
|
|
2215
|
+
Qt as c,
|
|
2200
2216
|
tr as d,
|
|
2201
2217
|
yr as e,
|
|
2202
2218
|
hr as f,
|
|
2203
2219
|
cr as g,
|
|
2204
2220
|
mr as h,
|
|
2205
2221
|
gr as i,
|
|
2206
|
-
|
|
2222
|
+
Ct as j,
|
|
2207
2223
|
pt as k,
|
|
2208
2224
|
pr as l,
|
|
2209
2225
|
dn as m,
|
|
@@ -2213,11 +2229,11 @@ export {
|
|
|
2213
2229
|
Er as q,
|
|
2214
2230
|
fr as r,
|
|
2215
2231
|
br as s,
|
|
2216
|
-
|
|
2232
|
+
k as t,
|
|
2217
2233
|
wr as u,
|
|
2218
2234
|
G as v,
|
|
2219
2235
|
gn as w,
|
|
2220
|
-
|
|
2236
|
+
Ar as x,
|
|
2221
2237
|
Sr as y,
|
|
2222
2238
|
Nr as z
|
|
2223
2239
|
};
|