@nongt/visql-core 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{core-api-Bg_I2ak0.js → core-api-BsEMnDQ1.js} +21 -21
- package/dist/core.js +3 -3
- package/dist/{issueLocation-CD9XckYv.js → issueLocation-732-e0B8.js} +819 -804
- package/dist/{schema-z95dxLxu.js → schema-DFC26AhZ.js} +142 -126
- package/dist/sql-import.js +1 -1
- package/dist/types/core/i18n/defaultMessages.d.ts +2 -0
- package/dist/types/core/schema.d.ts +19 -0
- package/dist/types/core-api.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import { D as
|
|
2
|
-
import { c as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
1
|
+
import { D as $e, h as ue, q as Q, t as D, i as H, s as Xn, l as le, u as Kn, w as Pe, e as Ve, x as dn, k as z, r as fe, o as xe, j as K, y as Yn, d as W, z as Jt, A as Be, B as me, C as Pt, M as Y, F as zn, G as Vt, g as Z, H as We, I as fn, b as be, J as Zn, n as Wt, K as et, f as Ht, L as Xt, N as Mn, O as On, P as Ge, Q as Kt } from "./schema-DFC26AhZ.js";
|
|
2
|
+
import { c as Yt, s as zt, b as nt } from "./calendarDate-CYlr9TvX.js";
|
|
3
|
+
const Zt = 1e3, tt = 15, er = 40, ls = 100;
|
|
4
|
+
function nr(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 nn(e) {
|
|
9
|
-
return Number.isFinite(e) &&
|
|
9
|
+
return Number.isFinite(e) && nr(String(e)) <= tt;
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
function
|
|
11
|
+
const us = [];
|
|
12
|
+
function oe(e) {
|
|
13
13
|
return Q(e).filter((n) => n.query !== void 0);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function Te(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 rt(e) {
|
|
20
20
|
const n = [], r = (t) => {
|
|
21
|
-
t.type === "subquery" ? n.push(t) :
|
|
21
|
+
t.type === "subquery" ? n.push(t) : fe(t).forEach(r);
|
|
22
22
|
};
|
|
23
|
-
return
|
|
23
|
+
return Xn(e).forEach(r), n;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function st(e, n) {
|
|
26
26
|
let r = !1;
|
|
27
27
|
const t = (i) => {
|
|
28
|
-
if (i.type !== "subquery") return
|
|
28
|
+
if (i.type !== "subquery") return xe(i, t);
|
|
29
29
|
const a = n(i);
|
|
30
30
|
return a !== i && (r = !0), a;
|
|
31
|
-
}, s =
|
|
31
|
+
}, s = Pe(e, t, (i) => i);
|
|
32
32
|
return r ? s : e;
|
|
33
33
|
}
|
|
34
|
-
const
|
|
35
|
-
function
|
|
34
|
+
const cs = (e, n) => `${e}#${n}`;
|
|
35
|
+
function tr(e) {
|
|
36
36
|
return !("type" in e) && "of" in e;
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const rr = (e) => ({
|
|
39
39
|
id: e.id,
|
|
40
40
|
alias: e.name,
|
|
41
41
|
query: e.query
|
|
42
42
|
});
|
|
43
|
-
function
|
|
43
|
+
function Un(e, n) {
|
|
44
44
|
var s;
|
|
45
|
-
const r =
|
|
45
|
+
const r = oe(e).find((i) => i.id === n);
|
|
46
46
|
if (r) return r;
|
|
47
47
|
const t = (s = e.shared) == null ? void 0 : s.find((i) => i.id === n);
|
|
48
|
-
return t &&
|
|
48
|
+
return t && rr(t);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
const r =
|
|
50
|
+
function it(e, n) {
|
|
51
|
+
const r = Un(e, n);
|
|
52
52
|
if (r) return H(r.query) ? void 0 : r;
|
|
53
|
-
const t =
|
|
53
|
+
const t = rt(e).find((l) => l.id === n);
|
|
54
54
|
if (t) return t;
|
|
55
|
-
const s = /^(.*)#(\d+)$/.exec(n), i = s ?
|
|
55
|
+
const s = /^(.*)#(\d+)$/.exec(n), i = s ? Un(e, s[1]) : void 0, a = Number(s == null ? void 0 : s[2]), o = i && H(i.query) ? i.query.union[a] : void 0;
|
|
56
56
|
return i && o ? {
|
|
57
57
|
id: n,
|
|
58
58
|
alias: i.alias,
|
|
@@ -61,8 +61,8 @@ function st(e, n) {
|
|
|
61
61
|
index: a
|
|
62
62
|
} : void 0;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
65
|
-
return { id: e.id, ...
|
|
64
|
+
function ot(e) {
|
|
65
|
+
return { id: e.id, ...Ve(e.query) };
|
|
66
66
|
}
|
|
67
67
|
function Ye(e) {
|
|
68
68
|
const {
|
|
@@ -84,24 +84,24 @@ function Ye(e) {
|
|
|
84
84
|
...o !== void 0 ? { distinct: o } : {}
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function sr(e, n) {
|
|
88
88
|
return n.reduce((r, t) => {
|
|
89
|
-
const s = r &&
|
|
90
|
-
return s ?
|
|
89
|
+
const s = r && it(r, t);
|
|
90
|
+
return s ? ot(s) : void 0;
|
|
91
91
|
}, e);
|
|
92
92
|
}
|
|
93
93
|
function mn(e, n, r) {
|
|
94
94
|
if (n.length === 0) return r(e);
|
|
95
|
-
const [t, ...s] = n, i =
|
|
95
|
+
const [t, ...s] = n, i = it(e, t);
|
|
96
96
|
if (!i) return e;
|
|
97
|
-
const a =
|
|
98
|
-
if (o === a || !
|
|
97
|
+
const a = ot(i), o = mn(a, s, r);
|
|
98
|
+
if (o === a || !ue(o)) return e;
|
|
99
99
|
if ("type" in i && i.type === "subquery") {
|
|
100
100
|
const c = { ...i, query: Ye(o) };
|
|
101
|
-
return
|
|
101
|
+
return st(e, (m) => m === i ? c : m);
|
|
102
102
|
}
|
|
103
103
|
const l = (c, m) => {
|
|
104
|
-
if (!
|
|
104
|
+
if (!oe(e).some((f) => f.id === c.id))
|
|
105
105
|
return dn(e, (f, p) => p.id === c.id ? m : f);
|
|
106
106
|
const d = { ...c, query: m };
|
|
107
107
|
return c === e.from ? { ...e, from: d } : {
|
|
@@ -109,7 +109,7 @@ function mn(e, n, r) {
|
|
|
109
109
|
joins: e.joins.map((f) => f === c ? d : f)
|
|
110
110
|
};
|
|
111
111
|
};
|
|
112
|
-
if (
|
|
112
|
+
if (tr(i)) {
|
|
113
113
|
const { of: c, index: m } = i, { union: d } = c.query;
|
|
114
114
|
return l(c, {
|
|
115
115
|
...c.query,
|
|
@@ -118,7 +118,7 @@ function mn(e, n, r) {
|
|
|
118
118
|
}
|
|
119
119
|
return l(i, Ye(o));
|
|
120
120
|
}
|
|
121
|
-
const
|
|
121
|
+
const ir = {
|
|
122
122
|
text: "varchar",
|
|
123
123
|
integer: "integer",
|
|
124
124
|
number: "decimal",
|
|
@@ -128,12 +128,12 @@ const sr = {
|
|
|
128
128
|
boolean: "boolean"
|
|
129
129
|
};
|
|
130
130
|
function Ne(e, n, r = []) {
|
|
131
|
-
const t =
|
|
131
|
+
const t = Ve(n);
|
|
132
132
|
if (t.select.length === 0)
|
|
133
133
|
return Q(t).flatMap((o) => {
|
|
134
134
|
var c;
|
|
135
135
|
if (o.table !== void 0) return ((c = z(e, o.table)) == null ? void 0 : c.columns) ?? [];
|
|
136
|
-
const l =
|
|
136
|
+
const l = Te(o, r);
|
|
137
137
|
return l ? Ne(e, l, r) : [];
|
|
138
138
|
});
|
|
139
139
|
const s = new Map(Q(t).map((o) => [D(o), o.table])), i = (o) => {
|
|
@@ -148,13 +148,13 @@ function Ne(e, n, r = []) {
|
|
|
148
148
|
if (c === "SUM" || c === "AVG") return "decimal";
|
|
149
149
|
if ((c === "MIN" || c === "MAX") && o.args[0]) return i(o.args[0]);
|
|
150
150
|
}
|
|
151
|
-
return o.type === "literal" && typeof o.value == "number" ? "decimal" : o.type === "literal" && o.as ?
|
|
151
|
+
return o.type === "literal" && typeof o.value == "number" ? "decimal" : o.type === "literal" && o.as ? ir[o.as] : "varchar";
|
|
152
152
|
}, a = (o) => {
|
|
153
153
|
var d, f;
|
|
154
154
|
if (o.type !== "field" || o.table === void 0) return !1;
|
|
155
155
|
const l = Q(t).find((p) => D(p) === o.table);
|
|
156
156
|
if (!l) return !1;
|
|
157
|
-
const c = l.table === void 0 ?
|
|
157
|
+
const c = l.table === void 0 ? Te(l, r) : void 0, m = l.table !== void 0 ? (d = z(e, l.table)) == null ? void 0 : d.columns : c && Ne(e, c, r);
|
|
158
158
|
return !!((f = m == null ? void 0 : m.find((p) => p.name === o.column)) != null && f.joinOnly);
|
|
159
159
|
};
|
|
160
160
|
return t.select.flatMap((o) => {
|
|
@@ -167,24 +167,24 @@ function Ne(e, n, r = []) {
|
|
|
167
167
|
}] : [];
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
|
-
function
|
|
171
|
-
const t =
|
|
170
|
+
function at(e, n, r = []) {
|
|
171
|
+
const t = Te(n, r), s = (t ? Ne(e, t, r) : []).filter((i, a, o) => o.findIndex((l) => l.name === i.name) === a);
|
|
172
172
|
return { name: n.alias, label: n.alias, columns: s };
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
return Q(n).filter((t) => t.table === void 0).map((t) =>
|
|
174
|
+
function ds(e, n, r = []) {
|
|
175
|
+
return Q(n).filter((t) => t.table === void 0).map((t) => at(e, t, r));
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function lt(e, n = $e) {
|
|
178
178
|
if (H(e)) return !1;
|
|
179
179
|
const r = e;
|
|
180
|
-
return (r.groupBy ?? []).length === 0 && r.select.length > 0 && r.select.every((t) =>
|
|
180
|
+
return (r.groupBy ?? []).length === 0 && r.select.length > 0 && r.select.every((t) => le(t.expression, n)) && Kn(r, n).select.length === 0;
|
|
181
181
|
}
|
|
182
|
-
function
|
|
183
|
-
const t = (s) => s.type === "field" ? s.table === n ? { ...s, table: r } : s : s.type === "exists" &&
|
|
184
|
-
return
|
|
182
|
+
function jn(e, n, r) {
|
|
183
|
+
const t = (s) => s.type === "field" ? s.table === n ? { ...s, table: r } : s : s.type === "exists" && Yn(s.query).has(n) ? { ...s, link: t(s.link) } : xe(s, t);
|
|
184
|
+
return Pe(e, t, (s) => s);
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
const r =
|
|
186
|
+
function ut(e, n) {
|
|
187
|
+
const r = Ve(n), t = Q(r).flatMap((s) => s.table === void 0 ? [] : [{ table: s.table, alias: s.alias }]);
|
|
188
188
|
return r.select.length === 0 ? t.flatMap(({ table: s }) => {
|
|
189
189
|
var i;
|
|
190
190
|
return (((i = z(e, s)) == null ? void 0 : i.columns) ?? []).map((a) => ({ name: a.name, table: s, column: a.name }));
|
|
@@ -195,8 +195,8 @@ function lt(e, n) {
|
|
|
195
195
|
return a ? [{ name: o, table: a.table, column: i.column }] : [];
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
function
|
|
199
|
-
return
|
|
198
|
+
function ct(e, n) {
|
|
199
|
+
return oe(n).flatMap((r) => ut(e, r.query).flatMap(({ name: t, table: s, column: i }) => e.relations.flatMap((a) => {
|
|
200
200
|
const o = a.fromTable === s && a.fromColumn === i;
|
|
201
201
|
if (!o && !(a.toTable === s && a.toColumn === i)) return [];
|
|
202
202
|
const l = o ? a.toTable : a.fromTable, c = {
|
|
@@ -208,16 +208,16 @@ function ut(e, n) {
|
|
|
208
208
|
return [{ table: l, on: c }];
|
|
209
209
|
})));
|
|
210
210
|
}
|
|
211
|
-
function
|
|
211
|
+
function or(e, n, r) {
|
|
212
212
|
var t;
|
|
213
|
-
return (t =
|
|
213
|
+
return (t = ct(e, n).find((s) => s.table === r)) == null ? void 0 : t.on;
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function dt(e, n, r) {
|
|
216
216
|
var l;
|
|
217
|
-
const t = Q(n).flatMap((c) => c !== r && c.table !== void 0 ? [{ table: c.table, alias: c.alias }] : []), s = (c, m) => m === void 0 ? { type: "field", table: c } : { type: "field", table: c, column: m }, a =
|
|
217
|
+
const t = Q(n).flatMap((c) => c !== r && c.table !== void 0 ? [{ table: c.table, alias: c.alias }] : []), s = (c, m) => m === void 0 ? { type: "field", table: c } : { type: "field", table: c, column: m }, a = ut(e, r.query).flatMap(({ name: c, table: m, column: d }) => t.flatMap((f) => e.relations.filter((p) => p.fromTable === m && p.fromColumn === d && p.toTable === f.table || p.toTable === m && p.toColumn === d && p.fromTable === f.table).map((p) => ({
|
|
218
218
|
name: c,
|
|
219
219
|
right: s(D(f), p.fromTable === m ? p.toColumn : p.fromColumn)
|
|
220
|
-
}))))[0], o = (l =
|
|
220
|
+
}))))[0], o = (l = at(e, r).columns[0]) == null ? void 0 : l.name;
|
|
221
221
|
return {
|
|
222
222
|
type: "binary",
|
|
223
223
|
operator: "=",
|
|
@@ -225,16 +225,16 @@ function ct(e, n, r) {
|
|
|
225
225
|
right: (a == null ? void 0 : a.right) ?? { type: "field" }
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
const
|
|
229
|
-
function
|
|
228
|
+
const Le = (e, n) => `${e} ${n}${e === 1 ? "" : "s"}`;
|
|
229
|
+
function ft({ unit: e, offset: n, anchor: r }) {
|
|
230
230
|
const t = Math.abs(n);
|
|
231
231
|
if (r) {
|
|
232
232
|
const s = r === "start" ? "Start" : "End";
|
|
233
|
-
return n === 0 ? `${s} of this ${e}` : t === 1 ? `${s} of ${n < 0 ? "last" : "next"} ${e}` : n < 0 ? `${s} of the ${e} ${
|
|
233
|
+
return n === 0 ? `${s} of this ${e}` : t === 1 ? `${s} of ${n < 0 ? "last" : "next"} ${e}` : n < 0 ? `${s} of the ${e} ${Le(t, e)} ago` : `${s} of the ${e} in ${Le(t, e)}`;
|
|
234
234
|
}
|
|
235
|
-
return n === 0 ? "Today" : e === "day" && t === 1 ? n < 0 ? "Yesterday" : "Tomorrow" : n < 0 ? `${
|
|
235
|
+
return n === 0 ? "Today" : e === "day" && t === 1 ? n < 0 ? "Yesterday" : "Tomorrow" : n < 0 ? `${Le(t, e)} ago` : `In ${Le(t, e)}`;
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const ar = {
|
|
238
238
|
// Section captions on the main canvas
|
|
239
239
|
sectionFrom: "From Tables",
|
|
240
240
|
sectionWhere: "Conditions",
|
|
@@ -314,7 +314,7 @@ const or = {
|
|
|
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: ft,
|
|
318
318
|
relativeCustom: "Custom…",
|
|
319
319
|
relativeUnits: {
|
|
320
320
|
day: "days",
|
|
@@ -354,6 +354,8 @@ const or = {
|
|
|
354
354
|
openUnionBranch: (e) => `Open ${e}'s query`,
|
|
355
355
|
removeUnionBranch: (e) => `Remove ${e}'s query`,
|
|
356
356
|
joinTableGroup: "Join a table",
|
|
357
|
+
/** The heading over tables in no group, when others have one. */
|
|
358
|
+
otherTablesGroup: "Other tables",
|
|
357
359
|
/** Free-form unions (issue 153): a new one, the query as one's first
|
|
358
360
|
* query, another query for one, and a new query's canvas. */
|
|
359
361
|
createUnion: "Create Union",
|
|
@@ -639,39 +641,39 @@ const or = {
|
|
|
639
641
|
outlineEmpty: "Nothing yet: pick a table to start.",
|
|
640
642
|
outlineLimit: (e) => `At most ${e} row${e === 1 ? "" : "s"}`,
|
|
641
643
|
outlineOffset: (e) => `Skip ${e} row${e === 1 ? "" : "s"}`
|
|
642
|
-
},
|
|
643
|
-
let Ln = 0;
|
|
644
|
-
function Te() {
|
|
645
|
-
return Ln += 1, `join-${Date.now().toString(36)}-${Ln}`;
|
|
646
|
-
}
|
|
644
|
+
}, Ln = (e) => "from" in e ? e.from : { table: e.table };
|
|
647
645
|
let Dn = 0;
|
|
648
|
-
function
|
|
649
|
-
return Dn += 1, `
|
|
646
|
+
function Ae() {
|
|
647
|
+
return Dn += 1, `join-${Date.now().toString(36)}-${Dn}`;
|
|
650
648
|
}
|
|
651
649
|
let Gn = 0;
|
|
652
|
-
function Rn() {
|
|
653
|
-
return Gn += 1, `group-${Date.now().toString(36)}-${Gn}`;
|
|
654
|
-
}
|
|
655
|
-
let qn = 0;
|
|
656
650
|
function lr() {
|
|
657
|
-
return
|
|
651
|
+
return Gn += 1, `select-${Date.now().toString(36)}-${Gn}`;
|
|
652
|
+
}
|
|
653
|
+
let Rn = 0;
|
|
654
|
+
function qn() {
|
|
655
|
+
return Rn += 1, `group-${Date.now().toString(36)}-${Rn}`;
|
|
656
|
+
}
|
|
657
|
+
let Qn = 0;
|
|
658
|
+
function ur() {
|
|
659
|
+
return Qn += 1, `order-${Date.now().toString(36)}-${Qn}`;
|
|
658
660
|
}
|
|
659
661
|
function ze(e, n, r) {
|
|
660
662
|
if (n < 0 || n >= e.length || r < 0 || r >= e.length || n === r) return e;
|
|
661
663
|
const t = [...e], [s] = t.splice(n, 1);
|
|
662
664
|
return t.splice(r, 0, s), t;
|
|
663
665
|
}
|
|
664
|
-
const
|
|
665
|
-
function
|
|
666
|
+
const _n = (e) => e !== void 0 && Number.isSafeInteger(e) && e >= 0 ? e : void 0, Ze = (e) => (e ?? "").length <= Y;
|
|
667
|
+
function Se(e, n, r) {
|
|
666
668
|
return e.map((t) => t.id === n ? r(t) : t);
|
|
667
669
|
}
|
|
668
|
-
function
|
|
670
|
+
function mt(e, n, r) {
|
|
669
671
|
return e.map((t) => t.id === n ? r(t) : t);
|
|
670
672
|
}
|
|
671
|
-
function
|
|
673
|
+
function cr(e) {
|
|
672
674
|
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 };
|
|
673
675
|
}
|
|
674
|
-
function
|
|
676
|
+
function dr(e, n, r) {
|
|
675
677
|
return e.query ? {
|
|
676
678
|
id: e.id,
|
|
677
679
|
alias: e.alias,
|
|
@@ -679,22 +681,22 @@ function cr(e, n, r) {
|
|
|
679
681
|
joinType: r,
|
|
680
682
|
on: n
|
|
681
683
|
} : e.shared !== void 0 ? {
|
|
682
|
-
id:
|
|
684
|
+
id: Ae(),
|
|
683
685
|
shared: e.shared,
|
|
684
686
|
alias: e.alias,
|
|
685
687
|
joinType: r,
|
|
686
688
|
on: n
|
|
687
689
|
} : {
|
|
688
|
-
id:
|
|
690
|
+
id: Ae(),
|
|
689
691
|
table: e.table,
|
|
690
692
|
alias: e.alias,
|
|
691
693
|
joinType: r,
|
|
692
694
|
on: n
|
|
693
695
|
};
|
|
694
696
|
}
|
|
695
|
-
function
|
|
697
|
+
function yt(e, n) {
|
|
696
698
|
const [r, ...t] = n;
|
|
697
|
-
return { ...e, from:
|
|
699
|
+
return { ...e, from: cr(r), joins: t };
|
|
698
700
|
}
|
|
699
701
|
function ne(e) {
|
|
700
702
|
const n = /* @__PURE__ */ new Set(), r = (t) => {
|
|
@@ -731,7 +733,7 @@ function ne(e) {
|
|
|
731
733
|
// tables are joined inside it (withExistsJoins), never to the query
|
|
732
734
|
// around it — that would repeat its rows, which EXISTS is there to avoid.
|
|
733
735
|
case "exists": {
|
|
734
|
-
const i =
|
|
736
|
+
const i = Yn(t.query);
|
|
735
737
|
ne(t.link).filter((a) => !i.has(a)).forEach((a) => n.add(a));
|
|
736
738
|
break;
|
|
737
739
|
}
|
|
@@ -740,30 +742,30 @@ function ne(e) {
|
|
|
740
742
|
return r(e), [...n];
|
|
741
743
|
}
|
|
742
744
|
function yn(e, n, r, t, s) {
|
|
743
|
-
const i =
|
|
744
|
-
id:
|
|
745
|
+
const i = Be(n), a = t === void 0 && s === void 0, o = a ? Vt(e, i, r) : void 0, l = {
|
|
746
|
+
id: Ae(),
|
|
745
747
|
table: r,
|
|
746
748
|
joinType: t ?? (o == null ? void 0 : o.joinType) ?? "inner",
|
|
747
749
|
// Else matched to a derived table holding its key, if one does.
|
|
748
|
-
on: s ?? (o == null ? void 0 : o.on) ?? (a ?
|
|
750
|
+
on: s ?? (o == null ? void 0 : o.on) ?? (a ? or(e, n, r) : void 0)
|
|
749
751
|
};
|
|
750
752
|
return { ...n, joins: [...n.joins, l] };
|
|
751
753
|
}
|
|
752
|
-
function
|
|
753
|
-
const t =
|
|
754
|
+
function fr(e, n, r) {
|
|
755
|
+
const t = Be(n), s = zn(e, t, r);
|
|
754
756
|
return (s && s.length > 0 ? s : [r]).reduce((a, o) => yn(e, a, o), n);
|
|
755
757
|
}
|
|
756
|
-
function
|
|
758
|
+
function ce(e, n, r) {
|
|
757
759
|
return ne(r).reduce((t, s) => {
|
|
758
760
|
if (Q(t).some((o) => o.alias === s)) return t;
|
|
759
|
-
const i =
|
|
760
|
-
return (
|
|
761
|
+
const i = Be(t);
|
|
762
|
+
return (zn(e, i, s) ?? [s]).reduce((o, l) => yn(e, o, l), t);
|
|
761
763
|
}, n);
|
|
762
764
|
}
|
|
763
|
-
function
|
|
765
|
+
function mr(e, n, r, t) {
|
|
764
766
|
return {
|
|
765
|
-
...
|
|
766
|
-
select:
|
|
767
|
+
...ce(e, n, t),
|
|
768
|
+
select: mt(n.select, r, (s) => ({ ...s, expression: t }))
|
|
767
769
|
};
|
|
768
770
|
}
|
|
769
771
|
function hn(e, n, r) {
|
|
@@ -775,9 +777,9 @@ function hn(e, n, r) {
|
|
|
775
777
|
let l, c;
|
|
776
778
|
if (n === 0 ? (c = a, l = o) : r === 0 && (l = t[n], c = a), l && c) {
|
|
777
779
|
const { on: m, joinType: d } = l;
|
|
778
|
-
s[s.indexOf(c)] =
|
|
780
|
+
s[s.indexOf(c)] = dr(c, m, d);
|
|
779
781
|
}
|
|
780
|
-
return
|
|
782
|
+
return yt(e, s);
|
|
781
783
|
}
|
|
782
784
|
function pn(e) {
|
|
783
785
|
const n = /* @__PURE__ */ new Set([D(e.from)]);
|
|
@@ -788,31 +790,31 @@ function pn(e) {
|
|
|
788
790
|
return i && (r = { table: t.table ?? D(t), needs: i }), i !== void 0;
|
|
789
791
|
}), r;
|
|
790
792
|
}
|
|
791
|
-
function
|
|
793
|
+
function fs(e, n, r) {
|
|
792
794
|
const t = hn(e, n, r);
|
|
793
795
|
return t === e ? void 0 : pn(t);
|
|
794
796
|
}
|
|
795
|
-
function
|
|
797
|
+
function yr(e, n, r) {
|
|
796
798
|
const t = hn(e, n, r);
|
|
797
799
|
return t !== e && pn(t) === void 0;
|
|
798
800
|
}
|
|
799
|
-
function
|
|
801
|
+
function hr(e, n, r, t) {
|
|
800
802
|
return {
|
|
801
|
-
...
|
|
803
|
+
...ce(e, n, t),
|
|
802
804
|
orderBy: (n.orderBy ?? []).map((s) => s.id === r ? { ...s, expression: t } : s)
|
|
803
805
|
};
|
|
804
806
|
}
|
|
805
|
-
function
|
|
807
|
+
function pr(e, n, r, t) {
|
|
806
808
|
return {
|
|
807
|
-
...
|
|
809
|
+
...ce(e, n, t),
|
|
808
810
|
groupBy: (n.groupBy ?? []).map((s) => s.id === r ? { ...s, expression: t } : s)
|
|
809
811
|
};
|
|
810
812
|
}
|
|
811
|
-
function
|
|
812
|
-
if (!n || !
|
|
813
|
-
const r =
|
|
813
|
+
function He(e, n) {
|
|
814
|
+
if (!n || !Jt(n)) return n;
|
|
815
|
+
const r = fe(n), t = r.map((l) => He(e, l)), i = t.some((l, c) => l !== r[c]) ? xe(n, (l) => t[r.indexOf(l)]) : n;
|
|
814
816
|
if (i.type !== "exists") return i;
|
|
815
|
-
const { query: a } = i, { joins: o } =
|
|
817
|
+
const { query: a } = i, { joins: o } = ce(
|
|
816
818
|
e,
|
|
817
819
|
{
|
|
818
820
|
id: "",
|
|
@@ -824,24 +826,24 @@ function We(e, n) {
|
|
|
824
826
|
);
|
|
825
827
|
return o === a.joins ? i : { ...i, query: { ...a, joins: o } };
|
|
826
828
|
}
|
|
827
|
-
function
|
|
828
|
-
const t =
|
|
829
|
-
return { ...
|
|
829
|
+
function ms(e, n, r) {
|
|
830
|
+
const t = He(e, r);
|
|
831
|
+
return { ...ce(e, n, t), having: t };
|
|
830
832
|
}
|
|
831
|
-
function
|
|
833
|
+
function Fn(e, n) {
|
|
832
834
|
const r = /* @__PURE__ */ new Set([
|
|
833
835
|
...n ? Q(n).map(D) : [],
|
|
834
|
-
...
|
|
836
|
+
...me(e).map((s) => s.name)
|
|
835
837
|
]);
|
|
836
838
|
let t = 1;
|
|
837
839
|
for (; r.has(`sub_query_${t}`); ) t += 1;
|
|
838
840
|
return `sub_query_${t}`;
|
|
839
841
|
}
|
|
840
|
-
function
|
|
842
|
+
function ys() {
|
|
841
843
|
return { id: W() };
|
|
842
844
|
}
|
|
843
845
|
function tn(e, n, r) {
|
|
844
|
-
if (!
|
|
846
|
+
if (!ue(n))
|
|
845
847
|
return r.type !== "setBaseTable" && r.type !== "setDerivedBaseTable" ? n : tn(e, {
|
|
846
848
|
id: n.id,
|
|
847
849
|
...n.shared ? { shared: n.shared } : {},
|
|
@@ -856,9 +858,9 @@ function tn(e, n, r) {
|
|
|
856
858
|
return {
|
|
857
859
|
...n,
|
|
858
860
|
from: {
|
|
859
|
-
id: r.id ??
|
|
860
|
-
alias:
|
|
861
|
-
query: { from:
|
|
861
|
+
id: r.id ?? Ae(),
|
|
862
|
+
alias: Fn(e, n),
|
|
863
|
+
query: { from: Ln(r), joins: [], select: [] }
|
|
862
864
|
}
|
|
863
865
|
};
|
|
864
866
|
case "changeBaseAlias":
|
|
@@ -869,22 +871,22 @@ function tn(e, n, r) {
|
|
|
869
871
|
from: n.from.table === void 0 ? { ...n.from, alias: r.alias || n.from.alias } : { ...n.from, alias: r.alias }
|
|
870
872
|
} : n;
|
|
871
873
|
case "addJoin":
|
|
872
|
-
return r.joinType === void 0 && r.on === void 0 ?
|
|
874
|
+
return r.joinType === void 0 && r.on === void 0 ? fr(e, n, r.table) : yn(e, n, r.table, r.joinType, r.on);
|
|
873
875
|
case "addDerivedJoin": {
|
|
874
876
|
const t = {
|
|
875
|
-
id: r.id ??
|
|
876
|
-
alias:
|
|
877
|
+
id: r.id ?? Ae(),
|
|
878
|
+
alias: Fn(e, n),
|
|
877
879
|
joinType: "left",
|
|
878
|
-
query: { from:
|
|
879
|
-
}, s =
|
|
880
|
+
query: { from: Ln(r), joins: [], select: [] }
|
|
881
|
+
}, s = dt(e, n, t);
|
|
880
882
|
return { ...n, joins: [...n.joins, { ...t, on: s }] };
|
|
881
883
|
}
|
|
882
884
|
case "renameDerivedTable": {
|
|
883
|
-
const t =
|
|
885
|
+
const t = oe(n).find((l) => l.id === r.derivedId), s = r.alias.trim();
|
|
884
886
|
if (!t || s === t.alias) return n;
|
|
885
887
|
const i = Q(n).filter((l) => l !== t).map(D);
|
|
886
888
|
if (!s || s.length > Y || i.includes(s) || z(e, s)) return n;
|
|
887
|
-
const a =
|
|
889
|
+
const a = jn(n, t.alias, s), { from: o } = a;
|
|
888
890
|
return {
|
|
889
891
|
...a,
|
|
890
892
|
from: o.query && o.id === t.id ? { ...o, alias: s } : o,
|
|
@@ -896,13 +898,13 @@ function tn(e, n, r) {
|
|
|
896
898
|
if ((t == null ? void 0 : t.shared) === void 0 || s === t.alias) return n;
|
|
897
899
|
const i = Q(n).filter((o) => o !== t).map(D);
|
|
898
900
|
if (!s || s.length > Y || i.includes(s) || z(e, s)) return n;
|
|
899
|
-
const a =
|
|
900
|
-
return r.joinId === void 0 ? { ...a, from: { ...a.from, alias: s } } : { ...a, joins:
|
|
901
|
+
const a = jn(n, t.alias, s);
|
|
902
|
+
return r.joinId === void 0 ? { ...a, from: { ...a.from, alias: s } } : { ...a, joins: Se(a.joins, r.joinId, (o) => ({ ...o, alias: s })) };
|
|
901
903
|
}
|
|
902
904
|
case "setMeasureSynced":
|
|
903
905
|
return {
|
|
904
906
|
...n,
|
|
905
|
-
joins:
|
|
907
|
+
joins: Se(n.joins, r.joinId, (t) => t.query && t.drillAcross ? { ...t, drillAcross: { ...t.drillAcross, synced: r.synced } } : t)
|
|
906
908
|
};
|
|
907
909
|
case "removeJoin":
|
|
908
910
|
return { ...n, joins: n.joins.filter((t) => t.id !== r.joinId) };
|
|
@@ -910,21 +912,21 @@ function tn(e, n, r) {
|
|
|
910
912
|
return {
|
|
911
913
|
...n,
|
|
912
914
|
// A CROSS JOIN uses no ON, but keeps it: switched back, it's used again.
|
|
913
|
-
joins:
|
|
915
|
+
joins: Se(n.joins, r.joinId, (t) => ({ ...t, joinType: r.joinType }))
|
|
914
916
|
};
|
|
915
917
|
case "changeJoinAlias":
|
|
916
918
|
return Ze(r.alias) ? {
|
|
917
919
|
...n,
|
|
918
920
|
// A derived table (or a shared query's place) goes by its alias: it
|
|
919
921
|
// can't be left without one.
|
|
920
|
-
joins:
|
|
922
|
+
joins: Se(n.joins, r.joinId, (t) => t.table === void 0 ? { ...t, alias: r.alias || t.alias } : { ...t, alias: r.alias })
|
|
921
923
|
} : n;
|
|
922
924
|
case "changeJoinOn":
|
|
923
925
|
return {
|
|
924
926
|
...n,
|
|
925
|
-
joins:
|
|
927
|
+
joins: Se(n.joins, r.joinId, (t) => ({
|
|
926
928
|
...t,
|
|
927
|
-
on:
|
|
929
|
+
on: He(e, r.on)
|
|
928
930
|
}))
|
|
929
931
|
};
|
|
930
932
|
case "reorderJoin": {
|
|
@@ -936,11 +938,11 @@ function tn(e, n, r) {
|
|
|
936
938
|
return [i[t], i[s]] = [i[s], i[t]], { ...n, joins: i };
|
|
937
939
|
}
|
|
938
940
|
case "reorderTables":
|
|
939
|
-
return
|
|
941
|
+
return yr(n, r.fromIndex, r.toIndex) ? hn(n, r.fromIndex, r.toIndex) : n;
|
|
940
942
|
case "removeBaseTable":
|
|
941
|
-
return n.joins.length > 0 ?
|
|
943
|
+
return n.joins.length > 0 ? yt(n, n.joins) : n.shared ? { id: n.id, shared: n.shared } : { id: n.id };
|
|
942
944
|
case "addSelectItem": {
|
|
943
|
-
const t = { id:
|
|
945
|
+
const t = { id: lr(), expression: { type: "field" } };
|
|
944
946
|
return { ...n, select: [...n.select, t] };
|
|
945
947
|
}
|
|
946
948
|
case "removeSelectItem":
|
|
@@ -952,12 +954,12 @@ function tn(e, n, r) {
|
|
|
952
954
|
case "setSelectAlias":
|
|
953
955
|
return Ze(r.alias) ? {
|
|
954
956
|
...n,
|
|
955
|
-
select:
|
|
957
|
+
select: mt(n.select, r.selectId, (t) => ({ ...t, alias: r.alias }))
|
|
956
958
|
} : n;
|
|
957
959
|
case "setSelectExpression":
|
|
958
|
-
return
|
|
960
|
+
return mr(e, n, r.selectId, r.expression);
|
|
959
961
|
case "addGroupByItem": {
|
|
960
|
-
const t = { id:
|
|
962
|
+
const t = { id: qn(), expression: { type: "field" } };
|
|
961
963
|
return { ...n, groupBy: [...n.groupBy ?? [], t] };
|
|
962
964
|
}
|
|
963
965
|
case "removeGroupByItem": {
|
|
@@ -969,11 +971,11 @@ function tn(e, n, r) {
|
|
|
969
971
|
return s === t ? n : { ...n, groupBy: s };
|
|
970
972
|
}
|
|
971
973
|
case "setGroupByExpression":
|
|
972
|
-
return
|
|
974
|
+
return pr(e, n, r.groupById, r.expression);
|
|
973
975
|
case "groupBySelectItem": {
|
|
974
976
|
const t = n.select.find((i) => i.id === r.selectId);
|
|
975
977
|
if (!t) return n;
|
|
976
|
-
const s = { id:
|
|
978
|
+
const s = { id: qn(), expression: t.expression };
|
|
977
979
|
return { ...n, groupBy: [...n.groupBy ?? [], s] };
|
|
978
980
|
}
|
|
979
981
|
case "removeHaving":
|
|
@@ -982,7 +984,7 @@ function tn(e, n, r) {
|
|
|
982
984
|
return { ...n, distinct: r.distinct || void 0 };
|
|
983
985
|
case "addOrderByItem": {
|
|
984
986
|
const t = {
|
|
985
|
-
id:
|
|
987
|
+
id: ur(),
|
|
986
988
|
expression: { type: "field" },
|
|
987
989
|
direction: "asc"
|
|
988
990
|
};
|
|
@@ -997,16 +999,16 @@ function tn(e, n, r) {
|
|
|
997
999
|
return s === t ? n : { ...n, orderBy: s };
|
|
998
1000
|
}
|
|
999
1001
|
case "setOrderByExpression":
|
|
1000
|
-
return
|
|
1002
|
+
return hr(e, n, r.orderById, r.expression);
|
|
1001
1003
|
case "setOrderByDirection":
|
|
1002
1004
|
return {
|
|
1003
1005
|
...n,
|
|
1004
1006
|
orderBy: (n.orderBy ?? []).map((t) => t.id === r.orderById ? { ...t, direction: r.direction } : t)
|
|
1005
1007
|
};
|
|
1006
1008
|
case "setLimit":
|
|
1007
|
-
return { ...n, limit:
|
|
1009
|
+
return { ...n, limit: _n(r.limit) };
|
|
1008
1010
|
case "setOffset":
|
|
1009
|
-
return { ...n, offset:
|
|
1011
|
+
return { ...n, offset: _n(r.offset) };
|
|
1010
1012
|
case "clearPaging":
|
|
1011
1013
|
return { ...n, limit: void 0, offset: void 0 };
|
|
1012
1014
|
/* v8 ignore start -- PipelineAction is a closed union; every real case is
|
|
@@ -1016,72 +1018,72 @@ function tn(e, n, r) {
|
|
|
1016
1018
|
return n;
|
|
1017
1019
|
}
|
|
1018
1020
|
}
|
|
1019
|
-
const
|
|
1021
|
+
const gr = {
|
|
1020
1022
|
inner: "INNER",
|
|
1021
1023
|
left: "LEFT",
|
|
1022
1024
|
right: "RIGHT",
|
|
1023
1025
|
full: "FULL",
|
|
1024
1026
|
cross: "CROSS"
|
|
1025
1027
|
};
|
|
1026
|
-
function
|
|
1027
|
-
return `${
|
|
1028
|
+
function hs(e) {
|
|
1029
|
+
return `${gr[e.joinType]} JOIN ${D(e)}`;
|
|
1028
1030
|
}
|
|
1029
|
-
function
|
|
1031
|
+
function ps(e) {
|
|
1030
1032
|
return e.alias || "Column";
|
|
1031
1033
|
}
|
|
1032
|
-
function
|
|
1034
|
+
function gs() {
|
|
1033
1035
|
return "Sort";
|
|
1034
1036
|
}
|
|
1035
|
-
function
|
|
1037
|
+
function bs() {
|
|
1036
1038
|
return "Group";
|
|
1037
1039
|
}
|
|
1038
|
-
function
|
|
1040
|
+
function ws(e, n, r) {
|
|
1039
1041
|
const t = Q(n);
|
|
1040
1042
|
if (r !== void 0) {
|
|
1041
1043
|
const l = t.findIndex((c) => "id" in c && c.id === r);
|
|
1042
1044
|
return new Set(t.slice(0, l + 1).map(D));
|
|
1043
1045
|
}
|
|
1044
|
-
const s = new Set(
|
|
1046
|
+
const s = new Set(Be(n)), i = Pt(e, [...s]), a = new Set(ct(e, n).map((l) => l.table)), o = me(e).filter((l) => !s.has(l.name) && (i.has(l.name) || a.has(l.name)));
|
|
1045
1047
|
return /* @__PURE__ */ new Set([...t.map(D), ...o.map((l) => l.name)]);
|
|
1046
1048
|
}
|
|
1047
|
-
function
|
|
1049
|
+
function $s(e, n) {
|
|
1048
1050
|
const r = Q(n);
|
|
1049
|
-
return
|
|
1051
|
+
return me(e).flatMap((t) => {
|
|
1050
1052
|
const s = r.filter((i) => i.table === t.name).map(D);
|
|
1051
1053
|
return (s.length > 0 ? s : [t.name]).map((i) => ({ ref: i, table: t }));
|
|
1052
1054
|
});
|
|
1053
1055
|
}
|
|
1054
|
-
function
|
|
1055
|
-
const r = new Set(
|
|
1056
|
-
return
|
|
1056
|
+
function vs(e, n) {
|
|
1057
|
+
const r = new Set(Be(n));
|
|
1058
|
+
return me(e).filter((t) => !r.has(t.name));
|
|
1057
1059
|
}
|
|
1058
1060
|
function rn(e) {
|
|
1059
1061
|
return e ? e.type === "logical" ? e.operands.reduce((n, r) => n + rn(r), 0) : e.type === "not" ? rn(e.operand) : 1 : 0;
|
|
1060
1062
|
}
|
|
1061
|
-
function
|
|
1063
|
+
function Jn(e) {
|
|
1062
1064
|
return e.column ? e.table ? `${e.table}.${e.column}` : e.column : "?";
|
|
1063
1065
|
}
|
|
1064
|
-
function
|
|
1066
|
+
function Ss(e, n = ar) {
|
|
1065
1067
|
var r;
|
|
1066
|
-
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 : `${
|
|
1068
|
+
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 : `${Jn(e.left)} ${e.operator ?? "="} ${Jn(e.right)}` : n.conditionCount(rn(e)) : n.setJoinCondition;
|
|
1067
1069
|
}
|
|
1068
|
-
function
|
|
1070
|
+
function Es(e, n) {
|
|
1069
1071
|
const r = new Set(ne(e.where));
|
|
1070
1072
|
return ne(e.having).forEach((t) => r.add(t)), e.joins.filter((t) => t.id !== n).forEach((t) => ne(t.on).forEach((s) => r.add(s))), [...e.select, ...e.groupBy ?? [], ...e.orderBy ?? []].forEach((t) => ne(t.expression).forEach((s) => r.add(s))), r;
|
|
1071
1073
|
}
|
|
1072
|
-
function
|
|
1073
|
-
const t =
|
|
1074
|
-
return { ...
|
|
1074
|
+
function Ts(e, n, r) {
|
|
1075
|
+
const t = He(e, r);
|
|
1076
|
+
return { ...ce(e, n, t), where: t };
|
|
1075
1077
|
}
|
|
1076
|
-
function
|
|
1077
|
-
return r.length === 0 ? tn(e, n, t) :
|
|
1078
|
+
function Ns(e, n, r, t) {
|
|
1079
|
+
return r.length === 0 ? tn(e, n, t) : ue(n) ? mn(n, r, (s) => tn(e, s, t)) : n;
|
|
1078
1080
|
}
|
|
1079
1081
|
const gn = (e) => typeof e == "object" && e !== null && !Array.isArray(e) && !(e instanceof Date), bn = (e) => typeof e.shared == "string";
|
|
1080
|
-
function
|
|
1082
|
+
function qe(e, n) {
|
|
1081
1083
|
if (Array.isArray(e)) {
|
|
1082
1084
|
let s = !1;
|
|
1083
1085
|
const i = e.flatMap((a) => {
|
|
1084
|
-
const o =
|
|
1086
|
+
const o = qe(a, n);
|
|
1085
1087
|
return o !== a && (s = !0), o === void 0 ? [] : [o];
|
|
1086
1088
|
});
|
|
1087
1089
|
return s ? i : e;
|
|
@@ -1090,12 +1092,12 @@ function Re(e, n) {
|
|
|
1090
1092
|
if (bn(e)) return n(e);
|
|
1091
1093
|
let r = !1;
|
|
1092
1094
|
const t = Object.entries(e).map(([s, i]) => {
|
|
1093
|
-
const a =
|
|
1095
|
+
const a = qe(i, n);
|
|
1094
1096
|
return a !== i && (r = !0), [s, a];
|
|
1095
1097
|
});
|
|
1096
1098
|
return r ? Object.fromEntries(t) : e;
|
|
1097
1099
|
}
|
|
1098
|
-
function
|
|
1100
|
+
function As(e) {
|
|
1099
1101
|
const n = new Map((e.shared ?? []).map((t) => [t.id, []])), r = (t, s) => {
|
|
1100
1102
|
if (Array.isArray(t)) {
|
|
1101
1103
|
t.forEach((i, a) => r(i, [...s, a]));
|
|
@@ -1112,55 +1114,55 @@ function Ns(e) {
|
|
|
1112
1114
|
};
|
|
1113
1115
|
return r(e, []), n;
|
|
1114
1116
|
}
|
|
1115
|
-
function
|
|
1117
|
+
function ks(e, n) {
|
|
1116
1118
|
const r = /* @__PURE__ */ new Set([
|
|
1117
1119
|
...(n.shared ?? []).map((s) => s.name),
|
|
1118
|
-
...
|
|
1120
|
+
...me(e).map((s) => s.name)
|
|
1119
1121
|
]);
|
|
1120
1122
|
let t = 1;
|
|
1121
1123
|
for (; r.has(`shared_query_${t}`); ) t += 1;
|
|
1122
1124
|
return `shared_query_${t}`;
|
|
1123
1125
|
}
|
|
1124
|
-
function
|
|
1126
|
+
function br(e, n) {
|
|
1125
1127
|
const r = new Set(Q(n).map(D));
|
|
1126
1128
|
let t = e;
|
|
1127
1129
|
for (let s = 2; r.has(t); s += 1) t = `${e}_${s}`;
|
|
1128
1130
|
return t;
|
|
1129
1131
|
}
|
|
1130
|
-
function
|
|
1132
|
+
function wr(e, n, r, t = W(), s) {
|
|
1131
1133
|
const i = e.shared ?? [], a = i.findIndex((l) => l.id === s), o = { id: t, name: n, query: r };
|
|
1132
1134
|
return {
|
|
1133
1135
|
...e,
|
|
1134
1136
|
shared: a < 0 ? [...i, o] : [...i.slice(0, a), o, ...i.slice(a)]
|
|
1135
1137
|
};
|
|
1136
1138
|
}
|
|
1137
|
-
const
|
|
1139
|
+
const ht = (e, n) => {
|
|
1138
1140
|
var r;
|
|
1139
1141
|
return (r = e.shared) == null ? void 0 : r.find((t) => t.id === n);
|
|
1140
1142
|
};
|
|
1141
|
-
function
|
|
1142
|
-
const s =
|
|
1143
|
+
function xs(e, n, r, t = {}) {
|
|
1144
|
+
const s = ht(e, r);
|
|
1143
1145
|
if (!s) return n;
|
|
1144
1146
|
const i = {
|
|
1145
1147
|
id: t.id ?? W(),
|
|
1146
1148
|
shared: r,
|
|
1147
|
-
alias:
|
|
1149
|
+
alias: br(s.name, n),
|
|
1148
1150
|
joinType: t.joinType ?? "inner",
|
|
1149
1151
|
...t.on ? { on: t.on } : {}
|
|
1150
1152
|
};
|
|
1151
1153
|
return { ...n, joins: [...n.joins, i] };
|
|
1152
1154
|
}
|
|
1153
|
-
function
|
|
1154
|
-
const t =
|
|
1155
|
+
function Bs(e, n, r) {
|
|
1156
|
+
const t = ht(e, r);
|
|
1155
1157
|
return t ? { ...n, from: { shared: r, alias: t.name } } : n;
|
|
1156
1158
|
}
|
|
1157
|
-
function
|
|
1158
|
-
const s =
|
|
1159
|
+
function Cs(e, n, r = W(), t = []) {
|
|
1160
|
+
const s = sr(e, t), i = s && oe(s).find((c) => c.id === n);
|
|
1159
1161
|
if (!i) return e;
|
|
1160
1162
|
const a = new Set((e.shared ?? []).map((c) => c.name));
|
|
1161
1163
|
let o = i.alias;
|
|
1162
1164
|
for (let c = 2; a.has(o); c += 1) o = `${i.alias}_${c}`;
|
|
1163
|
-
const l =
|
|
1165
|
+
const l = wr(e, o, i.query, r, t[0]);
|
|
1164
1166
|
return mn(l, t, (c) => c.from.query && c.from.id === n ? { ...c, from: { shared: r, alias: i.alias } } : {
|
|
1165
1167
|
...c,
|
|
1166
1168
|
joins: c.joins.map((m) => {
|
|
@@ -1170,51 +1172,51 @@ function xs(e, n, r = W(), t = []) {
|
|
|
1170
1172
|
})
|
|
1171
1173
|
});
|
|
1172
1174
|
}
|
|
1173
|
-
function
|
|
1175
|
+
function pt(e, n) {
|
|
1174
1176
|
const { shared: r, ...t } = e;
|
|
1175
1177
|
return "joinType" in t ? { ...t, query: n } : { id: W(), alias: t.alias, query: n };
|
|
1176
1178
|
}
|
|
1177
|
-
function
|
|
1179
|
+
function Is(e, n) {
|
|
1178
1180
|
const r = new Map((e.shared ?? []).map((s) => [s.id, s.query])), t = n.reduce(
|
|
1179
1181
|
(s, i) => typeof s == "object" && s !== null ? s[i] : void 0,
|
|
1180
1182
|
e
|
|
1181
1183
|
);
|
|
1182
|
-
return !gn(t) || !bn(t) ? e :
|
|
1184
|
+
return !gn(t) || !bn(t) ? e : qe(e, (s) => {
|
|
1183
1185
|
const i = r.get(s.shared);
|
|
1184
|
-
return s === t && i ?
|
|
1186
|
+
return s === t && i ? pt(s, i) : s;
|
|
1185
1187
|
});
|
|
1186
1188
|
}
|
|
1187
|
-
function
|
|
1189
|
+
function Ms(e, n, r) {
|
|
1188
1190
|
var t;
|
|
1189
1191
|
return !((t = e.shared) != null && t.some((s) => s.id === n)) || r === "" ? e : {
|
|
1190
1192
|
...e,
|
|
1191
1193
|
shared: e.shared.map((s) => s.id === n ? { ...s, name: r } : s)
|
|
1192
1194
|
};
|
|
1193
1195
|
}
|
|
1194
|
-
class
|
|
1196
|
+
class $r extends Error {
|
|
1195
1197
|
constructor(n) {
|
|
1196
1198
|
super(`removeSharedQuery: "${n}" is a query's base: make it a sub query there instead`), this.name = "SharedBaseError";
|
|
1197
1199
|
}
|
|
1198
1200
|
}
|
|
1199
|
-
function
|
|
1201
|
+
function Os(e, n, r = "subQueries") {
|
|
1200
1202
|
var l;
|
|
1201
1203
|
const t = (l = e.shared) == null ? void 0 : l.find((c) => c.id === n);
|
|
1202
1204
|
if (!t) return e;
|
|
1203
1205
|
const s = e.shared.filter((c) => c !== t), { shared: i, ...a } = e, o = s.length > 0 ? { ...a, shared: s } : a;
|
|
1204
|
-
return
|
|
1206
|
+
return qe(o, (c) => {
|
|
1205
1207
|
if (c.shared !== n) return c;
|
|
1206
|
-
if (r === "subQueries") return
|
|
1207
|
-
if (!("joinType" in c)) throw new
|
|
1208
|
+
if (r === "subQueries") return pt(c, t.query);
|
|
1209
|
+
if (!("joinType" in c)) throw new $r(t.name);
|
|
1208
1210
|
});
|
|
1209
1211
|
}
|
|
1210
|
-
const
|
|
1211
|
-
function
|
|
1212
|
+
const gt = (e) => e.query !== void 0 && !H(e.query);
|
|
1213
|
+
function bt(e) {
|
|
1212
1214
|
const n = /* @__PURE__ */ new Map();
|
|
1213
1215
|
return e.relations.forEach((r) => {
|
|
1214
1216
|
n.set(r.fromTable, [...n.get(r.fromTable) ?? [], r.toTable]);
|
|
1215
1217
|
}), n;
|
|
1216
1218
|
}
|
|
1217
|
-
function
|
|
1219
|
+
function Ce(e, n, r = bt(e)) {
|
|
1218
1220
|
const t = /* @__PURE__ */ new Set([n]), s = [n];
|
|
1219
1221
|
for (let i = s.shift(); i !== void 0; i = s.shift())
|
|
1220
1222
|
(r.get(i) ?? []).forEach((a) => {
|
|
@@ -1222,16 +1224,16 @@ function Be(e, n, r = gt(e)) {
|
|
|
1222
1224
|
});
|
|
1223
1225
|
return t;
|
|
1224
1226
|
}
|
|
1225
|
-
const
|
|
1226
|
-
function
|
|
1227
|
+
const we = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [];
|
|
1228
|
+
function wt(e, n) {
|
|
1227
1229
|
const r = new Map(Q(e).map((t) => [D(t), t.table]));
|
|
1228
1230
|
return ne(n).map((t) => ({
|
|
1229
1231
|
ref: t,
|
|
1230
1232
|
table: r.has(t) ? r.get(t) : t
|
|
1231
1233
|
}));
|
|
1232
1234
|
}
|
|
1233
|
-
const wn = (e, n) =>
|
|
1234
|
-
function
|
|
1235
|
+
const wn = (e, n) => wt(e, n).map((r) => r.table);
|
|
1236
|
+
function Pn(e, n) {
|
|
1235
1237
|
const r = new Map(Q(e).map((t) => [D(t), t.table]));
|
|
1236
1238
|
return fn(n, (t) => {
|
|
1237
1239
|
if (t.type !== "field" || t.table === void 0) return t;
|
|
@@ -1239,28 +1241,28 @@ function Jn(e, n) {
|
|
|
1239
1241
|
return s === void 0 || s === t.table ? t : { ...t, table: s };
|
|
1240
1242
|
});
|
|
1241
1243
|
}
|
|
1242
|
-
function
|
|
1243
|
-
const r = (n.groupBy ?? []).flatMap((s) =>
|
|
1244
|
-
return
|
|
1245
|
-
const i =
|
|
1244
|
+
function $t(e, n) {
|
|
1245
|
+
const r = (n.groupBy ?? []).flatMap((s) => wt(n, s.expression)), t = bt(e);
|
|
1246
|
+
return me(e).map((s) => {
|
|
1247
|
+
const i = Ce(e, s.name, t), a = r.find((o) => o.table === void 0 || !i.has(o.table));
|
|
1246
1248
|
return a ? { table: s, unlinked: a.table ?? a.ref } : { table: s };
|
|
1247
1249
|
});
|
|
1248
1250
|
}
|
|
1249
|
-
function
|
|
1250
|
-
const t =
|
|
1251
|
-
return
|
|
1251
|
+
function vr(e, n, r) {
|
|
1252
|
+
const t = Ce(e, r);
|
|
1253
|
+
return we(n.where).filter((s) => {
|
|
1252
1254
|
const i = wn(n, s);
|
|
1253
1255
|
return i.length > 0 && i.every((a) => a !== void 0 && t.has(a));
|
|
1254
1256
|
});
|
|
1255
1257
|
}
|
|
1256
|
-
function
|
|
1257
|
-
const t =
|
|
1258
|
-
return
|
|
1258
|
+
function Sr(e, n, r) {
|
|
1259
|
+
const t = Ce(e, r);
|
|
1260
|
+
return we(n.where).some((s) => {
|
|
1259
1261
|
const i = wn(n, s);
|
|
1260
1262
|
return i.some((a) => a !== void 0 && t.has(a)) && i.some((a) => a === void 0 || !t.has(a));
|
|
1261
1263
|
});
|
|
1262
1264
|
}
|
|
1263
|
-
function
|
|
1265
|
+
function Re(e, n) {
|
|
1264
1266
|
let r = e;
|
|
1265
1267
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1266
1268
|
return r;
|
|
@@ -1274,7 +1276,7 @@ function sn(e, n) {
|
|
|
1274
1276
|
return n;
|
|
1275
1277
|
}
|
|
1276
1278
|
const on = (e, n) => ({ type: "field", table: e, column: n });
|
|
1277
|
-
function
|
|
1279
|
+
function Er(e, n) {
|
|
1278
1280
|
return {
|
|
1279
1281
|
type: "logical",
|
|
1280
1282
|
operator: "OR",
|
|
@@ -1296,25 +1298,25 @@ function Sr(e, n) {
|
|
|
1296
1298
|
]
|
|
1297
1299
|
};
|
|
1298
1300
|
}
|
|
1299
|
-
function
|
|
1301
|
+
function Tr(e, n, r) {
|
|
1300
1302
|
var i;
|
|
1301
1303
|
if (r.type !== "field" || r.table === void 0 || r.column === void 0) return !1;
|
|
1302
1304
|
const t = wn(n, r)[0], s = (i = z(e, t)) == null ? void 0 : i.columns.find((a) => a.name === r.column);
|
|
1303
1305
|
return s !== void 0 && !s.nullable;
|
|
1304
1306
|
}
|
|
1305
|
-
function
|
|
1306
|
-
const s = n.groupBy.map((a) => a.expression), i = t.map((a, o) =>
|
|
1307
|
+
function vt(e, n, r, t) {
|
|
1308
|
+
const s = n.groupBy.map((a) => a.expression), i = t.map((a, o) => Tr(e, n, s[o]) ? {
|
|
1307
1309
|
type: "binary",
|
|
1308
1310
|
operator: "=",
|
|
1309
1311
|
left: on(r, a),
|
|
1310
1312
|
right: s[o]
|
|
1311
|
-
} :
|
|
1313
|
+
} : Er(on(r, a), s[o]));
|
|
1312
1314
|
return i.length === 1 ? i[0] : { type: "logical", operator: "AND", operands: i };
|
|
1313
1315
|
}
|
|
1314
|
-
function
|
|
1315
|
-
var
|
|
1316
|
-
const a = n.groupBy.map((b) =>
|
|
1317
|
-
const G =
|
|
1316
|
+
function St(e, n, r, t, s, i) {
|
|
1317
|
+
var k;
|
|
1318
|
+
const a = n.groupBy.map((b) => Pn(n, b.expression)), o = vr(e, n, r).map((b) => Pn(n, b)), l = new Set(s.map((b) => b.alias).filter((b) => !!b)), c = a.map((b, I) => {
|
|
1319
|
+
const G = Re(sn(b, `key_${I + 1}`), l);
|
|
1318
1320
|
return l.add(G), G;
|
|
1319
1321
|
}), m = [...o, ...t];
|
|
1320
1322
|
let d = {
|
|
@@ -1324,9 +1326,9 @@ function vt(e, n, r, t, s, i) {
|
|
|
1324
1326
|
select: []
|
|
1325
1327
|
};
|
|
1326
1328
|
[...a, ...m, ...s.map((b) => b.expression)].forEach((b) => {
|
|
1327
|
-
d =
|
|
1329
|
+
d = ce(e, d, b);
|
|
1328
1330
|
});
|
|
1329
|
-
const f = ((
|
|
1331
|
+
const f = ((k = i == null ? void 0 : i.groupBy) == null ? void 0 : k.length) ?? 0, p = [...(i == null ? void 0 : i.joins) ?? []], v = d.joins.map((b) => {
|
|
1330
1332
|
const I = p.findIndex((R) => R.table !== void 0 && R.table === b.table);
|
|
1331
1333
|
if (I === -1) return b;
|
|
1332
1334
|
const [G] = p.splice(I, 1);
|
|
@@ -1357,26 +1359,26 @@ function vt(e, n, r, t, s, i) {
|
|
|
1357
1359
|
};
|
|
1358
1360
|
return $.where === void 0 && delete $.where, { query: $, copied: o.length, keyNames: c };
|
|
1359
1361
|
}
|
|
1360
|
-
function
|
|
1362
|
+
function Us(e, n, r) {
|
|
1361
1363
|
var v;
|
|
1362
1364
|
if ((n.groupBy ?? []).length === 0)
|
|
1363
1365
|
throw new Error("addMeasure: the query isn't grouped (a measure is per group)");
|
|
1364
|
-
const t =
|
|
1366
|
+
const t = $t(e, n).find(($) => $.table.name === r.table);
|
|
1365
1367
|
if (!t) throw new Error(`addMeasure: unknown table "${r.table}"`);
|
|
1366
1368
|
if (t.unlinked !== void 0)
|
|
1367
1369
|
throw new Error(`addMeasure: "${r.table}" doesn't share the query's grouping`);
|
|
1368
|
-
const s =
|
|
1369
|
-
var
|
|
1370
|
-
return
|
|
1370
|
+
const s = we(r.where), i = n.joins.find(($) => {
|
|
1371
|
+
var k;
|
|
1372
|
+
return gt($) && ((k = $.drillAcross) == null ? void 0 : k.synced) === !0 && $.query.from.table === r.table && Z(we($.query.where).slice($.drillAcross.copied), s);
|
|
1371
1373
|
});
|
|
1372
1374
|
let { joins: a } = n, o, l;
|
|
1373
1375
|
if (i) {
|
|
1374
1376
|
o = i.alias;
|
|
1375
|
-
const $ = ((v = i.query.groupBy) == null ? void 0 : v.length) ?? 0,
|
|
1376
|
-
if (
|
|
1377
|
-
l =
|
|
1377
|
+
const $ = ((v = i.query.groupBy) == null ? void 0 : v.length) ?? 0, k = i.query.select.slice($).find((b) => Z(b.expression, r.value));
|
|
1378
|
+
if (k)
|
|
1379
|
+
l = k.alias;
|
|
1378
1380
|
else {
|
|
1379
|
-
l =
|
|
1381
|
+
l = Re(
|
|
1380
1382
|
sn(r.value, "value"),
|
|
1381
1383
|
new Set(i.query.select.map((I) => I.alias ?? ""))
|
|
1382
1384
|
);
|
|
@@ -1385,18 +1387,18 @@ function Ms(e, n, r) {
|
|
|
1385
1387
|
}
|
|
1386
1388
|
} else {
|
|
1387
1389
|
l = sn(r.value, "value");
|
|
1388
|
-
const $ = { id: W(), alias: l, expression: r.value },
|
|
1390
|
+
const $ = { id: W(), alias: l, expression: r.value }, k = St(e, n, r.table, s, [$]), b = /* @__PURE__ */ new Set([
|
|
1389
1391
|
...Q(n).map(D),
|
|
1390
|
-
...
|
|
1391
|
-
]), I = `${r.table}_per_${
|
|
1392
|
-
o =
|
|
1392
|
+
...me(e).map((R) => R.name)
|
|
1393
|
+
]), I = `${r.table}_per_${k.keyNames.join("_and_")}`.slice(0, Y - 4);
|
|
1394
|
+
o = Re(I, b);
|
|
1393
1395
|
const G = {
|
|
1394
1396
|
id: W(),
|
|
1395
1397
|
alias: o,
|
|
1396
1398
|
joinType: "left",
|
|
1397
|
-
query:
|
|
1398
|
-
on:
|
|
1399
|
-
drillAcross: { synced: !0, copied:
|
|
1399
|
+
query: k.query,
|
|
1400
|
+
on: vt(e, n, o, k.keyNames),
|
|
1401
|
+
drillAcross: { synced: !0, copied: k.copied }
|
|
1400
1402
|
};
|
|
1401
1403
|
a = [...a, G];
|
|
1402
1404
|
}
|
|
@@ -1404,46 +1406,46 @@ function Ms(e, n, r) {
|
|
|
1404
1406
|
type: "function",
|
|
1405
1407
|
name: "MAX",
|
|
1406
1408
|
args: [on(o, l)]
|
|
1407
|
-
}, m = new Set(n.select.map(($) => $.alias).filter(($) => !!$)), d =
|
|
1409
|
+
}, m = new Set(n.select.map(($) => $.alias).filter(($) => !!$)), d = Re(`${r.table}_${l}`.slice(0, Y - 4), m);
|
|
1408
1410
|
let f = r.selectId !== void 0 ? n.select.map(($) => $.id === r.selectId ? { ...$, expression: c, alias: $.alias || d } : $) : [...n.select, { id: W(), expression: c, alias: d }];
|
|
1409
|
-
return f = [...n.groupBy.filter(($) => !f.some((
|
|
1411
|
+
return f = [...n.groupBy.filter(($) => !f.some((k) => Z(k.expression, $.expression))).map(($) => ({ id: W(), expression: $.expression })), ...f], { ...n, joins: a, select: f };
|
|
1410
1412
|
}
|
|
1411
|
-
function
|
|
1413
|
+
function Et(e, n, r) {
|
|
1412
1414
|
var m, d;
|
|
1413
|
-
if (!
|
|
1415
|
+
if (!gt(r)) return;
|
|
1414
1416
|
const t = r, s = t.query.from.table, i = n.groupBy ?? [];
|
|
1415
1417
|
if (s === void 0 || i.length === 0) return;
|
|
1416
|
-
const a =
|
|
1418
|
+
const a = $t(e, n).find((f) => f.table.name === s);
|
|
1417
1419
|
if (!a || a.unlinked !== void 0) return;
|
|
1418
|
-
const o = ((m = t.query.groupBy) == null ? void 0 : m.length) ?? 0, l =
|
|
1420
|
+
const o = ((m = t.query.groupBy) == null ? void 0 : m.length) ?? 0, l = we(t.query.where).slice(((d = t.drillAcross) == null ? void 0 : d.copied) ?? 0), c = St(e, n, s, l, t.query.select.slice(o), t.query);
|
|
1419
1421
|
return {
|
|
1420
1422
|
...t,
|
|
1421
1423
|
query: c.query,
|
|
1422
|
-
on:
|
|
1424
|
+
on: vt(e, n, t.alias, c.keyNames),
|
|
1423
1425
|
drillAcross: { synced: !0, copied: c.copied }
|
|
1424
1426
|
};
|
|
1425
1427
|
}
|
|
1426
|
-
function
|
|
1428
|
+
function Qe(e) {
|
|
1427
1429
|
var t, s;
|
|
1428
|
-
const n =
|
|
1430
|
+
const n = Ve(e.query), r = ((t = n.groupBy) == null ? void 0 : t.length) ?? 0;
|
|
1429
1431
|
return {
|
|
1430
1432
|
keys: (n.groupBy ?? []).map((i) => i.expression),
|
|
1431
1433
|
keyColumns: n.select.slice(0, r).map((i) => [i.alias, i.expression]),
|
|
1432
|
-
copied:
|
|
1434
|
+
copied: we(n.where).slice(0, ((s = e.drillAcross) == null ? void 0 : s.copied) ?? 0),
|
|
1433
1435
|
on: e.on
|
|
1434
1436
|
};
|
|
1435
1437
|
}
|
|
1436
1438
|
function Nr(e, n, r) {
|
|
1437
|
-
const t =
|
|
1438
|
-
return t !== void 0 && Z(
|
|
1439
|
+
const t = Et(e, n, r);
|
|
1440
|
+
return t !== void 0 && Z(Qe(t), Qe(r));
|
|
1439
1441
|
}
|
|
1440
|
-
function
|
|
1442
|
+
function Tt(e, n, r) {
|
|
1441
1443
|
let t = !1;
|
|
1442
|
-
const s = (o, l) =>
|
|
1444
|
+
const s = (o, l) => We(
|
|
1443
1445
|
l,
|
|
1444
|
-
(c, m) =>
|
|
1446
|
+
(c, m) => Tt(
|
|
1445
1447
|
e,
|
|
1446
|
-
o && H(o) === H(l) ?
|
|
1448
|
+
o && H(o) === H(l) ? be(o)[m] : void 0,
|
|
1447
1449
|
c
|
|
1448
1450
|
)
|
|
1449
1451
|
), i = r.from.query ? (() => {
|
|
@@ -1457,9 +1459,9 @@ function Et(e, n, r) {
|
|
|
1457
1459
|
const l = n == null ? void 0 : n.joins.find((f) => f.id === o.id && f.query !== void 0), c = s(l == null ? void 0 : l.query, o.query);
|
|
1458
1460
|
let m = c === o.query ? o : { ...o, query: c };
|
|
1459
1461
|
if ((d = m.drillAcross) != null && d.synced) {
|
|
1460
|
-
const f =
|
|
1462
|
+
const f = Et(e, r, m);
|
|
1461
1463
|
f && !Z(f, m) && (m = f);
|
|
1462
|
-
} else if (m.drillAcross && (l != null && l.drillAcross) && !Z(
|
|
1464
|
+
} else if (m.drillAcross && (l != null && l.drillAcross) && !Z(Qe(l), Qe(m))) {
|
|
1463
1465
|
const f = { ...m };
|
|
1464
1466
|
delete f.drillAcross, m = f;
|
|
1465
1467
|
}
|
|
@@ -1467,10 +1469,10 @@ function Et(e, n, r) {
|
|
|
1467
1469
|
});
|
|
1468
1470
|
return t ? { ...r, from: i, joins: a } : r;
|
|
1469
1471
|
}
|
|
1470
|
-
function
|
|
1471
|
-
return
|
|
1472
|
+
function Ar(e, n, r) {
|
|
1473
|
+
return ue(r) ? Tt(e, n && ue(n) ? n : void 0, r) : r;
|
|
1472
1474
|
}
|
|
1473
|
-
const
|
|
1475
|
+
const js = ["text", "number", "date", "boolean"], kr = {
|
|
1474
1476
|
varchar: "text",
|
|
1475
1477
|
integer: "integer",
|
|
1476
1478
|
decimal: "number",
|
|
@@ -1480,9 +1482,9 @@ const Os = ["text", "number", "date", "boolean"], Ar = {
|
|
|
1480
1482
|
boolean: "boolean"
|
|
1481
1483
|
};
|
|
1482
1484
|
function Nt(e) {
|
|
1483
|
-
return
|
|
1485
|
+
return kr[e];
|
|
1484
1486
|
}
|
|
1485
|
-
function
|
|
1487
|
+
function xr(e) {
|
|
1486
1488
|
const n = e.trim().toUpperCase();
|
|
1487
1489
|
if (/^((TINY|SMALL|MEDIUM|BIG)?INT|SIGNED|UNSIGNED)/.test(n)) return "integer";
|
|
1488
1490
|
if (/^(DECIMAL|NUMERIC|FLOAT|DOUBLE|REAL|MONEY)/.test(n)) return "number";
|
|
@@ -1492,14 +1494,14 @@ function kr(e) {
|
|
|
1492
1494
|
if (/^BOOL|^BIT$/.test(n)) return "boolean";
|
|
1493
1495
|
if (/^(N?VAR)?CHAR|^N?TEXT|^STRING/.test(n)) return "text";
|
|
1494
1496
|
}
|
|
1495
|
-
function
|
|
1497
|
+
function _e(e) {
|
|
1496
1498
|
if (e.as) return e.as;
|
|
1497
1499
|
const { value: n } = e;
|
|
1498
1500
|
if (typeof n == "string") return n === "" ? void 0 : "text";
|
|
1499
1501
|
if (typeof n == "number") return Number.isInteger(n) ? "integer" : "number";
|
|
1500
1502
|
if (typeof n == "bigint") return "integer";
|
|
1501
1503
|
if (typeof n == "boolean") return "boolean";
|
|
1502
|
-
if (n instanceof Date) return
|
|
1504
|
+
if (n instanceof Date) return nt(n) ? "date" : "dateTime";
|
|
1503
1505
|
}
|
|
1504
1506
|
function $n(e, n, r) {
|
|
1505
1507
|
if (!e) return;
|
|
@@ -1508,11 +1510,11 @@ function $n(e, n, r) {
|
|
|
1508
1510
|
case "field":
|
|
1509
1511
|
return n(e);
|
|
1510
1512
|
case "literal":
|
|
1511
|
-
return
|
|
1513
|
+
return _e(e);
|
|
1512
1514
|
case "function": {
|
|
1513
|
-
const s =
|
|
1515
|
+
const s = Zn(e.name, r), i = (s == null ? void 0 : s.args.findIndex((l) => l.kind === "type-name")) ?? -1, a = i >= 0 ? e.args[i] : void 0;
|
|
1514
1516
|
if ((a == null ? void 0 : a.type) === "literal" && typeof a.value == "string")
|
|
1515
|
-
return
|
|
1517
|
+
return xr(a.value);
|
|
1516
1518
|
const o = s == null ? void 0 : s.returns;
|
|
1517
1519
|
return o === "arg" ? t(e.args[0]) : o;
|
|
1518
1520
|
}
|
|
@@ -1524,28 +1526,28 @@ function $n(e, n, r) {
|
|
|
1524
1526
|
return;
|
|
1525
1527
|
}
|
|
1526
1528
|
}
|
|
1527
|
-
const
|
|
1529
|
+
const Br = /^[+-]?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i, Cr = /^([01]\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$/, Ir = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/;
|
|
1528
1530
|
function vn(e, n) {
|
|
1529
1531
|
if (e === "" || e === null) return e;
|
|
1530
1532
|
const r = typeof e == "string" ? e.trim() : void 0;
|
|
1531
1533
|
switch (n) {
|
|
1532
1534
|
case "text":
|
|
1533
|
-
return e instanceof Date ?
|
|
1535
|
+
return e instanceof Date ? zt(e) : String(e);
|
|
1534
1536
|
case "integer":
|
|
1535
1537
|
case "number": {
|
|
1536
1538
|
let t;
|
|
1537
|
-
return typeof e == "number" ? t = e : typeof e == "bigint" ? t = Number(e) : r !== void 0 &&
|
|
1539
|
+
return typeof e == "number" ? t = e : typeof e == "bigint" ? t = Number(e) : r !== void 0 && Br.test(r) && (t = Number(r)), t === void 0 || !nn(t) || n === "integer" && !Number.isInteger(t) ? void 0 : t;
|
|
1538
1540
|
}
|
|
1539
1541
|
case "date":
|
|
1540
1542
|
case "dateTime": {
|
|
1541
|
-
if (e instanceof Date) return n === "date" && !
|
|
1542
|
-
const t = r === void 0 ? null :
|
|
1543
|
+
if (e instanceof Date) return n === "date" && !nt(e) ? void 0 : e;
|
|
1544
|
+
const t = r === void 0 ? null : Ir.exec(r);
|
|
1543
1545
|
if (!t) return;
|
|
1544
|
-
const [, s, i, a, o, l, c] = t.map(Number), m =
|
|
1546
|
+
const [, s, i, a, o, l, c] = t.map(Number), m = Yt(s, i, a);
|
|
1545
1547
|
return m.getUTCMonth() !== i - 1 || m.getUTCDate() !== a ? void 0 : t[4] === void 0 ? m : n === "date" ? void 0 : new Date(Date.UTC(s, i - 1, a, o, l, Number.isNaN(c) ? 0 : c));
|
|
1546
1548
|
}
|
|
1547
1549
|
case "time": {
|
|
1548
|
-
const t = r === void 0 ? null :
|
|
1550
|
+
const t = r === void 0 ? null : Cr.exec(r);
|
|
1549
1551
|
return t ? `${t[1]}:${t[2]}:${t[3] ?? "00"}` : void 0;
|
|
1550
1552
|
}
|
|
1551
1553
|
case "boolean":
|
|
@@ -1555,7 +1557,7 @@ function vn(e, n) {
|
|
|
1555
1557
|
return;
|
|
1556
1558
|
}
|
|
1557
1559
|
}
|
|
1558
|
-
function
|
|
1560
|
+
function Mr(e, n, r) {
|
|
1559
1561
|
var m;
|
|
1560
1562
|
if (n === void 0) return e;
|
|
1561
1563
|
const { as: t, empty: s, ...i } = e;
|
|
@@ -1564,19 +1566,19 @@ function Ir(e, n, r) {
|
|
|
1564
1566
|
const o = s && n === "text", l = a === void 0 ? { type: "literal", value: "" } : { ...i, value: a, ...o ? { empty: s } : {} };
|
|
1565
1567
|
return t === void 0 && !!s == !!o && a === e.value ? e : l;
|
|
1566
1568
|
}
|
|
1567
|
-
function
|
|
1569
|
+
function Ls(e, n, r, t = !1) {
|
|
1568
1570
|
const s = e.items.flatMap((a) => {
|
|
1569
1571
|
if (a.type !== "literal") return [a];
|
|
1570
|
-
const o =
|
|
1572
|
+
const o = Mr(a, n, r);
|
|
1571
1573
|
return o.value === "" && !o.empty && !t ? [] : [o];
|
|
1572
1574
|
});
|
|
1573
1575
|
return s.length === e.items.length && s.every((a, o) => a === e.items[o]) ? e : { ...e, items: s };
|
|
1574
1576
|
}
|
|
1575
|
-
function
|
|
1576
|
-
const n =
|
|
1577
|
+
function Ds(e) {
|
|
1578
|
+
const n = _e(e);
|
|
1577
1579
|
return n === "integer" || n === "number" ? "number" : n === "date" || n === "dateTime" ? "date" : n;
|
|
1578
1580
|
}
|
|
1579
|
-
function
|
|
1581
|
+
function Gs(e, n) {
|
|
1580
1582
|
const t = (e.type === "literal" ? vn(e.value, n) : void 0) ?? "", s = e.type === "literal" && e.empty && n === "text";
|
|
1581
1583
|
return {
|
|
1582
1584
|
type: "literal",
|
|
@@ -1585,7 +1587,7 @@ function Ls(e, n) {
|
|
|
1585
1587
|
...s ? { empty: s } : {}
|
|
1586
1588
|
};
|
|
1587
1589
|
}
|
|
1588
|
-
function
|
|
1590
|
+
function Rs(e, n = !1) {
|
|
1589
1591
|
if (e !== void 0)
|
|
1590
1592
|
return e === "text" ? [
|
|
1591
1593
|
"=",
|
|
@@ -1598,14 +1600,14 @@ function Ds(e, n = !1) {
|
|
|
1598
1600
|
"IS NOT NULL"
|
|
1599
1601
|
] : e === "boolean" ? ["=", "!=", "IS NULL", "IS NOT NULL"] : ["=", "!=", "<", "<=", ">", ">=", "IN", "BETWEEN", "IS NULL", "IS NOT NULL"];
|
|
1600
1602
|
}
|
|
1601
|
-
const
|
|
1603
|
+
const At = "source", kt = "rows_", se = (e) => e ? { type: "literal", value: null, as: e } : { type: "literal", value: null }, ke = (e) => e.type === "literal" && e.value === null, Sn = (e) => new Map(
|
|
1602
1604
|
Q(e).map((n) => [D(n), n.table])
|
|
1603
1605
|
);
|
|
1604
1606
|
function an(e, n) {
|
|
1605
1607
|
const r = Sn(e);
|
|
1606
1608
|
return ne(n).map((t) => r.get(t) ?? t);
|
|
1607
1609
|
}
|
|
1608
|
-
function
|
|
1610
|
+
function xt(e, n) {
|
|
1609
1611
|
const r = Sn(e);
|
|
1610
1612
|
return fn(n, (t) => {
|
|
1611
1613
|
if (t.type !== "field" || t.table === void 0) return t;
|
|
@@ -1613,57 +1615,57 @@ function kt(e, n) {
|
|
|
1613
1615
|
return s === void 0 || s === t.table ? t : { ...t, table: s };
|
|
1614
1616
|
});
|
|
1615
1617
|
}
|
|
1616
|
-
function
|
|
1618
|
+
function Fe(e, n, r) {
|
|
1617
1619
|
const t = Sn(n);
|
|
1618
1620
|
return $n(r, (s) => {
|
|
1619
1621
|
var o;
|
|
1620
1622
|
const i = t.get(s.table ?? "") ?? s.table ?? "", a = (o = z(e, i)) == null ? void 0 : o.columns.find((l) => l.name === s.column);
|
|
1621
1623
|
return a && Nt(a.type);
|
|
1622
|
-
},
|
|
1624
|
+
}, $e);
|
|
1623
1625
|
}
|
|
1624
1626
|
function En(e, n) {
|
|
1625
1627
|
let r = e;
|
|
1626
1628
|
for (let t = 2; n.has(r); t += 1) r = `${e}_${t}`;
|
|
1627
1629
|
return r;
|
|
1628
1630
|
}
|
|
1629
|
-
const
|
|
1631
|
+
const Je = (e) => e ? e.type === "logical" && e.operator === "AND" ? e.operands : [e] : [], Bt = (e) => {
|
|
1630
1632
|
if (e.length !== 0)
|
|
1631
1633
|
return e.length === 1 ? e[0] : { type: "logical", operator: "AND", operands: e };
|
|
1632
|
-
},
|
|
1633
|
-
function
|
|
1634
|
+
}, ie = (e) => e.from.table, Vn = (e, n) => z(e, n).label;
|
|
1635
|
+
function Xe(e) {
|
|
1634
1636
|
const { from: n } = e;
|
|
1635
1637
|
return n.query && H(n.query) ? n : void 0;
|
|
1636
1638
|
}
|
|
1637
|
-
function
|
|
1638
|
-
if (n === void 0) return
|
|
1639
|
-
const r =
|
|
1639
|
+
function Ie(e, n) {
|
|
1640
|
+
if (n === void 0) return Xe(e);
|
|
1641
|
+
const r = oe(e).find((t) => t.id === n);
|
|
1640
1642
|
return r && H(r.query) ? r : void 0;
|
|
1641
1643
|
}
|
|
1642
|
-
function
|
|
1644
|
+
function Me(e, n, r) {
|
|
1643
1645
|
const t = { ...n, query: r };
|
|
1644
1646
|
return n === e.from ? { ...e, from: t } : { ...e, joins: e.joins.map((s) => s === n ? t : s) };
|
|
1645
1647
|
}
|
|
1646
|
-
function
|
|
1648
|
+
function Ke(e, n) {
|
|
1647
1649
|
const [r] = n;
|
|
1648
1650
|
return r.select.map((t, s) => {
|
|
1649
1651
|
var d;
|
|
1650
1652
|
const i = K(t) ?? "", a = n.map((f) => {
|
|
1651
1653
|
var p;
|
|
1652
1654
|
return { branch: f, expression: (p = f.select[s]) == null ? void 0 : p.expression };
|
|
1653
|
-
}).filter((f) => f.expression !== void 0 && !
|
|
1655
|
+
}).filter((f) => f.expression !== void 0 && !ke(f.expression)), l = ((d = n.map((f) => {
|
|
1654
1656
|
var p;
|
|
1655
1657
|
return (p = f.select[s]) == null ? void 0 : p.expression;
|
|
1656
1658
|
}).filter(
|
|
1657
1659
|
(f) => (f == null ? void 0 : f.type) === "literal" && f.value === null
|
|
1658
|
-
).find((f) => f.as)) == null ? void 0 : d.as) ?? (a[0] &&
|
|
1659
|
-
if (i ===
|
|
1660
|
+
).find((f) => f.as)) == null ? void 0 : d.as) ?? (a[0] && Fe(e, a[0].branch, a[0].expression));
|
|
1661
|
+
if (i === At && a.length === n.length && a.every((f) => f.expression.type === "literal"))
|
|
1660
1662
|
return {
|
|
1661
1663
|
name: i,
|
|
1662
1664
|
kind: "source",
|
|
1663
1665
|
tables: [],
|
|
1664
1666
|
type: "text"
|
|
1665
1667
|
};
|
|
1666
|
-
if (i.startsWith(
|
|
1668
|
+
if (i.startsWith(kt) && a.length === 1 && a[0].expression.type === "literal")
|
|
1667
1669
|
return {
|
|
1668
1670
|
name: i,
|
|
1669
1671
|
kind: "rows",
|
|
@@ -1679,7 +1681,7 @@ function Xe(e, n) {
|
|
|
1679
1681
|
type: l
|
|
1680
1682
|
};
|
|
1681
1683
|
const m = an(c.branch, c.expression);
|
|
1682
|
-
return a.some((f) => an(f.branch, f.expression).includes(
|
|
1684
|
+
return a.some((f) => an(f.branch, f.expression).includes(ie(f.branch))) ? {
|
|
1683
1685
|
name: i,
|
|
1684
1686
|
kind: "own",
|
|
1685
1687
|
tables: m,
|
|
@@ -1689,26 +1691,26 @@ function Xe(e, n) {
|
|
|
1689
1691
|
kind: "shared",
|
|
1690
1692
|
tables: m,
|
|
1691
1693
|
type: l,
|
|
1692
|
-
expression:
|
|
1694
|
+
expression: xt(c.branch, c.expression)
|
|
1693
1695
|
};
|
|
1694
1696
|
});
|
|
1695
1697
|
}
|
|
1696
|
-
function
|
|
1697
|
-
const r =
|
|
1698
|
+
function qs(e, n) {
|
|
1699
|
+
const r = Xe(n);
|
|
1698
1700
|
if (!r) return [];
|
|
1699
1701
|
const { union: t } = r.query;
|
|
1700
|
-
return
|
|
1701
|
-
const a = t.map((o) => !
|
|
1702
|
+
return Ke(e, t).map((s, i) => {
|
|
1703
|
+
const a = t.map((o) => !ke(o.select[i].expression));
|
|
1702
1704
|
return {
|
|
1703
1705
|
name: s.name,
|
|
1704
1706
|
kind: s.kind,
|
|
1705
|
-
filledBy: t.filter((o, l) => a[l]).map(
|
|
1706
|
-
nullIn: t.filter((o, l) => !a[l]).map(
|
|
1707
|
+
filledBy: t.filter((o, l) => a[l]).map(ie),
|
|
1708
|
+
nullIn: t.filter((o, l) => !a[l]).map(ie)
|
|
1707
1709
|
};
|
|
1708
1710
|
});
|
|
1709
1711
|
}
|
|
1710
|
-
function
|
|
1711
|
-
const i =
|
|
1712
|
+
function Ct(e, n, r, t, s) {
|
|
1713
|
+
const i = Ce(e, n), a = r.filter((m) => m.kind === "shared" && m.expression), o = (m) => m.tables.every((d) => i.has(d));
|
|
1712
1714
|
if (!a.some(o)) return `"${n}" shares no column with the union`;
|
|
1713
1715
|
const l = a.find((m) => !o(m));
|
|
1714
1716
|
if (l && s === "refuse")
|
|
@@ -1717,89 +1719,89 @@ function Bt(e, n, r, t, s) {
|
|
|
1717
1719
|
if (c)
|
|
1718
1720
|
return `"${n}" can't follow a condition on ${c.tables.join(", ")}`;
|
|
1719
1721
|
}
|
|
1720
|
-
function
|
|
1721
|
-
const [n] = e, r = new Set(e.map(
|
|
1722
|
-
return
|
|
1722
|
+
function It(e) {
|
|
1723
|
+
const [n] = e, r = new Set(e.map(ie));
|
|
1724
|
+
return Je(n.where).flatMap((t) => {
|
|
1723
1725
|
const s = an(n, t), i = s.filter((a) => r.has(a));
|
|
1724
|
-
if (i.length === 0) return [{ operand:
|
|
1726
|
+
if (i.length === 0) return [{ operand: xt(n, t), tables: s }];
|
|
1725
1727
|
if (i.length === s.length) return [];
|
|
1726
1728
|
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");
|
|
1727
1729
|
});
|
|
1728
1730
|
}
|
|
1729
|
-
function
|
|
1730
|
-
const s = t.unshared ?? "refuse", i =
|
|
1731
|
+
function Wn(e, n, r, t) {
|
|
1732
|
+
const s = t.unshared ?? "refuse", i = Ke(e, n), a = It(n);
|
|
1731
1733
|
if (!z(e, r.table))
|
|
1732
1734
|
throw new Error(`addUnionTable: unknown table "${r.table}"`);
|
|
1733
|
-
if (n.some((x) =>
|
|
1735
|
+
if (n.some((x) => ie(x) === r.table))
|
|
1734
1736
|
throw new Error(`addUnionTable: "${r.table}" is in the union already`);
|
|
1735
|
-
const o =
|
|
1737
|
+
const o = Ct(e, r.table, i, a, s);
|
|
1736
1738
|
if (o) throw new Error(`addUnionTable: ${o}`);
|
|
1737
|
-
const l =
|
|
1738
|
-
const
|
|
1739
|
-
return d.add(
|
|
1739
|
+
const l = Ce(e, r.table), c = r.label ?? Vn(e, r.table), m = i.map((x) => x.kind === "source" ? { type: "literal", value: c } : x.kind === "shared" && x.expression && x.tables.every((F) => l.has(F)) ? x.expression : se(x.type)), d = new Set(i.map((x) => x.name)), f = [], p = (x) => {
|
|
1740
|
+
const F = En(x, d);
|
|
1741
|
+
return d.add(F), f.push(F), F;
|
|
1740
1742
|
}, v = [], $ = {
|
|
1741
1743
|
from: { table: r.table },
|
|
1742
1744
|
joins: []
|
|
1743
1745
|
};
|
|
1744
1746
|
r.columns.forEach((x) => {
|
|
1745
|
-
const
|
|
1746
|
-
v.push({ name: p(
|
|
1747
|
+
const F = x.alias ?? (x.expression.type === "field" ? x.expression.column : void 0) ?? "value", pe = Fe(e, $, x.expression);
|
|
1748
|
+
v.push({ name: p(F), own: x.expression, others: () => se(pe) });
|
|
1747
1749
|
}), t.source && !i.some((x) => x.kind === "source") && v.push({
|
|
1748
|
-
name: p(
|
|
1750
|
+
name: p(At),
|
|
1749
1751
|
own: { type: "literal", value: c },
|
|
1750
|
-
others: (x) => ({ type: "literal", value:
|
|
1752
|
+
others: (x) => ({ type: "literal", value: Vn(e, ie(x)) })
|
|
1751
1753
|
});
|
|
1752
|
-
const
|
|
1753
|
-
(t.rowMarkers || i.some((x) => x.kind === "rows")) && (n.filter((x) => !d.has(
|
|
1754
|
+
const k = (x) => `${kt}${x}`;
|
|
1755
|
+
(t.rowMarkers || i.some((x) => x.kind === "rows")) && (n.filter((x) => !d.has(k(ie(x)))).forEach((x) => {
|
|
1754
1756
|
v.push({
|
|
1755
|
-
name: p(
|
|
1756
|
-
own:
|
|
1757
|
-
others: (
|
|
1757
|
+
name: p(k(ie(x))),
|
|
1758
|
+
own: se("integer"),
|
|
1759
|
+
others: (F) => F === x ? { type: "literal", value: 1 } : se("integer")
|
|
1758
1760
|
});
|
|
1759
1761
|
}), v.push({
|
|
1760
|
-
name: p(
|
|
1762
|
+
name: p(k(r.table)),
|
|
1761
1763
|
own: { type: "literal", value: 1 },
|
|
1762
|
-
others: () =>
|
|
1764
|
+
others: () => se("integer")
|
|
1763
1765
|
}));
|
|
1764
|
-
const b = (x,
|
|
1766
|
+
const b = (x, F) => ({
|
|
1765
1767
|
id: W(),
|
|
1766
1768
|
alias: x,
|
|
1767
|
-
expression:
|
|
1769
|
+
expression: F
|
|
1768
1770
|
}), I = n.map((x) => ({
|
|
1769
1771
|
...x,
|
|
1770
|
-
select: [...x.select, ...v.map((
|
|
1771
|
-
})), G =
|
|
1772
|
+
select: [...x.select, ...v.map((F) => b(F.name, F.others(x)))]
|
|
1773
|
+
})), G = Bt([...a.map((x) => x.operand), ...Je(r.where)]);
|
|
1772
1774
|
let R = {
|
|
1773
1775
|
id: "",
|
|
1774
1776
|
from: { table: r.table },
|
|
1775
1777
|
joins: [],
|
|
1776
1778
|
...G ? { where: G } : {},
|
|
1777
1779
|
select: [
|
|
1778
|
-
...i.map((x,
|
|
1780
|
+
...i.map((x, F) => b(x.name, m[F])),
|
|
1779
1781
|
...v.map((x) => b(x.name, x.own))
|
|
1780
1782
|
]
|
|
1781
1783
|
};
|
|
1782
1784
|
[G, ...R.select.map((x) => x.expression)].forEach((x) => {
|
|
1783
|
-
R =
|
|
1785
|
+
R = ce(e, R, x);
|
|
1784
1786
|
});
|
|
1785
1787
|
const {
|
|
1786
1788
|
from: X,
|
|
1787
1789
|
joins: ee,
|
|
1788
|
-
select:
|
|
1789
|
-
where:
|
|
1790
|
-
} = R,
|
|
1790
|
+
select: ye,
|
|
1791
|
+
where: he
|
|
1792
|
+
} = R, te = {
|
|
1791
1793
|
from: X,
|
|
1792
1794
|
joins: ee,
|
|
1793
|
-
select:
|
|
1794
|
-
...
|
|
1795
|
+
select: ye,
|
|
1796
|
+
...he ? { where: he } : {}
|
|
1795
1797
|
};
|
|
1796
|
-
return { union: [...I,
|
|
1798
|
+
return { union: [...I, te], added: f };
|
|
1797
1799
|
}
|
|
1798
|
-
function
|
|
1800
|
+
function Mt(e) {
|
|
1799
1801
|
const n = (s) => new Error(`addUnionTable: ${s}`);
|
|
1800
1802
|
if (e.from.query) throw n("the query reads from a derived table");
|
|
1801
1803
|
if (e.select.length === 0) throw n("the query picks no columns (SELECT *)");
|
|
1802
|
-
if ((e.groupBy ?? []).length > 0 || e.having || e.distinct || (e.orderBy ?? []).length > 0 || e.select.some((s) =>
|
|
1804
|
+
if ((e.groupBy ?? []).length > 0 || e.having || e.distinct || (e.orderBy ?? []).length > 0 || e.select.some((s) => le(s.expression, $e)))
|
|
1803
1805
|
throw n("a union is of detail rows: no aggregates, GROUP BY, HAVING, DISTINCT or ORDER BY");
|
|
1804
1806
|
const r = /* @__PURE__ */ new Set(), t = e.select.map((s, i) => {
|
|
1805
1807
|
const a = En(K(s) ?? `column_${i + 1}`, r);
|
|
@@ -1812,10 +1814,10 @@ function It(e) {
|
|
|
1812
1814
|
select: t
|
|
1813
1815
|
};
|
|
1814
1816
|
}
|
|
1815
|
-
function
|
|
1816
|
-
const s =
|
|
1817
|
+
function Qs(e, n, r, t = {}) {
|
|
1818
|
+
const s = Xe(n);
|
|
1817
1819
|
if (s) {
|
|
1818
|
-
const { union: c, added: m } =
|
|
1820
|
+
const { union: c, added: m } = Wn(e, s.query.union, r, t), d = { ...s, query: { ...s.query, union: c } }, f = n.select.length === 0 ? [] : [
|
|
1819
1821
|
...n.select,
|
|
1820
1822
|
...m.map((p) => ({
|
|
1821
1823
|
id: W(),
|
|
@@ -1824,7 +1826,7 @@ function Rs(e, n, r, t = {}) {
|
|
|
1824
1826
|
];
|
|
1825
1827
|
return { ...n, from: d, select: f };
|
|
1826
1828
|
}
|
|
1827
|
-
const i =
|
|
1829
|
+
const i = Mt(n), { union: a } = Wn(e, [i], r, t), o = t.alias ?? "stacked", l = a[0].select.map((c) => c.alias);
|
|
1828
1830
|
return {
|
|
1829
1831
|
id: n.id,
|
|
1830
1832
|
from: { id: W(), alias: o, query: { union: a, all: !0 } },
|
|
@@ -1837,40 +1839,40 @@ function Rs(e, n, r, t = {}) {
|
|
|
1837
1839
|
...n.offset !== void 0 ? { offset: n.offset } : {}
|
|
1838
1840
|
};
|
|
1839
1841
|
}
|
|
1840
|
-
function
|
|
1841
|
-
const t =
|
|
1842
|
+
function _s(e, n, r = {}) {
|
|
1843
|
+
const t = Xe(n);
|
|
1842
1844
|
let s;
|
|
1843
1845
|
try {
|
|
1844
|
-
s = t ? t.query.union : [
|
|
1846
|
+
s = t ? t.query.union : [Mt(n)];
|
|
1845
1847
|
} catch {
|
|
1846
1848
|
return [];
|
|
1847
1849
|
}
|
|
1848
|
-
const i =
|
|
1850
|
+
const i = Ke(e, s);
|
|
1849
1851
|
let a;
|
|
1850
1852
|
try {
|
|
1851
|
-
a =
|
|
1853
|
+
a = It(s);
|
|
1852
1854
|
} catch {
|
|
1853
1855
|
return [];
|
|
1854
1856
|
}
|
|
1855
1857
|
const o = /* @__PURE__ */ new Set([
|
|
1856
|
-
...s.map(
|
|
1858
|
+
...s.map(ie),
|
|
1857
1859
|
...i.flatMap((l) => l.kind === "shared" ? l.tables : [])
|
|
1858
1860
|
]);
|
|
1859
|
-
return e.tables.map((l) => l.name).filter((l) => !o.has(l) &&
|
|
1861
|
+
return e.tables.map((l) => l.name).filter((l) => !o.has(l) && Ct(e, l, i, a, r.unshared ?? "refuse") === void 0);
|
|
1860
1862
|
}
|
|
1861
|
-
function
|
|
1863
|
+
function Or(e, n, r) {
|
|
1862
1864
|
const t = r.union.findIndex((l, c) => l.select !== n.union[c].select);
|
|
1863
1865
|
if (t === -1) return r;
|
|
1864
1866
|
const s = r.union[t], i = n.union[t].select.map((l) => l.id), a = r.union.map((l, c) => {
|
|
1865
1867
|
if (c === t) return l;
|
|
1866
1868
|
const m = s.select.map((f) => {
|
|
1867
|
-
const p = K(f), v =
|
|
1868
|
-
if (!
|
|
1869
|
-
return { id: W(), ...p ? { alias: p } : {}, expression:
|
|
1870
|
-
let b =
|
|
1871
|
-
K(
|
|
1872
|
-
const { expression: I } =
|
|
1873
|
-
return
|
|
1869
|
+
const p = K(f), v = Fe(e, s, f.expression), $ = i.indexOf(f.id), k = $ === -1 ? void 0 : l.select[$];
|
|
1870
|
+
if (!k)
|
|
1871
|
+
return { id: W(), ...p ? { alias: p } : {}, expression: se(v) };
|
|
1872
|
+
let b = k;
|
|
1873
|
+
K(k) !== p && (b = { ...b, alias: p });
|
|
1874
|
+
const { expression: I } = k;
|
|
1875
|
+
return ke(I) && I.type === "literal" && I.as !== v && (b = { ...b, expression: se(v) }), b;
|
|
1874
1876
|
});
|
|
1875
1877
|
return m.length === l.select.length && m.every((f, p) => f === l.select[p]) ? l : { ...l, select: m };
|
|
1876
1878
|
}), o = a.map((l) => {
|
|
@@ -1879,38 +1881,38 @@ function Mr(e, n, r) {
|
|
|
1879
1881
|
if (f.type !== "literal" || f.value !== null) return m;
|
|
1880
1882
|
const p = a.find(($) => {
|
|
1881
1883
|
var b;
|
|
1882
|
-
const
|
|
1883
|
-
return
|
|
1884
|
-
}), v = p &&
|
|
1885
|
-
return v && f.as !== v ? { ...m, expression:
|
|
1884
|
+
const k = (b = $.select[d]) == null ? void 0 : b.expression;
|
|
1885
|
+
return k !== void 0 && !ke(k);
|
|
1886
|
+
}), v = p && Fe(e, p, p.select[d].expression);
|
|
1887
|
+
return v && f.as !== v ? { ...m, expression: se(v) } : m;
|
|
1886
1888
|
});
|
|
1887
1889
|
return c.every((m, d) => m === l.select[d]) ? l : { ...l, select: c };
|
|
1888
1890
|
});
|
|
1889
1891
|
return o.every((l, c) => l === r.union[c]) ? r : { ...r, union: o };
|
|
1890
1892
|
}
|
|
1891
|
-
function
|
|
1893
|
+
function Ur(e, n) {
|
|
1892
1894
|
const r = (i) => i.union[0].select.map((a) => K(a)), t = r(e), s = r(n);
|
|
1893
1895
|
return t.length !== s.length ? [] : t.flatMap((i, a) => {
|
|
1894
1896
|
const o = s[a];
|
|
1895
1897
|
return i && o && i !== o && !s.includes(i) && !t.includes(o) ? [{ from: i, to: o }] : [];
|
|
1896
1898
|
});
|
|
1897
1899
|
}
|
|
1898
|
-
function
|
|
1900
|
+
function Ot(e, n, r) {
|
|
1899
1901
|
let t = r;
|
|
1900
|
-
n && H(n) && H(t) && n.union.length === t.union.length && (t =
|
|
1902
|
+
n && H(n) && H(t) && n.union.length === t.union.length && (t = Or(e, n, t));
|
|
1901
1903
|
const s = t;
|
|
1902
|
-
return
|
|
1904
|
+
return We(s, (i, a) => Tn(
|
|
1903
1905
|
e,
|
|
1904
|
-
n && H(n) === H(s) ?
|
|
1906
|
+
n && H(n) === H(s) ? be(n)[a] : void 0,
|
|
1905
1907
|
i
|
|
1906
1908
|
));
|
|
1907
1909
|
}
|
|
1908
|
-
function
|
|
1910
|
+
function Tn(e, n, r) {
|
|
1909
1911
|
const t = (f) => {
|
|
1910
1912
|
var p;
|
|
1911
|
-
return
|
|
1913
|
+
return Ot(
|
|
1912
1914
|
e,
|
|
1913
|
-
n && ((p =
|
|
1915
|
+
n && ((p = oe(n).find((v) => v.id === f.id)) == null ? void 0 : p.query),
|
|
1914
1916
|
f.query
|
|
1915
1917
|
);
|
|
1916
1918
|
}, { from: s } = r, i = s.query && t(s), a = i && i !== s.query ? { ...s, query: i } : s;
|
|
@@ -1921,36 +1923,36 @@ function Nn(e, n, r) {
|
|
|
1921
1923
|
return p === f.query ? f : (o = !0, { ...f, query: p });
|
|
1922
1924
|
});
|
|
1923
1925
|
if (a === s && !o) return r;
|
|
1924
|
-
const c = { ...r, from: a, joins: l }, m =
|
|
1926
|
+
const c = { ...r, from: a, joins: l }, m = oe(c).flatMap((f) => {
|
|
1925
1927
|
var v;
|
|
1926
|
-
const p = n && ((v =
|
|
1927
|
-
return p && H(p) && H(f.query) ?
|
|
1928
|
+
const p = n && ((v = oe(n).find(($) => $.id === f.id)) == null ? void 0 : v.query);
|
|
1929
|
+
return p && H(p) && H(f.query) ? Ur(p, f.query).map(($) => ({ ...$, alias: f.alias })) : [];
|
|
1928
1930
|
});
|
|
1929
1931
|
if (m.length === 0) return c;
|
|
1930
1932
|
const d = (f) => {
|
|
1931
|
-
if (f.type !== "field") return
|
|
1933
|
+
if (f.type !== "field") return xe(f, d);
|
|
1932
1934
|
const p = m.find((v) => v.alias === f.table && v.from === f.column);
|
|
1933
1935
|
return p ? { ...f, column: p.to } : f;
|
|
1934
1936
|
};
|
|
1935
|
-
return
|
|
1937
|
+
return Pe(c, d, (f) => f);
|
|
1936
1938
|
}
|
|
1937
|
-
function
|
|
1938
|
-
if (!
|
|
1939
|
-
const t = n &&
|
|
1940
|
-
return dn(
|
|
1939
|
+
function jr(e, n, r) {
|
|
1940
|
+
if (!ue(r)) return r;
|
|
1941
|
+
const t = n && ue(n) ? n : void 0;
|
|
1942
|
+
return dn(Tn(e, t, r), (s, i) => {
|
|
1941
1943
|
var a, o;
|
|
1942
|
-
return
|
|
1944
|
+
return Ot(
|
|
1943
1945
|
e,
|
|
1944
1946
|
(o = (a = t == null ? void 0 : t.shared) == null ? void 0 : a.find((l) => l.id === i.id)) == null ? void 0 : o.query,
|
|
1945
1947
|
s
|
|
1946
1948
|
);
|
|
1947
1949
|
});
|
|
1948
1950
|
}
|
|
1949
|
-
function
|
|
1950
|
-
return e.type === "field" ? [e] :
|
|
1951
|
+
function Ut(e) {
|
|
1952
|
+
return e.type === "field" ? [e] : fe(e).flatMap(Ut);
|
|
1951
1953
|
}
|
|
1952
|
-
const
|
|
1953
|
-
function
|
|
1954
|
+
const jt = (e, n, r) => Ut(e).some((t) => t.table === n && r.has(t.column ?? ""));
|
|
1955
|
+
function Lr(e, n, r) {
|
|
1954
1956
|
const t = n.query.union.filter((l, c) => c !== r), s = [
|
|
1955
1957
|
e.where,
|
|
1956
1958
|
e.having,
|
|
@@ -1958,9 +1960,9 @@ function jr(e, n, r) {
|
|
|
1958
1960
|
...(e.groupBy ?? []).map((l) => l.expression),
|
|
1959
1961
|
...(e.orderBy ?? []).map((l) => l.expression)
|
|
1960
1962
|
].filter((l) => l !== void 0), i = (l) => s.some(
|
|
1961
|
-
(c) =>
|
|
1963
|
+
(c) => jt(c, n.alias, /* @__PURE__ */ new Set([l]))
|
|
1962
1964
|
), a = new Set(t[0].select.flatMap((l, c) => {
|
|
1963
|
-
const m = t.every((f) => f.select[c] &&
|
|
1965
|
+
const m = t.every((f) => f.select[c] && ke(f.select[c].expression)), d = K(l);
|
|
1964
1966
|
return m && !(d && i(d)) ? [c] : [];
|
|
1965
1967
|
})), o = new Set([...a].flatMap((l) => {
|
|
1966
1968
|
const c = K(t[0].select[l]);
|
|
@@ -1968,15 +1970,15 @@ function jr(e, n, r) {
|
|
|
1968
1970
|
}));
|
|
1969
1971
|
return { at: a, names: o };
|
|
1970
1972
|
}
|
|
1971
|
-
function
|
|
1972
|
-
const t =
|
|
1973
|
+
function Fs(e, n, r) {
|
|
1974
|
+
const t = Ie(e, r);
|
|
1973
1975
|
if (!t || !t.query.union[n] || t.query.union.length < 2) return e;
|
|
1974
|
-
const s =
|
|
1975
|
-
(c) => !
|
|
1976
|
+
const s = Lr(e, t, n), i = t.query.union.filter((c, m) => m !== n), a = s.at.size < i[0].select.length ? s : { at: /* @__PURE__ */ new Set(), names: /* @__PURE__ */ new Set() }, o = e.select.filter(
|
|
1977
|
+
(c) => !jt(c.expression, t.alias, a.names)
|
|
1976
1978
|
), l = i.map((c) => ({ ...c, select: c.select.filter((m, d) => !a.at.has(d)) }));
|
|
1977
|
-
return
|
|
1979
|
+
return Me({ ...e, select: o }, t, { ...t.query, union: l });
|
|
1978
1980
|
}
|
|
1979
|
-
function
|
|
1981
|
+
function Dr(e, n) {
|
|
1980
1982
|
const r = /* @__PURE__ */ new Set([
|
|
1981
1983
|
...n ? Q(n).map(D) : [],
|
|
1982
1984
|
...e.tables.map((s) => s.name)
|
|
@@ -1985,7 +1987,7 @@ function Lr(e, n) {
|
|
|
1985
1987
|
for (; r.has(`union_${t}`); ) t += 1;
|
|
1986
1988
|
return `union_${t}`;
|
|
1987
1989
|
}
|
|
1988
|
-
function
|
|
1990
|
+
function Js(e, n, r, t) {
|
|
1989
1991
|
return {
|
|
1990
1992
|
id: e,
|
|
1991
1993
|
from: { id: n, alias: r, query: { union: [{ from: t, joins: [], select: [] }], all: !0 } },
|
|
@@ -1993,9 +1995,9 @@ function _s(e, n, r, t) {
|
|
|
1993
1995
|
select: []
|
|
1994
1996
|
};
|
|
1995
1997
|
}
|
|
1996
|
-
function
|
|
1997
|
-
const t = /* @__PURE__ */ new Set(), s = e.select.map(($,
|
|
1998
|
-
const b = En(K($) ?? `column_${
|
|
1998
|
+
function Ps(e, n, r) {
|
|
1999
|
+
const t = /* @__PURE__ */ new Set(), s = e.select.map(($, k) => {
|
|
2000
|
+
const b = En(K($) ?? `column_${k + 1}`, t);
|
|
1999
2001
|
return t.add(b), { ...$, alias: b };
|
|
2000
2002
|
}), {
|
|
2001
2003
|
from: i,
|
|
@@ -2013,8 +2015,8 @@ function Fs(e, n, r) {
|
|
|
2013
2015
|
...c ? { having: c } : {},
|
|
2014
2016
|
...m !== void 0 ? { distinct: m } : {}
|
|
2015
2017
|
}, f = ($) => ({ type: "field", table: r, column: $ }), p = ($) => {
|
|
2016
|
-
var
|
|
2017
|
-
return (
|
|
2018
|
+
var k;
|
|
2019
|
+
return (k = s.find((b) => Z(b.expression, $))) == null ? void 0 : k.alias;
|
|
2018
2020
|
}, v = {
|
|
2019
2021
|
...e,
|
|
2020
2022
|
from: { id: n, alias: r, query: { union: [d], all: !0 } },
|
|
@@ -2022,54 +2024,54 @@ function Fs(e, n, r) {
|
|
|
2022
2024
|
select: s.map(($) => ({ id: W(), expression: f($.alias) })),
|
|
2023
2025
|
...e.orderBy ? {
|
|
2024
2026
|
orderBy: e.orderBy.map(($) => {
|
|
2025
|
-
const
|
|
2026
|
-
return
|
|
2027
|
+
const k = p($.expression);
|
|
2028
|
+
return k ? { ...$, expression: f(k) } : $;
|
|
2027
2029
|
})
|
|
2028
2030
|
} : {}
|
|
2029
2031
|
};
|
|
2030
2032
|
return ["where", "groupBy", "having", "distinct"].forEach(($) => delete v[$]), v;
|
|
2031
2033
|
}
|
|
2032
|
-
function
|
|
2033
|
-
const s =
|
|
2034
|
+
function Vs(e, n, r, t) {
|
|
2035
|
+
const s = Ie(n, r);
|
|
2034
2036
|
if (!s) return n;
|
|
2035
|
-
const i =
|
|
2037
|
+
const i = Ke(e, s.query.union).map((a) => ({
|
|
2036
2038
|
id: W(),
|
|
2037
2039
|
...a.name ? { alias: a.name } : {},
|
|
2038
|
-
expression:
|
|
2040
|
+
expression: se(a.type)
|
|
2039
2041
|
}));
|
|
2040
|
-
return
|
|
2042
|
+
return Me(n, s, {
|
|
2041
2043
|
...s.query,
|
|
2042
2044
|
union: [...s.query.union, { from: t, joins: [], select: i }]
|
|
2043
2045
|
});
|
|
2044
2046
|
}
|
|
2045
|
-
function
|
|
2047
|
+
function Ws(e, n, r, t) {
|
|
2046
2048
|
const s = {
|
|
2047
2049
|
id: r,
|
|
2048
|
-
alias:
|
|
2050
|
+
alias: Dr(e, n),
|
|
2049
2051
|
joinType: "left",
|
|
2050
2052
|
query: { union: [{ from: t, joins: [], select: [] }], all: !0 }
|
|
2051
2053
|
};
|
|
2052
|
-
return { ...n, joins: [...n.joins, { ...s, on:
|
|
2054
|
+
return { ...n, joins: [...n.joins, { ...s, on: dt(e, n, s) }] };
|
|
2053
2055
|
}
|
|
2054
|
-
function
|
|
2055
|
-
const t =
|
|
2056
|
-
return !t || t.query.all === r ? e :
|
|
2056
|
+
function Hs(e, n, r) {
|
|
2057
|
+
const t = Ie(e, n);
|
|
2058
|
+
return !t || t.query.all === r ? e : Me(e, t, { ...t.query, all: r });
|
|
2057
2059
|
}
|
|
2058
|
-
function
|
|
2059
|
-
const i =
|
|
2060
|
+
function Xs(e, n, r, t, s) {
|
|
2061
|
+
const i = Ie(n, r), [a, ...o] = (i == null ? void 0 : i.query.union) ?? [], l = a == null ? void 0 : a.select[t], c = s.trim();
|
|
2060
2062
|
if (!i || !l || !c || c.length > Y || a.select.some((d) => K(d) === c)) return n;
|
|
2061
|
-
const m =
|
|
2063
|
+
const m = Me(n, i, {
|
|
2062
2064
|
...i.query,
|
|
2063
2065
|
union: [
|
|
2064
2066
|
{ ...a, select: a.select.map((d, f) => f === t ? { ...d, alias: c } : d) },
|
|
2065
2067
|
...o
|
|
2066
2068
|
]
|
|
2067
2069
|
});
|
|
2068
|
-
return
|
|
2070
|
+
return Tn(e, n, m);
|
|
2069
2071
|
}
|
|
2070
|
-
function
|
|
2072
|
+
function Ks(e, n) {
|
|
2071
2073
|
var m;
|
|
2072
|
-
const r =
|
|
2074
|
+
const r = Ie(e, n);
|
|
2073
2075
|
if (!r || r.query.union.length !== 1) return e;
|
|
2074
2076
|
const [t] = r.query.union, s = new Map(t.select.flatMap((d) => {
|
|
2075
2077
|
const f = K(d);
|
|
@@ -2079,14 +2081,14 @@ function Hs(e, n) {
|
|
|
2079
2081
|
if (d.alias || !i(d.expression)) return { ...d, expression: f };
|
|
2080
2082
|
const p = d.expression.column;
|
|
2081
2083
|
return K({ ...d, expression: f }) === p ? { ...d, expression: f } : { ...d, expression: f, alias: p };
|
|
2082
|
-
}), l = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((d) =>
|
|
2084
|
+
}), l = t.groupBy !== void 0 || t.having !== void 0 || !!t.distinct || t.select.some((d) => le(d.expression, $e));
|
|
2083
2085
|
if (r === e.from && !l) {
|
|
2084
|
-
const d =
|
|
2086
|
+
const d = Pe({ ...e, select: o }, a, (f) => f);
|
|
2085
2087
|
return {
|
|
2086
2088
|
...d,
|
|
2087
2089
|
from: t.from,
|
|
2088
2090
|
joins: [...t.joins, ...d.joins],
|
|
2089
|
-
where:
|
|
2091
|
+
where: Bt([...Je(t.where), ...Je(d.where)]),
|
|
2090
2092
|
// Nothing picked: the query's own columns, as the union had them.
|
|
2091
2093
|
select: d.select.length > 0 ? d.select : t.select
|
|
2092
2094
|
};
|
|
@@ -2099,9 +2101,9 @@ function Hs(e, n) {
|
|
|
2099
2101
|
...e.orderBy ? {
|
|
2100
2102
|
orderBy: e.orderBy.map((d) => ({ ...d, expression: a(d.expression) }))
|
|
2101
2103
|
} : {}
|
|
2102
|
-
} :
|
|
2104
|
+
} : Me(e, r, t);
|
|
2103
2105
|
}
|
|
2104
|
-
const
|
|
2106
|
+
const Hn = (e, n) => e.type === "binary" && e.operator === "IS NULL" && Z(e.left, n);
|
|
2105
2107
|
function ln(e) {
|
|
2106
2108
|
var n;
|
|
2107
2109
|
if (!e) return [];
|
|
@@ -2110,20 +2112,20 @@ function ln(e) {
|
|
|
2110
2112
|
return [[e.left, e.right]];
|
|
2111
2113
|
if (e.type === "logical" && e.operator === "OR" && e.operands.length === 2) {
|
|
2112
2114
|
const [[r] = [], t] = [ln(e.operands[0]), e.operands[1]];
|
|
2113
|
-
if (r && t.type === "logical" && t.operator === "AND" && t.operands.length === 2 &&
|
|
2115
|
+
if (r && t.type === "logical" && t.operator === "AND" && t.operands.length === 2 && Hn(t.operands[0], r[0]) && Hn(t.operands[1], r[1]))
|
|
2114
2116
|
return [r];
|
|
2115
2117
|
}
|
|
2116
2118
|
return [];
|
|
2117
2119
|
}
|
|
2118
|
-
function
|
|
2120
|
+
function Gr(e, n) {
|
|
2119
2121
|
const r = e.groupBy ?? [];
|
|
2120
2122
|
return r.length > 0 && r.every((t) => e.select.some((s) => Z(s.expression, t.expression) && n.includes(K(s) ?? "")));
|
|
2121
2123
|
}
|
|
2122
|
-
function
|
|
2124
|
+
function Rr(e, n) {
|
|
2123
2125
|
const r = D(e.from), t = /* @__PURE__ */ new Map([[r, e.from.table]]), s = [r], i = e.shared ?? [];
|
|
2124
2126
|
return e.joins.map((a) => {
|
|
2125
2127
|
var f, p;
|
|
2126
|
-
const { id: o } = a, l =
|
|
2128
|
+
const { id: o } = a, l = Te(a, i), c = D(a);
|
|
2127
2129
|
t.set(c, a.table);
|
|
2128
2130
|
const m = ln(a.on).flatMap(([v, $]) => [[v, $], [$, v]]).filter(([v, $]) => v.table === c && s.includes($.table ?? ""));
|
|
2129
2131
|
if (s.push(c), a.joinType === "cross")
|
|
@@ -2131,10 +2133,10 @@ function Gr(e, n) {
|
|
|
2131
2133
|
joinId: o,
|
|
2132
2134
|
key: c,
|
|
2133
2135
|
parent: r,
|
|
2134
|
-
side: l &&
|
|
2136
|
+
side: l && lt(l) ? "one" : "cross"
|
|
2135
2137
|
};
|
|
2136
2138
|
if (a.table === void 0) {
|
|
2137
|
-
const v = m.length > 0 && l !== void 0 && !H(l) &&
|
|
2139
|
+
const v = m.length > 0 && l !== void 0 && !H(l) && Gr(l, m.map(([$]) => $.column));
|
|
2138
2140
|
return {
|
|
2139
2141
|
joinId: o,
|
|
2140
2142
|
key: c,
|
|
@@ -2143,15 +2145,15 @@ function Gr(e, n) {
|
|
|
2143
2145
|
};
|
|
2144
2146
|
}
|
|
2145
2147
|
return m.map(([v, $]) => {
|
|
2146
|
-
const
|
|
2147
|
-
if (b([a.table, v], [
|
|
2148
|
+
const k = t.get($.table), b = (I, G) => n.relations.some((R) => R.fromTable === I[0] && R.fromColumn === I[1].column && R.toTable === G[0] && R.toColumn === G[1].column);
|
|
2149
|
+
if (b([a.table, v], [k, $]))
|
|
2148
2150
|
return {
|
|
2149
2151
|
joinId: o,
|
|
2150
2152
|
key: c,
|
|
2151
2153
|
parent: $.table,
|
|
2152
2154
|
side: "many"
|
|
2153
2155
|
};
|
|
2154
|
-
if (b([
|
|
2156
|
+
if (b([k, $], [a.table, v]))
|
|
2155
2157
|
return {
|
|
2156
2158
|
joinId: o,
|
|
2157
2159
|
key: c,
|
|
@@ -2167,7 +2169,7 @@ function Gr(e, n) {
|
|
|
2167
2169
|
});
|
|
2168
2170
|
}
|
|
2169
2171
|
function un(e, n, r = {}) {
|
|
2170
|
-
const t =
|
|
2172
|
+
const t = Rr(e, n).map((o) => o.side === "unknown" && r.unknown === "repeat" ? { ...o, side: "many" } : o), s = [D(e.from), ...t.map((o) => o.key)], i = (o) => {
|
|
2171
2173
|
const l = /* @__PURE__ */ new Set([o]);
|
|
2172
2174
|
return t.forEach((c) => {
|
|
2173
2175
|
l.has(c.parent) && l.add(c.key);
|
|
@@ -2178,21 +2180,21 @@ function un(e, n, r = {}) {
|
|
|
2178
2180
|
o.side === "many" && s.filter((c) => !l.has(c)).forEach((c) => a.add(c)), o.side === "one" && l.forEach((c) => a.add(c)), o.side === "cross" && s.forEach((c) => a.add(c));
|
|
2179
2181
|
}), a;
|
|
2180
2182
|
}
|
|
2181
|
-
const
|
|
2182
|
-
function
|
|
2183
|
-
return e.type === "field" ? e.table && n.has(e.table) ? [e.table] : [] : [...new Set(
|
|
2183
|
+
const qr = /* @__PURE__ */ new Set(["SUM", "AVG", "COUNT"]);
|
|
2184
|
+
function Qr(e, n) {
|
|
2185
|
+
return e.type === "field" ? e.table && n.has(e.table) ? [e.table] : [] : [...new Set(fe(e).flatMap((r) => Qr(r, n)))];
|
|
2184
2186
|
}
|
|
2185
|
-
function
|
|
2187
|
+
function Ys(e, n) {
|
|
2186
2188
|
const r = D(e.from);
|
|
2187
2189
|
return e.joins.some((s) => s.joinType === "right" || s.joinType === "full") || un(e, n).has(r) ? "many" : un(e, n, { unknown: "repeat" }).has(r) ? "unknown" : "one";
|
|
2188
2190
|
}
|
|
2189
|
-
function
|
|
2190
|
-
const t = e.type === "function" &&
|
|
2191
|
-
return e.type === "field" ? s && e.table && n.has(e.table) ? [e.table] : [] :
|
|
2191
|
+
function Lt(e, n, r = !1) {
|
|
2192
|
+
const t = e.type === "function" && qr.has(e.name.toUpperCase()) && !e.distinct, s = r || t;
|
|
2193
|
+
return e.type === "field" ? s && e.table && n.has(e.table) ? [e.table] : [] : fe(e).flatMap((i) => Lt(i, n, s));
|
|
2192
2194
|
}
|
|
2193
|
-
function
|
|
2195
|
+
function _r(e, n) {
|
|
2194
2196
|
const r = un(e, n), t = /* @__PURE__ */ new Set(), s = (l) => {
|
|
2195
|
-
const c = l ?
|
|
2197
|
+
const c = l ? Lt(l, r) : [];
|
|
2196
2198
|
return c.forEach((m) => t.add(m)), c.length > 0;
|
|
2197
2199
|
}, i = e.select.filter((l) => s(l.expression)).map((l) => l.id), a = (e.orderBy ?? []).filter((l) => s(l.expression)).map((l) => l.id), o = s(e.having);
|
|
2198
2200
|
return {
|
|
@@ -2202,25 +2204,25 @@ function Qr(e, n) {
|
|
|
2202
2204
|
having: o
|
|
2203
2205
|
};
|
|
2204
2206
|
}
|
|
2205
|
-
function
|
|
2206
|
-
return e.select.filter((r) =>
|
|
2207
|
+
function Fr(e, n) {
|
|
2208
|
+
return e.select.filter((r) => le(r.expression, n));
|
|
2207
2209
|
}
|
|
2208
|
-
function
|
|
2210
|
+
function Jr(e) {
|
|
2209
2211
|
return { ...e.expression, fromSelect: e.id };
|
|
2210
2212
|
}
|
|
2211
|
-
function
|
|
2213
|
+
function Ee(e) {
|
|
2212
2214
|
const { fromSelect: n, ...r } = e;
|
|
2213
2215
|
return n === void 0 ? e : r;
|
|
2214
2216
|
}
|
|
2215
|
-
function
|
|
2216
|
-
const r = (s) => typeof s.fromSelect == "string" ? n(s, s.fromSelect) :
|
|
2217
|
+
function Dt(e, n) {
|
|
2218
|
+
const r = (s) => typeof s.fromSelect == "string" ? n(s, s.fromSelect) : xe(s, r), t = r(e);
|
|
2217
2219
|
return Z(t, e) ? e : t;
|
|
2218
2220
|
}
|
|
2219
|
-
function
|
|
2221
|
+
function Pr(e, n) {
|
|
2220
2222
|
var o;
|
|
2221
|
-
const r = new Map(
|
|
2223
|
+
const r = new Map(Fr(e, n).map((l) => [l.id, l])), t = (l) => Dt(l, (c, m) => {
|
|
2222
2224
|
const d = r.get(m);
|
|
2223
|
-
return d ?
|
|
2225
|
+
return d ? Jr(d) : Ee(c);
|
|
2224
2226
|
}), s = e.having && t(e.having);
|
|
2225
2227
|
let i = !1;
|
|
2226
2228
|
const a = (o = e.orderBy) == null ? void 0 : o.map((l) => {
|
|
@@ -2229,35 +2231,35 @@ function Jr(e, n) {
|
|
|
2229
2231
|
});
|
|
2230
2232
|
return s === e.having && !i ? e : { ...e, having: s, ...a ? { orderBy: a } : {} };
|
|
2231
2233
|
}
|
|
2232
|
-
function
|
|
2234
|
+
function zs(e, n) {
|
|
2233
2235
|
const r = new Set((n.groupBy ?? []).flatMap(({ expression: t }) => t.type === "field" && t.column ? [t.column.toLowerCase()] : []));
|
|
2234
|
-
return
|
|
2236
|
+
return Dt(e, (t, s) => {
|
|
2235
2237
|
const i = n.select.find((a) => a.id === s);
|
|
2236
|
-
return !(i != null && i.alias) || r.has(i.alias.toLowerCase()) || !Z(
|
|
2238
|
+
return !(i != null && i.alias) || r.has(i.alias.toLowerCase()) || !Z(Ee(t), i.expression) ? Ee(t) : { type: "field", column: i.alias };
|
|
2237
2239
|
});
|
|
2238
2240
|
}
|
|
2239
2241
|
function cn(e, n) {
|
|
2240
|
-
const r = (m) => cn(m, n), t = (m) =>
|
|
2242
|
+
const r = (m) => cn(m, n), t = (m) => We(m, r), s = e.from.query && t(e.from.query), i = s && s !== e.from.query ? { ...e.from, query: s } : e.from;
|
|
2241
2243
|
let a = !1;
|
|
2242
2244
|
const o = e.joins.map((m) => {
|
|
2243
2245
|
if (!m.query) return m;
|
|
2244
2246
|
const d = t(m.query);
|
|
2245
2247
|
return d === m.query ? m : (a = !0, { ...m, query: d });
|
|
2246
|
-
}), l = i === e.from && !a ? e : { ...e, from: i, joins: o }, c =
|
|
2248
|
+
}), l = i === e.from && !a ? e : { ...e, from: i, joins: o }, c = st(l, (m) => {
|
|
2247
2249
|
const d = r(m.query);
|
|
2248
2250
|
return d === m.query ? m : { ...m, query: d };
|
|
2249
2251
|
});
|
|
2250
|
-
return
|
|
2252
|
+
return Wt(Pr(c, n), n);
|
|
2251
2253
|
}
|
|
2252
|
-
function
|
|
2253
|
-
if (!
|
|
2254
|
+
function Zs(e, n, r, t = $e) {
|
|
2255
|
+
if (!ue(r)) return r;
|
|
2254
2256
|
const s = dn(
|
|
2255
2257
|
cn(r, t),
|
|
2256
|
-
(a) =>
|
|
2257
|
-
), i =
|
|
2258
|
-
return
|
|
2258
|
+
(a) => We(a, (o) => cn(o, t))
|
|
2259
|
+
), i = jr(e, n, s);
|
|
2260
|
+
return Ar(e, n, i);
|
|
2259
2261
|
}
|
|
2260
|
-
const
|
|
2262
|
+
const Vr = [
|
|
2261
2263
|
"=",
|
|
2262
2264
|
"!=",
|
|
2263
2265
|
"<",
|
|
@@ -2270,22 +2272,22 @@ const Pr = [
|
|
|
2270
2272
|
"REGEXP",
|
|
2271
2273
|
"IS NULL",
|
|
2272
2274
|
"IS NOT NULL"
|
|
2273
|
-
],
|
|
2274
|
-
function Wr(e) {
|
|
2275
|
-
return Vr.includes(e);
|
|
2276
|
-
}
|
|
2275
|
+
], Wr = ["IS NULL", "IS NOT NULL"];
|
|
2277
2276
|
function Hr(e) {
|
|
2278
|
-
return
|
|
2277
|
+
return Wr.includes(e);
|
|
2279
2278
|
}
|
|
2280
|
-
function
|
|
2281
|
-
n
|
|
2279
|
+
function Xr(e) {
|
|
2280
|
+
return !e.distinct || !e.orderBy ? [] : e.orderBy.filter(({ expression: n }) => !(n.type === "field" && !n.column)).filter(({ expression: n }) => e.select.length === 0 ? n.type !== "field" : !e.select.some((r) => Z(r.expression, Ee(n)))).map(({ id: n }) => n);
|
|
2281
|
+
}
|
|
2282
|
+
function Gt(e, n) {
|
|
2283
|
+
n(e), fe(e).forEach((r) => Gt(r, n));
|
|
2282
2284
|
}
|
|
2283
|
-
const
|
|
2285
|
+
const Rt = (e) => {
|
|
2284
2286
|
const n = /* @__PURE__ */ new Map();
|
|
2285
|
-
return
|
|
2287
|
+
return et(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;
|
|
2286
2288
|
};
|
|
2287
|
-
function
|
|
2288
|
-
const r = /* @__PURE__ */ new Map(), t = (i, a) =>
|
|
2289
|
+
function qt(e, n) {
|
|
2290
|
+
const r = /* @__PURE__ */ new Map(), t = (i, a) => Gt(i, (o) => {
|
|
2289
2291
|
if (o.type === "param" && !r.has(o.name) && r.set(o.name, /* @__PURE__ */ new Set()), o.type !== "binary" || !o.right) return;
|
|
2290
2292
|
const l = (m, d) => {
|
|
2291
2293
|
const f = a(d);
|
|
@@ -2301,13 +2303,13 @@ function Rt(e, n) {
|
|
|
2301
2303
|
const c = a.has(l.table) ? a.get(l.table) : l.table, m = c === void 0 ? void 0 : z(n, c);
|
|
2302
2304
|
return (d = m == null ? void 0 : m.columns.find((f) => f.name === l.column)) == null ? void 0 : d.type;
|
|
2303
2305
|
};
|
|
2304
|
-
|
|
2306
|
+
Xn(i).forEach((l) => t(l, o)), Q(i).forEach((l) => l.query && be(l.query).forEach(s)), rt(i).forEach((l) => s(l.query));
|
|
2305
2307
|
};
|
|
2306
|
-
return (e.shared ?? []).forEach((i) =>
|
|
2308
|
+
return (e.shared ?? []).forEach((i) => be(i.query).forEach(s)), s(e), r;
|
|
2307
2309
|
}
|
|
2308
|
-
function
|
|
2309
|
-
const r =
|
|
2310
|
-
return [...
|
|
2310
|
+
function ei(e, n) {
|
|
2311
|
+
const r = Rt(e);
|
|
2312
|
+
return [...qt(e, n)].map(([t, s]) => {
|
|
2311
2313
|
const i = r.get(t);
|
|
2312
2314
|
return {
|
|
2313
2315
|
name: t,
|
|
@@ -2317,33 +2319,33 @@ function zs(e, n) {
|
|
|
2317
2319
|
};
|
|
2318
2320
|
});
|
|
2319
2321
|
}
|
|
2320
|
-
function
|
|
2321
|
-
return [...
|
|
2322
|
+
function Kr(e) {
|
|
2323
|
+
return [...Rt(e)].filter(([, n]) => n.size > 1).map(([n]) => n);
|
|
2322
2324
|
}
|
|
2323
|
-
function
|
|
2324
|
-
return [...
|
|
2325
|
+
function Yr(e, n) {
|
|
2326
|
+
return [...qt(e, n)].filter(([, r]) => r.size > 1).map(([r]) => r);
|
|
2325
2327
|
}
|
|
2326
|
-
function
|
|
2328
|
+
function ni(e, n) {
|
|
2327
2329
|
const r = new Map(Object.entries(n));
|
|
2328
|
-
return
|
|
2330
|
+
return et(e, (t) => {
|
|
2329
2331
|
if (t.type !== "param") return t;
|
|
2330
2332
|
if (!r.has(t.name)) throw new Error(`no value for parameter "${t.name}"`);
|
|
2331
2333
|
const s = r.get(t.name);
|
|
2332
2334
|
return s === "" ? { type: "literal", value: s, empty: !0 } : { type: "literal", value: s };
|
|
2333
2335
|
});
|
|
2334
2336
|
}
|
|
2335
|
-
function
|
|
2337
|
+
function zr(e, n, r, t) {
|
|
2336
2338
|
const s = new Map(t);
|
|
2337
2339
|
return Q(n).forEach((i) => {
|
|
2338
2340
|
var o;
|
|
2339
2341
|
const a = i.table !== void 0 ? (o = z(e, i.table)) == null ? void 0 : o.columns : (() => {
|
|
2340
|
-
const l =
|
|
2342
|
+
const l = Te(i, r);
|
|
2341
2343
|
return l && Ne(e, l, r);
|
|
2342
2344
|
})();
|
|
2343
2345
|
s.set(D(i), new Set((a ?? []).filter((l) => l.joinOnly).map((l) => l.name)));
|
|
2344
2346
|
}), s;
|
|
2345
2347
|
}
|
|
2346
|
-
function
|
|
2348
|
+
function Zr(e, n) {
|
|
2347
2349
|
const r = [], t = n.shared ?? [], s = (o, l, c, m) => {
|
|
2348
2350
|
var f;
|
|
2349
2351
|
if (Array.isArray(o)) {
|
|
@@ -2368,27 +2370,27 @@ function zr(e, n) {
|
|
|
2368
2370
|
}
|
|
2369
2371
|
Object.entries(d).forEach(([p, v]) => s(v, [...l, p], c, m));
|
|
2370
2372
|
}, i = (o, l) => {
|
|
2371
|
-
"union" in o ?
|
|
2373
|
+
"union" in o ? be(o).forEach((c, m) => a(c, [...l, "union", m], !0)) : a(o, l, !0);
|
|
2372
2374
|
};
|
|
2373
2375
|
function a(o, l, c, m) {
|
|
2374
2376
|
var p, v, $;
|
|
2375
|
-
const d =
|
|
2376
|
-
o.from.query && i(o.from.query, [...l, "from", "query"]), o.joins.forEach((
|
|
2377
|
-
|
|
2377
|
+
const d = zr(e, o, t, m);
|
|
2378
|
+
o.from.query && i(o.from.query, [...l, "from", "query"]), o.joins.forEach((k, b) => {
|
|
2379
|
+
k.query && i(k.query, [...l, "joins", b, "query"]), k.on && s(k.on, [...l, "joins", b, "on"], d, !0);
|
|
2378
2380
|
}), o.where && s(o.where, [...l, "where"], d, !1);
|
|
2379
2381
|
const f = o;
|
|
2380
|
-
(p = f.select) == null || p.forEach((
|
|
2381
|
-
|
|
2382
|
+
(p = f.select) == null || p.forEach((k, b) => s(
|
|
2383
|
+
k.expression,
|
|
2382
2384
|
[...l, "select", b, "expression"],
|
|
2383
2385
|
d,
|
|
2384
2386
|
c
|
|
2385
|
-
)), (v = f.groupBy) == null || v.forEach((
|
|
2386
|
-
|
|
2387
|
+
)), (v = f.groupBy) == null || v.forEach((k, b) => s(
|
|
2388
|
+
k.expression,
|
|
2387
2389
|
[...l, "groupBy", b, "expression"],
|
|
2388
2390
|
d,
|
|
2389
2391
|
c
|
|
2390
|
-
)), f.having && s(f.having, [...l, "having"], d, !1), ($ = f.orderBy) == null || $.forEach((
|
|
2391
|
-
|
|
2392
|
+
)), f.having && s(f.having, [...l, "having"], d, !1), ($ = f.orderBy) == null || $.forEach((k, b) => s(
|
|
2393
|
+
k.expression,
|
|
2392
2394
|
[...l, "orderBy", b, "expression"],
|
|
2393
2395
|
d,
|
|
2394
2396
|
!1
|
|
@@ -2396,7 +2398,13 @@ function zr(e, n) {
|
|
|
2396
2398
|
}
|
|
2397
2399
|
return t.forEach((o, l) => i(o.query, ["shared", l, "query"])), a(n, [], !1), r;
|
|
2398
2400
|
}
|
|
2399
|
-
|
|
2401
|
+
function ti(e, n) {
|
|
2402
|
+
return !(e === "mssql" && n === "REGEXP");
|
|
2403
|
+
}
|
|
2404
|
+
function es(e, n) {
|
|
2405
|
+
return !(e === "mysql" && n === "full");
|
|
2406
|
+
}
|
|
2407
|
+
const ri = [
|
|
2400
2408
|
"invalidStructure",
|
|
2401
2409
|
"duplicateId",
|
|
2402
2410
|
"unknownTable",
|
|
@@ -2433,7 +2441,7 @@ const ei = [
|
|
|
2433
2441
|
"sharedOrder",
|
|
2434
2442
|
"unusedShared",
|
|
2435
2443
|
"joinOnlyColumn"
|
|
2436
|
-
],
|
|
2444
|
+
], si = [
|
|
2437
2445
|
"fanOut",
|
|
2438
2446
|
"crossJoin",
|
|
2439
2447
|
"unlinkedJoin",
|
|
@@ -2445,10 +2453,10 @@ const ei = [
|
|
|
2445
2453
|
"unknownAggregate",
|
|
2446
2454
|
"unusedShared"
|
|
2447
2455
|
];
|
|
2448
|
-
function
|
|
2456
|
+
function ns(e) {
|
|
2449
2457
|
return [...e.matchAll(/([A-Za-z_][A-Za-z0-9_]*)|\[(\d+)\]/g)].map(([, n, r]) => n ?? Number(r));
|
|
2450
2458
|
}
|
|
2451
|
-
const
|
|
2459
|
+
const De = (e) => e === "integer" ? "number" : e === "dateTime" ? "date" : e, de = {
|
|
2452
2460
|
text: "text",
|
|
2453
2461
|
integer: "a whole number",
|
|
2454
2462
|
number: "a number",
|
|
@@ -2456,139 +2464,141 @@ const Le = (e) => e === "integer" ? "number" : e === "dateTime" ? "date" : e, fe
|
|
|
2456
2464
|
dateTime: "a date and time",
|
|
2457
2465
|
time: "a time of day",
|
|
2458
2466
|
boolean: "yes / no"
|
|
2459
|
-
}, O = (e) => typeof e == "object" && e !== null && !Array.isArray(e), q = (e) => typeof e == "string",
|
|
2460
|
-
function
|
|
2467
|
+
}, O = (e) => typeof e == "object" && e !== null && !Array.isArray(e), q = (e) => typeof e == "string", ts = ["day", "week", "month", "year"], rs = (e) => O(e) && ts.includes(e.unit) && Number.isSafeInteger(e.offset) && (e.anchor === void 0 || e.unit !== "day" && (e.anchor === "start" || e.anchor === "end")), ge = (e) => e === void 0 || q(e), ss = (e) => e === null || q(e) || typeof e == "boolean" || typeof e == "bigint" || typeof e == "number" && Number.isFinite(e) || e instanceof Date && !Number.isNaN(e.getTime()), en = (e) => O(e) && e.type === "literal" && e.value === "" && e.empty !== !0;
|
|
2468
|
+
function ii(e, n, r = {}) {
|
|
2461
2469
|
var xn, Bn;
|
|
2462
2470
|
const t = [], s = (u, y, g, h = "error") => {
|
|
2463
2471
|
t.push({
|
|
2464
2472
|
kind: u,
|
|
2465
2473
|
severity: h,
|
|
2466
2474
|
path: y,
|
|
2467
|
-
pathSegments:
|
|
2475
|
+
pathSegments: ns(y),
|
|
2468
2476
|
message: g
|
|
2469
2477
|
});
|
|
2470
2478
|
};
|
|
2471
2479
|
if (!O(n) || !q(n.id) || n.id === "")
|
|
2472
2480
|
return s("invalidStructure", "", "a query is an object with a non-empty string id"), t;
|
|
2473
2481
|
if (!("from" in n)) return t;
|
|
2474
|
-
const i =
|
|
2482
|
+
const i = Ht(e, r.tableFilter, r.columnFilter), a = Xt(r.functions ?? $e);
|
|
2475
2483
|
let o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c;
|
|
2476
2484
|
const m = (u, y, g, h) => {
|
|
2477
2485
|
q(u) && u.length > y && s("tooLong", g, `${h} is longer than ${y} characters`);
|
|
2478
2486
|
}, d = /* @__PURE__ */ new Set(), f = O(n) && Array.isArray(n.shared) ? n.shared : [], p = new Set(f.flatMap((u) => O(u) && q(u.id) ? [u.id] : [])), v = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Set();
|
|
2479
|
-
let
|
|
2487
|
+
let k;
|
|
2480
2488
|
const b = (u, y) => {
|
|
2481
2489
|
o.has(u) && s("duplicateTableName", y, `two tables named "${u}"`);
|
|
2482
|
-
}, I = (u, y
|
|
2490
|
+
}, I = (u, y) => {
|
|
2491
|
+
On.includes(u) && !es(r.dialect, u) && s("dialectUnsupported", y, `${u.toUpperCase()} JOIN isn't in this database`);
|
|
2492
|
+
}, G = (u, y, g = !1) => {
|
|
2483
2493
|
if (g && O(u) && u.query !== void 0) {
|
|
2484
|
-
|
|
2494
|
+
k(u, y);
|
|
2485
2495
|
return;
|
|
2486
2496
|
}
|
|
2487
2497
|
if (g && O(u) && u.shared !== void 0) {
|
|
2488
|
-
const { shared:
|
|
2489
|
-
if (!q(
|
|
2498
|
+
const { shared: N, alias: w } = u, S = q(w) && w !== "";
|
|
2499
|
+
if (!q(N) || !S || u.table !== void 0) {
|
|
2490
2500
|
s("invalidStructure", y, "a shared query's place has a string `shared` and an `alias`, and no `table`"), S && (b(w, `${y}.alias`), o.set(w, void 0));
|
|
2491
2501
|
return;
|
|
2492
2502
|
}
|
|
2493
|
-
m(w, Y, `${y}.alias`, "an alias"), b(w, `${y}.alias`), $.add(
|
|
2503
|
+
m(w, Y, `${y}.alias`, "an alias"), b(w, `${y}.alias`), $.add(N), p.has(N) ? v.has(N) || s("sharedOrder", `${y}.shared`, "a shared query can use only those before it") : s("unknownTable", `${y}.shared`, `no shared query "${N}"`), o.set(w, v.get(N));
|
|
2494
2504
|
return;
|
|
2495
2505
|
}
|
|
2496
|
-
if (!O(u) || !q(u.table) || !
|
|
2506
|
+
if (!O(u) || !q(u.table) || !ge(u.alias)) {
|
|
2497
2507
|
s("invalidStructure", y, "a table entry has a string `table` and optional `alias`");
|
|
2498
2508
|
return;
|
|
2499
2509
|
}
|
|
2500
2510
|
m(u.alias, Y, `${y}.alias`, "an alias");
|
|
2501
|
-
const h = i.tables.find((
|
|
2511
|
+
const h = i.tables.find((N) => N.name === u.table);
|
|
2502
2512
|
h || s("unknownTable", `${y}.table`, `unknown table "${u.table}"`), q(u.alias) && u.alias !== "" ? (b(u.alias, `${y}.alias`), o.set(u.alias, h), l.set(u.table, u.alias)) : (b(u.table, `${y}.table`), o.set(u.table, h));
|
|
2503
|
-
},
|
|
2504
|
-
var
|
|
2513
|
+
}, R = (u, y, g) => {
|
|
2514
|
+
var T;
|
|
2505
2515
|
if (!u) return;
|
|
2506
|
-
const { args: h, name:
|
|
2507
|
-
y < w ? s("incomplete", g, `${
|
|
2516
|
+
const { args: h, name: N } = u, w = h.filter((A) => !A.optional).length, S = (T = h[h.length - 1]) != null && T.variadic ? 1 / 0 : h.length;
|
|
2517
|
+
y < w ? s("incomplete", g, `${N} needs ${w} argument(s)`) : y > S && s("argCount", g, `${N} takes ${S} argument(s)`);
|
|
2508
2518
|
};
|
|
2509
|
-
let
|
|
2510
|
-
const
|
|
2519
|
+
let X, ee, ye;
|
|
2520
|
+
const he = (u) => {
|
|
2511
2521
|
const y = u.table && (o.get(u.table) ?? (c == null ? void 0 : c.get(u.table)));
|
|
2512
2522
|
if (!y || Array.isArray(y)) return;
|
|
2513
2523
|
const g = y.columns.find((h) => h.name === u.column);
|
|
2514
2524
|
return g && Nt(g.type);
|
|
2515
|
-
}, te = (u) => $n(u,
|
|
2525
|
+
}, te = (u) => $n(u, he, a), x = r.typeMismatch ?? "warning", F = (u, y, g) => {
|
|
2516
2526
|
if (u.type === "literal") {
|
|
2517
2527
|
if (u.value === null || u.value === "" && !u.empty || typeof u.value == "number" && !nn(u.value) || vn(u.value, y) !== void 0) return;
|
|
2518
2528
|
const w = u.value instanceof Date ? "a date" : JSON.stringify(String(u.value));
|
|
2519
|
-
s("typeMismatch", g, `${w} isn't ${
|
|
2529
|
+
s("typeMismatch", g, `${w} isn't ${de[y]}`, x);
|
|
2520
2530
|
return;
|
|
2521
2531
|
}
|
|
2522
2532
|
const h = te(u);
|
|
2523
|
-
if (h === void 0 ||
|
|
2524
|
-
const
|
|
2525
|
-
s("typeMismatch", g,
|
|
2526
|
-
},
|
|
2527
|
-
const { operator: g, left: h, right:
|
|
2528
|
-
if (!
|
|
2529
|
-
const w = (
|
|
2530
|
-
if (
|
|
2531
|
-
const E =
|
|
2533
|
+
if (h === void 0 || De(h) === De(y)) return;
|
|
2534
|
+
const N = `${de[h]} compared with ${de[y]}`;
|
|
2535
|
+
s("typeMismatch", g, N, x);
|
|
2536
|
+
}, pe = (u) => u && u.type !== "literal" ? te(u) : void 0, Qt = (u, y) => {
|
|
2537
|
+
const { operator: g, left: h, right: N } = u;
|
|
2538
|
+
if (!N) return;
|
|
2539
|
+
const w = (T, A, M) => {
|
|
2540
|
+
if (T.type !== "param" || !T.relative) return;
|
|
2541
|
+
const E = pe(A);
|
|
2532
2542
|
if (E === void 0 || E === "date" || E === "dateTime") return;
|
|
2533
|
-
const C = `a relative date compared with ${
|
|
2534
|
-
s("typeMismatch", M, C,
|
|
2543
|
+
const C = `a relative date compared with ${de[E]}`;
|
|
2544
|
+
s("typeMismatch", M, C, x);
|
|
2535
2545
|
};
|
|
2536
|
-
if (w(
|
|
2537
|
-
const
|
|
2538
|
-
if (
|
|
2539
|
-
const
|
|
2540
|
-
s("typeMismatch", `${y}.left`,
|
|
2546
|
+
if (w(N, h, `${y}.right`), w(h, N, `${y}.left`), g === "LIKE" || g === "REGEXP") {
|
|
2547
|
+
const T = pe(h);
|
|
2548
|
+
if (T !== void 0 && T !== "text") {
|
|
2549
|
+
const A = `${g} matches text, not ${de[T]}`;
|
|
2550
|
+
s("typeMismatch", `${y}.left`, A, x);
|
|
2541
2551
|
}
|
|
2542
|
-
if (
|
|
2552
|
+
if (F(N, "text", `${y}.right`), g === "REGEXP" && N.type === "literal" && q(N.value))
|
|
2543
2553
|
try {
|
|
2544
|
-
new RegExp(
|
|
2545
|
-
} catch (
|
|
2546
|
-
const M = `not a regular expression: ${
|
|
2554
|
+
new RegExp(N.value);
|
|
2555
|
+
} catch (A) {
|
|
2556
|
+
const M = `not a regular expression: ${A.message}`;
|
|
2547
2557
|
s("invalidPattern", `${y}.right`, M);
|
|
2548
2558
|
}
|
|
2549
2559
|
return;
|
|
2550
2560
|
}
|
|
2551
|
-
const S =
|
|
2561
|
+
const S = pe(h);
|
|
2552
2562
|
if (g === "IN" || g === "BETWEEN") {
|
|
2553
|
-
if (S === void 0 ||
|
|
2554
|
-
|
|
2563
|
+
if (S === void 0 || N.type !== "list") return;
|
|
2564
|
+
N.items.forEach((T, A) => F(T, S, `${y}.right.items[${A}]`));
|
|
2555
2565
|
return;
|
|
2556
2566
|
}
|
|
2557
|
-
if (S !== void 0)
|
|
2567
|
+
if (S !== void 0) F(N, S, `${y}.right`);
|
|
2558
2568
|
else {
|
|
2559
|
-
const
|
|
2560
|
-
|
|
2569
|
+
const T = pe(N);
|
|
2570
|
+
T !== void 0 && F(h, T, `${y}.left`);
|
|
2561
2571
|
}
|
|
2562
|
-
},
|
|
2563
|
-
const y = u.map(([g]) => g.type === "literal" ?
|
|
2564
|
-
y !== void 0 && u.forEach(([g, h]) =>
|
|
2572
|
+
}, Nn = (u) => {
|
|
2573
|
+
const y = u.map(([g]) => g.type === "literal" ? _e(g) : te(g)).find((g) => g !== void 0);
|
|
2574
|
+
y !== void 0 && u.forEach(([g, h]) => F(g, y, h));
|
|
2565
2575
|
}, V = (u, y, g = !1) => {
|
|
2566
2576
|
if (!O(u) || !q(u.type)) {
|
|
2567
2577
|
s("invalidStructure", y, "an expression is an object with a string `type`");
|
|
2568
2578
|
return;
|
|
2569
2579
|
}
|
|
2570
|
-
const h = (w) => s("invalidStructure", y, w),
|
|
2580
|
+
const h = (w) => s("invalidStructure", y, w), N = (w, S) => {
|
|
2571
2581
|
u[w] !== void 0 && V(u[w], `${y}.${w}`, S);
|
|
2572
2582
|
};
|
|
2573
|
-
switch (g && u.type === "exists" && h("EXISTS is a condition, not a value"),
|
|
2583
|
+
switch (g && u.type === "exists" && h("EXISTS is a condition, not a value"), ge(u.fromSelect) || h("`fromSelect` is a column's id"), u.type) {
|
|
2574
2584
|
case "literal":
|
|
2575
|
-
if (!
|
|
2585
|
+
if (!ss(u.value))
|
|
2576
2586
|
h("a literal value is a string, number, boolean, date or null");
|
|
2577
2587
|
else if (u.empty !== void 0 && typeof u.empty != "boolean")
|
|
2578
2588
|
h("a literal's `empty` is a boolean");
|
|
2579
2589
|
else if (en(u))
|
|
2580
2590
|
s("incomplete", y, "a value not filled in");
|
|
2581
2591
|
else if (typeof u.value == "number" && !nn(u.value)) {
|
|
2582
|
-
const w = `a number with more than ${
|
|
2592
|
+
const w = `a number with more than ${tt} significant digits is written as another number`;
|
|
2583
2593
|
s("tooLong", `${y}.value`, w);
|
|
2584
2594
|
} else
|
|
2585
|
-
m(u.value,
|
|
2595
|
+
m(u.value, Zt, `${y}.value`, "a text value");
|
|
2586
2596
|
break;
|
|
2587
2597
|
case "param":
|
|
2588
|
-
(!q(u.name) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(u.name)) && h("a param has a plain identifier as its `name`"), u.relative !== void 0 && !
|
|
2598
|
+
(!q(u.name) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(u.name)) && h("a param has a plain identifier as its `name`"), u.relative !== void 0 && !rs(u.relative) && h("a relative date has a `unit` (day, week, month or year), a whole `offset`, and an `anchor` (start or end) only for a week, month or year"), m(u.name, Y, `${y}.name`, "a parameter's name");
|
|
2589
2599
|
break;
|
|
2590
2600
|
case "field":
|
|
2591
|
-
if (!
|
|
2601
|
+
if (!ge(u.table) || !ge(u.column))
|
|
2592
2602
|
h("a field has string `table` and `column`");
|
|
2593
2603
|
else if (u.column === void 0 || u.column === "")
|
|
2594
2604
|
s("incomplete", y, "a field with no column picked");
|
|
@@ -2596,9 +2606,9 @@ function ti(e, n, r = {}) {
|
|
|
2596
2606
|
s("unqualifiedField", y, `column "${u.column}" names no table`);
|
|
2597
2607
|
else if (o.has(u.table)) {
|
|
2598
2608
|
const w = o.get(u.table);
|
|
2599
|
-
if (!(Array.isArray(w) ? w.includes(u.column) : !w || w.columns.some((
|
|
2600
|
-
const
|
|
2601
|
-
s("unknownColumn", `${y}.column`, `unknown column "${
|
|
2609
|
+
if (!(Array.isArray(w) ? w.includes(u.column) : !w || w.columns.some((T) => T.name === u.column))) {
|
|
2610
|
+
const T = `${u.table}.${u.column}`;
|
|
2611
|
+
s("unknownColumn", `${y}.column`, `unknown column "${T}"`);
|
|
2602
2612
|
}
|
|
2603
2613
|
} else {
|
|
2604
2614
|
const w = l.get(u.table);
|
|
@@ -2613,14 +2623,14 @@ function ti(e, n, r = {}) {
|
|
|
2613
2623
|
}
|
|
2614
2624
|
!r.allowUnknownFunctions && !a[u.name.toUpperCase()] && s("unknownFunction", `${y}.name`, `function "${u.name}" isn't allowed`);
|
|
2615
2625
|
const w = a[u.name.toUpperCase()];
|
|
2616
|
-
if (r.dialect && (w != null && w.dialects) && !w.dialects.includes(r.dialect) && s("dialectUnsupported", `${y}.name`, `${w.name} isn't in this database`), m(u.name, Y, `${y}.name`, "a function's name"),
|
|
2626
|
+
if (r.dialect && (w != null && w.dialects) && !w.dialects.includes(r.dialect) && s("dialectUnsupported", `${y}.name`, `${w.name} isn't in this database`), m(u.name, Y, `${y}.name`, "a function's name"), R(w, u.args.length, `${y}.args`), u.distinct !== void 0 && typeof u.distinct != "boolean" && h("a function's `distinct` is a boolean"), u.distinct === !0 && r.dialect === "mssql" && u.name.toUpperCase() === "STRING_AGG" && s("dialectUnsupported", y, "SQL Server's STRING_AGG can't join only different values"), u.args.forEach((S, T) => {
|
|
2617
2627
|
var E, C;
|
|
2618
|
-
const
|
|
2619
|
-
V(S, `${y}.args[${
|
|
2620
|
-
const M = !t.slice(
|
|
2621
|
-
w != null && w.aggregate && M &&
|
|
2628
|
+
const A = t.length;
|
|
2629
|
+
V(S, `${y}.args[${T}]`, !0), w && ((E = Ge(w, T)) == null ? void 0 : E.kind) === "type-name" && O(S) && m(S.value, er, `${y}.args[${T}].value`, "a type name"), w && ((C = Ge(w, T)) == null ? void 0 : C.kind) === "fixed-text" && O(S) && !(S.type === "literal" && q(S.value)) && h(`${w.name}'s ${Ge(w, T).label} is a text value`);
|
|
2630
|
+
const M = !t.slice(A).some((P) => P.kind === "invalidStructure");
|
|
2631
|
+
w != null && w.aggregate && M && le(S, a) && s(
|
|
2622
2632
|
"misplacedAggregate",
|
|
2623
|
-
`${y}.args[${
|
|
2633
|
+
`${y}.args[${T}]`,
|
|
2624
2634
|
"an aggregate can't be inside another: sum up per group in a sub query first"
|
|
2625
2635
|
);
|
|
2626
2636
|
}), u.orderBy !== void 0) {
|
|
@@ -2628,16 +2638,16 @@ function ti(e, n, r = {}) {
|
|
|
2628
2638
|
h("a function's `orderBy` is an array");
|
|
2629
2639
|
break;
|
|
2630
2640
|
}
|
|
2631
|
-
u.name.toUpperCase() !== "STRING_AGG" && h("only STRING_AGG takes an `orderBy`"), u.orderBy.forEach((S,
|
|
2632
|
-
const
|
|
2641
|
+
u.name.toUpperCase() !== "STRING_AGG" && h("only STRING_AGG takes an `orderBy`"), u.orderBy.forEach((S, T) => {
|
|
2642
|
+
const A = `${y}.orderBy[${T}]`;
|
|
2633
2643
|
if (!O(S) || S.direction !== "asc" && S.direction !== "desc") {
|
|
2634
|
-
s("invalidStructure",
|
|
2644
|
+
s("invalidStructure", A, "a sort key has an `expression` and a `direction`");
|
|
2635
2645
|
return;
|
|
2636
2646
|
}
|
|
2637
2647
|
const M = t.length;
|
|
2638
|
-
V(S.expression, `${
|
|
2648
|
+
V(S.expression, `${A}.expression`, !0), !t.slice(M).some((E) => E.kind === "invalidStructure") && (le(S.expression, a) && s("misplacedAggregate", `${A}.expression`, "an aggregate can't be inside another"), u.distinct === !0 && r.dialect === "postgres" && !Z(S.expression, u.args[0]) && s(
|
|
2639
2649
|
"dialectUnsupported",
|
|
2640
|
-
`${
|
|
2650
|
+
`${A}.expression`,
|
|
2641
2651
|
"PostgreSQL orders STRING_AGG of different values by the value only"
|
|
2642
2652
|
));
|
|
2643
2653
|
});
|
|
@@ -2645,26 +2655,26 @@ function ti(e, n, r = {}) {
|
|
|
2645
2655
|
break;
|
|
2646
2656
|
}
|
|
2647
2657
|
case "binary": {
|
|
2648
|
-
u.operator !== void 0 && !
|
|
2658
|
+
u.operator !== void 0 && !Vr.includes(u.operator) && h(`unknown operator ${JSON.stringify(u.operator)}`), u.operator === "REGEXP" && r.dialect === "mssql" && s("dialectUnsupported", y, "SQL Server has no REGEXP");
|
|
2649
2659
|
const w = t.length;
|
|
2650
2660
|
V(u.left, `${y}.left`, !0);
|
|
2651
|
-
const S = t.slice(w).some((
|
|
2652
|
-
if (
|
|
2661
|
+
const S = t.slice(w).some((T) => T.kind === "incomplete");
|
|
2662
|
+
if (Hr(u.operator))
|
|
2653
2663
|
u.right !== void 0 && h(`${String(u.operator)} takes no right side`);
|
|
2654
2664
|
else if (u.right === void 0)
|
|
2655
2665
|
s("incomplete", `${y}.right`, "a comparison with nothing to compare to");
|
|
2656
2666
|
else if (O(u.right) && u.right.type === "literal" && u.right.value === null)
|
|
2657
2667
|
s("incomplete", `${y}.right`, "compared with NULL (never true): use IS NULL");
|
|
2658
2668
|
else if (O(u.right) && u.right.type === "subquery")
|
|
2659
|
-
u.operator === "IN" ?
|
|
2669
|
+
u.operator === "IN" ? ee(u.right, `${y}.right`) : s("invalidStructure", `${y}.right`, "a sub query is only IN's right side");
|
|
2660
2670
|
else if (u.operator === "BETWEEN") {
|
|
2661
|
-
const { right:
|
|
2662
|
-
(
|
|
2671
|
+
const { right: T } = u, A = O(T) && T.type === "list" && Array.isArray(T.items) ? T.items : void 0;
|
|
2672
|
+
(A == null ? void 0 : A.length) !== 2 ? s("invalidStructure", `${y}.right`, "BETWEEN takes its two bounds as a list (expr.between)") : A.forEach((M, E) => {
|
|
2663
2673
|
const C = `${y}.right.items[${E}]`;
|
|
2664
2674
|
O(M) && M.type === "literal" && M.value === null ? s("incomplete", C, "a bound of NULL (never true)") : S && en(M) || V(M, C, !0);
|
|
2665
2675
|
});
|
|
2666
|
-
} else O(u.right) && u.right.type === "list" ? u.operator === "IN" ?
|
|
2667
|
-
t.slice(w).some((
|
|
2676
|
+
} else O(u.right) && u.right.type === "list" ? u.operator === "IN" ? ye(u.right, `${y}.right`) : s("invalidStructure", `${y}.right`, "a list is only IN's or BETWEEN's right side") : u.operator === "IN" ? s("invalidStructure", `${y}.right`, "IN takes a list (expr.list) or a sub query") : S && en(u.right) || V(u.right, `${y}.right`, !0);
|
|
2677
|
+
t.slice(w).some((T) => T.kind === "invalidStructure") || Qt(u, y);
|
|
2668
2678
|
break;
|
|
2669
2679
|
}
|
|
2670
2680
|
case "logical":
|
|
@@ -2685,30 +2695,30 @@ function ti(e, n, r = {}) {
|
|
|
2685
2695
|
u[S] === void 0 && s("incomplete", `${y}.${S}`, `an IF with no ${S}`);
|
|
2686
2696
|
});
|
|
2687
2697
|
const w = t.length;
|
|
2688
|
-
|
|
2698
|
+
N("condition", !1), N("then", !0), N("else", !0), t.slice(w).some((S) => S.kind === "invalidStructure") || Nn(
|
|
2689
2699
|
["then", "else"].filter((S) => u[S] !== void 0).map((S) => [u[S], `${y}.${S}`])
|
|
2690
2700
|
);
|
|
2691
2701
|
break;
|
|
2692
2702
|
}
|
|
2693
2703
|
case "case": {
|
|
2694
2704
|
const w = t.length;
|
|
2695
|
-
|
|
2696
|
-
if (!O(
|
|
2697
|
-
const M = `${y}.branches[${
|
|
2705
|
+
N("subject", !0), Array.isArray(u.branches) ? (u.branches.length === 0 && s("incomplete", y, "a CASE with no WHEN"), u.branches.forEach((T, A) => {
|
|
2706
|
+
if (!O(T)) {
|
|
2707
|
+
const M = `${y}.branches[${A}]`;
|
|
2698
2708
|
s("invalidStructure", M, "a branch has `when` and `then`");
|
|
2699
2709
|
return;
|
|
2700
2710
|
}
|
|
2701
|
-
V(
|
|
2711
|
+
V(T.when, `${y}.branches[${A}].when`, u.subject !== void 0), V(T.then, `${y}.branches[${A}].then`, !0);
|
|
2702
2712
|
})) : h("a case node has a `branches` array");
|
|
2703
2713
|
const S = t.length;
|
|
2704
|
-
|
|
2705
|
-
...u.branches.map((
|
|
2714
|
+
N("else", !0), Array.isArray(u.branches) && t.slice(w).concat(t.slice(S)).every((T) => T.kind !== "invalidStructure") && Nn([
|
|
2715
|
+
...u.branches.map((T, A) => [T.then, `${y}.branches[${A}].then`]),
|
|
2706
2716
|
...u.else === void 0 ? [] : [[u.else, `${y}.else`]]
|
|
2707
2717
|
]);
|
|
2708
2718
|
break;
|
|
2709
2719
|
}
|
|
2710
2720
|
case "exists":
|
|
2711
|
-
|
|
2721
|
+
X(u, y);
|
|
2712
2722
|
break;
|
|
2713
2723
|
case "subquery":
|
|
2714
2724
|
h("a sub query is only IN's right side");
|
|
@@ -2720,81 +2730,83 @@ function ti(e, n, r = {}) {
|
|
|
2720
2730
|
h(`unknown expression type ${JSON.stringify(u.type)}`);
|
|
2721
2731
|
}
|
|
2722
2732
|
};
|
|
2723
|
-
|
|
2733
|
+
ye = (u, y) => {
|
|
2724
2734
|
Array.isArray(u.items) ? u.items.length === 0 ? s("incomplete", y, "IN with no values") : u.items.forEach((g, h) => V(g, `${y}.items[${h}]`, !0)) : s("invalidStructure", y, "a list has an `items` array");
|
|
2725
|
-
},
|
|
2735
|
+
}, ee = (u, y) => {
|
|
2726
2736
|
const { id: g, query: h } = u;
|
|
2727
2737
|
if (!q(g) || g === "" || !O(h)) {
|
|
2728
2738
|
s("invalidStructure", y, "a sub query has a non-empty string `id` and a `query`");
|
|
2729
2739
|
return;
|
|
2730
2740
|
}
|
|
2731
2741
|
d.has(g) && s("duplicateId", `${y}.id`, `the id "${g}" is used twice`), d.add(g);
|
|
2732
|
-
const
|
|
2742
|
+
const N = { inQuery: o, aliasOf: l, outerTables: c };
|
|
2733
2743
|
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = void 0;
|
|
2734
2744
|
const w = t.length;
|
|
2735
|
-
|
|
2745
|
+
Oe(h, `${y}.query`, !1), { inQuery: o, aliasOf: l, outerTables: c } = N;
|
|
2736
2746
|
const S = t.length === w;
|
|
2737
|
-
(Array.isArray(h.select) ? h.select : []).length !== 1 && s("subqueryColumns", `${y}.query.select`, "a sub query after IN picks exactly one column to compare with"), S &&
|
|
2738
|
-
},
|
|
2747
|
+
(Array.isArray(h.select) ? h.select : []).length !== 1 && s("subqueryColumns", `${y}.query.select`, "a sub query after IN picks exactly one column to compare with"), S && Ue(h, `${y}.query`);
|
|
2748
|
+
}, X = (u, y) => {
|
|
2739
2749
|
const { query: g, link: h } = u;
|
|
2740
2750
|
if (!O(g) || !Array.isArray(g.joins)) {
|
|
2741
2751
|
s("invalidStructure", `${y}.query`, "an EXISTS has a `query` with `from` and `joins`");
|
|
2742
2752
|
return;
|
|
2743
2753
|
}
|
|
2744
|
-
const
|
|
2745
|
-
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c =
|
|
2754
|
+
const N = { inQuery: o, aliasOf: l, outerTables: c };
|
|
2755
|
+
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = N.inQuery, [
|
|
2746
2756
|
[g.from, `${y}.query.from`],
|
|
2747
|
-
...g.joins.map((
|
|
2748
|
-
].forEach(([
|
|
2757
|
+
...g.joins.map((A, M) => [A, `${y}.query.joins[${M}]`])
|
|
2758
|
+
].forEach(([A, M], E) => {
|
|
2749
2759
|
const C = new Set(o.keys());
|
|
2750
|
-
|
|
2760
|
+
G(A, M, E > 0), E > 0 && O(A) && I(A.joinType, `${M}.joinType`), [...o.keys()].filter((P) => !C.has(P) && N.inQuery.has(P)).forEach((P) => s(
|
|
2751
2761
|
"ambiguousTable",
|
|
2752
2762
|
`${M}.table`,
|
|
2753
2763
|
`"${P}" is a table of the query around it too: give it an alias`
|
|
2754
2764
|
));
|
|
2755
2765
|
});
|
|
2756
2766
|
const S = [
|
|
2757
|
-
...g.joins.map((
|
|
2758
|
-
O(
|
|
2767
|
+
...g.joins.map((A, M) => [
|
|
2768
|
+
O(A) ? A.on : void 0,
|
|
2759
2769
|
`${y}.query.joins[${M}].on`
|
|
2760
2770
|
]),
|
|
2761
2771
|
[g.where, `${y}.query.where`]
|
|
2762
2772
|
];
|
|
2763
|
-
S.forEach(([
|
|
2764
|
-
|
|
2773
|
+
S.forEach(([A, M]) => {
|
|
2774
|
+
A !== void 0 && V(A, M);
|
|
2765
2775
|
});
|
|
2766
|
-
const
|
|
2767
|
-
o = new Map([...
|
|
2768
|
-
O(
|
|
2776
|
+
const T = { inQuery: o, aliasOf: l };
|
|
2777
|
+
o = new Map([...N.inQuery, ...T.inQuery]), l = new Map([...N.aliasOf, ...T.aliasOf]), c = void 0, V(h, `${y}.link`), { inQuery: o, aliasOf: l, outerTables: c } = N, [...S, [h, `${y}.link`]].forEach(([A, M]) => {
|
|
2778
|
+
O(A) && le(A, a) && s("misplacedAggregate", M, "an aggregate (SUM, COUNT, …) can't be used here");
|
|
2769
2779
|
});
|
|
2770
2780
|
};
|
|
2771
|
-
const
|
|
2781
|
+
const ve = (u, y, g = []) => {
|
|
2772
2782
|
const h = new Set(g);
|
|
2773
|
-
u.forEach((
|
|
2774
|
-
!O(
|
|
2783
|
+
u.forEach((N, w) => {
|
|
2784
|
+
!O(N) || !q(N.id) || N.id === "" ? s("invalidStructure", `${y}[${w}]`, "every entry has a non-empty string id") : h.has(N.id) ? s("duplicateId", `${y}[${w}].id`, `id "${N.id}" is used twice`) : h.add(N.id);
|
|
2775
2785
|
});
|
|
2776
|
-
}, An = (u, y, g) => Array.isArray(u[y]) ? u[y] : (u[y] !== void 0 && s("invalidStructure", g, `\`${y}\` is an array`), []),
|
|
2786
|
+
}, An = (u, y, g) => Array.isArray(u[y]) ? u[y] : (u[y] !== void 0 && s("invalidStructure", g, `\`${y}\` is an array`), []), Oe = (u, y, g) => {
|
|
2777
2787
|
const h = (E) => y ? `${y}.${E}` : E;
|
|
2778
|
-
|
|
2779
|
-
const { from:
|
|
2780
|
-
O(
|
|
2788
|
+
G(u.from, h("from"), !0);
|
|
2789
|
+
const { from: N } = u, w = O(N) && N.query !== void 0 ? N.id : void 0;
|
|
2790
|
+
O(N) && N.query !== void 0 && (!q(w) || w === "") && s("invalidStructure", h("from"), "a derived table has a non-empty string id");
|
|
2781
2791
|
const S = Array.isArray(u.joins) ? u.joins : [];
|
|
2782
|
-
Array.isArray(u.joins) || s("invalidStructure", h("joins"), "`joins` is an array"), S.forEach((E, C) =>
|
|
2792
|
+
Array.isArray(u.joins) || s("invalidStructure", h("joins"), "`joins` is an array"), S.forEach((E, C) => G(E, h(`joins[${C}]`), !0)), ve(S, h("joins"), q(w) ? [w] : []), S.forEach((E, C) => {
|
|
2783
2793
|
if (O(E)) {
|
|
2784
|
-
if (
|
|
2794
|
+
if (On.includes(E.joinType))
|
|
2795
|
+
I(E.joinType, h(`joins[${C}].joinType`));
|
|
2796
|
+
else {
|
|
2785
2797
|
const P = JSON.stringify(E.joinType);
|
|
2786
2798
|
s("invalidStructure", h(`joins[${C}].joinType`), `unknown join type ${P}`);
|
|
2787
2799
|
}
|
|
2788
2800
|
E.joinType !== "cross" && (E.on !== void 0 ? V(E.on, h(`joins[${C}].on`)) : s("incomplete", h(`joins[${C}].on`), "a join with no ON condition"));
|
|
2789
2801
|
}
|
|
2790
2802
|
}), u.where !== void 0 && V(u.where, h("where"));
|
|
2791
|
-
const
|
|
2792
|
-
Array.isArray(u.select) || s("invalidStructure", h("select"), "`select` is an array"),
|
|
2793
|
-
O(E) && (m(E.alias, Y, h(`select[${C}].alias`), "an alias"),
|
|
2803
|
+
const T = Array.isArray(u.select) ? u.select : [];
|
|
2804
|
+
Array.isArray(u.select) || s("invalidStructure", h("select"), "`select` is an array"), ve(T, h("select")), T.forEach((E, C) => {
|
|
2805
|
+
O(E) && (m(E.alias, Y, h(`select[${C}].alias`), "an alias"), ge(E.alias) || s("invalidStructure", h(`select[${C}].alias`), "an alias is a string"), V(E.expression, h(`select[${C}].expression`), !0));
|
|
2794
2806
|
});
|
|
2795
|
-
const
|
|
2796
|
-
if (
|
|
2797
|
-
O(E) && (
|
|
2807
|
+
const A = An(u, "groupBy", h("groupBy"));
|
|
2808
|
+
if (ve(A, h("groupBy")), A.forEach((E, C) => {
|
|
2809
|
+
O(E) && (ge(E.fromSelect) || s("invalidStructure", h(`groupBy[${C}].fromSelect`), "`fromSelect` is a column's id"), V(E.expression, h(`groupBy[${C}].expression`), !0));
|
|
2798
2810
|
}), u.having !== void 0 && V(u.having, h("having")), u.distinct !== void 0 && typeof u.distinct != "boolean" && s("invalidStructure", h("distinct"), "`distinct` is a boolean"), !g) {
|
|
2799
2811
|
["orderBy", "limit", "offset", "shared"].forEach((E) => {
|
|
2800
2812
|
u[E] !== void 0 && s("invalidStructure", h(E), `a derived table has no \`${E}\``);
|
|
@@ -2802,40 +2814,40 @@ function ti(e, n, r = {}) {
|
|
|
2802
2814
|
return;
|
|
2803
2815
|
}
|
|
2804
2816
|
const M = An(u, "orderBy", "orderBy");
|
|
2805
|
-
|
|
2817
|
+
ve(M, "orderBy"), M.forEach((E, C) => {
|
|
2806
2818
|
O(E) && (E.direction !== "asc" && E.direction !== "desc" && s("invalidStructure", `orderBy[${C}].direction`, 'a sort direction is "asc" or "desc"'), V(E.expression, `orderBy[${C}].expression`, !0));
|
|
2807
2819
|
}), ["limit", "offset"].forEach((E) => {
|
|
2808
2820
|
const C = u[E];
|
|
2809
2821
|
C !== void 0 && !(Number.isInteger(C) && C >= 0) ? s("invalidStructure", E, `\`${E}\` is a non-negative integer`) : C !== void 0 && !Number.isSafeInteger(C) && s("tooLong", E, `\`${E}\` is past ${Number.MAX_SAFE_INTEGER}, which is exact`);
|
|
2810
2822
|
});
|
|
2811
|
-
},
|
|
2812
|
-
const h = `${y}.query`, { union:
|
|
2813
|
-
if (!Array.isArray(
|
|
2823
|
+
}, _t = (u, y, g) => {
|
|
2824
|
+
const h = `${y}.query`, { union: N } = u;
|
|
2825
|
+
if (!Array.isArray(N) || N.length < 1 || typeof u.all != "boolean") {
|
|
2814
2826
|
s("invalidStructure", h, "a union has one or more branches in `union`, and a boolean `all`"), b(g, `${y}.alias`), o.set(g, void 0);
|
|
2815
2827
|
return;
|
|
2816
2828
|
}
|
|
2817
2829
|
let w = [];
|
|
2818
2830
|
const S = [];
|
|
2819
|
-
let
|
|
2820
|
-
|
|
2831
|
+
let T = !0;
|
|
2832
|
+
N.forEach((A, M) => {
|
|
2821
2833
|
const E = `${h}.union[${M}]`;
|
|
2822
|
-
if (!O(
|
|
2823
|
-
s("invalidStructure", E, "a union's branch is a query"),
|
|
2834
|
+
if (!O(A)) {
|
|
2835
|
+
s("invalidStructure", E, "a union's branch is a query"), T = !1;
|
|
2824
2836
|
return;
|
|
2825
2837
|
}
|
|
2826
2838
|
const C = { inQuery: o, aliasOf: l, outerTables: c };
|
|
2827
2839
|
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = void 0;
|
|
2828
2840
|
const P = t.length;
|
|
2829
|
-
|
|
2830
|
-
const
|
|
2831
|
-
if ({ inQuery: o, aliasOf: l, outerTables: c } = C, !
|
|
2832
|
-
|
|
2841
|
+
Oe(A, E, !1);
|
|
2842
|
+
const ae = t.length === P, B = (Array.isArray(A.select) ? A.select : []).filter(O), U = ae ? B.map((j) => j.expression.type === "literal" ? _e(j.expression) : te(j.expression)) : [];
|
|
2843
|
+
if ({ inQuery: o, aliasOf: l, outerTables: c } = C, !ae) {
|
|
2844
|
+
T = !1;
|
|
2833
2845
|
return;
|
|
2834
2846
|
}
|
|
2835
|
-
|
|
2847
|
+
Ue(A, E);
|
|
2836
2848
|
const _ = B.map((j) => K(j));
|
|
2837
2849
|
if (B.length === 0) {
|
|
2838
|
-
s("unionColumns", `${E}.select`, "a union's branch names its columns"),
|
|
2850
|
+
s("unionColumns", `${E}.select`, "a union's branch names its columns"), T = !1;
|
|
2839
2851
|
return;
|
|
2840
2852
|
}
|
|
2841
2853
|
if (M === 0)
|
|
@@ -2852,25 +2864,25 @@ function ti(e, n, r = {}) {
|
|
|
2852
2864
|
} else
|
|
2853
2865
|
_.forEach((j, L) => {
|
|
2854
2866
|
if (j === w[L]) return;
|
|
2855
|
-
const
|
|
2856
|
-
s("unionColumns", `${E}.select[${L}]`,
|
|
2867
|
+
const J = `column ${L + 1} is "${String(w[L])}" in the first branch, not "${String(j)}"`;
|
|
2868
|
+
s("unionColumns", `${E}.select[${L}]`, J);
|
|
2857
2869
|
});
|
|
2858
2870
|
U.forEach((j, L) => {
|
|
2859
2871
|
if (j === void 0) return;
|
|
2860
|
-
const
|
|
2861
|
-
if (
|
|
2872
|
+
const J = S[L];
|
|
2873
|
+
if (J === void 0)
|
|
2862
2874
|
S[L] = j;
|
|
2863
|
-
else if (
|
|
2864
|
-
const
|
|
2865
|
-
s("unionTypes", `${E}.select[${L}].expression`,
|
|
2875
|
+
else if (De(J) !== De(j)) {
|
|
2876
|
+
const re = `column "${String(w[L])}" is ${de[j]} here, ${de[J]} in a branch before`;
|
|
2877
|
+
s("unionTypes", `${E}.select[${L}].expression`, re);
|
|
2866
2878
|
}
|
|
2867
2879
|
});
|
|
2868
|
-
}), b(g, `${y}.alias`), o.set(g,
|
|
2880
|
+
}), b(g, `${y}.alias`), o.set(g, T ? w.filter((A) => A !== void 0) : void 0);
|
|
2869
2881
|
};
|
|
2870
|
-
|
|
2882
|
+
k = (u, y) => {
|
|
2871
2883
|
const { query: g, alias: h } = u;
|
|
2872
2884
|
if (u.table === void 0 && O(g) && g.union !== void 0 && q(h) && h !== "") {
|
|
2873
|
-
m(h, Y, `${y}.alias`, "an alias"),
|
|
2885
|
+
m(h, Y, `${y}.alias`, "an alias"), _t(g, y, h);
|
|
2874
2886
|
return;
|
|
2875
2887
|
}
|
|
2876
2888
|
if (u.table !== void 0 || !O(g) || !q(h) || h === "") {
|
|
@@ -2878,25 +2890,25 @@ function ti(e, n, r = {}) {
|
|
|
2878
2890
|
return;
|
|
2879
2891
|
}
|
|
2880
2892
|
m(h, Y, `${y}.alias`, "an alias");
|
|
2881
|
-
const
|
|
2893
|
+
const N = { inQuery: o, aliasOf: l, outerTables: c };
|
|
2882
2894
|
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = void 0;
|
|
2883
2895
|
const w = t.length;
|
|
2884
|
-
|
|
2885
|
-
const S = Array.isArray(g.select) ? g.select : [],
|
|
2886
|
-
|
|
2896
|
+
Oe(g, `${y}.query`, !1), { inQuery: o, aliasOf: l, outerTables: c } = N;
|
|
2897
|
+
const S = Array.isArray(g.select) ? g.select : [], T = [], A = (C, P) => {
|
|
2898
|
+
T.includes(C) ? s("derivedColumnName", P, `two columns named "${C}"`) : T.push(C);
|
|
2887
2899
|
};
|
|
2888
2900
|
S.forEach((C, P) => {
|
|
2889
2901
|
if (!O(C) || !O(C.expression)) return;
|
|
2890
|
-
const
|
|
2891
|
-
|
|
2902
|
+
const ae = K(C);
|
|
2903
|
+
ae ? A(ae, `${y}.query.select[${P}]`) : s("derivedColumnName", `${y}.query.select[${P}]`, "a derived table's column needs an alias: nothing outside could name it");
|
|
2892
2904
|
});
|
|
2893
2905
|
const M = t.length === w;
|
|
2894
|
-
M && S.length === 0 && Ne(i, g, f).forEach((C) =>
|
|
2906
|
+
M && S.length === 0 && Ne(i, g, f).forEach((C) => A(C.name, `${y}.query.select`)), b(h, `${y}.alias`), o.set(h, M || S.length > 0 ? T : void 0), M && Ue(g, `${y}.query`);
|
|
2895
2907
|
const { drillAcross: E } = u;
|
|
2896
2908
|
E !== void 0 && !(O(E) && typeof E.synced == "boolean" && Number.isInteger(E.copied) && E.copied >= 0) && s("invalidStructure", `${y}.drillAcross`, "`drillAcross` has a boolean `synced` and a non-negative integer `copied`");
|
|
2897
2909
|
};
|
|
2898
|
-
const
|
|
2899
|
-
var M, E, C, P,
|
|
2910
|
+
const Ue = (u, y) => {
|
|
2911
|
+
var M, E, C, P, ae;
|
|
2900
2912
|
const g = (B) => y ? `${y}.${B}` : B, h = pn(u);
|
|
2901
2913
|
if (h) {
|
|
2902
2914
|
const B = u.joins.findIndex((U) => (U.table ?? D(U)) === h.table);
|
|
@@ -2906,38 +2918,38 @@ function ti(e, n, r = {}) {
|
|
|
2906
2918
|
`the join condition of "${h.table}" uses "${h.needs}", which is joined after it`
|
|
2907
2919
|
);
|
|
2908
2920
|
}
|
|
2909
|
-
const
|
|
2910
|
-
|
|
2921
|
+
const N = (B, U) => {
|
|
2922
|
+
le(B, a) && s("misplacedAggregate", U, "an aggregate (SUM, COUNT, …) can't be used here");
|
|
2911
2923
|
};
|
|
2912
|
-
|
|
2913
|
-
B.joinType !== "cross" &&
|
|
2914
|
-
}), (M = u.groupBy) == null || M.forEach((B, U) =>
|
|
2915
|
-
const w =
|
|
2924
|
+
N(u.where, g("where")), u.joins.forEach((B, U) => {
|
|
2925
|
+
B.joinType !== "cross" && N(B.on, g(`joins[${U}].on`));
|
|
2926
|
+
}), (M = u.groupBy) == null || M.forEach((B, U) => N(B.expression, g(`groupBy[${U}].expression`)));
|
|
2927
|
+
const w = Kn(u, a), S = "isn't a group key or an aggregate (SUM, COUNT, …)";
|
|
2916
2928
|
if (w.selectAll && s("notGrouped", g("select"), "a grouped query has to pick its columns, not *"), u.select.forEach((B, U) => {
|
|
2917
2929
|
w.select.includes(B.id) && s("notGrouped", g(`select[${U}].expression`), `this column ${S}`);
|
|
2918
2930
|
}), (E = u.orderBy) == null || E.forEach((B, U) => {
|
|
2919
2931
|
w.orderBy.includes(B.id) && s("notGrouped", `orderBy[${U}].expression`, `this sort key ${S}`);
|
|
2920
2932
|
}), w.having && s("notGrouped", g("having"), `a column in this condition ${S}`), r.dialect === "mssql") {
|
|
2921
|
-
const B = [], U = (L,
|
|
2922
|
-
const [
|
|
2923
|
-
return
|
|
2933
|
+
const B = [], U = (L, J) => {
|
|
2934
|
+
const [re, je] = L.length <= J.length ? [L, J] : [J, L];
|
|
2935
|
+
return re.every((Cn, In) => Cn.direction === je[In].direction && Z(Cn.expression, je[In].expression));
|
|
2924
2936
|
}, _ = (L) => {
|
|
2925
|
-
var
|
|
2926
|
-
return [...L.type === "function" && ((
|
|
2927
|
-
}, j = (L,
|
|
2928
|
-
_(L).forEach((
|
|
2929
|
-
B.some((
|
|
2937
|
+
var re;
|
|
2938
|
+
return [...L.type === "function" && ((re = L.orderBy) != null && re.length) ? [L.orderBy] : [], ...fe(L).flatMap(_)];
|
|
2939
|
+
}, j = (L, J) => {
|
|
2940
|
+
_(L).forEach((re) => {
|
|
2941
|
+
B.some((je) => !U(je, re)) && s(
|
|
2930
2942
|
"dialectUnsupported",
|
|
2931
|
-
|
|
2943
|
+
J,
|
|
2932
2944
|
"SQL Server sorts every STRING_AGG of a query alike: this one's order differs"
|
|
2933
|
-
), B.push(
|
|
2945
|
+
), B.push(re);
|
|
2934
2946
|
});
|
|
2935
2947
|
};
|
|
2936
|
-
u.select.forEach((L,
|
|
2948
|
+
u.select.forEach((L, J) => j(L.expression, g(`select[${J}].expression`))), u.having && j(u.having, g("having")), (C = u.orderBy) == null || C.forEach((L, J) => j(L.expression, `orderBy[${J}].expression`));
|
|
2937
2949
|
}
|
|
2938
2950
|
if (r.allowUnknownFunctions && Mn(u, a)) {
|
|
2939
2951
|
const B = (U, _) => {
|
|
2940
|
-
|
|
2952
|
+
Kt(U, a) && s(
|
|
2941
2953
|
"unknownAggregate",
|
|
2942
2954
|
_,
|
|
2943
2955
|
"a function the editor doesn't know: it isn't made a group key, in case it sums rows up — declare it in `functions` (`aggregate: true` if it does)",
|
|
@@ -2949,7 +2961,7 @@ function ti(e, n, r = {}) {
|
|
|
2949
2961
|
u.joins.forEach((B, U) => {
|
|
2950
2962
|
if (B.joinType === "cross" || !B.on) return;
|
|
2951
2963
|
const _ = ne(B.on), j = D(B), L = Q(u).slice(0, U + 1).map(D);
|
|
2952
|
-
_.some((
|
|
2964
|
+
_.some((J) => J !== j && !L.includes(J)) || _.includes(j) && _.some((J) => L.includes(J)) || s(
|
|
2953
2965
|
"unlinkedJoin",
|
|
2954
2966
|
g(`joins[${U}].on`),
|
|
2955
2967
|
`the join condition of "${j}" doesn't compare it with a table joined before it: every row meets every row it lets through`,
|
|
@@ -2964,54 +2976,54 @@ function ti(e, n, r = {}) {
|
|
|
2964
2976
|
`"${B.alias}" is kept in step with the query but doesn't match its grouping`
|
|
2965
2977
|
);
|
|
2966
2978
|
const _ = H(B.query) ? void 0 : B.query.from.table;
|
|
2967
|
-
_ !== void 0 &&
|
|
2979
|
+
_ !== void 0 && Sr(i, u, _) && s(
|
|
2968
2980
|
"drillAcrossFilterMixed",
|
|
2969
2981
|
g(`joins[${U}]`),
|
|
2970
2982
|
`a condition of the query names both what "${B.alias}" shares and what it doesn't: it isn't applied to it`,
|
|
2971
2983
|
"warning"
|
|
2972
2984
|
);
|
|
2973
2985
|
}), u.joins.forEach((B, U) => {
|
|
2974
|
-
B.joinType !== "cross" || B.query &&
|
|
2986
|
+
B.joinType !== "cross" || B.query && lt(B.query, a) || s(
|
|
2975
2987
|
"crossJoin",
|
|
2976
2988
|
g(`joins[${U}]`),
|
|
2977
2989
|
`every row of "${D(B)}" meets every row of the query: they multiply`,
|
|
2978
2990
|
"warning"
|
|
2979
2991
|
);
|
|
2980
2992
|
});
|
|
2981
|
-
const
|
|
2993
|
+
const T = _r(u, i), A = (B) => s(
|
|
2982
2994
|
"fanOut",
|
|
2983
2995
|
B,
|
|
2984
|
-
`${
|
|
2996
|
+
`${T.tables.map((U) => `"${U}"`).join(", ")} rows repeat in this join: a sum, average or count of their columns comes out too high`,
|
|
2985
2997
|
"warning"
|
|
2986
2998
|
);
|
|
2987
2999
|
u.select.forEach((B, U) => {
|
|
2988
|
-
|
|
2989
|
-
}),
|
|
2990
|
-
|
|
3000
|
+
T.select.includes(B.id) && A(g(`select[${U}].expression`));
|
|
3001
|
+
}), T.having && A(g("having")), (ae = u.orderBy) == null || ae.forEach((B, U) => {
|
|
3002
|
+
T.orderBy.includes(B.id) && A(`orderBy[${U}].expression`);
|
|
2991
3003
|
});
|
|
2992
3004
|
};
|
|
2993
|
-
n.shared !== void 0 && !Array.isArray(n.shared) && s("invalidStructure", "shared", "`shared` is an array"),
|
|
3005
|
+
n.shared !== void 0 && !Array.isArray(n.shared) && s("invalidStructure", "shared", "`shared` is an array"), ve(f, "shared");
|
|
2994
3006
|
const kn = /* @__PURE__ */ new Set();
|
|
2995
3007
|
if (f.forEach((u, y) => {
|
|
2996
3008
|
if (!O(u)) return;
|
|
2997
3009
|
const g = `shared[${y}]`, { name: h } = u;
|
|
2998
3010
|
!q(h) || h === "" ? s("invalidStructure", `${g}.name`, "a shared query has a non-empty string `name`") : (m(h, Y, `${g}.name`, "a name"), kn.has(h) && s("duplicateTableName", `${g}.name`, `two shared queries named "${h}"`), kn.add(h));
|
|
2999
|
-
const
|
|
3000
|
-
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = void 0,
|
|
3001
|
-
const S = o.get(
|
|
3011
|
+
const N = q(h) && h !== "" ? h : g, w = { inQuery: o, aliasOf: l, outerTables: c };
|
|
3012
|
+
o = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = void 0, k({ query: u.query, alias: N }, g);
|
|
3013
|
+
const S = o.get(N);
|
|
3002
3014
|
({ inQuery: o, aliasOf: l, outerTables: c } = w), q(u.id) && v.set(u.id, Array.isArray(S) ? S : void 0);
|
|
3003
|
-
}),
|
|
3015
|
+
}), Oe(n, "", !0), t.length === 0) {
|
|
3004
3016
|
const u = n;
|
|
3005
|
-
if (
|
|
3017
|
+
if (Ue(u, ""), r.requireLimit) {
|
|
3006
3018
|
const { max: g } = r.requireLimit === !0 ? {} : r.requireLimit, h = Mn(u, a) && !((xn = u.groupBy) != null && xn.length);
|
|
3007
3019
|
u.limit === void 0 && !h ? s("noLimit", "limit", "no LIMIT: the query reads every row", "warning") : g !== void 0 && u.limit !== void 0 && u.limit > g && s("limitTooHigh", "limit", `LIMIT ${u.limit} is above ${g}`, "warning");
|
|
3008
3020
|
}
|
|
3009
|
-
|
|
3021
|
+
Yr(u, i).forEach((g) => {
|
|
3010
3022
|
s("paramConflict", "", `param "${g}" is compared against columns of different types`);
|
|
3011
|
-
}),
|
|
3023
|
+
}), Kr(u).forEach((g) => {
|
|
3012
3024
|
s("paramConflict", "", `param "${g}" stands for two different relative dates`);
|
|
3013
3025
|
});
|
|
3014
|
-
const y =
|
|
3026
|
+
const y = Xr(u);
|
|
3015
3027
|
(Bn = u.orderBy) == null || Bn.forEach((g, h) => {
|
|
3016
3028
|
y.includes(g.id) && s(
|
|
3017
3029
|
"distinctSort",
|
|
@@ -3020,27 +3032,27 @@ function ti(e, n, r = {}) {
|
|
|
3020
3032
|
);
|
|
3021
3033
|
});
|
|
3022
3034
|
}
|
|
3023
|
-
t.some((u) => u.kind === "invalidStructure") ||
|
|
3035
|
+
t.some((u) => u.kind === "invalidStructure") || Zr(e, n).forEach((u) => s(
|
|
3024
3036
|
"joinOnlyColumn",
|
|
3025
3037
|
u.map((y, g) => typeof y == "number" ? `[${y}]` : `${g ? "." : ""}${y}`).join(""),
|
|
3026
3038
|
"a column for joining tables only, used outside a join's condition"
|
|
3027
3039
|
)), f.forEach((u, y) => {
|
|
3028
3040
|
!O(u) || !q(u.id) || $.has(u.id) || s("unusedShared", `shared[${y}]`, "a shared query used nowhere", "warning");
|
|
3029
3041
|
});
|
|
3030
|
-
const
|
|
3031
|
-
return t.filter((u) => u.severity === "error" || !
|
|
3042
|
+
const Ft = r.hideWarnings ?? [];
|
|
3043
|
+
return t.filter((u) => u.severity === "error" || !Ft.includes(u.kind));
|
|
3032
3044
|
}
|
|
3033
|
-
function
|
|
3034
|
-
relativeDate:
|
|
3045
|
+
function oi(e, n = {
|
|
3046
|
+
relativeDate: ft
|
|
3035
3047
|
}) {
|
|
3036
3048
|
return n.relativeDate(e);
|
|
3037
3049
|
}
|
|
3038
|
-
function
|
|
3050
|
+
function ai({ unit: e, offset: n, anchor: r }) {
|
|
3039
3051
|
if (e === "day" && n === 0) return "today";
|
|
3040
3052
|
const t = n < 0 ? `minus_${-n}` : `plus_${n}`;
|
|
3041
3053
|
return [e, n === 0 ? "0" : t, r].filter(Boolean).join("_");
|
|
3042
3054
|
}
|
|
3043
|
-
const
|
|
3055
|
+
const is = {
|
|
3044
3056
|
from: "from",
|
|
3045
3057
|
joins: "from",
|
|
3046
3058
|
where: "where",
|
|
@@ -3052,12 +3064,12 @@ const rs = {
|
|
|
3052
3064
|
limit: "order",
|
|
3053
3065
|
offset: "order"
|
|
3054
3066
|
};
|
|
3055
|
-
function
|
|
3067
|
+
function li(e, n, r = {}) {
|
|
3056
3068
|
const { schema: t, functions: s } = r, i = (d, f) => typeof f == "number" ? d == null ? void 0 : d[f] : void 0, a = (d) => {
|
|
3057
3069
|
var f;
|
|
3058
3070
|
return d.alias || t && d.table !== void 0 && ((f = z(t, d.table)) == null ? void 0 : f.label) || d.table || "";
|
|
3059
3071
|
}, o = (d, f) => {
|
|
3060
|
-
var
|
|
3072
|
+
var k;
|
|
3061
3073
|
if (!d || f.length === 0) return [];
|
|
3062
3074
|
const [p, v, $] = f;
|
|
3063
3075
|
switch (d.type) {
|
|
@@ -3075,7 +3087,7 @@ function ii(e, n, r = {}) {
|
|
|
3075
3087
|
case "function": {
|
|
3076
3088
|
const b = { kind: "function", name: d.name };
|
|
3077
3089
|
if (p === "args" && i(d.args, v)) {
|
|
3078
|
-
const G =
|
|
3090
|
+
const G = Zn(d.name, s), R = G && ((k = Ge(G, v)) == null ? void 0 : k.label);
|
|
3079
3091
|
return [
|
|
3080
3092
|
b,
|
|
3081
3093
|
{ kind: "argument", number: v + 1, ...R && { label: R } },
|
|
@@ -3115,16 +3127,16 @@ function ii(e, n, r = {}) {
|
|
|
3115
3127
|
function c(d, f, p, v = "subQuery") {
|
|
3116
3128
|
const $ = { kind: v, name: d };
|
|
3117
3129
|
if (!H(f)) return [$, ...m(f, p)];
|
|
3118
|
-
const
|
|
3119
|
-
if (!
|
|
3130
|
+
const k = p[0] === "union" ? i(be(f), p[1]) : void 0;
|
|
3131
|
+
if (!k) return [$];
|
|
3120
3132
|
const b = p[1] + 1;
|
|
3121
|
-
return [$, { kind: "unionQuery", number: b }, ...m(
|
|
3133
|
+
return [$, { kind: "unionQuery", number: b }, ...m(k, p.slice(2))];
|
|
3122
3134
|
}
|
|
3123
3135
|
function m(d, f) {
|
|
3124
3136
|
var G, R;
|
|
3125
|
-
const [p, v, $] = f,
|
|
3126
|
-
if (!
|
|
3127
|
-
const b = { kind: "section", section:
|
|
3137
|
+
const [p, v, $] = f, k = is[String(p)];
|
|
3138
|
+
if (!k) return [];
|
|
3139
|
+
const b = { kind: "section", section: k }, I = f.slice(3);
|
|
3128
3140
|
switch (p) {
|
|
3129
3141
|
// A sub query is a place of its own: no "From Tables" before it.
|
|
3130
3142
|
case "from":
|
|
@@ -3139,10 +3151,10 @@ function ii(e, n, r = {}) {
|
|
|
3139
3151
|
case "select": {
|
|
3140
3152
|
const X = i(d.select, v);
|
|
3141
3153
|
if (!X) return [b];
|
|
3142
|
-
const { expression: ee, alias:
|
|
3154
|
+
const { expression: ee, alias: ye } = X, he = ee.type === "field" && t && ee.table !== void 0 ? (R = (G = z(t, ee.table)) == null ? void 0 : G.columns.find((x) => x.name === ee.column)) == null ? void 0 : R.label : void 0, te = ye || he;
|
|
3143
3155
|
return [
|
|
3144
3156
|
b,
|
|
3145
|
-
{ kind: "column", number: v + 1, ...
|
|
3157
|
+
{ kind: "column", number: v + 1, ...te && { name: te } },
|
|
3146
3158
|
...$ === "expression" ? o(ee, I) : []
|
|
3147
3159
|
];
|
|
3148
3160
|
}
|
|
@@ -3166,101 +3178,104 @@ function ii(e, n, r = {}) {
|
|
|
3166
3178
|
return m(e, n);
|
|
3167
3179
|
}
|
|
3168
3180
|
export {
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3181
|
+
Hr as $,
|
|
3182
|
+
As as A,
|
|
3183
|
+
Rr as B,
|
|
3184
|
+
Qr as C,
|
|
3185
|
+
ar as D,
|
|
3174
3186
|
un as E,
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3187
|
+
Ys as F,
|
|
3188
|
+
ei as G,
|
|
3189
|
+
oi as H,
|
|
3190
|
+
si as I,
|
|
3191
|
+
ii as J,
|
|
3192
|
+
li as K,
|
|
3193
|
+
ls as L,
|
|
3194
|
+
tt as M,
|
|
3195
|
+
sr as N,
|
|
3196
|
+
it as O,
|
|
3197
|
+
hs as P,
|
|
3198
|
+
ri as Q,
|
|
3199
|
+
ps as R,
|
|
3200
|
+
$r as S,
|
|
3201
|
+
bs as T,
|
|
3202
|
+
gs as U,
|
|
3203
|
+
cs as V,
|
|
3192
3204
|
$n as W,
|
|
3193
3205
|
Nt as X,
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
Ws as
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
xs as
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3206
|
+
Ds as Y,
|
|
3207
|
+
js as Z,
|
|
3208
|
+
Gs as _,
|
|
3209
|
+
Zt as a,
|
|
3210
|
+
Vr as a0,
|
|
3211
|
+
Rs as a1,
|
|
3212
|
+
ti as a2,
|
|
3213
|
+
Ls as a3,
|
|
3214
|
+
Mr as a4,
|
|
3215
|
+
Jr as a5,
|
|
3216
|
+
_e as a6,
|
|
3217
|
+
nr as a7,
|
|
3218
|
+
vn as a8,
|
|
3219
|
+
ai as a9,
|
|
3220
|
+
$s as aA,
|
|
3221
|
+
tr as aB,
|
|
3222
|
+
rt as aC,
|
|
3223
|
+
ne as aD,
|
|
3224
|
+
Ae as aE,
|
|
3225
|
+
Xe as aF,
|
|
3226
|
+
Ce as aG,
|
|
3227
|
+
tn as aH,
|
|
3228
|
+
ni as aI,
|
|
3229
|
+
zs as aJ,
|
|
3230
|
+
ct as aa,
|
|
3231
|
+
fs as ab,
|
|
3232
|
+
vs as ac,
|
|
3233
|
+
Es as ad,
|
|
3234
|
+
lt as ae,
|
|
3235
|
+
Ss as af,
|
|
3236
|
+
es as ag,
|
|
3237
|
+
Xr as ah,
|
|
3238
|
+
at as ai,
|
|
3239
|
+
Zs as aj,
|
|
3240
|
+
us as ak,
|
|
3241
|
+
Ns as al,
|
|
3242
|
+
mn as am,
|
|
3243
|
+
pr as an,
|
|
3244
|
+
ms as ao,
|
|
3245
|
+
hr as ap,
|
|
3246
|
+
mr as aq,
|
|
3247
|
+
He as ar,
|
|
3248
|
+
Ts as as,
|
|
3249
|
+
Fn as at,
|
|
3250
|
+
dt as au,
|
|
3251
|
+
Fr as av,
|
|
3252
|
+
_r as aw,
|
|
3253
|
+
oe as ax,
|
|
3254
|
+
ds as ay,
|
|
3255
|
+
ws as az,
|
|
3256
|
+
er as b,
|
|
3257
|
+
ys as c,
|
|
3258
|
+
Us as d,
|
|
3259
|
+
Vs as e,
|
|
3260
|
+
Ws as f,
|
|
3261
|
+
Qs as g,
|
|
3262
|
+
Js as h,
|
|
3263
|
+
Xs as i,
|
|
3264
|
+
Dr as j,
|
|
3265
|
+
Ar as k,
|
|
3266
|
+
Ps as l,
|
|
3267
|
+
$t as m,
|
|
3268
|
+
_s as n,
|
|
3269
|
+
qs as o,
|
|
3270
|
+
wr as p,
|
|
3271
|
+
xs as q,
|
|
3272
|
+
Fs as r,
|
|
3273
|
+
Hs as s,
|
|
3274
|
+
Cs as t,
|
|
3275
|
+
Ks as u,
|
|
3276
|
+
Is as v,
|
|
3277
|
+
Os as w,
|
|
3278
|
+
Ms as x,
|
|
3279
|
+
Bs as y,
|
|
3280
|
+
ks as z
|
|
3266
3281
|
};
|