drizzle-cube 0.1.26 → 0.1.28

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.
Files changed (29) hide show
  1. package/dist/adapters/{compiler-CSr2Ti96.js → compiler-BibS3bXd.js} +980 -920
  2. package/dist/adapters/express/index.js +1 -1
  3. package/dist/adapters/fastify/index.js +1 -1
  4. package/dist/adapters/hono/index.js +1 -1
  5. package/dist/adapters/nextjs/index.js +1 -1
  6. package/dist/adapters/utils.d.ts +1 -1
  7. package/dist/client/charts.js +1 -1
  8. package/dist/client/chunks/{charts-JUvTF2xT.js → charts-Dm25kuUn.js} +54 -50
  9. package/dist/client/chunks/{charts-JUvTF2xT.js.map → charts-Dm25kuUn.js.map} +1 -1
  10. package/dist/client/chunks/{icons-ChgBIaCg.js → icons-B_0yoGjv.js} +398 -352
  11. package/dist/client/chunks/icons-B_0yoGjv.js.map +1 -0
  12. package/dist/client/chunks/providers-B7MVnAAt.js.map +1 -1
  13. package/dist/client/components/CubeRelationshipDiagram/CubeNode.d.ts +13 -0
  14. package/dist/client/components/CubeRelationshipDiagram/ERDControls.d.ts +7 -0
  15. package/dist/client/components/CubeRelationshipDiagram/RelationshipEdge.d.ts +11 -0
  16. package/dist/client/components/CubeRelationshipDiagram/index.d.ts +10 -0
  17. package/dist/client/components/CubeRelationshipDiagram/useERDLayout.d.ts +21 -0
  18. package/dist/client/components/QueryBuilder/types.d.ts +4 -0
  19. package/dist/client/components.js +14393 -4492
  20. package/dist/client/components.js.map +1 -1
  21. package/dist/client/hooks/useCubeMeta.d.ts +9 -0
  22. package/dist/client/index.js +1 -1
  23. package/dist/client/styles.css +1 -1
  24. package/dist/client/types.d.ts +2 -1
  25. package/dist/client-bundle-stats.html +1 -1
  26. package/dist/server/index.d.ts +27 -9
  27. package/dist/server/index.js +1002 -942
  28. package/package.json +5 -2
  29. package/dist/client/chunks/icons-ChgBIaCg.js.map +0 -1
@@ -1,6 +1,6 @@
1
- var hR = Object.defineProperty;
2
- var VR = (T, E, R) => E in T ? hR(T, E, { enumerable: !0, configurable: !0, writable: !0, value: R }) : T[E] = R;
3
- var l = (T, E, R) => VR(T, typeof E != "symbol" ? E + "" : E, R);
1
+ var WR = Object.defineProperty;
2
+ var XR = (T, E, R) => E in T ? WR(T, E, { enumerable: !0, configurable: !0, writable: !0, value: R }) : T[E] = R;
3
+ var l = (T, E, R) => XR(T, typeof E != "symbol" ? E + "" : E, R);
4
4
  const X = Symbol.for("drizzle:entityKind");
5
5
  function F(T, E) {
6
6
  if (!T || typeof T != "object")
@@ -55,21 +55,21 @@ class RE {
55
55
  }
56
56
  }
57
57
  l(RE, QT, "Column");
