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