@nongt/visql-core 0.11.0 → 0.12.1

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.
@@ -1,42 +1,42 @@
1
- import { l as ye, z as Ke, q as Se, t as X, i as Ee, y as ke, d as te, o as be, b as _e, j as $e, f as He, A as ze, D as Ve, B as he, C as Ce, M as K, F as Ye, G as Z, u as ne, H as ge, I as Ze, J as er } from "./schema-CzKt6cN2.js";
2
- import { C as rr, E as nr, F as tr, G as Re, H as Qe, I as ir, J as De, K as sr, L as ar, N as or, t as cr, O as lr, P as ur, A as fr, z as dr, b as mr, Q as Ue, M as yr, a as hr, R as Ge, S as gr, w as pr, T as br, U as $r } from "./params-DVkfcD6D.js";
1
+ import { l as ye, z as Ke, q as Se, t as P, i as Ee, y as ke, d as te, o as be, b as _e, j as $e, f as He, A as ze, D as Ve, B as he, C as Ce, M as K, F as Ye, G as ee, u as ne, H as ge, I as Ze, J as er } from "./schema-DsMO9oFE.js";
2
+ import { C as rr, E as nr, F as tr, G as Re, H as Qe, I as ir, J as De, K as sr, L as ar, N as or, t as cr, O as lr, P as ur, Q as fr, A as dr, z as mr, b as yr, R as Ue, M as hr, a as gr, S as Ge, T as pr, w as br, U as $r, V as vr } from "./params-Btjlj45_.js";
3
3
  const Ae = (n) => typeof n == "object" && n !== null && !Array.isArray(n) && !(n instanceof Date), Ne = (n) => typeof n.shared == "string";