58
- const aE = Symbol.for("drizzle:Name"), ST = Symbol.for("drizzle:isPgEnum");
59
- function WR(T) {
60
- return !!T && typeof T == "function" && ST in T && T[ST] === !0;
58
+ const aE = Symbol.for("drizzle:Name"), eT = Symbol.for("drizzle:isPgEnum");
59
+ function bR(T) {
60
+ return !!T && typeof T == "function" && eT in T && T[eT] === !0;
61
61
  }
62
62
  var ZT;
63
63
  ZT = X;
64
64
  class zE {
65
- constructor(E, R, A, S = !1, e = []) {
65
+ constructor(E, R, A, e = !1, S = []) {
66
66
  this._ = {
67
67
  brand: "Subquery",
68
68
  sql: E,
69
69
  selectedFields: R,
70
70
  alias: A,
71
- isWith: S,
72
- usedTables: e
71
+ isWith: e,
72
+ usedTables: S
73
73
  };
74
74
  }
75
75
  // getSQL(): SQL<unknown> {
@@ -77,20 +77,20 @@ class zE {
77
77
  // }
78
78
  }
79
79
  l(zE, ZT, "Subquery");
80
- const XR = {
80
+ const yR = {
81
81
  startActiveSpan(T, E) {
82
82
  return E();
83
83
  }
84
- }, SE = Symbol.for("drizzle:ViewBaseConfig"), oE = Symbol.for("drizzle:Schema"), eT = Symbol.for("drizzle:Columns"), IT = Symbol.for("drizzle:ExtraConfigColumns"), PE = Symbol.for("drizzle:OriginalName"), ME = Symbol.for("drizzle:BaseName"), CE = Symbol.for("drizzle:IsAlias"), OT = Symbol.for("drizzle:ExtraConfigBuilder"), bR = Symbol.for("drizzle:IsDrizzleTable");
85
- var qT, jT, kT, zT, ER, TR, RR, AR, SR, eR;
86
- eR = X, SR = aE, AR = PE, RR = oE, TR = eT, ER = IT, zT = ME, kT = CE, jT = bR, qT = OT;
84
+ }, eE = Symbol.for("drizzle:ViewBaseConfig"), oE = Symbol.for("drizzle:Schema"), ST = Symbol.for("drizzle:Columns"), IT = Symbol.for("drizzle:ExtraConfigColumns"), PE = Symbol.for("drizzle:OriginalName"), ME = Symbol.for("drizzle:BaseName"), CE = Symbol.for("drizzle:IsAlias"), OT = Symbol.for("drizzle:ExtraConfigBuilder"), KR = Symbol.for("drizzle:IsDrizzleTable");
85
+ var qT, jT, kT, zT, ER, TR, RR, AR, eR, SR;
86
+ SR = X, eR = aE, AR = PE, RR = oE, TR = ST, ER = IT, zT = ME, kT = CE, jT = KR, qT = OT;
87
87
  class W {
88
88
  constructor(E, R, A) {
89
89
  /**
90
90
  * @internal
91
91
  * Can be changed if the table is aliased.
92
92
  */
93
- l(this, SR);
93
+ l(this, eR);
94
94
  /**
95
95
  * @internal
96
96
  * Used to store the original name of the table, before any aliasing.
@@ -116,12 +116,12 @@ class W {
116
116
  this[aE] = this[PE] = E, this[oE] = R, this[ME] = A;
117
117
  }
118
118
  }
119
- l(W, eR, "Table"), /** @internal */
119
+ l(W, SR, "Table"), /** @internal */
120
120
  l(W, "Symbol", {
121
121
  Name: aE,
122
122
  Schema: oE,
123
123
  OriginalName: PE,
124
- Columns: eT,
124
+ Columns: ST,
125
125
  ExtraConfigColumns: IT,
126
126
  BaseName: ME,
127
127
  IsAlias: CE,
@@ -130,7 +130,7 @@ l(W, "Symbol", {
130
130
  function nR(T) {
131
131
  return T != null && typeof T.getSQL == "function";
132
132
  }
133
- function yR(T) {
133
+ function $R(T) {
134
134
  var R;
135
135
  const E = { sql: "", params: [] };
136
136
  for (const A of T)
@@ -171,7 +171,7 @@ const v = class v {
171
171
  return this.queryChunks.push(...E.queryChunks), this;
172
172
  }
173
173
  toQuery(E) {
174
- return XR.startActiveSpan("drizzle.buildSQL", (R) => {
174
+ return yR.startActiveSpan("drizzle.buildSQL", (R) => {
175
175
  const A = this.buildQueryFromSourceParams(this.queryChunks, E);
176
176
  return R == null || R.setAttributes({
177
177
  "drizzle.query.text": A.sql,
@@ -184,19 +184,19 @@ const v = class v {
184
184
  inlineParams: R.inlineParams || this.shouldInlineParams,
185
185
  paramStartIndex: R.paramStartIndex || { value: 0 }
186
186
  }), {
187
- casing: S,
188
- escapeName: e,
187
+ casing: e,
188
+ escapeName: S,
189
189
  escapeParam: N,
190
190
  prepareTyping: s,
191
191
  inlineParams: _,
192
192
  paramStartIndex: I
193
193
  } = A;
194
- return yR(E.map((O) => {
194
+ return $R(E.map((O) => {
195
195
  var C;
196
196
  if (F(O, h))
197
197
  return { sql: O.value.join(""), params: [] };
198
198
  if (F(O, LE))
199
- return { sql: e(O.value), params: [] };
199
+ return { sql: S(O.value), params: [] };
200
200
  if (O === void 0)
201
201
  return { sql: "", params: [] };
202
202
  if (Array.isArray(O)) {
@@ -213,24 +213,24 @@ const v = class v {
213
213
  if (F(O, W)) {
214
214
  const t = O[W.Symbol.Schema], i = O[W.Symbol.Name];
215
215
  return {
216
- sql: t === void 0 || O[CE] ? e(i) : e(t) + "." + e(i),
216
+ sql: t === void 0 || O[CE] ? S(i) : S(t) + "." + S(i),
217
217
  params: []
218
218
  };
219
219
  }
220
220
  if (F(O, RE)) {
221
- const t = S.getColumnCasing(O);
221
+ const t = e.getColumnCasing(O);
222
222
  if (R.invokeSource === "indexes")
223
- return { sql: e(t), params: [] };
223
+ return { sql: S(t), params: [] };
224
224
  const i = O.table[W.Symbol.Schema];
225
225
  return {
226
- sql: O.table[CE] || i === void 0 ? e(O.table[W.Symbol.Name]) + "." + e(t) : e(i) + "." + e(O.table[W.Symbol.Name]) + "." + e(t),
226
+ sql: O.table[CE] || i === void 0 ? S(O.table[W.Symbol.Name]) + "." + S(t) : S(i) + "." + S(O.table[W.Symbol.Name]) + "." + S(t),
227
227
  params: []
228
228
  };
229
229
  }
230
230
  if (F(O, ET)) {
231
- const t = O[SE].schema, i = O[SE].name;
231
+ const t = O[eE].schema, i = O[eE].name;
232
232
  return {
233
- sql: t === void 0 || O[SE].isAlias ? e(i) : e(t) + "." + e(i),
233
+ sql: t === void 0 || O[eE].isAlias ? S(i) : S(t) + "." + S(i),
234
234
  params: []
235
235
  };
236
236
  }
@@ -245,12 +245,12 @@ const v = class v {
245
245
  let i = ["none"];
246
246
  return s && (i = [s(O.encoder)]), { sql: N(I.value++, t), params: [t], typings: i };
247
247
  }
248
- return F(O, OE) ? { sql: N(I.value++, O), params: [O], typings: ["none"] } : F(O, v.Aliased) && O.fieldAlias !== void 0 ? { sql: e(O.fieldAlias), params: [] } : F(O, zE) ? O._.isWith ? { sql: e(O._.alias), params: [] } : this.buildQueryFromSourceParams([
248
+ return F(O, OE) ? { sql: N(I.value++, O), params: [O], typings: ["none"] } : F(O, v.Aliased) && O.fieldAlias !== void 0 ? { sql: S(O.fieldAlias), params: [] } : F(O, zE) ? O._.isWith ? { sql: S(O._.alias), params: [] } : this.buildQueryFromSourceParams([
249
249
  new h("("),
250
250
  O._.sql,
251
251
  new h(") "),
252
252
  new LE(O._.alias)
253
- ], A) : WR(O) ? O.schema ? { sql: e(O.schema) + "." + e(O.enumName), params: [] } : { sql: e(O.enumName), params: [] } : nR(O) ? (C = O.shouldOmitSQLParens) != null && C.call(O) ? this.buildQueryFromSourceParams([O.getSQL()], A) : this.buildQueryFromSourceParams([
253
+ ], A) : bR(O) ? O.schema ? { sql: S(O.schema) + "." + S(O.enumName), params: [] } : { sql: S(O.enumName), params: [] } : nR(O) ? (C = O.shouldOmitSQLParens) != null && C.call(O) ? this.buildQueryFromSourceParams([O.getSQL()], A) : this.buildQueryFromSourceParams([
254
254
  new h("("),
255
255
  O.getSQL(),
256
256
  new h(")")
@@ -306,7 +306,7 @@ class LE {
306
306
  }
307
307
  }
308
308
  l(LE, tR, "Name");
309
- function KR(T) {
309
+ function gR(T) {
310
310
  return typeof T == "object" && T !== null && "mapToDriverValue" in T && typeof T.mapToDriverValue == "function";
311
311
  }
312
312
  const iR = {
@@ -337,8 +337,8 @@ l(IE, sR, "Param");
337
337
  function L(T, ...E) {
338
338
  const R = [];
339
339
  (E.length > 0 || T.length > 0 && T[0] !== "") && R.push(new h(T[0]));
340
- for (const [A, S] of E.entries())
341
- R.push(S, new h(T[A + 1]));
340
+ for (const [A, e] of E.entries())
341
+ R.push(e, new h(T[A + 1]));
342
342
  return new m(R);
343
343
  }
344
344
  ((T) => {
@@ -354,17 +354,17 @@ function L(T, ...E) {
354
354
  return new m([new h(_)]);
355
355
  }
356
356
  T.raw = A;
357
- function S(_, I) {
357
+ function e(_, I) {
358
358
  const O = [];
359
359
  for (const [C, t] of _.entries())
360
360
  C > 0 && I !== void 0 && O.push(I), O.push(t);
361
361
  return new m(O);
362
362
  }
363
- T.join = S;
364
- function e(_) {
363
+ T.join = e;
364
+ function S(_) {
365
365
  return new LE(_);
366
366
  }
367
- T.identifier = e;
367
+ T.identifier = S;
368
368
  function N(_) {
369
369
  return new OE(_);
370
370
  }
@@ -378,10 +378,10 @@ function L(T, ...E) {
378
378
  var R;
379
379
  R = X;
380
380
  const A = class A {
381
- constructor(e, N) {
381
+ constructor(S, N) {
382
382
  /** @internal */
383
383
  l(this, "isSelectionField", !1);
384
- this.sql = e, this.fieldAlias = N;
384
+ this.sql = S, this.fieldAlias = N;
385
385
  }
386
386
  getSQL() {
387
387
  return this.sql;
@@ -406,22 +406,22 @@ class OE {
406
406
  }
407
407
  }
408
408
  l(OE, CR, "Placeholder");
409
- const $R = Symbol.for("drizzle:IsDrizzleView");
409
+ const JR = Symbol.for("drizzle:IsDrizzleView");
410
410
  var LR, _R, rR;
411
- rR = X, _R = SE, LR = $R;
411
+ rR = X, _R = eE, LR = JR;
412
412
  class ET {
413
- constructor({ name: E, schema: R, selectedFields: A, query: S }) {
413
+ constructor({ name: E, schema: R, selectedFields: A, query: e }) {
414
414
  /** @internal */
415
415
  l(this, _R);
416
416
  /** @internal */
417
417
  l(this, LR, !0);
418
- this[SE] = {
418
+ this[eE] = {
419
419
  name: E,
420
420
  originalName: E,
421
421
  schema: R,
422
422
  selectedFields: A,
423
- query: S,
424
- isExisting: !S,
423
+ query: e,
424
+ isExisting: !e,
425
425
  isAlias: !1
426
426
  };
427
427
  }
@@ -440,7 +440,7 @@ zE.prototype.getSQL = function() {
440
440
  return new m([this]);
441
441
  };
442
442
  function $(T, E) {
443
- return KR(E) && !nR(T) && !F(T, IE) && !F(T, OE) && !F(T, RE) && !F(T, W) && !F(T, ET) ? new IE(T, E) : T;
443
+ return gR(E) && !nR(T) && !F(T, IE) && !F(T, OE) && !F(T, RE) && !F(T, W) && !F(T, ET) ? new IE(T, E) : T;
444
444
  }
445
445
  const _E = (T, E) => L`${T} = ${$(E, T)}`, NT = (T, E) => L`${T} <> ${$(E, T)}`;
446
446
  function b(...T) {
@@ -481,13 +481,13 @@ function CT(T) {
481
481
  function LT(T) {
482
482
  return L`${T} asc`;
483
483
  }
484
- function gR(T) {
484
+ function wR(T) {
485
485
  return L`${T} desc`;
486
486
  }
487
487
  function uE(T) {
488
488
  return L`count(${T || L.raw("*")})`.mapWith(Number);
489
489
  }
490
- function JR(T) {
490
+ function xR(T) {
491
491
  return L`count(distinct ${T})`.mapWith(Number);
492
492
  }
493
493
  function Q(T) {
@@ -518,7 +518,7 @@ class TT {
518
518
  }
519
519
  }
520
520
  }
521
- class wR extends TT {
521
+ class vR extends TT {
522
522
  getEngineType() {
523
523
  return "postgres";
524
524
  }
@@ -604,7 +604,7 @@ class wR extends TT {
604
604
  * Build PostgreSQL CASE WHEN conditional expression
605
605
  */
606
606
  buildCaseWhen(E, R) {
607
- const A = E.map((S) => L`WHEN ${S.when} THEN ${S.then}`).reduce((S, e) => L`${S} ${e}`);
607
+ const A = E.map((e) => L`WHEN ${e.when} THEN ${e.then}`).reduce((e, S) => L`${e} ${S}`);
608
608
  return R !== void 0 ? L`CASE ${A} ELSE ${R} END` : L`CASE ${A} END`;
609
609
  }
610
610
  /**
@@ -642,7 +642,7 @@ class wR extends TT {
642
642
  return E;
643
643
  }
644
644
  }
645
- class xR extends TT {
645
+ class aR extends TT {
646
646
  getEngineType() {
647
647
  return "mysql";
648
648
  }
@@ -669,8 +669,8 @@ class xR extends TT {
669
669
  case "week":
670
670
  return L`DATE_SUB(${R}, INTERVAL WEEKDAY(${R}) DAY)`;
671
671
  default:
672
- const S = A[E];
673
- return S ? L`STR_TO_DATE(DATE_FORMAT(${R}, ${S}), '%Y-%m-%d %H:%i:%s')` : R;
672
+ const e = A[E];
673
+ return e ? L`STR_TO_DATE(DATE_FORMAT(${R}, ${e}), '%Y-%m-%d %H:%i:%s')` : R;
674
674
  }
675
675
  }
676
676
  /**
@@ -729,7 +729,7 @@ class xR extends TT {
729
729
  * Build MySQL CASE WHEN conditional expression
730
730
  */
731
731
  buildCaseWhen(E, R) {
732
- const A = E.map((S) => L`WHEN ${S.when} THEN ${S.then}`).reduce((S, e) => L`${S} ${e}`);
732
+ const A = E.map((e) => L`WHEN ${e.when} THEN ${e.then}`).reduce((e, S) => L`${e} ${S}`);
733
733
  return R !== void 0 ? L`CASE ${A} ELSE ${R} END` : L`CASE ${A} END`;
734
734
  }
735
735
  /**
@@ -767,7 +767,7 @@ class xR extends TT {
767
767
  return E;
768
768
  }
769
769
  }
770
- class vR extends TT {
770
+ class QR extends TT {
771
771
  getEngineType() {
772
772
  return "sqlite";
773
773
  }
@@ -792,11 +792,11 @@ class vR extends TT {
792
792
  case "day":
793
793
  return L`datetime(${R}, 'unixepoch', 'start of day')`;
794
794
  case "hour":
795
- const S = L`datetime(${R}, 'unixepoch')`;
796
- return L`datetime(strftime('%Y-%m-%d %H:00:00', ${S}))`;
797
- case "minute":
798
795
  const e = L`datetime(${R}, 'unixepoch')`;
799
- return L`datetime(strftime('%Y-%m-%d %H:%M:00', ${e}))`;
796
+ return L`datetime(strftime('%Y-%m-%d %H:00:00', ${e}))`;
797
+ case "minute":
798
+ const S = L`datetime(${R}, 'unixepoch')`;
799
+ return L`datetime(strftime('%Y-%m-%d %H:%M:00', ${S}))`;
800
800
  case "second":
801
801
  const N = L`datetime(${R}, 'unixepoch')`;
802
802
  return L`datetime(strftime('%Y-%m-%d %H:%M:%S', ${N}))`;
@@ -859,7 +859,7 @@ class vR extends TT {
859
859
  * Build SQLite CASE WHEN conditional expression
860
860
  */
861
861
  buildCaseWhen(E, R) {
862
- const A = E.map((S) => S.then && typeof S.then == "object" && (S.then.queryChunks || S.then._ || S.then.sql) ? L`WHEN ${S.when} THEN ${L.raw("(")}${S.then}${L.raw(")")}` : L`WHEN ${S.when} THEN ${S.then}`).reduce((S, e) => L`${S} ${e}`);
862
+ const A = E.map((e) => e.then && typeof e.then == "object" && (e.then.queryChunks || e.then._ || e.then.sql) ? L`WHEN ${e.when} THEN ${L.raw("(")}${e.then}${L.raw(")")}` : L`WHEN ${e.when} THEN ${e.then}`).reduce((e, S) => L`${e} ${S}`);
863
863
  return R !== void 0 ? R && typeof R == "object" && (R.queryChunks || R._ || R.sql) ? L`CASE ${A} ELSE ${L.raw("(")}${R}${L.raw(")")} END` : L`CASE ${A} ELSE ${R} END` : L`CASE ${A} END`;
864
864
  }
865
865
  /**
@@ -903,14 +903,29 @@ class vR extends TT {
903
903
  return E;
904
904
  }
905
905
  }
906
- function QR(T) {
906
+ class ZR extends aR {
907
+ getEngineType() {
908
+ return "singlestore";
909
+ }
910
+ // SingleStore inherits most MySQL functionality
911
+ // Override methods here only if SingleStore-specific behavior is needed
912
+ // Note: SingleStore has some known limitations:
913
+ // - ORDER BY and LIMIT cannot be chained together in some contexts
914
+ // - Nested selects with aggregation functions are not supported
915
+ // - Serial column type only assures uniqueness (tests may need ORDER BY)
916
+ // These limitations are typically handled at the query building level
917
+ // rather than in the adapter, but can be addressed here if needed
918
+ }
919
+ function qR(T) {
907
920
  switch (T) {
908
921
  case "postgres":
909
- return new wR();
922
+ return new vR();
910
923
  case "mysql":
911
- return new xR();
924
+ return new aR();
912
925
  case "sqlite":
913
- return new vR();
926
+ return new QR();
927
+ case "singlestore":
928
+ return new ZR();
914
929
  default:
915
930
  throw new Error(`Unsupported database engine: ${T}`);
916
931
  }
@@ -919,20 +934,20 @@ class RT {
919
934
  constructor(E, R, A) {
920
935
  l(this, "databaseAdapter");
921
936
  this.db = E, this.schema = R;
922
- const S = A || this.getEngineType();
923
- this.databaseAdapter = QR(S);
937
+ const e = A || this.getEngineType();
938
+ this.databaseAdapter = qR(e);
924
939
  }
925
940
  }
926
- class ZR extends RT {
941
+ class jR extends RT {
927
942
  async execute(E, R) {
928
943
  if (E && typeof E == "object" && typeof E.execute == "function") {
929
- const S = await E.execute();
930
- return Array.isArray(S) ? S.map((e) => this.convertNumericFields(e, R)) : S;
944
+ const e = await E.execute();
945
+ return Array.isArray(e) ? e.map((S) => this.convertNumericFields(S, R)) : e;
931
946
  }
932
947
  if (!this.db.execute)
933
948
  throw new Error("PostgreSQL database instance must have an execute method");
934
949
  const A = await this.db.execute(E);
935
- return Array.isArray(A) ? A.map((S) => this.convertNumericFields(S, R)) : A;
950
+ return Array.isArray(A) ? A.map((e) => this.convertNumericFields(e, R)) : A;
936
951
  }
937
952
  /**
938
953
  * Convert numeric string fields to numbers (only for measure fields)
@@ -940,8 +955,8 @@ class ZR extends RT {
940
955
  convertNumericFields(E, R) {
941
956
  if (!E || typeof E != "object") return E;
942
957
  const A = {};
943
- for (const [S, e] of Object.entries(E))
944
- R && R.includes(S) ? A[S] = this.coerceToNumber(e) : A[S] = e;
958
+ for (const [e, S] of Object.entries(E))
959
+ R && R.includes(e) ? A[e] = this.coerceToNumber(S) : A[e] = S;
945
960
  return A;
946
961
  }
947
962
  /**
@@ -953,13 +968,13 @@ class ZR extends RT {
953
968
  if (typeof E == "bigint") return Number(E);
954
969
  if (E && typeof E == "object") {
955
970
  if (typeof E.toString == "function") {
956
- const S = E.toString();
957
- if (/^-?\d+(\.\d+)?$/.test(S))
958
- return S.includes(".") ? parseFloat(S) : parseInt(S, 10);
971
+ const e = E.toString();
972
+ if (/^-?\d+(\.\d+)?$/.test(e))
973
+ return e.includes(".") ? parseFloat(e) : parseInt(e, 10);
959
974
  }
960
975
  if (((R = E.constructor) == null ? void 0 : R.name) === "Numeric" || ((A = E.constructor) == null ? void 0 : A.name) === "Decimal" || "digits" in E || "sign" in E) {
961
- const S = E.toString();
962
- return parseFloat(S);
976
+ const e = E.toString();
977
+ return parseFloat(e);
963
978
  }
964
979
  return E;
965
980
  }
@@ -976,18 +991,18 @@ class ZR extends RT {
976
991
  }
977
992
  }
978
993
  function _T(T, E) {
979
- return new ZR(T, E, "postgres");
994
+ return new jR(T, E, "postgres");
980
995
  }
981
- class qR extends RT {
996
+ class oR extends RT {
982
997
  async execute(E, R) {
983
998
  if (E && typeof E == "object" && typeof E.execute == "function") {
984
- const S = await E.execute();
985
- return Array.isArray(S) ? S.map((e) => this.convertNumericFields(e, R)) : S;
999
+ const e = await E.execute();
1000
+ return Array.isArray(e) ? e.map((S) => this.convertNumericFields(S, R)) : e;
986
1001
  }
987
1002
  if (!this.db.execute)
988
1003
  throw new Error("MySQL database instance must have an execute method");
989
1004
  const A = await this.db.execute(E);
990
- return Array.isArray(A) ? A.map((S) => this.convertNumericFields(S, R)) : A;
1005
+ return Array.isArray(A) ? A.map((e) => this.convertNumericFields(e, R)) : A;
991
1006
  }
992
1007
  /**
993
1008
  * Convert numeric string fields to numbers (measure fields + numeric dimensions)
@@ -995,8 +1010,8 @@ class qR extends RT {
995
1010
  convertNumericFields(E, R) {
996
1011
  if (!E || typeof E != "object") return E;
997
1012
  const A = {};
998
- for (const [S, e] of Object.entries(E))
999
- R && R.includes(S) ? A[S] = this.coerceToNumber(e) : A[S] = e;
1013
+ for (const [e, S] of Object.entries(E))
1014
+ R && R.includes(e) ? A[e] = this.coerceToNumber(S) : A[e] = S;
1000
1015
  return A;
1001
1016
  }
1002
1017
  /**
@@ -1016,19 +1031,19 @@ class qR extends RT {
1016
1031
  return "mysql";
1017
1032
  }
1018
1033
  }
1019
- function jR(T, E) {
1020
- return new qR(T, E, "mysql");
1034
+ function kR(T, E) {
1035
+ return new oR(T, E, "mysql");
1021
1036
  }
1022
- class kR extends RT {
1037
+ class zR extends RT {
1023
1038
  async execute(E, R) {
1024
1039
  if (E && typeof E == "object" && typeof E.execute == "function") {
1025
1040
  const A = await E.execute();
1026
- return Array.isArray(A) ? A.map((S) => this.convertNumericFields(S, R)) : A;
1041
+ return Array.isArray(A) ? A.map((e) => this.convertNumericFields(e, R)) : A;
1027
1042
  }
1028
1043
  try {
1029
1044
  if (this.db.all) {
1030
1045
  const A = this.db.all(E);
1031
- return Array.isArray(A) ? A.map((S) => this.convertNumericFields(S, R)) : A;
1046
+ return Array.isArray(A) ? A.map((e) => this.convertNumericFields(e, R)) : A;
1032
1047
  } else {
1033
1048
  if (this.db.run)
1034
1049
  return this.db.run(E);
@@ -1044,8 +1059,8 @@ class kR extends RT {
1044
1059
  convertNumericFields(E, R) {
1045
1060
  if (!E || typeof E != "object") return E;
1046
1061
  const A = {};
1047
- for (const [S, e] of Object.entries(E))
1048
- R && R.includes(S) ? A[S] = this.coerceToNumber(e) : A[S] = e;
1062
+ for (const [e, S] of Object.entries(E))
1063
+ R && R.includes(e) ? A[e] = this.coerceToNumber(S) : A[e] = S;
1049
1064
  return A;
1050
1065
  }
1051
1066
  /**
@@ -1066,7 +1081,18 @@ class kR extends RT {
1066
1081
  }
1067
1082
  }
1068
1083
  function rT(T, E) {
1069
- return new kR(T, E, "sqlite");
1084
+ return new zR(T, E, "sqlite");
1085
+ }
1086
+ class EA extends oR {
1087
+ getEngineType() {
1088
+ return "singlestore";
1089
+ }
1090
+ // SingleStore-specific optimizations can be added here if needed
1091
+ // For now, we inherit all behavior from MySQLExecutor since
1092
+ // SingleStore is largely MySQL-compatible
1093
+ }
1094
+ function TA(T, E) {
1095
+ return new EA(T, E);
1070
1096
  }
1071
1097
  function nT(T, E, R) {
1072
1098
  if (R)
@@ -1074,9 +1100,11 @@ function nT(T, E, R) {
1074
1100
  case "postgres":
1075
1101
  return _T(T, E);
1076
1102
  case "mysql":
1077
- return jR(T, E);
1103
+ return kR(T, E);
1078
1104
  case "sqlite":
1079
1105
  return rT(T, E);
1106
+ case "singlestore":
1107
+ return TA(T, E);
1080
1108
  }
1081
1109
  if (T.all && T.run)
1082
1110
  return rT(T, E);
@@ -1087,7 +1115,7 @@ function nT(T, E, R) {
1087
1115
  function iT(T) {
1088
1116
  return typeof T == "function" ? T() : T;
1089
1117
  }
1090
- function zR(T, E) {
1118
+ function RA(T, E) {
1091
1119
  if (E) return E;
1092
1120
  switch (T) {
1093
1121
  case "belongsTo":
@@ -1103,7 +1131,7 @@ function zR(T, E) {
1103
1131
  function x(T, E) {
1104
1132
  return typeof T == "function" ? T(E) : T;
1105
1133
  }
1106
- class EA {
1134
+ class AA {
1107
1135
  constructor(E) {
1108
1136
  this.databaseAdapter = E;
1109
1137
  }
@@ -1112,43 +1140,43 @@ class EA {
1112
1140
  * Works for both single and multi-cube queries
1113
1141
  */
1114
1142
  buildSelections(E, R, A) {
1115
- const S = {}, e = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1143
+ const e = {}, S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1116
1144
  if (R.dimensions)
1117
1145
  for (const N of R.dimensions) {
1118
- const [s, _] = N.split("."), I = e.get(s);
1146
+ const [s, _] = N.split("."), I = S.get(s);
1119
1147
  if (I && I.dimensions && I.dimensions[_]) {
1120
1148
  const O = I.dimensions[_], C = x(O.sql, A);
1121
- S[N] = L`${C}`.as(N);
1149
+ e[N] = L`${C}`.as(N);
1122
1150
  }
1123
1151
  }
1124
1152
  if (R.measures)
1125
1153
  for (const N of R.measures) {
1126
- const [s, _] = N.split("."), I = e.get(s);
1154
+ const [s, _] = N.split("."), I = S.get(s);
1127
1155
  if (I && I.measures && I.measures[_]) {
1128
1156
  const O = I.measures[_], C = this.buildMeasureExpression(O, A);
1129
- S[N] = L`${C}`.as(N);
1157
+ e[N] = L`${C}`.as(N);
1130
1158
  }
1131
1159
  }
1132
1160
  if (R.timeDimensions)
1133
1161
  for (const N of R.timeDimensions) {
1134
- const [s, _] = N.dimension.split("."), I = e.get(s);
1162
+ const [s, _] = N.dimension.split("."), I = S.get(s);
1135
1163
  if (I && I.dimensions && I.dimensions[_]) {
1136
1164
  const O = I.dimensions[_], C = this.buildTimeDimensionExpression(
1137
1165
  O.sql,
1138
1166
  N.granularity,
1139
1167
  A
1140
1168
  );
1141
- S[N.dimension] = L`${C}`.as(N.dimension);
1169
+ e[N.dimension] = L`${C}`.as(N.dimension);
1142
1170
  }
1143
1171
  }
1144
- return Object.keys(S).length === 0 && (S.count = uE()), S;
1172
+ return Object.keys(e).length === 0 && (e.count = uE()), e;
1145
1173
  }
1146
1174
  /**
1147
1175
  * Build measure expression for HAVING clause, handling CTE references correctly
1148
1176
  */
1149
- buildHavingMeasureExpression(E, R, A, S, e) {
1150
- if (e && e.preAggregationCTEs) {
1151
- const N = e.preAggregationCTEs.find((s) => s.cube.name === E);
1177
+ buildHavingMeasureExpression(E, R, A, e, S) {
1178
+ if (S && S.preAggregationCTEs) {
1179
+ const N = S.preAggregationCTEs.find((s) => s.cube.name === E);
1152
1180
  if (N && N.measures.includes(`${E}.${R}`)) {
1153
1181
  const s = L`${L.identifier(N.cteAlias)}.${L.identifier(R)}`;
1154
1182
  switch (A.type) {
@@ -1169,7 +1197,7 @@ class EA {
1169
1197
  }
1170
1198
  }
1171
1199
  }
1172
- return this.buildMeasureExpression(A, S);
1200
+ return this.buildMeasureExpression(A, e);
1173
1201
  }
1174
1202
  /**
1175
1203
  * Build measure expression with aggregation and filters
@@ -1177,11 +1205,11 @@ class EA {
1177
1205
  buildMeasureExpression(E, R) {
1178
1206
  let A = x(E.sql, R);
1179
1207
  if (E.filters && E.filters.length > 0) {
1180
- const S = E.filters.map((e) => e(R)).filter(Boolean);
1181
- if (S.length > 0) {
1182
- const e = S.length === 1 ? S[0] : b(...S);
1208
+ const e = E.filters.map((S) => S(R)).filter(Boolean);
1209
+ if (e.length > 0) {
1210
+ const S = e.length === 1 ? e[0] : b(...e);
1183
1211
  A = this.databaseAdapter.buildCaseWhen([
1184
- { when: e, then: A }
1212
+ { when: S, then: A }
1185
1213
  ]);
1186
1214
  }
1187
1215
  }
@@ -1189,7 +1217,7 @@ class EA {
1189
1217
  case "count":
1190
1218
  return uE(A);
1191
1219
  case "countDistinct":
1192
- return JR(A);
1220
+ return xR(A);
1193
1221
  case "sum":
1194
1222
  return Q(A);
1195
1223
  case "avg":
@@ -1208,58 +1236,58 @@ class EA {
1208
1236
  * Build time dimension expression with granularity using database adapter
1209
1237
  */
1210
1238
  buildTimeDimensionExpression(E, R, A) {
1211
- const S = x(E, A);
1212
- return R ? this.databaseAdapter.buildTimeDimension(R, S) : S instanceof m ? S : L`${S}`;
1239
+ const e = x(E, A);
1240
+ return R ? this.databaseAdapter.buildTimeDimension(R, e) : e instanceof m ? e : L`${e}`;
1213
1241
  }
1214
1242
  /**
1215
1243
  * Build WHERE conditions from semantic query filters (dimensions only)
1216
1244
  * Works for both single and multi-cube queries
1217
1245
  */
1218
- buildWhereConditions(E, R, A, S) {
1219
- const e = [], N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1246
+ buildWhereConditions(E, R, A, e) {
1247
+ const S = [], N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1220
1248
  if (R.filters && R.filters.length > 0)
1221
1249
  for (const s of R.filters) {
1222
- const _ = this.processFilter(s, N, A, "where", S);
1223
- _ && e.push(_);
1250
+ const _ = this.processFilter(s, N, A, "where", e);
1251
+ _ && S.push(_);
1224
1252
  }
1225
1253
  if (R.timeDimensions)
1226
1254
  for (const s of R.timeDimensions) {
1227
1255
  const [_, I] = s.dimension.split("."), O = N.get(_);
1228
1256
  if (O && O.dimensions[I] && s.dateRange) {
1229
- if (S != null && S.preAggregationCTEs && S.preAggregationCTEs.some((M) => M.cube.name === _))
1257
+ if (e != null && e.preAggregationCTEs && e.preAggregationCTEs.some((M) => M.cube.name === _))
1230
1258
  continue;
1231
1259
  const C = O.dimensions[I], t = x(C.sql, A), i = this.buildDateRangeCondition(t, s.dateRange);
1232
- i && e.push(i);
1260
+ i && S.push(i);
1233
1261
  }
1234
1262
  }
1235
- return e;
1263
+ return S;
1236
1264
  }
1237
1265
  /**
1238
1266
  * Build HAVING conditions from semantic query filters (measures only)
1239
1267
  * Works for both single and multi-cube queries
1240
1268
  */
1241
- buildHavingConditions(E, R, A, S) {
1242
- const e = [], N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1269
+ buildHavingConditions(E, R, A, e) {
1270
+ const S = [], N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1243
1271
  if (R.filters && R.filters.length > 0)
1244
1272
  for (const s of R.filters) {
1245
- const _ = this.processFilter(s, N, A, "having", S);
1246
- _ && e.push(_);
1273
+ const _ = this.processFilter(s, N, A, "having", e);
1274
+ _ && S.push(_);
1247
1275
  }
1248
- return e;
1276
+ return S;
1249
1277
  }
1250
1278
  /**
1251
1279
  * Process a single filter (basic or logical)
1252
1280
  * @param filterType - 'where' for dimension filters, 'having' for measure filters
1253
1281
  */
1254
- processFilter(E, R, A, S, e) {
1282
+ processFilter(E, R, A, e, S) {
1255
1283
  if ("and" in E || "or" in E) {
1256
1284
  const i = E;
1257
1285
  if (i.and) {
1258
- const P = i.and.map((M) => this.processFilter(M, R, A, S, e)).filter((M) => M !== null);
1286
+ const P = i.and.map((M) => this.processFilter(M, R, A, e, S)).filter((M) => M !== null);
1259
1287
  return P.length > 0 ? b(...P) : null;
1260
1288
  }
1261
1289
  if (i.or) {
1262
- const P = i.or.map((M) => this.processFilter(M, R, A, S, e)).filter((M) => M !== null);
1290
+ const P = i.or.map((M) => this.processFilter(M, R, A, e, S)).filter((M) => M !== null);
1263
1291
  return P.length > 0 ? UE(...P) : null;
1264
1292
  }
1265
1293
  }
@@ -1267,16 +1295,16 @@ class EA {
1267
1295
  if (!I) return null;
1268
1296
  const O = I.dimensions[_], C = I.measures[_], t = O || C;
1269
1297
  if (!t) return null;
1270
- if (S === "where" && O) {
1271
- if (e != null && e.preAggregationCTEs && e.preAggregationCTEs.some((M) => M.cube.name === s))
1298
+ if (e === "where" && O) {
1299
+ if (S != null && S.preAggregationCTEs && S.preAggregationCTEs.some((M) => M.cube.name === s))
1272
1300
  return null;
1273
1301
  const i = x(O.sql, A);
1274
1302
  return this.buildFilterCondition(i, N.operator, N.values, t);
1275
1303
  } else {
1276
- if (S === "where" && C)
1304
+ if (e === "where" && C)
1277
1305
  return null;
1278
- if (S === "having" && C) {
1279
- const i = this.buildHavingMeasureExpression(s, _, C, A, e);
1306
+ if (e === "having" && C) {
1307
+ const i = this.buildHavingMeasureExpression(s, _, C, A, S);
1280
1308
  return this.buildFilterCondition(i, N.operator, N.values, t);
1281
1309
  }
1282
1310
  }
@@ -1285,28 +1313,28 @@ class EA {
1285
1313
  /**
1286
1314
  * Build filter condition using Drizzle operators
1287
1315
  */
1288
- buildFilterCondition(E, R, A, S) {
1316
+ buildFilterCondition(E, R, A, e) {
1289
1317
  if (!A || A.length === 0)
1290
1318
  return R === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
1291
- const e = A.filter((s) => !(s == null || s === "" || typeof s == "string" && s.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
1292
- if (e.length === 0 && !["set", "notSet"].includes(R))
1319
+ const S = A.filter((s) => !(s == null || s === "" || typeof s == "string" && s.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
1320
+ if (S.length === 0 && !["set", "notSet"].includes(R))
1293
1321
  return R === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
1294
- const N = e[0];
1322
+ const N = S[0];
1295
1323
  switch (R) {
1296
1324
  case "equals":
1297
- if (e.length > 1) {
1298
- if ((S == null ? void 0 : S.type) === "time") {
1299
- const s = e.map((_) => this.normalizeDate(_) || _);
1325
+ if (S.length > 1) {
1326
+ if ((e == null ? void 0 : e.type) === "time") {
1327
+ const s = S.map((_) => this.normalizeDate(_) || _);
1300
1328
  return cE(E, s);
1301
1329
  }
1302
- return cE(E, e);
1303
- } else if (e.length === 1) {
1304
- const s = (S == null ? void 0 : S.type) === "time" && this.normalizeDate(N) || N;
1330
+ return cE(E, S);
1331
+ } else if (S.length === 1) {
1332
+ const s = (e == null ? void 0 : e.type) === "time" && this.normalizeDate(N) || N;
1305
1333
  return _E(E, s);
1306
1334
  }
1307
1335
  return this.databaseAdapter.buildBooleanLiteral(!1);
1308
1336
  case "notEquals":
1309
- return e.length > 1 ? tT(E, e) : e.length === 1 ? NT(E, N) : null;
1337
+ return S.length > 1 ? tT(E, S) : S.length === 1 ? NT(E, N) : null;
1310
1338
  case "contains":
1311
1339
  return this.databaseAdapter.buildStringCondition(E, "contains", N);
1312
1340
  case "notContains":
@@ -1328,8 +1356,8 @@ class EA {
1328
1356
  case "notSet":
1329
1357
  return sT(E);
1330
1358
  case "inDateRange":
1331
- if (e.length >= 2) {
1332
- const s = this.normalizeDate(e[0]), _ = this.normalizeDate(e[1]);
1359
+ if (S.length >= 2) {
1360
+ const s = this.normalizeDate(S[0]), _ = this.normalizeDate(S[1]);
1333
1361
  if (s && _)
1334
1362
  return b(
1335
1363
  j(E, s),
@@ -1346,19 +1374,19 @@ class EA {
1346
1374
  return s ? GE(E, s) : null;
1347
1375
  }
1348
1376
  case "between":
1349
- return e.length >= 2 ? b(
1350
- j(E, e[0]),
1351
- k(E, e[1])
1377
+ return S.length >= 2 ? b(
1378
+ j(E, S[0]),
1379
+ k(E, S[1])
1352
1380
  ) : null;
1353
1381
  case "notBetween":
1354
- return e.length >= 2 ? UE(
1355
- lE(E, e[0]),
1356
- GE(E, e[1])
1382
+ return S.length >= 2 ? UE(
1383
+ lE(E, S[0]),
1384
+ GE(E, S[1])
1357
1385
  ) : null;
1358
1386
  case "in":
1359
- return e.length > 0 ? cE(E, e) : null;
1387
+ return S.length > 0 ? cE(E, S) : null;
1360
1388
  case "notIn":
1361
- return e.length > 0 ? tT(E, e) : null;
1389
+ return S.length > 0 ? tT(E, S) : null;
1362
1390
  case "like":
1363
1391
  return this.databaseAdapter.buildStringCondition(E, "like", N);
1364
1392
  case "notLike":
@@ -1389,10 +1417,10 @@ class EA {
1389
1417
  buildDateRangeCondition(E, R) {
1390
1418
  if (!R) return null;
1391
1419
  if (Array.isArray(R) && R.length >= 2) {
1392
- const A = this.normalizeDate(R[0]), S = this.normalizeDate(R[1]);
1393
- return !A || !S ? null : b(
1420
+ const A = this.normalizeDate(R[0]), e = this.normalizeDate(R[1]);
1421
+ return !A || !e ? null : b(
1394
1422
  j(E, A),
1395
- k(E, S)
1423
+ k(E, e)
1396
1424
  );
1397
1425
  }
1398
1426
  if (typeof R == "string") {
@@ -1402,13 +1430,13 @@ class EA {
1402
1430
  j(E, A.start),
1403
1431
  k(E, A.end)
1404
1432
  );
1405
- const S = this.normalizeDate(R);
1406
- if (!S) return null;
1407
- const e = new Date(S);
1408
- e.setUTCHours(0, 0, 0, 0);
1409
- const N = new Date(S);
1433
+ const e = this.normalizeDate(R);
1434
+ if (!e) return null;
1435
+ const S = new Date(e);
1436
+ S.setUTCHours(0, 0, 0, 0);
1437
+ const N = new Date(e);
1410
1438
  return N.setUTCHours(23, 59, 59, 999), b(
1411
- j(E, e),
1439
+ j(E, S),
1412
1440
  k(E, N)
1413
1441
  );
1414
1442
  }
@@ -1419,7 +1447,7 @@ class EA {
1419
1447
  * Handles all 14 DATE_RANGE_OPTIONS from the client
1420
1448
  */
1421
1449
  parseRelativeDateRange(E) {
1422
- const R = /* @__PURE__ */ new Date(), A = E.toLowerCase().trim(), S = R.getUTCFullYear(), e = R.getUTCMonth(), N = R.getUTCDate(), s = R.getUTCDay();
1450
+ const R = /* @__PURE__ */ new Date(), A = E.toLowerCase().trim(), e = R.getUTCFullYear(), S = R.getUTCMonth(), N = R.getUTCDate(), s = R.getUTCDay();
1423
1451
  if (A === "today") {
1424
1452
  const C = new Date(R);
1425
1453
  C.setUTCHours(0, 0, 0, 0);
@@ -1439,15 +1467,15 @@ class EA {
1439
1467
  return i.setUTCDate(t.getUTCDate() + 6), i.setUTCHours(23, 59, 59, 999), { start: t, end: i };
1440
1468
  }
1441
1469
  if (A === "this month") {
1442
- const C = new Date(Date.UTC(S, e, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(S, e + 1, 0, 23, 59, 59, 999));
1470
+ const C = new Date(Date.UTC(e, S, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(e, S + 1, 0, 23, 59, 59, 999));
1443
1471
  return { start: C, end: t };
1444
1472
  }
1445
1473
  if (A === "this quarter") {
1446
- const C = Math.floor(e / 3), t = new Date(Date.UTC(S, C * 3, 1, 0, 0, 0, 0)), i = new Date(Date.UTC(S, C * 3 + 3, 0, 23, 59, 59, 999));
1474
+ const C = Math.floor(S / 3), t = new Date(Date.UTC(e, C * 3, 1, 0, 0, 0, 0)), i = new Date(Date.UTC(e, C * 3 + 3, 0, 23, 59, 59, 999));
1447
1475
  return { start: t, end: i };
1448
1476
  }
1449
1477
  if (A === "this year") {
1450
- const C = new Date(Date.UTC(S, 0, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(S, 11, 31, 23, 59, 59, 999));
1478
+ const C = new Date(Date.UTC(e, 0, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(e, 11, 31, 23, 59, 59, 999));
1451
1479
  return { start: C, end: t };
1452
1480
  }
1453
1481
  const _ = A.match(/^last\s+(\d+)\s+days?$/);
@@ -1464,29 +1492,29 @@ class EA {
1464
1492
  return i.setUTCDate(t.getUTCDate() + 6), i.setUTCHours(23, 59, 59, 999), { start: t, end: i };
1465
1493
  }
1466
1494
  if (A === "last month") {
1467
- const C = new Date(Date.UTC(S, e - 1, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(S, e, 0, 23, 59, 59, 999));
1495
+ const C = new Date(Date.UTC(e, S - 1, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(e, S, 0, 23, 59, 59, 999));
1468
1496
  return { start: C, end: t };
1469
1497
  }
1470
1498
  if (A === "last quarter") {
1471
- const C = Math.floor(e / 3), t = C === 0 ? 3 : C - 1, i = C === 0 ? S - 1 : S, P = new Date(Date.UTC(i, t * 3, 1, 0, 0, 0, 0)), M = new Date(Date.UTC(i, t * 3 + 3, 0, 23, 59, 59, 999));
1499
+ const C = Math.floor(S / 3), t = C === 0 ? 3 : C - 1, i = C === 0 ? e - 1 : e, P = new Date(Date.UTC(i, t * 3, 1, 0, 0, 0, 0)), M = new Date(Date.UTC(i, t * 3 + 3, 0, 23, 59, 59, 999));
1472
1500
  return { start: P, end: M };
1473
1501
  }
1474
1502
  if (A === "last year") {
1475
- const C = new Date(Date.UTC(S - 1, 0, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(S - 1, 11, 31, 23, 59, 59, 999));
1503
+ const C = new Date(Date.UTC(e - 1, 0, 1, 0, 0, 0, 0)), t = new Date(Date.UTC(e - 1, 11, 31, 23, 59, 59, 999));
1476
1504
  return { start: C, end: t };
1477
1505
  }
1478
1506
  if (A === "last 12 months") {
1479
- const C = new Date(Date.UTC(S, e - 11, 1, 0, 0, 0, 0)), t = new Date(R);
1507
+ const C = new Date(Date.UTC(e, S - 11, 1, 0, 0, 0, 0)), t = new Date(R);
1480
1508
  return t.setUTCHours(23, 59, 59, 999), { start: C, end: t };
1481
1509
  }
1482
1510
  const I = A.match(/^last\s+(\d+)\s+months?$/);
1483
1511
  if (I) {
1484
- const C = parseInt(I[1], 10), t = new Date(Date.UTC(S, e - C + 1, 1, 0, 0, 0, 0)), i = new Date(R);
1512
+ const C = parseInt(I[1], 10), t = new Date(Date.UTC(e, S - C + 1, 1, 0, 0, 0, 0)), i = new Date(R);
1485
1513
  return i.setUTCHours(23, 59, 59, 999), { start: t, end: i };
1486
1514
  }
1487
1515
  const O = A.match(/^last\s+(\d+)\s+years?$/);
1488
1516
  if (O) {
1489
- const C = parseInt(O[1], 10), t = new Date(Date.UTC(S - C, 0, 1, 0, 0, 0, 0)), i = new Date(R);
1517
+ const C = parseInt(O[1], 10), t = new Date(Date.UTC(e - C, 0, 1, 0, 0, 0, 0)), i = new Date(R);
1490
1518
  return i.setUTCHours(23, 59, 59, 999), { start: t, end: i };
1491
1519
  }
1492
1520
  return null;
@@ -1501,8 +1529,8 @@ class EA {
1501
1529
  if (E instanceof Date)
1502
1530
  return isNaN(E.getTime()) ? null : E;
1503
1531
  if (typeof E == "number") {
1504
- const A = E < 1e10 ? E * 1e3 : E, S = new Date(A);
1505
- return isNaN(S.getTime()) ? null : S;
1532
+ const A = E < 1e10 ? E * 1e3 : E, e = new Date(A);
1533
+ return isNaN(e.getTime()) ? null : e;
1506
1534
  }
1507
1535
  if (typeof E == "string") {
1508
1536
  const A = new Date(E);
@@ -1515,9 +1543,9 @@ class EA {
1515
1543
  * Build GROUP BY fields from dimensions and time dimensions
1516
1544
  * Works for both single and multi-cube queries
1517
1545
  */
1518
- buildGroupByFields(E, R, A, S) {
1546
+ buildGroupByFields(E, R, A, e) {
1519
1547
  var _, I;
1520
- const e = [];
1548
+ const S = [];
1521
1549
  if (!(R.measures && R.measures.length > 0))
1522
1550
  return [];
1523
1551
  const s = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
@@ -1525,35 +1553,35 @@ class EA {
1525
1553
  for (const O of R.dimensions) {
1526
1554
  const [C, t] = O.split("."), i = s.get(C);
1527
1555
  if (i && i.dimensions && i.dimensions[t])
1528
- if ((_ = S == null ? void 0 : S.preAggregationCTEs) == null ? void 0 : _.some((M) => M.cube.name === C)) {
1529
- const M = S.preAggregationCTEs.find((G) => G.cube.name === C), o = M.joinKeys.find((G) => G.targetColumn === t);
1556
+ if ((_ = e == null ? void 0 : e.preAggregationCTEs) == null ? void 0 : _.some((M) => M.cube.name === C)) {
1557
+ const M = e.preAggregationCTEs.find((G) => G.cube.name === C), o = M.joinKeys.find((G) => G.targetColumn === t);
1530
1558
  if (o && o.sourceColumnObj)
1531
- e.push(o.sourceColumnObj);
1559
+ S.push(o.sourceColumnObj);
1532
1560
  else {
1533
1561
  const G = L`${L.identifier(M.cteAlias)}.${L.identifier(t)}`;
1534
- e.push(G);
1562
+ S.push(G);
1535
1563
  }
1536
1564
  } else {
1537
1565
  const M = i.dimensions[t], o = x(M.sql, A);
1538
- e.push(o);
1566
+ S.push(o);
1539
1567
  }
1540
1568
  }
1541
1569
  if (R.timeDimensions)
1542
1570
  for (const O of R.timeDimensions) {
1543
1571
  const [C, t] = O.dimension.split("."), i = s.get(C);
1544
1572
  if (i && i.dimensions && i.dimensions[t])
1545
- if ((I = S == null ? void 0 : S.preAggregationCTEs) == null ? void 0 : I.some((M) => M.cube.name === C)) {
1546
- const M = S.preAggregationCTEs.find((G) => G.cube.name === C), o = M.joinKeys.find((G) => G.targetColumn === t);
1573
+ if ((I = e == null ? void 0 : e.preAggregationCTEs) == null ? void 0 : I.some((M) => M.cube.name === C)) {
1574
+ const M = e.preAggregationCTEs.find((G) => G.cube.name === C), o = M.joinKeys.find((G) => G.targetColumn === t);
1547
1575
  if (o && o.sourceColumnObj) {
1548
1576
  const G = this.buildTimeDimensionExpression(
1549
1577
  o.sourceColumnObj,
1550
1578
  O.granularity,
1551
1579
  A
1552
1580
  );
1553
- e.push(G);
1581
+ S.push(G);
1554
1582
  } else {
1555
1583
  const G = L`${L.identifier(M.cteAlias)}.${L.identifier(t)}`;
1556
- e.push(G);
1584
+ S.push(G);
1557
1585
  }
1558
1586
  } else {
1559
1587
  const M = i.dimensions[t], o = this.buildTimeDimensionExpression(
@@ -1561,26 +1589,26 @@ class EA {
1561
1589
  O.granularity,
1562
1590
  A
1563
1591
  );
1564
- e.push(o);
1592
+ S.push(o);
1565
1593
  }
1566
1594
  }
1567
- return e;
1595
+ return S;
1568
1596
  }
1569
1597
  /**
1570
1598
  * Build ORDER BY clause with automatic time dimension sorting
1571
1599
  */
1572
1600
  buildOrderBy(E, R) {
1573
- var e;
1574
- const A = [], S = R || [
1601
+ var S;
1602
+ const A = [], e = R || [
1575
1603
  ...E.measures || [],
1576
1604
  ...E.dimensions || [],
1577
- ...((e = E.timeDimensions) == null ? void 0 : e.map((N) => N.dimension)) || []
1605
+ ...((S = E.timeDimensions) == null ? void 0 : S.map((N) => N.dimension)) || []
1578
1606
  ];
1579
1607
  if (E.order && Object.keys(E.order).length > 0)
1580
1608
  for (const [N, s] of Object.entries(E.order)) {
1581
- if (!S.includes(N))
1609
+ if (!e.includes(N))
1582
1610
  throw new Error(`Cannot order by '${N}': field is not selected in the query`);
1583
- const _ = s === "desc" ? gR(L.identifier(N)) : LT(L.identifier(N));
1611
+ const _ = s === "desc" ? wR(L.identifier(N)) : LT(L.identifier(N));
1584
1612
  A.push(_);
1585
1613
  }
1586
1614
  if (E.timeDimensions && E.timeDimensions.length > 0) {
@@ -1597,13 +1625,13 @@ class EA {
1597
1625
  * Works for both single and multi-cube queries
1598
1626
  */
1599
1627
  collectNumericFields(E, R) {
1600
- const A = [], S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1628
+ const A = [], e = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1601
1629
  if (R.measures && A.push(...R.measures), R.dimensions)
1602
- for (const e of R.dimensions) {
1603
- const [N, s] = e.split("."), _ = S.get(N);
1630
+ for (const S of R.dimensions) {
1631
+ const [N, s] = S.split("."), _ = e.get(N);
1604
1632
  if (_) {
1605
1633
  const I = _.dimensions[s];
1606
- I && I.type === "number" && A.push(e);
1634
+ I && I.type === "number" && A.push(S);
1607
1635
  }
1608
1636
  }
1609
1637
  return A;
@@ -1615,21 +1643,21 @@ class EA {
1615
1643
  applyLimitAndOffset(E, R) {
1616
1644
  let A = R.limit;
1617
1645
  R.offset !== void 0 && R.offset > 0 && A === void 0 && (A = 50);
1618
- let S = E;
1646
+ let e = E;
1619
1647
  if (A !== void 0) {
1620
1648
  if (A < 0)
1621
1649
  throw new Error("Limit must be non-negative");
1622
- S = S.limit(A);
1650
+ e = e.limit(A);
1623
1651
  }
1624
1652
  if (R.offset !== void 0) {
1625
1653
  if (R.offset < 0)
1626
1654
  throw new Error("Offset must be non-negative");
1627
- S = S.offset(R.offset);
1655
+ e = e.offset(R.offset);
1628
1656
  }
1629
- return S;
1657
+ return e;
1630
1658
  }
1631
1659
  }
1632
- class TA {
1660
+ class eA {
1633
1661
  /**
1634
1662
  * Analyze a semantic query to determine which cubes are involved
1635
1663
  */
@@ -1637,18 +1665,18 @@ class TA {
1637
1665
  const R = /* @__PURE__ */ new Set();
1638
1666
  if (E.measures)
1639
1667
  for (const A of E.measures) {
1640
- const [S] = A.split(".");
1641
- R.add(S);
1668
+ const [e] = A.split(".");
1669
+ R.add(e);
1642
1670
  }
1643
1671
  if (E.dimensions)
1644
1672
  for (const A of E.dimensions) {
1645
- const [S] = A.split(".");
1646
- R.add(S);
1673
+ const [e] = A.split(".");
1674
+ R.add(e);
1647
1675
  }
1648
1676
  if (E.timeDimensions)
1649
1677
  for (const A of E.timeDimensions) {
1650
- const [S] = A.dimension.split(".");
1651
- R.add(S);
1678
+ const [e] = A.dimension.split(".");
1679
+ R.add(e);
1652
1680
  }
1653
1681
  if (E.filters)
1654
1682
  for (const A of E.filters)
@@ -1661,8 +1689,8 @@ class TA {
1661
1689
  extractCubeNamesFromFilter(E, R) {
1662
1690
  if ("and" in E || "or" in E) {
1663
1691
  const A = E.and || E.or || [];
1664
- for (const S of A)
1665
- this.extractCubeNamesFromFilter(S, R);
1692
+ for (const e of A)
1693
+ this.extractCubeNamesFromFilter(e, R);
1666
1694
  return;
1667
1695
  }
1668
1696
  if ("member" in E) {
@@ -1677,8 +1705,8 @@ class TA {
1677
1705
  const A = [];
1678
1706
  if (!E.filters)
1679
1707
  return A;
1680
- for (const S of E.filters)
1681
- this.extractMeasuresFromFilter(S, R, A);
1708
+ for (const e of E.filters)
1709
+ this.extractMeasuresFromFilter(e, R, A);
1682
1710
  return A;
1683
1711
  }
1684
1712
  /**
@@ -1686,27 +1714,27 @@ class TA {
1686
1714
  */
1687
1715
  extractMeasuresFromFilter(E, R, A) {
1688
1716
  if ("and" in E || "or" in E) {
1689
- const S = E.and || E.or || [];
1690
- for (const e of S)
1691
- this.extractMeasuresFromFilter(e, R, A);
1717
+ const e = E.and || E.or || [];
1718
+ for (const S of e)
1719
+ this.extractMeasuresFromFilter(S, R, A);
1692
1720
  return;
1693
1721
  }
1694
1722
  if ("member" in E) {
1695
- const S = E.member, [e] = S.split(".");
1696
- e === R && A.push(S);
1723
+ const e = E.member, [S] = e.split(".");
1724
+ S === R && A.push(e);
1697
1725
  }
1698
1726
  }
1699
1727
  /**
1700
1728
  * Create a unified query plan that works for both single and multi-cube queries
1701
1729
  */
1702
1730
  createQueryPlan(E, R, A) {
1703
- const S = this.analyzeCubeUsage(R), e = Array.from(S);
1704
- if (e.length === 0)
1731
+ const e = this.analyzeCubeUsage(R), S = Array.from(e);
1732
+ if (S.length === 0)
1705
1733
  throw new Error("No cubes found in query");
1706
- const N = this.choosePrimaryCube(e, R, E), s = E.get(N);
1734
+ const N = this.choosePrimaryCube(S, R, E), s = E.get(N);
1707
1735
  if (!s)
1708
1736
  throw new Error(`Primary cube '${N}' not found`);
1709
- if (e.length === 1)
1737
+ if (S.length === 1)
1710
1738
  return {
1711
1739
  primaryCube: s,
1712
1740
  joinCubes: [],
@@ -1718,7 +1746,7 @@ class TA {
1718
1746
  groupByFields: []
1719
1747
  // Will be built by QueryBuilder
1720
1748
  };
1721
- const _ = this.buildJoinPlan(E, s, e), I = this.planPreAggregationCTEs(E, s, _, R);
1749
+ const _ = this.buildJoinPlan(E, s, S), I = this.planPreAggregationCTEs(E, s, _, R);
1722
1750
  return {
1723
1751
  primaryCube: s,
1724
1752
  joinCubes: _,
@@ -1737,26 +1765,26 @@ class TA {
1737
1765
  */
1738
1766
  choosePrimaryCube(E, R, A) {
1739
1767
  if (R.dimensions && R.dimensions.length > 0 && A) {
1740
- const S = R.dimensions.map((N) => N.split(".")[0]), e = /* @__PURE__ */ new Map();
1741
- for (const N of S)
1742
- e.set(N, (e.get(N) || 0) + 1);
1743
- if (e.size > 0) {
1744
- const N = Math.max(...e.values()), s = [...e.entries()].filter(([, _]) => _ === N).map(([_]) => _).sort();
1768
+ const e = R.dimensions.map((N) => N.split(".")[0]), S = /* @__PURE__ */ new Map();
1769
+ for (const N of e)
1770
+ S.set(N, (S.get(N) || 0) + 1);
1771
+ if (S.size > 0) {
1772
+ const N = Math.max(...S.values()), s = [...S.entries()].filter(([, _]) => _ === N).map(([_]) => _).sort();
1745
1773
  for (const _ of s)
1746
1774
  if (this.canReachAllCubes(_, E, A))
1747
1775
  return _;
1748
1776
  }
1749
1777
  }
1750
1778
  if (A) {
1751
- const S = /* @__PURE__ */ new Map();
1752
- for (const e of E)
1753
- if (this.canReachAllCubes(e, E, A)) {
1754
- const N = A.get(e), s = N != null && N.joins ? Object.keys(N.joins).length : 0;
1755
- S.set(e, s);
1779
+ const e = /* @__PURE__ */ new Map();
1780
+ for (const S of E)
1781
+ if (this.canReachAllCubes(S, E, A)) {
1782
+ const N = A.get(S), s = N != null && N.joins ? Object.keys(N.joins).length : 0;
1783
+ e.set(S, s);
1756
1784
  }
1757
- if (S.size > 0) {
1758
- const e = Math.max(...S.values());
1759
- return [...S.entries()].filter(([, s]) => s === e).map(([s]) => s).sort()[0];
1785
+ if (e.size > 0) {
1786
+ const S = Math.max(...e.values());
1787
+ return [...e.entries()].filter(([, s]) => s === S).map(([s]) => s).sort()[0];
1760
1788
  }
1761
1789
  }
1762
1790
  return [...E].sort()[0];
@@ -1765,9 +1793,9 @@ class TA {
1765
1793
  * Check if a cube can reach all other cubes in the list via joins
1766
1794
  */
1767
1795
  canReachAllCubes(E, R, A) {
1768
- const S = R.filter((e) => e !== E);
1769
- for (const e of S) {
1770
- const N = this.findJoinPath(A, E, e, /* @__PURE__ */ new Set());
1796
+ const e = R.filter((S) => S !== E);
1797
+ for (const S of e) {
1798
+ const N = this.findJoinPath(A, E, S, /* @__PURE__ */ new Set());
1771
1799
  if (!N || N.length === 0)
1772
1800
  return !1;
1773
1801
  }
@@ -1778,15 +1806,15 @@ class TA {
1778
1806
  * Supports both direct joins and transitive joins through intermediate cubes
1779
1807
  */
1780
1808
  buildJoinPlan(E, R, A) {
1781
- const S = [], e = /* @__PURE__ */ new Set([R.name]), N = A.filter((s) => s !== R.name);
1809
+ const e = [], S = /* @__PURE__ */ new Set([R.name]), N = A.filter((s) => s !== R.name);
1782
1810
  for (const s of N) {
1783
- if (e.has(s))
1811
+ if (S.has(s))
1784
1812
  continue;
1785
- const _ = this.findJoinPath(E, R.name, s, e);
1813
+ const _ = this.findJoinPath(E, R.name, s, S);
1786
1814
  if (!_ || _.length === 0)
1787
1815
  throw new Error(`No join path found from '${R.name}' to '${s}'`);
1788
1816
  for (const { toCube: I, joinDef: O } of _) {
1789
- if (e.has(I))
1817
+ if (S.has(I))
1790
1818
  continue;
1791
1819
  const C = E.get(I);
1792
1820
  if (!C)
@@ -1797,40 +1825,40 @@ class TA {
1797
1825
  // No source alias needed - use the actual column
1798
1826
  null
1799
1827
  // No target alias needed - use the actual column
1800
- ), i = zR(O.relationship, O.sqlJoinType);
1801
- S.push({
1828
+ ), i = RA(O.relationship, O.sqlJoinType);
1829
+ e.push({
1802
1830
  cube: C,
1803
1831
  alias: `${I.toLowerCase()}_cube`,
1804
1832
  joinType: i,
1805
1833
  joinCondition: t
1806
- }), e.add(I);
1834
+ }), S.add(I);
1807
1835
  }
1808
1836
  }
1809
- return S;
1837
+ return e;
1810
1838
  }
1811
1839
  /**
1812
1840
  * Build join condition from new array-based join definition
1813
1841
  */
1814
1842
  buildJoinCondition(E, R, A) {
1815
- const S = [];
1816
- for (const e of E.on) {
1817
- const N = R ? L`${L.identifier(R)}.${L.identifier(e.source.name)}` : e.source, s = A ? L`${L.identifier(A)}.${L.identifier(e.target.name)}` : e.target, _ = e.as || _E;
1818
- S.push(_(N, s));
1843
+ const e = [];
1844
+ for (const S of E.on) {
1845
+ const N = R ? L`${L.identifier(R)}.${L.identifier(S.source.name)}` : S.source, s = A ? L`${L.identifier(A)}.${L.identifier(S.target.name)}` : S.target, _ = S.as || _E;
1846
+ e.push(_(N, s));
1819
1847
  }
1820
- return b(...S);
1848
+ return b(...e);
1821
1849
  }
1822
1850
  /**
1823
1851
  * Find join path from source cube to target cube
1824
1852
  * Returns array of join steps to reach target
1825
1853
  */
1826
- findJoinPath(E, R, A, S) {
1854
+ findJoinPath(E, R, A, e) {
1827
1855
  if (R === A)
1828
1856
  return [];
1829
- const e = [
1857
+ const S = [
1830
1858
  { cube: R, path: [] }
1831
- ], N = /* @__PURE__ */ new Set([R, ...S]);
1832
- for (; e.length > 0; ) {
1833
- const { cube: s, path: _ } = e.shift(), I = E.get(s);
1859
+ ], N = /* @__PURE__ */ new Set([R, ...e]);
1860
+ for (; S.length > 0; ) {
1861
+ const { cube: s, path: _ } = S.shift(), I = E.get(s);
1834
1862
  if (I != null && I.joins)
1835
1863
  for (const [, O] of Object.entries(I.joins)) {
1836
1864
  const t = iT(O.targetCube).name;
@@ -1843,7 +1871,7 @@ class TA {
1843
1871
  }];
1844
1872
  if (t === A)
1845
1873
  return i;
1846
- N.add(t), e.push({ cube: t, path: i });
1874
+ N.add(t), S.push({ cube: t, path: i });
1847
1875
  }
1848
1876
  }
1849
1877
  return null;
@@ -1851,17 +1879,17 @@ class TA {
1851
1879
  /**
1852
1880
  * Plan pre-aggregation CTEs for hasMany relationships to prevent fan-out
1853
1881
  */
1854
- planPreAggregationCTEs(E, R, A, S) {
1855
- const e = [];
1856
- if (!S.measures || S.measures.length === 0)
1857
- return e;
1882
+ planPreAggregationCTEs(E, R, A, e) {
1883
+ const S = [];
1884
+ if (!e.measures || e.measures.length === 0)
1885
+ return S;
1858
1886
  for (const N of A) {
1859
1887
  const s = this.findHasManyJoinDef(R, N.cube.name);
1860
1888
  if (!s)
1861
1889
  continue;
1862
- const _ = S.measures ? S.measures.filter(
1890
+ const _ = e.measures ? e.measures.filter(
1863
1891
  (t) => t.startsWith(N.cube.name + ".")
1864
- ) : [], I = this.extractMeasuresFromFilters(S, N.cube.name), O = [.../* @__PURE__ */ new Set([..._, ...I])];
1892
+ ) : [], I = this.extractMeasuresFromFilters(e, N.cube.name), O = [.../* @__PURE__ */ new Set([..._, ...I])];
1865
1893
  if (O.length === 0)
1866
1894
  continue;
1867
1895
  const C = s.on.map((t) => ({
@@ -1870,7 +1898,7 @@ class TA {
1870
1898
  sourceColumnObj: t.source,
1871
1899
  targetColumnObj: t.target
1872
1900
  }));
1873
- e.push({
1901
+ S.push({
1874
1902
  cube: N.cube,
1875
1903
  alias: N.alias,
1876
1904
  cteAlias: `${N.cube.name.toLowerCase()}_agg`,
@@ -1878,7 +1906,7 @@ class TA {
1878
1906
  measures: O
1879
1907
  });
1880
1908
  }
1881
- return e;
1909
+ return S;
1882
1910
  }
1883
1911
  /**
1884
1912
  * Find hasMany join definition from primary cube to target cube
@@ -1899,21 +1927,21 @@ class HE {
1899
1927
  l(this, "databaseAdapter");
1900
1928
  if (this.dbExecutor = E, this.databaseAdapter = E.databaseAdapter, !this.databaseAdapter)
1901
1929
  throw new Error("DatabaseExecutor must have a databaseAdapter property");
1902
- this.queryBuilder = new EA(this.databaseAdapter), this.queryPlanner = new TA();
1930
+ this.queryBuilder = new AA(this.databaseAdapter), this.queryPlanner = new eA();
1903
1931
  }
1904
1932
  /**
1905
1933
  * Unified query execution method that handles both single and multi-cube queries
1906
1934
  */
1907
1935
  async execute(E, R, A) {
1908
1936
  try {
1909
- const S = pR(E, R);
1910
- if (!S.isValid)
1911
- throw new Error(`Query validation failed: ${S.errors.join(", ")}`);
1912
- const e = {
1937
+ const e = fR(E, R);
1938
+ if (!e.isValid)
1939
+ throw new Error(`Query validation failed: ${e.errors.join(", ")}`);
1940
+ const S = {
1913
1941
  db: this.dbExecutor.db,
1914
1942
  schema: this.dbExecutor.schema,
1915
1943
  securityContext: A
1916
- }, N = this.queryPlanner.createQueryPlan(E, R, e), s = this.buildUnifiedQuery(N, R, e), _ = this.queryBuilder.collectNumericFields(E, R), I = await this.dbExecutor.execute(s, _), O = Array.isArray(I) ? I.map((t) => {
1944
+ }, N = this.queryPlanner.createQueryPlan(E, R, S), s = this.buildUnifiedQuery(N, R, S), _ = this.queryBuilder.collectNumericFields(E, R), I = await this.dbExecutor.execute(s, _), O = Array.isArray(I) ? I.map((t) => {
1917
1945
  const i = { ...t };
1918
1946
  if (R.timeDimensions) {
1919
1947
  for (const P of R.timeDimensions)
@@ -1932,65 +1960,65 @@ class HE {
1932
1960
  data: O,
1933
1961
  annotation: C
1934
1962
  };
1935
- } catch (S) {
1936
- throw new Error(`Query execution failed: ${S instanceof Error ? S.message : "Unknown error"}`);
1963
+ } catch (e) {
1964
+ throw new Error(`Query execution failed: ${e instanceof Error ? e.message : "Unknown error"}`);
1937
1965
  }
1938
1966
  }
1939
1967
  /**
1940
1968
  * Legacy interface for single cube queries
1941
1969
  */
1942
1970
  async executeQuery(E, R, A) {
1943
- const S = /* @__PURE__ */ new Map();
1944
- return S.set(E.name, E), this.execute(S, R, A);
1971
+ const e = /* @__PURE__ */ new Map();
1972
+ return e.set(E.name, E), this.execute(e, R, A);
1945
1973
  }
1946
1974
  /**
1947
1975
  * Build pre-aggregation CTE for hasMany relationships
1948
1976
  */
1949
- buildPreAggregationCTE(E, R, A, S) {
1977
+ buildPreAggregationCTE(E, R, A, e) {
1950
1978
  var M;
1951
- const e = E.cube, N = e.sql(A), s = {};
1979
+ const S = E.cube, N = S.sql(A), s = {};
1952
1980
  for (const o of E.joinKeys)
1953
1981
  if (o.targetColumnObj) {
1954
1982
  s[o.targetColumn] = o.targetColumnObj;
1955
- for (const [G, a] of Object.entries(e.dimensions || {}))
1983
+ for (const [G, a] of Object.entries(S.dimensions || {}))
1956
1984
  a.sql === o.targetColumnObj && G !== o.targetColumn && (s[G] = L`${o.targetColumnObj}`.as(G));
1957
1985
  }
1958
1986
  for (const o of E.measures) {
1959
1987
  const [, G] = o.split(".");
1960
- if (e.measures && e.measures[G]) {
1961
- const a = e.measures[G], H = this.queryBuilder.buildMeasureExpression(a, A);
1988
+ if (S.measures && S.measures[G]) {
1989
+ const a = S.measures[G], H = this.queryBuilder.buildMeasureExpression(a, A);
1962
1990
  s[G] = L`${H}`.as(G);
1963
1991
  }
1964
1992
  }
1965
- const _ = e.name;
1993
+ const _ = S.name;
1966
1994
  if (R.dimensions)
1967
1995
  for (const o of R.dimensions) {
1968
1996
  const [G, a] = o.split(".");
1969
- if (G === _ && e.dimensions && e.dimensions[a]) {
1970
- const H = e.dimensions[a], u = this.queryBuilder.buildMeasureExpression({ sql: H.sql, type: "number" }, A);
1997
+ if (G === _ && S.dimensions && S.dimensions[a]) {
1998
+ const H = S.dimensions[a], u = this.queryBuilder.buildMeasureExpression({ sql: H.sql, type: "number" }, A);
1971
1999
  s[a] = L`${u}`.as(a);
1972
2000
  }
1973
2001
  }
1974
2002
  if (R.timeDimensions)
1975
2003
  for (const o of R.timeDimensions) {
1976
2004
  const [G, a] = o.dimension.split(".");
1977
- if (G === _ && e.dimensions && e.dimensions[a]) {
1978
- const H = e.dimensions[a], u = this.queryBuilder.buildTimeDimensionExpression(H.sql, o.granularity, A);
2005
+ if (G === _ && S.dimensions && S.dimensions[a]) {
2006
+ const H = S.dimensions[a], u = this.queryBuilder.buildTimeDimensionExpression(H.sql, o.granularity, A);
1979
2007
  s[a] = L`${u}`.as(a);
1980
2008
  }
1981
2009
  }
1982
2010
  if (Object.keys(s).length === 0)
1983
2011
  return null;
1984
2012
  let I = A.db.select(s).from(N.from);
1985
- const O = S ? {
1986
- ...S,
1987
- preAggregationCTEs: (M = S.preAggregationCTEs) == null ? void 0 : M.filter((o) => o.cube.name !== e.name)
1988
- } : void 0, C = this.queryBuilder.buildWhereConditions(e, R, A, O), t = [];
2013
+ const O = e ? {
2014
+ ...e,
2015
+ preAggregationCTEs: (M = e.preAggregationCTEs) == null ? void 0 : M.filter((o) => o.cube.name !== S.name)
2016
+ } : void 0, C = this.queryBuilder.buildWhereConditions(S, R, A, O), t = [];
1989
2017
  if (R.timeDimensions)
1990
2018
  for (const o of R.timeDimensions) {
1991
2019
  const [G, a] = o.dimension.split(".");
1992
- if (G === _ && e.dimensions && e.dimensions[a] && o.dateRange) {
1993
- const H = e.dimensions[a], u = this.queryBuilder.buildMeasureExpression({ sql: H.sql, type: "number" }, A), B = this.queryBuilder.buildDateRangeCondition(u, o.dateRange);
2020
+ if (G === _ && S.dimensions && S.dimensions[a] && o.dateRange) {
2021
+ const H = S.dimensions[a], u = this.queryBuilder.buildMeasureExpression({ sql: H.sql, type: "number" }, A), B = this.queryBuilder.buildDateRangeCondition(u, o.dateRange);
1994
2022
  B && t.push(B);
1995
2023
  }
1996
2024
  }
@@ -1998,8 +2026,8 @@ class HE {
1998
2026
  for (const o of R.filters)
1999
2027
  if (!("and" in o) && !("or" in o) && "member" in o && "operator" in o) {
2000
2028
  const G = o, [a, H] = G.member.split(".");
2001
- if (a === _ && e.dimensions && e.dimensions[H]) {
2002
- const u = e.dimensions[H];
2029
+ if (a === _ && S.dimensions && S.dimensions[H]) {
2030
+ const u = S.dimensions[H];
2003
2031
  if (G.operator === "inDateRange") {
2004
2032
  const B = this.queryBuilder.buildMeasureExpression({ sql: u.sql, type: "number" }, A), Y = this.queryBuilder.buildDateRangeCondition(B, G.values);
2005
2033
  Y && t.push(Y);
@@ -2018,16 +2046,16 @@ class HE {
2018
2046
  if (R.dimensions)
2019
2047
  for (const o of R.dimensions) {
2020
2048
  const [G, a] = o.split(".");
2021
- if (G === _ && e.dimensions && e.dimensions[a]) {
2022
- const H = e.dimensions[a], u = x(H.sql, A);
2049
+ if (G === _ && S.dimensions && S.dimensions[a]) {
2050
+ const H = S.dimensions[a], u = x(H.sql, A);
2023
2051
  P.push(u);
2024
2052
  }
2025
2053
  }
2026
2054
  if (R.timeDimensions)
2027
2055
  for (const o of R.timeDimensions) {
2028
2056
  const [G, a] = o.dimension.split(".");
2029
- if (G === _ && e.dimensions && e.dimensions[a]) {
2030
- const H = e.dimensions[a], u = this.queryBuilder.buildTimeDimensionExpression(H.sql, o.granularity, A);
2057
+ if (G === _ && S.dimensions && S.dimensions[a]) {
2058
+ const H = S.dimensions[a], u = this.queryBuilder.buildTimeDimensionExpression(H.sql, o.granularity, A);
2031
2059
  P.push(u);
2032
2060
  }
2033
2061
  }
@@ -2039,26 +2067,26 @@ class HE {
2039
2067
  */
2040
2068
  buildCTEJoinCondition(E, R, A) {
2041
2069
  var N;
2042
- const S = (N = A.preAggregationCTEs) == null ? void 0 : N.find((s) => s.cube.name === E.cube.name);
2043
- if (!S)
2070
+ const e = (N = A.preAggregationCTEs) == null ? void 0 : N.find((s) => s.cube.name === E.cube.name);
2071
+ if (!e)
2044
2072
  throw new Error(`CTE info not found for cube ${E.cube.name}`);
2045
- const e = [];
2046
- for (const s of S.joinKeys) {
2073
+ const S = [];
2074
+ for (const s of e.joinKeys) {
2047
2075
  const _ = s.sourceColumnObj || L.identifier(s.sourceColumn), I = L`${L.identifier(R)}.${L.identifier(s.targetColumn)}`;
2048
- e.push(_E(_, I));
2076
+ S.push(_E(_, I));
2049
2077
  }
2050
- return e.length === 1 ? e[0] : b(...e);
2078
+ return S.length === 1 ? S[0] : b(...S);
2051
2079
  }
2052
2080
  /**
2053
2081
  * Build unified query that works for both single and multi-cube queries
2054
2082
  */
2055
2083
  buildUnifiedQuery(E, R, A) {
2056
2084
  var M, o, G;
2057
- const S = [], e = /* @__PURE__ */ new Map();
2085
+ const e = [], S = /* @__PURE__ */ new Map();
2058
2086
  if (E.preAggregationCTEs && E.preAggregationCTEs.length > 0)
2059
2087
  for (const a of E.preAggregationCTEs) {
2060
2088
  const H = this.buildPreAggregationCTE(a, R, A, E);
2061
- H && (S.push(H), e.set(a.cube.name, a.cteAlias));
2089
+ H && (e.push(H), S.set(a.cube.name, a.cteAlias));
2062
2090
  }
2063
2091
  const N = E.primaryCube.sql(A), _ = { ...this.queryBuilder.buildSelections(
2064
2092
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
@@ -2107,7 +2135,7 @@ class HE {
2107
2135
  let iE = a.joinKeys.find((DE) => DE.targetColumn === Y);
2108
2136
  if (!iE && ((o = V == null ? void 0 : V.dimensions) != null && o[Y])) {
2109
2137
  const DE = V.dimensions[Y].sql;
2110
- iE = a.joinKeys.find((fR) => fR.targetColumnObj === DE);
2138
+ iE = a.joinKeys.find((VR) => VR.targetColumnObj === DE);
2111
2139
  }
2112
2140
  iE ? _[u] = L`${L.identifier(a.cteAlias)}.${L.identifier(Y)}`.as(u) : K && ((G = V == null ? void 0 : V.dimensions) != null && G[Y]) && (_[u] = L`${L.identifier(a.cteAlias)}.${L.identifier(Y)}`.as(u));
2113
2141
  }
@@ -2115,7 +2143,7 @@ class HE {
2115
2143
  }
2116
2144
  }
2117
2145
  let I = A.db.select(_).from(N.from);
2118
- if (S.length > 0 && (I = A.db.with(...S).select(_).from(N.from)), N.joins)
2146
+ if (e.length > 0 && (I = A.db.with(...e).select(_).from(N.from)), N.joins)
2119
2147
  for (const a of N.joins)
2120
2148
  switch (a.type || "left") {
2121
2149
  case "left":
@@ -2133,7 +2161,7 @@ class HE {
2133
2161
  }
2134
2162
  if (E.joinCubes && E.joinCubes.length > 0)
2135
2163
  for (const a of E.joinCubes) {
2136
- const H = e.get(a.cube.name);
2164
+ const H = S.get(a.cube.name);
2137
2165
  let u, B;
2138
2166
  H ? (u = L`${L.identifier(H)}`, B = this.buildCTEJoinCondition(a, H, E)) : (u = a.cube.sql(A).from, B = a.joinCondition);
2139
2167
  try {
@@ -2157,7 +2185,7 @@ class HE {
2157
2185
  const O = [];
2158
2186
  if (N.where && O.push(N.where), E.joinCubes && E.joinCubes.length > 0)
2159
2187
  for (const a of E.joinCubes) {
2160
- if (e.get(a.cube.name))
2188
+ if (S.get(a.cube.name))
2161
2189
  continue;
2162
2190
  const u = a.cube.sql(A);
2163
2191
  u.where && O.push(u.where);
@@ -2212,8 +2240,8 @@ class HE {
2212
2240
  * Generate raw SQL for debugging (without execution) - unified approach
2213
2241
  */
2214
2242
  async generateSQL(E, R, A) {
2215
- const S = /* @__PURE__ */ new Map();
2216
- return S.set(E.name, E), this.generateUnifiedSQL(S, R, A);
2243
+ const e = /* @__PURE__ */ new Map();
2244
+ return e.set(E.name, E), this.generateUnifiedSQL(e, R, A);
2217
2245
  }
2218
2246
  /**
2219
2247
  * Generate raw SQL for multi-cube queries without execution - unified approach
@@ -2225,11 +2253,11 @@ class HE {
2225
2253
  * Generate SQL using unified approach (works for both single and multi-cube)
2226
2254
  */
2227
2255
  async generateUnifiedSQL(E, R, A) {
2228
- const S = {
2256
+ const e = {
2229
2257
  db: this.dbExecutor.db,
2230
2258
  schema: this.dbExecutor.schema,
2231
2259
  securityContext: A
2232
- }, e = this.queryPlanner.createQueryPlan(E, R, S), s = this.buildUnifiedQuery(e, R, S).toSQL();
2260
+ }, S = this.queryPlanner.createQueryPlan(E, R, e), s = this.buildUnifiedQuery(S, R, e).toSQL();
2233
2261
  return {
2234
2262
  sql: s.sql,
2235
2263
  params: s.params
@@ -2239,7 +2267,7 @@ class HE {
2239
2267
  * Generate annotations for UI metadata - unified approach
2240
2268
  */
2241
2269
  generateAnnotations(E, R) {
2242
- const A = {}, S = {}, e = {}, N = [E.primaryCube];
2270
+ const A = {}, e = {}, S = {}, N = [E.primaryCube];
2243
2271
  if (E.joinCubes && E.joinCubes.length > 0 && N.push(...E.joinCubes.map((s) => s.cube)), R.measures)
2244
2272
  for (const s of R.measures) {
2245
2273
  const [_, I] = s.split("."), O = N.find((C) => C.name === _);
@@ -2257,7 +2285,7 @@ class HE {
2257
2285
  const [_, I] = s.split("."), O = N.find((C) => C.name === _);
2258
2286
  if (O && O.dimensions[I]) {
2259
2287
  const C = O.dimensions[I];
2260
- S[s] = {
2288
+ e[s] = {
2261
2289
  title: C.title || I,
2262
2290
  shortTitle: C.title || I,
2263
2291
  type: C.type
@@ -2269,7 +2297,7 @@ class HE {
2269
2297
  const [_, I] = s.dimension.split("."), O = N.find((C) => C.name === _);
2270
2298
  if (O && O.dimensions && O.dimensions[I]) {
2271
2299
  const C = O.dimensions[I];
2272
- e[s.dimension] = {
2300
+ S[s.dimension] = {
2273
2301
  title: C.title || I,
2274
2302
  shortTitle: C.title || I,
2275
2303
  type: C.type,
@@ -2279,20 +2307,20 @@ class HE {
2279
2307
  }
2280
2308
  return {
2281
2309
  measures: A,
2282
- dimensions: S,
2310
+ dimensions: e,
2283
2311
  segments: {},
2284
- timeDimensions: e
2312
+ timeDimensions: S
2285
2313
  };
2286
2314
  }
2287
2315
  }
2288
- const r = (T) => T.flatMap(RA), RA = (T) => NE(SA(T)).map(AA), AA = (T) => T.replace(/ +/g, " ").trim(), SA = (T) => ({
2316
+ const r = (T) => T.flatMap(SA), SA = (T) => NE(OA(T)).map(IA), IA = (T) => T.replace(/ +/g, " ").trim(), OA = (T) => ({
2289
2317
  type: "mandatory_block",
2290
2318
  items: AT(T, 0)[0]
2291
2319
  }), AT = (T, E, R) => {
2292
2320
  const A = [];
2293
2321
  for (; T[E]; ) {
2294
- const [S, e] = eA(T, E);
2295
- if (A.push(S), E = e, T[E] === "|")
2322
+ const [e, S] = NA(T, E);
2323
+ if (A.push(e), E = S, T[E] === "|")
2296
2324
  E++;
2297
2325
  else if (T[E] === "}" || T[E] === "]") {
2298
2326
  if (R !== T[E])
@@ -2306,67 +2334,67 @@ const r = (T) => T.flatMap(RA), RA = (T) => NE(SA(T)).map(AA), AA = (T) => T.rep
2306
2334
  throw new Error(`Unexpected "${T[E]}"`);
2307
2335
  }
2308
2336
  return [A, E];
2309
- }, eA = (T, E) => {
2337
+ }, NA = (T, E) => {
2310
2338
  const R = [];
2311
2339
  for (; ; ) {
2312
- const [A, S] = IA(T, E);
2340
+ const [A, e] = tA(T, E);
2313
2341
  if (A)
2314
- R.push(A), E = S;
2342
+ R.push(A), E = e;
2315
2343
  else
2316
2344
  break;
2317
2345
  }
2318
2346
  return R.length === 1 ? [R[0], E] : [{ type: "concatenation", items: R }, E];
2319
- }, IA = (T, E) => {
2347
+ }, tA = (T, E) => {
2320
2348
  if (T[E] === "{")
2321
- return OA(T, E + 1);
2349
+ return sA(T, E + 1);
2322
2350
  if (T[E] === "[")
2323
- return NA(T, E + 1);
2351
+ return CA(T, E + 1);
2324
2352
  {
2325
2353
  let R = "";
2326
2354
  for (; T[E] && /[A-Za-z0-9_ ]/.test(T[E]); )
2327
2355
  R += T[E], E++;
2328
2356
  return [R, E];
2329
2357
  }
2330
- }, OA = (T, E) => {
2358
+ }, sA = (T, E) => {
2331
2359
  const [R, A] = AT(T, E, "}");
2332
2360
  return [{ type: "mandatory_block", items: R }, A];
2333
- }, NA = (T, E) => {
2361
+ }, CA = (T, E) => {
2334
2362
  const [R, A] = AT(T, E, "]");
2335
2363
  return [{ type: "optional_block", items: R }, A];
2336
2364
  }, NE = (T) => {
2337
2365
  if (typeof T == "string")
2338
2366
  return [T];
2339
2367
  if (T.type === "concatenation")
2340
- return T.items.map(NE).reduce(tA, [""]);
2368
+ return T.items.map(NE).reduce(LA, [""]);
2341
2369
  if (T.type === "mandatory_block")
2342
2370
  return T.items.flatMap(NE);
2343
2371
  if (T.type === "optional_block")
2344
2372
  return ["", ...T.items.flatMap(NE)];
2345
2373
  throw new Error(`Unknown node type: ${T}`);
2346
- }, tA = (T, E) => {
2374
+ }, LA = (T, E) => {
2347
2375
  const R = [];
2348
2376
  for (const A of T)
2349
- for (const S of E)
2350
- R.push(A + S);
2377
+ for (const e of E)
2378
+ R.push(A + e);
2351
2379
  return R;
2352
2380
  };
2353
2381
  var D;
2354
2382
  (function(T) {
2355
2383
  T.QUOTED_IDENTIFIER = "QUOTED_IDENTIFIER", T.IDENTIFIER = "IDENTIFIER", T.STRING = "STRING", T.VARIABLE = "VARIABLE", T.RESERVED_DATA_TYPE = "RESERVED_DATA_TYPE", T.RESERVED_PARAMETERIZED_DATA_TYPE = "RESERVED_PARAMETERIZED_DATA_TYPE", T.RESERVED_KEYWORD = "RESERVED_KEYWORD", T.RESERVED_FUNCTION_NAME = "RESERVED_FUNCTION_NAME", T.RESERVED_PHRASE = "RESERVED_PHRASE", T.RESERVED_SET_OPERATION = "RESERVED_SET_OPERATION", T.RESERVED_CLAUSE = "RESERVED_CLAUSE", T.RESERVED_SELECT = "RESERVED_SELECT", T.RESERVED_JOIN = "RESERVED_JOIN", T.ARRAY_IDENTIFIER = "ARRAY_IDENTIFIER", T.ARRAY_KEYWORD = "ARRAY_KEYWORD", T.CASE = "CASE", T.END = "END", T.WHEN = "WHEN", T.ELSE = "ELSE", T.THEN = "THEN", T.LIMIT = "LIMIT", T.BETWEEN = "BETWEEN", T.AND = "AND", T.OR = "OR", T.XOR = "XOR", T.OPERATOR = "OPERATOR", T.COMMA = "COMMA", T.ASTERISK = "ASTERISK", T.PROPERTY_ACCESS_OPERATOR = "PROPERTY_ACCESS_OPERATOR", T.OPEN_PAREN = "OPEN_PAREN", T.CLOSE_PAREN = "CLOSE_PAREN", T.LINE_COMMENT = "LINE_COMMENT", T.BLOCK_COMMENT = "BLOCK_COMMENT", T.DISABLE_COMMENT = "DISABLE_COMMENT", T.NUMBER = "NUMBER", T.NAMED_PARAMETER = "NAMED_PARAMETER", T.QUOTED_PARAMETER = "QUOTED_PARAMETER", T.NUMBERED_PARAMETER = "NUMBERED_PARAMETER", T.POSITIONAL_PARAMETER = "POSITIONAL_PARAMETER", T.CUSTOM_PARAMETER = "CUSTOM_PARAMETER", T.DELIMITER = "DELIMITER", T.EOF = "EOF";
2356
2384
  })(D = D || (D = {}));
2357
- const aR = (T) => ({
2385
+ const PR = (T) => ({
2358
2386
  type: D.EOF,
2359
2387
  raw: "«EOF»",
2360
2388
  text: "«EOF»",
2361
2389
  start: T
2362
- }), TE = aR(1 / 0), z = (T) => (E) => E.type === T.type && E.text === T.text, Z = {
2390
+ }), TE = PR(1 / 0), z = (T) => (E) => E.type === T.type && E.text === T.text, Z = {
2363
2391
  ARRAY: z({ text: "ARRAY", type: D.RESERVED_DATA_TYPE }),
2364
2392
  BY: z({ text: "BY", type: D.RESERVED_KEYWORD }),
2365
2393
  SET: z({ text: "SET", type: D.RESERVED_CLAUSE }),
2366
2394
  STRUCT: z({ text: "STRUCT", type: D.RESERVED_DATA_TYPE }),
2367
2395
  WINDOW: z({ text: "WINDOW", type: D.RESERVED_CLAUSE }),
2368
2396
  VALUES: z({ text: "VALUES", type: D.RESERVED_CLAUSE })
2369
- }, oR = (T) => T === D.RESERVED_DATA_TYPE || T === D.RESERVED_KEYWORD || T === D.RESERVED_FUNCTION_NAME || T === D.RESERVED_PHRASE || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.ARRAY_KEYWORD || T === D.CASE || T === D.END || T === D.WHEN || T === D.ELSE || T === D.THEN || T === D.LIMIT || T === D.BETWEEN || T === D.AND || T === D.OR || T === D.XOR, sA = (T) => T === D.AND || T === D.OR || T === D.XOR, CA = [
2397
+ }, MR = (T) => T === D.RESERVED_DATA_TYPE || T === D.RESERVED_KEYWORD || T === D.RESERVED_FUNCTION_NAME || T === D.RESERVED_PHRASE || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.ARRAY_KEYWORD || T === D.CASE || T === D.END || T === D.WHEN || T === D.ELSE || T === D.THEN || T === D.LIMIT || T === D.BETWEEN || T === D.AND || T === D.OR || T === D.XOR, _A = (T) => T === D.AND || T === D.OR || T === D.XOR, rA = [
2370
2398
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/aead_encryption_functions
2371
2399
  "KEYS.NEW_KEYSET",
2372
2400
  "KEYS.ADD_KEY_FROM_RAW_BYTES",
@@ -2910,7 +2938,7 @@ const aR = (T) => ({
2910
2938
  // pivot
2911
2939
  "PIVOT",
2912
2940
  "UNPIVOT"
2913
- ], LA = [
2941
+ ], nA = [
2914
2942
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#reserved_keywords
2915
2943
  "ALL",
2916
2944
  "AND",
@@ -3018,7 +3046,7 @@ const aR = (T) => ({
3018
3046
  "CASCADE",
3019
3047
  "RESTRICT",
3020
3048
  "DETERMINISTIC"
3021
- ], _A = [
3049
+ ], iA = [
3022
3050
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
3023
3051
  "ARRAY",
3024
3052
  "BOOL",
@@ -3043,7 +3071,7 @@ const aR = (T) => ({
3043
3071
  "STRUCT",
3044
3072
  "TIME",
3045
3073
  "TIMEZONE"
3046
- ], rA = r(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), nA = r([
3074
+ ], DA = r(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), aA = r([
3047
3075
  // Queries: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
3048
3076
  "WITH [RECURSIVE]",
3049
3077
  "FROM",
@@ -3162,15 +3190,15 @@ const aR = (T) => ({
3162
3190
  "ASSERT",
3163
3191
  // Other, https://cloud.google.com/bigquery/docs/reference/standard-sql/other-statements
3164
3192
  "EXPORT DATA"
3165
- ]), iA = r([
3193
+ ]), oA = r([
3166
3194
  "UNION {ALL | DISTINCT}",
3167
3195
  "EXCEPT DISTINCT",
3168
3196
  "INTERSECT DISTINCT"
3169
- ]), DA = r([
3197
+ ]), PA = r([
3170
3198
  "JOIN",
3171
3199
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
3172
3200
  "{INNER | CROSS} JOIN"
3173
- ]), aA = r([
3201
+ ]), MA = r([
3174
3202
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#tablesample_operator
3175
3203
  "TABLESAMPLE SYSTEM",
3176
3204
  // From DDL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
@@ -3181,17 +3209,17 @@ const aR = (T) => ({
3181
3209
  "{ROWS | RANGE} BETWEEN",
3182
3210
  // comparison operator
3183
3211
  "IS [NOT] DISTINCT FROM"
3184
- ]), oA = {
3212
+ ]), UA = {
3185
3213
  name: "bigquery",
3186
3214
  tokenizerOptions: {
3187
- reservedSelect: rA,
3188
- reservedClauses: [...nA, ...BE, ...DT],
3189
- reservedSetOperations: iA,
3190
- reservedJoins: DA,
3191
- reservedPhrases: aA,
3192
- reservedKeywords: LA,
3193
- reservedDataTypes: _A,
3194
- reservedFunctionNames: CA,
3215
+ reservedSelect: DA,
3216
+ reservedClauses: [...aA, ...BE, ...DT],
3217
+ reservedSetOperations: oA,
3218
+ reservedJoins: PA,
3219
+ reservedPhrases: MA,
3220
+ reservedKeywords: nA,
3221
+ reservedDataTypes: iA,
3222
+ reservedFunctionNames: rA,
3195
3223
  extraParens: ["[]"],
3196
3224
  stringTypes: [
3197
3225
  // The triple-quoted strings are listed first, so they get matched first.
@@ -3209,49 +3237,49 @@ const aR = (T) => ({
3209
3237
  variableTypes: [{ regex: String.raw`@@\w+` }],
3210
3238
  lineCommentTypes: ["--", "#"],
3211
3239
  operators: ["&", "|", "^", "~", ">>", "<<", "||", "=>"],
3212
- postProcess: PA
3240
+ postProcess: GA
3213
3241
  },
3214
3242
  formatOptions: {
3215
3243
  onelineClauses: [...DT, ...BE],
3216
3244
  tabularOnelineClauses: BE
3217
3245
  }
3218
3246
  };
3219
- function PA(T) {
3220
- return MA(UA(T));
3247
+ function GA(T) {
3248
+ return lA(cA(T));
3221
3249
  }
3222
- function MA(T) {
3250
+ function lA(T) {
3223
3251
  let E = TE;
3224
3252
  return T.map((R) => R.text === "OFFSET" && E.text === "[" ? (E = R, Object.assign(Object.assign({}, R), { type: D.RESERVED_FUNCTION_NAME })) : (E = R, R));
3225
3253
  }
3226
- function UA(T) {
3254
+ function cA(T) {
3227
3255
  var E;
3228
3256
  const R = [];
3229
3257
  for (let A = 0; A < T.length; A++) {
3230
- const S = T[A];
3231
- if ((Z.ARRAY(S) || Z.STRUCT(S)) && ((E = T[A + 1]) === null || E === void 0 ? void 0 : E.text) === "<") {
3232
- const e = GA(T, A + 1), N = T.slice(A, e + 1);
3258
+ const e = T[A];
3259
+ if ((Z.ARRAY(e) || Z.STRUCT(e)) && ((E = T[A + 1]) === null || E === void 0 ? void 0 : E.text) === "<") {
3260
+ const S = uA(T, A + 1), N = T.slice(A, S + 1);
3233
3261
  R.push({
3234
3262
  type: D.IDENTIFIER,
3235
3263
  raw: N.map(aT("raw")).join(""),
3236
3264
  text: N.map(aT("text")).join(""),
3237
- start: S.start
3238
- }), A = e;
3265
+ start: e.start
3266
+ }), A = S;
3239
3267
  } else
3240
- R.push(S);
3268
+ R.push(e);
3241
3269
  }
3242
3270
  return R;
3243
3271
  }
3244
3272
  const aT = (T) => (E) => E.type === D.IDENTIFIER || E.type === D.COMMA ? E[T] + " " : E[T];
3245
- function GA(T, E) {
3273
+ function uA(T, E) {
3246
3274
  let R = 0;
3247
3275
  for (let A = E; A < T.length; A++) {
3248
- const S = T[A];
3249
- if (S.text === "<" ? R++ : S.text === ">" ? R-- : S.text === ">>" && (R -= 2), R === 0)
3276
+ const e = T[A];
3277
+ if (e.text === "<" ? R++ : e.text === ">" ? R-- : e.text === ">>" && (R -= 2), R === 0)
3250
3278
  return A;
3251
3279
  }
3252
3280
  return T.length - 1;
3253
3281
  }
3254
- const lA = [
3282
+ const HA = [
3255
3283
  // https://www.ibm.com/docs/en/db2/11.5?topic=bif-aggregate-functions
3256
3284
  "ARRAY_AGG",
3257
3285
  "AVG",
@@ -3571,7 +3599,7 @@ const lA = [
3571
3599
  "RATIO_TO_REPORT",
3572
3600
  // Type casting
3573
3601
  "CAST"
3574
- ], cA = [
3602
+ ], BA = [
3575
3603
  // https://www.ibm.com/docs/en/db2/11.5?topic=sql-reserved-schema-names-reserved-words
3576
3604
  "ACTIVATE",
3577
3605
  "ADD",
@@ -3972,7 +4000,7 @@ const lA = [
3972
4000
  "XMLNAMESPACES",
3973
4001
  "YEAR",
3974
4002
  "YEARS"
3975
- ], uA = [
4003
+ ], mA = [
3976
4004
  // https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
3977
4005
  "ARRAY",
3978
4006
  "BIGINT",
@@ -4014,7 +4042,7 @@ const lA = [
4014
4042
  "VARBINARY",
4015
4043
  "VARCHAR",
4016
4044
  "VARGRAPHIC"
4017
- ], HA = r(["SELECT [ALL | DISTINCT]"]), BA = r([
4045
+ ], FA = r(["SELECT [ALL | DISTINCT]"]), YA = r([
4018
4046
  // queries
4019
4047
  "WITH",
4020
4048
  "FROM",
@@ -4248,26 +4276,26 @@ const lA = [
4248
4276
  "TRANSFER OWNERSHIP OF",
4249
4277
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}",
4250
4278
  "WHILE"
4251
- ]), mA = r(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), FA = r([
4279
+ ]), pA = r(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), dA = r([
4252
4280
  "JOIN",
4253
4281
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
4254
4282
  "{INNER | CROSS} JOIN"
4255
- ]), YA = r([
4283
+ ]), fA = r([
4256
4284
  "ON DELETE",
4257
4285
  "ON UPDATE",
4258
4286
  "SET NULL",
4259
4287
  "{ROWS | RANGE} BETWEEN"
4260
- ]), pA = {
4288
+ ]), hA = {
4261
4289
  name: "db2",
4262
4290
  tokenizerOptions: {
4263
- reservedSelect: HA,
4264
- reservedClauses: [...BA, ...oT, ...mE],
4265
- reservedSetOperations: mA,
4266
- reservedJoins: FA,
4267
- reservedPhrases: YA,
4268
- reservedKeywords: cA,
4269
- reservedDataTypes: uA,
4270
- reservedFunctionNames: lA,
4291
+ reservedSelect: FA,
4292
+ reservedClauses: [...YA, ...oT, ...mE],
4293
+ reservedSetOperations: pA,
4294
+ reservedJoins: dA,
4295
+ reservedPhrases: fA,
4296
+ reservedKeywords: BA,
4297
+ reservedDataTypes: mA,
4298
+ reservedFunctionNames: HA,
4271
4299
  extraParens: ["[]"],
4272
4300
  stringTypes: [
4273
4301
  { quote: "''-qq", prefixes: ["G", "N", "U&"] },
@@ -4301,7 +4329,7 @@ const lA = [
4301
4329
  onelineClauses: [...oT, ...mE],
4302
4330
  tabularOnelineClauses: mE
4303
4331
  }
4304
- }, dA = [
4332
+ }, VA = [
4305
4333
  // https://www.ibm.com/docs/en/i/7.5?topic=functions-aggregate
4306
4334
  // TODO: 'ANY', - conflicts with test for ANY predicate in 'operators.ys'!!
4307
4335
  "ARRAY_AGG",
@@ -4635,7 +4663,7 @@ const lA = [
4635
4663
  "ROW_NUMBER",
4636
4664
  // Type casting
4637
4665
  "CAST"
4638
- ], fA = [
4666
+ ], WA = [
4639
4667
  // https://www.ibm.com/docs/en/i/7.5?topic=words-reserved
4640
4668
  // TODO: This list likely contains all keywords, not only the reserved ones,
4641
4669
  // try to filter it down to just the reserved keywords.
@@ -5131,7 +5159,7 @@ const lA = [
5131
5159
  "YEARS",
5132
5160
  "YES",
5133
5161
  "ZONE"
5134
- ], hA = [
5162
+ ], XA = [
5135
5163
  // https://www.ibm.com/docs/en/i/7.2?topic=iaodsd-odbc-data-types-how-they-correspond-db2-i-database-types
5136
5164
  "ARRAY",
5137
5165
  "BIGINT",
@@ -5167,7 +5195,7 @@ const lA = [
5167
5195
  "VARCHAR",
5168
5196
  "VARGRAPHIC",
5169
5197
  "XML"
5170
- ], VA = r(["SELECT [ALL | DISTINCT]"]), WA = r([
5198
+ ], bA = r(["SELECT [ALL | DISTINCT]"]), yA = r([
5171
5199
  // queries
5172
5200
  "WITH [RECURSIVE]",
5173
5201
  "INTO",
@@ -5293,27 +5321,27 @@ const lA = [
5293
5321
  "TAG",
5294
5322
  "TRANSFER OWNERSHIP OF",
5295
5323
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}"
5296
- ]), XA = r(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), bA = r([
5324
+ ]), KA = r(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), $A = r([
5297
5325
  "JOIN",
5298
5326
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
5299
5327
  "[LEFT | RIGHT] EXCEPTION JOIN",
5300
5328
  "{INNER | CROSS} JOIN"
5301
- ]), yA = r([
5329
+ ]), gA = r([
5302
5330
  "ON DELETE",
5303
5331
  "ON UPDATE",
5304
5332
  "SET NULL",
5305
5333
  "{ROWS | RANGE} BETWEEN"
5306
- ]), KA = {
5334
+ ]), JA = {
5307
5335
  name: "db2i",
5308
5336
  tokenizerOptions: {
5309
- reservedSelect: VA,
5310
- reservedClauses: [...WA, ...PT, ...FE],
5311
- reservedSetOperations: XA,
5312
- reservedJoins: bA,
5313
- reservedPhrases: yA,
5314
- reservedKeywords: fA,
5315
- reservedDataTypes: hA,
5316
- reservedFunctionNames: dA,
5337
+ reservedSelect: bA,
5338
+ reservedClauses: [...yA, ...PT, ...FE],
5339
+ reservedSetOperations: KA,
5340
+ reservedJoins: $A,
5341
+ reservedPhrases: gA,
5342
+ reservedKeywords: WA,
5343
+ reservedDataTypes: XA,
5344
+ reservedFunctionNames: VA,
5317
5345
  nestedBlockComments: !0,
5318
5346
  extraParens: ["[]"],
5319
5347
  stringTypes: [
@@ -5330,7 +5358,7 @@ const lA = [
5330
5358
  onelineClauses: [...PT, ...FE],
5331
5359
  tabularOnelineClauses: FE
5332
5360
  }
5333
- }, $A = [
5361
+ }, wA = [
5334
5362
  // Functions from DuckDB (excluding those that start with an underscore):
5335
5363
  // SELECT DISTINCT upper(function_name) AS function_name
5336
5364
  // FROM duckdb_functions()
@@ -5993,7 +6021,7 @@ const lA = [
5993
6021
  // 'NULL', we really prefer treating it as keyword
5994
6022
  "RANK",
5995
6023
  "ROW_NUMBER"
5996
- ], gA = [
6024
+ ], xA = [
5997
6025
  // Keywords from DuckDB:
5998
6026
  // SELECT upper(keyword_name)
5999
6027
  // FROM duckdb_keywords()
@@ -6075,7 +6103,7 @@ const lA = [
6075
6103
  "WHERE",
6076
6104
  "WINDOW",
6077
6105
  "WITH"
6078
- ], JA = [
6106
+ ], vA = [
6079
6107
  // Types from DuckDB:
6080
6108
  // SELECT DISTINCT upper(type_name)
6081
6109
  // FROM duckdb_types()
@@ -6155,7 +6183,7 @@ const lA = [
6155
6183
  "UUID",
6156
6184
  "VARBINARY",
6157
6185
  "VARCHAR"
6158
- ], wA = r(["SELECT [ALL | DISTINCT]"]), xA = r([
6186
+ ], QA = r(["SELECT [ALL | DISTINCT]"]), ZA = r([
6159
6187
  // queries
6160
6188
  "WITH [RECURSIVE]",
6161
6189
  "FROM",
@@ -6259,11 +6287,11 @@ const lA = [
6259
6287
  "PREPARE",
6260
6288
  "EXECUTE",
6261
6289
  "DEALLOCATE [PREPARE]"
6262
- ]), vA = r([
6290
+ ]), qA = r([
6263
6291
  "UNION [ALL | BY NAME]",
6264
6292
  "EXCEPT [ALL]",
6265
6293
  "INTERSECT [ALL]"
6266
- ]), QA = r([
6294
+ ]), jA = r([
6267
6295
  "JOIN",
6268
6296
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6269
6297
  "{INNER | CROSS} JOIN",
@@ -6272,23 +6300,23 @@ const lA = [
6272
6300
  "POSITIONAL JOIN",
6273
6301
  "ANTI JOIN",
6274
6302
  "SEMI JOIN"
6275
- ]), ZA = r([
6303
+ ]), kA = r([
6276
6304
  "{ROWS | RANGE | GROUPS} BETWEEN",
6277
6305
  "SIMILAR TO",
6278
6306
  "IS [NOT] DISTINCT FROM",
6279
6307
  "TIMESTAMP WITH TIME ZONE"
6280
- ]), qA = {
6308
+ ]), zA = {
6281
6309
  name: "duckdb",
6282
6310
  tokenizerOptions: {
6283
- reservedSelect: wA,
6284
- reservedClauses: [...xA, ...MT, ...YE],
6285
- reservedSetOperations: vA,
6286
- reservedJoins: QA,
6287
- reservedPhrases: ZA,
6311
+ reservedSelect: QA,
6312
+ reservedClauses: [...ZA, ...MT, ...YE],
6313
+ reservedSetOperations: qA,
6314
+ reservedJoins: jA,
6315
+ reservedPhrases: kA,
6288
6316
  supportsXor: !0,
6289
- reservedKeywords: gA,
6290
- reservedDataTypes: JA,
6291
- reservedFunctionNames: $A,
6317
+ reservedKeywords: xA,
6318
+ reservedDataTypes: vA,
6319
+ reservedFunctionNames: wA,
6292
6320
  nestedBlockComments: !0,
6293
6321
  extraParens: ["[]", "{}"],
6294
6322
  stringTypes: [
@@ -6351,7 +6379,7 @@ const lA = [
6351
6379
  onelineClauses: [...MT, ...YE],
6352
6380
  tabularOnelineClauses: YE
6353
6381
  }
6354
- }, jA = [
6382
+ }, Ee = [
6355
6383
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
6356
6384
  // math
6357
6385
  "ABS",
@@ -6559,7 +6587,7 @@ const lA = [
6559
6587
  "CUME_DIST",
6560
6588
  "PERCENT_RANK",
6561
6589
  "NTILE"
6562
- ], kA = [
6590
+ ], Te = [
6563
6591
  // https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl
6564
6592
  // Non-reserved keywords have proscribed meanings in. HiveQL, but can still be used as table or column names
6565
6593
  "ADD",
@@ -6874,7 +6902,7 @@ const lA = [
6874
6902
  "JSONFILE",
6875
6903
  "INPUTFORMAT",
6876
6904
  "OUTPUTFORMAT"
6877
- ], zA = [
6905
+ ], Re = [
6878
6906
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
6879
6907
  "ARRAY",
6880
6908
  "BIGINT",
@@ -6895,7 +6923,7 @@ const lA = [
6895
6923
  "STRUCT",
6896
6924
  "TIMESTAMP",
6897
6925
  "VARCHAR"
6898
- ], ES = r(["SELECT [ALL | DISTINCT]"]), TS = r([
6926
+ ], Ae = r(["SELECT [ALL | DISTINCT]"]), ee = r([
6899
6927
  // queries
6900
6928
  "WITH",
6901
6929
  "FROM",
@@ -6956,23 +6984,23 @@ const lA = [
6956
6984
  "STORED AS",
6957
6985
  "STORED BY",
6958
6986
  "ROW FORMAT"
6959
- ]), RS = r(["UNION [ALL | DISTINCT]"]), AS = r([
6987
+ ]), Se = r(["UNION [ALL | DISTINCT]"]), Ie = r([
6960
6988
  "JOIN",
6961
6989
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6962
6990
  "{INNER | CROSS} JOIN",
6963
6991
  // non-standard joins
6964
6992
  "LEFT SEMI JOIN"
6965
- ]), SS = r(["{ROWS | RANGE} BETWEEN"]), eS = {
6993
+ ]), Oe = r(["{ROWS | RANGE} BETWEEN"]), Ne = {
6966
6994
  name: "hive",
6967
6995
  tokenizerOptions: {
6968
- reservedSelect: ES,
6969
- reservedClauses: [...TS, ...UT, ...pE],
6970
- reservedSetOperations: RS,
6971
- reservedJoins: AS,
6972
- reservedPhrases: SS,
6973
- reservedKeywords: kA,
6974
- reservedDataTypes: zA,
6975
- reservedFunctionNames: jA,
6996
+ reservedSelect: Ae,
6997
+ reservedClauses: [...ee, ...UT, ...pE],
6998
+ reservedSetOperations: Se,
6999
+ reservedJoins: Ie,
7000
+ reservedPhrases: Oe,
7001
+ reservedKeywords: Te,
7002
+ reservedDataTypes: Re,
7003
+ reservedFunctionNames: Ee,
6976
7004
  extraParens: ["[]"],
6977
7005
  stringTypes: ['""-bs', "''-bs"],
6978
7006
  identTypes: ["``"],
@@ -6989,11 +7017,11 @@ function nE(T) {
6989
7017
  const A = T[R + 1] || TE;
6990
7018
  if (Z.SET(E) && A.text === "(")
6991
7019
  return Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME });
6992
- const S = T[R - 1] || TE;
6993
- return Z.VALUES(E) && S.text === "=" ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E;
7020
+ const e = T[R - 1] || TE;
7021
+ return Z.VALUES(E) && e.text === "=" ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E;
6994
7022
  });
6995
7023
  }
6996
- const IS = [
7024
+ const te = [
6997
7025
  // https://mariadb.com/kb/en/reserved-words/
6998
7026
  "ACCESSIBLE",
6999
7027
  "ADD",
@@ -7210,7 +7238,7 @@ const IS = [
7210
7238
  "XOR",
7211
7239
  "YEAR_MONTH",
7212
7240
  "ZEROFILL"
7213
- ], OS = [
7241
+ ], se = [
7214
7242
  // https://mariadb.com/kb/en/data-types/
7215
7243
  "BIGINT",
7216
7244
  "BINARY",
@@ -7261,7 +7289,7 @@ const IS = [
7261
7289
  "YEAR"
7262
7290
  // 'NUMBER', // ?? In oracle mode only
7263
7291
  // 'SET' // handled as special-case in postProcess
7264
- ], NS = [
7292
+ ], Ce = [
7265
7293
  // https://mariadb.com/kb/en/information-schema-sql_functions-table/
7266
7294
  "ADDDATE",
7267
7295
  "ADD_MONTHS",
@@ -7499,7 +7527,7 @@ const IS = [
7499
7527
  // CASE expression shorthands
7500
7528
  "COALESCE",
7501
7529
  "NULLIF"
7502
- ], tS = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), sS = r([
7530
+ ], Le = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), _e = r([
7503
7531
  // queries
7504
7532
  "WITH [RECURSIVE]",
7505
7533
  "FROM",
@@ -7730,12 +7758,12 @@ const IS = [
7730
7758
  "XA RECOVER",
7731
7759
  "XA ROLLBACK",
7732
7760
  "XA START"
7733
- ]), CS = r([
7761
+ ]), re = r([
7734
7762
  "UNION [ALL | DISTINCT]",
7735
7763
  "EXCEPT [ALL | DISTINCT]",
7736
7764
  "INTERSECT [ALL | DISTINCT]",
7737
7765
  "MINUS [ALL | DISTINCT]"
7738
- ]), LS = r([
7766
+ ]), ne = r([
7739
7767
  "JOIN",
7740
7768
  "{LEFT | RIGHT} [OUTER] JOIN",
7741
7769
  "{INNER | CROSS} JOIN",
@@ -7743,23 +7771,23 @@ const IS = [
7743
7771
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
7744
7772
  // non-standard joins
7745
7773
  "STRAIGHT_JOIN"
7746
- ]), _S = r([
7774
+ ]), ie = r([
7747
7775
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
7748
7776
  "CHARACTER SET",
7749
7777
  "{ROWS | RANGE} BETWEEN",
7750
7778
  "IDENTIFIED BY"
7751
- ]), rS = {
7779
+ ]), De = {
7752
7780
  name: "mariadb",
7753
7781
  tokenizerOptions: {
7754
- reservedSelect: tS,
7755
- reservedClauses: [...sS, ...GT, ...dE],
7756
- reservedSetOperations: CS,
7757
- reservedJoins: LS,
7758
- reservedPhrases: _S,
7782
+ reservedSelect: Le,
7783
+ reservedClauses: [..._e, ...GT, ...dE],
7784
+ reservedSetOperations: re,
7785
+ reservedJoins: ne,
7786
+ reservedPhrases: ie,
7759
7787
  supportsXor: !0,
7760
- reservedKeywords: IS,
7761
- reservedDataTypes: OS,
7762
- reservedFunctionNames: NS,
7788
+ reservedKeywords: te,
7789
+ reservedDataTypes: se,
7790
+ reservedFunctionNames: Ce,
7763
7791
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
7764
7792
  stringTypes: [
7765
7793
  '""-qq-bs',
@@ -7798,7 +7826,7 @@ const IS = [
7798
7826
  onelineClauses: [...GT, ...dE],
7799
7827
  tabularOnelineClauses: dE
7800
7828
  }
7801
- }, nS = [
7829
+ }, ae = [
7802
7830
  // https://dev.mysql.com/doc/refman/8.0/en/keywords.html
7803
7831
  "ACCESSIBLE",
7804
7832
  "ADD",
@@ -8029,7 +8057,7 @@ const IS = [
8029
8057
  "YEAR_MONTH",
8030
8058
  "ZEROFILL"
8031
8059
  // (R)
8032
- ], iS = [
8060
+ ], oe = [
8033
8061
  // https://dev.mysql.com/doc/refman/8.0/en/data-types.html
8034
8062
  "BIGINT",
8035
8063
  "BINARY",
@@ -8081,7 +8109,7 @@ const IS = [
8081
8109
  "VARYING",
8082
8110
  "YEAR"
8083
8111
  // 'SET' // handled as special-case in postProcess
8084
- ], DS = [
8112
+ ], Pe = [
8085
8113
  // https://dev.mysql.com/doc/refman/8.0/en/built-in-function-reference.html
8086
8114
  "ABS",
8087
8115
  "ACOS",
@@ -8504,7 +8532,7 @@ const IS = [
8504
8532
  // 'XOR',
8505
8533
  "YEAR",
8506
8534
  "YEARWEEK"
8507
- ], aS = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), oS = r([
8535
+ ], Me = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Ue = r([
8508
8536
  // queries
8509
8537
  "WITH [RECURSIVE]",
8510
8538
  "FROM",
@@ -8705,7 +8733,7 @@ const IS = [
8705
8733
  "REPEAT",
8706
8734
  "RETURN",
8707
8735
  "WHILE"
8708
- ]), PS = r(["UNION [ALL | DISTINCT]"]), MS = r([
8736
+ ]), Ge = r(["UNION [ALL | DISTINCT]"]), le = r([
8709
8737
  "JOIN",
8710
8738
  "{LEFT | RIGHT} [OUTER] JOIN",
8711
8739
  "{INNER | CROSS} JOIN",
@@ -8713,23 +8741,23 @@ const IS = [
8713
8741
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
8714
8742
  // non-standard joins
8715
8743
  "STRAIGHT_JOIN"
8716
- ]), US = r([
8744
+ ]), ce = r([
8717
8745
  "ON {UPDATE | DELETE} [SET NULL]",
8718
8746
  "CHARACTER SET",
8719
8747
  "{ROWS | RANGE} BETWEEN",
8720
8748
  "IDENTIFIED BY"
8721
- ]), GS = {
8749
+ ]), ue = {
8722
8750
  name: "mysql",
8723
8751
  tokenizerOptions: {
8724
- reservedSelect: aS,
8725
- reservedClauses: [...oS, ...lT, ...fE],
8726
- reservedSetOperations: PS,
8727
- reservedJoins: MS,
8728
- reservedPhrases: US,
8752
+ reservedSelect: Me,
8753
+ reservedClauses: [...Ue, ...lT, ...fE],
8754
+ reservedSetOperations: Ge,
8755
+ reservedJoins: le,
8756
+ reservedPhrases: ce,
8729
8757
  supportsXor: !0,
8730
- reservedKeywords: nS,
8731
- reservedDataTypes: iS,
8732
- reservedFunctionNames: DS,
8758
+ reservedKeywords: ae,
8759
+ reservedDataTypes: oe,
8760
+ reservedFunctionNames: Pe,
8733
8761
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
8734
8762
  stringTypes: [
8735
8763
  '""-qq-bs',
@@ -8770,7 +8798,7 @@ const IS = [
8770
8798
  onelineClauses: [...lT, ...fE],
8771
8799
  tabularOnelineClauses: fE
8772
8800
  }
8773
- }, lS = [
8801
+ }, He = [
8774
8802
  // https://docs.pingcap.com/tidb/stable/keywords
8775
8803
  "ADD",
8776
8804
  "ALL",
@@ -8962,7 +8990,7 @@ const IS = [
8962
8990
  "YEAR_MONTH",
8963
8991
  "ZEROFILL"
8964
8992
  // (R)
8965
- ], cS = [
8993
+ ], Be = [
8966
8994
  // https://docs.pingcap.com/tidb/stable/data-type-overview
8967
8995
  "BIGINT",
8968
8996
  "BINARY",
@@ -9009,7 +9037,7 @@ const IS = [
9009
9037
  "VARYING",
9010
9038
  "YEAR"
9011
9039
  // 'SET' // handled as special-case in postProcess
9012
- ], uS = [
9040
+ ], me = [
9013
9041
  // https://docs.pingcap.com/tidb/stable/sql-statement-show-builtins
9014
9042
  // https://docs.pingcap.com/tidb/stable/functions-and-operators-overview
9015
9043
  // + MySQL aggregate functions: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html
@@ -9335,7 +9363,7 @@ const IS = [
9335
9363
  // 'XOR',
9336
9364
  "YEAR",
9337
9365
  "YEARWEEK"
9338
- ], HS = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), BS = r([
9366
+ ], Fe = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Ye = r([
9339
9367
  // queries
9340
9368
  "WITH [RECURSIVE]",
9341
9369
  "FROM",
@@ -9470,7 +9498,7 @@ const IS = [
9470
9498
  "UNLOCK TABLES",
9471
9499
  // https://docs.pingcap.com/tidb/stable/sql-statement-use
9472
9500
  "USE"
9473
- ]), mS = r(["UNION [ALL | DISTINCT]"]), FS = r([
9501
+ ]), pe = r(["UNION [ALL | DISTINCT]"]), de = r([
9474
9502
  "JOIN",
9475
9503
  "{LEFT | RIGHT} [OUTER] JOIN",
9476
9504
  "{INNER | CROSS} JOIN",
@@ -9478,23 +9506,23 @@ const IS = [
9478
9506
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
9479
9507
  // non-standard joins
9480
9508
  "STRAIGHT_JOIN"
9481
- ]), YS = r([
9509
+ ]), fe = r([
9482
9510
  "ON {UPDATE | DELETE} [SET NULL]",
9483
9511
  "CHARACTER SET",
9484
9512
  "{ROWS | RANGE} BETWEEN",
9485
9513
  "IDENTIFIED BY"
9486
- ]), pS = {
9514
+ ]), he = {
9487
9515
  name: "tidb",
9488
9516
  tokenizerOptions: {
9489
- reservedSelect: HS,
9490
- reservedClauses: [...BS, ...cT, ...hE],
9491
- reservedSetOperations: mS,
9492
- reservedJoins: FS,
9493
- reservedPhrases: YS,
9517
+ reservedSelect: Fe,
9518
+ reservedClauses: [...Ye, ...cT, ...hE],
9519
+ reservedSetOperations: pe,
9520
+ reservedJoins: de,
9521
+ reservedPhrases: fe,
9494
9522
  supportsXor: !0,
9495
- reservedKeywords: lS,
9496
- reservedDataTypes: cS,
9497
- reservedFunctionNames: uS,
9523
+ reservedKeywords: He,
9524
+ reservedDataTypes: Be,
9525
+ reservedFunctionNames: me,
9498
9526
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
9499
9527
  stringTypes: [
9500
9528
  '""-qq-bs',
@@ -9535,7 +9563,7 @@ const IS = [
9535
9563
  onelineClauses: [...cT, ...hE],
9536
9564
  tabularOnelineClauses: hE
9537
9565
  }
9538
- }, dS = [
9566
+ }, Ve = [
9539
9567
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/functions.html
9540
9568
  "ABORT",
9541
9569
  "ABS",
@@ -9765,7 +9793,7 @@ const IS = [
9765
9793
  // not implemented in N1QL, but added here now for the sake of tests
9766
9794
  // https://docs.couchbase.com/server/current/analytics/3_query.html#Vs_SQL-92
9767
9795
  "CAST"
9768
- ], fS = [
9796
+ ], We = [
9769
9797
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/reservedwords.html
9770
9798
  "ADVISE",
9771
9799
  "ALL",
@@ -9971,7 +9999,7 @@ const IS = [
9971
9999
  "WITHIN",
9972
10000
  "WORK",
9973
10001
  "XOR"
9974
- ], hS = [
10002
+ ], Xe = [
9975
10003
  // N1QL does not support any way of declaring types for columns.
9976
10004
  // It does not support the CREATE TABLE statement nor the CAST() expression.
9977
10005
  //
@@ -9980,7 +10008,7 @@ const IS = [
9980
10008
  // which it actually doesn't use.
9981
10009
  //
9982
10010
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datatypes.html
9983
- ], VS = r(["SELECT [ALL | DISTINCT]"]), WS = r([
10011
+ ], be = r(["SELECT [ALL | DISTINCT]"]), ye = r([
9984
10012
  // queries
9985
10013
  "WITH",
9986
10014
  "FROM",
@@ -10047,18 +10075,18 @@ const IS = [
10047
10075
  "SET CURRENT SCHEMA",
10048
10076
  "SHOW",
10049
10077
  "USE [PRIMARY] KEYS"
10050
- ]), XS = r(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), bS = r(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), yS = r(["{ROWS | RANGE | GROUPS} BETWEEN"]), KS = {
10078
+ ]), Ke = r(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), $e = r(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), ge = r(["{ROWS | RANGE | GROUPS} BETWEEN"]), Je = {
10051
10079
  name: "n1ql",
10052
10080
  tokenizerOptions: {
10053
- reservedSelect: VS,
10054
- reservedClauses: [...WS, ...uT],
10055
- reservedSetOperations: XS,
10056
- reservedJoins: bS,
10057
- reservedPhrases: yS,
10081
+ reservedSelect: be,
10082
+ reservedClauses: [...ye, ...uT],
10083
+ reservedSetOperations: Ke,
10084
+ reservedJoins: $e,
10085
+ reservedPhrases: ge,
10058
10086
  supportsXor: !0,
10059
- reservedKeywords: fS,
10060
- reservedDataTypes: hS,
10061
- reservedFunctionNames: dS,
10087
+ reservedKeywords: We,
10088
+ reservedDataTypes: Xe,
10089
+ reservedFunctionNames: Ve,
10062
10090
  // NOTE: single quotes are actually not supported in N1QL,
10063
10091
  // but we support them anyway as all other SQL dialects do,
10064
10092
  // which simplifies writing tests that are shared between all dialects.
@@ -10072,7 +10100,7 @@ const IS = [
10072
10100
  formatOptions: {
10073
10101
  onelineClauses: uT
10074
10102
  }
10075
- }, $S = [
10103
+ }, we = [
10076
10104
  // https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/reservewords.htm
10077
10105
  // 'A',
10078
10106
  "ADD",
@@ -10377,7 +10405,7 @@ const IS = [
10377
10405
  "WRITE",
10378
10406
  "YEAR",
10379
10407
  "ZONE"
10380
- ], gS = [
10408
+ ], xe = [
10381
10409
  // https://www.ibm.com/docs/en/db2/10.5?topic=plsql-data-types
10382
10410
  "ARRAY",
10383
10411
  "BFILE_BASE",
@@ -10415,7 +10443,7 @@ const IS = [
10415
10443
  "UROWID",
10416
10444
  "VARCHAR",
10417
10445
  "VARCHAR2"
10418
- ], JS = [
10446
+ ], ve = [
10419
10447
  // https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
10420
10448
  // numeric
10421
10449
  "ABS",
@@ -10680,7 +10708,7 @@ const IS = [
10680
10708
  "PRESENTNNV",
10681
10709
  "PRESENTV",
10682
10710
  "PREVIOUS"
10683
- ], wS = r(["SELECT [ALL | DISTINCT | UNIQUE]"]), xS = r([
10711
+ ], Qe = r(["SELECT [ALL | DISTINCT | UNIQUE]"]), Ze = r([
10684
10712
  // queries
10685
10713
  "WITH",
10686
10714
  "FROM",
@@ -10734,7 +10762,7 @@ const IS = [
10734
10762
  "EXCEPTION",
10735
10763
  "LOOP",
10736
10764
  "START WITH"
10737
- ]), vS = r(["UNION [ALL]", "MINUS", "INTERSECT"]), QS = r([
10765
+ ]), qe = r(["UNION [ALL]", "MINUS", "INTERSECT"]), je = r([
10738
10766
  "JOIN",
10739
10767
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
10740
10768
  "{INNER | CROSS} JOIN",
@@ -10742,22 +10770,22 @@ const IS = [
10742
10770
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN",
10743
10771
  // non-standard joins
10744
10772
  "{CROSS | OUTER} APPLY"
10745
- ]), ZS = r([
10773
+ ]), ke = r([
10746
10774
  "ON {UPDATE | DELETE} [SET NULL]",
10747
10775
  "ON COMMIT",
10748
10776
  "{ROWS | RANGE} BETWEEN"
10749
- ]), qS = {
10777
+ ]), ze = {
10750
10778
  name: "plsql",
10751
10779
  tokenizerOptions: {
10752
- reservedSelect: wS,
10753
- reservedClauses: [...xS, ...HT, ...VE],
10754
- reservedSetOperations: vS,
10755
- reservedJoins: QS,
10756
- reservedPhrases: ZS,
10780
+ reservedSelect: Qe,
10781
+ reservedClauses: [...Ze, ...HT, ...VE],
10782
+ reservedSetOperations: qe,
10783
+ reservedJoins: je,
10784
+ reservedPhrases: ke,
10757
10785
  supportsXor: !0,
10758
- reservedKeywords: $S,
10759
- reservedDataTypes: gS,
10760
- reservedFunctionNames: JS,
10786
+ reservedKeywords: we,
10787
+ reservedDataTypes: xe,
10788
+ reservedFunctionNames: ve,
10761
10789
  stringTypes: [
10762
10790
  { quote: "''-qq", prefixes: ["N"] },
10763
10791
  { quote: "q''", prefixes: ["N"] }
@@ -10782,7 +10810,7 @@ const IS = [
10782
10810
  "@",
10783
10811
  "||"
10784
10812
  ],
10785
- postProcess: jS
10813
+ postProcess: ES
10786
10814
  },
10787
10815
  formatOptions: {
10788
10816
  alwaysDenseOperators: ["@"],
@@ -10790,11 +10818,11 @@ const IS = [
10790
10818
  tabularOnelineClauses: VE
10791
10819
  }
10792
10820
  };
10793
- function jS(T) {
10821
+ function ES(T) {
10794
10822
  let E = TE;
10795
- return T.map((R) => Z.SET(R) && Z.BY(E) ? Object.assign(Object.assign({}, R), { type: D.RESERVED_KEYWORD }) : (oR(R.type) && (E = R), R));
10823
+ return T.map((R) => Z.SET(R) && Z.BY(E) ? Object.assign(Object.assign({}, R), { type: D.RESERVED_KEYWORD }) : (MR(R.type) && (E = R), R));
10796
10824
  }
10797
- const kS = [
10825
+ const TS = [
10798
10826
  // https://www.postgresql.org/docs/14/functions.html
10799
10827
  //
10800
10828
  // https://www.postgresql.org/docs/14/functions-math.html
@@ -11478,7 +11506,7 @@ const kS = [
11478
11506
  "PG_MCV_LIST_ITEMS",
11479
11507
  // cast
11480
11508
  "CAST"
11481
- ], zS = [
11509
+ ], RS = [
11482
11510
  // https://www.postgresql.org/docs/14/sql-keywords-appendix.html
11483
11511
  "ALL",
11484
11512
  "ANALYSE",
@@ -11597,7 +11625,7 @@ const kS = [
11597
11625
  "WITHOUT",
11598
11626
  "YEAR"
11599
11627
  // requires AS
11600
- ], Ee = [
11628
+ ], AS = [
11601
11629
  // https://www.postgresql.org/docs/current/datatype.html
11602
11630
  "ARRAY",
11603
11631
  "BIGINT",
@@ -11631,7 +11659,7 @@ const kS = [
11631
11659
  "VARCHAR",
11632
11660
  "XML",
11633
11661
  "ZONE"
11634
- ], Te = r(["SELECT [ALL | DISTINCT]"]), Re = r([
11662
+ ], eS = r(["SELECT [ALL | DISTINCT]"]), SS = r([
11635
11663
  // queries
11636
11664
  "WITH [RECURSIVE]",
11637
11665
  "FROM",
@@ -11854,17 +11882,17 @@ const kS = [
11854
11882
  "START TRANSACTION",
11855
11883
  "UNLISTEN",
11856
11884
  "VACUUM"
11857
- ]), Ae = r([
11885
+ ]), IS = r([
11858
11886
  "UNION [ALL | DISTINCT]",
11859
11887
  "EXCEPT [ALL | DISTINCT]",
11860
11888
  "INTERSECT [ALL | DISTINCT]"
11861
- ]), Se = r([
11889
+ ]), OS = r([
11862
11890
  "JOIN",
11863
11891
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
11864
11892
  "{INNER | CROSS} JOIN",
11865
11893
  "NATURAL [INNER] JOIN",
11866
11894
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
11867
- ]), ee = r([
11895
+ ]), NS = r([
11868
11896
  "PRIMARY KEY",
11869
11897
  "GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY",
11870
11898
  "ON {UPDATE | DELETE} [NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT]",
@@ -11877,17 +11905,17 @@ const kS = [
11877
11905
  "IS [NOT] DISTINCT FROM",
11878
11906
  "NULLS {FIRST | LAST}",
11879
11907
  "WITH ORDINALITY"
11880
- ]), Ie = {
11908
+ ]), tS = {
11881
11909
  name: "postgresql",
11882
11910
  tokenizerOptions: {
11883
- reservedSelect: Te,
11884
- reservedClauses: [...Re, ...BT, ...WE],
11885
- reservedSetOperations: Ae,
11886
- reservedJoins: Se,
11887
- reservedPhrases: ee,
11888
- reservedKeywords: zS,
11889
- reservedDataTypes: Ee,
11890
- reservedFunctionNames: kS,
11911
+ reservedSelect: eS,
11912
+ reservedClauses: [...SS, ...BT, ...WE],
11913
+ reservedSetOperations: IS,
11914
+ reservedJoins: OS,
11915
+ reservedPhrases: NS,
11916
+ reservedKeywords: RS,
11917
+ reservedDataTypes: AS,
11918
+ reservedFunctionNames: TS,
11891
11919
  nestedBlockComments: !0,
11892
11920
  extraParens: ["[]"],
11893
11921
  stringTypes: [
@@ -12001,7 +12029,7 @@ const kS = [
12001
12029
  onelineClauses: [...BT, ...WE],
12002
12030
  tabularOnelineClauses: WE
12003
12031
  }
12004
- }, Oe = [
12032
+ }, sS = [
12005
12033
  // https://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html
12006
12034
  "ANY_VALUE",
12007
12035
  "APPROXIMATE PERCENTILE_DISC",
@@ -12347,7 +12375,7 @@ const kS = [
12347
12375
  "SLICE_NUM",
12348
12376
  "USER",
12349
12377
  "VERSION"
12350
- ], Ne = [
12378
+ ], CS = [
12351
12379
  // https://docs.aws.amazon.com/redshift/latest/dg/r_pg_keywords.html
12352
12380
  "AES128",
12353
12381
  "AES256",
@@ -12536,7 +12564,7 @@ const kS = [
12536
12564
  * SVL: https://docs.aws.amazon.com/redshift/latest/dg/svl_views.html
12537
12565
  * SVV: https://docs.aws.amazon.com/redshift/latest/dg/svv_views.html
12538
12566
  */
12539
- ], te = [
12567
+ ], LS = [
12540
12568
  // https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-text-and-bpchar-types
12541
12569
  "ARRAY",
12542
12570
  "BIGINT",
@@ -12557,7 +12585,7 @@ const kS = [
12557
12585
  "TEXT",
12558
12586
  "VARBYTE",
12559
12587
  "VARCHAR"
12560
- ], se = r(["SELECT [ALL | DISTINCT]"]), Ce = r([
12588
+ ], _S = r(["SELECT [ALL | DISTINCT]"]), rS = r([
12561
12589
  // queries
12562
12590
  "WITH [RECURSIVE]",
12563
12591
  "FROM",
@@ -12668,13 +12696,13 @@ const kS = [
12668
12696
  "START TRANSACTION",
12669
12697
  "UNLOAD",
12670
12698
  "VACUUM"
12671
- ]), Le = r(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), _e = r([
12699
+ ]), nS = r(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), iS = r([
12672
12700
  "JOIN",
12673
12701
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
12674
12702
  "{INNER | CROSS} JOIN",
12675
12703
  "NATURAL [INNER] JOIN",
12676
12704
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
12677
- ]), re = r([
12705
+ ]), DS = r([
12678
12706
  // https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html
12679
12707
  "NULL AS",
12680
12708
  // https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_SCHEMA.html
@@ -12682,17 +12710,17 @@ const kS = [
12682
12710
  "HIVE METASTORE",
12683
12711
  // in window specifications
12684
12712
  "{ROWS | RANGE} BETWEEN"
12685
- ]), ne = {
12713
+ ]), aS = {
12686
12714
  name: "redshift",
12687
12715
  tokenizerOptions: {
12688
- reservedSelect: se,
12689
- reservedClauses: [...Ce, ...mT, ...XE],
12690
- reservedSetOperations: Le,
12691
- reservedJoins: _e,
12692
- reservedPhrases: re,
12693
- reservedKeywords: Ne,
12694
- reservedDataTypes: te,
12695
- reservedFunctionNames: Oe,
12716
+ reservedSelect: _S,
12717
+ reservedClauses: [...rS, ...mT, ...XE],
12718
+ reservedSetOperations: nS,
12719
+ reservedJoins: iS,
12720
+ reservedPhrases: DS,
12721
+ reservedKeywords: CS,
12722
+ reservedDataTypes: LS,
12723
+ reservedFunctionNames: sS,
12696
12724
  stringTypes: ["''-qq"],
12697
12725
  identTypes: ['""-qq'],
12698
12726
  identChars: { first: "#" },
@@ -12718,7 +12746,7 @@ const kS = [
12718
12746
  onelineClauses: [...mT, ...XE],
12719
12747
  tabularOnelineClauses: XE
12720
12748
  }
12721
- }, ie = [
12749
+ }, oS = [
12722
12750
  // https://deepkb.com/CO_000013/en/kb/IMPORT-fbfa59f0-2bf1-31fe-bb7b-0f9efe9932c6/spark-sql-keywords
12723
12751
  "ADD",
12724
12752
  "AFTER",
@@ -12985,7 +13013,7 @@ const kS = [
12985
13013
  "UNSIGNED",
12986
13014
  "VARIABLES",
12987
13015
  "YEAR_MONTH"
12988
- ], De = [
13016
+ ], PS = [
12989
13017
  // https://spark.apache.org/docs/latest/sql-ref-datatypes.html
12990
13018
  "ARRAY",
12991
13019
  "BIGINT",
@@ -13015,7 +13043,7 @@ const kS = [
13015
13043
  "TINYINT",
13016
13044
  "VARCHAR"
13017
13045
  // No varchar type in Spark, only STRING. Added for the sake of tests
13018
- ], ae = [
13046
+ ], MS = [
13019
13047
  // http://spark.apache.org/docs/latest/sql-ref-functions.html
13020
13048
  //
13021
13049
  // http://spark.apache.org/docs/latest/sql-ref-functions-builtin.html#aggregate-functions
@@ -13336,7 +13364,7 @@ const kS = [
13336
13364
  // Shorthand functions to use in place of CASE expression
13337
13365
  "COALESCE",
13338
13366
  "NULLIF"
13339
- ], oe = r(["SELECT [ALL | DISTINCT]"]), Pe = r([
13367
+ ], US = r(["SELECT [ALL | DISTINCT]"]), GS = r([
13340
13368
  // queries
13341
13369
  "WITH",
13342
13370
  "FROM",
@@ -13417,11 +13445,11 @@ const kS = [
13417
13445
  "SHOW TBLPROPERTIES",
13418
13446
  "SHOW VIEWS",
13419
13447
  "UNCACHE TABLE"
13420
- ]), Me = r([
13448
+ ]), lS = r([
13421
13449
  "UNION [ALL | DISTINCT]",
13422
13450
  "EXCEPT [ALL | DISTINCT]",
13423
13451
  "INTERSECT [ALL | DISTINCT]"
13424
- ]), Ue = r([
13452
+ ]), cS = r([
13425
13453
  "JOIN",
13426
13454
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13427
13455
  "{INNER | CROSS} JOIN",
@@ -13430,23 +13458,23 @@ const kS = [
13430
13458
  // non-standard-joins
13431
13459
  "[LEFT] {ANTI | SEMI} JOIN",
13432
13460
  "NATURAL [LEFT] {ANTI | SEMI} JOIN"
13433
- ]), Ge = r([
13461
+ ]), uS = r([
13434
13462
  "ON DELETE",
13435
13463
  "ON UPDATE",
13436
13464
  "CURRENT ROW",
13437
13465
  "{ROWS | RANGE} BETWEEN"
13438
- ]), le = {
13466
+ ]), HS = {
13439
13467
  name: "spark",
13440
13468
  tokenizerOptions: {
13441
- reservedSelect: oe,
13442
- reservedClauses: [...Pe, ...FT, ...bE],
13443
- reservedSetOperations: Me,
13444
- reservedJoins: Ue,
13445
- reservedPhrases: Ge,
13469
+ reservedSelect: US,
13470
+ reservedClauses: [...GS, ...FT, ...bE],
13471
+ reservedSetOperations: lS,
13472
+ reservedJoins: cS,
13473
+ reservedPhrases: uS,
13446
13474
  supportsXor: !0,
13447
- reservedKeywords: ie,
13448
- reservedDataTypes: De,
13449
- reservedFunctionNames: ae,
13475
+ reservedKeywords: oS,
13476
+ reservedDataTypes: PS,
13477
+ reservedFunctionNames: MS,
13450
13478
  extraParens: ["[]"],
13451
13479
  stringTypes: [
13452
13480
  "''-bs",
@@ -13458,20 +13486,20 @@ const kS = [
13458
13486
  identChars: { allowFirstCharNumber: !0 },
13459
13487
  variableTypes: [{ quote: "{}", prefixes: ["$"], requirePrefix: !0 }],
13460
13488
  operators: ["%", "~", "^", "|", "&", "<=>", "==", "!", "||", "->"],
13461
- postProcess: ce
13489
+ postProcess: BS
13462
13490
  },
13463
13491
  formatOptions: {
13464
13492
  onelineClauses: [...FT, ...bE],
13465
13493
  tabularOnelineClauses: bE
13466
13494
  }
13467
13495
  };
13468
- function ce(T) {
13496
+ function BS(T) {
13469
13497
  return T.map((E, R) => {
13470
- const A = T[R - 1] || TE, S = T[R + 1] || TE;
13471
- return Z.WINDOW(E) && S.type === D.OPEN_PAREN ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E.text === "ITEMS" && E.type === D.RESERVED_KEYWORD && !(A.text === "COLLECTION" && S.text === "TERMINATED") ? Object.assign(Object.assign({}, E), { type: D.IDENTIFIER, text: E.raw }) : E;
13498
+ const A = T[R - 1] || TE, e = T[R + 1] || TE;
13499
+ return Z.WINDOW(E) && e.type === D.OPEN_PAREN ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E.text === "ITEMS" && E.type === D.RESERVED_KEYWORD && !(A.text === "COLLECTION" && e.text === "TERMINATED") ? Object.assign(Object.assign({}, E), { type: D.IDENTIFIER, text: E.raw }) : E;
13472
13500
  });
13473
13501
  }
13474
- const ue = [
13502
+ const mS = [
13475
13503
  // https://www.sqlite.org/lang_corefunc.html
13476
13504
  "ABS",
13477
13505
  "CHANGES",
@@ -13595,7 +13623,7 @@ const ue = [
13595
13623
  "JSON_TREE",
13596
13624
  // cast
13597
13625
  "CAST"
13598
- ], He = [
13626
+ ], FS = [
13599
13627
  // https://www.sqlite.org/lang_keywords.html
13600
13628
  // Note: The keywords listed on that URL are not all reserved keywords.
13601
13629
  // We'll need to clean up this list to only include reserved keywords.
@@ -13748,7 +13776,7 @@ const ue = [
13748
13776
  "WINDOW",
13749
13777
  "WITH",
13750
13778
  "WITHOUT"
13751
- ], Be = [
13779
+ ], YS = [
13752
13780
  // SQLite allows any word as a data type, e.g. CREATE TABLE foo (col1 madeupname(123));
13753
13781
  // Here we just list some common ones as SQL Formatter
13754
13782
  // is only able to detect a predefined list of data types.
@@ -13769,7 +13797,7 @@ const ue = [
13769
13797
  "TEXT",
13770
13798
  "VARCHAR",
13771
13799
  "VARYING CHARACTER"
13772
- ], me = r(["SELECT [ALL | DISTINCT]"]), Fe = r([
13800
+ ], pS = r(["SELECT [ALL | DISTINCT]"]), dS = r([
13773
13801
  // queries
13774
13802
  "WITH [RECURSIVE]",
13775
13803
  "FROM",
@@ -13807,27 +13835,27 @@ const ue = [
13807
13835
  "RENAME TO",
13808
13836
  // - set schema
13809
13837
  "SET SCHEMA"
13810
- ]), Ye = r(["UNION [ALL]", "EXCEPT", "INTERSECT"]), pe = r([
13838
+ ]), fS = r(["UNION [ALL]", "EXCEPT", "INTERSECT"]), hS = r([
13811
13839
  "JOIN",
13812
13840
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13813
13841
  "{INNER | CROSS} JOIN",
13814
13842
  "NATURAL [INNER] JOIN",
13815
13843
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
13816
- ]), de = r([
13844
+ ]), VS = r([
13817
13845
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
13818
13846
  "{ROWS | RANGE | GROUPS} BETWEEN",
13819
13847
  "DO UPDATE"
13820
- ]), fe = {
13848
+ ]), WS = {
13821
13849
  name: "sqlite",
13822
13850
  tokenizerOptions: {
13823
- reservedSelect: me,
13824
- reservedClauses: [...Fe, ...YT, ...yE],
13825
- reservedSetOperations: Ye,
13826
- reservedJoins: pe,
13827
- reservedPhrases: de,
13828
- reservedKeywords: He,
13829
- reservedDataTypes: Be,
13830
- reservedFunctionNames: ue,
13851
+ reservedSelect: pS,
13852
+ reservedClauses: [...dS, ...YT, ...yE],
13853
+ reservedSetOperations: fS,
13854
+ reservedJoins: hS,
13855
+ reservedPhrases: VS,
13856
+ reservedKeywords: FS,
13857
+ reservedDataTypes: YS,
13858
+ reservedFunctionNames: mS,
13831
13859
  stringTypes: [
13832
13860
  "''-qq",
13833
13861
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -13843,7 +13871,7 @@ const ue = [
13843
13871
  onelineClauses: [...YT, ...yE],
13844
13872
  tabularOnelineClauses: yE
13845
13873
  }
13846
- }, he = [
13874
+ }, XS = [
13847
13875
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_9_set_function_specification
13848
13876
  "GROUPING",
13849
13877
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_10_window_function
@@ -13940,7 +13968,7 @@ const ue = [
13940
13968
  "ASIN",
13941
13969
  "ACOS",
13942
13970
  "ATAN"
13943
- ], Ve = [
13971
+ ], bS = [
13944
13972
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#reserved-word
13945
13973
  "ALL",
13946
13974
  "ALLOCATE",
@@ -14138,7 +14166,7 @@ const ue = [
14138
14166
  "WITHIN",
14139
14167
  "WITHOUT",
14140
14168
  "YEAR"
14141
- ], We = [
14169
+ ], yS = [
14142
14170
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_1_data_type
14143
14171
  "ARRAY",
14144
14172
  "BIGINT",
@@ -14178,7 +14206,7 @@ const ue = [
14178
14206
  "TIMESTAMP",
14179
14207
  "VARBINARY",
14180
14208
  "VARCHAR"
14181
- ], Xe = r(["SELECT [ALL | DISTINCT]"]), be = r([
14209
+ ], KS = r(["SELECT [ALL | DISTINCT]"]), $S = r([
14182
14210
  // queries
14183
14211
  "WITH [RECURSIVE]",
14184
14212
  "FROM",
@@ -14222,30 +14250,30 @@ const ue = [
14222
14250
  "TRUNCATE TABLE",
14223
14251
  // other
14224
14252
  "SET SCHEMA"
14225
- ]), ye = r([
14253
+ ]), gS = r([
14226
14254
  "UNION [ALL | DISTINCT]",
14227
14255
  "EXCEPT [ALL | DISTINCT]",
14228
14256
  "INTERSECT [ALL | DISTINCT]"
14229
- ]), Ke = r([
14257
+ ]), JS = r([
14230
14258
  "JOIN",
14231
14259
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14232
14260
  "{INNER | CROSS} JOIN",
14233
14261
  "NATURAL [INNER] JOIN",
14234
14262
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
14235
- ]), $e = r([
14263
+ ]), wS = r([
14236
14264
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
14237
14265
  "{ROWS | RANGE} BETWEEN"
14238
- ]), ge = {
14266
+ ]), xS = {
14239
14267
  name: "sql",
14240
14268
  tokenizerOptions: {
14241
- reservedSelect: Xe,
14242
- reservedClauses: [...be, ...pT, ...KE],
14243
- reservedSetOperations: ye,
14244
- reservedJoins: Ke,
14245
- reservedPhrases: $e,
14246
- reservedKeywords: Ve,
14247
- reservedDataTypes: We,
14248
- reservedFunctionNames: he,
14269
+ reservedSelect: KS,
14270
+ reservedClauses: [...$S, ...pT, ...KE],
14271
+ reservedSetOperations: gS,
14272
+ reservedJoins: JS,
14273
+ reservedPhrases: wS,
14274
+ reservedKeywords: bS,
14275
+ reservedDataTypes: yS,
14276
+ reservedFunctionNames: XS,
14249
14277
  stringTypes: [
14250
14278
  { quote: "''-qq-bs", prefixes: ["N", "U&"] },
14251
14279
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -14258,7 +14286,7 @@ const ue = [
14258
14286
  onelineClauses: [...pT, ...KE],
14259
14287
  tabularOnelineClauses: KE
14260
14288
  }
14261
- }, Je = [
14289
+ }, vS = [
14262
14290
  // https://github.com/trinodb/trino/tree/432d2897bdef99388c1a47188743a061c4ac1f34/docs/src/main/sphinx/functions
14263
14291
  // rg '^\.\. function::' ./docs/src/main/sphinx/functions | cut -d' ' -f 3 | cut -d '(' -f 1 | sort | uniq
14264
14292
  // rg '\* ' ./docs/src/main/sphinx/functions/list-by-topic.rst | grep '\* :func:' | cut -d'`' -f 2
@@ -14692,7 +14720,7 @@ const ue = [
14692
14720
  "NEXT",
14693
14721
  "PERMUTE",
14694
14722
  "PREV"
14695
- ], we = [
14723
+ ], QS = [
14696
14724
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4#L858-L1128
14697
14725
  "ABSENT",
14698
14726
  "ADD",
@@ -14929,7 +14957,7 @@ const ue = [
14929
14957
  "WRAPPER",
14930
14958
  "WRITE",
14931
14959
  "ZONE"
14932
- ], xe = [
14960
+ ], ZS = [
14933
14961
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-main/src/main/java/io/trino/metadata/TypeRegistry.java#L131-L168
14934
14962
  // or https://trino.io/docs/current/language/types.html
14935
14963
  "BIGINT",
@@ -14968,7 +14996,7 @@ const ue = [
14968
14996
  "CODEPOINTS",
14969
14997
  "FUNCTION",
14970
14998
  "JSONPATH"
14971
- ], ve = r(["SELECT [ALL | DISTINCT]"]), Qe = r([
14999
+ ], qS = r(["SELECT [ALL | DISTINCT]"]), jS = r([
14972
15000
  // queries
14973
15001
  "WITH [RECURSIVE]",
14974
15002
  "FROM",
@@ -15054,31 +15082,31 @@ const ue = [
15054
15082
  "SHOW ROLE GRANTS",
15055
15083
  "SHOW FUNCTIONS",
15056
15084
  "SHOW SESSION"
15057
- ]), Ze = r([
15085
+ ]), kS = r([
15058
15086
  "UNION [ALL | DISTINCT]",
15059
15087
  "EXCEPT [ALL | DISTINCT]",
15060
15088
  "INTERSECT [ALL | DISTINCT]"
15061
- ]), qe = r([
15089
+ ]), zS = r([
15062
15090
  "JOIN",
15063
15091
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15064
15092
  "{INNER | CROSS} JOIN",
15065
15093
  "NATURAL [INNER] JOIN",
15066
15094
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
15067
- ]), je = r([
15095
+ ]), EI = r([
15068
15096
  "{ROWS | RANGE | GROUPS} BETWEEN",
15069
15097
  // comparison operator
15070
15098
  "IS [NOT] DISTINCT FROM"
15071
- ]), ke = {
15099
+ ]), TI = {
15072
15100
  name: "trino",
15073
15101
  tokenizerOptions: {
15074
- reservedSelect: ve,
15075
- reservedClauses: [...Qe, ...dT, ...$E],
15076
- reservedSetOperations: Ze,
15077
- reservedJoins: qe,
15078
- reservedPhrases: je,
15079
- reservedKeywords: we,
15080
- reservedDataTypes: xe,
15081
- reservedFunctionNames: Je,
15102
+ reservedSelect: qS,
15103
+ reservedClauses: [...jS, ...dT, ...$E],
15104
+ reservedSetOperations: kS,
15105
+ reservedJoins: zS,
15106
+ reservedPhrases: EI,
15107
+ reservedKeywords: QS,
15108
+ reservedDataTypes: ZS,
15109
+ reservedFunctionNames: vS,
15082
15110
  // Trino also supports {- ... -} parenthesis.
15083
15111
  // The formatting of these currently works out as a result of { and -
15084
15112
  // not getting a space added in-between.
@@ -15110,7 +15138,7 @@ const ue = [
15110
15138
  onelineClauses: [...dT, ...$E],
15111
15139
  tabularOnelineClauses: $E
15112
15140
  }
15113
- }, ze = [
15141
+ }, RI = [
15114
15142
  // https://docs.microsoft.com/en-us/sql/t-sql/functions/functions?view=sql-server-ver15
15115
15143
  // aggregate
15116
15144
  "APPROX_COUNT_DISTINCT",
@@ -15415,7 +15443,7 @@ const ue = [
15415
15443
  // Shorthand functions to use in place of CASE expression
15416
15444
  "COALESCE",
15417
15445
  "NULLIF"
15418
- ], EI = [
15446
+ ], AI = [
15419
15447
  // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15
15420
15448
  // standard
15421
15449
  "ADD",
@@ -15596,7 +15624,7 @@ const ue = [
15596
15624
  "WRITETEXT",
15597
15625
  // https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-ver16#action
15598
15626
  "$ACTION"
15599
- ], TI = [
15627
+ ], eI = [
15600
15628
  // https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15
15601
15629
  "BINARY",
15602
15630
  "BIT",
@@ -15623,7 +15651,7 @@ const ue = [
15623
15651
  "TIMESTAMP",
15624
15652
  "VARBINARY",
15625
15653
  "VARCHAR"
15626
- ], RI = r(["SELECT [ALL | DISTINCT]"]), AI = r([
15654
+ ], SI = r(["SELECT [ALL | DISTINCT]"]), II = r([
15627
15655
  // queries
15628
15656
  "WITH",
15629
15657
  "INTO",
@@ -15830,26 +15858,26 @@ const ue = [
15830
15858
  "XACT_ABORT",
15831
15859
  "XML INDEX",
15832
15860
  "XML SCHEMA COLLECTION"
15833
- ]), SI = r(["UNION [ALL]", "EXCEPT", "INTERSECT"]), eI = r([
15861
+ ]), OI = r(["UNION [ALL]", "EXCEPT", "INTERSECT"]), NI = r([
15834
15862
  "JOIN",
15835
15863
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15836
15864
  "{INNER | CROSS} JOIN",
15837
15865
  // non-standard joins
15838
15866
  "{CROSS | OUTER} APPLY"
15839
- ]), II = r([
15867
+ ]), tI = r([
15840
15868
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
15841
15869
  "{ROWS | RANGE} BETWEEN"
15842
- ]), OI = {
15870
+ ]), sI = {
15843
15871
  name: "transactsql",
15844
15872
  tokenizerOptions: {
15845
- reservedSelect: RI,
15846
- reservedClauses: [...AI, ...fT, ...gE],
15847
- reservedSetOperations: SI,
15848
- reservedJoins: eI,
15849
- reservedPhrases: II,
15850
- reservedKeywords: EI,
15851
- reservedDataTypes: TI,
15852
- reservedFunctionNames: ze,
15873
+ reservedSelect: SI,
15874
+ reservedClauses: [...II, ...fT, ...gE],
15875
+ reservedSetOperations: OI,
15876
+ reservedJoins: NI,
15877
+ reservedPhrases: tI,
15878
+ reservedKeywords: AI,
15879
+ reservedDataTypes: eI,
15880
+ reservedFunctionNames: RI,
15853
15881
  nestedBlockComments: !0,
15854
15882
  stringTypes: [{ quote: "''-qq", prefixes: ["N"] }, "{}"],
15855
15883
  identTypes: ['""-qq', "[]"],
@@ -15882,7 +15910,7 @@ const ue = [
15882
15910
  onelineClauses: [...fT, ...gE],
15883
15911
  tabularOnelineClauses: gE
15884
15912
  }
15885
- }, NI = [
15913
+ }, CI = [
15886
15914
  // List of all keywords taken from:
15887
15915
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/restricted-keywords/list-of-restricted-keywords.html
15888
15916
  // Then filtered down to reserved keywords by running
@@ -16095,7 +16123,7 @@ const ue = [
16095
16123
  "XOR",
16096
16124
  "YEAR_MONTH",
16097
16125
  "ZEROFILL"
16098
- ], tI = [
16126
+ ], LI = [
16099
16127
  // https://docs.singlestore.com/cloud/reference/sql-reference/data-types/
16100
16128
  "BIGINT",
16101
16129
  "BINARY",
@@ -16144,7 +16172,7 @@ const ue = [
16144
16172
  "VARCHAR",
16145
16173
  "VARCHARACTER",
16146
16174
  "YEAR"
16147
- ], sI = [
16175
+ ], _I = [
16148
16176
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions/vector-functions.html
16149
16177
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/window-functions/window-functions.html
16150
16178
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/string-functions/string-functions.html
@@ -16424,7 +16452,7 @@ const ue = [
16424
16452
  "WEEKDAY",
16425
16453
  "WEEKOFYEAR",
16426
16454
  "YEAR"
16427
- ], CI = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), LI = r([
16455
+ ], rI = r(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), nI = r([
16428
16456
  // queries
16429
16457
  "WITH",
16430
16458
  "FROM",
@@ -16625,35 +16653,35 @@ const ue = [
16625
16653
  "REPEAT",
16626
16654
  "RETURN",
16627
16655
  "WHILE"
16628
- ]), _I = r([
16656
+ ]), iI = r([
16629
16657
  "UNION [ALL | DISTINCT]",
16630
16658
  "EXCEPT",
16631
16659
  "INTERSECT",
16632
16660
  "MINUS"
16633
- ]), rI = r([
16661
+ ]), DI = r([
16634
16662
  "JOIN",
16635
16663
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
16636
16664
  "{INNER | CROSS} JOIN",
16637
16665
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
16638
16666
  // non-standard joins
16639
16667
  "STRAIGHT_JOIN"
16640
- ]), nI = r([
16668
+ ]), aI = r([
16641
16669
  "ON DELETE",
16642
16670
  "ON UPDATE",
16643
16671
  "CHARACTER SET",
16644
16672
  "{ROWS | RANGE} BETWEEN",
16645
16673
  "IDENTIFIED BY"
16646
- ]), iI = {
16674
+ ]), oI = {
16647
16675
  name: "singlestoredb",
16648
16676
  tokenizerOptions: {
16649
- reservedSelect: CI,
16650
- reservedClauses: [...LI, ...hT, ...JE],
16651
- reservedSetOperations: _I,
16652
- reservedJoins: rI,
16653
- reservedPhrases: nI,
16654
- reservedKeywords: NI,
16655
- reservedDataTypes: tI,
16656
- reservedFunctionNames: sI,
16677
+ reservedSelect: rI,
16678
+ reservedClauses: [...nI, ...hT, ...JE],
16679
+ reservedSetOperations: iI,
16680
+ reservedJoins: DI,
16681
+ reservedPhrases: aI,
16682
+ reservedKeywords: CI,
16683
+ reservedDataTypes: LI,
16684
+ reservedFunctionNames: _I,
16657
16685
  // TODO: support _binary"some string" prefix
16658
16686
  stringTypes: [
16659
16687
  '""-qq-bs',
@@ -16693,7 +16721,7 @@ const ue = [
16693
16721
  onelineClauses: [...hT, ...JE],
16694
16722
  tabularOnelineClauses: JE
16695
16723
  }
16696
- }, DI = [
16724
+ }, PI = [
16697
16725
  // https://docs.snowflake.com/en/sql-reference-functions.html
16698
16726
  //
16699
16727
  // https://docs.snowflake.com/en/sql-reference/functions-all.html
@@ -17300,7 +17328,7 @@ const ue = [
17300
17328
  "QUARTER",
17301
17329
  "ZEROIFNULL",
17302
17330
  "ZIPF"
17303
- ], aI = [
17331
+ ], MI = [
17304
17332
  // https://docs.snowflake.com/en/sql-reference/reserved-keywords.html
17305
17333
  //
17306
17334
  // run in console on this page: $x('//tbody/tr/*[1]/p/text()').map(x => x.nodeValue)
@@ -17397,7 +17425,7 @@ const ue = [
17397
17425
  "WITH",
17398
17426
  // These are definitely keywords, but haven't found a definite list in the docs
17399
17427
  "COMMENT"
17400
- ], oI = [
17428
+ ], UI = [
17401
17429
  "NUMBER",
17402
17430
  "DECIMAL",
17403
17431
  "NUMERIC",
@@ -17434,7 +17462,7 @@ const ue = [
17434
17462
  "ARRAY",
17435
17463
  "GEOGRAPHY",
17436
17464
  "GEOMETRY"
17437
- ], PI = r(["SELECT [ALL | DISTINCT]"]), MI = r([
17465
+ ], GI = r(["SELECT [ALL | DISTINCT]"]), lI = r([
17438
17466
  // queries
17439
17467
  "WITH [RECURSIVE]",
17440
17468
  "FROM",
@@ -17706,24 +17734,24 @@ const ue = [
17706
17734
  "USE SCHEMA",
17707
17735
  "USE SECONDARY ROLES",
17708
17736
  "USE WAREHOUSE"
17709
- ]), UI = r(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), GI = r([
17737
+ ]), cI = r(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), uI = r([
17710
17738
  "[INNER] JOIN",
17711
17739
  "[NATURAL] {LEFT | RIGHT | FULL} [OUTER] JOIN",
17712
17740
  "{CROSS | NATURAL} JOIN"
17713
- ]), lI = r([
17741
+ ]), HI = r([
17714
17742
  "{ROWS | RANGE} BETWEEN",
17715
17743
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]"
17716
- ]), cI = {
17744
+ ]), BI = {
17717
17745
  name: "snowflake",
17718
17746
  tokenizerOptions: {
17719
- reservedSelect: PI,
17720
- reservedClauses: [...MI, ...VT, ...wE],
17721
- reservedSetOperations: UI,
17722
- reservedJoins: GI,
17723
- reservedPhrases: lI,
17724
- reservedKeywords: aI,
17725
- reservedDataTypes: oI,
17726
- reservedFunctionNames: DI,
17747
+ reservedSelect: GI,
17748
+ reservedClauses: [...lI, ...VT, ...wE],
17749
+ reservedSetOperations: cI,
17750
+ reservedJoins: uI,
17751
+ reservedPhrases: HI,
17752
+ reservedKeywords: MI,
17753
+ reservedDataTypes: UI,
17754
+ reservedFunctionNames: PI,
17727
17755
  stringTypes: ["$$", "''-qq-bs"],
17728
17756
  identTypes: ['""-qq'],
17729
17757
  variableTypes: [
@@ -17756,43 +17784,43 @@ const ue = [
17756
17784
  onelineClauses: [...VT, ...wE],
17757
17785
  tabularOnelineClauses: wE
17758
17786
  }
17759
- }, uI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17787
+ }, mI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17760
17788
  __proto__: null,
17761
- bigquery: oA,
17762
- db2: pA,
17763
- db2i: KA,
17764
- duckdb: qA,
17765
- hive: eS,
17766
- mariadb: rS,
17767
- mysql: GS,
17768
- n1ql: KS,
17769
- plsql: qS,
17770
- postgresql: Ie,
17771
- redshift: ne,
17772
- singlestoredb: iI,
17773
- snowflake: cI,
17774
- spark: le,
17775
- sql: ge,
17776
- sqlite: fe,
17777
- tidb: pS,
17778
- transactsql: OI,
17779
- trino: ke
17780
- }, Symbol.toStringTag, { value: "Module" })), eE = (T) => T[T.length - 1], PR = (T) => T.sort((E, R) => R.length - E.length || E.localeCompare(R)), tE = (T) => T.replace(/\s+/gu, " "), xE = (T) => /\n/.test(T), y = (T) => T.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"), WT = /\s+/uy, q = (T) => new RegExp(`(?:${T})`, "uy"), HI = (T) => T.split("").map((E) => / /gu.test(E) ? "\\s+" : `[${E.toUpperCase()}${E.toLowerCase()}]`).join(""), BI = (T) => T + "(?:-" + T + ")*", mI = ({ prefixes: T, requirePrefix: E }) => `(?:${T.map(HI).join("|")}${E ? "" : "|"})`, FI = (T) => new RegExp(`(?:${T.map(y).join("|")}).*?(?=\r
17789
+ bigquery: UA,
17790
+ db2: hA,
17791
+ db2i: JA,
17792
+ duckdb: zA,
17793
+ hive: Ne,
17794
+ mariadb: De,
17795
+ mysql: ue,
17796
+ n1ql: Je,
17797
+ plsql: ze,
17798
+ postgresql: tS,
17799
+ redshift: aS,
17800
+ singlestoredb: oI,
17801
+ snowflake: BI,
17802
+ spark: HS,
17803
+ sql: xS,
17804
+ sqlite: WS,
17805
+ tidb: he,
17806
+ transactsql: sI,
17807
+ trino: TI
17808
+ }, Symbol.toStringTag, { value: "Module" })), SE = (T) => T[T.length - 1], UR = (T) => T.sort((E, R) => R.length - E.length || E.localeCompare(R)), tE = (T) => T.replace(/\s+/gu, " "), xE = (T) => /\n/.test(T), y = (T) => T.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"), WT = /\s+/uy, q = (T) => new RegExp(`(?:${T})`, "uy"), FI = (T) => T.split("").map((E) => / /gu.test(E) ? "\\s+" : `[${E.toUpperCase()}${E.toLowerCase()}]`).join(""), YI = (T) => T + "(?:-" + T + ")*", pI = ({ prefixes: T, requirePrefix: E }) => `(?:${T.map(FI).join("|")}${E ? "" : "|"})`, dI = (T) => new RegExp(`(?:${T.map(y).join("|")}).*?(?=\r
17781
17809
  |\r|
17782
17810
  |$)`, "uy"), XT = (T, E = []) => {
17783
- const R = T === "open" ? 0 : 1, A = ["()", ...E].map((S) => S[R]);
17811
+ const R = T === "open" ? 0 : 1, A = ["()", ...E].map((e) => e[R]);
17784
17812
  return q(A.map(y).join("|"));
17785
- }, bT = (T) => q(`${PR(T).map(y).join("|")}`), YI = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", J = (T, E = {}) => {
17813
+ }, bT = (T) => q(`${UR(T).map(y).join("|")}`), fI = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", J = (T, E = {}) => {
17786
17814
  if (T.length === 0)
17787
17815
  return /^\b$/u;
17788
- const R = YI(E), A = PR(T).map(y).join("|").replace(/ /gu, "\\s+");
17816
+ const R = fI(E), A = UR(T).map(y).join("|").replace(/ /gu, "\\s+");
17789
17817
  return new RegExp(`(?:${A})${R}\\b`, "iuy");
17790
17818
  }, vE = (T, E) => {
17791
17819
  if (!T.length)
17792
17820
  return;
17793
17821
  const R = T.map(y).join("|");
17794
17822
  return q(`(?:${R})(?:${E})`);
17795
- }, pI = () => {
17823
+ }, hI = () => {
17796
17824
  const T = {
17797
17825
  "<": ">",
17798
17826
  "[": "]",
@@ -17824,16 +17852,16 @@ const ue = [
17824
17852
  // Hive and Spark variables: ${name}
17825
17853
  "{}": String.raw`(?:\{[^\}]*\})`,
17826
17854
  // Oracle q'' strings: q'<text>' q'|text|' ...
17827
- "q''": pI()
17828
- }, MR = (T) => typeof T == "string" ? yT[T] : "regex" in T ? T.regex : mI(T) + yT[T.quote], dI = (T) => q(T.map((E) => "regex" in E ? E.regex : MR(E)).join("|")), UR = (T) => T.map(MR).join("|"), KT = (T) => q(UR(T)), fI = (T = {}) => q(GR(T)), GR = ({ first: T, rest: E, dashes: R, allowFirstCharNumber: A } = {}) => {
17829
- const S = "\\p{Alphabetic}\\p{Mark}_", e = "\\p{Decimal_Number}", N = y(T ?? ""), s = y(E ?? ""), _ = A ? `[${S}${e}${N}][${S}${e}${s}]*` : `[${S}${N}][${S}${e}${s}]*`;
17830
- return R ? BI(_) : _;
17855
+ "q''": hI()
17856
+ }, GR = (T) => typeof T == "string" ? yT[T] : "regex" in T ? T.regex : pI(T) + yT[T.quote], VI = (T) => q(T.map((E) => "regex" in E ? E.regex : GR(E)).join("|")), lR = (T) => T.map(GR).join("|"), KT = (T) => q(lR(T)), WI = (T = {}) => q(cR(T)), cR = ({ first: T, rest: E, dashes: R, allowFirstCharNumber: A } = {}) => {
17857
+ const e = "\\p{Alphabetic}\\p{Mark}_", S = "\\p{Decimal_Number}", N = y(T ?? ""), s = y(E ?? ""), _ = A ? `[${e}${S}${N}][${e}${S}${s}]*` : `[${e}${N}][${e}${S}${s}]*`;
17858
+ return R ? YI(_) : _;
17831
17859
  };
17832
- function lR(T, E) {
17860
+ function uR(T, E) {
17833
17861
  const R = T.slice(0, E).split(/\n/);
17834
17862
  return { line: R.length, col: R[R.length - 1].length + 1 };
17835
17863
  }
17836
- class hI {
17864
+ class XI {
17837
17865
  constructor(E, R) {
17838
17866
  this.rules = E, this.dialectName = R, this.input = "", this.index = 0;
17839
17867
  }
@@ -17849,17 +17877,17 @@ class hI {
17849
17877
  const R = [];
17850
17878
  let A;
17851
17879
  for (; this.index < this.input.length; ) {
17852
- const S = this.getWhitespace();
17880
+ const e = this.getWhitespace();
17853
17881
  if (this.index < this.input.length) {
17854
17882
  if (A = this.getNextToken(), !A)
17855
17883
  throw this.createParseError();
17856
- R.push(Object.assign(Object.assign({}, A), { precedingWhitespace: S }));
17884
+ R.push(Object.assign(Object.assign({}, A), { precedingWhitespace: e }));
17857
17885
  }
17858
17886
  }
17859
17887
  return R;
17860
17888
  }
17861
17889
  createParseError() {
17862
- const E = this.input.slice(this.index, this.index + 10), { line: R, col: A } = lR(this.input, this.index);
17890
+ const E = this.input.slice(this.index, this.index + 10), { line: R, col: A } = uR(this.input, this.index);
17863
17891
  return new Error(`Parse error: Unexpected "${E}" at line ${R} column ${A}.
17864
17892
  ${this.dialectInfo()}`);
17865
17893
  }
@@ -17885,33 +17913,33 @@ If possible, please select a more specific dialect (like sqlite, postgresql, etc
17885
17913
  E.regex.lastIndex = this.index;
17886
17914
  const R = E.regex.exec(this.input);
17887
17915
  if (R) {
17888
- const A = R[0], S = {
17916
+ const A = R[0], e = {
17889
17917
  type: E.type,
17890
17918
  raw: A,
17891
17919
  text: E.text ? E.text(A) : A,
17892
17920
  start: this.index
17893
17921
  };
17894
- return E.key && (S.key = E.key(A)), this.index += A.length, S;
17922
+ return E.key && (e.key = E.key(A)), this.index += A.length, e;
17895
17923
  }
17896
17924
  }
17897
17925
  }
17898
- const $T = /\/\*/uy, VI = /[\s\S]/uy, WI = /\*\//uy;
17899
- class XI {
17926
+ const $T = /\/\*/uy, bI = /[\s\S]/uy, yI = /\*\//uy;
17927
+ class KI {
17900
17928
  constructor() {
17901
17929
  this.lastIndex = 0;
17902
17930
  }
17903
17931
  exec(E) {
17904
- let R = "", A, S = 0;
17932
+ let R = "", A, e = 0;
17905
17933
  if (A = this.matchSection($T, E))
17906
- R += A, S++;
17934
+ R += A, e++;
17907
17935
  else
17908
17936
  return null;
17909
- for (; S > 0; )
17937
+ for (; e > 0; )
17910
17938
  if (A = this.matchSection($T, E))
17911
- R += A, S++;
17912
- else if (A = this.matchSection(WI, E))
17913
- R += A, S--;
17914
- else if (A = this.matchSection(VI, E))
17939
+ R += A, e++;
17940
+ else if (A = this.matchSection(yI, E))
17941
+ R += A, e--;
17942
+ else if (A = this.matchSection(bI, E))
17915
17943
  R += A;
17916
17944
  else
17917
17945
  return null;
@@ -17923,7 +17951,7 @@ class XI {
17923
17951
  return A && (this.lastIndex += A[0].length), A ? A[0] : null;
17924
17952
  }
17925
17953
  }
17926
- class bI {
17954
+ class $I {
17927
17955
  constructor(E, R) {
17928
17956
  this.cfg = E, this.dialectName = R, this.rulesBeforeParams = this.buildRulesBeforeParams(E), this.rulesAfterParams = this.buildRulesAfterParams(E);
17929
17957
  }
@@ -17932,8 +17960,8 @@ class bI {
17932
17960
  ...this.rulesBeforeParams,
17933
17961
  ...this.buildParamRules(this.cfg, R),
17934
17962
  ...this.rulesAfterParams
17935
- ], S = new hI(A, this.dialectName).tokenize(E);
17936
- return this.cfg.postProcess ? this.cfg.postProcess(S) : S;
17963
+ ], e = new XI(A, this.dialectName).tokenize(E);
17964
+ return this.cfg.postProcess ? this.cfg.postProcess(e) : e;
17937
17965
  }
17938
17966
  // These rules can be cached as they only depend on
17939
17967
  // the Tokenizer config options specified for each SQL dialect
@@ -17946,11 +17974,11 @@ class bI {
17946
17974
  },
17947
17975
  {
17948
17976
  type: D.BLOCK_COMMENT,
17949
- regex: E.nestedBlockComments ? new XI() : /(\/\*[^]*?\*\/)/uy
17977
+ regex: E.nestedBlockComments ? new KI() : /(\/\*[^]*?\*\/)/uy
17950
17978
  },
17951
17979
  {
17952
17980
  type: D.LINE_COMMENT,
17953
- regex: FI((R = E.lineCommentTypes) !== null && R !== void 0 ? R : ["--"])
17981
+ regex: dI((R = E.lineCommentTypes) !== null && R !== void 0 ? R : ["--"])
17954
17982
  },
17955
17983
  {
17956
17984
  type: D.QUOTED_IDENTIFIER,
@@ -18067,12 +18095,12 @@ class bI {
18067
18095
  return this.validRules([
18068
18096
  {
18069
18097
  type: D.VARIABLE,
18070
- regex: E.variableTypes ? dI(E.variableTypes) : void 0
18098
+ regex: E.variableTypes ? VI(E.variableTypes) : void 0
18071
18099
  },
18072
18100
  { type: D.STRING, regex: KT(E.stringTypes) },
18073
18101
  {
18074
18102
  type: D.IDENTIFIER,
18075
- regex: fI(E.identChars)
18103
+ regex: WI(E.identChars)
18076
18104
  },
18077
18105
  { type: D.DELIMITER, regex: /[;]/uy },
18078
18106
  { type: D.COMMA, regex: /[,]/y },
@@ -18111,23 +18139,23 @@ class bI {
18111
18139
  // These rules can't be blindly cached as the paramTypesOverrides object
18112
18140
  // can differ on each invocation of the format() function.
18113
18141
  buildParamRules(E, R) {
18114
- var A, S, e, N, s;
18142
+ var A, e, S, N, s;
18115
18143
  const _ = {
18116
18144
  named: (R == null ? void 0 : R.named) || ((A = E.paramTypes) === null || A === void 0 ? void 0 : A.named) || [],
18117
- quoted: (R == null ? void 0 : R.quoted) || ((S = E.paramTypes) === null || S === void 0 ? void 0 : S.quoted) || [],
18118
- numbered: (R == null ? void 0 : R.numbered) || ((e = E.paramTypes) === null || e === void 0 ? void 0 : e.numbered) || [],
18145
+ quoted: (R == null ? void 0 : R.quoted) || ((e = E.paramTypes) === null || e === void 0 ? void 0 : e.quoted) || [],
18146
+ numbered: (R == null ? void 0 : R.numbered) || ((S = E.paramTypes) === null || S === void 0 ? void 0 : S.numbered) || [],
18119
18147
  positional: typeof (R == null ? void 0 : R.positional) == "boolean" ? R.positional : (N = E.paramTypes) === null || N === void 0 ? void 0 : N.positional,
18120
18148
  custom: (R == null ? void 0 : R.custom) || ((s = E.paramTypes) === null || s === void 0 ? void 0 : s.custom) || []
18121
18149
  };
18122
18150
  return this.validRules([
18123
18151
  {
18124
18152
  type: D.NAMED_PARAMETER,
18125
- regex: vE(_.named, GR(E.paramChars || E.identChars)),
18153
+ regex: vE(_.named, cR(E.paramChars || E.identChars)),
18126
18154
  key: (I) => I.slice(1)
18127
18155
  },
18128
18156
  {
18129
18157
  type: D.QUOTED_PARAMETER,
18130
- regex: vE(_.quoted, UR(E.identTypes)),
18158
+ regex: vE(_.quoted, lR(E.identTypes)),
18131
18159
  key: (I) => (({ tokenKey: O, quoteChar: C }) => O.replace(new RegExp(y("\\" + C), "gu"), C))({
18132
18160
  tokenKey: I.slice(2, -1),
18133
18161
  quoteChar: I.slice(-1)
@@ -18157,13 +18185,13 @@ class bI {
18157
18185
  return E.filter((R) => !!R.regex);
18158
18186
  }
18159
18187
  }
18160
- const p = (T) => tE(T.toUpperCase()), gT = /* @__PURE__ */ new Map(), yI = (T) => {
18188
+ const p = (T) => tE(T.toUpperCase()), gT = /* @__PURE__ */ new Map(), gI = (T) => {
18161
18189
  let E = gT.get(T);
18162
- return E || (E = KI(T), gT.set(T, E)), E;
18163
- }, KI = (T) => ({
18164
- tokenizer: new bI(T.tokenizerOptions, T.name),
18165
- formatOptions: $I(T.formatOptions)
18166
- }), $I = (T) => {
18190
+ return E || (E = JI(T), gT.set(T, E)), E;
18191
+ }, JI = (T) => ({
18192
+ tokenizer: new $I(T.tokenizerOptions, T.name),
18193
+ formatOptions: wI(T.formatOptions)
18194
+ }), wI = (T) => {
18167
18195
  var E;
18168
18196
  return {
18169
18197
  alwaysDenseOperators: T.alwaysDenseOperators || [],
@@ -18171,13 +18199,13 @@ const p = (T) => tE(T.toUpperCase()), gT = /* @__PURE__ */ new Map(), yI = (T) =
18171
18199
  tabularOnelineClauses: Object.fromEntries(((E = T.tabularOnelineClauses) !== null && E !== void 0 ? E : T.onelineClauses).map((R) => [R, !0]))
18172
18200
  };
18173
18201
  };
18174
- function gI(T) {
18202
+ function xI(T) {
18175
18203
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight" ? " ".repeat(10) : T.useTabs ? " " : " ".repeat(T.tabWidth);
18176
18204
  }
18177
18205
  function EE(T) {
18178
18206
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight";
18179
18207
  }
18180
- class JI {
18208
+ class vI {
18181
18209
  constructor(E) {
18182
18210
  this.params = E, this.index = 0;
18183
18211
  }
@@ -18200,15 +18228,15 @@ class JI {
18200
18228
  this.index = E;
18201
18229
  }
18202
18230
  }
18203
- var wI = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
18204
- function xI(T) {
18231
+ var QI = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
18232
+ function ZI(T) {
18205
18233
  return T && T.__esModule && Object.prototype.hasOwnProperty.call(T, "default") ? T.default : T;
18206
18234
  }
18207
- var cR = { exports: {} };
18235
+ var HR = { exports: {} };
18208
18236
  (function(T) {
18209
18237
  (function(E, R) {
18210
18238
  T.exports ? T.exports = R() : E.nearley = R();
18211
- })(wI, function() {
18239
+ })(QI, function() {
18212
18240
  function E(I, O, C) {
18213
18241
  return this.id = ++E.highestId, this.name = I, this.symbols = O, this.postprocess = C, this;
18214
18242
  }
@@ -18275,38 +18303,38 @@ var cR = { exports: {} };
18275
18303
  var C = I.nextState(O);
18276
18304
  this.states.push(C);
18277
18305
  };
18278
- function S(I, O) {
18306
+ function e(I, O) {
18279
18307
  this.rules = I, this.start = O || this.rules[0].name;
18280
18308
  var C = this.byName = {};
18281
18309
  this.rules.forEach(function(t) {
18282
18310
  C.hasOwnProperty(t.name) || (C[t.name] = []), C[t.name].push(t);
18283
18311
  });
18284
18312
  }
18285
- S.fromCompiled = function(t, O) {
18313
+ e.fromCompiled = function(t, O) {
18286
18314
  var C = t.Lexer;
18287
18315
  t.ParserStart && (O = t.ParserStart, t = t.ParserRules);
18288
18316
  var t = t.map(function(P) {
18289
18317
  return new E(P.name, P.symbols, P.postprocess);
18290
- }), i = new S(t, O);
18318
+ }), i = new e(t, O);
18291
18319
  return i.lexer = C, i;
18292
18320
  };
18293
- function e() {
18321
+ function S() {
18294
18322
  this.reset("");
18295
18323
  }
18296
- e.prototype.reset = function(I, O) {
18324
+ S.prototype.reset = function(I, O) {
18297
18325
  this.buffer = I, this.index = 0, this.line = O ? O.line : 1, this.lastLineBreak = O ? -O.col : 0;
18298
- }, e.prototype.next = function() {
18326
+ }, S.prototype.next = function() {
18299
18327
  if (this.index < this.buffer.length) {
18300
18328
  var I = this.buffer[this.index++];
18301
18329
  return I === `
18302
18330
  ` && (this.line += 1, this.lastLineBreak = this.index), { value: I };
18303
18331
  }
18304
- }, e.prototype.save = function() {
18332
+ }, S.prototype.save = function() {
18305
18333
  return {
18306
18334
  line: this.line,
18307
18335
  col: this.index - this.lastLineBreak
18308
18336
  };
18309
- }, e.prototype.formatError = function(I, O) {
18337
+ }, S.prototype.formatError = function(I, O) {
18310
18338
  var C = this.buffer;
18311
18339
  if (typeof C == "string") {
18312
18340
  var t = C.split(`
@@ -18333,13 +18361,13 @@ var cR = { exports: {} };
18333
18361
  }
18334
18362
  };
18335
18363
  function N(I, O, C) {
18336
- if (I instanceof S)
18364
+ if (I instanceof e)
18337
18365
  var t = I, C = O;
18338
18366
  else
18339
- var t = S.fromCompiled(I, O);
18367
+ var t = e.fromCompiled(I, O);
18340
18368
  this.grammar = t, this.options = {
18341
18369
  keepHistory: !1,
18342
- lexer: t.lexer || new e()
18370
+ lexer: t.lexer || new S()
18343
18371
  };
18344
18372
  for (var i in C || {})
18345
18373
  this.options[i] = C[i];
@@ -18364,7 +18392,7 @@ var cR = { exports: {} };
18364
18392
  this.options.keepHistory || delete this.table[this.current - 1];
18365
18393
  var P = this.current + 1, M = new A(this.grammar, P);
18366
18394
  this.table.push(M);
18367
- for (var o = C.text !== void 0 ? C.text : C.value, G = O.constructor === e ? C.value : C, a = i.scannable, H = a.length; H--; ) {
18395
+ for (var o = C.text !== void 0 ? C.text : C.value, G = O.constructor === S ? C.value : C, a = i.scannable, H = a.length; H--; ) {
18368
18396
  var u = a[H], B = u.rule.symbols[u.dot];
18369
18397
  if (B.test ? B.test(G) : B.type ? B.type === C.type : B.literal === o) {
18370
18398
  var Y = u.nextState({ data: G, token: C, isToken: !0, reference: P - 1 });
@@ -18473,61 +18501,61 @@ var cR = { exports: {} };
18473
18501
  }
18474
18502
  return {
18475
18503
  Parser: N,
18476
- Grammar: S,
18504
+ Grammar: e,
18477
18505
  Rule: E
18478
18506
  };
18479
18507
  });
18480
- })(cR);
18481
- var vI = cR.exports;
18482
- const QI = /* @__PURE__ */ xI(vI);
18483
- function ZI(T) {
18484
- return T.map(qI).map(jI).map(kI).map(zI).map(EO);
18508
+ })(HR);
18509
+ var qI = HR.exports;
18510
+ const jI = /* @__PURE__ */ ZI(qI);
18511
+ function kI(T) {
18512
+ return T.map(zI).map(EO).map(TO).map(RO).map(AO);
18485
18513
  }
18486
- const qI = (T, E, R) => {
18487
- if (oR(T.type)) {
18488
- const A = TO(R, E);
18514
+ const zI = (T, E, R) => {
18515
+ if (MR(T.type)) {
18516
+ const A = eO(R, E);
18489
18517
  if (A && A.type === D.PROPERTY_ACCESS_OPERATOR)
18490
18518
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18491
- const S = AE(R, E);
18492
- if (S && S.type === D.PROPERTY_ACCESS_OPERATOR)
18519
+ const e = AE(R, E);
18520
+ if (e && e.type === D.PROPERTY_ACCESS_OPERATOR)
18493
18521
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18494
18522
  }
18495
18523
  return T;
18496
- }, jI = (T, E, R) => {
18524
+ }, EO = (T, E, R) => {
18497
18525
  if (T.type === D.RESERVED_FUNCTION_NAME) {
18498
18526
  const A = AE(R, E);
18499
- if (!A || !uR(A))
18527
+ if (!A || !BR(A))
18500
18528
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18501
18529
  }
18502
18530
  return T;
18503
- }, kI = (T, E, R) => {
18531
+ }, TO = (T, E, R) => {
18504
18532
  if (T.type === D.RESERVED_DATA_TYPE) {
18505
18533
  const A = AE(R, E);
18506
- if (A && uR(A))
18534
+ if (A && BR(A))
18507
18535
  return Object.assign(Object.assign({}, T), { type: D.RESERVED_PARAMETERIZED_DATA_TYPE });
18508
18536
  }
18509
18537
  return T;
18510
- }, zI = (T, E, R) => {
18538
+ }, RO = (T, E, R) => {
18511
18539
  if (T.type === D.IDENTIFIER) {
18512
18540
  const A = AE(R, E);
18513
- if (A && HR(A))
18541
+ if (A && mR(A))
18514
18542
  return Object.assign(Object.assign({}, T), { type: D.ARRAY_IDENTIFIER });
18515
18543
  }
18516
18544
  return T;
18517
- }, EO = (T, E, R) => {
18545
+ }, AO = (T, E, R) => {
18518
18546
  if (T.type === D.RESERVED_DATA_TYPE) {
18519
18547
  const A = AE(R, E);
18520
- if (A && HR(A))
18548
+ if (A && mR(A))
18521
18549
  return Object.assign(Object.assign({}, T), { type: D.ARRAY_KEYWORD });
18522
18550
  }
18523
18551
  return T;
18524
- }, TO = (T, E) => AE(T, E, -1), AE = (T, E, R = 1) => {
18552
+ }, eO = (T, E) => AE(T, E, -1), AE = (T, E, R = 1) => {
18525
18553
  let A = 1;
18526
- for (; T[E + A * R] && RO(T[E + A * R]); )
18554
+ for (; T[E + A * R] && SO(T[E + A * R]); )
18527
18555
  A++;
18528
18556
  return T[E + A * R];
18529
- }, uR = (T) => T.type === D.OPEN_PAREN && T.text === "(", HR = (T) => T.type === D.OPEN_PAREN && T.text === "[", RO = (T) => T.type === D.BLOCK_COMMENT || T.type === D.LINE_COMMENT;
18530
- class BR {
18557
+ }, BR = (T) => T.type === D.OPEN_PAREN && T.text === "(", mR = (T) => T.type === D.OPEN_PAREN && T.text === "[", SO = (T) => T.type === D.BLOCK_COMMENT || T.type === D.LINE_COMMENT;
18558
+ class FR {
18531
18559
  constructor(E) {
18532
18560
  this.tokenize = E, this.index = 0, this.tokens = [], this.input = "";
18533
18561
  }
@@ -18540,7 +18568,7 @@ class BR {
18540
18568
  save() {
18541
18569
  }
18542
18570
  formatError(E) {
18543
- const { line: R, col: A } = lR(this.input, E.start);
18571
+ const { line: R, col: A } = uR(this.input, E.start);
18544
18572
  return `Parse error at token: ${E.text} at line ${R} column ${A}`;
18545
18573
  }
18546
18574
  has(E) {
@@ -18554,7 +18582,7 @@ var U;
18554
18582
  function QE(T) {
18555
18583
  return T[0];
18556
18584
  }
18557
- const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18585
+ const c = new FR((T) => []), w = ([[T]]) => T, d = (T) => ({
18558
18586
  type: U.keyword,
18559
18587
  tokenType: T.type,
18560
18588
  text: T.text,
@@ -18563,17 +18591,17 @@ const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18563
18591
  type: U.data_type,
18564
18592
  text: T.text,
18565
18593
  raw: T.raw
18566
- }), f = (T, { leading: E, trailing: R }) => (E != null && E.length && (T = Object.assign(Object.assign({}, T), { leadingComments: E })), R != null && R.length && (T = Object.assign(Object.assign({}, T), { trailingComments: R })), T), AO = (T, { leading: E, trailing: R }) => {
18594
+ }), f = (T, { leading: E, trailing: R }) => (E != null && E.length && (T = Object.assign(Object.assign({}, T), { leadingComments: E })), R != null && R.length && (T = Object.assign(Object.assign({}, T), { trailingComments: R })), T), IO = (T, { leading: E, trailing: R }) => {
18567
18595
  if (E != null && E.length) {
18568
- const [A, ...S] = T;
18569
- T = [f(A, { leading: E }), ...S];
18596
+ const [A, ...e] = T;
18597
+ T = [f(A, { leading: E }), ...e];
18570
18598
  }
18571
18599
  if (R != null && R.length) {
18572
- const A = T.slice(0, -1), S = T[T.length - 1];
18573
- T = [...A, f(S, { trailing: R })];
18600
+ const A = T.slice(0, -1), e = T[T.length - 1];
18601
+ T = [...A, f(e, { trailing: R })];
18574
18602
  }
18575
18603
  return T;
18576
- }, SO = {
18604
+ }, OO = {
18577
18605
  Lexer: c,
18578
18606
  ParserRules: [
18579
18607
  { name: "main$ebnf$1", symbols: [] },
@@ -18621,12 +18649,12 @@ const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18621
18649
  symbols: [c.has("LIMIT") ? { type: "LIMIT" } : LIMIT, "_", "expression_chain_", "limit_clause$ebnf$1"],
18622
18650
  postprocess: ([T, E, R, A]) => {
18623
18651
  if (A) {
18624
- const [S, e] = A;
18652
+ const [e, S] = A;
18625
18653
  return {
18626
18654
  type: U.limit_clause,
18627
18655
  limitKw: f(d(T), { trailing: E }),
18628
18656
  offset: R,
18629
- count: e
18657
+ count: S
18630
18658
  };
18631
18659
  } else
18632
18660
  return {
@@ -18824,23 +18852,23 @@ const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18824
18852
  // A better way would be to allow <property_access> on the left side of array_subscript,
18825
18853
  // but we currently can't do that because of another hack that requires
18826
18854
  // %ARRAY_IDENTIFIER on the left side of <array_subscript>.
18827
- ([T, E, R, A, [S]]) => ({
18855
+ ([T, E, R, A, [e]]) => ({
18828
18856
  type: U.property_access,
18829
18857
  object: f(T, { trailing: E }),
18830
18858
  operator: R.text,
18831
- property: f(S, { leading: A })
18859
+ property: f(e, { leading: A })
18832
18860
  })
18833
18861
  )
18834
18862
  },
18835
18863
  {
18836
18864
  name: "between_predicate",
18837
18865
  symbols: [c.has("BETWEEN") ? { type: "BETWEEN" } : BETWEEN, "_", "andless_expression_chain", "_", c.has("AND") ? { type: "AND" } : AND, "_", "andless_expression"],
18838
- postprocess: ([T, E, R, A, S, e, N]) => ({
18866
+ postprocess: ([T, E, R, A, e, S, N]) => ({
18839
18867
  type: U.between_predicate,
18840
18868
  betweenKw: d(T),
18841
- expr1: AO(R, { leading: E, trailing: A }),
18842
- andKw: d(S),
18843
- expr2: [f(N, { leading: e })]
18869
+ expr1: IO(R, { leading: E, trailing: A }),
18870
+ andKw: d(e),
18871
+ expr2: [f(N, { leading: S })]
18844
18872
  })
18845
18873
  },
18846
18874
  { name: "case_expression$ebnf$1", symbols: ["expression_chain_"], postprocess: QE },
@@ -18850,10 +18878,10 @@ const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18850
18878
  {
18851
18879
  name: "case_expression",
18852
18880
  symbols: [c.has("CASE") ? { type: "CASE" } : CASE, "_", "case_expression$ebnf$1", "case_expression$ebnf$2", c.has("END") ? { type: "END" } : END],
18853
- postprocess: ([T, E, R, A, S]) => ({
18881
+ postprocess: ([T, E, R, A, e]) => ({
18854
18882
  type: U.case_expression,
18855
18883
  caseKw: f(d(T), { trailing: E }),
18856
- endKw: d(S),
18884
+ endKw: d(e),
18857
18885
  expr: R || [],
18858
18886
  clauses: A
18859
18887
  })
@@ -18861,12 +18889,12 @@ const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18861
18889
  {
18862
18890
  name: "case_clause",
18863
18891
  symbols: [c.has("WHEN") ? { type: "WHEN" } : WHEN, "_", "expression_chain_", c.has("THEN") ? { type: "THEN" } : THEN, "_", "expression_chain_"],
18864
- postprocess: ([T, E, R, A, S, e]) => ({
18892
+ postprocess: ([T, E, R, A, e, S]) => ({
18865
18893
  type: U.case_when,
18866
18894
  whenKw: f(d(T), { trailing: E }),
18867
- thenKw: f(d(A), { trailing: S }),
18895
+ thenKw: f(d(A), { trailing: e }),
18868
18896
  condition: R,
18869
- result: e
18897
+ result: S
18870
18898
  })
18871
18899
  },
18872
18900
  {
@@ -18969,17 +18997,17 @@ const c = new BR((T) => []), w = ([[T]]) => T, d = (T) => ({
18969
18997
  }
18970
18998
  ],
18971
18999
  ParserStart: "main"
18972
- }, { Parser: eO, Grammar: IO } = QI;
18973
- function OO(T) {
19000
+ }, { Parser: NO, Grammar: tO } = jI;
19001
+ function sO(T) {
18974
19002
  let E = {};
18975
- const R = new BR((S) => [
18976
- ...ZI(T.tokenize(S, E)),
18977
- aR(S.length)
18978
- ]), A = new eO(IO.fromCompiled(SO), { lexer: R });
19003
+ const R = new FR((e) => [
19004
+ ...kI(T.tokenize(e, E)),
19005
+ PR(e.length)
19006
+ ]), A = new NO(tO.fromCompiled(OO), { lexer: R });
18979
19007
  return {
18980
- parse: (S, e) => {
18981
- E = e;
18982
- const { results: N } = A.feed(S);
19008
+ parse: (e, S) => {
19009
+ E = S;
19010
+ const { results: N } = A.feed(e);
18983
19011
  if (N.length === 1)
18984
19012
  return N[0];
18985
19013
  throw N.length === 0 ? new Error("Parse error: Invalid SQL") : new Error(`Parse error: Ambiguous grammar
@@ -18991,7 +19019,7 @@ var n;
18991
19019
  (function(T) {
18992
19020
  T[T.SPACE = 0] = "SPACE", T[T.NO_SPACE = 1] = "NO_SPACE", T[T.NO_NEWLINE = 2] = "NO_NEWLINE", T[T.NEWLINE = 3] = "NEWLINE", T[T.MANDATORY_NEWLINE = 4] = "MANDATORY_NEWLINE", T[T.INDENT = 5] = "INDENT", T[T.SINGLE_INDENT = 6] = "SINGLE_INDENT";
18993
19021
  })(n = n || (n = {}));
18994
- class mR {
19022
+ class YR {
18995
19023
  constructor(E) {
18996
19024
  this.indentation = E, this.items = [];
18997
19025
  }
@@ -19027,16 +19055,16 @@ class mR {
19027
19055
  }
19028
19056
  }
19029
19057
  trimHorizontalWhitespace() {
19030
- for (; NO(eE(this.items)); )
19058
+ for (; CO(SE(this.items)); )
19031
19059
  this.items.pop();
19032
19060
  }
19033
19061
  trimWhitespace() {
19034
- for (; tO(eE(this.items)); )
19062
+ for (; LO(SE(this.items)); )
19035
19063
  this.items.pop();
19036
19064
  }
19037
19065
  addNewline(E) {
19038
19066
  if (this.items.length > 0)
19039
- switch (eE(this.items)) {
19067
+ switch (SE(this.items)) {
19040
19068
  case n.NEWLINE:
19041
19069
  this.items.pop(), this.items.push(E);
19042
19070
  break;
@@ -19078,7 +19106,7 @@ class mR {
19078
19106
  }
19079
19107
  }
19080
19108
  }
19081
- const NO = (T) => T === n.SPACE || T === n.SINGLE_INDENT, tO = (T) => T === n.SPACE || T === n.SINGLE_INDENT || T === n.NEWLINE;
19109
+ const CO = (T) => T === n.SPACE || T === n.SINGLE_INDENT, LO = (T) => T === n.SPACE || T === n.SINGLE_INDENT || T === n.NEWLINE;
19082
19110
  function wT(T, E) {
19083
19111
  if (E === "standard")
19084
19112
  return T;
@@ -19086,10 +19114,10 @@ function wT(T, E) {
19086
19114
  return T.length >= 10 && T.includes(" ") && ([T, ...R] = T.split(" ")), E === "tabularLeft" ? T = T.padEnd(9, " ") : T = T.padStart(9, " "), T + ["", ...R].join(" ");
19087
19115
  }
19088
19116
  function xT(T) {
19089
- return sA(T) || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.LIMIT;
19117
+ return _A(T) || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.LIMIT;
19090
19118
  }
19091
- const ZE = "top-level", sO = "block-level";
19092
- class FR {
19119
+ const ZE = "top-level", _O = "block-level";
19120
+ class pR {
19093
19121
  /**
19094
19122
  * @param {string} indent A string to indent with
19095
19123
  */
@@ -19118,14 +19146,14 @@ class FR {
19118
19146
  * Increases indentation by one block-level indent.
19119
19147
  */
19120
19148
  increaseBlockLevel() {
19121
- this.indentTypes.push(sO);
19149
+ this.indentTypes.push(_O);
19122
19150
  }
19123
19151
  /**
19124
19152
  * Decreases indentation by one top-level indent.
19125
19153
  * Does nothing when the previous indent is not top-level.
19126
19154
  */
19127
19155
  decreaseTopLevel() {
19128
- this.indentTypes.length > 0 && eE(this.indentTypes) === ZE && this.indentTypes.pop();
19156
+ this.indentTypes.length > 0 && SE(this.indentTypes) === ZE && this.indentTypes.pop();
19129
19157
  }
19130
19158
  /**
19131
19159
  * Decreases indentation by one block-level indent.
@@ -19137,9 +19165,9 @@ class FR {
19137
19165
  ;
19138
19166
  }
19139
19167
  }
19140
- class CO extends mR {
19168
+ class rO extends YR {
19141
19169
  constructor(E) {
19142
- super(new FR("")), this.expressionWidth = E, this.length = 0, this.trailingSpace = !1;
19170
+ super(new pR("")), this.expressionWidth = E, this.length = 0, this.trailingSpace = !1;
19143
19171
  }
19144
19172
  add(...E) {
19145
19173
  if (E.forEach((R) => this.addToLength(R)), this.length > this.expressionWidth)
@@ -19159,8 +19187,8 @@ class CO extends mR {
19159
19187
  class kE extends Error {
19160
19188
  }
19161
19189
  class rE {
19162
- constructor({ cfg: E, dialectCfg: R, params: A, layout: S, inline: e = !1 }) {
19163
- this.inline = !1, this.nodes = [], this.index = -1, this.cfg = E, this.dialectCfg = R, this.inline = e, this.params = A, this.layout = S;
19190
+ constructor({ cfg: E, dialectCfg: R, params: A, layout: e, inline: S = !1 }) {
19191
+ this.inline = !1, this.nodes = [], this.index = -1, this.cfg = E, this.dialectCfg = R, this.inline = S, this.params = A, this.layout = e;
19164
19192
  }
19165
19193
  format(E) {
19166
19194
  for (this.nodes = E, this.index = 0; this.index < this.nodes.length; this.index++)
@@ -19332,7 +19360,7 @@ class rE {
19332
19360
  // first line starts with /* or /**
19333
19361
  /^\/\*\*?$/.test(R[0]) && // intermediate lines start with *
19334
19362
  R.slice(1, R.length - 1).every((A) => /^\s*\*/.test(A)) && // last line ends with */
19335
- /^\s*\*\/$/.test(eE(R))
19363
+ /^\s*\*\/$/.test(SE(R))
19336
19364
  );
19337
19365
  }
19338
19366
  // Breaks up block comment to multiple lines.
@@ -19381,7 +19409,7 @@ class rE {
19381
19409
  cfg: this.cfg,
19382
19410
  dialectCfg: this.dialectCfg,
19383
19411
  params: this.params,
19384
- layout: new CO(this.cfg.expressionWidth),
19412
+ layout: new rO(this.cfg.expressionWidth),
19385
19413
  inline: !0
19386
19414
  }).format(E);
19387
19415
  } catch (A) {
@@ -19467,9 +19495,9 @@ class rE {
19467
19495
  }
19468
19496
  }
19469
19497
  }
19470
- class LO {
19498
+ class nO {
19471
19499
  constructor(E, R) {
19472
- this.dialect = E, this.cfg = R, this.params = new JI(this.cfg.params);
19500
+ this.dialect = E, this.cfg = R, this.params = new vI(this.cfg.params);
19473
19501
  }
19474
19502
  /**
19475
19503
  * Formats an SQL query.
@@ -19481,7 +19509,7 @@ class LO {
19481
19509
  return this.formatAst(R).trimEnd();
19482
19510
  }
19483
19511
  parse(E) {
19484
- return OO(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19512
+ return sO(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19485
19513
  }
19486
19514
  formatAst(E) {
19487
19515
  return E.map((R) => this.formatStatement(R)).join(`
@@ -19492,14 +19520,14 @@ class LO {
19492
19520
  cfg: this.cfg,
19493
19521
  dialectCfg: this.dialect.formatOptions,
19494
19522
  params: this.params,
19495
- layout: new mR(new FR(gI(this.cfg)))
19523
+ layout: new YR(new pR(xI(this.cfg)))
19496
19524
  }).format(E.children);
19497
19525
  return E.hasSemicolon && (this.cfg.newlineBeforeSemicolon ? R.add(n.NEWLINE, ";") : R.add(n.NO_NEWLINE, ";")), R.toString();
19498
19526
  }
19499
19527
  }
19500
19528
  class sE extends Error {
19501
19529
  }
19502
- function _O(T) {
19530
+ function iO(T) {
19503
19531
  const E = [
19504
19532
  "multilineLists",
19505
19533
  "newlineBeforeOpenParen",
@@ -19513,25 +19541,25 @@ function _O(T) {
19513
19541
  throw new sE(`${R} config is no more supported.`);
19514
19542
  if (T.expressionWidth <= 0)
19515
19543
  throw new sE(`expressionWidth config must be positive number. Received ${T.expressionWidth} instead.`);
19516
- if (T.params && !rO(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !nO(T.paramTypes))
19544
+ if (T.params && !DO(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !aO(T.paramTypes))
19517
19545
  throw new sE("Empty regex given in custom paramTypes. That would result in matching infinite amount of parameters.");
19518
19546
  return T;
19519
19547
  }
19520
- function rO(T) {
19548
+ function DO(T) {
19521
19549
  return (T instanceof Array ? T : Object.values(T)).every((R) => typeof R == "string");
19522
19550
  }
19523
- function nO(T) {
19551
+ function aO(T) {
19524
19552
  return T.custom && Array.isArray(T.custom) ? T.custom.every((E) => E.regex !== "") : !0;
19525
19553
  }
19526
- var iO = function(T, E) {
19554
+ var oO = function(T, E) {
19527
19555
  var R = {};
19528
19556
  for (var A in T) Object.prototype.hasOwnProperty.call(T, A) && E.indexOf(A) < 0 && (R[A] = T[A]);
19529
19557
  if (T != null && typeof Object.getOwnPropertySymbols == "function")
19530
- for (var S = 0, A = Object.getOwnPropertySymbols(T); S < A.length; S++)
19531
- E.indexOf(A[S]) < 0 && Object.prototype.propertyIsEnumerable.call(T, A[S]) && (R[A[S]] = T[A[S]]);
19558
+ for (var e = 0, A = Object.getOwnPropertySymbols(T); e < A.length; e++)
19559
+ E.indexOf(A[e]) < 0 && Object.prototype.propertyIsEnumerable.call(T, A[e]) && (R[A[e]] = T[A[e]]);
19532
19560
  return R;
19533
19561
  };
19534
- const YR = {
19562
+ const dR = {
19535
19563
  bigquery: "bigquery",
19536
19564
  db2: "db2",
19537
19565
  db2i: "db2i",
@@ -19552,7 +19580,7 @@ const YR = {
19552
19580
  tsql: "transactsql",
19553
19581
  singlestoredb: "singlestoredb",
19554
19582
  snowflake: "snowflake"
19555
- }, DO = Object.keys(YR), aO = {
19583
+ }, PO = Object.keys(dR), MO = {
19556
19584
  tabWidth: 2,
19557
19585
  useTabs: !1,
19558
19586
  keywordCase: "preserve",
@@ -19565,28 +19593,28 @@ const YR = {
19565
19593
  linesBetweenQueries: 1,
19566
19594
  denseOperators: !1,
19567
19595
  newlineBeforeSemicolon: !1
19568
- }, oO = (T, E = {}) => {
19569
- if (typeof E.language == "string" && !DO.includes(E.language))
19596
+ }, UO = (T, E = {}) => {
19597
+ if (typeof E.language == "string" && !PO.includes(E.language))
19570
19598
  throw new sE(`Unsupported SQL dialect: ${E.language}`);
19571
- const R = YR[E.language || "sql"];
19572
- return PO(T, Object.assign(Object.assign({}, E), { dialect: uI[R] }));
19573
- }, PO = (T, E) => {
19574
- var { dialect: R } = E, A = iO(E, ["dialect"]);
19599
+ const R = dR[E.language || "sql"];
19600
+ return GO(T, Object.assign(Object.assign({}, E), { dialect: mI[R] }));
19601
+ }, GO = (T, E) => {
19602
+ var { dialect: R } = E, A = oO(E, ["dialect"]);
19575
19603
  if (typeof T != "string")
19576
19604
  throw new Error("Invalid query argument. Expected string, instead got " + typeof T);
19577
- const S = _O(Object.assign(Object.assign({}, aO), A));
19578
- return new LO(yI(R), S).format(T);
19605
+ const e = iO(Object.assign(Object.assign({}, MO), A));
19606
+ return new nO(gI(R), e).format(T);
19579
19607
  };
19580
- function MO(T) {
19581
- var R, A, S, e;
19608
+ function lO(T) {
19609
+ var R, A, e, S;
19582
19610
  let E = 0;
19583
- return E += (((R = T.measures) == null ? void 0 : R.length) || 0) * 1, E += (((A = T.dimensions) == null ? void 0 : A.length) || 0) * 1, E += (((S = T.filters) == null ? void 0 : S.length) || 0) * 2, E += (((e = T.timeDimensions) == null ? void 0 : e.length) || 0) * 3, E <= 5 ? "low" : E <= 15 ? "medium" : "high";
19611
+ return E += (((R = T.measures) == null ? void 0 : R.length) || 0) * 1, E += (((A = T.dimensions) == null ? void 0 : A.length) || 0) * 1, E += (((e = T.filters) == null ? void 0 : e.length) || 0) * 2, E += (((S = T.timeDimensions) == null ? void 0 : S.length) || 0) * 3, E <= 5 ? "low" : E <= 15 ? "medium" : "high";
19584
19612
  }
19585
- function UO() {
19613
+ function cO() {
19586
19614
  const T = Date.now(), E = Math.random().toString(36).substring(2, 9);
19587
19615
  return `${T}-${E}`;
19588
19616
  }
19589
- function GO(T) {
19617
+ function uO(T) {
19590
19618
  const E = T.dimensions || [], R = T.timeDimensions || [], A = T.measures || [];
19591
19619
  return {
19592
19620
  sortedDimensions: E,
@@ -19611,7 +19639,7 @@ function GO(T) {
19611
19639
  hasMultiStage: !1
19612
19640
  };
19613
19641
  }
19614
- function lO(T) {
19642
+ function HO(T) {
19615
19643
  if (T.hasExecutor()) {
19616
19644
  const E = T.databaseExecutor;
19617
19645
  if (E != null && E.engineType)
@@ -19619,36 +19647,36 @@ function lO(T) {
19619
19647
  }
19620
19648
  return "postgres";
19621
19649
  }
19622
- async function HO(T, E, R) {
19650
+ async function FO(T, E, R) {
19623
19651
  var _, I, O, C;
19624
19652
  const A = R.validateQuery(T);
19625
19653
  if (!A.isValid)
19626
19654
  throw new Error(`Query validation failed: ${A.errors.join(", ")}`);
19627
- const S = /* @__PURE__ */ new Set();
19655
+ const e = /* @__PURE__ */ new Set();
19628
19656
  (_ = T.measures) == null || _.forEach((t) => {
19629
19657
  const i = t.split(".")[0];
19630
- S.add(i);
19658
+ e.add(i);
19631
19659
  }), (I = T.dimensions) == null || I.forEach((t) => {
19632
19660
  const i = t.split(".")[0];
19633
- S.add(i);
19661
+ e.add(i);
19634
19662
  }), (O = T.timeDimensions) == null || O.forEach((t) => {
19635
19663
  const i = t.dimension.split(".")[0];
19636
- S.add(i);
19664
+ e.add(i);
19637
19665
  }), (C = T.filters) == null || C.forEach((t) => {
19638
19666
  if ("member" in t) {
19639
19667
  const i = t.member.split(".")[0];
19640
- S.add(i);
19668
+ e.add(i);
19641
19669
  }
19642
19670
  });
19643
- const e = S.size > 1;
19671
+ const S = e.size > 1;
19644
19672
  let N;
19645
- if (e)
19673
+ if (S)
19646
19674
  N = await R.generateMultiCubeSQL(T, E);
19647
19675
  else {
19648
- const t = Array.from(S)[0];
19676
+ const t = Array.from(e)[0];
19649
19677
  N = await R.generateSQL(t, T, E);
19650
19678
  }
19651
- const s = Array.from(S).map((t) => {
19679
+ const s = Array.from(e).map((t) => {
19652
19680
  var i, P;
19653
19681
  return {
19654
19682
  cube: t,
@@ -19666,33 +19694,33 @@ async function HO(T, E, R) {
19666
19694
  return {
19667
19695
  queryType: "regularQuery",
19668
19696
  normalizedQueries: s,
19669
- queryOrder: Array.from(S),
19697
+ queryOrder: Array.from(e),
19670
19698
  transformedQueries: s,
19671
19699
  pivotQuery: {
19672
19700
  query: T,
19673
- cubes: Array.from(S)
19701
+ cubes: Array.from(e)
19674
19702
  },
19675
19703
  sql: {
19676
19704
  sql: [N.sql],
19677
19705
  params: N.params || []
19678
19706
  },
19679
- complexity: MO(T),
19707
+ complexity: lO(T),
19680
19708
  valid: !0,
19681
- cubesUsed: Array.from(S),
19682
- joinType: e ? "multi_cube_join" : "single_cube",
19709
+ cubesUsed: Array.from(e),
19710
+ joinType: S ? "multi_cube_join" : "single_cube",
19683
19711
  query: T
19684
19712
  };
19685
19713
  }
19686
- function BO(T, E, R) {
19687
- const A = lO(R), S = UO(), e = (/* @__PURE__ */ new Date()).toISOString(), N = GO(T);
19714
+ function YO(T, E, R) {
19715
+ const A = HO(R), e = cO(), S = (/* @__PURE__ */ new Date()).toISOString(), N = uO(T);
19688
19716
  return {
19689
19717
  queryType: "regularQuery",
19690
19718
  results: [{
19691
19719
  query: T,
19692
- lastRefreshTime: e,
19720
+ lastRefreshTime: S,
19693
19721
  usedPreAggregations: {},
19694
19722
  transformedQuery: N,
19695
- requestId: S,
19723
+ requestId: e,
19696
19724
  annotation: E.annotation,
19697
19725
  dataSource: "default",
19698
19726
  dbType: A,
@@ -19710,11 +19738,13 @@ function BO(T, E, R) {
19710
19738
  }
19711
19739
  function vT(T, E) {
19712
19740
  try {
19713
- return oO(T, {
19741
+ return UO(T, {
19714
19742
  language: {
19715
19743
  postgres: "postgresql",
19716
19744
  mysql: "mysql",
19717
- sqlite: "sqlite"
19745
+ sqlite: "sqlite",
19746
+ singlestore: "mysql"
19747
+ // SingleStore uses MySQL dialect for formatting
19718
19748
  }[E],
19719
19749
  tabWidth: 2,
19720
19750
  keywordCase: "upper",
@@ -19724,25 +19754,25 @@ function vT(T, E) {
19724
19754
  return console.warn("SQL formatting failed:", R), T;
19725
19755
  }
19726
19756
  }
19727
- function mO(T, E) {
19757
+ function pO(T, E) {
19728
19758
  return {
19729
19759
  sql: E.sql,
19730
19760
  params: E.params || [],
19731
19761
  query: T
19732
19762
  };
19733
19763
  }
19734
- function FO(T) {
19764
+ function dO(T) {
19735
19765
  return {
19736
19766
  cubes: T
19737
19767
  };
19738
19768
  }
19739
- function YO(T, E = 500) {
19769
+ function fO(T, E = 500) {
19740
19770
  return {
19741
19771
  error: T instanceof Error ? T.message : T,
19742
19772
  status: E
19743
19773
  };
19744
19774
  }
19745
- class cO {
19775
+ class BO {
19746
19776
  // 5 minutes in milliseconds
19747
19777
  constructor(E) {
19748
19778
  l(this, "cubes", /* @__PURE__ */ new Map());
@@ -19838,56 +19868,86 @@ class cO {
19838
19868
  const R = Array.from(this.cubes.values()).map((A) => this.generateCubeMetadata(A));
19839
19869
  return this.metadataCache = R, this.metadataCacheTimestamp = E, R;
19840
19870
  }
19871
+ /**
19872
+ * Extract column name from Drizzle column reference
19873
+ * Handles different column types and extracts the actual column name
19874
+ */
19875
+ getColumnName(E) {
19876
+ if (E && E.name || E && E.columnType && E.name)
19877
+ return E.name;
19878
+ if (typeof E == "string")
19879
+ return E;
19880
+ if (E && typeof E == "object") {
19881
+ if (E._.name) return E._.name;
19882
+ if (E.name) return E.name;
19883
+ if (E.columnName) return E.columnName;
19884
+ }
19885
+ return "unknown_column";
19886
+ }
19841
19887
  /**
19842
19888
  * Generate cube metadata for API responses from cubes
19843
19889
  * Optimized version that minimizes object iterations
19844
19890
  */
19845
19891
  generateCubeMetadata(E) {
19846
- const R = Object.keys(E.measures), A = Object.keys(E.dimensions), S = new Array(R.length), e = new Array(A.length);
19847
- for (let N = 0; N < R.length; N++) {
19848
- const s = R[N], _ = E.measures[s];
19849
- S[N] = {
19850
- name: `${E.name}.${s}`,
19851
- title: _.title || s,
19852
- shortTitle: _.title || s,
19853
- type: _.type,
19892
+ const R = Object.keys(E.measures), A = Object.keys(E.dimensions), e = new Array(R.length), S = new Array(A.length);
19893
+ for (let s = 0; s < R.length; s++) {
19894
+ const _ = R[s], I = E.measures[_];
19895
+ e[s] = {
19896
+ name: `${E.name}.${_}`,
19897
+ title: I.title || _,
19898
+ shortTitle: I.title || _,
19899
+ type: I.type,
19854
19900
  format: void 0,
19855
19901
  // Measure doesn't have format field
19856
- description: _.description
19902
+ description: I.description
19857
19903
  };
19858
19904
  }
19859
- for (let N = 0; N < A.length; N++) {
19860
- const s = A[N], _ = E.dimensions[s];
19861
- e[N] = {
19862
- name: `${E.name}.${s}`,
19863
- title: _.title || s,
19864
- shortTitle: _.title || s,
19865
- type: _.type,
19905
+ for (let s = 0; s < A.length; s++) {
19906
+ const _ = A[s], I = E.dimensions[_];
19907
+ S[s] = {
19908
+ name: `${E.name}.${_}`,
19909
+ title: I.title || _,
19910
+ shortTitle: I.title || _,
19911
+ type: I.type,
19866
19912
  format: void 0,
19867
19913
  // Dimension doesn't have format field
19868
- description: _.description
19914
+ description: I.description
19869
19915
  };
19870
19916
  }
19917
+ const N = [];
19918
+ if (E.joins)
19919
+ for (const [, s] of Object.entries(E.joins)) {
19920
+ const _ = typeof s.targetCube == "function" ? s.targetCube() : s.targetCube;
19921
+ N.push({
19922
+ targetCube: _.name,
19923
+ relationship: s.relationship,
19924
+ joinFields: s.on.map((I) => ({
19925
+ sourceField: this.getColumnName(I.source),
19926
+ targetField: this.getColumnName(I.target)
19927
+ }))
19928
+ });
19929
+ }
19871
19930
  return {
19872
19931
  name: E.name,
19873
19932
  title: E.title || E.name,
19874
19933
  description: E.description,
19875
- measures: S,
19876
- dimensions: e,
19877
- segments: []
19934
+ measures: e,
19935
+ dimensions: S,
19936
+ segments: [],
19878
19937
  // Add segments support later if needed
19938
+ relationships: N.length > 0 ? N : void 0
19879
19939
  };
19880
19940
  }
19881
19941
  /**
19882
19942
  * Get SQL for a query without executing it (debugging)
19883
19943
  */
19884
19944
  async generateSQL(E, R, A) {
19885
- const S = this.getCube(E);
19886
- if (!S)
19945
+ const e = this.getCube(E);
19946
+ if (!e)
19887
19947
  throw new Error(`Cube '${E}' not found`);
19888
19948
  if (!this.dbExecutor)
19889
19949
  throw new Error("Database executor not configured");
19890
- const N = await new HE(this.dbExecutor).generateSQL(S, R, A), s = this.dbExecutor.getEngineType();
19950
+ const N = await new HE(this.dbExecutor).generateSQL(e, R, A), s = this.dbExecutor.getEngineType();
19891
19951
  return {
19892
19952
  sql: vT(N.sql, s),
19893
19953
  params: N.params
@@ -19899,10 +19959,10 @@ class cO {
19899
19959
  async generateMultiCubeSQL(E, R) {
19900
19960
  if (!this.dbExecutor)
19901
19961
  throw new Error("Database executor not configured");
19902
- const S = await new HE(this.dbExecutor).generateMultiCubeSQL(this.cubes, E, R), e = this.dbExecutor.getEngineType();
19962
+ const e = await new HE(this.dbExecutor).generateMultiCubeSQL(this.cubes, E, R), S = this.dbExecutor.getEngineType();
19903
19963
  return {
19904
- sql: vT(S.sql, e),
19905
- params: S.params
19964
+ sql: vT(e.sql, S),
19965
+ params: e.params
19906
19966
  };
19907
19967
  }
19908
19968
  /**
@@ -19942,94 +20002,94 @@ class cO {
19942
20002
  * Ensures all referenced cubes and fields exist
19943
20003
  */
19944
20004
  validateQuery(E) {
19945
- return pR(this.cubes, E);
20005
+ return fR(this.cubes, E);
19946
20006
  }
19947
20007
  }
19948
- function pR(T, E) {
20008
+ function fR(T, E) {
19949
20009
  const R = [], A = /* @__PURE__ */ new Set();
19950
20010
  if (E.measures)
19951
- for (const S of E.measures) {
19952
- const [e, N] = S.split(".");
19953
- if (!e || !N) {
19954
- R.push(`Invalid measure format: ${S}. Expected format: 'CubeName.fieldName'`);
20011
+ for (const e of E.measures) {
20012
+ const [S, N] = e.split(".");
20013
+ if (!S || !N) {
20014
+ R.push(`Invalid measure format: ${e}. Expected format: 'CubeName.fieldName'`);
19955
20015
  continue;
19956
20016
  }
19957
- A.add(e);
19958
- const s = T.get(e);
20017
+ A.add(S);
20018
+ const s = T.get(S);
19959
20019
  if (!s) {
19960
- R.push(`Cube '${e}' not found (referenced in measure '${S}')`);
20020
+ R.push(`Cube '${S}' not found (referenced in measure '${e}')`);
19961
20021
  continue;
19962
20022
  }
19963
- s.measures[N] || R.push(`Measure '${N}' not found on cube '${e}'`);
20023
+ s.measures[N] || R.push(`Measure '${N}' not found on cube '${S}'`);
19964
20024
  }
19965
20025
  if (E.dimensions)
19966
- for (const S of E.dimensions) {
19967
- const [e, N] = S.split(".");
19968
- if (!e || !N) {
19969
- R.push(`Invalid dimension format: ${S}. Expected format: 'CubeName.fieldName'`);
20026
+ for (const e of E.dimensions) {
20027
+ const [S, N] = e.split(".");
20028
+ if (!S || !N) {
20029
+ R.push(`Invalid dimension format: ${e}. Expected format: 'CubeName.fieldName'`);
19970
20030
  continue;
19971
20031
  }
19972
- A.add(e);
19973
- const s = T.get(e);
20032
+ A.add(S);
20033
+ const s = T.get(S);
19974
20034
  if (!s) {
19975
- R.push(`Cube '${e}' not found (referenced in dimension '${S}')`);
20035
+ R.push(`Cube '${S}' not found (referenced in dimension '${e}')`);
19976
20036
  continue;
19977
20037
  }
19978
- s.dimensions[N] || R.push(`Dimension '${N}' not found on cube '${e}'`);
20038
+ s.dimensions[N] || R.push(`Dimension '${N}' not found on cube '${S}'`);
19979
20039
  }
19980
20040
  if (E.timeDimensions)
19981
- for (const S of E.timeDimensions) {
19982
- const [e, N] = S.dimension.split(".");
19983
- if (!e || !N) {
19984
- R.push(`Invalid timeDimension format: ${S.dimension}. Expected format: 'CubeName.fieldName'`);
20041
+ for (const e of E.timeDimensions) {
20042
+ const [S, N] = e.dimension.split(".");
20043
+ if (!S || !N) {
20044
+ R.push(`Invalid timeDimension format: ${e.dimension}. Expected format: 'CubeName.fieldName'`);
19985
20045
  continue;
19986
20046
  }
19987
- A.add(e);
19988
- const s = T.get(e);
20047
+ A.add(S);
20048
+ const s = T.get(S);
19989
20049
  if (!s) {
19990
- R.push(`Cube '${e}' not found (referenced in timeDimension '${S.dimension}')`);
20050
+ R.push(`Cube '${S}' not found (referenced in timeDimension '${e.dimension}')`);
19991
20051
  continue;
19992
20052
  }
19993
- s.dimensions[N] || R.push(`TimeDimension '${N}' not found on cube '${e}' (must be a dimension with time type)`);
20053
+ s.dimensions[N] || R.push(`TimeDimension '${N}' not found on cube '${S}' (must be a dimension with time type)`);
19994
20054
  }
19995
20055
  if (E.filters)
19996
- for (const S of E.filters)
19997
- dR(S, T, R, A);
20056
+ for (const e of E.filters)
20057
+ hR(e, T, R, A);
19998
20058
  return A.size === 0 && R.push("Query must reference at least one cube through measures, dimensions, or filters"), {
19999
20059
  isValid: R.length === 0,
20000
20060
  errors: R
20001
20061
  };
20002
20062
  }
20003
- function dR(T, E, R, A) {
20063
+ function hR(T, E, R, A) {
20004
20064
  if ("and" in T || "or" in T) {
20005
20065
  const s = T.and || T.or || [];
20006
20066
  for (const _ of s)
20007
- dR(_, E, R, A);
20067
+ hR(_, E, R, A);
20008
20068
  return;
20009
20069
  }
20010
20070
  if (!("member" in T)) {
20011
20071
  R.push("Filter must have a member field");
20012
20072
  return;
20013
20073
  }
20014
- const [S, e] = T.member.split(".");
20015
- if (!S || !e) {
20074
+ const [e, S] = T.member.split(".");
20075
+ if (!e || !S) {
20016
20076
  R.push(`Invalid filter member format: ${T.member}. Expected format: 'CubeName.fieldName'`);
20017
20077
  return;
20018
20078
  }
20019
- A.add(S);
20020
- const N = E.get(S);
20079
+ A.add(e);
20080
+ const N = E.get(e);
20021
20081
  if (!N) {
20022
- R.push(`Cube '${S}' not found (referenced in filter '${T.member}')`);
20082
+ R.push(`Cube '${e}' not found (referenced in filter '${T.member}')`);
20023
20083
  return;
20024
20084
  }
20025
- !N.dimensions[e] && !N.measures[e] && R.push(`Filter field '${e}' not found on cube '${S}' (must be a dimension or measure)`);
20085
+ !N.dimensions[S] && !N.measures[S] && R.push(`Filter field '${S}' not found on cube '${e}' (must be a dimension or measure)`);
20026
20086
  }
20027
- new cO();
20087
+ new BO();
20028
20088
  export {
20029
- cO as S,
20030
- FO as a,
20031
- mO as b,
20032
- YO as c,
20033
- BO as f,
20034
- HO as h
20089
+ BO as S,
20090
+ dO as a,
20091
+ pO as b,
20092
+ fO as c,
20093
+ YO as f,
20094
+ FO as h
20035
20095
  };