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