4
4
  function me(n, a) {
5
5
  if (Array.isArray(n)) {
6
6
  let r = !1;
7
- const g = n.flatMap((w) => {
7
+ const $ = n.flatMap((w) => {
8
8
  const l = me(w, a);
9
9
  return l !== w && (r = !0), l === void 0 ? [] : [l];
10
10
  });
11
- return r ? g : n;
11
+ return r ? $ : n;
12
12
  }
13
13
  if (!Ae(n)) return n;
14
14
  if (Ne(n)) return a(n);
15
15
  let u = !1;
16
- const s = Object.entries(n).map(([r, g]) => {
17
- const w = me(g, a);
18
- return w !== g && (u = !0), [r, w];
16
+ const s = Object.entries(n).map(([r, $]) => {
17
+ const w = me($, a);
18
+ return w !== $ && (u = !0), [r, w];
19
19
  });
20
20
  return u ? Object.fromEntries(s) : n;
21
21
  }
22
- function Rr(n) {
22
+ function Dr(n) {
23
23
  const a = new Map((n.shared ?? []).map((s) => [s.id, []])), u = (s, r) => {
24
24
  if (Array.isArray(s)) {
25
- s.forEach((g, w) => u(g, [...r, w]));
25
+ s.forEach(($, w) => u($, [...r, w]));
26
26
  return;
27
27
  }
28
28
  if (Ae(s)) {
29
29
  if (Ne(s)) {
30
- const g = s.shared;
31
- a.set(g, [...a.get(g) ?? [], r]);
30
+ const $ = s.shared;
31
+ a.set($, [...a.get($) ?? [], r]);
32
32
  return;
33
33
  }
34
- Object.entries(s).forEach(([g, w]) => u(w, [...r, g]));
34
+ Object.entries(s).forEach(([$, w]) => u(w, [...r, $]));
35
35
  }
36
36
  };
37
37
  return u(n, []), a;
38
38
  }
39
- function Qr(n, a) {
39
+ function Fr(n, a) {
40
40
  const u = /* @__PURE__ */ new Set([
41
41
  ...(a.shared ?? []).map((r) => r.name),
42
42
  ...Ke(n).map((r) => r.name)
@@ -45,51 +45,51 @@ function Qr(n, a) {
45
45
  for (; u.has(`shared_query_${s}`); ) s += 1;
46
46
  return `shared_query_${s}`;
47
47
  }
48
- function vr(n, a) {
49
- const u = new Set(Se(a).map(X));
48
+ function wr(n, a) {
49
+ const u = new Set(Se(a).map(P));
50
50
  let s = n;
51
51
  for (let r = 2; u.has(s); r += 1) s = `${n}_${r}`;
52
52
  return s;
53
53
  }
54
- function wr(n, a, u, s = ye(), r) {
55
- const g = n.shared ?? [], w = g.findIndex((m) => m.id === r), l = { id: s, name: a, query: u };
54
+ function Sr(n, a, u, s = ye(), r) {
55
+ const $ = n.shared ?? [], w = $.findIndex((m) => m.id === r), l = { id: s, name: a, query: u };
56
56
  return {
57
57
  ...n,
58
- shared: w < 0 ? [...g, l] : [...g.slice(0, w), l, ...g.slice(w)]
58
+ shared: w < 0 ? [...$, l] : [...$.slice(0, w), l, ...$.slice(w)]
59
59
  };
60
60
  }
61
61
  const Fe = (n, a) => {
62
62
  var u;
63
63
  return (u = n.shared) == null ? void 0 : u.find((s) => s.id === a);
64
64
  };
65
- function Dr(n, a, u, s = {}) {
65
+ function Wr(n, a, u, s = {}) {
66
66
  const r = Fe(n, u);
67
67
  if (!r) return a;
68
- const g = {
68
+ const $ = {
69
69
  id: s.id ?? ye(),
70
70
  shared: u,
71
- alias: vr(r.name, a),
71
+ alias: wr(r.name, a),
72
72
  joinType: s.joinType ?? "inner",
73
73
  ...s.on ? { on: s.on } : {}
74
74
  };
75
- return { ...a, joins: [...a.joins, g] };
75
+ return { ...a, joins: [...a.joins, $] };
76
76
  }
77
- function Fr(n, a, u) {
77
+ function qr(n, a, u) {
78
78
  const s = Fe(n, u);
79
79
  return s ? { ...a, from: { shared: u, alias: s.name } } : a;
80
80
  }
81
- function Wr(n, a, u = ye(), s = []) {
82
- const r = rr(n, s), g = r && nr(r).find((d) => d.id === a);
83
- if (!g) return n;
81
+ function Jr(n, a, u = ye(), s = []) {
82
+ const r = rr(n, s), $ = r && nr(r).find((d) => d.id === a);
83
+ if (!$) return n;
84
84
  const w = new Set((n.shared ?? []).map((d) => d.name));
85
- let l = g.alias;
86
- for (let d = 2; w.has(l); d += 1) l = `${g.alias}_${d}`;
87
- const m = wr(n, l, g.query, u, s[0]);
88
- return tr(m, s, (d) => d.from.query && d.from.id === a ? { ...d, from: { shared: u, alias: g.alias } } : {
85
+ let l = $.alias;
86
+ for (let d = 2; w.has(l); d += 1) l = `${$.alias}_${d}`;
87
+ const m = Sr(n, l, $.query, u, s[0]);
88
+ return tr(m, s, (d) => d.from.query && d.from.id === a ? { ...d, from: { shared: u, alias: $.alias } } : {
89
89
  ...d,
90
90
  joins: d.joins.map((O) => {
91
91
  if (O.id !== a || !O.query) return O;
92
- const { query: y, ...E } = O;
92
+ const { query: h, ...E } = O;
93
93
  return { ...E, shared: u };
94
94
  })
95
95
  });
@@ -98,37 +98,37 @@ function We(n, a) {
98
98
  const { shared: u, ...s } = n;
99
99
  return "joinType" in s ? { ...s, query: a } : { id: ye(), alias: s.alias, query: a };
100
100
  }
101
- function qr(n, a) {
101
+ function Pr(n, a) {
102
102
  const u = new Map((n.shared ?? []).map((r) => [r.id, r.query])), s = a.reduce(
103
- (r, g) => typeof r == "object" && r !== null ? r[g] : void 0,
103
+ (r, $) => typeof r == "object" && r !== null ? r[$] : void 0,
104
104
  n
105
105
  );
106
106
  return !Ae(s) || !Ne(s) ? n : me(n, (r) => {
107
- const g = u.get(r.shared);
108
- return r === s && g ? We(r, g) : r;
107
+ const $ = u.get(r.shared);
108
+ return r === s && $ ? We(r, $) : r;
109
109
  });
110
110
  }
111
- function Jr(n, a, u) {
111
+ function Xr(n, a, u) {
112
112
  var s;
113
113
  return !((s = n.shared) != null && s.some((r) => r.id === a)) || u === "" ? n : {
114
114
  ...n,
115
115
  shared: n.shared.map((r) => r.id === a ? { ...r, name: u } : r)
116
116
  };
117
117
  }
118
- class Sr extends Error {
118
+ class Er extends Error {
119
119
  constructor(a) {
120
120
  super(`removeSharedQuery: "${a}" is a query's base: make it a sub query there instead`), this.name = "SharedBaseError";
121
121
  }
122
122
  }
123
- function Xr(n, a, u = "subQueries") {
123
+ function Kr(n, a, u = "subQueries") {
124
124
  var m;
125
125
  const s = (m = n.shared) == null ? void 0 : m.find((d) => d.id === a);
126
126
  if (!s) return n;
127
- const r = n.shared.filter((d) => d !== s), { shared: g, ...w } = n, l = r.length > 0 ? { ...w, shared: r } : w;
127
+ const r = n.shared.filter((d) => d !== s), { shared: $, ...w } = n, l = r.length > 0 ? { ...w, shared: r } : w;
128
128
  return me(l, (d) => {
129
129
  if (d.shared !== a) return d;
130
130
  if (u === "subQueries") return We(d, s.query);
131
- if (!("joinType" in d)) throw new Sr(s.name);
131
+ if (!("joinType" in d)) throw new Er(s.name);
132
132
  });
133
133
  }
134
134
  const Le = (n, a) => n.type === "binary" && n.operator === "IS NULL" && te(n.left, a);
@@ -145,15 +145,15 @@ function ve(n) {
145
145
  }
146
146
  return [];
147
147
  }
148
- function Er(n, a) {
148
+ function kr(n, a) {
149
149
  const u = n.groupBy ?? [];
150
150
  return u.length > 0 && u.every((s) => n.select.some((r) => te(r.expression, s.expression) && a.includes(be(r) ?? "")));
151
151
  }
152
- function kr(n, a) {
153
- const u = X(n.from), s = /* @__PURE__ */ new Map([[u, n.from.table]]), r = [u], g = n.shared ?? [];
152
+ function Ar(n, a) {
153
+ const u = P(n.from), s = /* @__PURE__ */ new Map([[u, n.from.table]]), r = [u], $ = n.shared ?? [];
154
154
  return n.joins.map((w) => {
155
- var E, N;
156
- const { id: l } = w, m = Re(w, g), d = X(w);
155
+ var E, k;
156
+ const { id: l } = w, m = Re(w, $), d = P(w);
157
157
  s.set(d, w.table);
158
158
  const O = ve(w.on).flatMap(([x, j]) => [[x, j], [j, x]]).filter(([x, j]) => x.table === d && r.includes(j.table ?? ""));
159
159
  if (r.push(d), w.joinType === "cross")
@@ -164,7 +164,7 @@ function kr(n, a) {
164
164
  side: m && Qe(m) ? "one" : "cross"
165
165
  };
166
166
  if (w.table === void 0) {
167
- const x = O.length > 0 && m !== void 0 && !Ee(m) && Er(m, O.map(([j]) => j.column));
167
+ const x = O.length > 0 && m !== void 0 && !Ee(m) && kr(m, O.map(([j]) => j.column));
168
168
  return {
169
169
  joinId: l,
170
170
  key: d,
@@ -191,121 +191,121 @@ function kr(n, a) {
191
191
  }).find((x) => x !== void 0) ?? {
192
192
  joinId: l,
193
193
  key: d,
194
- parent: ((N = O[0]) == null ? void 0 : N[1].table) ?? u,
194
+ parent: ((k = O[0]) == null ? void 0 : k[1].table) ?? u,
195
195
  side: "unknown"
196
196
  };
197
197
  });
198
198
  }
199
199
  function we(n, a, u = {}) {
200
- const s = kr(n, a).map((l) => l.side === "unknown" && u.unknown === "repeat" ? { ...l, side: "many" } : l), r = [X(n.from), ...s.map((l) => l.key)], g = (l) => {
200
+ const s = Ar(n, a).map((l) => l.side === "unknown" && u.unknown === "repeat" ? { ...l, side: "many" } : l), r = [P(n.from), ...s.map((l) => l.key)], $ = (l) => {
201
201
  const m = /* @__PURE__ */ new Set([l]);
202
202
  return s.forEach((d) => {
203
203
  m.has(d.parent) && m.add(d.key);
204
204
  }), m;
205
205
  }, w = /* @__PURE__ */ new Set();
206
206
  return s.forEach((l) => {
207
- const m = g(l.key);
207
+ const m = $(l.key);
208
208
  l.side === "many" && r.filter((d) => !m.has(d)).forEach((d) => w.add(d)), l.side === "one" && m.forEach((d) => w.add(d)), l.side === "cross" && r.forEach((d) => w.add(d));
209
209
  }), w;
210
210
  }
211
- const Ar = /* @__PURE__ */ new Set(["SUM", "AVG", "COUNT"]);
212
- function Nr(n, a) {
213
- return n.type === "field" ? n.table && a.has(n.table) ? [n.table] : [] : [...new Set(ke(n).flatMap((u) => Nr(u, a)))];
211
+ const Nr = /* @__PURE__ */ new Set(["SUM", "AVG", "COUNT"]);
212
+ function Tr(n, a) {
213
+ return n.type === "field" ? n.table && a.has(n.table) ? [n.table] : [] : [...new Set(ke(n).flatMap((u) => Tr(u, a)))];
214
214
  }
215
- function Pr(n, a) {
216
- const u = X(n.from);
215
+ function Hr(n, a) {
216
+ const u = P(n.from);
217
217
  return n.joins.some((r) => r.joinType === "right" || r.joinType === "full") || we(n, a).has(u) ? "many" : we(n, a, { unknown: "repeat" }).has(u) ? "unknown" : "one";
218
218
  }
219
219
  function qe(n, a, u = !1) {
220
- const s = n.type === "function" && Ar.has(n.name.toUpperCase()) && !n.distinct, r = u || s;
221
- return n.type === "field" ? r && n.table && a.has(n.table) ? [n.table] : [] : ke(n).flatMap((g) => qe(g, a, r));
220
+ const s = n.type === "function" && Nr.has(n.name.toUpperCase()) && !n.distinct, r = u || s;
221
+ return n.type === "field" ? r && n.table && a.has(n.table) ? [n.table] : [] : ke(n).flatMap(($) => qe($, a, r));
222
222
  }
223
- function Tr(n, a) {
223
+ function xr(n, a) {
224
224
  const u = we(n, a), s = /* @__PURE__ */ new Set(), r = (m) => {
225
225
  const d = m ? qe(m, u) : [];
226
226
  return d.forEach((O) => s.add(O)), d.length > 0;
227
- }, g = n.select.filter((m) => r(m.expression)).map((m) => m.id), w = (n.orderBy ?? []).filter((m) => r(m.expression)).map((m) => m.id), l = r(n.having);
227
+ }, $ = n.select.filter((m) => r(m.expression)).map((m) => m.id), w = (n.orderBy ?? []).filter((m) => r(m.expression)).map((m) => m.id), l = r(n.having);
228
228
  return {
229
229
  tables: [...s],
230
- select: g,
230
+ select: $,
231
231
  orderBy: w,
232
232
  having: l
233
233
  };
234
234
  }
235
- function xr(n) {
235
+ function Br(n) {
236
236
  return !n.distinct || !n.orderBy ? [] : n.orderBy.filter(({ expression: a }) => !(a.type === "field" && !a.column)).filter(({ expression: a }) => n.select.length === 0 ? a.type !== "field" : !n.select.some((u) => te(u.expression, ir(a)))).map(({ id: a }) => a);
237
237
  }
238
- function Br(n, a, u, s) {
238
+ function Ir(n, a, u, s) {
239
239
  const r = new Map(s);
240
- return Se(a).forEach((g) => {
240
+ return Se(a).forEach(($) => {
241
241
  var l;
242
- const w = g.table !== void 0 ? (l = $e(n, g.table)) == null ? void 0 : l.columns : (() => {
243
- const m = Re(g, u);
242
+ const w = $.table !== void 0 ? (l = $e(n, $.table)) == null ? void 0 : l.columns : (() => {
243
+ const m = Re($, u);
244
244
  return m && De(n, m, u);
245
245
  })();
246
- r.set(X(g), new Set((w ?? []).filter((m) => m.joinOnly).map((m) => m.name)));
246
+ r.set(P($), new Set((w ?? []).filter((m) => m.joinOnly).map((m) => m.name)));
247
247
  }), r;
248
248
  }
249
- function Ir(n, a) {
249
+ function Or(n, a) {
250
250
  const u = [], s = a.shared ?? [], r = (l, m, d, O) => {
251
251
  var E;
252
252
  if (Array.isArray(l)) {
253
- l.forEach((N, x) => r(N, [...m, x], d, O));
253
+ l.forEach((k, x) => r(k, [...m, x], d, O));
254
254
  return;
255
255
  }
256
256
  if (typeof l != "object" || l === null || l instanceof Date) return;
257
- const y = l;
258
- if (y.type === "field") {
259
- const { table: N, column: x } = y;
260
- !O && N && x && ((E = d.get(N)) != null && E.has(x)) && u.push(m);
257
+ const h = l;
258
+ if (h.type === "field") {
259
+ const { table: k, column: x } = h;
260
+ !O && k && x && ((E = d.get(k)) != null && E.has(x)) && u.push(m);
261
261
  return;
262
262
  }
263
- if (y.type === "subquery") {
264
- w(y.query, [...m, "query"], !0);
263
+ if (h.type === "subquery") {
264
+ w(h.query, [...m, "query"], !0);
265
265
  return;
266
266
  }
267
- if (y.type === "exists") {
268
- const N = y.query;
269
- w(N, [...m, "query"], !1, d);
267
+ if (h.type === "exists") {
268
+ const k = h.query;
269
+ w(k, [...m, "query"], !1, d);
270
270
  return;
271
271
  }
272
- Object.entries(y).forEach(([N, x]) => r(x, [...m, N], d, O));
273
- }, g = (l, m) => {
272
+ Object.entries(h).forEach(([k, x]) => r(x, [...m, k], d, O));
273
+ }, $ = (l, m) => {
274
274
  "union" in l ? _e(l).forEach((d, O) => w(d, [...m, "union", O], !0)) : w(l, m, !0);
275
275
  };
276
276
  function w(l, m, d, O) {
277
- var N, x, j;
278
- const y = Br(n, l, s, O);
279
- l.from.query && g(l.from.query, [...m, "from", "query"]), l.joins.forEach((M, T) => {
280
- M.query && g(M.query, [...m, "joins", T, "query"]), M.on && r(M.on, [...m, "joins", T, "on"], y, !0);
281
- }), l.where && r(l.where, [...m, "where"], y, !1);
277
+ var k, x, j;
278
+ const h = Ir(n, l, s, O);
279
+ l.from.query && $(l.from.query, [...m, "from", "query"]), l.joins.forEach((M, T) => {
280
+ M.query && $(M.query, [...m, "joins", T, "query"]), M.on && r(M.on, [...m, "joins", T, "on"], h, !0);
281
+ }), l.where && r(l.where, [...m, "where"], h, !1);
282
282
  const E = l;
283
- (N = E.select) == null || N.forEach((M, T) => r(
283
+ (k = E.select) == null || k.forEach((M, T) => r(
284
284
  M.expression,
285
285
  [...m, "select", T, "expression"],
286
- y,
286
+ h,
287
287
  d
288
288
  )), (x = E.groupBy) == null || x.forEach((M, T) => r(
289
289
  M.expression,
290
290
  [...m, "groupBy", T, "expression"],
291
- y,
291
+ h,
292
292
  d
293
- )), E.having && r(E.having, [...m, "having"], y, !1), (j = E.orderBy) == null || j.forEach((M, T) => r(
293
+ )), E.having && r(E.having, [...m, "having"], h, !1), (j = E.orderBy) == null || j.forEach((M, T) => r(
294
294
  M.expression,
295
295
  [...m, "orderBy", T, "expression"],
296
- y,
296
+ h,
297
297
  !1
298
298
  ));
299
299
  }
300
- return s.forEach((l, m) => g(l.query, ["shared", m, "query"])), w(a, [], !1), u;
300
+ return s.forEach((l, m) => $(l.query, ["shared", m, "query"])), w(a, [], !1), u;
301
301
  }
302
- function Kr(n, a) {
302
+ function zr(n, a) {
303
303
  return !(n === "mssql" && a === "REGEXP");
304
304
  }
305
- function Or(n, a) {
305
+ function jr(n, a) {
306
306
  return !(n === "mysql" && a === "full");
307
307
  }
308
- const Hr = [
308
+ const Vr = [
309
309
  "invalidStructure",
310
310
  "duplicateId",
311
311
  "unknownTable",
@@ -345,7 +345,7 @@ const Hr = [
345
345
  "sharedOrder",
346
346
  "unusedShared",
347
347
  "joinOnlyColumn"
348
- ], zr = [
348
+ ], Yr = [
349
349
  "fanOut",
350
350
  "crossJoin",
351
351
  "unlinkedJoin",
@@ -357,10 +357,10 @@ const Hr = [
357
357
  "unknownAggregate",
358
358
  "unusedShared"
359
359
  ];
360
- function jr(n) {
360
+ function Mr(n) {
361
361
  return [...n.matchAll(/([A-Za-z_][A-Za-z0-9_]*)|\[(\d+)\]/g)].map(([, a, u]) => a ?? Number(u));
362
362
  }
363
- const de = (n) => n === "integer" ? "number" : n === "dateTime" ? "date" : n, z = {
363
+ const Cr = /* @__PURE__ */ new Set(["binary", "logical", "not", "exists"]), de = (n) => n === "integer" ? "number" : n === "dateTime" ? "date" : n, z = {
364
364
  text: "text",
365
365
  integer: "a whole number",
366
366
  number: "a number",
@@ -368,143 +368,143 @@ const de = (n) => n === "integer" ? "number" : n === "dateTime" ? "date" : n, z
368
368
  dateTime: "a date and time",
369
369
  time: "a time of day",
370
370
  boolean: "yes / no"
371
- }, I = (n) => typeof n == "object" && n !== null && !Array.isArray(n), G = (n) => typeof n == "string", Mr = ["day", "week", "month", "year"], Cr = (n) => I(n) && Mr.includes(n.unit) && Number.isSafeInteger(n.offset) && (n.anchor === void 0 || n.unit !== "day" && (n.anchor === "start" || n.anchor === "end")), Y = (n) => n === void 0 || G(n), Ur = (n) => n === null || G(n) || typeof n == "boolean" || typeof n == "bigint" || typeof n == "number" && Number.isFinite(n) || n instanceof Date && !Number.isNaN(n.getTime()), pe = (n) => I(n) && n.type === "literal" && n.value === "" && n.empty !== !0;
372
- function Vr(n, a, u = {}) {
371
+ }, B = (n) => typeof n == "object" && n !== null && !Array.isArray(n), G = (n) => typeof n == "string", Ur = ["day", "week", "month", "year"], Gr = (n) => B(n) && Ur.includes(n.unit) && Number.isSafeInteger(n.offset) && (n.anchor === void 0 || n.unit !== "day" && (n.anchor === "start" || n.anchor === "end")), Z = (n) => n === void 0 || G(n), Lr = (n) => n === null || G(n) || typeof n == "boolean" || typeof n == "bigint" || typeof n == "number" && Number.isFinite(n) || n instanceof Date && !Number.isNaN(n.getTime()), pe = (n) => B(n) && n.type === "literal" && n.value === "" && n.empty !== !0;
372
+ function Zr(n, a, u = {}) {
373
373
  var Ie, Oe;
374
374
  const s = [], r = (e, t, o, i = "error") => {
375
375
  s.push({
376
376
  kind: e,
377
377
  severity: i,
378
378
  path: t,
379
- pathSegments: jr(t),
379
+ pathSegments: Mr(t),
380
380
  message: o
381
381
  });
382
382
  };
383
- if (!I(a) || !G(a.id) || a.id === "")
383
+ if (!B(a) || !G(a.id) || a.id === "")
384
384
  return r("invalidStructure", "", "a query is an object with a non-empty string id"), s;
385
385
  if (!("from" in a)) return s;
386
- const g = He(n, u.tableFilter, u.columnFilter), w = ze(u.functions ?? Ve);
386
+ const $ = He(n, u.tableFilter, u.columnFilter), w = ze(u.functions ?? Ve);
387
387
  let l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d;
388
388
  const O = (e, t, o, i) => {
389
389
  G(e) && e.length > t && r("tooLong", o, `${i} is longer than ${t} characters`);
390
- }, y = /* @__PURE__ */ new Set(), E = I(a) && Array.isArray(a.shared) ? a.shared : [], N = new Set(E.flatMap((e) => I(e) && G(e.id) ? [e.id] : [])), x = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Set();
390
+ }, h = /* @__PURE__ */ new Set(), E = B(a) && Array.isArray(a.shared) ? a.shared : [], k = new Set(E.flatMap((e) => B(e) && G(e.id) ? [e.id] : [])), x = /* @__PURE__ */ new Map(), j = /* @__PURE__ */ new Set();
391
391
  let M;
392
392
  const T = (e, t) => {
393
393
  l.has(e) && r("duplicateTableName", t, `two tables named "${e}"`);
394
394
  }, _ = (e, t) => {
395
- Ce.includes(e) && !Or(u.dialect, e) && r("dialectUnsupported", t, `${e.toUpperCase()} JOIN isn't in this database`);
395
+ Ce.includes(e) && !jr(u.dialect, e) && r("dialectUnsupported", t, `${e.toUpperCase()} JOIN isn't in this database`);
396
396
  }, q = (e, t, o = !1) => {
397
- if (o && I(e) && e.query !== void 0) {
397
+ if (o && B(e) && e.query !== void 0) {
398
398
  M(e, t);
399
399
  return;
400
400
  }
401
- if (o && I(e) && e.shared !== void 0) {
402
- const { shared: b, alias: c } = e, v = G(c) && c !== "";
403
- if (!G(b) || !v || e.table !== void 0) {
404
- r("invalidStructure", t, "a shared query's place has a string `shared` and an `alias`, and no `table`"), v && (T(c, `${t}.alias`), l.set(c, void 0));
401
+ if (o && B(e) && e.shared !== void 0) {
402
+ const { shared: v, alias: c } = e, g = G(c) && c !== "";
403
+ if (!G(v) || !g || e.table !== void 0) {
404
+ r("invalidStructure", t, "a shared query's place has a string `shared` and an `alias`, and no `table`"), g && (T(c, `${t}.alias`), l.set(c, void 0));
405
405
  return;
406
406
  }
407
- O(c, K, `${t}.alias`, "an alias"), T(c, `${t}.alias`), j.add(b), N.has(b) ? x.has(b) || r("sharedOrder", `${t}.shared`, "a shared query can use only those before it") : r("unknownTable", `${t}.shared`, `no shared query "${b}"`), l.set(c, x.get(b));
407
+ O(c, K, `${t}.alias`, "an alias"), T(c, `${t}.alias`), j.add(v), k.has(v) ? x.has(v) || r("sharedOrder", `${t}.shared`, "a shared query can use only those before it") : r("unknownTable", `${t}.shared`, `no shared query "${v}"`), l.set(c, x.get(v));
408
408
  return;
409
409
  }
410
- if (!I(e) || !G(e.table) || !Y(e.alias)) {
410
+ if (!B(e) || !G(e.table) || !Z(e.alias)) {
411
411
  r("invalidStructure", t, "a table entry has a string `table` and optional `alias`");
412
412
  return;
413
413
  }
414
414
  O(e.alias, K, `${t}.alias`, "an alias");
415
- const i = g.tables.find((b) => b.name === e.table);
415
+ const i = $.tables.find((v) => v.name === e.table);
416
416
  i || r("unknownTable", `${t}.table`, `unknown table "${e.table}"`), G(e.alias) && e.alias !== "" ? (T(e.alias, `${t}.alias`), l.set(e.alias, i), m.set(e.table, e.alias)) : (T(e.table, `${t}.table`), l.set(e.table, i));
417
417
  }, W = (e, t) => {
418
418
  ge(e) && r("misplacedWindow", t, "a window function goes only in SELECT and ORDER BY");
419
419
  }, F = (e, t, o) => {
420
- var p;
420
+ var y;
421
421
  if (!e) return;
422
- const { args: i, name: b } = e, c = i.filter(($) => !$.optional).length, v = (p = i[i.length - 1]) != null && p.variadic ? 1 / 0 : i.length;
423
- t < c ? r("incomplete", o, `${b} needs ${c} argument(s)`) : t > v && r("argCount", o, `${b} takes ${v} argument(s)`);
422
+ const { args: i, name: v } = e, c = i.filter((p) => !p.optional).length, g = (y = i[i.length - 1]) != null && y.variadic ? 1 / 0 : i.length;
423
+ t < c ? r("incomplete", o, `${v} needs ${c} argument(s)`) : t > g && r("argCount", o, `${v} takes ${g} argument(s)`);
424
424
  };
425
- let P, ie, se;
425
+ let X, ie, se;
426
426
  const ae = (e) => {
427
427
  const t = e.table && (l.get(e.table) ?? (d == null ? void 0 : d.get(e.table)));
428
428
  if (!t || Array.isArray(t)) return;
429
429
  const o = t.columns.find((i) => i.name === e.column);
430
- return o && br(o.type);
431
- }, V = (e) => gr(e, ae, w), oe = u.typeMismatch ?? "warning", ee = (e, t, o) => {
430
+ return o && $r(o.type);
431
+ }, V = (e) => pr(e, ae, w), oe = u.typeMismatch ?? "warning", Y = (e, t, o) => {
432
432
  if (e.type === "literal") {
433
- if (e.value === null || e.value === "" && !e.empty || typeof e.value == "number" && !Ue(e.value) || pr(e.value, t) !== void 0) return;
433
+ if (e.value === null || e.value === "" && !e.empty || typeof e.value == "number" && !Ue(e.value) || br(e.value, t) !== void 0) return;
434
434
  const c = e.value instanceof Date ? "a date" : JSON.stringify(String(e.value));
435
435
  r("typeMismatch", o, `${c} isn't ${z[t]}`, oe);
436
436
  return;
437
437
  }
438
438
  const i = V(e);
439
439
  if (i === void 0 || de(i) === de(t)) return;
440
- const b = `${z[i]} compared with ${z[t]}`;
441
- r("typeMismatch", o, b, oe);
440
+ const v = `${z[i]} compared with ${z[t]}`;
441
+ r("typeMismatch", o, v, oe);
442
442
  }, ce = (e) => e && e.type !== "literal" ? V(e) : void 0, Je = (e, t) => {
443
- const { operator: o, left: i, right: b } = e;
444
- if (!b) return;
445
- const c = (p, $, h) => {
446
- if (p.type !== "param" || !p.relative) return;
447
- const f = ce($);
443
+ const { operator: o, left: i, right: v } = e;
444
+ if (!v) return;
445
+ const c = (y, p, b) => {
446
+ if (y.type !== "param" || !y.relative) return;
447
+ const f = ce(p);
448
448
  if (f === void 0 || f === "date" || f === "dateTime") return;
449
449
  const S = `a relative date compared with ${z[f]}`;
450
- r("typeMismatch", h, S, oe);
450
+ r("typeMismatch", b, S, oe);
451
451
  };
452
- if (c(b, i, `${t}.right`), c(i, b, `${t}.left`), o === "LIKE" || o === "REGEXP") {
453
- const p = ce(i);
454
- if (p !== void 0 && p !== "text") {
455
- const $ = `${o} matches text, not ${z[p]}`;
456
- r("typeMismatch", `${t}.left`, $, oe);
452
+ if (c(v, i, `${t}.right`), c(i, v, `${t}.left`), o === "LIKE" || o === "REGEXP") {
453
+ const y = ce(i);
454
+ if (y !== void 0 && y !== "text") {
455
+ const p = `${o} matches text, not ${z[y]}`;
456
+ r("typeMismatch", `${t}.left`, p, oe);
457
457
  }
458
- if (ee(b, "text", `${t}.right`), o === "REGEXP" && b.type === "literal" && G(b.value))
458
+ if (Y(v, "text", `${t}.right`), o === "REGEXP" && v.type === "literal" && G(v.value))
459
459
  try {
460
- new RegExp(b.value);
461
- } catch ($) {
462
- const h = `not a regular expression: ${$.message}`;
463
- r("invalidPattern", `${t}.right`, h);
460
+ new RegExp(v.value);
461
+ } catch (p) {
462
+ const b = `not a regular expression: ${p.message}`;
463
+ r("invalidPattern", `${t}.right`, b);
464
464
  }
465
465
  return;
466
466
  }
467
- const v = ce(i);
467
+ const g = ce(i);
468
468
  if (o === "IN" || o === "BETWEEN") {
469
- if (v === void 0 || b.type !== "list") return;
470
- b.items.forEach((p, $) => ee(p, v, `${t}.right.items[${$}]`));
469
+ if (g === void 0 || v.type !== "list") return;
470
+ v.items.forEach((y, p) => Y(y, g, `${t}.right.items[${p}]`));
471
471
  return;
472
472
  }
473
- if (v !== void 0) ee(b, v, `${t}.right`);
473
+ if (g !== void 0) Y(v, g, `${t}.right`);
474
474
  else {
475
- const p = ce(b);
476
- p !== void 0 && ee(i, p, `${t}.left`);
475
+ const y = ce(v);
476
+ y !== void 0 && Y(i, y, `${t}.left`);
477
477
  }
478
478
  }, Te = (e) => {
479
479
  const t = e.map(([o]) => o.type === "literal" ? Ge(o) : V(o)).find((o) => o !== void 0);
480
- t !== void 0 && e.forEach(([o, i]) => ee(o, t, i));
480
+ t !== void 0 && e.forEach(([o, i]) => Y(o, t, i));
481
481
  }, R = (e, t, o = !1) => {
482
- if (!I(e) || !G(e.type)) {
482
+ if (!B(e) || !G(e.type)) {
483
483
  r("invalidStructure", t, "an expression is an object with a string `type`");
484
484
  return;
485
485
  }
486
- const i = (c) => r("invalidStructure", t, c), b = (c, v) => {
487
- e[c] !== void 0 && R(e[c], `${t}.${c}`, v);
486
+ const i = (c) => r("invalidStructure", t, c), v = (c, g) => {
487
+ e[c] !== void 0 && R(e[c], `${t}.${c}`, g);
488
488
  };
489
- switch (o && e.type === "exists" && i("EXISTS is a condition, not a value"), Y(e.fromSelect) || i("`fromSelect` is a column's id"), e.type) {
489
+ switch (o && e.type === "exists" && i("EXISTS is a condition, not a value"), Z(e.fromSelect) || i("`fromSelect` is a column's id"), e.type) {
490
490
  case "literal":
491
- if (!Ur(e.value))
491
+ if (!Lr(e.value))
492
492
  i("a literal value is a string, number, boolean, date or null");
493
493
  else if (e.empty !== void 0 && typeof e.empty != "boolean")
494
494
  i("a literal's `empty` is a boolean");
495
495
  else if (pe(e))
496
496
  r("incomplete", t, "a value not filled in");
497
497
  else if (typeof e.value == "number" && !Ue(e.value)) {
498
- const c = `a number with more than ${yr} significant digits is written as another number`;
498
+ const c = `a number with more than ${hr} significant digits is written as another number`;
499
499
  r("tooLong", `${t}.value`, c);
500
500
  } else
501
- O(e.value, hr, `${t}.value`, "a text value");
501
+ O(e.value, gr, `${t}.value`, "a text value");
502
502
  break;
503
503
  case "param":
504
- (!G(e.name) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(e.name)) && i("a param has a plain identifier as its `name`"), e.relative !== void 0 && !Cr(e.relative) && i("a relative date has a `unit` (day, week, month or year), a whole `offset`, and an `anchor` (start or end) only for a week, month or year"), O(e.name, K, `${t}.name`, "a parameter's name");
504
+ (!G(e.name) || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(e.name)) && i("a param has a plain identifier as its `name`"), e.relative !== void 0 && !Gr(e.relative) && i("a relative date has a `unit` (day, week, month or year), a whole `offset`, and an `anchor` (start or end) only for a week, month or year"), O(e.name, K, `${t}.name`, "a parameter's name");
505
505
  break;
506
506
  case "field":
507
- if (!Y(e.table) || !Y(e.column))
507
+ if (!Z(e.table) || !Z(e.column))
508
508
  i("a field has string `table` and `column`");
509
509
  else if (e.column === void 0 || e.column === "")
510
510
  r("incomplete", t, "a field with no column picked");
@@ -512,14 +512,14 @@ function Vr(n, a, u = {}) {
512
512
  r("unqualifiedField", t, `column "${e.column}" names no table`);
513
513
  else if (l.has(e.table)) {
514
514
  const c = l.get(e.table);
515
- if (!(Array.isArray(c) ? c.includes(e.column) : !c || c.columns.some((p) => p.name === e.column))) {
516
- const p = `${e.table}.${e.column}`;
517
- r("unknownColumn", `${t}.column`, `unknown column "${p}"`);
515
+ if (!(Array.isArray(c) ? c.includes(e.column) : !c || c.columns.some((y) => y.name === e.column))) {
516
+ const y = `${e.table}.${e.column}`;
517
+ r("unknownColumn", `${t}.column`, `unknown column "${y}"`);
518
518
  }
519
519
  } else {
520
520
  const c = m.get(e.table);
521
- let v = `table "${e.table}" isn't in the query`;
522
- c ? v = `table "${e.table}" is named "${c}" in the query: use that` : d != null && d.has(e.table) && (v = `table "${e.table}" is the outer query's: only the EXISTS link names it`), r("tableNotInQuery", `${t}.table`, v);
521
+ let g = `table "${e.table}" isn't in the query`;
522
+ c ? g = `table "${e.table}" is named "${c}" in the query: use that` : d != null && d.has(e.table) && (g = `table "${e.table}" is the outer query's: only the EXISTS link names it`), r("tableNotInQuery", `${t}.table`, g);
523
523
  }
524
524
  break;
525
525
  case "function": {
@@ -528,46 +528,46 @@ function Vr(n, a, u = {}) {
528
528
  break;
529
529
  }
530
530
  !u.allowUnknownFunctions && !w[e.name.toUpperCase()] && r("unknownFunction", `${t}.name`, `function "${e.name}" isn't allowed`);
531
- const c = w[e.name.toUpperCase()], v = (h, f) => {
532
- (e.over === !0 || c != null && c.aggregate) && ge(h) && r("misplacedWindow", f, "a window function can't be inside another, or inside an aggregate"), e.over === !0 && ne(h, w) && r("misplacedAggregate", f, "an aggregate can't be inside a window function: sum up in a sub query first");
531
+ const c = w[e.name.toUpperCase()], g = (b, f) => {
532
+ (e.over === !0 || c != null && c.aggregate) && ge(b) && r("misplacedWindow", f, "a window function can't be inside another, or inside an aggregate"), e.over === !0 && ne(b, w) && r("misplacedAggregate", f, "an aggregate can't be inside a window function: sum up in a sub query first");
533
533
  };
534
- u.dialect && (c != null && c.dialects) && !c.dialects.includes(u.dialect) && r("dialectUnsupported", `${t}.name`, `${c.name} isn't in this database`), O(e.name, K, `${t}.name`, "a function's name"), F(c, e.args.length, `${t}.args`), e.distinct !== void 0 && typeof e.distinct != "boolean" && i("a function's `distinct` is a boolean"), e.distinct === !0 && u.dialect === "mssql" && e.name.toUpperCase() === "STRING_AGG" && r("dialectUnsupported", t, "SQL Server's STRING_AGG can't join only different values"), e.args.forEach((h, f) => {
535
- var J, k, A;
534
+ u.dialect && (c != null && c.dialects) && !c.dialects.includes(u.dialect) && r("dialectUnsupported", `${t}.name`, `${c.name} isn't in this database`), O(e.name, K, `${t}.name`, "a function's name"), F(c, e.args.length, `${t}.args`), e.distinct !== void 0 && typeof e.distinct != "boolean" && i("a function's `distinct` is a boolean"), e.distinct === !0 && u.dialect === "mssql" && e.name.toUpperCase() === "STRING_AGG" && r("dialectUnsupported", t, "SQL Server's STRING_AGG can't join only different values"), e.args.forEach((b, f) => {
535
+ var J, A, N;
536
536
  const S = s.length;
537
- R(h, `${t}.args[${f}]`, !0), c && ((J = Z(c, f)) == null ? void 0 : J.kind) === "type-name" && I(h) && O(h.value, mr, `${t}.args[${f}].value`, "a type name"), c && ((k = Z(c, f)) == null ? void 0 : k.kind) === "fixed-text" && I(h) && !(h.type === "literal" && G(h.value)) && i(`${c.name}'s ${Z(c, f).label} is a text value`);
538
- const U = I(h) && h.type === "literal" ? h.value : void 0;
539
- c && ((A = Z(c, f)) == null ? void 0 : A.kind) === "fixed-count" && I(h) && !(Number.isInteger(U) && U >= 0) && i(`${c.name}'s ${Z(c, f).label} is a whole number from 0`);
540
- const D = !s.slice(S).some((B) => B.kind === "invalidStructure");
541
- D && v(h, `${t}.args[${f}]`), c != null && c.aggregate && D && ne(h, w) && r(
537
+ R(b, `${t}.args[${f}]`, !0), c && ((J = ee(c, f)) == null ? void 0 : J.kind) === "type-name" && B(b) && O(b.value, yr, `${t}.args[${f}].value`, "a type name"), c && ((A = ee(c, f)) == null ? void 0 : A.kind) === "fixed-text" && B(b) && !(b.type === "literal" && G(b.value)) && i(`${c.name}'s ${ee(c, f).label} is a text value`);
538
+ const U = B(b) && b.type === "literal" ? b.value : void 0;
539
+ c && ((N = ee(c, f)) == null ? void 0 : N.kind) === "fixed-count" && B(b) && !(Number.isInteger(U) && U >= 0) && i(`${c.name}'s ${ee(c, f).label} is a whole number from 0`);
540
+ const D = !s.slice(S).some((I) => I.kind === "invalidStructure");
541
+ D && g(b, `${t}.args[${f}]`), c != null && c.aggregate && D && ne(b, w) && r(
542
542
  "misplacedAggregate",
543
543
  `${t}.args[${f}]`,
544
544
  "an aggregate can't be inside another: sum up per group in a sub query first"
545
545
  );
546
546
  }), e.over !== void 0 && typeof e.over != "boolean" && i("a function's `over` is a boolean");
547
- const p = e.over === !0, $ = c == null ? void 0 : c.name;
548
- if (p && c && !c.window && i(`${$} isn't a window function`), !p && (c != null && c.window) && i(`${$} is a window function: it has \`over\``), e.partitionBy !== void 0) {
547
+ const y = e.over === !0, p = c == null ? void 0 : c.name;
548
+ if (y && c && !c.window && i(`${p} isn't a window function`), !y && (c != null && c.window) && i(`${p} is a window function: it has \`over\``), e.partitionBy !== void 0) {
549
549
  if (!Array.isArray(e.partitionBy)) {
550
550
  i("a function's `partitionBy` is an array");
551
551
  break;
552
552
  }
553
- p || i("only a window call (`over`) takes a `partitionBy`"), e.partitionBy.forEach((h, f) => {
553
+ y || i("only a window call (`over`) takes a `partitionBy`"), e.partitionBy.forEach((b, f) => {
554
554
  const S = `${t}.partitionBy[${f}]`, U = s.length;
555
- R(h, S, !0), s.slice(U).some((D) => D.kind === "invalidStructure") || v(h, S);
555
+ R(b, S, !0), s.slice(U).some((D) => D.kind === "invalidStructure") || g(b, S);
556
556
  });
557
557
  }
558
- if (p && !(Array.isArray(e.orderBy) && e.orderBy.length > 0) && r("unorderedWindow", t, "a window function needs an ORDER BY"), e.orderBy !== void 0) {
558
+ if (y && !(Array.isArray(e.orderBy) && e.orderBy.length > 0) && r("unorderedWindow", t, "a window function needs an ORDER BY"), e.orderBy !== void 0) {
559
559
  if (!Array.isArray(e.orderBy)) {
560
560
  i("a function's `orderBy` is an array");
561
561
  break;
562
562
  }
563
- e.name.toUpperCase() !== "STRING_AGG" && !p && i("only STRING_AGG and window calls take an `orderBy`"), e.orderBy.forEach((h, f) => {
563
+ e.name.toUpperCase() !== "STRING_AGG" && !y && i("only STRING_AGG and window calls take an `orderBy`"), e.orderBy.forEach((b, f) => {
564
564
  const S = `${t}.orderBy[${f}]`;
565
- if (!I(h) || h.direction !== "asc" && h.direction !== "desc") {
565
+ if (!B(b) || b.direction !== "asc" && b.direction !== "desc") {
566
566
  r("invalidStructure", S, "a sort key has an `expression` and a `direction`");
567
567
  return;
568
568
  }
569
569
  const U = s.length;
570
- R(h.expression, `${S}.expression`, !0), !s.slice(U).some((D) => D.kind === "invalidStructure") && (!p && ne(h.expression, w) && r("misplacedAggregate", `${S}.expression`, "an aggregate can't be inside another"), p && v(h.expression, `${S}.expression`), e.distinct === !0 && u.dialect === "postgres" && !te(h.expression, e.args[0]) && r(
570
+ R(b.expression, `${S}.expression`, !0), !s.slice(U).some((D) => D.kind === "invalidStructure") && (!y && ne(b.expression, w) && r("misplacedAggregate", `${S}.expression`, "an aggregate can't be inside another"), y && g(b.expression, `${S}.expression`), e.distinct === !0 && u.dialect === "postgres" && !te(b.expression, e.args[0]) && r(
571
571
  "dialectUnsupported",
572
572
  `${S}.expression`,
573
573
  "PostgreSQL orders STRING_AGG of different values by the value only"
@@ -577,26 +577,38 @@ function Vr(n, a, u = {}) {
577
577
  break;
578
578
  }
579
579
  case "binary": {
580
- e.operator !== void 0 && !fr.includes(e.operator) && i(`unknown operator ${JSON.stringify(e.operator)}`), e.operator === "REGEXP" && u.dialect === "mssql" && r("dialectUnsupported", t, "SQL Server has no REGEXP");
580
+ e.operator !== void 0 && !dr.includes(e.operator) && i(`unknown operator ${JSON.stringify(e.operator)}`), e.operator === "REGEXP" && u.dialect === "mssql" && r("dialectUnsupported", t, "SQL Server has no REGEXP");
581
581
  const c = s.length;
582
582
  R(e.left, `${t}.left`, !0);
583
- const v = s.slice(c).some((p) => p.kind === "incomplete");
584
- if (dr(e.operator))
583
+ const g = s.slice(c).some((y) => y.kind === "incomplete");
584
+ if (mr(e.operator))
585
585
  e.right !== void 0 && i(`${String(e.operator)} takes no right side`);
586
586
  else if (e.right === void 0)
587
587
  r("incomplete", `${t}.right`, "a comparison with nothing to compare to");
588
- else if (I(e.right) && e.right.type === "literal" && e.right.value === null && e.operator !== "IS NOT DISTINCT FROM")
588
+ else if (B(e.right) && e.right.type === "literal" && e.right.value === null && e.operator !== "IS NOT DISTINCT FROM")
589
589
  r("incomplete", `${t}.right`, "compared with NULL (never true): use IS NULL");
590
- else if (I(e.right) && e.right.type === "subquery")
590
+ else if (B(e.right) && e.right.type === "subquery")
591
591
  e.operator === "IN" ? ie(e.right, `${t}.right`) : r("invalidStructure", `${t}.right`, "a sub query is only IN's right side");
592
592
  else if (e.operator === "BETWEEN") {
593
- const { right: p } = e, $ = I(p) && p.type === "list" && Array.isArray(p.items) ? p.items : void 0;
594
- ($ == null ? void 0 : $.length) !== 2 ? r("invalidStructure", `${t}.right`, "BETWEEN takes its two bounds as a list (expr.between)") : $.forEach((h, f) => {
593
+ const { right: y } = e, p = B(y) && y.type === "list" && Array.isArray(y.items) ? y.items : void 0;
594
+ (p == null ? void 0 : p.length) !== 2 ? r("invalidStructure", `${t}.right`, "BETWEEN takes its two bounds as a list (expr.between)") : p.forEach((b, f) => {
595
595
  const S = `${t}.right.items[${f}]`;
596
- I(h) && h.type === "literal" && h.value === null ? r("incomplete", S, "a bound of NULL (never true)") : v && pe(h) || R(h, S, !0);
596
+ B(b) && b.type === "literal" && b.value === null ? r("incomplete", S, "a bound of NULL (never true)") : g && pe(b) || R(b, S, !0);
597
597
  });
598
- } else I(e.right) && e.right.type === "list" ? e.operator === "IN" ? se(e.right, `${t}.right`) : r("invalidStructure", `${t}.right`, "a list is only IN's or BETWEEN's right side") : e.operator === "IN" ? r("invalidStructure", `${t}.right`, "IN takes a list (expr.list) or a sub query") : v && pe(e.right) || R(e.right, `${t}.right`, !0);
599
- s.slice(c).some((p) => p.kind === "invalidStructure") || Je(e, t);
598
+ } else B(e.right) && e.right.type === "list" ? e.operator === "IN" ? se(e.right, `${t}.right`) : r("invalidStructure", `${t}.right`, "a list is only IN's or BETWEEN's right side") : e.operator === "IN" ? r("invalidStructure", `${t}.right`, "IN takes a list (expr.list) or a sub query") : g && pe(e.right) || R(e.right, `${t}.right`, !0);
599
+ s.slice(c).some((y) => y.kind === "invalidStructure") || Je(e, t);
600
+ break;
601
+ }
602
+ case "arithmetic": {
603
+ fr.includes(e.operator) || i("a calculation's operator is +, -, * or /");
604
+ const c = s.length;
605
+ ["left", "right"].forEach((g) => {
606
+ const y = e[g], p = `${t}.${g}`;
607
+ y === void 0 ? r("incomplete", p, "a calculation with a side missing") : B(y) && Cr.has(y.type) ? r("invalidStructure", p, "a calculation's side is a value, not a condition") : R(y, p, !0);
608
+ }), s.slice(c).some((g) => g.kind === "invalidStructure") || ["left", "right"].forEach((g) => {
609
+ const y = e[g];
610
+ y !== void 0 && Y(y, "number", `${t}.${g}`);
611
+ });
600
612
  break;
601
613
  }
602
614
  case "logical":
@@ -604,43 +616,43 @@ function Vr(n, a, u = {}) {
604
616
  i("a logical node has an `operands` array");
605
617
  break;
606
618
  }
607
- e.operands.length === 0 && r("incomplete", t, "an empty AND/OR group"), e.operands.forEach((c, v) => R(c, `${t}.operands[${v}]`));
619
+ e.operands.length === 0 && r("incomplete", t, "an empty AND/OR group"), e.operands.forEach((c, g) => R(c, `${t}.operands[${g}]`));
608
620
  break;
609
621
  case "not": {
610
622
  R(e.operand, `${t}.operand`);
611
623
  const { operand: c } = e;
612
- I(c) && c.type === "binary" && c.operator === "IN" && I(c.right) && c.right.type === "subquery" && r("notInSubquery", t, "NOT IN keeps no rows at all if the sub query gives a NULL: NOT EXISTS doesn't", "warning");
624
+ B(c) && c.type === "binary" && c.operator === "IN" && B(c.right) && c.right.type === "subquery" && r("notInSubquery", t, "NOT IN keeps no rows at all if the sub query gives a NULL: NOT EXISTS doesn't", "warning");
613
625
  break;
614
626
  }
615
627
  case "if": {
616
- ["condition", "then"].forEach((v) => {
617
- e[v] === void 0 && r("incomplete", `${t}.${v}`, `an IF with no ${v}`);
628
+ ["condition", "then"].forEach((g) => {
629
+ e[g] === void 0 && r("incomplete", `${t}.${g}`, `an IF with no ${g}`);
618
630
  });
619
631
  const c = s.length;
620
- b("condition", !1), b("then", !0), b("else", !0), s.slice(c).some((v) => v.kind === "invalidStructure") || Te(
621
- ["then", "else"].filter((v) => e[v] !== void 0).map((v) => [e[v], `${t}.${v}`])
632
+ v("condition", !1), v("then", !0), v("else", !0), s.slice(c).some((g) => g.kind === "invalidStructure") || Te(
633
+ ["then", "else"].filter((g) => e[g] !== void 0).map((g) => [e[g], `${t}.${g}`])
622
634
  );
623
635
  break;
624
636
  }
625
637
  case "case": {
626
638
  const c = s.length;
627
- b("subject", !0), Array.isArray(e.branches) ? (e.branches.length === 0 && r("incomplete", t, "a CASE with no WHEN"), e.branches.forEach((p, $) => {
628
- if (!I(p)) {
629
- const h = `${t}.branches[${$}]`;
630
- r("invalidStructure", h, "a branch has `when` and `then`");
639
+ v("subject", !0), Array.isArray(e.branches) ? (e.branches.length === 0 && r("incomplete", t, "a CASE with no WHEN"), e.branches.forEach((y, p) => {
640
+ if (!B(y)) {
641
+ const b = `${t}.branches[${p}]`;
642
+ r("invalidStructure", b, "a branch has `when` and `then`");
631
643
  return;
632
644
  }
633
- R(p.when, `${t}.branches[${$}].when`, e.subject !== void 0), R(p.then, `${t}.branches[${$}].then`, !0);
645
+ R(y.when, `${t}.branches[${p}].when`, e.subject !== void 0), R(y.then, `${t}.branches[${p}].then`, !0);
634
646
  })) : i("a case node has a `branches` array");
635
- const v = s.length;
636
- b("else", !0), Array.isArray(e.branches) && s.slice(c).concat(s.slice(v)).every((p) => p.kind !== "invalidStructure") && Te([
637
- ...e.branches.map((p, $) => [p.then, `${t}.branches[${$}].then`]),
647
+ const g = s.length;
648
+ v("else", !0), Array.isArray(e.branches) && s.slice(c).concat(s.slice(g)).every((y) => y.kind !== "invalidStructure") && Te([
649
+ ...e.branches.map((y, p) => [y.then, `${t}.branches[${p}].then`]),
638
650
  ...e.else === void 0 ? [] : [[e.else, `${t}.else`]]
639
651
  ]);
640
652
  break;
641
653
  }
642
654
  case "exists":
643
- P(e, t);
655
+ X(e, t);
644
656
  break;
645
657
  case "subquery":
646
658
  i("a sub query is only IN's right side");
@@ -656,65 +668,65 @@ function Vr(n, a, u = {}) {
656
668
  Array.isArray(e.items) ? e.items.length === 0 ? r("incomplete", t, "IN with no values") : e.items.forEach((o, i) => R(o, `${t}.items[${i}]`, !0)) : r("invalidStructure", t, "a list has an `items` array");
657
669
  }, ie = (e, t) => {
658
670
  const { id: o, query: i } = e;
659
- if (!G(o) || o === "" || !I(i)) {
671
+ if (!G(o) || o === "" || !B(i)) {
660
672
  r("invalidStructure", t, "a sub query has a non-empty string `id` and a `query`");
661
673
  return;
662
674
  }
663
- y.has(o) && r("duplicateId", `${t}.id`, `the id "${o}" is used twice`), y.add(o);
664
- const b = { inQuery: l, aliasOf: m, outerTables: d };
675
+ h.has(o) && r("duplicateId", `${t}.id`, `the id "${o}" is used twice`), h.add(o);
676
+ const v = { inQuery: l, aliasOf: m, outerTables: d };
665
677
  l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = void 0;
666
678
  const c = s.length;
667
- le(i, `${t}.query`, !1), { inQuery: l, aliasOf: m, outerTables: d } = b;
668
- const v = s.length === c;
669
- (Array.isArray(i.select) ? i.select : []).length !== 1 && r("subqueryColumns", `${t}.query.select`, "a sub query after IN picks exactly one column to compare with"), v && ue(i, `${t}.query`);
670
- }, P = (e, t) => {
679
+ le(i, `${t}.query`, !1), { inQuery: l, aliasOf: m, outerTables: d } = v;
680
+ const g = s.length === c;
681
+ (Array.isArray(i.select) ? i.select : []).length !== 1 && r("subqueryColumns", `${t}.query.select`, "a sub query after IN picks exactly one column to compare with"), g && ue(i, `${t}.query`);
682
+ }, X = (e, t) => {
671
683
  const { query: o, link: i } = e;
672
- if (!I(o) || !Array.isArray(o.joins)) {
684
+ if (!B(o) || !Array.isArray(o.joins)) {
673
685
  r("invalidStructure", `${t}.query`, "an EXISTS has a `query` with `from` and `joins`");
674
686
  return;
675
687
  }
676
- const b = { inQuery: l, aliasOf: m, outerTables: d };
677
- l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = b.inQuery, [
688
+ const v = { inQuery: l, aliasOf: m, outerTables: d };
689
+ l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = v.inQuery, [
678
690
  [o.from, `${t}.query.from`],
679
- ...o.joins.map(($, h) => [$, `${t}.query.joins[${h}]`])
680
- ].forEach(([$, h], f) => {
691
+ ...o.joins.map((p, b) => [p, `${t}.query.joins[${b}]`])
692
+ ].forEach(([p, b], f) => {
681
693
  const S = new Set(l.keys());
682
- q($, h, f > 0), f > 0 && I($) && _($.joinType, `${h}.joinType`), [...l.keys()].filter((U) => !S.has(U) && b.inQuery.has(U)).forEach((U) => r(
694
+ q(p, b, f > 0), f > 0 && B(p) && _(p.joinType, `${b}.joinType`), [...l.keys()].filter((U) => !S.has(U) && v.inQuery.has(U)).forEach((U) => r(
683
695
  "ambiguousTable",
684
- `${h}.table`,
696
+ `${b}.table`,
685
697
  `"${U}" is a table of the query around it too: give it an alias`
686
698
  ));
687
699
  });
688
- const v = [
689
- ...o.joins.map(($, h) => [
690
- I($) ? $.on : void 0,
691
- `${t}.query.joins[${h}].on`
700
+ const g = [
701
+ ...o.joins.map((p, b) => [
702
+ B(p) ? p.on : void 0,
703
+ `${t}.query.joins[${b}].on`
692
704
  ]),
693
705
  [o.where, `${t}.query.where`]
694
706
  ];
695
- v.forEach(([$, h]) => {
696
- $ !== void 0 && R($, h);
697
- }), o.joins.forEach(($, h) => {
698
- I($) && $.joinType !== "cross" && $.on === void 0 && r("incomplete", `${t}.query.joins[${h}].on`, "a join with no ON condition");
707
+ g.forEach(([p, b]) => {
708
+ p !== void 0 && R(p, b);
709
+ }), o.joins.forEach((p, b) => {
710
+ B(p) && p.joinType !== "cross" && p.on === void 0 && r("incomplete", `${t}.query.joins[${b}].on`, "a join with no ON condition");
699
711
  });
700
- const p = { inQuery: l, aliasOf: m };
701
- l = new Map([...b.inQuery, ...p.inQuery]), m = new Map([...b.aliasOf, ...p.aliasOf]), d = void 0, R(i, `${t}.link`), { inQuery: l, aliasOf: m, outerTables: d } = b, [...v, [i, `${t}.link`]].forEach(([$, h]) => {
702
- I($) && ne($, w) && r("misplacedAggregate", h, "an aggregate (SUM, COUNT, …) can't be used here"), I($) && W($, h);
712
+ const y = { inQuery: l, aliasOf: m };
713
+ l = new Map([...v.inQuery, ...y.inQuery]), m = new Map([...v.aliasOf, ...y.aliasOf]), d = void 0, R(i, `${t}.link`), { inQuery: l, aliasOf: m, outerTables: d } = v, [...g, [i, `${t}.link`]].forEach(([p, b]) => {
714
+ B(p) && ne(p, w) && r("misplacedAggregate", b, "an aggregate (SUM, COUNT, …) can't be used here"), B(p) && W(p, b);
703
715
  });
704
716
  };
705
717
  const re = (e, t, o = []) => {
706
718
  const i = new Set(o);
707
- e.forEach((b, c) => {
708
- !I(b) || !G(b.id) || b.id === "" ? r("invalidStructure", `${t}[${c}]`, "every entry has a non-empty string id") : i.has(b.id) ? r("duplicateId", `${t}[${c}].id`, `id "${b.id}" is used twice`) : i.add(b.id);
719
+ e.forEach((v, c) => {
720
+ !B(v) || !G(v.id) || v.id === "" ? r("invalidStructure", `${t}[${c}]`, "every entry has a non-empty string id") : i.has(v.id) ? r("duplicateId", `${t}[${c}].id`, `id "${v.id}" is used twice`) : i.add(v.id);
709
721
  });
710
722
  }, xe = (e, t, o) => Array.isArray(e[t]) ? e[t] : (e[t] !== void 0 && r("invalidStructure", o, `\`${t}\` is an array`), []), le = (e, t, o) => {
711
723
  const i = (f) => t ? `${t}.${f}` : f;
712
724
  q(e.from, i("from"), !0);
713
- const { from: b } = e, c = I(b) && b.query !== void 0 ? b.id : void 0;
714
- I(b) && b.query !== void 0 && (!G(c) || c === "") && r("invalidStructure", i("from"), "a derived table has a non-empty string id");
715
- const v = Array.isArray(e.joins) ? e.joins : [];
716
- Array.isArray(e.joins) || r("invalidStructure", i("joins"), "`joins` is an array"), v.forEach((f, S) => q(f, i(`joins[${S}]`), !0)), re(v, i("joins"), G(c) ? [c] : []), v.forEach((f, S) => {
717
- if (I(f)) {
725
+ const { from: v } = e, c = B(v) && v.query !== void 0 ? v.id : void 0;
726
+ B(v) && v.query !== void 0 && (!G(c) || c === "") && r("invalidStructure", i("from"), "a derived table has a non-empty string id");
727
+ const g = Array.isArray(e.joins) ? e.joins : [];
728
+ Array.isArray(e.joins) || r("invalidStructure", i("joins"), "`joins` is an array"), g.forEach((f, S) => q(f, i(`joins[${S}]`), !0)), re(g, i("joins"), G(c) ? [c] : []), g.forEach((f, S) => {
729
+ if (B(f)) {
718
730
  if (Ce.includes(f.joinType))
719
731
  _(f.joinType, i(`joins[${S}].joinType`));
720
732
  else {
@@ -724,235 +736,235 @@ function Vr(n, a, u = {}) {
724
736
  f.joinType !== "cross" && (f.on !== void 0 ? R(f.on, i(`joins[${S}].on`)) : r("incomplete", i(`joins[${S}].on`), "a join with no ON condition"));
725
737
  }
726
738
  }), e.where !== void 0 && R(e.where, i("where"));
727
- const p = Array.isArray(e.select) ? e.select : [];
728
- Array.isArray(e.select) || r("invalidStructure", i("select"), "`select` is an array"), re(p, i("select")), p.forEach((f, S) => {
729
- I(f) && (O(f.alias, K, i(`select[${S}].alias`), "an alias"), Y(f.alias) || r("invalidStructure", i(`select[${S}].alias`), "an alias is a string"), R(f.expression, i(`select[${S}].expression`), !0));
739
+ const y = Array.isArray(e.select) ? e.select : [];
740
+ Array.isArray(e.select) || r("invalidStructure", i("select"), "`select` is an array"), re(y, i("select")), y.forEach((f, S) => {
741
+ B(f) && (O(f.alias, K, i(`select[${S}].alias`), "an alias"), Z(f.alias) || r("invalidStructure", i(`select[${S}].alias`), "an alias is a string"), R(f.expression, i(`select[${S}].expression`), !0));
730
742
  });
731
- const $ = xe(e, "groupBy", i("groupBy"));
732
- if (re($, i("groupBy")), $.forEach((f, S) => {
733
- I(f) && (Y(f.fromSelect) || r("invalidStructure", i(`groupBy[${S}].fromSelect`), "`fromSelect` is a column's id"), R(f.expression, i(`groupBy[${S}].expression`), !0));
743
+ const p = xe(e, "groupBy", i("groupBy"));
744
+ if (re(p, i("groupBy")), p.forEach((f, S) => {
745
+ B(f) && (Z(f.fromSelect) || r("invalidStructure", i(`groupBy[${S}].fromSelect`), "`fromSelect` is a column's id"), R(f.expression, i(`groupBy[${S}].expression`), !0));
734
746
  }), e.having !== void 0 && R(e.having, i("having")), e.distinct !== void 0 && typeof e.distinct != "boolean" && r("invalidStructure", i("distinct"), "`distinct` is a boolean"), !o) {
735
747
  ["orderBy", "limit", "offset", "shared"].forEach((f) => {
736
748
  e[f] !== void 0 && r("invalidStructure", i(f), `a derived table has no \`${f}\``);
737
749
  });
738
750
  return;
739
751
  }
740
- const h = xe(e, "orderBy", "orderBy");
741
- re(h, "orderBy"), h.forEach((f, S) => {
742
- I(f) && (f.direction !== "asc" && f.direction !== "desc" && r("invalidStructure", `orderBy[${S}].direction`, 'a sort direction is "asc" or "desc"'), R(f.expression, `orderBy[${S}].expression`, !0));
752
+ const b = xe(e, "orderBy", "orderBy");
753
+ re(b, "orderBy"), b.forEach((f, S) => {
754
+ B(f) && (f.direction !== "asc" && f.direction !== "desc" && r("invalidStructure", `orderBy[${S}].direction`, 'a sort direction is "asc" or "desc"'), R(f.expression, `orderBy[${S}].expression`, !0));
743
755
  }), ["limit", "offset"].forEach((f) => {
744
756
  const S = e[f];
745
757
  S !== void 0 && !(Number.isInteger(S) && S >= 0) ? r("invalidStructure", f, `\`${f}\` is a non-negative integer`) : S !== void 0 && !Number.isSafeInteger(S) && r("tooLong", f, `\`${f}\` is past ${Number.MAX_SAFE_INTEGER}, which is exact`);
746
758
  });
747
- }, Xe = (e, t, o) => {
748
- const i = `${t}.query`, { union: b } = e;
749
- if (!Array.isArray(b) || b.length < 1 || typeof e.all != "boolean") {
759
+ }, Pe = (e, t, o) => {
760
+ const i = `${t}.query`, { union: v } = e;
761
+ if (!Array.isArray(v) || v.length < 1 || typeof e.all != "boolean") {
750
762
  r("invalidStructure", i, "a union has one or more branches in `union`, and a boolean `all`"), T(o, `${t}.alias`), l.set(o, void 0);
751
763
  return;
752
764
  }
753
765
  let c = [];
754
- const v = [];
755
- let p = !0;
756
- b.forEach(($, h) => {
757
- const f = `${i}.union[${h}]`;
758
- if (!I($)) {
759
- r("invalidStructure", f, "a union's branch is a query"), p = !1;
766
+ const g = [];
767
+ let y = !0;
768
+ v.forEach((p, b) => {
769
+ const f = `${i}.union[${b}]`;
770
+ if (!B(p)) {
771
+ r("invalidStructure", f, "a union's branch is a query"), y = !1;
760
772
  return;
761
773
  }
762
774
  const S = { inQuery: l, aliasOf: m, outerTables: d };
763
775
  l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = void 0;
764
776
  const U = s.length;
765
- le($, f, !1);
766
- const D = s.length === U, J = (Array.isArray($.select) ? $.select : []).filter(I), k = D ? J.map((B) => B.expression.type === "literal" ? Ge(B.expression) : V(B.expression)) : [];
777
+ le(p, f, !1);
778
+ const D = s.length === U, J = (Array.isArray(p.select) ? p.select : []).filter(B), A = D ? J.map((I) => I.expression.type === "literal" ? Ge(I.expression) : V(I.expression)) : [];
767
779
  if ({ inQuery: l, aliasOf: m, outerTables: d } = S, !D) {
768
- p = !1;
780
+ y = !1;
769
781
  return;
770
782
  }
771
- ue($, f);
772
- const A = J.map((B) => be(B));
783
+ ue(p, f);
784
+ const N = J.map((I) => be(I));
773
785
  if (J.length === 0) {
774
- r("unionColumns", `${f}.select`, "a union's branch names its columns"), p = !1;
786
+ r("unionColumns", `${f}.select`, "a union's branch names its columns"), y = !1;
775
787
  return;
776
788
  }
777
- if (h === 0)
778
- c = A, A.forEach((B, C) => {
779
- if (B) return;
789
+ if (b === 0)
790
+ c = N, N.forEach((I, C) => {
791
+ if (I) return;
780
792
  r("derivedColumnName", `${f}.select[${C}]`, "a union's column needs an alias: nothing outside could name it");
781
- }), A.forEach((B, C) => {
782
- B && A.indexOf(B) !== C && r("derivedColumnName", `${f}.select[${C}]`, `two columns named "${B}"`);
793
+ }), N.forEach((I, C) => {
794
+ I && N.indexOf(I) !== C && r("derivedColumnName", `${f}.select[${C}]`, `two columns named "${I}"`);
783
795
  });
784
- else if (A.length !== c.length) {
785
- const B = `${A.length} column(s), where the first branch has ${c.length}`;
786
- r("unionColumns", `${f}.select`, B);
796
+ else if (N.length !== c.length) {
797
+ const I = `${N.length} column(s), where the first branch has ${c.length}`;
798
+ r("unionColumns", `${f}.select`, I);
787
799
  return;
788
800
  } else
789
- A.forEach((B, C) => {
790
- if (B === c[C]) return;
791
- const L = `column ${C + 1} is "${String(c[C])}" in the first branch, not "${String(B)}"`;
801
+ N.forEach((I, C) => {
802
+ if (I === c[C]) return;
803
+ const L = `column ${C + 1} is "${String(c[C])}" in the first branch, not "${String(I)}"`;
792
804
  r("unionColumns", `${f}.select[${C}]`, L);
793
805
  });
794
- k.forEach((B, C) => {
795
- if (B === void 0) return;
796
- const L = v[C];
806
+ A.forEach((I, C) => {
807
+ if (I === void 0) return;
808
+ const L = g[C];
797
809
  if (L === void 0)
798
- v[C] = B;
799
- else if (de(L) !== de(B)) {
800
- const Q = `column "${String(c[C])}" is ${z[B]} here, ${z[L]} in a branch before`;
810
+ g[C] = I;
811
+ else if (de(L) !== de(I)) {
812
+ const Q = `column "${String(c[C])}" is ${z[I]} here, ${z[L]} in a branch before`;
801
813
  r("unionTypes", `${f}.select[${C}].expression`, Q);
802
814
  }
803
815
  });
804
- }), T(o, `${t}.alias`), l.set(o, p ? c.filter(($) => $ !== void 0) : void 0);
816
+ }), T(o, `${t}.alias`), l.set(o, y ? c.filter((p) => p !== void 0) : void 0);
805
817
  };
806
818
  M = (e, t) => {
807
819
  const { query: o, alias: i } = e;
808
- if (e.table === void 0 && I(o) && o.union !== void 0 && G(i) && i !== "") {
809
- O(i, K, `${t}.alias`, "an alias"), Xe(o, t, i);
820
+ if (e.table === void 0 && B(o) && o.union !== void 0 && G(i) && i !== "") {
821
+ O(i, K, `${t}.alias`, "an alias"), Pe(o, t, i);
810
822
  return;
811
823
  }
812
- if (e.table !== void 0 || !I(o) || !G(i) || i === "") {
824
+ if (e.table !== void 0 || !B(o) || !G(i) || i === "") {
813
825
  r("invalidStructure", t, "a derived table has a `query` and an `alias`, and no `table`"), G(i) && i !== "" && (T(i, `${t}.alias`), l.set(i, void 0));
814
826
  return;
815
827
  }
816
828
  O(i, K, `${t}.alias`, "an alias");
817
- const b = { inQuery: l, aliasOf: m, outerTables: d };
829
+ const v = { inQuery: l, aliasOf: m, outerTables: d };
818
830
  l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = void 0;
819
831
  const c = s.length;
820
- le(o, `${t}.query`, !1), { inQuery: l, aliasOf: m, outerTables: d } = b;
821
- const v = Array.isArray(o.select) ? o.select : [], p = [], $ = (S, U) => {
822
- p.includes(S) ? r("derivedColumnName", U, `two columns named "${S}"`) : p.push(S);
832
+ le(o, `${t}.query`, !1), { inQuery: l, aliasOf: m, outerTables: d } = v;
833
+ const g = Array.isArray(o.select) ? o.select : [], y = [], p = (S, U) => {
834
+ y.includes(S) ? r("derivedColumnName", U, `two columns named "${S}"`) : y.push(S);
823
835
  };
824
- v.forEach((S, U) => {
825
- if (!I(S) || !I(S.expression)) return;
836
+ g.forEach((S, U) => {
837
+ if (!B(S) || !B(S.expression)) return;
826
838
  const D = be(S);
827
- D ? $(D, `${t}.query.select[${U}]`) : r("derivedColumnName", `${t}.query.select[${U}]`, "a derived table's column needs an alias: nothing outside could name it");
839
+ D ? p(D, `${t}.query.select[${U}]`) : r("derivedColumnName", `${t}.query.select[${U}]`, "a derived table's column needs an alias: nothing outside could name it");
828
840
  });
829
- const h = s.length === c;
830
- h && v.length === 0 && De(g, o, E).forEach((S) => $(S.name, `${t}.query.select`)), T(i, `${t}.alias`), l.set(i, h || v.length > 0 ? p : void 0), h && ue(o, `${t}.query`);
841
+ const b = s.length === c;
842
+ b && g.length === 0 && De($, o, E).forEach((S) => p(S.name, `${t}.query.select`)), T(i, `${t}.alias`), l.set(i, b || g.length > 0 ? y : void 0), b && ue(o, `${t}.query`);
831
843
  const { drillAcross: f } = e;
832
- f !== void 0 && !(I(f) && typeof f.synced == "boolean" && Number.isInteger(f.copied) && f.copied >= 0) && r("invalidStructure", `${t}.drillAcross`, "`drillAcross` has a boolean `synced` and a non-negative integer `copied`");
844
+ f !== void 0 && !(B(f) && typeof f.synced == "boolean" && Number.isInteger(f.copied) && f.copied >= 0) && r("invalidStructure", `${t}.drillAcross`, "`drillAcross` has a boolean `synced` and a non-negative integer `copied`");
833
845
  };
834
846
  const ue = (e, t) => {
835
- var h, f, S, U, D, J;
836
- const o = (k) => t ? `${t}.${k}` : k, i = or(e);
847
+ var b, f, S, U, D, J;
848
+ const o = (A) => t ? `${t}.${A}` : A, i = or(e);
837
849
  if (i) {
838
- const k = e.joins.findIndex((A) => (A.table ?? X(A)) === i.table);
850
+ const A = e.joins.findIndex((N) => (N.table ?? P(N)) === i.table);
839
851
  r(
840
852
  "joinOrder",
841
- o(`joins[${k}].on`),
853
+ o(`joins[${A}].on`),
842
854
  `the join condition of "${i.table}" uses "${i.needs}", which is joined after it`
843
855
  );
844
856
  }
845
- const b = (k, A) => {
846
- ne(k, w) && r("misplacedAggregate", A, "an aggregate (SUM, COUNT, …) can't be used here"), W(k, A);
857
+ const v = (A, N) => {
858
+ ne(A, w) && r("misplacedAggregate", N, "an aggregate (SUM, COUNT, …) can't be used here"), W(A, N);
847
859
  };
848
- if (b(e.where, o("where")), e.joins.forEach((k, A) => {
849
- k.joinType !== "cross" && b(k.on, o(`joins[${A}].on`));
850
- }), (h = e.groupBy) == null || h.forEach((k, A) => b(k.expression, o(`groupBy[${A}].expression`))), W(e.having, o("having")), he(e, w)) {
851
- const k = (A, B) => {
852
- ge(A.expression) && r("groupedWindow", B, "a window function can't be in a grouped query: work it out in a sub query, and group the rows around it");
860
+ if (v(e.where, o("where")), e.joins.forEach((A, N) => {
861
+ A.joinType !== "cross" && v(A.on, o(`joins[${N}].on`));
862
+ }), (b = e.groupBy) == null || b.forEach((A, N) => v(A.expression, o(`groupBy[${N}].expression`))), W(e.having, o("having")), he(e, w)) {
863
+ const A = (N, I) => {
864
+ ge(N.expression) && r("groupedWindow", I, "a window function can't be in a grouped query: work it out in a sub query, and group the rows around it");
853
865
  };
854
- e.select.forEach((A, B) => k(A, o(`select[${B}].expression`))), (f = e.orderBy) == null || f.forEach((A, B) => k(A, `orderBy[${B}].expression`));
866
+ e.select.forEach((N, I) => A(N, o(`select[${I}].expression`))), (f = e.orderBy) == null || f.forEach((N, I) => A(N, `orderBy[${I}].expression`));
855
867
  }
856
- const c = Ye(e, w), v = "isn't a group key or an aggregate (SUM, COUNT, …)";
857
- if (c.selectAll && r("notGrouped", o("select"), "a grouped query has to pick its columns, not *"), e.select.forEach((k, A) => {
858
- c.select.includes(k.id) && r("notGrouped", o(`select[${A}].expression`), `this column ${v}`);
859
- }), (S = e.orderBy) == null || S.forEach((k, A) => {
860
- c.orderBy.includes(k.id) && r("notGrouped", `orderBy[${A}].expression`, `this sort key ${v}`);
861
- }), c.having && r("notGrouped", o("having"), `a column in this condition ${v}`), u.dialect === "mssql") {
862
- const k = [], A = (L, Q) => {
868
+ const c = Ye(e, w), g = "isn't a group key or an aggregate (SUM, COUNT, …)";
869
+ if (c.selectAll && r("notGrouped", o("select"), "a grouped query has to pick its columns, not *"), e.select.forEach((A, N) => {
870
+ c.select.includes(A.id) && r("notGrouped", o(`select[${N}].expression`), `this column ${g}`);
871
+ }), (S = e.orderBy) == null || S.forEach((A, N) => {
872
+ c.orderBy.includes(A.id) && r("notGrouped", `orderBy[${N}].expression`, `this sort key ${g}`);
873
+ }), c.having && r("notGrouped", o("having"), `a column in this condition ${g}`), u.dialect === "mssql") {
874
+ const A = [], N = (L, Q) => {
863
875
  const [H, fe] = L.length <= Q.length ? [L, Q] : [Q, L];
864
876
  return H.every((je, Me) => je.direction === fe[Me].direction && te(je.expression, fe[Me].expression));
865
- }, B = (L) => {
877
+ }, I = (L) => {
866
878
  var H;
867
- return [...L.type === "function" && ((H = L.orderBy) != null && H.length) ? [L.orderBy] : [], ...ke(L).flatMap(B)];
879
+ return [...L.type === "function" && ((H = L.orderBy) != null && H.length) ? [L.orderBy] : [], ...ke(L).flatMap(I)];
868
880
  }, C = (L, Q) => {
869
- B(L).forEach((H) => {
870
- k.some((fe) => !A(fe, H)) && r(
881
+ I(L).forEach((H) => {
882
+ A.some((fe) => !N(fe, H)) && r(
871
883
  "dialectUnsupported",
872
884
  Q,
873
885
  "SQL Server sorts every STRING_AGG of a query alike: this one's order differs"
874
- ), k.push(H);
886
+ ), A.push(H);
875
887
  });
876
888
  };
877
889
  e.select.forEach((L, Q) => C(L.expression, o(`select[${Q}].expression`))), e.having && C(e.having, o("having")), (U = e.orderBy) == null || U.forEach((L, Q) => C(L.expression, `orderBy[${Q}].expression`));
878
890
  }
879
891
  if (u.allowUnknownFunctions && he(e, w)) {
880
- const k = (A, B) => {
881
- Ze(A, w) && r(
892
+ const A = (N, I) => {
893
+ Ze(N, w) && r(
882
894
  "unknownAggregate",
883
- B,
895
+ I,
884
896
  "a function the editor doesn't know: it isn't made a group key, in case it sums rows up — declare it in `functions` (`aggregate: true` if it does)",
885
897
  "warning"
886
898
  );
887
899
  };
888
- e.select.forEach((A, B) => k(A.expression, o(`select[${B}].expression`))), (D = e.orderBy) == null || D.forEach((A, B) => k(A.expression, `orderBy[${B}].expression`)), k(e.having, o("having"));
900
+ e.select.forEach((N, I) => A(N.expression, o(`select[${I}].expression`))), (D = e.orderBy) == null || D.forEach((N, I) => A(N.expression, `orderBy[${I}].expression`)), A(e.having, o("having"));
889
901
  }
890
- e.joins.forEach((k, A) => {
891
- if (k.joinType === "cross" || !k.on) return;
892
- const B = cr(k.on), C = X(k), L = Se(e).slice(0, A + 1).map(X);
893
- B.some((Q) => Q !== C && !L.includes(Q)) || B.includes(C) && B.some((Q) => L.includes(Q)) || r(
902
+ e.joins.forEach((A, N) => {
903
+ if (A.joinType === "cross" || !A.on) return;
904
+ const I = cr(A.on), C = P(A), L = Se(e).slice(0, N + 1).map(P);
905
+ I.some((Q) => Q !== C && !L.includes(Q)) || I.includes(C) && I.some((Q) => L.includes(Q)) || r(
894
906
  "unlinkedJoin",
895
- o(`joins[${A}].on`),
907
+ o(`joins[${N}].on`),
896
908
  `the join condition of "${C}" doesn't compare it with a table joined before it: every row meets every row it lets through`,
897
909
  "warning"
898
910
  );
899
- }), e.joins.forEach((k, A) => {
911
+ }), e.joins.forEach((A, N) => {
900
912
  var C;
901
- if (!k.query || !((C = k.drillAcross) != null && C.synced)) return;
902
- lr(g, e, k) || r(
913
+ if (!A.query || !((C = A.drillAcross) != null && C.synced)) return;
914
+ lr($, e, A) || r(
903
915
  "drillAcrossOutOfStep",
904
- o(`joins[${A}]`),
905
- `"${k.alias}" is kept in step with the query but doesn't match its grouping`
916
+ o(`joins[${N}]`),
917
+ `"${A.alias}" is kept in step with the query but doesn't match its grouping`
906
918
  );
907
- const B = Ee(k.query) ? void 0 : k.query.from.table;
908
- B !== void 0 && ur(g, e, B) && r(
919
+ const I = Ee(A.query) ? void 0 : A.query.from.table;
920
+ I !== void 0 && ur($, e, I) && r(
909
921
  "drillAcrossFilterMixed",
910
- o(`joins[${A}]`),
911
- `a condition of the query names both what "${k.alias}" shares and what it doesn't: it isn't applied to it`,
922
+ o(`joins[${N}]`),
923
+ `a condition of the query names both what "${A.alias}" shares and what it doesn't: it isn't applied to it`,
912
924
  "warning"
913
925
  );
914
- }), e.joins.forEach((k, A) => {
915
- k.joinType !== "cross" || k.query && Qe(k.query, w) || r(
926
+ }), e.joins.forEach((A, N) => {
927
+ A.joinType !== "cross" || A.query && Qe(A.query, w) || r(
916
928
  "crossJoin",
917
- o(`joins[${A}]`),
918
- `every row of "${X(k)}" meets every row of the query: they multiply`,
929
+ o(`joins[${N}]`),
930
+ `every row of "${P(A)}" meets every row of the query: they multiply`,
919
931
  "warning"
920
932
  );
921
933
  });
922
- const p = Tr(e, g), $ = (k) => r(
934
+ const y = xr(e, $), p = (A) => r(
923
935
  "fanOut",
924
- k,
925
- `${p.tables.map((A) => `"${A}"`).join(", ")} rows repeat in this join: a sum, average or count of their columns comes out too high`,
936
+ A,
937
+ `${y.tables.map((N) => `"${N}"`).join(", ")} rows repeat in this join: a sum, average or count of their columns comes out too high`,
926
938
  "warning"
927
939
  );
928
- e.select.forEach((k, A) => {
929
- p.select.includes(k.id) && $(o(`select[${A}].expression`));
930
- }), p.having && $(o("having")), (J = e.orderBy) == null || J.forEach((k, A) => {
931
- p.orderBy.includes(k.id) && $(`orderBy[${A}].expression`);
940
+ e.select.forEach((A, N) => {
941
+ y.select.includes(A.id) && p(o(`select[${N}].expression`));
942
+ }), y.having && p(o("having")), (J = e.orderBy) == null || J.forEach((A, N) => {
943
+ y.orderBy.includes(A.id) && p(`orderBy[${N}].expression`);
932
944
  });
933
945
  };
934
946
  a.shared !== void 0 && !Array.isArray(a.shared) && r("invalidStructure", "shared", "`shared` is an array"), re(E, "shared");
935
947
  const Be = /* @__PURE__ */ new Set();
936
948
  if (E.forEach((e, t) => {
937
- if (!I(e)) return;
949
+ if (!B(e)) return;
938
950
  const o = `shared[${t}]`, { name: i } = e;
939
951
  !G(i) || i === "" ? r("invalidStructure", `${o}.name`, "a shared query has a non-empty string `name`") : (O(i, K, `${o}.name`, "a name"), Be.has(i) && r("duplicateTableName", `${o}.name`, `two shared queries named "${i}"`), Be.add(i));
940
- const b = G(i) && i !== "" ? i : o, c = { inQuery: l, aliasOf: m, outerTables: d };
941
- l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = void 0, M({ query: e.query, alias: b }, o);
942
- const v = l.get(b);
943
- ({ inQuery: l, aliasOf: m, outerTables: d } = c), G(e.id) && x.set(e.id, Array.isArray(v) ? v : void 0);
952
+ const v = G(i) && i !== "" ? i : o, c = { inQuery: l, aliasOf: m, outerTables: d };
953
+ l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = void 0, M({ query: e.query, alias: v }, o);
954
+ const g = l.get(v);
955
+ ({ inQuery: l, aliasOf: m, outerTables: d } = c), G(e.id) && x.set(e.id, Array.isArray(g) ? g : void 0);
944
956
  }), le(a, "", !0), s.length === 0) {
945
957
  const e = a;
946
958
  if (ue(e, ""), u.requireLimit) {
947
959
  const { max: o } = u.requireLimit === !0 ? {} : u.requireLimit, i = he(e, w) && !((Ie = e.groupBy) != null && Ie.length);
948
960
  e.limit === void 0 && !i ? r("noLimit", "limit", "no LIMIT: the query reads every row", "warning") : o !== void 0 && e.limit !== void 0 && e.limit > o && r("limitTooHigh", "limit", `LIMIT ${e.limit} is above ${o}`, "warning");
949
961
  }
950
- sr(e, g).forEach((o) => {
962
+ sr(e, $).forEach((o) => {
951
963
  r("paramConflict", "", `param "${o}" is compared against columns of different types`);
952
964
  }), ar(e).forEach((o) => {
953
965
  r("paramConflict", "", `param "${o}" stands for two different relative dates`);
954
966
  });
955
- const t = xr(e);
967
+ const t = Br(e);
956
968
  (Oe = e.orderBy) == null || Oe.forEach((o, i) => {
957
969
  t.includes(o.id) && r(
958
970
  "distinctSort",
@@ -961,27 +973,27 @@ function Vr(n, a, u = {}) {
961
973
  );
962
974
  });
963
975
  }
964
- s.some((e) => e.kind === "invalidStructure") || Ir(n, a).forEach((e) => r(
976
+ s.some((e) => e.kind === "invalidStructure") || Or(n, a).forEach((e) => r(
965
977
  "joinOnlyColumn",
966
978
  e.map((t, o) => typeof t == "number" ? `[${t}]` : `${o ? "." : ""}${t}`).join(""),
967
979
  "a column for joining tables only, used outside a join's condition"
968
980
  )), E.forEach((e, t) => {
969
- !I(e) || !G(e.id) || j.has(e.id) || r("unusedShared", `shared[${t}]`, "a shared query used nowhere", "warning");
981
+ !B(e) || !G(e.id) || j.has(e.id) || r("unusedShared", `shared[${t}]`, "a shared query used nowhere", "warning");
970
982
  });
971
- const Pe = u.hideWarnings ?? [];
972
- return s.filter((e) => e.severity === "error" || !Pe.includes(e.kind));
983
+ const Xe = u.hideWarnings ?? [];
984
+ return s.filter((e) => e.severity === "error" || !Xe.includes(e.kind));
973
985
  }
974
- function Yr(n, a = {
975
- relativeDate: $r
986
+ function en(n, a = {
987
+ relativeDate: vr
976
988
  }) {
977
989
  return a.relativeDate(n);
978
990
  }
979
- function Zr({ unit: n, offset: a, anchor: u }) {
991
+ function rn({ unit: n, offset: a, anchor: u }) {
980
992
  if (n === "day" && a === 0) return "today";
981
993
  const s = a < 0 ? `minus_${-a}` : `plus_${a}`;
982
994
  return [n, a === 0 ? "0" : s, u].filter(Boolean).join("_");
983
995
  }
984
- const Gr = {
996
+ const _r = {
985
997
  from: "from",
986
998
  joins: "from",
987
999
  where: "where",
@@ -993,44 +1005,46 @@ const Gr = {
993
1005
  limit: "order",
994
1006
  offset: "order"
995
1007
  };
996
- function en(n, a, u = {}) {
997
- const { schema: s, functions: r } = u, g = (y, E) => typeof E == "number" ? y == null ? void 0 : y[E] : void 0, w = (y) => {
1008
+ function nn(n, a, u = {}) {
1009
+ const { schema: s, functions: r } = u, $ = (h, E) => typeof E == "number" ? h == null ? void 0 : h[E] : void 0, w = (h) => {
998
1010
  var E;
999
- return y.alias || s && y.table !== void 0 && ((E = $e(s, y.table)) == null ? void 0 : E.label) || y.table || "";
1000
- }, l = (y, E) => {
1011
+ return h.alias || s && h.table !== void 0 && ((E = $e(s, h.table)) == null ? void 0 : E.label) || h.table || "";
1012
+ }, l = (h, E) => {
1001
1013
  var M;
1002
- if (!y || E.length === 0) return [];
1003
- const [N, x, j] = E;
1004
- switch (y.type) {
1014
+ if (!h || E.length === 0) return [];
1015
+ const [k, x, j] = E;
1016
+ switch (h.type) {
1005
1017
  case "logical": {
1006
- const T = g(y.operands, x);
1018
+ const T = $(h.operands, x);
1007
1019
  return T ? [{ kind: "condition", number: x + 1 }, ...l(T, E.slice(2))] : [];
1008
1020
  }
1009
1021
  case "not":
1010
- return [{ kind: "not" }, ...l(y.operand, E.slice(1))];
1022
+ return [{ kind: "not" }, ...l(h.operand, E.slice(1))];
1011
1023
  case "binary": {
1012
- if (N !== "left" && N !== "right") return [];
1013
- const T = { kind: "side", side: N }, _ = y[N];
1014
- return (_ == null ? void 0 : _.type) === "subquery" && x === "query" ? [T, { kind: "inSubQuery" }, ...O(_.query, E.slice(2))] : (_ == null ? void 0 : _.type) === "list" && x === "items" && g(_.items, j) ? [T, { kind: "listItem", number: j + 1 }] : [T, ...l(_, E.slice(1))];
1024
+ if (k !== "left" && k !== "right") return [];
1025
+ const T = { kind: "side", side: k }, _ = h[k];
1026
+ return (_ == null ? void 0 : _.type) === "subquery" && x === "query" ? [T, { kind: "inSubQuery" }, ...O(_.query, E.slice(2))] : (_ == null ? void 0 : _.type) === "list" && x === "items" && $(_.items, j) ? [T, { kind: "listItem", number: j + 1 }] : [T, ...l(_, E.slice(1))];
1015
1027
  }
1028
+ case "arithmetic":
1029
+ return k !== "left" && k !== "right" ? [] : [{ kind: "side", side: k }, ...l(h[k], E.slice(1))];
1016
1030
  case "function": {
1017
- const T = { kind: "function", name: y.name };
1018
- if (N === "args" && g(y.args, x)) {
1019
- const W = er(y.name, r), F = W && ((M = Z(W, x)) == null ? void 0 : M.label);
1031
+ const T = { kind: "function", name: h.name };
1032
+ if (k === "args" && $(h.args, x)) {
1033
+ const W = er(h.name, r), F = W && ((M = ee(W, x)) == null ? void 0 : M.label);
1020
1034
  return [
1021
1035
  T,
1022
1036
  { kind: "argument", number: x + 1, ...F && { label: F } },
1023
- ...l(y.args[x], E.slice(2))
1037
+ ...l(h.args[x], E.slice(2))
1024
1038
  ];
1025
1039
  }
1026
- const _ = N === "partitionBy" ? g(y.partitionBy, x) : void 0;
1040
+ const _ = k === "partitionBy" ? $(h.partitionBy, x) : void 0;
1027
1041
  if (_)
1028
1042
  return [
1029
1043
  T,
1030
1044
  { kind: "partitionKey", number: x + 1 },
1031
1045
  ...l(_, E.slice(2))
1032
1046
  ];
1033
- const q = N === "orderBy" ? g(y.orderBy, x) : void 0;
1047
+ const q = k === "orderBy" ? $(h.orderBy, x) : void 0;
1034
1048
  return q ? [
1035
1049
  T,
1036
1050
  { kind: "sortKey", number: x + 1 },
@@ -1038,68 +1052,68 @@ function en(n, a, u = {}) {
1038
1052
  ] : [T];
1039
1053
  }
1040
1054
  case "if":
1041
- return N === "condition" || N === "then" || N === "else" ? [{ kind: "if", part: N }, ...l(y[N], E.slice(1))] : [];
1055
+ return k === "condition" || k === "then" || k === "else" ? [{ kind: "if", part: k }, ...l(h[k], E.slice(1))] : [];
1042
1056
  case "case": {
1043
- if (N === "subject" || N === "else")
1044
- return [{ kind: "case", part: N }, ...l(y[N], E.slice(1))];
1045
- const T = N === "branches" ? g(y.branches, x) : void 0;
1057
+ if (k === "subject" || k === "else")
1058
+ return [{ kind: "case", part: k }, ...l(h[k], E.slice(1))];
1059
+ const T = k === "branches" ? $(h.branches, x) : void 0;
1046
1060
  return !T || j !== "when" && j !== "then" ? [] : [
1047
1061
  { kind: "case", part: j, branch: x + 1 },
1048
1062
  ...l(T[j], E.slice(3))
1049
1063
  ];
1050
1064
  }
1051
1065
  case "exists": {
1052
- const T = { kind: "exists", table: w(y.query.from) };
1053
- return N === "link" ? [T, { kind: "existsLink" }] : N === "query" ? [T, ...O(y.query, E.slice(1))] : [T];
1066
+ const T = { kind: "exists", table: w(h.query.from) };
1067
+ return k === "link" ? [T, { kind: "existsLink" }] : k === "query" ? [T, ...O(h.query, E.slice(1))] : [T];
1054
1068
  }
1055
1069
  default:
1056
1070
  return [];
1057
1071
  }
1058
- }, m = (y, E) => {
1059
- if (y.query && E[0] === "query") return d(y.alias, y.query, E.slice(1));
1060
- const N = y.query ? { kind: "subQuery", name: y.alias } : { kind: "table", name: w(y) };
1061
- return E[0] === "on" ? [N, { kind: "joinCondition" }, ...l(y.on, E.slice(1))] : [N];
1072
+ }, m = (h, E) => {
1073
+ if (h.query && E[0] === "query") return d(h.alias, h.query, E.slice(1));
1074
+ const k = h.query ? { kind: "subQuery", name: h.alias } : { kind: "table", name: w(h) };
1075
+ return E[0] === "on" ? [k, { kind: "joinCondition" }, ...l(h.on, E.slice(1))] : [k];
1062
1076
  };
1063
- function d(y, E, N, x = "subQuery") {
1064
- const j = { kind: x, name: y };
1065
- if (!Ee(E)) return [j, ...O(E, N)];
1066
- const M = N[0] === "union" ? g(_e(E), N[1]) : void 0;
1077
+ function d(h, E, k, x = "subQuery") {
1078
+ const j = { kind: x, name: h };
1079
+ if (!Ee(E)) return [j, ...O(E, k)];
1080
+ const M = k[0] === "union" ? $(_e(E), k[1]) : void 0;
1067
1081
  if (!M) return [j];
1068
- const T = N[1] + 1;
1069
- return [j, { kind: "unionQuery", number: T }, ...O(M, N.slice(2))];
1082
+ const T = k[1] + 1;
1083
+ return [j, { kind: "unionQuery", number: T }, ...O(M, k.slice(2))];
1070
1084
  }
1071
- function O(y, E) {
1085
+ function O(h, E) {
1072
1086
  var q, W;
1073
- const [N, x, j] = E, M = Gr[String(N)];
1087
+ const [k, x, j] = E, M = _r[String(k)];
1074
1088
  if (!M) return [];
1075
1089
  const T = { kind: "section", section: M }, _ = E.slice(3);
1076
- switch (N) {
1090
+ switch (k) {
1077
1091
  // A sub query is a place of its own: no "From Tables" before it.
1078
1092
  case "from":
1079
- return y.from.query ? x === "query" ? d(y.from.alias, y.from.query, E.slice(2)) : [{ kind: "subQuery", name: y.from.alias }] : [T, { kind: "table", name: w(y.from) }];
1093
+ return h.from.query ? x === "query" ? d(h.from.alias, h.from.query, E.slice(2)) : [{ kind: "subQuery", name: h.from.alias }] : [T, { kind: "table", name: w(h.from) }];
1080
1094
  case "joins": {
1081
- const F = g(y.joins, x);
1095
+ const F = $(h.joins, x);
1082
1096
  return F ? F.query ? m(F, E.slice(2)) : [T, ...m(F, E.slice(2))] : [T];
1083
1097
  }
1084
1098
  case "where":
1085
1099
  case "having":
1086
- return [T, ...l(y[N], E.slice(1))];
1100
+ return [T, ...l(h[k], E.slice(1))];
1087
1101
  case "select": {
1088
- const F = g(y.select, x);
1102
+ const F = $(h.select, x);
1089
1103
  if (!F) return [T];
1090
- const { expression: P, alias: ie } = F, se = P.type === "field" && s && P.table !== void 0 ? (W = (q = $e(s, P.table)) == null ? void 0 : q.columns.find((V) => V.name === P.column)) == null ? void 0 : W.label : void 0, ae = ie || se;
1104
+ const { expression: X, alias: ie } = F, se = X.type === "field" && s && X.table !== void 0 ? (W = (q = $e(s, X.table)) == null ? void 0 : q.columns.find((V) => V.name === X.column)) == null ? void 0 : W.label : void 0, ae = ie || se;
1091
1105
  return [
1092
1106
  T,
1093
1107
  { kind: "column", number: x + 1, ...ae && { name: ae } },
1094
- ...j === "expression" ? l(P, _) : []
1108
+ ...j === "expression" ? l(X, _) : []
1095
1109
  ];
1096
1110
  }
1097
1111
  case "groupBy":
1098
1112
  case "orderBy": {
1099
- const F = g(y[N], x);
1113
+ const F = $(h[k], x);
1100
1114
  return F ? [
1101
1115
  T,
1102
- { kind: N === "groupBy" ? "groupKey" : "sortKey", number: x + 1 },
1116
+ { kind: k === "groupBy" ? "groupKey" : "sortKey", number: x + 1 },
1103
1117
  ...j === "expression" ? l(F.expression, _) : []
1104
1118
  ] : [T];
1105
1119
  }
@@ -1108,34 +1122,34 @@ function en(n, a, u = {}) {
1108
1122
  }
1109
1123
  }
1110
1124
  if (a[0] === "shared") {
1111
- const y = g(n.shared, a[1]);
1112
- return y ? a[2] === "query" ? d(y.name, y.query, a.slice(3), "sharedQuery") : [{ kind: "sharedQuery", name: y.name }] : [];
1125
+ const h = $(n.shared, a[1]);
1126
+ return h ? a[2] === "query" ? d(h.name, h.query, a.slice(3), "sharedQuery") : [{ kind: "sharedQuery", name: h.name }] : [];
1113
1127
  }
1114
1128
  return O(n, a);
1115
1129
  }
1116
1130
  export {
1117
- Hr as Q,
1118
- Sr as S,
1119
- wr as a,
1120
- qr as b,
1121
- Jr as c,
1122
- Qr as d,
1123
- Rr as e,
1124
- kr as f,
1125
- Nr as g,
1131
+ Vr as Q,
1132
+ Er as S,
1133
+ Sr as a,
1134
+ Pr as b,
1135
+ Xr as c,
1136
+ Fr as d,
1137
+ Dr as e,
1138
+ Ar as f,
1139
+ Tr as g,
1126
1140
  we as h,
1127
- Pr as i,
1128
- Dr as j,
1129
- Yr as k,
1130
- zr as l,
1131
- Wr as m,
1132
- en as n,
1133
- Kr as o,
1134
- Zr as p,
1135
- Or as q,
1136
- Xr as r,
1137
- Fr as s,
1138
- xr as t,
1139
- Tr as u,
1140
- Vr as v
1141
+ Hr as i,
1142
+ Wr as j,
1143
+ en as k,
1144
+ Yr as l,
1145
+ Jr as m,
1146
+ nn as n,
1147
+ zr as o,
1148
+ rn as p,
1149
+ jr as q,
1150
+ Kr as r,
1151
+ qr as s,
1152
+ Br as t,
1153
+ xr as u,
1154
+ Zr as v
1141
1155
  };