@nongt/visql 0.9.0 → 0.10.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/{PipelineEditor-C10lng6j.js → PipelineEditor-Ch_i6OAc.js} +310 -317
- package/dist/core.js +83 -80
- package/dist/explain.js +325 -134
- package/dist/index.js +91 -88
- package/dist/{issueLocation-BOSdd1JX.js → issueLocation-Y1iaP_Cs.js} +176 -174
- package/dist/mui.js +1 -1
- package/dist/{params-MMOdKWnW.js → params-kc6eNrpu.js} +501 -495
- package/dist/{schema-dP_ISylQ.js → schema-KDJ1rpG5.js} +333 -298
- package/dist/sql-import.js +1 -1
- package/dist/{sqlGen-B7-2-i9V.js → sqlGen-Crgheqys.js} +33 -33
- package/dist/types/core/existsMenu.d.ts +4 -3
- package/dist/types/core/pipelineFlow.d.ts +1 -1
- package/dist/types/core/schema.d.ts +51 -22
- package/dist/types/core-api.d.ts +1 -1
- package/dist/types/explain/explainQuery.d.ts +12 -6
- package/dist/types/explain/mySqlPlan.d.ts +4 -0
- package/dist/types/explain/planPlaces.d.ts +27 -0
- package/dist/types/explain/postgresPlan.d.ts +2 -10
- package/dist/types/explain/sqlServerPlan.d.ts +4 -0
- package/dist/types/explain/xml.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { D as Q, h as U, q as S, t as
|
|
2
|
-
import { c as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
1
|
+
import { D as Q, h as U, q as S, t as v, i as C, J as Je, u as ne, F as jn, e as te, n as re, K as Te, j as A, y as oe, m as _, o as x, L as Pe, l as E, N as qn, O as J, z as q, r as Rn, M as D, s as Gn, P as Fn, d as M, g as se, Q as Ne, b as Y, I as Qn, x as _n, R as Ve } from "./schema-KDJ1rpG5.js";
|
|
2
|
+
import { c as Jn, s as Pn, b as We } from "./calendarDate-CYlr9TvX.js";
|
|
3
|
+
const Ot = 1e3, Vn = 15, Ut = 40, Lt = 100;
|
|
4
|
+
function Wn(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
|
-
function
|
|
9
|
-
return Number.isFinite(e) &&
|
|
8
|
+
function Hn(e) {
|
|
9
|
+
return Number.isFinite(e) && Wn(String(e)) <= Vn;
|
|
10
10
|
}
|
|
11
|
-
const
|
|
11
|
+
const Dt = [];
|
|
12
12
|
function O(e) {
|
|
13
13
|
return S(e).filter((n) => n.query !== void 0);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function pe(e, n = []) {
|
|
16
16
|
var r;
|
|
17
17
|
return e.query ? e.query : e.shared === void 0 || (r = n.find((t) => t.id === e.shared)) == null ? void 0 : r.query;
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
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 Je(e).forEach(r), n;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function Xe(e, n) {
|
|
26
26
|
let r = !1;
|
|
27
27
|
const t = (s) => {
|
|
28
|
-
if (s.type !== "subquery") return
|
|
28
|
+
if (s.type !== "subquery") return _(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
|
-
const
|
|
35
|
-
function
|
|
34
|
+
const jt = (e, n) => `${e}#${n}`;
|
|
35
|
+
function Xn(e) {
|
|
36
36
|
return !("type" in e) && "of" in e;
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const Kn = (e) => ({
|
|
39
39
|
id: e.id,
|
|
40
40
|
alias: e.name,
|
|
41
41
|
query: e.query
|
|
@@ -45,12 +45,12 @@ function Ie(e, n) {
|
|
|
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 && Kn(t);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function Ke(e, n) {
|
|
51
51
|
const r = Ie(e, n);
|
|
52
52
|
if (r) return C(r.query) ? void 0 : r;
|
|
53
|
-
const t =
|
|
53
|
+
const t = He(e).find((a) => a.id === n);
|
|
54
54
|
if (t) return t;
|
|
55
55
|
const o = /^(.*)#(\d+)$/.exec(n), s = o ? Ie(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 ? {
|
|
@@ -61,10 +61,10 @@ function Ye(e, n) {
|
|
|
61
61
|
index: i
|
|
62
62
|
} : void 0;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function Ye(e) {
|
|
65
65
|
return { id: e.id, ...re(e.query) };
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function ce(e) {
|
|
68
68
|
const {
|
|
69
69
|
from: n,
|
|
70
70
|
joins: r,
|
|
@@ -84,41 +84,41 @@ function le(e) {
|
|
|
84
84
|
...u !== void 0 ? { distinct: u } : {}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function qt(e, n) {
|
|
88
88
|
return n.reduce((r, t) => {
|
|
89
|
-
const o = r &&
|
|
90
|
-
return o ?
|
|
89
|
+
const o = r && Ke(r, t);
|
|
90
|
+
return o ? Ye(o) : void 0;
|
|
91
91
|
}, e);
|
|
92
92
|
}
|
|
93
|
-
function
|
|
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 = Ke(e, t);
|
|
96
96
|
if (!s) return e;
|
|
97
|
-
const i =
|
|
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
|
-
const l = { ...s, query:
|
|
101
|
-
return
|
|
100
|
+
const l = { ...s, query: ce(u) };
|
|
101
|
+
return Xe(e, (c) => c === s ? l : c);
|
|
102
102
|
}
|
|
103
103
|
const a = (l, c) => {
|
|
104
|
-
if (!O(e).some((
|
|
105
|
-
return Te(e, (
|
|
106
|
-
const
|
|
107
|
-
return l === e.from ? { ...e, from:
|
|
104
|
+
if (!O(e).some((f) => f.id === l.id))
|
|
105
|
+
return Te(e, (f, m) => m.id === l.id ? c : f);
|
|
106
|
+
const d = { ...l, query: c };
|
|
107
|
+
return l === e.from ? { ...e, from: d } : {
|
|
108
108
|
...e,
|
|
109
|
-
joins: e.joins.map((
|
|
109
|
+
joins: e.joins.map((f) => f === l ? d : f)
|
|
110
110
|
};
|
|
111
111
|
};
|
|
112
|
-
if (
|
|
113
|
-
const { of: l, index: c } = s, { union:
|
|
112
|
+
if (Xn(s)) {
|
|
113
|
+
const { of: l, index: c } = s, { union: d } = l.query;
|
|
114
114
|
return a(l, {
|
|
115
115
|
...l.query,
|
|
116
|
-
union:
|
|
116
|
+
union: d.map((f, m) => m === c ? ce(u) : f)
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
return a(s,
|
|
119
|
+
return a(s, ce(u));
|
|
120
120
|
}
|
|
121
|
-
const
|
|
121
|
+
const Yn = {
|
|
122
122
|
text: "varchar",
|
|
123
123
|
integer: "integer",
|
|
124
124
|
number: "decimal",
|
|
@@ -127,19 +127,19 @@ const Kn = {
|
|
|
127
127
|
time: "time",
|
|
128
128
|
boolean: "boolean"
|
|
129
129
|
};
|
|
130
|
-
function
|
|
130
|
+
function ye(e, n, r = []) {
|
|
131
131
|
const t = re(n);
|
|
132
132
|
if (t.select.length === 0)
|
|
133
133
|
return S(t).flatMap((u) => {
|
|
134
134
|
var l;
|
|
135
135
|
if (u.table !== void 0) return ((l = A(e, u.table)) == null ? void 0 : l.columns) ?? [];
|
|
136
|
-
const a =
|
|
137
|
-
return a ?
|
|
136
|
+
const a = pe(u, r);
|
|
137
|
+
return a ? ye(e, a, r) : [];
|
|
138
138
|
});
|
|
139
|
-
const o = new Map(S(t).map((u) => [
|
|
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 = A(e, l)) == null ? void 0 : a.columns.find((
|
|
142
|
+
const l = u.table === void 0 ? void 0 : o.get(u.table), c = l === void 0 || (a = A(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,14 +148,14 @@ function pe(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 ?
|
|
151
|
+
return u.type === "literal" && typeof u.value == "number" ? "decimal" : u.type === "literal" && u.as ? Yn[u.as] : "varchar";
|
|
152
152
|
}, i = (u) => {
|
|
153
|
-
var
|
|
153
|
+
var d, f;
|
|
154
154
|
if (u.type !== "field" || u.table === void 0) return !1;
|
|
155
|
-
const a = S(t).find((m) =>
|
|
155
|
+
const a = S(t).find((m) => v(m) === u.table);
|
|
156
156
|
if (!a) return !1;
|
|
157
|
-
const l = a.table === void 0 ?
|
|
158
|
-
return !!((
|
|
157
|
+
const l = a.table === void 0 ? pe(a, r) : void 0, c = a.table !== void 0 ? (d = A(e, a.table)) == null ? void 0 : d.columns : l && ye(e, l, r);
|
|
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
161
|
const a = x(u);
|
|
@@ -167,23 +167,23 @@ function pe(e, n, r = []) {
|
|
|
167
167
|
}] : [];
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
function
|
|
171
|
-
const t =
|
|
170
|
+
function Ze(e, n, r = []) {
|
|
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
|
|
175
|
-
return S(n).filter((t) => t.table === void 0).map((t) =>
|
|
174
|
+
function Rt(e, n, r = []) {
|
|
175
|
+
return S(n).filter((t) => t.table === void 0).map((t) => Ze(e, t, r));
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function Gt(e, n = Q) {
|
|
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
182
|
function ke(e, n, r) {
|
|
183
|
-
const t = (o) => o.type === "field" ? o.table === n ? { ...o, table: r } : o : o.type === "exists" &&
|
|
183
|
+
const t = (o) => o.type === "field" ? o.table === n ? { ...o, table: r } : o : o.type === "exists" && Pe(o.query).has(n) ? { ...o, link: t(o.link) } : _(o, t);
|
|
184
184
|
return te(e, t, (o) => o);
|
|
185
185
|
}
|
|
186
|
-
function
|
|
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;
|
|
@@ -191,12 +191,12 @@ function nn(e, n) {
|
|
|
191
191
|
}) : r.select.flatMap((o) => {
|
|
192
192
|
const { expression: s } = o;
|
|
193
193
|
if (s.type !== "field" || !s.column) return [];
|
|
194
|
-
const i = t.find((a) =>
|
|
194
|
+
const i = t.find((a) => v(a) === s.table), u = o.alias || s.column;
|
|
195
195
|
return i ? [{ name: u, table: i.table, column: s.column }] : [];
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return O(n).flatMap((r) =>
|
|
198
|
+
function nn(e, n) {
|
|
199
|
+
return O(n).flatMap((r) => en(e, r.query).flatMap(({ name: t, table: o, column: s }) => e.relations.flatMap((i) => {
|
|
200
200
|
const u = i.fromTable === o && i.fromColumn === s;
|
|
201
201
|
if (!u && !(i.toTable === o && i.toColumn === s)) return [];
|
|
202
202
|
const a = u ? i.toTable : i.fromTable, l = {
|
|
@@ -208,16 +208,16 @@ function tn(e, n) {
|
|
|
208
208
|
return [{ table: a, on: l }];
|
|
209
209
|
})));
|
|
210
210
|
}
|
|
211
|
-
function
|
|
211
|
+
function zn(e, n, r) {
|
|
212
212
|
var t;
|
|
213
|
-
return (t =
|
|
213
|
+
return (t = nn(e, n).find((o) => o.table === r)) == null ? void 0 : t.on;
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function tn(e, n, r) {
|
|
216
216
|
var a;
|
|
217
|
-
const t = S(n).flatMap((l) => l !== r && l.table !== void 0 ? [{ table: l.table, alias: l.alias }] : []), o = (l, c) => c === void 0 ? { type: "field", table: l } : { type: "field", table: l, column: c }, i =
|
|
217
|
+
const t = S(n).flatMap((l) => l !== r && l.table !== void 0 ? [{ table: l.table, alias: l.alias }] : []), o = (l, c) => c === void 0 ? { type: "field", table: l } : { type: "field", table: l, column: c }, i = en(e, r.query).flatMap(({ name: l, table: c, column: d }) => t.flatMap((f) => e.relations.filter((m) => m.fromTable === c && m.fromColumn === d && m.toTable === f.table || m.toTable === c && m.toColumn === d && m.fromTable === f.table).map((m) => ({
|
|
218
218
|
name: l,
|
|
219
|
-
right: o(
|
|
220
|
-
}))))[0], u = (a =
|
|
219
|
+
right: o(v(f), m.fromTable === c ? m.toColumn : m.fromColumn)
|
|
220
|
+
}))))[0], u = (a = Ze(e, r).columns[0]) == null ? void 0 : a.name;
|
|
221
221
|
return {
|
|
222
222
|
type: "binary",
|
|
223
223
|
operator: "=",
|
|
@@ -226,7 +226,7 @@ function rn(e, n, r) {
|
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
const H = (e, n) => `${e} ${n}${e === 1 ? "" : "s"}`;
|
|
229
|
-
function
|
|
229
|
+
function Zn({ unit: e, offset: n, anchor: r }) {
|
|
230
230
|
const t = Math.abs(n);
|
|
231
231
|
if (r) {
|
|
232
232
|
const o = r === "start" ? "Start" : "End";
|
|
@@ -234,7 +234,7 @@ function zn({ unit: e, offset: n, anchor: r }) {
|
|
|
234
234
|
}
|
|
235
235
|
return n === 0 ? "Today" : e === "day" && t === 1 ? n < 0 ? "Yesterday" : "Tomorrow" : n < 0 ? `${H(t, e)} ago` : `In ${H(t, e)}`;
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const et = {
|
|
238
238
|
// Section captions on the main canvas
|
|
239
239
|
sectionFrom: "From Tables",
|
|
240
240
|
sectionWhere: "Conditions",
|
|
@@ -314,7 +314,7 @@ const Zn = {
|
|
|
314
314
|
* item, its words ("30 days ago", "Start of last month"), its presets'
|
|
315
315
|
* "Custom", and its custom parts. */
|
|
316
316
|
typeRelativeDate: "Relative date",
|
|
317
|
-
relativeDate:
|
|
317
|
+
relativeDate: Zn,
|
|
318
318
|
relativeCustom: "Custom…",
|
|
319
319
|
relativeUnits: {
|
|
320
320
|
day: "days",
|
|
@@ -665,7 +665,7 @@ function G() {
|
|
|
665
665
|
return Oe += 1, `join-${Date.now().toString(36)}-${Oe}`;
|
|
666
666
|
}
|
|
667
667
|
let Ue = 0;
|
|
668
|
-
function
|
|
668
|
+
function nt() {
|
|
669
669
|
return Ue += 1, `select-${Date.now().toString(36)}-${Ue}`;
|
|
670
670
|
}
|
|
671
671
|
let Le = 0;
|
|
@@ -673,25 +673,25 @@ function De() {
|
|
|
673
673
|
return Le += 1, `group-${Date.now().toString(36)}-${Le}`;
|
|
674
674
|
}
|
|
675
675
|
let je = 0;
|
|
676
|
-
function
|
|
676
|
+
function tt() {
|
|
677
677
|
return je += 1, `order-${Date.now().toString(36)}-${je}`;
|
|
678
678
|
}
|
|
679
|
-
function
|
|
679
|
+
function de(e, n, r) {
|
|
680
680
|
if (n < 0 || n >= e.length || r < 0 || r >= e.length || n === r) return e;
|
|
681
681
|
const t = [...e], [o] = t.splice(n, 1);
|
|
682
682
|
return t.splice(r, 0, o), t;
|
|
683
683
|
}
|
|
684
|
-
const qe = (e) => e !== void 0 && Number.isSafeInteger(e) && e >= 0 ? e : void 0,
|
|
684
|
+
const qe = (e) => e !== void 0 && Number.isSafeInteger(e) && e >= 0 ? e : void 0, fe = (e) => (e ?? "").length <= D;
|
|
685
685
|
function R(e, n, r) {
|
|
686
686
|
return e.map((t) => t.id === n ? r(t) : t);
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function rn(e, n, r) {
|
|
689
689
|
return e.map((t) => t.id === n ? r(t) : t);
|
|
690
690
|
}
|
|
691
|
-
function
|
|
691
|
+
function rt(e) {
|
|
692
692
|
return e.query ? { id: e.id, alias: e.alias, query: e.query } : e.shared !== void 0 ? { shared: e.shared, alias: e.alias } : { table: e.table, alias: e.alias };
|
|
693
693
|
}
|
|
694
|
-
function
|
|
694
|
+
function ot(e, n, r) {
|
|
695
695
|
return e.query ? {
|
|
696
696
|
id: e.id,
|
|
697
697
|
alias: e.alias,
|
|
@@ -712,9 +712,9 @@ function rt(e, n, r) {
|
|
|
712
712
|
on: n
|
|
713
713
|
};
|
|
714
714
|
}
|
|
715
|
-
function
|
|
715
|
+
function on(e, n) {
|
|
716
716
|
const [r, ...t] = n;
|
|
717
|
-
return { ...e, from:
|
|
717
|
+
return { ...e, from: rt(r), joins: t };
|
|
718
718
|
}
|
|
719
719
|
function I(e) {
|
|
720
720
|
const n = /* @__PURE__ */ new Set(), r = (t) => {
|
|
@@ -751,7 +751,7 @@ function I(e) {
|
|
|
751
751
|
// tables are joined inside it (withExistsJoins), never to the query
|
|
752
752
|
// around it — that would repeat its rows, which EXISTS is there to avoid.
|
|
753
753
|
case "exists": {
|
|
754
|
-
const s =
|
|
754
|
+
const s = Pe(t.query);
|
|
755
755
|
I(t.link).filter((i) => !s.has(i)).forEach((i) => n.add(i));
|
|
756
756
|
break;
|
|
757
757
|
}
|
|
@@ -759,31 +759,37 @@ function I(e) {
|
|
|
759
759
|
};
|
|
760
760
|
return r(e), [...n];
|
|
761
761
|
}
|
|
762
|
-
function
|
|
763
|
-
const
|
|
762
|
+
function ie(e, n, r, t, o, s) {
|
|
763
|
+
const i = J(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
764
|
id: G(),
|
|
765
765
|
table: r,
|
|
766
|
-
joinType: t ?? (
|
|
766
|
+
joinType: t ?? (l == null ? void 0 : l.joinType) ?? "inner",
|
|
767
767
|
// Else matched to a derived table holding its key, if one does.
|
|
768
|
-
on: o ?? (
|
|
768
|
+
on: o ?? (l == null ? void 0 : l.on) ?? (u ? zn(e, n, r) : void 0)
|
|
769
769
|
};
|
|
770
|
-
return { ...n, joins: [...n.joins,
|
|
770
|
+
return { ...n, joins: [...n.joins, c] };
|
|
771
|
+
}
|
|
772
|
+
function sn(e, n, r) {
|
|
773
|
+
const t = J(n);
|
|
774
|
+
if (t.includes(r)) return;
|
|
775
|
+
const o = Fn(e, t, r);
|
|
776
|
+
if (!o) return;
|
|
777
|
+
const s = [o.start, ...o.tables];
|
|
778
|
+
return o.tables.reduce(
|
|
779
|
+
(i, u, a) => ie(e, i, u, void 0, void 0, s[a]),
|
|
780
|
+
n
|
|
781
|
+
);
|
|
771
782
|
}
|
|
772
|
-
function
|
|
773
|
-
|
|
774
|
-
return (o && o.length > 0 ? o : [r]).reduce((i, u) => Ne(e, i, u), n);
|
|
783
|
+
function st(e, n, r) {
|
|
784
|
+
return sn(e, n, r) ?? ie(e, n, r);
|
|
775
785
|
}
|
|
776
786
|
function L(e, n, r) {
|
|
777
|
-
return I(r).reduce((t, o) =>
|
|
778
|
-
if (S(t).some((u) => u.alias === o)) return t;
|
|
779
|
-
const s = _(t);
|
|
780
|
-
return (Ve(e, s, o) ?? [o]).reduce((u, a) => Ne(e, u, a), t);
|
|
781
|
-
}, n);
|
|
787
|
+
return I(r).reduce((t, o) => S(t).some((s) => s.alias === o) || J(t).includes(o) ? t : sn(e, t, o) ?? ie(e, t, o), n);
|
|
782
788
|
}
|
|
783
|
-
function
|
|
789
|
+
function it(e, n, r, t) {
|
|
784
790
|
return {
|
|
785
791
|
...L(e, n, t),
|
|
786
|
-
select:
|
|
792
|
+
select: rn(n.select, r, (o) => ({ ...o, expression: t }))
|
|
787
793
|
};
|
|
788
794
|
}
|
|
789
795
|
function Ee(e, n, r) {
|
|
@@ -794,43 +800,43 @@ function Ee(e, n, r) {
|
|
|
794
800
|
const [i, u] = t;
|
|
795
801
|
let a, l;
|
|
796
802
|
if (n === 0 ? (l = i, a = u) : r === 0 && (a = t[n], l = i), a && l) {
|
|
797
|
-
const { on: c, joinType:
|
|
798
|
-
o[o.indexOf(l)] =
|
|
803
|
+
const { on: c, joinType: d } = a;
|
|
804
|
+
o[o.indexOf(l)] = ot(l, c, d);
|
|
799
805
|
}
|
|
800
|
-
return
|
|
806
|
+
return on(e, o);
|
|
801
807
|
}
|
|
802
808
|
function an(e) {
|
|
803
|
-
const n = /* @__PURE__ */ new Set([
|
|
809
|
+
const n = /* @__PURE__ */ new Set([v(e.from)]);
|
|
804
810
|
let r;
|
|
805
811
|
return e.joins.some((t) => {
|
|
806
|
-
n.add(
|
|
812
|
+
n.add(v(t));
|
|
807
813
|
const o = t.joinType === "cross" ? void 0 : t.on, s = I(o).find((i) => !n.has(i));
|
|
808
|
-
return s && (r = { table: t.table ??
|
|
814
|
+
return s && (r = { table: t.table ?? v(t), needs: s }), s !== void 0;
|
|
809
815
|
}), r;
|
|
810
816
|
}
|
|
811
|
-
function
|
|
817
|
+
function Ft(e, n, r) {
|
|
812
818
|
const t = Ee(e, n, r);
|
|
813
819
|
return t === e ? void 0 : an(t);
|
|
814
820
|
}
|
|
815
|
-
function
|
|
821
|
+
function at(e, n, r) {
|
|
816
822
|
const t = Ee(e, n, r);
|
|
817
823
|
return t !== e && an(t) === void 0;
|
|
818
824
|
}
|
|
819
|
-
function
|
|
825
|
+
function ut(e, n, r, t) {
|
|
820
826
|
return {
|
|
821
827
|
...L(e, n, t),
|
|
822
828
|
orderBy: (n.orderBy ?? []).map((o) => o.id === r ? { ...o, expression: t } : o)
|
|
823
829
|
};
|
|
824
830
|
}
|
|
825
|
-
function
|
|
831
|
+
function lt(e, n, r, t) {
|
|
826
832
|
return {
|
|
827
833
|
...L(e, n, t),
|
|
828
834
|
groupBy: (n.groupBy ?? []).map((o) => o.id === r ? { ...o, expression: t } : o)
|
|
829
835
|
};
|
|
830
836
|
}
|
|
831
|
-
function
|
|
837
|
+
function ae(e, n) {
|
|
832
838
|
if (!n || !qn(n)) return n;
|
|
833
|
-
const r = oe(n), t = r.map((a) =>
|
|
839
|
+
const r = oe(n), t = r.map((a) => ae(e, a)), s = t.some((a, l) => a !== r[l]) ? _(n, (a) => t[r.indexOf(a)]) : n;
|
|
834
840
|
if (s.type !== "exists") return s;
|
|
835
841
|
const { query: i } = s, { joins: u } = L(
|
|
836
842
|
e,
|
|
@@ -844,20 +850,20 @@ function ie(e, n) {
|
|
|
844
850
|
);
|
|
845
851
|
return u === i.joins ? s : { ...s, query: { ...i, joins: u } };
|
|
846
852
|
}
|
|
847
|
-
function
|
|
848
|
-
const t =
|
|
853
|
+
function Qt(e, n, r) {
|
|
854
|
+
const t = ae(e, r);
|
|
849
855
|
return { ...L(e, n, t), having: t };
|
|
850
856
|
}
|
|
851
857
|
function Re(e, n) {
|
|
852
858
|
const r = /* @__PURE__ */ new Set([
|
|
853
|
-
...n ? S(n).map(
|
|
859
|
+
...n ? S(n).map(v) : [],
|
|
854
860
|
...q(e).map((o) => o.name)
|
|
855
861
|
]);
|
|
856
862
|
let t = 1;
|
|
857
863
|
for (; r.has(`sub_query_${t}`); ) t += 1;
|
|
858
864
|
return `sub_query_${t}`;
|
|
859
865
|
}
|
|
860
|
-
function
|
|
866
|
+
function _t() {
|
|
861
867
|
return { id: E() };
|
|
862
868
|
}
|
|
863
869
|
function he(e, n, r) {
|
|
@@ -882,27 +888,27 @@ function he(e, n, r) {
|
|
|
882
888
|
}
|
|
883
889
|
};
|
|
884
890
|
case "changeBaseAlias":
|
|
885
|
-
return
|
|
891
|
+
return fe(r.alias) ? {
|
|
886
892
|
...n,
|
|
887
893
|
// A derived table (or a shared query's place) goes by its alias: it
|
|
888
894
|
// can't be left without one.
|
|
889
895
|
from: n.from.table === void 0 ? { ...n.from, alias: r.alias || n.from.alias } : { ...n.from, alias: r.alias }
|
|
890
896
|
} : n;
|
|
891
897
|
case "addJoin":
|
|
892
|
-
return r.joinType === void 0 && r.on === void 0 ?
|
|
898
|
+
return r.joinType === void 0 && r.on === void 0 ? st(e, n, r.table) : ie(e, n, r.table, r.joinType, r.on);
|
|
893
899
|
case "addDerivedJoin": {
|
|
894
900
|
const t = {
|
|
895
901
|
id: r.id ?? G(),
|
|
896
902
|
alias: Re(e, n),
|
|
897
903
|
joinType: "left",
|
|
898
904
|
query: { from: Me(r), joins: [], select: [] }
|
|
899
|
-
}, o =
|
|
905
|
+
}, o = tn(e, n, t);
|
|
900
906
|
return { ...n, joins: [...n.joins, { ...t, on: o }] };
|
|
901
907
|
}
|
|
902
908
|
case "renameDerivedTable": {
|
|
903
909
|
const t = O(n).find((a) => a.id === r.derivedId), o = r.alias.trim();
|
|
904
910
|
if (!t || o === t.alias) return n;
|
|
905
|
-
const s = S(n).filter((a) => a !== t).map(
|
|
911
|
+
const s = S(n).filter((a) => a !== t).map(v);
|
|
906
912
|
if (!o || o.length > D || s.includes(o) || A(e, o)) return n;
|
|
907
913
|
const i = ke(n, t.alias, o), { from: u } = i;
|
|
908
914
|
return {
|
|
@@ -914,7 +920,7 @@ function he(e, n, r) {
|
|
|
914
920
|
case "renameSharedPlace": {
|
|
915
921
|
const t = r.joinId === void 0 ? n.from : n.joins.find((u) => u.id === r.joinId), o = r.alias.trim();
|
|
916
922
|
if ((t == null ? void 0 : t.shared) === void 0 || o === t.alias) return n;
|
|
917
|
-
const s = S(n).filter((u) => u !== t).map(
|
|
923
|
+
const s = S(n).filter((u) => u !== t).map(v);
|
|
918
924
|
if (!o || o.length > D || s.includes(o) || A(e, o)) return n;
|
|
919
925
|
const i = ke(n, t.alias, o);
|
|
920
926
|
return r.joinId === void 0 ? { ...i, from: { ...i.from, alias: o } } : { ...i, joins: R(i.joins, r.joinId, (u) => ({ ...u, alias: o })) };
|
|
@@ -933,7 +939,7 @@ function he(e, n, r) {
|
|
|
933
939
|
joins: R(n.joins, r.joinId, (t) => ({ ...t, joinType: r.joinType }))
|
|
934
940
|
};
|
|
935
941
|
case "changeJoinAlias":
|
|
936
|
-
return
|
|
942
|
+
return fe(r.alias) ? {
|
|
937
943
|
...n,
|
|
938
944
|
// A derived table (or a shared query's place) goes by its alias: it
|
|
939
945
|
// can't be left without one.
|
|
@@ -944,7 +950,7 @@ function he(e, n, r) {
|
|
|
944
950
|
...n,
|
|
945
951
|
joins: R(n.joins, r.joinId, (t) => ({
|
|
946
952
|
...t,
|
|
947
|
-
on:
|
|
953
|
+
on: ae(e, r.on)
|
|
948
954
|
}))
|
|
949
955
|
};
|
|
950
956
|
case "reorderJoin": {
|
|
@@ -956,26 +962,26 @@ function he(e, n, r) {
|
|
|
956
962
|
return [s[t], s[o]] = [s[o], s[t]], { ...n, joins: s };
|
|
957
963
|
}
|
|
958
964
|
case "reorderTables":
|
|
959
|
-
return
|
|
965
|
+
return at(n, r.fromIndex, r.toIndex) ? Ee(n, r.fromIndex, r.toIndex) : n;
|
|
960
966
|
case "removeBaseTable":
|
|
961
|
-
return n.joins.length > 0 ?
|
|
967
|
+
return n.joins.length > 0 ? on(n, n.joins) : n.shared ? { id: n.id, shared: n.shared } : { id: n.id };
|
|
962
968
|
case "addSelectItem": {
|
|
963
|
-
const t = { id:
|
|
969
|
+
const t = { id: nt(), expression: { type: "field" } };
|
|
964
970
|
return { ...n, select: [...n.select, t] };
|
|
965
971
|
}
|
|
966
972
|
case "removeSelectItem":
|
|
967
973
|
return { ...n, select: n.select.filter((t) => t.id !== r.selectId) };
|
|
968
974
|
case "reorderSelectItems": {
|
|
969
|
-
const t =
|
|
975
|
+
const t = de(n.select, r.fromIndex, r.toIndex);
|
|
970
976
|
return t === n.select ? n : { ...n, select: t };
|
|
971
977
|
}
|
|
972
978
|
case "setSelectAlias":
|
|
973
|
-
return
|
|
979
|
+
return fe(r.alias) ? {
|
|
974
980
|
...n,
|
|
975
|
-
select:
|
|
981
|
+
select: rn(n.select, r.selectId, (t) => ({ ...t, alias: r.alias }))
|
|
976
982
|
} : n;
|
|
977
983
|
case "setSelectExpression":
|
|
978
|
-
return
|
|
984
|
+
return it(e, n, r.selectId, r.expression);
|
|
979
985
|
case "addGroupByItem": {
|
|
980
986
|
const t = { id: De(), expression: { type: "field" } };
|
|
981
987
|
return { ...n, groupBy: [...n.groupBy ?? [], t] };
|
|
@@ -985,11 +991,11 @@ function he(e, n, r) {
|
|
|
985
991
|
return { ...n, groupBy: t.length > 0 ? t : void 0 };
|
|
986
992
|
}
|
|
987
993
|
case "reorderGroupByItems": {
|
|
988
|
-
const t = n.groupBy ?? [], o =
|
|
994
|
+
const t = n.groupBy ?? [], o = de(t, r.fromIndex, r.toIndex);
|
|
989
995
|
return o === t ? n : { ...n, groupBy: o };
|
|
990
996
|
}
|
|
991
997
|
case "setGroupByExpression":
|
|
992
|
-
return
|
|
998
|
+
return lt(e, n, r.groupById, r.expression);
|
|
993
999
|
case "groupBySelectItem": {
|
|
994
1000
|
const t = n.select.find((s) => s.id === r.selectId);
|
|
995
1001
|
if (!t) return n;
|
|
@@ -1002,7 +1008,7 @@ function he(e, n, r) {
|
|
|
1002
1008
|
return { ...n, distinct: r.distinct || void 0 };
|
|
1003
1009
|
case "addOrderByItem": {
|
|
1004
1010
|
const t = {
|
|
1005
|
-
id:
|
|
1011
|
+
id: tt(),
|
|
1006
1012
|
expression: { type: "field" },
|
|
1007
1013
|
direction: "asc"
|
|
1008
1014
|
};
|
|
@@ -1013,11 +1019,11 @@ function he(e, n, r) {
|
|
|
1013
1019
|
return { ...n, orderBy: t.length > 0 ? t : void 0 };
|
|
1014
1020
|
}
|
|
1015
1021
|
case "reorderOrderByItems": {
|
|
1016
|
-
const t = n.orderBy ?? [], o =
|
|
1022
|
+
const t = n.orderBy ?? [], o = de(t, r.fromIndex, r.toIndex);
|
|
1017
1023
|
return o === t ? n : { ...n, orderBy: o };
|
|
1018
1024
|
}
|
|
1019
1025
|
case "setOrderByExpression":
|
|
1020
|
-
return
|
|
1026
|
+
return ut(e, n, r.orderById, r.expression);
|
|
1021
1027
|
case "setOrderByDirection":
|
|
1022
1028
|
return {
|
|
1023
1029
|
...n,
|
|
@@ -1036,65 +1042,65 @@ function he(e, n, r) {
|
|
|
1036
1042
|
return n;
|
|
1037
1043
|
}
|
|
1038
1044
|
}
|
|
1039
|
-
const
|
|
1045
|
+
const ct = {
|
|
1040
1046
|
inner: "INNER",
|
|
1041
1047
|
left: "LEFT",
|
|
1042
1048
|
right: "RIGHT",
|
|
1043
1049
|
full: "FULL",
|
|
1044
1050
|
cross: "CROSS"
|
|
1045
1051
|
};
|
|
1046
|
-
function
|
|
1047
|
-
return `${
|
|
1052
|
+
function Jt(e) {
|
|
1053
|
+
return `${ct[e.joinType]} JOIN ${v(e)}`;
|
|
1048
1054
|
}
|
|
1049
|
-
function
|
|
1055
|
+
function Pt(e) {
|
|
1050
1056
|
return e.alias || "Column";
|
|
1051
1057
|
}
|
|
1052
|
-
function
|
|
1058
|
+
function Vt() {
|
|
1053
1059
|
return "Sort";
|
|
1054
1060
|
}
|
|
1055
|
-
function
|
|
1061
|
+
function Wt() {
|
|
1056
1062
|
return "Group";
|
|
1057
1063
|
}
|
|
1058
|
-
function
|
|
1064
|
+
function Ht(e, n, r) {
|
|
1059
1065
|
const t = S(n);
|
|
1060
1066
|
if (r !== void 0) {
|
|
1061
1067
|
const a = t.findIndex((l) => "id" in l && l.id === r);
|
|
1062
|
-
return new Set(t.slice(0, a + 1).map(
|
|
1068
|
+
return new Set(t.slice(0, a + 1).map(v));
|
|
1063
1069
|
}
|
|
1064
|
-
const o = new Set(
|
|
1065
|
-
return /* @__PURE__ */ new Set([...t.map(
|
|
1070
|
+
const o = new Set(J(n)), s = Rn(e, [...o]), i = new Set(nn(e, n).map((a) => a.table)), u = q(e).filter((a) => !o.has(a.name) && (s.has(a.name) || i.has(a.name)));
|
|
1071
|
+
return /* @__PURE__ */ new Set([...t.map(v), ...u.map((a) => a.name)]);
|
|
1066
1072
|
}
|
|
1067
|
-
function
|
|
1073
|
+
function Xt(e, n) {
|
|
1068
1074
|
const r = S(n);
|
|
1069
1075
|
return q(e).flatMap((t) => {
|
|
1070
|
-
const o = r.filter((s) => s.table === t.name).map(
|
|
1076
|
+
const o = r.filter((s) => s.table === t.name).map(v);
|
|
1071
1077
|
return (o.length > 0 ? o : [t.name]).map((s) => ({ ref: s, table: t }));
|
|
1072
1078
|
});
|
|
1073
1079
|
}
|
|
1074
|
-
function
|
|
1075
|
-
const r = new Set(
|
|
1080
|
+
function Kt(e, n) {
|
|
1081
|
+
const r = new Set(J(n));
|
|
1076
1082
|
return q(e).filter((t) => !r.has(t.name));
|
|
1077
1083
|
}
|
|
1078
|
-
function
|
|
1079
|
-
return e ? e.type === "logical" ? e.operands.reduce((n, r) => n +
|
|
1084
|
+
function be(e) {
|
|
1085
|
+
return e ? e.type === "logical" ? e.operands.reduce((n, r) => n + be(r), 0) : e.type === "not" ? be(e.operand) : 1 : 0;
|
|
1080
1086
|
}
|
|
1081
1087
|
function Ge(e) {
|
|
1082
1088
|
return e.column ? e.table ? `${e.table}.${e.column}` : e.column : "?";
|
|
1083
1089
|
}
|
|
1084
|
-
function
|
|
1090
|
+
function Yt(e, n = et) {
|
|
1085
1091
|
var r;
|
|
1086
|
-
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(
|
|
1092
|
+
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;
|
|
1087
1093
|
}
|
|
1088
|
-
function
|
|
1094
|
+
function zt(e, n) {
|
|
1089
1095
|
const r = new Set(I(e.where));
|
|
1090
1096
|
return I(e.having).forEach((t) => r.add(t)), e.joins.filter((t) => t.id !== n).forEach((t) => I(t.on).forEach((o) => r.add(o))), [...e.select, ...e.groupBy ?? [], ...e.orderBy ?? []].forEach((t) => I(t.expression).forEach((o) => r.add(o))), r;
|
|
1091
1097
|
}
|
|
1092
|
-
function
|
|
1093
|
-
const t =
|
|
1098
|
+
function Zt(e, n, r) {
|
|
1099
|
+
const t = ae(e, r);
|
|
1094
1100
|
return { ...L(e, n, t), where: t };
|
|
1095
1101
|
}
|
|
1096
|
-
function
|
|
1097
|
-
return r.length === 0 ? he(e, n, t) : U(n) ?
|
|
1102
|
+
function er(e, n, r, t) {
|
|
1103
|
+
return r.length === 0 ? he(e, n, t) : U(n) ? ze(n, r, (o) => he(e, o, t)) : n;
|
|
1098
1104
|
}
|
|
1099
1105
|
const un = (e) => e.query !== void 0 && !C(e.query);
|
|
1100
1106
|
function ln(e) {
|
|
@@ -1103,7 +1109,7 @@ function ln(e) {
|
|
|
1103
1109
|
n.set(r.fromTable, [...n.get(r.fromTable) ?? [], r.toTable]);
|
|
1104
1110
|
}), n;
|
|
1105
1111
|
}
|
|
1106
|
-
function
|
|
1112
|
+
function P(e, n, r = ln(e)) {
|
|
1107
1113
|
const t = /* @__PURE__ */ new Set([n]), o = [n];
|
|
1108
1114
|
for (let s = o.shift(); s !== void 0; s = o.shift())
|
|
1109
1115
|
(r.get(s) ?? []).forEach((i) => {
|
|
@@ -1113,7 +1119,7 @@ function J(e, n, r = ln(e)) {
|
|
|
1113
1119
|
}
|
|
1114
1120
|
const j = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [];
|
|
1115
1121
|
function cn(e, n) {
|
|
1116
|
-
const r = new Map(S(e).map((t) => [
|
|
1122
|
+
const r = new Map(S(e).map((t) => [v(t), t.table]));
|
|
1117
1123
|
return I(n).map((t) => ({
|
|
1118
1124
|
ref: t,
|
|
1119
1125
|
table: r.has(t) ? r.get(t) : t
|
|
@@ -1121,8 +1127,8 @@ function cn(e, n) {
|
|
|
1121
1127
|
}
|
|
1122
1128
|
const Ce = (e, n) => cn(e, n).map((r) => r.table);
|
|
1123
1129
|
function Fe(e, n) {
|
|
1124
|
-
const r = new Map(S(e).map((t) => [
|
|
1125
|
-
return
|
|
1130
|
+
const r = new Map(S(e).map((t) => [v(t), t.table]));
|
|
1131
|
+
return Ne(n, (t) => {
|
|
1126
1132
|
if (t.type !== "field" || t.table === void 0) return t;
|
|
1127
1133
|
const o = r.get(t.table);
|
|
1128
1134
|
return o === void 0 || o === t.table ? t : { ...t, table: o };
|
|
@@ -1131,19 +1137,19 @@ function Fe(e, n) {
|
|
|
1131
1137
|
function dn(e, n) {
|
|
1132
1138
|
const r = (n.groupBy ?? []).flatMap((o) => cn(n, o.expression)), t = ln(e);
|
|
1133
1139
|
return q(e).map((o) => {
|
|
1134
|
-
const s =
|
|
1140
|
+
const s = P(e, o.name, t), i = r.find((u) => u.table === void 0 || !s.has(u.table));
|
|
1135
1141
|
return i ? { table: o, unlinked: i.table ?? i.ref } : { table: o };
|
|
1136
1142
|
});
|
|
1137
1143
|
}
|
|
1138
|
-
function
|
|
1139
|
-
const t =
|
|
1144
|
+
function dt(e, n, r) {
|
|
1145
|
+
const t = P(e, r);
|
|
1140
1146
|
return j(n.where).filter((o) => {
|
|
1141
1147
|
const s = Ce(n, o);
|
|
1142
1148
|
return s.length > 0 && s.every((i) => i !== void 0 && t.has(i));
|
|
1143
1149
|
});
|
|
1144
1150
|
}
|
|
1145
|
-
function
|
|
1146
|
-
const t =
|
|
1151
|
+
function nr(e, n, r) {
|
|
1152
|
+
const t = P(e, r);
|
|
1147
1153
|
return j(n.where).some((o) => {
|
|
1148
1154
|
const s = Ce(n, o);
|
|
1149
1155
|
return s.some((i) => i !== void 0 && t.has(i)) && s.some((i) => i === void 0 || !t.has(i));
|
|
@@ -1154,7 +1160,7 @@ function X(e, n) {
|
|
|
1154
1160
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1155
1161
|
return r;
|
|
1156
1162
|
}
|
|
1157
|
-
function
|
|
1163
|
+
function ge(e, n) {
|
|
1158
1164
|
if (e.type === "field" && e.column) return e.column;
|
|
1159
1165
|
if (e.type === "function") {
|
|
1160
1166
|
const r = e.args[0];
|
|
@@ -1162,8 +1168,8 @@ function be(e, n) {
|
|
|
1162
1168
|
}
|
|
1163
1169
|
return n;
|
|
1164
1170
|
}
|
|
1165
|
-
const
|
|
1166
|
-
function
|
|
1171
|
+
const we = (e, n) => ({ type: "field", table: e, column: n });
|
|
1172
|
+
function ft(e, n) {
|
|
1167
1173
|
return {
|
|
1168
1174
|
type: "logical",
|
|
1169
1175
|
operator: "OR",
|
|
@@ -1185,60 +1191,60 @@ function dt(e, n) {
|
|
|
1185
1191
|
]
|
|
1186
1192
|
};
|
|
1187
1193
|
}
|
|
1188
|
-
function
|
|
1194
|
+
function mt(e, n, r) {
|
|
1189
1195
|
var s;
|
|
1190
1196
|
if (r.type !== "field" || r.table === void 0 || r.column === void 0) return !1;
|
|
1191
1197
|
const t = Ce(n, r)[0], o = (s = A(e, t)) == null ? void 0 : s.columns.find((i) => i.name === r.column);
|
|
1192
1198
|
return o !== void 0 && !o.nullable;
|
|
1193
1199
|
}
|
|
1194
1200
|
function fn(e, n, r, t) {
|
|
1195
|
-
const o = n.groupBy.map((i) => i.expression), s = t.map((i, u) =>
|
|
1201
|
+
const o = n.groupBy.map((i) => i.expression), s = t.map((i, u) => mt(e, n, o[u]) ? {
|
|
1196
1202
|
type: "binary",
|
|
1197
1203
|
operator: "=",
|
|
1198
|
-
left:
|
|
1204
|
+
left: we(r, i),
|
|
1199
1205
|
right: o[u]
|
|
1200
|
-
} :
|
|
1206
|
+
} : ft(we(r, i), o[u]));
|
|
1201
1207
|
return s.length === 1 ? s[0] : { type: "logical", operator: "AND", operands: s };
|
|
1202
1208
|
}
|
|
1203
1209
|
function mn(e, n, r, t, o, s) {
|
|
1204
1210
|
var b;
|
|
1205
|
-
const i = n.groupBy.map((
|
|
1206
|
-
const
|
|
1207
|
-
return a.add(
|
|
1211
|
+
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 = X(ge(y, `key_${w + 1}`), a);
|
|
1213
|
+
return a.add(T), T;
|
|
1208
1214
|
}), c = [...u, ...t];
|
|
1209
|
-
let
|
|
1215
|
+
let d = {
|
|
1210
1216
|
id: "",
|
|
1211
1217
|
from: { table: r },
|
|
1212
1218
|
joins: [],
|
|
1213
1219
|
select: []
|
|
1214
1220
|
};
|
|
1215
|
-
[...i, ...c, ...o.map((
|
|
1216
|
-
|
|
1221
|
+
[...i, ...c, ...o.map((y) => y.expression)].forEach((y) => {
|
|
1222
|
+
d = L(e, d, y);
|
|
1217
1223
|
});
|
|
1218
|
-
const
|
|
1219
|
-
const w = m.findIndex(($) => $.table !== void 0 && $.table ===
|
|
1220
|
-
if (w === -1) return
|
|
1221
|
-
const [
|
|
1222
|
-
return { ...
|
|
1224
|
+
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(($) => $.table !== void 0 && $.table === y.table);
|
|
1226
|
+
if (w === -1) return y;
|
|
1227
|
+
const [T] = m.splice(w, 1);
|
|
1228
|
+
return { ...y, id: T.id };
|
|
1223
1229
|
}), p = {
|
|
1224
1230
|
...s,
|
|
1225
|
-
from:
|
|
1231
|
+
from: d.from,
|
|
1226
1232
|
joins: g,
|
|
1227
1233
|
where: c.length > 0 ? { type: "logical", operator: "AND", operands: c } : void 0,
|
|
1228
|
-
groupBy: i.map((
|
|
1229
|
-
var
|
|
1234
|
+
groupBy: i.map((y, w) => {
|
|
1235
|
+
var T, $;
|
|
1230
1236
|
return {
|
|
1231
|
-
id: (($ = (
|
|
1232
|
-
expression:
|
|
1237
|
+
id: (($ = (T = s == null ? void 0 : s.groupBy) == null ? void 0 : T[w]) == null ? void 0 : $.id) ?? E(),
|
|
1238
|
+
expression: y
|
|
1233
1239
|
};
|
|
1234
1240
|
}),
|
|
1235
1241
|
select: [
|
|
1236
|
-
...i.map((
|
|
1237
|
-
var
|
|
1242
|
+
...i.map((y, w) => {
|
|
1243
|
+
var T;
|
|
1238
1244
|
return {
|
|
1239
|
-
id: w <
|
|
1245
|
+
id: w < f && ((T = s == null ? void 0 : s.select[w]) == null ? void 0 : T.id) || E(),
|
|
1240
1246
|
alias: l[w],
|
|
1241
|
-
expression:
|
|
1247
|
+
expression: y
|
|
1242
1248
|
};
|
|
1243
1249
|
}),
|
|
1244
1250
|
...o
|
|
@@ -1246,7 +1252,7 @@ function mn(e, n, r, t, o, s) {
|
|
|
1246
1252
|
};
|
|
1247
1253
|
return p.where === void 0 && delete p.where, { query: p, copied: u.length, keyNames: l };
|
|
1248
1254
|
}
|
|
1249
|
-
function
|
|
1255
|
+
function tr(e, n, r) {
|
|
1250
1256
|
var g;
|
|
1251
1257
|
if ((n.groupBy ?? []).length === 0)
|
|
1252
1258
|
throw new Error("addMeasure: the query isn't grouped (a measure is per group)");
|
|
@@ -1261,25 +1267,25 @@ function nr(e, n, r) {
|
|
|
1261
1267
|
let { joins: i } = n, u, a;
|
|
1262
1268
|
if (s) {
|
|
1263
1269
|
u = s.alias;
|
|
1264
|
-
const p = ((g = s.query.groupBy) == null ? void 0 : g.length) ?? 0, b = s.query.select.slice(p).find((
|
|
1270
|
+
const p = ((g = s.query.groupBy) == null ? void 0 : g.length) ?? 0, b = s.query.select.slice(p).find((y) => M(y.expression, r.value));
|
|
1265
1271
|
if (b)
|
|
1266
1272
|
a = b.alias;
|
|
1267
1273
|
else {
|
|
1268
1274
|
a = X(
|
|
1269
|
-
|
|
1275
|
+
ge(r.value, "value"),
|
|
1270
1276
|
new Set(s.query.select.map((w) => w.alias ?? ""))
|
|
1271
1277
|
);
|
|
1272
|
-
const
|
|
1273
|
-
i = i.map((w) => w === s ? { ...s, query: { ...s.query, select: [...s.query.select,
|
|
1278
|
+
const y = { id: E(), alias: a, expression: r.value };
|
|
1279
|
+
i = i.map((w) => w === s ? { ...s, query: { ...s.query, select: [...s.query.select, y] } } : w);
|
|
1274
1280
|
}
|
|
1275
1281
|
} else {
|
|
1276
|
-
a =
|
|
1277
|
-
const p = { id: E(), alias: a, expression: r.value }, b = mn(e, n, r.table, o, [p]),
|
|
1278
|
-
...S(n).map(
|
|
1282
|
+
a = ge(r.value, "value");
|
|
1283
|
+
const p = { id: E(), alias: a, expression: r.value }, b = mn(e, n, r.table, o, [p]), y = /* @__PURE__ */ new Set([
|
|
1284
|
+
...S(n).map(v),
|
|
1279
1285
|
...q(e).map(($) => $.name)
|
|
1280
1286
|
]), w = `${r.table}_per_${b.keyNames.join("_and_")}`.slice(0, D - 4);
|
|
1281
|
-
u = X(w,
|
|
1282
|
-
const
|
|
1287
|
+
u = X(w, y);
|
|
1288
|
+
const T = {
|
|
1283
1289
|
id: E(),
|
|
1284
1290
|
alias: u,
|
|
1285
1291
|
joinType: "left",
|
|
@@ -1287,24 +1293,24 @@ function nr(e, n, r) {
|
|
|
1287
1293
|
on: fn(e, n, u, b.keyNames),
|
|
1288
1294
|
drillAcross: { synced: !0, copied: b.copied }
|
|
1289
1295
|
};
|
|
1290
|
-
i = [...i,
|
|
1296
|
+
i = [...i, T];
|
|
1291
1297
|
}
|
|
1292
1298
|
const l = {
|
|
1293
1299
|
type: "function",
|
|
1294
1300
|
name: "MAX",
|
|
1295
|
-
args: [
|
|
1296
|
-
}, c = new Set(n.select.map((p) => p.alias).filter((p) => !!p)),
|
|
1297
|
-
let
|
|
1298
|
-
return
|
|
1301
|
+
args: [we(u, a)]
|
|
1302
|
+
}, c = new Set(n.select.map((p) => p.alias).filter((p) => !!p)), d = X(`${r.table}_${a}`.slice(0, D - 4), c);
|
|
1303
|
+
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
|
+
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 };
|
|
1299
1305
|
}
|
|
1300
1306
|
function pn(e, n, r) {
|
|
1301
|
-
var c,
|
|
1307
|
+
var c, d;
|
|
1302
1308
|
if (!un(r)) return;
|
|
1303
1309
|
const t = r, o = t.query.from.table, s = n.groupBy ?? [];
|
|
1304
1310
|
if (o === void 0 || s.length === 0) return;
|
|
1305
|
-
const i = dn(e, n).find((
|
|
1311
|
+
const i = dn(e, n).find((f) => f.table.name === o);
|
|
1306
1312
|
if (!i || i.unlinked !== void 0) return;
|
|
1307
|
-
const u = ((c = t.query.groupBy) == null ? void 0 : c.length) ?? 0, a = j(t.query.where).slice(((
|
|
1313
|
+
const u = ((c = t.query.groupBy) == null ? void 0 : c.length) ?? 0, a = j(t.query.where).slice(((d = t.drillAcross) == null ? void 0 : d.copied) ?? 0), l = mn(e, n, o, a, t.query.select.slice(u), t.query);
|
|
1308
1314
|
return {
|
|
1309
1315
|
...t,
|
|
1310
1316
|
query: l.query,
|
|
@@ -1322,15 +1328,15 @@ function z(e) {
|
|
|
1322
1328
|
on: e.on
|
|
1323
1329
|
};
|
|
1324
1330
|
}
|
|
1325
|
-
function
|
|
1331
|
+
function rr(e, n, r) {
|
|
1326
1332
|
const t = pn(e, n, r);
|
|
1327
1333
|
return t !== void 0 && M(z(t), z(r));
|
|
1328
1334
|
}
|
|
1329
|
-
function
|
|
1335
|
+
function yn(e, n, r) {
|
|
1330
1336
|
let t = !1;
|
|
1331
1337
|
const o = (u, a) => se(
|
|
1332
1338
|
a,
|
|
1333
|
-
(l, c) =>
|
|
1339
|
+
(l, c) => yn(
|
|
1334
1340
|
e,
|
|
1335
1341
|
u && C(u) === C(a) ? Y(u)[c] : void 0,
|
|
1336
1342
|
l
|
|
@@ -1341,25 +1347,25 @@ function hn(e, n, r) {
|
|
|
1341
1347
|
})() : r.from;
|
|
1342
1348
|
s !== r.from && (t = !0);
|
|
1343
1349
|
const i = r.joins.map((u) => {
|
|
1344
|
-
var
|
|
1350
|
+
var d;
|
|
1345
1351
|
if (!u.query) return u;
|
|
1346
|
-
const a = n == null ? void 0 : n.joins.find((
|
|
1352
|
+
const a = n == null ? void 0 : n.joins.find((f) => f.id === u.id && f.query !== void 0), l = o(a == null ? void 0 : a.query, u.query);
|
|
1347
1353
|
let c = l === u.query ? u : { ...u, query: l };
|
|
1348
|
-
if ((
|
|
1349
|
-
const
|
|
1350
|
-
|
|
1354
|
+
if ((d = c.drillAcross) != null && d.synced) {
|
|
1355
|
+
const f = pn(e, r, c);
|
|
1356
|
+
f && !M(f, c) && (c = f);
|
|
1351
1357
|
} else if (c.drillAcross && (a != null && a.drillAcross) && !M(z(a), z(c))) {
|
|
1352
|
-
const
|
|
1353
|
-
delete
|
|
1358
|
+
const f = { ...c };
|
|
1359
|
+
delete f.drillAcross, c = f;
|
|
1354
1360
|
}
|
|
1355
1361
|
return c !== u && (t = !0), c;
|
|
1356
1362
|
});
|
|
1357
1363
|
return t ? { ...r, from: s, joins: i } : r;
|
|
1358
1364
|
}
|
|
1359
|
-
function
|
|
1360
|
-
return U(r) ?
|
|
1365
|
+
function pt(e, n, r) {
|
|
1366
|
+
return U(r) ? yn(e, n && U(n) ? n : void 0, r) : r;
|
|
1361
1367
|
}
|
|
1362
|
-
const
|
|
1368
|
+
const or = ["text", "number", "date", "boolean"], yt = {
|
|
1363
1369
|
varchar: "text",
|
|
1364
1370
|
integer: "integer",
|
|
1365
1371
|
decimal: "number",
|
|
@@ -1369,9 +1375,9 @@ const rr = ["text", "number", "date", "boolean"], pt = {
|
|
|
1369
1375
|
boolean: "boolean"
|
|
1370
1376
|
};
|
|
1371
1377
|
function ht(e) {
|
|
1372
|
-
return
|
|
1378
|
+
return yt[e];
|
|
1373
1379
|
}
|
|
1374
|
-
function
|
|
1380
|
+
function bt(e) {
|
|
1375
1381
|
const n = e.trim().toUpperCase();
|
|
1376
1382
|
if (/^((TINY|SMALL|MEDIUM|BIG)?INT|SIGNED|UNSIGNED)/.test(n)) return "integer";
|
|
1377
1383
|
if (/^(DECIMAL|NUMERIC|FLOAT|DOUBLE|REAL|MONEY)/.test(n)) return "number";
|
|
@@ -1381,14 +1387,14 @@ function yt(e) {
|
|
|
1381
1387
|
if (/^BOOL|^BIT$/.test(n)) return "boolean";
|
|
1382
1388
|
if (/^(N?VAR)?CHAR|^N?TEXT|^STRING/.test(n)) return "text";
|
|
1383
1389
|
}
|
|
1384
|
-
function
|
|
1390
|
+
function hn(e) {
|
|
1385
1391
|
if (e.as) return e.as;
|
|
1386
1392
|
const { value: n } = e;
|
|
1387
1393
|
if (typeof n == "string") return n === "" ? void 0 : "text";
|
|
1388
1394
|
if (typeof n == "number") return Number.isInteger(n) ? "integer" : "number";
|
|
1389
1395
|
if (typeof n == "bigint") return "integer";
|
|
1390
1396
|
if (typeof n == "boolean") return "boolean";
|
|
1391
|
-
if (n instanceof Date) return
|
|
1397
|
+
if (n instanceof Date) return We(n) ? "date" : "dateTime";
|
|
1392
1398
|
}
|
|
1393
1399
|
function bn(e, n, r) {
|
|
1394
1400
|
if (!e) return;
|
|
@@ -1397,11 +1403,11 @@ function bn(e, n, r) {
|
|
|
1397
1403
|
case "field":
|
|
1398
1404
|
return n(e);
|
|
1399
1405
|
case "literal":
|
|
1400
|
-
return
|
|
1406
|
+
return hn(e);
|
|
1401
1407
|
case "function": {
|
|
1402
|
-
const o =
|
|
1408
|
+
const o = Qn(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;
|
|
1403
1409
|
if ((i == null ? void 0 : i.type) === "literal" && typeof i.value == "string")
|
|
1404
|
-
return
|
|
1410
|
+
return bt(i.value);
|
|
1405
1411
|
const u = o == null ? void 0 : o.returns;
|
|
1406
1412
|
return u === "arg" ? t(e.args[0]) : u;
|
|
1407
1413
|
}
|
|
@@ -1413,28 +1419,28 @@ function bn(e, n, r) {
|
|
|
1413
1419
|
return;
|
|
1414
1420
|
}
|
|
1415
1421
|
}
|
|
1416
|
-
const
|
|
1422
|
+
const gt = /^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i, wt = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$/, St = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
1417
1423
|
function gn(e, n) {
|
|
1418
1424
|
if (e === "" || e === null) return e;
|
|
1419
1425
|
const r = typeof e == "string" ? e.trim() : void 0;
|
|
1420
1426
|
switch (n) {
|
|
1421
1427
|
case "text":
|
|
1422
|
-
return e instanceof Date ?
|
|
1428
|
+
return e instanceof Date ? Pn(e) : String(e);
|
|
1423
1429
|
case "integer":
|
|
1424
1430
|
case "number": {
|
|
1425
1431
|
let t;
|
|
1426
|
-
return typeof e == "number" ? t = e : typeof e == "bigint" ? t = Number(e) : r !== void 0 &&
|
|
1432
|
+
return typeof e == "number" ? t = e : typeof e == "bigint" ? t = Number(e) : r !== void 0 && gt.test(r) && (t = Number(r)), t === void 0 || !Hn(t) || n === "integer" && !Number.isInteger(t) ? void 0 : t;
|
|
1427
1433
|
}
|
|
1428
1434
|
case "date":
|
|
1429
1435
|
case "dateTime": {
|
|
1430
|
-
if (e instanceof Date) return n === "date" && !
|
|
1431
|
-
const t = r === void 0 ? null :
|
|
1436
|
+
if (e instanceof Date) return n === "date" && !We(e) ? void 0 : e;
|
|
1437
|
+
const t = r === void 0 ? null : St.exec(r);
|
|
1432
1438
|
if (!t) return;
|
|
1433
|
-
const [, o, s, i, u, a, l] = t.map(Number), c =
|
|
1439
|
+
const [, o, s, i, u, a, l] = t.map(Number), c = Jn(o, s, i);
|
|
1434
1440
|
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));
|
|
1435
1441
|
}
|
|
1436
1442
|
case "time": {
|
|
1437
|
-
const t = r === void 0 ? null :
|
|
1443
|
+
const t = r === void 0 ? null : wt.exec(r);
|
|
1438
1444
|
return t ? `${t[1]}:${t[2]}:${t[3] ?? "00"}` : void 0;
|
|
1439
1445
|
}
|
|
1440
1446
|
case "boolean":
|
|
@@ -1444,28 +1450,28 @@ function gn(e, n) {
|
|
|
1444
1450
|
return;
|
|
1445
1451
|
}
|
|
1446
1452
|
}
|
|
1447
|
-
function
|
|
1453
|
+
function vt(e, n, r) {
|
|
1448
1454
|
var c;
|
|
1449
1455
|
if (n === void 0) return e;
|
|
1450
1456
|
const { as: t, empty: o, ...s } = e;
|
|
1451
1457
|
let i = gn(e.value, n);
|
|
1452
|
-
r != null && r.length && i !== "" && i !== null && (i = (c = r.find((
|
|
1458
|
+
r != null && r.length && i !== "" && i !== null && (i = (c = r.find((d) => String(d.value) === String(e.value))) == null ? void 0 : c.value);
|
|
1453
1459
|
const u = o && n === "text", a = i === void 0 ? { type: "literal", value: "" } : { ...s, value: i, ...u ? { empty: o } : {} };
|
|
1454
1460
|
return t === void 0 && !!o == !!u && i === e.value ? e : a;
|
|
1455
1461
|
}
|
|
1456
|
-
function
|
|
1462
|
+
function sr(e, n, r, t = !1) {
|
|
1457
1463
|
const o = e.items.flatMap((i) => {
|
|
1458
1464
|
if (i.type !== "literal") return [i];
|
|
1459
|
-
const u =
|
|
1465
|
+
const u = vt(i, n, r);
|
|
1460
1466
|
return u.value === "" && !u.empty && !t ? [] : [u];
|
|
1461
1467
|
});
|
|
1462
1468
|
return o.length === e.items.length && o.every((i, u) => i === e.items[u]) ? e : { ...e, items: o };
|
|
1463
1469
|
}
|
|
1464
|
-
function
|
|
1465
|
-
const n =
|
|
1470
|
+
function ir(e) {
|
|
1471
|
+
const n = hn(e);
|
|
1466
1472
|
return n === "integer" || n === "number" ? "number" : n === "date" || n === "dateTime" ? "date" : n;
|
|
1467
1473
|
}
|
|
1468
|
-
function
|
|
1474
|
+
function ar(e, n) {
|
|
1469
1475
|
const t = (e.type === "literal" ? gn(e.value, n) : void 0) ?? "", o = e.type === "literal" && e.empty && n === "text";
|
|
1470
1476
|
return {
|
|
1471
1477
|
type: "literal",
|
|
@@ -1474,31 +1480,31 @@ function ir(e, n) {
|
|
|
1474
1480
|
...o ? { empty: o } : {}
|
|
1475
1481
|
};
|
|
1476
1482
|
}
|
|
1477
|
-
const
|
|
1478
|
-
function
|
|
1483
|
+
const me = "IS NOT DISTINCT FROM";
|
|
1484
|
+
function ur(e, n = !1) {
|
|
1479
1485
|
if (e !== void 0)
|
|
1480
1486
|
return e === "text" ? [
|
|
1481
1487
|
"=",
|
|
1482
1488
|
"!=",
|
|
1483
|
-
|
|
1489
|
+
me,
|
|
1484
1490
|
"LIKE",
|
|
1485
1491
|
"REGEXP",
|
|
1486
1492
|
"IN",
|
|
1487
1493
|
...n ? ["BETWEEN"] : [],
|
|
1488
1494
|
"IS NULL",
|
|
1489
1495
|
"IS NOT NULL"
|
|
1490
|
-
] : e === "boolean" ? ["=", "!=",
|
|
1496
|
+
] : e === "boolean" ? ["=", "!=", me, "IS NULL", "IS NOT NULL"] : ["=", "!=", me, "<", "<=", ">", ">=", "IN", "BETWEEN", "IS NULL", "IS NOT NULL"];
|
|
1491
1497
|
}
|
|
1492
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, $e = (e) => new Map(
|
|
1493
|
-
S(e).map((n) => [
|
|
1499
|
+
S(e).map((n) => [v(n), n.table])
|
|
1494
1500
|
);
|
|
1495
|
-
function
|
|
1501
|
+
function Se(e, n) {
|
|
1496
1502
|
const r = $e(e);
|
|
1497
1503
|
return I(n).map((t) => r.get(t) ?? t);
|
|
1498
1504
|
}
|
|
1499
|
-
function
|
|
1505
|
+
function vn(e, n) {
|
|
1500
1506
|
const r = $e(e);
|
|
1501
|
-
return
|
|
1507
|
+
return Ne(n, (t) => {
|
|
1502
1508
|
if (t.type !== "field" || t.table === void 0) return t;
|
|
1503
1509
|
const o = r.get(t.table);
|
|
1504
1510
|
return o === void 0 || o === t.table ? t : { ...t, table: o };
|
|
@@ -1517,16 +1523,16 @@ function xe(e, n) {
|
|
|
1517
1523
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1518
1524
|
return r;
|
|
1519
1525
|
}
|
|
1520
|
-
const ee = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [],
|
|
1526
|
+
const ee = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [], Tn = (e) => {
|
|
1521
1527
|
if (e.length !== 0)
|
|
1522
1528
|
return e.length === 1 ? e[0] : { type: "logical", operator: "AND", operands: e };
|
|
1523
1529
|
}, k = (e) => e.from.table, Qe = (e, n) => A(e, n).label;
|
|
1524
|
-
function
|
|
1530
|
+
function ue(e) {
|
|
1525
1531
|
const { from: n } = e;
|
|
1526
1532
|
return n.query && C(n.query) ? n : void 0;
|
|
1527
1533
|
}
|
|
1528
1534
|
function V(e, n) {
|
|
1529
|
-
if (n === void 0) return
|
|
1535
|
+
if (n === void 0) return ue(e);
|
|
1530
1536
|
const r = O(e).find((t) => t.id === n);
|
|
1531
1537
|
return r && C(r.query) ? r : void 0;
|
|
1532
1538
|
}
|
|
@@ -1534,20 +1540,20 @@ function W(e, n, r) {
|
|
|
1534
1540
|
const t = { ...n, query: r };
|
|
1535
1541
|
return n === e.from ? { ...e, from: t } : { ...e, joins: e.joins.map((o) => o === n ? t : o) };
|
|
1536
1542
|
}
|
|
1537
|
-
function
|
|
1543
|
+
function le(e, n) {
|
|
1538
1544
|
const [r] = n;
|
|
1539
1545
|
return r.select.map((t, o) => {
|
|
1540
|
-
var
|
|
1541
|
-
const s = x(t) ?? "", i = n.map((
|
|
1546
|
+
var d;
|
|
1547
|
+
const s = x(t) ?? "", i = n.map((f) => {
|
|
1542
1548
|
var m;
|
|
1543
|
-
return { branch:
|
|
1544
|
-
}).filter((
|
|
1549
|
+
return { branch: f, expression: (m = f.select[o]) == null ? void 0 : m.expression };
|
|
1550
|
+
}).filter((f) => f.expression !== void 0 && !F(f.expression)), a = ((d = n.map((f) => {
|
|
1545
1551
|
var m;
|
|
1546
|
-
return (m =
|
|
1552
|
+
return (m = f.select[o]) == null ? void 0 : m.expression;
|
|
1547
1553
|
}).filter(
|
|
1548
|
-
(
|
|
1549
|
-
).find((
|
|
1550
|
-
if (s === wn && i.length === n.length && i.every((
|
|
1554
|
+
(f) => (f == null ? void 0 : f.type) === "literal" && f.value === null
|
|
1555
|
+
).find((f) => f.as)) == null ? void 0 : d.as) ?? (i[0] && Z(e, i[0].branch, i[0].expression));
|
|
1556
|
+
if (s === wn && i.length === n.length && i.every((f) => f.expression.type === "literal"))
|
|
1551
1557
|
return {
|
|
1552
1558
|
name: s,
|
|
1553
1559
|
kind: "source",
|
|
@@ -1569,8 +1575,8 @@ function ue(e, n) {
|
|
|
1569
1575
|
tables: [],
|
|
1570
1576
|
type: a
|
|
1571
1577
|
};
|
|
1572
|
-
const c =
|
|
1573
|
-
return i.some((
|
|
1578
|
+
const c = Se(l.branch, l.expression);
|
|
1579
|
+
return i.some((f) => Se(f.branch, f.expression).includes(k(f.branch))) ? {
|
|
1574
1580
|
name: s,
|
|
1575
1581
|
kind: "own",
|
|
1576
1582
|
tables: c,
|
|
@@ -1580,15 +1586,15 @@ function ue(e, n) {
|
|
|
1580
1586
|
kind: "shared",
|
|
1581
1587
|
tables: c,
|
|
1582
1588
|
type: a,
|
|
1583
|
-
expression:
|
|
1589
|
+
expression: vn(l.branch, l.expression)
|
|
1584
1590
|
};
|
|
1585
1591
|
});
|
|
1586
1592
|
}
|
|
1587
|
-
function
|
|
1588
|
-
const r =
|
|
1593
|
+
function lr(e, n) {
|
|
1594
|
+
const r = ue(n);
|
|
1589
1595
|
if (!r) return [];
|
|
1590
1596
|
const { union: t } = r.query;
|
|
1591
|
-
return
|
|
1597
|
+
return le(e, t).map((o, s) => {
|
|
1592
1598
|
const i = t.map((u) => !F(u.select[s].expression));
|
|
1593
1599
|
return {
|
|
1594
1600
|
name: o.name,
|
|
@@ -1599,79 +1605,79 @@ function ur(e, n) {
|
|
|
1599
1605
|
});
|
|
1600
1606
|
}
|
|
1601
1607
|
function Nn(e, n, r, t, o) {
|
|
1602
|
-
const s =
|
|
1608
|
+
const s = P(e, n), i = r.filter((c) => c.kind === "shared" && c.expression), u = (c) => c.tables.every((d) => s.has(d));
|
|
1603
1609
|
if (!i.some(u)) return `"${n}" shares no column with the union`;
|
|
1604
1610
|
const a = i.find((c) => !u(c));
|
|
1605
1611
|
if (a && o === "refuse")
|
|
1606
1612
|
return `"${n}" can't reach column "${a.name}" (${a.tables.join(", ")})`;
|
|
1607
|
-
const l = t.find((c) => !c.tables.every((
|
|
1613
|
+
const l = t.find((c) => !c.tables.every((d) => s.has(d)));
|
|
1608
1614
|
if (l)
|
|
1609
1615
|
return `"${n}" can't follow a condition on ${l.tables.join(", ")}`;
|
|
1610
1616
|
}
|
|
1611
1617
|
function En(e) {
|
|
1612
1618
|
const [n] = e, r = new Set(e.map(k));
|
|
1613
1619
|
return ee(n.where).flatMap((t) => {
|
|
1614
|
-
const o =
|
|
1615
|
-
if (s.length === 0) return [{ operand:
|
|
1620
|
+
const o = Se(n, t), s = o.filter((i) => r.has(i));
|
|
1621
|
+
if (s.length === 0) return [{ operand: vn(n, t), tables: o }];
|
|
1616
1622
|
if (s.length === o.length) return [];
|
|
1617
1623
|
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");
|
|
1618
1624
|
});
|
|
1619
1625
|
}
|
|
1620
|
-
function
|
|
1621
|
-
const o = t.unshared ?? "refuse", s =
|
|
1626
|
+
function _e(e, n, r, t) {
|
|
1627
|
+
const o = t.unshared ?? "refuse", s = le(e, n), i = En(n);
|
|
1622
1628
|
if (!A(e, r.table))
|
|
1623
1629
|
throw new Error(`addUnionTable: unknown table "${r.table}"`);
|
|
1624
|
-
if (n.some((
|
|
1630
|
+
if (n.some((h) => k(h) === r.table))
|
|
1625
1631
|
throw new Error(`addUnionTable: "${r.table}" is in the union already`);
|
|
1626
1632
|
const u = Nn(e, r.table, s, i, o);
|
|
1627
1633
|
if (u) throw new Error(`addUnionTable: ${u}`);
|
|
1628
|
-
const a =
|
|
1629
|
-
const N = xe(
|
|
1630
|
-
return
|
|
1634
|
+
const a = P(e, r.table), l = r.label ?? Qe(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) => {
|
|
1635
|
+
const N = xe(h, d);
|
|
1636
|
+
return d.add(N), f.push(N), N;
|
|
1631
1637
|
}, g = [], p = {
|
|
1632
1638
|
from: { table: r.table },
|
|
1633
1639
|
joins: []
|
|
1634
1640
|
};
|
|
1635
|
-
r.columns.forEach((
|
|
1636
|
-
const N =
|
|
1637
|
-
g.push({ name: m(N), own:
|
|
1638
|
-
}), t.source && !s.some((
|
|
1641
|
+
r.columns.forEach((h) => {
|
|
1642
|
+
const N = h.alias ?? (h.expression.type === "field" ? h.expression.column : void 0) ?? "value", Dn = Z(e, p, h.expression);
|
|
1643
|
+
g.push({ name: m(N), own: h.expression, others: () => B(Dn) });
|
|
1644
|
+
}), t.source && !s.some((h) => h.kind === "source") && g.push({
|
|
1639
1645
|
name: m(wn),
|
|
1640
1646
|
own: { type: "literal", value: l },
|
|
1641
|
-
others: (
|
|
1647
|
+
others: (h) => ({ type: "literal", value: Qe(e, k(h)) })
|
|
1642
1648
|
});
|
|
1643
|
-
const b = (
|
|
1644
|
-
(t.rowMarkers || s.some((
|
|
1649
|
+
const b = (h) => `${Sn}${h}`;
|
|
1650
|
+
(t.rowMarkers || s.some((h) => h.kind === "rows")) && (n.filter((h) => !d.has(b(k(h)))).forEach((h) => {
|
|
1645
1651
|
g.push({
|
|
1646
|
-
name: m(b(k(
|
|
1652
|
+
name: m(b(k(h))),
|
|
1647
1653
|
own: B("integer"),
|
|
1648
|
-
others: (N) => N ===
|
|
1654
|
+
others: (N) => N === h ? { type: "literal", value: 1 } : B("integer")
|
|
1649
1655
|
});
|
|
1650
1656
|
}), g.push({
|
|
1651
1657
|
name: m(b(r.table)),
|
|
1652
1658
|
own: { type: "literal", value: 1 },
|
|
1653
1659
|
others: () => B("integer")
|
|
1654
1660
|
}));
|
|
1655
|
-
const
|
|
1661
|
+
const y = (h, N) => ({
|
|
1656
1662
|
id: E(),
|
|
1657
|
-
alias:
|
|
1663
|
+
alias: h,
|
|
1658
1664
|
expression: N
|
|
1659
|
-
}), w = n.map((
|
|
1660
|
-
...
|
|
1661
|
-
select: [...
|
|
1662
|
-
})),
|
|
1665
|
+
}), w = n.map((h) => ({
|
|
1666
|
+
...h,
|
|
1667
|
+
select: [...h.select, ...g.map((N) => y(N.name, N.others(h)))]
|
|
1668
|
+
})), T = Tn([...i.map((h) => h.operand), ...ee(r.where)]);
|
|
1663
1669
|
let $ = {
|
|
1664
1670
|
id: "",
|
|
1665
1671
|
from: { table: r.table },
|
|
1666
1672
|
joins: [],
|
|
1667
|
-
...
|
|
1673
|
+
...T ? { where: T } : {},
|
|
1668
1674
|
select: [
|
|
1669
|
-
...s.map((
|
|
1670
|
-
...g.map((
|
|
1675
|
+
...s.map((h, N) => y(h.name, c[N])),
|
|
1676
|
+
...g.map((h) => y(h.name, h.own))
|
|
1671
1677
|
]
|
|
1672
1678
|
};
|
|
1673
|
-
[
|
|
1674
|
-
$ = L(e, $,
|
|
1679
|
+
[T, ...$.select.map((h) => h.expression)].forEach((h) => {
|
|
1680
|
+
$ = L(e, $, h);
|
|
1675
1681
|
});
|
|
1676
1682
|
const {
|
|
1677
1683
|
from: Mn,
|
|
@@ -1684,7 +1690,7 @@ function Pe(e, n, r, t) {
|
|
|
1684
1690
|
select: Un,
|
|
1685
1691
|
...Be ? { where: Be } : {}
|
|
1686
1692
|
};
|
|
1687
|
-
return { union: [...w, Ln], added:
|
|
1693
|
+
return { union: [...w, Ln], added: f };
|
|
1688
1694
|
}
|
|
1689
1695
|
function Cn(e) {
|
|
1690
1696
|
const n = (o) => new Error(`addUnionTable: ${o}`);
|
|
@@ -1703,19 +1709,19 @@ function Cn(e) {
|
|
|
1703
1709
|
select: t
|
|
1704
1710
|
};
|
|
1705
1711
|
}
|
|
1706
|
-
function
|
|
1707
|
-
const o =
|
|
1712
|
+
function cr(e, n, r, t = {}) {
|
|
1713
|
+
const o = ue(n);
|
|
1708
1714
|
if (o) {
|
|
1709
|
-
const { union: l, added: c } =
|
|
1715
|
+
const { union: l, added: c } = _e(e, o.query.union, r, t), d = { ...o, query: { ...o.query, union: l } }, f = n.select.length === 0 ? [] : [
|
|
1710
1716
|
...n.select,
|
|
1711
1717
|
...c.map((m) => ({
|
|
1712
1718
|
id: E(),
|
|
1713
1719
|
expression: { type: "field", table: o.alias, column: m }
|
|
1714
1720
|
}))
|
|
1715
1721
|
];
|
|
1716
|
-
return { ...n, from:
|
|
1722
|
+
return { ...n, from: d, select: f };
|
|
1717
1723
|
}
|
|
1718
|
-
const s = Cn(n), { union: i } =
|
|
1724
|
+
const s = Cn(n), { union: i } = _e(e, [s], r, t), u = t.alias ?? "stacked", a = i[0].select.map((l) => l.alias);
|
|
1719
1725
|
return {
|
|
1720
1726
|
id: n.id,
|
|
1721
1727
|
from: { id: E(), alias: u, query: { union: i, all: !0 } },
|
|
@@ -1728,15 +1734,15 @@ function lr(e, n, r, t = {}) {
|
|
|
1728
1734
|
...n.offset !== void 0 ? { offset: n.offset } : {}
|
|
1729
1735
|
};
|
|
1730
1736
|
}
|
|
1731
|
-
function
|
|
1732
|
-
const t =
|
|
1737
|
+
function dr(e, n, r = {}) {
|
|
1738
|
+
const t = ue(n);
|
|
1733
1739
|
let o;
|
|
1734
1740
|
try {
|
|
1735
1741
|
o = t ? t.query.union : [Cn(n)];
|
|
1736
1742
|
} catch {
|
|
1737
1743
|
return [];
|
|
1738
1744
|
}
|
|
1739
|
-
const s =
|
|
1745
|
+
const s = le(e, o);
|
|
1740
1746
|
let i;
|
|
1741
1747
|
try {
|
|
1742
1748
|
i = En(o);
|
|
@@ -1754,32 +1760,32 @@ function Tt(e, n, r) {
|
|
|
1754
1760
|
if (t === -1) return r;
|
|
1755
1761
|
const o = r.union[t], s = n.union[t].select.map((a) => a.id), i = r.union.map((a, l) => {
|
|
1756
1762
|
if (l === t) return a;
|
|
1757
|
-
const c = o.select.map((
|
|
1758
|
-
const m = x(
|
|
1763
|
+
const c = o.select.map((f) => {
|
|
1764
|
+
const m = x(f), g = Z(e, o, f.expression), p = s.indexOf(f.id), b = p === -1 ? void 0 : a.select[p];
|
|
1759
1765
|
if (!b)
|
|
1760
1766
|
return { id: E(), ...m ? { alias: m } : {}, expression: B(g) };
|
|
1761
|
-
let
|
|
1762
|
-
x(b) !== m && (
|
|
1767
|
+
let y = b;
|
|
1768
|
+
x(b) !== m && (y = { ...y, alias: m });
|
|
1763
1769
|
const { expression: w } = b;
|
|
1764
|
-
return F(w) && w.type === "literal" && w.as !== g && (
|
|
1770
|
+
return F(w) && w.type === "literal" && w.as !== g && (y = { ...y, expression: B(g) }), y;
|
|
1765
1771
|
});
|
|
1766
|
-
return c.length === a.select.length && c.every((
|
|
1772
|
+
return c.length === a.select.length && c.every((f, m) => f === a.select[m]) ? a : { ...a, select: c };
|
|
1767
1773
|
}), u = i.map((a) => {
|
|
1768
|
-
const l = a.select.map((c,
|
|
1769
|
-
const { expression:
|
|
1770
|
-
if (
|
|
1774
|
+
const l = a.select.map((c, d) => {
|
|
1775
|
+
const { expression: f } = c;
|
|
1776
|
+
if (f.type !== "literal" || f.value !== null) return c;
|
|
1771
1777
|
const m = i.find((p) => {
|
|
1772
|
-
var
|
|
1773
|
-
const b = (
|
|
1778
|
+
var y;
|
|
1779
|
+
const b = (y = p.select[d]) == null ? void 0 : y.expression;
|
|
1774
1780
|
return b !== void 0 && !F(b);
|
|
1775
|
-
}), g = m && Z(e, m, m.select[
|
|
1776
|
-
return g &&
|
|
1781
|
+
}), g = m && Z(e, m, m.select[d].expression);
|
|
1782
|
+
return g && f.as !== g ? { ...c, expression: B(g) } : c;
|
|
1777
1783
|
});
|
|
1778
|
-
return l.every((c,
|
|
1784
|
+
return l.every((c, d) => c === a.select[d]) ? a : { ...a, select: l };
|
|
1779
1785
|
});
|
|
1780
1786
|
return u.every((a, l) => a === r.union[l]) ? r : { ...r, union: u };
|
|
1781
1787
|
}
|
|
1782
|
-
function
|
|
1788
|
+
function Nt(e, n) {
|
|
1783
1789
|
const r = (s) => s.union[0].select.map((i) => x(i)), t = r(e), o = r(n);
|
|
1784
1790
|
return t.length !== o.length ? [] : t.flatMap((s, i) => {
|
|
1785
1791
|
const u = o[i];
|
|
@@ -1797,35 +1803,35 @@ function $n(e, n, r) {
|
|
|
1797
1803
|
));
|
|
1798
1804
|
}
|
|
1799
1805
|
function Ae(e, n, r) {
|
|
1800
|
-
const t = (
|
|
1806
|
+
const t = (f) => {
|
|
1801
1807
|
var m;
|
|
1802
1808
|
return $n(
|
|
1803
1809
|
e,
|
|
1804
|
-
n && ((m = O(n).find((g) => g.id ===
|
|
1805
|
-
|
|
1810
|
+
n && ((m = O(n).find((g) => g.id === f.id)) == null ? void 0 : m.query),
|
|
1811
|
+
f.query
|
|
1806
1812
|
);
|
|
1807
1813
|
}, { from: o } = r, s = o.query && t(o), i = s && s !== o.query ? { ...o, query: s } : o;
|
|
1808
1814
|
let u = !1;
|
|
1809
|
-
const a = r.joins.map((
|
|
1810
|
-
if (!
|
|
1811
|
-
const m = t(
|
|
1812
|
-
return m ===
|
|
1815
|
+
const a = r.joins.map((f) => {
|
|
1816
|
+
if (!f.query) return f;
|
|
1817
|
+
const m = t(f);
|
|
1818
|
+
return m === f.query ? f : (u = !0, { ...f, query: m });
|
|
1813
1819
|
});
|
|
1814
1820
|
if (i === o && !u) return r;
|
|
1815
|
-
const l = { ...r, from: i, joins: a }, c = O(l).flatMap((
|
|
1821
|
+
const l = { ...r, from: i, joins: a }, c = O(l).flatMap((f) => {
|
|
1816
1822
|
var g;
|
|
1817
|
-
const m = n && ((g = O(n).find((p) => p.id ===
|
|
1818
|
-
return m && C(m) && C(
|
|
1823
|
+
const m = n && ((g = O(n).find((p) => p.id === f.id)) == null ? void 0 : g.query);
|
|
1824
|
+
return m && C(m) && C(f.query) ? Nt(m, f.query).map((p) => ({ ...p, alias: f.alias })) : [];
|
|
1819
1825
|
});
|
|
1820
1826
|
if (c.length === 0) return l;
|
|
1821
|
-
const
|
|
1822
|
-
if (
|
|
1823
|
-
const m = c.find((g) => g.alias ===
|
|
1824
|
-
return m ? { ...
|
|
1827
|
+
const d = (f) => {
|
|
1828
|
+
if (f.type !== "field") return _(f, d);
|
|
1829
|
+
const m = c.find((g) => g.alias === f.table && g.from === f.column);
|
|
1830
|
+
return m ? { ...f, column: m.to } : f;
|
|
1825
1831
|
};
|
|
1826
|
-
return te(l,
|
|
1832
|
+
return te(l, d, (f) => f);
|
|
1827
1833
|
}
|
|
1828
|
-
function
|
|
1834
|
+
function Et(e, n, r) {
|
|
1829
1835
|
if (!U(r)) return r;
|
|
1830
1836
|
const t = n && U(n) ? n : void 0;
|
|
1831
1837
|
return Te(Ae(e, t, r), (o, s) => {
|
|
@@ -1841,7 +1847,7 @@ function xn(e) {
|
|
|
1841
1847
|
return e.type === "field" ? [e] : oe(e).flatMap(xn);
|
|
1842
1848
|
}
|
|
1843
1849
|
const An = (e, n, r) => xn(e).some((t) => t.table === n && r.has(t.column ?? ""));
|
|
1844
|
-
function
|
|
1850
|
+
function Ct(e, n, r) {
|
|
1845
1851
|
const t = n.query.union.filter((a, l) => l !== r), o = [
|
|
1846
1852
|
e.where,
|
|
1847
1853
|
e.having,
|
|
@@ -1851,32 +1857,32 @@ function Et(e, n, r) {
|
|
|
1851
1857
|
].filter((a) => a !== void 0), s = (a) => o.some(
|
|
1852
1858
|
(l) => An(l, n.alias, /* @__PURE__ */ new Set([a]))
|
|
1853
1859
|
), i = new Set(t[0].select.flatMap((a, l) => {
|
|
1854
|
-
const c = t.every((
|
|
1855
|
-
return c && !(
|
|
1860
|
+
const c = t.every((f) => f.select[l] && F(f.select[l].expression)), d = x(a);
|
|
1861
|
+
return c && !(d && s(d)) ? [l] : [];
|
|
1856
1862
|
})), u = new Set([...i].flatMap((a) => {
|
|
1857
1863
|
const l = x(t[0].select[a]);
|
|
1858
1864
|
return l ? [l] : [];
|
|
1859
1865
|
}));
|
|
1860
1866
|
return { at: i, names: u };
|
|
1861
1867
|
}
|
|
1862
|
-
function
|
|
1868
|
+
function fr(e, n, r) {
|
|
1863
1869
|
const t = V(e, r);
|
|
1864
1870
|
if (!t || !t.query.union[n] || t.query.union.length < 2) return e;
|
|
1865
|
-
const o =
|
|
1871
|
+
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(
|
|
1866
1872
|
(l) => !An(l.expression, t.alias, i.names)
|
|
1867
|
-
), a = s.map((l) => ({ ...l, select: l.select.filter((c,
|
|
1873
|
+
), a = s.map((l) => ({ ...l, select: l.select.filter((c, d) => !i.at.has(d)) }));
|
|
1868
1874
|
return W({ ...e, select: u }, t, { ...t.query, union: a });
|
|
1869
1875
|
}
|
|
1870
|
-
function
|
|
1876
|
+
function $t(e, n) {
|
|
1871
1877
|
const r = /* @__PURE__ */ new Set([
|
|
1872
|
-
...n ? S(n).map(
|
|
1878
|
+
...n ? S(n).map(v) : [],
|
|
1873
1879
|
...e.tables.map((o) => o.name)
|
|
1874
1880
|
]);
|
|
1875
1881
|
let t = 1;
|
|
1876
1882
|
for (; r.has(`union_${t}`); ) t += 1;
|
|
1877
1883
|
return `union_${t}`;
|
|
1878
1884
|
}
|
|
1879
|
-
function
|
|
1885
|
+
function mr(e, n, r, t) {
|
|
1880
1886
|
return {
|
|
1881
1887
|
id: e,
|
|
1882
1888
|
from: { id: n, alias: r, query: { union: [{ from: t, joins: [], select: [] }], all: !0 } },
|
|
@@ -1884,10 +1890,10 @@ function fr(e, n, r, t) {
|
|
|
1884
1890
|
select: []
|
|
1885
1891
|
};
|
|
1886
1892
|
}
|
|
1887
|
-
function
|
|
1893
|
+
function pr(e, n, r) {
|
|
1888
1894
|
const t = /* @__PURE__ */ new Set(), o = e.select.map((p, b) => {
|
|
1889
|
-
const
|
|
1890
|
-
return t.add(
|
|
1895
|
+
const y = xe(x(p) ?? `column_${b + 1}`, t);
|
|
1896
|
+
return t.add(y), { ...p, alias: y };
|
|
1891
1897
|
}), {
|
|
1892
1898
|
from: s,
|
|
1893
1899
|
joins: i,
|
|
@@ -1895,7 +1901,7 @@ function mr(e, n, r) {
|
|
|
1895
1901
|
groupBy: a,
|
|
1896
1902
|
having: l,
|
|
1897
1903
|
distinct: c
|
|
1898
|
-
} = e,
|
|
1904
|
+
} = e, d = {
|
|
1899
1905
|
from: s,
|
|
1900
1906
|
joins: i,
|
|
1901
1907
|
select: o,
|
|
@@ -1903,27 +1909,27 @@ function mr(e, n, r) {
|
|
|
1903
1909
|
...a ? { groupBy: a } : {},
|
|
1904
1910
|
...l ? { having: l } : {},
|
|
1905
1911
|
...c !== void 0 ? { distinct: c } : {}
|
|
1906
|
-
},
|
|
1912
|
+
}, f = (p) => ({ type: "field", table: r, column: p }), m = (p) => {
|
|
1907
1913
|
var b;
|
|
1908
|
-
return (b = o.find((
|
|
1914
|
+
return (b = o.find((y) => M(y.expression, p))) == null ? void 0 : b.alias;
|
|
1909
1915
|
}, g = {
|
|
1910
1916
|
...e,
|
|
1911
|
-
from: { id: n, alias: r, query: { union: [
|
|
1917
|
+
from: { id: n, alias: r, query: { union: [d], all: !0 } },
|
|
1912
1918
|
joins: [],
|
|
1913
|
-
select: o.map((p) => ({ id: E(), expression:
|
|
1919
|
+
select: o.map((p) => ({ id: E(), expression: f(p.alias) })),
|
|
1914
1920
|
...e.orderBy ? {
|
|
1915
1921
|
orderBy: e.orderBy.map((p) => {
|
|
1916
1922
|
const b = m(p.expression);
|
|
1917
|
-
return b ? { ...p, expression:
|
|
1923
|
+
return b ? { ...p, expression: f(b) } : p;
|
|
1918
1924
|
})
|
|
1919
1925
|
} : {}
|
|
1920
1926
|
};
|
|
1921
1927
|
return ["where", "groupBy", "having", "distinct"].forEach((p) => delete g[p]), g;
|
|
1922
1928
|
}
|
|
1923
|
-
function
|
|
1929
|
+
function yr(e, n, r, t) {
|
|
1924
1930
|
const o = V(n, r);
|
|
1925
1931
|
if (!o) return n;
|
|
1926
|
-
const s =
|
|
1932
|
+
const s = le(e, o.query.union).map((i) => ({
|
|
1927
1933
|
id: E(),
|
|
1928
1934
|
...i.name ? { alias: i.name } : {},
|
|
1929
1935
|
expression: B(i.type)
|
|
@@ -1936,66 +1942,66 @@ function pr(e, n, r, t) {
|
|
|
1936
1942
|
function hr(e, n, r, t) {
|
|
1937
1943
|
const o = {
|
|
1938
1944
|
id: r,
|
|
1939
|
-
alias:
|
|
1945
|
+
alias: $t(e, n),
|
|
1940
1946
|
joinType: "left",
|
|
1941
1947
|
query: { union: [{ from: t, joins: [], select: [] }], all: !0 }
|
|
1942
1948
|
};
|
|
1943
|
-
return { ...n, joins: [...n.joins, { ...o, on:
|
|
1949
|
+
return { ...n, joins: [...n.joins, { ...o, on: tn(e, n, o) }] };
|
|
1944
1950
|
}
|
|
1945
|
-
function
|
|
1951
|
+
function br(e, n, r) {
|
|
1946
1952
|
const t = V(e, n);
|
|
1947
1953
|
return !t || t.query.all === r ? e : W(e, t, { ...t.query, all: r });
|
|
1948
1954
|
}
|
|
1949
|
-
function
|
|
1955
|
+
function gr(e, n, r, t, o) {
|
|
1950
1956
|
const s = V(n, r), [i, ...u] = (s == null ? void 0 : s.query.union) ?? [], a = i == null ? void 0 : i.select[t], l = o.trim();
|
|
1951
|
-
if (!s || !a || !l || l.length > D || i.select.some((
|
|
1957
|
+
if (!s || !a || !l || l.length > D || i.select.some((d) => x(d) === l)) return n;
|
|
1952
1958
|
const c = W(n, s, {
|
|
1953
1959
|
...s.query,
|
|
1954
1960
|
union: [
|
|
1955
|
-
{ ...i, select: i.select.map((
|
|
1961
|
+
{ ...i, select: i.select.map((d, f) => f === t ? { ...d, alias: l } : d) },
|
|
1956
1962
|
...u
|
|
1957
1963
|
]
|
|
1958
1964
|
});
|
|
1959
1965
|
return Ae(e, n, c);
|
|
1960
1966
|
}
|
|
1961
|
-
function
|
|
1967
|
+
function wr(e, n) {
|
|
1962
1968
|
var c;
|
|
1963
1969
|
const r = V(e, n);
|
|
1964
1970
|
if (!r || r.query.union.length !== 1) return e;
|
|
1965
|
-
const [t] = r.query.union, o = new Map(t.select.flatMap((
|
|
1966
|
-
const
|
|
1967
|
-
return
|
|
1968
|
-
})), s = (
|
|
1969
|
-
const
|
|
1970
|
-
if (
|
|
1971
|
-
const m =
|
|
1972
|
-
return x({ ...
|
|
1973
|
-
}), a = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((
|
|
1971
|
+
const [t] = r.query.union, o = new Map(t.select.flatMap((d) => {
|
|
1972
|
+
const f = x(d);
|
|
1973
|
+
return f ? [[f, d.expression]] : [];
|
|
1974
|
+
})), 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
|
+
const f = i(d.expression);
|
|
1976
|
+
if (d.alias || !s(d.expression)) return { ...d, expression: f };
|
|
1977
|
+
const m = d.expression.column;
|
|
1978
|
+
return x({ ...d, expression: f }) === m ? { ...d, expression: f } : { ...d, expression: f, alias: m };
|
|
1979
|
+
}), a = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((d) => ne(d.expression, Q));
|
|
1974
1980
|
if (r === e.from && !a) {
|
|
1975
|
-
const
|
|
1981
|
+
const d = te({ ...e, select: u }, i, (f) => f);
|
|
1976
1982
|
return {
|
|
1977
|
-
...
|
|
1983
|
+
...d,
|
|
1978
1984
|
from: t.from,
|
|
1979
|
-
joins: [...t.joins, ...
|
|
1980
|
-
where:
|
|
1985
|
+
joins: [...t.joins, ...d.joins],
|
|
1986
|
+
where: Tn([...ee(t.where), ...ee(d.where)]),
|
|
1981
1987
|
// Nothing picked: the query's own columns, as the union had them.
|
|
1982
|
-
select:
|
|
1988
|
+
select: d.select.length > 0 ? d.select : t.select
|
|
1983
1989
|
};
|
|
1984
1990
|
}
|
|
1985
|
-
const l = e.joins.length === 0 && !e.where && !((c = e.groupBy) != null && c.length) && !e.having && !e.distinct && [...e.select, ...e.orderBy ?? []].every((
|
|
1991
|
+
const l = e.joins.length === 0 && !e.where && !((c = e.groupBy) != null && c.length) && !e.having && !e.distinct && [...e.select, ...e.orderBy ?? []].every((d) => s(d.expression));
|
|
1986
1992
|
return r === e.from && l ? {
|
|
1987
1993
|
...e,
|
|
1988
1994
|
...t,
|
|
1989
1995
|
select: u.length > 0 ? u : t.select,
|
|
1990
1996
|
...e.orderBy ? {
|
|
1991
|
-
orderBy: e.orderBy.map((
|
|
1997
|
+
orderBy: e.orderBy.map((d) => ({ ...d, expression: i(d.expression) }))
|
|
1992
1998
|
} : {}
|
|
1993
1999
|
} : W(e, r, t);
|
|
1994
2000
|
}
|
|
1995
|
-
function
|
|
2001
|
+
function xt(e, n) {
|
|
1996
2002
|
return e.select.filter((r) => ne(r.expression, n));
|
|
1997
2003
|
}
|
|
1998
|
-
function
|
|
2004
|
+
function At(e) {
|
|
1999
2005
|
return { ...e.expression, fromSelect: e.id };
|
|
2000
2006
|
}
|
|
2001
2007
|
function K(e) {
|
|
@@ -2003,14 +2009,14 @@ function K(e) {
|
|
|
2003
2009
|
return n === void 0 ? e : r;
|
|
2004
2010
|
}
|
|
2005
2011
|
function Bn(e, n) {
|
|
2006
|
-
const r = (o) => typeof o.fromSelect == "string" ? n(o, o.fromSelect) :
|
|
2012
|
+
const r = (o) => typeof o.fromSelect == "string" ? n(o, o.fromSelect) : _(o, r), t = r(e);
|
|
2007
2013
|
return M(t, e) ? e : t;
|
|
2008
2014
|
}
|
|
2009
|
-
function
|
|
2015
|
+
function Bt(e, n) {
|
|
2010
2016
|
var u;
|
|
2011
|
-
const r = new Map(
|
|
2012
|
-
const
|
|
2013
|
-
return
|
|
2017
|
+
const r = new Map(xt(e, n).map((a) => [a.id, a])), t = (a) => Bn(a, (l, c) => {
|
|
2018
|
+
const d = r.get(c);
|
|
2019
|
+
return d ? At(d) : K(l);
|
|
2014
2020
|
}), o = e.having && t(e.having);
|
|
2015
2021
|
let s = !1;
|
|
2016
2022
|
const i = (u = e.orderBy) == null ? void 0 : u.map((a) => {
|
|
@@ -2019,33 +2025,33 @@ function At(e, n) {
|
|
|
2019
2025
|
});
|
|
2020
2026
|
return o === e.having && !s ? e : { ...e, having: o, ...i ? { orderBy: i } : {} };
|
|
2021
2027
|
}
|
|
2022
|
-
function
|
|
2028
|
+
function Sr(e, n) {
|
|
2023
2029
|
const r = new Set((n.groupBy ?? []).flatMap(({ expression: t }) => t.type === "field" && t.column ? [t.column.toLowerCase()] : []));
|
|
2024
2030
|
return Bn(e, (t, o) => {
|
|
2025
2031
|
const s = n.select.find((i) => i.id === o);
|
|
2026
2032
|
return !(s != null && s.alias) || r.has(s.alias.toLowerCase()) || !M(K(t), s.expression) ? K(t) : { type: "field", column: s.alias };
|
|
2027
2033
|
});
|
|
2028
2034
|
}
|
|
2029
|
-
function
|
|
2030
|
-
const r = (c) =>
|
|
2035
|
+
function ve(e, n) {
|
|
2036
|
+
const r = (c) => ve(c, n), t = (c) => se(c, r), o = e.from.query && t(e.from.query), s = o && o !== e.from.query ? { ...e.from, query: o } : e.from;
|
|
2031
2037
|
let i = !1;
|
|
2032
2038
|
const u = e.joins.map((c) => {
|
|
2033
2039
|
if (!c.query) return c;
|
|
2034
|
-
const
|
|
2035
|
-
return
|
|
2036
|
-
}), a = s === e.from && !i ? e : { ...e, from: s, joins: u }, l =
|
|
2037
|
-
const
|
|
2038
|
-
return
|
|
2040
|
+
const d = t(c.query);
|
|
2041
|
+
return d === c.query ? c : (i = !0, { ...c, query: d });
|
|
2042
|
+
}), a = s === e.from && !i ? e : { ...e, from: s, joins: u }, l = Xe(a, (c) => {
|
|
2043
|
+
const d = r(c.query);
|
|
2044
|
+
return d === c.query ? c : { ...c, query: d };
|
|
2039
2045
|
});
|
|
2040
|
-
return
|
|
2046
|
+
return _n(Bt(l, n), n);
|
|
2041
2047
|
}
|
|
2042
|
-
function
|
|
2048
|
+
function vr(e, n, r, t = Q) {
|
|
2043
2049
|
if (!U(r)) return r;
|
|
2044
2050
|
const o = Te(
|
|
2045
|
-
|
|
2046
|
-
(i) => se(i, (u) =>
|
|
2047
|
-
), s =
|
|
2048
|
-
return
|
|
2051
|
+
ve(r, t),
|
|
2052
|
+
(i) => se(i, (u) => ve(u, t))
|
|
2053
|
+
), s = Et(e, n, o);
|
|
2054
|
+
return pt(e, n, s);
|
|
2049
2055
|
}
|
|
2050
2056
|
const Tr = [
|
|
2051
2057
|
"=",
|
|
@@ -2061,44 +2067,44 @@ const Tr = [
|
|
|
2061
2067
|
"REGEXP",
|
|
2062
2068
|
"IS NULL",
|
|
2063
2069
|
"IS NOT NULL"
|
|
2064
|
-
],
|
|
2065
|
-
function
|
|
2066
|
-
return
|
|
2070
|
+
], It = ["IS NULL", "IS NOT NULL"];
|
|
2071
|
+
function Nr(e) {
|
|
2072
|
+
return It.includes(e);
|
|
2067
2073
|
}
|
|
2068
2074
|
const In = (e) => {
|
|
2069
2075
|
const n = /* @__PURE__ */ new Map();
|
|
2070
|
-
return
|
|
2076
|
+
return Ve(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;
|
|
2071
2077
|
};
|
|
2072
2078
|
function kn(e, n) {
|
|
2073
2079
|
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) => {
|
|
2074
2080
|
const c = new Map(a);
|
|
2075
|
-
return S(l).forEach((
|
|
2081
|
+
return S(l).forEach((d) => c.set(v(d), d.table)), c;
|
|
2076
2082
|
}, s = (a, l) => {
|
|
2077
2083
|
if (!n || l.type !== "field" || !l.table || !l.column) return;
|
|
2078
|
-
const c = a.has(l.table) ? a.get(l.table) : l.table,
|
|
2079
|
-
return
|
|
2084
|
+
const c = a.has(l.table) ? a.get(l.table) : l.table, d = c === void 0 ? void 0 : A(n, c), f = d == null ? void 0 : d.columns.find((m) => m.name === l.column);
|
|
2085
|
+
return d && f ? { table: d.name, column: f } : void 0;
|
|
2080
2086
|
}, i = (a, l) => {
|
|
2081
2087
|
if (a.type === "param" && t(a.name), a.type === "binary" && a.right) {
|
|
2082
|
-
const
|
|
2088
|
+
const d = a.operator === "LIKE" || a.operator === "REGEXP", f = (g, p) => {
|
|
2083
2089
|
const b = s(l, p);
|
|
2084
2090
|
if (g.type !== "param" || !b) return;
|
|
2085
|
-
const
|
|
2086
|
-
if (
|
|
2091
|
+
const y = t(g.name);
|
|
2092
|
+
if (y.types.add(b.column.type), !d) {
|
|
2087
2093
|
const w = `${b.table}.${b.column.name}`;
|
|
2088
|
-
|
|
2094
|
+
y.columns.set(w, { table: b.table, column: b.column.name });
|
|
2089
2095
|
}
|
|
2090
2096
|
};
|
|
2091
|
-
|
|
2097
|
+
f(a.left, a.right), (a.right.type === "list" ? a.right.items : [a.right]).forEach((g) => f(g, a.left));
|
|
2092
2098
|
}
|
|
2093
2099
|
const c = a.type === "exists" ? o(l, a.query) : l;
|
|
2094
|
-
oe(a).forEach((
|
|
2100
|
+
oe(a).forEach((d) => i(d, c));
|
|
2095
2101
|
}, u = (a) => {
|
|
2096
2102
|
const l = o(/* @__PURE__ */ new Map(), a);
|
|
2097
|
-
|
|
2103
|
+
Je(a).forEach((c) => i(c, l)), S(a).forEach((c) => c.query && Y(c.query).forEach(u)), He(a).forEach((c) => u(c.query));
|
|
2098
2104
|
};
|
|
2099
2105
|
return (e.shared ?? []).forEach((a) => Y(a.query).forEach(u)), u(e), r;
|
|
2100
2106
|
}
|
|
2101
|
-
function
|
|
2107
|
+
function Er(e, n) {
|
|
2102
2108
|
const r = In(e);
|
|
2103
2109
|
return [...kn(e, n)].map(([t, { types: o, columns: s }]) => {
|
|
2104
2110
|
const i = r.get(t);
|
|
@@ -2111,15 +2117,15 @@ function Nr(e, n) {
|
|
|
2111
2117
|
};
|
|
2112
2118
|
});
|
|
2113
2119
|
}
|
|
2114
|
-
function
|
|
2120
|
+
function Cr(e) {
|
|
2115
2121
|
return [...In(e)].filter(([, n]) => n.size > 1).map(([n]) => n);
|
|
2116
2122
|
}
|
|
2117
|
-
function
|
|
2123
|
+
function $r(e, n) {
|
|
2118
2124
|
return [...kn(e, n)].filter(([, r]) => r.types.size > 1).map(([r]) => r);
|
|
2119
2125
|
}
|
|
2120
|
-
function
|
|
2126
|
+
function xr(e, n) {
|
|
2121
2127
|
const r = new Map(Object.entries(n));
|
|
2122
|
-
return
|
|
2128
|
+
return Ve(e, (t) => {
|
|
2123
2129
|
if (t.type !== "param") return t;
|
|
2124
2130
|
if (!r.has(t.name)) throw new Error(`no value for parameter "${t.name}"`);
|
|
2125
2131
|
const o = r.get(t.name);
|
|
@@ -2127,91 +2133,91 @@ function $r(e, n) {
|
|
|
2127
2133
|
});
|
|
2128
2134
|
}
|
|
2129
2135
|
export {
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2136
|
+
jt as $,
|
|
2137
|
+
Tr as A,
|
|
2138
|
+
ke as B,
|
|
2139
|
+
qt as C,
|
|
2140
|
+
et as D,
|
|
2135
2141
|
O as E,
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2142
|
+
ze as F,
|
|
2143
|
+
pe as G,
|
|
2144
|
+
Gt as H,
|
|
2139
2145
|
K as I,
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2146
|
+
ye as J,
|
|
2147
|
+
$r as K,
|
|
2148
|
+
Cr as L,
|
|
2149
|
+
Vn as M,
|
|
2144
2150
|
an as N,
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2151
|
+
rr as O,
|
|
2152
|
+
nr as P,
|
|
2153
|
+
Hn as Q,
|
|
2154
|
+
hn as R,
|
|
2149
2155
|
bn as S,
|
|
2150
2156
|
ht as T,
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2157
|
+
Zn as U,
|
|
2158
|
+
Lt as V,
|
|
2159
|
+
Ke as W,
|
|
2160
|
+
Jt as X,
|
|
2161
|
+
Pt as Y,
|
|
2162
|
+
Wt as Z,
|
|
2163
|
+
Vt as _,
|
|
2164
|
+
Ot as a,
|
|
2165
|
+
ir as a0,
|
|
2166
|
+
or as a1,
|
|
2167
|
+
ar as a2,
|
|
2168
|
+
ur as a3,
|
|
2169
|
+
sr as a4,
|
|
2170
|
+
vt as a5,
|
|
2171
|
+
At as a6,
|
|
2172
|
+
Wn as a7,
|
|
2173
|
+
nn as a8,
|
|
2174
|
+
Ft as a9,
|
|
2175
|
+
Kt as aa,
|
|
2176
|
+
zt as ab,
|
|
2177
|
+
Yt as ac,
|
|
2178
|
+
Ze as ad,
|
|
2179
|
+
Dt as ae,
|
|
2180
|
+
er as af,
|
|
2181
|
+
lt as ag,
|
|
2182
|
+
Qt as ah,
|
|
2183
|
+
ut as ai,
|
|
2184
|
+
it as aj,
|
|
2185
|
+
ae as ak,
|
|
2186
|
+
Zt as al,
|
|
2181
2187
|
Re as am,
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2188
|
+
tn as an,
|
|
2189
|
+
xt as ao,
|
|
2190
|
+
Rt as ap,
|
|
2191
|
+
Ht as aq,
|
|
2192
|
+
Xt as ar,
|
|
2193
|
+
Xn as as,
|
|
2194
|
+
He as at,
|
|
2195
|
+
ue as au,
|
|
2196
|
+
P as av,
|
|
2191
2197
|
he as aw,
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2198
|
+
Ut as b,
|
|
2199
|
+
_t as c,
|
|
2200
|
+
tr as d,
|
|
2201
|
+
yr as e,
|
|
2196
2202
|
hr as f,
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
+
cr as g,
|
|
2204
|
+
mr as h,
|
|
2205
|
+
gr as i,
|
|
2206
|
+
$t as j,
|
|
2207
|
+
pt as k,
|
|
2208
|
+
pr as l,
|
|
2203
2209
|
dn as m,
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2210
|
+
dr as n,
|
|
2211
|
+
lr as o,
|
|
2212
|
+
vr as p,
|
|
2213
|
+
Er as q,
|
|
2214
|
+
fr as r,
|
|
2215
|
+
br as s,
|
|
2216
|
+
I as t,
|
|
2217
|
+
wr as u,
|
|
2218
|
+
G as v,
|
|
2219
|
+
gn as w,
|
|
2220
|
+
xr as x,
|
|
2221
|
+
Sr as y,
|
|
2222
|
+
Nr as z
|
|
2217
2223
|
};
|