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