drizzle-cube 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { sql as _, count as RE, sum as f, max as YE, min as mE, and as m, countDistinct as $T, SQL as gT, or as AE, isNotNull as fE, ne as XE, isNull as bE, eq as j, notInArray as KE, inArray as SE, lt as eE, gt as IE, gte as y, lte as $, desc as JT, asc as yE } from "drizzle-orm";
1
+ import { sql as _, eq as w, and as m, count as RE, sum as W, max as YE, min as mE, countDistinct as gT, SQL as JT, or as AE, isNotNull as WE, ne as XE, isNull as bE, notInArray as yE, inArray as SE, lt as eE, gt as IE, gte as K, lte as $, desc as wT, asc as KE } from "drizzle-orm";
2
2
  class dE {
3
3
  /**
4
4
  * Helper method to build pattern for string matching
@@ -18,7 +18,7 @@ class dE {
18
18
  }
19
19
  }
20
20
  }
21
- class wT extends dE {
21
+ class xT extends dE {
22
22
  getEngineType() {
23
23
  return "postgres";
24
24
  }
@@ -267,7 +267,7 @@ class cT extends dE {
267
267
  return E;
268
268
  }
269
269
  }
270
- class xT extends dE {
270
+ class vT extends dE {
271
271
  getEngineType() {
272
272
  return "sqlite";
273
273
  }
@@ -403,7 +403,7 @@ class xT extends dE {
403
403
  return E;
404
404
  }
405
405
  }
406
- class vT extends cT {
406
+ class QT extends cT {
407
407
  getEngineType() {
408
408
  return "singlestore";
409
409
  }
@@ -416,29 +416,29 @@ class vT extends cT {
416
416
  // These limitations are typically handled at the query building level
417
417
  // rather than in the adapter, but can be addressed here if needed
418
418
  }
419
- function QT(T) {
419
+ function ZT(T) {
420
420
  switch (T) {
421
421
  case "postgres":
422
- return new wT();
422
+ return new xT();
423
423
  case "mysql":
424
424
  return new cT();
425
425
  case "sqlite":
426
- return new xT();
427
- case "singlestore":
428
426
  return new vT();
427
+ case "singlestore":
428
+ return new QT();
429
429
  default:
430
430
  throw new Error(`Unsupported database engine: ${T}`);
431
431
  }
432
432
  }
433
- class VE {
433
+ class hE {
434
434
  constructor(E, R, A) {
435
435
  this.db = E, this.schema = R;
436
436
  const S = A || this.getEngineType();
437
- this.databaseAdapter = QT(S);
437
+ this.databaseAdapter = ZT(S);
438
438
  }
439
439
  databaseAdapter;
440
440
  }
441
- class ZT extends VE {
441
+ class qT extends hE {
442
442
  async execute(E, R) {
443
443
  if (E && typeof E == "object" && typeof E.execute == "function") {
444
444
  const S = await E.execute();
@@ -490,9 +490,9 @@ class ZT extends VE {
490
490
  }
491
491
  }
492
492
  function $E(T, E) {
493
- return new ZT(T, E, "postgres");
493
+ return new qT(T, E, "postgres");
494
494
  }
495
- class lT extends VE {
495
+ class lT extends hE {
496
496
  async execute(E, R) {
497
497
  if (E && typeof E == "object" && typeof E.execute == "function") {
498
498
  const S = await E.execute();
@@ -530,10 +530,10 @@ class lT extends VE {
530
530
  return "mysql";
531
531
  }
532
532
  }
533
- function qT(T, E) {
533
+ function jT(T, E) {
534
534
  return new lT(T, E, "mysql");
535
535
  }
536
- class kT extends VE {
536
+ class kT extends hE {
537
537
  async execute(E, R) {
538
538
  if (E && typeof E == "object" && typeof E.execute == "function") {
539
539
  const A = await E.execute();
@@ -582,7 +582,7 @@ class kT extends VE {
582
582
  function gE(T, E) {
583
583
  return new kT(T, E, "sqlite");
584
584
  }
585
- class jT extends lT {
585
+ class zT extends lT {
586
586
  getEngineType() {
587
587
  return "singlestore";
588
588
  }
@@ -590,8 +590,8 @@ class jT extends lT {
590
590
  // For now, we inherit all behavior from MySQLExecutor since
591
591
  // SingleStore is largely MySQL-compatible
592
592
  }
593
- function zT(T, E) {
594
- return new jT(T, E);
593
+ function ER(T, E) {
594
+ return new zT(T, E);
595
595
  }
596
596
  function JE(T, E, R) {
597
597
  if (R)
@@ -599,11 +599,11 @@ function JE(T, E, R) {
599
599
  case "postgres":
600
600
  return $E(T, E);
601
601
  case "mysql":
602
- return qT(T, E);
602
+ return jT(T, E);
603
603
  case "sqlite":
604
604
  return gE(T, E);
605
605
  case "singlestore":
606
- return zT(T, E);
606
+ return ER(T, E);
607
607
  }
608
608
  if (T.all && T.run)
609
609
  return gE(T, E);
@@ -614,7 +614,7 @@ function JE(T, E, R) {
614
614
  function wE(T) {
615
615
  return typeof T == "function" ? T() : T;
616
616
  }
617
- function ER(T, E) {
617
+ function HT(T, E) {
618
618
  if (E) return E;
619
619
  switch (T) {
620
620
  case "belongsTo":
@@ -626,27 +626,66 @@ function ER(T, E) {
626
626
  case "hasMany":
627
627
  return "left";
628
628
  // Parent may have no children
629
+ case "belongsToMany":
630
+ return "left";
631
+ // Many-to-many through junction table
629
632
  default:
630
633
  return "left";
631
634
  }
632
635
  }
633
- function W(T, E) {
636
+ function f(T, E) {
634
637
  return typeof T == "function" ? T(E) : T;
635
638
  }
636
- function wI(T, E, R) {
639
+ function xI(T, E, R) {
637
640
  return {
638
641
  ...T,
639
642
  cubes: E,
640
643
  currentCube: R
641
644
  };
642
645
  }
643
- function xI(T, E) {
646
+ function vI(T, E) {
644
647
  return {
645
648
  name: T,
646
649
  ...E
647
650
  };
648
651
  }
649
- class TR {
652
+ function TR(T, E) {
653
+ if (T.relationship !== "belongsToMany" || !T.through)
654
+ throw new Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
655
+ const { table: R, sourceKey: A, targetKey: S, securitySql: e } = T.through, O = [];
656
+ for (const N of A) {
657
+ const s = N.as || w;
658
+ O.push(s(N.source, N.target));
659
+ }
660
+ const t = [];
661
+ for (const N of S) {
662
+ const s = N.as || w;
663
+ t.push(s(N.source, N.target));
664
+ }
665
+ let D;
666
+ if (e) {
667
+ const N = e(E);
668
+ D = Array.isArray(N) ? N : [N];
669
+ }
670
+ const I = HT("belongsToMany", T.sqlJoinType);
671
+ return {
672
+ junctionJoins: [
673
+ {
674
+ joinType: I,
675
+ table: R,
676
+ condition: m(...O)
677
+ },
678
+ {
679
+ joinType: I,
680
+ table: R,
681
+ // This will be replaced with target cube table in query planner
682
+ condition: m(...t)
683
+ }
684
+ ],
685
+ junctionSecurityConditions: D
686
+ };
687
+ }
688
+ class RR {
650
689
  constructor(E) {
651
690
  this.databaseAdapter = E;
652
691
  }
@@ -658,26 +697,26 @@ class TR {
658
697
  const S = {}, e = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
659
698
  if (R.dimensions)
660
699
  for (const O of R.dimensions) {
661
- const [N, D] = O.split("."), I = e.get(N);
700
+ const [t, D] = O.split("."), I = e.get(t);
662
701
  if (I && I.dimensions && I.dimensions[D]) {
663
- const C = I.dimensions[D], s = W(C.sql, A);
702
+ const N = I.dimensions[D], s = f(N.sql, A);
664
703
  S[O] = _`${s}`.as(O);
665
704
  }
666
705
  }
667
706
  if (R.measures)
668
707
  for (const O of R.measures) {
669
- const [N, D] = O.split("."), I = e.get(N);
708
+ const [t, D] = O.split("."), I = e.get(t);
670
709
  if (I && I.measures && I.measures[D]) {
671
- const C = I.measures[D], s = this.buildMeasureExpression(C, A);
710
+ const N = I.measures[D], s = this.buildMeasureExpression(N, A);
672
711
  S[O] = _`${s}`.as(O);
673
712
  }
674
713
  }
675
714
  if (R.timeDimensions)
676
715
  for (const O of R.timeDimensions) {
677
- const [N, D] = O.dimension.split("."), I = e.get(N);
716
+ const [t, D] = O.dimension.split("."), I = e.get(t);
678
717
  if (I && I.dimensions && I.dimensions[D]) {
679
- const C = I.dimensions[D], s = this.buildTimeDimensionExpression(
680
- C.sql,
718
+ const N = I.dimensions[D], s = this.buildTimeDimensionExpression(
719
+ N.sql,
681
720
  O.granularity,
682
721
  A
683
722
  );
@@ -691,24 +730,24 @@ class TR {
691
730
  */
692
731
  buildHavingMeasureExpression(E, R, A, S, e) {
693
732
  if (e && e.preAggregationCTEs) {
694
- const O = e.preAggregationCTEs.find((N) => N.cube.name === E);
733
+ const O = e.preAggregationCTEs.find((t) => t.cube.name === E);
695
734
  if (O && O.measures.includes(`${E}.${R}`)) {
696
- const N = _`${_.identifier(O.cteAlias)}.${_.identifier(R)}`;
735
+ const t = _`${_.identifier(O.cteAlias)}.${_.identifier(R)}`;
697
736
  switch (A.type) {
698
737
  case "count":
699
738
  case "countDistinct":
700
739
  case "sum":
701
- return f(N);
740
+ return W(t);
702
741
  case "avg":
703
- return this.databaseAdapter.buildAvg(N);
742
+ return this.databaseAdapter.buildAvg(t);
704
743
  case "min":
705
- return mE(N);
744
+ return mE(t);
706
745
  case "max":
707
- return YE(N);
746
+ return YE(t);
708
747
  case "number":
709
- return f(N);
748
+ return W(t);
710
749
  default:
711
- return f(N);
750
+ return W(t);
712
751
  }
713
752
  }
714
753
  }
@@ -718,7 +757,7 @@ class TR {
718
757
  * Build measure expression with aggregation and filters
719
758
  */
720
759
  buildMeasureExpression(E, R) {
721
- let A = W(E.sql, R);
760
+ let A = f(E.sql, R);
722
761
  if (E.filters && E.filters.length > 0) {
723
762
  const S = E.filters.map((e) => e(R)).filter(Boolean);
724
763
  if (S.length > 0) {
@@ -732,9 +771,9 @@ class TR {
732
771
  case "count":
733
772
  return RE(A);
734
773
  case "countDistinct":
735
- return $T(A);
774
+ return gT(A);
736
775
  case "sum":
737
- return f(A);
776
+ return W(A);
738
777
  case "avg":
739
778
  return this.databaseAdapter.buildAvg(A);
740
779
  case "min":
@@ -751,8 +790,8 @@ class TR {
751
790
  * Build time dimension expression with granularity using database adapter
752
791
  */
753
792
  buildTimeDimensionExpression(E, R, A) {
754
- const S = W(E, A);
755
- return R ? this.databaseAdapter.buildTimeDimension(R, S) : S instanceof gT ? S : _`${S}`;
793
+ const S = f(E, A);
794
+ return R ? this.databaseAdapter.buildTimeDimension(R, S) : S instanceof JT ? S : _`${S}`;
756
795
  }
757
796
  /**
758
797
  * Build WHERE conditions from semantic query filters (dimensions only)
@@ -761,17 +800,17 @@ class TR {
761
800
  buildWhereConditions(E, R, A, S) {
762
801
  const e = [], O = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
763
802
  if (R.filters && R.filters.length > 0)
764
- for (const N of R.filters) {
765
- const D = this.processFilter(N, O, A, "where", S);
803
+ for (const t of R.filters) {
804
+ const D = this.processFilter(t, O, A, "where", S);
766
805
  D && e.push(D);
767
806
  }
768
807
  if (R.timeDimensions)
769
- for (const N of R.timeDimensions) {
770
- const [D, I] = N.dimension.split("."), C = O.get(D);
771
- if (C && C.dimensions[I] && N.dateRange) {
808
+ for (const t of R.timeDimensions) {
809
+ const [D, I] = t.dimension.split("."), N = O.get(D);
810
+ if (N && N.dimensions[I] && t.dateRange) {
772
811
  if (S?.preAggregationCTEs && S.preAggregationCTEs.some((r) => r.cube.name === D))
773
812
  continue;
774
- const s = C.dimensions[I], L = W(s.sql, A), P = this.buildDateRangeCondition(L, N.dateRange);
813
+ const s = N.dimensions[I], L = f(s.sql, A), P = this.buildDateRangeCondition(L, t.dateRange);
775
814
  P && e.push(P);
776
815
  }
777
816
  }
@@ -784,8 +823,8 @@ class TR {
784
823
  buildHavingConditions(E, R, A, S) {
785
824
  const e = [], O = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
786
825
  if (R.filters && R.filters.length > 0)
787
- for (const N of R.filters) {
788
- const D = this.processFilter(N, O, A, "having", S);
826
+ for (const t of R.filters) {
827
+ const D = this.processFilter(t, O, A, "having", S);
789
828
  D && e.push(D);
790
829
  }
791
830
  return e;
@@ -798,28 +837,28 @@ class TR {
798
837
  if ("and" in E || "or" in E) {
799
838
  const P = E;
800
839
  if (P.and) {
801
- const a = P.and.map((r) => this.processFilter(r, R, A, S, e)).filter((r) => r !== null);
802
- return a.length > 0 ? m(...a) : null;
840
+ const o = P.and.map((r) => this.processFilter(r, R, A, S, e)).filter((r) => r !== null);
841
+ return o.length > 0 ? m(...o) : null;
803
842
  }
804
843
  if (P.or) {
805
- const a = P.or.map((r) => this.processFilter(r, R, A, S, e)).filter((r) => r !== null);
806
- return a.length > 0 ? AE(...a) : null;
844
+ const o = P.or.map((r) => this.processFilter(r, R, A, S, e)).filter((r) => r !== null);
845
+ return o.length > 0 ? AE(...o) : null;
807
846
  }
808
847
  }
809
- const O = E, [N, D] = O.member.split("."), I = R.get(N);
848
+ const O = E, [t, D] = O.member.split("."), I = R.get(t);
810
849
  if (!I) return null;
811
- const C = I.dimensions[D], s = I.measures[D], L = C || s;
850
+ const N = I.dimensions[D], s = I.measures[D], L = N || s;
812
851
  if (!L) return null;
813
- if (S === "where" && C) {
814
- if (e?.preAggregationCTEs && e.preAggregationCTEs.some((r) => r.cube.name === N))
852
+ if (S === "where" && N) {
853
+ if (e?.preAggregationCTEs && e.preAggregationCTEs.some((r) => r.cube.name === t))
815
854
  return null;
816
- const P = W(C.sql, A);
855
+ const P = f(N.sql, A);
817
856
  return this.buildFilterCondition(P, O.operator, O.values, L);
818
857
  } else {
819
858
  if (S === "where" && s)
820
859
  return null;
821
860
  if (S === "having" && s) {
822
- const P = this.buildHavingMeasureExpression(N, D, s, A, e);
861
+ const P = this.buildHavingMeasureExpression(t, D, s, A, e);
823
862
  return this.buildFilterCondition(P, O.operator, O.values, L);
824
863
  }
825
864
  }
@@ -831,7 +870,7 @@ class TR {
831
870
  buildFilterCondition(E, R, A, S) {
832
871
  if (!A || A.length === 0)
833
872
  return R === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
834
- const e = A.filter((N) => !(N == null || N === "" || typeof N == "string" && N.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
873
+ const e = A.filter((t) => !(t == null || t === "" || typeof t == "string" && t.includes("\0"))).map(this.databaseAdapter.convertFilterValue);
835
874
  if (e.length === 0 && !["set", "notSet"].includes(R))
836
875
  return R === "equals" ? this.databaseAdapter.buildBooleanLiteral(!1) : null;
837
876
  const O = e[0];
@@ -839,17 +878,17 @@ class TR {
839
878
  case "equals":
840
879
  if (e.length > 1) {
841
880
  if (S?.type === "time") {
842
- const N = e.map((D) => this.normalizeDate(D) || D);
843
- return SE(E, N);
881
+ const t = e.map((D) => this.normalizeDate(D) || D);
882
+ return SE(E, t);
844
883
  }
845
884
  return SE(E, e);
846
885
  } else if (e.length === 1) {
847
- const N = S?.type === "time" && this.normalizeDate(O) || O;
848
- return j(E, N);
886
+ const t = S?.type === "time" && this.normalizeDate(O) || O;
887
+ return w(E, t);
849
888
  }
850
889
  return this.databaseAdapter.buildBooleanLiteral(!1);
851
890
  case "notEquals":
852
- return e.length > 1 ? KE(E, e) : e.length === 1 ? XE(E, O) : null;
891
+ return e.length > 1 ? yE(E, e) : e.length === 1 ? XE(E, O) : null;
853
892
  case "contains":
854
893
  return this.databaseAdapter.buildStringCondition(E, "contains", O);
855
894
  case "notContains":
@@ -861,36 +900,36 @@ class TR {
861
900
  case "gt":
862
901
  return IE(E, O);
863
902
  case "gte":
864
- return y(E, O);
903
+ return K(E, O);
865
904
  case "lt":
866
905
  return eE(E, O);
867
906
  case "lte":
868
907
  return $(E, O);
869
908
  case "set":
870
- return fE(E);
909
+ return WE(E);
871
910
  case "notSet":
872
911
  return bE(E);
873
912
  case "inDateRange":
874
913
  if (e.length >= 2) {
875
- const N = this.normalizeDate(e[0]), D = this.normalizeDate(e[1]);
876
- if (N && D)
914
+ const t = this.normalizeDate(e[0]), D = this.normalizeDate(e[1]);
915
+ if (t && D)
877
916
  return m(
878
- y(E, N),
917
+ K(E, t),
879
918
  $(E, D)
880
919
  );
881
920
  }
882
921
  return null;
883
922
  case "beforeDate": {
884
- const N = this.normalizeDate(O);
885
- return N ? eE(E, N) : null;
923
+ const t = this.normalizeDate(O);
924
+ return t ? eE(E, t) : null;
886
925
  }
887
926
  case "afterDate": {
888
- const N = this.normalizeDate(O);
889
- return N ? IE(E, N) : null;
927
+ const t = this.normalizeDate(O);
928
+ return t ? IE(E, t) : null;
890
929
  }
891
930
  case "between":
892
931
  return e.length >= 2 ? m(
893
- y(E, e[0]),
932
+ K(E, e[0]),
894
933
  $(E, e[1])
895
934
  ) : null;
896
935
  case "notBetween":
@@ -901,7 +940,7 @@ class TR {
901
940
  case "in":
902
941
  return e.length > 0 ? SE(E, e) : null;
903
942
  case "notIn":
904
- return e.length > 0 ? KE(E, e) : null;
943
+ return e.length > 0 ? yE(E, e) : null;
905
944
  case "like":
906
945
  return this.databaseAdapter.buildStringCondition(E, "like", O);
907
946
  case "notLike":
@@ -915,11 +954,11 @@ class TR {
915
954
  case "isEmpty":
916
955
  return AE(
917
956
  bE(E),
918
- j(E, "")
957
+ w(E, "")
919
958
  );
920
959
  case "isNotEmpty":
921
960
  return m(
922
- fE(E),
961
+ WE(E),
923
962
  XE(E, "")
924
963
  );
925
964
  default:
@@ -934,7 +973,7 @@ class TR {
934
973
  if (Array.isArray(R) && R.length >= 2) {
935
974
  const A = this.normalizeDate(R[0]), S = this.normalizeDate(R[1]);
936
975
  return !A || !S ? null : m(
937
- y(E, A),
976
+ K(E, A),
938
977
  $(E, S)
939
978
  );
940
979
  }
@@ -942,7 +981,7 @@ class TR {
942
981
  const A = this.parseRelativeDateRange(R);
943
982
  if (A)
944
983
  return m(
945
- y(E, A.start),
984
+ K(E, A.start),
946
985
  $(E, A.end)
947
986
  );
948
987
  const S = this.normalizeDate(R);
@@ -951,7 +990,7 @@ class TR {
951
990
  e.setUTCHours(0, 0, 0, 0);
952
991
  const O = new Date(S);
953
992
  return O.setUTCHours(23, 59, 59, 999), m(
954
- y(E, e),
993
+ K(E, e),
955
994
  $(E, O)
956
995
  );
957
996
  }
@@ -962,7 +1001,7 @@ class TR {
962
1001
  * Handles all 14 DATE_RANGE_OPTIONS from the client
963
1002
  */
964
1003
  parseRelativeDateRange(E) {
965
- const R = /* @__PURE__ */ new Date(), A = E.toLowerCase().trim(), S = R.getUTCFullYear(), e = R.getUTCMonth(), O = R.getUTCDate(), N = R.getUTCDay();
1004
+ const R = /* @__PURE__ */ new Date(), A = E.toLowerCase().trim(), S = R.getUTCFullYear(), e = R.getUTCMonth(), O = R.getUTCDate(), t = R.getUTCDay();
966
1005
  if (A === "today") {
967
1006
  const s = new Date(R);
968
1007
  s.setUTCHours(0, 0, 0, 0);
@@ -976,7 +1015,7 @@ class TR {
976
1015
  return L.setUTCDate(O - 1), L.setUTCHours(23, 59, 59, 999), { start: s, end: L };
977
1016
  }
978
1017
  if (A === "this week") {
979
- const s = N === 0 ? -6 : 1 - N, L = new Date(R);
1018
+ const s = t === 0 ? -6 : 1 - t, L = new Date(R);
980
1019
  L.setUTCDate(O + s), L.setUTCHours(0, 0, 0, 0);
981
1020
  const P = new Date(L);
982
1021
  return P.setUTCDate(L.getUTCDate() + 6), P.setUTCHours(23, 59, 59, 999), { start: L, end: P };
@@ -1001,7 +1040,7 @@ class TR {
1001
1040
  return P.setUTCHours(23, 59, 59, 999), { start: L, end: P };
1002
1041
  }
1003
1042
  if (A === "last week") {
1004
- const s = N === 0 ? -13 : -6 - N, L = new Date(R);
1043
+ const s = t === 0 ? -13 : -6 - t, L = new Date(R);
1005
1044
  L.setUTCDate(O + s), L.setUTCHours(0, 0, 0, 0);
1006
1045
  const P = new Date(L);
1007
1046
  return P.setUTCDate(L.getUTCDate() + 6), P.setUTCHours(23, 59, 59, 999), { start: L, end: P };
@@ -1011,8 +1050,8 @@ class TR {
1011
1050
  return { start: s, end: L };
1012
1051
  }
1013
1052
  if (A === "last quarter") {
1014
- const s = Math.floor(e / 3), L = s === 0 ? 3 : s - 1, P = s === 0 ? S - 1 : S, a = new Date(Date.UTC(P, L * 3, 1, 0, 0, 0, 0)), r = new Date(Date.UTC(P, L * 3 + 3, 0, 23, 59, 59, 999));
1015
- return { start: a, end: r };
1053
+ const s = Math.floor(e / 3), L = s === 0 ? 3 : s - 1, P = s === 0 ? S - 1 : S, o = new Date(Date.UTC(P, L * 3, 1, 0, 0, 0, 0)), r = new Date(Date.UTC(P, L * 3 + 3, 0, 23, 59, 59, 999));
1054
+ return { start: o, end: r };
1016
1055
  }
1017
1056
  if (A === "last year") {
1018
1057
  const s = new Date(Date.UTC(S - 1, 0, 1, 0, 0, 0, 0)), L = new Date(Date.UTC(S - 1, 11, 31, 23, 59, 59, 999));
@@ -1027,9 +1066,9 @@ class TR {
1027
1066
  const s = parseInt(I[1], 10), L = new Date(Date.UTC(S, e - s + 1, 1, 0, 0, 0, 0)), P = new Date(R);
1028
1067
  return P.setUTCHours(23, 59, 59, 999), { start: L, end: P };
1029
1068
  }
1030
- const C = A.match(/^last\s+(\d+)\s+years?$/);
1031
- if (C) {
1032
- const s = parseInt(C[1], 10), L = new Date(Date.UTC(S - s, 0, 1, 0, 0, 0, 0)), P = new Date(R);
1069
+ const N = A.match(/^last\s+(\d+)\s+years?$/);
1070
+ if (N) {
1071
+ const s = parseInt(N[1], 10), L = new Date(Date.UTC(S - s, 0, 1, 0, 0, 0, 0)), P = new Date(R);
1033
1072
  return P.setUTCHours(23, 59, 59, 999), { start: L, end: P };
1034
1073
  }
1035
1074
  return null;
@@ -1062,48 +1101,48 @@ class TR {
1062
1101
  const e = [];
1063
1102
  if (!(R.measures && R.measures.length > 0))
1064
1103
  return [];
1065
- const N = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1104
+ const t = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1066
1105
  if (R.dimensions)
1067
1106
  for (const D of R.dimensions) {
1068
- const [I, C] = D.split("."), s = N.get(I);
1069
- if (s && s.dimensions && s.dimensions[C])
1107
+ const [I, N] = D.split("."), s = t.get(I);
1108
+ if (s && s.dimensions && s.dimensions[N])
1070
1109
  if (S?.preAggregationCTEs?.some((P) => P.cube.name === I)) {
1071
- const P = S.preAggregationCTEs.find((r) => r.cube.name === I), a = P.joinKeys.find((r) => r.targetColumn === C);
1072
- if (a && a.sourceColumnObj)
1073
- e.push(a.sourceColumnObj);
1110
+ const P = S.preAggregationCTEs.find((r) => r.cube.name === I), o = P.joinKeys.find((r) => r.targetColumn === N);
1111
+ if (o && o.sourceColumnObj)
1112
+ e.push(o.sourceColumnObj);
1074
1113
  else {
1075
- const r = _`${_.identifier(P.cteAlias)}.${_.identifier(C)}`;
1114
+ const r = _`${_.identifier(P.cteAlias)}.${_.identifier(N)}`;
1076
1115
  e.push(r);
1077
1116
  }
1078
1117
  } else {
1079
- const P = s.dimensions[C], a = W(P.sql, A);
1080
- e.push(a);
1118
+ const P = s.dimensions[N], o = f(P.sql, A);
1119
+ e.push(o);
1081
1120
  }
1082
1121
  }
1083
1122
  if (R.timeDimensions)
1084
1123
  for (const D of R.timeDimensions) {
1085
- const [I, C] = D.dimension.split("."), s = N.get(I);
1086
- if (s && s.dimensions && s.dimensions[C])
1124
+ const [I, N] = D.dimension.split("."), s = t.get(I);
1125
+ if (s && s.dimensions && s.dimensions[N])
1087
1126
  if (S?.preAggregationCTEs?.some((P) => P.cube.name === I)) {
1088
- const P = S.preAggregationCTEs.find((r) => r.cube.name === I), a = P.joinKeys.find((r) => r.targetColumn === C);
1089
- if (a && a.sourceColumnObj) {
1127
+ const P = S.preAggregationCTEs.find((r) => r.cube.name === I), o = P.joinKeys.find((r) => r.targetColumn === N);
1128
+ if (o && o.sourceColumnObj) {
1090
1129
  const r = this.buildTimeDimensionExpression(
1091
- a.sourceColumnObj,
1130
+ o.sourceColumnObj,
1092
1131
  D.granularity,
1093
1132
  A
1094
1133
  );
1095
1134
  e.push(r);
1096
1135
  } else {
1097
- const r = _`${_.identifier(P.cteAlias)}.${_.identifier(C)}`;
1136
+ const r = _`${_.identifier(P.cteAlias)}.${_.identifier(N)}`;
1098
1137
  e.push(r);
1099
1138
  }
1100
1139
  } else {
1101
- const P = s.dimensions[C], a = this.buildTimeDimensionExpression(
1140
+ const P = s.dimensions[N], o = this.buildTimeDimensionExpression(
1102
1141
  P.sql,
1103
1142
  D.granularity,
1104
1143
  A
1105
1144
  );
1106
- e.push(a);
1145
+ e.push(o);
1107
1146
  }
1108
1147
  }
1109
1148
  return e;
@@ -1121,15 +1160,15 @@ class TR {
1121
1160
  for (const [e, O] of Object.entries(E.order)) {
1122
1161
  if (!S.includes(e))
1123
1162
  throw new Error(`Cannot order by '${e}': field is not selected in the query`);
1124
- const N = O === "desc" ? JT(_.identifier(e)) : yE(_.identifier(e));
1125
- A.push(N);
1163
+ const t = O === "desc" ? wT(_.identifier(e)) : KE(_.identifier(e));
1164
+ A.push(t);
1126
1165
  }
1127
1166
  if (E.timeDimensions && E.timeDimensions.length > 0) {
1128
1167
  const e = new Set(Object.keys(E.order || {})), O = [...E.timeDimensions].sort(
1129
- (N, D) => N.dimension.localeCompare(D.dimension)
1168
+ (t, D) => t.dimension.localeCompare(D.dimension)
1130
1169
  );
1131
- for (const N of O)
1132
- e.has(N.dimension) || A.push(yE(_.identifier(N.dimension)));
1170
+ for (const t of O)
1171
+ e.has(t.dimension) || A.push(KE(_.identifier(t.dimension)));
1133
1172
  }
1134
1173
  return A;
1135
1174
  }
@@ -1141,9 +1180,9 @@ class TR {
1141
1180
  const A = [], S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1142
1181
  if (R.measures && A.push(...R.measures), R.dimensions)
1143
1182
  for (const e of R.dimensions) {
1144
- const [O, N] = e.split("."), D = S.get(O);
1183
+ const [O, t] = e.split("."), D = S.get(O);
1145
1184
  if (D) {
1146
- const I = D.dimensions[N];
1185
+ const I = D.dimensions[t];
1147
1186
  I && I.type === "number" && A.push(e);
1148
1187
  }
1149
1188
  }
@@ -1170,7 +1209,7 @@ class TR {
1170
1209
  return S;
1171
1210
  }
1172
1211
  }
1173
- class RR {
1212
+ class AR {
1174
1213
  /**
1175
1214
  * Analyze a semantic query to determine which cubes are involved
1176
1215
  */
@@ -1244,12 +1283,12 @@ class RR {
1244
1283
  const S = this.analyzeCubeUsage(R), e = Array.from(S);
1245
1284
  if (e.length === 0)
1246
1285
  throw new Error("No cubes found in query");
1247
- const O = this.choosePrimaryCube(e, R, E), N = E.get(O);
1248
- if (!N)
1286
+ const O = this.choosePrimaryCube(e, R, E), t = E.get(O);
1287
+ if (!t)
1249
1288
  throw new Error(`Primary cube '${O}' not found`);
1250
1289
  if (e.length === 1)
1251
1290
  return {
1252
- primaryCube: N,
1291
+ primaryCube: t,
1253
1292
  joinCubes: [],
1254
1293
  // Empty for single cube
1255
1294
  selections: {},
@@ -1259,9 +1298,9 @@ class RR {
1259
1298
  groupByFields: []
1260
1299
  // Will be built by QueryBuilder
1261
1300
  };
1262
- const D = this.buildJoinPlan(E, N, e), I = this.planPreAggregationCTEs(E, N, D, R);
1301
+ const D = this.buildJoinPlan(E, t, e, A), I = this.planPreAggregationCTEs(E, t, D, R);
1263
1302
  return {
1264
- primaryCube: N,
1303
+ primaryCube: t,
1265
1304
  joinCubes: D,
1266
1305
  selections: {},
1267
1306
  // Will be built by QueryBuilder
@@ -1282,8 +1321,8 @@ class RR {
1282
1321
  for (const O of S)
1283
1322
  e.set(O, (e.get(O) || 0) + 1);
1284
1323
  if (e.size > 0) {
1285
- const O = Math.max(...e.values()), N = [...e.entries()].filter(([, D]) => D === O).map(([D]) => D).sort();
1286
- for (const D of N)
1324
+ const O = Math.max(...e.values()), t = [...e.entries()].filter(([, D]) => D === O).map(([D]) => D).sort();
1325
+ for (const D of t)
1287
1326
  if (this.canReachAllCubes(D, E, A))
1288
1327
  return D;
1289
1328
  }
@@ -1292,12 +1331,12 @@ class RR {
1292
1331
  const S = /* @__PURE__ */ new Map();
1293
1332
  for (const e of E)
1294
1333
  if (this.canReachAllCubes(e, E, A)) {
1295
- const O = A.get(e), N = O?.joins ? Object.keys(O.joins).length : 0;
1296
- S.set(e, N);
1334
+ const O = A.get(e), t = O?.joins ? Object.keys(O.joins).length : 0;
1335
+ S.set(e, t);
1297
1336
  }
1298
1337
  if (S.size > 0) {
1299
1338
  const e = Math.max(...S.values());
1300
- return [...S.entries()].filter(([, N]) => N === e).map(([N]) => N).sort()[0];
1339
+ return [...S.entries()].filter(([, t]) => t === e).map(([t]) => t).sort()[0];
1301
1340
  }
1302
1341
  }
1303
1342
  return [...E].sort()[0];
@@ -1318,36 +1357,56 @@ class RR {
1318
1357
  * Build join plan for multi-cube query
1319
1358
  * Supports both direct joins and transitive joins through intermediate cubes
1320
1359
  */
1321
- buildJoinPlan(E, R, A) {
1322
- const S = [], e = /* @__PURE__ */ new Set([R.name]), O = A.filter((N) => N !== R.name);
1323
- for (const N of O) {
1324
- if (e.has(N))
1360
+ buildJoinPlan(E, R, A, S) {
1361
+ const e = [], O = /* @__PURE__ */ new Set([R.name]), t = A.filter((D) => D !== R.name);
1362
+ for (const D of t) {
1363
+ if (O.has(D))
1325
1364
  continue;
1326
- const D = this.findJoinPath(E, R.name, N, e);
1327
- if (!D || D.length === 0)
1328
- throw new Error(`No join path found from '${R.name}' to '${N}'`);
1329
- for (const { toCube: I, joinDef: C } of D) {
1330
- if (e.has(I))
1365
+ const I = this.findJoinPath(E, R.name, D, O);
1366
+ if (!I || I.length === 0)
1367
+ throw new Error(`No join path found from '${R.name}' to '${D}'`);
1368
+ for (const { toCube: N, joinDef: s } of I) {
1369
+ if (O.has(N))
1331
1370
  continue;
1332
- const s = E.get(I);
1333
- if (!s)
1334
- throw new Error(`Cube '${I}' not found`);
1335
- const L = this.buildJoinCondition(
1336
- C,
1337
- null,
1338
- // No source alias needed - use the actual column
1339
- null
1340
- // No target alias needed - use the actual column
1341
- ), P = ER(C.relationship, C.sqlJoinType);
1342
- S.push({
1343
- cube: s,
1344
- alias: `${I.toLowerCase()}_cube`,
1345
- joinType: P,
1346
- joinCondition: L
1347
- }), e.add(I);
1371
+ const L = E.get(N);
1372
+ if (!L)
1373
+ throw new Error(`Cube '${N}' not found`);
1374
+ if (s.relationship === "belongsToMany" && s.through) {
1375
+ const P = TR(s, S.securityContext);
1376
+ e.push({
1377
+ cube: L,
1378
+ alias: `${N.toLowerCase()}_cube`,
1379
+ joinType: P.junctionJoins[1].joinType,
1380
+ // Use the target join type
1381
+ joinCondition: P.junctionJoins[1].condition,
1382
+ // Target join condition
1383
+ junctionTable: {
1384
+ table: s.through.table,
1385
+ alias: `junction_${N.toLowerCase()}`,
1386
+ joinType: P.junctionJoins[0].joinType,
1387
+ joinCondition: P.junctionJoins[0].condition,
1388
+ securitySql: s.through.securitySql
1389
+ }
1390
+ });
1391
+ } else {
1392
+ const P = this.buildJoinCondition(
1393
+ s,
1394
+ null,
1395
+ // No source alias needed - use the actual column
1396
+ null
1397
+ // No target alias needed - use the actual column
1398
+ ), o = HT(s.relationship, s.sqlJoinType);
1399
+ e.push({
1400
+ cube: L,
1401
+ alias: `${N.toLowerCase()}_cube`,
1402
+ joinType: o,
1403
+ joinCondition: P
1404
+ });
1405
+ }
1406
+ O.add(N);
1348
1407
  }
1349
1408
  }
1350
- return S;
1409
+ return e;
1351
1410
  }
1352
1411
  /**
1353
1412
  * Build join condition from new array-based join definition
@@ -1355,8 +1414,8 @@ class RR {
1355
1414
  buildJoinCondition(E, R, A) {
1356
1415
  const S = [];
1357
1416
  for (const e of E.on) {
1358
- const O = R ? _`${_.identifier(R)}.${_.identifier(e.source.name)}` : e.source, N = A ? _`${_.identifier(A)}.${_.identifier(e.target.name)}` : e.target, D = e.as || j;
1359
- S.push(D(O, N));
1417
+ const O = R ? _`${_.identifier(R)}.${_.identifier(e.source.name)}` : e.source, t = A ? _`${_.identifier(A)}.${_.identifier(e.target.name)}` : e.target, D = e.as || w;
1418
+ S.push(D(O, t));
1360
1419
  }
1361
1420
  return m(...S);
1362
1421
  }
@@ -1371,16 +1430,16 @@ class RR {
1371
1430
  { cube: R, path: [] }
1372
1431
  ], O = /* @__PURE__ */ new Set([R, ...S]);
1373
1432
  for (; e.length > 0; ) {
1374
- const { cube: N, path: D } = e.shift(), I = E.get(N);
1433
+ const { cube: t, path: D } = e.shift(), I = E.get(t);
1375
1434
  if (I?.joins)
1376
- for (const [, C] of Object.entries(I.joins)) {
1377
- const L = wE(C.targetCube).name;
1435
+ for (const [, N] of Object.entries(I.joins)) {
1436
+ const L = wE(N.targetCube).name;
1378
1437
  if (O.has(L))
1379
1438
  continue;
1380
1439
  const P = [...D, {
1381
- fromCube: N,
1440
+ fromCube: t,
1382
1441
  toCube: L,
1383
- joinDef: C
1442
+ joinDef: N
1384
1443
  }];
1385
1444
  if (L === A)
1386
1445
  return P;
@@ -1391,21 +1450,23 @@ class RR {
1391
1450
  }
1392
1451
  /**
1393
1452
  * Plan pre-aggregation CTEs for hasMany relationships to prevent fan-out
1453
+ * Note: belongsToMany relationships handle fan-out differently through their junction table structure
1454
+ * and don't require CTEs - the two-hop join with the junction table provides natural grouping
1394
1455
  */
1395
1456
  planPreAggregationCTEs(E, R, A, S) {
1396
1457
  const e = [];
1397
1458
  if (!S.measures || S.measures.length === 0)
1398
1459
  return e;
1399
1460
  for (const O of A) {
1400
- const N = this.findHasManyJoinDef(R, O.cube.name);
1401
- if (!N)
1461
+ const t = this.findHasManyJoinDef(R, O.cube.name);
1462
+ if (!t)
1402
1463
  continue;
1403
1464
  const D = S.measures ? S.measures.filter(
1404
1465
  (L) => L.startsWith(O.cube.name + ".")
1405
- ) : [], I = this.extractMeasuresFromFilters(S, O.cube.name), C = [.../* @__PURE__ */ new Set([...D, ...I])];
1406
- if (C.length === 0)
1466
+ ) : [], I = this.extractMeasuresFromFilters(S, O.cube.name), N = [.../* @__PURE__ */ new Set([...D, ...I])];
1467
+ if (N.length === 0)
1407
1468
  continue;
1408
- const s = N.on.map((L) => ({
1469
+ const s = t.on.map((L) => ({
1409
1470
  sourceColumn: L.source.name,
1410
1471
  targetColumn: L.target.name,
1411
1472
  sourceColumnObj: L.source,
@@ -1416,7 +1477,7 @@ class RR {
1416
1477
  alias: O.alias,
1417
1478
  cteAlias: `${O.cube.name.toLowerCase()}_agg`,
1418
1479
  joinKeys: s,
1419
- measures: C
1480
+ measures: N
1420
1481
  });
1421
1482
  }
1422
1483
  return e;
@@ -1437,7 +1498,7 @@ class OE {
1437
1498
  constructor(E) {
1438
1499
  if (this.dbExecutor = E, this.databaseAdapter = E.databaseAdapter, !this.databaseAdapter)
1439
1500
  throw new Error("DatabaseExecutor must have a databaseAdapter property");
1440
- this.queryBuilder = new TR(this.databaseAdapter), this.queryPlanner = new RR();
1501
+ this.queryBuilder = new RR(this.databaseAdapter), this.queryPlanner = new AR();
1441
1502
  }
1442
1503
  queryBuilder;
1443
1504
  queryPlanner;
@@ -1447,30 +1508,30 @@ class OE {
1447
1508
  */
1448
1509
  async execute(E, R, A) {
1449
1510
  try {
1450
- const S = bT(E, R);
1511
+ const S = yT(E, R);
1451
1512
  if (!S.isValid)
1452
1513
  throw new Error(`Query validation failed: ${S.errors.join(", ")}`);
1453
1514
  const e = {
1454
1515
  db: this.dbExecutor.db,
1455
1516
  schema: this.dbExecutor.schema,
1456
1517
  securityContext: A
1457
- }, O = this.queryPlanner.createQueryPlan(E, R, e), N = this.buildUnifiedQuery(O, R, e), D = this.queryBuilder.collectNumericFields(E, R), I = await this.dbExecutor.execute(N, D), C = Array.isArray(I) ? I.map((L) => {
1518
+ }, O = this.queryPlanner.createQueryPlan(E, R, e), t = this.buildUnifiedQuery(O, R, e), D = this.queryBuilder.collectNumericFields(E, R), I = await this.dbExecutor.execute(t, D), N = Array.isArray(I) ? I.map((L) => {
1458
1519
  const P = { ...L };
1459
1520
  if (R.timeDimensions) {
1460
- for (const a of R.timeDimensions)
1461
- if (a.dimension in P) {
1462
- let r = P[a.dimension];
1521
+ for (const o of R.timeDimensions)
1522
+ if (o.dimension in P) {
1523
+ let r = P[o.dimension];
1463
1524
  if (typeof r == "string" && r.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
1464
- const U = r.replace(" ", "T"), o = !U.endsWith("Z") && !U.includes("+") ? U + "Z" : U;
1465
- r = new Date(o);
1525
+ const U = r.replace(" ", "T"), a = !U.endsWith("Z") && !U.includes("+") ? U + "Z" : U;
1526
+ r = new Date(a);
1466
1527
  }
1467
- r = this.databaseAdapter.convertTimeDimensionResult(r), P[a.dimension] = r;
1528
+ r = this.databaseAdapter.convertTimeDimensionResult(r), P[o.dimension] = r;
1468
1529
  }
1469
1530
  }
1470
1531
  return P;
1471
1532
  }) : [I], s = this.generateAnnotations(O, R);
1472
1533
  return {
1473
- data: C,
1534
+ data: N,
1474
1535
  annotation: s
1475
1536
  };
1476
1537
  } catch (S) {
@@ -1488,61 +1549,61 @@ class OE {
1488
1549
  * Build pre-aggregation CTE for hasMany relationships
1489
1550
  */
1490
1551
  buildPreAggregationCTE(E, R, A, S) {
1491
- const e = E.cube, O = e.sql(A), N = {};
1552
+ const e = E.cube, O = e.sql(A), t = {};
1492
1553
  for (const r of E.joinKeys)
1493
1554
  if (r.targetColumnObj) {
1494
- N[r.targetColumn] = r.targetColumnObj;
1495
- for (const [U, o] of Object.entries(e.dimensions || {}))
1496
- o.sql === r.targetColumnObj && U !== r.targetColumn && (N[U] = _`${r.targetColumnObj}`.as(U));
1555
+ t[r.targetColumn] = r.targetColumnObj;
1556
+ for (const [U, a] of Object.entries(e.dimensions || {}))
1557
+ a.sql === r.targetColumnObj && U !== r.targetColumn && (t[U] = _`${r.targetColumnObj}`.as(U));
1497
1558
  }
1498
1559
  for (const r of E.measures) {
1499
1560
  const [, U] = r.split(".");
1500
1561
  if (e.measures && e.measures[U]) {
1501
- const o = e.measures[U], c = this.queryBuilder.buildMeasureExpression(o, A);
1502
- N[U] = _`${c}`.as(U);
1562
+ const a = e.measures[U], l = this.queryBuilder.buildMeasureExpression(a, A);
1563
+ t[U] = _`${l}`.as(U);
1503
1564
  }
1504
1565
  }
1505
1566
  const D = e.name;
1506
1567
  if (R.dimensions)
1507
1568
  for (const r of R.dimensions) {
1508
- const [U, o] = r.split(".");
1509
- if (U === D && e.dimensions && e.dimensions[o]) {
1510
- const c = e.dimensions[o], l = this.queryBuilder.buildMeasureExpression({ sql: c.sql, type: "number" }, A);
1511
- N[o] = _`${l}`.as(o);
1569
+ const [U, a] = r.split(".");
1570
+ if (U === D && e.dimensions && e.dimensions[a]) {
1571
+ const l = e.dimensions[a], c = this.queryBuilder.buildMeasureExpression({ sql: l.sql, type: "number" }, A);
1572
+ t[a] = _`${c}`.as(a);
1512
1573
  }
1513
1574
  }
1514
1575
  if (R.timeDimensions)
1515
1576
  for (const r of R.timeDimensions) {
1516
- const [U, o] = r.dimension.split(".");
1517
- if (U === D && e.dimensions && e.dimensions[o]) {
1518
- const c = e.dimensions[o], l = this.queryBuilder.buildTimeDimensionExpression(c.sql, r.granularity, A);
1519
- N[o] = _`${l}`.as(o);
1577
+ const [U, a] = r.dimension.split(".");
1578
+ if (U === D && e.dimensions && e.dimensions[a]) {
1579
+ const l = e.dimensions[a], c = this.queryBuilder.buildTimeDimensionExpression(l.sql, r.granularity, A);
1580
+ t[a] = _`${c}`.as(a);
1520
1581
  }
1521
1582
  }
1522
- if (Object.keys(N).length === 0)
1583
+ if (Object.keys(t).length === 0)
1523
1584
  return null;
1524
- let I = A.db.select(N).from(O.from);
1525
- const C = S ? {
1585
+ let I = A.db.select(t).from(O.from);
1586
+ const N = S ? {
1526
1587
  ...S,
1527
1588
  preAggregationCTEs: S.preAggregationCTEs?.filter((r) => r.cube.name !== e.name)
1528
- } : void 0, s = this.queryBuilder.buildWhereConditions(e, R, A, C), L = [];
1589
+ } : void 0, s = this.queryBuilder.buildWhereConditions(e, R, A, N), L = [];
1529
1590
  if (R.timeDimensions)
1530
1591
  for (const r of R.timeDimensions) {
1531
- const [U, o] = r.dimension.split(".");
1532
- if (U === D && e.dimensions && e.dimensions[o] && r.dateRange) {
1533
- const c = e.dimensions[o], l = this.queryBuilder.buildMeasureExpression({ sql: c.sql, type: "number" }, A), u = this.queryBuilder.buildDateRangeCondition(l, r.dateRange);
1534
- u && L.push(u);
1592
+ const [U, a] = r.dimension.split(".");
1593
+ if (U === D && e.dimensions && e.dimensions[a] && r.dateRange) {
1594
+ const l = e.dimensions[a], c = this.queryBuilder.buildMeasureExpression({ sql: l.sql, type: "number" }, A), H = this.queryBuilder.buildDateRangeCondition(c, r.dateRange);
1595
+ H && L.push(H);
1535
1596
  }
1536
1597
  }
1537
1598
  if (R.filters) {
1538
1599
  for (const r of R.filters)
1539
1600
  if (!("and" in r) && !("or" in r) && "member" in r && "operator" in r) {
1540
- const U = r, [o, c] = U.member.split(".");
1541
- if (o === D && e.dimensions && e.dimensions[c]) {
1542
- const l = e.dimensions[c];
1601
+ const U = r, [a, l] = U.member.split(".");
1602
+ if (a === D && e.dimensions && e.dimensions[l]) {
1603
+ const c = e.dimensions[l];
1543
1604
  if (U.operator === "inDateRange") {
1544
- const u = this.queryBuilder.buildMeasureExpression({ sql: l.sql, type: "number" }, A), Y = this.queryBuilder.buildDateRangeCondition(u, U.values);
1545
- Y && L.push(Y);
1605
+ const H = this.queryBuilder.buildMeasureExpression({ sql: c.sql, type: "number" }, A), u = this.queryBuilder.buildDateRangeCondition(H, U.values);
1606
+ u && L.push(u);
1546
1607
  }
1547
1608
  }
1548
1609
  }
@@ -1552,26 +1613,26 @@ class OE {
1552
1613
  const r = P.length === 1 ? P[0] : m(...P);
1553
1614
  I = I.where(r);
1554
1615
  }
1555
- const a = [];
1616
+ const o = [];
1556
1617
  for (const r of E.joinKeys)
1557
- r.targetColumnObj && a.push(r.targetColumnObj);
1618
+ r.targetColumnObj && o.push(r.targetColumnObj);
1558
1619
  if (R.dimensions)
1559
1620
  for (const r of R.dimensions) {
1560
- const [U, o] = r.split(".");
1561
- if (U === D && e.dimensions && e.dimensions[o]) {
1562
- const c = e.dimensions[o], l = W(c.sql, A);
1563
- a.push(l);
1621
+ const [U, a] = r.split(".");
1622
+ if (U === D && e.dimensions && e.dimensions[a]) {
1623
+ const l = e.dimensions[a], c = f(l.sql, A);
1624
+ o.push(c);
1564
1625
  }
1565
1626
  }
1566
1627
  if (R.timeDimensions)
1567
1628
  for (const r of R.timeDimensions) {
1568
- const [U, o] = r.dimension.split(".");
1569
- if (U === D && e.dimensions && e.dimensions[o]) {
1570
- const c = e.dimensions[o], l = this.queryBuilder.buildTimeDimensionExpression(c.sql, r.granularity, A);
1571
- a.push(l);
1629
+ const [U, a] = r.dimension.split(".");
1630
+ if (U === D && e.dimensions && e.dimensions[a]) {
1631
+ const l = e.dimensions[a], c = this.queryBuilder.buildTimeDimensionExpression(l.sql, r.granularity, A);
1632
+ o.push(c);
1572
1633
  }
1573
1634
  }
1574
- return a.length > 0 && (I = I.groupBy(...a)), A.db.$with(E.cteAlias).as(I);
1635
+ return o.length > 0 && (I = I.groupBy(...o)), A.db.$with(E.cteAlias).as(I);
1575
1636
  }
1576
1637
  // Removed unused getActualJoinTargetColumn method
1577
1638
  /**
@@ -1583,8 +1644,8 @@ class OE {
1583
1644
  throw new Error(`CTE info not found for cube ${E.cube.name}`);
1584
1645
  const e = [];
1585
1646
  for (const O of S.joinKeys) {
1586
- const N = O.sourceColumnObj || _.identifier(O.sourceColumn), D = _`${_.identifier(R)}.${_.identifier(O.targetColumn)}`;
1587
- e.push(j(N, D));
1647
+ const t = O.sourceColumnObj || _.identifier(O.sourceColumn), D = _`${_.identifier(R)}.${_.identifier(O.targetColumn)}`;
1648
+ e.push(w(t, D));
1588
1649
  }
1589
1650
  return e.length === 1 ? e[0] : m(...e);
1590
1651
  }
@@ -1607,98 +1668,123 @@ class OE {
1607
1668
  if (E.preAggregationCTEs)
1608
1669
  for (const r of E.preAggregationCTEs) {
1609
1670
  const U = r.cube.name;
1610
- for (const o of r.measures)
1611
- if (D[o]) {
1612
- const [, c] = o.split("."), l = this.getCubesFromPlan(E).get(U);
1613
- if (l && l.measures && l.measures[c]) {
1614
- const u = l.measures[c], Y = _`${_.identifier(r.cteAlias)}.${_.identifier(c)}`;
1671
+ for (const a of r.measures)
1672
+ if (D[a]) {
1673
+ const [, l] = a.split("."), c = this.getCubesFromPlan(E).get(U);
1674
+ if (c && c.measures && c.measures[l]) {
1675
+ const H = c.measures[l], u = _`${_.identifier(r.cteAlias)}.${_.identifier(l)}`;
1615
1676
  let p;
1616
- switch (u.type) {
1677
+ switch (H.type) {
1617
1678
  case "count":
1618
1679
  case "countDistinct":
1619
1680
  case "sum":
1620
- p = f(Y);
1681
+ p = W(u);
1621
1682
  break;
1622
1683
  case "avg":
1623
- p = this.databaseAdapter.buildAvg(Y);
1684
+ p = this.databaseAdapter.buildAvg(u);
1624
1685
  break;
1625
1686
  case "min":
1626
- p = mE(Y);
1687
+ p = mE(u);
1627
1688
  break;
1628
1689
  case "max":
1629
- p = YE(Y);
1690
+ p = YE(u);
1630
1691
  break;
1631
1692
  case "number":
1632
- p = f(Y);
1693
+ p = W(u);
1633
1694
  break;
1634
1695
  default:
1635
- p = f(Y);
1696
+ p = W(u);
1636
1697
  }
1637
- D[o] = _`${p}`.as(o);
1698
+ D[a] = _`${p}`.as(a);
1638
1699
  }
1639
1700
  }
1640
- for (const o in D) {
1641
- const [c, l] = o.split(".");
1642
- if (c === U) {
1643
- const u = this.getCubesFromPlan(E).get(U), Y = u && u.dimensions?.[l], p = o.startsWith(U + ".");
1644
- if (Y || p) {
1645
- let K = r.joinKeys.find((TE) => TE.targetColumn === l);
1646
- if (!K && u?.dimensions?.[l]) {
1647
- const TE = u.dimensions[l].sql;
1648
- K = r.joinKeys.find((yT) => yT.targetColumnObj === TE);
1701
+ for (const a in D) {
1702
+ const [l, c] = a.split(".");
1703
+ if (l === U) {
1704
+ const H = this.getCubesFromPlan(E).get(U), u = H && H.dimensions?.[c], p = a.startsWith(U + ".");
1705
+ if (u || p) {
1706
+ let y = r.joinKeys.find((TE) => TE.targetColumn === c);
1707
+ if (!y && H?.dimensions?.[c]) {
1708
+ const TE = H.dimensions[c].sql;
1709
+ y = r.joinKeys.find(($T) => $T.targetColumnObj === TE);
1649
1710
  }
1650
- K ? D[o] = _`${_.identifier(r.cteAlias)}.${_.identifier(l)}`.as(o) : p && u?.dimensions?.[l] && (D[o] = _`${_.identifier(r.cteAlias)}.${_.identifier(l)}`.as(o));
1711
+ y ? D[a] = _`${_.identifier(r.cteAlias)}.${_.identifier(c)}`.as(a) : p && H?.dimensions?.[c] && (D[a] = _`${_.identifier(r.cteAlias)}.${_.identifier(c)}`.as(a));
1651
1712
  }
1652
1713
  }
1653
1714
  }
1654
1715
  }
1655
- let I = A.db.select(D).from(O.from);
1656
- if (S.length > 0 && (I = A.db.with(...S).select(D).from(O.from)), O.joins)
1716
+ const I = [];
1717
+ let N = A.db.select(D).from(O.from);
1718
+ if (S.length > 0 && (N = A.db.with(...S).select(D).from(O.from)), O.joins)
1657
1719
  for (const r of O.joins)
1658
1720
  switch (r.type || "left") {
1659
1721
  case "left":
1660
- I = I.leftJoin(r.table, r.on);
1722
+ N = N.leftJoin(r.table, r.on);
1661
1723
  break;
1662
1724
  case "inner":
1663
- I = I.innerJoin(r.table, r.on);
1725
+ N = N.innerJoin(r.table, r.on);
1664
1726
  break;
1665
1727
  case "right":
1666
- I = I.rightJoin(r.table, r.on);
1728
+ N = N.rightJoin(r.table, r.on);
1667
1729
  break;
1668
1730
  case "full":
1669
- I = I.fullJoin(r.table, r.on);
1731
+ N = N.fullJoin(r.table, r.on);
1670
1732
  break;
1671
1733
  }
1672
1734
  if (E.joinCubes && E.joinCubes.length > 0)
1673
1735
  for (const r of E.joinCubes) {
1674
1736
  const U = e.get(r.cube.name);
1675
- let o, c;
1676
- U ? (o = _`${_.identifier(U)}`, c = this.buildCTEJoinCondition(r, U, E)) : (o = r.cube.sql(A).from, c = r.joinCondition);
1737
+ if (r.junctionTable) {
1738
+ const c = r.junctionTable, H = [];
1739
+ if (c.securitySql) {
1740
+ const u = c.securitySql(A.securityContext);
1741
+ Array.isArray(u) ? H.push(...u) : H.push(u);
1742
+ }
1743
+ try {
1744
+ switch (c.joinType || "left") {
1745
+ case "left":
1746
+ N = N.leftJoin(c.table, c.joinCondition);
1747
+ break;
1748
+ case "inner":
1749
+ N = N.innerJoin(c.table, c.joinCondition);
1750
+ break;
1751
+ case "right":
1752
+ N = N.rightJoin(c.table, c.joinCondition);
1753
+ break;
1754
+ case "full":
1755
+ N = N.fullJoin(c.table, c.joinCondition);
1756
+ break;
1757
+ }
1758
+ H.length > 0 && I.push(...H);
1759
+ } catch {
1760
+ }
1761
+ }
1762
+ let a, l;
1763
+ U ? (a = _`${_.identifier(U)}`, l = this.buildCTEJoinCondition(r, U, E)) : (a = r.cube.sql(A).from, l = r.joinCondition);
1677
1764
  try {
1678
1765
  switch (r.joinType || "left") {
1679
1766
  case "left":
1680
- I = I.leftJoin(o, c);
1767
+ N = N.leftJoin(a, l);
1681
1768
  break;
1682
1769
  case "inner":
1683
- I = I.innerJoin(o, c);
1770
+ N = N.innerJoin(a, l);
1684
1771
  break;
1685
1772
  case "right":
1686
- I = I.rightJoin(o, c);
1773
+ N = N.rightJoin(a, l);
1687
1774
  break;
1688
1775
  case "full":
1689
- I = I.fullJoin(o, c);
1776
+ N = N.fullJoin(a, l);
1690
1777
  break;
1691
1778
  }
1692
1779
  } catch {
1693
1780
  }
1694
1781
  }
1695
- const C = [];
1696
- if (O.where && C.push(O.where), E.joinCubes && E.joinCubes.length > 0)
1782
+ if (O.where && I.push(O.where), E.joinCubes && E.joinCubes.length > 0)
1697
1783
  for (const r of E.joinCubes) {
1698
1784
  if (e.get(r.cube.name))
1699
1785
  continue;
1700
- const o = r.cube.sql(A);
1701
- o.where && C.push(o.where);
1786
+ const a = r.cube.sql(A);
1787
+ a.where && I.push(a.where);
1702
1788
  }
1703
1789
  const s = this.queryBuilder.buildWhereConditions(
1704
1790
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
@@ -1708,9 +1794,9 @@ class OE {
1708
1794
  E
1709
1795
  // Pass the queryPlan to handle CTE scenarios
1710
1796
  );
1711
- if (s.length > 0 && C.push(...s), C.length > 0) {
1712
- const r = C.length === 1 ? C[0] : m(...C);
1713
- I = I.where(r);
1797
+ if (s.length > 0 && I.push(...s), I.length > 0) {
1798
+ const r = I.length === 1 ? I[0] : m(...I);
1799
+ N = N.where(r);
1714
1800
  }
1715
1801
  const L = this.queryBuilder.buildGroupByFields(
1716
1802
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
@@ -1720,7 +1806,7 @@ class OE {
1720
1806
  E
1721
1807
  // Pass the queryPlan to handle CTE scenarios
1722
1808
  );
1723
- L.length > 0 && (I = I.groupBy(...L));
1809
+ L.length > 0 && (N = N.groupBy(...L));
1724
1810
  const P = this.queryBuilder.buildHavingConditions(
1725
1811
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
1726
1812
  // Single cube
@@ -1731,10 +1817,10 @@ class OE {
1731
1817
  );
1732
1818
  if (P.length > 0) {
1733
1819
  const r = P.length === 1 ? P[0] : m(...P);
1734
- I = I.having(r);
1820
+ N = N.having(r);
1735
1821
  }
1736
- const a = this.queryBuilder.buildOrderBy(R);
1737
- return a.length > 0 && (I = I.orderBy(...a)), I = this.queryBuilder.applyLimitAndOffset(I, R), I;
1822
+ const o = this.queryBuilder.buildOrderBy(R);
1823
+ return o.length > 0 && (N = N.orderBy(...o)), N = this.queryBuilder.applyLimitAndOffset(N, R), N;
1738
1824
  }
1739
1825
  /**
1740
1826
  * Convert query plan to cube map for QueryBuilder methods
@@ -1767,10 +1853,10 @@ class OE {
1767
1853
  db: this.dbExecutor.db,
1768
1854
  schema: this.dbExecutor.schema,
1769
1855
  securityContext: A
1770
- }, e = this.queryPlanner.createQueryPlan(E, R, S), N = this.buildUnifiedQuery(e, R, S).toSQL();
1856
+ }, e = this.queryPlanner.createQueryPlan(E, R, S), t = this.buildUnifiedQuery(e, R, S).toSQL();
1771
1857
  return {
1772
- sql: N.sql,
1773
- params: N.params
1858
+ sql: t.sql,
1859
+ params: t.params
1774
1860
  };
1775
1861
  }
1776
1862
  /**
@@ -1778,12 +1864,12 @@ class OE {
1778
1864
  */
1779
1865
  generateAnnotations(E, R) {
1780
1866
  const A = {}, S = {}, e = {}, O = [E.primaryCube];
1781
- if (E.joinCubes && E.joinCubes.length > 0 && O.push(...E.joinCubes.map((N) => N.cube)), R.measures)
1782
- for (const N of R.measures) {
1783
- const [D, I] = N.split("."), C = O.find((s) => s.name === D);
1784
- if (C && C.measures[I]) {
1785
- const s = C.measures[I];
1786
- A[N] = {
1867
+ if (E.joinCubes && E.joinCubes.length > 0 && O.push(...E.joinCubes.map((t) => t.cube)), R.measures)
1868
+ for (const t of R.measures) {
1869
+ const [D, I] = t.split("."), N = O.find((s) => s.name === D);
1870
+ if (N && N.measures[I]) {
1871
+ const s = N.measures[I];
1872
+ A[t] = {
1787
1873
  title: s.title || I,
1788
1874
  shortTitle: s.title || I,
1789
1875
  type: s.type
@@ -1791,11 +1877,11 @@ class OE {
1791
1877
  }
1792
1878
  }
1793
1879
  if (R.dimensions)
1794
- for (const N of R.dimensions) {
1795
- const [D, I] = N.split("."), C = O.find((s) => s.name === D);
1796
- if (C && C.dimensions[I]) {
1797
- const s = C.dimensions[I];
1798
- S[N] = {
1880
+ for (const t of R.dimensions) {
1881
+ const [D, I] = t.split("."), N = O.find((s) => s.name === D);
1882
+ if (N && N.dimensions[I]) {
1883
+ const s = N.dimensions[I];
1884
+ S[t] = {
1799
1885
  title: s.title || I,
1800
1886
  shortTitle: s.title || I,
1801
1887
  type: s.type
@@ -1803,15 +1889,15 @@ class OE {
1803
1889
  }
1804
1890
  }
1805
1891
  if (R.timeDimensions)
1806
- for (const N of R.timeDimensions) {
1807
- const [D, I] = N.dimension.split("."), C = O.find((s) => s.name === D);
1808
- if (C && C.dimensions && C.dimensions[I]) {
1809
- const s = C.dimensions[I];
1810
- e[N.dimension] = {
1892
+ for (const t of R.timeDimensions) {
1893
+ const [D, I] = t.dimension.split("."), N = O.find((s) => s.name === D);
1894
+ if (N && N.dimensions && N.dimensions[I]) {
1895
+ const s = N.dimensions[I];
1896
+ e[t.dimension] = {
1811
1897
  title: s.title || I,
1812
1898
  shortTitle: s.title || I,
1813
1899
  type: s.type,
1814
- granularity: N.granularity
1900
+ granularity: t.granularity
1815
1901
  };
1816
1902
  }
1817
1903
  }
@@ -1823,13 +1909,13 @@ class OE {
1823
1909
  };
1824
1910
  }
1825
1911
  }
1826
- const t = (T) => T.flatMap(AR), AR = (T) => Q(eR(T)).map(SR), SR = (T) => T.replace(/ +/g, " ").trim(), eR = (T) => ({
1912
+ const C = (T) => T.flatMap(SR), SR = (T) => Z(IR(T)).map(eR), eR = (T) => T.replace(/ +/g, " ").trim(), IR = (T) => ({
1827
1913
  type: "mandatory_block",
1828
- items: hE(T, 0)[0]
1829
- }), hE = (T, E, R) => {
1914
+ items: VE(T, 0)[0]
1915
+ }), VE = (T, E, R) => {
1830
1916
  const A = [];
1831
1917
  for (; T[E]; ) {
1832
- const [S, e] = IR(T, E);
1918
+ const [S, e] = NR(T, E);
1833
1919
  if (A.push(S), E = e, T[E] === "|")
1834
1920
  E++;
1835
1921
  else if (T[E] === "}" || T[E] === "]") {
@@ -1844,44 +1930,44 @@ const t = (T) => T.flatMap(AR), AR = (T) => Q(eR(T)).map(SR), SR = (T) => T.repl
1844
1930
  throw new Error(`Unexpected "${T[E]}"`);
1845
1931
  }
1846
1932
  return [A, E];
1847
- }, IR = (T, E) => {
1933
+ }, NR = (T, E) => {
1848
1934
  const R = [];
1849
1935
  for (; ; ) {
1850
- const [A, S] = NR(T, E);
1936
+ const [A, S] = sR(T, E);
1851
1937
  if (A)
1852
1938
  R.push(A), E = S;
1853
1939
  else
1854
1940
  break;
1855
1941
  }
1856
1942
  return R.length === 1 ? [R[0], E] : [{ type: "concatenation", items: R }, E];
1857
- }, NR = (T, E) => {
1943
+ }, sR = (T, E) => {
1858
1944
  if (T[E] === "{")
1859
- return sR(T, E + 1);
1860
- if (T[E] === "[")
1861
1945
  return tR(T, E + 1);
1946
+ if (T[E] === "[")
1947
+ return CR(T, E + 1);
1862
1948
  {
1863
1949
  let R = "";
1864
1950
  for (; T[E] && /[A-Za-z0-9_ ]/.test(T[E]); )
1865
1951
  R += T[E], E++;
1866
1952
  return [R, E];
1867
1953
  }
1868
- }, sR = (T, E) => {
1869
- const [R, A] = hE(T, E, "}");
1870
- return [{ type: "mandatory_block", items: R }, A];
1871
1954
  }, tR = (T, E) => {
1872
- const [R, A] = hE(T, E, "]");
1955
+ const [R, A] = VE(T, E, "}");
1956
+ return [{ type: "mandatory_block", items: R }, A];
1957
+ }, CR = (T, E) => {
1958
+ const [R, A] = VE(T, E, "]");
1873
1959
  return [{ type: "optional_block", items: R }, A];
1874
- }, Q = (T) => {
1960
+ }, Z = (T) => {
1875
1961
  if (typeof T == "string")
1876
1962
  return [T];
1877
1963
  if (T.type === "concatenation")
1878
- return T.items.map(Q).reduce(CR, [""]);
1964
+ return T.items.map(Z).reduce(LR, [""]);
1879
1965
  if (T.type === "mandatory_block")
1880
- return T.items.flatMap(Q);
1966
+ return T.items.flatMap(Z);
1881
1967
  if (T.type === "optional_block")
1882
- return ["", ...T.items.flatMap(Q)];
1968
+ return ["", ...T.items.flatMap(Z)];
1883
1969
  throw new Error(`Unknown node type: ${T}`);
1884
- }, CR = (T, E) => {
1970
+ }, LR = (T, E) => {
1885
1971
  const R = [];
1886
1972
  for (const A of T)
1887
1973
  for (const S of E)
@@ -1892,19 +1978,19 @@ var i;
1892
1978
  (function(T) {
1893
1979
  T.QUOTED_IDENTIFIER = "QUOTED_IDENTIFIER", T.IDENTIFIER = "IDENTIFIER", T.STRING = "STRING", T.VARIABLE = "VARIABLE", T.RESERVED_DATA_TYPE = "RESERVED_DATA_TYPE", T.RESERVED_PARAMETERIZED_DATA_TYPE = "RESERVED_PARAMETERIZED_DATA_TYPE", T.RESERVED_KEYWORD = "RESERVED_KEYWORD", T.RESERVED_FUNCTION_NAME = "RESERVED_FUNCTION_NAME", T.RESERVED_KEYWORD_PHRASE = "RESERVED_KEYWORD_PHRASE", T.RESERVED_DATA_TYPE_PHRASE = "RESERVED_DATA_TYPE_PHRASE", T.RESERVED_SET_OPERATION = "RESERVED_SET_OPERATION", T.RESERVED_CLAUSE = "RESERVED_CLAUSE", T.RESERVED_SELECT = "RESERVED_SELECT", T.RESERVED_JOIN = "RESERVED_JOIN", T.ARRAY_IDENTIFIER = "ARRAY_IDENTIFIER", T.ARRAY_KEYWORD = "ARRAY_KEYWORD", T.CASE = "CASE", T.END = "END", T.WHEN = "WHEN", T.ELSE = "ELSE", T.THEN = "THEN", T.LIMIT = "LIMIT", T.BETWEEN = "BETWEEN", T.AND = "AND", T.OR = "OR", T.XOR = "XOR", T.OPERATOR = "OPERATOR", T.COMMA = "COMMA", T.ASTERISK = "ASTERISK", T.PROPERTY_ACCESS_OPERATOR = "PROPERTY_ACCESS_OPERATOR", T.OPEN_PAREN = "OPEN_PAREN", T.CLOSE_PAREN = "CLOSE_PAREN", T.LINE_COMMENT = "LINE_COMMENT", T.BLOCK_COMMENT = "BLOCK_COMMENT", T.DISABLE_COMMENT = "DISABLE_COMMENT", T.NUMBER = "NUMBER", T.NAMED_PARAMETER = "NAMED_PARAMETER", T.QUOTED_PARAMETER = "QUOTED_PARAMETER", T.NUMBERED_PARAMETER = "NUMBERED_PARAMETER", T.POSITIONAL_PARAMETER = "POSITIONAL_PARAMETER", T.CUSTOM_PARAMETER = "CUSTOM_PARAMETER", T.DELIMITER = "DELIMITER", T.EOF = "EOF";
1894
1980
  })(i = i || (i = {}));
1895
- const HT = (T) => ({
1981
+ const uT = (T) => ({
1896
1982
  type: i.EOF,
1897
1983
  raw: "«EOF»",
1898
1984
  text: "«EOF»",
1899
1985
  start: T
1900
- }), w = HT(1 / 0), g = (T) => (E) => E.type === T.type && E.text === T.text, X = {
1986
+ }), x = uT(1 / 0), g = (T) => (E) => E.type === T.type && E.text === T.text, X = {
1901
1987
  ARRAY: g({ text: "ARRAY", type: i.RESERVED_DATA_TYPE }),
1902
1988
  BY: g({ text: "BY", type: i.RESERVED_KEYWORD }),
1903
1989
  SET: g({ text: "SET", type: i.RESERVED_CLAUSE }),
1904
1990
  STRUCT: g({ text: "STRUCT", type: i.RESERVED_DATA_TYPE }),
1905
1991
  WINDOW: g({ text: "WINDOW", type: i.RESERVED_CLAUSE }),
1906
1992
  VALUES: g({ text: "VALUES", type: i.RESERVED_CLAUSE })
1907
- }, uT = (T) => T === i.RESERVED_DATA_TYPE || T === i.RESERVED_KEYWORD || T === i.RESERVED_FUNCTION_NAME || T === i.RESERVED_KEYWORD_PHRASE || T === i.RESERVED_DATA_TYPE_PHRASE || T === i.RESERVED_CLAUSE || T === i.RESERVED_SELECT || T === i.RESERVED_SET_OPERATION || T === i.RESERVED_JOIN || T === i.ARRAY_KEYWORD || T === i.CASE || T === i.END || T === i.WHEN || T === i.ELSE || T === i.THEN || T === i.LIMIT || T === i.BETWEEN || T === i.AND || T === i.OR || T === i.XOR, LR = (T) => T === i.AND || T === i.OR || T === i.XOR, _R = [
1993
+ }, BT = (T) => T === i.RESERVED_DATA_TYPE || T === i.RESERVED_KEYWORD || T === i.RESERVED_FUNCTION_NAME || T === i.RESERVED_KEYWORD_PHRASE || T === i.RESERVED_DATA_TYPE_PHRASE || T === i.RESERVED_CLAUSE || T === i.RESERVED_SELECT || T === i.RESERVED_SET_OPERATION || T === i.RESERVED_JOIN || T === i.ARRAY_KEYWORD || T === i.CASE || T === i.END || T === i.WHEN || T === i.ELSE || T === i.THEN || T === i.LIMIT || T === i.BETWEEN || T === i.AND || T === i.OR || T === i.XOR, _R = (T) => T === i.AND || T === i.OR || T === i.XOR, rR = [
1908
1994
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/aead_encryption_functions
1909
1995
  "KEYS.NEW_KEYSET",
1910
1996
  "KEYS.ADD_KEY_FROM_RAW_BYTES",
@@ -2448,7 +2534,7 @@ const HT = (T) => ({
2448
2534
  // pivot
2449
2535
  "PIVOT",
2450
2536
  "UNPIVOT"
2451
- ], rR = [
2537
+ ], nR = [
2452
2538
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#reserved_keywords
2453
2539
  "ALL",
2454
2540
  "AND",
@@ -2556,7 +2642,7 @@ const HT = (T) => ({
2556
2642
  "CASCADE",
2557
2643
  "RESTRICT",
2558
2644
  "DETERMINISTIC"
2559
- ], nR = [
2645
+ ], DR = [
2560
2646
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
2561
2647
  "ARRAY",
2562
2648
  "BOOL",
@@ -2581,7 +2667,7 @@ const HT = (T) => ({
2581
2667
  "STRUCT",
2582
2668
  "TIME",
2583
2669
  "TIMEZONE"
2584
- ], DR = t(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), iR = t([
2670
+ ], iR = C(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), PR = C([
2585
2671
  // Queries: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
2586
2672
  "WITH [RECURSIVE]",
2587
2673
  "FROM",
@@ -2610,9 +2696,9 @@ const HT = (T) => ({
2610
2696
  "WITH CONNECTION",
2611
2697
  "WITH PARTITION COLUMNS",
2612
2698
  "REMOTE WITH CONNECTION"
2613
- ]), xE = t([
2699
+ ]), xE = C([
2614
2700
  "CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]"
2615
- ]), NE = t([
2701
+ ]), NE = C([
2616
2702
  // - create:
2617
2703
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
2618
2704
  "CREATE [OR REPLACE] [MATERIALIZED] VIEW [IF NOT EXISTS]",
@@ -2700,15 +2786,15 @@ const HT = (T) => ({
2700
2786
  "ASSERT",
2701
2787
  // Other, https://cloud.google.com/bigquery/docs/reference/standard-sql/other-statements
2702
2788
  "EXPORT DATA"
2703
- ]), PR = t([
2789
+ ]), oR = C([
2704
2790
  "UNION {ALL | DISTINCT}",
2705
2791
  "EXCEPT DISTINCT",
2706
2792
  "INTERSECT DISTINCT"
2707
- ]), aR = t([
2793
+ ]), aR = C([
2708
2794
  "JOIN",
2709
2795
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
2710
2796
  "{INNER | CROSS} JOIN"
2711
- ]), oR = t([
2797
+ ]), MR = C([
2712
2798
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#tablesample_operator
2713
2799
  "TABLESAMPLE SYSTEM",
2714
2800
  // From DDL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
@@ -2719,18 +2805,18 @@ const HT = (T) => ({
2719
2805
  "{ROWS | RANGE} BETWEEN",
2720
2806
  // comparison operator
2721
2807
  "IS [NOT] DISTINCT FROM"
2722
- ]), MR = t([]), UR = {
2808
+ ]), UR = C([]), GR = {
2723
2809
  name: "bigquery",
2724
2810
  tokenizerOptions: {
2725
- reservedSelect: DR,
2726
- reservedClauses: [...iR, ...NE, ...xE],
2727
- reservedSetOperations: PR,
2811
+ reservedSelect: iR,
2812
+ reservedClauses: [...PR, ...NE, ...xE],
2813
+ reservedSetOperations: oR,
2728
2814
  reservedJoins: aR,
2729
- reservedKeywordPhrases: oR,
2730
- reservedDataTypePhrases: MR,
2731
- reservedKeywords: rR,
2732
- reservedDataTypes: nR,
2733
- reservedFunctionNames: _R,
2815
+ reservedKeywordPhrases: MR,
2816
+ reservedDataTypePhrases: UR,
2817
+ reservedKeywords: nR,
2818
+ reservedDataTypes: DR,
2819
+ reservedFunctionNames: rR,
2734
2820
  extraParens: ["[]"],
2735
2821
  stringTypes: [
2736
2822
  // The triple-quoted strings are listed first, so they get matched first.
@@ -2748,27 +2834,27 @@ const HT = (T) => ({
2748
2834
  variableTypes: [{ regex: String.raw`@@\w+` }],
2749
2835
  lineCommentTypes: ["--", "#"],
2750
2836
  operators: ["&", "|", "^", "~", ">>", "<<", "||", "=>"],
2751
- postProcess: GR
2837
+ postProcess: cR
2752
2838
  },
2753
2839
  formatOptions: {
2754
2840
  onelineClauses: [...xE, ...NE],
2755
2841
  tabularOnelineClauses: NE
2756
2842
  }
2757
2843
  };
2758
- function GR(T) {
2759
- return cR(lR(T));
2760
- }
2761
2844
  function cR(T) {
2762
- let E = w;
2763
- return T.map((R) => R.text === "OFFSET" && E.text === "[" ? (E = R, Object.assign(Object.assign({}, R), { type: i.RESERVED_FUNCTION_NAME })) : (E = R, R));
2845
+ return lR(HR(T));
2764
2846
  }
2765
2847
  function lR(T) {
2848
+ let E = x;
2849
+ return T.map((R) => R.text === "OFFSET" && E.text === "[" ? (E = R, Object.assign(Object.assign({}, R), { type: i.RESERVED_FUNCTION_NAME })) : (E = R, R));
2850
+ }
2851
+ function HR(T) {
2766
2852
  var E;
2767
2853
  const R = [];
2768
2854
  for (let A = 0; A < T.length; A++) {
2769
2855
  const S = T[A];
2770
2856
  if ((X.ARRAY(S) || X.STRUCT(S)) && ((E = T[A + 1]) === null || E === void 0 ? void 0 : E.text) === "<") {
2771
- const e = HR(T, A + 1), O = T.slice(A, e + 1);
2857
+ const e = uR(T, A + 1), O = T.slice(A, e + 1);
2772
2858
  R.push({
2773
2859
  type: i.IDENTIFIER,
2774
2860
  raw: O.map(vE("raw")).join(""),
@@ -2781,7 +2867,7 @@ function lR(T) {
2781
2867
  return R;
2782
2868
  }
2783
2869
  const vE = (T) => (E) => E.type === i.IDENTIFIER || E.type === i.COMMA ? E[T] + " " : E[T];
2784
- function HR(T, E) {
2870
+ function uR(T, E) {
2785
2871
  let R = 0;
2786
2872
  for (let A = E; A < T.length; A++) {
2787
2873
  const S = T[A];
@@ -2790,7 +2876,7 @@ function HR(T, E) {
2790
2876
  }
2791
2877
  return T.length - 1;
2792
2878
  }
2793
- const uR = [
2879
+ const BR = [
2794
2880
  // https://www.ibm.com/docs/en/db2/11.5?topic=bif-aggregate-functions
2795
2881
  "ARRAY_AGG",
2796
2882
  "AVG",
@@ -3110,7 +3196,7 @@ const uR = [
3110
3196
  "RATIO_TO_REPORT",
3111
3197
  // Type casting
3112
3198
  "CAST"
3113
- ], BR = [
3199
+ ], FR = [
3114
3200
  // https://www.ibm.com/docs/en/db2/11.5?topic=sql-reserved-schema-names-reserved-words
3115
3201
  "ACTIVATE",
3116
3202
  "ADD",
@@ -3511,7 +3597,7 @@ const uR = [
3511
3597
  "XMLNAMESPACES",
3512
3598
  "YEAR",
3513
3599
  "YEARS"
3514
- ], FR = [
3600
+ ], YR = [
3515
3601
  // https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
3516
3602
  "ARRAY",
3517
3603
  "BIGINT",
@@ -3553,7 +3639,7 @@ const uR = [
3553
3639
  "VARBINARY",
3554
3640
  "VARCHAR",
3555
3641
  "VARGRAPHIC"
3556
- ], YR = t(["SELECT [ALL | DISTINCT]"]), mR = t([
3642
+ ], mR = C(["SELECT [ALL | DISTINCT]"]), pR = C([
3557
3643
  // queries
3558
3644
  "WITH",
3559
3645
  "FROM",
@@ -3582,9 +3668,9 @@ const uR = [
3582
3668
  "WHEN [NOT] MATCHED [THEN]",
3583
3669
  "UPDATE SET",
3584
3670
  "INSERT"
3585
- ]), QE = t([
3671
+ ]), QE = C([
3586
3672
  "CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]"
3587
- ]), sE = t([
3673
+ ]), sE = C([
3588
3674
  // - create:
3589
3675
  "CREATE [OR REPLACE] VIEW",
3590
3676
  // - update:
@@ -3787,27 +3873,27 @@ const uR = [
3787
3873
  "TRANSFER OWNERSHIP OF",
3788
3874
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}",
3789
3875
  "WHILE"
3790
- ]), pR = t(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), dR = t([
3876
+ ]), dR = C(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), hR = C([
3791
3877
  "JOIN",
3792
3878
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
3793
3879
  "{INNER | CROSS} JOIN"
3794
- ]), VR = t([
3880
+ ]), VR = C([
3795
3881
  "ON DELETE",
3796
3882
  "ON UPDATE",
3797
3883
  "SET NULL",
3798
3884
  "{ROWS | RANGE} BETWEEN"
3799
- ]), hR = t([]), WR = {
3885
+ ]), fR = C([]), WR = {
3800
3886
  name: "db2",
3801
3887
  tokenizerOptions: {
3802
- reservedSelect: YR,
3803
- reservedClauses: [...mR, ...QE, ...sE],
3804
- reservedSetOperations: pR,
3805
- reservedJoins: dR,
3888
+ reservedSelect: mR,
3889
+ reservedClauses: [...pR, ...QE, ...sE],
3890
+ reservedSetOperations: dR,
3891
+ reservedJoins: hR,
3806
3892
  reservedKeywordPhrases: VR,
3807
- reservedDataTypePhrases: hR,
3808
- reservedKeywords: BR,
3809
- reservedDataTypes: FR,
3810
- reservedFunctionNames: uR,
3893
+ reservedDataTypePhrases: fR,
3894
+ reservedKeywords: FR,
3895
+ reservedDataTypes: YR,
3896
+ reservedFunctionNames: BR,
3811
3897
  extraParens: ["[]"],
3812
3898
  stringTypes: [
3813
3899
  { quote: "''-qq", prefixes: ["G", "N", "U&"] },
@@ -3841,7 +3927,7 @@ const uR = [
3841
3927
  onelineClauses: [...QE, ...sE],
3842
3928
  tabularOnelineClauses: sE
3843
3929
  }
3844
- }, fR = [
3930
+ }, XR = [
3845
3931
  // https://www.ibm.com/docs/en/i/7.5?topic=functions-aggregate
3846
3932
  // TODO: 'ANY', - conflicts with test for ANY predicate in 'operators.ys'!!
3847
3933
  "ARRAY_AGG",
@@ -4175,7 +4261,7 @@ const uR = [
4175
4261
  "ROW_NUMBER",
4176
4262
  // Type casting
4177
4263
  "CAST"
4178
- ], XR = [
4264
+ ], bR = [
4179
4265
  // https://www.ibm.com/docs/en/i/7.5?topic=words-reserved
4180
4266
  // TODO: This list likely contains all keywords, not only the reserved ones,
4181
4267
  // try to filter it down to just the reserved keywords.
@@ -4671,7 +4757,7 @@ const uR = [
4671
4757
  "YEARS",
4672
4758
  "YES",
4673
4759
  "ZONE"
4674
- ], bR = [
4760
+ ], yR = [
4675
4761
  // https://www.ibm.com/docs/en/i/7.2?topic=iaodsd-odbc-data-types-how-they-correspond-db2-i-database-types
4676
4762
  "ARRAY",
4677
4763
  "BIGINT",
@@ -4707,7 +4793,7 @@ const uR = [
4707
4793
  "VARCHAR",
4708
4794
  "VARGRAPHIC",
4709
4795
  "XML"
4710
- ], KR = t(["SELECT [ALL | DISTINCT]"]), yR = t([
4796
+ ], KR = C(["SELECT [ALL | DISTINCT]"]), $R = C([
4711
4797
  // queries
4712
4798
  "WITH [RECURSIVE]",
4713
4799
  "INTO",
@@ -4737,7 +4823,7 @@ const uR = [
4737
4823
  "INSERT",
4738
4824
  // Data definition - table
4739
4825
  "FOR SYSTEM NAME"
4740
- ]), ZE = t(["CREATE [OR REPLACE] TABLE"]), tE = t([
4826
+ ]), ZE = C(["CREATE [OR REPLACE] TABLE"]), tE = C([
4741
4827
  // - create:
4742
4828
  "CREATE [OR REPLACE] [RECURSIVE] VIEW",
4743
4829
  // - update:
@@ -4833,28 +4919,28 @@ const uR = [
4833
4919
  "TAG",
4834
4920
  "TRANSFER OWNERSHIP OF",
4835
4921
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}"
4836
- ]), $R = t(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), gR = t([
4922
+ ]), gR = C(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), JR = C([
4837
4923
  "JOIN",
4838
4924
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
4839
4925
  "[LEFT | RIGHT] EXCEPTION JOIN",
4840
4926
  "{INNER | CROSS} JOIN"
4841
- ]), JR = t([
4927
+ ]), wR = C([
4842
4928
  "ON DELETE",
4843
4929
  "ON UPDATE",
4844
4930
  "SET NULL",
4845
4931
  "{ROWS | RANGE} BETWEEN"
4846
- ]), wR = t([]), xR = {
4932
+ ]), xR = C([]), vR = {
4847
4933
  name: "db2i",
4848
4934
  tokenizerOptions: {
4849
4935
  reservedSelect: KR,
4850
- reservedClauses: [...yR, ...ZE, ...tE],
4851
- reservedSetOperations: $R,
4852
- reservedJoins: gR,
4853
- reservedKeywordPhrases: JR,
4854
- reservedDataTypePhrases: wR,
4855
- reservedKeywords: XR,
4856
- reservedDataTypes: bR,
4857
- reservedFunctionNames: fR,
4936
+ reservedClauses: [...$R, ...ZE, ...tE],
4937
+ reservedSetOperations: gR,
4938
+ reservedJoins: JR,
4939
+ reservedKeywordPhrases: wR,
4940
+ reservedDataTypePhrases: xR,
4941
+ reservedKeywords: bR,
4942
+ reservedDataTypes: yR,
4943
+ reservedFunctionNames: XR,
4858
4944
  nestedBlockComments: !0,
4859
4945
  extraParens: ["[]"],
4860
4946
  stringTypes: [
@@ -4871,7 +4957,7 @@ const uR = [
4871
4957
  onelineClauses: [...ZE, ...tE],
4872
4958
  tabularOnelineClauses: tE
4873
4959
  }
4874
- }, vR = [
4960
+ }, QR = [
4875
4961
  // Functions from DuckDB (excluding those that start with an underscore):
4876
4962
  // SELECT DISTINCT upper(function_name) AS function_name
4877
4963
  // FROM duckdb_functions()
@@ -5534,7 +5620,7 @@ const uR = [
5534
5620
  // 'NULL', we really prefer treating it as keyword
5535
5621
  "RANK",
5536
5622
  "ROW_NUMBER"
5537
- ], QR = [
5623
+ ], ZR = [
5538
5624
  // Keywords from DuckDB:
5539
5625
  // SELECT upper(keyword_name)
5540
5626
  // FROM duckdb_keywords()
@@ -5616,7 +5702,7 @@ const uR = [
5616
5702
  "WHERE",
5617
5703
  "WINDOW",
5618
5704
  "WITH"
5619
- ], ZR = [
5705
+ ], qR = [
5620
5706
  // Types from DuckDB:
5621
5707
  // SELECT DISTINCT upper(type_name)
5622
5708
  // FROM duckdb_types()
@@ -5696,7 +5782,7 @@ const uR = [
5696
5782
  "UUID",
5697
5783
  "VARBINARY",
5698
5784
  "VARCHAR"
5699
- ], qR = t(["SELECT [ALL | DISTINCT]"]), kR = t([
5785
+ ], jR = C(["SELECT [ALL | DISTINCT]"]), kR = C([
5700
5786
  // queries
5701
5787
  "WITH [RECURSIVE]",
5702
5788
  "FROM",
@@ -5720,9 +5806,9 @@ const uR = [
5720
5806
  "SET",
5721
5807
  // other:
5722
5808
  "RETURNING"
5723
- ]), qE = t([
5809
+ ]), qE = C([
5724
5810
  "CREATE [OR REPLACE] [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]"
5725
- ]), CE = t([
5811
+ ]), CE = C([
5726
5812
  // TABLE
5727
5813
  // - update:
5728
5814
  "UPDATE",
@@ -5800,11 +5886,11 @@ const uR = [
5800
5886
  "PREPARE",
5801
5887
  "EXECUTE",
5802
5888
  "DEALLOCATE [PREPARE]"
5803
- ]), jR = t([
5889
+ ]), zR = C([
5804
5890
  "UNION [ALL | BY NAME]",
5805
5891
  "EXCEPT [ALL]",
5806
5892
  "INTERSECT [ALL]"
5807
- ]), zR = t([
5893
+ ]), EA = C([
5808
5894
  "JOIN",
5809
5895
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
5810
5896
  "{INNER | CROSS} JOIN",
@@ -5813,23 +5899,23 @@ const uR = [
5813
5899
  "POSITIONAL JOIN",
5814
5900
  "ANTI JOIN",
5815
5901
  "SEMI JOIN"
5816
- ]), EA = t([
5902
+ ]), TA = C([
5817
5903
  "{ROWS | RANGE | GROUPS} BETWEEN",
5818
5904
  "SIMILAR TO",
5819
5905
  "IS [NOT] DISTINCT FROM"
5820
- ]), TA = t(["TIMESTAMP WITH TIME ZONE"]), RA = {
5906
+ ]), RA = C(["TIMESTAMP WITH TIME ZONE"]), AA = {
5821
5907
  name: "duckdb",
5822
5908
  tokenizerOptions: {
5823
- reservedSelect: qR,
5909
+ reservedSelect: jR,
5824
5910
  reservedClauses: [...kR, ...qE, ...CE],
5825
- reservedSetOperations: jR,
5826
- reservedJoins: zR,
5827
- reservedKeywordPhrases: EA,
5828
- reservedDataTypePhrases: TA,
5911
+ reservedSetOperations: zR,
5912
+ reservedJoins: EA,
5913
+ reservedKeywordPhrases: TA,
5914
+ reservedDataTypePhrases: RA,
5829
5915
  supportsXor: !0,
5830
- reservedKeywords: QR,
5831
- reservedDataTypes: ZR,
5832
- reservedFunctionNames: vR,
5916
+ reservedKeywords: ZR,
5917
+ reservedDataTypes: qR,
5918
+ reservedFunctionNames: QR,
5833
5919
  nestedBlockComments: !0,
5834
5920
  extraParens: ["[]", "{}"],
5835
5921
  underscoresInNumbers: !0,
@@ -5893,7 +5979,7 @@ const uR = [
5893
5979
  onelineClauses: [...qE, ...CE],
5894
5980
  tabularOnelineClauses: CE
5895
5981
  }
5896
- }, AA = [
5982
+ }, SA = [
5897
5983
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
5898
5984
  // math
5899
5985
  "ABS",
@@ -6101,7 +6187,7 @@ const uR = [
6101
6187
  "CUME_DIST",
6102
6188
  "PERCENT_RANK",
6103
6189
  "NTILE"
6104
- ], SA = [
6190
+ ], eA = [
6105
6191
  // https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl
6106
6192
  // Non-reserved keywords have proscribed meanings in. HiveQL, but can still be used as table or column names
6107
6193
  "ADD",
@@ -6416,7 +6502,7 @@ const uR = [
6416
6502
  "JSONFILE",
6417
6503
  "INPUTFORMAT",
6418
6504
  "OUTPUTFORMAT"
6419
- ], eA = [
6505
+ ], IA = [
6420
6506
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
6421
6507
  "ARRAY",
6422
6508
  "BIGINT",
@@ -6437,7 +6523,7 @@ const uR = [
6437
6523
  "STRUCT",
6438
6524
  "TIMESTAMP",
6439
6525
  "VARCHAR"
6440
- ], IA = t(["SELECT [ALL | DISTINCT]"]), OA = t([
6526
+ ], OA = C(["SELECT [ALL | DISTINCT]"]), NA = C([
6441
6527
  // queries
6442
6528
  "WITH",
6443
6529
  "FROM",
@@ -6471,9 +6557,9 @@ const uR = [
6471
6557
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML#LanguageManualDML-Loadingfilesintotables
6472
6558
  "LOAD DATA [LOCAL] INPATH",
6473
6559
  "[OVERWRITE] INTO TABLE"
6474
- ]), kE = t([
6560
+ ]), jE = C([
6475
6561
  "CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]"
6476
- ]), LE = t([
6562
+ ]), LE = C([
6477
6563
  // - create:
6478
6564
  "CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]",
6479
6565
  // - update:
@@ -6498,24 +6584,24 @@ const uR = [
6498
6584
  "STORED AS",
6499
6585
  "STORED BY",
6500
6586
  "ROW FORMAT"
6501
- ]), NA = t(["UNION [ALL | DISTINCT]"]), sA = t([
6587
+ ]), sA = C(["UNION [ALL | DISTINCT]"]), tA = C([
6502
6588
  "JOIN",
6503
6589
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6504
6590
  "{INNER | CROSS} JOIN",
6505
6591
  // non-standard joins
6506
6592
  "LEFT SEMI JOIN"
6507
- ]), tA = t(["{ROWS | RANGE} BETWEEN"]), CA = t([]), LA = {
6593
+ ]), CA = C(["{ROWS | RANGE} BETWEEN"]), LA = C([]), _A = {
6508
6594
  name: "hive",
6509
6595
  tokenizerOptions: {
6510
- reservedSelect: IA,
6511
- reservedClauses: [...OA, ...kE, ...LE],
6512
- reservedSetOperations: NA,
6513
- reservedJoins: sA,
6514
- reservedKeywordPhrases: tA,
6515
- reservedDataTypePhrases: CA,
6516
- reservedKeywords: SA,
6517
- reservedDataTypes: eA,
6518
- reservedFunctionNames: AA,
6596
+ reservedSelect: OA,
6597
+ reservedClauses: [...NA, ...jE, ...LE],
6598
+ reservedSetOperations: sA,
6599
+ reservedJoins: tA,
6600
+ reservedKeywordPhrases: CA,
6601
+ reservedDataTypePhrases: LA,
6602
+ reservedKeywords: eA,
6603
+ reservedDataTypes: IA,
6604
+ reservedFunctionNames: SA,
6519
6605
  extraParens: ["[]"],
6520
6606
  stringTypes: ['""-bs', "''-bs"],
6521
6607
  identTypes: ["``"],
@@ -6523,20 +6609,20 @@ const uR = [
6523
6609
  operators: ["%", "~", "^", "|", "&", "<=>", "==", "!", "||"]
6524
6610
  },
6525
6611
  formatOptions: {
6526
- onelineClauses: [...kE, ...LE],
6612
+ onelineClauses: [...jE, ...LE],
6527
6613
  tabularOnelineClauses: LE
6528
6614
  }
6529
6615
  };
6530
6616
  function EE(T) {
6531
6617
  return T.map((E, R) => {
6532
- const A = T[R + 1] || w;
6618
+ const A = T[R + 1] || x;
6533
6619
  if (X.SET(E) && A.text === "(")
6534
6620
  return Object.assign(Object.assign({}, E), { type: i.RESERVED_FUNCTION_NAME });
6535
- const S = T[R - 1] || w;
6621
+ const S = T[R - 1] || x;
6536
6622
  return X.VALUES(E) && S.text === "=" ? Object.assign(Object.assign({}, E), { type: i.RESERVED_FUNCTION_NAME }) : E;
6537
6623
  });
6538
6624
  }
6539
- const _A = [
6625
+ const rA = [
6540
6626
  // https://mariadb.com/kb/en/reserved-words/
6541
6627
  "ACCESSIBLE",
6542
6628
  "ADD",
@@ -6753,7 +6839,7 @@ const _A = [
6753
6839
  "XOR",
6754
6840
  "YEAR_MONTH",
6755
6841
  "ZEROFILL"
6756
- ], rA = [
6842
+ ], nA = [
6757
6843
  // https://mariadb.com/kb/en/data-types/
6758
6844
  "BIGINT",
6759
6845
  "BINARY",
@@ -6804,7 +6890,7 @@ const _A = [
6804
6890
  "YEAR"
6805
6891
  // 'NUMBER', // ?? In oracle mode only
6806
6892
  // 'SET' // handled as special-case in postProcess
6807
- ], nA = [
6893
+ ], DA = [
6808
6894
  // https://mariadb.com/kb/en/information-schema-sql_functions-table/
6809
6895
  "ADDDATE",
6810
6896
  "ADD_MONTHS",
@@ -7042,7 +7128,7 @@ const _A = [
7042
7128
  // CASE expression shorthands
7043
7129
  "COALESCE",
7044
7130
  "NULLIF"
7045
- ], DA = t(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), iA = t([
7131
+ ], iA = C(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), PA = C([
7046
7132
  // queries
7047
7133
  "WITH [RECURSIVE]",
7048
7134
  "FROM",
@@ -7064,9 +7150,9 @@ const _A = [
7064
7150
  "SET",
7065
7151
  // other
7066
7152
  "RETURNING"
7067
- ]), jE = t([
7153
+ ]), kE = C([
7068
7154
  "CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]"
7069
- ]), _E = t([
7155
+ ]), _E = C([
7070
7156
  // - create:
7071
7157
  "CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]",
7072
7158
  // - update:
@@ -7273,12 +7359,12 @@ const _A = [
7273
7359
  "XA RECOVER",
7274
7360
  "XA ROLLBACK",
7275
7361
  "XA START"
7276
- ]), PA = t([
7362
+ ]), oA = C([
7277
7363
  "UNION [ALL | DISTINCT]",
7278
7364
  "EXCEPT [ALL | DISTINCT]",
7279
7365
  "INTERSECT [ALL | DISTINCT]",
7280
7366
  "MINUS [ALL | DISTINCT]"
7281
- ]), aA = t([
7367
+ ]), aA = C([
7282
7368
  "JOIN",
7283
7369
  "{LEFT | RIGHT} [OUTER] JOIN",
7284
7370
  "{INNER | CROSS} JOIN",
@@ -7286,24 +7372,24 @@ const _A = [
7286
7372
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
7287
7373
  // non-standard joins
7288
7374
  "STRAIGHT_JOIN"
7289
- ]), oA = t([
7375
+ ]), MA = C([
7290
7376
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
7291
7377
  "CHARACTER SET",
7292
7378
  "{ROWS | RANGE} BETWEEN",
7293
7379
  "IDENTIFIED BY"
7294
- ]), MA = t([]), UA = {
7380
+ ]), UA = C([]), GA = {
7295
7381
  name: "mariadb",
7296
7382
  tokenizerOptions: {
7297
- reservedSelect: DA,
7298
- reservedClauses: [...iA, ...jE, ..._E],
7299
- reservedSetOperations: PA,
7383
+ reservedSelect: iA,
7384
+ reservedClauses: [...PA, ...kE, ..._E],
7385
+ reservedSetOperations: oA,
7300
7386
  reservedJoins: aA,
7301
- reservedKeywordPhrases: oA,
7302
- reservedDataTypePhrases: MA,
7387
+ reservedKeywordPhrases: MA,
7388
+ reservedDataTypePhrases: UA,
7303
7389
  supportsXor: !0,
7304
- reservedKeywords: _A,
7305
- reservedDataTypes: rA,
7306
- reservedFunctionNames: nA,
7390
+ reservedKeywords: rA,
7391
+ reservedDataTypes: nA,
7392
+ reservedFunctionNames: DA,
7307
7393
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
7308
7394
  stringTypes: [
7309
7395
  '""-qq-bs',
@@ -7339,10 +7425,10 @@ const _A = [
7339
7425
  postProcess: EE
7340
7426
  },
7341
7427
  formatOptions: {
7342
- onelineClauses: [...jE, ..._E],
7428
+ onelineClauses: [...kE, ..._E],
7343
7429
  tabularOnelineClauses: _E
7344
7430
  }
7345
- }, GA = [
7431
+ }, cA = [
7346
7432
  // https://dev.mysql.com/doc/refman/8.0/en/keywords.html
7347
7433
  "ACCESSIBLE",
7348
7434
  "ADD",
@@ -7573,7 +7659,7 @@ const _A = [
7573
7659
  "YEAR_MONTH",
7574
7660
  "ZEROFILL"
7575
7661
  // (R)
7576
- ], cA = [
7662
+ ], lA = [
7577
7663
  // https://dev.mysql.com/doc/refman/8.0/en/data-types.html
7578
7664
  "BIGINT",
7579
7665
  "BINARY",
@@ -7625,7 +7711,7 @@ const _A = [
7625
7711
  "VARYING",
7626
7712
  "YEAR"
7627
7713
  // 'SET' // handled as special-case in postProcess
7628
- ], lA = [
7714
+ ], HA = [
7629
7715
  // https://dev.mysql.com/doc/refman/8.0/en/built-in-function-reference.html
7630
7716
  "ABS",
7631
7717
  "ACOS",
@@ -8048,7 +8134,7 @@ const _A = [
8048
8134
  // 'XOR',
8049
8135
  "YEAR",
8050
8136
  "YEARWEEK"
8051
- ], HA = t(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), uA = t([
8137
+ ], uA = C(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), BA = C([
8052
8138
  // queries
8053
8139
  "WITH [RECURSIVE]",
8054
8140
  "FROM",
@@ -8068,7 +8154,7 @@ const _A = [
8068
8154
  "ON DUPLICATE KEY UPDATE",
8069
8155
  // - update:
8070
8156
  "SET"
8071
- ]), zE = t(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), rE = t([
8157
+ ]), zE = C(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), rE = C([
8072
8158
  // - create:
8073
8159
  "CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]",
8074
8160
  // - update:
@@ -8249,7 +8335,7 @@ const _A = [
8249
8335
  "REPEAT",
8250
8336
  "RETURN",
8251
8337
  "WHILE"
8252
- ]), BA = t(["UNION [ALL | DISTINCT]"]), FA = t([
8338
+ ]), FA = C(["UNION [ALL | DISTINCT]"]), YA = C([
8253
8339
  "JOIN",
8254
8340
  "{LEFT | RIGHT} [OUTER] JOIN",
8255
8341
  "{INNER | CROSS} JOIN",
@@ -8257,24 +8343,24 @@ const _A = [
8257
8343
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
8258
8344
  // non-standard joins
8259
8345
  "STRAIGHT_JOIN"
8260
- ]), YA = t([
8346
+ ]), mA = C([
8261
8347
  "ON {UPDATE | DELETE} [SET NULL]",
8262
8348
  "CHARACTER SET",
8263
8349
  "{ROWS | RANGE} BETWEEN",
8264
8350
  "IDENTIFIED BY"
8265
- ]), mA = t([]), pA = {
8351
+ ]), pA = C([]), dA = {
8266
8352
  name: "mysql",
8267
8353
  tokenizerOptions: {
8268
- reservedSelect: HA,
8269
- reservedClauses: [...uA, ...zE, ...rE],
8270
- reservedSetOperations: BA,
8271
- reservedJoins: FA,
8272
- reservedKeywordPhrases: YA,
8273
- reservedDataTypePhrases: mA,
8354
+ reservedSelect: uA,
8355
+ reservedClauses: [...BA, ...zE, ...rE],
8356
+ reservedSetOperations: FA,
8357
+ reservedJoins: YA,
8358
+ reservedKeywordPhrases: mA,
8359
+ reservedDataTypePhrases: pA,
8274
8360
  supportsXor: !0,
8275
- reservedKeywords: GA,
8276
- reservedDataTypes: cA,
8277
- reservedFunctionNames: lA,
8361
+ reservedKeywords: cA,
8362
+ reservedDataTypes: lA,
8363
+ reservedFunctionNames: HA,
8278
8364
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
8279
8365
  stringTypes: [
8280
8366
  '""-qq-bs',
@@ -8315,7 +8401,7 @@ const _A = [
8315
8401
  onelineClauses: [...zE, ...rE],
8316
8402
  tabularOnelineClauses: rE
8317
8403
  }
8318
- }, dA = [
8404
+ }, hA = [
8319
8405
  // https://docs.pingcap.com/tidb/stable/keywords
8320
8406
  "ADD",
8321
8407
  "ALL",
@@ -8554,7 +8640,7 @@ const _A = [
8554
8640
  "VARYING",
8555
8641
  "YEAR"
8556
8642
  // 'SET' // handled as special-case in postProcess
8557
- ], hA = [
8643
+ ], fA = [
8558
8644
  // https://docs.pingcap.com/tidb/stable/sql-statement-show-builtins
8559
8645
  // https://docs.pingcap.com/tidb/stable/functions-and-operators-overview
8560
8646
  // + MySQL aggregate functions: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html
@@ -8880,7 +8966,7 @@ const _A = [
8880
8966
  // 'XOR',
8881
8967
  "YEAR",
8882
8968
  "YEARWEEK"
8883
- ], WA = t(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), fA = t([
8969
+ ], WA = C(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), XA = C([
8884
8970
  // queries
8885
8971
  "WITH [RECURSIVE]",
8886
8972
  "FROM",
@@ -8900,7 +8986,7 @@ const _A = [
8900
8986
  "ON DUPLICATE KEY UPDATE",
8901
8987
  // - update:
8902
8988
  "SET"
8903
- ]), ET = t(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), nE = t([
8989
+ ]), ET = C(["CREATE [TEMPORARY] TABLE [IF NOT EXISTS]"]), nE = C([
8904
8990
  // https://docs.pingcap.com/tidb/stable/sql-statement-create-view
8905
8991
  "CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]",
8906
8992
  // https://docs.pingcap.com/tidb/stable/sql-statement-update
@@ -9015,7 +9101,7 @@ const _A = [
9015
9101
  "UNLOCK TABLES",
9016
9102
  // https://docs.pingcap.com/tidb/stable/sql-statement-use
9017
9103
  "USE"
9018
- ]), XA = t(["UNION [ALL | DISTINCT]"]), bA = t([
9104
+ ]), bA = C(["UNION [ALL | DISTINCT]"]), yA = C([
9019
9105
  "JOIN",
9020
9106
  "{LEFT | RIGHT} [OUTER] JOIN",
9021
9107
  "{INNER | CROSS} JOIN",
@@ -9023,24 +9109,24 @@ const _A = [
9023
9109
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
9024
9110
  // non-standard joins
9025
9111
  "STRAIGHT_JOIN"
9026
- ]), KA = t([
9112
+ ]), KA = C([
9027
9113
  "ON {UPDATE | DELETE} [SET NULL]",
9028
9114
  "CHARACTER SET",
9029
9115
  "{ROWS | RANGE} BETWEEN",
9030
9116
  "IDENTIFIED BY"
9031
- ]), yA = t([]), $A = {
9117
+ ]), $A = C([]), gA = {
9032
9118
  name: "tidb",
9033
9119
  tokenizerOptions: {
9034
9120
  reservedSelect: WA,
9035
- reservedClauses: [...fA, ...ET, ...nE],
9036
- reservedSetOperations: XA,
9037
- reservedJoins: bA,
9121
+ reservedClauses: [...XA, ...ET, ...nE],
9122
+ reservedSetOperations: bA,
9123
+ reservedJoins: yA,
9038
9124
  reservedKeywordPhrases: KA,
9039
- reservedDataTypePhrases: yA,
9125
+ reservedDataTypePhrases: $A,
9040
9126
  supportsXor: !0,
9041
- reservedKeywords: dA,
9127
+ reservedKeywords: hA,
9042
9128
  reservedDataTypes: VA,
9043
- reservedFunctionNames: hA,
9129
+ reservedFunctionNames: fA,
9044
9130
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
9045
9131
  stringTypes: [
9046
9132
  '""-qq-bs',
@@ -9081,7 +9167,7 @@ const _A = [
9081
9167
  onelineClauses: [...ET, ...nE],
9082
9168
  tabularOnelineClauses: nE
9083
9169
  }
9084
- }, gA = [
9170
+ }, JA = [
9085
9171
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/functions.html
9086
9172
  "ABORT",
9087
9173
  "ABS",
@@ -9311,7 +9397,7 @@ const _A = [
9311
9397
  // not implemented in N1QL, but added here now for the sake of tests
9312
9398
  // https://docs.couchbase.com/server/current/analytics/3_query.html#Vs_SQL-92
9313
9399
  "CAST"
9314
- ], JA = [
9400
+ ], wA = [
9315
9401
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/reservedwords.html
9316
9402
  "ADVISE",
9317
9403
  "ALL",
@@ -9517,7 +9603,7 @@ const _A = [
9517
9603
  "WITHIN",
9518
9604
  "WORK",
9519
9605
  "XOR"
9520
- ], wA = [
9606
+ ], xA = [
9521
9607
  // N1QL does not support any way of declaring types for columns.
9522
9608
  // It does not support the CREATE TABLE statement nor the CAST() expression.
9523
9609
  //
@@ -9526,7 +9612,7 @@ const _A = [
9526
9612
  // which it actually doesn't use.
9527
9613
  //
9528
9614
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datatypes.html
9529
- ], xA = t(["SELECT [ALL | DISTINCT]"]), vA = t([
9615
+ ], vA = C(["SELECT [ALL | DISTINCT]"]), QA = C([
9530
9616
  // queries
9531
9617
  "WITH",
9532
9618
  "FROM",
@@ -9553,7 +9639,7 @@ const _A = [
9553
9639
  "NEST",
9554
9640
  "UNNEST",
9555
9641
  "RETURNING"
9556
- ]), TT = t([
9642
+ ]), TT = C([
9557
9643
  // - update:
9558
9644
  "UPDATE",
9559
9645
  // - delete:
@@ -9593,19 +9679,19 @@ const _A = [
9593
9679
  "SET CURRENT SCHEMA",
9594
9680
  "SHOW",
9595
9681
  "USE [PRIMARY] KEYS"
9596
- ]), QA = t(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), ZA = t(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), qA = t(["{ROWS | RANGE | GROUPS} BETWEEN"]), kA = t([]), jA = {
9682
+ ]), ZA = C(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), qA = C(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), jA = C(["{ROWS | RANGE | GROUPS} BETWEEN"]), kA = C([]), zA = {
9597
9683
  name: "n1ql",
9598
9684
  tokenizerOptions: {
9599
- reservedSelect: xA,
9600
- reservedClauses: [...vA, ...TT],
9601
- reservedSetOperations: QA,
9602
- reservedJoins: ZA,
9603
- reservedKeywordPhrases: qA,
9685
+ reservedSelect: vA,
9686
+ reservedClauses: [...QA, ...TT],
9687
+ reservedSetOperations: ZA,
9688
+ reservedJoins: qA,
9689
+ reservedKeywordPhrases: jA,
9604
9690
  reservedDataTypePhrases: kA,
9605
9691
  supportsXor: !0,
9606
- reservedKeywords: JA,
9607
- reservedDataTypes: wA,
9608
- reservedFunctionNames: gA,
9692
+ reservedKeywords: wA,
9693
+ reservedDataTypes: xA,
9694
+ reservedFunctionNames: JA,
9609
9695
  // NOTE: single quotes are actually not supported in N1QL,
9610
9696
  // but we support them anyway as all other SQL dialects do,
9611
9697
  // which simplifies writing tests that are shared between all dialects.
@@ -9619,7 +9705,7 @@ const _A = [
9619
9705
  formatOptions: {
9620
9706
  onelineClauses: TT
9621
9707
  }
9622
- }, zA = [
9708
+ }, ES = [
9623
9709
  // https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/reservewords.htm
9624
9710
  // 'A',
9625
9711
  "ADD",
@@ -9924,7 +10010,7 @@ const _A = [
9924
10010
  "WRITE",
9925
10011
  "YEAR",
9926
10012
  "ZONE"
9927
- ], ES = [
10013
+ ], TS = [
9928
10014
  // https://www.ibm.com/docs/en/db2/10.5?topic=plsql-data-types
9929
10015
  "ARRAY",
9930
10016
  "BFILE_BASE",
@@ -9962,7 +10048,7 @@ const _A = [
9962
10048
  "UROWID",
9963
10049
  "VARCHAR",
9964
10050
  "VARCHAR2"
9965
- ], TS = [
10051
+ ], RS = [
9966
10052
  // https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
9967
10053
  // numeric
9968
10054
  "ABS",
@@ -10227,7 +10313,7 @@ const _A = [
10227
10313
  "PRESENTNNV",
10228
10314
  "PRESENTV",
10229
10315
  "PREVIOUS"
10230
- ], RS = t(["SELECT [ALL | DISTINCT | UNIQUE]"]), AS = t([
10316
+ ], AS = C(["SELECT [ALL | DISTINCT | UNIQUE]"]), SS = C([
10231
10317
  // queries
10232
10318
  "WITH",
10233
10319
  "FROM",
@@ -10251,9 +10337,9 @@ const _A = [
10251
10337
  "UPDATE SET",
10252
10338
  // other
10253
10339
  "RETURNING"
10254
- ]), RT = t([
10340
+ ]), RT = C([
10255
10341
  "CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE"
10256
- ]), DE = t([
10342
+ ]), DE = C([
10257
10343
  // - create:
10258
10344
  "CREATE [OR REPLACE] [NO FORCE | FORCE] [EDITIONING | EDITIONABLE | EDITIONABLE EDITIONING | NONEDITIONABLE] VIEW",
10259
10345
  "CREATE MATERIALIZED VIEW",
@@ -10281,7 +10367,7 @@ const _A = [
10281
10367
  "EXCEPTION",
10282
10368
  "LOOP",
10283
10369
  "START WITH"
10284
- ]), SS = t(["UNION [ALL]", "MINUS", "INTERSECT"]), eS = t([
10370
+ ]), eS = C(["UNION [ALL]", "MINUS", "INTERSECT"]), IS = C([
10285
10371
  "JOIN",
10286
10372
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
10287
10373
  "{INNER | CROSS} JOIN",
@@ -10289,23 +10375,23 @@ const _A = [
10289
10375
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN",
10290
10376
  // non-standard joins
10291
10377
  "{CROSS | OUTER} APPLY"
10292
- ]), IS = t([
10378
+ ]), OS = C([
10293
10379
  "ON {UPDATE | DELETE} [SET NULL]",
10294
10380
  "ON COMMIT",
10295
10381
  "{ROWS | RANGE} BETWEEN"
10296
- ]), OS = t([]), NS = {
10382
+ ]), NS = C([]), sS = {
10297
10383
  name: "plsql",
10298
10384
  tokenizerOptions: {
10299
- reservedSelect: RS,
10300
- reservedClauses: [...AS, ...RT, ...DE],
10301
- reservedSetOperations: SS,
10302
- reservedJoins: eS,
10303
- reservedKeywordPhrases: IS,
10304
- reservedDataTypePhrases: OS,
10385
+ reservedSelect: AS,
10386
+ reservedClauses: [...SS, ...RT, ...DE],
10387
+ reservedSetOperations: eS,
10388
+ reservedJoins: IS,
10389
+ reservedKeywordPhrases: OS,
10390
+ reservedDataTypePhrases: NS,
10305
10391
  supportsXor: !0,
10306
- reservedKeywords: zA,
10307
- reservedDataTypes: ES,
10308
- reservedFunctionNames: TS,
10392
+ reservedKeywords: ES,
10393
+ reservedDataTypes: TS,
10394
+ reservedFunctionNames: RS,
10309
10395
  stringTypes: [
10310
10396
  { quote: "''-qq", prefixes: ["N"] },
10311
10397
  { quote: "q''", prefixes: ["N"] }
@@ -10330,7 +10416,7 @@ const _A = [
10330
10416
  "@",
10331
10417
  "||"
10332
10418
  ],
10333
- postProcess: sS
10419
+ postProcess: tS
10334
10420
  },
10335
10421
  formatOptions: {
10336
10422
  alwaysDenseOperators: ["@"],
@@ -10338,11 +10424,11 @@ const _A = [
10338
10424
  tabularOnelineClauses: DE
10339
10425
  }
10340
10426
  };
10341
- function sS(T) {
10342
- let E = w;
10343
- return T.map((R) => X.SET(R) && X.BY(E) ? Object.assign(Object.assign({}, R), { type: i.RESERVED_KEYWORD }) : (uT(R.type) && (E = R), R));
10427
+ function tS(T) {
10428
+ let E = x;
10429
+ return T.map((R) => X.SET(R) && X.BY(E) ? Object.assign(Object.assign({}, R), { type: i.RESERVED_KEYWORD }) : (BT(R.type) && (E = R), R));
10344
10430
  }
10345
- const tS = [
10431
+ const CS = [
10346
10432
  // https://www.postgresql.org/docs/14/functions.html
10347
10433
  //
10348
10434
  // https://www.postgresql.org/docs/14/functions-math.html
@@ -11026,7 +11112,7 @@ const tS = [
11026
11112
  "PG_MCV_LIST_ITEMS",
11027
11113
  // cast
11028
11114
  "CAST"
11029
- ], CS = [
11115
+ ], LS = [
11030
11116
  // https://www.postgresql.org/docs/14/sql-keywords-appendix.html
11031
11117
  "ALL",
11032
11118
  "ANALYSE",
@@ -11145,7 +11231,7 @@ const tS = [
11145
11231
  "WITHOUT",
11146
11232
  "YEAR"
11147
11233
  // requires AS
11148
- ], LS = [
11234
+ ], _S = [
11149
11235
  // https://www.postgresql.org/docs/current/datatype.html
11150
11236
  "ARRAY",
11151
11237
  "BIGINT",
@@ -11179,7 +11265,7 @@ const tS = [
11179
11265
  "VARCHAR",
11180
11266
  "XML",
11181
11267
  "ZONE"
11182
- ], _S = t(["SELECT [ALL | DISTINCT]"]), rS = t([
11268
+ ], rS = C(["SELECT [ALL | DISTINCT]"]), nS = C([
11183
11269
  // queries
11184
11270
  "WITH [RECURSIVE]",
11185
11271
  "FROM",
@@ -11202,9 +11288,9 @@ const tS = [
11202
11288
  "SET",
11203
11289
  // other
11204
11290
  "RETURNING"
11205
- ]), AT = t([
11291
+ ]), AT = C([
11206
11292
  "CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]"
11207
- ]), iE = t([
11293
+ ]), iE = C([
11208
11294
  // - create
11209
11295
  "CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW",
11210
11296
  "CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]",
@@ -11402,17 +11488,17 @@ const tS = [
11402
11488
  "START TRANSACTION",
11403
11489
  "UNLISTEN",
11404
11490
  "VACUUM"
11405
- ]), nS = t([
11491
+ ]), DS = C([
11406
11492
  "UNION [ALL | DISTINCT]",
11407
11493
  "EXCEPT [ALL | DISTINCT]",
11408
11494
  "INTERSECT [ALL | DISTINCT]"
11409
- ]), DS = t([
11495
+ ]), iS = C([
11410
11496
  "JOIN",
11411
11497
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
11412
11498
  "{INNER | CROSS} JOIN",
11413
11499
  "NATURAL [INNER] JOIN",
11414
11500
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
11415
- ]), iS = t([
11501
+ ]), PS = C([
11416
11502
  "PRIMARY KEY",
11417
11503
  "GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY",
11418
11504
  "ON {UPDATE | DELETE} [NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT]",
@@ -11423,21 +11509,21 @@ const tS = [
11423
11509
  "IS [NOT] DISTINCT FROM",
11424
11510
  "NULLS {FIRST | LAST}",
11425
11511
  "WITH ORDINALITY"
11426
- ]), PS = t([
11512
+ ]), oS = C([
11427
11513
  // https://www.postgresql.org/docs/current/datatype-datetime.html
11428
11514
  "[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE"
11429
11515
  ]), aS = {
11430
11516
  name: "postgresql",
11431
11517
  tokenizerOptions: {
11432
- reservedSelect: _S,
11433
- reservedClauses: [...rS, ...AT, ...iE],
11434
- reservedSetOperations: nS,
11435
- reservedJoins: DS,
11436
- reservedKeywordPhrases: iS,
11437
- reservedDataTypePhrases: PS,
11438
- reservedKeywords: CS,
11439
- reservedDataTypes: LS,
11440
- reservedFunctionNames: tS,
11518
+ reservedSelect: rS,
11519
+ reservedClauses: [...nS, ...AT, ...iE],
11520
+ reservedSetOperations: DS,
11521
+ reservedJoins: iS,
11522
+ reservedKeywordPhrases: PS,
11523
+ reservedDataTypePhrases: oS,
11524
+ reservedKeywords: LS,
11525
+ reservedDataTypes: _S,
11526
+ reservedFunctionNames: CS,
11441
11527
  nestedBlockComments: !0,
11442
11528
  extraParens: ["[]"],
11443
11529
  underscoresInNumbers: !0,
@@ -11552,7 +11638,7 @@ const tS = [
11552
11638
  onelineClauses: [...AT, ...iE],
11553
11639
  tabularOnelineClauses: iE
11554
11640
  }
11555
- }, oS = [
11641
+ }, MS = [
11556
11642
  // https://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html
11557
11643
  "ANY_VALUE",
11558
11644
  "APPROXIMATE PERCENTILE_DISC",
@@ -11898,7 +11984,7 @@ const tS = [
11898
11984
  "SLICE_NUM",
11899
11985
  "USER",
11900
11986
  "VERSION"
11901
- ], MS = [
11987
+ ], US = [
11902
11988
  // https://docs.aws.amazon.com/redshift/latest/dg/r_pg_keywords.html
11903
11989
  "AES128",
11904
11990
  "AES256",
@@ -12087,7 +12173,7 @@ const tS = [
12087
12173
  * SVL: https://docs.aws.amazon.com/redshift/latest/dg/svl_views.html
12088
12174
  * SVV: https://docs.aws.amazon.com/redshift/latest/dg/svv_views.html
12089
12175
  */
12090
- ], US = [
12176
+ ], GS = [
12091
12177
  // https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-text-and-bpchar-types
12092
12178
  "ARRAY",
12093
12179
  "BIGINT",
@@ -12108,7 +12194,7 @@ const tS = [
12108
12194
  "TEXT",
12109
12195
  "VARBYTE",
12110
12196
  "VARCHAR"
12111
- ], GS = t(["SELECT [ALL | DISTINCT]"]), cS = t([
12197
+ ], cS = C(["SELECT [ALL | DISTINCT]"]), lS = C([
12112
12198
  // queries
12113
12199
  "WITH [RECURSIVE]",
12114
12200
  "FROM",
@@ -12126,9 +12212,9 @@ const tS = [
12126
12212
  "VALUES",
12127
12213
  // - update:
12128
12214
  "SET"
12129
- ]), ST = t([
12215
+ ]), ST = C([
12130
12216
  "CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]"
12131
- ]), PE = t([
12217
+ ]), PE = C([
12132
12218
  // - create:
12133
12219
  "CREATE [OR REPLACE | MATERIALIZED] VIEW",
12134
12220
  // - update:
@@ -12219,13 +12305,13 @@ const tS = [
12219
12305
  "START TRANSACTION",
12220
12306
  "UNLOAD",
12221
12307
  "VACUUM"
12222
- ]), lS = t(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), HS = t([
12308
+ ]), HS = C(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), uS = C([
12223
12309
  "JOIN",
12224
12310
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
12225
12311
  "{INNER | CROSS} JOIN",
12226
12312
  "NATURAL [INNER] JOIN",
12227
12313
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
12228
- ]), uS = t([
12314
+ ]), BS = C([
12229
12315
  // https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html
12230
12316
  "NULL AS",
12231
12317
  // https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_SCHEMA.html
@@ -12233,18 +12319,18 @@ const tS = [
12233
12319
  "HIVE METASTORE",
12234
12320
  // in window specifications
12235
12321
  "{ROWS | RANGE} BETWEEN"
12236
- ]), BS = t([]), FS = {
12322
+ ]), FS = C([]), YS = {
12237
12323
  name: "redshift",
12238
12324
  tokenizerOptions: {
12239
- reservedSelect: GS,
12240
- reservedClauses: [...cS, ...ST, ...PE],
12241
- reservedSetOperations: lS,
12242
- reservedJoins: HS,
12243
- reservedKeywordPhrases: uS,
12244
- reservedDataTypePhrases: BS,
12245
- reservedKeywords: MS,
12246
- reservedDataTypes: US,
12247
- reservedFunctionNames: oS,
12325
+ reservedSelect: cS,
12326
+ reservedClauses: [...lS, ...ST, ...PE],
12327
+ reservedSetOperations: HS,
12328
+ reservedJoins: uS,
12329
+ reservedKeywordPhrases: BS,
12330
+ reservedDataTypePhrases: FS,
12331
+ reservedKeywords: US,
12332
+ reservedDataTypes: GS,
12333
+ reservedFunctionNames: MS,
12248
12334
  extraParens: ["[]"],
12249
12335
  stringTypes: ["''-qq"],
12250
12336
  identTypes: ['""-qq'],
@@ -12271,7 +12357,7 @@ const tS = [
12271
12357
  onelineClauses: [...ST, ...PE],
12272
12358
  tabularOnelineClauses: PE
12273
12359
  }
12274
- }, YS = [
12360
+ }, mS = [
12275
12361
  // https://deepkb.com/CO_000013/en/kb/IMPORT-fbfa59f0-2bf1-31fe-bb7b-0f9efe9932c6/spark-sql-keywords
12276
12362
  "ADD",
12277
12363
  "AFTER",
@@ -12538,7 +12624,7 @@ const tS = [
12538
12624
  "UNSIGNED",
12539
12625
  "VARIABLES",
12540
12626
  "YEAR_MONTH"
12541
- ], mS = [
12627
+ ], pS = [
12542
12628
  // https://spark.apache.org/docs/latest/sql-ref-datatypes.html
12543
12629
  "ARRAY",
12544
12630
  "BIGINT",
@@ -12568,7 +12654,7 @@ const tS = [
12568
12654
  "TINYINT",
12569
12655
  "VARCHAR"
12570
12656
  // No varchar type in Spark, only STRING. Added for the sake of tests
12571
- ], pS = [
12657
+ ], dS = [
12572
12658
  // http://spark.apache.org/docs/latest/sql-ref-functions.html
12573
12659
  //
12574
12660
  // http://spark.apache.org/docs/latest/sql-ref-functions-builtin.html#aggregate-functions
@@ -12889,7 +12975,7 @@ const tS = [
12889
12975
  // Shorthand functions to use in place of CASE expression
12890
12976
  "COALESCE",
12891
12977
  "NULLIF"
12892
- ], dS = t(["SELECT [ALL | DISTINCT]"]), VS = t([
12978
+ ], hS = C(["SELECT [ALL | DISTINCT]"]), VS = C([
12893
12979
  // queries
12894
12980
  "WITH",
12895
12981
  "FROM",
@@ -12914,7 +13000,7 @@ const tS = [
12914
13000
  // https://spark.apache.org/docs/latest/sql-ref-syntax-dml-load.html
12915
13001
  "LOAD DATA [LOCAL] INPATH",
12916
13002
  "[OVERWRITE] INTO TABLE"
12917
- ]), eT = t(["CREATE [EXTERNAL] TABLE [IF NOT EXISTS]"]), aE = t([
13003
+ ]), eT = C(["CREATE [EXTERNAL] TABLE [IF NOT EXISTS]"]), oE = C([
12918
13004
  // - create:
12919
13005
  "CREATE [OR REPLACE] [GLOBAL TEMPORARY | TEMPORARY] VIEW [IF NOT EXISTS]",
12920
13006
  // - drop table:
@@ -12970,11 +13056,11 @@ const tS = [
12970
13056
  "SHOW TBLPROPERTIES",
12971
13057
  "SHOW VIEWS",
12972
13058
  "UNCACHE TABLE"
12973
- ]), hS = t([
13059
+ ]), fS = C([
12974
13060
  "UNION [ALL | DISTINCT]",
12975
13061
  "EXCEPT [ALL | DISTINCT]",
12976
13062
  "INTERSECT [ALL | DISTINCT]"
12977
- ]), WS = t([
13063
+ ]), WS = C([
12978
13064
  "JOIN",
12979
13065
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
12980
13066
  "{INNER | CROSS} JOIN",
@@ -12983,24 +13069,24 @@ const tS = [
12983
13069
  // non-standard-joins
12984
13070
  "[LEFT] {ANTI | SEMI} JOIN",
12985
13071
  "NATURAL [LEFT] {ANTI | SEMI} JOIN"
12986
- ]), fS = t([
13072
+ ]), XS = C([
12987
13073
  "ON DELETE",
12988
13074
  "ON UPDATE",
12989
13075
  "CURRENT ROW",
12990
13076
  "{ROWS | RANGE} BETWEEN"
12991
- ]), XS = t([]), bS = {
13077
+ ]), bS = C([]), yS = {
12992
13078
  name: "spark",
12993
13079
  tokenizerOptions: {
12994
- reservedSelect: dS,
12995
- reservedClauses: [...VS, ...eT, ...aE],
12996
- reservedSetOperations: hS,
13080
+ reservedSelect: hS,
13081
+ reservedClauses: [...VS, ...eT, ...oE],
13082
+ reservedSetOperations: fS,
12997
13083
  reservedJoins: WS,
12998
- reservedKeywordPhrases: fS,
12999
- reservedDataTypePhrases: XS,
13084
+ reservedKeywordPhrases: XS,
13085
+ reservedDataTypePhrases: bS,
13000
13086
  supportsXor: !0,
13001
- reservedKeywords: YS,
13002
- reservedDataTypes: mS,
13003
- reservedFunctionNames: pS,
13087
+ reservedKeywords: mS,
13088
+ reservedDataTypes: pS,
13089
+ reservedFunctionNames: dS,
13004
13090
  extraParens: ["[]"],
13005
13091
  stringTypes: [
13006
13092
  "''-bs",
@@ -13015,17 +13101,17 @@ const tS = [
13015
13101
  postProcess: KS
13016
13102
  },
13017
13103
  formatOptions: {
13018
- onelineClauses: [...eT, ...aE],
13019
- tabularOnelineClauses: aE
13104
+ onelineClauses: [...eT, ...oE],
13105
+ tabularOnelineClauses: oE
13020
13106
  }
13021
13107
  };
13022
13108
  function KS(T) {
13023
13109
  return T.map((E, R) => {
13024
- const A = T[R - 1] || w, S = T[R + 1] || w;
13110
+ const A = T[R - 1] || x, S = T[R + 1] || x;
13025
13111
  return X.WINDOW(E) && S.type === i.OPEN_PAREN ? Object.assign(Object.assign({}, E), { type: i.RESERVED_FUNCTION_NAME }) : E.text === "ITEMS" && E.type === i.RESERVED_KEYWORD && !(A.text === "COLLECTION" && S.text === "TERMINATED") ? Object.assign(Object.assign({}, E), { type: i.IDENTIFIER, text: E.raw }) : E;
13026
13112
  });
13027
13113
  }
13028
- const yS = [
13114
+ const $S = [
13029
13115
  // https://www.sqlite.org/lang_corefunc.html
13030
13116
  "ABS",
13031
13117
  "CHANGES",
@@ -13149,7 +13235,7 @@ const yS = [
13149
13235
  "JSON_TREE",
13150
13236
  // cast
13151
13237
  "CAST"
13152
- ], $S = [
13238
+ ], gS = [
13153
13239
  // https://www.sqlite.org/lang_keywords.html
13154
13240
  // Note: The keywords listed on that URL are not all reserved keywords.
13155
13241
  // We'll need to clean up this list to only include reserved keywords.
@@ -13302,7 +13388,7 @@ const yS = [
13302
13388
  "WINDOW",
13303
13389
  "WITH",
13304
13390
  "WITHOUT"
13305
- ], gS = [
13391
+ ], JS = [
13306
13392
  // SQLite allows any word as a data type, e.g. CREATE TABLE foo (col1 madeupname(123));
13307
13393
  // Here we just list some common ones as SQL Formatter
13308
13394
  // is only able to detect a predefined list of data types.
@@ -13323,7 +13409,7 @@ const yS = [
13323
13409
  "TEXT",
13324
13410
  "VARCHAR",
13325
13411
  "VARYING CHARACTER"
13326
- ], JS = t(["SELECT [ALL | DISTINCT]"]), wS = t([
13412
+ ], wS = C(["SELECT [ALL | DISTINCT]"]), xS = C([
13327
13413
  // queries
13328
13414
  "WITH [RECURSIVE]",
13329
13415
  "FROM",
@@ -13344,7 +13430,7 @@ const yS = [
13344
13430
  "SET",
13345
13431
  // other:
13346
13432
  "RETURNING"
13347
- ]), IT = t(["CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]"]), oE = t([
13433
+ ]), IT = C(["CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]"]), aE = C([
13348
13434
  // - create:
13349
13435
  "CREATE [TEMPORARY | TEMP] VIEW [IF NOT EXISTS]",
13350
13436
  // - update:
@@ -13363,28 +13449,28 @@ const yS = [
13363
13449
  "RENAME TO",
13364
13450
  // - set schema
13365
13451
  "SET SCHEMA"
13366
- ]), xS = t(["UNION [ALL]", "EXCEPT", "INTERSECT"]), vS = t([
13452
+ ]), vS = C(["UNION [ALL]", "EXCEPT", "INTERSECT"]), QS = C([
13367
13453
  "JOIN",
13368
13454
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13369
13455
  "{INNER | CROSS} JOIN",
13370
13456
  "NATURAL [INNER] JOIN",
13371
13457
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
13372
- ]), QS = t([
13458
+ ]), ZS = C([
13373
13459
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
13374
13460
  "{ROWS | RANGE | GROUPS} BETWEEN",
13375
13461
  "DO UPDATE"
13376
- ]), ZS = t([]), qS = {
13462
+ ]), qS = C([]), jS = {
13377
13463
  name: "sqlite",
13378
13464
  tokenizerOptions: {
13379
- reservedSelect: JS,
13380
- reservedClauses: [...wS, ...IT, ...oE],
13381
- reservedSetOperations: xS,
13382
- reservedJoins: vS,
13383
- reservedKeywordPhrases: QS,
13384
- reservedDataTypePhrases: ZS,
13385
- reservedKeywords: $S,
13386
- reservedDataTypes: gS,
13387
- reservedFunctionNames: yS,
13465
+ reservedSelect: wS,
13466
+ reservedClauses: [...xS, ...IT, ...aE],
13467
+ reservedSetOperations: vS,
13468
+ reservedJoins: QS,
13469
+ reservedKeywordPhrases: ZS,
13470
+ reservedDataTypePhrases: qS,
13471
+ reservedKeywords: gS,
13472
+ reservedDataTypes: JS,
13473
+ reservedFunctionNames: $S,
13388
13474
  stringTypes: [
13389
13475
  "''-qq",
13390
13476
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -13397,8 +13483,8 @@ const yS = [
13397
13483
  operators: ["%", "~", "&", "|", "<<", ">>", "==", "->", "->>", "||"]
13398
13484
  },
13399
13485
  formatOptions: {
13400
- onelineClauses: [...IT, ...oE],
13401
- tabularOnelineClauses: oE
13486
+ onelineClauses: [...IT, ...aE],
13487
+ tabularOnelineClauses: aE
13402
13488
  }
13403
13489
  }, kS = [
13404
13490
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_9_set_function_specification
@@ -13497,7 +13583,7 @@ const yS = [
13497
13583
  "ASIN",
13498
13584
  "ACOS",
13499
13585
  "ATAN"
13500
- ], jS = [
13586
+ ], zS = [
13501
13587
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#reserved-word
13502
13588
  "ALL",
13503
13589
  "ALLOCATE",
@@ -13695,7 +13781,7 @@ const yS = [
13695
13781
  "WITHIN",
13696
13782
  "WITHOUT",
13697
13783
  "YEAR"
13698
- ], zS = [
13784
+ ], Ee = [
13699
13785
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_1_data_type
13700
13786
  "ARRAY",
13701
13787
  "BIGINT",
@@ -13735,7 +13821,7 @@ const yS = [
13735
13821
  "TIMESTAMP",
13736
13822
  "VARBINARY",
13737
13823
  "VARCHAR"
13738
- ], Ee = t(["SELECT [ALL | DISTINCT]"]), Te = t([
13824
+ ], Te = C(["SELECT [ALL | DISTINCT]"]), Re = C([
13739
13825
  // queries
13740
13826
  "WITH [RECURSIVE]",
13741
13827
  "FROM",
@@ -13754,7 +13840,7 @@ const yS = [
13754
13840
  "VALUES",
13755
13841
  // - update:
13756
13842
  "SET"
13757
- ]), OT = t(["CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE"]), ME = t([
13843
+ ]), OT = C(["CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE"]), ME = C([
13758
13844
  // - create:
13759
13845
  "CREATE [RECURSIVE] VIEW",
13760
13846
  // - update:
@@ -13779,30 +13865,30 @@ const yS = [
13779
13865
  "TRUNCATE TABLE",
13780
13866
  // other
13781
13867
  "SET SCHEMA"
13782
- ]), Re = t([
13868
+ ]), Ae = C([
13783
13869
  "UNION [ALL | DISTINCT]",
13784
13870
  "EXCEPT [ALL | DISTINCT]",
13785
13871
  "INTERSECT [ALL | DISTINCT]"
13786
- ]), Ae = t([
13872
+ ]), Se = C([
13787
13873
  "JOIN",
13788
13874
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13789
13875
  "{INNER | CROSS} JOIN",
13790
13876
  "NATURAL [INNER] JOIN",
13791
13877
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
13792
- ]), Se = t([
13878
+ ]), ee = C([
13793
13879
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
13794
13880
  "{ROWS | RANGE} BETWEEN"
13795
- ]), ee = t([]), Ie = {
13881
+ ]), Ie = C([]), Oe = {
13796
13882
  name: "sql",
13797
13883
  tokenizerOptions: {
13798
- reservedSelect: Ee,
13799
- reservedClauses: [...Te, ...OT, ...ME],
13800
- reservedSetOperations: Re,
13801
- reservedJoins: Ae,
13802
- reservedKeywordPhrases: Se,
13803
- reservedDataTypePhrases: ee,
13804
- reservedKeywords: jS,
13805
- reservedDataTypes: zS,
13884
+ reservedSelect: Te,
13885
+ reservedClauses: [...Re, ...OT, ...ME],
13886
+ reservedSetOperations: Ae,
13887
+ reservedJoins: Se,
13888
+ reservedKeywordPhrases: ee,
13889
+ reservedDataTypePhrases: Ie,
13890
+ reservedKeywords: zS,
13891
+ reservedDataTypes: Ee,
13806
13892
  reservedFunctionNames: kS,
13807
13893
  stringTypes: [
13808
13894
  { quote: "''-qq-bs", prefixes: ["N", "U&"] },
@@ -13816,7 +13902,7 @@ const yS = [
13816
13902
  onelineClauses: [...OT, ...ME],
13817
13903
  tabularOnelineClauses: ME
13818
13904
  }
13819
- }, Oe = [
13905
+ }, Ne = [
13820
13906
  // https://github.com/trinodb/trino/tree/432d2897bdef99388c1a47188743a061c4ac1f34/docs/src/main/sphinx/functions
13821
13907
  // rg '^\.\. function::' ./docs/src/main/sphinx/functions | cut -d' ' -f 3 | cut -d '(' -f 1 | sort | uniq
13822
13908
  // rg '\* ' ./docs/src/main/sphinx/functions/list-by-topic.rst | grep '\* :func:' | cut -d'`' -f 2
@@ -14250,7 +14336,7 @@ const yS = [
14250
14336
  "NEXT",
14251
14337
  "PERMUTE",
14252
14338
  "PREV"
14253
- ], Ne = [
14339
+ ], se = [
14254
14340
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4#L858-L1128
14255
14341
  "ABSENT",
14256
14342
  "ADD",
@@ -14487,7 +14573,7 @@ const yS = [
14487
14573
  "WRAPPER",
14488
14574
  "WRITE",
14489
14575
  "ZONE"
14490
- ], se = [
14576
+ ], te = [
14491
14577
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-main/src/main/java/io/trino/metadata/TypeRegistry.java#L131-L168
14492
14578
  // or https://trino.io/docs/current/language/types.html
14493
14579
  "BIGINT",
@@ -14526,7 +14612,7 @@ const yS = [
14526
14612
  "CODEPOINTS",
14527
14613
  "FUNCTION",
14528
14614
  "JSONPATH"
14529
- ], te = t(["SELECT [ALL | DISTINCT]"]), Ce = t([
14615
+ ], Ce = C(["SELECT [ALL | DISTINCT]"]), Le = C([
14530
14616
  // queries
14531
14617
  "WITH [RECURSIVE]",
14532
14618
  "FROM",
@@ -14554,7 +14640,7 @@ const yS = [
14554
14640
  "PATTERN",
14555
14641
  "SUBSET",
14556
14642
  "DEFINE"
14557
- ]), NT = t(["CREATE TABLE [IF NOT EXISTS]"]), UE = t([
14643
+ ]), NT = C(["CREATE TABLE [IF NOT EXISTS]"]), UE = C([
14558
14644
  // - create:
14559
14645
  "CREATE [OR REPLACE] [MATERIALIZED] VIEW",
14560
14646
  // - update:
@@ -14612,32 +14698,32 @@ const yS = [
14612
14698
  "SHOW ROLE GRANTS",
14613
14699
  "SHOW FUNCTIONS",
14614
14700
  "SHOW SESSION"
14615
- ]), Le = t([
14701
+ ]), _e = C([
14616
14702
  "UNION [ALL | DISTINCT]",
14617
14703
  "EXCEPT [ALL | DISTINCT]",
14618
14704
  "INTERSECT [ALL | DISTINCT]"
14619
- ]), _e = t([
14705
+ ]), re = C([
14620
14706
  "JOIN",
14621
14707
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14622
14708
  "{INNER | CROSS} JOIN",
14623
14709
  "NATURAL [INNER] JOIN",
14624
14710
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
14625
- ]), re = t([
14711
+ ]), ne = C([
14626
14712
  "{ROWS | RANGE | GROUPS} BETWEEN",
14627
14713
  // comparison operator
14628
14714
  "IS [NOT] DISTINCT FROM"
14629
- ]), ne = t([]), De = {
14715
+ ]), De = C([]), ie = {
14630
14716
  name: "trino",
14631
14717
  tokenizerOptions: {
14632
- reservedSelect: te,
14633
- reservedClauses: [...Ce, ...NT, ...UE],
14634
- reservedSetOperations: Le,
14635
- reservedJoins: _e,
14636
- reservedKeywordPhrases: re,
14637
- reservedDataTypePhrases: ne,
14638
- reservedKeywords: Ne,
14639
- reservedDataTypes: se,
14640
- reservedFunctionNames: Oe,
14718
+ reservedSelect: Ce,
14719
+ reservedClauses: [...Le, ...NT, ...UE],
14720
+ reservedSetOperations: _e,
14721
+ reservedJoins: re,
14722
+ reservedKeywordPhrases: ne,
14723
+ reservedDataTypePhrases: De,
14724
+ reservedKeywords: se,
14725
+ reservedDataTypes: te,
14726
+ reservedFunctionNames: Ne,
14641
14727
  // Trino also supports {- ... -} parenthesis.
14642
14728
  // The formatting of these currently works out as a result of { and -
14643
14729
  // not getting a space added in-between.
@@ -14669,7 +14755,7 @@ const yS = [
14669
14755
  onelineClauses: [...NT, ...UE],
14670
14756
  tabularOnelineClauses: UE
14671
14757
  }
14672
- }, ie = [
14758
+ }, Pe = [
14673
14759
  // https://docs.microsoft.com/en-us/sql/t-sql/functions/functions?view=sql-server-ver15
14674
14760
  // aggregate
14675
14761
  "APPROX_COUNT_DISTINCT",
@@ -14974,7 +15060,7 @@ const yS = [
14974
15060
  // Shorthand functions to use in place of CASE expression
14975
15061
  "COALESCE",
14976
15062
  "NULLIF"
14977
- ], Pe = [
15063
+ ], oe = [
14978
15064
  // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15
14979
15065
  // standard
14980
15066
  "ADD",
@@ -15182,7 +15268,7 @@ const yS = [
15182
15268
  "TIMESTAMP",
15183
15269
  "VARBINARY",
15184
15270
  "VARCHAR"
15185
- ], oe = t(["SELECT [ALL | DISTINCT]"]), Me = t([
15271
+ ], Me = C(["SELECT [ALL | DISTINCT]"]), Ue = C([
15186
15272
  // queries
15187
15273
  "WITH",
15188
15274
  "INTO",
@@ -15207,7 +15293,7 @@ const yS = [
15207
15293
  "MERGE [INTO]",
15208
15294
  "WHEN [NOT] MATCHED [BY TARGET | BY SOURCE] [THEN]",
15209
15295
  "UPDATE SET"
15210
- ]), sT = t(["CREATE TABLE"]), GE = t([
15296
+ ]), sT = C(["CREATE TABLE"]), GE = C([
15211
15297
  // - create:
15212
15298
  "CREATE [OR ALTER] [MATERIALIZED] VIEW",
15213
15299
  // - update:
@@ -15387,27 +15473,27 @@ const yS = [
15387
15473
  "XACT_ABORT",
15388
15474
  "XML INDEX",
15389
15475
  "XML SCHEMA COLLECTION"
15390
- ]), Ue = t(["UNION [ALL]", "EXCEPT", "INTERSECT"]), Ge = t([
15476
+ ]), Ge = C(["UNION [ALL]", "EXCEPT", "INTERSECT"]), ce = C([
15391
15477
  "JOIN",
15392
15478
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15393
15479
  "{INNER | CROSS} JOIN",
15394
15480
  // non-standard joins
15395
15481
  "{CROSS | OUTER} APPLY"
15396
- ]), ce = t([
15482
+ ]), le = C([
15397
15483
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
15398
15484
  "{ROWS | RANGE} BETWEEN"
15399
- ]), le = t([]), He = {
15485
+ ]), He = C([]), ue = {
15400
15486
  name: "transactsql",
15401
15487
  tokenizerOptions: {
15402
- reservedSelect: oe,
15403
- reservedClauses: [...Me, ...sT, ...GE],
15404
- reservedSetOperations: Ue,
15405
- reservedJoins: Ge,
15406
- reservedKeywordPhrases: ce,
15407
- reservedDataTypePhrases: le,
15408
- reservedKeywords: Pe,
15488
+ reservedSelect: Me,
15489
+ reservedClauses: [...Ue, ...sT, ...GE],
15490
+ reservedSetOperations: Ge,
15491
+ reservedJoins: ce,
15492
+ reservedKeywordPhrases: le,
15493
+ reservedDataTypePhrases: He,
15494
+ reservedKeywords: oe,
15409
15495
  reservedDataTypes: ae,
15410
- reservedFunctionNames: ie,
15496
+ reservedFunctionNames: Pe,
15411
15497
  nestedBlockComments: !0,
15412
15498
  stringTypes: [{ quote: "''-qq", prefixes: ["N"] }, "{}"],
15413
15499
  identTypes: ['""-qq', "[]"],
@@ -15440,7 +15526,7 @@ const yS = [
15440
15526
  onelineClauses: [...sT, ...GE],
15441
15527
  tabularOnelineClauses: GE
15442
15528
  }
15443
- }, ue = [
15529
+ }, Be = [
15444
15530
  // List of all keywords taken from:
15445
15531
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/restricted-keywords/list-of-restricted-keywords.html
15446
15532
  // Then filtered down to reserved keywords by running
@@ -15653,7 +15739,7 @@ const yS = [
15653
15739
  "XOR",
15654
15740
  "YEAR_MONTH",
15655
15741
  "ZEROFILL"
15656
- ], Be = [
15742
+ ], Fe = [
15657
15743
  // https://docs.singlestore.com/cloud/reference/sql-reference/data-types/
15658
15744
  "BIGINT",
15659
15745
  "BINARY",
@@ -15702,7 +15788,7 @@ const yS = [
15702
15788
  "VARCHAR",
15703
15789
  "VARCHARACTER",
15704
15790
  "YEAR"
15705
- ], Fe = [
15791
+ ], Ye = [
15706
15792
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions/vector-functions.html
15707
15793
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/window-functions/window-functions.html
15708
15794
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/string-functions/string-functions.html
@@ -15982,7 +16068,7 @@ const yS = [
15982
16068
  "WEEKDAY",
15983
16069
  "WEEKOFYEAR",
15984
16070
  "YEAR"
15985
- ], Ye = t(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), me = t([
16071
+ ], me = C(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), pe = C([
15986
16072
  // queries
15987
16073
  "WITH",
15988
16074
  "FROM",
@@ -16004,9 +16090,9 @@ const yS = [
16004
16090
  // Data definition
16005
16091
  "CREATE [OR REPLACE] [TEMPORARY] PROCEDURE [IF NOT EXISTS]",
16006
16092
  "CREATE [OR REPLACE] [EXTERNAL] FUNCTION"
16007
- ]), tT = t([
16093
+ ]), tT = C([
16008
16094
  "CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]"
16009
- ]), cE = t([
16095
+ ]), cE = C([
16010
16096
  // - create:
16011
16097
  "CREATE VIEW",
16012
16098
  // - update:
@@ -16183,36 +16269,36 @@ const yS = [
16183
16269
  "REPEAT",
16184
16270
  "RETURN",
16185
16271
  "WHILE"
16186
- ]), pe = t([
16272
+ ]), de = C([
16187
16273
  "UNION [ALL | DISTINCT]",
16188
16274
  "EXCEPT",
16189
16275
  "INTERSECT",
16190
16276
  "MINUS"
16191
- ]), de = t([
16277
+ ]), he = C([
16192
16278
  "JOIN",
16193
16279
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
16194
16280
  "{INNER | CROSS} JOIN",
16195
16281
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
16196
16282
  // non-standard joins
16197
16283
  "STRAIGHT_JOIN"
16198
- ]), Ve = t([
16284
+ ]), Ve = C([
16199
16285
  "ON DELETE",
16200
16286
  "ON UPDATE",
16201
16287
  "CHARACTER SET",
16202
16288
  "{ROWS | RANGE} BETWEEN",
16203
16289
  "IDENTIFIED BY"
16204
- ]), he = t([]), We = {
16290
+ ]), fe = C([]), We = {
16205
16291
  name: "singlestoredb",
16206
16292
  tokenizerOptions: {
16207
- reservedSelect: Ye,
16208
- reservedClauses: [...me, ...tT, ...cE],
16209
- reservedSetOperations: pe,
16210
- reservedJoins: de,
16293
+ reservedSelect: me,
16294
+ reservedClauses: [...pe, ...tT, ...cE],
16295
+ reservedSetOperations: de,
16296
+ reservedJoins: he,
16211
16297
  reservedKeywordPhrases: Ve,
16212
- reservedDataTypePhrases: he,
16213
- reservedKeywords: ue,
16214
- reservedDataTypes: Be,
16215
- reservedFunctionNames: Fe,
16298
+ reservedDataTypePhrases: fe,
16299
+ reservedKeywords: Be,
16300
+ reservedDataTypes: Fe,
16301
+ reservedFunctionNames: Ye,
16216
16302
  // TODO: support _binary"some string" prefix
16217
16303
  stringTypes: [
16218
16304
  '""-qq-bs',
@@ -16252,7 +16338,7 @@ const yS = [
16252
16338
  onelineClauses: [...tT, ...cE],
16253
16339
  tabularOnelineClauses: cE
16254
16340
  }
16255
- }, fe = [
16341
+ }, Xe = [
16256
16342
  // https://docs.snowflake.com/en/sql-reference-functions.html
16257
16343
  //
16258
16344
  // https://docs.snowflake.com/en/sql-reference/functions-all.html
@@ -16860,7 +16946,7 @@ const yS = [
16860
16946
  "QUARTER",
16861
16947
  "ZEROIFNULL",
16862
16948
  "ZIPF"
16863
- ], Xe = [
16949
+ ], be = [
16864
16950
  // https://docs.snowflake.com/en/sql-reference/reserved-keywords.html
16865
16951
  //
16866
16952
  // run in console on this page: $x('//tbody/tr/*[1]/p/text()').map(x => x.nodeValue)
@@ -16957,7 +17043,7 @@ const yS = [
16957
17043
  "WITH",
16958
17044
  // These are definitely keywords, but haven't found a definite list in the docs
16959
17045
  "COMMENT"
16960
- ], be = [
17046
+ ], ye = [
16961
17047
  "NUMBER",
16962
17048
  "DECIMAL",
16963
17049
  "NUMERIC",
@@ -16994,7 +17080,7 @@ const yS = [
16994
17080
  "ARRAY",
16995
17081
  "GEOGRAPHY",
16996
17082
  "GEOMETRY"
16997
- ], Ke = t(["SELECT [ALL | DISTINCT]"]), ye = t([
17083
+ ], Ke = C(["SELECT [ALL | DISTINCT]"]), $e = C([
16998
17084
  // queries
16999
17085
  "WITH [RECURSIVE]",
17000
17086
  "FROM",
@@ -17022,10 +17108,10 @@ const yS = [
17022
17108
  "WHEN MATCHED [AND]",
17023
17109
  "THEN {UPDATE SET | DELETE}",
17024
17110
  "WHEN NOT MATCHED THEN INSERT"
17025
- ]), CT = t([
17111
+ ]), CT = C([
17026
17112
  "CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]",
17027
17113
  "CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]"
17028
- ]), lE = t([
17114
+ ]), lE = C([
17029
17115
  // - create:
17030
17116
  "CREATE [OR REPLACE] [SECURE] [RECURSIVE] VIEW [IF NOT EXISTS]",
17031
17117
  // - update:
@@ -17266,25 +17352,25 @@ const yS = [
17266
17352
  "USE SCHEMA",
17267
17353
  "USE SECONDARY ROLES",
17268
17354
  "USE WAREHOUSE"
17269
- ]), $e = t(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), ge = t([
17355
+ ]), ge = C(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), Je = C([
17270
17356
  "[INNER] JOIN",
17271
17357
  "[NATURAL] {LEFT | RIGHT | FULL} [OUTER] JOIN",
17272
17358
  "{CROSS | NATURAL} JOIN"
17273
- ]), Je = t([
17359
+ ]), we = C([
17274
17360
  "{ROWS | RANGE} BETWEEN",
17275
17361
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]"
17276
- ]), we = t([]), xe = {
17362
+ ]), xe = C([]), ve = {
17277
17363
  name: "snowflake",
17278
17364
  tokenizerOptions: {
17279
17365
  reservedSelect: Ke,
17280
- reservedClauses: [...ye, ...CT, ...lE],
17281
- reservedSetOperations: $e,
17282
- reservedJoins: ge,
17283
- reservedKeywordPhrases: Je,
17284
- reservedDataTypePhrases: we,
17285
- reservedKeywords: Xe,
17286
- reservedDataTypes: be,
17287
- reservedFunctionNames: fe,
17366
+ reservedClauses: [...$e, ...CT, ...lE],
17367
+ reservedSetOperations: ge,
17368
+ reservedJoins: Je,
17369
+ reservedKeywordPhrases: we,
17370
+ reservedDataTypePhrases: xe,
17371
+ reservedKeywords: be,
17372
+ reservedDataTypes: ye,
17373
+ reservedFunctionNames: Xe,
17288
17374
  stringTypes: ["$$", "''-qq-bs"],
17289
17375
  identTypes: ['""-qq'],
17290
17376
  variableTypes: [
@@ -17317,49 +17403,49 @@ const yS = [
17317
17403
  onelineClauses: [...CT, ...lE],
17318
17404
  tabularOnelineClauses: lE
17319
17405
  }
17320
- }, ve = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17406
+ }, Qe = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17321
17407
  __proto__: null,
17322
- bigquery: UR,
17408
+ bigquery: GR,
17323
17409
  db2: WR,
17324
- db2i: xR,
17325
- duckdb: RA,
17326
- hive: LA,
17327
- mariadb: UA,
17328
- mysql: pA,
17329
- n1ql: jA,
17330
- plsql: NS,
17410
+ db2i: vR,
17411
+ duckdb: AA,
17412
+ hive: _A,
17413
+ mariadb: GA,
17414
+ mysql: dA,
17415
+ n1ql: zA,
17416
+ plsql: sS,
17331
17417
  postgresql: aS,
17332
- redshift: FS,
17418
+ redshift: YS,
17333
17419
  singlestoredb: We,
17334
- snowflake: xe,
17335
- spark: bS,
17336
- sql: Ie,
17337
- sqlite: qS,
17338
- tidb: $A,
17339
- transactsql: He,
17340
- trino: De
17341
- }, Symbol.toStringTag, { value: "Module" })), v = (T) => T[T.length - 1], BT = (T) => T.sort((E, R) => R.length - E.length || E.localeCompare(R)), Z = (T) => T.replace(/\s+/gu, " "), HE = (T) => /\n/.test(T), d = (T) => T.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"), LT = /\s+/uy, b = (T) => new RegExp(`(?:${T})`, "uy"), Qe = (T) => T.split("").map((E) => / /gu.test(E) ? "\\s+" : `[${E.toUpperCase()}${E.toLowerCase()}]`).join(""), Ze = (T) => T + "(?:-" + T + ")*", qe = ({ prefixes: T, requirePrefix: E }) => `(?:${T.map(Qe).join("|")}${E ? "" : "|"})`, ke = (T) => new RegExp(`(?:${T.map(d).join("|")}).*?(?=\r
17420
+ snowflake: ve,
17421
+ spark: yS,
17422
+ sql: Oe,
17423
+ sqlite: jS,
17424
+ tidb: gA,
17425
+ transactsql: ue,
17426
+ trino: ie
17427
+ }, Symbol.toStringTag, { value: "Module" })), Q = (T) => T[T.length - 1], FT = (T) => T.sort((E, R) => R.length - E.length || E.localeCompare(R)), q = (T) => T.replace(/\s+/gu, " "), HE = (T) => /\n/.test(T), d = (T) => T.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"), LT = /\s+/uy, b = (T) => new RegExp(`(?:${T})`, "uy"), Ze = (T) => T.split("").map((E) => / /gu.test(E) ? "\\s+" : `[${E.toUpperCase()}${E.toLowerCase()}]`).join(""), qe = (T) => T + "(?:-" + T + ")*", je = ({ prefixes: T, requirePrefix: E }) => `(?:${T.map(Ze).join("|")}${E ? "" : "|"})`, ke = (T) => new RegExp(`(?:${T.map(d).join("|")}).*?(?=\r
17342
17428
  |\r|
17343
17429
  |$)`, "uy"), _T = (T, E = []) => {
17344
17430
  const R = T === "open" ? 0 : 1, A = ["()", ...E].map((S) => S[R]);
17345
17431
  return b(A.map(d).join("|"));
17346
- }, rT = (T) => b(`${BT(T).map(d).join("|")}`), je = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", V = (T, E = {}) => {
17432
+ }, rT = (T) => b(`${FT(T).map(d).join("|")}`), ze = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", h = (T, E = {}) => {
17347
17433
  if (T.length === 0)
17348
17434
  return /^\b$/u;
17349
- const R = je(E), A = BT(T).map(d).join("|").replace(/ /gu, "\\s+");
17435
+ const R = ze(E), A = FT(T).map(d).join("|").replace(/ /gu, "\\s+");
17350
17436
  return new RegExp(`(?:${A})${R}\\b`, "iuy");
17351
17437
  }, uE = (T, E) => {
17352
17438
  if (!T.length)
17353
17439
  return;
17354
17440
  const R = T.map(d).join("|");
17355
17441
  return b(`(?:${R})(?:${E})`);
17356
- }, ze = () => {
17442
+ }, EI = () => {
17357
17443
  const T = {
17358
17444
  "<": ">",
17359
17445
  "[": "]",
17360
17446
  "(": ")",
17361
17447
  "{": "}"
17362
- }, E = "{left}(?:(?!{right}').)*?{right}", R = Object.entries(T).map(([O, N]) => E.replace(/{left}/g, d(O)).replace(/{right}/g, d(N))), A = d(Object.keys(T).join(""));
17448
+ }, E = "{left}(?:(?!{right}').)*?{right}", R = Object.entries(T).map(([O, t]) => E.replace(/{left}/g, d(O)).replace(/{right}/g, d(t))), A = d(Object.keys(T).join(""));
17363
17449
  return `[Qq]'(?:${String.raw`(?<tag>[^\s${A}])(?:(?!\k<tag>').)*?\k<tag>`}|${R.join("|")})'`;
17364
17450
  }, nT = {
17365
17451
  // - backtick quoted (using `` to escape)
@@ -17385,16 +17471,16 @@ const yS = [
17385
17471
  // Hive and Spark variables: ${name}
17386
17472
  "{}": String.raw`(?:\{[^\}]*\})`,
17387
17473
  // Oracle q'' strings: q'<text>' q'|text|' ...
17388
- "q''": ze()
17389
- }, FT = (T) => typeof T == "string" ? nT[T] : "regex" in T ? T.regex : qe(T) + nT[T.quote], EI = (T) => b(T.map((E) => "regex" in E ? E.regex : FT(E)).join("|")), YT = (T) => T.map(FT).join("|"), DT = (T) => b(YT(T)), TI = (T = {}) => b(mT(T)), mT = ({ first: T, rest: E, dashes: R, allowFirstCharNumber: A } = {}) => {
17390
- const S = "\\p{Alphabetic}\\p{Mark}_", e = "\\p{Decimal_Number}", O = d(T ?? ""), N = d(E ?? ""), D = A ? `[${S}${e}${O}][${S}${e}${N}]*` : `[${S}${O}][${S}${e}${N}]*`;
17391
- return R ? Ze(D) : D;
17474
+ "q''": EI()
17475
+ }, YT = (T) => typeof T == "string" ? nT[T] : "regex" in T ? T.regex : je(T) + nT[T.quote], TI = (T) => b(T.map((E) => "regex" in E ? E.regex : YT(E)).join("|")), mT = (T) => T.map(YT).join("|"), DT = (T) => b(mT(T)), RI = (T = {}) => b(pT(T)), pT = ({ first: T, rest: E, dashes: R, allowFirstCharNumber: A } = {}) => {
17476
+ const S = "\\p{Alphabetic}\\p{Mark}_", e = "\\p{Decimal_Number}", O = d(T ?? ""), t = d(E ?? ""), D = A ? `[${S}${e}${O}][${S}${e}${t}]*` : `[${S}${O}][${S}${e}${t}]*`;
17477
+ return R ? qe(D) : D;
17392
17478
  };
17393
- function pT(T, E) {
17479
+ function dT(T, E) {
17394
17480
  const R = T.slice(0, E).split(/\n/);
17395
17481
  return { line: R.length, col: R[R.length - 1].length + 1 };
17396
17482
  }
17397
- class RI {
17483
+ class AI {
17398
17484
  constructor(E, R) {
17399
17485
  this.rules = E, this.dialectName = R, this.input = "", this.index = 0;
17400
17486
  }
@@ -17420,7 +17506,7 @@ class RI {
17420
17506
  return R;
17421
17507
  }
17422
17508
  createParseError() {
17423
- const E = this.input.slice(this.index, this.index + 10), { line: R, col: A } = pT(this.input, this.index);
17509
+ const E = this.input.slice(this.index, this.index + 10), { line: R, col: A } = dT(this.input, this.index);
17424
17510
  return new Error(`Parse error: Unexpected "${E}" at line ${R} column ${A}.
17425
17511
  ${this.dialectInfo()}`);
17426
17512
  }
@@ -17456,8 +17542,8 @@ If possible, please select a more specific dialect (like sqlite, postgresql, etc
17456
17542
  }
17457
17543
  }
17458
17544
  }
17459
- const iT = /\/\*/uy, AI = /[\s\S]/uy, SI = /\*\//uy;
17460
- class eI {
17545
+ const iT = /\/\*/uy, SI = /[\s\S]/uy, eI = /\*\//uy;
17546
+ class II {
17461
17547
  constructor() {
17462
17548
  this.lastIndex = 0;
17463
17549
  }
@@ -17470,9 +17556,9 @@ class eI {
17470
17556
  for (; S > 0; )
17471
17557
  if (A = this.matchSection(iT, E))
17472
17558
  R += A, S++;
17473
- else if (A = this.matchSection(SI, E))
17559
+ else if (A = this.matchSection(eI, E))
17474
17560
  R += A, S--;
17475
- else if (A = this.matchSection(AI, E))
17561
+ else if (A = this.matchSection(SI, E))
17476
17562
  R += A;
17477
17563
  else
17478
17564
  return null;
@@ -17484,7 +17570,7 @@ class eI {
17484
17570
  return A && (this.lastIndex += A[0].length), A ? A[0] : null;
17485
17571
  }
17486
17572
  }
17487
- class II {
17573
+ class OI {
17488
17574
  constructor(E, R) {
17489
17575
  this.cfg = E, this.dialectName = R, this.rulesBeforeParams = this.buildRulesBeforeParams(E), this.rulesAfterParams = this.buildRulesAfterParams(E);
17490
17576
  }
@@ -17493,7 +17579,7 @@ class II {
17493
17579
  ...this.rulesBeforeParams,
17494
17580
  ...this.buildParamRules(this.cfg, R),
17495
17581
  ...this.rulesAfterParams
17496
- ], S = new RI(A, this.dialectName).tokenize(E);
17582
+ ], S = new AI(A, this.dialectName).tokenize(E);
17497
17583
  return this.cfg.postProcess ? this.cfg.postProcess(S) : S;
17498
17584
  }
17499
17585
  // These rules can be cached as they only depend on
@@ -17507,7 +17593,7 @@ class II {
17507
17593
  },
17508
17594
  {
17509
17595
  type: i.BLOCK_COMMENT,
17510
- regex: E.nestedBlockComments ? new eI() : /(\/\*[^]*?\*\/)/uy
17596
+ regex: E.nestedBlockComments ? new II() : /(\/\*[^]*?\*\/)/uy
17511
17597
  },
17512
17598
  {
17513
17599
  type: i.LINE_COMMENT,
@@ -17525,83 +17611,83 @@ class II {
17525
17611
  // to e.g. prioritize matching "TIMESTAMP WITH TIME ZONE" phrase over "WITH" clause.
17526
17612
  {
17527
17613
  type: i.RESERVED_KEYWORD_PHRASE,
17528
- regex: V((A = E.reservedKeywordPhrases) !== null && A !== void 0 ? A : [], E.identChars),
17529
- text: H
17614
+ regex: h((A = E.reservedKeywordPhrases) !== null && A !== void 0 ? A : [], E.identChars),
17615
+ text: B
17530
17616
  },
17531
17617
  {
17532
17618
  type: i.RESERVED_DATA_TYPE_PHRASE,
17533
- regex: V((S = E.reservedDataTypePhrases) !== null && S !== void 0 ? S : [], E.identChars),
17534
- text: H
17619
+ regex: h((S = E.reservedDataTypePhrases) !== null && S !== void 0 ? S : [], E.identChars),
17620
+ text: B
17535
17621
  },
17536
17622
  {
17537
17623
  type: i.CASE,
17538
17624
  regex: /CASE\b/iuy,
17539
- text: H
17625
+ text: B
17540
17626
  },
17541
17627
  {
17542
17628
  type: i.END,
17543
17629
  regex: /END\b/iuy,
17544
- text: H
17630
+ text: B
17545
17631
  },
17546
17632
  {
17547
17633
  type: i.BETWEEN,
17548
17634
  regex: /BETWEEN\b/iuy,
17549
- text: H
17635
+ text: B
17550
17636
  },
17551
17637
  {
17552
17638
  type: i.LIMIT,
17553
17639
  regex: E.reservedClauses.includes("LIMIT") ? /LIMIT\b/iuy : void 0,
17554
- text: H
17640
+ text: B
17555
17641
  },
17556
17642
  {
17557
17643
  type: i.RESERVED_CLAUSE,
17558
- regex: V(E.reservedClauses, E.identChars),
17559
- text: H
17644
+ regex: h(E.reservedClauses, E.identChars),
17645
+ text: B
17560
17646
  },
17561
17647
  {
17562
17648
  type: i.RESERVED_SELECT,
17563
- regex: V(E.reservedSelect, E.identChars),
17564
- text: H
17649
+ regex: h(E.reservedSelect, E.identChars),
17650
+ text: B
17565
17651
  },
17566
17652
  {
17567
17653
  type: i.RESERVED_SET_OPERATION,
17568
- regex: V(E.reservedSetOperations, E.identChars),
17569
- text: H
17654
+ regex: h(E.reservedSetOperations, E.identChars),
17655
+ text: B
17570
17656
  },
17571
17657
  {
17572
17658
  type: i.WHEN,
17573
17659
  regex: /WHEN\b/iuy,
17574
- text: H
17660
+ text: B
17575
17661
  },
17576
17662
  {
17577
17663
  type: i.ELSE,
17578
17664
  regex: /ELSE\b/iuy,
17579
- text: H
17665
+ text: B
17580
17666
  },
17581
17667
  {
17582
17668
  type: i.THEN,
17583
17669
  regex: /THEN\b/iuy,
17584
- text: H
17670
+ text: B
17585
17671
  },
17586
17672
  {
17587
17673
  type: i.RESERVED_JOIN,
17588
- regex: V(E.reservedJoins, E.identChars),
17589
- text: H
17674
+ regex: h(E.reservedJoins, E.identChars),
17675
+ text: B
17590
17676
  },
17591
17677
  {
17592
17678
  type: i.AND,
17593
17679
  regex: /AND\b/iuy,
17594
- text: H
17680
+ text: B
17595
17681
  },
17596
17682
  {
17597
17683
  type: i.OR,
17598
17684
  regex: /OR\b/iuy,
17599
- text: H
17685
+ text: B
17600
17686
  },
17601
17687
  {
17602
17688
  type: i.XOR,
17603
17689
  regex: E.supportsXor ? /XOR\b/iuy : void 0,
17604
- text: H
17690
+ text: B
17605
17691
  },
17606
17692
  ...E.operatorKeyword ? [
17607
17693
  {
@@ -17611,18 +17697,18 @@ class II {
17611
17697
  ] : [],
17612
17698
  {
17613
17699
  type: i.RESERVED_FUNCTION_NAME,
17614
- regex: V(E.reservedFunctionNames, E.identChars),
17615
- text: H
17700
+ regex: h(E.reservedFunctionNames, E.identChars),
17701
+ text: B
17616
17702
  },
17617
17703
  {
17618
17704
  type: i.RESERVED_DATA_TYPE,
17619
- regex: V(E.reservedDataTypes, E.identChars),
17620
- text: H
17705
+ regex: h(E.reservedDataTypes, E.identChars),
17706
+ text: B
17621
17707
  },
17622
17708
  {
17623
17709
  type: i.RESERVED_KEYWORD,
17624
- regex: V(E.reservedKeywords, E.identChars),
17625
- text: H
17710
+ regex: h(E.reservedKeywords, E.identChars),
17711
+ text: B
17626
17712
  }
17627
17713
  ]);
17628
17714
  }
@@ -17633,12 +17719,12 @@ class II {
17633
17719
  return this.validRules([
17634
17720
  {
17635
17721
  type: i.VARIABLE,
17636
- regex: E.variableTypes ? EI(E.variableTypes) : void 0
17722
+ regex: E.variableTypes ? TI(E.variableTypes) : void 0
17637
17723
  },
17638
17724
  { type: i.STRING, regex: DT(E.stringTypes) },
17639
17725
  {
17640
17726
  type: i.IDENTIFIER,
17641
- regex: TI(E.identChars)
17727
+ regex: RI(E.identChars)
17642
17728
  },
17643
17729
  { type: i.DELIMITER, regex: /[;]/uy },
17644
17730
  { type: i.COMMA, regex: /[,]/y },
@@ -17677,24 +17763,24 @@ class II {
17677
17763
  // These rules can't be blindly cached as the paramTypesOverrides object
17678
17764
  // can differ on each invocation of the format() function.
17679
17765
  buildParamRules(E, R) {
17680
- var A, S, e, O, N;
17766
+ var A, S, e, O, t;
17681
17767
  const D = {
17682
17768
  named: R?.named || ((A = E.paramTypes) === null || A === void 0 ? void 0 : A.named) || [],
17683
17769
  quoted: R?.quoted || ((S = E.paramTypes) === null || S === void 0 ? void 0 : S.quoted) || [],
17684
17770
  numbered: R?.numbered || ((e = E.paramTypes) === null || e === void 0 ? void 0 : e.numbered) || [],
17685
17771
  positional: typeof R?.positional == "boolean" ? R.positional : (O = E.paramTypes) === null || O === void 0 ? void 0 : O.positional,
17686
- custom: R?.custom || ((N = E.paramTypes) === null || N === void 0 ? void 0 : N.custom) || []
17772
+ custom: R?.custom || ((t = E.paramTypes) === null || t === void 0 ? void 0 : t.custom) || []
17687
17773
  };
17688
17774
  return this.validRules([
17689
17775
  {
17690
17776
  type: i.NAMED_PARAMETER,
17691
- regex: uE(D.named, mT(E.paramChars || E.identChars)),
17777
+ regex: uE(D.named, pT(E.paramChars || E.identChars)),
17692
17778
  key: (I) => I.slice(1)
17693
17779
  },
17694
17780
  {
17695
17781
  type: i.QUOTED_PARAMETER,
17696
- regex: uE(D.quoted, YT(E.identTypes)),
17697
- key: (I) => (({ tokenKey: C, quoteChar: s }) => C.replace(new RegExp(d("\\" + s), "gu"), s))({
17782
+ regex: uE(D.quoted, mT(E.identTypes)),
17783
+ key: (I) => (({ tokenKey: N, quoteChar: s }) => N.replace(new RegExp(d("\\" + s), "gu"), s))({
17698
17784
  tokenKey: I.slice(2, -1),
17699
17785
  quoteChar: I.slice(-1)
17700
17786
  })
@@ -17709,11 +17795,11 @@ class II {
17709
17795
  regex: D.positional ? /[?]/y : void 0
17710
17796
  },
17711
17797
  ...D.custom.map((I) => {
17712
- var C;
17798
+ var N;
17713
17799
  return {
17714
17800
  type: i.CUSTOM_PARAMETER,
17715
17801
  regex: b(I.regex),
17716
- key: (C = I.key) !== null && C !== void 0 ? C : ((s) => s)
17802
+ key: (N = I.key) !== null && N !== void 0 ? N : ((s) => s)
17717
17803
  };
17718
17804
  })
17719
17805
  ]);
@@ -17723,13 +17809,13 @@ class II {
17723
17809
  return E.filter((R) => !!R.regex);
17724
17810
  }
17725
17811
  }
17726
- const H = (T) => Z(T.toUpperCase()), PT = /* @__PURE__ */ new Map(), OI = (T) => {
17812
+ const B = (T) => q(T.toUpperCase()), PT = /* @__PURE__ */ new Map(), NI = (T) => {
17727
17813
  let E = PT.get(T);
17728
- return E || (E = NI(T), PT.set(T, E)), E;
17729
- }, NI = (T) => ({
17730
- tokenizer: new II(T.tokenizerOptions, T.name),
17731
- formatOptions: sI(T.formatOptions)
17732
- }), sI = (T) => {
17814
+ return E || (E = sI(T), PT.set(T, E)), E;
17815
+ }, sI = (T) => ({
17816
+ tokenizer: new OI(T.tokenizerOptions, T.name),
17817
+ formatOptions: tI(T.formatOptions)
17818
+ }), tI = (T) => {
17733
17819
  var E;
17734
17820
  return {
17735
17821
  alwaysDenseOperators: T.alwaysDenseOperators || [],
@@ -17737,13 +17823,13 @@ const H = (T) => Z(T.toUpperCase()), PT = /* @__PURE__ */ new Map(), OI = (T) =>
17737
17823
  tabularOnelineClauses: Object.fromEntries(((E = T.tabularOnelineClauses) !== null && E !== void 0 ? E : T.onelineClauses).map((R) => [R, !0]))
17738
17824
  };
17739
17825
  };
17740
- function tI(T) {
17826
+ function CI(T) {
17741
17827
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight" ? " ".repeat(10) : T.useTabs ? " " : " ".repeat(T.tabWidth);
17742
17828
  }
17743
17829
  function J(T) {
17744
17830
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight";
17745
17831
  }
17746
- class CI {
17832
+ class LI {
17747
17833
  constructor(E) {
17748
17834
  this.params = E, this.index = 0;
17749
17835
  }
@@ -17766,101 +17852,101 @@ class CI {
17766
17852
  this.index = E;
17767
17853
  }
17768
17854
  }
17769
- function LI(T) {
17855
+ function _I(T) {
17770
17856
  return T && T.__esModule && Object.prototype.hasOwnProperty.call(T, "default") ? T.default : T;
17771
17857
  }
17772
- var q = { exports: {} }, _I = q.exports, aT;
17773
- function rI() {
17774
- return aT || (aT = 1, (function(T) {
17858
+ var j = { exports: {} }, rI = j.exports, oT;
17859
+ function nI() {
17860
+ return oT || (oT = 1, (function(T) {
17775
17861
  (function(E, R) {
17776
17862
  T.exports ? T.exports = R() : E.nearley = R();
17777
- })(_I, function() {
17778
- function E(I, C, s) {
17779
- return this.id = ++E.highestId, this.name = I, this.symbols = C, this.postprocess = s, this;
17863
+ })(rI, function() {
17864
+ function E(I, N, s) {
17865
+ return this.id = ++E.highestId, this.name = I, this.symbols = N, this.postprocess = s, this;
17780
17866
  }
17781
17867
  E.highestId = 0, E.prototype.toString = function(I) {
17782
- var C = typeof I > "u" ? this.symbols.map(D).join(" ") : this.symbols.slice(0, I).map(D).join(" ") + " ● " + this.symbols.slice(I).map(D).join(" ");
17783
- return this.name + " → " + C;
17868
+ var N = typeof I > "u" ? this.symbols.map(D).join(" ") : this.symbols.slice(0, I).map(D).join(" ") + " ● " + this.symbols.slice(I).map(D).join(" ");
17869
+ return this.name + " → " + N;
17784
17870
  };
17785
- function R(I, C, s, L) {
17786
- this.rule = I, this.dot = C, this.reference = s, this.data = [], this.wantedBy = L, this.isComplete = this.dot === I.symbols.length;
17871
+ function R(I, N, s, L) {
17872
+ this.rule = I, this.dot = N, this.reference = s, this.data = [], this.wantedBy = L, this.isComplete = this.dot === I.symbols.length;
17787
17873
  }
17788
17874
  R.prototype.toString = function() {
17789
17875
  return "{" + this.rule.toString(this.dot) + "}, from: " + (this.reference || 0);
17790
17876
  }, R.prototype.nextState = function(I) {
17791
- var C = new R(this.rule, this.dot + 1, this.reference, this.wantedBy);
17792
- return C.left = this, C.right = I, C.isComplete && (C.data = C.build(), C.right = void 0), C;
17877
+ var N = new R(this.rule, this.dot + 1, this.reference, this.wantedBy);
17878
+ return N.left = this, N.right = I, N.isComplete && (N.data = N.build(), N.right = void 0), N;
17793
17879
  }, R.prototype.build = function() {
17794
- var I = [], C = this;
17880
+ var I = [], N = this;
17795
17881
  do
17796
- I.push(C.right.data), C = C.left;
17797
- while (C.left);
17882
+ I.push(N.right.data), N = N.left;
17883
+ while (N.left);
17798
17884
  return I.reverse(), I;
17799
17885
  }, R.prototype.finish = function() {
17800
17886
  this.rule.postprocess && (this.data = this.rule.postprocess(this.data, this.reference, O.fail));
17801
17887
  };
17802
- function A(I, C) {
17803
- this.grammar = I, this.index = C, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
17888
+ function A(I, N) {
17889
+ this.grammar = I, this.index = N, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
17804
17890
  }
17805
17891
  A.prototype.process = function(I) {
17806
- for (var C = this.states, s = this.wants, L = this.completed, P = 0; P < C.length; P++) {
17807
- var a = C[P];
17808
- if (a.isComplete) {
17809
- if (a.finish(), a.data !== O.fail) {
17810
- for (var r = a.wantedBy, U = r.length; U--; ) {
17811
- var o = r[U];
17812
- this.complete(o, a);
17892
+ for (var N = this.states, s = this.wants, L = this.completed, P = 0; P < N.length; P++) {
17893
+ var o = N[P];
17894
+ if (o.isComplete) {
17895
+ if (o.finish(), o.data !== O.fail) {
17896
+ for (var r = o.wantedBy, U = r.length; U--; ) {
17897
+ var a = r[U];
17898
+ this.complete(a, o);
17813
17899
  }
17814
- if (a.reference === this.index) {
17815
- var c = a.rule.name;
17816
- (this.completed[c] = this.completed[c] || []).push(a);
17900
+ if (o.reference === this.index) {
17901
+ var l = o.rule.name;
17902
+ (this.completed[l] = this.completed[l] || []).push(o);
17817
17903
  }
17818
17904
  }
17819
17905
  } else {
17820
- var c = a.rule.symbols[a.dot];
17821
- if (typeof c != "string") {
17822
- this.scannable.push(a);
17906
+ var l = o.rule.symbols[o.dot];
17907
+ if (typeof l != "string") {
17908
+ this.scannable.push(o);
17823
17909
  continue;
17824
17910
  }
17825
- if (s[c]) {
17826
- if (s[c].push(a), L.hasOwnProperty(c))
17827
- for (var l = L[c], U = 0; U < l.length; U++) {
17828
- var u = l[U];
17829
- this.complete(a, u);
17911
+ if (s[l]) {
17912
+ if (s[l].push(o), L.hasOwnProperty(l))
17913
+ for (var c = L[l], U = 0; U < c.length; U++) {
17914
+ var H = c[U];
17915
+ this.complete(o, H);
17830
17916
  }
17831
17917
  } else
17832
- s[c] = [a], this.predict(c);
17918
+ s[l] = [o], this.predict(l);
17833
17919
  }
17834
17920
  }
17835
17921
  }, A.prototype.predict = function(I) {
17836
- for (var C = this.grammar.byName[I] || [], s = 0; s < C.length; s++) {
17837
- var L = C[s], P = this.wants[I], a = new R(L, 0, this.index, P);
17838
- this.states.push(a);
17922
+ for (var N = this.grammar.byName[I] || [], s = 0; s < N.length; s++) {
17923
+ var L = N[s], P = this.wants[I], o = new R(L, 0, this.index, P);
17924
+ this.states.push(o);
17839
17925
  }
17840
- }, A.prototype.complete = function(I, C) {
17841
- var s = I.nextState(C);
17926
+ }, A.prototype.complete = function(I, N) {
17927
+ var s = I.nextState(N);
17842
17928
  this.states.push(s);
17843
17929
  };
17844
- function S(I, C) {
17845
- this.rules = I, this.start = C || this.rules[0].name;
17930
+ function S(I, N) {
17931
+ this.rules = I, this.start = N || this.rules[0].name;
17846
17932
  var s = this.byName = {};
17847
17933
  this.rules.forEach(function(L) {
17848
17934
  s.hasOwnProperty(L.name) || (s[L.name] = []), s[L.name].push(L);
17849
17935
  });
17850
17936
  }
17851
- S.fromCompiled = function(L, C) {
17937
+ S.fromCompiled = function(L, N) {
17852
17938
  var s = L.Lexer;
17853
- L.ParserStart && (C = L.ParserStart, L = L.ParserRules);
17854
- var L = L.map(function(a) {
17855
- return new E(a.name, a.symbols, a.postprocess);
17856
- }), P = new S(L, C);
17939
+ L.ParserStart && (N = L.ParserStart, L = L.ParserRules);
17940
+ var L = L.map(function(o) {
17941
+ return new E(o.name, o.symbols, o.postprocess);
17942
+ }), P = new S(L, N);
17857
17943
  return P.lexer = s, P;
17858
17944
  };
17859
17945
  function e() {
17860
17946
  this.reset("");
17861
17947
  }
17862
- e.prototype.reset = function(I, C) {
17863
- this.buffer = I, this.index = 0, this.line = C ? C.line : 1, this.lastLineBreak = C ? -C.col : 0;
17948
+ e.prototype.reset = function(I, N) {
17949
+ this.buffer = I, this.index = 0, this.line = N ? N.line : 1, this.lastLineBreak = N ? -N.col : 0;
17864
17950
  }, e.prototype.next = function() {
17865
17951
  if (this.index < this.buffer.length) {
17866
17952
  var I = this.buffer[this.index++];
@@ -17872,7 +17958,7 @@ function rI() {
17872
17958
  line: this.line,
17873
17959
  col: this.index - this.lastLineBreak
17874
17960
  };
17875
- }, e.prototype.formatError = function(I, C) {
17961
+ }, e.prototype.formatError = function(I, N) {
17876
17962
  var s = this.buffer;
17877
17963
  if (typeof s == "string") {
17878
17964
  var L = s.split(`
@@ -17882,27 +17968,27 @@ function rI() {
17882
17968
  ), P = s.indexOf(`
17883
17969
  `, this.index);
17884
17970
  P === -1 && (P = s.length);
17885
- var a = this.index - this.lastLineBreak, r = String(this.line).length;
17886
- return C += " at line " + this.line + " col " + a + `:
17971
+ var o = this.index - this.lastLineBreak, r = String(this.line).length;
17972
+ return N += " at line " + this.line + " col " + o + `:
17887
17973
 
17888
- `, C += L.map(function(o, c) {
17889
- return U(this.line - L.length + c + 1, r) + " " + o;
17974
+ `, N += L.map(function(a, l) {
17975
+ return U(this.line - L.length + l + 1, r) + " " + a;
17890
17976
  }, this).join(`
17891
- `), C += `
17892
- ` + U("", r + a) + `^
17893
- `, C;
17977
+ `), N += `
17978
+ ` + U("", r + o) + `^
17979
+ `, N;
17894
17980
  } else
17895
- return C + " at index " + (this.index - 1);
17896
- function U(o, c) {
17897
- var l = String(o);
17898
- return Array(c - l.length + 1).join(" ") + l;
17981
+ return N + " at index " + (this.index - 1);
17982
+ function U(a, l) {
17983
+ var c = String(a);
17984
+ return Array(l - c.length + 1).join(" ") + c;
17899
17985
  }
17900
17986
  };
17901
- function O(I, C, s) {
17987
+ function O(I, N, s) {
17902
17988
  if (I instanceof S)
17903
- var L = I, s = C;
17989
+ var L = I, s = N;
17904
17990
  else
17905
- var L = S.fromCompiled(I, C);
17991
+ var L = S.fromCompiled(I, N);
17906
17992
  this.grammar = L, this.options = {
17907
17993
  keepHistory: !1,
17908
17994
  lexer: L.lexer || new e()
@@ -17910,30 +17996,30 @@ function rI() {
17910
17996
  for (var P in s || {})
17911
17997
  this.options[P] = s[P];
17912
17998
  this.lexer = this.options.lexer, this.lexerState = void 0;
17913
- var a = new A(L, 0);
17914
- this.table = [a], a.wants[L.start] = [], a.predict(L.start), a.process(), this.current = 0;
17999
+ var o = new A(L, 0);
18000
+ this.table = [o], o.wants[L.start] = [], o.predict(L.start), o.process(), this.current = 0;
17915
18001
  }
17916
18002
  O.fail = {}, O.prototype.feed = function(I) {
17917
- var C = this.lexer;
17918
- C.reset(I, this.lexerState);
18003
+ var N = this.lexer;
18004
+ N.reset(I, this.lexerState);
17919
18005
  for (var s; ; ) {
17920
18006
  try {
17921
- if (s = C.next(), !s)
18007
+ if (s = N.next(), !s)
17922
18008
  break;
17923
- } catch (K) {
18009
+ } catch (y) {
17924
18010
  var r = new A(this.grammar, this.current + 1);
17925
18011
  this.table.push(r);
17926
- var L = new Error(this.reportLexerError(K));
17927
- throw L.offset = this.current, L.token = K.token, L;
18012
+ var L = new Error(this.reportLexerError(y));
18013
+ throw L.offset = this.current, L.token = y.token, L;
17928
18014
  }
17929
18015
  var P = this.table[this.current];
17930
18016
  this.options.keepHistory || delete this.table[this.current - 1];
17931
- var a = this.current + 1, r = new A(this.grammar, a);
18017
+ var o = this.current + 1, r = new A(this.grammar, o);
17932
18018
  this.table.push(r);
17933
- for (var U = s.text !== void 0 ? s.text : s.value, o = C.constructor === e ? s.value : s, c = P.scannable, l = c.length; l--; ) {
17934
- var u = c[l], Y = u.rule.symbols[u.dot];
17935
- if (Y.test ? Y.test(o) : Y.type ? Y.type === s.type : Y.literal === U) {
17936
- var p = u.nextState({ data: o, token: s, isToken: !0, reference: a - 1 });
18019
+ for (var U = s.text !== void 0 ? s.text : s.value, a = N.constructor === e ? s.value : s, l = P.scannable, c = l.length; c--; ) {
18020
+ var H = l[c], u = H.rule.symbols[H.dot];
18021
+ if (u.test ? u.test(a) : u.type ? u.type === s.type : u.literal === U) {
18022
+ var p = H.nextState({ data: a, token: s, isToken: !0, reference: o - 1 });
17937
18023
  r.states.push(p);
17938
18024
  }
17939
18025
  }
@@ -17941,75 +18027,75 @@ function rI() {
17941
18027
  var L = new Error(this.reportError(s));
17942
18028
  throw L.offset = this.current, L.token = s, L;
17943
18029
  }
17944
- this.options.keepHistory && (P.lexerState = C.save()), this.current++;
18030
+ this.options.keepHistory && (P.lexerState = N.save()), this.current++;
17945
18031
  }
17946
- return P && (this.lexerState = C.save()), this.results = this.finish(), this;
18032
+ return P && (this.lexerState = N.save()), this.results = this.finish(), this;
17947
18033
  }, O.prototype.reportLexerError = function(I) {
17948
- var C, s, L = I.token;
17949
- return L ? (C = "input " + JSON.stringify(L.text[0]) + " (lexer error)", s = this.lexer.formatError(L, "Syntax error")) : (C = "input (lexer error)", s = I.message), this.reportErrorCommon(s, C);
18034
+ var N, s, L = I.token;
18035
+ return L ? (N = "input " + JSON.stringify(L.text[0]) + " (lexer error)", s = this.lexer.formatError(L, "Syntax error")) : (N = "input (lexer error)", s = I.message), this.reportErrorCommon(s, N);
17950
18036
  }, O.prototype.reportError = function(I) {
17951
- var C = (I.type ? I.type + " token: " : "") + JSON.stringify(I.value !== void 0 ? I.value : I), s = this.lexer.formatError(I, "Syntax error");
17952
- return this.reportErrorCommon(s, C);
17953
- }, O.prototype.reportErrorCommon = function(I, C) {
18037
+ var N = (I.type ? I.type + " token: " : "") + JSON.stringify(I.value !== void 0 ? I.value : I), s = this.lexer.formatError(I, "Syntax error");
18038
+ return this.reportErrorCommon(s, N);
18039
+ }, O.prototype.reportErrorCommon = function(I, N) {
17954
18040
  var s = [];
17955
18041
  s.push(I);
17956
- var L = this.table.length - 2, P = this.table[L], a = P.states.filter(function(U) {
17957
- var o = U.rule.symbols[U.dot];
17958
- return o && typeof o != "string";
18042
+ var L = this.table.length - 2, P = this.table[L], o = P.states.filter(function(U) {
18043
+ var a = U.rule.symbols[U.dot];
18044
+ return a && typeof a != "string";
17959
18045
  });
17960
- if (a.length === 0)
17961
- s.push("Unexpected " + C + `. I did not expect any more input. Here is the state of my parse table:
18046
+ if (o.length === 0)
18047
+ s.push("Unexpected " + N + `. I did not expect any more input. Here is the state of my parse table:
17962
18048
  `), this.displayStateStack(P.states, s);
17963
18049
  else {
17964
- s.push("Unexpected " + C + `. Instead, I was expecting to see one of the following:
18050
+ s.push("Unexpected " + N + `. Instead, I was expecting to see one of the following:
17965
18051
  `);
17966
- var r = a.map(function(U) {
18052
+ var r = o.map(function(U) {
17967
18053
  return this.buildFirstStateStack(U, []) || [U];
17968
18054
  }, this);
17969
18055
  r.forEach(function(U) {
17970
- var o = U[0], c = o.rule.symbols[o.dot], l = this.getSymbolDisplay(c);
17971
- s.push("A " + l + " based on:"), this.displayStateStack(U, s);
18056
+ var a = U[0], l = a.rule.symbols[a.dot], c = this.getSymbolDisplay(l);
18057
+ s.push("A " + c + " based on:"), this.displayStateStack(U, s);
17972
18058
  }, this);
17973
18059
  }
17974
18060
  return s.push(""), s.join(`
17975
18061
  `);
17976
- }, O.prototype.displayStateStack = function(I, C) {
18062
+ }, O.prototype.displayStateStack = function(I, N) {
17977
18063
  for (var s, L = 0, P = 0; P < I.length; P++) {
17978
- var a = I[P], r = a.rule.toString(a.dot);
17979
- r === s ? L++ : (L > 0 && C.push(" ^ " + L + " more lines identical to this"), L = 0, C.push(" " + r)), s = r;
18064
+ var o = I[P], r = o.rule.toString(o.dot);
18065
+ r === s ? L++ : (L > 0 && N.push(" ^ " + L + " more lines identical to this"), L = 0, N.push(" " + r)), s = r;
17980
18066
  }
17981
18067
  }, O.prototype.getSymbolDisplay = function(I) {
17982
- return N(I);
17983
- }, O.prototype.buildFirstStateStack = function(I, C) {
17984
- if (C.indexOf(I) !== -1)
18068
+ return t(I);
18069
+ }, O.prototype.buildFirstStateStack = function(I, N) {
18070
+ if (N.indexOf(I) !== -1)
17985
18071
  return null;
17986
18072
  if (I.wantedBy.length === 0)
17987
18073
  return [I];
17988
- var s = I.wantedBy[0], L = [I].concat(C), P = this.buildFirstStateStack(s, L);
18074
+ var s = I.wantedBy[0], L = [I].concat(N), P = this.buildFirstStateStack(s, L);
17989
18075
  return P === null ? null : [I].concat(P);
17990
18076
  }, O.prototype.save = function() {
17991
18077
  var I = this.table[this.current];
17992
18078
  return I.lexerState = this.lexerState, I;
17993
18079
  }, O.prototype.restore = function(I) {
17994
- var C = I.index;
17995
- this.current = C, this.table[C] = I, this.table.splice(C + 1), this.lexerState = I.lexerState, this.results = this.finish();
18080
+ var N = I.index;
18081
+ this.current = N, this.table[N] = I, this.table.splice(N + 1), this.lexerState = I.lexerState, this.results = this.finish();
17996
18082
  }, O.prototype.rewind = function(I) {
17997
18083
  if (!this.options.keepHistory)
17998
18084
  throw new Error("set option `keepHistory` to enable rewinding");
17999
18085
  this.restore(this.table[I]);
18000
18086
  }, O.prototype.finish = function() {
18001
- var I = [], C = this.grammar.start, s = this.table[this.table.length - 1];
18087
+ var I = [], N = this.grammar.start, s = this.table[this.table.length - 1];
18002
18088
  return s.states.forEach(function(L) {
18003
- L.rule.name === C && L.dot === L.rule.symbols.length && L.reference === 0 && L.data !== O.fail && I.push(L);
18089
+ L.rule.name === N && L.dot === L.rule.symbols.length && L.reference === 0 && L.data !== O.fail && I.push(L);
18004
18090
  }), I.map(function(L) {
18005
18091
  return L.data;
18006
18092
  });
18007
18093
  };
18008
- function N(I) {
18009
- var C = typeof I;
18010
- if (C === "string")
18094
+ function t(I) {
18095
+ var N = typeof I;
18096
+ if (N === "string")
18011
18097
  return I;
18012
- if (C === "object") {
18098
+ if (N === "object") {
18013
18099
  if (I.literal)
18014
18100
  return JSON.stringify(I.literal);
18015
18101
  if (I instanceof RegExp)
@@ -18022,10 +18108,10 @@ function rI() {
18022
18108
  }
18023
18109
  }
18024
18110
  function D(I) {
18025
- var C = typeof I;
18026
- if (C === "string")
18111
+ var N = typeof I;
18112
+ if (N === "string")
18027
18113
  return I;
18028
- if (C === "object") {
18114
+ if (N === "object") {
18029
18115
  if (I.literal)
18030
18116
  return JSON.stringify(I.literal);
18031
18117
  if (I instanceof RegExp)
@@ -18043,58 +18129,58 @@ function rI() {
18043
18129
  Rule: E
18044
18130
  };
18045
18131
  });
18046
- })(q)), q.exports;
18132
+ })(j)), j.exports;
18047
18133
  }
18048
- var nI = rI();
18049
- const DI = /* @__PURE__ */ LI(nI);
18050
- function iI(T) {
18051
- return T.map(PI).map(aI).map(oI).map(MI).map(UI);
18134
+ var DI = nI();
18135
+ const iI = /* @__PURE__ */ _I(DI);
18136
+ function PI(T) {
18137
+ return T.map(oI).map(aI).map(MI).map(UI).map(GI);
18052
18138
  }
18053
- const PI = (T, E, R) => {
18054
- if (uT(T.type)) {
18055
- const A = GI(R, E);
18139
+ const oI = (T, E, R) => {
18140
+ if (BT(T.type)) {
18141
+ const A = cI(R, E);
18056
18142
  if (A && A.type === i.PROPERTY_ACCESS_OPERATOR)
18057
18143
  return Object.assign(Object.assign({}, T), { type: i.IDENTIFIER, text: T.raw });
18058
- const S = x(R, E);
18144
+ const S = v(R, E);
18059
18145
  if (S && S.type === i.PROPERTY_ACCESS_OPERATOR)
18060
18146
  return Object.assign(Object.assign({}, T), { type: i.IDENTIFIER, text: T.raw });
18061
18147
  }
18062
18148
  return T;
18063
18149
  }, aI = (T, E, R) => {
18064
18150
  if (T.type === i.RESERVED_FUNCTION_NAME) {
18065
- const A = x(R, E);
18066
- if (!A || !dT(A))
18151
+ const A = v(R, E);
18152
+ if (!A || !hT(A))
18067
18153
  return Object.assign(Object.assign({}, T), { type: i.IDENTIFIER, text: T.raw });
18068
18154
  }
18069
18155
  return T;
18070
- }, oI = (T, E, R) => {
18156
+ }, MI = (T, E, R) => {
18071
18157
  if (T.type === i.RESERVED_DATA_TYPE) {
18072
- const A = x(R, E);
18073
- if (A && dT(A))
18158
+ const A = v(R, E);
18159
+ if (A && hT(A))
18074
18160
  return Object.assign(Object.assign({}, T), { type: i.RESERVED_PARAMETERIZED_DATA_TYPE });
18075
18161
  }
18076
18162
  return T;
18077
- }, MI = (T, E, R) => {
18163
+ }, UI = (T, E, R) => {
18078
18164
  if (T.type === i.IDENTIFIER) {
18079
- const A = x(R, E);
18165
+ const A = v(R, E);
18080
18166
  if (A && VT(A))
18081
18167
  return Object.assign(Object.assign({}, T), { type: i.ARRAY_IDENTIFIER });
18082
18168
  }
18083
18169
  return T;
18084
- }, UI = (T, E, R) => {
18170
+ }, GI = (T, E, R) => {
18085
18171
  if (T.type === i.RESERVED_DATA_TYPE) {
18086
- const A = x(R, E);
18172
+ const A = v(R, E);
18087
18173
  if (A && VT(A))
18088
18174
  return Object.assign(Object.assign({}, T), { type: i.ARRAY_KEYWORD });
18089
18175
  }
18090
18176
  return T;
18091
- }, GI = (T, E) => x(T, E, -1), x = (T, E, R = 1) => {
18177
+ }, cI = (T, E) => v(T, E, -1), v = (T, E, R = 1) => {
18092
18178
  let A = 1;
18093
- for (; T[E + A * R] && cI(T[E + A * R]); )
18179
+ for (; T[E + A * R] && lI(T[E + A * R]); )
18094
18180
  A++;
18095
18181
  return T[E + A * R];
18096
- }, dT = (T) => T.type === i.OPEN_PAREN && T.text === "(", VT = (T) => T.type === i.OPEN_PAREN && T.text === "[", cI = (T) => T.type === i.BLOCK_COMMENT || T.type === i.LINE_COMMENT;
18097
- class hT {
18182
+ }, hT = (T) => T.type === i.OPEN_PAREN && T.text === "(", VT = (T) => T.type === i.OPEN_PAREN && T.text === "[", lI = (T) => T.type === i.BLOCK_COMMENT || T.type === i.LINE_COMMENT;
18183
+ class fT {
18098
18184
  constructor(E) {
18099
18185
  this.tokenize = E, this.index = 0, this.tokens = [], this.input = "";
18100
18186
  }
@@ -18107,7 +18193,7 @@ class hT {
18107
18193
  save() {
18108
18194
  }
18109
18195
  formatError(E) {
18110
- const { line: R, col: A } = pT(this.input, E.start);
18196
+ const { line: R, col: A } = dT(this.input, E.start);
18111
18197
  return `Parse error at token: ${E.text} at line ${R} column ${A}`;
18112
18198
  }
18113
18199
  has(E) {
@@ -18121,26 +18207,26 @@ var M;
18121
18207
  function BE(T) {
18122
18208
  return T[0];
18123
18209
  }
18124
- const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18210
+ const G = new fT((T) => []), V = ([[T]]) => T, F = (T) => ({
18125
18211
  type: M.keyword,
18126
18212
  tokenType: T.type,
18127
18213
  text: T.text,
18128
18214
  raw: T.raw
18129
- }), oT = (T) => ({
18215
+ }), aT = (T) => ({
18130
18216
  type: M.data_type,
18131
18217
  text: T.text,
18132
18218
  raw: T.raw
18133
- }), F = (T, { leading: E, trailing: R }) => (E?.length && (T = Object.assign(Object.assign({}, T), { leadingComments: E })), R?.length && (T = Object.assign(Object.assign({}, T), { trailingComments: R })), T), lI = (T, { leading: E, trailing: R }) => {
18219
+ }), Y = (T, { leading: E, trailing: R }) => (E?.length && (T = Object.assign(Object.assign({}, T), { leadingComments: E })), R?.length && (T = Object.assign(Object.assign({}, T), { trailingComments: R })), T), HI = (T, { leading: E, trailing: R }) => {
18134
18220
  if (E?.length) {
18135
18221
  const [A, ...S] = T;
18136
- T = [F(A, { leading: E }), ...S];
18222
+ T = [Y(A, { leading: E }), ...S];
18137
18223
  }
18138
18224
  if (R?.length) {
18139
18225
  const A = T.slice(0, -1), S = T[T.length - 1];
18140
- T = [...A, F(S, { trailing: R })];
18226
+ T = [...A, Y(S, { trailing: R })];
18141
18227
  }
18142
18228
  return T;
18143
- }, HI = {
18229
+ }, uI = {
18144
18230
  Lexer: G,
18145
18231
  ParserRules: [
18146
18232
  { name: "main$ebnf$1", symbols: [] },
@@ -18177,7 +18263,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18177
18263
  { name: "clause$subexpression$1", symbols: ["select_clause"] },
18178
18264
  { name: "clause$subexpression$1", symbols: ["other_clause"] },
18179
18265
  { name: "clause$subexpression$1", symbols: ["set_operation"] },
18180
- { name: "clause", symbols: ["clause$subexpression$1"], postprocess: h },
18266
+ { name: "clause", symbols: ["clause$subexpression$1"], postprocess: V },
18181
18267
  { name: "limit_clause$ebnf$1$subexpression$1$ebnf$1", symbols: ["free_form_sql"] },
18182
18268
  { name: "limit_clause$ebnf$1$subexpression$1$ebnf$1", symbols: ["limit_clause$ebnf$1$subexpression$1$ebnf$1", "free_form_sql"], postprocess: (T) => T[0].concat([T[1]]) },
18183
18269
  { name: "limit_clause$ebnf$1$subexpression$1", symbols: [G.has("COMMA") ? { type: "COMMA" } : COMMA, "limit_clause$ebnf$1$subexpression$1$ebnf$1"] },
@@ -18191,14 +18277,14 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18191
18277
  const [S, e] = A;
18192
18278
  return {
18193
18279
  type: M.limit_clause,
18194
- limitKw: F(B(T), { trailing: E }),
18280
+ limitKw: Y(F(T), { trailing: E }),
18195
18281
  offset: R,
18196
18282
  count: e
18197
18283
  };
18198
18284
  } else
18199
18285
  return {
18200
18286
  type: M.limit_clause,
18201
- limitKw: F(B(T), { trailing: E }),
18287
+ limitKw: Y(F(T), { trailing: E }),
18202
18288
  count: R
18203
18289
  };
18204
18290
  }
@@ -18214,7 +18300,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18214
18300
  symbols: [G.has("RESERVED_SELECT") ? { type: "RESERVED_SELECT" } : RESERVED_SELECT, "select_clause$subexpression$1"],
18215
18301
  postprocess: ([T, [E, R]]) => ({
18216
18302
  type: M.clause,
18217
- nameKw: B(T),
18303
+ nameKw: F(T),
18218
18304
  children: [E, ...R]
18219
18305
  })
18220
18306
  },
@@ -18223,7 +18309,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18223
18309
  symbols: [G.has("RESERVED_SELECT") ? { type: "RESERVED_SELECT" } : RESERVED_SELECT],
18224
18310
  postprocess: ([T]) => ({
18225
18311
  type: M.clause,
18226
- nameKw: B(T),
18312
+ nameKw: F(T),
18227
18313
  children: []
18228
18314
  })
18229
18315
  },
@@ -18239,7 +18325,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18239
18325
  symbols: [G.has("RESERVED_CLAUSE") ? { type: "RESERVED_CLAUSE" } : RESERVED_CLAUSE, "other_clause$ebnf$1"],
18240
18326
  postprocess: ([T, E]) => ({
18241
18327
  type: M.clause,
18242
- nameKw: B(T),
18328
+ nameKw: F(T),
18243
18329
  children: E
18244
18330
  })
18245
18331
  },
@@ -18250,7 +18336,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18250
18336
  symbols: [G.has("RESERVED_SET_OPERATION") ? { type: "RESERVED_SET_OPERATION" } : RESERVED_SET_OPERATION, "set_operation$ebnf$1"],
18251
18337
  postprocess: ([T, E]) => ({
18252
18338
  type: M.set_operation,
18253
- nameKw: B(T),
18339
+ nameKw: F(T),
18254
18340
  children: E
18255
18341
  })
18256
18342
  },
@@ -18274,37 +18360,37 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18274
18360
  {
18275
18361
  name: "expression_with_comments_",
18276
18362
  symbols: ["expression", "_"],
18277
- postprocess: ([T, E]) => F(T, { trailing: E })
18363
+ postprocess: ([T, E]) => Y(T, { trailing: E })
18278
18364
  },
18279
18365
  {
18280
18366
  name: "_expression_with_comments",
18281
18367
  symbols: ["_", "expression"],
18282
- postprocess: ([T, E]) => F(E, { leading: T })
18368
+ postprocess: ([T, E]) => Y(E, { leading: T })
18283
18369
  },
18284
18370
  {
18285
18371
  name: "_andless_expression_with_comments",
18286
18372
  symbols: ["_", "andless_expression"],
18287
- postprocess: ([T, E]) => F(E, { leading: T })
18373
+ postprocess: ([T, E]) => Y(E, { leading: T })
18288
18374
  },
18289
18375
  { name: "free_form_sql$subexpression$1", symbols: ["asteriskless_free_form_sql"] },
18290
18376
  { name: "free_form_sql$subexpression$1", symbols: ["asterisk"] },
18291
- { name: "free_form_sql", symbols: ["free_form_sql$subexpression$1"], postprocess: h },
18377
+ { name: "free_form_sql", symbols: ["free_form_sql$subexpression$1"], postprocess: V },
18292
18378
  { name: "asteriskless_free_form_sql$subexpression$1", symbols: ["asteriskless_andless_expression"] },
18293
18379
  { name: "asteriskless_free_form_sql$subexpression$1", symbols: ["logic_operator"] },
18294
18380
  { name: "asteriskless_free_form_sql$subexpression$1", symbols: ["comma"] },
18295
18381
  { name: "asteriskless_free_form_sql$subexpression$1", symbols: ["comment"] },
18296
18382
  { name: "asteriskless_free_form_sql$subexpression$1", symbols: ["other_keyword"] },
18297
- { name: "asteriskless_free_form_sql", symbols: ["asteriskless_free_form_sql$subexpression$1"], postprocess: h },
18383
+ { name: "asteriskless_free_form_sql", symbols: ["asteriskless_free_form_sql$subexpression$1"], postprocess: V },
18298
18384
  { name: "expression$subexpression$1", symbols: ["andless_expression"] },
18299
18385
  { name: "expression$subexpression$1", symbols: ["logic_operator"] },
18300
- { name: "expression", symbols: ["expression$subexpression$1"], postprocess: h },
18386
+ { name: "expression", symbols: ["expression$subexpression$1"], postprocess: V },
18301
18387
  { name: "andless_expression$subexpression$1", symbols: ["asteriskless_andless_expression"] },
18302
18388
  { name: "andless_expression$subexpression$1", symbols: ["asterisk"] },
18303
- { name: "andless_expression", symbols: ["andless_expression$subexpression$1"], postprocess: h },
18389
+ { name: "andless_expression", symbols: ["andless_expression$subexpression$1"], postprocess: V },
18304
18390
  { name: "asteriskless_andless_expression$subexpression$1", symbols: ["atomic_expression"] },
18305
18391
  { name: "asteriskless_andless_expression$subexpression$1", symbols: ["between_predicate"] },
18306
18392
  { name: "asteriskless_andless_expression$subexpression$1", symbols: ["case_expression"] },
18307
- { name: "asteriskless_andless_expression", symbols: ["asteriskless_andless_expression$subexpression$1"], postprocess: h },
18393
+ { name: "asteriskless_andless_expression", symbols: ["asteriskless_andless_expression$subexpression$1"], postprocess: V },
18308
18394
  { name: "atomic_expression$subexpression$1", symbols: ["array_subscript"] },
18309
18395
  { name: "atomic_expression$subexpression$1", symbols: ["function_call"] },
18310
18396
  { name: "atomic_expression$subexpression$1", symbols: ["property_access"] },
@@ -18317,13 +18403,13 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18317
18403
  { name: "atomic_expression$subexpression$1", symbols: ["literal"] },
18318
18404
  { name: "atomic_expression$subexpression$1", symbols: ["data_type"] },
18319
18405
  { name: "atomic_expression$subexpression$1", symbols: ["keyword"] },
18320
- { name: "atomic_expression", symbols: ["atomic_expression$subexpression$1"], postprocess: h },
18406
+ { name: "atomic_expression", symbols: ["atomic_expression$subexpression$1"], postprocess: V },
18321
18407
  {
18322
18408
  name: "array_subscript",
18323
18409
  symbols: [G.has("ARRAY_IDENTIFIER") ? { type: "ARRAY_IDENTIFIER" } : ARRAY_IDENTIFIER, "_", "square_brackets"],
18324
18410
  postprocess: ([T, E, R]) => ({
18325
18411
  type: M.array_subscript,
18326
- array: F({ type: M.identifier, quoted: !1, text: T.text }, { trailing: E }),
18412
+ array: Y({ type: M.identifier, quoted: !1, text: T.text }, { trailing: E }),
18327
18413
  parenthesis: R
18328
18414
  })
18329
18415
  },
@@ -18332,7 +18418,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18332
18418
  symbols: [G.has("ARRAY_KEYWORD") ? { type: "ARRAY_KEYWORD" } : ARRAY_KEYWORD, "_", "square_brackets"],
18333
18419
  postprocess: ([T, E, R]) => ({
18334
18420
  type: M.array_subscript,
18335
- array: F(B(T), { trailing: E }),
18421
+ array: Y(F(T), { trailing: E }),
18336
18422
  parenthesis: R
18337
18423
  })
18338
18424
  },
@@ -18341,7 +18427,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18341
18427
  symbols: [G.has("RESERVED_FUNCTION_NAME") ? { type: "RESERVED_FUNCTION_NAME" } : RESERVED_FUNCTION_NAME, "_", "parenthesis"],
18342
18428
  postprocess: ([T, E, R]) => ({
18343
18429
  type: M.function_call,
18344
- nameKw: F(B(T), { trailing: E }),
18430
+ nameKw: Y(F(T), { trailing: E }),
18345
18431
  parenthesis: R
18346
18432
  })
18347
18433
  },
@@ -18393,9 +18479,9 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18393
18479
  // %ARRAY_IDENTIFIER on the left side of <array_subscript>.
18394
18480
  ([T, E, R, A, [S]]) => ({
18395
18481
  type: M.property_access,
18396
- object: F(T, { trailing: E }),
18482
+ object: Y(T, { trailing: E }),
18397
18483
  operator: R.text,
18398
- property: F(S, { leading: A })
18484
+ property: Y(S, { leading: A })
18399
18485
  })
18400
18486
  )
18401
18487
  },
@@ -18404,10 +18490,10 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18404
18490
  symbols: [G.has("BETWEEN") ? { type: "BETWEEN" } : BETWEEN, "_", "andless_expression_chain", "_", G.has("AND") ? { type: "AND" } : AND, "_", "andless_expression"],
18405
18491
  postprocess: ([T, E, R, A, S, e, O]) => ({
18406
18492
  type: M.between_predicate,
18407
- betweenKw: B(T),
18408
- expr1: lI(R, { leading: E, trailing: A }),
18409
- andKw: B(S),
18410
- expr2: [F(O, { leading: e })]
18493
+ betweenKw: F(T),
18494
+ expr1: HI(R, { leading: E, trailing: A }),
18495
+ andKw: F(S),
18496
+ expr2: [Y(O, { leading: e })]
18411
18497
  })
18412
18498
  },
18413
18499
  { name: "case_expression$ebnf$1", symbols: ["expression_chain_"], postprocess: BE },
@@ -18419,8 +18505,8 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18419
18505
  symbols: [G.has("CASE") ? { type: "CASE" } : CASE, "_", "case_expression$ebnf$1", "case_expression$ebnf$2", G.has("END") ? { type: "END" } : END],
18420
18506
  postprocess: ([T, E, R, A, S]) => ({
18421
18507
  type: M.case_expression,
18422
- caseKw: F(B(T), { trailing: E }),
18423
- endKw: B(S),
18508
+ caseKw: Y(F(T), { trailing: E }),
18509
+ endKw: F(S),
18424
18510
  expr: R || [],
18425
18511
  clauses: A
18426
18512
  })
@@ -18430,8 +18516,8 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18430
18516
  symbols: [G.has("WHEN") ? { type: "WHEN" } : WHEN, "_", "expression_chain_", G.has("THEN") ? { type: "THEN" } : THEN, "_", "expression_chain_"],
18431
18517
  postprocess: ([T, E, R, A, S, e]) => ({
18432
18518
  type: M.case_when,
18433
- whenKw: F(B(T), { trailing: E }),
18434
- thenKw: F(B(A), { trailing: S }),
18519
+ whenKw: Y(F(T), { trailing: E }),
18520
+ thenKw: Y(F(A), { trailing: S }),
18435
18521
  condition: R,
18436
18522
  result: e
18437
18523
  })
@@ -18441,7 +18527,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18441
18527
  symbols: [G.has("ELSE") ? { type: "ELSE" } : ELSE, "_", "expression_chain_"],
18442
18528
  postprocess: ([T, E, R]) => ({
18443
18529
  type: M.case_else,
18444
- elseKw: F(B(T), { trailing: E }),
18530
+ elseKw: Y(F(T), { trailing: E }),
18445
18531
  result: R
18446
18532
  })
18447
18533
  },
@@ -18470,21 +18556,21 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18470
18556
  {
18471
18557
  name: "keyword",
18472
18558
  symbols: ["keyword$subexpression$1"],
18473
- postprocess: ([[T]]) => B(T)
18559
+ postprocess: ([[T]]) => F(T)
18474
18560
  },
18475
18561
  { name: "data_type$subexpression$1", symbols: [G.has("RESERVED_DATA_TYPE") ? { type: "RESERVED_DATA_TYPE" } : RESERVED_DATA_TYPE] },
18476
18562
  { name: "data_type$subexpression$1", symbols: [G.has("RESERVED_DATA_TYPE_PHRASE") ? { type: "RESERVED_DATA_TYPE_PHRASE" } : RESERVED_DATA_TYPE_PHRASE] },
18477
18563
  {
18478
18564
  name: "data_type",
18479
18565
  symbols: ["data_type$subexpression$1"],
18480
- postprocess: ([[T]]) => oT(T)
18566
+ postprocess: ([[T]]) => aT(T)
18481
18567
  },
18482
18568
  {
18483
18569
  name: "data_type",
18484
18570
  symbols: [G.has("RESERVED_PARAMETERIZED_DATA_TYPE") ? { type: "RESERVED_PARAMETERIZED_DATA_TYPE" } : RESERVED_PARAMETERIZED_DATA_TYPE, "_", "parenthesis"],
18485
18571
  postprocess: ([T, E, R]) => ({
18486
18572
  type: M.parameterized_data_type,
18487
- dataType: F(oT(T), { trailing: E }),
18573
+ dataType: Y(aT(T), { trailing: E }),
18488
18574
  parenthesis: R
18489
18575
  })
18490
18576
  },
@@ -18494,7 +18580,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18494
18580
  {
18495
18581
  name: "logic_operator",
18496
18582
  symbols: ["logic_operator$subexpression$1"],
18497
- postprocess: ([[T]]) => B(T)
18583
+ postprocess: ([[T]]) => F(T)
18498
18584
  },
18499
18585
  { name: "other_keyword$subexpression$1", symbols: [G.has("WHEN") ? { type: "WHEN" } : WHEN] },
18500
18586
  { name: "other_keyword$subexpression$1", symbols: [G.has("THEN") ? { type: "THEN" } : THEN] },
@@ -18503,7 +18589,7 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18503
18589
  {
18504
18590
  name: "other_keyword",
18505
18591
  symbols: ["other_keyword$subexpression$1"],
18506
- postprocess: ([[T]]) => B(T)
18592
+ postprocess: ([[T]]) => F(T)
18507
18593
  },
18508
18594
  { name: "_$ebnf$1", symbols: [] },
18509
18595
  { name: "_$ebnf$1", symbols: ["_$ebnf$1", "comment"], postprocess: (T) => T[0].concat([T[1]]) },
@@ -18537,13 +18623,13 @@ const G = new hT((T) => []), h = ([[T]]) => T, B = (T) => ({
18537
18623
  }
18538
18624
  ],
18539
18625
  ParserStart: "main"
18540
- }, { Parser: uI, Grammar: BI } = DI;
18541
- function FI(T) {
18626
+ }, { Parser: BI, Grammar: FI } = iI;
18627
+ function YI(T) {
18542
18628
  let E = {};
18543
- const R = new hT((S) => [
18544
- ...iI(T.tokenize(S, E)),
18545
- HT(S.length)
18546
- ]), A = new uI(BI.fromCompiled(HI), { lexer: R });
18629
+ const R = new fT((S) => [
18630
+ ...PI(T.tokenize(S, E)),
18631
+ uT(S.length)
18632
+ ]), A = new BI(FI.fromCompiled(uI), { lexer: R });
18547
18633
  return {
18548
18634
  parse: (S, e) => {
18549
18635
  E = e;
@@ -18595,16 +18681,16 @@ class WT {
18595
18681
  }
18596
18682
  }
18597
18683
  trimHorizontalWhitespace() {
18598
- for (; YI(v(this.items)); )
18684
+ for (; mI(Q(this.items)); )
18599
18685
  this.items.pop();
18600
18686
  }
18601
18687
  trimWhitespace() {
18602
- for (; mI(v(this.items)); )
18688
+ for (; pI(Q(this.items)); )
18603
18689
  this.items.pop();
18604
18690
  }
18605
18691
  addNewline(E) {
18606
18692
  if (this.items.length > 0)
18607
- switch (v(this.items)) {
18693
+ switch (Q(this.items)) {
18608
18694
  case n.NEWLINE:
18609
18695
  this.items.pop(), this.items.push(E);
18610
18696
  break;
@@ -18646,7 +18732,7 @@ class WT {
18646
18732
  }
18647
18733
  }
18648
18734
  }
18649
- const YI = (T) => T === n.SPACE || T === n.SINGLE_INDENT, mI = (T) => T === n.SPACE || T === n.SINGLE_INDENT || T === n.NEWLINE;
18735
+ const mI = (T) => T === n.SPACE || T === n.SINGLE_INDENT, pI = (T) => T === n.SPACE || T === n.SINGLE_INDENT || T === n.NEWLINE;
18650
18736
  function MT(T, E) {
18651
18737
  if (E === "standard")
18652
18738
  return T;
@@ -18654,10 +18740,10 @@ function MT(T, E) {
18654
18740
  return T.length >= 10 && T.includes(" ") && ([T, ...R] = T.split(" ")), E === "tabularLeft" ? T = T.padEnd(9, " ") : T = T.padStart(9, " "), T + ["", ...R].join(" ");
18655
18741
  }
18656
18742
  function UT(T) {
18657
- return LR(T) || T === i.RESERVED_CLAUSE || T === i.RESERVED_SELECT || T === i.RESERVED_SET_OPERATION || T === i.RESERVED_JOIN || T === i.LIMIT;
18743
+ return _R(T) || T === i.RESERVED_CLAUSE || T === i.RESERVED_SELECT || T === i.RESERVED_SET_OPERATION || T === i.RESERVED_JOIN || T === i.LIMIT;
18658
18744
  }
18659
- const FE = "top-level", pI = "block-level";
18660
- class fT {
18745
+ const FE = "top-level", dI = "block-level";
18746
+ class XT {
18661
18747
  /**
18662
18748
  * @param {string} indent A string to indent with
18663
18749
  */
@@ -18686,14 +18772,14 @@ class fT {
18686
18772
  * Increases indentation by one block-level indent.
18687
18773
  */
18688
18774
  increaseBlockLevel() {
18689
- this.indentTypes.push(pI);
18775
+ this.indentTypes.push(dI);
18690
18776
  }
18691
18777
  /**
18692
18778
  * Decreases indentation by one top-level indent.
18693
18779
  * Does nothing when the previous indent is not top-level.
18694
18780
  */
18695
18781
  decreaseTopLevel() {
18696
- this.indentTypes.length > 0 && v(this.indentTypes) === FE && this.indentTypes.pop();
18782
+ this.indentTypes.length > 0 && Q(this.indentTypes) === FE && this.indentTypes.pop();
18697
18783
  }
18698
18784
  /**
18699
18785
  * Decreases indentation by one block-level indent.
@@ -18705,9 +18791,9 @@ class fT {
18705
18791
  ;
18706
18792
  }
18707
18793
  }
18708
- class dI extends WT {
18794
+ class hI extends WT {
18709
18795
  constructor(E) {
18710
- super(new fT("")), this.expressionWidth = E, this.length = 0, this.trailingSpace = !1;
18796
+ super(new XT("")), this.expressionWidth = E, this.length = 0, this.trailingSpace = !1;
18711
18797
  }
18712
18798
  add(...E) {
18713
18799
  if (E.forEach((R) => this.addToLength(R)), this.length > this.expressionWidth)
@@ -18900,7 +18986,7 @@ class z {
18900
18986
  // first line starts with /* or /**
18901
18987
  /^\/\*\*?$/.test(R[0]) && // intermediate lines start with *
18902
18988
  R.slice(1, R.length - 1).every((A) => /^\s*\*/.test(A)) && // last line ends with */
18903
- /^\s*\*\/$/.test(v(R))
18989
+ /^\s*\*\/$/.test(Q(R))
18904
18990
  );
18905
18991
  }
18906
18992
  // Breaks up block comment to multiple lines.
@@ -18949,7 +19035,7 @@ class z {
18949
19035
  cfg: this.cfg,
18950
19036
  dialectCfg: this.dialectCfg,
18951
19037
  params: this.params,
18952
- layout: new dI(this.cfg.expressionWidth),
19038
+ layout: new hI(this.cfg.expressionWidth),
18953
19039
  inline: !0
18954
19040
  }).format(E);
18955
19041
  } catch (A) {
@@ -18991,7 +19077,7 @@ class z {
18991
19077
  showNonTabularKw(E) {
18992
19078
  switch (this.cfg.keywordCase) {
18993
19079
  case "preserve":
18994
- return Z(E.raw);
19080
+ return q(E.raw);
18995
19081
  case "upper":
18996
19082
  return E.text;
18997
19083
  case "lower":
@@ -19005,7 +19091,7 @@ class z {
19005
19091
  showNonTabularFunctionKw(E) {
19006
19092
  switch (this.cfg.functionCase) {
19007
19093
  case "preserve":
19008
- return Z(E.raw);
19094
+ return q(E.raw);
19009
19095
  case "upper":
19010
19096
  return E.text;
19011
19097
  case "lower":
@@ -19027,7 +19113,7 @@ class z {
19027
19113
  showDataType(E) {
19028
19114
  switch (this.cfg.dataTypeCase) {
19029
19115
  case "preserve":
19030
- return Z(E.raw);
19116
+ return q(E.raw);
19031
19117
  case "upper":
19032
19118
  return E.text;
19033
19119
  case "lower":
@@ -19037,7 +19123,7 @@ class z {
19037
19123
  }
19038
19124
  class VI {
19039
19125
  constructor(E, R) {
19040
- this.dialect = E, this.cfg = R, this.params = new CI(this.cfg.params);
19126
+ this.dialect = E, this.cfg = R, this.params = new LI(this.cfg.params);
19041
19127
  }
19042
19128
  /**
19043
19129
  * Formats an SQL query.
@@ -19049,7 +19135,7 @@ class VI {
19049
19135
  return this.formatAst(R).trimEnd();
19050
19136
  }
19051
19137
  parse(E) {
19052
- return FI(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19138
+ return YI(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19053
19139
  }
19054
19140
  formatAst(E) {
19055
19141
  return E.map((R) => this.formatStatement(R)).join(`
@@ -19060,14 +19146,14 @@ class VI {
19060
19146
  cfg: this.cfg,
19061
19147
  dialectCfg: this.dialect.formatOptions,
19062
19148
  params: this.params,
19063
- layout: new WT(new fT(tI(this.cfg)))
19149
+ layout: new WT(new XT(CI(this.cfg)))
19064
19150
  }).format(E.children);
19065
19151
  return E.hasSemicolon && (this.cfg.newlineBeforeSemicolon ? R.add(n.NEWLINE, ";") : R.add(n.NO_NEWLINE, ";")), R.toString();
19066
19152
  }
19067
19153
  }
19068
19154
  class k extends Error {
19069
19155
  }
19070
- function hI(T) {
19156
+ function fI(T) {
19071
19157
  const E = [
19072
19158
  "multilineLists",
19073
19159
  "newlineBeforeOpenParen",
@@ -19081,17 +19167,17 @@ function hI(T) {
19081
19167
  throw new k(`${R} config is no more supported.`);
19082
19168
  if (T.expressionWidth <= 0)
19083
19169
  throw new k(`expressionWidth config must be positive number. Received ${T.expressionWidth} instead.`);
19084
- if (T.params && !WI(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !fI(T.paramTypes))
19170
+ if (T.params && !WI(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !XI(T.paramTypes))
19085
19171
  throw new k("Empty regex given in custom paramTypes. That would result in matching infinite amount of parameters.");
19086
19172
  return T;
19087
19173
  }
19088
19174
  function WI(T) {
19089
19175
  return (T instanceof Array ? T : Object.values(T)).every((R) => typeof R == "string");
19090
19176
  }
19091
- function fI(T) {
19177
+ function XI(T) {
19092
19178
  return T.custom && Array.isArray(T.custom) ? T.custom.every((E) => E.regex !== "") : !0;
19093
19179
  }
19094
- var XI = function(T, E) {
19180
+ var bI = function(T, E) {
19095
19181
  var R = {};
19096
19182
  for (var A in T) Object.prototype.hasOwnProperty.call(T, A) && E.indexOf(A) < 0 && (R[A] = T[A]);
19097
19183
  if (T != null && typeof Object.getOwnPropertySymbols == "function")
@@ -19099,7 +19185,7 @@ var XI = function(T, E) {
19099
19185
  E.indexOf(A[S]) < 0 && Object.prototype.propertyIsEnumerable.call(T, A[S]) && (R[A[S]] = T[A[S]]);
19100
19186
  return R;
19101
19187
  };
19102
- const XT = {
19188
+ const bT = {
19103
19189
  bigquery: "bigquery",
19104
19190
  db2: "db2",
19105
19191
  db2i: "db2i",
@@ -19120,7 +19206,7 @@ const XT = {
19120
19206
  tsql: "transactsql",
19121
19207
  singlestoredb: "singlestoredb",
19122
19208
  snowflake: "snowflake"
19123
- }, bI = Object.keys(XT), KI = {
19209
+ }, yI = Object.keys(bT), KI = {
19124
19210
  tabWidth: 2,
19125
19211
  useTabs: !1,
19126
19212
  keywordCase: "preserve",
@@ -19133,21 +19219,21 @@ const XT = {
19133
19219
  linesBetweenQueries: 1,
19134
19220
  denseOperators: !1,
19135
19221
  newlineBeforeSemicolon: !1
19136
- }, yI = (T, E = {}) => {
19137
- if (typeof E.language == "string" && !bI.includes(E.language))
19222
+ }, $I = (T, E = {}) => {
19223
+ if (typeof E.language == "string" && !yI.includes(E.language))
19138
19224
  throw new k(`Unsupported SQL dialect: ${E.language}`);
19139
- const R = XT[E.language || "sql"];
19140
- return $I(T, Object.assign(Object.assign({}, E), { dialect: ve[R] }));
19141
- }, $I = (T, E) => {
19142
- var { dialect: R } = E, A = XI(E, ["dialect"]);
19225
+ const R = bT[E.language || "sql"];
19226
+ return gI(T, Object.assign(Object.assign({}, E), { dialect: Qe[R] }));
19227
+ }, gI = (T, E) => {
19228
+ var { dialect: R } = E, A = bI(E, ["dialect"]);
19143
19229
  if (typeof T != "string")
19144
19230
  throw new Error("Invalid query argument. Expected string, instead got " + typeof T);
19145
- const S = hI(Object.assign(Object.assign({}, KI), A));
19146
- return new VI(OI(R), S).format(T);
19231
+ const S = fI(Object.assign(Object.assign({}, KI), A));
19232
+ return new VI(NI(R), S).format(T);
19147
19233
  };
19148
19234
  function GT(T, E) {
19149
19235
  try {
19150
- return yI(T, {
19236
+ return $I(T, {
19151
19237
  language: {
19152
19238
  postgres: "postgresql",
19153
19239
  mysql: "mysql",
@@ -19163,7 +19249,7 @@ function GT(T, E) {
19163
19249
  return console.warn("SQL formatting failed:", R), T;
19164
19250
  }
19165
19251
  }
19166
- class WE {
19252
+ class fE {
19167
19253
  cubes = /* @__PURE__ */ new Map();
19168
19254
  dbExecutor;
19169
19255
  metadataCache;
@@ -19280,9 +19366,9 @@ class WE {
19280
19366
  */
19281
19367
  generateCubeMetadata(E) {
19282
19368
  const R = Object.keys(E.measures), A = Object.keys(E.dimensions), S = new Array(R.length), e = new Array(A.length);
19283
- for (let N = 0; N < R.length; N++) {
19284
- const D = R[N], I = E.measures[D];
19285
- S[N] = {
19369
+ for (let t = 0; t < R.length; t++) {
19370
+ const D = R[t], I = E.measures[D];
19371
+ S[t] = {
19286
19372
  name: `${E.name}.${D}`,
19287
19373
  title: I.title || D,
19288
19374
  shortTitle: I.title || D,
@@ -19292,9 +19378,9 @@ class WE {
19292
19378
  description: I.description
19293
19379
  };
19294
19380
  }
19295
- for (let N = 0; N < A.length; N++) {
19296
- const D = A[N], I = E.dimensions[D];
19297
- e[N] = {
19381
+ for (let t = 0; t < A.length; t++) {
19382
+ const D = A[t], I = E.dimensions[D];
19383
+ e[t] = {
19298
19384
  name: `${E.name}.${D}`,
19299
19385
  title: I.title || D,
19300
19386
  shortTitle: I.title || D,
@@ -19306,12 +19392,12 @@ class WE {
19306
19392
  }
19307
19393
  const O = [];
19308
19394
  if (E.joins)
19309
- for (const [, N] of Object.entries(E.joins)) {
19310
- const D = typeof N.targetCube == "function" ? N.targetCube() : N.targetCube;
19395
+ for (const [, t] of Object.entries(E.joins)) {
19396
+ const D = typeof t.targetCube == "function" ? t.targetCube() : t.targetCube;
19311
19397
  O.push({
19312
19398
  targetCube: D.name,
19313
- relationship: N.relationship,
19314
- joinFields: N.on.map((I) => ({
19399
+ relationship: t.relationship,
19400
+ joinFields: t.on.map((I) => ({
19315
19401
  sourceField: this.getColumnName(I.source),
19316
19402
  targetField: this.getColumnName(I.target)
19317
19403
  }))
@@ -19337,9 +19423,9 @@ class WE {
19337
19423
  throw new Error(`Cube '${E}' not found`);
19338
19424
  if (!this.dbExecutor)
19339
19425
  throw new Error("Database executor not configured");
19340
- const O = await new OE(this.dbExecutor).generateSQL(S, R, A), N = this.dbExecutor.getEngineType();
19426
+ const O = await new OE(this.dbExecutor).generateSQL(S, R, A), t = this.dbExecutor.getEngineType();
19341
19427
  return {
19342
- sql: GT(O.sql, N),
19428
+ sql: GT(O.sql, t),
19343
19429
  params: O.params
19344
19430
  };
19345
19431
  }
@@ -19392,10 +19478,10 @@ class WE {
19392
19478
  * Ensures all referenced cubes and fields exist
19393
19479
  */
19394
19480
  validateQuery(E) {
19395
- return bT(this.cubes, E);
19481
+ return yT(this.cubes, E);
19396
19482
  }
19397
19483
  }
19398
- function bT(T, E) {
19484
+ function yT(T, E) {
19399
19485
  const R = [], A = /* @__PURE__ */ new Set();
19400
19486
  if (E.measures)
19401
19487
  for (const S of E.measures) {
@@ -19405,12 +19491,12 @@ function bT(T, E) {
19405
19491
  continue;
19406
19492
  }
19407
19493
  A.add(e);
19408
- const N = T.get(e);
19409
- if (!N) {
19494
+ const t = T.get(e);
19495
+ if (!t) {
19410
19496
  R.push(`Cube '${e}' not found (referenced in measure '${S}')`);
19411
19497
  continue;
19412
19498
  }
19413
- N.measures[O] || R.push(`Measure '${O}' not found on cube '${e}'`);
19499
+ t.measures[O] || R.push(`Measure '${O}' not found on cube '${e}'`);
19414
19500
  }
19415
19501
  if (E.dimensions)
19416
19502
  for (const S of E.dimensions) {
@@ -19420,12 +19506,12 @@ function bT(T, E) {
19420
19506
  continue;
19421
19507
  }
19422
19508
  A.add(e);
19423
- const N = T.get(e);
19424
- if (!N) {
19509
+ const t = T.get(e);
19510
+ if (!t) {
19425
19511
  R.push(`Cube '${e}' not found (referenced in dimension '${S}')`);
19426
19512
  continue;
19427
19513
  }
19428
- N.dimensions[O] || R.push(`Dimension '${O}' not found on cube '${e}'`);
19514
+ t.dimensions[O] || R.push(`Dimension '${O}' not found on cube '${e}'`);
19429
19515
  }
19430
19516
  if (E.timeDimensions)
19431
19517
  for (const S of E.timeDimensions) {
@@ -19435,12 +19521,12 @@ function bT(T, E) {
19435
19521
  continue;
19436
19522
  }
19437
19523
  A.add(e);
19438
- const N = T.get(e);
19439
- if (!N) {
19524
+ const t = T.get(e);
19525
+ if (!t) {
19440
19526
  R.push(`Cube '${e}' not found (referenced in timeDimension '${S.dimension}')`);
19441
19527
  continue;
19442
19528
  }
19443
- N.dimensions[O] || R.push(`TimeDimension '${O}' not found on cube '${e}' (must be a dimension with time type)`);
19529
+ t.dimensions[O] || R.push(`TimeDimension '${O}' not found on cube '${e}' (must be a dimension with time type)`);
19444
19530
  }
19445
19531
  if (E.filters)
19446
19532
  for (const S of E.filters)
@@ -19452,8 +19538,8 @@ function bT(T, E) {
19452
19538
  }
19453
19539
  function KT(T, E, R, A) {
19454
19540
  if ("and" in T || "or" in T) {
19455
- const N = T.and || T.or || [];
19456
- for (const D of N)
19541
+ const t = T.and || T.or || [];
19542
+ for (const D of t)
19457
19543
  KT(D, E, R, A);
19458
19544
  return;
19459
19545
  }
@@ -19474,17 +19560,17 @@ function KT(T, E, R, A) {
19474
19560
  }
19475
19561
  !O.dimensions[e] && !O.measures[e] && R.push(`Filter field '${e}' not found on cube '${S}' (must be a dimension or measure)`);
19476
19562
  }
19477
- function vI(T) {
19478
- return new WE(T);
19563
+ function QI(T) {
19564
+ return new fE(T);
19479
19565
  }
19480
- const gI = new WE(), QI = gI;
19481
- function ZI(T) {
19482
- return new WE({
19566
+ const JI = new fE(), ZI = JI;
19567
+ function qI(T) {
19568
+ return new fE({
19483
19569
  drizzle: T.drizzle,
19484
19570
  schema: T.schema
19485
19571
  });
19486
19572
  }
19487
- const qI = {
19573
+ const jI = {
19488
19574
  /**
19489
19575
  * Create a simple query builder
19490
19576
  */
@@ -19591,26 +19677,26 @@ const qI = {
19591
19677
  }
19592
19678
  };
19593
19679
  export {
19594
- VE as BaseDatabaseExecutor,
19680
+ hE as BaseDatabaseExecutor,
19595
19681
  lT as MySQLExecutor,
19596
- ZT as PostgresExecutor,
19597
- TR as QueryBuilder,
19682
+ qT as PostgresExecutor,
19683
+ RR as QueryBuilder,
19598
19684
  OE as QueryExecutor,
19599
- RR as QueryPlanner,
19685
+ AR as QueryPlanner,
19600
19686
  kT as SQLiteExecutor,
19601
- WE as SemanticLayerCompiler,
19602
- qI as SemanticLayerUtils,
19687
+ fE as SemanticLayerCompiler,
19688
+ jI as SemanticLayerUtils,
19603
19689
  JE as createDatabaseExecutor,
19604
- ZI as createDrizzleSemanticLayer,
19605
- wI as createMultiCubeContext,
19606
- qT as createMySQLExecutor,
19690
+ qI as createDrizzleSemanticLayer,
19691
+ xI as createMultiCubeContext,
19692
+ jT as createMySQLExecutor,
19607
19693
  $E as createPostgresExecutor,
19608
19694
  gE as createSQLiteExecutor,
19609
- vI as createSemanticLayer,
19610
- QI as defaultSemanticLayer,
19611
- xI as defineCube,
19612
- ER as getJoinType,
19695
+ QI as createSemanticLayer,
19696
+ ZI as defaultSemanticLayer,
19697
+ vI as defineCube,
19698
+ HT as getJoinType,
19613
19699
  wE as resolveCubeReference,
19614
- W as resolveSqlExpression,
19615
- gI as semanticLayer
19700
+ f as resolveSqlExpression,
19701
+ JI as semanticLayer
19616
19702
  };