drizzle-cube 0.1.40 → 0.1.42

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.
@@ -174,74 +174,74 @@ class H {
174
174
  }), {
175
175
  casing: A,
176
176
  escapeName: S,
177
- escapeParam: N,
177
+ escapeParam: I,
178
178
  prepareTyping: t,
179
- inlineParams: C,
179
+ inlineParams: s,
180
180
  paramStartIndex: O
181
181
  } = R;
182
- return De(E.map((I) => {
183
- if (d(I, f))
184
- return { sql: I.value.join(""), params: [] };
185
- if (d(I, ZE))
186
- return { sql: S(I.value), params: [] };
187
- if (I === void 0)
182
+ return De(E.map((N) => {
183
+ if (d(N, f))
184
+ return { sql: N.value.join(""), params: [] };
185
+ if (d(N, ZE))
186
+ return { sql: S(N.value), params: [] };
187
+ if (N === void 0)
188
188
  return { sql: "", params: [] };
189
- if (Array.isArray(I)) {
190
- const s = [new f("(")];
191
- for (const [r, _] of I.entries())
192
- s.push(_), r < I.length - 1 && s.push(new f(", "));
193
- return s.push(new f(")")), this.buildQueryFromSourceParams(s, R);
189
+ if (Array.isArray(N)) {
190
+ const C = [new f("(")];
191
+ for (const [L, n] of N.entries())
192
+ C.push(n), L < N.length - 1 && C.push(new f(", "));
193
+ return C.push(new f(")")), this.buildQueryFromSourceParams(C, R);
194
194
  }
195
- if (d(I, H))
196
- return this.buildQueryFromSourceParams(I.queryChunks, {
195
+ if (d(N, H))
196
+ return this.buildQueryFromSourceParams(N.queryChunks, {
197
197
  ...R,
198
- inlineParams: C || I.shouldInlineParams
198
+ inlineParams: s || N.shouldInlineParams
199
199
  });
200
- if (d(I, W)) {
201
- const s = I[W.Symbol.Schema], r = I[W.Symbol.Name];
200
+ if (d(N, W)) {
201
+ const C = N[W.Symbol.Schema], L = N[W.Symbol.Name];
202
202
  return {
203
- sql: s === void 0 || I[sE] ? S(r) : S(s) + "." + S(r),
203
+ sql: C === void 0 || N[sE] ? S(L) : S(C) + "." + S(L),
204
204
  params: []
205
205
  };
206
206
  }
207
- if (d(I, RE)) {
208
- const s = A.getColumnCasing(I);
207
+ if (d(N, RE)) {
208
+ const C = A.getColumnCasing(N);
209
209
  if (e.invokeSource === "indexes")
210
- return { sql: S(s), params: [] };
211
- const r = I.table[W.Symbol.Schema];
210
+ return { sql: S(C), params: [] };
211
+ const L = N.table[W.Symbol.Schema];
212
212
  return {
213
- sql: I.table[sE] || r === void 0 ? S(I.table[W.Symbol.Name]) + "." + S(s) : S(r) + "." + S(I.table[W.Symbol.Name]) + "." + S(s),
213
+ sql: N.table[sE] || L === void 0 ? S(N.table[W.Symbol.Name]) + "." + S(C) : S(L) + "." + S(N.table[W.Symbol.Name]) + "." + S(C),
214
214
  params: []
215
215
  };
216
216
  }
217
- if (d(I, qT)) {
218
- const s = I[TE].schema, r = I[TE].name;
217
+ if (d(N, qT)) {
218
+ const C = N[TE].schema, L = N[TE].name;
219
219
  return {
220
- sql: s === void 0 || I[TE].isAlias ? S(r) : S(s) + "." + S(r),
220
+ sql: C === void 0 || N[TE].isAlias ? S(L) : S(C) + "." + S(L),
221
221
  params: []
222
222
  };
223
223
  }
224
- if (d(I, CE)) {
225
- if (d(I.value, rE))
226
- return { sql: N(O.value++, I), params: [I], typings: ["none"] };
227
- const s = I.value === null ? null : I.encoder.mapToDriverValue(I.value);
228
- if (d(s, H))
229
- return this.buildQueryFromSourceParams([s], R);
230
- if (C)
231
- return { sql: this.mapInlineParam(s, R), params: [] };
232
- let r = ["none"];
233
- return t && (r = [t(I.encoder)]), { sql: N(O.value++, s), params: [s], typings: r };
224
+ if (d(N, CE)) {
225
+ if (d(N.value, rE))
226
+ return { sql: I(O.value++, N), params: [N], typings: ["none"] };
227
+ const C = N.value === null ? null : N.encoder.mapToDriverValue(N.value);
228
+ if (d(C, H))
229
+ return this.buildQueryFromSourceParams([C], R);
230
+ if (s)
231
+ return { sql: this.mapInlineParam(C, R), params: [] };
232
+ let L = ["none"];
233
+ return t && (L = [t(N.encoder)]), { sql: I(O.value++, C), params: [C], typings: L };
234
234
  }
235
- return d(I, rE) ? { sql: N(O.value++, I), params: [I], typings: ["none"] } : d(I, H.Aliased) && I.fieldAlias !== void 0 ? { sql: S(I.fieldAlias), params: [] } : d(I, xT) ? I._.isWith ? { sql: S(I._.alias), params: [] } : this.buildQueryFromSourceParams([
235
+ return d(N, rE) ? { sql: I(O.value++, N), params: [N], typings: ["none"] } : d(N, H.Aliased) && N.fieldAlias !== void 0 ? { sql: S(N.fieldAlias), params: [] } : d(N, xT) ? N._.isWith ? { sql: S(N._.alias), params: [] } : this.buildQueryFromSourceParams([
236
236
  new f("("),
237
- I._.sql,
237
+ N._.sql,
238
238
  new f(") "),
239
- new ZE(I._.alias)
240
- ], R) : ie(I) ? I.schema ? { sql: S(I.schema) + "." + S(I.enumName), params: [] } : { sql: S(I.enumName), params: [] } : vT(I) ? I.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([I.getSQL()], R) : this.buildQueryFromSourceParams([
239
+ new ZE(N._.alias)
240
+ ], R) : ie(N) ? N.schema ? { sql: S(N.schema) + "." + S(N.enumName), params: [] } : { sql: S(N.enumName), params: [] } : vT(N) ? N.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([N.getSQL()], R) : this.buildQueryFromSourceParams([
241
241
  new f("("),
242
- I.getSQL(),
242
+ N.getSQL(),
243
243
  new f(")")
244
- ], R) : C ? { sql: this.mapInlineParam(I, R), params: [] } : { sql: N(O.value++, I), params: [I], typings: ["none"] };
244
+ ], R) : s ? { sql: this.mapInlineParam(N, R), params: [] } : { sql: I(O.value++, N), params: [N], typings: ["none"] };
245
245
  }));
246
246
  }
247
247
  mapInlineParam(E, { escapeString: e }) {
@@ -315,7 +315,7 @@ class CE {
315
315
  return new H([this]);
316
316
  }
317
317
  }
318
- function L(T, ...E) {
318
+ function r(T, ...E) {
319
319
  const e = [];
320
320
  (E.length > 0 || T.length > 0 && T[0] !== "") && e.push(new f(T[0]));
321
321
  for (const [R, A] of E.entries())
@@ -327,34 +327,34 @@ function L(T, ...E) {
327
327
  return new H([]);
328
328
  }
329
329
  T.empty = E;
330
- function e(C) {
331
- return new H(C);
330
+ function e(s) {
331
+ return new H(s);
332
332
  }
333
333
  T.fromList = e;
334
- function R(C) {
335
- return new H([new f(C)]);
334
+ function R(s) {
335
+ return new H([new f(s)]);
336
336
  }
337
337
  T.raw = R;
338
- function A(C, O) {
339
- const I = [];
340
- for (const [s, r] of C.entries())
341
- s > 0 && O !== void 0 && I.push(O), I.push(r);
342
- return new H(I);
338
+ function A(s, O) {
339
+ const N = [];
340
+ for (const [C, L] of s.entries())
341
+ C > 0 && O !== void 0 && N.push(O), N.push(L);
342
+ return new H(N);
343
343
  }
344
344
  T.join = A;
345
- function S(C) {
346
- return new ZE(C);
345
+ function S(s) {
346
+ return new ZE(s);
347
347
  }
348
348
  T.identifier = S;
349
- function N(C) {
350
- return new rE(C);
349
+ function I(s) {
350
+ return new rE(s);
351
351
  }
352
- T.placeholder = N;
353
- function t(C, O) {
354
- return new CE(C, O);
352
+ T.placeholder = I;
353
+ function t(s, O) {
354
+ return new CE(s, O);
355
355
  }
356
356
  T.param = t;
357
- })(L || (L = {}));
357
+ })(r || (r = {}));
358
358
  ((T) => {
359
359
  class E {
360
360
  constructor(R, A) {
@@ -413,10 +413,10 @@ W.prototype.getSQL = function() {
413
413
  xT.prototype.getSQL = function() {
414
414
  return new H([this]);
415
415
  };
416
- function K(T, E) {
416
+ function g(T, E) {
417
417
  return Pe(E) && !vT(T) && !d(T, CE) && !d(T, rE) && !d(T, RE) && !d(T, W) && !d(T, qT) ? new CE(T, E) : T;
418
418
  }
419
- const k = (T, E) => L`${T} = ${K(E, T)}`, ST = (T, E) => L`${T} <> ${K(E, T)}`;
419
+ const k = (T, E) => r`${T} = ${g(E, T)}`, ST = (T, E) => r`${T} <> ${g(E, T)}`;
420
420
  function h(...T) {
421
421
  const E = T.filter(
422
422
  (e) => e !== void 0
@@ -424,7 +424,7 @@ function h(...T) {
424
424
  if (E.length !== 0)
425
425
  return E.length === 1 ? new H(E) : new H([
426
426
  new f("("),
427
- L.join(E, new f(" and ")),
427
+ r.join(E, new f(" and ")),
428
428
  new f(")")
429
429
  ]);
430
430
  }
@@ -435,43 +435,43 @@ function PE(...T) {
435
435
  if (E.length !== 0)
436
436
  return E.length === 1 ? new H(E) : new H([
437
437
  new f("("),
438
- L.join(E, new f(" or ")),
438
+ r.join(E, new f(" or ")),
439
439
  new f(")")
440
440
  ]);
441
441
  }
442
- const ME = (T, E) => L`${T} > ${K(E, T)}`, Q = (T, E) => L`${T} >= ${K(E, T)}`, UE = (T, E) => L`${T} < ${K(E, T)}`, Z = (T, E) => L`${T} <= ${K(E, T)}`;
442
+ const ME = (T, E) => r`${T} > ${g(E, T)}`, Q = (T, E) => r`${T} >= ${g(E, T)}`, UE = (T, E) => r`${T} < ${g(E, T)}`, Z = (T, E) => r`${T} <= ${g(E, T)}`;
443
443
  function lE(T, E) {
444
- return Array.isArray(E) ? E.length === 0 ? L`false` : L`${T} in ${E.map((e) => K(e, T))}` : L`${T} in ${K(E, T)}`;
444
+ return Array.isArray(E) ? E.length === 0 ? r`false` : r`${T} in ${E.map((e) => g(e, T))}` : r`${T} in ${g(E, T)}`;
445
445
  }
446
446
  function IT(T, E) {
447
- return Array.isArray(E) ? E.length === 0 ? L`true` : L`${T} not in ${E.map((e) => K(e, T))}` : L`${T} not in ${K(E, T)}`;
447
+ return Array.isArray(E) ? E.length === 0 ? r`true` : r`${T} not in ${E.map((e) => g(e, T))}` : r`${T} not in ${g(E, T)}`;
448
448
  }
449
449
  function NT(T) {
450
- return L`${T} is null`;
450
+ return r`${T} is null`;
451
451
  }
452
452
  function OT(T) {
453
- return L`${T} is not null`;
453
+ return r`${T} is not null`;
454
454
  }
455
455
  function tT(T) {
456
- return L`${T} asc`;
456
+ return r`${T} asc`;
457
457
  }
458
458
  function Ue(T) {
459
- return L`${T} desc`;
459
+ return r`${T} desc`;
460
460
  }
461
461
  function cE(T) {
462
- return L`count(${T || L.raw("*")})`.mapWith(Number);
462
+ return r`count(${T || r.raw("*")})`.mapWith(Number);
463
463
  }
464
464
  function le(T) {
465
- return L`count(distinct ${T})`.mapWith(Number);
465
+ return r`count(distinct ${T})`.mapWith(Number);
466
466
  }
467
467
  function y(T) {
468
- return L`sum(${T})`.mapWith(String);
468
+ return r`sum(${T})`.mapWith(String);
469
469
  }
470
470
  function AE(T) {
471
- return L`max(${T})`.mapWith(d(T, RE) ? T : String);
471
+ return r`max(${T})`.mapWith(d(T, RE) ? T : String);
472
472
  }
473
473
  function SE(T) {
474
- return L`min(${T})`.mapWith(d(T, RE) ? T : String);
474
+ return r`min(${T})`.mapWith(d(T, RE) ? T : String);
475
475
  }
476
476
  class jE {
477
477
  /**
@@ -510,21 +510,21 @@ class ce extends jE {
510
510
  buildTimeDimension(E, e) {
511
511
  switch (E) {
512
512
  case "year":
513
- return L`DATE_TRUNC('year', ${e}::timestamp)`;
513
+ return r`DATE_TRUNC('year', ${e}::timestamp)`;
514
514
  case "quarter":
515
- return L`DATE_TRUNC('quarter', ${e}::timestamp)`;
515
+ return r`DATE_TRUNC('quarter', ${e}::timestamp)`;
516
516
  case "month":
517
- return L`DATE_TRUNC('month', ${e}::timestamp)`;
517
+ return r`DATE_TRUNC('month', ${e}::timestamp)`;
518
518
  case "week":
519
- return L`DATE_TRUNC('week', ${e}::timestamp)`;
519
+ return r`DATE_TRUNC('week', ${e}::timestamp)`;
520
520
  case "day":
521
- return L`DATE_TRUNC('day', ${e}::timestamp)::timestamp`;
521
+ return r`DATE_TRUNC('day', ${e}::timestamp)::timestamp`;
522
522
  case "hour":
523
- return L`DATE_TRUNC('hour', ${e}::timestamp)`;
523
+ return r`DATE_TRUNC('hour', ${e}::timestamp)`;
524
524
  case "minute":
525
- return L`DATE_TRUNC('minute', ${e}::timestamp)`;
525
+ return r`DATE_TRUNC('minute', ${e}::timestamp)`;
526
526
  case "second":
527
- return L`DATE_TRUNC('second', ${e}::timestamp)`;
527
+ return r`DATE_TRUNC('second', ${e}::timestamp)`;
528
528
  default:
529
529
  return e;
530
530
  }
@@ -536,23 +536,23 @@ class ce extends jE {
536
536
  buildStringCondition(E, e, R) {
537
537
  switch (e) {
538
538
  case "contains":
539
- return L`${E} ILIKE ${`%${R}%`}`;
539
+ return r`${E} ILIKE ${`%${R}%`}`;
540
540
  case "notContains":
541
- return L`${E} NOT ILIKE ${`%${R}%`}`;
541
+ return r`${E} NOT ILIKE ${`%${R}%`}`;
542
542
  case "startsWith":
543
- return L`${E} ILIKE ${`${R}%`}`;
543
+ return r`${E} ILIKE ${`${R}%`}`;
544
544
  case "endsWith":
545
- return L`${E} ILIKE ${`%${R}`}`;
545
+ return r`${E} ILIKE ${`%${R}`}`;
546
546
  case "like":
547
- return L`${E} LIKE ${R}`;
547
+ return r`${E} LIKE ${R}`;
548
548
  case "notLike":
549
- return L`${E} NOT LIKE ${R}`;
549
+ return r`${E} NOT LIKE ${R}`;
550
550
  case "ilike":
551
- return L`${E} ILIKE ${R}`;
551
+ return r`${E} ILIKE ${R}`;
552
552
  case "regex":
553
- return L`${E} ~* ${R}`;
553
+ return r`${E} ~* ${R}`;
554
554
  case "notRegex":
555
- return L`${E} !~* ${R}`;
555
+ return r`${E} !~* ${R}`;
556
556
  default:
557
557
  throw new Error(`Unsupported string operator: ${e}`);
558
558
  }
@@ -564,11 +564,11 @@ class ce extends jE {
564
564
  castToType(E, e) {
565
565
  switch (e) {
566
566
  case "timestamp":
567
- return L`${E}::timestamp`;
567
+ return r`${E}::timestamp`;
568
568
  case "decimal":
569
- return L`${E}::decimal`;
569
+ return r`${E}::decimal`;
570
570
  case "integer":
571
- return L`${E}::integer`;
571
+ return r`${E}::integer`;
572
572
  default:
573
573
  throw new Error(`Unsupported cast type: ${e}`);
574
574
  }
@@ -579,21 +579,21 @@ class ce extends jE {
579
579
  * Extracted from multi-cube-builder.ts:284
580
580
  */
581
581
  buildAvg(E) {
582
- return L`COALESCE(AVG(${E}), 0)`;
582
+ return r`COALESCE(AVG(${E}), 0)`;
583
583
  }
584
584
  /**
585
585
  * Build PostgreSQL CASE WHEN conditional expression
586
586
  */
587
587
  buildCaseWhen(E, e) {
588
- const R = E.map((A) => L`WHEN ${A.when} THEN ${A.then}`).reduce((A, S) => L`${A} ${S}`);
589
- return e !== void 0 ? L`CASE ${R} ELSE ${e} END` : L`CASE ${R} END`;
588
+ const R = E.map((A) => r`WHEN ${A.when} THEN ${A.then}`).reduce((A, S) => r`${A} ${S}`);
589
+ return e !== void 0 ? r`CASE ${R} ELSE ${e} END` : r`CASE ${R} END`;
590
590
  }
591
591
  /**
592
592
  * Build PostgreSQL boolean literal
593
593
  * PostgreSQL uses TRUE/FALSE keywords
594
594
  */
595
595
  buildBooleanLiteral(E) {
596
- return E ? L`TRUE` : L`FALSE`;
596
+ return E ? r`TRUE` : r`FALSE`;
597
597
  }
598
598
  /**
599
599
  * Convert filter values - PostgreSQL uses native types
@@ -646,12 +646,12 @@ class jT extends jE {
646
646
  };
647
647
  switch (E) {
648
648
  case "quarter":
649
- return L`DATE_ADD(MAKEDATE(YEAR(${e}), 1), INTERVAL (QUARTER(${e}) - 1) * 3 MONTH)`;
649
+ return r`DATE_ADD(MAKEDATE(YEAR(${e}), 1), INTERVAL (QUARTER(${e}) - 1) * 3 MONTH)`;
650
650
  case "week":
651
- return L`DATE_SUB(${e}, INTERVAL WEEKDAY(${e}) DAY)`;
651
+ return r`DATE_SUB(${e}, INTERVAL WEEKDAY(${e}) DAY)`;
652
652
  default:
653
653
  const A = R[E];
654
- return A ? L`STR_TO_DATE(DATE_FORMAT(${e}, ${A}), '%Y-%m-%d %H:%i:%s')` : e;
654
+ return A ? r`STR_TO_DATE(DATE_FORMAT(${e}, ${A}), '%Y-%m-%d %H:%i:%s')` : e;
655
655
  }
656
656
  }
657
657
  /**
@@ -662,23 +662,23 @@ class jT extends jE {
662
662
  buildStringCondition(E, e, R) {
663
663
  switch (e) {
664
664
  case "contains":
665
- return L`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
665
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
666
666
  case "notContains":
667
- return L`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
667
+ return r`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
668
668
  case "startsWith":
669
- return L`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
669
+ return r`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
670
670
  case "endsWith":
671
- return L`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
671
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
672
672
  case "like":
673
- return L`${E} LIKE ${R}`;
673
+ return r`${E} LIKE ${R}`;
674
674
  case "notLike":
675
- return L`${E} NOT LIKE ${R}`;
675
+ return r`${E} NOT LIKE ${R}`;
676
676
  case "ilike":
677
- return L`LOWER(${E}) LIKE ${R.toLowerCase()}`;
677
+ return r`LOWER(${E}) LIKE ${R.toLowerCase()}`;
678
678
  case "regex":
679
- return L`${E} REGEXP ${R}`;
679
+ return r`${E} REGEXP ${R}`;
680
680
  case "notRegex":
681
- return L`${E} NOT REGEXP ${R}`;
681
+ return r`${E} NOT REGEXP ${R}`;
682
682
  default:
683
683
  throw new Error(`Unsupported string operator: ${e}`);
684
684
  }
@@ -690,11 +690,11 @@ class jT extends jE {
690
690
  castToType(E, e) {
691
691
  switch (e) {
692
692
  case "timestamp":
693
- return L`CAST(${E} AS DATETIME)`;
693
+ return r`CAST(${E} AS DATETIME)`;
694
694
  case "decimal":
695
- return L`CAST(${E} AS DECIMAL(10,2))`;
695
+ return r`CAST(${E} AS DECIMAL(10,2))`;
696
696
  case "integer":
697
- return L`CAST(${E} AS SIGNED INTEGER)`;
697
+ return r`CAST(${E} AS SIGNED INTEGER)`;
698
698
  default:
699
699
  throw new Error(`Unsupported cast type: ${e}`);
700
700
  }
@@ -704,21 +704,21 @@ class jT extends jE {
704
704
  * MySQL AVG returns NULL for empty sets, using IFNULL for consistency
705
705
  */
706
706
  buildAvg(E) {
707
- return L`IFNULL(AVG(${E}), 0)`;
707
+ return r`IFNULL(AVG(${E}), 0)`;
708
708
  }
709
709
  /**
710
710
  * Build MySQL CASE WHEN conditional expression
711
711
  */
712
712
  buildCaseWhen(E, e) {
713
- const R = E.map((A) => L`WHEN ${A.when} THEN ${A.then}`).reduce((A, S) => L`${A} ${S}`);
714
- return e !== void 0 ? L`CASE ${R} ELSE ${e} END` : L`CASE ${R} END`;
713
+ const R = E.map((A) => r`WHEN ${A.when} THEN ${A.then}`).reduce((A, S) => r`${A} ${S}`);
714
+ return e !== void 0 ? r`CASE ${R} ELSE ${e} END` : r`CASE ${R} END`;
715
715
  }
716
716
  /**
717
717
  * Build MySQL boolean literal
718
718
  * MySQL uses TRUE/FALSE keywords (equivalent to 1/0)
719
719
  */
720
720
  buildBooleanLiteral(E) {
721
- return E ? L`TRUE` : L`FALSE`;
721
+ return E ? r`TRUE` : r`FALSE`;
722
722
  }
723
723
  /**
724
724
  * Convert filter values - MySQL uses native types
@@ -761,28 +761,28 @@ class ue extends jE {
761
761
  buildTimeDimension(E, e) {
762
762
  switch (E) {
763
763
  case "year":
764
- return L`datetime(${e}, 'unixepoch', 'start of year')`;
764
+ return r`datetime(${e}, 'unixepoch', 'start of year')`;
765
765
  case "quarter":
766
- const R = L`datetime(${e}, 'unixepoch')`;
767
- return L`datetime(${R}, 'start of year',
766
+ const R = r`datetime(${e}, 'unixepoch')`;
767
+ return r`datetime(${R}, 'start of year',
768
768
  '+' || (((CAST(strftime('%m', ${R}) AS INTEGER) - 1) / 3) * 3) || ' months')`;
769
769
  case "month":
770
- return L`datetime(${e}, 'unixepoch', 'start of month')`;
770
+ return r`datetime(${e}, 'unixepoch', 'start of month')`;
771
771
  case "week":
772
- return L`date(datetime(${e}, 'unixepoch'), 'weekday 1', '-6 days')`;
772
+ return r`date(datetime(${e}, 'unixepoch'), 'weekday 1', '-6 days')`;
773
773
  case "day":
774
- return L`datetime(${e}, 'unixepoch', 'start of day')`;
774
+ return r`datetime(${e}, 'unixepoch', 'start of day')`;
775
775
  case "hour":
776
- const A = L`datetime(${e}, 'unixepoch')`;
777
- return L`datetime(strftime('%Y-%m-%d %H:00:00', ${A}))`;
776
+ const A = r`datetime(${e}, 'unixepoch')`;
777
+ return r`datetime(strftime('%Y-%m-%d %H:00:00', ${A}))`;
778
778
  case "minute":
779
- const S = L`datetime(${e}, 'unixepoch')`;
780
- return L`datetime(strftime('%Y-%m-%d %H:%M:00', ${S}))`;
779
+ const S = r`datetime(${e}, 'unixepoch')`;
780
+ return r`datetime(strftime('%Y-%m-%d %H:%M:00', ${S}))`;
781
781
  case "second":
782
- const N = L`datetime(${e}, 'unixepoch')`;
783
- return L`datetime(strftime('%Y-%m-%d %H:%M:%S', ${N}))`;
782
+ const I = r`datetime(${e}, 'unixepoch')`;
783
+ return r`datetime(strftime('%Y-%m-%d %H:%M:%S', ${I}))`;
784
784
  default:
785
- return L`datetime(${e}, 'unixepoch')`;
785
+ return r`datetime(${e}, 'unixepoch')`;
786
786
  }
787
787
  }
788
788
  /**
@@ -792,23 +792,23 @@ class ue extends jE {
792
792
  buildStringCondition(E, e, R) {
793
793
  switch (e) {
794
794
  case "contains":
795
- return L`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
795
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
796
796
  case "notContains":
797
- return L`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
797
+ return r`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
798
798
  case "startsWith":
799
- return L`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
799
+ return r`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
800
800
  case "endsWith":
801
- return L`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
801
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
802
802
  case "like":
803
- return L`${E} LIKE ${R}`;
803
+ return r`${E} LIKE ${R}`;
804
804
  case "notLike":
805
- return L`${E} NOT LIKE ${R}`;
805
+ return r`${E} NOT LIKE ${R}`;
806
806
  case "ilike":
807
- return L`LOWER(${E}) LIKE ${R.toLowerCase()}`;
807
+ return r`LOWER(${E}) LIKE ${R.toLowerCase()}`;
808
808
  case "regex":
809
- return L`${E} GLOB ${R}`;
809
+ return r`${E} GLOB ${R}`;
810
810
  case "notRegex":
811
- return L`${E} NOT GLOB ${R}`;
811
+ return r`${E} NOT GLOB ${R}`;
812
812
  default:
813
813
  throw new Error(`Unsupported string operator: ${e}`);
814
814
  }
@@ -820,11 +820,11 @@ class ue extends jE {
820
820
  castToType(E, e) {
821
821
  switch (e) {
822
822
  case "timestamp":
823
- return L`datetime(${E} / 1000, 'unixepoch')`;
823
+ return r`datetime(${E} / 1000, 'unixepoch')`;
824
824
  case "decimal":
825
- return L`CAST(${E} AS REAL)`;
825
+ return r`CAST(${E} AS REAL)`;
826
826
  case "integer":
827
- return L`CAST(${E} AS INTEGER)`;
827
+ return r`CAST(${E} AS INTEGER)`;
828
828
  default:
829
829
  throw new Error(`Unsupported cast type: ${e}`);
830
830
  }
@@ -834,21 +834,21 @@ class ue extends jE {
834
834
  * SQLite AVG returns NULL for empty sets, using IFNULL for consistency
835
835
  */
836
836
  buildAvg(E) {
837
- return L`IFNULL(AVG(${E}), 0)`;
837
+ return r`IFNULL(AVG(${E}), 0)`;
838
838
  }
839
839
  /**
840
840
  * Build SQLite CASE WHEN conditional expression
841
841
  */
842
842
  buildCaseWhen(E, e) {
843
- const R = E.map((A) => A.then && typeof A.then == "object" && (A.then.queryChunks || A.then._ || A.then.sql) ? L`WHEN ${A.when} THEN ${L.raw("(")}${A.then}${L.raw(")")}` : L`WHEN ${A.when} THEN ${A.then}`).reduce((A, S) => L`${A} ${S}`);
844
- return e !== void 0 ? e && typeof e == "object" && (e.queryChunks || e._ || e.sql) ? L`CASE ${R} ELSE ${L.raw("(")}${e}${L.raw(")")} END` : L`CASE ${R} ELSE ${e} END` : L`CASE ${R} END`;
843
+ const R = E.map((A) => A.then && typeof A.then == "object" && (A.then.queryChunks || A.then._ || A.then.sql) ? r`WHEN ${A.when} THEN ${r.raw("(")}${A.then}${r.raw(")")}` : r`WHEN ${A.when} THEN ${A.then}`).reduce((A, S) => r`${A} ${S}`);
844
+ return e !== void 0 ? e && typeof e == "object" && (e.queryChunks || e._ || e.sql) ? r`CASE ${R} ELSE ${r.raw("(")}${e}${r.raw(")")} END` : r`CASE ${R} ELSE ${e} END` : r`CASE ${R} END`;
845
845
  }
846
846
  /**
847
847
  * Build SQLite boolean literal
848
848
  * SQLite uses 1/0 for true/false
849
849
  */
850
850
  buildBooleanLiteral(E) {
851
- return E ? L`1` : L`0`;
851
+ return E ? r`1` : r`0`;
852
852
  }
853
853
  /**
854
854
  * Preprocess calculated measure templates for SQLite-specific handling
@@ -1131,7 +1131,7 @@ function zT(T, E) {
1131
1131
  }
1132
1132
  }
1133
1133
  function Ye(T) {
1134
- return T && typeof T == "object" ? L`${L`${T}`}` : T;
1134
+ return T && typeof T == "object" ? r`${r`${T}`}` : T;
1135
1135
  }
1136
1136
  function w(T, E) {
1137
1137
  const e = typeof T == "function" ? T(E) : T;
@@ -1140,20 +1140,20 @@ function w(T, E) {
1140
1140
  function fe(T, E) {
1141
1141
  if (T.relationship !== "belongsToMany" || !T.through)
1142
1142
  throw new Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
1143
- const { table: e, sourceKey: R, targetKey: A, securitySql: S } = T.through, N = [];
1144
- for (const I of R) {
1145
- const s = I.as || k;
1146
- N.push(s(I.source, I.target));
1143
+ const { table: e, sourceKey: R, targetKey: A, securitySql: S } = T.through, I = [];
1144
+ for (const N of R) {
1145
+ const C = N.as || k;
1146
+ I.push(C(N.source, N.target));
1147
1147
  }
1148
1148
  const t = [];
1149
- for (const I of A) {
1150
- const s = I.as || k;
1151
- t.push(s(I.source, I.target));
1149
+ for (const N of A) {
1150
+ const C = N.as || k;
1151
+ t.push(C(N.source, N.target));
1152
1152
  }
1153
- let C;
1153
+ let s;
1154
1154
  if (S) {
1155
- const I = S(E);
1156
- C = Array.isArray(I) ? I : [I];
1155
+ const N = S(E);
1156
+ s = Array.isArray(N) ? N : [N];
1157
1157
  }
1158
1158
  const O = zT("belongsToMany", T.sqlJoinType);
1159
1159
  return {
@@ -1161,7 +1161,7 @@ function fe(T, E) {
1161
1161
  {
1162
1162
  joinType: O,
1163
1163
  table: e,
1164
- condition: h(...N)
1164
+ condition: h(...I)
1165
1165
  },
1166
1166
  {
1167
1167
  joinType: O,
@@ -1170,7 +1170,7 @@ function fe(T, E) {
1170
1170
  condition: h(...t)
1171
1171
  }
1172
1172
  ],
1173
- junctionSecurityConditions: C
1173
+ junctionSecurityConditions: s
1174
1174
  };
1175
1175
  }
1176
1176
  class J {
@@ -1189,19 +1189,19 @@ class J {
1189
1189
  extractDependencies(E) {
1190
1190
  const e = /\{([^}]+)\}/g, R = E.matchAll(e), A = [];
1191
1191
  for (const S of R) {
1192
- const N = S[1].trim();
1193
- if (N.includes(".")) {
1194
- const [t, C] = N.split(".");
1192
+ const I = S[1].trim();
1193
+ if (I.includes(".")) {
1194
+ const [t, s] = I.split(".");
1195
1195
  A.push({
1196
- measureName: N,
1196
+ measureName: I,
1197
1197
  cubeName: t.trim(),
1198
- fieldName: C.trim()
1198
+ fieldName: s.trim()
1199
1199
  });
1200
1200
  } else
1201
1201
  A.push({
1202
- measureName: N,
1202
+ measureName: I,
1203
1203
  cubeName: null,
1204
- fieldName: N
1204
+ fieldName: I
1205
1205
  });
1206
1206
  }
1207
1207
  return A;
@@ -1214,14 +1214,14 @@ class J {
1214
1214
  buildGraph(E) {
1215
1215
  for (const [e, R] of Object.entries(E.measures))
1216
1216
  if (R.type === "calculated" && R.calculatedSql) {
1217
- const A = `${E.name}.${e}`, S = this.extractDependencies(R.calculatedSql), N = /* @__PURE__ */ new Set();
1217
+ const A = `${E.name}.${e}`, S = this.extractDependencies(R.calculatedSql), I = /* @__PURE__ */ new Set();
1218
1218
  for (const t of S) {
1219
1219
  const O = `${t.cubeName || E.name}.${t.fieldName}`;
1220
- N.add(O);
1220
+ I.add(O);
1221
1221
  }
1222
1222
  this.dependencyGraph.set(A, {
1223
1223
  id: A,
1224
- dependencies: N,
1224
+ dependencies: I,
1225
1225
  inDegree: 0
1226
1226
  });
1227
1227
  }
@@ -1259,27 +1259,27 @@ class J {
1259
1259
  topologicalSort(E) {
1260
1260
  const e = /* @__PURE__ */ new Map(), R = [], A = [];
1261
1261
  for (const S of E) {
1262
- const N = this.dependencyGraph.get(S);
1263
- N && e.set(S, {
1264
- id: N.id,
1265
- dependencies: new Set(N.dependencies),
1262
+ const I = this.dependencyGraph.get(S);
1263
+ I && e.set(S, {
1264
+ id: I.id,
1265
+ dependencies: new Set(I.dependencies),
1266
1266
  inDegree: 0
1267
1267
  // Will recalculate below
1268
1268
  });
1269
1269
  }
1270
1270
  for (const S of e.values()) {
1271
- let N = 0;
1271
+ let I = 0;
1272
1272
  for (const t of S.dependencies)
1273
- e.has(t) && N++;
1274
- S.inDegree = N;
1273
+ e.has(t) && I++;
1274
+ S.inDegree = I;
1275
1275
  }
1276
- for (const [S, N] of e)
1277
- N.inDegree === 0 && R.push(S);
1276
+ for (const [S, I] of e)
1277
+ I.inDegree === 0 && R.push(S);
1278
1278
  for (; R.length > 0; ) {
1279
1279
  const S = R.shift();
1280
1280
  A.push(S);
1281
- for (const [N, t] of e)
1282
- t.dependencies.has(S) && (t.inDegree--, t.inDegree === 0 && R.push(N));
1281
+ for (const [I, t] of e)
1282
+ t.dependencies.has(S) && (t.inDegree--, t.inDegree === 0 && R.push(I));
1283
1283
  }
1284
1284
  if (A.length < e.size) {
1285
1285
  const S = this.detectCycle();
@@ -1313,14 +1313,14 @@ class J {
1313
1313
  const S = this.dependencyGraph.get(E);
1314
1314
  if (!S)
1315
1315
  return A.pop(), R.delete(E), null;
1316
- for (const N of S.dependencies)
1317
- if (e.has(N)) {
1318
- if (R.has(N)) {
1319
- const t = A.indexOf(N);
1320
- return [...A.slice(t), N];
1316
+ for (const I of S.dependencies)
1317
+ if (e.has(I)) {
1318
+ if (R.has(I)) {
1319
+ const t = A.indexOf(I);
1320
+ return [...A.slice(t), I];
1321
1321
  }
1322
1322
  } else {
1323
- const t = this.dfs(N, e, R, A);
1323
+ const t = this.dfs(I, e, R, A);
1324
1324
  if (t)
1325
1325
  return t;
1326
1326
  }
@@ -1336,9 +1336,9 @@ class J {
1336
1336
  const e = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Set(), A = (S) => {
1337
1337
  if (R.has(S)) return;
1338
1338
  R.add(S);
1339
- const N = this.dependencyGraph.get(S);
1340
- if (N)
1341
- for (const t of N.dependencies)
1339
+ const I = this.dependencyGraph.get(S);
1340
+ if (I)
1341
+ for (const t of I.dependencies)
1342
1342
  e.add(t), A(t);
1343
1343
  };
1344
1344
  return A(E), e;
@@ -1354,16 +1354,16 @@ class J {
1354
1354
  if (R.type === "calculated" && R.calculatedSql) {
1355
1355
  const A = this.extractDependencies(R.calculatedSql);
1356
1356
  for (const S of A) {
1357
- const N = S.cubeName || E.name, t = this.cubes.get(N);
1357
+ const I = S.cubeName || E.name, t = this.cubes.get(I);
1358
1358
  if (!t)
1359
1359
  throw new Error(
1360
- `Calculated measure '${E.name}.${e}' references unknown cube '${N}'`
1360
+ `Calculated measure '${E.name}.${e}' references unknown cube '${I}'`
1361
1361
  );
1362
1362
  if (!t.measures[S.fieldName])
1363
1363
  throw new Error(
1364
1364
  `Calculated measure '${E.name}.${e}' references unknown measure '${S.measureName}'`
1365
1365
  );
1366
- if (N === E.name && S.fieldName === e)
1366
+ if (I === E.name && S.fieldName === e)
1367
1367
  throw new Error(
1368
1368
  `Calculated measure '${E.name}.${e}' cannot reference itself`
1369
1369
  );
@@ -1394,47 +1394,47 @@ class J {
1394
1394
  }
1395
1395
  }
1396
1396
  function he(T, E) {
1397
- const { cube: e, allCubes: R, resolvedMeasures: A } = E, S = zE(T), N = /* @__PURE__ */ new Map();
1398
- for (const s of S) {
1399
- const { originalRef: r, cubeName: _, fieldName: D } = s, o = _ || e.name;
1397
+ const { cube: e, allCubes: R, resolvedMeasures: A } = E, S = zE(T), I = /* @__PURE__ */ new Map();
1398
+ for (const C of S) {
1399
+ const { originalRef: L, cubeName: n, fieldName: i } = C, o = n || e.name;
1400
1400
  if (!R.get(o))
1401
1401
  throw new Error(
1402
- `Cannot substitute {${r}}: cube '${o}' not found`
1402
+ `Cannot substitute {${L}}: cube '${o}' not found`
1403
1403
  );
1404
- const P = `${o}.${D}`, l = A.get(P);
1404
+ const P = `${o}.${i}`, l = A.get(P);
1405
1405
  if (!l)
1406
1406
  throw new Error(
1407
- `Cannot substitute {${r}}: measure '${P}' not resolved yet. Ensure measures are resolved in dependency order.`
1407
+ `Cannot substitute {${L}}: measure '${P}' not resolved yet. Ensure measures are resolved in dependency order.`
1408
1408
  );
1409
- const M = l(), G = L`${M}`;
1410
- N.set(r, G);
1409
+ const M = l(), G = r`${M}`;
1410
+ I.set(L, G);
1411
1411
  }
1412
- const t = [], C = [];
1412
+ const t = [], s = [];
1413
1413
  let O = 0;
1414
- for (const s of S) {
1415
- const r = `{${s.originalRef}}`, _ = T.indexOf(r, O);
1416
- if (_ >= 0) {
1417
- t.push(T.substring(O, _));
1418
- const D = N.get(s.originalRef);
1419
- D && C.push(D), O = _ + r.length;
1414
+ for (const C of S) {
1415
+ const L = `{${C.originalRef}}`, n = T.indexOf(L, O);
1416
+ if (n >= 0) {
1417
+ t.push(T.substring(O, n));
1418
+ const i = I.get(C.originalRef);
1419
+ i && s.push(i), O = n + L.length;
1420
1420
  }
1421
1421
  }
1422
- if (t.push(T.substring(O)), C.length === 0)
1423
- return L.raw(T);
1424
- const I = [];
1425
- for (let s = 0; s < t.length; s++)
1426
- t[s] && I.push(new f(t[s])), s < C.length && I.push(C[s]);
1427
- return L.join(I, L.raw(""));
1422
+ if (t.push(T.substring(O)), s.length === 0)
1423
+ return r.raw(T);
1424
+ const N = [];
1425
+ for (let C = 0; C < t.length; C++)
1426
+ t[C] && N.push(new f(t[C])), C < s.length && N.push(s[C]);
1427
+ return r.join(N, r.raw(""));
1428
1428
  }
1429
1429
  function zE(T) {
1430
1430
  const E = /\{([^}]+)\}/g, e = T.matchAll(E), R = [];
1431
1431
  for (const A of e) {
1432
1432
  const S = A[1].trim();
1433
1433
  if (S.includes(".")) {
1434
- const [N, t] = S.split(".").map((C) => C.trim());
1434
+ const [I, t] = S.split(".").map((s) => s.trim());
1435
1435
  R.push({
1436
1436
  originalRef: S,
1437
- cubeName: N,
1437
+ cubeName: I,
1438
1438
  fieldName: t
1439
1439
  });
1440
1440
  } else
@@ -1449,21 +1449,21 @@ function zE(T) {
1449
1449
  function Ve(T) {
1450
1450
  const E = [];
1451
1451
  let e = 0;
1452
- for (let N = 0; N < T.length; N++)
1453
- if (T[N] === "{")
1452
+ for (let I = 0; I < T.length; I++)
1453
+ if (T[I] === "{")
1454
1454
  e++;
1455
- else if (T[N] === "}" && (e--, e < 0)) {
1456
- E.push(`Unmatched closing brace at position ${N}`);
1455
+ else if (T[I] === "}" && (e--, e < 0)) {
1456
+ E.push(`Unmatched closing brace at position ${I}`);
1457
1457
  break;
1458
1458
  }
1459
1459
  e > 0 && E.push("Unmatched opening brace in template"), /\{\s*\}/.test(T) && E.push("Empty member reference {} found in template"), /\{[^}]*\{/.test(T) && E.push("Nested braces are not allowed in member references");
1460
1460
  const S = zE(T);
1461
- for (const N of S) {
1462
- const t = N.cubeName ? `${N.cubeName}.${N.fieldName}` : N.fieldName;
1461
+ for (const I of S) {
1462
+ const t = I.cubeName ? `${I.cubeName}.${I.fieldName}` : I.fieldName;
1463
1463
  /^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(t) || E.push(
1464
- `Invalid member reference {${N.originalRef}}: must start with letter or underscore, and contain only letters, numbers, underscores, and dots`
1464
+ `Invalid member reference {${I.originalRef}}: must start with letter or underscore, and contain only letters, numbers, underscores, and dots`
1465
1465
  ), t.split(".").length > 2 && E.push(
1466
- `Invalid member reference {${N.originalRef}}: only one dot allowed (Cube.measure format)`
1466
+ `Invalid member reference {${I.originalRef}}: only one dot allowed (Cube.measure format)`
1467
1467
  );
1468
1468
  }
1469
1469
  return {
@@ -1474,8 +1474,8 @@ function Ve(T) {
1474
1474
  function uE(T, E) {
1475
1475
  const e = zE(T), R = /* @__PURE__ */ new Set();
1476
1476
  for (const A of e) {
1477
- const N = `${A.cubeName || E}.${A.fieldName}`;
1478
- R.add(N);
1477
+ const I = `${A.cubeName || E}.${A.fieldName}`;
1478
+ R.add(I);
1479
1479
  }
1480
1480
  return Array.from(R);
1481
1481
  }
@@ -1495,44 +1495,44 @@ class We {
1495
1495
  * @returns Map of measure names to SQL builder functions
1496
1496
  */
1497
1497
  buildResolvedMeasures(E, e, R, A) {
1498
- const S = /* @__PURE__ */ new Map(), N = [], t = [], C = new Set(E), O = new J(e);
1499
- for (const I of e.values())
1500
- O.buildGraph(I);
1501
- for (const I of E) {
1502
- const [s, r] = I.split("."), _ = e.get(s);
1503
- if (_ && _.measures && _.measures[r]) {
1504
- const D = _.measures[r];
1505
- J.isCalculatedMeasure(D) ? (t.push(I), uE(D.calculatedSql, s).forEach((P) => C.add(P)), O.getAllDependencies(I).forEach((P) => {
1498
+ const S = /* @__PURE__ */ new Map(), I = [], t = [], s = new Set(E), O = new J(e);
1499
+ for (const N of e.values())
1500
+ O.buildGraph(N);
1501
+ for (const N of E) {
1502
+ const [C, L] = N.split("."), n = e.get(C);
1503
+ if (n && n.measures && n.measures[L]) {
1504
+ const i = n.measures[L];
1505
+ J.isCalculatedMeasure(i) ? (t.push(N), uE(i.calculatedSql, C).forEach((P) => s.add(P)), O.getAllDependencies(N).forEach((P) => {
1506
1506
  const [l, M] = P.split("."), G = e.get(l);
1507
1507
  if (G && G.measures[M]) {
1508
1508
  const m = G.measures[M];
1509
- J.isCalculatedMeasure(m) && uE(m.calculatedSql, l).forEach((b) => C.add(b));
1509
+ J.isCalculatedMeasure(m) && uE(m.calculatedSql, l).forEach((b) => s.add(b));
1510
1510
  }
1511
- })) : N.push(I);
1511
+ })) : I.push(N);
1512
1512
  }
1513
1513
  }
1514
- for (const I of C) {
1515
- const [s, r] = I.split("."), _ = e.get(s);
1516
- if (_ && _.measures && _.measures[r]) {
1517
- const D = _.measures[r];
1518
- J.isCalculatedMeasure(D) ? t.includes(I) || t.push(I) : N.includes(I) || N.push(I);
1514
+ for (const N of s) {
1515
+ const [C, L] = N.split("."), n = e.get(C);
1516
+ if (n && n.measures && n.measures[L]) {
1517
+ const i = n.measures[L];
1518
+ J.isCalculatedMeasure(i) ? t.includes(N) || t.push(N) : I.includes(N) || I.push(N);
1519
1519
  }
1520
1520
  }
1521
- for (const I of N) {
1522
- const [s, r] = I.split("."), _ = e.get(s), D = _.measures[r];
1521
+ for (const N of I) {
1522
+ const [C, L] = N.split("."), n = e.get(C), i = n.measures[L];
1523
1523
  if (A) {
1524
- const o = A(I, D, _);
1525
- S.set(I, () => o);
1524
+ const o = A(N, i, n);
1525
+ S.set(N, () => o);
1526
1526
  } else
1527
- S.set(I, () => this.buildMeasureExpression(D, R));
1527
+ S.set(N, () => this.buildMeasureExpression(i, R));
1528
1528
  }
1529
1529
  if (t.length > 0) {
1530
- const I = O.topologicalSort(t);
1531
- for (const s of I) {
1532
- const [r, _] = s.split("."), D = e.get(r), o = D.measures[_];
1533
- S.set(s, () => this.buildCalculatedMeasure(
1530
+ const N = O.topologicalSort(t);
1531
+ for (const C of N) {
1532
+ const [L, n] = C.split("."), i = e.get(L), o = i.measures[n];
1533
+ S.set(C, () => this.buildCalculatedMeasure(
1534
1534
  o,
1535
- D,
1535
+ i,
1536
1536
  e,
1537
1537
  S,
1538
1538
  R
@@ -1549,37 +1549,37 @@ class We {
1549
1549
  buildSelections(E, e, R) {
1550
1550
  const A = {}, S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1551
1551
  if (e.dimensions)
1552
- for (const N of e.dimensions) {
1553
- const [t, C] = N.split("."), O = S.get(t);
1554
- if (O && O.dimensions && O.dimensions[C]) {
1555
- const I = O.dimensions[C], s = w(I.sql, R);
1556
- A[N] = L`${s}`.as(N);
1552
+ for (const I of e.dimensions) {
1553
+ const [t, s] = I.split("."), O = S.get(t);
1554
+ if (O && O.dimensions && O.dimensions[s]) {
1555
+ const N = O.dimensions[s], C = w(N.sql, R);
1556
+ A[I] = r`${C}`.as(I);
1557
1557
  }
1558
1558
  }
1559
1559
  if (e.measures) {
1560
- const N = this.buildResolvedMeasures(
1560
+ const I = this.buildResolvedMeasures(
1561
1561
  e.measures,
1562
1562
  S,
1563
1563
  R
1564
1564
  );
1565
1565
  for (const t of e.measures) {
1566
- const C = N.get(t);
1567
- if (C) {
1568
- const O = C();
1569
- A[t] = L`${O}`.as(t);
1566
+ const s = I.get(t);
1567
+ if (s) {
1568
+ const O = s();
1569
+ A[t] = r`${O}`.as(t);
1570
1570
  }
1571
1571
  }
1572
1572
  }
1573
1573
  if (e.timeDimensions)
1574
- for (const N of e.timeDimensions) {
1575
- const [t, C] = N.dimension.split("."), O = S.get(t);
1576
- if (O && O.dimensions && O.dimensions[C]) {
1577
- const I = O.dimensions[C], s = this.buildTimeDimensionExpression(
1578
- I.sql,
1579
- N.granularity,
1574
+ for (const I of e.timeDimensions) {
1575
+ const [t, s] = I.dimension.split("."), O = S.get(t);
1576
+ if (O && O.dimensions && O.dimensions[s]) {
1577
+ const N = O.dimensions[s], C = this.buildTimeDimensionExpression(
1578
+ N.sql,
1579
+ I.granularity,
1580
1580
  R
1581
1581
  );
1582
- A[N.dimension] = L`${s}`.as(N.dimension);
1582
+ A[I.dimension] = r`${C}`.as(I.dimension);
1583
1583
  }
1584
1584
  }
1585
1585
  return Object.keys(A).length === 0 && (A.count = cE()), A;
@@ -1593,8 +1593,8 @@ class We {
1593
1593
  throw new Error(
1594
1594
  `Calculated measure '${e.name}.${E.name}' missing calculatedSql property`
1595
1595
  );
1596
- const N = this.databaseAdapter.preprocessCalculatedTemplate(E.calculatedSql);
1597
- return he(N, {
1596
+ const I = this.databaseAdapter.preprocessCalculatedTemplate(E.calculatedSql);
1597
+ return he(I, {
1598
1598
  cube: e,
1599
1599
  allCubes: R,
1600
1600
  resolvedMeasures: A
@@ -1619,36 +1619,36 @@ class We {
1619
1619
  throw new Error(
1620
1620
  `Calculated measure '${e.name}.${E.name || "unknown"}' missing calculatedSql property`
1621
1621
  );
1622
- const N = /* @__PURE__ */ new Map(), t = uE(E.calculatedSql, e.name);
1623
- for (const C of t) {
1624
- const [O, I] = C.split("."), s = A.get(O);
1625
- if (s && s.measures[I]) {
1626
- const r = s.measures[I];
1627
- if (R.measures.includes(C)) {
1628
- const _ = L`${L.identifier(R.cteAlias)}.${L.identifier(I)}`;
1629
- let D;
1630
- switch (r.type) {
1622
+ const I = /* @__PURE__ */ new Map(), t = uE(E.calculatedSql, e.name);
1623
+ for (const s of t) {
1624
+ const [O, N] = s.split("."), C = A.get(O);
1625
+ if (C && C.measures[N]) {
1626
+ const L = C.measures[N];
1627
+ if (R.measures.includes(s)) {
1628
+ const n = r`${r.identifier(R.cteAlias)}.${r.identifier(N)}`;
1629
+ let i;
1630
+ switch (L.type) {
1631
1631
  case "count":
1632
1632
  case "countDistinct":
1633
1633
  case "sum":
1634
- D = y(_);
1634
+ i = y(n);
1635
1635
  break;
1636
1636
  case "avg":
1637
- D = this.databaseAdapter.buildAvg(_);
1637
+ i = this.databaseAdapter.buildAvg(n);
1638
1638
  break;
1639
1639
  case "min":
1640
- D = SE(_);
1640
+ i = SE(n);
1641
1641
  break;
1642
1642
  case "max":
1643
- D = AE(_);
1643
+ i = AE(n);
1644
1644
  break;
1645
1645
  case "number":
1646
- D = y(_);
1646
+ i = y(n);
1647
1647
  break;
1648
1648
  default:
1649
- D = y(_);
1649
+ i = y(n);
1650
1650
  }
1651
- N.set(C, () => D);
1651
+ I.set(s, () => i);
1652
1652
  }
1653
1653
  }
1654
1654
  }
@@ -1656,7 +1656,7 @@ class We {
1656
1656
  E,
1657
1657
  e,
1658
1658
  A,
1659
- N,
1659
+ I,
1660
1660
  S
1661
1661
  );
1662
1662
  }
@@ -1665,25 +1665,25 @@ class We {
1665
1665
  */
1666
1666
  buildHavingMeasureExpression(E, e, R, A, S) {
1667
1667
  if (S && S.preAggregationCTEs) {
1668
- const N = S.preAggregationCTEs.find((t) => t.cube.name === E);
1669
- if (N && N.measures.includes(`${E}.${e}`))
1668
+ const I = S.preAggregationCTEs.find((t) => t.cube.name === E);
1669
+ if (I && I.measures.includes(`${E}.${e}`))
1670
1670
  if (R.type === "calculated" && R.calculatedSql) {
1671
1671
  const t = S.primaryCube.name === E ? S.primaryCube : S.joinCubes?.find((O) => O.cube.name === E)?.cube;
1672
1672
  if (!t)
1673
1673
  throw new Error(`Cube ${E} not found in query plan`);
1674
- const C = /* @__PURE__ */ new Map([[S.primaryCube.name, S.primaryCube]]);
1674
+ const s = /* @__PURE__ */ new Map([[S.primaryCube.name, S.primaryCube]]);
1675
1675
  if (S.joinCubes)
1676
1676
  for (const O of S.joinCubes)
1677
- C.set(O.cube.name, O.cube);
1677
+ s.set(O.cube.name, O.cube);
1678
1678
  return this.buildCTECalculatedMeasure(
1679
1679
  R,
1680
1680
  t,
1681
- N,
1682
- C,
1681
+ I,
1682
+ s,
1683
1683
  A
1684
1684
  );
1685
1685
  } else {
1686
- const t = L`${L.identifier(N.cteAlias)}.${L.identifier(e)}`;
1686
+ const t = r`${r.identifier(I.cteAlias)}.${r.identifier(e)}`;
1687
1687
  switch (R.type) {
1688
1688
  case "count":
1689
1689
  case "countDistinct":
@@ -1713,11 +1713,15 @@ class We {
1713
1713
  throw new Error(
1714
1714
  `Cannot build calculated measure '${E.name}' directly. Use buildCalculatedMeasure instead.`
1715
1715
  );
1716
+ if (!E.sql)
1717
+ throw new Error(
1718
+ `Measure '${E.name}' of type '${E.type}' is missing required 'sql' property. Only calculated measures can omit 'sql'.`
1719
+ );
1716
1720
  let R = w(E.sql, e);
1717
1721
  if (E.filters && E.filters.length > 0) {
1718
1722
  const A = E.filters.map((S) => {
1719
- const N = S(e);
1720
- return N ? L`(${N})` : void 0;
1723
+ const I = S(e);
1724
+ return I ? r`(${I})` : void 0;
1721
1725
  }).filter(Boolean);
1722
1726
  if (A.length > 0) {
1723
1727
  const S = A.length === 1 ? A[0] : h(...A);
@@ -1750,27 +1754,27 @@ class We {
1750
1754
  */
1751
1755
  buildTimeDimensionExpression(E, e, R) {
1752
1756
  const A = w(E, R);
1753
- return e ? this.databaseAdapter.buildTimeDimension(e, A) : A instanceof H ? A : L`${A}`;
1757
+ return e ? this.databaseAdapter.buildTimeDimension(e, A) : A instanceof H ? A : r`${A}`;
1754
1758
  }
1755
1759
  /**
1756
1760
  * Build WHERE conditions from semantic query filters (dimensions only)
1757
1761
  * Works for both single and multi-cube queries
1758
1762
  */
1759
1763
  buildWhereConditions(E, e, R, A) {
1760
- const S = [], N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1764
+ const S = [], I = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1761
1765
  if (e.filters && e.filters.length > 0)
1762
1766
  for (const t of e.filters) {
1763
- const C = this.processFilter(t, N, R, "where", A);
1764
- C && S.push(C);
1767
+ const s = this.processFilter(t, I, R, "where", A);
1768
+ s && S.push(s);
1765
1769
  }
1766
1770
  if (e.timeDimensions)
1767
1771
  for (const t of e.timeDimensions) {
1768
- const [C, O] = t.dimension.split("."), I = N.get(C);
1769
- if (I && I.dimensions[O] && t.dateRange) {
1770
- if (A?.preAggregationCTEs && A.preAggregationCTEs.some((o) => o.cube.name === C))
1772
+ const [s, O] = t.dimension.split("."), N = I.get(s);
1773
+ if (N && N.dimensions[O] && t.dateRange) {
1774
+ if (A?.preAggregationCTEs && A.preAggregationCTEs.some((o) => o.cube.name === s))
1771
1775
  continue;
1772
- const s = I.dimensions[O], r = w(s.sql, R), _ = this.buildDateRangeCondition(r, t.dateRange);
1773
- _ && S.push(_);
1776
+ const C = N.dimensions[O], L = w(C.sql, R), n = this.buildDateRangeCondition(L, t.dateRange);
1777
+ n && S.push(n);
1774
1778
  }
1775
1779
  }
1776
1780
  return S;
@@ -1780,11 +1784,11 @@ class We {
1780
1784
  * Works for both single and multi-cube queries
1781
1785
  */
1782
1786
  buildHavingConditions(E, e, R, A) {
1783
- const S = [], N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1787
+ const S = [], I = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1784
1788
  if (e.filters && e.filters.length > 0)
1785
1789
  for (const t of e.filters) {
1786
- const C = this.processFilter(t, N, R, "having", A);
1787
- C && S.push(C);
1790
+ const s = this.processFilter(t, I, R, "having", A);
1791
+ s && S.push(s);
1788
1792
  }
1789
1793
  return S;
1790
1794
  }
@@ -1794,31 +1798,43 @@ class We {
1794
1798
  */
1795
1799
  processFilter(E, e, R, A, S) {
1796
1800
  if ("and" in E || "or" in E) {
1797
- const _ = E;
1798
- if (_.and) {
1799
- const D = _.and.map((o) => this.processFilter(o, e, R, A, S)).filter((o) => o !== null);
1800
- return D.length > 0 ? h(...D) : null;
1801
+ const n = E;
1802
+ if (n.and) {
1803
+ const i = n.and.map((o) => this.processFilter(o, e, R, A, S)).filter((o) => o !== null);
1804
+ return i.length > 0 ? h(...i) : null;
1801
1805
  }
1802
- if (_.or) {
1803
- const D = _.or.map((o) => this.processFilter(o, e, R, A, S)).filter((o) => o !== null);
1804
- return D.length > 0 ? PE(...D) : null;
1806
+ if (n.or) {
1807
+ const i = n.or.map((o) => this.processFilter(o, e, R, A, S)).filter((o) => o !== null);
1808
+ return i.length > 0 ? PE(...i) : null;
1805
1809
  }
1806
1810
  }
1807
- const N = E, [t, C] = N.member.split("."), O = e.get(t);
1811
+ const I = E, [t, s] = I.member.split("."), O = e.get(t);
1808
1812
  if (!O) return null;
1809
- const I = O.dimensions[C], s = O.measures[C], r = I || s;
1810
- if (!r) return null;
1811
- if (A === "where" && I) {
1813
+ const N = O.dimensions[s], C = O.measures[s], L = N || C;
1814
+ if (!L) return null;
1815
+ if (A === "where" && N) {
1812
1816
  if (S?.preAggregationCTEs && S.preAggregationCTEs.some((o) => o.cube.name === t))
1813
1817
  return null;
1814
- const _ = w(I.sql, R);
1815
- return this.buildFilterCondition(_, N.operator, N.values, r);
1818
+ const n = w(N.sql, R);
1819
+ return this.buildFilterCondition(
1820
+ n,
1821
+ I.operator,
1822
+ I.values,
1823
+ L,
1824
+ I.dateRange
1825
+ );
1816
1826
  } else {
1817
- if (A === "where" && s)
1827
+ if (A === "where" && C)
1818
1828
  return null;
1819
- if (A === "having" && s) {
1820
- const _ = this.buildHavingMeasureExpression(t, C, s, R, S);
1821
- return this.buildFilterCondition(_, N.operator, N.values, r);
1829
+ if (A === "having" && C) {
1830
+ const n = this.buildHavingMeasureExpression(t, s, C, R, S);
1831
+ return this.buildFilterCondition(
1832
+ n,
1833
+ I.operator,
1834
+ I.values,
1835
+ L,
1836
+ I.dateRange
1837
+ );
1822
1838
  }
1823
1839
  }
1824
1840
  return null;
@@ -1826,97 +1842,108 @@ class We {
1826
1842
  /**
1827
1843
  * Build filter condition using Drizzle operators
1828
1844
  */
1829
- buildFilterCondition(E, e, R, A) {
1845
+ buildFilterCondition(E, e, R, A, S) {
1846
+ if (S !== void 0) {
1847
+ if (e !== "inDateRange")
1848
+ throw new Error(
1849
+ `dateRange can only be used with 'inDateRange' operator, but got '${e}'. Use explicit date values in the 'values' array for other date operators.`
1850
+ );
1851
+ if (A && A.type !== "time")
1852
+ throw new Error(
1853
+ `dateRange can only be used on time dimensions, but field '${A.name || "unknown"}' has type '${A.type}'`
1854
+ );
1855
+ return this.buildDateRangeCondition(E, S);
1856
+ }
1830
1857
  if (!R || R.length === 0)
1831
1858
  return e === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
1832
- const S = R.filter((t) => !(t == null || t === "" || typeof t == "string" && t.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
1833
- if (S.length === 0 && !["set", "notSet"].includes(e))
1859
+ const I = R.filter((s) => !(s == null || s === "" || typeof s == "string" && s.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
1860
+ if (I.length === 0 && !["set", "notSet"].includes(e))
1834
1861
  return e === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
1835
- const N = S[0];
1862
+ const t = I[0];
1836
1863
  switch (e) {
1837
1864
  case "equals":
1838
- if (S.length > 1) {
1865
+ if (I.length > 1) {
1839
1866
  if (A?.type === "time") {
1840
- const t = S.map((C) => this.normalizeDate(C) || C);
1841
- return lE(E, t);
1867
+ const s = I.map((O) => this.normalizeDate(O) || O);
1868
+ return lE(E, s);
1842
1869
  }
1843
- return lE(E, S);
1844
- } else if (S.length === 1) {
1845
- const t = A?.type === "time" && this.normalizeDate(N) || N;
1846
- return k(E, t);
1870
+ return lE(E, I);
1871
+ } else if (I.length === 1) {
1872
+ const s = A?.type === "time" && this.normalizeDate(t) || t;
1873
+ return k(E, s);
1847
1874
  }
1848
1875
  return this.databaseAdapter.buildBooleanLiteral(!1);
1849
1876
  case "notEquals":
1850
- return S.length > 1 ? IT(E, S) : S.length === 1 ? ST(E, N) : null;
1877
+ return I.length > 1 ? IT(E, I) : I.length === 1 ? ST(E, t) : null;
1851
1878
  case "contains":
1852
- return this.databaseAdapter.buildStringCondition(E, "contains", N);
1879
+ return this.databaseAdapter.buildStringCondition(E, "contains", t);
1853
1880
  case "notContains":
1854
- return this.databaseAdapter.buildStringCondition(E, "notContains", N);
1881
+ return this.databaseAdapter.buildStringCondition(E, "notContains", t);
1855
1882
  case "startsWith":
1856
- return this.databaseAdapter.buildStringCondition(E, "startsWith", N);
1883
+ return this.databaseAdapter.buildStringCondition(E, "startsWith", t);
1857
1884
  case "endsWith":
1858
- return this.databaseAdapter.buildStringCondition(E, "endsWith", N);
1885
+ return this.databaseAdapter.buildStringCondition(E, "endsWith", t);
1859
1886
  case "gt":
1860
- return ME(E, N);
1887
+ return ME(E, t);
1861
1888
  case "gte":
1862
- return Q(E, N);
1889
+ return Q(E, t);
1863
1890
  case "lt":
1864
- return UE(E, N);
1891
+ return UE(E, t);
1865
1892
  case "lte":
1866
- return Z(E, N);
1893
+ return Z(E, t);
1867
1894
  case "set":
1868
1895
  return OT(E);
1869
1896
  case "notSet":
1870
1897
  return NT(E);
1871
1898
  case "inDateRange":
1872
- if (S.length >= 2) {
1873
- const t = this.normalizeDate(S[0]);
1874
- let C = this.normalizeDate(S[1]);
1875
- if (t && C) {
1876
- const O = R[1];
1877
- if (typeof O == "string" && /^\d{4}-\d{2}-\d{2}$/.test(O.trim())) {
1878
- const I = typeof C == "number" ? new Date(C * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(C), s = new Date(I);
1879
- s.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? C = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(s.getTime() / 1e3) : s.getTime() : C = s.toISOString();
1899
+ if (I.length >= 2) {
1900
+ const s = this.normalizeDate(I[0]);
1901
+ let O = this.normalizeDate(I[1]);
1902
+ if (s && O) {
1903
+ const N = R[1];
1904
+ if (typeof N == "string" && /^\d{4}-\d{2}-\d{2}$/.test(N.trim())) {
1905
+ const C = typeof O == "number" ? new Date(O * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(O), L = new Date(C);
1906
+ L.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? O = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(L.getTime() / 1e3) : L.getTime() : O = L.toISOString();
1880
1907
  }
1881
1908
  return h(
1882
- Q(E, t),
1883
- Z(E, C)
1909
+ Q(E, s),
1910
+ Z(E, O)
1884
1911
  );
1885
1912
  }
1886
1913
  }
1887
1914
  return null;
1888
1915
  case "beforeDate": {
1889
- const t = this.normalizeDate(N);
1890
- return t ? UE(E, t) : null;
1916
+ const s = this.normalizeDate(t);
1917
+ return s ? UE(E, s) : null;
1891
1918
  }
1892
1919
  case "afterDate": {
1893
- const t = this.normalizeDate(N);
1894
- return t ? ME(E, t) : null;
1920
+ const s = this.normalizeDate(t);
1921
+ return s ? ME(E, s) : null;
1895
1922
  }
1896
1923
  case "between":
1897
- return S.length >= 2 ? h(
1898
- Q(E, S[0]),
1899
- Z(E, S[1])
1924
+ return I.length >= 2 ? h(
1925
+ Q(E, I[0]),
1926
+ Z(E, I[1])
1900
1927
  ) : null;
1901
1928
  case "notBetween":
1902
- return S.length >= 2 ? PE(
1903
- UE(E, S[0]),
1904
- ME(E, S[1])
1929
+ return I.length >= 2 ? PE(
1930
+ UE(E, I[0]),
1931
+ ME(E, I[1])
1905
1932
  ) : null;
1906
1933
  case "in":
1907
- return S.length > 0 ? lE(E, S) : null;
1934
+ return I.length > 0 ? lE(E, I) : null;
1908
1935
  case "notIn":
1909
- return S.length > 0 ? IT(E, S) : null;
1936
+ return I.length > 0 ? IT(E, I) : null;
1910
1937
  case "like":
1911
- return this.databaseAdapter.buildStringCondition(E, "like", N);
1938
+ return this.databaseAdapter.buildStringCondition(E, "like", t);
1912
1939
  case "notLike":
1913
- return this.databaseAdapter.buildStringCondition(E, "notLike", N);
1940
+ return this.databaseAdapter.buildStringCondition(E, "notLike", t);
1914
1941
  case "ilike":
1915
- return this.databaseAdapter.buildStringCondition(E, "ilike", N);
1942
+ return this.databaseAdapter.buildStringCondition(E, "ilike", t);
1916
1943
  case "regex":
1917
- return this.databaseAdapter.buildStringCondition(E, "regex", N);
1944
+ return this.databaseAdapter.buildStringCondition(E, "regex", t);
1918
1945
  case "notRegex":
1919
- return this.databaseAdapter.buildStringCondition(E, "notRegex", N);
1946
+ return this.databaseAdapter.buildStringCondition(E, "notRegex", t);
1920
1947
  case "isEmpty":
1921
1948
  return PE(
1922
1949
  NT(E),
@@ -1941,8 +1968,8 @@ class We {
1941
1968
  let A = this.normalizeDate(e[1]);
1942
1969
  if (!R || !A) return null;
1943
1970
  if (typeof e[1] == "string" && /^\d{4}-\d{2}-\d{2}$/.test(e[1].trim())) {
1944
- const S = typeof A == "number" ? new Date(A * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(A), N = new Date(S);
1945
- N.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? A = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(N.getTime() / 1e3) : N.getTime() : A = N.toISOString();
1971
+ const S = typeof A == "number" ? new Date(A * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(A), I = new Date(S);
1972
+ I.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? A = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(I.getTime() / 1e3) : I.getTime() : A = I.toISOString();
1946
1973
  }
1947
1974
  return h(
1948
1975
  Q(E, R),
@@ -1952,21 +1979,21 @@ class We {
1952
1979
  if (typeof e == "string") {
1953
1980
  const R = this.parseRelativeDateRange(e);
1954
1981
  if (R) {
1955
- let I, s;
1956
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (I = Math.floor(R.start.getTime() / 1e3), s = Math.floor(R.end.getTime() / 1e3)) : (I = R.start.getTime(), s = R.end.getTime()) : (I = R.start.toISOString(), s = R.end.toISOString()), h(
1957
- Q(E, I),
1958
- Z(E, s)
1982
+ let N, C;
1983
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (N = Math.floor(R.start.getTime() / 1e3), C = Math.floor(R.end.getTime() / 1e3)) : (N = R.start.getTime(), C = R.end.getTime()) : (N = R.start.toISOString(), C = R.end.toISOString()), h(
1984
+ Q(E, N),
1985
+ Z(E, C)
1959
1986
  );
1960
1987
  }
1961
1988
  const A = this.normalizeDate(e);
1962
1989
  if (!A) return null;
1963
- const S = typeof A == "number" ? new Date(A * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(A), N = new Date(S);
1964
- N.setUTCHours(0, 0, 0, 0);
1990
+ const S = typeof A == "number" ? new Date(A * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(A), I = new Date(S);
1991
+ I.setUTCHours(0, 0, 0, 0);
1965
1992
  const t = new Date(S);
1966
1993
  t.setUTCHours(23, 59, 59, 999);
1967
- let C, O;
1968
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (C = Math.floor(N.getTime() / 1e3), O = Math.floor(t.getTime() / 1e3)) : (C = N.getTime(), O = t.getTime()) : (C = N.toISOString(), O = t.toISOString()), h(
1969
- Q(E, C),
1994
+ let s, O;
1995
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (s = Math.floor(I.getTime() / 1e3), O = Math.floor(t.getTime() / 1e3)) : (s = I.getTime(), O = t.getTime()) : (s = I.toISOString(), O = t.toISOString()), h(
1996
+ Q(E, s),
1970
1997
  Z(E, O)
1971
1998
  );
1972
1999
  }
@@ -1977,75 +2004,82 @@ class We {
1977
2004
  * Handles all 14 DATE_RANGE_OPTIONS from the client
1978
2005
  */
1979
2006
  parseRelativeDateRange(E) {
1980
- const e = /* @__PURE__ */ new Date(), R = E.toLowerCase().trim(), A = e.getUTCFullYear(), S = e.getUTCMonth(), N = e.getUTCDate(), t = e.getUTCDay();
2007
+ const e = /* @__PURE__ */ new Date(), R = E.toLowerCase().trim(), A = e.getUTCFullYear(), S = e.getUTCMonth(), I = e.getUTCDate(), t = e.getUTCDay();
1981
2008
  if (R === "today") {
1982
- const s = new Date(e);
1983
- s.setUTCHours(0, 0, 0, 0);
1984
- const r = new Date(e);
1985
- return r.setUTCHours(23, 59, 59, 999), { start: s, end: r };
2009
+ const L = new Date(e);
2010
+ L.setUTCHours(0, 0, 0, 0);
2011
+ const n = new Date(e);
2012
+ return n.setUTCHours(23, 59, 59, 999), { start: L, end: n };
1986
2013
  }
1987
2014
  if (R === "yesterday") {
1988
- const s = new Date(e);
1989
- s.setUTCDate(N - 1), s.setUTCHours(0, 0, 0, 0);
1990
- const r = new Date(e);
1991
- return r.setUTCDate(N - 1), r.setUTCHours(23, 59, 59, 999), { start: s, end: r };
2015
+ const L = new Date(e);
2016
+ L.setUTCDate(I - 1), L.setUTCHours(0, 0, 0, 0);
2017
+ const n = new Date(e);
2018
+ return n.setUTCDate(I - 1), n.setUTCHours(23, 59, 59, 999), { start: L, end: n };
1992
2019
  }
1993
2020
  if (R === "this week") {
1994
- const s = t === 0 ? -6 : 1 - t, r = new Date(e);
1995
- r.setUTCDate(N + s), r.setUTCHours(0, 0, 0, 0);
1996
- const _ = new Date(r);
1997
- return _.setUTCDate(r.getUTCDate() + 6), _.setUTCHours(23, 59, 59, 999), { start: r, end: _ };
2021
+ const L = t === 0 ? -6 : 1 - t, n = new Date(e);
2022
+ n.setUTCDate(I + L), n.setUTCHours(0, 0, 0, 0);
2023
+ const i = new Date(n);
2024
+ return i.setUTCDate(n.getUTCDate() + 6), i.setUTCHours(23, 59, 59, 999), { start: n, end: i };
1998
2025
  }
1999
2026
  if (R === "this month") {
2000
- const s = new Date(Date.UTC(A, S, 1, 0, 0, 0, 0)), r = new Date(Date.UTC(A, S + 1, 0, 23, 59, 59, 999));
2001
- return { start: s, end: r };
2027
+ const L = new Date(Date.UTC(A, S, 1, 0, 0, 0, 0)), n = new Date(Date.UTC(A, S + 1, 0, 23, 59, 59, 999));
2028
+ return { start: L, end: n };
2002
2029
  }
2003
2030
  if (R === "this quarter") {
2004
- const s = Math.floor(S / 3), r = new Date(Date.UTC(A, s * 3, 1, 0, 0, 0, 0)), _ = new Date(Date.UTC(A, s * 3 + 3, 0, 23, 59, 59, 999));
2005
- return { start: r, end: _ };
2031
+ const L = Math.floor(S / 3), n = new Date(Date.UTC(A, L * 3, 1, 0, 0, 0, 0)), i = new Date(Date.UTC(A, L * 3 + 3, 0, 23, 59, 59, 999));
2032
+ return { start: n, end: i };
2006
2033
  }
2007
2034
  if (R === "this year") {
2008
- const s = new Date(Date.UTC(A, 0, 1, 0, 0, 0, 0)), r = new Date(Date.UTC(A, 11, 31, 23, 59, 59, 999));
2009
- return { start: s, end: r };
2035
+ const L = new Date(Date.UTC(A, 0, 1, 0, 0, 0, 0)), n = new Date(Date.UTC(A, 11, 31, 23, 59, 59, 999));
2036
+ return { start: L, end: n };
2010
2037
  }
2011
- const C = R.match(/^last\s+(\d+)\s+days?$/);
2012
- if (C) {
2013
- const s = parseInt(C[1], 10), r = new Date(e);
2014
- r.setUTCDate(N - s + 1), r.setUTCHours(0, 0, 0, 0);
2015
- const _ = new Date(e);
2016
- return _.setUTCHours(23, 59, 59, 999), { start: r, end: _ };
2038
+ const s = R.match(/^last\s+(\d+)\s+days?$/);
2039
+ if (s) {
2040
+ const L = parseInt(s[1], 10), n = new Date(e);
2041
+ n.setUTCDate(I - L + 1), n.setUTCHours(0, 0, 0, 0);
2042
+ const i = new Date(e);
2043
+ return i.setUTCHours(23, 59, 59, 999), { start: n, end: i };
2044
+ }
2045
+ const O = R.match(/^last\s+(\d+)\s+weeks?$/);
2046
+ if (O) {
2047
+ const n = parseInt(O[1], 10) * 7, i = new Date(e);
2048
+ i.setUTCDate(I - n + 1), i.setUTCHours(0, 0, 0, 0);
2049
+ const o = new Date(e);
2050
+ return o.setUTCHours(23, 59, 59, 999), { start: i, end: o };
2017
2051
  }
2018
2052
  if (R === "last week") {
2019
- const s = t === 0 ? -13 : -6 - t, r = new Date(e);
2020
- r.setUTCDate(N + s), r.setUTCHours(0, 0, 0, 0);
2021
- const _ = new Date(r);
2022
- return _.setUTCDate(r.getUTCDate() + 6), _.setUTCHours(23, 59, 59, 999), { start: r, end: _ };
2053
+ const L = t === 0 ? -13 : -6 - t, n = new Date(e);
2054
+ n.setUTCDate(I + L), n.setUTCHours(0, 0, 0, 0);
2055
+ const i = new Date(n);
2056
+ return i.setUTCDate(n.getUTCDate() + 6), i.setUTCHours(23, 59, 59, 999), { start: n, end: i };
2023
2057
  }
2024
2058
  if (R === "last month") {
2025
- const s = new Date(Date.UTC(A, S - 1, 1, 0, 0, 0, 0)), r = new Date(Date.UTC(A, S, 0, 23, 59, 59, 999));
2026
- return { start: s, end: r };
2059
+ const L = new Date(Date.UTC(A, S - 1, 1, 0, 0, 0, 0)), n = new Date(Date.UTC(A, S, 0, 23, 59, 59, 999));
2060
+ return { start: L, end: n };
2027
2061
  }
2028
2062
  if (R === "last quarter") {
2029
- const s = Math.floor(S / 3), r = s === 0 ? 3 : s - 1, _ = s === 0 ? A - 1 : A, D = new Date(Date.UTC(_, r * 3, 1, 0, 0, 0, 0)), o = new Date(Date.UTC(_, r * 3 + 3, 0, 23, 59, 59, 999));
2030
- return { start: D, end: o };
2063
+ const L = Math.floor(S / 3), n = L === 0 ? 3 : L - 1, i = L === 0 ? A - 1 : A, o = new Date(Date.UTC(i, n * 3, 1, 0, 0, 0, 0)), u = new Date(Date.UTC(i, n * 3 + 3, 0, 23, 59, 59, 999));
2064
+ return { start: o, end: u };
2031
2065
  }
2032
2066
  if (R === "last year") {
2033
- const s = new Date(Date.UTC(A - 1, 0, 1, 0, 0, 0, 0)), r = new Date(Date.UTC(A - 1, 11, 31, 23, 59, 59, 999));
2034
- return { start: s, end: r };
2067
+ const L = new Date(Date.UTC(A - 1, 0, 1, 0, 0, 0, 0)), n = new Date(Date.UTC(A - 1, 11, 31, 23, 59, 59, 999));
2068
+ return { start: L, end: n };
2035
2069
  }
2036
2070
  if (R === "last 12 months") {
2037
- const s = new Date(Date.UTC(A, S - 11, 1, 0, 0, 0, 0)), r = new Date(e);
2038
- return r.setUTCHours(23, 59, 59, 999), { start: s, end: r };
2071
+ const L = new Date(Date.UTC(A, S - 11, 1, 0, 0, 0, 0)), n = new Date(e);
2072
+ return n.setUTCHours(23, 59, 59, 999), { start: L, end: n };
2039
2073
  }
2040
- const O = R.match(/^last\s+(\d+)\s+months?$/);
2041
- if (O) {
2042
- const s = parseInt(O[1], 10), r = new Date(Date.UTC(A, S - s + 1, 1, 0, 0, 0, 0)), _ = new Date(e);
2043
- return _.setUTCHours(23, 59, 59, 999), { start: r, end: _ };
2074
+ const N = R.match(/^last\s+(\d+)\s+months?$/);
2075
+ if (N) {
2076
+ const L = parseInt(N[1], 10), n = new Date(Date.UTC(A, S - L + 1, 1, 0, 0, 0, 0)), i = new Date(e);
2077
+ return i.setUTCHours(23, 59, 59, 999), { start: n, end: i };
2044
2078
  }
2045
- const I = R.match(/^last\s+(\d+)\s+years?$/);
2046
- if (I) {
2047
- const s = parseInt(I[1], 10), r = new Date(Date.UTC(A - s, 0, 1, 0, 0, 0, 0)), _ = new Date(e);
2048
- return _.setUTCHours(23, 59, 59, 999), { start: r, end: _ };
2079
+ const C = R.match(/^last\s+(\d+)\s+years?$/);
2080
+ if (C) {
2081
+ const L = parseInt(C[1], 10), n = new Date(Date.UTC(A - L, 0, 1, 0, 0, 0, 0)), i = new Date(e);
2082
+ return i.setUTCHours(23, 59, 59, 999), { start: n, end: i };
2049
2083
  }
2050
2084
  return null;
2051
2085
  }
@@ -2083,46 +2117,46 @@ class We {
2083
2117
  return [];
2084
2118
  const t = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
2085
2119
  if (e.dimensions)
2086
- for (const C of e.dimensions) {
2087
- const [O, I] = C.split("."), s = t.get(O);
2088
- if (s && s.dimensions && s.dimensions[I])
2089
- if (A?.preAggregationCTEs?.some((_) => _.cube.name === O)) {
2090
- const _ = A.preAggregationCTEs.find((o) => o.cube.name === O), D = _.joinKeys.find((o) => o.targetColumn === I);
2091
- if (D && D.sourceColumnObj)
2092
- S.push(D.sourceColumnObj);
2120
+ for (const s of e.dimensions) {
2121
+ const [O, N] = s.split("."), C = t.get(O);
2122
+ if (C && C.dimensions && C.dimensions[N])
2123
+ if (A?.preAggregationCTEs?.some((n) => n.cube.name === O)) {
2124
+ const n = A.preAggregationCTEs.find((o) => o.cube.name === O), i = n.joinKeys.find((o) => o.targetColumn === N);
2125
+ if (i && i.sourceColumnObj)
2126
+ S.push(i.sourceColumnObj);
2093
2127
  else {
2094
- const o = L`${L.identifier(_.cteAlias)}.${L.identifier(I)}`;
2128
+ const o = r`${r.identifier(n.cteAlias)}.${r.identifier(N)}`;
2095
2129
  S.push(o);
2096
2130
  }
2097
2131
  } else {
2098
- const _ = s.dimensions[I], D = w(_.sql, R);
2099
- S.push(D);
2132
+ const n = C.dimensions[N], i = w(n.sql, R);
2133
+ S.push(i);
2100
2134
  }
2101
2135
  }
2102
2136
  if (e.timeDimensions)
2103
- for (const C of e.timeDimensions) {
2104
- const [O, I] = C.dimension.split("."), s = t.get(O);
2105
- if (s && s.dimensions && s.dimensions[I])
2106
- if (A?.preAggregationCTEs?.some((_) => _.cube.name === O)) {
2107
- const _ = A.preAggregationCTEs.find((o) => o.cube.name === O), D = _.joinKeys.find((o) => o.targetColumn === I);
2108
- if (D && D.sourceColumnObj) {
2137
+ for (const s of e.timeDimensions) {
2138
+ const [O, N] = s.dimension.split("."), C = t.get(O);
2139
+ if (C && C.dimensions && C.dimensions[N])
2140
+ if (A?.preAggregationCTEs?.some((n) => n.cube.name === O)) {
2141
+ const n = A.preAggregationCTEs.find((o) => o.cube.name === O), i = n.joinKeys.find((o) => o.targetColumn === N);
2142
+ if (i && i.sourceColumnObj) {
2109
2143
  const o = this.buildTimeDimensionExpression(
2110
- D.sourceColumnObj,
2111
- C.granularity,
2144
+ i.sourceColumnObj,
2145
+ s.granularity,
2112
2146
  R
2113
2147
  );
2114
2148
  S.push(o);
2115
2149
  } else {
2116
- const o = L`${L.identifier(_.cteAlias)}.${L.identifier(I)}`;
2150
+ const o = r`${r.identifier(n.cteAlias)}.${r.identifier(N)}`;
2117
2151
  S.push(o);
2118
2152
  }
2119
2153
  } else {
2120
- const _ = s.dimensions[I], D = this.buildTimeDimensionExpression(
2121
- _.sql,
2122
- C.granularity,
2154
+ const n = C.dimensions[N], i = this.buildTimeDimensionExpression(
2155
+ n.sql,
2156
+ s.granularity,
2123
2157
  R
2124
2158
  );
2125
- S.push(D);
2159
+ S.push(i);
2126
2160
  }
2127
2161
  }
2128
2162
  return S;
@@ -2137,18 +2171,18 @@ class We {
2137
2171
  ...E.timeDimensions?.map((S) => S.dimension) || []
2138
2172
  ];
2139
2173
  if (E.order && Object.keys(E.order).length > 0)
2140
- for (const [S, N] of Object.entries(E.order)) {
2174
+ for (const [S, I] of Object.entries(E.order)) {
2141
2175
  if (!A.includes(S))
2142
2176
  throw new Error(`Cannot order by '${S}': field is not selected in the query`);
2143
- const t = N === "desc" ? Ue(L.identifier(S)) : tT(L.identifier(S));
2177
+ const t = I === "desc" ? Ue(r.identifier(S)) : tT(r.identifier(S));
2144
2178
  R.push(t);
2145
2179
  }
2146
2180
  if (E.timeDimensions && E.timeDimensions.length > 0) {
2147
- const S = new Set(Object.keys(E.order || {})), N = [...E.timeDimensions].sort(
2148
- (t, C) => t.dimension.localeCompare(C.dimension)
2181
+ const S = new Set(Object.keys(E.order || {})), I = [...E.timeDimensions].sort(
2182
+ (t, s) => t.dimension.localeCompare(s.dimension)
2149
2183
  );
2150
- for (const t of N)
2151
- S.has(t.dimension) || R.push(tT(L.identifier(t.dimension)));
2184
+ for (const t of I)
2185
+ S.has(t.dimension) || R.push(tT(r.identifier(t.dimension)));
2152
2186
  }
2153
2187
  return R;
2154
2188
  }
@@ -2160,9 +2194,9 @@ class We {
2160
2194
  const R = [], A = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
2161
2195
  if (e.measures && R.push(...e.measures), e.dimensions)
2162
2196
  for (const S of e.dimensions) {
2163
- const [N, t] = S.split("."), C = A.get(N);
2164
- if (C) {
2165
- const O = C.dimensions[t];
2197
+ const [I, t] = S.split("."), s = A.get(I);
2198
+ if (s) {
2199
+ const O = s.dimensions[t];
2166
2200
  O && O.type === "number" && R.push(S);
2167
2201
  }
2168
2202
  }
@@ -2263,9 +2297,9 @@ class be {
2263
2297
  const A = this.analyzeCubeUsage(e), S = Array.from(A);
2264
2298
  if (S.length === 0)
2265
2299
  throw new Error("No cubes found in query");
2266
- const N = this.choosePrimaryCube(S, e, E), t = E.get(N);
2300
+ const I = this.choosePrimaryCube(S, e, E), t = E.get(I);
2267
2301
  if (!t)
2268
- throw new Error(`Primary cube '${N}' not found`);
2302
+ throw new Error(`Primary cube '${I}' not found`);
2269
2303
  if (S.length === 1)
2270
2304
  return {
2271
2305
  primaryCube: t,
@@ -2278,10 +2312,10 @@ class be {
2278
2312
  groupByFields: []
2279
2313
  // Will be built by QueryBuilder
2280
2314
  };
2281
- const C = this.buildJoinPlan(E, t, S, R), O = this.planPreAggregationCTEs(E, t, C, e);
2315
+ const s = this.buildJoinPlan(E, t, S, R), O = this.planPreAggregationCTEs(E, t, s, e);
2282
2316
  return {
2283
2317
  primaryCube: t,
2284
- joinCubes: C,
2318
+ joinCubes: s,
2285
2319
  selections: {},
2286
2320
  // Will be built by QueryBuilder
2287
2321
  whereConditions: [],
@@ -2297,21 +2331,21 @@ class be {
2297
2331
  */
2298
2332
  choosePrimaryCube(E, e, R) {
2299
2333
  if (e.dimensions && e.dimensions.length > 0 && R) {
2300
- const A = e.dimensions.map((N) => N.split(".")[0]), S = /* @__PURE__ */ new Map();
2301
- for (const N of A)
2302
- S.set(N, (S.get(N) || 0) + 1);
2334
+ const A = e.dimensions.map((I) => I.split(".")[0]), S = /* @__PURE__ */ new Map();
2335
+ for (const I of A)
2336
+ S.set(I, (S.get(I) || 0) + 1);
2303
2337
  if (S.size > 0) {
2304
- const N = Math.max(...S.values()), t = [...S.entries()].filter(([, C]) => C === N).map(([C]) => C).sort();
2305
- for (const C of t)
2306
- if (this.canReachAllCubes(C, E, R))
2307
- return C;
2338
+ const I = Math.max(...S.values()), t = [...S.entries()].filter(([, s]) => s === I).map(([s]) => s).sort();
2339
+ for (const s of t)
2340
+ if (this.canReachAllCubes(s, E, R))
2341
+ return s;
2308
2342
  }
2309
2343
  }
2310
2344
  if (R) {
2311
2345
  const A = /* @__PURE__ */ new Map();
2312
2346
  for (const S of E)
2313
2347
  if (this.canReachAllCubes(S, E, R)) {
2314
- const N = R.get(S), t = N?.joins ? Object.keys(N.joins).length : 0;
2348
+ const I = R.get(S), t = I?.joins ? Object.keys(I.joins).length : 0;
2315
2349
  A.set(S, t);
2316
2350
  }
2317
2351
  if (A.size > 0) {
@@ -2327,8 +2361,8 @@ class be {
2327
2361
  canReachAllCubes(E, e, R) {
2328
2362
  const A = e.filter((S) => S !== E);
2329
2363
  for (const S of A) {
2330
- const N = this.findJoinPath(R, E, S, /* @__PURE__ */ new Set());
2331
- if (!N || N.length === 0)
2364
+ const I = this.findJoinPath(R, E, S, /* @__PURE__ */ new Set());
2365
+ if (!I || I.length === 0)
2332
2366
  return !1;
2333
2367
  }
2334
2368
  return !0;
@@ -2338,52 +2372,52 @@ class be {
2338
2372
  * Supports both direct joins and transitive joins through intermediate cubes
2339
2373
  */
2340
2374
  buildJoinPlan(E, e, R, A) {
2341
- const S = [], N = /* @__PURE__ */ new Set([e.name]), t = R.filter((C) => C !== e.name);
2342
- for (const C of t) {
2343
- if (N.has(C))
2375
+ const S = [], I = /* @__PURE__ */ new Set([e.name]), t = R.filter((s) => s !== e.name);
2376
+ for (const s of t) {
2377
+ if (I.has(s))
2344
2378
  continue;
2345
- const O = this.findJoinPath(E, e.name, C, N);
2379
+ const O = this.findJoinPath(E, e.name, s, I);
2346
2380
  if (!O || O.length === 0)
2347
- throw new Error(`No join path found from '${e.name}' to '${C}'`);
2348
- for (const { toCube: I, joinDef: s } of O) {
2349
- if (N.has(I))
2381
+ throw new Error(`No join path found from '${e.name}' to '${s}'`);
2382
+ for (const { toCube: N, joinDef: C } of O) {
2383
+ if (I.has(N))
2350
2384
  continue;
2351
- const r = E.get(I);
2352
- if (!r)
2353
- throw new Error(`Cube '${I}' not found`);
2354
- if (s.relationship === "belongsToMany" && s.through) {
2355
- const _ = fe(s, A.securityContext);
2385
+ const L = E.get(N);
2386
+ if (!L)
2387
+ throw new Error(`Cube '${N}' not found`);
2388
+ if (C.relationship === "belongsToMany" && C.through) {
2389
+ const n = fe(C, A.securityContext);
2356
2390
  S.push({
2357
- cube: r,
2358
- alias: `${I.toLowerCase()}_cube`,
2359
- joinType: _.junctionJoins[1].joinType,
2391
+ cube: L,
2392
+ alias: `${N.toLowerCase()}_cube`,
2393
+ joinType: n.junctionJoins[1].joinType,
2360
2394
  // Use the target join type
2361
- joinCondition: _.junctionJoins[1].condition,
2395
+ joinCondition: n.junctionJoins[1].condition,
2362
2396
  // Target join condition
2363
2397
  junctionTable: {
2364
- table: s.through.table,
2365
- alias: `junction_${I.toLowerCase()}`,
2366
- joinType: _.junctionJoins[0].joinType,
2367
- joinCondition: _.junctionJoins[0].condition,
2368
- securitySql: s.through.securitySql
2398
+ table: C.through.table,
2399
+ alias: `junction_${N.toLowerCase()}`,
2400
+ joinType: n.junctionJoins[0].joinType,
2401
+ joinCondition: n.junctionJoins[0].condition,
2402
+ securitySql: C.through.securitySql
2369
2403
  }
2370
2404
  });
2371
2405
  } else {
2372
- const _ = this.buildJoinCondition(
2373
- s,
2406
+ const n = this.buildJoinCondition(
2407
+ C,
2374
2408
  null,
2375
2409
  // No source alias needed - use the actual column
2376
2410
  null
2377
2411
  // No target alias needed - use the actual column
2378
- ), D = zT(s.relationship, s.sqlJoinType);
2412
+ ), i = zT(C.relationship, C.sqlJoinType);
2379
2413
  S.push({
2380
- cube: r,
2381
- alias: `${I.toLowerCase()}_cube`,
2382
- joinType: D,
2383
- joinCondition: _
2414
+ cube: L,
2415
+ alias: `${N.toLowerCase()}_cube`,
2416
+ joinType: i,
2417
+ joinCondition: n
2384
2418
  });
2385
2419
  }
2386
- N.add(I);
2420
+ I.add(N);
2387
2421
  }
2388
2422
  }
2389
2423
  return S;
@@ -2394,8 +2428,8 @@ class be {
2394
2428
  buildJoinCondition(E, e, R) {
2395
2429
  const A = [];
2396
2430
  for (const S of E.on) {
2397
- const N = e ? L`${L.identifier(e)}.${L.identifier(S.source.name)}` : S.source, t = R ? L`${L.identifier(R)}.${L.identifier(S.target.name)}` : S.target, C = S.as || k;
2398
- A.push(C(N, t));
2431
+ const I = e ? r`${r.identifier(e)}.${r.identifier(S.source.name)}` : S.source, t = R ? r`${r.identifier(R)}.${r.identifier(S.target.name)}` : S.target, s = S.as || k;
2432
+ A.push(s(I, t));
2399
2433
  }
2400
2434
  return h(...A);
2401
2435
  }
@@ -2408,22 +2442,22 @@ class be {
2408
2442
  return [];
2409
2443
  const S = [
2410
2444
  { cube: e, path: [] }
2411
- ], N = /* @__PURE__ */ new Set([e, ...A]);
2445
+ ], I = /* @__PURE__ */ new Set([e, ...A]);
2412
2446
  for (; S.length > 0; ) {
2413
- const { cube: t, path: C } = S.shift(), O = E.get(t);
2447
+ const { cube: t, path: s } = S.shift(), O = E.get(t);
2414
2448
  if (O?.joins)
2415
- for (const [, I] of Object.entries(O.joins)) {
2416
- const r = LT(I.targetCube).name;
2417
- if (N.has(r))
2449
+ for (const [, N] of Object.entries(O.joins)) {
2450
+ const L = LT(N.targetCube).name;
2451
+ if (I.has(L))
2418
2452
  continue;
2419
- const _ = [...C, {
2453
+ const n = [...s, {
2420
2454
  fromCube: t,
2421
- toCube: r,
2422
- joinDef: I
2455
+ toCube: L,
2456
+ joinDef: N
2423
2457
  }];
2424
- if (r === R)
2425
- return _;
2426
- N.add(r), S.push({ cube: r, path: _ });
2458
+ if (L === R)
2459
+ return n;
2460
+ I.add(L), S.push({ cube: L, path: n });
2427
2461
  }
2428
2462
  }
2429
2463
  return null;
@@ -2437,30 +2471,30 @@ class be {
2437
2471
  const S = [];
2438
2472
  if (!A.measures || A.measures.length === 0)
2439
2473
  return S;
2440
- for (const N of R) {
2441
- const t = this.findHasManyJoinDef(e, N.cube.name);
2474
+ for (const I of R) {
2475
+ const t = this.findHasManyJoinDef(e, I.cube.name);
2442
2476
  if (!t)
2443
2477
  continue;
2444
- const C = A.measures ? A.measures.filter(
2445
- (_) => _.startsWith(N.cube.name + ".")
2446
- ) : [], O = this.extractMeasuresFromFilters(A, N.cube.name), I = [.../* @__PURE__ */ new Set([...C, ...O])];
2447
- if (I.length === 0)
2478
+ const s = A.measures ? A.measures.filter(
2479
+ (n) => n.startsWith(I.cube.name + ".")
2480
+ ) : [], O = this.extractMeasuresFromFilters(A, I.cube.name), N = [.../* @__PURE__ */ new Set([...s, ...O])];
2481
+ if (N.length === 0)
2448
2482
  continue;
2449
- const s = this.expandCalculatedMeasureDependencies(
2450
- N.cube,
2451
- I
2452
- ), r = t.on.map((_) => ({
2453
- sourceColumn: _.source.name,
2454
- targetColumn: _.target.name,
2455
- sourceColumnObj: _.source,
2456
- targetColumnObj: _.target
2483
+ const C = this.expandCalculatedMeasureDependencies(
2484
+ I.cube,
2485
+ N
2486
+ ), L = t.on.map((n) => ({
2487
+ sourceColumn: n.source.name,
2488
+ targetColumn: n.target.name,
2489
+ sourceColumnObj: n.source,
2490
+ targetColumnObj: n.target
2457
2491
  }));
2458
2492
  S.push({
2459
- cube: N.cube,
2460
- alias: N.alias,
2461
- cteAlias: `${N.cube.name.toLowerCase()}_agg`,
2462
- joinKeys: r,
2463
- measures: s
2493
+ cube: I.cube,
2494
+ alias: I.alias,
2495
+ cteAlias: `${I.cube.name.toLowerCase()}_agg`,
2496
+ joinKeys: L,
2497
+ measures: C
2464
2498
  });
2465
2499
  }
2466
2500
  return S;
@@ -2475,13 +2509,13 @@ class be {
2475
2509
  if (R.has(S))
2476
2510
  continue;
2477
2511
  R.add(S);
2478
- const [, N] = S.split(".");
2479
- if (!E.measures || !E.measures[N])
2512
+ const [, I] = S.split(".");
2513
+ if (!E.measures || !E.measures[I])
2480
2514
  continue;
2481
- const t = E.measures[N];
2515
+ const t = E.measures[I];
2482
2516
  if (t.type === "calculated" && t.calculatedSql) {
2483
- const C = this.extractDependenciesFromTemplate(t.calculatedSql, E.name);
2484
- for (const O of C)
2517
+ const s = this.extractDependenciesFromTemplate(t.calculatedSql, E.name);
2518
+ for (const O of s)
2485
2519
  R.has(O) || A.push(O);
2486
2520
  }
2487
2521
  }
@@ -2492,8 +2526,8 @@ class be {
2492
2526
  */
2493
2527
  extractDependenciesFromTemplate(E, e) {
2494
2528
  const R = /\{([^}]+)\}/g, A = E.matchAll(R), S = [];
2495
- for (const N of A) {
2496
- const t = N[1].trim();
2529
+ for (const I of A) {
2530
+ const t = I[1].trim();
2497
2531
  t.includes(".") ? S.push(t) : S.push(`${e}.${t}`);
2498
2532
  }
2499
2533
  return S;
@@ -2531,24 +2565,24 @@ class GE {
2531
2565
  db: this.dbExecutor.db,
2532
2566
  schema: this.dbExecutor.schema,
2533
2567
  securityContext: R
2534
- }, N = this.queryPlanner.createQueryPlan(E, e, S), t = this.buildUnifiedQuery(N, e, S), C = this.queryBuilder.collectNumericFields(E, e), O = await this.dbExecutor.execute(t, C), I = Array.isArray(O) ? O.map((r) => {
2535
- const _ = { ...r };
2568
+ }, I = this.queryPlanner.createQueryPlan(E, e, S), t = this.buildUnifiedQuery(I, e, S), s = this.queryBuilder.collectNumericFields(E, e), O = await this.dbExecutor.execute(t, s), N = Array.isArray(O) ? O.map((L) => {
2569
+ const n = { ...L };
2536
2570
  if (e.timeDimensions) {
2537
- for (const D of e.timeDimensions)
2538
- if (D.dimension in _) {
2539
- let o = _[D.dimension];
2571
+ for (const i of e.timeDimensions)
2572
+ if (i.dimension in n) {
2573
+ let o = n[i.dimension];
2540
2574
  if (typeof o == "string" && o.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
2541
2575
  const u = o.replace(" ", "T"), P = !u.endsWith("Z") && !u.includes("+") ? u + "Z" : u;
2542
2576
  o = new Date(P);
2543
2577
  }
2544
- o = this.databaseAdapter.convertTimeDimensionResult(o), _[D.dimension] = o;
2578
+ o = this.databaseAdapter.convertTimeDimensionResult(o), n[i.dimension] = o;
2545
2579
  }
2546
2580
  }
2547
- return _;
2548
- }) : [O], s = this.generateAnnotations(N, e);
2581
+ return n;
2582
+ }) : [O], C = this.generateAnnotations(I, e);
2549
2583
  return {
2550
- data: I,
2551
- annotation: s
2584
+ data: N,
2585
+ annotation: C
2552
2586
  };
2553
2587
  } catch (A) {
2554
2588
  throw new Error(`Query execution failed: ${A instanceof Error ? A.message : "Unknown error"}`);
@@ -2565,73 +2599,73 @@ class GE {
2565
2599
  * Build pre-aggregation CTE for hasMany relationships
2566
2600
  */
2567
2601
  buildPreAggregationCTE(E, e, R, A) {
2568
- const S = E.cube, N = S.sql(R), t = {};
2602
+ const S = E.cube, I = S.sql(R), t = {};
2569
2603
  for (const P of E.joinKeys)
2570
2604
  if (P.targetColumnObj) {
2571
2605
  t[P.targetColumn] = P.targetColumnObj;
2572
2606
  for (const [l, M] of Object.entries(S.dimensions || {}))
2573
- M.sql === P.targetColumnObj && l !== P.targetColumn && (t[l] = L`${P.targetColumnObj}`.as(l));
2607
+ M.sql === P.targetColumnObj && l !== P.targetColumn && (t[l] = r`${P.targetColumnObj}`.as(l));
2574
2608
  }
2575
- const C = S.name, O = /* @__PURE__ */ new Map([[C, S]]), I = this.queryBuilder.buildResolvedMeasures(
2609
+ const s = S.name, O = /* @__PURE__ */ new Map([[s, S]]), N = this.queryBuilder.buildResolvedMeasures(
2576
2610
  E.measures,
2577
2611
  O,
2578
2612
  R
2579
2613
  );
2580
2614
  for (const P of E.measures) {
2581
- const [, l] = P.split("."), M = I.get(P);
2615
+ const [, l] = P.split("."), M = N.get(P);
2582
2616
  if (M) {
2583
2617
  const G = M();
2584
- t[l] = L`${G}`.as(l);
2618
+ t[l] = r`${G}`.as(l);
2585
2619
  }
2586
2620
  }
2587
2621
  if (e.dimensions)
2588
2622
  for (const P of e.dimensions) {
2589
2623
  const [l, M] = P.split(".");
2590
- if (l === C && S.dimensions && S.dimensions[M]) {
2624
+ if (l === s && S.dimensions && S.dimensions[M]) {
2591
2625
  const G = S.dimensions[M], m = this.queryBuilder.buildMeasureExpression({ sql: G.sql, type: "number" }, R);
2592
- t[M] = L`${m}`.as(M);
2626
+ t[M] = r`${m}`.as(M);
2593
2627
  }
2594
2628
  }
2595
2629
  if (e.timeDimensions)
2596
2630
  for (const P of e.timeDimensions) {
2597
2631
  const [l, M] = P.dimension.split(".");
2598
- if (l === C && S.dimensions && S.dimensions[M]) {
2632
+ if (l === s && S.dimensions && S.dimensions[M]) {
2599
2633
  const G = S.dimensions[M], m = this.queryBuilder.buildTimeDimensionExpression(G.sql, P.granularity, R);
2600
- t[M] = L`${m}`.as(M);
2634
+ t[M] = r`${m}`.as(M);
2601
2635
  }
2602
2636
  }
2603
2637
  if (Object.keys(t).length === 0)
2604
2638
  return null;
2605
- let s = R.db.select(t).from(N.from);
2606
- const r = A ? {
2639
+ let C = R.db.select(t).from(I.from);
2640
+ const L = A ? {
2607
2641
  ...A,
2608
2642
  preAggregationCTEs: A.preAggregationCTEs?.filter((P) => P.cube.name !== S.name)
2609
- } : void 0, _ = this.queryBuilder.buildWhereConditions(S, e, R, r), D = [];
2643
+ } : void 0, n = this.queryBuilder.buildWhereConditions(S, e, R, L), i = [];
2610
2644
  if (e.timeDimensions)
2611
2645
  for (const P of e.timeDimensions) {
2612
2646
  const [l, M] = P.dimension.split(".");
2613
- if (l === C && S.dimensions && S.dimensions[M] && P.dateRange) {
2647
+ if (l === s && S.dimensions && S.dimensions[M] && P.dateRange) {
2614
2648
  const G = S.dimensions[M], m = this.queryBuilder.buildMeasureExpression({ sql: G.sql, type: "number" }, R), B = this.queryBuilder.buildDateRangeCondition(m, P.dateRange);
2615
- B && D.push(B);
2649
+ B && i.push(B);
2616
2650
  }
2617
2651
  }
2618
2652
  if (e.filters) {
2619
2653
  for (const P of e.filters)
2620
2654
  if (!("and" in P) && !("or" in P) && "member" in P && "operator" in P) {
2621
2655
  const l = P, [M, G] = l.member.split(".");
2622
- if (M === C && S.dimensions && S.dimensions[G]) {
2656
+ if (M === s && S.dimensions && S.dimensions[G]) {
2623
2657
  const m = S.dimensions[G];
2624
2658
  if (l.operator === "inDateRange") {
2625
2659
  const B = this.queryBuilder.buildMeasureExpression({ sql: m.sql, type: "number" }, R), b = this.queryBuilder.buildDateRangeCondition(B, l.values);
2626
- b && D.push(b);
2660
+ b && i.push(b);
2627
2661
  }
2628
2662
  }
2629
2663
  }
2630
2664
  }
2631
2665
  const o = [];
2632
- if (N.where && o.push(N.where), o.push(..._, ...D), o.length > 0) {
2666
+ if (I.where && o.push(I.where), o.push(...n, ...i), o.length > 0) {
2633
2667
  const P = o.length === 1 ? o[0] : h(...o);
2634
- s = s.where(P);
2668
+ C = C.where(P);
2635
2669
  }
2636
2670
  const u = [];
2637
2671
  for (const P of E.joinKeys)
@@ -2639,7 +2673,7 @@ class GE {
2639
2673
  if (e.dimensions)
2640
2674
  for (const P of e.dimensions) {
2641
2675
  const [l, M] = P.split(".");
2642
- if (l === C && S.dimensions && S.dimensions[M]) {
2676
+ if (l === s && S.dimensions && S.dimensions[M]) {
2643
2677
  const G = S.dimensions[M], m = w(G.sql, R);
2644
2678
  u.push(m);
2645
2679
  }
@@ -2647,25 +2681,25 @@ class GE {
2647
2681
  if (e.timeDimensions)
2648
2682
  for (const P of e.timeDimensions) {
2649
2683
  const [l, M] = P.dimension.split(".");
2650
- if (l === C && S.dimensions && S.dimensions[M]) {
2684
+ if (l === s && S.dimensions && S.dimensions[M]) {
2651
2685
  const G = S.dimensions[M], m = this.queryBuilder.buildTimeDimensionExpression(G.sql, P.granularity, R);
2652
2686
  u.push(m);
2653
2687
  }
2654
2688
  }
2655
- return u.length > 0 && (s = s.groupBy(...u)), R.db.$with(E.cteAlias).as(s);
2689
+ return u.length > 0 && (C = C.groupBy(...u)), R.db.$with(E.cteAlias).as(C);
2656
2690
  }
2657
2691
  // Removed unused getActualJoinTargetColumn method
2658
2692
  /**
2659
2693
  * Build join condition for CTE
2660
2694
  */
2661
2695
  buildCTEJoinCondition(E, e, R) {
2662
- const A = R.preAggregationCTEs?.find((N) => N.cube.name === E.cube.name);
2696
+ const A = R.preAggregationCTEs?.find((I) => I.cube.name === E.cube.name);
2663
2697
  if (!A)
2664
2698
  throw new Error(`CTE info not found for cube ${E.cube.name}`);
2665
2699
  const S = [];
2666
- for (const N of A.joinKeys) {
2667
- const t = N.sourceColumnObj || L.identifier(N.sourceColumn), C = L`${L.identifier(e)}.${L.identifier(N.targetColumn)}`;
2668
- S.push(k(t, C));
2700
+ for (const I of A.joinKeys) {
2701
+ const t = I.sourceColumnObj || r.identifier(I.sourceColumn), s = r`${r.identifier(e)}.${r.identifier(I.targetColumn)}`;
2702
+ S.push(k(t, s));
2669
2703
  }
2670
2704
  return S.length === 1 ? S[0] : h(...S);
2671
2705
  }
@@ -2679,7 +2713,7 @@ class GE {
2679
2713
  const u = this.buildPreAggregationCTE(o, e, R, E);
2680
2714
  u && (A.push(u), S.set(o.cube.name, o.cteAlias));
2681
2715
  }
2682
- const N = E.primaryCube.sql(R), C = { ...this.queryBuilder.buildSelections(
2716
+ const I = E.primaryCube.sql(R), s = { ...this.queryBuilder.buildSelections(
2683
2717
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
2684
2718
  // Single cube
2685
2719
  e,
@@ -2689,7 +2723,7 @@ class GE {
2689
2723
  for (const o of E.preAggregationCTEs) {
2690
2724
  const u = o.cube.name;
2691
2725
  for (const P of o.measures)
2692
- if (C[P]) {
2726
+ if (s[P]) {
2693
2727
  const [, l] = P.split("."), M = this.getCubesFromPlan(E).get(u);
2694
2728
  if (M && M.measures && M.measures[l]) {
2695
2729
  const G = M.measures[l];
@@ -2704,7 +2738,7 @@ class GE {
2704
2738
  R
2705
2739
  );
2706
2740
  } else {
2707
- const B = L`${L.identifier(o.cteAlias)}.${L.identifier(l)}`;
2741
+ const B = r`${r.identifier(o.cteAlias)}.${r.identifier(l)}`;
2708
2742
  switch (G.type) {
2709
2743
  case "count":
2710
2744
  case "countDistinct":
@@ -2727,10 +2761,10 @@ class GE {
2727
2761
  m = y(B);
2728
2762
  }
2729
2763
  }
2730
- C[P] = L`${m}`.as(P);
2764
+ s[P] = r`${m}`.as(P);
2731
2765
  }
2732
2766
  }
2733
- for (const P in C) {
2767
+ for (const P in s) {
2734
2768
  const [l, M] = P.split(".");
2735
2769
  if (l === u) {
2736
2770
  const G = this.getCubesFromPlan(E).get(u), m = G && G.dimensions?.[M], B = P.startsWith(u + ".");
@@ -2740,27 +2774,27 @@ class GE {
2740
2774
  const _E = G.dimensions[M].sql;
2741
2775
  b = o.joinKeys.find((_e) => _e.targetColumnObj === _E);
2742
2776
  }
2743
- b ? C[P] = L`${L.identifier(o.cteAlias)}.${L.identifier(M)}`.as(P) : B && G?.dimensions?.[M] && (C[P] = L`${L.identifier(o.cteAlias)}.${L.identifier(M)}`.as(P));
2777
+ b ? s[P] = r`${r.identifier(o.cteAlias)}.${r.identifier(M)}`.as(P) : B && G?.dimensions?.[M] && (s[P] = r`${r.identifier(o.cteAlias)}.${r.identifier(M)}`.as(P));
2744
2778
  }
2745
2779
  }
2746
2780
  }
2747
2781
  }
2748
2782
  const O = [];
2749
- let I = R.db.select(C).from(N.from);
2750
- if (A.length > 0 && (I = R.db.with(...A).select(C).from(N.from)), N.joins)
2751
- for (const o of N.joins)
2783
+ let N = R.db.select(s).from(I.from);
2784
+ if (A.length > 0 && (N = R.db.with(...A).select(s).from(I.from)), I.joins)
2785
+ for (const o of I.joins)
2752
2786
  switch (o.type || "left") {
2753
2787
  case "left":
2754
- I = I.leftJoin(o.table, o.on);
2788
+ N = N.leftJoin(o.table, o.on);
2755
2789
  break;
2756
2790
  case "inner":
2757
- I = I.innerJoin(o.table, o.on);
2791
+ N = N.innerJoin(o.table, o.on);
2758
2792
  break;
2759
2793
  case "right":
2760
- I = I.rightJoin(o.table, o.on);
2794
+ N = N.rightJoin(o.table, o.on);
2761
2795
  break;
2762
2796
  case "full":
2763
- I = I.fullJoin(o.table, o.on);
2797
+ N = N.fullJoin(o.table, o.on);
2764
2798
  break;
2765
2799
  }
2766
2800
  if (E.joinCubes && E.joinCubes.length > 0)
@@ -2775,16 +2809,16 @@ class GE {
2775
2809
  try {
2776
2810
  switch (M.joinType || "left") {
2777
2811
  case "left":
2778
- I = I.leftJoin(M.table, M.joinCondition);
2812
+ N = N.leftJoin(M.table, M.joinCondition);
2779
2813
  break;
2780
2814
  case "inner":
2781
- I = I.innerJoin(M.table, M.joinCondition);
2815
+ N = N.innerJoin(M.table, M.joinCondition);
2782
2816
  break;
2783
2817
  case "right":
2784
- I = I.rightJoin(M.table, M.joinCondition);
2818
+ N = N.rightJoin(M.table, M.joinCondition);
2785
2819
  break;
2786
2820
  case "full":
2787
- I = I.fullJoin(M.table, M.joinCondition);
2821
+ N = N.fullJoin(M.table, M.joinCondition);
2788
2822
  break;
2789
2823
  }
2790
2824
  G.length > 0 && O.push(...G);
@@ -2792,33 +2826,33 @@ class GE {
2792
2826
  }
2793
2827
  }
2794
2828
  let P, l;
2795
- u ? (P = L`${L.identifier(u)}`, l = this.buildCTEJoinCondition(o, u, E)) : (P = o.cube.sql(R).from, l = o.joinCondition);
2829
+ u ? (P = r`${r.identifier(u)}`, l = this.buildCTEJoinCondition(o, u, E)) : (P = o.cube.sql(R).from, l = o.joinCondition);
2796
2830
  try {
2797
2831
  switch (o.joinType || "left") {
2798
2832
  case "left":
2799
- I = I.leftJoin(P, l);
2833
+ N = N.leftJoin(P, l);
2800
2834
  break;
2801
2835
  case "inner":
2802
- I = I.innerJoin(P, l);
2836
+ N = N.innerJoin(P, l);
2803
2837
  break;
2804
2838
  case "right":
2805
- I = I.rightJoin(P, l);
2839
+ N = N.rightJoin(P, l);
2806
2840
  break;
2807
2841
  case "full":
2808
- I = I.fullJoin(P, l);
2842
+ N = N.fullJoin(P, l);
2809
2843
  break;
2810
2844
  }
2811
2845
  } catch {
2812
2846
  }
2813
2847
  }
2814
- if (N.where && O.push(N.where), E.joinCubes && E.joinCubes.length > 0)
2848
+ if (I.where && O.push(I.where), E.joinCubes && E.joinCubes.length > 0)
2815
2849
  for (const o of E.joinCubes) {
2816
2850
  if (S.get(o.cube.name))
2817
2851
  continue;
2818
2852
  const P = o.cube.sql(R);
2819
2853
  P.where && O.push(P.where);
2820
2854
  }
2821
- const s = this.queryBuilder.buildWhereConditions(
2855
+ const C = this.queryBuilder.buildWhereConditions(
2822
2856
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
2823
2857
  // Single cube
2824
2858
  e,
@@ -2826,11 +2860,11 @@ class GE {
2826
2860
  E
2827
2861
  // Pass the queryPlan to handle CTE scenarios
2828
2862
  );
2829
- if (s.length > 0 && O.push(...s), O.length > 0) {
2863
+ if (C.length > 0 && O.push(...C), O.length > 0) {
2830
2864
  const o = O.length === 1 ? O[0] : h(...O);
2831
- I = I.where(o);
2865
+ N = N.where(o);
2832
2866
  }
2833
- const r = this.queryBuilder.buildGroupByFields(
2867
+ const L = this.queryBuilder.buildGroupByFields(
2834
2868
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
2835
2869
  // Single cube
2836
2870
  e,
@@ -2838,8 +2872,8 @@ class GE {
2838
2872
  E
2839
2873
  // Pass the queryPlan to handle CTE scenarios
2840
2874
  );
2841
- r.length > 0 && (I = I.groupBy(...r));
2842
- const _ = this.queryBuilder.buildHavingConditions(
2875
+ L.length > 0 && (N = N.groupBy(...L));
2876
+ const n = this.queryBuilder.buildHavingConditions(
2843
2877
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
2844
2878
  // Single cube
2845
2879
  e,
@@ -2847,12 +2881,12 @@ class GE {
2847
2881
  E
2848
2882
  // Pass the queryPlan to handle CTE scenarios
2849
2883
  );
2850
- if (_.length > 0) {
2851
- const o = _.length === 1 ? _[0] : h(..._);
2852
- I = I.having(o);
2884
+ if (n.length > 0) {
2885
+ const o = n.length === 1 ? n[0] : h(...n);
2886
+ N = N.having(o);
2853
2887
  }
2854
- const D = this.queryBuilder.buildOrderBy(e);
2855
- return D.length > 0 && (I = I.orderBy(...D)), I = this.queryBuilder.applyLimitAndOffset(I, e), I;
2888
+ const i = this.queryBuilder.buildOrderBy(e);
2889
+ return i.length > 0 && (N = N.orderBy(...i)), N = this.queryBuilder.applyLimitAndOffset(N, e), N;
2856
2890
  }
2857
2891
  /**
2858
2892
  * Convert query plan to cube map for QueryBuilder methods
@@ -2895,40 +2929,40 @@ class GE {
2895
2929
  * Generate annotations for UI metadata - unified approach
2896
2930
  */
2897
2931
  generateAnnotations(E, e) {
2898
- const R = {}, A = {}, S = {}, N = [E.primaryCube];
2899
- if (E.joinCubes && E.joinCubes.length > 0 && N.push(...E.joinCubes.map((t) => t.cube)), e.measures)
2932
+ const R = {}, A = {}, S = {}, I = [E.primaryCube];
2933
+ if (E.joinCubes && E.joinCubes.length > 0 && I.push(...E.joinCubes.map((t) => t.cube)), e.measures)
2900
2934
  for (const t of e.measures) {
2901
- const [C, O] = t.split("."), I = N.find((s) => s.name === C);
2902
- if (I && I.measures[O]) {
2903
- const s = I.measures[O];
2935
+ const [s, O] = t.split("."), N = I.find((C) => C.name === s);
2936
+ if (N && N.measures[O]) {
2937
+ const C = N.measures[O];
2904
2938
  R[t] = {
2905
- title: s.title || O,
2906
- shortTitle: s.title || O,
2907
- type: s.type
2939
+ title: C.title || O,
2940
+ shortTitle: C.title || O,
2941
+ type: C.type
2908
2942
  };
2909
2943
  }
2910
2944
  }
2911
2945
  if (e.dimensions)
2912
2946
  for (const t of e.dimensions) {
2913
- const [C, O] = t.split("."), I = N.find((s) => s.name === C);
2914
- if (I && I.dimensions[O]) {
2915
- const s = I.dimensions[O];
2947
+ const [s, O] = t.split("."), N = I.find((C) => C.name === s);
2948
+ if (N && N.dimensions[O]) {
2949
+ const C = N.dimensions[O];
2916
2950
  A[t] = {
2917
- title: s.title || O,
2918
- shortTitle: s.title || O,
2919
- type: s.type
2951
+ title: C.title || O,
2952
+ shortTitle: C.title || O,
2953
+ type: C.type
2920
2954
  };
2921
2955
  }
2922
2956
  }
2923
2957
  if (e.timeDimensions)
2924
2958
  for (const t of e.timeDimensions) {
2925
- const [C, O] = t.dimension.split("."), I = N.find((s) => s.name === C);
2926
- if (I && I.dimensions && I.dimensions[O]) {
2927
- const s = I.dimensions[O];
2959
+ const [s, O] = t.dimension.split("."), N = I.find((C) => C.name === s);
2960
+ if (N && N.dimensions && N.dimensions[O]) {
2961
+ const C = N.dimensions[O];
2928
2962
  S[t.dimension] = {
2929
- title: s.title || O,
2930
- shortTitle: s.title || O,
2931
- type: s.type,
2963
+ title: C.title || O,
2964
+ shortTitle: C.title || O,
2965
+ type: C.type,
2932
2966
  granularity: t.granularity
2933
2967
  };
2934
2968
  }
@@ -2941,13 +2975,13 @@ class GE {
2941
2975
  };
2942
2976
  }
2943
2977
  }
2944
- const n = (T) => T.flatMap(Xe), Xe = (T) => IE(Ke(T)).map(ye), ye = (T) => T.replace(/ +/g, " ").trim(), Ke = (T) => ({
2978
+ const _ = (T) => T.flatMap(Xe), Xe = (T) => IE(ge(T)).map(ye), ye = (T) => T.replace(/ +/g, " ").trim(), ge = (T) => ({
2945
2979
  type: "mandatory_block",
2946
2980
  items: ET(T, 0)[0]
2947
2981
  }), ET = (T, E, e) => {
2948
2982
  const R = [];
2949
2983
  for (; T[E]; ) {
2950
- const [A, S] = ge(T, E);
2984
+ const [A, S] = Ke(T, E);
2951
2985
  if (R.push(A), E = S, T[E] === "|")
2952
2986
  E++;
2953
2987
  else if (T[E] === "}" || T[E] === "]") {
@@ -2962,7 +2996,7 @@ const n = (T) => T.flatMap(Xe), Xe = (T) => IE(Ke(T)).map(ye), ye = (T) => T.rep
2962
2996
  throw new Error(`Unexpected "${T[E]}"`);
2963
2997
  }
2964
2998
  return [R, E];
2965
- }, ge = (T, E) => {
2999
+ }, Ke = (T, E) => {
2966
3000
  const e = [];
2967
3001
  for (; ; ) {
2968
3002
  const [R, A] = $e(T, E);
@@ -3006,23 +3040,23 @@ const n = (T) => T.flatMap(Xe), Xe = (T) => IE(Ke(T)).map(ye), ye = (T) => T.rep
3006
3040
  e.push(R + A);
3007
3041
  return e;
3008
3042
  };
3009
- var a;
3043
+ var D;
3010
3044
  (function(T) {
3011
3045
  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_KEYWORD_PHRASE = "RESERVED_KEYWORD_PHRASE", T.RESERVED_DATA_TYPE_PHRASE = "RESERVED_DATA_TYPE_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";
3012
- })(a = a || (a = {}));
3046
+ })(D = D || (D = {}));
3013
3047
  const Ee = (T) => ({
3014
- type: a.EOF,
3048
+ type: D.EOF,
3015
3049
  raw: "«EOF»",
3016
3050
  text: "«EOF»",
3017
3051
  start: T
3018
3052
  }), z = Ee(1 / 0), q = (T) => (E) => E.type === T.type && E.text === T.text, x = {
3019
- ARRAY: q({ text: "ARRAY", type: a.RESERVED_DATA_TYPE }),
3020
- BY: q({ text: "BY", type: a.RESERVED_KEYWORD }),
3021
- SET: q({ text: "SET", type: a.RESERVED_CLAUSE }),
3022
- STRUCT: q({ text: "STRUCT", type: a.RESERVED_DATA_TYPE }),
3023
- WINDOW: q({ text: "WINDOW", type: a.RESERVED_CLAUSE }),
3024
- VALUES: q({ text: "VALUES", type: a.RESERVED_CLAUSE })
3025
- }, Te = (T) => T === a.RESERVED_DATA_TYPE || T === a.RESERVED_KEYWORD || T === a.RESERVED_FUNCTION_NAME || T === a.RESERVED_KEYWORD_PHRASE || T === a.RESERVED_DATA_TYPE_PHRASE || T === a.RESERVED_CLAUSE || T === a.RESERVED_SELECT || T === a.RESERVED_SET_OPERATION || T === a.RESERVED_JOIN || T === a.ARRAY_KEYWORD || T === a.CASE || T === a.END || T === a.WHEN || T === a.ELSE || T === a.THEN || T === a.LIMIT || T === a.BETWEEN || T === a.AND || T === a.OR || T === a.XOR, ve = (T) => T === a.AND || T === a.OR || T === a.XOR, Qe = [
3053
+ ARRAY: q({ text: "ARRAY", type: D.RESERVED_DATA_TYPE }),
3054
+ BY: q({ text: "BY", type: D.RESERVED_KEYWORD }),
3055
+ SET: q({ text: "SET", type: D.RESERVED_CLAUSE }),
3056
+ STRUCT: q({ text: "STRUCT", type: D.RESERVED_DATA_TYPE }),
3057
+ WINDOW: q({ text: "WINDOW", type: D.RESERVED_CLAUSE }),
3058
+ VALUES: q({ text: "VALUES", type: D.RESERVED_CLAUSE })
3059
+ }, Te = (T) => T === D.RESERVED_DATA_TYPE || T === D.RESERVED_KEYWORD || T === D.RESERVED_FUNCTION_NAME || T === D.RESERVED_KEYWORD_PHRASE || T === D.RESERVED_DATA_TYPE_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, ve = (T) => T === D.AND || T === D.OR || T === D.XOR, Qe = [
3026
3060
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/aead_encryption_functions
3027
3061
  "KEYS.NEW_KEYSET",
3028
3062
  "KEYS.ADD_KEY_FROM_RAW_BYTES",
@@ -3699,7 +3733,7 @@ const Ee = (T) => ({
3699
3733
  "STRUCT",
3700
3734
  "TIME",
3701
3735
  "TIMEZONE"
3702
- ], je = n(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), ke = n([
3736
+ ], je = _(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), ke = _([
3703
3737
  // Queries: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
3704
3738
  "WITH [RECURSIVE]",
3705
3739
  "FROM",
@@ -3728,9 +3762,9 @@ const Ee = (T) => ({
3728
3762
  "WITH CONNECTION",
3729
3763
  "WITH PARTITION COLUMNS",
3730
3764
  "REMOTE WITH CONNECTION"
3731
- ]), nT = n([
3765
+ ]), nT = _([
3732
3766
  "CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]"
3733
- ]), mE = n([
3767
+ ]), mE = _([
3734
3768
  // - create:
3735
3769
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
3736
3770
  "CREATE [OR REPLACE] [MATERIALIZED] VIEW [IF NOT EXISTS]",
@@ -3818,15 +3852,15 @@ const Ee = (T) => ({
3818
3852
  "ASSERT",
3819
3853
  // Other, https://cloud.google.com/bigquery/docs/reference/standard-sql/other-statements
3820
3854
  "EXPORT DATA"
3821
- ]), ze = n([
3855
+ ]), ze = _([
3822
3856
  "UNION {ALL | DISTINCT}",
3823
3857
  "EXCEPT DISTINCT",
3824
3858
  "INTERSECT DISTINCT"
3825
- ]), ER = n([
3859
+ ]), ER = _([
3826
3860
  "JOIN",
3827
3861
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
3828
3862
  "{INNER | CROSS} JOIN"
3829
- ]), TR = n([
3863
+ ]), TR = _([
3830
3864
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#tablesample_operator
3831
3865
  "TABLESAMPLE SYSTEM",
3832
3866
  // From DDL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
@@ -3837,7 +3871,7 @@ const Ee = (T) => ({
3837
3871
  "{ROWS | RANGE} BETWEEN",
3838
3872
  // comparison operator
3839
3873
  "IS [NOT] DISTINCT FROM"
3840
- ]), eR = n([]), RR = {
3874
+ ]), eR = _([]), RR = {
3841
3875
  name: "bigquery",
3842
3876
  tokenizerOptions: {
3843
3877
  reservedSelect: je,
@@ -3878,7 +3912,7 @@ function AR(T) {
3878
3912
  }
3879
3913
  function SR(T) {
3880
3914
  let E = z;
3881
- return T.map((e) => e.text === "OFFSET" && E.text === "[" ? (E = e, Object.assign(Object.assign({}, e), { type: a.RESERVED_FUNCTION_NAME })) : (E = e, e));
3915
+ return T.map((e) => e.text === "OFFSET" && E.text === "[" ? (E = e, Object.assign(Object.assign({}, e), { type: D.RESERVED_FUNCTION_NAME })) : (E = e, e));
3882
3916
  }
3883
3917
  function IR(T) {
3884
3918
  var E;
@@ -3886,11 +3920,11 @@ function IR(T) {
3886
3920
  for (let R = 0; R < T.length; R++) {
3887
3921
  const A = T[R];
3888
3922
  if ((x.ARRAY(A) || x.STRUCT(A)) && ((E = T[R + 1]) === null || E === void 0 ? void 0 : E.text) === "<") {
3889
- const S = NR(T, R + 1), N = T.slice(R, S + 1);
3923
+ const S = NR(T, R + 1), I = T.slice(R, S + 1);
3890
3924
  e.push({
3891
- type: a.IDENTIFIER,
3892
- raw: N.map(_T("raw")).join(""),
3893
- text: N.map(_T("text")).join(""),
3925
+ type: D.IDENTIFIER,
3926
+ raw: I.map(_T("raw")).join(""),
3927
+ text: I.map(_T("text")).join(""),
3894
3928
  start: A.start
3895
3929
  }), R = S;
3896
3930
  } else
@@ -3898,7 +3932,7 @@ function IR(T) {
3898
3932
  }
3899
3933
  return e;
3900
3934
  }
3901
- const _T = (T) => (E) => E.type === a.IDENTIFIER || E.type === a.COMMA ? E[T] + " " : E[T];
3935
+ const _T = (T) => (E) => E.type === D.IDENTIFIER || E.type === D.COMMA ? E[T] + " " : E[T];
3902
3936
  function NR(T, E) {
3903
3937
  let e = 0;
3904
3938
  for (let R = E; R < T.length; R++) {
@@ -4671,7 +4705,7 @@ const tR = [
4671
4705
  "VARBINARY",
4672
4706
  "VARCHAR",
4673
4707
  "VARGRAPHIC"
4674
- ], rR = n(["SELECT [ALL | DISTINCT]"]), LR = n([
4708
+ ], rR = _(["SELECT [ALL | DISTINCT]"]), LR = _([
4675
4709
  // queries
4676
4710
  "WITH",
4677
4711
  "FROM",
@@ -4700,9 +4734,9 @@ const tR = [
4700
4734
  "WHEN [NOT] MATCHED [THEN]",
4701
4735
  "UPDATE SET",
4702
4736
  "INSERT"
4703
- ]), iT = n([
4737
+ ]), iT = _([
4704
4738
  "CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]"
4705
- ]), HE = n([
4739
+ ]), HE = _([
4706
4740
  // - create:
4707
4741
  "CREATE [OR REPLACE] VIEW",
4708
4742
  // - update:
@@ -4905,16 +4939,16 @@ const tR = [
4905
4939
  "TRANSFER OWNERSHIP OF",
4906
4940
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}",
4907
4941
  "WHILE"
4908
- ]), nR = n(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), _R = n([
4942
+ ]), nR = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), _R = _([
4909
4943
  "JOIN",
4910
4944
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
4911
4945
  "{INNER | CROSS} JOIN"
4912
- ]), iR = n([
4946
+ ]), iR = _([
4913
4947
  "ON DELETE",
4914
4948
  "ON UPDATE",
4915
4949
  "SET NULL",
4916
4950
  "{ROWS | RANGE} BETWEEN"
4917
- ]), aR = n([]), oR = {
4951
+ ]), aR = _([]), oR = {
4918
4952
  name: "db2",
4919
4953
  tokenizerOptions: {
4920
4954
  reservedSelect: rR,
@@ -5825,7 +5859,7 @@ const tR = [
5825
5859
  "VARCHAR",
5826
5860
  "VARGRAPHIC",
5827
5861
  "XML"
5828
- ], UR = n(["SELECT [ALL | DISTINCT]"]), lR = n([
5862
+ ], UR = _(["SELECT [ALL | DISTINCT]"]), lR = _([
5829
5863
  // queries
5830
5864
  "WITH [RECURSIVE]",
5831
5865
  "INTO",
@@ -5855,7 +5889,7 @@ const tR = [
5855
5889
  "INSERT",
5856
5890
  // Data definition - table
5857
5891
  "FOR SYSTEM NAME"
5858
- ]), aT = n(["CREATE [OR REPLACE] TABLE"]), dE = n([
5892
+ ]), aT = _(["CREATE [OR REPLACE] TABLE"]), dE = _([
5859
5893
  // - create:
5860
5894
  "CREATE [OR REPLACE] [RECURSIVE] VIEW",
5861
5895
  // - update:
@@ -5951,17 +5985,17 @@ const tR = [
5951
5985
  "TAG",
5952
5986
  "TRANSFER OWNERSHIP OF",
5953
5987
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}"
5954
- ]), cR = n(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), uR = n([
5988
+ ]), cR = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), uR = _([
5955
5989
  "JOIN",
5956
5990
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
5957
5991
  "[LEFT | RIGHT] EXCEPTION JOIN",
5958
5992
  "{INNER | CROSS} JOIN"
5959
- ]), GR = n([
5993
+ ]), GR = _([
5960
5994
  "ON DELETE",
5961
5995
  "ON UPDATE",
5962
5996
  "SET NULL",
5963
5997
  "{ROWS | RANGE} BETWEEN"
5964
- ]), mR = n([]), HR = {
5998
+ ]), mR = _([]), HR = {
5965
5999
  name: "db2i",
5966
6000
  tokenizerOptions: {
5967
6001
  reservedSelect: UR,
@@ -6814,7 +6848,7 @@ const tR = [
6814
6848
  "UUID",
6815
6849
  "VARBINARY",
6816
6850
  "VARCHAR"
6817
- ], FR = n(["SELECT [ALL | DISTINCT]"]), YR = n([
6851
+ ], FR = _(["SELECT [ALL | DISTINCT]"]), YR = _([
6818
6852
  // queries
6819
6853
  "WITH [RECURSIVE]",
6820
6854
  "FROM",
@@ -6838,9 +6872,9 @@ const tR = [
6838
6872
  "SET",
6839
6873
  // other:
6840
6874
  "RETURNING"
6841
- ]), oT = n([
6875
+ ]), oT = _([
6842
6876
  "CREATE [OR REPLACE] [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]"
6843
- ]), BE = n([
6877
+ ]), BE = _([
6844
6878
  // TABLE
6845
6879
  // - update:
6846
6880
  "UPDATE",
@@ -6918,11 +6952,11 @@ const tR = [
6918
6952
  "PREPARE",
6919
6953
  "EXECUTE",
6920
6954
  "DEALLOCATE [PREPARE]"
6921
- ]), fR = n([
6955
+ ]), fR = _([
6922
6956
  "UNION [ALL | BY NAME]",
6923
6957
  "EXCEPT [ALL]",
6924
6958
  "INTERSECT [ALL]"
6925
- ]), hR = n([
6959
+ ]), hR = _([
6926
6960
  "JOIN",
6927
6961
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6928
6962
  "{INNER | CROSS} JOIN",
@@ -6931,11 +6965,11 @@ const tR = [
6931
6965
  "POSITIONAL JOIN",
6932
6966
  "ANTI JOIN",
6933
6967
  "SEMI JOIN"
6934
- ]), VR = n([
6968
+ ]), VR = _([
6935
6969
  "{ROWS | RANGE | GROUPS} BETWEEN",
6936
6970
  "SIMILAR TO",
6937
6971
  "IS [NOT] DISTINCT FROM"
6938
- ]), WR = n(["TIMESTAMP WITH TIME ZONE"]), bR = {
6972
+ ]), WR = _(["TIMESTAMP WITH TIME ZONE"]), bR = {
6939
6973
  name: "duckdb",
6940
6974
  tokenizerOptions: {
6941
6975
  reservedSelect: FR,
@@ -7534,7 +7568,7 @@ const tR = [
7534
7568
  "JSONFILE",
7535
7569
  "INPUTFORMAT",
7536
7570
  "OUTPUTFORMAT"
7537
- ], KR = [
7571
+ ], gR = [
7538
7572
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
7539
7573
  "ARRAY",
7540
7574
  "BIGINT",
@@ -7555,7 +7589,7 @@ const tR = [
7555
7589
  "STRUCT",
7556
7590
  "TIMESTAMP",
7557
7591
  "VARCHAR"
7558
- ], gR = n(["SELECT [ALL | DISTINCT]"]), $R = n([
7592
+ ], KR = _(["SELECT [ALL | DISTINCT]"]), $R = _([
7559
7593
  // queries
7560
7594
  "WITH",
7561
7595
  "FROM",
@@ -7589,9 +7623,9 @@ const tR = [
7589
7623
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Loadingfilesintotables
7590
7624
  "LOAD DATA [LOCAL] INPATH",
7591
7625
  "[OVERWRITE] INTO TABLE"
7592
- ]), DT = n([
7626
+ ]), DT = _([
7593
7627
  "CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]"
7594
- ]), pE = n([
7628
+ ]), pE = _([
7595
7629
  // - create:
7596
7630
  "CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]",
7597
7631
  // - update:
@@ -7616,23 +7650,23 @@ const tR = [
7616
7650
  "STORED AS",
7617
7651
  "STORED BY",
7618
7652
  "ROW FORMAT"
7619
- ]), wR = n(["UNION [ALL | DISTINCT]"]), JR = n([
7653
+ ]), wR = _(["UNION [ALL | DISTINCT]"]), JR = _([
7620
7654
  "JOIN",
7621
7655
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
7622
7656
  "{INNER | CROSS} JOIN",
7623
7657
  // non-standard joins
7624
7658
  "LEFT SEMI JOIN"
7625
- ]), xR = n(["{ROWS | RANGE} BETWEEN"]), vR = n([]), QR = {
7659
+ ]), xR = _(["{ROWS | RANGE} BETWEEN"]), vR = _([]), QR = {
7626
7660
  name: "hive",
7627
7661
  tokenizerOptions: {
7628
- reservedSelect: gR,
7662
+ reservedSelect: KR,
7629
7663
  reservedClauses: [...$R, ...DT, ...pE],
7630
7664
  reservedSetOperations: wR,
7631
7665
  reservedJoins: JR,
7632
7666
  reservedKeywordPhrases: xR,
7633
7667
  reservedDataTypePhrases: vR,
7634
7668
  reservedKeywords: yR,
7635
- reservedDataTypes: KR,
7669
+ reservedDataTypes: gR,
7636
7670
  reservedFunctionNames: XR,
7637
7671
  extraParens: ["[]"],
7638
7672
  stringTypes: ['""-bs', "''-bs"],
@@ -7649,9 +7683,9 @@ function nE(T) {
7649
7683
  return T.map((E, e) => {
7650
7684
  const R = T[e + 1] || z;
7651
7685
  if (x.SET(E) && R.text === "(")
7652
- return Object.assign(Object.assign({}, E), { type: a.RESERVED_FUNCTION_NAME });
7686
+ return Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME });
7653
7687
  const A = T[e - 1] || z;
7654
- return x.VALUES(E) && A.text === "=" ? Object.assign(Object.assign({}, E), { type: a.RESERVED_FUNCTION_NAME }) : E;
7688
+ return x.VALUES(E) && A.text === "=" ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E;
7655
7689
  });
7656
7690
  }
7657
7691
  const ZR = [
@@ -8160,7 +8194,7 @@ const ZR = [
8160
8194
  // CASE expression shorthands
8161
8195
  "COALESCE",
8162
8196
  "NULLIF"
8163
- ], kR = n(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), zR = n([
8197
+ ], kR = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), zR = _([
8164
8198
  // queries
8165
8199
  "WITH [RECURSIVE]",
8166
8200
  "FROM",
@@ -8182,9 +8216,9 @@ const ZR = [
8182
8216
  "SET",
8183
8217
  // other
8184
8218
  "RETURNING"
8185
- ]), PT = n([
8219
+ ]), PT = _([
8186
8220
  "CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]"
8187
- ]), FE = n([
8221
+ ]), FE = _([
8188
8222
  // - create:
8189
8223
  "CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]",
8190
8224
  // - update:
@@ -8391,12 +8425,12 @@ const ZR = [
8391
8425
  "XA RECOVER",
8392
8426
  "XA ROLLBACK",
8393
8427
  "XA START"
8394
- ]), EA = n([
8428
+ ]), EA = _([
8395
8429
  "UNION [ALL | DISTINCT]",
8396
8430
  "EXCEPT [ALL | DISTINCT]",
8397
8431
  "INTERSECT [ALL | DISTINCT]",
8398
8432
  "MINUS [ALL | DISTINCT]"
8399
- ]), TA = n([
8433
+ ]), TA = _([
8400
8434
  "JOIN",
8401
8435
  "{LEFT | RIGHT} [OUTER] JOIN",
8402
8436
  "{INNER | CROSS} JOIN",
@@ -8404,12 +8438,12 @@ const ZR = [
8404
8438
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
8405
8439
  // non-standard joins
8406
8440
  "STRAIGHT_JOIN"
8407
- ]), eA = n([
8441
+ ]), eA = _([
8408
8442
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
8409
8443
  "CHARACTER SET",
8410
8444
  "{ROWS | RANGE} BETWEEN",
8411
8445
  "IDENTIFIED BY"
8412
- ]), RA = n([]), AA = {
8446
+ ]), RA = _([]), AA = {
8413
8447
  name: "mariadb",
8414
8448
  tokenizerOptions: {
8415
8449
  reservedSelect: kR,
@@ -9166,7 +9200,7 @@ const ZR = [
9166
9200
  // 'XOR',
9167
9201
  "YEAR",
9168
9202
  "YEARWEEK"
9169
- ], OA = n(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), tA = n([
9203
+ ], OA = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), tA = _([
9170
9204
  // queries
9171
9205
  "WITH [RECURSIVE]",
9172
9206
  "FROM",
@@ -9186,7 +9220,7 @@ const ZR = [
9186
9220
  "ON DUPLICATE KEY UPDATE",
9187
9221
  // - update:
9188
9222
  "SET"
9189
- ]), MT = n(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), YE = n([
9223
+ ]), MT = _(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), YE = _([
9190
9224
  // - create:
9191
9225
  "CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]",
9192
9226
  // - update:
@@ -9367,7 +9401,7 @@ const ZR = [
9367
9401
  "REPEAT",
9368
9402
  "RETURN",
9369
9403
  "WHILE"
9370
- ]), sA = n(["UNION [ALL | DISTINCT]"]), CA = n([
9404
+ ]), sA = _(["UNION [ALL | DISTINCT]"]), CA = _([
9371
9405
  "JOIN",
9372
9406
  "{LEFT | RIGHT} [OUTER] JOIN",
9373
9407
  "{INNER | CROSS} JOIN",
@@ -9375,12 +9409,12 @@ const ZR = [
9375
9409
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
9376
9410
  // non-standard joins
9377
9411
  "STRAIGHT_JOIN"
9378
- ]), rA = n([
9412
+ ]), rA = _([
9379
9413
  "ON {UPDATE | DELETE} [SET NULL]",
9380
9414
  "CHARACTER SET",
9381
9415
  "{ROWS | RANGE} BETWEEN",
9382
9416
  "IDENTIFIED BY"
9383
- ]), LA = n([]), nA = {
9417
+ ]), LA = _([]), nA = {
9384
9418
  name: "mysql",
9385
9419
  tokenizerOptions: {
9386
9420
  reservedSelect: OA,
@@ -9998,7 +10032,7 @@ const ZR = [
9998
10032
  // 'XOR',
9999
10033
  "YEAR",
10000
10034
  "YEARWEEK"
10001
- ], oA = n(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), DA = n([
10035
+ ], oA = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), DA = _([
10002
10036
  // queries
10003
10037
  "WITH [RECURSIVE]",
10004
10038
  "FROM",
@@ -10018,7 +10052,7 @@ const ZR = [
10018
10052
  "ON DUPLICATE KEY UPDATE",
10019
10053
  // - update:
10020
10054
  "SET"
10021
- ]), UT = n(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), fE = n([
10055
+ ]), UT = _(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), fE = _([
10022
10056
  // https://docs.pingcap.com/tidb/stable/sql-statement-create-view
10023
10057
  "CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]",
10024
10058
  // https://docs.pingcap.com/tidb/stable/sql-statement-update
@@ -10133,7 +10167,7 @@ const ZR = [
10133
10167
  "UNLOCK TABLES",
10134
10168
  // https://docs.pingcap.com/tidb/stable/sql-statement-use
10135
10169
  "USE"
10136
- ]), PA = n(["UNION [ALL | DISTINCT]"]), MA = n([
10170
+ ]), PA = _(["UNION [ALL | DISTINCT]"]), MA = _([
10137
10171
  "JOIN",
10138
10172
  "{LEFT | RIGHT} [OUTER] JOIN",
10139
10173
  "{INNER | CROSS} JOIN",
@@ -10141,12 +10175,12 @@ const ZR = [
10141
10175
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
10142
10176
  // non-standard joins
10143
10177
  "STRAIGHT_JOIN"
10144
- ]), UA = n([
10178
+ ]), UA = _([
10145
10179
  "ON {UPDATE | DELETE} [SET NULL]",
10146
10180
  "CHARACTER SET",
10147
10181
  "{ROWS | RANGE} BETWEEN",
10148
10182
  "IDENTIFIED BY"
10149
- ]), lA = n([]), cA = {
10183
+ ]), lA = _([]), cA = {
10150
10184
  name: "tidb",
10151
10185
  tokenizerOptions: {
10152
10186
  reservedSelect: oA,
@@ -10644,7 +10678,7 @@ const ZR = [
10644
10678
  // which it actually doesn't use.
10645
10679
  //
10646
10680
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datatypes.html
10647
- ], HA = n(["SELECT [ALL | DISTINCT]"]), dA = n([
10681
+ ], HA = _(["SELECT [ALL | DISTINCT]"]), dA = _([
10648
10682
  // queries
10649
10683
  "WITH",
10650
10684
  "FROM",
@@ -10671,7 +10705,7 @@ const ZR = [
10671
10705
  "NEST",
10672
10706
  "UNNEST",
10673
10707
  "RETURNING"
10674
- ]), lT = n([
10708
+ ]), lT = _([
10675
10709
  // - update:
10676
10710
  "UPDATE",
10677
10711
  // - delete:
@@ -10711,7 +10745,7 @@ const ZR = [
10711
10745
  "SET CURRENT SCHEMA",
10712
10746
  "SHOW",
10713
10747
  "USE [PRIMARY] KEYS"
10714
- ]), BA = n(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), pA = n(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), FA = n(["{ROWS | RANGE | GROUPS} BETWEEN"]), YA = n([]), fA = {
10748
+ ]), BA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), pA = _(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), FA = _(["{ROWS | RANGE | GROUPS} BETWEEN"]), YA = _([]), fA = {
10715
10749
  name: "n1ql",
10716
10750
  tokenizerOptions: {
10717
10751
  reservedSelect: HA,
@@ -11345,7 +11379,7 @@ const ZR = [
11345
11379
  "PRESENTNNV",
11346
11380
  "PRESENTV",
11347
11381
  "PREVIOUS"
11348
- ], bA = n(["SELECT [ALL | DISTINCT | UNIQUE]"]), XA = n([
11382
+ ], bA = _(["SELECT [ALL | DISTINCT | UNIQUE]"]), XA = _([
11349
11383
  // queries
11350
11384
  "WITH",
11351
11385
  "FROM",
@@ -11369,9 +11403,9 @@ const ZR = [
11369
11403
  "UPDATE SET",
11370
11404
  // other
11371
11405
  "RETURNING"
11372
- ]), cT = n([
11406
+ ]), cT = _([
11373
11407
  "CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE"
11374
- ]), hE = n([
11408
+ ]), hE = _([
11375
11409
  // - create:
11376
11410
  "CREATE [OR REPLACE] [NO FORCE | FORCE] [EDITIONING | EDITIONABLE | EDITIONABLE EDITIONING | NONEDITIONABLE] VIEW",
11377
11411
  "CREATE MATERIALIZED VIEW",
@@ -11399,7 +11433,7 @@ const ZR = [
11399
11433
  "EXCEPTION",
11400
11434
  "LOOP",
11401
11435
  "START WITH"
11402
- ]), yA = n(["UNION [ALL]", "MINUS", "INTERSECT"]), KA = n([
11436
+ ]), yA = _(["UNION [ALL]", "MINUS", "INTERSECT"]), gA = _([
11403
11437
  "JOIN",
11404
11438
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
11405
11439
  "{INNER | CROSS} JOIN",
@@ -11407,18 +11441,18 @@ const ZR = [
11407
11441
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN",
11408
11442
  // non-standard joins
11409
11443
  "{CROSS | OUTER} APPLY"
11410
- ]), gA = n([
11444
+ ]), KA = _([
11411
11445
  "ON {UPDATE | DELETE} [SET NULL]",
11412
11446
  "ON COMMIT",
11413
11447
  "{ROWS | RANGE} BETWEEN"
11414
- ]), $A = n([]), wA = {
11448
+ ]), $A = _([]), wA = {
11415
11449
  name: "plsql",
11416
11450
  tokenizerOptions: {
11417
11451
  reservedSelect: bA,
11418
11452
  reservedClauses: [...XA, ...cT, ...hE],
11419
11453
  reservedSetOperations: yA,
11420
- reservedJoins: KA,
11421
- reservedKeywordPhrases: gA,
11454
+ reservedJoins: gA,
11455
+ reservedKeywordPhrases: KA,
11422
11456
  reservedDataTypePhrases: $A,
11423
11457
  supportsXor: !0,
11424
11458
  reservedKeywords: hA,
@@ -11458,7 +11492,7 @@ const ZR = [
11458
11492
  };
11459
11493
  function JA(T) {
11460
11494
  let E = z;
11461
- return T.map((e) => x.SET(e) && x.BY(E) ? Object.assign(Object.assign({}, e), { type: a.RESERVED_KEYWORD }) : (Te(e.type) && (E = e), e));
11495
+ return T.map((e) => x.SET(e) && x.BY(E) ? Object.assign(Object.assign({}, e), { type: D.RESERVED_KEYWORD }) : (Te(e.type) && (E = e), e));
11462
11496
  }
11463
11497
  const xA = [
11464
11498
  // https://www.postgresql.org/docs/14/functions.html
@@ -12297,7 +12331,7 @@ const xA = [
12297
12331
  "VARCHAR",
12298
12332
  "XML",
12299
12333
  "ZONE"
12300
- ], ZA = n(["SELECT [ALL | DISTINCT]"]), qA = n([
12334
+ ], ZA = _(["SELECT [ALL | DISTINCT]"]), qA = _([
12301
12335
  // queries
12302
12336
  "WITH [RECURSIVE]",
12303
12337
  "FROM",
@@ -12320,9 +12354,9 @@ const xA = [
12320
12354
  "SET",
12321
12355
  // other
12322
12356
  "RETURNING"
12323
- ]), uT = n([
12357
+ ]), uT = _([
12324
12358
  "CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]"
12325
- ]), VE = n([
12359
+ ]), VE = _([
12326
12360
  // - create
12327
12361
  "CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW",
12328
12362
  "CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]",
@@ -12520,17 +12554,17 @@ const xA = [
12520
12554
  "START TRANSACTION",
12521
12555
  "UNLISTEN",
12522
12556
  "VACUUM"
12523
- ]), jA = n([
12557
+ ]), jA = _([
12524
12558
  "UNION [ALL | DISTINCT]",
12525
12559
  "EXCEPT [ALL | DISTINCT]",
12526
12560
  "INTERSECT [ALL | DISTINCT]"
12527
- ]), kA = n([
12561
+ ]), kA = _([
12528
12562
  "JOIN",
12529
12563
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
12530
12564
  "{INNER | CROSS} JOIN",
12531
12565
  "NATURAL [INNER] JOIN",
12532
12566
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
12533
- ]), zA = n([
12567
+ ]), zA = _([
12534
12568
  "PRIMARY KEY",
12535
12569
  "GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY",
12536
12570
  "ON {UPDATE | DELETE} [NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT]",
@@ -12541,7 +12575,7 @@ const xA = [
12541
12575
  "IS [NOT] DISTINCT FROM",
12542
12576
  "NULLS {FIRST | LAST}",
12543
12577
  "WITH ORDINALITY"
12544
- ]), ES = n([
12578
+ ]), ES = _([
12545
12579
  // https://www.postgresql.org/docs/current/datatype-datetime.html
12546
12580
  "[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE"
12547
12581
  ]), TS = {
@@ -13226,7 +13260,7 @@ const xA = [
13226
13260
  "TEXT",
13227
13261
  "VARBYTE",
13228
13262
  "VARCHAR"
13229
- ], SS = n(["SELECT [ALL | DISTINCT]"]), IS = n([
13263
+ ], SS = _(["SELECT [ALL | DISTINCT]"]), IS = _([
13230
13264
  // queries
13231
13265
  "WITH [RECURSIVE]",
13232
13266
  "FROM",
@@ -13244,9 +13278,9 @@ const xA = [
13244
13278
  "VALUES",
13245
13279
  // - update:
13246
13280
  "SET"
13247
- ]), GT = n([
13281
+ ]), GT = _([
13248
13282
  "CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]"
13249
- ]), WE = n([
13283
+ ]), WE = _([
13250
13284
  // - create:
13251
13285
  "CREATE [OR REPLACE | MATERIALIZED] VIEW",
13252
13286
  // - update:
@@ -13337,13 +13371,13 @@ const xA = [
13337
13371
  "START TRANSACTION",
13338
13372
  "UNLOAD",
13339
13373
  "VACUUM"
13340
- ]), NS = n(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), OS = n([
13374
+ ]), NS = _(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), OS = _([
13341
13375
  "JOIN",
13342
13376
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13343
13377
  "{INNER | CROSS} JOIN",
13344
13378
  "NATURAL [INNER] JOIN",
13345
13379
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
13346
- ]), tS = n([
13380
+ ]), tS = _([
13347
13381
  // https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html
13348
13382
  "NULL AS",
13349
13383
  // https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_SCHEMA.html
@@ -13351,7 +13385,7 @@ const xA = [
13351
13385
  "HIVE METASTORE",
13352
13386
  // in window specifications
13353
13387
  "{ROWS | RANGE} BETWEEN"
13354
- ]), sS = n([]), CS = {
13388
+ ]), sS = _([]), CS = {
13355
13389
  name: "redshift",
13356
13390
  tokenizerOptions: {
13357
13391
  reservedSelect: SS,
@@ -14007,7 +14041,7 @@ const xA = [
14007
14041
  // Shorthand functions to use in place of CASE expression
14008
14042
  "COALESCE",
14009
14043
  "NULLIF"
14010
- ], _S = n(["SELECT [ALL | DISTINCT]"]), iS = n([
14044
+ ], _S = _(["SELECT [ALL | DISTINCT]"]), iS = _([
14011
14045
  // queries
14012
14046
  "WITH",
14013
14047
  "FROM",
@@ -14032,7 +14066,7 @@ const xA = [
14032
14066
  // https://spark.apache.org/docs/latest/sql-ref-syntax-dml-load.html
14033
14067
  "LOAD DATA [LOCAL] INPATH",
14034
14068
  "[OVERWRITE] INTO TABLE"
14035
- ]), mT = n(["CREATE [EXTERNAL] TABLE [IF NOT EXISTS]"]), bE = n([
14069
+ ]), mT = _(["CREATE [EXTERNAL] TABLE [IF NOT EXISTS]"]), bE = _([
14036
14070
  // - create:
14037
14071
  "CREATE [OR REPLACE] [GLOBAL TEMPORARY | TEMPORARY] VIEW [IF NOT EXISTS]",
14038
14072
  // - drop table:
@@ -14088,11 +14122,11 @@ const xA = [
14088
14122
  "SHOW TBLPROPERTIES",
14089
14123
  "SHOW VIEWS",
14090
14124
  "UNCACHE TABLE"
14091
- ]), aS = n([
14125
+ ]), aS = _([
14092
14126
  "UNION [ALL | DISTINCT]",
14093
14127
  "EXCEPT [ALL | DISTINCT]",
14094
14128
  "INTERSECT [ALL | DISTINCT]"
14095
- ]), oS = n([
14129
+ ]), oS = _([
14096
14130
  "JOIN",
14097
14131
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14098
14132
  "{INNER | CROSS} JOIN",
@@ -14101,12 +14135,12 @@ const xA = [
14101
14135
  // non-standard-joins
14102
14136
  "[LEFT] {ANTI | SEMI} JOIN",
14103
14137
  "NATURAL [LEFT] {ANTI | SEMI} JOIN"
14104
- ]), DS = n([
14138
+ ]), DS = _([
14105
14139
  "ON DELETE",
14106
14140
  "ON UPDATE",
14107
14141
  "CURRENT ROW",
14108
14142
  "{ROWS | RANGE} BETWEEN"
14109
- ]), PS = n([]), MS = {
14143
+ ]), PS = _([]), MS = {
14110
14144
  name: "spark",
14111
14145
  tokenizerOptions: {
14112
14146
  reservedSelect: _S,
@@ -14140,7 +14174,7 @@ const xA = [
14140
14174
  function US(T) {
14141
14175
  return T.map((E, e) => {
14142
14176
  const R = T[e - 1] || z, A = T[e + 1] || z;
14143
- return x.WINDOW(E) && A.type === a.OPEN_PAREN ? Object.assign(Object.assign({}, E), { type: a.RESERVED_FUNCTION_NAME }) : E.text === "ITEMS" && E.type === a.RESERVED_KEYWORD && !(R.text === "COLLECTION" && A.text === "TERMINATED") ? Object.assign(Object.assign({}, E), { type: a.IDENTIFIER, text: E.raw }) : E;
14177
+ return x.WINDOW(E) && A.type === D.OPEN_PAREN ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E.text === "ITEMS" && E.type === D.RESERVED_KEYWORD && !(R.text === "COLLECTION" && A.text === "TERMINATED") ? Object.assign(Object.assign({}, E), { type: D.IDENTIFIER, text: E.raw }) : E;
14144
14178
  });
14145
14179
  }
14146
14180
  const lS = [
@@ -14441,7 +14475,7 @@ const lS = [
14441
14475
  "TEXT",
14442
14476
  "VARCHAR",
14443
14477
  "VARYING CHARACTER"
14444
- ], GS = n(["SELECT [ALL | DISTINCT]"]), mS = n([
14478
+ ], GS = _(["SELECT [ALL | DISTINCT]"]), mS = _([
14445
14479
  // queries
14446
14480
  "WITH [RECURSIVE]",
14447
14481
  "FROM",
@@ -14462,7 +14496,7 @@ const lS = [
14462
14496
  "SET",
14463
14497
  // other:
14464
14498
  "RETURNING"
14465
- ]), HT = n(["CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]"]), XE = n([
14499
+ ]), HT = _(["CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]"]), XE = _([
14466
14500
  // - create:
14467
14501
  "CREATE [TEMPORARY | TEMP] VIEW [IF NOT EXISTS]",
14468
14502
  // - update:
@@ -14481,17 +14515,17 @@ const lS = [
14481
14515
  "RENAME TO",
14482
14516
  // - set schema
14483
14517
  "SET SCHEMA"
14484
- ]), HS = n(["UNION [ALL]", "EXCEPT", "INTERSECT"]), dS = n([
14518
+ ]), HS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), dS = _([
14485
14519
  "JOIN",
14486
14520
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14487
14521
  "{INNER | CROSS} JOIN",
14488
14522
  "NATURAL [INNER] JOIN",
14489
14523
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
14490
- ]), BS = n([
14524
+ ]), BS = _([
14491
14525
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
14492
14526
  "{ROWS | RANGE | GROUPS} BETWEEN",
14493
14527
  "DO UPDATE"
14494
- ]), pS = n([]), FS = {
14528
+ ]), pS = _([]), FS = {
14495
14529
  name: "sqlite",
14496
14530
  tokenizerOptions: {
14497
14531
  reservedSelect: GS,
@@ -14853,7 +14887,7 @@ const lS = [
14853
14887
  "TIMESTAMP",
14854
14888
  "VARBINARY",
14855
14889
  "VARCHAR"
14856
- ], VS = n(["SELECT [ALL | DISTINCT]"]), WS = n([
14890
+ ], VS = _(["SELECT [ALL | DISTINCT]"]), WS = _([
14857
14891
  // queries
14858
14892
  "WITH [RECURSIVE]",
14859
14893
  "FROM",
@@ -14872,7 +14906,7 @@ const lS = [
14872
14906
  "VALUES",
14873
14907
  // - update:
14874
14908
  "SET"
14875
- ]), dT = n(["CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE"]), yE = n([
14909
+ ]), dT = _(["CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE"]), yE = _([
14876
14910
  // - create:
14877
14911
  "CREATE [RECURSIVE] VIEW",
14878
14912
  // - update:
@@ -14897,20 +14931,20 @@ const lS = [
14897
14931
  "TRUNCATE TABLE",
14898
14932
  // other
14899
14933
  "SET SCHEMA"
14900
- ]), bS = n([
14934
+ ]), bS = _([
14901
14935
  "UNION [ALL | DISTINCT]",
14902
14936
  "EXCEPT [ALL | DISTINCT]",
14903
14937
  "INTERSECT [ALL | DISTINCT]"
14904
- ]), XS = n([
14938
+ ]), XS = _([
14905
14939
  "JOIN",
14906
14940
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14907
14941
  "{INNER | CROSS} JOIN",
14908
14942
  "NATURAL [INNER] JOIN",
14909
14943
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
14910
- ]), yS = n([
14944
+ ]), yS = _([
14911
14945
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
14912
14946
  "{ROWS | RANGE} BETWEEN"
14913
- ]), KS = n([]), gS = {
14947
+ ]), gS = _([]), KS = {
14914
14948
  name: "sql",
14915
14949
  tokenizerOptions: {
14916
14950
  reservedSelect: VS,
@@ -14918,7 +14952,7 @@ const lS = [
14918
14952
  reservedSetOperations: bS,
14919
14953
  reservedJoins: XS,
14920
14954
  reservedKeywordPhrases: yS,
14921
- reservedDataTypePhrases: KS,
14955
+ reservedDataTypePhrases: gS,
14922
14956
  reservedKeywords: fS,
14923
14957
  reservedDataTypes: hS,
14924
14958
  reservedFunctionNames: YS,
@@ -15644,7 +15678,7 @@ const lS = [
15644
15678
  "CODEPOINTS",
15645
15679
  "FUNCTION",
15646
15680
  "JSONPATH"
15647
- ], xS = n(["SELECT [ALL | DISTINCT]"]), vS = n([
15681
+ ], xS = _(["SELECT [ALL | DISTINCT]"]), vS = _([
15648
15682
  // queries
15649
15683
  "WITH [RECURSIVE]",
15650
15684
  "FROM",
@@ -15672,7 +15706,7 @@ const lS = [
15672
15706
  "PATTERN",
15673
15707
  "SUBSET",
15674
15708
  "DEFINE"
15675
- ]), BT = n(["CREATE TABLE [IF NOT EXISTS]"]), KE = n([
15709
+ ]), BT = _(["CREATE TABLE [IF NOT EXISTS]"]), gE = _([
15676
15710
  // - create:
15677
15711
  "CREATE [OR REPLACE] [MATERIALIZED] VIEW",
15678
15712
  // - update:
@@ -15730,25 +15764,25 @@ const lS = [
15730
15764
  "SHOW ROLE GRANTS",
15731
15765
  "SHOW FUNCTIONS",
15732
15766
  "SHOW SESSION"
15733
- ]), QS = n([
15767
+ ]), QS = _([
15734
15768
  "UNION [ALL | DISTINCT]",
15735
15769
  "EXCEPT [ALL | DISTINCT]",
15736
15770
  "INTERSECT [ALL | DISTINCT]"
15737
- ]), ZS = n([
15771
+ ]), ZS = _([
15738
15772
  "JOIN",
15739
15773
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15740
15774
  "{INNER | CROSS} JOIN",
15741
15775
  "NATURAL [INNER] JOIN",
15742
15776
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
15743
- ]), qS = n([
15777
+ ]), qS = _([
15744
15778
  "{ROWS | RANGE | GROUPS} BETWEEN",
15745
15779
  // comparison operator
15746
15780
  "IS [NOT] DISTINCT FROM"
15747
- ]), jS = n([]), kS = {
15781
+ ]), jS = _([]), kS = {
15748
15782
  name: "trino",
15749
15783
  tokenizerOptions: {
15750
15784
  reservedSelect: xS,
15751
- reservedClauses: [...vS, ...BT, ...KE],
15785
+ reservedClauses: [...vS, ...BT, ...gE],
15752
15786
  reservedSetOperations: QS,
15753
15787
  reservedJoins: ZS,
15754
15788
  reservedKeywordPhrases: qS,
@@ -15784,8 +15818,8 @@ const lS = [
15784
15818
  ]
15785
15819
  },
15786
15820
  formatOptions: {
15787
- onelineClauses: [...BT, ...KE],
15788
- tabularOnelineClauses: KE
15821
+ onelineClauses: [...BT, ...gE],
15822
+ tabularOnelineClauses: gE
15789
15823
  }
15790
15824
  }, zS = [
15791
15825
  // https://docs.microsoft.com/en-us/sql/t-sql/functions/functions?view=sql-server-ver15
@@ -16300,7 +16334,7 @@ const lS = [
16300
16334
  "TIMESTAMP",
16301
16335
  "VARBINARY",
16302
16336
  "VARCHAR"
16303
- ], eI = n(["SELECT [ALL | DISTINCT]"]), RI = n([
16337
+ ], eI = _(["SELECT [ALL | DISTINCT]"]), RI = _([
16304
16338
  // queries
16305
16339
  "WITH",
16306
16340
  "INTO",
@@ -16325,7 +16359,7 @@ const lS = [
16325
16359
  "MERGE [INTO]",
16326
16360
  "WHEN [NOT] MATCHED [BY TARGET | BY SOURCE] [THEN]",
16327
16361
  "UPDATE SET"
16328
- ]), pT = n(["CREATE TABLE"]), gE = n([
16362
+ ]), pT = _(["CREATE TABLE"]), KE = _([
16329
16363
  // - create:
16330
16364
  "CREATE [OR ALTER] [MATERIALIZED] VIEW",
16331
16365
  // - update:
@@ -16505,20 +16539,20 @@ const lS = [
16505
16539
  "XACT_ABORT",
16506
16540
  "XML INDEX",
16507
16541
  "XML SCHEMA COLLECTION"
16508
- ]), AI = n(["UNION [ALL]", "EXCEPT", "INTERSECT"]), SI = n([
16542
+ ]), AI = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), SI = _([
16509
16543
  "JOIN",
16510
16544
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
16511
16545
  "{INNER | CROSS} JOIN",
16512
16546
  // non-standard joins
16513
16547
  "{CROSS | OUTER} APPLY"
16514
- ]), II = n([
16548
+ ]), II = _([
16515
16549
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
16516
16550
  "{ROWS | RANGE} BETWEEN"
16517
- ]), NI = n([]), OI = {
16551
+ ]), NI = _([]), OI = {
16518
16552
  name: "transactsql",
16519
16553
  tokenizerOptions: {
16520
16554
  reservedSelect: eI,
16521
- reservedClauses: [...RI, ...pT, ...gE],
16555
+ reservedClauses: [...RI, ...pT, ...KE],
16522
16556
  reservedSetOperations: AI,
16523
16557
  reservedJoins: SI,
16524
16558
  reservedKeywordPhrases: II,
@@ -16555,8 +16589,8 @@ const lS = [
16555
16589
  },
16556
16590
  formatOptions: {
16557
16591
  alwaysDenseOperators: ["::"],
16558
- onelineClauses: [...pT, ...gE],
16559
- tabularOnelineClauses: gE
16592
+ onelineClauses: [...pT, ...KE],
16593
+ tabularOnelineClauses: KE
16560
16594
  }
16561
16595
  }, tI = [
16562
16596
  // List of all keywords taken from:
@@ -17100,7 +17134,7 @@ const lS = [
17100
17134
  "WEEKDAY",
17101
17135
  "WEEKOFYEAR",
17102
17136
  "YEAR"
17103
- ], rI = n(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), LI = n([
17137
+ ], rI = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), LI = _([
17104
17138
  // queries
17105
17139
  "WITH",
17106
17140
  "FROM",
@@ -17122,9 +17156,9 @@ const lS = [
17122
17156
  // Data definition
17123
17157
  "CREATE [OR REPLACE] [TEMPORARY] PROCEDURE [IF NOT EXISTS]",
17124
17158
  "CREATE [OR REPLACE] [EXTERNAL] FUNCTION"
17125
- ]), FT = n([
17159
+ ]), FT = _([
17126
17160
  "CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]"
17127
- ]), $E = n([
17161
+ ]), $E = _([
17128
17162
  // - create:
17129
17163
  "CREATE VIEW",
17130
17164
  // - update:
@@ -17301,25 +17335,25 @@ const lS = [
17301
17335
  "REPEAT",
17302
17336
  "RETURN",
17303
17337
  "WHILE"
17304
- ]), nI = n([
17338
+ ]), nI = _([
17305
17339
  "UNION [ALL | DISTINCT]",
17306
17340
  "EXCEPT",
17307
17341
  "INTERSECT",
17308
17342
  "MINUS"
17309
- ]), _I = n([
17343
+ ]), _I = _([
17310
17344
  "JOIN",
17311
17345
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
17312
17346
  "{INNER | CROSS} JOIN",
17313
17347
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
17314
17348
  // non-standard joins
17315
17349
  "STRAIGHT_JOIN"
17316
- ]), iI = n([
17350
+ ]), iI = _([
17317
17351
  "ON DELETE",
17318
17352
  "ON UPDATE",
17319
17353
  "CHARACTER SET",
17320
17354
  "{ROWS | RANGE} BETWEEN",
17321
17355
  "IDENTIFIED BY"
17322
- ]), aI = n([]), oI = {
17356
+ ]), aI = _([]), oI = {
17323
17357
  name: "singlestoredb",
17324
17358
  tokenizerOptions: {
17325
17359
  reservedSelect: rI,
@@ -18112,7 +18146,7 @@ const lS = [
18112
18146
  "ARRAY",
18113
18147
  "GEOGRAPHY",
18114
18148
  "GEOMETRY"
18115
- ], UI = n(["SELECT [ALL | DISTINCT]"]), lI = n([
18149
+ ], UI = _(["SELECT [ALL | DISTINCT]"]), lI = _([
18116
18150
  // queries
18117
18151
  "WITH [RECURSIVE]",
18118
18152
  "FROM",
@@ -18140,10 +18174,10 @@ const lS = [
18140
18174
  "WHEN MATCHED [AND]",
18141
18175
  "THEN {UPDATE SET | DELETE}",
18142
18176
  "WHEN NOT MATCHED THEN INSERT"
18143
- ]), YT = n([
18177
+ ]), YT = _([
18144
18178
  "CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]",
18145
18179
  "CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]"
18146
- ]), wE = n([
18180
+ ]), wE = _([
18147
18181
  // - create:
18148
18182
  "CREATE [OR REPLACE] [SECURE] [RECURSIVE] VIEW [IF NOT EXISTS]",
18149
18183
  // - update:
@@ -18384,14 +18418,14 @@ const lS = [
18384
18418
  "USE SCHEMA",
18385
18419
  "USE SECONDARY ROLES",
18386
18420
  "USE WAREHOUSE"
18387
- ]), cI = n(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), uI = n([
18421
+ ]), cI = _(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), uI = _([
18388
18422
  "[INNER] JOIN",
18389
18423
  "[NATURAL] {LEFT | RIGHT | FULL} [OUTER] JOIN",
18390
18424
  "{CROSS | NATURAL} JOIN"
18391
- ]), GI = n([
18425
+ ]), GI = _([
18392
18426
  "{ROWS | RANGE} BETWEEN",
18393
18427
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]"
18394
- ]), mI = n([]), HI = {
18428
+ ]), mI = _([]), HI = {
18395
18429
  name: "snowflake",
18396
18430
  tokenizerOptions: {
18397
18431
  reservedSelect: UI,
@@ -18451,7 +18485,7 @@ const lS = [
18451
18485
  singlestoredb: oI,
18452
18486
  snowflake: HI,
18453
18487
  spark: MS,
18454
- sql: gS,
18488
+ sql: KS,
18455
18489
  sqlite: FS,
18456
18490
  tidb: cA,
18457
18491
  transactsql: OI,
@@ -18461,7 +18495,7 @@ const lS = [
18461
18495
  |$)`, "uy"), hT = (T, E = []) => {
18462
18496
  const e = T === "open" ? 0 : 1, R = ["()", ...E].map((A) => A[e]);
18463
18497
  return v(R.map(X).join("|"));
18464
- }, VT = (T) => v(`${ee(T).map(X).join("|")}`), fI = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", g = (T, E = {}) => {
18498
+ }, VT = (T) => v(`${ee(T).map(X).join("|")}`), fI = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", K = (T, E = {}) => {
18465
18499
  if (T.length === 0)
18466
18500
  return /^\b$/u;
18467
18501
  const e = fI(E), R = ee(T).map(X).join("|").replace(/ /gu, "\\s+");
@@ -18477,7 +18511,7 @@ const lS = [
18477
18511
  "[": "]",
18478
18512
  "(": ")",
18479
18513
  "{": "}"
18480
- }, E = "{left}(?:(?!{right}').)*?{right}", e = Object.entries(T).map(([N, t]) => E.replace(/{left}/g, X(N)).replace(/{right}/g, X(t))), R = X(Object.keys(T).join(""));
18514
+ }, E = "{left}(?:(?!{right}').)*?{right}", e = Object.entries(T).map(([I, t]) => E.replace(/{left}/g, X(I)).replace(/{right}/g, X(t))), R = X(Object.keys(T).join(""));
18481
18515
  return `[Qq]'(?:${String.raw`(?<tag>[^\s${R}])(?:(?!\k<tag>').)*?\k<tag>`}|${e.join("|")})'`;
18482
18516
  }, WT = {
18483
18517
  // - backtick quoted (using `` to escape)
@@ -18505,8 +18539,8 @@ const lS = [
18505
18539
  // Oracle q'' strings: q'<text>' q'|text|' ...
18506
18540
  "q''": hI()
18507
18541
  }, Re = (T) => typeof T == "string" ? WT[T] : "regex" in T ? T.regex : FI(T) + WT[T.quote], VI = (T) => v(T.map((E) => "regex" in E ? E.regex : Re(E)).join("|")), Ae = (T) => T.map(Re).join("|"), bT = (T) => v(Ae(T)), WI = (T = {}) => v(Se(T)), Se = ({ first: T, rest: E, dashes: e, allowFirstCharNumber: R } = {}) => {
18508
- const A = "\\p{Alphabetic}\\p{Mark}_", S = "\\p{Decimal_Number}", N = X(T ?? ""), t = X(E ?? ""), C = R ? `[${A}${S}${N}][${A}${S}${t}]*` : `[${A}${N}][${A}${S}${t}]*`;
18509
- return e ? pI(C) : C;
18542
+ const A = "\\p{Alphabetic}\\p{Mark}_", S = "\\p{Decimal_Number}", I = X(T ?? ""), t = X(E ?? ""), s = R ? `[${A}${S}${I}][${A}${S}${t}]*` : `[${A}${I}][${A}${S}${t}]*`;
18543
+ return e ? pI(s) : s;
18510
18544
  };
18511
18545
  function Ie(T, E) {
18512
18546
  const e = T.slice(0, E).split(/\n/);
@@ -18575,7 +18609,7 @@ If possible, please select a more specific dialect (like sqlite, postgresql, etc
18575
18609
  }
18576
18610
  }
18577
18611
  const XT = /\/\*/uy, XI = /[\s\S]/uy, yI = /\*\//uy;
18578
- class KI {
18612
+ class gI {
18579
18613
  constructor() {
18580
18614
  this.lastIndex = 0;
18581
18615
  }
@@ -18602,7 +18636,7 @@ class KI {
18602
18636
  return R && (this.lastIndex += R[0].length), R ? R[0] : null;
18603
18637
  }
18604
18638
  }
18605
- class gI {
18639
+ class KI {
18606
18640
  constructor(E, e) {
18607
18641
  this.cfg = E, this.dialectName = e, this.rulesBeforeParams = this.buildRulesBeforeParams(E), this.rulesAfterParams = this.buildRulesAfterParams(E);
18608
18642
  }
@@ -18620,126 +18654,126 @@ class gI {
18620
18654
  var e, R, A;
18621
18655
  return this.validRules([
18622
18656
  {
18623
- type: a.DISABLE_COMMENT,
18657
+ type: D.DISABLE_COMMENT,
18624
18658
  regex: /(\/\* *sql-formatter-disable *\*\/[\s\S]*?(?:\/\* *sql-formatter-enable *\*\/|$))/uy
18625
18659
  },
18626
18660
  {
18627
- type: a.BLOCK_COMMENT,
18628
- regex: E.nestedBlockComments ? new KI() : /(\/\*[^]*?\*\/)/uy
18661
+ type: D.BLOCK_COMMENT,
18662
+ regex: E.nestedBlockComments ? new gI() : /(\/\*[^]*?\*\/)/uy
18629
18663
  },
18630
18664
  {
18631
- type: a.LINE_COMMENT,
18665
+ type: D.LINE_COMMENT,
18632
18666
  regex: YI((e = E.lineCommentTypes) !== null && e !== void 0 ? e : ["--"])
18633
18667
  },
18634
18668
  {
18635
- type: a.QUOTED_IDENTIFIER,
18669
+ type: D.QUOTED_IDENTIFIER,
18636
18670
  regex: bT(E.identTypes)
18637
18671
  },
18638
18672
  {
18639
- type: a.NUMBER,
18673
+ type: D.NUMBER,
18640
18674
  regex: E.underscoresInNumbers ? /(?:0x[0-9a-fA-F_]+|0b[01_]+|(?:-\s*)?(?:[0-9_]*\.[0-9_]+|[0-9_]+(?:\.[0-9_]*)?)(?:[eE][-+]?[0-9_]+(?:\.[0-9_]+)?)?)(?![\w\p{Alphabetic}])/uy : /(?:0x[0-9a-fA-F]+|0b[01]+|(?:-\s*)?(?:[0-9]*\.[0-9]+|[0-9]+(?:\.[0-9]*)?)(?:[eE][-+]?[0-9]+(?:\.[0-9]+)?)?)(?![\w\p{Alphabetic}])/uy
18641
18675
  },
18642
18676
  // RESERVED_KEYWORD_PHRASE and RESERVED_DATA_TYPE_PHRASE is matched before all other keyword tokens
18643
18677
  // to e.g. prioritize matching "TIMESTAMP WITH TIME ZONE" phrase over "WITH" clause.
18644
18678
  {
18645
- type: a.RESERVED_KEYWORD_PHRASE,
18646
- regex: g((R = E.reservedKeywordPhrases) !== null && R !== void 0 ? R : [], E.identChars),
18679
+ type: D.RESERVED_KEYWORD_PHRASE,
18680
+ regex: K((R = E.reservedKeywordPhrases) !== null && R !== void 0 ? R : [], E.identChars),
18647
18681
  text: p
18648
18682
  },
18649
18683
  {
18650
- type: a.RESERVED_DATA_TYPE_PHRASE,
18651
- regex: g((A = E.reservedDataTypePhrases) !== null && A !== void 0 ? A : [], E.identChars),
18684
+ type: D.RESERVED_DATA_TYPE_PHRASE,
18685
+ regex: K((A = E.reservedDataTypePhrases) !== null && A !== void 0 ? A : [], E.identChars),
18652
18686
  text: p
18653
18687
  },
18654
18688
  {
18655
- type: a.CASE,
18689
+ type: D.CASE,
18656
18690
  regex: /CASE\b/iuy,
18657
18691
  text: p
18658
18692
  },
18659
18693
  {
18660
- type: a.END,
18694
+ type: D.END,
18661
18695
  regex: /END\b/iuy,
18662
18696
  text: p
18663
18697
  },
18664
18698
  {
18665
- type: a.BETWEEN,
18699
+ type: D.BETWEEN,
18666
18700
  regex: /BETWEEN\b/iuy,
18667
18701
  text: p
18668
18702
  },
18669
18703
  {
18670
- type: a.LIMIT,
18704
+ type: D.LIMIT,
18671
18705
  regex: E.reservedClauses.includes("LIMIT") ? /LIMIT\b/iuy : void 0,
18672
18706
  text: p
18673
18707
  },
18674
18708
  {
18675
- type: a.RESERVED_CLAUSE,
18676
- regex: g(E.reservedClauses, E.identChars),
18709
+ type: D.RESERVED_CLAUSE,
18710
+ regex: K(E.reservedClauses, E.identChars),
18677
18711
  text: p
18678
18712
  },
18679
18713
  {
18680
- type: a.RESERVED_SELECT,
18681
- regex: g(E.reservedSelect, E.identChars),
18714
+ type: D.RESERVED_SELECT,
18715
+ regex: K(E.reservedSelect, E.identChars),
18682
18716
  text: p
18683
18717
  },
18684
18718
  {
18685
- type: a.RESERVED_SET_OPERATION,
18686
- regex: g(E.reservedSetOperations, E.identChars),
18719
+ type: D.RESERVED_SET_OPERATION,
18720
+ regex: K(E.reservedSetOperations, E.identChars),
18687
18721
  text: p
18688
18722
  },
18689
18723
  {
18690
- type: a.WHEN,
18724
+ type: D.WHEN,
18691
18725
  regex: /WHEN\b/iuy,
18692
18726
  text: p
18693
18727
  },
18694
18728
  {
18695
- type: a.ELSE,
18729
+ type: D.ELSE,
18696
18730
  regex: /ELSE\b/iuy,
18697
18731
  text: p
18698
18732
  },
18699
18733
  {
18700
- type: a.THEN,
18734
+ type: D.THEN,
18701
18735
  regex: /THEN\b/iuy,
18702
18736
  text: p
18703
18737
  },
18704
18738
  {
18705
- type: a.RESERVED_JOIN,
18706
- regex: g(E.reservedJoins, E.identChars),
18739
+ type: D.RESERVED_JOIN,
18740
+ regex: K(E.reservedJoins, E.identChars),
18707
18741
  text: p
18708
18742
  },
18709
18743
  {
18710
- type: a.AND,
18744
+ type: D.AND,
18711
18745
  regex: /AND\b/iuy,
18712
18746
  text: p
18713
18747
  },
18714
18748
  {
18715
- type: a.OR,
18749
+ type: D.OR,
18716
18750
  regex: /OR\b/iuy,
18717
18751
  text: p
18718
18752
  },
18719
18753
  {
18720
- type: a.XOR,
18754
+ type: D.XOR,
18721
18755
  regex: E.supportsXor ? /XOR\b/iuy : void 0,
18722
18756
  text: p
18723
18757
  },
18724
18758
  ...E.operatorKeyword ? [
18725
18759
  {
18726
- type: a.OPERATOR,
18760
+ type: D.OPERATOR,
18727
18761
  regex: /OPERATOR *\([^)]+\)/iuy
18728
18762
  }
18729
18763
  ] : [],
18730
18764
  {
18731
- type: a.RESERVED_FUNCTION_NAME,
18732
- regex: g(E.reservedFunctionNames, E.identChars),
18765
+ type: D.RESERVED_FUNCTION_NAME,
18766
+ regex: K(E.reservedFunctionNames, E.identChars),
18733
18767
  text: p
18734
18768
  },
18735
18769
  {
18736
- type: a.RESERVED_DATA_TYPE,
18737
- regex: g(E.reservedDataTypes, E.identChars),
18770
+ type: D.RESERVED_DATA_TYPE,
18771
+ regex: K(E.reservedDataTypes, E.identChars),
18738
18772
  text: p
18739
18773
  },
18740
18774
  {
18741
- type: a.RESERVED_KEYWORD,
18742
- regex: g(E.reservedKeywords, E.identChars),
18775
+ type: D.RESERVED_KEYWORD,
18776
+ regex: K(E.reservedKeywords, E.identChars),
18743
18777
  text: p
18744
18778
  }
18745
18779
  ]);
@@ -18750,26 +18784,26 @@ class gI {
18750
18784
  var e, R;
18751
18785
  return this.validRules([
18752
18786
  {
18753
- type: a.VARIABLE,
18787
+ type: D.VARIABLE,
18754
18788
  regex: E.variableTypes ? VI(E.variableTypes) : void 0
18755
18789
  },
18756
- { type: a.STRING, regex: bT(E.stringTypes) },
18790
+ { type: D.STRING, regex: bT(E.stringTypes) },
18757
18791
  {
18758
- type: a.IDENTIFIER,
18792
+ type: D.IDENTIFIER,
18759
18793
  regex: WI(E.identChars)
18760
18794
  },
18761
- { type: a.DELIMITER, regex: /[;]/uy },
18762
- { type: a.COMMA, regex: /[,]/y },
18795
+ { type: D.DELIMITER, regex: /[;]/uy },
18796
+ { type: D.COMMA, regex: /[,]/y },
18763
18797
  {
18764
- type: a.OPEN_PAREN,
18798
+ type: D.OPEN_PAREN,
18765
18799
  regex: hT("open", E.extraParens)
18766
18800
  },
18767
18801
  {
18768
- type: a.CLOSE_PAREN,
18802
+ type: D.CLOSE_PAREN,
18769
18803
  regex: hT("close", E.extraParens)
18770
18804
  },
18771
18805
  {
18772
- type: a.OPERATOR,
18806
+ type: D.OPERATOR,
18773
18807
  regex: VT([
18774
18808
  // standard operators
18775
18809
  "+",
@@ -18785,9 +18819,9 @@ class gI {
18785
18819
  ...(e = E.operators) !== null && e !== void 0 ? e : []
18786
18820
  ])
18787
18821
  },
18788
- { type: a.ASTERISK, regex: /[*]/uy },
18822
+ { type: D.ASTERISK, regex: /[*]/uy },
18789
18823
  {
18790
- type: a.PROPERTY_ACCESS_OPERATOR,
18824
+ type: D.PROPERTY_ACCESS_OPERATOR,
18791
18825
  regex: VT([".", ...(R = E.propertyAccessOperators) !== null && R !== void 0 ? R : []])
18792
18826
  }
18793
18827
  ]);
@@ -18795,43 +18829,43 @@ class gI {
18795
18829
  // These rules can't be blindly cached as the paramTypesOverrides object
18796
18830
  // can differ on each invocation of the format() function.
18797
18831
  buildParamRules(E, e) {
18798
- var R, A, S, N, t;
18799
- const C = {
18832
+ var R, A, S, I, t;
18833
+ const s = {
18800
18834
  named: e?.named || ((R = E.paramTypes) === null || R === void 0 ? void 0 : R.named) || [],
18801
18835
  quoted: e?.quoted || ((A = E.paramTypes) === null || A === void 0 ? void 0 : A.quoted) || [],
18802
18836
  numbered: e?.numbered || ((S = E.paramTypes) === null || S === void 0 ? void 0 : S.numbered) || [],
18803
- positional: typeof e?.positional == "boolean" ? e.positional : (N = E.paramTypes) === null || N === void 0 ? void 0 : N.positional,
18837
+ positional: typeof e?.positional == "boolean" ? e.positional : (I = E.paramTypes) === null || I === void 0 ? void 0 : I.positional,
18804
18838
  custom: e?.custom || ((t = E.paramTypes) === null || t === void 0 ? void 0 : t.custom) || []
18805
18839
  };
18806
18840
  return this.validRules([
18807
18841
  {
18808
- type: a.NAMED_PARAMETER,
18809
- regex: xE(C.named, Se(E.paramChars || E.identChars)),
18842
+ type: D.NAMED_PARAMETER,
18843
+ regex: xE(s.named, Se(E.paramChars || E.identChars)),
18810
18844
  key: (O) => O.slice(1)
18811
18845
  },
18812
18846
  {
18813
- type: a.QUOTED_PARAMETER,
18814
- regex: xE(C.quoted, Ae(E.identTypes)),
18815
- key: (O) => (({ tokenKey: I, quoteChar: s }) => I.replace(new RegExp(X("\\" + s), "gu"), s))({
18847
+ type: D.QUOTED_PARAMETER,
18848
+ regex: xE(s.quoted, Ae(E.identTypes)),
18849
+ key: (O) => (({ tokenKey: N, quoteChar: C }) => N.replace(new RegExp(X("\\" + C), "gu"), C))({
18816
18850
  tokenKey: O.slice(2, -1),
18817
18851
  quoteChar: O.slice(-1)
18818
18852
  })
18819
18853
  },
18820
18854
  {
18821
- type: a.NUMBERED_PARAMETER,
18822
- regex: xE(C.numbered, "[0-9]+"),
18855
+ type: D.NUMBERED_PARAMETER,
18856
+ regex: xE(s.numbered, "[0-9]+"),
18823
18857
  key: (O) => O.slice(1)
18824
18858
  },
18825
18859
  {
18826
- type: a.POSITIONAL_PARAMETER,
18827
- regex: C.positional ? /[?]/y : void 0
18860
+ type: D.POSITIONAL_PARAMETER,
18861
+ regex: s.positional ? /[?]/y : void 0
18828
18862
  },
18829
- ...C.custom.map((O) => {
18830
- var I;
18863
+ ...s.custom.map((O) => {
18864
+ var N;
18831
18865
  return {
18832
- type: a.CUSTOM_PARAMETER,
18866
+ type: D.CUSTOM_PARAMETER,
18833
18867
  regex: v(O.regex),
18834
- key: (I = O.key) !== null && I !== void 0 ? I : ((s) => s)
18868
+ key: (N = O.key) !== null && N !== void 0 ? N : ((C) => C)
18835
18869
  };
18836
18870
  })
18837
18871
  ]);
@@ -18845,7 +18879,7 @@ const p = (T) => NE(T.toUpperCase()), yT = /* @__PURE__ */ new Map(), $I = (T) =
18845
18879
  let E = yT.get(T);
18846
18880
  return E || (E = wI(T), yT.set(T, E)), E;
18847
18881
  }, wI = (T) => ({
18848
- tokenizer: new gI(T.tokenizerOptions, T.name),
18882
+ tokenizer: new KI(T.tokenizerOptions, T.name),
18849
18883
  formatOptions: JI(T.formatOptions)
18850
18884
  }), JI = (T) => {
18851
18885
  var E;
@@ -18887,98 +18921,98 @@ class vI {
18887
18921
  function QI(T) {
18888
18922
  return T && T.__esModule && Object.prototype.hasOwnProperty.call(T, "default") ? T.default : T;
18889
18923
  }
18890
- var OE = { exports: {} }, ZI = OE.exports, KT;
18924
+ var OE = { exports: {} }, ZI = OE.exports, gT;
18891
18925
  function qI() {
18892
- return KT || (KT = 1, (function(T) {
18926
+ return gT || (gT = 1, (function(T) {
18893
18927
  (function(E, e) {
18894
18928
  T.exports ? T.exports = e() : E.nearley = e();
18895
18929
  })(ZI, function() {
18896
- function E(O, I, s) {
18897
- return this.id = ++E.highestId, this.name = O, this.symbols = I, this.postprocess = s, this;
18930
+ function E(O, N, C) {
18931
+ return this.id = ++E.highestId, this.name = O, this.symbols = N, this.postprocess = C, this;
18898
18932
  }
18899
18933
  E.highestId = 0, E.prototype.toString = function(O) {
18900
- var I = typeof O > "u" ? this.symbols.map(C).join(" ") : this.symbols.slice(0, O).map(C).join(" ") + " ● " + this.symbols.slice(O).map(C).join(" ");
18901
- return this.name + " → " + I;
18934
+ var N = typeof O > "u" ? this.symbols.map(s).join(" ") : this.symbols.slice(0, O).map(s).join(" ") + " ● " + this.symbols.slice(O).map(s).join(" ");
18935
+ return this.name + " → " + N;
18902
18936
  };
18903
- function e(O, I, s, r) {
18904
- this.rule = O, this.dot = I, this.reference = s, this.data = [], this.wantedBy = r, this.isComplete = this.dot === O.symbols.length;
18937
+ function e(O, N, C, L) {
18938
+ this.rule = O, this.dot = N, this.reference = C, this.data = [], this.wantedBy = L, this.isComplete = this.dot === O.symbols.length;
18905
18939
  }
18906
18940
  e.prototype.toString = function() {
18907
18941
  return "{" + this.rule.toString(this.dot) + "}, from: " + (this.reference || 0);
18908
18942
  }, e.prototype.nextState = function(O) {
18909
- var I = new e(this.rule, this.dot + 1, this.reference, this.wantedBy);
18910
- return I.left = this, I.right = O, I.isComplete && (I.data = I.build(), I.right = void 0), I;
18943
+ var N = new e(this.rule, this.dot + 1, this.reference, this.wantedBy);
18944
+ return N.left = this, N.right = O, N.isComplete && (N.data = N.build(), N.right = void 0), N;
18911
18945
  }, e.prototype.build = function() {
18912
- var O = [], I = this;
18946
+ var O = [], N = this;
18913
18947
  do
18914
- O.push(I.right.data), I = I.left;
18915
- while (I.left);
18948
+ O.push(N.right.data), N = N.left;
18949
+ while (N.left);
18916
18950
  return O.reverse(), O;
18917
18951
  }, e.prototype.finish = function() {
18918
- this.rule.postprocess && (this.data = this.rule.postprocess(this.data, this.reference, N.fail));
18952
+ this.rule.postprocess && (this.data = this.rule.postprocess(this.data, this.reference, I.fail));
18919
18953
  };
18920
- function R(O, I) {
18921
- this.grammar = O, this.index = I, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
18954
+ function R(O, N) {
18955
+ this.grammar = O, this.index = N, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
18922
18956
  }
18923
18957
  R.prototype.process = function(O) {
18924
- for (var I = this.states, s = this.wants, r = this.completed, _ = 0; _ < I.length; _++) {
18925
- var D = I[_];
18926
- if (D.isComplete) {
18927
- if (D.finish(), D.data !== N.fail) {
18928
- for (var o = D.wantedBy, u = o.length; u--; ) {
18958
+ for (var N = this.states, C = this.wants, L = this.completed, n = 0; n < N.length; n++) {
18959
+ var i = N[n];
18960
+ if (i.isComplete) {
18961
+ if (i.finish(), i.data !== I.fail) {
18962
+ for (var o = i.wantedBy, u = o.length; u--; ) {
18929
18963
  var P = o[u];
18930
- this.complete(P, D);
18964
+ this.complete(P, i);
18931
18965
  }
18932
- if (D.reference === this.index) {
18933
- var l = D.rule.name;
18934
- (this.completed[l] = this.completed[l] || []).push(D);
18966
+ if (i.reference === this.index) {
18967
+ var l = i.rule.name;
18968
+ (this.completed[l] = this.completed[l] || []).push(i);
18935
18969
  }
18936
18970
  }
18937
18971
  } else {
18938
- var l = D.rule.symbols[D.dot];
18972
+ var l = i.rule.symbols[i.dot];
18939
18973
  if (typeof l != "string") {
18940
- this.scannable.push(D);
18974
+ this.scannable.push(i);
18941
18975
  continue;
18942
18976
  }
18943
- if (s[l]) {
18944
- if (s[l].push(D), r.hasOwnProperty(l))
18945
- for (var M = r[l], u = 0; u < M.length; u++) {
18977
+ if (C[l]) {
18978
+ if (C[l].push(i), L.hasOwnProperty(l))
18979
+ for (var M = L[l], u = 0; u < M.length; u++) {
18946
18980
  var G = M[u];
18947
- this.complete(D, G);
18981
+ this.complete(i, G);
18948
18982
  }
18949
18983
  } else
18950
- s[l] = [D], this.predict(l);
18984
+ C[l] = [i], this.predict(l);
18951
18985
  }
18952
18986
  }
18953
18987
  }, R.prototype.predict = function(O) {
18954
- for (var I = this.grammar.byName[O] || [], s = 0; s < I.length; s++) {
18955
- var r = I[s], _ = this.wants[O], D = new e(r, 0, this.index, _);
18956
- this.states.push(D);
18988
+ for (var N = this.grammar.byName[O] || [], C = 0; C < N.length; C++) {
18989
+ var L = N[C], n = this.wants[O], i = new e(L, 0, this.index, n);
18990
+ this.states.push(i);
18957
18991
  }
18958
- }, R.prototype.complete = function(O, I) {
18959
- var s = O.nextState(I);
18960
- this.states.push(s);
18992
+ }, R.prototype.complete = function(O, N) {
18993
+ var C = O.nextState(N);
18994
+ this.states.push(C);
18961
18995
  };
18962
- function A(O, I) {
18963
- this.rules = O, this.start = I || this.rules[0].name;
18964
- var s = this.byName = {};
18965
- this.rules.forEach(function(r) {
18966
- s.hasOwnProperty(r.name) || (s[r.name] = []), s[r.name].push(r);
18996
+ function A(O, N) {
18997
+ this.rules = O, this.start = N || this.rules[0].name;
18998
+ var C = this.byName = {};
18999
+ this.rules.forEach(function(L) {
19000
+ C.hasOwnProperty(L.name) || (C[L.name] = []), C[L.name].push(L);
18967
19001
  });
18968
19002
  }
18969
- A.fromCompiled = function(r, I) {
18970
- var s = r.Lexer;
18971
- r.ParserStart && (I = r.ParserStart, r = r.ParserRules);
18972
- var r = r.map(function(D) {
18973
- return new E(D.name, D.symbols, D.postprocess);
18974
- }), _ = new A(r, I);
18975
- return _.lexer = s, _;
19003
+ A.fromCompiled = function(L, N) {
19004
+ var C = L.Lexer;
19005
+ L.ParserStart && (N = L.ParserStart, L = L.ParserRules);
19006
+ var L = L.map(function(i) {
19007
+ return new E(i.name, i.symbols, i.postprocess);
19008
+ }), n = new A(L, N);
19009
+ return n.lexer = C, n;
18976
19010
  };
18977
19011
  function S() {
18978
19012
  this.reset("");
18979
19013
  }
18980
- S.prototype.reset = function(O, I) {
18981
- this.buffer = O, this.index = 0, this.line = I ? I.line : 1, this.lastLineBreak = I ? -I.col : 0;
19014
+ S.prototype.reset = function(O, N) {
19015
+ this.buffer = O, this.index = 0, this.line = N ? N.line : 1, this.lastLineBreak = N ? -N.col : 0;
18982
19016
  }, S.prototype.next = function() {
18983
19017
  if (this.index < this.buffer.length) {
18984
19018
  var O = this.buffer[this.index++];
@@ -18990,144 +19024,144 @@ function qI() {
18990
19024
  line: this.line,
18991
19025
  col: this.index - this.lastLineBreak
18992
19026
  };
18993
- }, S.prototype.formatError = function(O, I) {
18994
- var s = this.buffer;
18995
- if (typeof s == "string") {
18996
- var r = s.split(`
19027
+ }, S.prototype.formatError = function(O, N) {
19028
+ var C = this.buffer;
19029
+ if (typeof C == "string") {
19030
+ var L = C.split(`
18997
19031
  `).slice(
18998
19032
  Math.max(0, this.line - 5),
18999
19033
  this.line
19000
- ), _ = s.indexOf(`
19034
+ ), n = C.indexOf(`
19001
19035
  `, this.index);
19002
- _ === -1 && (_ = s.length);
19003
- var D = this.index - this.lastLineBreak, o = String(this.line).length;
19004
- return I += " at line " + this.line + " col " + D + `:
19036
+ n === -1 && (n = C.length);
19037
+ var i = this.index - this.lastLineBreak, o = String(this.line).length;
19038
+ return N += " at line " + this.line + " col " + i + `:
19005
19039
 
19006
- `, I += r.map(function(P, l) {
19007
- return u(this.line - r.length + l + 1, o) + " " + P;
19040
+ `, N += L.map(function(P, l) {
19041
+ return u(this.line - L.length + l + 1, o) + " " + P;
19008
19042
  }, this).join(`
19009
- `), I += `
19010
- ` + u("", o + D) + `^
19011
- `, I;
19043
+ `), N += `
19044
+ ` + u("", o + i) + `^
19045
+ `, N;
19012
19046
  } else
19013
- return I + " at index " + (this.index - 1);
19047
+ return N + " at index " + (this.index - 1);
19014
19048
  function u(P, l) {
19015
19049
  var M = String(P);
19016
19050
  return Array(l - M.length + 1).join(" ") + M;
19017
19051
  }
19018
19052
  };
19019
- function N(O, I, s) {
19053
+ function I(O, N, C) {
19020
19054
  if (O instanceof A)
19021
- var r = O, s = I;
19055
+ var L = O, C = N;
19022
19056
  else
19023
- var r = A.fromCompiled(O, I);
19024
- this.grammar = r, this.options = {
19057
+ var L = A.fromCompiled(O, N);
19058
+ this.grammar = L, this.options = {
19025
19059
  keepHistory: !1,
19026
- lexer: r.lexer || new S()
19060
+ lexer: L.lexer || new S()
19027
19061
  };
19028
- for (var _ in s || {})
19029
- this.options[_] = s[_];
19062
+ for (var n in C || {})
19063
+ this.options[n] = C[n];
19030
19064
  this.lexer = this.options.lexer, this.lexerState = void 0;
19031
- var D = new R(r, 0);
19032
- this.table = [D], D.wants[r.start] = [], D.predict(r.start), D.process(), this.current = 0;
19065
+ var i = new R(L, 0);
19066
+ this.table = [i], i.wants[L.start] = [], i.predict(L.start), i.process(), this.current = 0;
19033
19067
  }
19034
- N.fail = {}, N.prototype.feed = function(O) {
19035
- var I = this.lexer;
19036
- I.reset(O, this.lexerState);
19037
- for (var s; ; ) {
19068
+ I.fail = {}, I.prototype.feed = function(O) {
19069
+ var N = this.lexer;
19070
+ N.reset(O, this.lexerState);
19071
+ for (var C; ; ) {
19038
19072
  try {
19039
- if (s = I.next(), !s)
19073
+ if (C = N.next(), !C)
19040
19074
  break;
19041
19075
  } catch (b) {
19042
19076
  var o = new R(this.grammar, this.current + 1);
19043
19077
  this.table.push(o);
19044
- var r = new Error(this.reportLexerError(b));
19045
- throw r.offset = this.current, r.token = b.token, r;
19078
+ var L = new Error(this.reportLexerError(b));
19079
+ throw L.offset = this.current, L.token = b.token, L;
19046
19080
  }
19047
- var _ = this.table[this.current];
19081
+ var n = this.table[this.current];
19048
19082
  this.options.keepHistory || delete this.table[this.current - 1];
19049
- var D = this.current + 1, o = new R(this.grammar, D);
19083
+ var i = this.current + 1, o = new R(this.grammar, i);
19050
19084
  this.table.push(o);
19051
- for (var u = s.text !== void 0 ? s.text : s.value, P = I.constructor === S ? s.value : s, l = _.scannable, M = l.length; M--; ) {
19085
+ for (var u = C.text !== void 0 ? C.text : C.value, P = N.constructor === S ? C.value : C, l = n.scannable, M = l.length; M--; ) {
19052
19086
  var G = l[M], m = G.rule.symbols[G.dot];
19053
- if (m.test ? m.test(P) : m.type ? m.type === s.type : m.literal === u) {
19054
- var B = G.nextState({ data: P, token: s, isToken: !0, reference: D - 1 });
19087
+ if (m.test ? m.test(P) : m.type ? m.type === C.type : m.literal === u) {
19088
+ var B = G.nextState({ data: P, token: C, isToken: !0, reference: i - 1 });
19055
19089
  o.states.push(B);
19056
19090
  }
19057
19091
  }
19058
19092
  if (o.process(), o.states.length === 0) {
19059
- var r = new Error(this.reportError(s));
19060
- throw r.offset = this.current, r.token = s, r;
19093
+ var L = new Error(this.reportError(C));
19094
+ throw L.offset = this.current, L.token = C, L;
19061
19095
  }
19062
- this.options.keepHistory && (_.lexerState = I.save()), this.current++;
19096
+ this.options.keepHistory && (n.lexerState = N.save()), this.current++;
19063
19097
  }
19064
- return _ && (this.lexerState = I.save()), this.results = this.finish(), this;
19065
- }, N.prototype.reportLexerError = function(O) {
19066
- var I, s, r = O.token;
19067
- return r ? (I = "input " + JSON.stringify(r.text[0]) + " (lexer error)", s = this.lexer.formatError(r, "Syntax error")) : (I = "input (lexer error)", s = O.message), this.reportErrorCommon(s, I);
19068
- }, N.prototype.reportError = function(O) {
19069
- var I = (O.type ? O.type + " token: " : "") + JSON.stringify(O.value !== void 0 ? O.value : O), s = this.lexer.formatError(O, "Syntax error");
19070
- return this.reportErrorCommon(s, I);
19071
- }, N.prototype.reportErrorCommon = function(O, I) {
19072
- var s = [];
19073
- s.push(O);
19074
- var r = this.table.length - 2, _ = this.table[r], D = _.states.filter(function(u) {
19098
+ return n && (this.lexerState = N.save()), this.results = this.finish(), this;
19099
+ }, I.prototype.reportLexerError = function(O) {
19100
+ var N, C, L = O.token;
19101
+ return L ? (N = "input " + JSON.stringify(L.text[0]) + " (lexer error)", C = this.lexer.formatError(L, "Syntax error")) : (N = "input (lexer error)", C = O.message), this.reportErrorCommon(C, N);
19102
+ }, I.prototype.reportError = function(O) {
19103
+ var N = (O.type ? O.type + " token: " : "") + JSON.stringify(O.value !== void 0 ? O.value : O), C = this.lexer.formatError(O, "Syntax error");
19104
+ return this.reportErrorCommon(C, N);
19105
+ }, I.prototype.reportErrorCommon = function(O, N) {
19106
+ var C = [];
19107
+ C.push(O);
19108
+ var L = this.table.length - 2, n = this.table[L], i = n.states.filter(function(u) {
19075
19109
  var P = u.rule.symbols[u.dot];
19076
19110
  return P && typeof P != "string";
19077
19111
  });
19078
- if (D.length === 0)
19079
- s.push("Unexpected " + I + `. I did not expect any more input. Here is the state of my parse table:
19080
- `), this.displayStateStack(_.states, s);
19112
+ if (i.length === 0)
19113
+ C.push("Unexpected " + N + `. I did not expect any more input. Here is the state of my parse table:
19114
+ `), this.displayStateStack(n.states, C);
19081
19115
  else {
19082
- s.push("Unexpected " + I + `. Instead, I was expecting to see one of the following:
19116
+ C.push("Unexpected " + N + `. Instead, I was expecting to see one of the following:
19083
19117
  `);
19084
- var o = D.map(function(u) {
19118
+ var o = i.map(function(u) {
19085
19119
  return this.buildFirstStateStack(u, []) || [u];
19086
19120
  }, this);
19087
19121
  o.forEach(function(u) {
19088
19122
  var P = u[0], l = P.rule.symbols[P.dot], M = this.getSymbolDisplay(l);
19089
- s.push("A " + M + " based on:"), this.displayStateStack(u, s);
19123
+ C.push("A " + M + " based on:"), this.displayStateStack(u, C);
19090
19124
  }, this);
19091
19125
  }
19092
- return s.push(""), s.join(`
19126
+ return C.push(""), C.join(`
19093
19127
  `);
19094
- }, N.prototype.displayStateStack = function(O, I) {
19095
- for (var s, r = 0, _ = 0; _ < O.length; _++) {
19096
- var D = O[_], o = D.rule.toString(D.dot);
19097
- o === s ? r++ : (r > 0 && I.push(" ^ " + r + " more lines identical to this"), r = 0, I.push(" " + o)), s = o;
19128
+ }, I.prototype.displayStateStack = function(O, N) {
19129
+ for (var C, L = 0, n = 0; n < O.length; n++) {
19130
+ var i = O[n], o = i.rule.toString(i.dot);
19131
+ o === C ? L++ : (L > 0 && N.push(" ^ " + L + " more lines identical to this"), L = 0, N.push(" " + o)), C = o;
19098
19132
  }
19099
- }, N.prototype.getSymbolDisplay = function(O) {
19133
+ }, I.prototype.getSymbolDisplay = function(O) {
19100
19134
  return t(O);
19101
- }, N.prototype.buildFirstStateStack = function(O, I) {
19102
- if (I.indexOf(O) !== -1)
19135
+ }, I.prototype.buildFirstStateStack = function(O, N) {
19136
+ if (N.indexOf(O) !== -1)
19103
19137
  return null;
19104
19138
  if (O.wantedBy.length === 0)
19105
19139
  return [O];
19106
- var s = O.wantedBy[0], r = [O].concat(I), _ = this.buildFirstStateStack(s, r);
19107
- return _ === null ? null : [O].concat(_);
19108
- }, N.prototype.save = function() {
19140
+ var C = O.wantedBy[0], L = [O].concat(N), n = this.buildFirstStateStack(C, L);
19141
+ return n === null ? null : [O].concat(n);
19142
+ }, I.prototype.save = function() {
19109
19143
  var O = this.table[this.current];
19110
19144
  return O.lexerState = this.lexerState, O;
19111
- }, N.prototype.restore = function(O) {
19112
- var I = O.index;
19113
- this.current = I, this.table[I] = O, this.table.splice(I + 1), this.lexerState = O.lexerState, this.results = this.finish();
19114
- }, N.prototype.rewind = function(O) {
19145
+ }, I.prototype.restore = function(O) {
19146
+ var N = O.index;
19147
+ this.current = N, this.table[N] = O, this.table.splice(N + 1), this.lexerState = O.lexerState, this.results = this.finish();
19148
+ }, I.prototype.rewind = function(O) {
19115
19149
  if (!this.options.keepHistory)
19116
19150
  throw new Error("set option `keepHistory` to enable rewinding");
19117
19151
  this.restore(this.table[O]);
19118
- }, N.prototype.finish = function() {
19119
- var O = [], I = this.grammar.start, s = this.table[this.table.length - 1];
19120
- return s.states.forEach(function(r) {
19121
- r.rule.name === I && r.dot === r.rule.symbols.length && r.reference === 0 && r.data !== N.fail && O.push(r);
19122
- }), O.map(function(r) {
19123
- return r.data;
19152
+ }, I.prototype.finish = function() {
19153
+ var O = [], N = this.grammar.start, C = this.table[this.table.length - 1];
19154
+ return C.states.forEach(function(L) {
19155
+ L.rule.name === N && L.dot === L.rule.symbols.length && L.reference === 0 && L.data !== I.fail && O.push(L);
19156
+ }), O.map(function(L) {
19157
+ return L.data;
19124
19158
  });
19125
19159
  };
19126
19160
  function t(O) {
19127
- var I = typeof O;
19128
- if (I === "string")
19161
+ var N = typeof O;
19162
+ if (N === "string")
19129
19163
  return O;
19130
- if (I === "object") {
19164
+ if (N === "object") {
19131
19165
  if (O.literal)
19132
19166
  return JSON.stringify(O.literal);
19133
19167
  if (O instanceof RegExp)
@@ -19139,11 +19173,11 @@ function qI() {
19139
19173
  throw new Error("Unknown symbol type: " + O);
19140
19174
  }
19141
19175
  }
19142
- function C(O) {
19143
- var I = typeof O;
19144
- if (I === "string")
19176
+ function s(O) {
19177
+ var N = typeof O;
19178
+ if (N === "string")
19145
19179
  return O;
19146
- if (I === "object") {
19180
+ if (N === "object") {
19147
19181
  if (O.literal)
19148
19182
  return JSON.stringify(O.literal);
19149
19183
  if (O instanceof RegExp)
@@ -19156,7 +19190,7 @@ function qI() {
19156
19190
  }
19157
19191
  }
19158
19192
  return {
19159
- Parser: N,
19193
+ Parser: I,
19160
19194
  Grammar: A,
19161
19195
  Rule: E
19162
19196
  };
@@ -19171,39 +19205,39 @@ function zI(T) {
19171
19205
  const EN = (T, E, e) => {
19172
19206
  if (Te(T.type)) {
19173
19207
  const R = SN(e, E);
19174
- if (R && R.type === a.PROPERTY_ACCESS_OPERATOR)
19175
- return Object.assign(Object.assign({}, T), { type: a.IDENTIFIER, text: T.raw });
19208
+ if (R && R.type === D.PROPERTY_ACCESS_OPERATOR)
19209
+ return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
19176
19210
  const A = EE(e, E);
19177
- if (A && A.type === a.PROPERTY_ACCESS_OPERATOR)
19178
- return Object.assign(Object.assign({}, T), { type: a.IDENTIFIER, text: T.raw });
19211
+ if (A && A.type === D.PROPERTY_ACCESS_OPERATOR)
19212
+ return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
19179
19213
  }
19180
19214
  return T;
19181
19215
  }, TN = (T, E, e) => {
19182
- if (T.type === a.RESERVED_FUNCTION_NAME) {
19216
+ if (T.type === D.RESERVED_FUNCTION_NAME) {
19183
19217
  const R = EE(e, E);
19184
19218
  if (!R || !Ne(R))
19185
- return Object.assign(Object.assign({}, T), { type: a.IDENTIFIER, text: T.raw });
19219
+ return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
19186
19220
  }
19187
19221
  return T;
19188
19222
  }, eN = (T, E, e) => {
19189
- if (T.type === a.RESERVED_DATA_TYPE) {
19223
+ if (T.type === D.RESERVED_DATA_TYPE) {
19190
19224
  const R = EE(e, E);
19191
19225
  if (R && Ne(R))
19192
- return Object.assign(Object.assign({}, T), { type: a.RESERVED_PARAMETERIZED_DATA_TYPE });
19226
+ return Object.assign(Object.assign({}, T), { type: D.RESERVED_PARAMETERIZED_DATA_TYPE });
19193
19227
  }
19194
19228
  return T;
19195
19229
  }, RN = (T, E, e) => {
19196
- if (T.type === a.IDENTIFIER) {
19230
+ if (T.type === D.IDENTIFIER) {
19197
19231
  const R = EE(e, E);
19198
19232
  if (R && Oe(R))
19199
- return Object.assign(Object.assign({}, T), { type: a.ARRAY_IDENTIFIER });
19233
+ return Object.assign(Object.assign({}, T), { type: D.ARRAY_IDENTIFIER });
19200
19234
  }
19201
19235
  return T;
19202
19236
  }, AN = (T, E, e) => {
19203
- if (T.type === a.RESERVED_DATA_TYPE) {
19237
+ if (T.type === D.RESERVED_DATA_TYPE) {
19204
19238
  const R = EE(e, E);
19205
19239
  if (R && Oe(R))
19206
- return Object.assign(Object.assign({}, T), { type: a.ARRAY_KEYWORD });
19240
+ return Object.assign(Object.assign({}, T), { type: D.ARRAY_KEYWORD });
19207
19241
  }
19208
19242
  return T;
19209
19243
  }, SN = (T, E) => EE(T, E, -1), EE = (T, E, e = 1) => {
@@ -19211,7 +19245,7 @@ const EN = (T, E, e) => {
19211
19245
  for (; T[E + R * e] && IN(T[E + R * e]); )
19212
19246
  R++;
19213
19247
  return T[E + R * e];
19214
- }, Ne = (T) => T.type === a.OPEN_PAREN && T.text === "(", Oe = (T) => T.type === a.OPEN_PAREN && T.text === "[", IN = (T) => T.type === a.BLOCK_COMMENT || T.type === a.LINE_COMMENT;
19248
+ }, Ne = (T) => T.type === D.OPEN_PAREN && T.text === "(", Oe = (T) => T.type === D.OPEN_PAREN && T.text === "[", IN = (T) => T.type === D.BLOCK_COMMENT || T.type === D.LINE_COMMENT;
19215
19249
  class te {
19216
19250
  constructor(E) {
19217
19251
  this.tokenize = E, this.index = 0, this.tokens = [], this.input = "";
@@ -19229,7 +19263,7 @@ class te {
19229
19263
  return `Parse error at token: ${E.text} at line ${e} column ${R}`;
19230
19264
  }
19231
19265
  has(E) {
19232
- return E in a;
19266
+ return E in D;
19233
19267
  }
19234
19268
  }
19235
19269
  var U;
@@ -19244,7 +19278,7 @@ const c = new te((T) => []), $ = ([[T]]) => T, F = (T) => ({
19244
19278
  tokenType: T.type,
19245
19279
  text: T.text,
19246
19280
  raw: T.raw
19247
- }), gT = (T) => ({
19281
+ }), KT = (T) => ({
19248
19282
  type: U.data_type,
19249
19283
  text: T.text,
19250
19284
  raw: T.raw
@@ -19279,7 +19313,7 @@ const c = new te((T) => []), $ = ([[T]]) => T, F = (T) => ({
19279
19313
  postprocess: ([T, [E]]) => ({
19280
19314
  type: U.statement,
19281
19315
  children: T,
19282
- hasSemicolon: E.type === a.DELIMITER
19316
+ hasSemicolon: E.type === D.DELIMITER
19283
19317
  })
19284
19318
  },
19285
19319
  { name: "expressions_or_clauses$ebnf$1", symbols: [] },
@@ -19520,12 +19554,12 @@ const c = new te((T) => []), $ = ([[T]]) => T, F = (T) => ({
19520
19554
  {
19521
19555
  name: "between_predicate",
19522
19556
  symbols: [c.has("BETWEEN") ? { type: "BETWEEN" } : BETWEEN, "_", "andless_expression_chain", "_", c.has("AND") ? { type: "AND" } : AND, "_", "andless_expression"],
19523
- postprocess: ([T, E, e, R, A, S, N]) => ({
19557
+ postprocess: ([T, E, e, R, A, S, I]) => ({
19524
19558
  type: U.between_predicate,
19525
19559
  betweenKw: F(T),
19526
19560
  expr1: NN(e, { leading: E, trailing: R }),
19527
19561
  andKw: F(A),
19528
- expr2: [Y(N, { leading: S })]
19562
+ expr2: [Y(I, { leading: S })]
19529
19563
  })
19530
19564
  },
19531
19565
  { name: "case_expression$ebnf$1", symbols: ["expression_chain_"], postprocess: vE },
@@ -19595,14 +19629,14 @@ const c = new te((T) => []), $ = ([[T]]) => T, F = (T) => ({
19595
19629
  {
19596
19630
  name: "data_type",
19597
19631
  symbols: ["data_type$subexpression$1"],
19598
- postprocess: ([[T]]) => gT(T)
19632
+ postprocess: ([[T]]) => KT(T)
19599
19633
  },
19600
19634
  {
19601
19635
  name: "data_type",
19602
19636
  symbols: [c.has("RESERVED_PARAMETERIZED_DATA_TYPE") ? { type: "RESERVED_PARAMETERIZED_DATA_TYPE" } : RESERVED_PARAMETERIZED_DATA_TYPE, "_", "parenthesis"],
19603
19637
  postprocess: ([T, E, e]) => ({
19604
19638
  type: U.parameterized_data_type,
19605
- dataType: Y(gT(T), { trailing: E }),
19639
+ dataType: Y(KT(T), { trailing: E }),
19606
19640
  parenthesis: e
19607
19641
  })
19608
19642
  },
@@ -19665,18 +19699,18 @@ function CN(T) {
19665
19699
  return {
19666
19700
  parse: (A, S) => {
19667
19701
  E = S;
19668
- const { results: N } = R.feed(A);
19669
- if (N.length === 1)
19670
- return N[0];
19671
- throw N.length === 0 ? new Error("Parse error: Invalid SQL") : new Error(`Parse error: Ambiguous grammar
19672
- ${JSON.stringify(N, void 0, 2)}`);
19702
+ const { results: I } = R.feed(A);
19703
+ if (I.length === 1)
19704
+ return I[0];
19705
+ throw I.length === 0 ? new Error("Parse error: Invalid SQL") : new Error(`Parse error: Ambiguous grammar
19706
+ ${JSON.stringify(I, void 0, 2)}`);
19673
19707
  }
19674
19708
  };
19675
19709
  }
19676
- var i;
19710
+ var a;
19677
19711
  (function(T) {
19678
19712
  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";
19679
- })(i = i || (i = {}));
19713
+ })(a = a || (a = {}));
19680
19714
  class se {
19681
19715
  constructor(E) {
19682
19716
  this.indentation = E, this.items = [];
@@ -19687,26 +19721,26 @@ class se {
19687
19721
  add(...E) {
19688
19722
  for (const e of E)
19689
19723
  switch (e) {
19690
- case i.SPACE:
19691
- this.items.push(i.SPACE);
19724
+ case a.SPACE:
19725
+ this.items.push(a.SPACE);
19692
19726
  break;
19693
- case i.NO_SPACE:
19727
+ case a.NO_SPACE:
19694
19728
  this.trimHorizontalWhitespace();
19695
19729
  break;
19696
- case i.NO_NEWLINE:
19730
+ case a.NO_NEWLINE:
19697
19731
  this.trimWhitespace();
19698
19732
  break;
19699
- case i.NEWLINE:
19700
- this.trimHorizontalWhitespace(), this.addNewline(i.NEWLINE);
19733
+ case a.NEWLINE:
19734
+ this.trimHorizontalWhitespace(), this.addNewline(a.NEWLINE);
19701
19735
  break;
19702
- case i.MANDATORY_NEWLINE:
19703
- this.trimHorizontalWhitespace(), this.addNewline(i.MANDATORY_NEWLINE);
19736
+ case a.MANDATORY_NEWLINE:
19737
+ this.trimHorizontalWhitespace(), this.addNewline(a.MANDATORY_NEWLINE);
19704
19738
  break;
19705
- case i.INDENT:
19739
+ case a.INDENT:
19706
19740
  this.addIndentation();
19707
19741
  break;
19708
- case i.SINGLE_INDENT:
19709
- this.items.push(i.SINGLE_INDENT);
19742
+ case a.SINGLE_INDENT:
19743
+ this.items.push(a.SINGLE_INDENT);
19710
19744
  break;
19711
19745
  default:
19712
19746
  this.items.push(e);
@@ -19723,10 +19757,10 @@ class se {
19723
19757
  addNewline(E) {
19724
19758
  if (this.items.length > 0)
19725
19759
  switch (eE(this.items)) {
19726
- case i.NEWLINE:
19760
+ case a.NEWLINE:
19727
19761
  this.items.pop(), this.items.push(E);
19728
19762
  break;
19729
- case i.MANDATORY_NEWLINE:
19763
+ case a.MANDATORY_NEWLINE:
19730
19764
  break;
19731
19765
  default:
19732
19766
  this.items.push(E);
@@ -19735,7 +19769,7 @@ class se {
19735
19769
  }
19736
19770
  addIndentation() {
19737
19771
  for (let E = 0; E < this.indentation.getLevel(); E++)
19738
- this.items.push(i.SINGLE_INDENT);
19772
+ this.items.push(a.SINGLE_INDENT);
19739
19773
  }
19740
19774
  /**
19741
19775
  * Returns the final SQL string.
@@ -19751,20 +19785,20 @@ class se {
19751
19785
  }
19752
19786
  itemToString(E) {
19753
19787
  switch (E) {
19754
- case i.SPACE:
19788
+ case a.SPACE:
19755
19789
  return " ";
19756
- case i.NEWLINE:
19757
- case i.MANDATORY_NEWLINE:
19790
+ case a.NEWLINE:
19791
+ case a.MANDATORY_NEWLINE:
19758
19792
  return `
19759
19793
  `;
19760
- case i.SINGLE_INDENT:
19794
+ case a.SINGLE_INDENT:
19761
19795
  return this.indentation.getSingleIndent();
19762
19796
  default:
19763
19797
  return E;
19764
19798
  }
19765
19799
  }
19766
19800
  }
19767
- const rN = (T) => T === i.SPACE || T === i.SINGLE_INDENT, LN = (T) => T === i.SPACE || T === i.SINGLE_INDENT || T === i.NEWLINE;
19801
+ const rN = (T) => T === a.SPACE || T === a.SINGLE_INDENT, LN = (T) => T === a.SPACE || T === a.SINGLE_INDENT || T === a.NEWLINE;
19768
19802
  function $T(T, E) {
19769
19803
  if (E === "standard")
19770
19804
  return T;
@@ -19772,7 +19806,7 @@ function $T(T, E) {
19772
19806
  return T.length >= 10 && T.includes(" ") && ([T, ...e] = T.split(" ")), E === "tabularLeft" ? T = T.padEnd(9, " ") : T = T.padStart(9, " "), T + ["", ...e].join(" ");
19773
19807
  }
19774
19808
  function wT(T) {
19775
- return ve(T) || T === a.RESERVED_CLAUSE || T === a.RESERVED_SELECT || T === a.RESERVED_SET_OPERATION || T === a.RESERVED_JOIN || T === a.LIMIT;
19809
+ return ve(T) || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.LIMIT;
19776
19810
  }
19777
19811
  const QE = "top-level", nN = "block-level";
19778
19812
  class Ce {
@@ -19836,9 +19870,9 @@ class _N extends se {
19836
19870
  if (typeof E == "string")
19837
19871
  this.length += E.length, this.trailingSpace = !1;
19838
19872
  else {
19839
- if (E === i.MANDATORY_NEWLINE || E === i.NEWLINE)
19873
+ if (E === a.MANDATORY_NEWLINE || E === a.NEWLINE)
19840
19874
  throw new qE();
19841
- E === i.INDENT || E === i.SINGLE_INDENT || E === i.SPACE ? this.trailingSpace || (this.length++, this.trailingSpace = !0) : (E === i.NO_NEWLINE || E === i.NO_SPACE) && this.trailingSpace && (this.trailingSpace = !1, this.length--);
19875
+ E === a.INDENT || E === a.SINGLE_INDENT || E === a.SPACE ? this.trailingSpace || (this.length++, this.trailingSpace = !0) : (E === a.NO_NEWLINE || E === a.NO_SPACE) && this.trailingSpace && (this.trailingSpace = !1, this.length--);
19842
19876
  }
19843
19877
  }
19844
19878
  }
@@ -19934,23 +19968,23 @@ class LE {
19934
19968
  }), this.formatNode(E.parenthesis);
19935
19969
  }
19936
19970
  formatPropertyAccess(E) {
19937
- this.formatNode(E.object), this.layout.add(i.NO_SPACE, E.operator), this.formatNode(E.property);
19971
+ this.formatNode(E.object), this.layout.add(a.NO_SPACE, E.operator), this.formatNode(E.property);
19938
19972
  }
19939
19973
  formatParenthesis(E) {
19940
19974
  const e = this.formatInlineExpression(E.children);
19941
- e ? (this.layout.add(E.openParen), this.layout.add(...e.getLayoutItems()), this.layout.add(i.NO_SPACE, E.closeParen, i.SPACE)) : (this.layout.add(E.openParen, i.NEWLINE), j(this.cfg) ? (this.layout.add(i.INDENT), this.layout = this.formatSubExpression(E.children)) : (this.layout.indentation.increaseBlockLevel(), this.layout.add(i.INDENT), this.layout = this.formatSubExpression(E.children), this.layout.indentation.decreaseBlockLevel()), this.layout.add(i.NEWLINE, i.INDENT, E.closeParen, i.SPACE));
19975
+ e ? (this.layout.add(E.openParen), this.layout.add(...e.getLayoutItems()), this.layout.add(a.NO_SPACE, E.closeParen, a.SPACE)) : (this.layout.add(E.openParen, a.NEWLINE), j(this.cfg) ? (this.layout.add(a.INDENT), this.layout = this.formatSubExpression(E.children)) : (this.layout.indentation.increaseBlockLevel(), this.layout.add(a.INDENT), this.layout = this.formatSubExpression(E.children), this.layout.indentation.decreaseBlockLevel()), this.layout.add(a.NEWLINE, a.INDENT, E.closeParen, a.SPACE));
19942
19976
  }
19943
19977
  formatBetweenPredicate(E) {
19944
- this.layout.add(this.showKw(E.betweenKw), i.SPACE), this.layout = this.formatSubExpression(E.expr1), this.layout.add(i.NO_SPACE, i.SPACE, this.showNonTabularKw(E.andKw), i.SPACE), this.layout = this.formatSubExpression(E.expr2), this.layout.add(i.SPACE);
19978
+ this.layout.add(this.showKw(E.betweenKw), a.SPACE), this.layout = this.formatSubExpression(E.expr1), this.layout.add(a.NO_SPACE, a.SPACE, this.showNonTabularKw(E.andKw), a.SPACE), this.layout = this.formatSubExpression(E.expr2), this.layout.add(a.SPACE);
19945
19979
  }
19946
19980
  formatCaseExpression(E) {
19947
- this.formatNode(E.caseKw), this.layout.indentation.increaseBlockLevel(), this.layout = this.formatSubExpression(E.expr), this.layout = this.formatSubExpression(E.clauses), this.layout.indentation.decreaseBlockLevel(), this.layout.add(i.NEWLINE, i.INDENT), this.formatNode(E.endKw);
19981
+ this.formatNode(E.caseKw), this.layout.indentation.increaseBlockLevel(), this.layout = this.formatSubExpression(E.expr), this.layout = this.formatSubExpression(E.clauses), this.layout.indentation.decreaseBlockLevel(), this.layout.add(a.NEWLINE, a.INDENT), this.formatNode(E.endKw);
19948
19982
  }
19949
19983
  formatCaseWhen(E) {
19950
- this.layout.add(i.NEWLINE, i.INDENT), this.formatNode(E.whenKw), this.layout = this.formatSubExpression(E.condition), this.formatNode(E.thenKw), this.layout = this.formatSubExpression(E.result);
19984
+ this.layout.add(a.NEWLINE, a.INDENT), this.formatNode(E.whenKw), this.layout = this.formatSubExpression(E.condition), this.formatNode(E.thenKw), this.layout = this.formatSubExpression(E.result);
19951
19985
  }
19952
19986
  formatCaseElse(E) {
19953
- this.layout.add(i.NEWLINE, i.INDENT), this.formatNode(E.elseKw), this.layout = this.formatSubExpression(E.result);
19987
+ this.layout.add(a.NEWLINE, a.INDENT), this.formatNode(E.elseKw), this.layout = this.formatSubExpression(E.result);
19954
19988
  }
19955
19989
  formatClause(E) {
19956
19990
  this.isOnelineClause(E) ? this.formatClauseInOnelineStyle(E) : j(this.cfg) ? this.formatClauseInTabularStyle(E) : this.formatClauseInIndentedStyle(E);
@@ -19959,39 +19993,39 @@ class LE {
19959
19993
  return j(this.cfg) ? this.dialectCfg.tabularOnelineClauses[E.nameKw.text] : this.dialectCfg.onelineClauses[E.nameKw.text];
19960
19994
  }
19961
19995
  formatClauseInIndentedStyle(E) {
19962
- this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E.nameKw), i.NEWLINE), this.layout.indentation.increaseTopLevel(), this.layout.add(i.INDENT), this.layout = this.formatSubExpression(E.children), this.layout.indentation.decreaseTopLevel();
19996
+ this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E.nameKw), a.NEWLINE), this.layout.indentation.increaseTopLevel(), this.layout.add(a.INDENT), this.layout = this.formatSubExpression(E.children), this.layout.indentation.decreaseTopLevel();
19963
19997
  }
19964
19998
  formatClauseInOnelineStyle(E) {
19965
- this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E.nameKw), i.SPACE), this.layout = this.formatSubExpression(E.children);
19999
+ this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E.nameKw), a.SPACE), this.layout = this.formatSubExpression(E.children);
19966
20000
  }
19967
20001
  formatClauseInTabularStyle(E) {
19968
- this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E.nameKw), i.SPACE), this.layout.indentation.increaseTopLevel(), this.layout = this.formatSubExpression(E.children), this.layout.indentation.decreaseTopLevel();
20002
+ this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E.nameKw), a.SPACE), this.layout.indentation.increaseTopLevel(), this.layout = this.formatSubExpression(E.children), this.layout.indentation.decreaseTopLevel();
19969
20003
  }
19970
20004
  formatSetOperation(E) {
19971
- this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E.nameKw), i.NEWLINE), this.layout.add(i.INDENT), this.layout = this.formatSubExpression(E.children);
20005
+ this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E.nameKw), a.NEWLINE), this.layout.add(a.INDENT), this.layout = this.formatSubExpression(E.children);
19972
20006
  }
19973
20007
  formatLimitClause(E) {
19974
20008
  this.withComments(E.limitKw, () => {
19975
- this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E.limitKw));
19976
- }), this.layout.indentation.increaseTopLevel(), j(this.cfg) ? this.layout.add(i.SPACE) : this.layout.add(i.NEWLINE, i.INDENT), E.offset ? (this.layout = this.formatSubExpression(E.offset), this.layout.add(i.NO_SPACE, ",", i.SPACE), this.layout = this.formatSubExpression(E.count)) : this.layout = this.formatSubExpression(E.count), this.layout.indentation.decreaseTopLevel();
20009
+ this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E.limitKw));
20010
+ }), this.layout.indentation.increaseTopLevel(), j(this.cfg) ? this.layout.add(a.SPACE) : this.layout.add(a.NEWLINE, a.INDENT), E.offset ? (this.layout = this.formatSubExpression(E.offset), this.layout.add(a.NO_SPACE, ",", a.SPACE), this.layout = this.formatSubExpression(E.count)) : this.layout = this.formatSubExpression(E.count), this.layout.indentation.decreaseTopLevel();
19977
20011
  }
19978
20012
  formatAllColumnsAsterisk(E) {
19979
- this.layout.add("*", i.SPACE);
20013
+ this.layout.add("*", a.SPACE);
19980
20014
  }
19981
20015
  formatLiteral(E) {
19982
- this.layout.add(E.text, i.SPACE);
20016
+ this.layout.add(E.text, a.SPACE);
19983
20017
  }
19984
20018
  formatIdentifier(E) {
19985
- this.layout.add(this.showIdentifier(E), i.SPACE);
20019
+ this.layout.add(this.showIdentifier(E), a.SPACE);
19986
20020
  }
19987
20021
  formatParameter(E) {
19988
- this.layout.add(this.params.get(E), i.SPACE);
20022
+ this.layout.add(this.params.get(E), a.SPACE);
19989
20023
  }
19990
20024
  formatOperator({ text: E }) {
19991
- this.cfg.denseOperators || this.dialectCfg.alwaysDenseOperators.includes(E) ? this.layout.add(i.NO_SPACE, E) : E === ":" ? this.layout.add(i.NO_SPACE, E, i.SPACE) : this.layout.add(E, i.SPACE);
20025
+ this.cfg.denseOperators || this.dialectCfg.alwaysDenseOperators.includes(E) ? this.layout.add(a.NO_SPACE, E) : E === ":" ? this.layout.add(a.NO_SPACE, E, a.SPACE) : this.layout.add(E, a.SPACE);
19992
20026
  }
19993
20027
  formatComma(E) {
19994
- this.inline ? this.layout.add(i.NO_SPACE, ",", i.SPACE) : this.layout.add(i.NO_SPACE, ",", i.NEWLINE, i.INDENT);
20028
+ this.inline ? this.layout.add(a.NO_SPACE, ",", a.SPACE) : this.layout.add(a.NO_SPACE, ",", a.NEWLINE, a.INDENT);
19995
20029
  }
19996
20030
  withComments(E, e) {
19997
20031
  this.formatComments(E.leadingComments), e(), this.formatComments(E.trailingComments);
@@ -20002,12 +20036,12 @@ class LE {
20002
20036
  });
20003
20037
  }
20004
20038
  formatLineComment(E) {
20005
- JE(E.precedingWhitespace || "") ? this.layout.add(i.NEWLINE, i.INDENT, E.text, i.MANDATORY_NEWLINE, i.INDENT) : this.layout.getLayoutItems().length > 0 ? this.layout.add(i.NO_NEWLINE, i.SPACE, E.text, i.MANDATORY_NEWLINE, i.INDENT) : this.layout.add(E.text, i.MANDATORY_NEWLINE, i.INDENT);
20039
+ JE(E.precedingWhitespace || "") ? this.layout.add(a.NEWLINE, a.INDENT, E.text, a.MANDATORY_NEWLINE, a.INDENT) : this.layout.getLayoutItems().length > 0 ? this.layout.add(a.NO_NEWLINE, a.SPACE, E.text, a.MANDATORY_NEWLINE, a.INDENT) : this.layout.add(E.text, a.MANDATORY_NEWLINE, a.INDENT);
20006
20040
  }
20007
20041
  formatBlockComment(E) {
20008
20042
  E.type === U.block_comment && this.isMultilineBlockComment(E) ? (this.splitBlockComment(E.text).forEach((e) => {
20009
- this.layout.add(i.NEWLINE, i.INDENT, e);
20010
- }), this.layout.add(i.NEWLINE, i.INDENT)) : this.layout.add(E.text, i.SPACE);
20043
+ this.layout.add(a.NEWLINE, a.INDENT, e);
20044
+ }), this.layout.add(a.NEWLINE, a.INDENT)) : this.layout.add(E.text, a.SPACE);
20011
20045
  }
20012
20046
  isMultilineBlockComment(E) {
20013
20047
  return JE(E.text) || JE(E.precedingWhitespace || "");
@@ -20080,27 +20114,27 @@ class LE {
20080
20114
  }
20081
20115
  formatKeywordNode(E) {
20082
20116
  switch (E.tokenType) {
20083
- case a.RESERVED_JOIN:
20117
+ case D.RESERVED_JOIN:
20084
20118
  return this.formatJoin(E);
20085
- case a.AND:
20086
- case a.OR:
20087
- case a.XOR:
20119
+ case D.AND:
20120
+ case D.OR:
20121
+ case D.XOR:
20088
20122
  return this.formatLogicalOperator(E);
20089
20123
  default:
20090
20124
  return this.formatKeyword(E);
20091
20125
  }
20092
20126
  }
20093
20127
  formatJoin(E) {
20094
- j(this.cfg) ? (this.layout.indentation.decreaseTopLevel(), this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E), i.SPACE), this.layout.indentation.increaseTopLevel()) : this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E), i.SPACE);
20128
+ j(this.cfg) ? (this.layout.indentation.decreaseTopLevel(), this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E), a.SPACE), this.layout.indentation.increaseTopLevel()) : this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E), a.SPACE);
20095
20129
  }
20096
20130
  formatKeyword(E) {
20097
- this.layout.add(this.showKw(E), i.SPACE);
20131
+ this.layout.add(this.showKw(E), a.SPACE);
20098
20132
  }
20099
20133
  formatLogicalOperator(E) {
20100
- this.cfg.logicalOperatorNewline === "before" ? j(this.cfg) ? (this.layout.indentation.decreaseTopLevel(), this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E), i.SPACE), this.layout.indentation.increaseTopLevel()) : this.layout.add(i.NEWLINE, i.INDENT, this.showKw(E), i.SPACE) : this.layout.add(this.showKw(E), i.NEWLINE, i.INDENT);
20134
+ this.cfg.logicalOperatorNewline === "before" ? j(this.cfg) ? (this.layout.indentation.decreaseTopLevel(), this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E), a.SPACE), this.layout.indentation.increaseTopLevel()) : this.layout.add(a.NEWLINE, a.INDENT, this.showKw(E), a.SPACE) : this.layout.add(this.showKw(E), a.NEWLINE, a.INDENT);
20101
20135
  }
20102
20136
  formatDataType(E) {
20103
- this.layout.add(this.showDataType(E), i.SPACE);
20137
+ this.layout.add(this.showDataType(E), a.SPACE);
20104
20138
  }
20105
20139
  showKw(E) {
20106
20140
  return wT(E.tokenType) ? $T(this.showNonTabularKw(E), this.cfg.indentStyle) : this.showNonTabularKw(E);
@@ -20180,7 +20214,7 @@ class iN {
20180
20214
  params: this.params,
20181
20215
  layout: new se(new Ce(xI(this.cfg)))
20182
20216
  }).format(E.children);
20183
- return E.hasSemicolon && (this.cfg.newlineBeforeSemicolon ? e.add(i.NEWLINE, ";") : e.add(i.NO_NEWLINE, ";")), e.toString();
20217
+ return E.hasSemicolon && (this.cfg.newlineBeforeSemicolon ? e.add(a.NEWLINE, ";") : e.add(a.NO_NEWLINE, ";")), e.toString();
20184
20218
  }
20185
20219
  }
20186
20220
  class tE extends Error {
@@ -20309,34 +20343,34 @@ async function BN(T, E, e) {
20309
20343
  if (!R.isValid)
20310
20344
  throw new Error(`Query validation failed: ${R.errors.join(", ")}`);
20311
20345
  const A = /* @__PURE__ */ new Set();
20312
- T.measures?.forEach((C) => {
20313
- const O = C.split(".")[0];
20346
+ T.measures?.forEach((s) => {
20347
+ const O = s.split(".")[0];
20314
20348
  A.add(O);
20315
- }), T.dimensions?.forEach((C) => {
20316
- const O = C.split(".")[0];
20349
+ }), T.dimensions?.forEach((s) => {
20350
+ const O = s.split(".")[0];
20317
20351
  A.add(O);
20318
- }), T.timeDimensions?.forEach((C) => {
20319
- const O = C.dimension.split(".")[0];
20352
+ }), T.timeDimensions?.forEach((s) => {
20353
+ const O = s.dimension.split(".")[0];
20320
20354
  A.add(O);
20321
- }), T.filters?.forEach((C) => {
20322
- if ("member" in C) {
20323
- const O = C.member.split(".")[0];
20355
+ }), T.filters?.forEach((s) => {
20356
+ if ("member" in s) {
20357
+ const O = s.member.split(".")[0];
20324
20358
  A.add(O);
20325
20359
  }
20326
20360
  });
20327
20361
  const S = A.size > 1;
20328
- let N;
20362
+ let I;
20329
20363
  if (S)
20330
- N = await e.generateMultiCubeSQL(T, E);
20364
+ I = await e.generateMultiCubeSQL(T, E);
20331
20365
  else {
20332
- const C = Array.from(A)[0];
20333
- N = await e.generateSQL(C, T, E);
20366
+ const s = Array.from(A)[0];
20367
+ I = await e.generateSQL(s, T, E);
20334
20368
  }
20335
- const t = Array.from(A).map((C) => ({
20336
- cube: C,
20369
+ const t = Array.from(A).map((s) => ({
20370
+ cube: s,
20337
20371
  query: {
20338
- measures: T.measures?.filter((O) => O.startsWith(C + ".")) || [],
20339
- dimensions: T.dimensions?.filter((O) => O.startsWith(C + ".")) || [],
20372
+ measures: T.measures?.filter((O) => O.startsWith(s + ".")) || [],
20373
+ dimensions: T.dimensions?.filter((O) => O.startsWith(s + ".")) || [],
20340
20374
  filters: T.filters || [],
20341
20375
  timeDimensions: T.timeDimensions || [],
20342
20376
  order: T.order || {},
@@ -20354,8 +20388,8 @@ async function BN(T, E, e) {
20354
20388
  cubes: Array.from(A)
20355
20389
  },
20356
20390
  sql: {
20357
- sql: [N.sql],
20358
- params: N.params || []
20391
+ sql: [I.sql],
20392
+ params: I.params || []
20359
20393
  },
20360
20394
  complexity: uN(T),
20361
20395
  valid: !0,
@@ -20365,14 +20399,14 @@ async function BN(T, E, e) {
20365
20399
  };
20366
20400
  }
20367
20401
  function pN(T, E, e) {
20368
- const R = HN(e), A = GN(), S = (/* @__PURE__ */ new Date()).toISOString(), N = mN(T);
20402
+ const R = HN(e), A = GN(), S = (/* @__PURE__ */ new Date()).toISOString(), I = mN(T);
20369
20403
  return {
20370
20404
  queryType: "regularQuery",
20371
20405
  results: [{
20372
20406
  query: T,
20373
20407
  lastRefreshTime: S,
20374
20408
  usedPreAggregations: {},
20375
- transformedQuery: N,
20409
+ transformedQuery: I,
20376
20410
  requestId: A,
20377
20411
  annotation: E.annotation,
20378
20412
  dataSource: "default",
@@ -20491,13 +20525,13 @@ class dN {
20491
20525
  );
20492
20526
  continue;
20493
20527
  }
20494
- const N = new Map(this.cubes);
20495
- N.set(E.name, E);
20496
- const t = new J(N);
20528
+ const I = new Map(this.cubes);
20529
+ I.set(E.name, E);
20530
+ const t = new J(I);
20497
20531
  try {
20498
20532
  t.validateDependencies(E);
20499
- } catch (C) {
20500
- e.push(C instanceof Error ? C.message : String(C));
20533
+ } catch (s) {
20534
+ e.push(s instanceof Error ? s.message : String(s));
20501
20535
  }
20502
20536
  }
20503
20537
  if (e.length === 0) {
@@ -20591,11 +20625,11 @@ ${e.join(`
20591
20625
  generateCubeMetadata(E) {
20592
20626
  const e = Object.keys(E.measures), R = Object.keys(E.dimensions), A = new Array(e.length), S = new Array(R.length);
20593
20627
  for (let t = 0; t < e.length; t++) {
20594
- const C = e[t], O = E.measures[C];
20628
+ const s = e[t], O = E.measures[s];
20595
20629
  A[t] = {
20596
- name: `${E.name}.${C}`,
20597
- title: O.title || C,
20598
- shortTitle: O.title || C,
20630
+ name: `${E.name}.${s}`,
20631
+ title: O.title || s,
20632
+ shortTitle: O.title || s,
20599
20633
  type: O.type,
20600
20634
  format: void 0,
20601
20635
  // Measure doesn't have format field
@@ -20603,23 +20637,23 @@ ${e.join(`
20603
20637
  };
20604
20638
  }
20605
20639
  for (let t = 0; t < R.length; t++) {
20606
- const C = R[t], O = E.dimensions[C];
20640
+ const s = R[t], O = E.dimensions[s];
20607
20641
  S[t] = {
20608
- name: `${E.name}.${C}`,
20609
- title: O.title || C,
20610
- shortTitle: O.title || C,
20642
+ name: `${E.name}.${s}`,
20643
+ title: O.title || s,
20644
+ shortTitle: O.title || s,
20611
20645
  type: O.type,
20612
20646
  format: void 0,
20613
20647
  // Dimension doesn't have format field
20614
20648
  description: O.description
20615
20649
  };
20616
20650
  }
20617
- const N = [];
20651
+ const I = [];
20618
20652
  if (E.joins)
20619
20653
  for (const [, t] of Object.entries(E.joins)) {
20620
- const C = typeof t.targetCube == "function" ? t.targetCube() : t.targetCube;
20621
- N.push({
20622
- targetCube: C.name,
20654
+ const s = typeof t.targetCube == "function" ? t.targetCube() : t.targetCube;
20655
+ I.push({
20656
+ targetCube: s.name,
20623
20657
  relationship: t.relationship,
20624
20658
  joinFields: t.on.map((O) => ({
20625
20659
  sourceField: this.getColumnName(O.source),
@@ -20635,7 +20669,7 @@ ${e.join(`
20635
20669
  dimensions: S,
20636
20670
  segments: [],
20637
20671
  // Add segments support later if needed
20638
- relationships: N.length > 0 ? N : void 0
20672
+ relationships: I.length > 0 ? I : void 0
20639
20673
  };
20640
20674
  }
20641
20675
  /**
@@ -20647,10 +20681,10 @@ ${e.join(`
20647
20681
  throw new Error(`Cube '${E}' not found`);
20648
20682
  if (!this.dbExecutor)
20649
20683
  throw new Error("Database executor not configured");
20650
- const N = await new GE(this.dbExecutor).generateSQL(A, e, R), t = this.dbExecutor.getEngineType();
20684
+ const I = await new GE(this.dbExecutor).generateSQL(A, e, R), t = this.dbExecutor.getEngineType();
20651
20685
  return {
20652
- sql: JT(N.sql, t),
20653
- params: N.params
20686
+ sql: JT(I.sql, t),
20687
+ params: I.params
20654
20688
  };
20655
20689
  }
20656
20690
  /**
@@ -20709,8 +20743,8 @@ function Le(T, E) {
20709
20743
  const e = [], R = /* @__PURE__ */ new Set();
20710
20744
  if (E.measures)
20711
20745
  for (const A of E.measures) {
20712
- const [S, N] = A.split(".");
20713
- if (!S || !N) {
20746
+ const [S, I] = A.split(".");
20747
+ if (!S || !I) {
20714
20748
  e.push(`Invalid measure format: ${A}. Expected format: 'CubeName.fieldName'`);
20715
20749
  continue;
20716
20750
  }
@@ -20720,12 +20754,12 @@ function Le(T, E) {
20720
20754
  e.push(`Cube '${S}' not found (referenced in measure '${A}')`);
20721
20755
  continue;
20722
20756
  }
20723
- t.measures[N] || e.push(`Measure '${N}' not found on cube '${S}'`);
20757
+ t.measures[I] || e.push(`Measure '${I}' not found on cube '${S}'`);
20724
20758
  }
20725
20759
  if (E.dimensions)
20726
20760
  for (const A of E.dimensions) {
20727
- const [S, N] = A.split(".");
20728
- if (!S || !N) {
20761
+ const [S, I] = A.split(".");
20762
+ if (!S || !I) {
20729
20763
  e.push(`Invalid dimension format: ${A}. Expected format: 'CubeName.fieldName'`);
20730
20764
  continue;
20731
20765
  }
@@ -20735,12 +20769,12 @@ function Le(T, E) {
20735
20769
  e.push(`Cube '${S}' not found (referenced in dimension '${A}')`);
20736
20770
  continue;
20737
20771
  }
20738
- t.dimensions[N] || e.push(`Dimension '${N}' not found on cube '${S}'`);
20772
+ t.dimensions[I] || e.push(`Dimension '${I}' not found on cube '${S}'`);
20739
20773
  }
20740
20774
  if (E.timeDimensions)
20741
20775
  for (const A of E.timeDimensions) {
20742
- const [S, N] = A.dimension.split(".");
20743
- if (!S || !N) {
20776
+ const [S, I] = A.dimension.split(".");
20777
+ if (!S || !I) {
20744
20778
  e.push(`Invalid timeDimension format: ${A.dimension}. Expected format: 'CubeName.fieldName'`);
20745
20779
  continue;
20746
20780
  }
@@ -20750,7 +20784,7 @@ function Le(T, E) {
20750
20784
  e.push(`Cube '${S}' not found (referenced in timeDimension '${A.dimension}')`);
20751
20785
  continue;
20752
20786
  }
20753
- t.dimensions[N] || e.push(`TimeDimension '${N}' not found on cube '${S}' (must be a dimension with time type)`);
20787
+ t.dimensions[I] || e.push(`TimeDimension '${I}' not found on cube '${S}' (must be a dimension with time type)`);
20754
20788
  }
20755
20789
  if (E.filters)
20756
20790
  for (const A of E.filters)
@@ -20763,8 +20797,8 @@ function Le(T, E) {
20763
20797
  function ne(T, E, e, R) {
20764
20798
  if ("and" in T || "or" in T) {
20765
20799
  const t = T.and || T.or || [];
20766
- for (const C of t)
20767
- ne(C, E, e, R);
20800
+ for (const s of t)
20801
+ ne(s, E, e, R);
20768
20802
  return;
20769
20803
  }
20770
20804
  if (!("member" in T)) {
@@ -20777,12 +20811,12 @@ function ne(T, E, e, R) {
20777
20811
  return;
20778
20812
  }
20779
20813
  R.add(A);
20780
- const N = E.get(A);
20781
- if (!N) {
20814
+ const I = E.get(A);
20815
+ if (!I) {
20782
20816
  e.push(`Cube '${A}' not found (referenced in filter '${T.member}')`);
20783
20817
  return;
20784
20818
  }
20785
- !N.dimensions[S] && !N.measures[S] && e.push(`Filter field '${S}' not found on cube '${A}' (must be a dimension or measure)`);
20819
+ !I.dimensions[S] && !I.measures[S] && e.push(`Filter field '${S}' not found on cube '${A}' (must be a dimension or measure)`);
20786
20820
  }
20787
20821
  new dN();
20788
20822
  export {