drizzle-cube 0.2.17 → 0.2.18

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.
@@ -175,7 +175,7 @@ class p {
175
175
  casing: A,
176
176
  escapeName: t,
177
177
  escapeParam: S,
178
- prepareTyping: r,
178
+ prepareTyping: O,
179
179
  inlineParams: C,
180
180
  paramStartIndex: N
181
181
  } = R;
@@ -230,7 +230,7 @@ class p {
230
230
  if (C)
231
231
  return { sql: this.mapInlineParam(I, R), params: [] };
232
232
  let n = ["none"];
233
- return r && (n = [r(s.encoder)]), { sql: S(N.value++, I), params: [I], typings: n };
233
+ return O && (n = [O(s.encoder)]), { sql: S(N.value++, I), params: [I], typings: n };
234
234
  }
235
235
  return H(s, iE) ? { sql: S(N.value++, s), params: [s], typings: ["none"] } : H(s, p.Aliased) && s.fieldAlias !== void 0 ? { sql: t(s.fieldAlias), params: [] } : H(s, kT) ? s._.isWith ? { sql: t(s._.alias), params: [] } : this.buildQueryFromSourceParams([
236
236
  new V("("),
@@ -315,7 +315,7 @@ class CE {
315
315
  return new p([this]);
316
316
  }
317
317
  }
318
- function O(e, ...E) {
318
+ function r(e, ...E) {
319
319
  const T = [];
320
320
  (E.length > 0 || e.length > 0 && e[0] !== "") && T.push(new V(e[0]));
321
321
  for (const [R, A] of E.entries())
@@ -350,11 +350,11 @@ function O(e, ...E) {
350
350
  return new iE(C);
351
351
  }
352
352
  e.placeholder = S;
353
- function r(C, N) {
353
+ function O(C, N) {
354
354
  return new CE(C, N);
355
355
  }
356
- e.param = r;
357
- })(O || (O = {}));
356
+ e.param = O;
357
+ })(r || (r = {}));
358
358
  ((e) => {
359
359
  class E {
360
360
  constructor(R, A) {
@@ -416,7 +416,7 @@ kT.prototype.getSQL = function() {
416
416
  function b(e, E) {
417
417
  return me(E) && !zT(e) && !H(e, CE) && !H(e, iE) && !H(e, AE) && !H(e, g) && !H(e, ee) ? new CE(e, E) : e;
418
418
  }
419
- const v = (e, E) => O`${e} = ${b(E, e)}`, rT = (e, E) => O`${e} <> ${b(E, e)}`;
419
+ const v = (e, E) => r`${e} = ${b(E, e)}`, rT = (e, E) => r`${e} <> ${b(E, e)}`;
420
420
  function F(...e) {
421
421
  const E = e.filter(
422
422
  (T) => T !== void 0
@@ -424,7 +424,7 @@ function F(...e) {
424
424
  if (E.length !== 0)
425
425
  return E.length === 1 ? new p(E) : new p([
426
426
  new V("("),
427
- O.join(E, new V(" and ")),
427
+ r.join(E, new V(" and ")),
428
428
  new V(")")
429
429
  ]);
430
430
  }
@@ -435,70 +435,70 @@ function tE(...e) {
435
435
  if (E.length !== 0)
436
436
  return E.length === 1 ? new p(E) : new p([
437
437
  new V("("),
438
- O.join(E, new V(" or ")),
438
+ r.join(E, new V(" or ")),
439
439
  new V(")")
440
440
  ]);
441
441
  }
442
- const uE = (e, E) => O`${e} > ${b(E, e)}`, k = (e, E) => O`${e} >= ${b(E, e)}`, cE = (e, E) => O`${e} < ${b(E, e)}`, z = (e, E) => O`${e} <= ${b(E, e)}`;
442
+ const uE = (e, E) => r`${e} > ${b(E, e)}`, k = (e, E) => r`${e} >= ${b(E, e)}`, cE = (e, E) => r`${e} < ${b(E, e)}`, z = (e, E) => r`${e} <= ${b(E, e)}`;
443
443
  function GE(e, E) {
444
- return Array.isArray(E) ? E.length === 0 ? O`false` : O`${e} in ${E.map((T) => b(T, e))}` : O`${e} in ${b(E, e)}`;
444
+ return Array.isArray(E) ? E.length === 0 ? r`false` : r`${e} in ${E.map((T) => b(T, e))}` : r`${e} in ${b(E, e)}`;
445
445
  }
446
446
  function nT(e, E) {
447
- return Array.isArray(E) ? E.length === 0 ? O`true` : O`${e} not in ${E.map((T) => b(T, e))}` : O`${e} not in ${b(E, e)}`;
447
+ return Array.isArray(E) ? E.length === 0 ? r`true` : r`${e} not in ${E.map((T) => b(T, e))}` : r`${e} not in ${b(E, e)}`;
448
448
  }
449
449
  function CT(e) {
450
- return O`${e} is null`;
450
+ return r`${e} is null`;
451
451
  }
452
452
  function iT(e) {
453
- return O`${e} is not null`;
453
+ return r`${e} is not null`;
454
454
  }
455
455
  function Be(e, E) {
456
456
  if (Array.isArray(E)) {
457
457
  if (E.length === 0)
458
458
  throw new Error("arrayContains requires at least one value");
459
- const T = O`${b(E, e)}`;
460
- return O`${e} @> ${T}`;
459
+ const T = r`${b(E, e)}`;
460
+ return r`${e} @> ${T}`;
461
461
  }
462
- return O`${e} @> ${b(E, e)}`;
462
+ return r`${e} @> ${b(E, e)}`;
463
463
  }
464
464
  function He(e, E) {
465
465
  if (Array.isArray(E)) {
466
466
  if (E.length === 0)
467
467
  throw new Error("arrayContained requires at least one value");
468
- const T = O`${b(E, e)}`;
469
- return O`${e} <@ ${T}`;
468
+ const T = r`${b(E, e)}`;
469
+ return r`${e} <@ ${T}`;
470
470
  }
471
- return O`${e} <@ ${b(E, e)}`;
471
+ return r`${e} <@ ${b(E, e)}`;
472
472
  }
473
473
  function fe(e, E) {
474
474
  if (Array.isArray(E)) {
475
475
  if (E.length === 0)
476
476
  throw new Error("arrayOverlaps requires at least one value");
477
- const T = O`${b(E, e)}`;
478
- return O`${e} && ${T}`;
477
+ const T = r`${b(E, e)}`;
478
+ return r`${e} && ${T}`;
479
479
  }
480
- return O`${e} && ${b(E, e)}`;
480
+ return r`${e} && ${b(E, e)}`;
481
481
  }
482
482
  function LT(e) {
483
- return O`${e} asc`;
483
+ return r`${e} asc`;
484
484
  }
485
485
  function Fe(e) {
486
- return O`${e} desc`;
486
+ return r`${e} desc`;
487
487
  }
488
488
  function kE(e) {
489
- return O`count(${e || O.raw("*")})`.mapWith(Number);
489
+ return r`count(${e || r.raw("*")})`.mapWith(Number);
490
490
  }
491
491
  function he(e) {
492
- return O`count(distinct ${e})`.mapWith(Number);
492
+ return r`count(distinct ${e})`.mapWith(Number);
493
493
  }
494
494
  function $(e) {
495
- return O`sum(${e})`.mapWith(String);
495
+ return r`sum(${e})`.mapWith(String);
496
496
  }
497
497
  function SE(e) {
498
- return O`max(${e})`.mapWith(H(e, AE) ? e : String);
498
+ return r`max(${e})`.mapWith(H(e, AE) ? e : String);
499
499
  }
500
500
  function sE(e) {
501
- return O`min(${e})`.mapWith(H(e, AE) ? e : String);
501
+ return r`min(${e})`.mapWith(H(e, AE) ? e : String);
502
502
  }
503
503
  class RT {
504
504
  /**
@@ -537,21 +537,21 @@ class Ye extends RT {
537
537
  buildTimeDimension(E, T) {
538
538
  switch (E) {
539
539
  case "year":
540
- return O`DATE_TRUNC('year', ${T}::timestamp)`;
540
+ return r`DATE_TRUNC('year', ${T}::timestamp)`;
541
541
  case "quarter":
542
- return O`DATE_TRUNC('quarter', ${T}::timestamp)`;
542
+ return r`DATE_TRUNC('quarter', ${T}::timestamp)`;
543
543
  case "month":
544
- return O`DATE_TRUNC('month', ${T}::timestamp)`;
544
+ return r`DATE_TRUNC('month', ${T}::timestamp)`;
545
545
  case "week":
546
- return O`DATE_TRUNC('week', ${T}::timestamp)`;
546
+ return r`DATE_TRUNC('week', ${T}::timestamp)`;
547
547
  case "day":
548
- return O`DATE_TRUNC('day', ${T}::timestamp)::timestamp`;
548
+ return r`DATE_TRUNC('day', ${T}::timestamp)::timestamp`;
549
549
  case "hour":
550
- return O`DATE_TRUNC('hour', ${T}::timestamp)`;
550
+ return r`DATE_TRUNC('hour', ${T}::timestamp)`;
551
551
  case "minute":
552
- return O`DATE_TRUNC('minute', ${T}::timestamp)`;
552
+ return r`DATE_TRUNC('minute', ${T}::timestamp)`;
553
553
  case "second":
554
- return O`DATE_TRUNC('second', ${T}::timestamp)`;
554
+ return r`DATE_TRUNC('second', ${T}::timestamp)`;
555
555
  default:
556
556
  return T;
557
557
  }
@@ -563,23 +563,23 @@ class Ye extends RT {
563
563
  buildStringCondition(E, T, R) {
564
564
  switch (T) {
565
565
  case "contains":
566
- return O`${E} ILIKE ${`%${R}%`}`;
566
+ return r`${E} ILIKE ${`%${R}%`}`;
567
567
  case "notContains":
568
- return O`${E} NOT ILIKE ${`%${R}%`}`;
568
+ return r`${E} NOT ILIKE ${`%${R}%`}`;
569
569
  case "startsWith":
570
- return O`${E} ILIKE ${`${R}%`}`;
570
+ return r`${E} ILIKE ${`${R}%`}`;
571
571
  case "endsWith":
572
- return O`${E} ILIKE ${`%${R}`}`;
572
+ return r`${E} ILIKE ${`%${R}`}`;
573
573
  case "like":
574
- return O`${E} LIKE ${R}`;
574
+ return r`${E} LIKE ${R}`;
575
575
  case "notLike":
576
- return O`${E} NOT LIKE ${R}`;
576
+ return r`${E} NOT LIKE ${R}`;
577
577
  case "ilike":
578
- return O`${E} ILIKE ${R}`;
578
+ return r`${E} ILIKE ${R}`;
579
579
  case "regex":
580
- return O`${E} ~* ${R}`;
580
+ return r`${E} ~* ${R}`;
581
581
  case "notRegex":
582
- return O`${E} !~* ${R}`;
582
+ return r`${E} !~* ${R}`;
583
583
  default:
584
584
  throw new Error(`Unsupported string operator: ${T}`);
585
585
  }
@@ -591,11 +591,11 @@ class Ye extends RT {
591
591
  castToType(E, T) {
592
592
  switch (T) {
593
593
  case "timestamp":
594
- return O`${E}::timestamp`;
594
+ return r`${E}::timestamp`;
595
595
  case "decimal":
596
- return O`${E}::decimal`;
596
+ return r`${E}::decimal`;
597
597
  case "integer":
598
- return O`${E}::integer`;
598
+ return r`${E}::integer`;
599
599
  default:
600
600
  throw new Error(`Unsupported cast type: ${T}`);
601
601
  }
@@ -606,21 +606,21 @@ class Ye extends RT {
606
606
  * Extracted from multi-cube-builder.ts:284
607
607
  */
608
608
  buildAvg(E) {
609
- return O`COALESCE(AVG(${E}), 0)`;
609
+ return r`COALESCE(AVG(${E}), 0)`;
610
610
  }
611
611
  /**
612
612
  * Build PostgreSQL CASE WHEN conditional expression
613
613
  */
614
614
  buildCaseWhen(E, T) {
615
- const R = E.map((A) => O`WHEN ${A.when} THEN ${A.then}`).reduce((A, t) => O`${A} ${t}`);
616
- return T !== void 0 ? O`CASE ${R} ELSE ${T} END` : O`CASE ${R} END`;
615
+ const R = E.map((A) => r`WHEN ${A.when} THEN ${A.then}`).reduce((A, t) => r`${A} ${t}`);
616
+ return T !== void 0 ? r`CASE ${R} ELSE ${T} END` : r`CASE ${R} END`;
617
617
  }
618
618
  /**
619
619
  * Build PostgreSQL boolean literal
620
620
  * PostgreSQL uses TRUE/FALSE keywords
621
621
  */
622
622
  buildBooleanLiteral(E) {
623
- return E ? O`TRUE` : O`FALSE`;
623
+ return E ? r`TRUE` : r`FALSE`;
624
624
  }
625
625
  /**
626
626
  * Convert filter values - PostgreSQL uses native types
@@ -670,7 +670,7 @@ class Ye extends RT {
670
670
  */
671
671
  buildStddev(E, T = !1) {
672
672
  const R = T ? "STDDEV_SAMP" : "STDDEV_POP";
673
- return O`COALESCE(${O.raw(R)}(${E}), 0)`;
673
+ return r`COALESCE(${r.raw(R)}(${E}), 0)`;
674
674
  }
675
675
  /**
676
676
  * Build PostgreSQL VARIANCE aggregation
@@ -678,7 +678,7 @@ class Ye extends RT {
678
678
  */
679
679
  buildVariance(E, T = !1) {
680
680
  const R = T ? "VAR_SAMP" : "VAR_POP";
681
- return O`COALESCE(${O.raw(R)}(${E}), 0)`;
681
+ return r`COALESCE(${r.raw(R)}(${E}), 0)`;
682
682
  }
683
683
  /**
684
684
  * Build PostgreSQL PERCENTILE_CONT aggregation
@@ -686,45 +686,45 @@ class Ye extends RT {
686
686
  */
687
687
  buildPercentile(E, T) {
688
688
  const R = T / 100;
689
- return O`PERCENTILE_CONT(${R}) WITHIN GROUP (ORDER BY ${E})`;
689
+ return r`PERCENTILE_CONT(${R}) WITHIN GROUP (ORDER BY ${E})`;
690
690
  }
691
691
  /**
692
692
  * Build PostgreSQL window function expression
693
693
  * PostgreSQL has full window function support
694
694
  */
695
695
  buildWindowFunction(E, T, R, A, t) {
696
- const S = R && R.length > 0 ? O`PARTITION BY ${O.join(R, O`, `)}` : O``, r = A && A.length > 0 ? O`ORDER BY ${O.join(A.map(
697
- (n) => n.direction === "desc" ? O`${n.field} DESC` : O`${n.field} ASC`
698
- ), O`, `)}` : O``;
699
- let C = O``;
696
+ const S = R && R.length > 0 ? r`PARTITION BY ${r.join(R, r`, `)}` : r``, O = A && A.length > 0 ? r`ORDER BY ${r.join(A.map(
697
+ (n) => n.direction === "desc" ? r`${n.field} DESC` : r`${n.field} ASC`
698
+ ), r`, `)}` : r``;
699
+ let C = r``;
700
700
  if (t?.frame) {
701
701
  const { type: n, start: i, end: L } = t.frame, M = n.toUpperCase(), D = i === "unbounded" ? "UNBOUNDED PRECEDING" : typeof i == "number" ? `${i} PRECEDING` : "CURRENT ROW", l = L === "unbounded" ? "UNBOUNDED FOLLOWING" : L === "current" ? "CURRENT ROW" : typeof L == "number" ? `${L} FOLLOWING` : "CURRENT ROW";
702
- C = O`${O.raw(M)} BETWEEN ${O.raw(D)} AND ${O.raw(l)}`;
702
+ C = r`${r.raw(M)} BETWEEN ${r.raw(D)} AND ${r.raw(l)}`;
703
703
  }
704
704
  const N = [];
705
- R && R.length > 0 && N.push(S), A && A.length > 0 && N.push(r), t?.frame && N.push(C);
706
- const s = N.length > 0 ? O.join(N, O` `) : O``, I = O`OVER (${s})`;
705
+ R && R.length > 0 && N.push(S), A && A.length > 0 && N.push(O), t?.frame && N.push(C);
706
+ const s = N.length > 0 ? r.join(N, r` `) : r``, I = r`OVER (${s})`;
707
707
  switch (E) {
708
708
  case "lag":
709
- return O`LAG(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? O`, ${t.defaultValue}` : O``}) ${I}`;
709
+ return r`LAG(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? r`, ${t.defaultValue}` : r``}) ${I}`;
710
710
  case "lead":
711
- return O`LEAD(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? O`, ${t.defaultValue}` : O``}) ${I}`;
711
+ return r`LEAD(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? r`, ${t.defaultValue}` : r``}) ${I}`;
712
712
  case "rank":
713
- return O`RANK() ${I}`;
713
+ return r`RANK() ${I}`;
714
714
  case "denseRank":
715
- return O`DENSE_RANK() ${I}`;
715
+ return r`DENSE_RANK() ${I}`;
716
716
  case "rowNumber":
717
- return O`ROW_NUMBER() ${I}`;
717
+ return r`ROW_NUMBER() ${I}`;
718
718
  case "ntile":
719
- return O`NTILE(${t?.nTile ?? 4}) ${I}`;
719
+ return r`NTILE(${t?.nTile ?? 4}) ${I}`;
720
720
  case "firstValue":
721
- return O`FIRST_VALUE(${T}) ${I}`;
721
+ return r`FIRST_VALUE(${T}) ${I}`;
722
722
  case "lastValue":
723
- return O`LAST_VALUE(${T}) ${I}`;
723
+ return r`LAST_VALUE(${T}) ${I}`;
724
724
  case "movingAvg":
725
- return O`AVG(${T}) ${I}`;
725
+ return r`AVG(${T}) ${I}`;
726
726
  case "movingSum":
727
- return O`SUM(${T}) ${I}`;
727
+ return r`SUM(${T}) ${I}`;
728
728
  default:
729
729
  throw new Error(`Unsupported window function: ${E}`);
730
730
  }
@@ -753,12 +753,12 @@ class Re extends RT {
753
753
  };
754
754
  switch (E) {
755
755
  case "quarter":
756
- return O`DATE_ADD(MAKEDATE(YEAR(${T}), 1), INTERVAL (QUARTER(${T}) - 1) * 3 MONTH)`;
756
+ return r`DATE_ADD(MAKEDATE(YEAR(${T}), 1), INTERVAL (QUARTER(${T}) - 1) * 3 MONTH)`;
757
757
  case "week":
758
- return O`DATE_SUB(${T}, INTERVAL WEEKDAY(${T}) DAY)`;
758
+ return r`DATE_SUB(${T}, INTERVAL WEEKDAY(${T}) DAY)`;
759
759
  default: {
760
760
  const A = R[E];
761
- return A ? O`STR_TO_DATE(DATE_FORMAT(${T}, ${A}), '%Y-%m-%d %H:%i:%s')` : T;
761
+ return A ? r`STR_TO_DATE(DATE_FORMAT(${T}, ${A}), '%Y-%m-%d %H:%i:%s')` : T;
762
762
  }
763
763
  }
764
764
  }
@@ -770,23 +770,23 @@ class Re extends RT {
770
770
  buildStringCondition(E, T, R) {
771
771
  switch (T) {
772
772
  case "contains":
773
- return O`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
773
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
774
774
  case "notContains":
775
- return O`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
775
+ return r`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
776
776
  case "startsWith":
777
- return O`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
777
+ return r`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
778
778
  case "endsWith":
779
- return O`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
779
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
780
780
  case "like":
781
- return O`${E} LIKE ${R}`;
781
+ return r`${E} LIKE ${R}`;
782
782
  case "notLike":
783
- return O`${E} NOT LIKE ${R}`;
783
+ return r`${E} NOT LIKE ${R}`;
784
784
  case "ilike":
785
- return O`LOWER(${E}) LIKE ${R.toLowerCase()}`;
785
+ return r`LOWER(${E}) LIKE ${R.toLowerCase()}`;
786
786
  case "regex":
787
- return O`${E} REGEXP ${R}`;
787
+ return r`${E} REGEXP ${R}`;
788
788
  case "notRegex":
789
- return O`${E} NOT REGEXP ${R}`;
789
+ return r`${E} NOT REGEXP ${R}`;
790
790
  default:
791
791
  throw new Error(`Unsupported string operator: ${T}`);
792
792
  }
@@ -798,11 +798,11 @@ class Re extends RT {
798
798
  castToType(E, T) {
799
799
  switch (T) {
800
800
  case "timestamp":
801
- return O`CAST(${E} AS DATETIME)`;
801
+ return r`CAST(${E} AS DATETIME)`;
802
802
  case "decimal":
803
- return O`CAST(${E} AS DECIMAL(10,2))`;
803
+ return r`CAST(${E} AS DECIMAL(10,2))`;
804
804
  case "integer":
805
- return O`CAST(${E} AS SIGNED INTEGER)`;
805
+ return r`CAST(${E} AS SIGNED INTEGER)`;
806
806
  default:
807
807
  throw new Error(`Unsupported cast type: ${T}`);
808
808
  }
@@ -812,21 +812,21 @@ class Re extends RT {
812
812
  * MySQL AVG returns NULL for empty sets, using IFNULL for consistency
813
813
  */
814
814
  buildAvg(E) {
815
- return O`IFNULL(AVG(${E}), 0)`;
815
+ return r`IFNULL(AVG(${E}), 0)`;
816
816
  }
817
817
  /**
818
818
  * Build MySQL CASE WHEN conditional expression
819
819
  */
820
820
  buildCaseWhen(E, T) {
821
- const R = E.map((A) => O`WHEN ${A.when} THEN ${A.then}`).reduce((A, t) => O`${A} ${t}`);
822
- return T !== void 0 ? O`CASE ${R} ELSE ${T} END` : O`CASE ${R} END`;
821
+ const R = E.map((A) => r`WHEN ${A.when} THEN ${A.then}`).reduce((A, t) => r`${A} ${t}`);
822
+ return T !== void 0 ? r`CASE ${R} ELSE ${T} END` : r`CASE ${R} END`;
823
823
  }
824
824
  /**
825
825
  * Build MySQL boolean literal
826
826
  * MySQL uses TRUE/FALSE keywords (equivalent to 1/0)
827
827
  */
828
828
  buildBooleanLiteral(E) {
829
- return E ? O`TRUE` : O`FALSE`;
829
+ return E ? r`TRUE` : r`FALSE`;
830
830
  }
831
831
  /**
832
832
  * Convert filter values - MySQL uses native types
@@ -878,7 +878,7 @@ class Re extends RT {
878
878
  */
879
879
  buildStddev(E, T = !1) {
880
880
  const R = T ? "STDDEV_SAMP" : "STDDEV_POP";
881
- return O`IFNULL(${O.raw(R)}(${E}), 0)`;
881
+ return r`IFNULL(${r.raw(R)}(${E}), 0)`;
882
882
  }
883
883
  /**
884
884
  * Build MySQL VARIANCE aggregation
@@ -886,7 +886,7 @@ class Re extends RT {
886
886
  */
887
887
  buildVariance(E, T = !1) {
888
888
  const R = T ? "VAR_SAMP" : "VAR_POP";
889
- return O`IFNULL(${O.raw(R)}(${E}), 0)`;
889
+ return r`IFNULL(${r.raw(R)}(${E}), 0)`;
890
890
  }
891
891
  /**
892
892
  * MySQL does not support PERCENTILE_CONT
@@ -900,38 +900,38 @@ class Re extends RT {
900
900
  * MySQL 8.0+ has full window function support
901
901
  */
902
902
  buildWindowFunction(E, T, R, A, t) {
903
- const S = R && R.length > 0 ? O`PARTITION BY ${O.join(R, O`, `)}` : O``, r = A && A.length > 0 ? O`ORDER BY ${O.join(A.map(
904
- (n) => n.direction === "desc" ? O`${n.field} DESC` : O`${n.field} ASC`
905
- ), O`, `)}` : O``;
906
- let C = O``;
903
+ const S = R && R.length > 0 ? r`PARTITION BY ${r.join(R, r`, `)}` : r``, O = A && A.length > 0 ? r`ORDER BY ${r.join(A.map(
904
+ (n) => n.direction === "desc" ? r`${n.field} DESC` : r`${n.field} ASC`
905
+ ), r`, `)}` : r``;
906
+ let C = r``;
907
907
  if (t?.frame) {
908
908
  const { type: n, start: i, end: L } = t.frame, M = n.toUpperCase(), D = i === "unbounded" ? "UNBOUNDED PRECEDING" : typeof i == "number" ? `${i} PRECEDING` : "CURRENT ROW", l = L === "unbounded" ? "UNBOUNDED FOLLOWING" : L === "current" ? "CURRENT ROW" : typeof L == "number" ? `${L} FOLLOWING` : "CURRENT ROW";
909
- C = O`${O.raw(M)} BETWEEN ${O.raw(D)} AND ${O.raw(l)}`;
909
+ C = r`${r.raw(M)} BETWEEN ${r.raw(D)} AND ${r.raw(l)}`;
910
910
  }
911
911
  const N = [];
912
- R && R.length > 0 && N.push(S), A && A.length > 0 && N.push(r), t?.frame && N.push(C);
913
- const s = N.length > 0 ? O.join(N, O` `) : O``, I = O`OVER (${s})`;
912
+ R && R.length > 0 && N.push(S), A && A.length > 0 && N.push(O), t?.frame && N.push(C);
913
+ const s = N.length > 0 ? r.join(N, r` `) : r``, I = r`OVER (${s})`;
914
914
  switch (E) {
915
915
  case "lag":
916
- return O`LAG(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? O`, ${t.defaultValue}` : O``}) ${I}`;
916
+ return r`LAG(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? r`, ${t.defaultValue}` : r``}) ${I}`;
917
917
  case "lead":
918
- return O`LEAD(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? O`, ${t.defaultValue}` : O``}) ${I}`;
918
+ return r`LEAD(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? r`, ${t.defaultValue}` : r``}) ${I}`;
919
919
  case "rank":
920
- return O`RANK() ${I}`;
920
+ return r`RANK() ${I}`;
921
921
  case "denseRank":
922
- return O`DENSE_RANK() ${I}`;
922
+ return r`DENSE_RANK() ${I}`;
923
923
  case "rowNumber":
924
- return O`ROW_NUMBER() ${I}`;
924
+ return r`ROW_NUMBER() ${I}`;
925
925
  case "ntile":
926
- return O`NTILE(${t?.nTile ?? 4}) ${I}`;
926
+ return r`NTILE(${t?.nTile ?? 4}) ${I}`;
927
927
  case "firstValue":
928
- return O`FIRST_VALUE(${T}) ${I}`;
928
+ return r`FIRST_VALUE(${T}) ${I}`;
929
929
  case "lastValue":
930
- return O`LAST_VALUE(${T}) ${I}`;
930
+ return r`LAST_VALUE(${T}) ${I}`;
931
931
  case "movingAvg":
932
- return O`AVG(${T}) ${I}`;
932
+ return r`AVG(${T}) ${I}`;
933
933
  case "movingSum":
934
- return O`SUM(${T}) ${I}`;
934
+ return r`SUM(${T}) ${I}`;
935
935
  default:
936
936
  throw new Error(`Unsupported window function: ${E}`);
937
937
  }
@@ -950,32 +950,32 @@ class Ve extends RT {
950
950
  buildTimeDimension(E, T) {
951
951
  switch (E) {
952
952
  case "year":
953
- return O`datetime(${T}, 'unixepoch', 'start of year')`;
953
+ return r`datetime(${T}, 'unixepoch', 'start of year')`;
954
954
  case "quarter": {
955
- const R = O`datetime(${T}, 'unixepoch')`;
956
- return O`datetime(${R}, 'start of year',
955
+ const R = r`datetime(${T}, 'unixepoch')`;
956
+ return r`datetime(${R}, 'start of year',
957
957
  '+' || (((CAST(strftime('%m', ${R}) AS INTEGER) - 1) / 3) * 3) || ' months')`;
958
958
  }
959
959
  case "month":
960
- return O`datetime(${T}, 'unixepoch', 'start of month')`;
960
+ return r`datetime(${T}, 'unixepoch', 'start of month')`;
961
961
  case "week":
962
- return O`date(datetime(${T}, 'unixepoch'), 'weekday 1', '-6 days')`;
962
+ return r`date(datetime(${T}, 'unixepoch'), 'weekday 1', '-6 days')`;
963
963
  case "day":
964
- return O`datetime(${T}, 'unixepoch', 'start of day')`;
964
+ return r`datetime(${T}, 'unixepoch', 'start of day')`;
965
965
  case "hour": {
966
- const R = O`datetime(${T}, 'unixepoch')`;
967
- return O`datetime(strftime('%Y-%m-%d %H:00:00', ${R}))`;
966
+ const R = r`datetime(${T}, 'unixepoch')`;
967
+ return r`datetime(strftime('%Y-%m-%d %H:00:00', ${R}))`;
968
968
  }
969
969
  case "minute": {
970
- const R = O`datetime(${T}, 'unixepoch')`;
971
- return O`datetime(strftime('%Y-%m-%d %H:%M:00', ${R}))`;
970
+ const R = r`datetime(${T}, 'unixepoch')`;
971
+ return r`datetime(strftime('%Y-%m-%d %H:%M:00', ${R}))`;
972
972
  }
973
973
  case "second": {
974
- const R = O`datetime(${T}, 'unixepoch')`;
975
- return O`datetime(strftime('%Y-%m-%d %H:%M:%S', ${R}))`;
974
+ const R = r`datetime(${T}, 'unixepoch')`;
975
+ return r`datetime(strftime('%Y-%m-%d %H:%M:%S', ${R}))`;
976
976
  }
977
977
  default:
978
- return O`datetime(${T}, 'unixepoch')`;
978
+ return r`datetime(${T}, 'unixepoch')`;
979
979
  }
980
980
  }
981
981
  /**
@@ -985,23 +985,23 @@ class Ve extends RT {
985
985
  buildStringCondition(E, T, R) {
986
986
  switch (T) {
987
987
  case "contains":
988
- return O`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
988
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}%`}`;
989
989
  case "notContains":
990
- return O`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
990
+ return r`LOWER(${E}) NOT LIKE ${`%${R.toLowerCase()}%`}`;
991
991
  case "startsWith":
992
- return O`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
992
+ return r`LOWER(${E}) LIKE ${`${R.toLowerCase()}%`}`;
993
993
  case "endsWith":
994
- return O`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
994
+ return r`LOWER(${E}) LIKE ${`%${R.toLowerCase()}`}`;
995
995
  case "like":
996
- return O`${E} LIKE ${R}`;
996
+ return r`${E} LIKE ${R}`;
997
997
  case "notLike":
998
- return O`${E} NOT LIKE ${R}`;
998
+ return r`${E} NOT LIKE ${R}`;
999
999
  case "ilike":
1000
- return O`LOWER(${E}) LIKE ${R.toLowerCase()}`;
1000
+ return r`LOWER(${E}) LIKE ${R.toLowerCase()}`;
1001
1001
  case "regex":
1002
- return O`${E} GLOB ${R}`;
1002
+ return r`${E} GLOB ${R}`;
1003
1003
  case "notRegex":
1004
- return O`${E} NOT GLOB ${R}`;
1004
+ return r`${E} NOT GLOB ${R}`;
1005
1005
  default:
1006
1006
  throw new Error(`Unsupported string operator: ${T}`);
1007
1007
  }
@@ -1013,11 +1013,11 @@ class Ve extends RT {
1013
1013
  castToType(E, T) {
1014
1014
  switch (T) {
1015
1015
  case "timestamp":
1016
- return O`datetime(${E} / 1000, 'unixepoch')`;
1016
+ return r`datetime(${E} / 1000, 'unixepoch')`;
1017
1017
  case "decimal":
1018
- return O`CAST(${E} AS REAL)`;
1018
+ return r`CAST(${E} AS REAL)`;
1019
1019
  case "integer":
1020
- return O`CAST(${E} AS INTEGER)`;
1020
+ return r`CAST(${E} AS INTEGER)`;
1021
1021
  default:
1022
1022
  throw new Error(`Unsupported cast type: ${T}`);
1023
1023
  }
@@ -1027,21 +1027,21 @@ class Ve extends RT {
1027
1027
  * SQLite AVG returns NULL for empty sets, using IFNULL for consistency
1028
1028
  */
1029
1029
  buildAvg(E) {
1030
- return O`IFNULL(AVG(${E}), 0)`;
1030
+ return r`IFNULL(AVG(${E}), 0)`;
1031
1031
  }
1032
1032
  /**
1033
1033
  * Build SQLite CASE WHEN conditional expression
1034
1034
  */
1035
1035
  buildCaseWhen(E, T) {
1036
- const R = E.map((A) => A.then && typeof A.then == "object" && (A.then.queryChunks || A.then._ || A.then.sql) ? O`WHEN ${A.when} THEN ${O.raw("(")}${A.then}${O.raw(")")}` : O`WHEN ${A.when} THEN ${A.then}`).reduce((A, t) => O`${A} ${t}`);
1037
- return T !== void 0 ? T && typeof T == "object" && (T.queryChunks || T._ || T.sql) ? O`CASE ${R} ELSE ${O.raw("(")}${T}${O.raw(")")} END` : O`CASE ${R} ELSE ${T} END` : O`CASE ${R} END`;
1036
+ 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, t) => r`${A} ${t}`);
1037
+ return T !== void 0 ? T && typeof T == "object" && (T.queryChunks || T._ || T.sql) ? r`CASE ${R} ELSE ${r.raw("(")}${T}${r.raw(")")} END` : r`CASE ${R} ELSE ${T} END` : r`CASE ${R} END`;
1038
1038
  }
1039
1039
  /**
1040
1040
  * Build SQLite boolean literal
1041
1041
  * SQLite uses 1/0 for true/false
1042
1042
  */
1043
1043
  buildBooleanLiteral(E) {
1044
- return E ? O`1` : O`0`;
1044
+ return E ? r`1` : r`0`;
1045
1045
  }
1046
1046
  /**
1047
1047
  * Preprocess calculated measure templates for SQLite-specific handling
@@ -1138,38 +1138,38 @@ class Ve extends RT {
1138
1138
  * SQLite 3.25+ supports window functions
1139
1139
  */
1140
1140
  buildWindowFunction(E, T, R, A, t) {
1141
- const S = R && R.length > 0 ? O`PARTITION BY ${O.join(R, O`, `)}` : O``, r = A && A.length > 0 ? O`ORDER BY ${O.join(A.map(
1142
- (n) => n.direction === "desc" ? O`${n.field} DESC` : O`${n.field} ASC`
1143
- ), O`, `)}` : O``;
1144
- let C = O``;
1141
+ const S = R && R.length > 0 ? r`PARTITION BY ${r.join(R, r`, `)}` : r``, O = A && A.length > 0 ? r`ORDER BY ${r.join(A.map(
1142
+ (n) => n.direction === "desc" ? r`${n.field} DESC` : r`${n.field} ASC`
1143
+ ), r`, `)}` : r``;
1144
+ let C = r``;
1145
1145
  if (t?.frame) {
1146
1146
  const { type: n, start: i, end: L } = t.frame, M = n.toUpperCase(), D = i === "unbounded" ? "UNBOUNDED PRECEDING" : typeof i == "number" ? `${i} PRECEDING` : "CURRENT ROW", l = L === "unbounded" ? "UNBOUNDED FOLLOWING" : L === "current" ? "CURRENT ROW" : typeof L == "number" ? `${L} FOLLOWING` : "CURRENT ROW";
1147
- C = O`${O.raw(M)} BETWEEN ${O.raw(D)} AND ${O.raw(l)}`;
1147
+ C = r`${r.raw(M)} BETWEEN ${r.raw(D)} AND ${r.raw(l)}`;
1148
1148
  }
1149
1149
  const N = [];
1150
- R && R.length > 0 && N.push(S), A && A.length > 0 && N.push(r), t?.frame && N.push(C);
1151
- const s = N.length > 0 ? O.join(N, O` `) : O``, I = O`OVER (${s})`;
1150
+ R && R.length > 0 && N.push(S), A && A.length > 0 && N.push(O), t?.frame && N.push(C);
1151
+ const s = N.length > 0 ? r.join(N, r` `) : r``, I = r`OVER (${s})`;
1152
1152
  switch (E) {
1153
1153
  case "lag":
1154
- return O`LAG(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? O`, ${t.defaultValue}` : O``}) ${I}`;
1154
+ return r`LAG(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? r`, ${t.defaultValue}` : r``}) ${I}`;
1155
1155
  case "lead":
1156
- return O`LEAD(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? O`, ${t.defaultValue}` : O``}) ${I}`;
1156
+ return r`LEAD(${T}, ${t?.offset ?? 1}${t?.defaultValue !== void 0 ? r`, ${t.defaultValue}` : r``}) ${I}`;
1157
1157
  case "rank":
1158
- return O`RANK() ${I}`;
1158
+ return r`RANK() ${I}`;
1159
1159
  case "denseRank":
1160
- return O`DENSE_RANK() ${I}`;
1160
+ return r`DENSE_RANK() ${I}`;
1161
1161
  case "rowNumber":
1162
- return O`ROW_NUMBER() ${I}`;
1162
+ return r`ROW_NUMBER() ${I}`;
1163
1163
  case "ntile":
1164
- return O`NTILE(${t?.nTile ?? 4}) ${I}`;
1164
+ return r`NTILE(${t?.nTile ?? 4}) ${I}`;
1165
1165
  case "firstValue":
1166
- return O`FIRST_VALUE(${T}) ${I}`;
1166
+ return r`FIRST_VALUE(${T}) ${I}`;
1167
1167
  case "lastValue":
1168
- return O`LAST_VALUE(${T}) ${I}`;
1168
+ return r`LAST_VALUE(${T}) ${I}`;
1169
1169
  case "movingAvg":
1170
- return O`AVG(${T}) ${I}`;
1170
+ return r`AVG(${T}) ${I}`;
1171
1171
  case "movingSum":
1172
- return O`SUM(${T}) ${I}`;
1172
+ return r`SUM(${T}) ${I}`;
1173
1173
  default:
1174
1174
  throw new Error(`Unsupported window function: ${E}`);
1175
1175
  }
@@ -1406,7 +1406,7 @@ function zE(e, E) {
1406
1406
  }
1407
1407
  }
1408
1408
  function ET(e) {
1409
- return e && typeof e == "object" ? O`${O`${e}`}` : e;
1409
+ return e && typeof e == "object" ? r`${r`${e}`}` : e;
1410
1410
  }
1411
1411
  function y(e, E) {
1412
1412
  const T = typeof e == "function" ? e(E) : e;
@@ -1420,10 +1420,10 @@ function we(e, E) {
1420
1420
  const I = s.as || v;
1421
1421
  S.push(I(s.source, s.target));
1422
1422
  }
1423
- const r = [];
1423
+ const O = [];
1424
1424
  for (const s of A) {
1425
1425
  const I = s.as || v;
1426
- r.push(I(s.source, s.target));
1426
+ O.push(I(s.source, s.target));
1427
1427
  }
1428
1428
  let C;
1429
1429
  if (t) {
@@ -1442,7 +1442,7 @@ function we(e, E) {
1442
1442
  joinType: N,
1443
1443
  table: T,
1444
1444
  // This will be replaced with target cube table in query planner
1445
- condition: F(...r)
1445
+ condition: F(...O)
1446
1446
  }
1447
1447
  ],
1448
1448
  junctionSecurityConditions: C
@@ -1533,7 +1533,7 @@ class ve {
1533
1533
  */
1534
1534
  buildTimeDimensionExpression(E, T, R) {
1535
1535
  const A = y(E, R);
1536
- return T ? this.databaseAdapter.buildTimeDimension(T, A) : A instanceof p ? A : O`${A}`;
1536
+ return T ? this.databaseAdapter.buildTimeDimension(T, A) : A instanceof p ? A : r`${A}`;
1537
1537
  }
1538
1538
  /**
1539
1539
  * Build date range condition for time dimensions
@@ -1566,10 +1566,10 @@ class ve {
1566
1566
  if (!A) return null;
1567
1567
  const t = typeof A == "number" ? new Date(A * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(A), S = new Date(t);
1568
1568
  S.setUTCHours(0, 0, 0, 0);
1569
- const r = new Date(t);
1570
- r.setUTCHours(23, 59, 59, 999);
1569
+ const O = new Date(t);
1570
+ O.setUTCHours(23, 59, 59, 999);
1571
1571
  let C, N;
1572
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (C = Math.floor(S.getTime() / 1e3), N = Math.floor(r.getTime() / 1e3)) : (C = S.getTime(), N = r.getTime()) : (C = S.toISOString(), N = r.toISOString()), F(
1572
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (C = Math.floor(S.getTime() / 1e3), N = Math.floor(O.getTime() / 1e3)) : (C = S.getTime(), N = O.getTime()) : (C = S.toISOString(), N = O.toISOString()), F(
1573
1573
  k(E, C),
1574
1574
  z(E, N)
1575
1575
  );
@@ -1581,7 +1581,7 @@ class ve {
1581
1581
  * Handles all 14 DATE_RANGE_OPTIONS from the client
1582
1582
  */
1583
1583
  parseRelativeDateRange(E) {
1584
- const T = /* @__PURE__ */ new Date(), R = E.toLowerCase().trim(), A = T.getUTCFullYear(), t = T.getUTCMonth(), S = T.getUTCDate(), r = T.getUTCDay();
1584
+ const T = /* @__PURE__ */ new Date(), R = E.toLowerCase().trim(), A = T.getUTCFullYear(), t = T.getUTCMonth(), S = T.getUTCDate(), O = T.getUTCDay();
1585
1585
  if (R === "today") {
1586
1586
  const n = new Date(T);
1587
1587
  n.setUTCHours(0, 0, 0, 0);
@@ -1595,7 +1595,7 @@ class ve {
1595
1595
  return i.setUTCDate(S - 1), i.setUTCHours(23, 59, 59, 999), { start: n, end: i };
1596
1596
  }
1597
1597
  if (R === "this week") {
1598
- const n = r === 0 ? -6 : 1 - r, i = new Date(T);
1598
+ const n = O === 0 ? -6 : 1 - O, i = new Date(T);
1599
1599
  i.setUTCDate(S + n), i.setUTCHours(0, 0, 0, 0);
1600
1600
  const L = new Date(i);
1601
1601
  return L.setUTCDate(i.getUTCDate() + 6), L.setUTCHours(23, 59, 59, 999), { start: i, end: L };
@@ -1627,7 +1627,7 @@ class ve {
1627
1627
  return M.setUTCHours(23, 59, 59, 999), { start: L, end: M };
1628
1628
  }
1629
1629
  if (R === "last week") {
1630
- const n = r === 0 ? -13 : -6 - r, i = new Date(T);
1630
+ const n = O === 0 ? -13 : -6 - O, i = new Date(T);
1631
1631
  i.setUTCDate(S + n), i.setUTCHours(0, 0, 0, 0);
1632
1632
  const L = new Date(i);
1633
1633
  return L.setUTCDate(i.getUTCDate() + 6), L.setUTCHours(23, 59, 59, 999), { start: i, end: L };
@@ -1709,7 +1709,7 @@ class xe {
1709
1709
  const S = R.filter((C) => !(C == null || C === "" || typeof C == "string" && C.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
1710
1710
  if (S.length === 0 && !["set", "notSet"].includes(T))
1711
1711
  return T === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
1712
- const r = S[0];
1712
+ const O = S[0];
1713
1713
  switch (T) {
1714
1714
  case "equals":
1715
1715
  if (S.length > 1) {
@@ -1719,28 +1719,28 @@ class xe {
1719
1719
  }
1720
1720
  return GE(E, S);
1721
1721
  } else if (S.length === 1) {
1722
- const C = A?.type === "time" && this.dateTimeBuilder.normalizeDate(r) || r;
1722
+ const C = A?.type === "time" && this.dateTimeBuilder.normalizeDate(O) || O;
1723
1723
  return v(E, C);
1724
1724
  }
1725
1725
  return this.databaseAdapter.buildBooleanLiteral(!1);
1726
1726
  case "notEquals":
1727
- return S.length > 1 ? nT(E, S) : S.length === 1 ? rT(E, r) : null;
1727
+ return S.length > 1 ? nT(E, S) : S.length === 1 ? rT(E, O) : null;
1728
1728
  case "contains":
1729
- return this.databaseAdapter.buildStringCondition(E, "contains", r);
1729
+ return this.databaseAdapter.buildStringCondition(E, "contains", O);
1730
1730
  case "notContains":
1731
- return this.databaseAdapter.buildStringCondition(E, "notContains", r);
1731
+ return this.databaseAdapter.buildStringCondition(E, "notContains", O);
1732
1732
  case "startsWith":
1733
- return this.databaseAdapter.buildStringCondition(E, "startsWith", r);
1733
+ return this.databaseAdapter.buildStringCondition(E, "startsWith", O);
1734
1734
  case "endsWith":
1735
- return this.databaseAdapter.buildStringCondition(E, "endsWith", r);
1735
+ return this.databaseAdapter.buildStringCondition(E, "endsWith", O);
1736
1736
  case "gt":
1737
- return uE(E, r);
1737
+ return uE(E, O);
1738
1738
  case "gte":
1739
- return k(E, r);
1739
+ return k(E, O);
1740
1740
  case "lt":
1741
- return cE(E, r);
1741
+ return cE(E, O);
1742
1742
  case "lte":
1743
- return z(E, r);
1743
+ return z(E, O);
1744
1744
  case "set":
1745
1745
  return iT(E);
1746
1746
  case "notSet":
@@ -1763,11 +1763,11 @@ class xe {
1763
1763
  }
1764
1764
  return null;
1765
1765
  case "beforeDate": {
1766
- const C = this.dateTimeBuilder.normalizeDate(r);
1766
+ const C = this.dateTimeBuilder.normalizeDate(O);
1767
1767
  return C ? cE(E, C) : null;
1768
1768
  }
1769
1769
  case "afterDate": {
1770
- const C = this.dateTimeBuilder.normalizeDate(r);
1770
+ const C = this.dateTimeBuilder.normalizeDate(O);
1771
1771
  return C ? uE(E, C) : null;
1772
1772
  }
1773
1773
  case "between":
@@ -1785,15 +1785,15 @@ class xe {
1785
1785
  case "notIn":
1786
1786
  return S.length > 0 ? nT(E, S) : null;
1787
1787
  case "like":
1788
- return this.databaseAdapter.buildStringCondition(E, "like", r);
1788
+ return this.databaseAdapter.buildStringCondition(E, "like", O);
1789
1789
  case "notLike":
1790
- return this.databaseAdapter.buildStringCondition(E, "notLike", r);
1790
+ return this.databaseAdapter.buildStringCondition(E, "notLike", O);
1791
1791
  case "ilike":
1792
- return this.databaseAdapter.buildStringCondition(E, "ilike", r);
1792
+ return this.databaseAdapter.buildStringCondition(E, "ilike", O);
1793
1793
  case "regex":
1794
- return this.databaseAdapter.buildStringCondition(E, "regex", r);
1794
+ return this.databaseAdapter.buildStringCondition(E, "regex", O);
1795
1795
  case "notRegex":
1796
- return this.databaseAdapter.buildStringCondition(E, "notRegex", r);
1796
+ return this.databaseAdapter.buildStringCondition(E, "notRegex", O);
1797
1797
  case "isEmpty":
1798
1798
  return tE(
1799
1799
  CT(E),
@@ -1838,9 +1838,9 @@ class xe {
1838
1838
  buildSingleFilter(E, T, R) {
1839
1839
  if ("and" in E || "or" in E)
1840
1840
  return this.buildLogicalFilter(E, T, R);
1841
- const A = E, [t, S] = A.member.split("."), r = T.get(t);
1842
- if (!r) return null;
1843
- const C = r.dimensions?.[S];
1841
+ const A = E, [t, S] = A.member.split("."), O = T.get(t);
1842
+ if (!O) return null;
1843
+ const C = O.dimensions?.[S];
1844
1844
  if (!C) return null;
1845
1845
  const N = y(C.sql, R);
1846
1846
  return this.buildFilterCondition(
@@ -1903,17 +1903,17 @@ class Qe {
1903
1903
  */
1904
1904
  buildGroupByFields(E, T, R, A) {
1905
1905
  const t = [], S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1906
- let r = !1, C = !1;
1906
+ let O = !1, C = !1;
1907
1907
  for (const N of T.measures || []) {
1908
1908
  const [s, I] = N.split("."), n = S.get(s);
1909
1909
  if (n && n.measures && n.measures[I]) {
1910
1910
  const i = n.measures[I];
1911
- (this.isAggregateFunctionType(i.type) || i.type === "calculated") && (r = !0), this.isWindowFunctionType(i.type) && (C = !0);
1911
+ (this.isAggregateFunctionType(i.type) || i.type === "calculated") && (O = !0), this.isWindowFunctionType(i.type) && (C = !0);
1912
1912
  }
1913
1913
  }
1914
- if (r && C && console.warn(
1914
+ if (O && C && console.warn(
1915
1915
  "[drizzle-cube] Warning: Mixing aggregate measures (count, sum, avg, etc.) with window functions (lag, lead, rank, etc.) in the same query may produce incorrect results. Window functions will operate on raw rows before aggregation. Consider separating these into different queries or using CTE pattern."
1916
- ), !r)
1916
+ ), !O)
1917
1917
  return [];
1918
1918
  if (T.dimensions)
1919
1919
  for (const N of T.dimensions) {
@@ -1924,7 +1924,7 @@ class Qe {
1924
1924
  if (M && M.sourceColumnObj)
1925
1925
  t.push(M.sourceColumnObj);
1926
1926
  else {
1927
- const D = O`${O.identifier(L.cteAlias)}.${O.identifier(I)}`;
1927
+ const D = r`${r.identifier(L.cteAlias)}.${r.identifier(I)}`;
1928
1928
  t.push(D);
1929
1929
  }
1930
1930
  } else {
@@ -1946,7 +1946,7 @@ class Qe {
1946
1946
  );
1947
1947
  t.push(D);
1948
1948
  } else {
1949
- const D = O`${O.identifier(L.cteAlias)}.${O.identifier(I)}`;
1949
+ const D = r`${r.identifier(L.cteAlias)}.${r.identifier(I)}`;
1950
1950
  t.push(D);
1951
1951
  }
1952
1952
  } else {
@@ -1979,10 +1979,10 @@ class J {
1979
1979
  for (const t of R) {
1980
1980
  const S = t[1].trim();
1981
1981
  if (S.includes(".")) {
1982
- const [r, C] = S.split(".");
1982
+ const [O, C] = S.split(".");
1983
1983
  A.push({
1984
1984
  measureName: S,
1985
- cubeName: r.trim(),
1985
+ cubeName: O.trim(),
1986
1986
  fieldName: C.trim()
1987
1987
  });
1988
1988
  } else
@@ -2003,8 +2003,8 @@ class J {
2003
2003
  for (const [T, R] of Object.entries(E.measures))
2004
2004
  if (R.type === "calculated" && R.calculatedSql) {
2005
2005
  const A = `${E.name}.${T}`, t = this.extractDependencies(R.calculatedSql), S = /* @__PURE__ */ new Set();
2006
- for (const r of t) {
2007
- const N = `${r.cubeName || E.name}.${r.fieldName}`;
2006
+ for (const O of t) {
2007
+ const N = `${O.cubeName || E.name}.${O.fieldName}`;
2008
2008
  S.add(N);
2009
2009
  }
2010
2010
  this.dependencyGraph.set(A, {
@@ -2057,8 +2057,8 @@ class J {
2057
2057
  }
2058
2058
  for (const t of T.values()) {
2059
2059
  let S = 0;
2060
- for (const r of t.dependencies)
2061
- T.has(r) && S++;
2060
+ for (const O of t.dependencies)
2061
+ T.has(O) && S++;
2062
2062
  t.inDegree = S;
2063
2063
  }
2064
2064
  for (const [t, S] of T)
@@ -2066,8 +2066,8 @@ class J {
2066
2066
  for (; R.length > 0; ) {
2067
2067
  const t = R.shift();
2068
2068
  A.push(t);
2069
- for (const [S, r] of T)
2070
- r.dependencies.has(t) && (r.inDegree--, r.inDegree === 0 && R.push(S));
2069
+ for (const [S, O] of T)
2070
+ O.dependencies.has(t) && (O.inDegree--, O.inDegree === 0 && R.push(S));
2071
2071
  }
2072
2072
  if (A.length < T.size) {
2073
2073
  const t = this.detectCycle();
@@ -2104,13 +2104,13 @@ class J {
2104
2104
  for (const S of t.dependencies)
2105
2105
  if (T.has(S)) {
2106
2106
  if (R.has(S)) {
2107
- const r = A.indexOf(S);
2108
- return [...A.slice(r), S];
2107
+ const O = A.indexOf(S);
2108
+ return [...A.slice(O), S];
2109
2109
  }
2110
2110
  } else {
2111
- const r = this.dfs(S, T, R, A);
2112
- if (r)
2113
- return r;
2111
+ const O = this.dfs(S, T, R, A);
2112
+ if (O)
2113
+ return O;
2114
2114
  }
2115
2115
  return A.pop(), R.delete(E), null;
2116
2116
  }
@@ -2126,8 +2126,8 @@ class J {
2126
2126
  R.add(t);
2127
2127
  const S = this.dependencyGraph.get(t);
2128
2128
  if (S)
2129
- for (const r of S.dependencies)
2130
- T.add(r), A(r);
2129
+ for (const O of S.dependencies)
2130
+ T.add(O), A(O);
2131
2131
  };
2132
2132
  return A(E), T;
2133
2133
  }
@@ -2142,12 +2142,12 @@ class J {
2142
2142
  if (R.type === "calculated" && R.calculatedSql) {
2143
2143
  const A = this.extractDependencies(R.calculatedSql);
2144
2144
  for (const t of A) {
2145
- const S = t.cubeName || E.name, r = this.cubes.get(S);
2146
- if (!r)
2145
+ const S = t.cubeName || E.name, O = this.cubes.get(S);
2146
+ if (!O)
2147
2147
  throw new Error(
2148
2148
  `Calculated measure '${E.name}.${T}' references unknown cube '${S}'`
2149
2149
  );
2150
- if (!r.measures[t.fieldName])
2150
+ if (!O.measures[t.fieldName])
2151
2151
  throw new Error(
2152
2152
  `Calculated measure '${E.name}.${T}' references unknown measure '${t.measureName}'`
2153
2153
  );
@@ -2194,36 +2194,36 @@ function Ze(e, E) {
2194
2194
  throw new Error(
2195
2195
  `Cannot substitute {${n}}: measure '${l}' not resolved yet. Ensure measures are resolved in dependency order.`
2196
2196
  );
2197
- const u = P(), U = O`${u}`;
2197
+ const u = P(), U = r`${u}`;
2198
2198
  S.set(n, U);
2199
2199
  }
2200
- const r = [], C = [];
2200
+ const O = [], C = [];
2201
2201
  let N = 0;
2202
2202
  for (const I of t) {
2203
2203
  const n = `{${I.originalRef}}`, i = e.indexOf(n, N);
2204
2204
  if (i >= 0) {
2205
- r.push(e.substring(N, i));
2205
+ O.push(e.substring(N, i));
2206
2206
  const L = S.get(I.originalRef);
2207
2207
  L && C.push(L), N = i + n.length;
2208
2208
  }
2209
2209
  }
2210
- if (r.push(e.substring(N)), C.length === 0)
2211
- return O.raw(e);
2210
+ if (O.push(e.substring(N)), C.length === 0)
2211
+ return r.raw(e);
2212
2212
  const s = [];
2213
- for (let I = 0; I < r.length; I++)
2214
- r[I] && s.push(new V(r[I])), I < C.length && s.push(C[I]);
2215
- return O.join(s, O.raw(""));
2213
+ for (let I = 0; I < O.length; I++)
2214
+ O[I] && s.push(new V(O[I])), I < C.length && s.push(C[I]);
2215
+ return r.join(s, r.raw(""));
2216
2216
  }
2217
2217
  function tT(e) {
2218
2218
  const E = /\{([^}]+)\}/g, T = e.matchAll(E), R = [];
2219
2219
  for (const A of T) {
2220
2220
  const t = A[1].trim();
2221
2221
  if (t.includes(".")) {
2222
- const [S, r] = t.split(".").map((C) => C.trim());
2222
+ const [S, O] = t.split(".").map((C) => C.trim());
2223
2223
  R.push({
2224
2224
  originalRef: t,
2225
2225
  cubeName: S,
2226
- fieldName: r
2226
+ fieldName: O
2227
2227
  });
2228
2228
  } else
2229
2229
  R.push({
@@ -2247,10 +2247,10 @@ function qe(e) {
2247
2247
  T > 0 && E.push("Unmatched opening brace in template"), /\{\s*\}/.test(e) && E.push("Empty member reference {} found in template"), /\{[^}]*\{/.test(e) && E.push("Nested braces are not allowed in member references");
2248
2248
  const t = tT(e);
2249
2249
  for (const S of t) {
2250
- const r = S.cubeName ? `${S.cubeName}.${S.fieldName}` : S.fieldName;
2251
- /^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(r) || E.push(
2250
+ const O = S.cubeName ? `${S.cubeName}.${S.fieldName}` : S.fieldName;
2251
+ /^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(O) || E.push(
2252
2252
  `Invalid member reference {${S.originalRef}}: must start with letter or underscore, and contain only letters, numbers, underscores, and dots`
2253
- ), r.split(".").length > 2 && E.push(
2253
+ ), O.split(".").length > 2 && E.push(
2254
2254
  `Invalid member reference {${S.originalRef}}: only one dot allowed (Cube.measure format)`
2255
2255
  );
2256
2256
  }
@@ -2283,14 +2283,14 @@ class je {
2283
2283
  * @returns Map of measure names to SQL builder functions
2284
2284
  */
2285
2285
  buildResolvedMeasures(E, T, R, A) {
2286
- const t = /* @__PURE__ */ new Map(), S = [], r = [], C = new Set(E), N = new J(T);
2286
+ const t = /* @__PURE__ */ new Map(), S = [], O = [], C = new Set(E), N = new J(T);
2287
2287
  for (const s of T.values())
2288
2288
  N.buildGraph(s);
2289
2289
  for (const s of E) {
2290
2290
  const [I, n] = s.split("."), i = T.get(I);
2291
2291
  if (i && i.measures && i.measures[n]) {
2292
2292
  const L = i.measures[n];
2293
- J.isCalculatedMeasure(L) ? (r.push(s), dE(L.calculatedSql, I).forEach((l) => C.add(l)), N.getAllDependencies(s).forEach((l) => {
2293
+ J.isCalculatedMeasure(L) ? (O.push(s), dE(L.calculatedSql, I).forEach((l) => C.add(l)), N.getAllDependencies(s).forEach((l) => {
2294
2294
  const [P, u] = l.split("."), U = T.get(P);
2295
2295
  if (U && U.measures[u]) {
2296
2296
  const d = U.measures[u];
@@ -2303,7 +2303,7 @@ class je {
2303
2303
  const [I, n] = s.split("."), i = T.get(I);
2304
2304
  if (i && i.measures && i.measures[n]) {
2305
2305
  const L = i.measures[n];
2306
- J.isCalculatedMeasure(L) ? r.includes(s) || r.push(s) : S.includes(s) || S.push(s);
2306
+ J.isCalculatedMeasure(L) ? O.includes(s) || O.push(s) : S.includes(s) || S.push(s);
2307
2307
  }
2308
2308
  }
2309
2309
  for (const s of S) {
@@ -2314,8 +2314,8 @@ class je {
2314
2314
  } else
2315
2315
  t.set(s, () => this.buildMeasureExpression(L, R, i));
2316
2316
  }
2317
- if (r.length > 0) {
2318
- const s = N.topologicalSort(r);
2317
+ if (O.length > 0) {
2318
+ const s = N.topologicalSort(O);
2319
2319
  for (const I of s) {
2320
2320
  const [n, i] = I.split("."), L = T.get(n), M = L.measures[i];
2321
2321
  t.set(I, () => this.buildCalculatedMeasure(
@@ -2364,13 +2364,13 @@ class je {
2364
2364
  throw new Error(
2365
2365
  `Calculated measure '${T.name}.${E.name || "unknown"}' missing calculatedSql property`
2366
2366
  );
2367
- const S = /* @__PURE__ */ new Map(), r = dE(E.calculatedSql, T.name);
2368
- for (const C of r) {
2367
+ const S = /* @__PURE__ */ new Map(), O = dE(E.calculatedSql, T.name);
2368
+ for (const C of O) {
2369
2369
  const [N, s] = C.split("."), I = A.get(N);
2370
2370
  if (I && I.measures[s]) {
2371
2371
  const n = I.measures[s];
2372
2372
  if (R.measures.includes(C)) {
2373
- const i = O`${O.identifier(R.cteAlias)}.${O.identifier(s)}`;
2373
+ const i = r`${r.identifier(R.cteAlias)}.${r.identifier(s)}`;
2374
2374
  let L;
2375
2375
  switch (n.type) {
2376
2376
  case "count":
@@ -2410,11 +2410,11 @@ class je {
2410
2410
  */
2411
2411
  buildHavingMeasureExpression(E, T, R, A, t) {
2412
2412
  if (t && t.preAggregationCTEs) {
2413
- const S = t.preAggregationCTEs.find((r) => r.cube.name === E);
2413
+ const S = t.preAggregationCTEs.find((O) => O.cube.name === E);
2414
2414
  if (S && S.measures.includes(`${E}.${T}`))
2415
2415
  if (R.type === "calculated" && R.calculatedSql) {
2416
- const r = t.primaryCube.name === E ? t.primaryCube : t.joinCubes?.find((N) => N.cube.name === E)?.cube;
2417
- if (!r)
2416
+ const O = t.primaryCube.name === E ? t.primaryCube : t.joinCubes?.find((N) => N.cube.name === E)?.cube;
2417
+ if (!O)
2418
2418
  throw new Error(`Cube ${E} not found in query plan`);
2419
2419
  const C = /* @__PURE__ */ new Map([[t.primaryCube.name, t.primaryCube]]);
2420
2420
  if (t.joinCubes)
@@ -2422,28 +2422,28 @@ class je {
2422
2422
  C.set(N.cube.name, N.cube);
2423
2423
  return this.buildCTECalculatedMeasure(
2424
2424
  R,
2425
- r,
2425
+ O,
2426
2426
  S,
2427
2427
  C,
2428
2428
  A
2429
2429
  );
2430
2430
  } else {
2431
- const r = O`${O.identifier(S.cteAlias)}.${O.identifier(T)}`;
2431
+ const O = r`${r.identifier(S.cteAlias)}.${r.identifier(T)}`;
2432
2432
  switch (R.type) {
2433
2433
  case "count":
2434
2434
  case "countDistinct":
2435
2435
  case "sum":
2436
- return $(r);
2436
+ return $(O);
2437
2437
  case "avg":
2438
- return this.databaseAdapter.buildAvg(r);
2438
+ return this.databaseAdapter.buildAvg(O);
2439
2439
  case "min":
2440
- return sE(r);
2440
+ return sE(O);
2441
2441
  case "max":
2442
- return SE(r);
2442
+ return SE(O);
2443
2443
  case "number":
2444
- return $(r);
2444
+ return $(O);
2445
2445
  default:
2446
- return $(r);
2446
+ return $(O);
2447
2447
  }
2448
2448
  }
2449
2449
  }
@@ -2469,8 +2469,8 @@ class je {
2469
2469
  let A = y(E.sql, T);
2470
2470
  if (E.filters && E.filters.length > 0) {
2471
2471
  const t = E.filters.map((S) => {
2472
- const r = S(T);
2473
- return r ? O`(${r})` : void 0;
2472
+ const O = S(T);
2473
+ return O ? r`(${O})` : void 0;
2474
2474
  }).filter(Boolean);
2475
2475
  if (t.length > 0) {
2476
2476
  const S = t.length === 1 ? t[0] : F(...t);
@@ -2498,12 +2498,12 @@ class je {
2498
2498
  case "stddev":
2499
2499
  case "stddevSamp": {
2500
2500
  const t = E.type === "stddevSamp" || E.statisticalConfig?.useSample, S = this.databaseAdapter.buildStddev(A, t);
2501
- return S === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), O`MAX(NULL)`) : S;
2501
+ return S === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), r`MAX(NULL)`) : S;
2502
2502
  }
2503
2503
  case "variance":
2504
2504
  case "varianceSamp": {
2505
2505
  const t = E.type === "varianceSamp" || E.statisticalConfig?.useSample, S = this.databaseAdapter.buildVariance(A, t);
2506
- return S === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), O`MAX(NULL)`) : S;
2506
+ return S === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), r`MAX(NULL)`) : S;
2507
2507
  }
2508
2508
  case "percentile":
2509
2509
  case "median":
@@ -2524,7 +2524,7 @@ class je {
2524
2524
  t = E.statisticalConfig?.percentile ?? 50;
2525
2525
  }
2526
2526
  const S = this.databaseAdapter.buildPercentile(A, t);
2527
- return S === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), O`MAX(NULL)`) : S;
2527
+ return S === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), r`MAX(NULL)`) : S;
2528
2528
  }
2529
2529
  // Window functions (Phase 2) - now with dimension resolution
2530
2530
  case "lag":
@@ -2546,7 +2546,7 @@ class je {
2546
2546
  }).filter((s) => s !== null);
2547
2547
  N.length > 0 && (S = N);
2548
2548
  }
2549
- let r;
2549
+ let O;
2550
2550
  if (t.orderBy && t.orderBy.length > 0 && R) {
2551
2551
  const N = t.orderBy.map((s) => {
2552
2552
  const I = s.field.includes(".") ? s.field.split(".")[1] : s.field, n = R.dimensions?.[I];
@@ -2561,13 +2561,13 @@ class je {
2561
2561
  direction: s.direction
2562
2562
  } : (console.warn(`[drizzle-cube] Window function order field '${s.field}' not found in cube '${R.name}'`), null);
2563
2563
  }).filter((s) => s !== null);
2564
- N.length > 0 && (r = N);
2564
+ N.length > 0 && (O = N);
2565
2565
  }
2566
2566
  const C = this.databaseAdapter.buildWindowFunction(
2567
2567
  E.type,
2568
2568
  ["rank", "denseRank", "rowNumber"].includes(E.type) ? null : A,
2569
2569
  S,
2570
- r,
2570
+ O,
2571
2571
  {
2572
2572
  offset: t.offset,
2573
2573
  defaultValue: t.defaultValue,
@@ -2575,7 +2575,7 @@ class je {
2575
2575
  frame: t.frame
2576
2576
  }
2577
2577
  );
2578
- return C === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), O`NULL`) : C;
2578
+ return C === null ? (console.warn(`[drizzle-cube] ${E.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), r`NULL`) : C;
2579
2579
  }
2580
2580
  default:
2581
2581
  return kE(A);
@@ -2606,10 +2606,10 @@ class ke {
2606
2606
  const A = {}, t = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
2607
2607
  if (T.dimensions)
2608
2608
  for (const S of T.dimensions) {
2609
- const [r, C] = S.split("."), N = t.get(r);
2609
+ const [O, C] = S.split("."), N = t.get(O);
2610
2610
  if (N && N.dimensions && N.dimensions[C]) {
2611
2611
  const s = N.dimensions[C], I = y(s.sql, R);
2612
- A[S] = O`${I}`.as(S);
2612
+ A[S] = r`${I}`.as(S);
2613
2613
  }
2614
2614
  }
2615
2615
  if (T.measures) {
@@ -2618,24 +2618,24 @@ class ke {
2618
2618
  t,
2619
2619
  R
2620
2620
  );
2621
- for (const r of T.measures) {
2622
- const C = S.get(r);
2621
+ for (const O of T.measures) {
2622
+ const C = S.get(O);
2623
2623
  if (C) {
2624
2624
  const N = C();
2625
- A[r] = O`${N}`.as(r);
2625
+ A[O] = r`${N}`.as(O);
2626
2626
  }
2627
2627
  }
2628
2628
  }
2629
2629
  if (T.timeDimensions)
2630
2630
  for (const S of T.timeDimensions) {
2631
- const [r, C] = S.dimension.split("."), N = t.get(r);
2631
+ const [O, C] = S.dimension.split("."), N = t.get(O);
2632
2632
  if (N && N.dimensions && N.dimensions[C]) {
2633
2633
  const s = N.dimensions[C], I = this.buildTimeDimensionExpression(
2634
2634
  s.sql,
2635
2635
  S.granularity,
2636
2636
  R
2637
2637
  );
2638
- A[S.dimension] = O`${I}`.as(S.dimension);
2638
+ A[S.dimension] = r`${I}`.as(S.dimension);
2639
2639
  }
2640
2640
  }
2641
2641
  return Object.keys(A).length === 0 && (A.count = kE()), A;
@@ -2681,24 +2681,24 @@ class ke {
2681
2681
  * @param preBuiltFilters - Optional map of cube name to pre-built filter SQL for parameter deduplication
2682
2682
  */
2683
2683
  buildWhereConditions(E, T, R, A, t) {
2684
- const S = [], r = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]), C = /* @__PURE__ */ new Set();
2684
+ const S = [], O = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]), C = /* @__PURE__ */ new Set();
2685
2685
  if (T.filters && T.filters.length > 0)
2686
2686
  for (const N of T.filters) {
2687
2687
  if (t && "member" in N) {
2688
2688
  const [I] = N.member.split(".");
2689
- if (r.has(I) && t.has(I) && !C.has(I)) {
2689
+ if (O.has(I) && t.has(I) && !C.has(I)) {
2690
2690
  const i = t.get(I);
2691
2691
  S.push(...i), C.add(I);
2692
2692
  continue;
2693
2693
  } else if (C.has(I))
2694
2694
  continue;
2695
2695
  }
2696
- const s = this.processFilter(N, r, R, "where", A);
2696
+ const s = this.processFilter(N, O, R, "where", A);
2697
2697
  s && S.push(s);
2698
2698
  }
2699
2699
  if (T.timeDimensions)
2700
2700
  for (const N of T.timeDimensions) {
2701
- const [s, I] = N.dimension.split("."), n = r.get(s);
2701
+ const [s, I] = N.dimension.split("."), n = O.get(s);
2702
2702
  if (n && n.dimensions[I] && N.dateRange) {
2703
2703
  if (A?.preAggregationCTEs && A.preAggregationCTEs.some((l) => l.cube.name === s))
2704
2704
  continue;
@@ -2722,8 +2722,8 @@ class ke {
2722
2722
  buildHavingConditions(E, T, R, A) {
2723
2723
  const t = [], S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
2724
2724
  if (T.filters && T.filters.length > 0)
2725
- for (const r of T.filters) {
2726
- const C = this.processFilter(r, S, R, "having", A);
2725
+ for (const O of T.filters) {
2726
+ const C = this.processFilter(O, S, R, "having", A);
2727
2727
  C && t.push(C);
2728
2728
  }
2729
2729
  return t;
@@ -2744,12 +2744,12 @@ class ke {
2744
2744
  return L.length > 0 ? tE(...L) : null;
2745
2745
  }
2746
2746
  }
2747
- const S = E, [r, C] = S.member.split("."), N = T.get(r);
2747
+ const S = E, [O, C] = S.member.split("."), N = T.get(O);
2748
2748
  if (!N) return null;
2749
2749
  const s = N.dimensions[C], I = N.measures[C], n = s || I;
2750
2750
  if (!n) return null;
2751
2751
  if (A === "where" && s) {
2752
- if (t?.preAggregationCTEs && t.preAggregationCTEs.some((D) => D.cube.name === r))
2752
+ if (t?.preAggregationCTEs && t.preAggregationCTEs.some((D) => D.cube.name === O))
2753
2753
  return null;
2754
2754
  const i = ["arrayContains", "arrayOverlaps", "arrayContained"].includes(S.operator);
2755
2755
  if (!i && R.filterCache) {
@@ -2769,7 +2769,7 @@ class ke {
2769
2769
  if (A === "where" && I)
2770
2770
  return null;
2771
2771
  if (A === "having" && I) {
2772
- const i = this.buildHavingMeasureExpression(r, C, I, R, t);
2772
+ const i = this.buildHavingMeasureExpression(O, C, I, R, t);
2773
2773
  return this.buildFilterCondition(
2774
2774
  i,
2775
2775
  S.operator,
@@ -2815,15 +2815,15 @@ class ke {
2815
2815
  for (const [t, S] of Object.entries(E.order)) {
2816
2816
  if (!A.includes(t))
2817
2817
  throw new Error(`Cannot order by '${t}': field is not selected in the query`);
2818
- const r = S === "desc" ? Fe(O.identifier(t)) : LT(O.identifier(t));
2819
- R.push(r);
2818
+ const O = S === "desc" ? Fe(r.identifier(t)) : LT(r.identifier(t));
2819
+ R.push(O);
2820
2820
  }
2821
2821
  if (E.timeDimensions && E.timeDimensions.length > 0) {
2822
2822
  const t = new Set(Object.keys(E.order || {})), S = [...E.timeDimensions].sort(
2823
- (r, C) => r.dimension.localeCompare(C.dimension)
2823
+ (O, C) => O.dimension.localeCompare(C.dimension)
2824
2824
  );
2825
- for (const r of S)
2826
- t.has(r.dimension) || R.push(LT(O.identifier(r.dimension)));
2825
+ for (const O of S)
2826
+ t.has(O.dimension) || R.push(LT(r.identifier(O.dimension)));
2827
2827
  }
2828
2828
  return R;
2829
2829
  }
@@ -2835,9 +2835,9 @@ class ke {
2835
2835
  const R = [], A = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
2836
2836
  if (T.measures && R.push(...T.measures), T.dimensions)
2837
2837
  for (const t of T.dimensions) {
2838
- const [S, r] = t.split("."), C = A.get(S);
2838
+ const [S, O] = t.split("."), C = A.get(S);
2839
2839
  if (C) {
2840
- const N = C.dimensions[r];
2840
+ const N = C.dimensions[O];
2841
2841
  N && N.type === "number" && R.push(t);
2842
2842
  }
2843
2843
  }
@@ -2905,13 +2905,13 @@ class ze {
2905
2905
  return t;
2906
2906
  const S = [
2907
2907
  { cube: E, path: [] }
2908
- ], r = /* @__PURE__ */ new Set([E, ...R]);
2908
+ ], O = /* @__PURE__ */ new Set([E, ...R]);
2909
2909
  for (; S.length > 0; ) {
2910
2910
  const { cube: C, path: N } = S.shift(), s = this.cubes.get(C);
2911
2911
  if (s?.joins)
2912
2912
  for (const [, I] of Object.entries(s.joins)) {
2913
2913
  const i = LE(I.targetCube).name;
2914
- if (r.has(i))
2914
+ if (O.has(i))
2915
2915
  continue;
2916
2916
  const L = [
2917
2917
  ...N,
@@ -2923,7 +2923,7 @@ class ze {
2923
2923
  ];
2924
2924
  if (i === T)
2925
2925
  return this.setInCache(A, L), L;
2926
- r.add(i), S.push({ cube: i, path: L });
2926
+ O.add(i), S.push({ cube: i, path: L });
2927
2927
  }
2928
2928
  }
2929
2929
  return this.setInCache(A, null), null;
@@ -2955,8 +2955,8 @@ class ze {
2955
2955
  buildJoinCondition(E, T, R) {
2956
2956
  const A = [];
2957
2957
  for (const t of E.on) {
2958
- const S = T ? O`${O.identifier(T)}.${O.identifier(t.source.name)}` : ET(t.source), r = R ? O`${O.identifier(R)}.${O.identifier(t.target.name)}` : ET(t.target), C = t.as || v;
2959
- A.push(C(S, r));
2958
+ const S = T ? r`${r.identifier(T)}.${r.identifier(t.source.name)}` : ET(t.source), O = R ? r`${r.identifier(R)}.${r.identifier(t.target.name)}` : ET(t.target), C = t.as || v;
2959
+ A.push(C(S, O));
2960
2960
  }
2961
2961
  return F(...A);
2962
2962
  }
@@ -3077,12 +3077,12 @@ class Se {
3077
3077
  const A = this.analyzeCubeUsage(T), t = Array.from(A);
3078
3078
  if (t.length === 0)
3079
3079
  throw new Error("No cubes found in query");
3080
- const S = this.choosePrimaryCube(t, T, E), r = E.get(S);
3081
- if (!r)
3080
+ const S = this.choosePrimaryCube(t, T, E), O = E.get(S);
3081
+ if (!O)
3082
3082
  throw new Error(`Primary cube '${S}' not found`);
3083
3083
  if (t.length === 1)
3084
3084
  return {
3085
- primaryCube: r,
3085
+ primaryCube: O,
3086
3086
  joinCubes: [],
3087
3087
  // Empty for single cube
3088
3088
  selections: {},
@@ -3092,9 +3092,9 @@ class Se {
3092
3092
  groupByFields: []
3093
3093
  // Will be built by QueryBuilder
3094
3094
  };
3095
- const C = this.buildJoinPlan(E, r, t, R), N = this.planPreAggregationCTEs(E, r, C, T);
3095
+ const C = this.buildJoinPlan(E, O, t, R), N = this.planPreAggregationCTEs(E, O, C, T);
3096
3096
  return {
3097
- primaryCube: r,
3097
+ primaryCube: O,
3098
3098
  joinCubes: C,
3099
3099
  selections: {},
3100
3100
  // Will be built by QueryBuilder
@@ -3120,15 +3120,15 @@ class Se {
3120
3120
  * Supports both direct joins and transitive joins through intermediate cubes
3121
3121
  */
3122
3122
  buildJoinPlan(E, T, R, A) {
3123
- const t = this.getResolver(E), S = [], r = /* @__PURE__ */ new Set([T.name]), C = R.filter((N) => N !== T.name);
3123
+ const t = this.getResolver(E), S = [], O = /* @__PURE__ */ new Set([T.name]), C = R.filter((N) => N !== T.name);
3124
3124
  for (const N of C) {
3125
- if (r.has(N))
3125
+ if (O.has(N))
3126
3126
  continue;
3127
- const s = t.findPath(T.name, N, r);
3127
+ const s = t.findPath(T.name, N, O);
3128
3128
  if (!s || s.length === 0)
3129
3129
  throw new Error(`No join path found from '${T.name}' to '${N}'`);
3130
3130
  for (const { toCube: I, joinDef: n } of s) {
3131
- if (r.has(I))
3131
+ if (O.has(I))
3132
3132
  continue;
3133
3133
  const i = E.get(I);
3134
3134
  if (!i)
@@ -3165,7 +3165,7 @@ class Se {
3165
3165
  joinCondition: L
3166
3166
  });
3167
3167
  }
3168
- r.add(I);
3168
+ O.add(I);
3169
3169
  }
3170
3170
  }
3171
3171
  return S;
@@ -3180,8 +3180,8 @@ class Se {
3180
3180
  if (!A.measures || A.measures.length === 0)
3181
3181
  return t;
3182
3182
  for (const S of R) {
3183
- const r = this.findHasManyJoinDef(T, S.cube.name);
3184
- if (!r)
3183
+ const O = this.findHasManyJoinDef(T, S.cube.name);
3184
+ if (!O)
3185
3185
  continue;
3186
3186
  const C = A.measures ? A.measures.filter(
3187
3187
  (L) => L.startsWith(S.cube.name + ".")
@@ -3191,7 +3191,7 @@ class Se {
3191
3191
  const I = this.expandCalculatedMeasureDependencies(
3192
3192
  S.cube,
3193
3193
  s
3194
- ), n = r.on.map((L) => ({
3194
+ ), n = O.on.map((L) => ({
3195
3195
  sourceColumn: L.source.name,
3196
3196
  targetColumn: L.target.name,
3197
3197
  sourceColumnObj: L.source,
@@ -3221,9 +3221,9 @@ class Se {
3221
3221
  const [, S] = t.split(".");
3222
3222
  if (!E.measures || !E.measures[S])
3223
3223
  continue;
3224
- const r = E.measures[S];
3225
- if (r.type === "calculated" && r.calculatedSql) {
3226
- const C = this.extractDependenciesFromTemplate(r.calculatedSql, E.name);
3224
+ const O = E.measures[S];
3225
+ if (O.type === "calculated" && O.calculatedSql) {
3226
+ const C = this.extractDependenciesFromTemplate(O.calculatedSql, E.name);
3227
3227
  for (const N of C)
3228
3228
  R.has(N) || A.push(N);
3229
3229
  }
@@ -3236,8 +3236,8 @@ class Se {
3236
3236
  extractDependenciesFromTemplate(E, T) {
3237
3237
  const R = /\{([^}]+)\}/g, A = E.matchAll(R), t = [];
3238
3238
  for (const S of A) {
3239
- const r = S[1].trim();
3240
- r.includes(".") ? t.push(r) : t.push(`${T}.${r}`);
3239
+ const O = S[1].trim();
3240
+ O.includes(".") ? t.push(O) : t.push(`${T}.${O}`);
3241
3241
  }
3242
3242
  return t;
3243
3243
  }
@@ -3267,19 +3267,19 @@ class Se {
3267
3267
  if (this.extractFilterCubeNamesToSet(E.filters, t), E.timeDimensions) {
3268
3268
  for (const S of E.timeDimensions)
3269
3269
  if (S.dateRange) {
3270
- const [r] = S.dimension.split(".");
3271
- r && t.add(r);
3270
+ const [O] = S.dimension.split(".");
3271
+ O && t.add(O);
3272
3272
  }
3273
3273
  }
3274
3274
  for (const S of t) {
3275
3275
  if (S === T.name) continue;
3276
- const r = R.get(S);
3277
- if (r?.joins) {
3278
- for (const [, C] of Object.entries(r.joins))
3276
+ const O = R.get(S);
3277
+ if (O?.joins) {
3278
+ for (const [, C] of Object.entries(O.joins))
3279
3279
  if (LE(C.targetCube).name === T.name && C.relationship === "hasMany") {
3280
3280
  const s = this.extractFiltersForCube(E.filters, S), I = this.extractTimeDimensionFiltersForCube(E, S), n = [...s, ...I];
3281
3281
  n.length > 0 && C.on.length > 0 && A.push({
3282
- sourceCube: r,
3282
+ sourceCube: O,
3283
3283
  filters: n,
3284
3284
  // Map all join keys for composite key support
3285
3285
  // source = filterCube PK (e.g., employees.id)
@@ -3330,8 +3330,8 @@ class Se {
3330
3330
  if ("or" in A) {
3331
3331
  const t = A.or || [];
3332
3332
  if (this.allFiltersFromCube(t, T)) {
3333
- const r = this.extractFiltersForCube(t, T);
3334
- r.length > 0 && R.push({ or: r });
3333
+ const O = this.extractFiltersForCube(t, T);
3334
+ O.length > 0 && R.push({ or: O });
3335
3335
  }
3336
3336
  continue;
3337
3337
  }
@@ -3409,7 +3409,7 @@ class Se {
3409
3409
  },
3410
3410
  warnings: ["No cubes found in query - add measures or dimensions"]
3411
3411
  };
3412
- const S = this.analyzePrimaryCubeSelection(t, T, E), r = S.selectedCube, C = {
3412
+ const S = this.analyzePrimaryCubeSelection(t, T, E), O = S.selectedCube, C = {
3413
3413
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
3414
3414
  cubeCount: t.length,
3415
3415
  cubesInvolved: t.sort(),
@@ -3425,12 +3425,12 @@ class Se {
3425
3425
  warnings: []
3426
3426
  };
3427
3427
  if (t.length > 1) {
3428
- const N = t.filter((i) => i !== r);
3428
+ const N = t.filter((i) => i !== O);
3429
3429
  for (const i of N)
3430
3430
  C.joinPaths.push(
3431
- this.analyzeJoinPath(E, r, i)
3431
+ this.analyzeJoinPath(E, O, i)
3432
3432
  );
3433
- const s = E.get(r);
3433
+ const s = E.get(O);
3434
3434
  s && (C.preAggregations = this.analyzePreAggregations(
3435
3435
  E,
3436
3436
  s,
@@ -3459,9 +3459,9 @@ class Se {
3459
3459
  const A = [], t = (T.dimensions || []).map((s) => s.split(".")[0]), S = /* @__PURE__ */ new Map();
3460
3460
  for (const s of t)
3461
3461
  S.set(s, (S.get(s) || 0) + 1);
3462
- const r = this.getResolver(R);
3462
+ const O = this.getResolver(R);
3463
3463
  for (const s of E) {
3464
- const I = R.get(s), n = S.get(s) || 0, i = I?.joins ? Object.keys(I.joins).length : 0, L = r.canReachAll(s, E);
3464
+ const I = R.get(s), n = S.get(s) || 0, i = I?.joins ? Object.keys(I.joins).length : 0, L = O.canReachAll(s, E);
3465
3465
  A.push({
3466
3466
  cubeName: s,
3467
3467
  dimensionCount: n,
@@ -3518,7 +3518,7 @@ class Se {
3518
3518
  error: `No join path found from '${T}' to '${R}'. Ensure the target cube has a relationship defined (belongsTo, hasOne, hasMany, or belongsToMany).`,
3519
3519
  visitedCubes: S
3520
3520
  };
3521
- const r = t.map((C) => {
3521
+ const O = t.map((C) => {
3522
3522
  const N = zE(C.joinDef.relationship, C.joinDef.sqlJoinType), s = C.joinDef.on.map((n) => ({
3523
3523
  sourceColumn: n.source.name,
3524
3524
  targetColumn: n.target.name
@@ -3542,8 +3542,8 @@ class Se {
3542
3542
  return {
3543
3543
  targetCube: R,
3544
3544
  pathFound: !0,
3545
- path: r,
3546
- pathLength: r.length,
3545
+ path: O,
3546
+ pathLength: O.length,
3547
3547
  visitedCubes: S
3548
3548
  };
3549
3549
  }
@@ -3556,8 +3556,8 @@ class Se {
3556
3556
  if (!A.measures || A.measures.length === 0)
3557
3557
  return t;
3558
3558
  for (const S of R) {
3559
- const r = this.findHasManyJoinDef(T, S);
3560
- if (!r)
3559
+ const O = this.findHasManyJoinDef(T, S);
3560
+ if (!O)
3561
3561
  continue;
3562
3562
  const C = E.get(S);
3563
3563
  if (!C)
@@ -3567,7 +3567,7 @@ class Se {
3567
3567
  ), s = this.extractMeasuresFromFilters(A, C), I = [.../* @__PURE__ */ new Set([...N, ...s])];
3568
3568
  if (I.length === 0)
3569
3569
  continue;
3570
- const n = r.on.map((i) => ({
3570
+ const n = O.on.map((i) => ({
3571
3571
  sourceColumn: i.source.name,
3572
3572
  targetColumn: i.target.name
3573
3573
  }));
@@ -3596,12 +3596,12 @@ class ER {
3596
3596
  * 4. Handles propagating filters from related cubes
3597
3597
  */
3598
3598
  buildPreAggregationCTE(E, T, R, A, t) {
3599
- const S = E.cube, r = S.sql(R), C = {};
3599
+ const S = E.cube, O = S.sql(R), C = {};
3600
3600
  for (const P of E.joinKeys)
3601
3601
  if (P.targetColumnObj) {
3602
3602
  C[P.targetColumn] = P.targetColumnObj;
3603
3603
  for (const [u, U] of Object.entries(S.dimensions || {}))
3604
- U.sql === P.targetColumnObj && u !== P.targetColumn && (C[u] = O`${P.targetColumnObj}`.as(u));
3604
+ U.sql === P.targetColumnObj && u !== P.targetColumn && (C[u] = r`${P.targetColumnObj}`.as(u));
3605
3605
  }
3606
3606
  const N = S.name, s = /* @__PURE__ */ new Map([[N, S]]), I = this.queryBuilder.buildResolvedMeasures(
3607
3607
  E.measures,
@@ -3612,7 +3612,7 @@ class ER {
3612
3612
  const [, u] = P.split("."), U = I.get(P);
3613
3613
  if (U) {
3614
3614
  const d = U();
3615
- C[u] = O`${d}`.as(u);
3615
+ C[u] = r`${d}`.as(u);
3616
3616
  }
3617
3617
  }
3618
3618
  if (T.dimensions)
@@ -3620,7 +3620,7 @@ class ER {
3620
3620
  const [u, U] = P.split(".");
3621
3621
  if (u === N && S.dimensions && S.dimensions[U]) {
3622
3622
  const d = S.dimensions[U], m = this.queryBuilder.buildMeasureExpression({ sql: d.sql, type: "number" }, R);
3623
- C[U] = O`${m}`.as(U);
3623
+ C[U] = r`${m}`.as(U);
3624
3624
  }
3625
3625
  }
3626
3626
  if (T.timeDimensions)
@@ -3628,12 +3628,12 @@ class ER {
3628
3628
  const [u, U] = P.dimension.split(".");
3629
3629
  if (u === N && S.dimensions && S.dimensions[U]) {
3630
3630
  const d = S.dimensions[U], m = this.queryBuilder.buildTimeDimensionExpression(d.sql, P.granularity, R);
3631
- C[U] = O`${m}`.as(U);
3631
+ C[U] = r`${m}`.as(U);
3632
3632
  }
3633
3633
  }
3634
3634
  if (Object.keys(C).length === 0)
3635
3635
  return null;
3636
- let n = R.db.select(C).from(r.from);
3636
+ let n = R.db.select(C).from(O.from);
3637
3637
  const i = A ? {
3638
3638
  ...A,
3639
3639
  preAggregationCTEs: A.preAggregationCTEs?.filter((P) => P.cube.name !== S.name)
@@ -3668,7 +3668,7 @@ class ER {
3668
3668
  u && M.push(u);
3669
3669
  }
3670
3670
  const D = [];
3671
- if (r.where && D.push(r.where), D.push(...L, ...M), D.length > 0) {
3671
+ if (O.where && D.push(O.where), D.push(...L, ...M), D.length > 0) {
3672
3672
  const P = D.length === 1 ? D[0] : F(...D);
3673
3673
  n = n.where(P);
3674
3674
  }
@@ -3705,8 +3705,8 @@ class ER {
3705
3705
  throw new Error(`CTE info not found for cube ${E.cube.name}`);
3706
3706
  const t = [];
3707
3707
  for (const S of A.joinKeys) {
3708
- const r = S.sourceColumnObj || O.identifier(S.sourceColumn), C = O`${O.identifier(T)}.${O.identifier(S.targetColumn)}`;
3709
- t.push(v(r, C));
3708
+ const O = S.sourceColumnObj || r.identifier(S.sourceColumn), C = r`${r.identifier(T)}.${r.identifier(S.targetColumn)}`;
3709
+ t.push(v(O, C));
3710
3710
  }
3711
3711
  return t.length === 1 ? t[0] : F(...t);
3712
3712
  }
@@ -3737,16 +3737,16 @@ class ER {
3737
3737
  }
3738
3738
  if (t.length === 0)
3739
3739
  return null;
3740
- const S = t.length === 1 ? t[0] : F(...t), r = E.joinConditions;
3741
- if (r.length === 1) {
3742
- const { source: C, target: N } = r[0], s = T.db.select({ pk: C }).from(A.from).where(S);
3743
- return O`${N} IN ${s}`;
3740
+ const S = t.length === 1 ? t[0] : F(...t), O = E.joinConditions;
3741
+ if (O.length === 1) {
3742
+ const { source: C, target: N } = O[0], s = T.db.select({ pk: C }).from(A.from).where(S);
3743
+ return r`${N} IN ${s}`;
3744
3744
  } else {
3745
- const C = r.map((I) => v(I.source, I.target)), N = F(
3745
+ const C = O.map((I) => v(I.source, I.target)), N = F(
3746
3746
  ...C,
3747
3747
  S
3748
- ), s = T.db.select({ one: O`1` }).from(A.from).where(N);
3749
- return O`EXISTS ${s}`;
3748
+ ), s = T.db.select({ one: r`1` }).from(A.from).where(N);
3749
+ return r`EXISTS ${s}`;
3750
3750
  }
3751
3751
  }
3752
3752
  }
@@ -3836,15 +3836,15 @@ function AR(e, E) {
3836
3836
  return E.length === 0 ? "__all__" : E.map((T) => String(e[T] ?? "")).join("|||");
3837
3837
  }
3838
3838
  function tR(e, E) {
3839
- const { timeDimensionKey: T, granularity: R, dateRange: A, fillValue: t, measures: S, dimensions: r } = E, C = TR(A[0], A[1], R);
3839
+ const { timeDimensionKey: T, granularity: R, dateRange: A, fillValue: t, measures: S, dimensions: O } = E, C = TR(A[0], A[1], R);
3840
3840
  if (C.length === 0)
3841
3841
  return e;
3842
3842
  const N = /* @__PURE__ */ new Map();
3843
3843
  for (const I of e) {
3844
- const n = AR(I, r), i = RR(I[T]);
3844
+ const n = AR(I, O), i = RR(I[T]);
3845
3845
  N.has(n) || N.set(n, /* @__PURE__ */ new Map()), N.get(n).set(i, I);
3846
3846
  }
3847
- N.size === 0 && r.length === 0 && N.set("__all__", /* @__PURE__ */ new Map());
3847
+ N.size === 0 && O.length === 0 && N.set("__all__", /* @__PURE__ */ new Map());
3848
3848
  const s = [];
3849
3849
  for (const [I, n] of N) {
3850
3850
  const i = n.size > 0 ? n.values().next().value : null;
@@ -3857,7 +3857,7 @@ function tR(e, E) {
3857
3857
  [T]: M
3858
3858
  };
3859
3859
  if (i)
3860
- for (const P of r)
3860
+ for (const P of O)
3861
3861
  l[P] = i[P];
3862
3862
  for (const P of S)
3863
3863
  l[P] = t;
@@ -3889,7 +3889,7 @@ function sR(e, E, T) {
3889
3889
  if (R.length === 0)
3890
3890
  return e;
3891
3891
  const A = E.fillMissingDatesValue === void 0 ? 0 : E.fillMissingDatesValue, t = new Set(E.timeDimensions.map((C) => C.dimension)), S = (E.dimensions || []).filter((C) => !t.has(C));
3892
- let r = e;
3892
+ let O = e;
3893
3893
  for (const C of R) {
3894
3894
  const N = SR(C.dateRange);
3895
3895
  if (!N)
@@ -3902,9 +3902,9 @@ function sR(e, E, T) {
3902
3902
  measures: T,
3903
3903
  dimensions: S
3904
3904
  };
3905
- r = tR(r, s);
3905
+ O = tR(O, s);
3906
3906
  }
3907
- return r;
3907
+ return O;
3908
3908
  }
3909
3909
  class mE {
3910
3910
  constructor(E) {
@@ -3931,9 +3931,9 @@ class mE {
3931
3931
  filterCache: t
3932
3932
  };
3933
3933
  this.preloadFilterCache(T, t, E, S);
3934
- const r = this.queryPlanner.createQueryPlan(E, T, S);
3935
- this.validateSecurityContext(r, S);
3936
- const C = this.buildUnifiedQuery(r, T, S), N = this.queryBuilder.collectNumericFields(E, T), s = await this.dbExecutor.execute(C, N), I = Array.isArray(s) ? s.map((M) => {
3934
+ const O = this.queryPlanner.createQueryPlan(E, T, S);
3935
+ this.validateSecurityContext(O, S);
3936
+ const C = this.buildUnifiedQuery(O, T, S), N = this.queryBuilder.collectNumericFields(E, T), s = await this.dbExecutor.execute(C, N), I = Array.isArray(s) ? s.map((M) => {
3937
3937
  const D = { ...M };
3938
3938
  if (T.timeDimensions) {
3939
3939
  for (const l of T.timeDimensions)
@@ -3947,7 +3947,7 @@ class mE {
3947
3947
  }
3948
3948
  }
3949
3949
  return D;
3950
- }) : [s], n = T.measures || [], i = sR(I, T, n), L = this.generateAnnotations(r, T);
3950
+ }) : [s], n = T.measures || [], i = sR(I, T, n), L = this.generateAnnotations(O, T);
3951
3951
  return {
3952
3952
  data: i,
3953
3953
  annotation: L
@@ -3971,20 +3971,21 @@ class mE {
3971
3971
  * detect cubes that may leak data across tenants.
3972
3972
  */
3973
3973
  validateSecurityContext(E, T) {
3974
- if (process.env.NODE_ENV !== "development" && !process.env.DRIZZLE_CUBE_WARN_SECURITY)
3974
+ const R = typeof process < "u" ? process.env?.NODE_ENV : void 0, A = typeof process < "u" ? process.env?.DRIZZLE_CUBE_WARN_SECURITY : void 0;
3975
+ if (R !== "development" && !A)
3975
3976
  return;
3976
- const R = [E.primaryCube];
3977
- for (const t of E.joinCubes || [])
3978
- R.push(t.cube);
3979
- for (const t of E.preAggregationCTEs || [])
3980
- R.push(t.cube);
3981
- const A = /* @__PURE__ */ new Set();
3982
- for (const t of R)
3983
- if (!A.has(t.name)) {
3984
- A.add(t.name);
3977
+ const t = [E.primaryCube];
3978
+ for (const O of E.joinCubes || [])
3979
+ t.push(O.cube);
3980
+ for (const O of E.preAggregationCTEs || [])
3981
+ t.push(O.cube);
3982
+ const S = /* @__PURE__ */ new Set();
3983
+ for (const O of t)
3984
+ if (!S.has(O.name)) {
3985
+ S.add(O.name);
3985
3986
  try {
3986
- t.sql(T).where || console.warn(
3987
- `[drizzle-cube] WARNING: Cube '${t.name}' may not have proper security filtering. The sql() function returned no 'where' clause. Ensure it returns a filter like: { from: table, where: eq(table.organisationId, ctx.securityContext.organisationId) }`
3987
+ O.sql(T).where || console.warn(
3988
+ `[drizzle-cube] WARNING: Cube '${O.name}' may not have proper security filtering. The sql() function returned no 'where' clause. Ensure it returns a filter like: { from: table, where: eq(table.organisationId, ctx.securityContext.organisationId) }`
3988
3989
  );
3989
3990
  } catch {
3990
3991
  }
@@ -4020,7 +4021,7 @@ class mE {
4020
4021
  const l = this.cteBuilder.buildPreAggregationCTE(D, T, R, E, A);
4021
4022
  l && (t.push(l), S.set(D.cube.name, D.cteAlias));
4022
4023
  }
4023
- const r = E.primaryCube.sql(R), N = { ...this.queryBuilder.buildSelections(
4024
+ const O = E.primaryCube.sql(R), N = { ...this.queryBuilder.buildSelections(
4024
4025
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
4025
4026
  // Single cube
4026
4027
  T,
@@ -4045,7 +4046,7 @@ class mE {
4045
4046
  R
4046
4047
  );
4047
4048
  } else {
4048
- const B = O`${O.identifier(D.cteAlias)}.${O.identifier(u)}`;
4049
+ const B = r`${r.identifier(D.cteAlias)}.${r.identifier(u)}`;
4049
4050
  switch (d.type) {
4050
4051
  case "count":
4051
4052
  case "countDistinct":
@@ -4068,7 +4069,7 @@ class mE {
4068
4069
  m = $(B);
4069
4070
  }
4070
4071
  }
4071
- N[P] = O`${m}`.as(P);
4072
+ N[P] = r`${m}`.as(P);
4072
4073
  }
4073
4074
  }
4074
4075
  for (const P in N) {
@@ -4081,15 +4082,15 @@ class mE {
4081
4082
  const DE = d.dimensions[U].sql;
4082
4083
  Z = D.joinKeys.find((le) => le.targetColumnObj === DE);
4083
4084
  }
4084
- Z ? N[P] = O`${O.identifier(D.cteAlias)}.${O.identifier(U)}`.as(P) : B && d?.dimensions?.[U] && (N[P] = O`${O.identifier(D.cteAlias)}.${O.identifier(U)}`.as(P));
4085
+ Z ? N[P] = r`${r.identifier(D.cteAlias)}.${r.identifier(U)}`.as(P) : B && d?.dimensions?.[U] && (N[P] = r`${r.identifier(D.cteAlias)}.${r.identifier(U)}`.as(P));
4085
4086
  }
4086
4087
  }
4087
4088
  }
4088
4089
  }
4089
4090
  const s = [];
4090
- let I = R.db.select(N).from(r.from);
4091
- if (t.length > 0 && (I = R.db.with(...t).select(N).from(r.from)), r.joins)
4092
- for (const D of r.joins)
4091
+ let I = R.db.select(N).from(O.from);
4092
+ if (t.length > 0 && (I = R.db.with(...t).select(N).from(O.from)), O.joins)
4093
+ for (const D of O.joins)
4093
4094
  switch (D.type || "left") {
4094
4095
  case "left":
4095
4096
  I = I.leftJoin(D.table, D.on);
@@ -4133,7 +4134,7 @@ class mE {
4133
4134
  }
4134
4135
  }
4135
4136
  let P, u;
4136
- l ? (P = O`${O.identifier(l)}`, u = this.cteBuilder.buildCTEJoinCondition(D, l, E)) : (P = D.cube.sql(R).from, u = D.joinCondition);
4137
+ l ? (P = r`${r.identifier(l)}`, u = this.cteBuilder.buildCTEJoinCondition(D, l, E)) : (P = D.cube.sql(R).from, u = D.joinCondition);
4137
4138
  try {
4138
4139
  switch (D.joinType || "left") {
4139
4140
  case "left":
@@ -4152,7 +4153,7 @@ class mE {
4152
4153
  } catch {
4153
4154
  }
4154
4155
  }
4155
- if (r.where && s.push(r.where), E.joinCubes && E.joinCubes.length > 0)
4156
+ if (O.where && s.push(O.where), E.joinCubes && E.joinCubes.length > 0)
4156
4157
  for (const D of E.joinCubes) {
4157
4158
  if (S.get(D.cube.name))
4158
4159
  continue;
@@ -4228,10 +4229,10 @@ class mE {
4228
4229
  db: this.dbExecutor.db,
4229
4230
  schema: this.dbExecutor.schema,
4230
4231
  securityContext: R
4231
- }, t = this.queryPlanner.createQueryPlan(E, T, A), r = this.buildUnifiedQuery(t, T, A).toSQL();
4232
+ }, t = this.queryPlanner.createQueryPlan(E, T, A), O = this.buildUnifiedQuery(t, T, A).toSQL();
4232
4233
  return {
4233
- sql: r.sql,
4234
- params: r.params
4234
+ sql: O.sql,
4235
+ params: O.params
4235
4236
  };
4236
4237
  }
4237
4238
  /**
@@ -4239,12 +4240,12 @@ class mE {
4239
4240
  */
4240
4241
  generateAnnotations(E, T) {
4241
4242
  const R = {}, A = {}, t = {}, S = [E.primaryCube];
4242
- if (E.joinCubes && E.joinCubes.length > 0 && S.push(...E.joinCubes.map((r) => r.cube)), T.measures)
4243
- for (const r of T.measures) {
4244
- const [C, N] = r.split("."), s = S.find((I) => I.name === C);
4243
+ if (E.joinCubes && E.joinCubes.length > 0 && S.push(...E.joinCubes.map((O) => O.cube)), T.measures)
4244
+ for (const O of T.measures) {
4245
+ const [C, N] = O.split("."), s = S.find((I) => I.name === C);
4245
4246
  if (s && s.measures[N]) {
4246
4247
  const I = s.measures[N];
4247
- R[r] = {
4248
+ R[O] = {
4248
4249
  title: I.title || N,
4249
4250
  shortTitle: I.title || N,
4250
4251
  type: I.type
@@ -4252,11 +4253,11 @@ class mE {
4252
4253
  }
4253
4254
  }
4254
4255
  if (T.dimensions)
4255
- for (const r of T.dimensions) {
4256
- const [C, N] = r.split("."), s = S.find((I) => I.name === C);
4256
+ for (const O of T.dimensions) {
4257
+ const [C, N] = O.split("."), s = S.find((I) => I.name === C);
4257
4258
  if (s && s.dimensions[N]) {
4258
4259
  const I = s.dimensions[N];
4259
- A[r] = {
4260
+ A[O] = {
4260
4261
  title: I.title || N,
4261
4262
  shortTitle: I.title || N,
4262
4263
  type: I.type
@@ -4264,15 +4265,15 @@ class mE {
4264
4265
  }
4265
4266
  }
4266
4267
  if (T.timeDimensions)
4267
- for (const r of T.timeDimensions) {
4268
- const [C, N] = r.dimension.split("."), s = S.find((I) => I.name === C);
4268
+ for (const O of T.timeDimensions) {
4269
+ const [C, N] = O.dimension.split("."), s = S.find((I) => I.name === C);
4269
4270
  if (s && s.dimensions && s.dimensions[N]) {
4270
4271
  const I = s.dimensions[N];
4271
- t[r.dimension] = {
4272
+ t[O.dimension] = {
4272
4273
  title: I.title || N,
4273
4274
  shortTitle: I.title || N,
4274
4275
  type: I.type,
4275
- granularity: r.granularity
4276
+ granularity: O.granularity
4276
4277
  };
4277
4278
  }
4278
4279
  }
@@ -4292,8 +4293,8 @@ class mE {
4292
4293
  if (E.filters && E.filters.length > 0) {
4293
4294
  const t = TT(E.filters);
4294
4295
  for (const S of t) {
4295
- const r = aE(S);
4296
- if (T.has(r)) continue;
4296
+ const O = aE(S);
4297
+ if (T.has(O)) continue;
4297
4298
  const [C, N] = S.member.split("."), s = R.get(C);
4298
4299
  if (!s) continue;
4299
4300
  const I = s.dimensions?.[N];
@@ -4306,7 +4307,7 @@ class mE {
4306
4307
  I,
4307
4308
  S.dateRange
4308
4309
  );
4309
- L && T.set(r, L);
4310
+ L && T.set(O, L);
4310
4311
  }
4311
4312
  }
4312
4313
  if (E.timeDimensions) {
@@ -4314,7 +4315,7 @@ class mE {
4314
4315
  if (t.dateRange) {
4315
4316
  const S = te(t.dimension, t.dateRange);
4316
4317
  if (T.has(S)) continue;
4317
- const [r, C] = t.dimension.split("."), N = R.get(r);
4318
+ const [O, C] = t.dimension.split("."), N = R.get(O);
4318
4319
  if (!N) continue;
4319
4320
  const s = N.dimensions?.[C];
4320
4321
  if (!s) continue;
@@ -19865,7 +19866,7 @@ const vt = [
19865
19866
  "[": "]",
19866
19867
  "(": ")",
19867
19868
  "{": "}"
19868
- }, E = "{left}(?:(?!{right}').)*?{right}", T = Object.entries(e).map(([S, r]) => E.replace(/{left}/g, X(S)).replace(/{right}/g, X(r))), R = X(Object.keys(e).join(""));
19869
+ }, E = "{left}(?:(?!{right}').)*?{right}", T = Object.entries(e).map(([S, O]) => E.replace(/{left}/g, X(S)).replace(/{right}/g, X(O))), R = X(Object.keys(e).join(""));
19869
19870
  return `[Qq]'(?:${String.raw`(?<tag>[^\s${R}])(?:(?!\k<tag>').)*?\k<tag>`}|${T.join("|")})'`;
19870
19871
  }, KT = {
19871
19872
  // - backtick quoted (using `` to escape)
@@ -19893,7 +19894,7 @@ const vt = [
19893
19894
  // Oracle q'' strings: q'<text>' q'|text|' ...
19894
19895
  "q''": As()
19895
19896
  }, Oe = (e) => typeof e == "string" ? KT[e] : "regex" in e ? e.regex : Ts(e) + KT[e.quote], ts = (e) => Q(e.map((E) => "regex" in E ? E.regex : Oe(E)).join("|")), re = (e) => e.map(Oe).join("|"), wT = (e) => Q(re(e)), Ss = (e = {}) => Q(ne(e)), ne = ({ first: e, rest: E, dashes: T, allowFirstCharNumber: R } = {}) => {
19896
- const A = "\\p{Alphabetic}\\p{Mark}_", t = "\\p{Decimal_Number}", S = X(e ?? ""), r = X(E ?? ""), C = R ? `[${A}${t}${S}][${A}${t}${r}]*` : `[${A}${S}][${A}${t}${r}]*`;
19897
+ const A = "\\p{Alphabetic}\\p{Mark}_", t = "\\p{Decimal_Number}", S = X(e ?? ""), O = X(E ?? ""), C = R ? `[${A}${t}${S}][${A}${t}${O}]*` : `[${A}${S}][${A}${t}${O}]*`;
19897
19898
  return T ? Es(C) : C;
19898
19899
  };
19899
19900
  function Ce(e, E) {
@@ -20183,13 +20184,13 @@ class rs {
20183
20184
  // These rules can't be blindly cached as the paramTypesOverrides object
20184
20185
  // can differ on each invocation of the format() function.
20185
20186
  buildParamRules(E, T) {
20186
- var R, A, t, S, r;
20187
+ var R, A, t, S, O;
20187
20188
  const C = {
20188
20189
  named: T?.named || ((R = E.paramTypes) === null || R === void 0 ? void 0 : R.named) || [],
20189
20190
  quoted: T?.quoted || ((A = E.paramTypes) === null || A === void 0 ? void 0 : A.quoted) || [],
20190
20191
  numbered: T?.numbered || ((t = E.paramTypes) === null || t === void 0 ? void 0 : t.numbered) || [],
20191
20192
  positional: typeof T?.positional == "boolean" ? T.positional : (S = E.paramTypes) === null || S === void 0 ? void 0 : S.positional,
20192
- custom: T?.custom || ((r = E.paramTypes) === null || r === void 0 ? void 0 : r.custom) || []
20193
+ custom: T?.custom || ((O = E.paramTypes) === null || O === void 0 ? void 0 : O.custom) || []
20193
20194
  };
20194
20195
  return this.validRules([
20195
20196
  {
@@ -20485,7 +20486,7 @@ function Ds() {
20485
20486
  M === I ? n++ : (n > 0 && s.push(" ^ " + n + " more lines identical to this"), n = 0, s.push(" " + M)), I = M;
20486
20487
  }
20487
20488
  }, S.prototype.getSymbolDisplay = function(N) {
20488
- return r(N);
20489
+ return O(N);
20489
20490
  }, S.prototype.buildFirstStateStack = function(N, s) {
20490
20491
  if (s.indexOf(N) !== -1)
20491
20492
  return null;
@@ -20511,7 +20512,7 @@ function Ds() {
20511
20512
  return n.data;
20512
20513
  });
20513
20514
  };
20514
- function r(N) {
20515
+ function O(N) {
20515
20516
  var s = typeof N;
20516
20517
  if (s === "string")
20517
20518
  return N;
@@ -21729,7 +21730,7 @@ async function zs(e, E, T) {
21729
21730
  const N = Array.from(A)[0];
21730
21731
  S = await T.generateSQL(N, e, E);
21731
21732
  }
21732
- const r = Array.from(A).map((N) => ({
21733
+ const O = Array.from(A).map((N) => ({
21733
21734
  cube: N,
21734
21735
  query: {
21735
21736
  measures: e.measures?.filter((s) => s.startsWith(N + ".")) || [],
@@ -21749,9 +21750,9 @@ async function zs(e, E, T) {
21749
21750
  }
21750
21751
  return {
21751
21752
  queryType: "regularQuery",
21752
- normalizedQueries: r,
21753
+ normalizedQueries: O,
21753
21754
  queryOrder: Array.from(A),
21754
- transformedQueries: r,
21755
+ transformedQueries: O,
21755
21756
  pivotQuery: {
21756
21757
  query: e,
21757
21758
  cubes: Array.from(A)
@@ -21911,9 +21912,9 @@ class AN {
21911
21912
  }
21912
21913
  const S = new Map(this.cubes);
21913
21914
  S.set(E.name, E);
21914
- const r = new J(S);
21915
+ const O = new J(S);
21915
21916
  try {
21916
- r.validateDependencies(E);
21917
+ O.validateDependencies(E);
21917
21918
  } catch (C) {
21918
21919
  T.push(C instanceof Error ? C.message : String(C));
21919
21920
  }
@@ -22005,9 +22006,9 @@ ${T.join(`
22005
22006
  */
22006
22007
  generateCubeMetadata(E) {
22007
22008
  const T = Object.keys(E.measures), R = Object.keys(E.dimensions), A = new Array(T.length), t = new Array(R.length);
22008
- for (let r = 0; r < T.length; r++) {
22009
- const C = T[r], N = E.measures[C];
22010
- A[r] = {
22009
+ for (let O = 0; O < T.length; O++) {
22010
+ const C = T[O], N = E.measures[C];
22011
+ A[O] = {
22011
22012
  name: `${E.name}.${C}`,
22012
22013
  title: N.title || C,
22013
22014
  shortTitle: N.title || C,
@@ -22017,9 +22018,9 @@ ${T.join(`
22017
22018
  description: N.description
22018
22019
  };
22019
22020
  }
22020
- for (let r = 0; r < R.length; r++) {
22021
- const C = R[r], N = E.dimensions[C];
22022
- t[r] = {
22021
+ for (let O = 0; O < R.length; O++) {
22022
+ const C = R[O], N = E.dimensions[C];
22023
+ t[O] = {
22023
22024
  name: `${E.name}.${C}`,
22024
22025
  title: N.title || C,
22025
22026
  shortTitle: N.title || C,
@@ -22031,12 +22032,12 @@ ${T.join(`
22031
22032
  }
22032
22033
  const S = [];
22033
22034
  if (E.joins)
22034
- for (const [, r] of Object.entries(E.joins)) {
22035
- const C = typeof r.targetCube == "function" ? r.targetCube() : r.targetCube;
22035
+ for (const [, O] of Object.entries(E.joins)) {
22036
+ const C = typeof O.targetCube == "function" ? O.targetCube() : O.targetCube;
22036
22037
  S.push({
22037
22038
  targetCube: C.name,
22038
- relationship: r.relationship,
22039
- joinFields: r.on.map((N) => ({
22039
+ relationship: O.relationship,
22040
+ joinFields: O.on.map((N) => ({
22040
22041
  sourceField: this.getColumnName(N.source),
22041
22042
  targetField: this.getColumnName(N.target)
22042
22043
  }))
@@ -22062,9 +22063,9 @@ ${T.join(`
22062
22063
  throw new Error(`Cube '${E}' not found`);
22063
22064
  if (!this.dbExecutor)
22064
22065
  throw new Error("Database executor not configured");
22065
- const S = await new mE(this.dbExecutor).generateSQL(A, T, R), r = this.dbExecutor.getEngineType();
22066
+ const S = await new mE(this.dbExecutor).generateSQL(A, T, R), O = this.dbExecutor.getEngineType();
22066
22067
  return {
22067
- sql: jT(S.sql, r),
22068
+ sql: jT(S.sql, O),
22068
22069
  params: S.params
22069
22070
  };
22070
22071
  }
@@ -22145,12 +22146,12 @@ function Me(e, E) {
22145
22146
  continue;
22146
22147
  }
22147
22148
  R.add(t);
22148
- const r = e.get(t);
22149
- if (!r) {
22149
+ const O = e.get(t);
22150
+ if (!O) {
22150
22151
  T.push(`Cube '${t}' not found (referenced in measure '${A}')`);
22151
22152
  continue;
22152
22153
  }
22153
- r.measures[S] || T.push(`Measure '${S}' not found on cube '${t}'`);
22154
+ O.measures[S] || T.push(`Measure '${S}' not found on cube '${t}'`);
22154
22155
  }
22155
22156
  if (E.dimensions)
22156
22157
  for (const A of E.dimensions) {
@@ -22160,12 +22161,12 @@ function Me(e, E) {
22160
22161
  continue;
22161
22162
  }
22162
22163
  R.add(t);
22163
- const r = e.get(t);
22164
- if (!r) {
22164
+ const O = e.get(t);
22165
+ if (!O) {
22165
22166
  T.push(`Cube '${t}' not found (referenced in dimension '${A}')`);
22166
22167
  continue;
22167
22168
  }
22168
- r.dimensions[S] || T.push(`Dimension '${S}' not found on cube '${t}'`);
22169
+ O.dimensions[S] || T.push(`Dimension '${S}' not found on cube '${t}'`);
22169
22170
  }
22170
22171
  if (E.timeDimensions)
22171
22172
  for (const A of E.timeDimensions) {
@@ -22175,12 +22176,12 @@ function Me(e, E) {
22175
22176
  continue;
22176
22177
  }
22177
22178
  R.add(t);
22178
- const r = e.get(t);
22179
- if (!r) {
22179
+ const O = e.get(t);
22180
+ if (!O) {
22180
22181
  T.push(`Cube '${t}' not found (referenced in timeDimension '${A.dimension}')`);
22181
22182
  continue;
22182
22183
  }
22183
- r.dimensions[S] || T.push(`TimeDimension '${S}' not found on cube '${t}' (must be a dimension with time type)`);
22184
+ O.dimensions[S] || T.push(`TimeDimension '${S}' not found on cube '${t}' (must be a dimension with time type)`);
22184
22185
  }
22185
22186
  if (E.filters)
22186
22187
  for (const A of E.filters)
@@ -22192,8 +22193,8 @@ function Me(e, E) {
22192
22193
  }
22193
22194
  function Ue(e, E, T, R) {
22194
22195
  if ("and" in e || "or" in e) {
22195
- const r = e.and || e.or || [];
22196
- for (const C of r)
22196
+ const O = e.and || e.or || [];
22197
+ for (const C of O)
22197
22198
  Ue(C, E, T, R);
22198
22199
  return;
22199
22200
  }