@nongt/visql-core 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,119 +1,153 @@
1
- var pt = Object.defineProperty;
2
- var At = (t, e, r) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var b = (t, e, r) => At(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { q as L, F as mt, G as gt, g as M, o as H, d as G, t as V, h as ht, w as W, H as Dt, k as Nt, b as Ot, i as St } from "./schema-z95dxLxu.js";
5
- import { ag as D, aA as J, aB as bt, aC as Rt, aD as It, aj as Ct, V as Lt, ap as Mt, aE as A, al as wt, a7 as Ft, aF as qt, aG as K, $ as Ut } from "./issueLocation-CWUdTtCh.js";
6
- import { s as z } from "./calendarDate-CYlr9TvX.js";
7
- class vt extends Error {
8
- constructor(r, n, s, i) {
9
- const a = i ? `"${n}" (as "${i}")` : `"${n}"`;
1
+ var qt = Object.defineProperty;
2
+ var Ut = (t, e, r) => e in t ? qt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var M = (t, e, r) => Ut(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { q as U, g as B, F as vt, G as Bt, o as K, d as nt, t as ft, h as jt, w as lt, H as _t, k as Ht, b as Yt, i as Pt } from "./schema-z95dxLxu.js";
5
+ import { ag as R, aA as k, aB as Gt, aC as xt, aD as kt, aj as Qt, V as Xt, ap as Vt, aE as A, al as Wt, a7 as Jt, aF as Kt, aG as $t, $ as zt } from "./issueLocation-CWUdTtCh.js";
6
+ import { s as Et } from "./calendarDate-CYlr9TvX.js";
7
+ class Zt extends Error {
8
+ constructor(r, n, s, o) {
9
+ const a = o ? `"${n}" (as "${o}")` : `"${n}"`;
10
10
  super(`scopeQuery: the query at ${r.length ? r.join(".") : "the top"} reads ${a} but can't reach "${s}", which the condition names`);
11
11
  /** Where the body is, as keys into the query (validateQuery's
12
12
  * `pathSegments` style). */
13
- b(this, "path");
13
+ M(this, "path");
14
14
  /** The table it reads that needs scope. */
15
- b(this, "table");
15
+ M(this, "table");
16
16
  /** The alias that copy of the table goes by, when it has one (a self
17
17
  * join reads a table more than once, issue 216). */
18
- b(this, "alias");
19
- this.name = "ScopeError", this.path = r, this.table = n, i && (this.alias = i);
18
+ M(this, "alias");
19
+ this.name = "ScopeError", this.path = r, this.table = n, o && (this.alias = o);
20
20
  }
21
21
  }
22
- const Y = (t) => Object.prototype.toString.call(t) === "[object Object]", dt = (t) => Array.isArray(t.joins) && Y(t.from);
23
- function w(t, e, r) {
22
+ const H = (t) => Object.prototype.toString.call(t) === "[object Object]", yt = (t) => Array.isArray(t.joins) && H(t.from);
23
+ function j(t, e, r) {
24
24
  if (Array.isArray(t)) {
25
- const a = t.map((o, f) => w(o, [...e, f], r));
26
- return a.every((o, f) => o === t[f]) ? t : a;
25
+ const a = t.map((i, c) => j(i, [...e, c], r));
26
+ return a.every((i, c) => i === t[c]) ? t : a;
27
27
  }
28
- if (!Y(t)) return t;
28
+ if (!H(t)) return t;
29
29
  let n = !1;
30
- const s = Object.entries(t).map(([a, o]) => {
31
- const f = w(o, [...e, a], r);
32
- return f !== o && (n = !0), [a, f];
33
- }), i = n ? Object.fromEntries(s) : t;
34
- return dt(i) ? r(i, e) : i;
30
+ const s = Object.entries(t).map(([a, i]) => {
31
+ const c = j(i, [...e, a], r);
32
+ return c !== i && (n = !0), [a, c];
33
+ }), o = n ? Object.fromEntries(s) : t;
34
+ return yt(o) ? r(o, e) : o;
35
35
  }
36
- const Z = (t, e) => L(t).flatMap((r) => r.table !== void 0 && e.requires(r.table) ? [{ table: r.table, ...r.alias ? { alias: r.alias } : {}, ref: r.alias ?? r.table }] : []), Bt = (t) => L(t).flatMap((e) => {
36
+ const pt = (t, e) => U(t).flatMap((r) => r.table !== void 0 && e.requires(r.table) ? [{ table: r.table, ...r.alias ? { alias: r.alias } : {}, ref: r.alias ?? r.table }] : []), Tt = (t) => U(t).flatMap((e) => {
37
37
  const r = e.alias ?? e.table;
38
38
  return r === void 0 ? [] : [r];
39
39
  });
40
- function v(t, e) {
40
+ function Q(t, e) {
41
41
  if (t.type === "field") {
42
42
  const r = t.table && e.get(t.table);
43
43
  return r ? { ...t, table: r } : t;
44
44
  }
45
- return H(t, (r) => v(r, e));
46
- }
47
- const tt = (t) => t ? t.type === "logical" && t.operator === "AND" ? t.operands : [t] : [];
48
- function jt(t, e) {
49
- var s, i;
50
- if (e.type !== "binary" || ((s = e.left) == null ? void 0 : s.type) !== "field" || ((i = e.right) == null ? void 0 : i.type) !== "field")
51
- return !1;
52
- const r = [e.left.table, e.right.table], n = { ...e, left: e.right, right: e.left };
53
- return t.joins.some((a) => r.includes(a.alias ?? a.table) && tt(a.on).some((o) => M(o, e) || M(o, n)));
54
- }
55
- function et(t, e, r, n) {
56
- const s = /* @__PURE__ */ new Map([[r.table, r.ref]]), i = [], a = new Set(Bt(e));
57
- let o;
58
- return J(n.condition).forEach((f) => {
59
- if (o || s.has(f)) return;
60
- const u = mt(t, [...s.keys()], f);
61
- if (!u) {
62
- o = f;
63
- return;
64
- }
65
- u.forEach((c) => {
66
- const l = gt(t, [...s.keys()], c);
67
- if (!l) return;
68
- const $ = (m) => v(l.on, new Map([...s, [c, m]])), y = L(e).flatMap((m) => m.table === c ? [m.alias ?? c] : []).find((m) => jt(e, $(m)));
69
- if (y) {
70
- s.set(c, y);
71
- return;
72
- }
73
- let T = c;
74
- for (let m = 2; a.has(T); m += 1) T = `${c}_${m}`;
75
- a.add(T), s.set(c, T), i.push({
76
- id: bt(),
77
- table: c,
78
- ...T !== c ? { alias: T } : {},
79
- joinType: l.joinType,
80
- on: $(T)
81
- });
82
- });
83
- }), { joins: i, condition: v(n.condition, s), ...o ? { missing: o } : {} };
45
+ return K(t, (r) => Q(r, e));
46
+ }
47
+ const At = (t) => t ? t.type === "logical" && t.operator === "AND" ? t.operands : [t] : [], te = (t) => t.joinType === "inner" || t.joinType === "left";
48
+ function ee(t, e, r, n, s) {
49
+ const o = e.type === "binary" && e.left && e.right ? { ...e, left: e.right, right: e.left } : e, a = { forward: !1, back: !1 };
50
+ return t.joins.forEach((i) => {
51
+ const c = i.alias ?? i.table;
52
+ if (c !== r && c !== n || !te(i) || !At(i.on).some((f) => B(f, e) || B(f, o))) return;
53
+ const u = i.joinType === "inner";
54
+ c === r ? (a.forward = !0, a.back || (a.back = u)) : (a.back = !0, a.forward || (a.forward = u || s));
55
+ }), a;
56
+ }
57
+ const st = (t) => t.some((e, r) => t.slice(0, r).every((n) => n.forward) && t.slice(r).every((n) => n.back)) || t.every((e) => e.forward);
58
+ function mt(t, e, r, n, s = new Set(Tt(e))) {
59
+ const o = k(n.condition), a = U(e), i = (c) => {
60
+ const u = /* @__PURE__ */ new Map([[r.table, r.ref]]), f = /* @__PURE__ */ new Map(), l = [], $ = new Set(s), p = (m) => {
61
+ const O = f.get(m);
62
+ return O ? [...p(O.ref), O.tie] : [];
63
+ }, g = (m, O, P) => {
64
+ if (O === m.length) return st(p(u.get(P)));
65
+ const h = m[O], L = Bt(t, [...u.keys()], h);
66
+ if (!L) return !1;
67
+ const Z = u.get(k(L.on).find((y) => y !== h)), tt = (y) => Q(L.on, new Map([...u, [h, y]])), et = o.includes(h), rt = (y, S) => {
68
+ u.set(h, y), f.set(y, { ref: Z, tie: S });
69
+ }, Ft = (y, S) => (rt(y, S), st(p(y)) && g(m, O + 1, P) ? !0 : (u.delete(h), f.delete(y), !1));
70
+ if (a.some((y) => {
71
+ if (y.table !== h) return !1;
72
+ const S = y.alias ?? h, G = ee(e, tt(S), Z, S, et);
73
+ return (G.forward || G.back) && Ft(S, G);
74
+ })) return !0;
75
+ if (!c) return !1;
76
+ let N = h;
77
+ for (let y = 2; $.has(N); y += 1) N = `${h}_${y}`;
78
+ return $.add(N), rt(N, { back: !0, forward: L.joinType === "inner" || et }), l.push({
79
+ id: Gt(),
80
+ table: h,
81
+ ...N !== h ? { alias: N } : {},
82
+ joinType: L.joinType,
83
+ on: tt(N)
84
+ }), g(m, O + 1, P);
85
+ };
86
+ let v;
87
+ if (o.every((m) => {
88
+ if (v || u.has(m)) return !0;
89
+ const O = vt(t, [...u.keys()], m);
90
+ return O ? g(O, 0, m) : (v = m, !0);
91
+ }))
92
+ return $.forEach((m) => s.add(m)), { joins: l, condition: Q(n.condition, u), ...v ? { missing: v } : {} };
93
+ };
94
+ return i(!1) ?? i(!0);
84
95
  }
85
- function rt(t, e) {
86
- return tt(t).some((r) => M(r, e));
96
+ function gt(t, e) {
97
+ return At(t).some((r) => B(r, e));
87
98
  }
88
- function _t(t, e) {
99
+ function re(t, e) {
89
100
  return (t == null ? void 0 : t.type) === "logical" && t.operator === "AND" ? { ...t, operands: [...t.operands, e] } : t ? { type: "logical", operator: "AND", operands: [t, e] } : e;
90
101
  }
91
- function x(t, e, r, n) {
92
- return Z(e, r).reduce((s, i) => {
93
- const a = et(t, s, i, r);
94
- if (a.missing) throw new vt(n, i.table, a.missing, i.alias);
95
- const o = rt(s.where, a.condition);
96
- return a.joins.length === 0 && o ? s : {
97
- ...s,
98
- joins: [...s.joins, ...a.joins],
99
- where: o ? s.where : _t(s.where, a.condition)
102
+ function ot(t, e, r, n, s) {
103
+ return pt(e, r).reduce((o, a) => {
104
+ const i = mt(t, o, a, r, s);
105
+ if (i.missing) throw new Zt(n, a.table, i.missing, a.alias);
106
+ const c = gt(o.where, i.condition);
107
+ return i.joins.length === 0 && c ? o : {
108
+ ...o,
109
+ joins: [...o.joins, ...i.joins],
110
+ where: c ? o.where : re(o.where, i.condition)
100
111
  };
101
112
  }, e);
102
113
  }
103
- function me(t, e, r) {
104
- const n = x(t, e, r, []), s = D(t, e, n), i = w(s, [], (a, o) => o.length === 0 ? a : x(t, a, r, o));
105
- return D(t, s, i);
114
+ function it(t) {
115
+ const e = /* @__PURE__ */ new Map(), r = (n, s, o, a) => {
116
+ if (Array.isArray(n)) {
117
+ n.forEach((c, u) => r(c, [...s, u], void 0, a));
118
+ return;
119
+ }
120
+ if (!H(n)) return;
121
+ let i = a;
122
+ yt(n) && (i = o ?? /* @__PURE__ */ new Set(), e.set(JSON.stringify(s), i), Tt(n).forEach((c) => i.add(c))), Object.entries(n).forEach(([c, u]) => r(
123
+ u,
124
+ [...s, c],
125
+ n.type === "exists" && c === "query" ? i : void 0,
126
+ i
127
+ ));
128
+ };
129
+ return r(t, [], void 0, /* @__PURE__ */ new Set()), e;
106
130
  }
107
- function ge(t, e, r) {
108
- if (!Y(t) || !Array.isArray(t.tables))
131
+ function ve(t, e, r) {
132
+ const n = ot(
133
+ t,
134
+ e,
135
+ r,
136
+ [],
137
+ it(e).get("[]")
138
+ ), s = R(t, e, n), o = it(s), a = j(s, [], (i, c) => c.length === 0 ? i : ot(t, i, r, c, o.get(JSON.stringify(c))));
139
+ return R(t, s, a);
140
+ }
141
+ function Be(t, e, r) {
142
+ if (!H(t) || !Array.isArray(t.tables))
109
143
  throw new TypeError("unscopedBodies takes (schema, query, rule) since 0.4.0");
110
144
  const n = [];
111
- return w(e, [], (s, i) => (Z(s, r).forEach((a) => {
112
- const o = et(t, s, a, r);
113
- (o.missing || o.joins.length > 0 || !rt(s.where, o.condition)) && n.push({ path: i, table: a.table, ...a.alias ? { alias: a.alias } : {} });
145
+ return j(e, [], (s, o) => (pt(s, r).forEach((a) => {
146
+ const i = mt(t, s, a, r);
147
+ (i.missing || i.joins.length > 0 || !gt(s.where, i.condition)) && n.push({ path: o, table: a.table, ...a.alias ? { alias: a.alias } : {} });
114
148
  }), s)), n;
115
149
  }
116
- const Ht = (t) => typeof t == "object" && t !== null && !(t instanceof Date), Q = {
150
+ const ne = (t) => typeof t == "object" && t !== null && !(t instanceof Date), at = {
117
151
  /** A column: `expr.field('orders', 'status')`. */
118
152
  field: (t, e) => ({ type: "field", table: t, column: e }),
119
153
  /** A literal value, written into the SQL (as a bound parameter by
@@ -180,7 +214,7 @@ const Ht = (t) => typeof t == "object" && t !== null && !(t instanceof Date), Q
180
214
  type: "binary",
181
215
  operator: "IN",
182
216
  left: t,
183
- right: Array.isArray(e) ? Q.list(...e) : e
217
+ right: Array.isArray(e) ? at.list(...e) : e
184
218
  }),
185
219
  /** `left BETWEEN low AND high` (issue 169), both bounds included: each a
186
220
  * value or an expression (a param, a relative date). NOT BETWEEN:
@@ -189,13 +223,13 @@ const Ht = (t) => typeof t == "object" && t !== null && !(t instanceof Date), Q
189
223
  type: "binary",
190
224
  operator: "BETWEEN",
191
225
  left: t,
192
- right: Q.list(e, r)
226
+ right: at.list(e, r)
193
227
  }),
194
228
  /** IN's values: each a value (`expr.list(1, 2)`) or an expression
195
229
  * (`expr.list(expr.param('a'), expr.param('b'))`). */
196
230
  list: (...t) => ({
197
231
  type: "list",
198
- items: t.map((e) => Ht(e) ? e : { type: "literal", value: e })
232
+ items: t.map((e) => ne(e) ? e : { type: "literal", value: e })
199
233
  }),
200
234
  /** A query of its own for IN to compare with, selecting `select` — one
201
235
  * column. Its tables are its own: it sees nothing of the query around
@@ -204,91 +238,91 @@ const Ht = (t) => typeof t == "object" && t !== null && !(t instanceof Date), Q
204
238
  * 'customer_id') }))`. */
205
239
  subquery: ({ select: t, ...e }) => ({
206
240
  type: "subquery",
207
- id: G(),
208
- query: { joins: [], ...e, select: [{ id: G(), expression: t }] }
241
+ id: nt(),
242
+ query: { joins: [], ...e, select: [{ id: nt(), expression: t }] }
209
243
  })
210
244
  };
211
- function he(t, e, r) {
245
+ function je(t, e, r) {
212
246
  return A(t, e, { type: "setBaseTable", table: r });
213
247
  }
214
- function De(t, e, r, n = {}) {
248
+ function _e(t, e, r, n = {}) {
215
249
  const s = { type: "addJoin", table: r, ...n };
216
250
  return A(t, e, s);
217
251
  }
218
- function Ne(t, e, r) {
252
+ function He(t, e, r) {
219
253
  return A(t, e, { type: "removeJoin", joinId: r });
220
254
  }
221
- function Yt(t, e, r, n = {}) {
222
- const s = Rt(e), i = J(r);
223
- if (s && i.some((u) => u !== s.alias)) {
224
- if (i.includes(s.alias))
255
+ function se(t, e, r, n = {}) {
256
+ const s = xt(e), o = k(r);
257
+ if (s && o.some((u) => u !== s.alias)) {
258
+ if (o.includes(s.alias))
225
259
  throw new Error("addCondition: a condition names both the union and tables of its branches: add it in two parts");
226
260
  return s.query.union.forEach((u) => {
227
- const c = u.from.table, l = new Set(L(u).map(V)), $ = It(t, c), y = i.find((T) => !l.has(T) && !$.has(T));
228
- if (y)
229
- throw new Error(`addCondition: "${y}" can't be reached from "${c}", one of the union's tables: a condition must reach every branch`);
230
- }), s.query.union.reduce((u, c, l) => Ct(
261
+ const f = u.from.table, l = new Set(U(u).map(ft)), $ = kt(t, f), p = o.find((g) => !l.has(g) && !$.has(g));
262
+ if (p)
263
+ throw new Error(`addCondition: "${p}" can't be reached from "${f}", one of the union's tables: a condition must reach every branch`);
264
+ }), s.query.union.reduce((u, f, l) => Qt(
231
265
  u,
232
- [Lt(s.id, l)],
233
- ($) => Yt(t, $, r, n)
266
+ [Xt(s.id, l)],
267
+ ($) => se(t, $, r, n)
234
268
  ), e);
235
269
  }
236
- const a = n.operator ?? "AND", { where: o } = e;
237
- let f;
238
- return o ? o.type === "logical" && o.operator === a ? f = { ...o, operands: [...o.operands, r] } : f = { type: "logical", operator: a, operands: [o, r] } : f = r, D(t, e, Mt(t, e, f));
270
+ const a = n.operator ?? "AND", { where: i } = e;
271
+ let c;
272
+ return i ? i.type === "logical" && i.operator === a ? c = { ...i, operands: [...i.operands, r] } : c = { type: "logical", operator: a, operands: [i, r] } : c = r, R(t, e, Vt(t, e, c));
239
273
  }
240
- function Oe(t, e, r, n) {
241
- const s = A(t, e, { type: "addSelectItem" }), i = s.select[s.select.length - 1].id, a = A(t, s, {
274
+ function Ye(t, e, r, n) {
275
+ const s = A(t, e, { type: "addSelectItem" }), o = s.select[s.select.length - 1].id, a = A(t, s, {
242
276
  type: "setSelectExpression",
243
- selectId: i,
277
+ selectId: o,
244
278
  expression: r
245
- }), o = n === void 0 ? a : A(t, a, { type: "setSelectAlias", selectId: i, alias: n });
246
- return D(t, e, o);
279
+ }), i = n === void 0 ? a : A(t, a, { type: "setSelectAlias", selectId: o, alias: n });
280
+ return R(t, e, i);
247
281
  }
248
- function Se(t, e, r) {
249
- const n = A(t, e, { type: "addGroupByItem" }), { id: s } = n.groupBy[n.groupBy.length - 1], i = A(t, n, {
282
+ function Pe(t, e, r) {
283
+ const n = A(t, e, { type: "addGroupByItem" }), { id: s } = n.groupBy[n.groupBy.length - 1], o = A(t, n, {
250
284
  type: "setGroupByExpression",
251
285
  groupById: s,
252
286
  expression: r
253
287
  });
254
- return D(t, e, i);
288
+ return R(t, e, o);
255
289
  }
256
- function be(t, e, r) {
257
- return D(t, e, wt(t, e, r));
290
+ function Ge(t, e, r) {
291
+ return R(t, e, Wt(t, e, r));
258
292
  }
259
- function Re(t, e, r, n = "asc") {
260
- const s = A(t, e, { type: "addOrderByItem" }), { id: i } = s.orderBy[s.orderBy.length - 1], a = A(t, s, {
293
+ function xe(t, e, r, n = "asc") {
294
+ const s = A(t, e, { type: "addOrderByItem" }), { id: o } = s.orderBy[s.orderBy.length - 1], a = A(t, s, {
261
295
  type: "setOrderByExpression",
262
- orderById: i,
296
+ orderById: o,
263
297
  expression: r
264
- }), o = A(t, a, {
298
+ }), i = A(t, a, {
265
299
  type: "setOrderByDirection",
266
- orderById: i,
300
+ orderById: o,
267
301
  direction: n
268
302
  });
269
- return D(t, e, o);
303
+ return R(t, e, i);
270
304
  }
271
- function Ie(t, e, r) {
305
+ function ke(t, e, r) {
272
306
  let n = e;
273
307
  return "limit" in r && (n = A(t, n, { type: "setLimit", limit: r.limit })), "offset" in r && (n = A(t, n, { type: "setOffset", offset: r.offset })), n;
274
308
  }
275
- function Ce(t, e, r) {
309
+ function Qe(t, e, r) {
276
310
  return A(t, e, { type: "setDistinct", distinct: r });
277
311
  }
278
- function Le(t) {
279
- if (!ht(t)) throw new Error(`query "${t.id}" has no base table yet`);
312
+ function Xe(t) {
313
+ if (!jt(t)) throw new Error(`query "${t.id}" has no base table yet`);
280
314
  return t;
281
315
  }
282
- const d = 4;
283
- class S extends Error {
316
+ const X = 4;
317
+ class w extends Error {
284
318
  constructor(r, n) {
285
319
  super(n);
286
- b(this, "kind");
320
+ M(this, "kind");
287
321
  this.name = "QueryFormatError", this.kind = r;
288
322
  }
289
323
  }
290
- const C = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
291
- function Pt(t) {
324
+ const q = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
325
+ function oe(t) {
292
326
  const e = [];
293
327
  let r = 0;
294
328
  for (; r < t.length; ) {
@@ -307,83 +341,83 @@ function Pt(t) {
307
341
  }
308
342
  return e;
309
343
  }
310
- function Gt(t) {
344
+ function ie(t) {
311
345
  const e = (r) => {
312
346
  if (Array.isArray(r)) return r.map(e);
313
- if (!C(r)) return r;
314
- const n = Object.fromEntries(Object.entries(r).map(([a, o]) => [a, e(o)])), { right: s } = n;
315
- if (n.type !== "binary" || n.operator !== "IN" || !C(s) || s.type === "subquery" || s.type === "list") return n;
316
- const i = s.type === "literal" && typeof s.value == "string" ? Pt(s.value).map((a) => ({ type: "literal", value: a })) : [s];
317
- return { ...n, right: { type: "list", items: i } };
347
+ if (!q(r)) return r;
348
+ const n = Object.fromEntries(Object.entries(r).map(([a, i]) => [a, e(i)])), { right: s } = n;
349
+ if (n.type !== "binary" || n.operator !== "IN" || !q(s) || s.type === "subquery" || s.type === "list") return n;
350
+ const o = s.type === "literal" && typeof s.value == "string" ? oe(s.value).map((a) => ({ type: "literal", value: a })) : [s];
351
+ return { ...n, right: { type: "list", items: o } };
318
352
  };
319
353
  return e(t);
320
354
  }
321
- const xt = (t) => t, Qt = (t) => t, Xt = [Gt, xt, Qt];
322
- function kt(t, e, r) {
355
+ const ae = (t) => t, ue = (t) => t, ce = [ie, ae, ue];
356
+ function fe(t, e, r) {
323
357
  return r.slice(e - 1).reduce((n, s) => s(n), t);
324
358
  }
325
- function F(t, e) {
326
- return Array.isArray(t) ? t.map((r) => F(r, e)) : C(t) ? t.type === "literal" ? e(t) : Object.fromEntries(Object.entries(t).map(([r, n]) => [r, F(n, e)])) : t;
359
+ function _(t, e) {
360
+ return Array.isArray(t) ? t.map((r) => _(r, e)) : q(t) ? t.type === "literal" ? e(t) : Object.fromEntries(Object.entries(t).map(([r, n]) => [r, _(n, e)])) : t;
327
361
  }
328
- function Vt(t) {
362
+ function le(t) {
329
363
  return t.value instanceof Date ? { ...t, value: t.value.toISOString(), valueType: "date" } : typeof t.value == "bigint" ? { ...t, value: String(t.value), valueType: "bigint" } : t;
330
364
  }
331
- function Wt(t) {
365
+ function $e(t) {
332
366
  if (t.valueType === void 0) return t;
333
367
  const { valueType: e, ...r } = t, n = String(r.value);
334
368
  let s;
335
369
  if (e === "date") {
336
370
  if (s = new Date(n), Number.isNaN(s.getTime()))
337
- throw new S("invalid", `not a date: ${JSON.stringify(n)}`);
371
+ throw new w("invalid", `not a date: ${JSON.stringify(n)}`);
338
372
  } else if (e === "bigint" && /^-?\d+$/.test(n))
339
373
  s = BigInt(n);
340
374
  else {
341
- const i = String(e);
342
- throw new S("invalid", `can't read a ${i} from ${JSON.stringify(n)}`);
375
+ const o = String(e);
376
+ throw new w("invalid", `can't read a ${o} from ${JSON.stringify(n)}`);
343
377
  }
344
378
  return { ...r, value: s };
345
379
  }
346
- function Me(t) {
380
+ function Ve(t) {
347
381
  return {
348
- version: d,
349
- query: F(t, Vt)
382
+ version: X,
383
+ query: _(t, le)
350
384
  };
351
385
  }
352
- function we(t) {
353
- if (!C(t))
354
- throw new S("invalid", "a stored query is an object");
386
+ function We(t) {
387
+ if (!q(t))
388
+ throw new w("invalid", "a stored query is an object");
355
389
  const { version: e } = t;
356
390
  if (typeof e != "number" || !Number.isInteger(e) || e < 1)
357
- throw new S("invalid", "a stored query has a whole-number version from 1");
358
- if (e > d)
359
- throw new S(
391
+ throw new w("invalid", "a stored query has a whole-number version from 1");
392
+ if (e > X)
393
+ throw new w(
360
394
  "newerVersion",
361
- `stored in format ${e}; this version reads up to ${d}`
395
+ `stored in format ${e}; this version reads up to ${X}`
362
396
  );
363
- const r = kt(t.query, e, Xt);
364
- if (!C(r) || typeof r.id != "string")
365
- throw new S("invalid", "a stored query has a query with a string id");
366
- return F(r, Wt);
397
+ const r = fe(t.query, e, ce);
398
+ if (!q(r) || typeof r.id != "string")
399
+ throw new w("invalid", "a stored query has a query with a string id");
400
+ return _(r, $e);
367
401
  }
368
- function B(t, e) {
402
+ function V(t, e) {
369
403
  const r = new Map(e == null ? void 0 : e.tableOf), n = new Set(e == null ? void 0 : e.aliases), s = new Set(e == null ? void 0 : e.derived);
370
- return t.forEach(({ table: i, alias: a }) => {
371
- if (i === void 0) {
404
+ return t.forEach(({ table: o, alias: a }) => {
405
+ if (o === void 0) {
372
406
  a && s.add(a);
373
407
  return;
374
408
  }
375
- if (r.set(i, i), a) {
376
- r.set(a, i), n.add(a), s.delete(a);
409
+ if (r.set(o, o), a) {
410
+ r.set(a, o), n.add(a), s.delete(a);
377
411
  return;
378
412
  }
379
- n.delete(i), s.delete(i);
413
+ n.delete(o), s.delete(o);
380
414
  }), { tableOf: r, aliases: n, derived: s };
381
415
  }
382
- function Jt(t, e, r) {
383
- const n = t.on && I(t.on, e, r);
384
- return t.query ? { ...t, on: n, query: Dt(t.query, (s) => q(s, r)) } : t.shared !== void 0 ? { ...t, on: n } : { ...t, on: n, table: r(t.table) };
416
+ function Ee(t, e, r) {
417
+ const n = t.on && F(t.on, e, r);
418
+ return t.query ? { ...t, on: n, query: _t(t.query, (s) => Y(s, r)) } : t.shared !== void 0 ? { ...t, on: n } : { ...t, on: n, table: r(t.table) };
385
419
  }
386
- function I(t, e, r) {
420
+ function F(t, e, r) {
387
421
  if (t.type === "field") {
388
422
  if (!t.table || e.derived.has(t.table)) return t;
389
423
  const n = e.tableOf.get(t.table) ?? t.table;
@@ -393,27 +427,27 @@ function I(t, e, r) {
393
427
  ...t.column ? { column: r(n, t.column) } : {}
394
428
  };
395
429
  }
396
- if (t.type === "subquery") return { ...t, query: q(t.query, r) };
430
+ if (t.type === "subquery") return { ...t, query: Y(t.query, r) };
397
431
  if (t.type === "exists") {
398
- const { query: n } = t, s = [n.from, ...n.joins], i = B(s), a = B(s, e);
432
+ const { query: n } = t, s = [n.from, ...n.joins], o = V(s), a = V(s, e);
399
433
  return {
400
434
  ...t,
401
- link: I(t.link, a, r),
435
+ link: F(t.link, a, r),
402
436
  query: {
403
437
  ...n,
404
438
  from: { ...n.from, table: r(n.from.table) },
405
- joins: n.joins.map((o) => Jt(o, i, r)),
406
- ...n.where ? { where: I(n.where, i, r) } : {}
439
+ joins: n.joins.map((i) => Ee(i, o, r)),
440
+ ...n.where ? { where: F(n.where, o, r) } : {}
407
441
  }
408
442
  };
409
443
  }
410
- return H(t, (n) => I(n, e, r));
444
+ return K(t, (n) => F(n, e, r));
411
445
  }
412
- function q(t, e) {
413
- const r = B([t.from, ...t.joins]), n = W(
446
+ function Y(t, e) {
447
+ const r = V([t.from, ...t.joins]), n = lt(
414
448
  t,
415
- (s) => I(s, r, e),
416
- (s) => q(s, e)
449
+ (s) => F(s, r, e),
450
+ (s) => Y(s, e)
417
451
  );
418
452
  return {
419
453
  ...n,
@@ -421,11 +455,11 @@ function q(t, e) {
421
455
  joins: n.joins.map((s) => s.table === void 0 ? s : { ...s, table: e(s.table) })
422
456
  };
423
457
  }
424
- function j(t, e) {
425
- if (Array.isArray(t)) return t.map((s) => j(s, e));
458
+ function W(t, e) {
459
+ if (Array.isArray(t)) return t.map((s) => W(s, e));
426
460
  if (typeof t != "object" || t === null || t instanceof Date) return t;
427
461
  const r = Object.fromEntries(Object.entries(t).map(
428
- ([s, i]) => [s, j(i, e)]
462
+ ([s, o]) => [s, W(o, e)]
429
463
  ));
430
464
  if (!("from" in r) || !Array.isArray(r.joins)) return r;
431
465
  const n = (s) => s.table !== void 0 && !s.alias && e(s.table) !== s.table ? { ...s, alias: s.table } : s;
@@ -435,70 +469,70 @@ function j(t, e) {
435
469
  joins: r.joins.map(n)
436
470
  };
437
471
  }
438
- function Kt(t, e) {
439
- return q(j(t, e), e);
472
+ function ye(t, e) {
473
+ return Y(W(t, e), e);
440
474
  }
441
- const zt = /^(\d{2}):(\d{2})(?::(\d{2}))?$/, X = /YYYY|MM|DD|HH|mm|ss/g, O = (t, e = 2) => String(t).padStart(e, "0");
442
- function nt(t, e) {
475
+ const pe = /^(\d{2}):(\d{2})(?::(\d{2}))?$/, ut = /YYYY|MM|DD|HH|mm|ss/g, C = (t, e = 2) => String(t).padStart(e, "0");
476
+ function ht(t, e) {
443
477
  let r;
444
- const n = typeof t == "string" ? zt.exec(t.trim()) : null;
478
+ const n = typeof t == "string" ? pe.exec(t.trim()) : null;
445
479
  if (n)
446
480
  r = { HH: n[1], mm: n[2], ss: n[3] ?? "00" };
447
481
  else {
448
- const a = typeof t == "string" ? Ft(t, "dateTime") : t;
482
+ const a = typeof t == "string" ? Jt(t, "dateTime") : t;
449
483
  a instanceof Date && (r = {
450
- YYYY: O(a.getUTCFullYear(), 4),
451
- MM: O(a.getUTCMonth() + 1),
452
- DD: O(a.getUTCDate()),
453
- HH: O(a.getUTCHours()),
454
- mm: O(a.getUTCMinutes()),
455
- ss: O(a.getUTCSeconds())
484
+ YYYY: C(a.getUTCFullYear(), 4),
485
+ MM: C(a.getUTCMonth() + 1),
486
+ DD: C(a.getUTCDate()),
487
+ HH: C(a.getUTCHours()),
488
+ mm: C(a.getUTCMinutes()),
489
+ ss: C(a.getUTCSeconds())
456
490
  });
457
491
  }
458
492
  if (!r) return t;
459
493
  const s = r;
460
- return (e.match(X) ?? []).some((a) => s[a] === void 0) ? t : e.replace(X, (a) => s[a]);
494
+ return (e.match(ut) ?? []).some((a) => s[a] === void 0) ? t : e.replace(ut, (a) => s[a]);
461
495
  }
462
- function st(t, e) {
496
+ function Ot(t, e) {
463
497
  const r = /* @__PURE__ */ new Map(), n = (s) => {
464
- const i = /* @__PURE__ */ new Map();
465
- L(s).forEach((u) => i.set(V(u), u.table));
498
+ const o = /* @__PURE__ */ new Map();
499
+ U(s).forEach((u) => o.set(ft(u), u.table));
466
500
  const a = (u) => {
467
501
  if ((u == null ? void 0 : u.type) !== "field" || !u.table || !u.column) return;
468
- const c = i.has(u.table) ? i.get(u.table) : u.table, l = c === void 0 ? void 0 : Nt(e, c), $ = l == null ? void 0 : l.columns.find((y) => y.name === u.column);
502
+ const f = o.has(u.table) ? o.get(u.table) : u.table, l = f === void 0 ? void 0 : Ht(e, f), $ = l == null ? void 0 : l.columns.find((p) => p.name === u.column);
469
503
  return $ == null ? void 0 : $.format;
470
- }, o = (u, c) => {
504
+ }, i = (u, f) => {
471
505
  switch (u.type) {
472
506
  case "literal":
473
- return { ...u, value: nt(u.value, c) };
507
+ return { ...u, value: ht(u.value, f) };
474
508
  case "list":
475
- return { ...u, items: u.items.map((l) => o(l, c)) };
509
+ return { ...u, items: u.items.map((l) => i(l, f)) };
476
510
  case "param":
477
- return r.has(u.name) || r.set(u.name, c), u;
511
+ return r.has(u.name) || r.set(u.name, f), u;
478
512
  default:
479
513
  return u;
480
514
  }
481
- }, f = (u) => {
515
+ }, c = (u) => {
482
516
  if (u.type === "subquery") return { ...u, query: n(u.query) };
483
- const c = H(u, f);
484
- if (c.type !== "binary" || !c.right) return c;
485
- const l = a(c.left), $ = a(c.right);
517
+ const f = K(u, c);
518
+ if (f.type !== "binary" || !f.right) return f;
519
+ const l = a(f.left), $ = a(f.right);
486
520
  return {
487
- ...c,
488
- left: $ ? o(c.left, $) : c.left,
489
- right: l ? o(c.right, l) : c.right
521
+ ...f,
522
+ left: $ ? i(f.left, $) : f.left,
523
+ right: l ? i(f.right, l) : f.right
490
524
  };
491
525
  };
492
- return W(s, f, (u) => n(u));
526
+ return lt(s, c, (u) => n(u));
493
527
  };
494
528
  return { query: n(t), params: r };
495
529
  }
496
- const Fe = ["mysql", "mssql", "postgres"], qe = {
530
+ const Je = ["mysql", "mssql", "postgres"], Ke = {
497
531
  mysql: "MySQL",
498
532
  mssql: "SQL Server",
499
533
  postgres: "PostgreSQL"
500
534
  };
501
- function g(t, e) {
535
+ function D(t, e) {
502
536
  const r = t.replace(/[\uE000-\uE003]/g, "");
503
537
  switch (e) {
504
538
  case "mysql":
@@ -511,36 +545,36 @@ function g(t, e) {
511
545
  return `"${r.replace(/"/g, '""')}"`;
512
546
  }
513
547
  }
514
- const Zt = /^[A-Za-z_][A-Za-z0-9_]*$/, it = (t) => `${t}`, te = /\uE000(\d+)\uE000/g;
515
- let N;
516
- function Ue(t, e) {
517
- N = { ...t, writing: [] };
548
+ const Te = /^[A-Za-z_][A-Za-z0-9_]*$/, Dt = (t) => `${t}`, Ae = /\uE000(\d+)\uE000/g;
549
+ let I;
550
+ function ze(t, e) {
551
+ I = { ...t, writing: [] };
518
552
  try {
519
553
  return e();
520
554
  } finally {
521
- N = void 0;
555
+ I = void 0;
522
556
  }
523
557
  }
524
- function ot(t, e, r) {
558
+ function Nt(t, e, r) {
525
559
  if (typeof t != "object" || t === null || t instanceof Date) return;
526
560
  let n;
527
- return Object.entries(t).some(([s, i]) => {
561
+ return Object.entries(t).some(([s, o]) => {
528
562
  const a = [...r, Array.isArray(t) ? Number(s) : s];
529
- return n = i === e ? a : ot(i, e, a), n !== void 0;
563
+ return n = o === e ? a : Nt(o, e, a), n !== void 0;
530
564
  }), n;
531
565
  }
532
- function p(t, e) {
533
- if (!N) return e();
534
- const { writing: r, paths: n } = N, s = r[r.length - 1], i = typeof t == "string" ? [t] : ot(s.value, t, s.path);
535
- if (!i) return e();
536
- r.push({ value: t, path: i });
566
+ function T(t, e) {
567
+ if (!I) return e();
568
+ const { writing: r, paths: n } = I, s = r[r.length - 1], o = typeof t == "string" ? [t] : Nt(s.value, t, s.path);
569
+ if (!o) return e();
570
+ r.push({ value: t, path: o });
537
571
  try {
538
- return `${n.push(i) - 1}${e()}`;
572
+ return `${n.push(o) - 1}${e()}`;
539
573
  } finally {
540
574
  r.pop();
541
575
  }
542
576
  }
543
- const ee = {
577
+ const me = {
544
578
  mysql: {
545
579
  text: "CHAR",
546
580
  integer: "SIGNED",
@@ -569,24 +603,24 @@ const ee = {
569
603
  boolean: "boolean"
570
604
  }
571
605
  };
572
- function re(t, e) {
606
+ function ge(t, e) {
573
607
  var n;
574
- const r = (n = ee[e]) == null ? void 0 : n[t];
608
+ const r = (n = me[e]) == null ? void 0 : n[t];
575
609
  return r ? e === "postgres" ? `NULL::${r}` : `CAST(NULL AS ${r})` : "NULL";
576
610
  }
577
- function at(t, e, r) {
611
+ function St(t, e, r) {
578
612
  if (t == null) return "NULL";
579
613
  if (r)
580
- return r.values.push(t), it(r.values.length - 1);
614
+ return r.values.push(t), Dt(r.values.length - 1);
581
615
  if (typeof t == "boolean")
582
616
  return e === "mssql" ? t ? "1" : "0" : t ? "TRUE" : "FALSE";
583
617
  if (typeof t == "string") {
584
- const n = N ? t.replace(/[\uE001-\uE003]/g, "") : t;
618
+ const n = I ? t.replace(/[\uE001-\uE003]/g, "") : t;
585
619
  return n === "" ? "''" : `'${n.replace(/'/g, "''")}'`;
586
620
  }
587
- return typeof t == "number" || typeof t == "bigint" ? String(t) : t instanceof Date ? `'${z(t)}'` : String(t);
621
+ return typeof t == "number" || typeof t == "bigint" ? String(t) : t instanceof Date ? `'${Et(t)}'` : String(t);
588
622
  }
589
- function ne(t, e) {
623
+ function he(t, e) {
590
624
  switch (t) {
591
625
  case "!=":
592
626
  return e === "mssql" ? "<>" : "!=";
@@ -598,10 +632,10 @@ function ne(t, e) {
598
632
  return t;
599
633
  }
600
634
  }
601
- function h(t) {
635
+ function b(t) {
602
636
  return (t == null ? void 0 : t.type) === "literal" && typeof t.value == "string" && /^[A-Za-z_]+$/.test(t.value) ? t.value.toUpperCase() : "DAY";
603
637
  }
604
- const U = {
638
+ const x = {
605
639
  YEAR: "year",
606
640
  QUARTER: "quarter",
607
641
  MONTH: "month",
@@ -611,43 +645,43 @@ const U = {
611
645
  MINUTE: "minute",
612
646
  SECOND: "second",
613
647
  MILLISECOND: "millisecond"
614
- }, se = {
648
+ }, Oe = {
615
649
  // ---- Date arithmetic ----
616
650
  DATE_ADD: ([t, e], r, n, s) => {
617
651
  var a;
618
- const i = h(r[2]);
652
+ const o = b(r[2]);
619
653
  switch (n) {
620
654
  case "mysql":
621
- return i === "MILLISECOND" ? `DATE_ADD(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_ADD(${t}, INTERVAL ${e} ${i})`;
655
+ return o === "MILLISECOND" ? `DATE_ADD(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_ADD(${t}, INTERVAL ${e} ${o})`;
622
656
  case "postgres": {
623
- const o = U[i] ?? i.toLowerCase();
624
- return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} + INTERVAL '${r[1].value} ${o}')` : `(${t} + (${e} * INTERVAL '1 ${o}'))`;
657
+ const i = x[o] ?? o.toLowerCase();
658
+ return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} + INTERVAL '${r[1].value} ${i}')` : `(${t} + (${e} * INTERVAL '1 ${i}'))`;
625
659
  }
626
660
  case "mssql":
627
- return `DATEADD(${i}, ${e}, ${t})`;
661
+ return `DATEADD(${o}, ${e}, ${t})`;
628
662
  default:
629
- return `DATE_ADD(${t}, ${e}, ${h(r[2])})`;
663
+ return `DATE_ADD(${t}, ${e}, ${b(r[2])})`;
630
664
  }
631
665
  },
632
666
  DATE_SUB: ([t, e], r, n, s) => {
633
667
  var a;
634
- const i = h(r[2]);
668
+ const o = b(r[2]);
635
669
  switch (n) {
636
670
  case "mysql":
637
- return i === "MILLISECOND" ? `DATE_SUB(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_SUB(${t}, INTERVAL ${e} ${i})`;
671
+ return o === "MILLISECOND" ? `DATE_SUB(${t}, INTERVAL (${e}) * 1000 MICROSECOND)` : `DATE_SUB(${t}, INTERVAL ${e} ${o})`;
638
672
  case "postgres": {
639
- const o = U[i] ?? i.toLowerCase();
640
- return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} - INTERVAL '${r[1].value} ${o}')` : `(${t} - (${e} * INTERVAL '1 ${o}'))`;
673
+ const i = x[o] ?? o.toLowerCase();
674
+ return !s && ((a = r[1]) == null ? void 0 : a.type) === "literal" && typeof r[1].value == "number" ? `(${t} - INTERVAL '${r[1].value} ${i}')` : `(${t} - (${e} * INTERVAL '1 ${i}'))`;
641
675
  }
642
676
  case "mssql":
643
- return `DATEADD(${i}, -(${e}), ${t})`;
677
+ return `DATEADD(${o}, -(${e}), ${t})`;
644
678
  default:
645
- return `DATE_SUB(${t}, ${e}, ${h(r[2])})`;
679
+ return `DATE_SUB(${t}, ${e}, ${b(r[2])})`;
646
680
  }
647
681
  },
648
682
  // ---- Date diff ----
649
683
  DATEDIFF: ([t, e], r, n) => {
650
- const s = h(r[2]);
684
+ const s = b(r[2]);
651
685
  switch (n) {
652
686
  case "mysql":
653
687
  return `TIMESTAMPDIFF(${s}, ${t}, ${e})`;
@@ -658,12 +692,12 @@ const U = {
658
692
  case "YEAR":
659
693
  return `EXTRACT(YEAR FROM age(${e}, ${t}))::integer`;
660
694
  case "QUARTER": {
661
- const i = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
662
- return `FLOOR((${i} * 12 + ${a}) / 3)::integer`;
695
+ const o = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
696
+ return `FLOOR((${o} * 12 + ${a}) / 3)::integer`;
663
697
  }
664
698
  case "MONTH": {
665
- const i = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
666
- return `(${i} * 12 + ${a})::integer`;
699
+ const o = `EXTRACT(YEAR FROM age(${e}, ${t}))`, a = `EXTRACT(MONTH FROM age(${e}, ${t}))`;
700
+ return `(${o} * 12 + ${a})::integer`;
667
701
  }
668
702
  case "WEEK":
669
703
  return `FLOOR((${e}::date - ${t}::date) / 7)`;
@@ -686,7 +720,7 @@ const U = {
686
720
  },
687
721
  // ---- Date extract ----
688
722
  EXTRACT: ([t], e, r) => {
689
- const n = h(e[1]);
723
+ const n = b(e[1]);
690
724
  switch (r) {
691
725
  case "mysql":
692
726
  return n === "MILLISECOND" ? `FLOOR(MICROSECOND(${t}) / 1000)` : `EXTRACT(${n} FROM ${t})`;
@@ -700,7 +734,7 @@ const U = {
700
734
  },
701
735
  // ---- Date truncation ----
702
736
  DATE_TRUNC: ([t], e, r) => {
703
- const n = h(e[1]);
737
+ const n = b(e[1]);
704
738
  switch (r) {
705
739
  case "mysql":
706
740
  switch (n) {
@@ -726,7 +760,7 @@ const U = {
726
760
  return `/* unknown unit: ${n} */`;
727
761
  }
728
762
  case "postgres":
729
- return `DATE_TRUNC('${U[n] ?? n.toLowerCase()}', ${t})`;
763
+ return `DATE_TRUNC('${x[n] ?? n.toLowerCase()}', ${t})`;
730
764
  case "mssql":
731
765
  switch (n) {
732
766
  case "YEAR":
@@ -770,72 +804,72 @@ const U = {
770
804
  // ---- String aggregation (issue 137) ----
771
805
  // The separator goes into the SQL as a literal even in parameterized SQL:
772
806
  // MySQL's SEPARATOR takes nothing else.
773
- STRING_AGG: ([t = "??"], e, r, n, s, i) => {
774
- const a = e[1] ?? { type: "literal", value: ", " }, o = a.type === "literal" && typeof a.value == "string" ? at(a.value, r) : "??", f = s.distinct ? "DISTINCT " : "", u = ($) => {
775
- var y;
776
- return (y = s.orderBy) != null && y.length ? `ORDER BY ${s.orderBy.map((T) => `${$(T)} ${T.direction === "desc" ? "DESC" : "ASC"}`).join(", ")}` : "";
777
- }, c = ($) => i($.expression), l = ($) => $ ? ` ${$}` : "";
807
+ STRING_AGG: ([t = "??"], e, r, n, s, o) => {
808
+ const a = e[1] ?? { type: "literal", value: ", " }, i = a.type === "literal" && typeof a.value == "string" ? St(a.value, r) : "??", c = s.distinct ? "DISTINCT " : "", u = ($) => {
809
+ var p;
810
+ return (p = s.orderBy) != null && p.length ? `ORDER BY ${s.orderBy.map((g) => `${$(g)} ${g.direction === "desc" ? "DESC" : "ASC"}`).join(", ")}` : "";
811
+ }, f = ($) => o($.expression), l = ($) => $ ? ` ${$}` : "";
778
812
  switch (r) {
779
813
  case "mysql":
780
- return `GROUP_CONCAT(${f}${t}${l(u(c))} SEPARATOR ${o})`;
814
+ return `GROUP_CONCAT(${c}${t}${l(u(f))} SEPARATOR ${i})`;
781
815
  case "postgres": {
782
- const $ = `CAST(${t} AS TEXT)`, y = u((T) => {
783
- if (!s.distinct) return c(T);
784
- if (M(T.expression, e[0])) return $;
816
+ const $ = `CAST(${t} AS TEXT)`, p = u((g) => {
817
+ if (!s.distinct) return f(g);
818
+ if (B(g.expression, e[0])) return $;
785
819
  throw new Error("PostgreSQL orders STRING_AGG of different values by the value only");
786
820
  });
787
- return `STRING_AGG(${f}${$}, ${o}${l(y)})`;
821
+ return `STRING_AGG(${c}${$}, ${i}${l(p)})`;
788
822
  }
789
823
  case "mssql": {
790
824
  if (s.distinct)
791
825
  throw new Error("SQL Server's STRING_AGG can't join only different values");
792
- const $ = u(c), y = $ ? ` WITHIN GROUP (${$})` : "";
793
- return `STRING_AGG(CAST(${t} AS NVARCHAR(MAX)), ${o})${y}`;
826
+ const $ = u(f), p = $ ? ` WITHIN GROUP (${$})` : "";
827
+ return `STRING_AGG(CAST(${t} AS NVARCHAR(MAX)), ${i})${p}`;
794
828
  }
795
829
  default:
796
- return `STRING_AGG(${f}${t}, ${o}${l(u(c))})`;
830
+ return `STRING_AGG(${c}${t}, ${i}${l(u(f))})`;
797
831
  }
798
832
  }
799
833
  };
800
- function R(t) {
834
+ function d(t) {
801
835
  return t.type === "binary" || t.type === "logical" || t.type === "if" || t.type === "case";
802
836
  }
803
837
  function E(t, e, r, n) {
804
- return p(t, () => ie(t, e, r, n));
838
+ return T(t, () => De(t, e, r, n));
805
839
  }
806
- function k(t, e, r, n) {
807
- const s = (i) => {
808
- if (!i) return "??";
809
- const a = E(i, e, r, n);
810
- return R(i) ? `(${a})` : a;
840
+ function ct(t, e, r, n) {
841
+ const s = (o) => {
842
+ if (!o) return "??";
843
+ const a = E(o, e, r, n);
844
+ return d(o) ? `(${a})` : a;
811
845
  };
812
- return p(t, () => {
813
- const [i, a] = t.type === "list" ? t.items : [t];
814
- return `${s(i)} AND ${s(a)}`;
846
+ return T(t, () => {
847
+ const [o, a] = t.type === "list" ? t.items : [t];
848
+ return `${s(o)} AND ${s(a)}`;
815
849
  });
816
850
  }
817
- function ie(t, e, r, n) {
851
+ function De(t, e, r, n) {
818
852
  var a;
819
- const s = " ".repeat(r), i = " ".repeat(r + 1);
853
+ const s = " ".repeat(r), o = " ".repeat(r + 1);
820
854
  switch (t.type) {
821
855
  case "literal":
822
- return t.value === "" && !t.empty ? "??" : t.value === null && t.as ? re(t.as, e) : at(t.value, e, n);
856
+ return t.value === "" && !t.empty ? "??" : t.value === null && t.as ? ge(t.as, e) : St(t.value, e, n);
823
857
  case "param": {
824
- if (!n) return Zt.test(t.name) ? `:${t.name}` : "??";
858
+ if (!n) return Te.test(t.name) ? `:${t.name}` : "??";
825
859
  if (!n.named.has(t.name))
826
860
  throw new Error(`no value for parameter "${t.name}"`);
827
- return n.values.push(n.named.get(t.name)), it(n.values.length - 1);
861
+ return n.values.push(n.named.get(t.name)), Dt(n.values.length - 1);
828
862
  }
829
863
  case "field": {
830
864
  if (!t.column) return "??";
831
- const o = g(t.column, e);
832
- return t.table ? `${g(t.table, e)}.${o}` : o;
865
+ const i = D(t.column, e);
866
+ return t.table ? `${D(t.table, e)}.${i}` : i;
833
867
  }
834
868
  case "function": {
835
- const o = t.args.map((l) => E(l, e, r, n)), f = se[t.name.toUpperCase()];
836
- if (f)
837
- return f(
838
- o,
869
+ const i = t.args.map((l) => E(l, e, r, n)), c = Oe[t.name.toUpperCase()];
870
+ if (c)
871
+ return c(
872
+ i,
839
873
  t.args,
840
874
  e,
841
875
  n !== void 0,
@@ -843,218 +877,218 @@ function ie(t, e, r, n) {
843
877
  (l) => E(l, e, r, n)
844
878
  );
845
879
  const u = /^[A-Za-z_][A-Za-z0-9_.]*$/.test(t.name) || t.name === "" ? t.name : "??";
846
- if (o.length === 0 && u.toUpperCase() === "COUNT") return `${u}(*)`;
847
- const c = t.distinct && o.length > 0 ? "DISTINCT " : "";
848
- return `${u}(${c}${o.join(", ")})`;
880
+ if (i.length === 0 && u.toUpperCase() === "COUNT") return `${u}(*)`;
881
+ const f = t.distinct && i.length > 0 ? "DISTINCT " : "";
882
+ return `${u}(${f}${i.join(", ")})`;
849
883
  }
850
884
  case "binary": {
851
- const o = t.operator ? ne(t.operator, e) : "=", f = E(t.left, e, r, n), u = R(t.left) ? `(${f})` : f;
852
- if (Ut(t.operator)) return `${u} ${o}`;
853
- if (!t.right) return `${u} ${o} ??`;
854
- if (o === "BETWEEN")
855
- return `${u} BETWEEN ${k(t.right, e, r, n)}`;
856
- if (o === "IN")
885
+ const i = t.operator ? he(t.operator, e) : "=", c = E(t.left, e, r, n), u = d(t.left) ? `(${c})` : c;
886
+ if (zt(t.operator)) return `${u} ${i}`;
887
+ if (!t.right) return `${u} ${i} ??`;
888
+ if (i === "BETWEEN")
889
+ return `${u} BETWEEN ${ct(t.right, e, r, n)}`;
890
+ if (i === "IN")
857
891
  return t.right.type === "list" ? `${u} IN ${E(t.right, e, r, n)}` : `${u} IN (${E(t.right, e, r, n)})`;
858
- const c = E(t.right, e, r, n), l = R(t.right) ? `(${c})` : c;
859
- return `${u} ${o} ${l}`;
892
+ const f = E(t.right, e, r, n), l = d(t.right) ? `(${f})` : f;
893
+ return `${u} ${i} ${l}`;
860
894
  }
861
895
  case "logical": {
862
896
  if (t.operands.length === 0) return "/* empty */";
863
897
  if (t.operands.length === 1)
864
898
  return E(t.operands[0], e, r, n);
865
- const o = `
899
+ const i = `
866
900
  ${s}${t.operator} `;
867
- return t.operands.map((f) => {
868
- if (f.type === "logical") {
869
- const u = E(f, e, r + 1, n);
901
+ return t.operands.map((c) => {
902
+ if (c.type === "logical") {
903
+ const u = E(c, e, r + 1, n);
870
904
  return `(
871
- ${i}${u}
905
+ ${o}${u}
872
906
  ${s})`;
873
907
  }
874
- return E(f, e, r, n);
875
- }).join(o);
908
+ return E(c, e, r, n);
909
+ }).join(i);
876
910
  }
877
911
  case "not": {
878
- const { operand: o } = t;
879
- if (o.type === "binary" && o.operator === "IN" && ((a = o.right) == null ? void 0 : a.type) === "subquery") {
880
- const f = E(o.left, e, r, n);
881
- return `${R(o.left) ? `(${f})` : f} NOT IN (${E(o.right, e, r, n)})`;
912
+ const { operand: i } = t;
913
+ if (i.type === "binary" && i.operator === "IN" && ((a = i.right) == null ? void 0 : a.type) === "subquery") {
914
+ const c = E(i.left, e, r, n);
915
+ return `${d(i.left) ? `(${c})` : c} NOT IN (${E(i.right, e, r, n)})`;
882
916
  }
883
- if (o.type === "binary" && o.operator === "BETWEEN" && o.right) {
884
- const f = E(o.left, e, r, n);
885
- return `${R(o.left) ? `(${f})` : f} NOT BETWEEN ${k(o.right, e, r, n)}`;
917
+ if (i.type === "binary" && i.operator === "BETWEEN" && i.right) {
918
+ const c = E(i.left, e, r, n);
919
+ return `${d(i.left) ? `(${c})` : c} NOT BETWEEN ${ct(i.right, e, r, n)}`;
886
920
  }
887
- if (o.type === "logical" || o.type === "not") {
888
- const f = E(o, e, r + 1, n);
921
+ if (i.type === "logical" || i.type === "not") {
922
+ const c = E(i, e, r + 1, n);
889
923
  return `NOT (
890
- ${i}${f}
924
+ ${o}${c}
891
925
  ${s})`;
892
926
  }
893
- return `NOT ${E(o, e, r, n)}`;
927
+ return `NOT ${E(i, e, r, n)}`;
894
928
  }
895
929
  case "if": {
896
- const o = t.condition ? E(t.condition, e, r, n) : "??", f = t.then ? E(t.then, e, r, n) : "??", u = t.else ? E(t.else, e, r, n) : "NULL";
897
- return e === "mysql" ? `IF(${o}, ${f}, ${u})` : e === "mssql" ? `IIF(${o}, ${f}, ${u})` : `CASE WHEN ${o} THEN ${f} ELSE ${u} END`;
930
+ const i = t.condition ? E(t.condition, e, r, n) : "??", c = t.then ? E(t.then, e, r, n) : "??", u = t.else ? E(t.else, e, r, n) : "NULL";
931
+ return e === "mysql" ? `IF(${i}, ${c}, ${u})` : e === "mssql" ? `IIF(${i}, ${c}, ${u})` : `CASE WHEN ${i} THEN ${c} ELSE ${u} END`;
898
932
  }
899
933
  case "case": {
900
- const o = t.subject ? ` ${E(t.subject, e, r, n)}` : "", f = t.branches.map((c) => {
901
- const l = E(c.when, e, r + 1, n), $ = E(c.then, e, r + 1, n);
902
- return `${i}WHEN ${l} THEN ${$}`;
934
+ const i = t.subject ? ` ${E(t.subject, e, r, n)}` : "", c = t.branches.map((f) => {
935
+ const l = E(f.when, e, r + 1, n), $ = E(f.then, e, r + 1, n);
936
+ return `${o}WHEN ${l} THEN ${$}`;
903
937
  }).join(`
904
938
  `), u = t.else ? `
905
- ${i}ELSE ${E(t.else, e, r + 1, n)}` : "";
906
- return `CASE${o}
907
- ${f}${u}
939
+ ${o}ELSE ${E(t.else, e, r + 1, n)}` : "";
940
+ return `CASE${i}
941
+ ${c}${u}
908
942
  ${s}END`;
909
943
  }
910
944
  // EXISTS (SELECT 1 FROM … WHERE <link> AND <where>): the subquery written
911
945
  // in place, one level in, so its params fall in reading order.
912
946
  case "exists": {
913
- const { query: o, link: f } = t, u = ($) => $.type === "logical" && $.operator === "AND" ? $.operands : [$], c = o.where ? { type: "logical", operator: "AND", operands: [...u(f), ...u(o.where)] } : f;
947
+ const { query: i, link: c } = t, u = ($) => $.type === "logical" && $.operator === "AND" ? $.operands : [$], f = i.where ? { type: "logical", operator: "AND", operands: [...u(c), ...u(i.where)] } : c;
914
948
  return `EXISTS (
915
949
  ${[
916
950
  "SELECT 1",
917
951
  // The clauses below write their expressions with formatNode.
918
952
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
919
- $t(o.from, e),
953
+ wt(i.from, e),
920
954
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
921
- ...o.joins.map(($) => Et($, e, n)),
955
+ ...i.joins.map(($) => Lt($, e, n)),
922
956
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
923
- ut(c, e, n)
957
+ bt(f, e, n)
924
958
  ].join(`
925
- `).replace(/^/gm, i)}
959
+ `).replace(/^/gm, o)}
926
960
  ${s})`;
927
961
  }
928
962
  // IN's right side (issue 122): its query, on lines of its own, inside the
929
963
  // parentheses IN writes around it.
930
964
  // An empty list is unfinished, like a value not filled in.
931
965
  case "list":
932
- return `(${t.items.map((o) => E(o, e, r, n)).join(", ") || "??"})`;
966
+ return `(${t.items.map((i) => E(i, e, r, n)).join(", ") || "??"})`;
933
967
  case "subquery":
934
968
  return `
935
- ${P(t.query, e, n).join(`
936
- `).replace(/^/gm, i)}
969
+ ${z(t.query, e, n).join(`
970
+ `).replace(/^/gm, o)}
937
971
  ${s}`;
938
972
  default:
939
973
  return "/* unknown */";
940
974
  }
941
975
  }
942
- function ut(t, e, r) {
976
+ function bt(t, e, r) {
943
977
  return `WHERE
944
978
  ${E(t, e, 1, r)}`;
945
979
  }
946
- const oe = {
980
+ const Ne = {
947
981
  inner: "INNER JOIN",
948
982
  left: "LEFT JOIN",
949
983
  right: "RIGHT JOIN",
950
984
  full: "FULL JOIN",
951
985
  cross: "CROSS JOIN"
952
986
  };
953
- let ct = /* @__PURE__ */ new Map();
954
- function ft(t, e, r) {
955
- return t.shared !== void 0 ? g(ct.get(t.shared) ?? "??", e) : t.query ? `(
956
- ${lt(t.query, e, r).replace(/^/gm, " ")}
957
- )` : g(t.table, e);
958
- }
959
- function lt(t, e, r) {
960
- return Ot(t).map((n) => P(n, e, r).join(`
961
- `)).join(St(t) && !t.all ? `
987
+ let Rt = /* @__PURE__ */ new Map();
988
+ function It(t, e, r) {
989
+ return t.shared !== void 0 ? D(Rt.get(t.shared) ?? "??", e) : t.query ? `(
990
+ ${Ct(t.query, e, r).replace(/^/gm, " ")}
991
+ )` : D(t.table, e);
992
+ }
993
+ function Ct(t, e, r) {
994
+ return Yt(t).map((n) => z(n, e, r).join(`
995
+ `)).join(Pt(t) && !t.all ? `
962
996
  UNION
963
997
  ` : `
964
998
  UNION ALL
965
999
  `);
966
1000
  }
967
- function ae(t, e, r) {
1001
+ function Se(t, e, r) {
968
1002
  return t.length === 0 ? [] : [`WITH
969
- ${t.map((s) => p(s, () => {
970
- const i = lt(s.query, e, r).replace(/^/gm, " ");
971
- return ` ${g(s.name, e)} AS (
972
- ${i}
1003
+ ${t.map((s) => T(s, () => {
1004
+ const o = Ct(s.query, e, r).replace(/^/gm, " ");
1005
+ return ` ${D(s.name, e)} AS (
1006
+ ${o}
973
1007
  )`;
974
1008
  })).join(`,
975
1009
  `)}`];
976
1010
  }
977
- function $t(t, e, r) {
978
- const n = t.alias ? ` AS ${g(t.alias, e)}` : "";
979
- return `FROM ${p(t, () => `${ft(t, e, r)}${n}`)}`;
1011
+ function wt(t, e, r) {
1012
+ const n = t.alias ? ` AS ${D(t.alias, e)}` : "";
1013
+ return `FROM ${T(t, () => `${It(t, e, r)}${n}`)}`;
980
1014
  }
981
- function Et(t, e, r) {
982
- return p(t, () => {
983
- const n = ft(t, e, r), s = t.alias ? ` AS ${g(t.alias, e)}` : "";
1015
+ function Lt(t, e, r) {
1016
+ return T(t, () => {
1017
+ const n = It(t, e, r), s = t.alias ? ` AS ${D(t.alias, e)}` : "";
984
1018
  if (t.joinType === "cross") return `CROSS JOIN ${n}${s}`;
985
- const i = t.on ? E(t.on, e, 1, r) : "/* unconfigured */";
986
- return `${oe[t.joinType]} ${n}${s}
987
- ON ${i}`;
1019
+ const o = t.on ? E(t.on, e, 1, r) : "/* unconfigured */";
1020
+ return `${Ne[t.joinType]} ${n}${s}
1021
+ ON ${o}`;
988
1022
  });
989
1023
  }
990
- function ue(t, e, r, n = "SELECT") {
991
- if (t.length === 0) return `${n} ${p(t, () => "*")}`;
992
- const s = t.map((i) => p(i, () => {
993
- const a = E(i.expression, e, 1, r), o = i.alias ? ` AS ${g(i.alias, e)}` : "";
994
- return `${a}${o}`;
1024
+ function be(t, e, r, n = "SELECT") {
1025
+ if (t.length === 0) return `${n} ${T(t, () => "*")}`;
1026
+ const s = t.map((o) => T(o, () => {
1027
+ const a = E(o.expression, e, 1, r), i = o.alias ? ` AS ${D(o.alias, e)}` : "";
1028
+ return `${a}${i}`;
995
1029
  }));
996
1030
  return `${n}
997
1031
  ${s.join(`,
998
1032
  `)}`;
999
1033
  }
1000
- function ce(t, e, r) {
1034
+ function Re(t, e, r) {
1001
1035
  return `GROUP BY
1002
- ${t.map((s) => p(
1036
+ ${t.map((s) => T(
1003
1037
  s,
1004
1038
  () => E(s.expression, e, 1, r)
1005
1039
  )).join(`,
1006
1040
  `)}`;
1007
1041
  }
1008
- function fe(t, e, r) {
1042
+ function Ie(t, e, r) {
1009
1043
  return `HAVING
1010
1044
  ${E(t, e, 1, r)}`;
1011
1045
  }
1012
- function le(t, e, r, n) {
1046
+ function Ce(t, e, r, n) {
1013
1047
  return `ORDER BY
1014
- ${t.map((i) => p(i, () => `${E(n(i.expression), e, 1, r)} ${i.direction === "desc" ? "DESC" : "ASC"}`)).join(`,
1048
+ ${t.map((o) => T(o, () => `${E(n(o.expression), e, 1, r)} ${o.direction === "desc" ? "DESC" : "ASC"}`)).join(`,
1015
1049
  `)}`;
1016
1050
  }
1017
- const _ = (t) => t !== void 0 && Number.isInteger(t) && t >= 0 ? t : void 0;
1018
- function Tt(t, e) {
1019
- const r = e.resolveName ? Kt(t, e.resolveName) : t;
1020
- return e.defaultLimit !== void 0 && _(r.limit) === void 0 ? { ...r, limit: e.defaultLimit } : r;
1051
+ const J = (t) => t !== void 0 && Number.isInteger(t) && t >= 0 ? t : void 0;
1052
+ function Mt(t, e) {
1053
+ const r = e.resolveName ? ye(t, e.resolveName) : t;
1054
+ return e.defaultLimit !== void 0 && J(r.limit) === void 0 ? { ...r, limit: e.defaultLimit } : r;
1021
1055
  }
1022
- const $e = "18446744073709551615";
1023
- function P(t, e, r, n = `SELECT${t.distinct ? " DISTINCT" : ""}`) {
1056
+ const we = "18446744073709551615";
1057
+ function z(t, e, r, n = `SELECT${t.distinct ? " DISTINCT" : ""}`) {
1024
1058
  const s = [
1025
- ue(t.select, e, r, n),
1026
- $t(t.from, e, r),
1027
- ...t.joins.map((a) => Et(a, e, r))
1059
+ be(t.select, e, r, n),
1060
+ wt(t.from, e, r),
1061
+ ...t.joins.map((a) => Lt(a, e, r))
1028
1062
  ];
1029
- t.where && s.push(ut(t.where, e, r));
1030
- const i = t.groupBy ?? [];
1031
- if (i.length > 0 && s.push(ce(i, e, r)), t.having) {
1032
- const a = e === "mysql" ? K(t.having, t) : t.having;
1033
- s.push(fe(a, e, r));
1063
+ t.where && s.push(bt(t.where, e, r));
1064
+ const o = t.groupBy ?? [];
1065
+ if (o.length > 0 && s.push(Re(o, e, r)), t.having) {
1066
+ const a = e === "mysql" ? $t(t.having, t) : t.having;
1067
+ s.push(Ie(a, e, r));
1034
1068
  }
1035
1069
  return s;
1036
1070
  }
1037
- function yt(t, e, r) {
1038
- N && (N.writing = [{ value: t, path: [] }]), ct = new Map((t.shared ?? []).map((c) => [c.id, c.name]));
1039
- const n = ae(t.shared ?? [], e, r), s = _(t.limit), i = _(t.offset) || void 0, a = t.orderBy ?? [], o = e === "mssql" && s !== void 0 && i === void 0, f = `SELECT${t.distinct ? " DISTINCT" : ""}${o ? ` ${p("limit", () => `TOP (${s})`)}` : ""}`, u = P(t, e, r, f);
1040
- if (a.length > 0 && u.push(le(a, e, r, (c) => e === "mysql" ? K(c, t) : c)), e === "mssql") {
1041
- if (i !== void 0) {
1071
+ function dt(t, e, r) {
1072
+ I && (I.writing = [{ value: t, path: [] }]), Rt = new Map((t.shared ?? []).map((f) => [f.id, f.name]));
1073
+ const n = Se(t.shared ?? [], e, r), s = J(t.limit), o = J(t.offset) || void 0, a = t.orderBy ?? [], i = e === "mssql" && s !== void 0 && o === void 0, c = `SELECT${t.distinct ? " DISTINCT" : ""}${i ? ` ${T("limit", () => `TOP (${s})`)}` : ""}`, u = z(t, e, r, c);
1074
+ if (a.length > 0 && u.push(Ce(a, e, r, (f) => e === "mysql" ? $t(f, t) : f)), e === "mssql") {
1075
+ if (o !== void 0) {
1042
1076
  a.length === 0 && u.push("ORDER BY (SELECT NULL)");
1043
- const c = s !== void 0 ? ` ${p("limit", () => `FETCH NEXT ${s} ROWS ONLY`)}` : "";
1044
- u.push(`${p("offset", () => `OFFSET ${i} ROWS`)}${c}`);
1077
+ const f = s !== void 0 ? ` ${T("limit", () => `FETCH NEXT ${s} ROWS ONLY`)}` : "";
1078
+ u.push(`${T("offset", () => `OFFSET ${o} ROWS`)}${f}`);
1045
1079
  }
1046
- } else if (s !== void 0 || i !== void 0) {
1047
- const c = s !== void 0 || e === "mysql" ? p(s !== void 0 ? "limit" : {}, () => `LIMIT ${s ?? $e}`) : "", l = i !== void 0 ? p("offset", () => `OFFSET ${i}`) : "";
1048
- u.push([c, l].filter(Boolean).join(" "));
1080
+ } else if (s !== void 0 || o !== void 0) {
1081
+ const f = s !== void 0 || e === "mysql" ? T(s !== void 0 ? "limit" : {}, () => `LIMIT ${s ?? we}`) : "", l = o !== void 0 ? T("offset", () => `OFFSET ${o}`) : "";
1082
+ u.push([f, l].filter(Boolean).join(" "));
1049
1083
  }
1050
1084
  return [...n, ...u].join(`
1051
1085
  `);
1052
1086
  }
1053
- function ve(t, e, r = {}) {
1054
- const n = r.values ? qt(t, r.values) : t, s = r.schema ? st(n, r.schema).query : n;
1055
- return yt(Tt(s, r), e);
1087
+ function Ze(t, e, r = {}) {
1088
+ const n = r.values ? Kt(t, r.values) : t, s = r.schema ? Ot(n, r.schema).query : n;
1089
+ return dt(Mt(s, r), e);
1056
1090
  }
1057
- function Ee(t, e) {
1091
+ function Le(t, e) {
1058
1092
  switch (t) {
1059
1093
  case "mysql":
1060
1094
  return "?";
@@ -1066,42 +1100,42 @@ function Ee(t, e) {
1066
1100
  return "?";
1067
1101
  }
1068
1102
  }
1069
- function de(t, e, r = {}) {
1070
- const n = r.schema ? st(t, r.schema) : { query: t, params: /* @__PURE__ */ new Map() }, s = {
1103
+ function tr(t, e, r = {}) {
1104
+ const n = r.schema ? Ot(t, r.schema) : { query: t, params: /* @__PURE__ */ new Map() }, s = {
1071
1105
  values: [],
1072
- named: new Map(Object.entries(r.values ?? {}).map(([u, c]) => {
1106
+ named: new Map(Object.entries(r.values ?? {}).map(([u, f]) => {
1073
1107
  const l = n.params.get(u);
1074
- return [u, l ? nt(c, l) : c];
1108
+ return [u, l ? ht(f, l) : f];
1075
1109
  }))
1076
- }, i = Tt(n.query, r), a = yt(i, e, s), o = [];
1077
- return { sql: a.replace(te, (u, c) => {
1078
- const l = s.values[Number(c)];
1079
- return o.push(l instanceof Date ? z(l) : l), Ee(e, o.length);
1080
- }), params: o };
1110
+ }, o = Mt(n.query, r), a = dt(o, e, s), i = [];
1111
+ return { sql: a.replace(Ae, (u, f) => {
1112
+ const l = s.values[Number(f)];
1113
+ return i.push(l instanceof Date ? Et(l) : l), Le(e, i.length);
1114
+ }), params: i };
1081
1115
  }
1082
1116
  export {
1083
- Fe as D,
1084
- d as Q,
1085
- vt as S,
1086
- de as a,
1087
- ve as b,
1088
- Yt as c,
1089
- Se as d,
1090
- De as e,
1091
- Re as f,
1092
- Oe as g,
1093
- Q as h,
1094
- Le as i,
1095
- he as j,
1096
- Ce as k,
1097
- be as l,
1098
- Ie as m,
1099
- S as n,
1100
- we as o,
1101
- Me as p,
1102
- qe as q,
1103
- Ne as r,
1104
- me as s,
1105
- ge as u,
1106
- Ue as w
1117
+ Je as D,
1118
+ X as Q,
1119
+ Zt as S,
1120
+ tr as a,
1121
+ Ze as b,
1122
+ se as c,
1123
+ Pe as d,
1124
+ _e as e,
1125
+ xe as f,
1126
+ Ye as g,
1127
+ at as h,
1128
+ Xe as i,
1129
+ je as j,
1130
+ Qe as k,
1131
+ Ge as l,
1132
+ ke as m,
1133
+ w as n,
1134
+ We as o,
1135
+ Ve as p,
1136
+ Ke as q,
1137
+ He as r,
1138
+ ve as s,
1139
+ Be as u,
1140
+ ze as w
1107
1141
  };