drizzle-cube 0.1.36 → 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,27 +1,27 @@
1
- const h = Symbol.for("drizzle:entityKind");
1
+ const f = Symbol.for("drizzle:entityKind");
2
2
  function m(T, E) {
3
3
  if (!T || typeof T != "object")
4
4
  return !1;
5
5
  if (T instanceof E)
6
6
  return !0;
7
- if (!Object.prototype.hasOwnProperty.call(E, h))
7
+ if (!Object.prototype.hasOwnProperty.call(E, f))
8
8
  throw new Error(
9
9
  `Class "${E.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
10
10
  );
11
11
  let R = Object.getPrototypeOf(T).constructor;
12
12
  if (R)
13
13
  for (; R; ) {
14
- if (h in R && R[h] === E[h])
14
+ if (f in R && R[f] === E[f])
15
15
  return !0;
16
16
  R = Object.getPrototypeOf(R);
17
17
  }
18
18
  return !1;
19
19
  }
20
- class TE {
20
+ class RE {
21
21
  constructor(E, R) {
22
22
  this.table = E, this.config = R, this.name = R.name, this.keyAsName = R.keyAsName, this.notNull = R.notNull, this.default = R.default, this.defaultFn = R.defaultFn, this.onUpdateFn = R.onUpdateFn, this.hasDefault = R.hasDefault, this.primary = R.primaryKey, this.isUnique = R.isUnique, this.uniqueName = R.uniqueName, this.uniqueType = R.uniqueType, this.dataType = R.dataType, this.columnType = R.columnType, this.generated = R.generated, this.generatedIdentity = R.generatedIdentity;
23
23
  }
24
- static [h] = "Column";
24
+ static [f] = "Column";
25
25
  name;
26
26
  keyAsName;
27
27
  primary;
@@ -51,11 +51,11 @@ class TE {
51
51
  }
52
52
  }
53
53
  const _E = Symbol.for("drizzle:Name"), kE = Symbol.for("drizzle:isPgEnum");
54
- function _R(T) {
54
+ function rR(T) {
55
55
  return !!T && typeof T == "function" && kE in T && T[kE] === !0;
56
56
  }
57
57
  class gT {
58
- static [h] = "Subquery";
58
+ static [f] = "Subquery";
59
59
  constructor(E, R, A, e = !1, S = []) {
60
60
  this._ = {
61
61
  brand: "Subquery",
@@ -70,13 +70,13 @@ class gT {
70
70
  // return new SQL([this]);
71
71
  // }
72
72
  }
73
- const rR = {
73
+ const nR = {
74
74
  startActiveSpan(T, E) {
75
75
  return E();
76
76
  }
77
- }, z = Symbol.for("drizzle:ViewBaseConfig"), rE = Symbol.for("drizzle:Schema"), zE = Symbol.for("drizzle:Columns"), ET = Symbol.for("drizzle:ExtraConfigColumns"), nE = Symbol.for("drizzle:OriginalName"), iE = Symbol.for("drizzle:BaseName"), IE = Symbol.for("drizzle:IsAlias"), TT = Symbol.for("drizzle:ExtraConfigBuilder"), nR = Symbol.for("drizzle:IsDrizzleTable");
77
+ }, EE = Symbol.for("drizzle:ViewBaseConfig"), rE = Symbol.for("drizzle:Schema"), zE = Symbol.for("drizzle:Columns"), ET = Symbol.for("drizzle:ExtraConfigColumns"), nE = Symbol.for("drizzle:OriginalName"), iE = Symbol.for("drizzle:BaseName"), OE = Symbol.for("drizzle:IsAlias"), TT = Symbol.for("drizzle:ExtraConfigBuilder"), iR = Symbol.for("drizzle:IsDrizzleTable");
78
78
  class W {
79
- static [h] = "Table";
79
+ static [f] = "Table";
80
80
  /** @internal */
81
81
  static Symbol = {
82
82
  Name: _E,
@@ -85,7 +85,7 @@ class W {
85
85
  Columns: zE,
86
86
  ExtraConfigColumns: ET,
87
87
  BaseName: iE,
88
- IsAlias: IE,
88
+ IsAlias: OE,
89
89
  ExtraConfigBuilder: TT
90
90
  };
91
91
  /**
@@ -110,9 +110,9 @@ class W {
110
110
  */
111
111
  [iE];
112
112
  /** @internal */
113
- [IE] = !1;
113
+ [OE] = !1;
114
114
  /** @internal */
115
- [nR] = !0;
115
+ [iR] = !0;
116
116
  /** @internal */
117
117
  [TT] = void 0;
118
118
  constructor(E, R, A) {
@@ -122,14 +122,14 @@ class W {
122
122
  function wT(T) {
123
123
  return T != null && typeof T.getSQL == "function";
124
124
  }
125
- function iR(T) {
125
+ function DR(T) {
126
126
  const E = { sql: "", params: [] };
127
127
  for (const R of T)
128
128
  E.sql += R.sql, E.params.push(...R.params), R.typings?.length && (E.typings || (E.typings = []), E.typings.push(...R.typings));
129
129
  return E;
130
130
  }
131
131
  class d {
132
- static [h] = "StringChunk";
132
+ static [f] = "StringChunk";
133
133
  value;
134
134
  constructor(E) {
135
135
  this.value = Array.isArray(E) ? E : [E];
@@ -149,7 +149,7 @@ class u {
149
149
  );
150
150
  }
151
151
  }
152
- static [h] = "SQL";
152
+ static [f] = "SQL";
153
153
  /** @internal */
154
154
  decoder = JT;
155
155
  shouldInlineParams = !1;
@@ -159,7 +159,7 @@ class u {
159
159
  return this.queryChunks.push(...E.queryChunks), this;
160
160
  }
161
161
  toQuery(E) {
162
- return rR.startActiveSpan("drizzle.buildSQL", (R) => {
162
+ return nR.startActiveSpan("drizzle.buildSQL", (R) => {
163
163
  const A = this.buildQueryFromSourceParams(this.queryChunks, E);
164
164
  return R?.setAttributes({
165
165
  "drizzle.query.text": A.sql,
@@ -179,7 +179,7 @@ class u {
179
179
  inlineParams: r,
180
180
  paramStartIndex: O
181
181
  } = A;
182
- return iR(E.map((I) => {
182
+ return DR(E.map((I) => {
183
183
  if (m(I, d))
184
184
  return { sql: I.value.join(""), params: [] };
185
185
  if (m(I, JE))
@@ -200,29 +200,29 @@ class u {
200
200
  if (m(I, W)) {
201
201
  const s = I[W.Symbol.Schema], L = I[W.Symbol.Name];
202
202
  return {
203
- sql: s === void 0 || I[IE] ? S(L) : S(s) + "." + S(L),
203
+ sql: s === void 0 || I[OE] ? S(L) : S(s) + "." + S(L),
204
204
  params: []
205
205
  };
206
206
  }
207
- if (m(I, TE)) {
207
+ if (m(I, RE)) {
208
208
  const s = e.getColumnCasing(I);
209
209
  if (R.invokeSource === "indexes")
210
210
  return { sql: S(s), params: [] };
211
211
  const L = I.table[W.Symbol.Schema];
212
212
  return {
213
- sql: I.table[IE] || L === void 0 ? S(I.table[W.Symbol.Name]) + "." + S(s) : S(L) + "." + S(I.table[W.Symbol.Name]) + "." + S(s),
213
+ sql: I.table[OE] || L === void 0 ? S(I.table[W.Symbol.Name]) + "." + S(s) : S(L) + "." + S(I.table[W.Symbol.Name]) + "." + S(s),
214
214
  params: []
215
215
  };
216
216
  }
217
217
  if (m(I, vT)) {
218
- const s = I[z].schema, L = I[z].name;
218
+ const s = I[EE].schema, L = I[EE].name;
219
219
  return {
220
- sql: s === void 0 || I[z].isAlias ? S(L) : S(s) + "." + S(L),
220
+ sql: s === void 0 || I[EE].isAlias ? S(L) : S(s) + "." + S(L),
221
221
  params: []
222
222
  };
223
223
  }
224
- if (m(I, OE)) {
225
- if (m(I.value, NE))
224
+ if (m(I, NE)) {
225
+ if (m(I.value, sE))
226
226
  return { sql: N(O.value++, I), params: [I], typings: ["none"] };
227
227
  const s = I.value === null ? null : I.encoder.mapToDriverValue(I.value);
228
228
  if (m(s, u))
@@ -232,12 +232,12 @@ class u {
232
232
  let L = ["none"];
233
233
  return t && (L = [t(I.encoder)]), { sql: N(O.value++, s), params: [s], typings: L };
234
234
  }
235
- return m(I, NE) ? { sql: N(O.value++, I), params: [I], typings: ["none"] } : m(I, u.Aliased) && I.fieldAlias !== void 0 ? { sql: S(I.fieldAlias), params: [] } : m(I, gT) ? I._.isWith ? { sql: S(I._.alias), params: [] } : this.buildQueryFromSourceParams([
235
+ return m(I, sE) ? { sql: N(O.value++, I), params: [I], typings: ["none"] } : m(I, u.Aliased) && I.fieldAlias !== void 0 ? { sql: S(I.fieldAlias), params: [] } : m(I, gT) ? I._.isWith ? { sql: S(I._.alias), params: [] } : this.buildQueryFromSourceParams([
236
236
  new d("("),
237
237
  I._.sql,
238
238
  new d(") "),
239
239
  new JE(I._.alias)
240
- ], A) : _R(I) ? I.schema ? { sql: S(I.schema) + "." + S(I.enumName), params: [] } : { sql: S(I.enumName), params: [] } : wT(I) ? I.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([I.getSQL()], A) : this.buildQueryFromSourceParams([
240
+ ], A) : rR(I) ? I.schema ? { sql: S(I.schema) + "." + S(I.enumName), params: [] } : { sql: S(I.enumName), params: [] } : wT(I) ? I.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([I.getSQL()], A) : this.buildQueryFromSourceParams([
241
241
  new d("("),
242
242
  I.getSQL(),
243
243
  new d(")")
@@ -283,13 +283,13 @@ class JE {
283
283
  constructor(E) {
284
284
  this.value = E;
285
285
  }
286
- static [h] = "Name";
286
+ static [f] = "Name";
287
287
  brand;
288
288
  getSQL() {
289
289
  return new u([this]);
290
290
  }
291
291
  }
292
- function DR(T) {
292
+ function aR(T) {
293
293
  return typeof T == "object" && T !== null && "mapToDriverValue" in T && typeof T.mapToDriverValue == "function";
294
294
  }
295
295
  const JT = {
@@ -301,7 +301,7 @@ const JT = {
301
301
  ...JT,
302
302
  ...xT
303
303
  });
304
- class OE {
304
+ class NE {
305
305
  /**
306
306
  * @param value - Parameter value
307
307
  * @param encoder - Encoder to convert the value to a driver parameter
@@ -309,7 +309,7 @@ class OE {
309
309
  constructor(E, R = xT) {
310
310
  this.value = E, this.encoder = R;
311
311
  }
312
- static [h] = "Param";
312
+ static [f] = "Param";
313
313
  brand;
314
314
  getSQL() {
315
315
  return new u([this]);
@@ -347,11 +347,11 @@ function C(T, ...E) {
347
347
  }
348
348
  T.identifier = S;
349
349
  function N(r) {
350
- return new NE(r);
350
+ return new sE(r);
351
351
  }
352
352
  T.placeholder = N;
353
353
  function t(r, O) {
354
- return new OE(r, O);
354
+ return new NE(r, O);
355
355
  }
356
356
  T.param = t;
357
357
  })(C || (C = {}));
@@ -360,7 +360,7 @@ function C(T, ...E) {
360
360
  constructor(A, e) {
361
361
  this.sql = A, this.fieldAlias = e;
362
362
  }
363
- static [h] = "SQL.Aliased";
363
+ static [f] = "SQL.Aliased";
364
364
  /** @internal */
365
365
  isSelectionField = !1;
366
366
  getSQL() {
@@ -373,24 +373,24 @@ function C(T, ...E) {
373
373
  }
374
374
  T.Aliased = E;
375
375
  })(u || (u = {}));
376
- class NE {
376
+ class sE {
377
377
  constructor(E) {
378
378
  this.name = E;
379
379
  }
380
- static [h] = "Placeholder";
380
+ static [f] = "Placeholder";
381
381
  getSQL() {
382
382
  return new u([this]);
383
383
  }
384
384
  }
385
- const aR = Symbol.for("drizzle:IsDrizzleView");
385
+ const oR = Symbol.for("drizzle:IsDrizzleView");
386
386
  class vT {
387
- static [h] = "View";
387
+ static [f] = "View";
388
388
  /** @internal */
389
- [z];
389
+ [EE];
390
390
  /** @internal */
391
- [aR] = !0;
391
+ [oR] = !0;
392
392
  constructor({ name: E, schema: R, selectedFields: A, query: e }) {
393
- this[z] = {
393
+ this[EE] = {
394
394
  name: E,
395
395
  originalName: E,
396
396
  schema: R,
@@ -404,7 +404,7 @@ class vT {
404
404
  return new u([this]);
405
405
  }
406
406
  }
407
- TE.prototype.getSQL = function() {
407
+ RE.prototype.getSQL = function() {
408
408
  return new u([this]);
409
409
  };
410
410
  W.prototype.getSQL = function() {
@@ -414,10 +414,10 @@ gT.prototype.getSQL = function() {
414
414
  return new u([this]);
415
415
  };
416
416
  function b(T, E) {
417
- return DR(E) && !wT(T) && !m(T, OE) && !m(T, NE) && !m(T, TE) && !m(T, W) && !m(T, vT) ? new OE(T, E) : T;
417
+ return aR(E) && !wT(T) && !m(T, NE) && !m(T, sE) && !m(T, RE) && !m(T, W) && !m(T, vT) ? new NE(T, E) : T;
418
418
  }
419
- const sE = (T, E) => C`${T} = ${b(E, T)}`, RT = (T, E) => C`${T} <> ${b(E, T)}`;
420
- function f(...T) {
419
+ const j = (T, E) => C`${T} = ${b(E, T)}`, RT = (T, E) => C`${T} <> ${b(E, T)}`;
420
+ function h(...T) {
421
421
  const E = T.filter(
422
422
  (R) => R !== void 0
423
423
  );
@@ -455,23 +455,23 @@ function ST(T) {
455
455
  function IT(T) {
456
456
  return C`${T} asc`;
457
457
  }
458
- function oR(T) {
458
+ function PR(T) {
459
459
  return C`${T} desc`;
460
460
  }
461
461
  function ME(T) {
462
462
  return C`count(${T || C.raw("*")})`.mapWith(Number);
463
463
  }
464
- function PR(T) {
464
+ function MR(T) {
465
465
  return C`count(distinct ${T})`.mapWith(Number);
466
466
  }
467
467
  function g(T) {
468
468
  return C`sum(${T})`.mapWith(String);
469
469
  }
470
470
  function xE(T) {
471
- return C`max(${T})`.mapWith(m(T, TE) ? T : String);
471
+ return C`max(${T})`.mapWith(m(T, RE) ? T : String);
472
472
  }
473
473
  function vE(T) {
474
- return C`min(${T})`.mapWith(m(T, TE) ? T : String);
474
+ return C`min(${T})`.mapWith(m(T, RE) ? T : String);
475
475
  }
476
476
  class ZE {
477
477
  /**
@@ -492,7 +492,7 @@ class ZE {
492
492
  }
493
493
  }
494
494
  }
495
- class MR extends ZE {
495
+ class UR extends ZE {
496
496
  getEngineType() {
497
497
  return "postgres";
498
498
  }
@@ -741,7 +741,7 @@ class QT extends ZE {
741
741
  return E;
742
742
  }
743
743
  }
744
- class UR extends ZE {
744
+ class GR extends ZE {
745
745
  getEngineType() {
746
746
  return "sqlite";
747
747
  }
@@ -877,7 +877,7 @@ class UR extends ZE {
877
877
  return E;
878
878
  }
879
879
  }
880
- class GR extends QT {
880
+ class lR extends QT {
881
881
  getEngineType() {
882
882
  return "singlestore";
883
883
  }
@@ -890,16 +890,16 @@ class GR extends QT {
890
890
  // These limitations are typically handled at the query building level
891
891
  // rather than in the adapter, but can be addressed here if needed
892
892
  }
893
- function lR(T) {
893
+ function cR(T) {
894
894
  switch (T) {
895
895
  case "postgres":
896
- return new MR();
896
+ return new UR();
897
897
  case "mysql":
898
898
  return new QT();
899
899
  case "sqlite":
900
- return new UR();
901
- case "singlestore":
902
900
  return new GR();
901
+ case "singlestore":
902
+ return new lR();
903
903
  default:
904
904
  throw new Error(`Unsupported database engine: ${T}`);
905
905
  }
@@ -908,11 +908,11 @@ class qE {
908
908
  constructor(E, R, A) {
909
909
  this.db = E, this.schema = R;
910
910
  const e = A || this.getEngineType();
911
- this.databaseAdapter = lR(e);
911
+ this.databaseAdapter = cR(e);
912
912
  }
913
913
  databaseAdapter;
914
914
  }
915
- class cR extends qE {
915
+ class uR extends qE {
916
916
  async execute(E, R) {
917
917
  if (E && typeof E == "object" && typeof E.execute == "function") {
918
918
  const e = await E.execute();
@@ -964,7 +964,7 @@ class cR extends qE {
964
964
  }
965
965
  }
966
966
  function OT(T, E) {
967
- return new cR(T, E, "postgres");
967
+ return new uR(T, E, "postgres");
968
968
  }
969
969
  class ZT extends qE {
970
970
  async execute(E, R) {
@@ -1004,10 +1004,10 @@ class ZT extends qE {
1004
1004
  return "mysql";
1005
1005
  }
1006
1006
  }
1007
- function uR(T, E) {
1007
+ function HR(T, E) {
1008
1008
  return new ZT(T, E, "mysql");
1009
1009
  }
1010
- class HR extends qE {
1010
+ class BR extends qE {
1011
1011
  async execute(E, R) {
1012
1012
  if (E && typeof E == "object" && typeof E.execute == "function") {
1013
1013
  const A = await E.execute();
@@ -1054,9 +1054,9 @@ class HR extends qE {
1054
1054
  }
1055
1055
  }
1056
1056
  function NT(T, E) {
1057
- return new HR(T, E, "sqlite");
1057
+ return new BR(T, E, "sqlite");
1058
1058
  }
1059
- class BR extends ZT {
1059
+ class mR extends ZT {
1060
1060
  getEngineType() {
1061
1061
  return "singlestore";
1062
1062
  }
@@ -1064,8 +1064,8 @@ class BR extends ZT {
1064
1064
  // For now, we inherit all behavior from MySQLExecutor since
1065
1065
  // SingleStore is largely MySQL-compatible
1066
1066
  }
1067
- function mR(T, E) {
1068
- return new BR(T, E);
1067
+ function FR(T, E) {
1068
+ return new mR(T, E);
1069
1069
  }
1070
1070
  function sT(T, E, R) {
1071
1071
  if (R)
@@ -1073,11 +1073,11 @@ function sT(T, E, R) {
1073
1073
  case "postgres":
1074
1074
  return OT(T, E);
1075
1075
  case "mysql":
1076
- return uR(T, E);
1076
+ return HR(T, E);
1077
1077
  case "sqlite":
1078
1078
  return NT(T, E);
1079
1079
  case "singlestore":
1080
- return mR(T, E);
1080
+ return FR(T, E);
1081
1081
  }
1082
1082
  if (T.all && T.run)
1083
1083
  return NT(T, E);
@@ -1088,7 +1088,7 @@ function sT(T, E, R) {
1088
1088
  function tT(T) {
1089
1089
  return typeof T == "function" ? T() : T;
1090
1090
  }
1091
- function FR(T, E) {
1091
+ function qT(T, E) {
1092
1092
  if (E) return E;
1093
1093
  switch (T) {
1094
1094
  case "belongsTo":
@@ -1110,7 +1110,43 @@ function FR(T, E) {
1110
1110
  function $(T, E) {
1111
1111
  return typeof T == "function" ? T(E) : T;
1112
1112
  }
1113
- class YR {
1113
+ function YR(T, E) {
1114
+ if (T.relationship !== "belongsToMany" || !T.through)
1115
+ throw new Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
1116
+ const { table: R, sourceKey: A, targetKey: e, securitySql: S } = T.through, N = [];
1117
+ for (const I of A) {
1118
+ const s = I.as || j;
1119
+ N.push(s(I.source, I.target));
1120
+ }
1121
+ const t = [];
1122
+ for (const I of e) {
1123
+ const s = I.as || j;
1124
+ t.push(s(I.source, I.target));
1125
+ }
1126
+ let r;
1127
+ if (S) {
1128
+ const I = S(E);
1129
+ r = Array.isArray(I) ? I : [I];
1130
+ }
1131
+ const O = qT("belongsToMany", T.sqlJoinType);
1132
+ return {
1133
+ junctionJoins: [
1134
+ {
1135
+ joinType: O,
1136
+ table: R,
1137
+ condition: h(...N)
1138
+ },
1139
+ {
1140
+ joinType: O,
1141
+ table: R,
1142
+ // This will be replaced with target cube table in query planner
1143
+ condition: h(...t)
1144
+ }
1145
+ ],
1146
+ junctionSecurityConditions: r
1147
+ };
1148
+ }
1149
+ class pR {
1114
1150
  constructor(E) {
1115
1151
  this.databaseAdapter = E;
1116
1152
  }
@@ -1186,7 +1222,7 @@ class YR {
1186
1222
  if (E.filters && E.filters.length > 0) {
1187
1223
  const e = E.filters.map((S) => S(R)).filter(Boolean);
1188
1224
  if (e.length > 0) {
1189
- const S = e.length === 1 ? e[0] : f(...e);
1225
+ const S = e.length === 1 ? e[0] : h(...e);
1190
1226
  A = this.databaseAdapter.buildCaseWhen([
1191
1227
  { when: S, then: A }
1192
1228
  ]);
@@ -1196,7 +1232,7 @@ class YR {
1196
1232
  case "count":
1197
1233
  return ME(A);
1198
1234
  case "countDistinct":
1199
- return PR(A);
1235
+ return MR(A);
1200
1236
  case "sum":
1201
1237
  return g(A);
1202
1238
  case "avg":
@@ -1263,7 +1299,7 @@ class YR {
1263
1299
  const a = E;
1264
1300
  if (a.and) {
1265
1301
  const o = a.and.map((n) => this.processFilter(n, R, A, e, S)).filter((n) => n !== null);
1266
- return o.length > 0 ? f(...o) : null;
1302
+ return o.length > 0 ? h(...o) : null;
1267
1303
  }
1268
1304
  if (a.or) {
1269
1305
  const o = a.or.map((n) => this.processFilter(n, R, A, e, S)).filter((n) => n !== null);
@@ -1309,7 +1345,7 @@ class YR {
1309
1345
  return PE(E, S);
1310
1346
  } else if (S.length === 1) {
1311
1347
  const t = e?.type === "time" && this.normalizeDate(N) || N;
1312
- return sE(E, t);
1348
+ return j(E, t);
1313
1349
  }
1314
1350
  return this.databaseAdapter.buildBooleanLiteral(!1);
1315
1351
  case "notEquals":
@@ -1338,7 +1374,7 @@ class YR {
1338
1374
  if (S.length >= 2) {
1339
1375
  const t = this.normalizeDate(S[0]), r = this.normalizeDate(S[1]);
1340
1376
  if (t && r)
1341
- return f(
1377
+ return h(
1342
1378
  v(E, t),
1343
1379
  Q(E, r)
1344
1380
  );
@@ -1353,7 +1389,7 @@ class YR {
1353
1389
  return t ? aE(E, t) : null;
1354
1390
  }
1355
1391
  case "between":
1356
- return S.length >= 2 ? f(
1392
+ return S.length >= 2 ? h(
1357
1393
  v(E, S[0]),
1358
1394
  Q(E, S[1])
1359
1395
  ) : null;
@@ -1379,10 +1415,10 @@ class YR {
1379
1415
  case "isEmpty":
1380
1416
  return DE(
1381
1417
  eT(E),
1382
- sE(E, "")
1418
+ j(E, "")
1383
1419
  );
1384
1420
  case "isNotEmpty":
1385
- return f(
1421
+ return h(
1386
1422
  ST(E),
1387
1423
  RT(E, "")
1388
1424
  );
@@ -1397,7 +1433,7 @@ class YR {
1397
1433
  if (!R) return null;
1398
1434
  if (Array.isArray(R) && R.length >= 2) {
1399
1435
  const A = this.normalizeDate(R[0]), e = this.normalizeDate(R[1]);
1400
- return !A || !e ? null : f(
1436
+ return !A || !e ? null : h(
1401
1437
  v(E, A),
1402
1438
  Q(E, e)
1403
1439
  );
@@ -1405,7 +1441,7 @@ class YR {
1405
1441
  if (typeof R == "string") {
1406
1442
  const A = this.parseRelativeDateRange(R);
1407
1443
  if (A)
1408
- return f(
1444
+ return h(
1409
1445
  v(E, A.start),
1410
1446
  Q(E, A.end)
1411
1447
  );
@@ -1414,7 +1450,7 @@ class YR {
1414
1450
  const S = new Date(e);
1415
1451
  S.setUTCHours(0, 0, 0, 0);
1416
1452
  const N = new Date(e);
1417
- return N.setUTCHours(23, 59, 59, 999), f(
1453
+ return N.setUTCHours(23, 59, 59, 999), h(
1418
1454
  v(E, S),
1419
1455
  Q(E, N)
1420
1456
  );
@@ -1585,7 +1621,7 @@ class YR {
1585
1621
  for (const [S, N] of Object.entries(E.order)) {
1586
1622
  if (!e.includes(S))
1587
1623
  throw new Error(`Cannot order by '${S}': field is not selected in the query`);
1588
- const t = N === "desc" ? oR(C.identifier(S)) : IT(C.identifier(S));
1624
+ const t = N === "desc" ? PR(C.identifier(S)) : IT(C.identifier(S));
1589
1625
  A.push(t);
1590
1626
  }
1591
1627
  if (E.timeDimensions && E.timeDimensions.length > 0) {
@@ -1634,7 +1670,7 @@ class YR {
1634
1670
  return e;
1635
1671
  }
1636
1672
  }
1637
- class pR {
1673
+ class dR {
1638
1674
  /**
1639
1675
  * Analyze a semantic query to determine which cubes are involved
1640
1676
  */
@@ -1723,7 +1759,7 @@ class pR {
1723
1759
  groupByFields: []
1724
1760
  // Will be built by QueryBuilder
1725
1761
  };
1726
- const r = this.buildJoinPlan(E, t, S), O = this.planPreAggregationCTEs(E, t, r, R);
1762
+ const r = this.buildJoinPlan(E, t, S, A), O = this.planPreAggregationCTEs(E, t, r, R);
1727
1763
  return {
1728
1764
  primaryCube: t,
1729
1765
  joinCubes: r,
@@ -1782,36 +1818,56 @@ class pR {
1782
1818
  * Build join plan for multi-cube query
1783
1819
  * Supports both direct joins and transitive joins through intermediate cubes
1784
1820
  */
1785
- buildJoinPlan(E, R, A) {
1786
- const e = [], S = /* @__PURE__ */ new Set([R.name]), N = A.filter((t) => t !== R.name);
1787
- for (const t of N) {
1788
- if (S.has(t))
1821
+ buildJoinPlan(E, R, A, e) {
1822
+ const S = [], N = /* @__PURE__ */ new Set([R.name]), t = A.filter((r) => r !== R.name);
1823
+ for (const r of t) {
1824
+ if (N.has(r))
1789
1825
  continue;
1790
- const r = this.findJoinPath(E, R.name, t, S);
1791
- if (!r || r.length === 0)
1792
- throw new Error(`No join path found from '${R.name}' to '${t}'`);
1793
- for (const { toCube: O, joinDef: I } of r) {
1794
- if (S.has(O))
1826
+ const O = this.findJoinPath(E, R.name, r, N);
1827
+ if (!O || O.length === 0)
1828
+ throw new Error(`No join path found from '${R.name}' to '${r}'`);
1829
+ for (const { toCube: I, joinDef: s } of O) {
1830
+ if (N.has(I))
1795
1831
  continue;
1796
- const s = E.get(O);
1797
- if (!s)
1798
- throw new Error(`Cube '${O}' not found`);
1799
- const L = this.buildJoinCondition(
1800
- I,
1801
- null,
1802
- // No source alias needed - use the actual column
1803
- null
1804
- // No target alias needed - use the actual column
1805
- ), a = FR(I.relationship, I.sqlJoinType);
1806
- e.push({
1807
- cube: s,
1808
- alias: `${O.toLowerCase()}_cube`,
1809
- joinType: a,
1810
- joinCondition: L
1811
- }), S.add(O);
1832
+ const L = E.get(I);
1833
+ if (!L)
1834
+ throw new Error(`Cube '${I}' not found`);
1835
+ if (s.relationship === "belongsToMany" && s.through) {
1836
+ const a = YR(s, e.securityContext);
1837
+ S.push({
1838
+ cube: L,
1839
+ alias: `${I.toLowerCase()}_cube`,
1840
+ joinType: a.junctionJoins[1].joinType,
1841
+ // Use the target join type
1842
+ joinCondition: a.junctionJoins[1].condition,
1843
+ // Target join condition
1844
+ junctionTable: {
1845
+ table: s.through.table,
1846
+ alias: `junction_${I.toLowerCase()}`,
1847
+ joinType: a.junctionJoins[0].joinType,
1848
+ joinCondition: a.junctionJoins[0].condition,
1849
+ securitySql: s.through.securitySql
1850
+ }
1851
+ });
1852
+ } else {
1853
+ const a = this.buildJoinCondition(
1854
+ s,
1855
+ null,
1856
+ // No source alias needed - use the actual column
1857
+ null
1858
+ // No target alias needed - use the actual column
1859
+ ), o = qT(s.relationship, s.sqlJoinType);
1860
+ S.push({
1861
+ cube: L,
1862
+ alias: `${I.toLowerCase()}_cube`,
1863
+ joinType: o,
1864
+ joinCondition: a
1865
+ });
1866
+ }
1867
+ N.add(I);
1812
1868
  }
1813
1869
  }
1814
- return e;
1870
+ return S;
1815
1871
  }
1816
1872
  /**
1817
1873
  * Build join condition from new array-based join definition
@@ -1819,10 +1875,10 @@ class pR {
1819
1875
  buildJoinCondition(E, R, A) {
1820
1876
  const e = [];
1821
1877
  for (const S of E.on) {
1822
- const N = R ? C`${C.identifier(R)}.${C.identifier(S.source.name)}` : S.source, t = A ? C`${C.identifier(A)}.${C.identifier(S.target.name)}` : S.target, r = S.as || sE;
1878
+ const N = R ? C`${C.identifier(R)}.${C.identifier(S.source.name)}` : S.source, t = A ? C`${C.identifier(A)}.${C.identifier(S.target.name)}` : S.target, r = S.as || j;
1823
1879
  e.push(r(N, t));
1824
1880
  }
1825
- return f(...e);
1881
+ return h(...e);
1826
1882
  }
1827
1883
  /**
1828
1884
  * Find join path from source cube to target cube
@@ -1855,6 +1911,8 @@ class pR {
1855
1911
  }
1856
1912
  /**
1857
1913
  * Plan pre-aggregation CTEs for hasMany relationships to prevent fan-out
1914
+ * Note: belongsToMany relationships handle fan-out differently through their junction table structure
1915
+ * and don't require CTEs - the two-hop join with the junction table provides natural grouping
1858
1916
  */
1859
1917
  planPreAggregationCTEs(E, R, A, e) {
1860
1918
  const S = [];
@@ -1901,7 +1959,7 @@ class UE {
1901
1959
  constructor(E) {
1902
1960
  if (this.dbExecutor = E, this.databaseAdapter = E.databaseAdapter, !this.databaseAdapter)
1903
1961
  throw new Error("DatabaseExecutor must have a databaseAdapter property");
1904
- this.queryBuilder = new YR(this.databaseAdapter), this.queryPlanner = new pR();
1962
+ this.queryBuilder = new pR(this.databaseAdapter), this.queryPlanner = new dR();
1905
1963
  }
1906
1964
  queryBuilder;
1907
1965
  queryPlanner;
@@ -1911,7 +1969,7 @@ class UE {
1911
1969
  */
1912
1970
  async execute(E, R, A) {
1913
1971
  try {
1914
- const e = tR(E, R);
1972
+ const e = CR(E, R);
1915
1973
  if (!e.isValid)
1916
1974
  throw new Error(`Query validation failed: ${e.errors.join(", ")}`);
1917
1975
  const S = {
@@ -2013,7 +2071,7 @@ class UE {
2013
2071
  }
2014
2072
  const a = [];
2015
2073
  if (N.where && a.push(N.where), a.push(...s, ...L), a.length > 0) {
2016
- const n = a.length === 1 ? a[0] : f(...a);
2074
+ const n = a.length === 1 ? a[0] : h(...a);
2017
2075
  O = O.where(n);
2018
2076
  }
2019
2077
  const o = [];
@@ -2048,9 +2106,9 @@ class UE {
2048
2106
  const S = [];
2049
2107
  for (const N of e.joinKeys) {
2050
2108
  const t = N.sourceColumnObj || C.identifier(N.sourceColumn), r = C`${C.identifier(R)}.${C.identifier(N.targetColumn)}`;
2051
- S.push(sE(t, r));
2109
+ S.push(j(t, r));
2052
2110
  }
2053
- return S.length === 1 ? S[0] : f(...S);
2111
+ return S.length === 1 ? S[0] : h(...S);
2054
2112
  }
2055
2113
  /**
2056
2114
  * Build unified query that works for both single and multi-cube queries
@@ -2109,7 +2167,7 @@ class UE {
2109
2167
  let x = n.joinKeys.find((LE) => LE.targetColumn === l);
2110
2168
  if (!x && H?.dimensions?.[l]) {
2111
2169
  const LE = H.dimensions[l].sql;
2112
- x = n.joinKeys.find((LR) => LR.targetColumnObj === LE);
2170
+ x = n.joinKeys.find((_R) => _R.targetColumnObj === LE);
2113
2171
  }
2114
2172
  x ? r[P] = C`${C.identifier(n.cteAlias)}.${C.identifier(l)}`.as(P) : V && H?.dimensions?.[l] && (r[P] = C`${C.identifier(n.cteAlias)}.${C.identifier(l)}`.as(P));
2115
2173
  }
@@ -2198,7 +2256,7 @@ class UE {
2198
2256
  // Pass the queryPlan to handle CTE scenarios
2199
2257
  );
2200
2258
  if (s.length > 0 && O.push(...s), O.length > 0) {
2201
- const n = O.length === 1 ? O[0] : f(...O);
2259
+ const n = O.length === 1 ? O[0] : h(...O);
2202
2260
  I = I.where(n);
2203
2261
  }
2204
2262
  const L = this.queryBuilder.buildGroupByFields(
@@ -2219,7 +2277,7 @@ class UE {
2219
2277
  // Pass the queryPlan to handle CTE scenarios
2220
2278
  );
2221
2279
  if (a.length > 0) {
2222
- const n = a.length === 1 ? a[0] : f(...a);
2280
+ const n = a.length === 1 ? a[0] : h(...a);
2223
2281
  I = I.having(n);
2224
2282
  }
2225
2283
  const o = this.queryBuilder.buildOrderBy(R);
@@ -2312,13 +2370,13 @@ class UE {
2312
2370
  };
2313
2371
  }
2314
2372
  }
2315
- const _ = (T) => T.flatMap(dR), dR = (T) => RE(fR(T)).map(hR), hR = (T) => T.replace(/ +/g, " ").trim(), fR = (T) => ({
2373
+ const _ = (T) => T.flatMap(hR), hR = (T) => AE(VR(T)).map(fR), fR = (T) => T.replace(/ +/g, " ").trim(), VR = (T) => ({
2316
2374
  type: "mandatory_block",
2317
2375
  items: jE(T, 0)[0]
2318
2376
  }), jE = (T, E, R) => {
2319
2377
  const A = [];
2320
2378
  for (; T[E]; ) {
2321
- const [e, S] = VR(T, E);
2379
+ const [e, S] = WR(T, E);
2322
2380
  if (A.push(e), E = S, T[E] === "|")
2323
2381
  E++;
2324
2382
  else if (T[E] === "}" || T[E] === "]") {
@@ -2333,44 +2391,44 @@ const _ = (T) => T.flatMap(dR), dR = (T) => RE(fR(T)).map(hR), hR = (T) => T.rep
2333
2391
  throw new Error(`Unexpected "${T[E]}"`);
2334
2392
  }
2335
2393
  return [A, E];
2336
- }, VR = (T, E) => {
2394
+ }, WR = (T, E) => {
2337
2395
  const R = [];
2338
2396
  for (; ; ) {
2339
- const [A, e] = WR(T, E);
2397
+ const [A, e] = XR(T, E);
2340
2398
  if (A)
2341
2399
  R.push(A), E = e;
2342
2400
  else
2343
2401
  break;
2344
2402
  }
2345
2403
  return R.length === 1 ? [R[0], E] : [{ type: "concatenation", items: R }, E];
2346
- }, WR = (T, E) => {
2404
+ }, XR = (T, E) => {
2347
2405
  if (T[E] === "{")
2348
- return XR(T, E + 1);
2349
- if (T[E] === "[")
2350
2406
  return bR(T, E + 1);
2407
+ if (T[E] === "[")
2408
+ return yR(T, E + 1);
2351
2409
  {
2352
2410
  let R = "";
2353
2411
  for (; T[E] && /[A-Za-z0-9_ ]/.test(T[E]); )
2354
2412
  R += T[E], E++;
2355
2413
  return [R, E];
2356
2414
  }
2357
- }, XR = (T, E) => {
2415
+ }, bR = (T, E) => {
2358
2416
  const [R, A] = jE(T, E, "}");
2359
2417
  return [{ type: "mandatory_block", items: R }, A];
2360
- }, bR = (T, E) => {
2418
+ }, yR = (T, E) => {
2361
2419
  const [R, A] = jE(T, E, "]");
2362
2420
  return [{ type: "optional_block", items: R }, A];
2363
- }, RE = (T) => {
2421
+ }, AE = (T) => {
2364
2422
  if (typeof T == "string")
2365
2423
  return [T];
2366
2424
  if (T.type === "concatenation")
2367
- return T.items.map(RE).reduce(yR, [""]);
2425
+ return T.items.map(AE).reduce(KR, [""]);
2368
2426
  if (T.type === "mandatory_block")
2369
- return T.items.flatMap(RE);
2427
+ return T.items.flatMap(AE);
2370
2428
  if (T.type === "optional_block")
2371
- return ["", ...T.items.flatMap(RE)];
2429
+ return ["", ...T.items.flatMap(AE)];
2372
2430
  throw new Error(`Unknown node type: ${T}`);
2373
- }, yR = (T, E) => {
2431
+ }, KR = (T, E) => {
2374
2432
  const R = [];
2375
2433
  for (const A of T)
2376
2434
  for (const e of E)
@@ -2381,19 +2439,19 @@ var D;
2381
2439
  (function(T) {
2382
2440
  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";
2383
2441
  })(D = D || (D = {}));
2384
- const qT = (T) => ({
2442
+ const jT = (T) => ({
2385
2443
  type: D.EOF,
2386
2444
  raw: "«EOF»",
2387
2445
  text: "«EOF»",
2388
2446
  start: T
2389
- }), j = qT(1 / 0), Z = (T) => (E) => E.type === T.type && E.text === T.text, w = {
2447
+ }), k = jT(1 / 0), Z = (T) => (E) => E.type === T.type && E.text === T.text, w = {
2390
2448
  ARRAY: Z({ text: "ARRAY", type: D.RESERVED_DATA_TYPE }),
2391
2449
  BY: Z({ text: "BY", type: D.RESERVED_KEYWORD }),
2392
2450
  SET: Z({ text: "SET", type: D.RESERVED_CLAUSE }),
2393
2451
  STRUCT: Z({ text: "STRUCT", type: D.RESERVED_DATA_TYPE }),
2394
2452
  WINDOW: Z({ text: "WINDOW", type: D.RESERVED_CLAUSE }),
2395
2453
  VALUES: Z({ text: "VALUES", type: D.RESERVED_CLAUSE })
2396
- }, jT = (T) => T === D.RESERVED_DATA_TYPE || T === D.RESERVED_KEYWORD || T === D.RESERVED_FUNCTION_NAME || T === D.RESERVED_KEYWORD_PHRASE || T === D.RESERVED_DATA_TYPE_PHRASE || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.ARRAY_KEYWORD || T === D.CASE || T === D.END || T === D.WHEN || T === D.ELSE || T === D.THEN || T === D.LIMIT || T === D.BETWEEN || T === D.AND || T === D.OR || T === D.XOR, KR = (T) => T === D.AND || T === D.OR || T === D.XOR, $R = [
2454
+ }, kT = (T) => T === D.RESERVED_DATA_TYPE || T === D.RESERVED_KEYWORD || T === D.RESERVED_FUNCTION_NAME || T === D.RESERVED_KEYWORD_PHRASE || T === D.RESERVED_DATA_TYPE_PHRASE || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.ARRAY_KEYWORD || T === D.CASE || T === D.END || T === D.WHEN || T === D.ELSE || T === D.THEN || T === D.LIMIT || T === D.BETWEEN || T === D.AND || T === D.OR || T === D.XOR, $R = (T) => T === D.AND || T === D.OR || T === D.XOR, gR = [
2397
2455
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/aead_encryption_functions
2398
2456
  "KEYS.NEW_KEYSET",
2399
2457
  "KEYS.ADD_KEY_FROM_RAW_BYTES",
@@ -2937,7 +2995,7 @@ const qT = (T) => ({
2937
2995
  // pivot
2938
2996
  "PIVOT",
2939
2997
  "UNPIVOT"
2940
- ], gR = [
2998
+ ], wR = [
2941
2999
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#reserved_keywords
2942
3000
  "ALL",
2943
3001
  "AND",
@@ -3045,7 +3103,7 @@ const qT = (T) => ({
3045
3103
  "CASCADE",
3046
3104
  "RESTRICT",
3047
3105
  "DETERMINISTIC"
3048
- ], wR = [
3106
+ ], JR = [
3049
3107
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
3050
3108
  "ARRAY",
3051
3109
  "BOOL",
@@ -3070,7 +3128,7 @@ const qT = (T) => ({
3070
3128
  "STRUCT",
3071
3129
  "TIME",
3072
3130
  "TIMEZONE"
3073
- ], JR = _(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), xR = _([
3131
+ ], xR = _(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), vR = _([
3074
3132
  // Queries: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
3075
3133
  "WITH [RECURSIVE]",
3076
3134
  "FROM",
@@ -3189,15 +3247,15 @@ const qT = (T) => ({
3189
3247
  "ASSERT",
3190
3248
  // Other, https://cloud.google.com/bigquery/docs/reference/standard-sql/other-statements
3191
3249
  "EXPORT DATA"
3192
- ]), vR = _([
3250
+ ]), QR = _([
3193
3251
  "UNION {ALL | DISTINCT}",
3194
3252
  "EXCEPT DISTINCT",
3195
3253
  "INTERSECT DISTINCT"
3196
- ]), QR = _([
3254
+ ]), ZR = _([
3197
3255
  "JOIN",
3198
3256
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
3199
3257
  "{INNER | CROSS} JOIN"
3200
- ]), ZR = _([
3258
+ ]), qR = _([
3201
3259
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#tablesample_operator
3202
3260
  "TABLESAMPLE SYSTEM",
3203
3261
  // From DDL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
@@ -3208,18 +3266,18 @@ const qT = (T) => ({
3208
3266
  "{ROWS | RANGE} BETWEEN",
3209
3267
  // comparison operator
3210
3268
  "IS [NOT] DISTINCT FROM"
3211
- ]), qR = _([]), jR = {
3269
+ ]), jR = _([]), kR = {
3212
3270
  name: "bigquery",
3213
3271
  tokenizerOptions: {
3214
- reservedSelect: JR,
3215
- reservedClauses: [...xR, ...GE, ...CT],
3216
- reservedSetOperations: vR,
3217
- reservedJoins: QR,
3218
- reservedKeywordPhrases: ZR,
3219
- reservedDataTypePhrases: qR,
3220
- reservedKeywords: gR,
3221
- reservedDataTypes: wR,
3222
- reservedFunctionNames: $R,
3272
+ reservedSelect: xR,
3273
+ reservedClauses: [...vR, ...GE, ...CT],
3274
+ reservedSetOperations: QR,
3275
+ reservedJoins: ZR,
3276
+ reservedKeywordPhrases: qR,
3277
+ reservedDataTypePhrases: jR,
3278
+ reservedKeywords: wR,
3279
+ reservedDataTypes: JR,
3280
+ reservedFunctionNames: gR,
3223
3281
  extraParens: ["[]"],
3224
3282
  stringTypes: [
3225
3283
  // The triple-quoted strings are listed first, so they get matched first.
@@ -3237,27 +3295,27 @@ const qT = (T) => ({
3237
3295
  variableTypes: [{ regex: String.raw`@@\w+` }],
3238
3296
  lineCommentTypes: ["--", "#"],
3239
3297
  operators: ["&", "|", "^", "~", ">>", "<<", "||", "=>"],
3240
- postProcess: kR
3298
+ postProcess: zR
3241
3299
  },
3242
3300
  formatOptions: {
3243
3301
  onelineClauses: [...CT, ...GE],
3244
3302
  tabularOnelineClauses: GE
3245
3303
  }
3246
3304
  };
3247
- function kR(T) {
3248
- return zR(EA(T));
3249
- }
3250
3305
  function zR(T) {
3251
- let E = j;
3252
- return T.map((R) => R.text === "OFFSET" && E.text === "[" ? (E = R, Object.assign(Object.assign({}, R), { type: D.RESERVED_FUNCTION_NAME })) : (E = R, R));
3306
+ return EA(TA(T));
3253
3307
  }
3254
3308
  function EA(T) {
3309
+ let E = k;
3310
+ return T.map((R) => R.text === "OFFSET" && E.text === "[" ? (E = R, Object.assign(Object.assign({}, R), { type: D.RESERVED_FUNCTION_NAME })) : (E = R, R));
3311
+ }
3312
+ function TA(T) {
3255
3313
  var E;
3256
3314
  const R = [];
3257
3315
  for (let A = 0; A < T.length; A++) {
3258
3316
  const e = T[A];
3259
3317
  if ((w.ARRAY(e) || w.STRUCT(e)) && ((E = T[A + 1]) === null || E === void 0 ? void 0 : E.text) === "<") {
3260
- const S = TA(T, A + 1), N = T.slice(A, S + 1);
3318
+ const S = RA(T, A + 1), N = T.slice(A, S + 1);
3261
3319
  R.push({
3262
3320
  type: D.IDENTIFIER,
3263
3321
  raw: N.map(LT("raw")).join(""),
@@ -3270,7 +3328,7 @@ function EA(T) {
3270
3328
  return R;
3271
3329
  }
3272
3330
  const LT = (T) => (E) => E.type === D.IDENTIFIER || E.type === D.COMMA ? E[T] + " " : E[T];
3273
- function TA(T, E) {
3331
+ function RA(T, E) {
3274
3332
  let R = 0;
3275
3333
  for (let A = E; A < T.length; A++) {
3276
3334
  const e = T[A];
@@ -3279,7 +3337,7 @@ function TA(T, E) {
3279
3337
  }
3280
3338
  return T.length - 1;
3281
3339
  }
3282
- const RA = [
3340
+ const AA = [
3283
3341
  // https://www.ibm.com/docs/en/db2/11.5?topic=bif-aggregate-functions
3284
3342
  "ARRAY_AGG",
3285
3343
  "AVG",
@@ -3599,7 +3657,7 @@ const RA = [
3599
3657
  "RATIO_TO_REPORT",
3600
3658
  // Type casting
3601
3659
  "CAST"
3602
- ], AA = [
3660
+ ], eA = [
3603
3661
  // https://www.ibm.com/docs/en/db2/11.5?topic=sql-reserved-schema-names-reserved-words
3604
3662
  "ACTIVATE",
3605
3663
  "ADD",
@@ -4000,7 +4058,7 @@ const RA = [
4000
4058
  "XMLNAMESPACES",
4001
4059
  "YEAR",
4002
4060
  "YEARS"
4003
- ], eA = [
4061
+ ], SA = [
4004
4062
  // https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
4005
4063
  "ARRAY",
4006
4064
  "BIGINT",
@@ -4042,7 +4100,7 @@ const RA = [
4042
4100
  "VARBINARY",
4043
4101
  "VARCHAR",
4044
4102
  "VARGRAPHIC"
4045
- ], SA = _(["SELECT [ALL | DISTINCT]"]), IA = _([
4103
+ ], IA = _(["SELECT [ALL | DISTINCT]"]), OA = _([
4046
4104
  // queries
4047
4105
  "WITH",
4048
4106
  "FROM",
@@ -4276,27 +4334,27 @@ const RA = [
4276
4334
  "TRANSFER OWNERSHIP OF",
4277
4335
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}",
4278
4336
  "WHILE"
4279
- ]), OA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), NA = _([
4337
+ ]), NA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), sA = _([
4280
4338
  "JOIN",
4281
4339
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
4282
4340
  "{INNER | CROSS} JOIN"
4283
- ]), sA = _([
4341
+ ]), tA = _([
4284
4342
  "ON DELETE",
4285
4343
  "ON UPDATE",
4286
4344
  "SET NULL",
4287
4345
  "{ROWS | RANGE} BETWEEN"
4288
- ]), tA = _([]), CA = {
4346
+ ]), CA = _([]), LA = {
4289
4347
  name: "db2",
4290
4348
  tokenizerOptions: {
4291
- reservedSelect: SA,
4292
- reservedClauses: [...IA, ..._T, ...lE],
4293
- reservedSetOperations: OA,
4294
- reservedJoins: NA,
4295
- reservedKeywordPhrases: sA,
4296
- reservedDataTypePhrases: tA,
4297
- reservedKeywords: AA,
4298
- reservedDataTypes: eA,
4299
- reservedFunctionNames: RA,
4349
+ reservedSelect: IA,
4350
+ reservedClauses: [...OA, ..._T, ...lE],
4351
+ reservedSetOperations: NA,
4352
+ reservedJoins: sA,
4353
+ reservedKeywordPhrases: tA,
4354
+ reservedDataTypePhrases: CA,
4355
+ reservedKeywords: eA,
4356
+ reservedDataTypes: SA,
4357
+ reservedFunctionNames: AA,
4300
4358
  extraParens: ["[]"],
4301
4359
  stringTypes: [
4302
4360
  { quote: "''-qq", prefixes: ["G", "N", "U&"] },
@@ -4330,7 +4388,7 @@ const RA = [
4330
4388
  onelineClauses: [..._T, ...lE],
4331
4389
  tabularOnelineClauses: lE
4332
4390
  }
4333
- }, LA = [
4391
+ }, _A = [
4334
4392
  // https://www.ibm.com/docs/en/i/7.5?topic=functions-aggregate
4335
4393
  // TODO: 'ANY', - conflicts with test for ANY predicate in 'operators.ys'!!
4336
4394
  "ARRAY_AGG",
@@ -4664,7 +4722,7 @@ const RA = [
4664
4722
  "ROW_NUMBER",
4665
4723
  // Type casting
4666
4724
  "CAST"
4667
- ], _A = [
4725
+ ], rA = [
4668
4726
  // https://www.ibm.com/docs/en/i/7.5?topic=words-reserved
4669
4727
  // TODO: This list likely contains all keywords, not only the reserved ones,
4670
4728
  // try to filter it down to just the reserved keywords.
@@ -5160,7 +5218,7 @@ const RA = [
5160
5218
  "YEARS",
5161
5219
  "YES",
5162
5220
  "ZONE"
5163
- ], rA = [
5221
+ ], nA = [
5164
5222
  // https://www.ibm.com/docs/en/i/7.2?topic=iaodsd-odbc-data-types-how-they-correspond-db2-i-database-types
5165
5223
  "ARRAY",
5166
5224
  "BIGINT",
@@ -5196,7 +5254,7 @@ const RA = [
5196
5254
  "VARCHAR",
5197
5255
  "VARGRAPHIC",
5198
5256
  "XML"
5199
- ], nA = _(["SELECT [ALL | DISTINCT]"]), iA = _([
5257
+ ], iA = _(["SELECT [ALL | DISTINCT]"]), DA = _([
5200
5258
  // queries
5201
5259
  "WITH [RECURSIVE]",
5202
5260
  "INTO",
@@ -5322,28 +5380,28 @@ const RA = [
5322
5380
  "TAG",
5323
5381
  "TRANSFER OWNERSHIP OF",
5324
5382
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}"
5325
- ]), DA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), aA = _([
5383
+ ]), aA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), oA = _([
5326
5384
  "JOIN",
5327
5385
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
5328
5386
  "[LEFT | RIGHT] EXCEPTION JOIN",
5329
5387
  "{INNER | CROSS} JOIN"
5330
- ]), oA = _([
5388
+ ]), PA = _([
5331
5389
  "ON DELETE",
5332
5390
  "ON UPDATE",
5333
5391
  "SET NULL",
5334
5392
  "{ROWS | RANGE} BETWEEN"
5335
- ]), PA = _([]), MA = {
5393
+ ]), MA = _([]), UA = {
5336
5394
  name: "db2i",
5337
5395
  tokenizerOptions: {
5338
- reservedSelect: nA,
5339
- reservedClauses: [...iA, ...rT, ...cE],
5340
- reservedSetOperations: DA,
5341
- reservedJoins: aA,
5342
- reservedKeywordPhrases: oA,
5343
- reservedDataTypePhrases: PA,
5344
- reservedKeywords: _A,
5345
- reservedDataTypes: rA,
5346
- reservedFunctionNames: LA,
5396
+ reservedSelect: iA,
5397
+ reservedClauses: [...DA, ...rT, ...cE],
5398
+ reservedSetOperations: aA,
5399
+ reservedJoins: oA,
5400
+ reservedKeywordPhrases: PA,
5401
+ reservedDataTypePhrases: MA,
5402
+ reservedKeywords: rA,
5403
+ reservedDataTypes: nA,
5404
+ reservedFunctionNames: _A,
5347
5405
  nestedBlockComments: !0,
5348
5406
  extraParens: ["[]"],
5349
5407
  stringTypes: [
@@ -5360,7 +5418,7 @@ const RA = [
5360
5418
  onelineClauses: [...rT, ...cE],
5361
5419
  tabularOnelineClauses: cE
5362
5420
  }
5363
- }, UA = [
5421
+ }, GA = [
5364
5422
  // Functions from DuckDB (excluding those that start with an underscore):
5365
5423
  // SELECT DISTINCT upper(function_name) AS function_name
5366
5424
  // FROM duckdb_functions()
@@ -6023,7 +6081,7 @@ const RA = [
6023
6081
  // 'NULL', we really prefer treating it as keyword
6024
6082
  "RANK",
6025
6083
  "ROW_NUMBER"
6026
- ], GA = [
6084
+ ], lA = [
6027
6085
  // Keywords from DuckDB:
6028
6086
  // SELECT upper(keyword_name)
6029
6087
  // FROM duckdb_keywords()
@@ -6105,7 +6163,7 @@ const RA = [
6105
6163
  "WHERE",
6106
6164
  "WINDOW",
6107
6165
  "WITH"
6108
- ], lA = [
6166
+ ], cA = [
6109
6167
  // Types from DuckDB:
6110
6168
  // SELECT DISTINCT upper(type_name)
6111
6169
  // FROM duckdb_types()
@@ -6185,7 +6243,7 @@ const RA = [
6185
6243
  "UUID",
6186
6244
  "VARBINARY",
6187
6245
  "VARCHAR"
6188
- ], cA = _(["SELECT [ALL | DISTINCT]"]), uA = _([
6246
+ ], uA = _(["SELECT [ALL | DISTINCT]"]), HA = _([
6189
6247
  // queries
6190
6248
  "WITH [RECURSIVE]",
6191
6249
  "FROM",
@@ -6289,11 +6347,11 @@ const RA = [
6289
6347
  "PREPARE",
6290
6348
  "EXECUTE",
6291
6349
  "DEALLOCATE [PREPARE]"
6292
- ]), HA = _([
6350
+ ]), BA = _([
6293
6351
  "UNION [ALL | BY NAME]",
6294
6352
  "EXCEPT [ALL]",
6295
6353
  "INTERSECT [ALL]"
6296
- ]), BA = _([
6354
+ ]), mA = _([
6297
6355
  "JOIN",
6298
6356
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6299
6357
  "{INNER | CROSS} JOIN",
@@ -6302,23 +6360,23 @@ const RA = [
6302
6360
  "POSITIONAL JOIN",
6303
6361
  "ANTI JOIN",
6304
6362
  "SEMI JOIN"
6305
- ]), mA = _([
6363
+ ]), FA = _([
6306
6364
  "{ROWS | RANGE | GROUPS} BETWEEN",
6307
6365
  "SIMILAR TO",
6308
6366
  "IS [NOT] DISTINCT FROM"
6309
- ]), FA = _(["TIMESTAMP WITH TIME ZONE"]), YA = {
6367
+ ]), YA = _(["TIMESTAMP WITH TIME ZONE"]), pA = {
6310
6368
  name: "duckdb",
6311
6369
  tokenizerOptions: {
6312
- reservedSelect: cA,
6313
- reservedClauses: [...uA, ...nT, ...uE],
6314
- reservedSetOperations: HA,
6315
- reservedJoins: BA,
6316
- reservedKeywordPhrases: mA,
6317
- reservedDataTypePhrases: FA,
6370
+ reservedSelect: uA,
6371
+ reservedClauses: [...HA, ...nT, ...uE],
6372
+ reservedSetOperations: BA,
6373
+ reservedJoins: mA,
6374
+ reservedKeywordPhrases: FA,
6375
+ reservedDataTypePhrases: YA,
6318
6376
  supportsXor: !0,
6319
- reservedKeywords: GA,
6320
- reservedDataTypes: lA,
6321
- reservedFunctionNames: UA,
6377
+ reservedKeywords: lA,
6378
+ reservedDataTypes: cA,
6379
+ reservedFunctionNames: GA,
6322
6380
  nestedBlockComments: !0,
6323
6381
  extraParens: ["[]", "{}"],
6324
6382
  underscoresInNumbers: !0,
@@ -6382,7 +6440,7 @@ const RA = [
6382
6440
  onelineClauses: [...nT, ...uE],
6383
6441
  tabularOnelineClauses: uE
6384
6442
  }
6385
- }, pA = [
6443
+ }, dA = [
6386
6444
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
6387
6445
  // math
6388
6446
  "ABS",
@@ -6590,7 +6648,7 @@ const RA = [
6590
6648
  "CUME_DIST",
6591
6649
  "PERCENT_RANK",
6592
6650
  "NTILE"
6593
- ], dA = [
6651
+ ], hA = [
6594
6652
  // https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl
6595
6653
  // Non-reserved keywords have proscribed meanings in. HiveQL, but can still be used as table or column names
6596
6654
  "ADD",
@@ -6905,7 +6963,7 @@ const RA = [
6905
6963
  "JSONFILE",
6906
6964
  "INPUTFORMAT",
6907
6965
  "OUTPUTFORMAT"
6908
- ], hA = [
6966
+ ], fA = [
6909
6967
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
6910
6968
  "ARRAY",
6911
6969
  "BIGINT",
@@ -6926,7 +6984,7 @@ const RA = [
6926
6984
  "STRUCT",
6927
6985
  "TIMESTAMP",
6928
6986
  "VARCHAR"
6929
- ], fA = _(["SELECT [ALL | DISTINCT]"]), VA = _([
6987
+ ], VA = _(["SELECT [ALL | DISTINCT]"]), WA = _([
6930
6988
  // queries
6931
6989
  "WITH",
6932
6990
  "FROM",
@@ -6987,24 +7045,24 @@ const RA = [
6987
7045
  "STORED AS",
6988
7046
  "STORED BY",
6989
7047
  "ROW FORMAT"
6990
- ]), WA = _(["UNION [ALL | DISTINCT]"]), XA = _([
7048
+ ]), XA = _(["UNION [ALL | DISTINCT]"]), bA = _([
6991
7049
  "JOIN",
6992
7050
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6993
7051
  "{INNER | CROSS} JOIN",
6994
7052
  // non-standard joins
6995
7053
  "LEFT SEMI JOIN"
6996
- ]), bA = _(["{ROWS | RANGE} BETWEEN"]), yA = _([]), KA = {
7054
+ ]), yA = _(["{ROWS | RANGE} BETWEEN"]), KA = _([]), $A = {
6997
7055
  name: "hive",
6998
7056
  tokenizerOptions: {
6999
- reservedSelect: fA,
7000
- reservedClauses: [...VA, ...iT, ...HE],
7001
- reservedSetOperations: WA,
7002
- reservedJoins: XA,
7003
- reservedKeywordPhrases: bA,
7004
- reservedDataTypePhrases: yA,
7005
- reservedKeywords: dA,
7006
- reservedDataTypes: hA,
7007
- reservedFunctionNames: pA,
7057
+ reservedSelect: VA,
7058
+ reservedClauses: [...WA, ...iT, ...HE],
7059
+ reservedSetOperations: XA,
7060
+ reservedJoins: bA,
7061
+ reservedKeywordPhrases: yA,
7062
+ reservedDataTypePhrases: KA,
7063
+ reservedKeywords: hA,
7064
+ reservedDataTypes: fA,
7065
+ reservedFunctionNames: dA,
7008
7066
  extraParens: ["[]"],
7009
7067
  stringTypes: ['""-bs', "''-bs"],
7010
7068
  identTypes: ["``"],
@@ -7018,14 +7076,14 @@ const RA = [
7018
7076
  };
7019
7077
  function CE(T) {
7020
7078
  return T.map((E, R) => {
7021
- const A = T[R + 1] || j;
7079
+ const A = T[R + 1] || k;
7022
7080
  if (w.SET(E) && A.text === "(")
7023
7081
  return Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME });
7024
- const e = T[R - 1] || j;
7082
+ const e = T[R - 1] || k;
7025
7083
  return w.VALUES(E) && e.text === "=" ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E;
7026
7084
  });
7027
7085
  }
7028
- const $A = [
7086
+ const gA = [
7029
7087
  // https://mariadb.com/kb/en/reserved-words/
7030
7088
  "ACCESSIBLE",
7031
7089
  "ADD",
@@ -7242,7 +7300,7 @@ const $A = [
7242
7300
  "XOR",
7243
7301
  "YEAR_MONTH",
7244
7302
  "ZEROFILL"
7245
- ], gA = [
7303
+ ], wA = [
7246
7304
  // https://mariadb.com/kb/en/data-types/
7247
7305
  "BIGINT",
7248
7306
  "BINARY",
@@ -7293,7 +7351,7 @@ const $A = [
7293
7351
  "YEAR"
7294
7352
  // 'NUMBER', // ?? In oracle mode only
7295
7353
  // 'SET' // handled as special-case in postProcess
7296
- ], wA = [
7354
+ ], JA = [
7297
7355
  // https://mariadb.com/kb/en/information-schema-sql_functions-table/
7298
7356
  "ADDDATE",
7299
7357
  "ADD_MONTHS",
@@ -7531,7 +7589,7 @@ const $A = [
7531
7589
  // CASE expression shorthands
7532
7590
  "COALESCE",
7533
7591
  "NULLIF"
7534
- ], JA = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), xA = _([
7592
+ ], xA = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), vA = _([
7535
7593
  // queries
7536
7594
  "WITH [RECURSIVE]",
7537
7595
  "FROM",
@@ -7762,12 +7820,12 @@ const $A = [
7762
7820
  "XA RECOVER",
7763
7821
  "XA ROLLBACK",
7764
7822
  "XA START"
7765
- ]), vA = _([
7823
+ ]), QA = _([
7766
7824
  "UNION [ALL | DISTINCT]",
7767
7825
  "EXCEPT [ALL | DISTINCT]",
7768
7826
  "INTERSECT [ALL | DISTINCT]",
7769
7827
  "MINUS [ALL | DISTINCT]"
7770
- ]), QA = _([
7828
+ ]), ZA = _([
7771
7829
  "JOIN",
7772
7830
  "{LEFT | RIGHT} [OUTER] JOIN",
7773
7831
  "{INNER | CROSS} JOIN",
@@ -7775,24 +7833,24 @@ const $A = [
7775
7833
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
7776
7834
  // non-standard joins
7777
7835
  "STRAIGHT_JOIN"
7778
- ]), ZA = _([
7836
+ ]), qA = _([
7779
7837
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
7780
7838
  "CHARACTER SET",
7781
7839
  "{ROWS | RANGE} BETWEEN",
7782
7840
  "IDENTIFIED BY"
7783
- ]), qA = _([]), jA = {
7841
+ ]), jA = _([]), kA = {
7784
7842
  name: "mariadb",
7785
7843
  tokenizerOptions: {
7786
- reservedSelect: JA,
7787
- reservedClauses: [...xA, ...DT, ...BE],
7788
- reservedSetOperations: vA,
7789
- reservedJoins: QA,
7790
- reservedKeywordPhrases: ZA,
7791
- reservedDataTypePhrases: qA,
7844
+ reservedSelect: xA,
7845
+ reservedClauses: [...vA, ...DT, ...BE],
7846
+ reservedSetOperations: QA,
7847
+ reservedJoins: ZA,
7848
+ reservedKeywordPhrases: qA,
7849
+ reservedDataTypePhrases: jA,
7792
7850
  supportsXor: !0,
7793
- reservedKeywords: $A,
7794
- reservedDataTypes: gA,
7795
- reservedFunctionNames: wA,
7851
+ reservedKeywords: gA,
7852
+ reservedDataTypes: wA,
7853
+ reservedFunctionNames: JA,
7796
7854
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
7797
7855
  stringTypes: [
7798
7856
  '""-qq-bs',
@@ -7831,7 +7889,7 @@ const $A = [
7831
7889
  onelineClauses: [...DT, ...BE],
7832
7890
  tabularOnelineClauses: BE
7833
7891
  }
7834
- }, kA = [
7892
+ }, zA = [
7835
7893
  // https://dev.mysql.com/doc/refman/8.0/en/keywords.html
7836
7894
  "ACCESSIBLE",
7837
7895
  "ADD",
@@ -8062,7 +8120,7 @@ const $A = [
8062
8120
  "YEAR_MONTH",
8063
8121
  "ZEROFILL"
8064
8122
  // (R)
8065
- ], zA = [
8123
+ ], Ee = [
8066
8124
  // https://dev.mysql.com/doc/refman/8.0/en/data-types.html
8067
8125
  "BIGINT",
8068
8126
  "BINARY",
@@ -8114,7 +8172,7 @@ const $A = [
8114
8172
  "VARYING",
8115
8173
  "YEAR"
8116
8174
  // 'SET' // handled as special-case in postProcess
8117
- ], Ee = [
8175
+ ], Te = [
8118
8176
  // https://dev.mysql.com/doc/refman/8.0/en/built-in-function-reference.html
8119
8177
  "ABS",
8120
8178
  "ACOS",
@@ -8537,7 +8595,7 @@ const $A = [
8537
8595
  // 'XOR',
8538
8596
  "YEAR",
8539
8597
  "YEARWEEK"
8540
- ], Te = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Re = _([
8598
+ ], Re = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Ae = _([
8541
8599
  // queries
8542
8600
  "WITH [RECURSIVE]",
8543
8601
  "FROM",
@@ -8738,7 +8796,7 @@ const $A = [
8738
8796
  "REPEAT",
8739
8797
  "RETURN",
8740
8798
  "WHILE"
8741
- ]), Ae = _(["UNION [ALL | DISTINCT]"]), ee = _([
8799
+ ]), ee = _(["UNION [ALL | DISTINCT]"]), Se = _([
8742
8800
  "JOIN",
8743
8801
  "{LEFT | RIGHT} [OUTER] JOIN",
8744
8802
  "{INNER | CROSS} JOIN",
@@ -8746,24 +8804,24 @@ const $A = [
8746
8804
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
8747
8805
  // non-standard joins
8748
8806
  "STRAIGHT_JOIN"
8749
- ]), Se = _([
8807
+ ]), Ie = _([
8750
8808
  "ON {UPDATE | DELETE} [SET NULL]",
8751
8809
  "CHARACTER SET",
8752
8810
  "{ROWS | RANGE} BETWEEN",
8753
8811
  "IDENTIFIED BY"
8754
- ]), Ie = _([]), Oe = {
8812
+ ]), Oe = _([]), Ne = {
8755
8813
  name: "mysql",
8756
8814
  tokenizerOptions: {
8757
- reservedSelect: Te,
8758
- reservedClauses: [...Re, ...aT, ...mE],
8759
- reservedSetOperations: Ae,
8760
- reservedJoins: ee,
8761
- reservedKeywordPhrases: Se,
8762
- reservedDataTypePhrases: Ie,
8815
+ reservedSelect: Re,
8816
+ reservedClauses: [...Ae, ...aT, ...mE],
8817
+ reservedSetOperations: ee,
8818
+ reservedJoins: Se,
8819
+ reservedKeywordPhrases: Ie,
8820
+ reservedDataTypePhrases: Oe,
8763
8821
  supportsXor: !0,
8764
- reservedKeywords: kA,
8765
- reservedDataTypes: zA,
8766
- reservedFunctionNames: Ee,
8822
+ reservedKeywords: zA,
8823
+ reservedDataTypes: Ee,
8824
+ reservedFunctionNames: Te,
8767
8825
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
8768
8826
  stringTypes: [
8769
8827
  '""-qq-bs',
@@ -8804,7 +8862,7 @@ const $A = [
8804
8862
  onelineClauses: [...aT, ...mE],
8805
8863
  tabularOnelineClauses: mE
8806
8864
  }
8807
- }, Ne = [
8865
+ }, se = [
8808
8866
  // https://docs.pingcap.com/tidb/stable/keywords
8809
8867
  "ADD",
8810
8868
  "ALL",
@@ -8996,7 +9054,7 @@ const $A = [
8996
9054
  "YEAR_MONTH",
8997
9055
  "ZEROFILL"
8998
9056
  // (R)
8999
- ], se = [
9057
+ ], te = [
9000
9058
  // https://docs.pingcap.com/tidb/stable/data-type-overview
9001
9059
  "BIGINT",
9002
9060
  "BINARY",
@@ -9043,7 +9101,7 @@ const $A = [
9043
9101
  "VARYING",
9044
9102
  "YEAR"
9045
9103
  // 'SET' // handled as special-case in postProcess
9046
- ], te = [
9104
+ ], Ce = [
9047
9105
  // https://docs.pingcap.com/tidb/stable/sql-statement-show-builtins
9048
9106
  // https://docs.pingcap.com/tidb/stable/functions-and-operators-overview
9049
9107
  // + MySQL aggregate functions: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html
@@ -9369,7 +9427,7 @@ const $A = [
9369
9427
  // 'XOR',
9370
9428
  "YEAR",
9371
9429
  "YEARWEEK"
9372
- ], Ce = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Le = _([
9430
+ ], Le = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), _e = _([
9373
9431
  // queries
9374
9432
  "WITH [RECURSIVE]",
9375
9433
  "FROM",
@@ -9504,7 +9562,7 @@ const $A = [
9504
9562
  "UNLOCK TABLES",
9505
9563
  // https://docs.pingcap.com/tidb/stable/sql-statement-use
9506
9564
  "USE"
9507
- ]), _e = _(["UNION [ALL | DISTINCT]"]), re = _([
9565
+ ]), re = _(["UNION [ALL | DISTINCT]"]), ne = _([
9508
9566
  "JOIN",
9509
9567
  "{LEFT | RIGHT} [OUTER] JOIN",
9510
9568
  "{INNER | CROSS} JOIN",
@@ -9512,24 +9570,24 @@ const $A = [
9512
9570
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
9513
9571
  // non-standard joins
9514
9572
  "STRAIGHT_JOIN"
9515
- ]), ne = _([
9573
+ ]), ie = _([
9516
9574
  "ON {UPDATE | DELETE} [SET NULL]",
9517
9575
  "CHARACTER SET",
9518
9576
  "{ROWS | RANGE} BETWEEN",
9519
9577
  "IDENTIFIED BY"
9520
- ]), ie = _([]), De = {
9578
+ ]), De = _([]), ae = {
9521
9579
  name: "tidb",
9522
9580
  tokenizerOptions: {
9523
- reservedSelect: Ce,
9524
- reservedClauses: [...Le, ...oT, ...FE],
9525
- reservedSetOperations: _e,
9526
- reservedJoins: re,
9527
- reservedKeywordPhrases: ne,
9528
- reservedDataTypePhrases: ie,
9581
+ reservedSelect: Le,
9582
+ reservedClauses: [..._e, ...oT, ...FE],
9583
+ reservedSetOperations: re,
9584
+ reservedJoins: ne,
9585
+ reservedKeywordPhrases: ie,
9586
+ reservedDataTypePhrases: De,
9529
9587
  supportsXor: !0,
9530
- reservedKeywords: Ne,
9531
- reservedDataTypes: se,
9532
- reservedFunctionNames: te,
9588
+ reservedKeywords: se,
9589
+ reservedDataTypes: te,
9590
+ reservedFunctionNames: Ce,
9533
9591
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
9534
9592
  stringTypes: [
9535
9593
  '""-qq-bs',
@@ -9570,7 +9628,7 @@ const $A = [
9570
9628
  onelineClauses: [...oT, ...FE],
9571
9629
  tabularOnelineClauses: FE
9572
9630
  }
9573
- }, ae = [
9631
+ }, oe = [
9574
9632
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/functions.html
9575
9633
  "ABORT",
9576
9634
  "ABS",
@@ -9800,7 +9858,7 @@ const $A = [
9800
9858
  // not implemented in N1QL, but added here now for the sake of tests
9801
9859
  // https://docs.couchbase.com/server/current/analytics/3_query.html#Vs_SQL-92
9802
9860
  "CAST"
9803
- ], oe = [
9861
+ ], Pe = [
9804
9862
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/reservedwords.html
9805
9863
  "ADVISE",
9806
9864
  "ALL",
@@ -10006,7 +10064,7 @@ const $A = [
10006
10064
  "WITHIN",
10007
10065
  "WORK",
10008
10066
  "XOR"
10009
- ], Pe = [
10067
+ ], Me = [
10010
10068
  // N1QL does not support any way of declaring types for columns.
10011
10069
  // It does not support the CREATE TABLE statement nor the CAST() expression.
10012
10070
  //
@@ -10015,7 +10073,7 @@ const $A = [
10015
10073
  // which it actually doesn't use.
10016
10074
  //
10017
10075
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datatypes.html
10018
- ], Me = _(["SELECT [ALL | DISTINCT]"]), Ue = _([
10076
+ ], Ue = _(["SELECT [ALL | DISTINCT]"]), Ge = _([
10019
10077
  // queries
10020
10078
  "WITH",
10021
10079
  "FROM",
@@ -10082,19 +10140,19 @@ const $A = [
10082
10140
  "SET CURRENT SCHEMA",
10083
10141
  "SHOW",
10084
10142
  "USE [PRIMARY] KEYS"
10085
- ]), Ge = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), le = _(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), ce = _(["{ROWS | RANGE | GROUPS} BETWEEN"]), ue = _([]), He = {
10143
+ ]), le = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), ce = _(["JOIN", "{LEFT | RIGHT} [OUTER] JOIN", "INNER JOIN"]), ue = _(["{ROWS | RANGE | GROUPS} BETWEEN"]), He = _([]), Be = {
10086
10144
  name: "n1ql",
10087
10145
  tokenizerOptions: {
10088
- reservedSelect: Me,
10089
- reservedClauses: [...Ue, ...PT],
10090
- reservedSetOperations: Ge,
10091
- reservedJoins: le,
10092
- reservedKeywordPhrases: ce,
10093
- reservedDataTypePhrases: ue,
10146
+ reservedSelect: Ue,
10147
+ reservedClauses: [...Ge, ...PT],
10148
+ reservedSetOperations: le,
10149
+ reservedJoins: ce,
10150
+ reservedKeywordPhrases: ue,
10151
+ reservedDataTypePhrases: He,
10094
10152
  supportsXor: !0,
10095
- reservedKeywords: oe,
10096
- reservedDataTypes: Pe,
10097
- reservedFunctionNames: ae,
10153
+ reservedKeywords: Pe,
10154
+ reservedDataTypes: Me,
10155
+ reservedFunctionNames: oe,
10098
10156
  // NOTE: single quotes are actually not supported in N1QL,
10099
10157
  // but we support them anyway as all other SQL dialects do,
10100
10158
  // which simplifies writing tests that are shared between all dialects.
@@ -10108,7 +10166,7 @@ const $A = [
10108
10166
  formatOptions: {
10109
10167
  onelineClauses: PT
10110
10168
  }
10111
- }, Be = [
10169
+ }, me = [
10112
10170
  // https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/reservewords.htm
10113
10171
  // 'A',
10114
10172
  "ADD",
@@ -10413,7 +10471,7 @@ const $A = [
10413
10471
  "WRITE",
10414
10472
  "YEAR",
10415
10473
  "ZONE"
10416
- ], me = [
10474
+ ], Fe = [
10417
10475
  // https://www.ibm.com/docs/en/db2/10.5?topic=plsql-data-types
10418
10476
  "ARRAY",
10419
10477
  "BFILE_BASE",
@@ -10451,7 +10509,7 @@ const $A = [
10451
10509
  "UROWID",
10452
10510
  "VARCHAR",
10453
10511
  "VARCHAR2"
10454
- ], Fe = [
10512
+ ], Ye = [
10455
10513
  // https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
10456
10514
  // numeric
10457
10515
  "ABS",
@@ -10716,7 +10774,7 @@ const $A = [
10716
10774
  "PRESENTNNV",
10717
10775
  "PRESENTV",
10718
10776
  "PREVIOUS"
10719
- ], Ye = _(["SELECT [ALL | DISTINCT | UNIQUE]"]), pe = _([
10777
+ ], pe = _(["SELECT [ALL | DISTINCT | UNIQUE]"]), de = _([
10720
10778
  // queries
10721
10779
  "WITH",
10722
10780
  "FROM",
@@ -10770,7 +10828,7 @@ const $A = [
10770
10828
  "EXCEPTION",
10771
10829
  "LOOP",
10772
10830
  "START WITH"
10773
- ]), de = _(["UNION [ALL]", "MINUS", "INTERSECT"]), he = _([
10831
+ ]), he = _(["UNION [ALL]", "MINUS", "INTERSECT"]), fe = _([
10774
10832
  "JOIN",
10775
10833
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
10776
10834
  "{INNER | CROSS} JOIN",
@@ -10778,23 +10836,23 @@ const $A = [
10778
10836
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN",
10779
10837
  // non-standard joins
10780
10838
  "{CROSS | OUTER} APPLY"
10781
- ]), fe = _([
10839
+ ]), Ve = _([
10782
10840
  "ON {UPDATE | DELETE} [SET NULL]",
10783
10841
  "ON COMMIT",
10784
10842
  "{ROWS | RANGE} BETWEEN"
10785
- ]), Ve = _([]), We = {
10843
+ ]), We = _([]), Xe = {
10786
10844
  name: "plsql",
10787
10845
  tokenizerOptions: {
10788
- reservedSelect: Ye,
10789
- reservedClauses: [...pe, ...MT, ...YE],
10790
- reservedSetOperations: de,
10791
- reservedJoins: he,
10792
- reservedKeywordPhrases: fe,
10793
- reservedDataTypePhrases: Ve,
10846
+ reservedSelect: pe,
10847
+ reservedClauses: [...de, ...MT, ...YE],
10848
+ reservedSetOperations: he,
10849
+ reservedJoins: fe,
10850
+ reservedKeywordPhrases: Ve,
10851
+ reservedDataTypePhrases: We,
10794
10852
  supportsXor: !0,
10795
- reservedKeywords: Be,
10796
- reservedDataTypes: me,
10797
- reservedFunctionNames: Fe,
10853
+ reservedKeywords: me,
10854
+ reservedDataTypes: Fe,
10855
+ reservedFunctionNames: Ye,
10798
10856
  stringTypes: [
10799
10857
  { quote: "''-qq", prefixes: ["N"] },
10800
10858
  { quote: "q''", prefixes: ["N"] }
@@ -10819,7 +10877,7 @@ const $A = [
10819
10877
  "@",
10820
10878
  "||"
10821
10879
  ],
10822
- postProcess: Xe
10880
+ postProcess: be
10823
10881
  },
10824
10882
  formatOptions: {
10825
10883
  alwaysDenseOperators: ["@"],
@@ -10827,11 +10885,11 @@ const $A = [
10827
10885
  tabularOnelineClauses: YE
10828
10886
  }
10829
10887
  };
10830
- function Xe(T) {
10831
- let E = j;
10832
- return T.map((R) => w.SET(R) && w.BY(E) ? Object.assign(Object.assign({}, R), { type: D.RESERVED_KEYWORD }) : (jT(R.type) && (E = R), R));
10888
+ function be(T) {
10889
+ let E = k;
10890
+ return T.map((R) => w.SET(R) && w.BY(E) ? Object.assign(Object.assign({}, R), { type: D.RESERVED_KEYWORD }) : (kT(R.type) && (E = R), R));
10833
10891
  }
10834
- const be = [
10892
+ const ye = [
10835
10893
  // https://www.postgresql.org/docs/14/functions.html
10836
10894
  //
10837
10895
  // https://www.postgresql.org/docs/14/functions-math.html
@@ -11515,7 +11573,7 @@ const be = [
11515
11573
  "PG_MCV_LIST_ITEMS",
11516
11574
  // cast
11517
11575
  "CAST"
11518
- ], ye = [
11576
+ ], Ke = [
11519
11577
  // https://www.postgresql.org/docs/14/sql-keywords-appendix.html
11520
11578
  "ALL",
11521
11579
  "ANALYSE",
@@ -11634,7 +11692,7 @@ const be = [
11634
11692
  "WITHOUT",
11635
11693
  "YEAR"
11636
11694
  // requires AS
11637
- ], Ke = [
11695
+ ], $e = [
11638
11696
  // https://www.postgresql.org/docs/current/datatype.html
11639
11697
  "ARRAY",
11640
11698
  "BIGINT",
@@ -11668,7 +11726,7 @@ const be = [
11668
11726
  "VARCHAR",
11669
11727
  "XML",
11670
11728
  "ZONE"
11671
- ], $e = _(["SELECT [ALL | DISTINCT]"]), ge = _([
11729
+ ], ge = _(["SELECT [ALL | DISTINCT]"]), we = _([
11672
11730
  // queries
11673
11731
  "WITH [RECURSIVE]",
11674
11732
  "FROM",
@@ -11891,17 +11949,17 @@ const be = [
11891
11949
  "START TRANSACTION",
11892
11950
  "UNLISTEN",
11893
11951
  "VACUUM"
11894
- ]), we = _([
11952
+ ]), Je = _([
11895
11953
  "UNION [ALL | DISTINCT]",
11896
11954
  "EXCEPT [ALL | DISTINCT]",
11897
11955
  "INTERSECT [ALL | DISTINCT]"
11898
- ]), Je = _([
11956
+ ]), xe = _([
11899
11957
  "JOIN",
11900
11958
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
11901
11959
  "{INNER | CROSS} JOIN",
11902
11960
  "NATURAL [INNER] JOIN",
11903
11961
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
11904
- ]), xe = _([
11962
+ ]), ve = _([
11905
11963
  "PRIMARY KEY",
11906
11964
  "GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY",
11907
11965
  "ON {UPDATE | DELETE} [NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT]",
@@ -11912,21 +11970,21 @@ const be = [
11912
11970
  "IS [NOT] DISTINCT FROM",
11913
11971
  "NULLS {FIRST | LAST}",
11914
11972
  "WITH ORDINALITY"
11915
- ]), ve = _([
11973
+ ]), Qe = _([
11916
11974
  // https://www.postgresql.org/docs/current/datatype-datetime.html
11917
11975
  "[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE"
11918
- ]), Qe = {
11976
+ ]), Ze = {
11919
11977
  name: "postgresql",
11920
11978
  tokenizerOptions: {
11921
- reservedSelect: $e,
11922
- reservedClauses: [...ge, ...UT, ...pE],
11923
- reservedSetOperations: we,
11924
- reservedJoins: Je,
11925
- reservedKeywordPhrases: xe,
11926
- reservedDataTypePhrases: ve,
11927
- reservedKeywords: ye,
11928
- reservedDataTypes: Ke,
11929
- reservedFunctionNames: be,
11979
+ reservedSelect: ge,
11980
+ reservedClauses: [...we, ...UT, ...pE],
11981
+ reservedSetOperations: Je,
11982
+ reservedJoins: xe,
11983
+ reservedKeywordPhrases: ve,
11984
+ reservedDataTypePhrases: Qe,
11985
+ reservedKeywords: Ke,
11986
+ reservedDataTypes: $e,
11987
+ reservedFunctionNames: ye,
11930
11988
  nestedBlockComments: !0,
11931
11989
  extraParens: ["[]"],
11932
11990
  underscoresInNumbers: !0,
@@ -12041,7 +12099,7 @@ const be = [
12041
12099
  onelineClauses: [...UT, ...pE],
12042
12100
  tabularOnelineClauses: pE
12043
12101
  }
12044
- }, Ze = [
12102
+ }, qe = [
12045
12103
  // https://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html
12046
12104
  "ANY_VALUE",
12047
12105
  "APPROXIMATE PERCENTILE_DISC",
@@ -12387,7 +12445,7 @@ const be = [
12387
12445
  "SLICE_NUM",
12388
12446
  "USER",
12389
12447
  "VERSION"
12390
- ], qe = [
12448
+ ], je = [
12391
12449
  // https://docs.aws.amazon.com/redshift/latest/dg/r_pg_keywords.html
12392
12450
  "AES128",
12393
12451
  "AES256",
@@ -12576,7 +12634,7 @@ const be = [
12576
12634
  * SVL: https://docs.aws.amazon.com/redshift/latest/dg/svl_views.html
12577
12635
  * SVV: https://docs.aws.amazon.com/redshift/latest/dg/svv_views.html
12578
12636
  */
12579
- ], je = [
12637
+ ], ke = [
12580
12638
  // https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-text-and-bpchar-types
12581
12639
  "ARRAY",
12582
12640
  "BIGINT",
@@ -12597,7 +12655,7 @@ const be = [
12597
12655
  "TEXT",
12598
12656
  "VARBYTE",
12599
12657
  "VARCHAR"
12600
- ], ke = _(["SELECT [ALL | DISTINCT]"]), ze = _([
12658
+ ], ze = _(["SELECT [ALL | DISTINCT]"]), ES = _([
12601
12659
  // queries
12602
12660
  "WITH [RECURSIVE]",
12603
12661
  "FROM",
@@ -12708,13 +12766,13 @@ const be = [
12708
12766
  "START TRANSACTION",
12709
12767
  "UNLOAD",
12710
12768
  "VACUUM"
12711
- ]), ES = _(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), TS = _([
12769
+ ]), TS = _(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), RS = _([
12712
12770
  "JOIN",
12713
12771
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
12714
12772
  "{INNER | CROSS} JOIN",
12715
12773
  "NATURAL [INNER] JOIN",
12716
12774
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
12717
- ]), RS = _([
12775
+ ]), AS = _([
12718
12776
  // https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html
12719
12777
  "NULL AS",
12720
12778
  // https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_SCHEMA.html
@@ -12722,18 +12780,18 @@ const be = [
12722
12780
  "HIVE METASTORE",
12723
12781
  // in window specifications
12724
12782
  "{ROWS | RANGE} BETWEEN"
12725
- ]), AS = _([]), eS = {
12783
+ ]), eS = _([]), SS = {
12726
12784
  name: "redshift",
12727
12785
  tokenizerOptions: {
12728
- reservedSelect: ke,
12729
- reservedClauses: [...ze, ...GT, ...dE],
12730
- reservedSetOperations: ES,
12731
- reservedJoins: TS,
12732
- reservedKeywordPhrases: RS,
12733
- reservedDataTypePhrases: AS,
12734
- reservedKeywords: qe,
12735
- reservedDataTypes: je,
12736
- reservedFunctionNames: Ze,
12786
+ reservedSelect: ze,
12787
+ reservedClauses: [...ES, ...GT, ...dE],
12788
+ reservedSetOperations: TS,
12789
+ reservedJoins: RS,
12790
+ reservedKeywordPhrases: AS,
12791
+ reservedDataTypePhrases: eS,
12792
+ reservedKeywords: je,
12793
+ reservedDataTypes: ke,
12794
+ reservedFunctionNames: qe,
12737
12795
  extraParens: ["[]"],
12738
12796
  stringTypes: ["''-qq"],
12739
12797
  identTypes: ['""-qq'],
@@ -12760,7 +12818,7 @@ const be = [
12760
12818
  onelineClauses: [...GT, ...dE],
12761
12819
  tabularOnelineClauses: dE
12762
12820
  }
12763
- }, SS = [
12821
+ }, IS = [
12764
12822
  // https://deepkb.com/CO_000013/en/kb/IMPORT-fbfa59f0-2bf1-31fe-bb7b-0f9efe9932c6/spark-sql-keywords
12765
12823
  "ADD",
12766
12824
  "AFTER",
@@ -13027,7 +13085,7 @@ const be = [
13027
13085
  "UNSIGNED",
13028
13086
  "VARIABLES",
13029
13087
  "YEAR_MONTH"
13030
- ], IS = [
13088
+ ], OS = [
13031
13089
  // https://spark.apache.org/docs/latest/sql-ref-datatypes.html
13032
13090
  "ARRAY",
13033
13091
  "BIGINT",
@@ -13057,7 +13115,7 @@ const be = [
13057
13115
  "TINYINT",
13058
13116
  "VARCHAR"
13059
13117
  // No varchar type in Spark, only STRING. Added for the sake of tests
13060
- ], OS = [
13118
+ ], NS = [
13061
13119
  // http://spark.apache.org/docs/latest/sql-ref-functions.html
13062
13120
  //
13063
13121
  // http://spark.apache.org/docs/latest/sql-ref-functions-builtin.html#aggregate-functions
@@ -13378,7 +13436,7 @@ const be = [
13378
13436
  // Shorthand functions to use in place of CASE expression
13379
13437
  "COALESCE",
13380
13438
  "NULLIF"
13381
- ], NS = _(["SELECT [ALL | DISTINCT]"]), sS = _([
13439
+ ], sS = _(["SELECT [ALL | DISTINCT]"]), tS = _([
13382
13440
  // queries
13383
13441
  "WITH",
13384
13442
  "FROM",
@@ -13459,11 +13517,11 @@ const be = [
13459
13517
  "SHOW TBLPROPERTIES",
13460
13518
  "SHOW VIEWS",
13461
13519
  "UNCACHE TABLE"
13462
- ]), tS = _([
13520
+ ]), CS = _([
13463
13521
  "UNION [ALL | DISTINCT]",
13464
13522
  "EXCEPT [ALL | DISTINCT]",
13465
13523
  "INTERSECT [ALL | DISTINCT]"
13466
- ]), CS = _([
13524
+ ]), LS = _([
13467
13525
  "JOIN",
13468
13526
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13469
13527
  "{INNER | CROSS} JOIN",
@@ -13472,24 +13530,24 @@ const be = [
13472
13530
  // non-standard-joins
13473
13531
  "[LEFT] {ANTI | SEMI} JOIN",
13474
13532
  "NATURAL [LEFT] {ANTI | SEMI} JOIN"
13475
- ]), LS = _([
13533
+ ]), _S = _([
13476
13534
  "ON DELETE",
13477
13535
  "ON UPDATE",
13478
13536
  "CURRENT ROW",
13479
13537
  "{ROWS | RANGE} BETWEEN"
13480
- ]), _S = _([]), rS = {
13538
+ ]), rS = _([]), nS = {
13481
13539
  name: "spark",
13482
13540
  tokenizerOptions: {
13483
- reservedSelect: NS,
13484
- reservedClauses: [...sS, ...lT, ...hE],
13485
- reservedSetOperations: tS,
13486
- reservedJoins: CS,
13487
- reservedKeywordPhrases: LS,
13488
- reservedDataTypePhrases: _S,
13541
+ reservedSelect: sS,
13542
+ reservedClauses: [...tS, ...lT, ...hE],
13543
+ reservedSetOperations: CS,
13544
+ reservedJoins: LS,
13545
+ reservedKeywordPhrases: _S,
13546
+ reservedDataTypePhrases: rS,
13489
13547
  supportsXor: !0,
13490
- reservedKeywords: SS,
13491
- reservedDataTypes: IS,
13492
- reservedFunctionNames: OS,
13548
+ reservedKeywords: IS,
13549
+ reservedDataTypes: OS,
13550
+ reservedFunctionNames: NS,
13493
13551
  extraParens: ["[]"],
13494
13552
  stringTypes: [
13495
13553
  "''-bs",
@@ -13501,20 +13559,20 @@ const be = [
13501
13559
  identChars: { allowFirstCharNumber: !0 },
13502
13560
  variableTypes: [{ quote: "{}", prefixes: ["$"], requirePrefix: !0 }],
13503
13561
  operators: ["%", "~", "^", "|", "&", "<=>", "==", "!", "||", "->"],
13504
- postProcess: nS
13562
+ postProcess: iS
13505
13563
  },
13506
13564
  formatOptions: {
13507
13565
  onelineClauses: [...lT, ...hE],
13508
13566
  tabularOnelineClauses: hE
13509
13567
  }
13510
13568
  };
13511
- function nS(T) {
13569
+ function iS(T) {
13512
13570
  return T.map((E, R) => {
13513
- const A = T[R - 1] || j, e = T[R + 1] || j;
13571
+ const A = T[R - 1] || k, e = T[R + 1] || k;
13514
13572
  return w.WINDOW(E) && e.type === D.OPEN_PAREN ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E.text === "ITEMS" && E.type === D.RESERVED_KEYWORD && !(A.text === "COLLECTION" && e.text === "TERMINATED") ? Object.assign(Object.assign({}, E), { type: D.IDENTIFIER, text: E.raw }) : E;
13515
13573
  });
13516
13574
  }
13517
- const iS = [
13575
+ const DS = [
13518
13576
  // https://www.sqlite.org/lang_corefunc.html
13519
13577
  "ABS",
13520
13578
  "CHANGES",
@@ -13638,7 +13696,7 @@ const iS = [
13638
13696
  "JSON_TREE",
13639
13697
  // cast
13640
13698
  "CAST"
13641
- ], DS = [
13699
+ ], aS = [
13642
13700
  // https://www.sqlite.org/lang_keywords.html
13643
13701
  // Note: The keywords listed on that URL are not all reserved keywords.
13644
13702
  // We'll need to clean up this list to only include reserved keywords.
@@ -13791,7 +13849,7 @@ const iS = [
13791
13849
  "WINDOW",
13792
13850
  "WITH",
13793
13851
  "WITHOUT"
13794
- ], aS = [
13852
+ ], oS = [
13795
13853
  // SQLite allows any word as a data type, e.g. CREATE TABLE foo (col1 madeupname(123));
13796
13854
  // Here we just list some common ones as SQL Formatter
13797
13855
  // is only able to detect a predefined list of data types.
@@ -13812,7 +13870,7 @@ const iS = [
13812
13870
  "TEXT",
13813
13871
  "VARCHAR",
13814
13872
  "VARYING CHARACTER"
13815
- ], oS = _(["SELECT [ALL | DISTINCT]"]), PS = _([
13873
+ ], PS = _(["SELECT [ALL | DISTINCT]"]), MS = _([
13816
13874
  // queries
13817
13875
  "WITH [RECURSIVE]",
13818
13876
  "FROM",
@@ -13852,28 +13910,28 @@ const iS = [
13852
13910
  "RENAME TO",
13853
13911
  // - set schema
13854
13912
  "SET SCHEMA"
13855
- ]), MS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), US = _([
13913
+ ]), US = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), GS = _([
13856
13914
  "JOIN",
13857
13915
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13858
13916
  "{INNER | CROSS} JOIN",
13859
13917
  "NATURAL [INNER] JOIN",
13860
13918
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
13861
- ]), GS = _([
13919
+ ]), lS = _([
13862
13920
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
13863
13921
  "{ROWS | RANGE | GROUPS} BETWEEN",
13864
13922
  "DO UPDATE"
13865
- ]), lS = _([]), cS = {
13923
+ ]), cS = _([]), uS = {
13866
13924
  name: "sqlite",
13867
13925
  tokenizerOptions: {
13868
- reservedSelect: oS,
13869
- reservedClauses: [...PS, ...cT, ...fE],
13870
- reservedSetOperations: MS,
13871
- reservedJoins: US,
13872
- reservedKeywordPhrases: GS,
13873
- reservedDataTypePhrases: lS,
13874
- reservedKeywords: DS,
13875
- reservedDataTypes: aS,
13876
- reservedFunctionNames: iS,
13926
+ reservedSelect: PS,
13927
+ reservedClauses: [...MS, ...cT, ...fE],
13928
+ reservedSetOperations: US,
13929
+ reservedJoins: GS,
13930
+ reservedKeywordPhrases: lS,
13931
+ reservedDataTypePhrases: cS,
13932
+ reservedKeywords: aS,
13933
+ reservedDataTypes: oS,
13934
+ reservedFunctionNames: DS,
13877
13935
  stringTypes: [
13878
13936
  "''-qq",
13879
13937
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -13889,7 +13947,7 @@ const iS = [
13889
13947
  onelineClauses: [...cT, ...fE],
13890
13948
  tabularOnelineClauses: fE
13891
13949
  }
13892
- }, uS = [
13950
+ }, HS = [
13893
13951
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_9_set_function_specification
13894
13952
  "GROUPING",
13895
13953
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_10_window_function
@@ -13986,7 +14044,7 @@ const iS = [
13986
14044
  "ASIN",
13987
14045
  "ACOS",
13988
14046
  "ATAN"
13989
- ], HS = [
14047
+ ], BS = [
13990
14048
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#reserved-word
13991
14049
  "ALL",
13992
14050
  "ALLOCATE",
@@ -14184,7 +14242,7 @@ const iS = [
14184
14242
  "WITHIN",
14185
14243
  "WITHOUT",
14186
14244
  "YEAR"
14187
- ], BS = [
14245
+ ], mS = [
14188
14246
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_1_data_type
14189
14247
  "ARRAY",
14190
14248
  "BIGINT",
@@ -14224,7 +14282,7 @@ const iS = [
14224
14282
  "TIMESTAMP",
14225
14283
  "VARBINARY",
14226
14284
  "VARCHAR"
14227
- ], mS = _(["SELECT [ALL | DISTINCT]"]), FS = _([
14285
+ ], FS = _(["SELECT [ALL | DISTINCT]"]), YS = _([
14228
14286
  // queries
14229
14287
  "WITH [RECURSIVE]",
14230
14288
  "FROM",
@@ -14268,31 +14326,31 @@ const iS = [
14268
14326
  "TRUNCATE TABLE",
14269
14327
  // other
14270
14328
  "SET SCHEMA"
14271
- ]), YS = _([
14329
+ ]), pS = _([
14272
14330
  "UNION [ALL | DISTINCT]",
14273
14331
  "EXCEPT [ALL | DISTINCT]",
14274
14332
  "INTERSECT [ALL | DISTINCT]"
14275
- ]), pS = _([
14333
+ ]), dS = _([
14276
14334
  "JOIN",
14277
14335
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14278
14336
  "{INNER | CROSS} JOIN",
14279
14337
  "NATURAL [INNER] JOIN",
14280
14338
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
14281
- ]), dS = _([
14339
+ ]), hS = _([
14282
14340
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
14283
14341
  "{ROWS | RANGE} BETWEEN"
14284
- ]), hS = _([]), fS = {
14342
+ ]), fS = _([]), VS = {
14285
14343
  name: "sql",
14286
14344
  tokenizerOptions: {
14287
- reservedSelect: mS,
14288
- reservedClauses: [...FS, ...uT, ...VE],
14289
- reservedSetOperations: YS,
14290
- reservedJoins: pS,
14291
- reservedKeywordPhrases: dS,
14292
- reservedDataTypePhrases: hS,
14293
- reservedKeywords: HS,
14294
- reservedDataTypes: BS,
14295
- reservedFunctionNames: uS,
14345
+ reservedSelect: FS,
14346
+ reservedClauses: [...YS, ...uT, ...VE],
14347
+ reservedSetOperations: pS,
14348
+ reservedJoins: dS,
14349
+ reservedKeywordPhrases: hS,
14350
+ reservedDataTypePhrases: fS,
14351
+ reservedKeywords: BS,
14352
+ reservedDataTypes: mS,
14353
+ reservedFunctionNames: HS,
14296
14354
  stringTypes: [
14297
14355
  { quote: "''-qq-bs", prefixes: ["N", "U&"] },
14298
14356
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -14305,7 +14363,7 @@ const iS = [
14305
14363
  onelineClauses: [...uT, ...VE],
14306
14364
  tabularOnelineClauses: VE
14307
14365
  }
14308
- }, VS = [
14366
+ }, WS = [
14309
14367
  // https://github.com/trinodb/trino/tree/432d2897bdef99388c1a47188743a061c4ac1f34/docs/src/main/sphinx/functions
14310
14368
  // rg '^\.\. function::' ./docs/src/main/sphinx/functions | cut -d' ' -f 3 | cut -d '(' -f 1 | sort | uniq
14311
14369
  // rg '\* ' ./docs/src/main/sphinx/functions/list-by-topic.rst | grep '\* :func:' | cut -d'`' -f 2
@@ -14739,7 +14797,7 @@ const iS = [
14739
14797
  "NEXT",
14740
14798
  "PERMUTE",
14741
14799
  "PREV"
14742
- ], WS = [
14800
+ ], XS = [
14743
14801
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4#L858-L1128
14744
14802
  "ABSENT",
14745
14803
  "ADD",
@@ -14976,7 +15034,7 @@ const iS = [
14976
15034
  "WRAPPER",
14977
15035
  "WRITE",
14978
15036
  "ZONE"
14979
- ], XS = [
15037
+ ], bS = [
14980
15038
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-main/src/main/java/io/trino/metadata/TypeRegistry.java#L131-L168
14981
15039
  // or https://trino.io/docs/current/language/types.html
14982
15040
  "BIGINT",
@@ -15015,7 +15073,7 @@ const iS = [
15015
15073
  "CODEPOINTS",
15016
15074
  "FUNCTION",
15017
15075
  "JSONPATH"
15018
- ], bS = _(["SELECT [ALL | DISTINCT]"]), yS = _([
15076
+ ], yS = _(["SELECT [ALL | DISTINCT]"]), KS = _([
15019
15077
  // queries
15020
15078
  "WITH [RECURSIVE]",
15021
15079
  "FROM",
@@ -15101,32 +15159,32 @@ const iS = [
15101
15159
  "SHOW ROLE GRANTS",
15102
15160
  "SHOW FUNCTIONS",
15103
15161
  "SHOW SESSION"
15104
- ]), KS = _([
15162
+ ]), $S = _([
15105
15163
  "UNION [ALL | DISTINCT]",
15106
15164
  "EXCEPT [ALL | DISTINCT]",
15107
15165
  "INTERSECT [ALL | DISTINCT]"
15108
- ]), $S = _([
15166
+ ]), gS = _([
15109
15167
  "JOIN",
15110
15168
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15111
15169
  "{INNER | CROSS} JOIN",
15112
15170
  "NATURAL [INNER] JOIN",
15113
15171
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
15114
- ]), gS = _([
15172
+ ]), wS = _([
15115
15173
  "{ROWS | RANGE | GROUPS} BETWEEN",
15116
15174
  // comparison operator
15117
15175
  "IS [NOT] DISTINCT FROM"
15118
- ]), wS = _([]), JS = {
15176
+ ]), JS = _([]), xS = {
15119
15177
  name: "trino",
15120
15178
  tokenizerOptions: {
15121
- reservedSelect: bS,
15122
- reservedClauses: [...yS, ...HT, ...WE],
15123
- reservedSetOperations: KS,
15124
- reservedJoins: $S,
15125
- reservedKeywordPhrases: gS,
15126
- reservedDataTypePhrases: wS,
15127
- reservedKeywords: WS,
15128
- reservedDataTypes: XS,
15129
- reservedFunctionNames: VS,
15179
+ reservedSelect: yS,
15180
+ reservedClauses: [...KS, ...HT, ...WE],
15181
+ reservedSetOperations: $S,
15182
+ reservedJoins: gS,
15183
+ reservedKeywordPhrases: wS,
15184
+ reservedDataTypePhrases: JS,
15185
+ reservedKeywords: XS,
15186
+ reservedDataTypes: bS,
15187
+ reservedFunctionNames: WS,
15130
15188
  // Trino also supports {- ... -} parenthesis.
15131
15189
  // The formatting of these currently works out as a result of { and -
15132
15190
  // not getting a space added in-between.
@@ -15158,7 +15216,7 @@ const iS = [
15158
15216
  onelineClauses: [...HT, ...WE],
15159
15217
  tabularOnelineClauses: WE
15160
15218
  }
15161
- }, xS = [
15219
+ }, vS = [
15162
15220
  // https://docs.microsoft.com/en-us/sql/t-sql/functions/functions?view=sql-server-ver15
15163
15221
  // aggregate
15164
15222
  "APPROX_COUNT_DISTINCT",
@@ -15463,7 +15521,7 @@ const iS = [
15463
15521
  // Shorthand functions to use in place of CASE expression
15464
15522
  "COALESCE",
15465
15523
  "NULLIF"
15466
- ], vS = [
15524
+ ], QS = [
15467
15525
  // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15
15468
15526
  // standard
15469
15527
  "ADD",
@@ -15644,7 +15702,7 @@ const iS = [
15644
15702
  "WRITETEXT",
15645
15703
  // https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-ver16#action
15646
15704
  "$ACTION"
15647
- ], QS = [
15705
+ ], ZS = [
15648
15706
  // https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15
15649
15707
  "BINARY",
15650
15708
  "BIT",
@@ -15671,7 +15729,7 @@ const iS = [
15671
15729
  "TIMESTAMP",
15672
15730
  "VARBINARY",
15673
15731
  "VARCHAR"
15674
- ], ZS = _(["SELECT [ALL | DISTINCT]"]), qS = _([
15732
+ ], qS = _(["SELECT [ALL | DISTINCT]"]), jS = _([
15675
15733
  // queries
15676
15734
  "WITH",
15677
15735
  "INTO",
@@ -15876,27 +15934,27 @@ const iS = [
15876
15934
  "XACT_ABORT",
15877
15935
  "XML INDEX",
15878
15936
  "XML SCHEMA COLLECTION"
15879
- ]), jS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), kS = _([
15937
+ ]), kS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), zS = _([
15880
15938
  "JOIN",
15881
15939
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15882
15940
  "{INNER | CROSS} JOIN",
15883
15941
  // non-standard joins
15884
15942
  "{CROSS | OUTER} APPLY"
15885
- ]), zS = _([
15943
+ ]), EI = _([
15886
15944
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
15887
15945
  "{ROWS | RANGE} BETWEEN"
15888
- ]), EI = _([]), TI = {
15946
+ ]), TI = _([]), RI = {
15889
15947
  name: "transactsql",
15890
15948
  tokenizerOptions: {
15891
- reservedSelect: ZS,
15892
- reservedClauses: [...qS, ...BT, ...XE],
15893
- reservedSetOperations: jS,
15894
- reservedJoins: kS,
15895
- reservedKeywordPhrases: zS,
15896
- reservedDataTypePhrases: EI,
15897
- reservedKeywords: vS,
15898
- reservedDataTypes: QS,
15899
- reservedFunctionNames: xS,
15949
+ reservedSelect: qS,
15950
+ reservedClauses: [...jS, ...BT, ...XE],
15951
+ reservedSetOperations: kS,
15952
+ reservedJoins: zS,
15953
+ reservedKeywordPhrases: EI,
15954
+ reservedDataTypePhrases: TI,
15955
+ reservedKeywords: QS,
15956
+ reservedDataTypes: ZS,
15957
+ reservedFunctionNames: vS,
15900
15958
  nestedBlockComments: !0,
15901
15959
  stringTypes: [{ quote: "''-qq", prefixes: ["N"] }, "{}"],
15902
15960
  identTypes: ['""-qq', "[]"],
@@ -15929,7 +15987,7 @@ const iS = [
15929
15987
  onelineClauses: [...BT, ...XE],
15930
15988
  tabularOnelineClauses: XE
15931
15989
  }
15932
- }, RI = [
15990
+ }, AI = [
15933
15991
  // List of all keywords taken from:
15934
15992
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/restricted-keywords/list-of-restricted-keywords.html
15935
15993
  // Then filtered down to reserved keywords by running
@@ -16142,7 +16200,7 @@ const iS = [
16142
16200
  "XOR",
16143
16201
  "YEAR_MONTH",
16144
16202
  "ZEROFILL"
16145
- ], AI = [
16203
+ ], eI = [
16146
16204
  // https://docs.singlestore.com/cloud/reference/sql-reference/data-types/
16147
16205
  "BIGINT",
16148
16206
  "BINARY",
@@ -16191,7 +16249,7 @@ const iS = [
16191
16249
  "VARCHAR",
16192
16250
  "VARCHARACTER",
16193
16251
  "YEAR"
16194
- ], eI = [
16252
+ ], SI = [
16195
16253
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions/vector-functions.html
16196
16254
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/window-functions/window-functions.html
16197
16255
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/string-functions/string-functions.html
@@ -16471,7 +16529,7 @@ const iS = [
16471
16529
  "WEEKDAY",
16472
16530
  "WEEKOFYEAR",
16473
16531
  "YEAR"
16474
- ], SI = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), II = _([
16532
+ ], II = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), OI = _([
16475
16533
  // queries
16476
16534
  "WITH",
16477
16535
  "FROM",
@@ -16672,36 +16730,36 @@ const iS = [
16672
16730
  "REPEAT",
16673
16731
  "RETURN",
16674
16732
  "WHILE"
16675
- ]), OI = _([
16733
+ ]), NI = _([
16676
16734
  "UNION [ALL | DISTINCT]",
16677
16735
  "EXCEPT",
16678
16736
  "INTERSECT",
16679
16737
  "MINUS"
16680
- ]), NI = _([
16738
+ ]), sI = _([
16681
16739
  "JOIN",
16682
16740
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
16683
16741
  "{INNER | CROSS} JOIN",
16684
16742
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
16685
16743
  // non-standard joins
16686
16744
  "STRAIGHT_JOIN"
16687
- ]), sI = _([
16745
+ ]), tI = _([
16688
16746
  "ON DELETE",
16689
16747
  "ON UPDATE",
16690
16748
  "CHARACTER SET",
16691
16749
  "{ROWS | RANGE} BETWEEN",
16692
16750
  "IDENTIFIED BY"
16693
- ]), tI = _([]), CI = {
16751
+ ]), CI = _([]), LI = {
16694
16752
  name: "singlestoredb",
16695
16753
  tokenizerOptions: {
16696
- reservedSelect: SI,
16697
- reservedClauses: [...II, ...mT, ...bE],
16698
- reservedSetOperations: OI,
16699
- reservedJoins: NI,
16700
- reservedKeywordPhrases: sI,
16701
- reservedDataTypePhrases: tI,
16702
- reservedKeywords: RI,
16703
- reservedDataTypes: AI,
16704
- reservedFunctionNames: eI,
16754
+ reservedSelect: II,
16755
+ reservedClauses: [...OI, ...mT, ...bE],
16756
+ reservedSetOperations: NI,
16757
+ reservedJoins: sI,
16758
+ reservedKeywordPhrases: tI,
16759
+ reservedDataTypePhrases: CI,
16760
+ reservedKeywords: AI,
16761
+ reservedDataTypes: eI,
16762
+ reservedFunctionNames: SI,
16705
16763
  // TODO: support _binary"some string" prefix
16706
16764
  stringTypes: [
16707
16765
  '""-qq-bs',
@@ -16741,7 +16799,7 @@ const iS = [
16741
16799
  onelineClauses: [...mT, ...bE],
16742
16800
  tabularOnelineClauses: bE
16743
16801
  }
16744
- }, LI = [
16802
+ }, _I = [
16745
16803
  // https://docs.snowflake.com/en/sql-reference-functions.html
16746
16804
  //
16747
16805
  // https://docs.snowflake.com/en/sql-reference/functions-all.html
@@ -17349,7 +17407,7 @@ const iS = [
17349
17407
  "QUARTER",
17350
17408
  "ZEROIFNULL",
17351
17409
  "ZIPF"
17352
- ], _I = [
17410
+ ], rI = [
17353
17411
  // https://docs.snowflake.com/en/sql-reference/reserved-keywords.html
17354
17412
  //
17355
17413
  // run in console on this page: $x('//tbody/tr/*[1]/p/text()').map(x => x.nodeValue)
@@ -17446,7 +17504,7 @@ const iS = [
17446
17504
  "WITH",
17447
17505
  // These are definitely keywords, but haven't found a definite list in the docs
17448
17506
  "COMMENT"
17449
- ], rI = [
17507
+ ], nI = [
17450
17508
  "NUMBER",
17451
17509
  "DECIMAL",
17452
17510
  "NUMERIC",
@@ -17483,7 +17541,7 @@ const iS = [
17483
17541
  "ARRAY",
17484
17542
  "GEOGRAPHY",
17485
17543
  "GEOMETRY"
17486
- ], nI = _(["SELECT [ALL | DISTINCT]"]), iI = _([
17544
+ ], iI = _(["SELECT [ALL | DISTINCT]"]), DI = _([
17487
17545
  // queries
17488
17546
  "WITH [RECURSIVE]",
17489
17547
  "FROM",
@@ -17755,25 +17813,25 @@ const iS = [
17755
17813
  "USE SCHEMA",
17756
17814
  "USE SECONDARY ROLES",
17757
17815
  "USE WAREHOUSE"
17758
- ]), DI = _(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), aI = _([
17816
+ ]), aI = _(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), oI = _([
17759
17817
  "[INNER] JOIN",
17760
17818
  "[NATURAL] {LEFT | RIGHT | FULL} [OUTER] JOIN",
17761
17819
  "{CROSS | NATURAL} JOIN"
17762
- ]), oI = _([
17820
+ ]), PI = _([
17763
17821
  "{ROWS | RANGE} BETWEEN",
17764
17822
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]"
17765
- ]), PI = _([]), MI = {
17823
+ ]), MI = _([]), UI = {
17766
17824
  name: "snowflake",
17767
17825
  tokenizerOptions: {
17768
- reservedSelect: nI,
17769
- reservedClauses: [...iI, ...FT, ...yE],
17770
- reservedSetOperations: DI,
17771
- reservedJoins: aI,
17772
- reservedKeywordPhrases: oI,
17773
- reservedDataTypePhrases: PI,
17774
- reservedKeywords: _I,
17775
- reservedDataTypes: rI,
17776
- reservedFunctionNames: LI,
17826
+ reservedSelect: iI,
17827
+ reservedClauses: [...DI, ...FT, ...yE],
17828
+ reservedSetOperations: aI,
17829
+ reservedJoins: oI,
17830
+ reservedKeywordPhrases: PI,
17831
+ reservedDataTypePhrases: MI,
17832
+ reservedKeywords: rI,
17833
+ reservedDataTypes: nI,
17834
+ reservedFunctionNames: _I,
17777
17835
  stringTypes: ["$$", "''-qq-bs"],
17778
17836
  identTypes: ['""-qq'],
17779
17837
  variableTypes: [
@@ -17806,43 +17864,43 @@ const iS = [
17806
17864
  onelineClauses: [...FT, ...yE],
17807
17865
  tabularOnelineClauses: yE
17808
17866
  }
17809
- }, UI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17867
+ }, GI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17810
17868
  __proto__: null,
17811
- bigquery: jR,
17812
- db2: CA,
17813
- db2i: MA,
17814
- duckdb: YA,
17815
- hive: KA,
17816
- mariadb: jA,
17817
- mysql: Oe,
17818
- n1ql: He,
17819
- plsql: We,
17820
- postgresql: Qe,
17821
- redshift: eS,
17822
- singlestoredb: CI,
17823
- snowflake: MI,
17824
- spark: rS,
17825
- sql: fS,
17826
- sqlite: cS,
17827
- tidb: De,
17828
- transactsql: TI,
17829
- trino: JS
17830
- }, Symbol.toStringTag, { value: "Module" })), EE = (T) => T[T.length - 1], kT = (T) => T.sort((E, R) => R.length - E.length || E.localeCompare(R)), AE = (T) => T.replace(/\s+/gu, " "), KE = (T) => /\n/.test(T), X = (T) => T.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"), YT = /\s+/uy, J = (T) => new RegExp(`(?:${T})`, "uy"), GI = (T) => T.split("").map((E) => / /gu.test(E) ? "\\s+" : `[${E.toUpperCase()}${E.toLowerCase()}]`).join(""), lI = (T) => T + "(?:-" + T + ")*", cI = ({ prefixes: T, requirePrefix: E }) => `(?:${T.map(GI).join("|")}${E ? "" : "|"})`, uI = (T) => new RegExp(`(?:${T.map(X).join("|")}).*?(?=\r
17869
+ bigquery: kR,
17870
+ db2: LA,
17871
+ db2i: UA,
17872
+ duckdb: pA,
17873
+ hive: $A,
17874
+ mariadb: kA,
17875
+ mysql: Ne,
17876
+ n1ql: Be,
17877
+ plsql: Xe,
17878
+ postgresql: Ze,
17879
+ redshift: SS,
17880
+ singlestoredb: LI,
17881
+ snowflake: UI,
17882
+ spark: nS,
17883
+ sql: VS,
17884
+ sqlite: uS,
17885
+ tidb: ae,
17886
+ transactsql: RI,
17887
+ trino: xS
17888
+ }, Symbol.toStringTag, { value: "Module" })), TE = (T) => T[T.length - 1], zT = (T) => T.sort((E, R) => R.length - E.length || E.localeCompare(R)), eE = (T) => T.replace(/\s+/gu, " "), KE = (T) => /\n/.test(T), X = (T) => T.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&"), YT = /\s+/uy, J = (T) => new RegExp(`(?:${T})`, "uy"), lI = (T) => T.split("").map((E) => / /gu.test(E) ? "\\s+" : `[${E.toUpperCase()}${E.toLowerCase()}]`).join(""), cI = (T) => T + "(?:-" + T + ")*", uI = ({ prefixes: T, requirePrefix: E }) => `(?:${T.map(lI).join("|")}${E ? "" : "|"})`, HI = (T) => new RegExp(`(?:${T.map(X).join("|")}).*?(?=\r
17831
17889
  |\r|
17832
17890
  |$)`, "uy"), pT = (T, E = []) => {
17833
17891
  const R = T === "open" ? 0 : 1, A = ["()", ...E].map((e) => e[R]);
17834
17892
  return J(A.map(X).join("|"));
17835
- }, dT = (T) => J(`${kT(T).map(X).join("|")}`), HI = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", y = (T, E = {}) => {
17893
+ }, dT = (T) => J(`${zT(T).map(X).join("|")}`), BI = ({ rest: T, dashes: E }) => T || E ? `(?![${T || ""}${E ? "-" : ""}])` : "", y = (T, E = {}) => {
17836
17894
  if (T.length === 0)
17837
17895
  return /^\b$/u;
17838
- const R = HI(E), A = kT(T).map(X).join("|").replace(/ /gu, "\\s+");
17896
+ const R = BI(E), A = zT(T).map(X).join("|").replace(/ /gu, "\\s+");
17839
17897
  return new RegExp(`(?:${A})${R}\\b`, "iuy");
17840
17898
  }, $E = (T, E) => {
17841
17899
  if (!T.length)
17842
17900
  return;
17843
17901
  const R = T.map(X).join("|");
17844
17902
  return J(`(?:${R})(?:${E})`);
17845
- }, BI = () => {
17903
+ }, mI = () => {
17846
17904
  const T = {
17847
17905
  "<": ">",
17848
17906
  "[": "]",
@@ -17874,16 +17932,16 @@ const iS = [
17874
17932
  // Hive and Spark variables: ${name}
17875
17933
  "{}": String.raw`(?:\{[^\}]*\})`,
17876
17934
  // Oracle q'' strings: q'<text>' q'|text|' ...
17877
- "q''": BI()
17878
- }, zT = (T) => typeof T == "string" ? hT[T] : "regex" in T ? T.regex : cI(T) + hT[T.quote], mI = (T) => J(T.map((E) => "regex" in E ? E.regex : zT(E)).join("|")), ER = (T) => T.map(zT).join("|"), fT = (T) => J(ER(T)), FI = (T = {}) => J(TR(T)), TR = ({ first: T, rest: E, dashes: R, allowFirstCharNumber: A } = {}) => {
17935
+ "q''": mI()
17936
+ }, ER = (T) => typeof T == "string" ? hT[T] : "regex" in T ? T.regex : uI(T) + hT[T.quote], FI = (T) => J(T.map((E) => "regex" in E ? E.regex : ER(E)).join("|")), TR = (T) => T.map(ER).join("|"), fT = (T) => J(TR(T)), YI = (T = {}) => J(RR(T)), RR = ({ first: T, rest: E, dashes: R, allowFirstCharNumber: A } = {}) => {
17879
17937
  const e = "\\p{Alphabetic}\\p{Mark}_", S = "\\p{Decimal_Number}", N = X(T ?? ""), t = X(E ?? ""), r = A ? `[${e}${S}${N}][${e}${S}${t}]*` : `[${e}${N}][${e}${S}${t}]*`;
17880
- return R ? lI(r) : r;
17938
+ return R ? cI(r) : r;
17881
17939
  };
17882
- function RR(T, E) {
17940
+ function AR(T, E) {
17883
17941
  const R = T.slice(0, E).split(/\n/);
17884
17942
  return { line: R.length, col: R[R.length - 1].length + 1 };
17885
17943
  }
17886
- class YI {
17944
+ class pI {
17887
17945
  constructor(E, R) {
17888
17946
  this.rules = E, this.dialectName = R, this.input = "", this.index = 0;
17889
17947
  }
@@ -17909,7 +17967,7 @@ class YI {
17909
17967
  return R;
17910
17968
  }
17911
17969
  createParseError() {
17912
- const E = this.input.slice(this.index, this.index + 10), { line: R, col: A } = RR(this.input, this.index);
17970
+ const E = this.input.slice(this.index, this.index + 10), { line: R, col: A } = AR(this.input, this.index);
17913
17971
  return new Error(`Parse error: Unexpected "${E}" at line ${R} column ${A}.
17914
17972
  ${this.dialectInfo()}`);
17915
17973
  }
@@ -17945,8 +18003,8 @@ If possible, please select a more specific dialect (like sqlite, postgresql, etc
17945
18003
  }
17946
18004
  }
17947
18005
  }
17948
- const VT = /\/\*/uy, pI = /[\s\S]/uy, dI = /\*\//uy;
17949
- class hI {
18006
+ const VT = /\/\*/uy, dI = /[\s\S]/uy, hI = /\*\//uy;
18007
+ class fI {
17950
18008
  constructor() {
17951
18009
  this.lastIndex = 0;
17952
18010
  }
@@ -17959,9 +18017,9 @@ class hI {
17959
18017
  for (; e > 0; )
17960
18018
  if (A = this.matchSection(VT, E))
17961
18019
  R += A, e++;
17962
- else if (A = this.matchSection(dI, E))
18020
+ else if (A = this.matchSection(hI, E))
17963
18021
  R += A, e--;
17964
- else if (A = this.matchSection(pI, E))
18022
+ else if (A = this.matchSection(dI, E))
17965
18023
  R += A;
17966
18024
  else
17967
18025
  return null;
@@ -17973,7 +18031,7 @@ class hI {
17973
18031
  return A && (this.lastIndex += A[0].length), A ? A[0] : null;
17974
18032
  }
17975
18033
  }
17976
- class fI {
18034
+ class VI {
17977
18035
  constructor(E, R) {
17978
18036
  this.cfg = E, this.dialectName = R, this.rulesBeforeParams = this.buildRulesBeforeParams(E), this.rulesAfterParams = this.buildRulesAfterParams(E);
17979
18037
  }
@@ -17982,7 +18040,7 @@ class fI {
17982
18040
  ...this.rulesBeforeParams,
17983
18041
  ...this.buildParamRules(this.cfg, R),
17984
18042
  ...this.rulesAfterParams
17985
- ], e = new YI(A, this.dialectName).tokenize(E);
18043
+ ], e = new pI(A, this.dialectName).tokenize(E);
17986
18044
  return this.cfg.postProcess ? this.cfg.postProcess(e) : e;
17987
18045
  }
17988
18046
  // These rules can be cached as they only depend on
@@ -17996,11 +18054,11 @@ class fI {
17996
18054
  },
17997
18055
  {
17998
18056
  type: D.BLOCK_COMMENT,
17999
- regex: E.nestedBlockComments ? new hI() : /(\/\*[^]*?\*\/)/uy
18057
+ regex: E.nestedBlockComments ? new fI() : /(\/\*[^]*?\*\/)/uy
18000
18058
  },
18001
18059
  {
18002
18060
  type: D.LINE_COMMENT,
18003
- regex: uI((R = E.lineCommentTypes) !== null && R !== void 0 ? R : ["--"])
18061
+ regex: HI((R = E.lineCommentTypes) !== null && R !== void 0 ? R : ["--"])
18004
18062
  },
18005
18063
  {
18006
18064
  type: D.QUOTED_IDENTIFIER,
@@ -18122,12 +18180,12 @@ class fI {
18122
18180
  return this.validRules([
18123
18181
  {
18124
18182
  type: D.VARIABLE,
18125
- regex: E.variableTypes ? mI(E.variableTypes) : void 0
18183
+ regex: E.variableTypes ? FI(E.variableTypes) : void 0
18126
18184
  },
18127
18185
  { type: D.STRING, regex: fT(E.stringTypes) },
18128
18186
  {
18129
18187
  type: D.IDENTIFIER,
18130
- regex: FI(E.identChars)
18188
+ regex: YI(E.identChars)
18131
18189
  },
18132
18190
  { type: D.DELIMITER, regex: /[;]/uy },
18133
18191
  { type: D.COMMA, regex: /[,]/y },
@@ -18177,12 +18235,12 @@ class fI {
18177
18235
  return this.validRules([
18178
18236
  {
18179
18237
  type: D.NAMED_PARAMETER,
18180
- regex: $E(r.named, TR(E.paramChars || E.identChars)),
18238
+ regex: $E(r.named, RR(E.paramChars || E.identChars)),
18181
18239
  key: (O) => O.slice(1)
18182
18240
  },
18183
18241
  {
18184
18242
  type: D.QUOTED_PARAMETER,
18185
- regex: $E(r.quoted, ER(E.identTypes)),
18243
+ regex: $E(r.quoted, TR(E.identTypes)),
18186
18244
  key: (O) => (({ tokenKey: I, quoteChar: s }) => I.replace(new RegExp(X("\\" + s), "gu"), s))({
18187
18245
  tokenKey: O.slice(2, -1),
18188
18246
  quoteChar: O.slice(-1)
@@ -18212,13 +18270,13 @@ class fI {
18212
18270
  return E.filter((R) => !!R.regex);
18213
18271
  }
18214
18272
  }
18215
- const F = (T) => AE(T.toUpperCase()), WT = /* @__PURE__ */ new Map(), VI = (T) => {
18273
+ const F = (T) => eE(T.toUpperCase()), WT = /* @__PURE__ */ new Map(), WI = (T) => {
18216
18274
  let E = WT.get(T);
18217
- return E || (E = WI(T), WT.set(T, E)), E;
18218
- }, WI = (T) => ({
18219
- tokenizer: new fI(T.tokenizerOptions, T.name),
18220
- formatOptions: XI(T.formatOptions)
18221
- }), XI = (T) => {
18275
+ return E || (E = XI(T), WT.set(T, E)), E;
18276
+ }, XI = (T) => ({
18277
+ tokenizer: new VI(T.tokenizerOptions, T.name),
18278
+ formatOptions: bI(T.formatOptions)
18279
+ }), bI = (T) => {
18222
18280
  var E;
18223
18281
  return {
18224
18282
  alwaysDenseOperators: T.alwaysDenseOperators || [],
@@ -18226,13 +18284,13 @@ const F = (T) => AE(T.toUpperCase()), WT = /* @__PURE__ */ new Map(), VI = (T) =
18226
18284
  tabularOnelineClauses: Object.fromEntries(((E = T.tabularOnelineClauses) !== null && E !== void 0 ? E : T.onelineClauses).map((R) => [R, !0]))
18227
18285
  };
18228
18286
  };
18229
- function bI(T) {
18287
+ function yI(T) {
18230
18288
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight" ? " ".repeat(10) : T.useTabs ? " " : " ".repeat(T.tabWidth);
18231
18289
  }
18232
18290
  function q(T) {
18233
18291
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight";
18234
18292
  }
18235
- class yI {
18293
+ class KI {
18236
18294
  constructor(E) {
18237
18295
  this.params = E, this.index = 0;
18238
18296
  }
@@ -18255,15 +18313,15 @@ class yI {
18255
18313
  this.index = E;
18256
18314
  }
18257
18315
  }
18258
- function KI(T) {
18316
+ function $I(T) {
18259
18317
  return T && T.__esModule && Object.prototype.hasOwnProperty.call(T, "default") ? T.default : T;
18260
18318
  }
18261
- var eE = { exports: {} }, $I = eE.exports, XT;
18262
- function gI() {
18319
+ var SE = { exports: {} }, gI = SE.exports, XT;
18320
+ function wI() {
18263
18321
  return XT || (XT = 1, (function(T) {
18264
18322
  (function(E, R) {
18265
18323
  T.exports ? T.exports = R() : E.nearley = R();
18266
- })($I, function() {
18324
+ })(gI, function() {
18267
18325
  function E(O, I, s) {
18268
18326
  return this.id = ++E.highestId, this.name = O, this.symbols = I, this.postprocess = s, this;
18269
18327
  }
@@ -18532,58 +18590,58 @@ function gI() {
18532
18590
  Rule: E
18533
18591
  };
18534
18592
  });
18535
- })(eE)), eE.exports;
18593
+ })(SE)), SE.exports;
18536
18594
  }
18537
- var wI = gI();
18538
- const JI = /* @__PURE__ */ KI(wI);
18539
- function xI(T) {
18540
- return T.map(vI).map(QI).map(ZI).map(qI).map(jI);
18595
+ var JI = wI();
18596
+ const xI = /* @__PURE__ */ $I(JI);
18597
+ function vI(T) {
18598
+ return T.map(QI).map(ZI).map(qI).map(jI).map(kI);
18541
18599
  }
18542
- const vI = (T, E, R) => {
18543
- if (jT(T.type)) {
18544
- const A = kI(R, E);
18600
+ const QI = (T, E, R) => {
18601
+ if (kT(T.type)) {
18602
+ const A = zI(R, E);
18545
18603
  if (A && A.type === D.PROPERTY_ACCESS_OPERATOR)
18546
18604
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18547
- const e = k(R, E);
18605
+ const e = z(R, E);
18548
18606
  if (e && e.type === D.PROPERTY_ACCESS_OPERATOR)
18549
18607
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18550
18608
  }
18551
18609
  return T;
18552
- }, QI = (T, E, R) => {
18610
+ }, ZI = (T, E, R) => {
18553
18611
  if (T.type === D.RESERVED_FUNCTION_NAME) {
18554
- const A = k(R, E);
18555
- if (!A || !AR(A))
18612
+ const A = z(R, E);
18613
+ if (!A || !eR(A))
18556
18614
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18557
18615
  }
18558
18616
  return T;
18559
- }, ZI = (T, E, R) => {
18617
+ }, qI = (T, E, R) => {
18560
18618
  if (T.type === D.RESERVED_DATA_TYPE) {
18561
- const A = k(R, E);
18562
- if (A && AR(A))
18619
+ const A = z(R, E);
18620
+ if (A && eR(A))
18563
18621
  return Object.assign(Object.assign({}, T), { type: D.RESERVED_PARAMETERIZED_DATA_TYPE });
18564
18622
  }
18565
18623
  return T;
18566
- }, qI = (T, E, R) => {
18624
+ }, jI = (T, E, R) => {
18567
18625
  if (T.type === D.IDENTIFIER) {
18568
- const A = k(R, E);
18569
- if (A && eR(A))
18626
+ const A = z(R, E);
18627
+ if (A && SR(A))
18570
18628
  return Object.assign(Object.assign({}, T), { type: D.ARRAY_IDENTIFIER });
18571
18629
  }
18572
18630
  return T;
18573
- }, jI = (T, E, R) => {
18631
+ }, kI = (T, E, R) => {
18574
18632
  if (T.type === D.RESERVED_DATA_TYPE) {
18575
- const A = k(R, E);
18576
- if (A && eR(A))
18633
+ const A = z(R, E);
18634
+ if (A && SR(A))
18577
18635
  return Object.assign(Object.assign({}, T), { type: D.ARRAY_KEYWORD });
18578
18636
  }
18579
18637
  return T;
18580
- }, kI = (T, E) => k(T, E, -1), k = (T, E, R = 1) => {
18638
+ }, zI = (T, E) => z(T, E, -1), z = (T, E, R = 1) => {
18581
18639
  let A = 1;
18582
- for (; T[E + A * R] && zI(T[E + A * R]); )
18640
+ for (; T[E + A * R] && EO(T[E + A * R]); )
18583
18641
  A++;
18584
18642
  return T[E + A * R];
18585
- }, AR = (T) => T.type === D.OPEN_PAREN && T.text === "(", eR = (T) => T.type === D.OPEN_PAREN && T.text === "[", zI = (T) => T.type === D.BLOCK_COMMENT || T.type === D.LINE_COMMENT;
18586
- class SR {
18643
+ }, eR = (T) => T.type === D.OPEN_PAREN && T.text === "(", SR = (T) => T.type === D.OPEN_PAREN && T.text === "[", EO = (T) => T.type === D.BLOCK_COMMENT || T.type === D.LINE_COMMENT;
18644
+ class IR {
18587
18645
  constructor(E) {
18588
18646
  this.tokenize = E, this.index = 0, this.tokens = [], this.input = "";
18589
18647
  }
@@ -18596,7 +18654,7 @@ class SR {
18596
18654
  save() {
18597
18655
  }
18598
18656
  formatError(E) {
18599
- const { line: R, col: A } = RR(this.input, E.start);
18657
+ const { line: R, col: A } = AR(this.input, E.start);
18600
18658
  return `Parse error at token: ${E.text} at line ${R} column ${A}`;
18601
18659
  }
18602
18660
  has(E) {
@@ -18610,7 +18668,7 @@ var M;
18610
18668
  function gE(T) {
18611
18669
  return T[0];
18612
18670
  }
18613
- const G = new SR((T) => []), K = ([[T]]) => T, Y = (T) => ({
18671
+ const G = new IR((T) => []), K = ([[T]]) => T, Y = (T) => ({
18614
18672
  type: M.keyword,
18615
18673
  tokenType: T.type,
18616
18674
  text: T.text,
@@ -18619,7 +18677,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, Y = (T) => ({
18619
18677
  type: M.data_type,
18620
18678
  text: T.text,
18621
18679
  raw: T.raw
18622
- }), p = (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), EO = (T, { leading: E, trailing: R }) => {
18680
+ }), p = (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), TO = (T, { leading: E, trailing: R }) => {
18623
18681
  if (E?.length) {
18624
18682
  const [A, ...e] = T;
18625
18683
  T = [p(A, { leading: E }), ...e];
@@ -18629,7 +18687,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, Y = (T) => ({
18629
18687
  T = [...A, p(e, { trailing: R })];
18630
18688
  }
18631
18689
  return T;
18632
- }, TO = {
18690
+ }, RO = {
18633
18691
  Lexer: G,
18634
18692
  ParserRules: [
18635
18693
  { name: "main$ebnf$1", symbols: [] },
@@ -18894,7 +18952,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, Y = (T) => ({
18894
18952
  postprocess: ([T, E, R, A, e, S, N]) => ({
18895
18953
  type: M.between_predicate,
18896
18954
  betweenKw: Y(T),
18897
- expr1: EO(R, { leading: E, trailing: A }),
18955
+ expr1: TO(R, { leading: E, trailing: A }),
18898
18956
  andKw: Y(e),
18899
18957
  expr2: [p(N, { leading: S })]
18900
18958
  })
@@ -19026,13 +19084,13 @@ const G = new SR((T) => []), K = ([[T]]) => T, Y = (T) => ({
19026
19084
  }
19027
19085
  ],
19028
19086
  ParserStart: "main"
19029
- }, { Parser: RO, Grammar: AO } = JI;
19030
- function eO(T) {
19087
+ }, { Parser: AO, Grammar: eO } = xI;
19088
+ function SO(T) {
19031
19089
  let E = {};
19032
- const R = new SR((e) => [
19033
- ...xI(T.tokenize(e, E)),
19034
- qT(e.length)
19035
- ]), A = new RO(AO.fromCompiled(TO), { lexer: R });
19090
+ const R = new IR((e) => [
19091
+ ...vI(T.tokenize(e, E)),
19092
+ jT(e.length)
19093
+ ]), A = new AO(eO.fromCompiled(RO), { lexer: R });
19036
19094
  return {
19037
19095
  parse: (e, S) => {
19038
19096
  E = S;
@@ -19048,7 +19106,7 @@ var i;
19048
19106
  (function(T) {
19049
19107
  T[T.SPACE = 0] = "SPACE", T[T.NO_SPACE = 1] = "NO_SPACE", T[T.NO_NEWLINE = 2] = "NO_NEWLINE", T[T.NEWLINE = 3] = "NEWLINE", T[T.MANDATORY_NEWLINE = 4] = "MANDATORY_NEWLINE", T[T.INDENT = 5] = "INDENT", T[T.SINGLE_INDENT = 6] = "SINGLE_INDENT";
19050
19108
  })(i = i || (i = {}));
19051
- class IR {
19109
+ class NR {
19052
19110
  constructor(E) {
19053
19111
  this.indentation = E, this.items = [];
19054
19112
  }
@@ -19084,16 +19142,16 @@ class IR {
19084
19142
  }
19085
19143
  }
19086
19144
  trimHorizontalWhitespace() {
19087
- for (; SO(EE(this.items)); )
19145
+ for (; IO(TE(this.items)); )
19088
19146
  this.items.pop();
19089
19147
  }
19090
19148
  trimWhitespace() {
19091
- for (; IO(EE(this.items)); )
19149
+ for (; OO(TE(this.items)); )
19092
19150
  this.items.pop();
19093
19151
  }
19094
19152
  addNewline(E) {
19095
19153
  if (this.items.length > 0)
19096
- switch (EE(this.items)) {
19154
+ switch (TE(this.items)) {
19097
19155
  case i.NEWLINE:
19098
19156
  this.items.pop(), this.items.push(E);
19099
19157
  break;
@@ -19135,7 +19193,7 @@ class IR {
19135
19193
  }
19136
19194
  }
19137
19195
  }
19138
- const SO = (T) => T === i.SPACE || T === i.SINGLE_INDENT, IO = (T) => T === i.SPACE || T === i.SINGLE_INDENT || T === i.NEWLINE;
19196
+ const IO = (T) => T === i.SPACE || T === i.SINGLE_INDENT, OO = (T) => T === i.SPACE || T === i.SINGLE_INDENT || T === i.NEWLINE;
19139
19197
  function yT(T, E) {
19140
19198
  if (E === "standard")
19141
19199
  return T;
@@ -19143,10 +19201,10 @@ function yT(T, E) {
19143
19201
  return T.length >= 10 && T.includes(" ") && ([T, ...R] = T.split(" ")), E === "tabularLeft" ? T = T.padEnd(9, " ") : T = T.padStart(9, " "), T + ["", ...R].join(" ");
19144
19202
  }
19145
19203
  function KT(T) {
19146
- return KR(T) || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.LIMIT;
19204
+ return $R(T) || T === D.RESERVED_CLAUSE || T === D.RESERVED_SELECT || T === D.RESERVED_SET_OPERATION || T === D.RESERVED_JOIN || T === D.LIMIT;
19147
19205
  }
19148
- const wE = "top-level", OO = "block-level";
19149
- class NR {
19206
+ const wE = "top-level", NO = "block-level";
19207
+ class sR {
19150
19208
  /**
19151
19209
  * @param {string} indent A string to indent with
19152
19210
  */
@@ -19175,14 +19233,14 @@ class NR {
19175
19233
  * Increases indentation by one block-level indent.
19176
19234
  */
19177
19235
  increaseBlockLevel() {
19178
- this.indentTypes.push(OO);
19236
+ this.indentTypes.push(NO);
19179
19237
  }
19180
19238
  /**
19181
19239
  * Decreases indentation by one top-level indent.
19182
19240
  * Does nothing when the previous indent is not top-level.
19183
19241
  */
19184
19242
  decreaseTopLevel() {
19185
- this.indentTypes.length > 0 && EE(this.indentTypes) === wE && this.indentTypes.pop();
19243
+ this.indentTypes.length > 0 && TE(this.indentTypes) === wE && this.indentTypes.pop();
19186
19244
  }
19187
19245
  /**
19188
19246
  * Decreases indentation by one block-level indent.
@@ -19194,9 +19252,9 @@ class NR {
19194
19252
  ;
19195
19253
  }
19196
19254
  }
19197
- class NO extends IR {
19255
+ class sO extends NR {
19198
19256
  constructor(E) {
19199
- super(new NR("")), this.expressionWidth = E, this.length = 0, this.trailingSpace = !1;
19257
+ super(new sR("")), this.expressionWidth = E, this.length = 0, this.trailingSpace = !1;
19200
19258
  }
19201
19259
  add(...E) {
19202
19260
  if (E.forEach((R) => this.addToLength(R)), this.length > this.expressionWidth)
@@ -19389,7 +19447,7 @@ class tE {
19389
19447
  // first line starts with /* or /**
19390
19448
  /^\/\*\*?$/.test(R[0]) && // intermediate lines start with *
19391
19449
  R.slice(1, R.length - 1).every((A) => /^\s*\*/.test(A)) && // last line ends with */
19392
- /^\s*\*\/$/.test(EE(R))
19450
+ /^\s*\*\/$/.test(TE(R))
19393
19451
  );
19394
19452
  }
19395
19453
  // Breaks up block comment to multiple lines.
@@ -19438,7 +19496,7 @@ class tE {
19438
19496
  cfg: this.cfg,
19439
19497
  dialectCfg: this.dialectCfg,
19440
19498
  params: this.params,
19441
- layout: new NO(this.cfg.expressionWidth),
19499
+ layout: new sO(this.cfg.expressionWidth),
19442
19500
  inline: !0
19443
19501
  }).format(E);
19444
19502
  } catch (A) {
@@ -19480,7 +19538,7 @@ class tE {
19480
19538
  showNonTabularKw(E) {
19481
19539
  switch (this.cfg.keywordCase) {
19482
19540
  case "preserve":
19483
- return AE(E.raw);
19541
+ return eE(E.raw);
19484
19542
  case "upper":
19485
19543
  return E.text;
19486
19544
  case "lower":
@@ -19494,7 +19552,7 @@ class tE {
19494
19552
  showNonTabularFunctionKw(E) {
19495
19553
  switch (this.cfg.functionCase) {
19496
19554
  case "preserve":
19497
- return AE(E.raw);
19555
+ return eE(E.raw);
19498
19556
  case "upper":
19499
19557
  return E.text;
19500
19558
  case "lower":
@@ -19516,7 +19574,7 @@ class tE {
19516
19574
  showDataType(E) {
19517
19575
  switch (this.cfg.dataTypeCase) {
19518
19576
  case "preserve":
19519
- return AE(E.raw);
19577
+ return eE(E.raw);
19520
19578
  case "upper":
19521
19579
  return E.text;
19522
19580
  case "lower":
@@ -19524,9 +19582,9 @@ class tE {
19524
19582
  }
19525
19583
  }
19526
19584
  }
19527
- class sO {
19585
+ class tO {
19528
19586
  constructor(E, R) {
19529
- this.dialect = E, this.cfg = R, this.params = new yI(this.cfg.params);
19587
+ this.dialect = E, this.cfg = R, this.params = new KI(this.cfg.params);
19530
19588
  }
19531
19589
  /**
19532
19590
  * Formats an SQL query.
@@ -19538,7 +19596,7 @@ class sO {
19538
19596
  return this.formatAst(R).trimEnd();
19539
19597
  }
19540
19598
  parse(E) {
19541
- return eO(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19599
+ return SO(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19542
19600
  }
19543
19601
  formatAst(E) {
19544
19602
  return E.map((R) => this.formatStatement(R)).join(`
@@ -19549,14 +19607,14 @@ class sO {
19549
19607
  cfg: this.cfg,
19550
19608
  dialectCfg: this.dialect.formatOptions,
19551
19609
  params: this.params,
19552
- layout: new IR(new NR(bI(this.cfg)))
19610
+ layout: new NR(new sR(yI(this.cfg)))
19553
19611
  }).format(E.children);
19554
19612
  return E.hasSemicolon && (this.cfg.newlineBeforeSemicolon ? R.add(i.NEWLINE, ";") : R.add(i.NO_NEWLINE, ";")), R.toString();
19555
19613
  }
19556
19614
  }
19557
- class SE extends Error {
19615
+ class IE extends Error {
19558
19616
  }
19559
- function tO(T) {
19617
+ function CO(T) {
19560
19618
  const E = [
19561
19619
  "multilineLists",
19562
19620
  "newlineBeforeOpenParen",
@@ -19567,20 +19625,20 @@ function tO(T) {
19567
19625
  ];
19568
19626
  for (const R of E)
19569
19627
  if (R in T)
19570
- throw new SE(`${R} config is no more supported.`);
19628
+ throw new IE(`${R} config is no more supported.`);
19571
19629
  if (T.expressionWidth <= 0)
19572
- throw new SE(`expressionWidth config must be positive number. Received ${T.expressionWidth} instead.`);
19573
- if (T.params && !CO(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !LO(T.paramTypes))
19574
- throw new SE("Empty regex given in custom paramTypes. That would result in matching infinite amount of parameters.");
19630
+ throw new IE(`expressionWidth config must be positive number. Received ${T.expressionWidth} instead.`);
19631
+ if (T.params && !LO(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !_O(T.paramTypes))
19632
+ throw new IE("Empty regex given in custom paramTypes. That would result in matching infinite amount of parameters.");
19575
19633
  return T;
19576
19634
  }
19577
- function CO(T) {
19635
+ function LO(T) {
19578
19636
  return (T instanceof Array ? T : Object.values(T)).every((R) => typeof R == "string");
19579
19637
  }
19580
- function LO(T) {
19638
+ function _O(T) {
19581
19639
  return T.custom && Array.isArray(T.custom) ? T.custom.every((E) => E.regex !== "") : !0;
19582
19640
  }
19583
- var _O = function(T, E) {
19641
+ var rO = function(T, E) {
19584
19642
  var R = {};
19585
19643
  for (var A in T) Object.prototype.hasOwnProperty.call(T, A) && E.indexOf(A) < 0 && (R[A] = T[A]);
19586
19644
  if (T != null && typeof Object.getOwnPropertySymbols == "function")
@@ -19588,7 +19646,7 @@ var _O = function(T, E) {
19588
19646
  E.indexOf(A[e]) < 0 && Object.prototype.propertyIsEnumerable.call(T, A[e]) && (R[A[e]] = T[A[e]]);
19589
19647
  return R;
19590
19648
  };
19591
- const sR = {
19649
+ const tR = {
19592
19650
  bigquery: "bigquery",
19593
19651
  db2: "db2",
19594
19652
  db2i: "db2i",
@@ -19609,7 +19667,7 @@ const sR = {
19609
19667
  tsql: "transactsql",
19610
19668
  singlestoredb: "singlestoredb",
19611
19669
  snowflake: "snowflake"
19612
- }, rO = Object.keys(sR), nO = {
19670
+ }, nO = Object.keys(tR), iO = {
19613
19671
  tabWidth: 2,
19614
19672
  useTabs: !1,
19615
19673
  keywordCase: "preserve",
@@ -19622,27 +19680,27 @@ const sR = {
19622
19680
  linesBetweenQueries: 1,
19623
19681
  denseOperators: !1,
19624
19682
  newlineBeforeSemicolon: !1
19625
- }, iO = (T, E = {}) => {
19626
- if (typeof E.language == "string" && !rO.includes(E.language))
19627
- throw new SE(`Unsupported SQL dialect: ${E.language}`);
19628
- const R = sR[E.language || "sql"];
19629
- return DO(T, Object.assign(Object.assign({}, E), { dialect: UI[R] }));
19630
- }, DO = (T, E) => {
19631
- var { dialect: R } = E, A = _O(E, ["dialect"]);
19683
+ }, DO = (T, E = {}) => {
19684
+ if (typeof E.language == "string" && !nO.includes(E.language))
19685
+ throw new IE(`Unsupported SQL dialect: ${E.language}`);
19686
+ const R = tR[E.language || "sql"];
19687
+ return aO(T, Object.assign(Object.assign({}, E), { dialect: GI[R] }));
19688
+ }, aO = (T, E) => {
19689
+ var { dialect: R } = E, A = rO(E, ["dialect"]);
19632
19690
  if (typeof T != "string")
19633
19691
  throw new Error("Invalid query argument. Expected string, instead got " + typeof T);
19634
- const e = tO(Object.assign(Object.assign({}, nO), A));
19635
- return new sO(VI(R), e).format(T);
19692
+ const e = CO(Object.assign(Object.assign({}, iO), A));
19693
+ return new tO(WI(R), e).format(T);
19636
19694
  };
19637
- function aO(T) {
19695
+ function oO(T) {
19638
19696
  let E = 0;
19639
19697
  return E += (T.measures?.length || 0) * 1, E += (T.dimensions?.length || 0) * 1, E += (T.filters?.length || 0) * 2, E += (T.timeDimensions?.length || 0) * 3, E <= 5 ? "low" : E <= 15 ? "medium" : "high";
19640
19698
  }
19641
- function oO() {
19699
+ function PO() {
19642
19700
  const T = Date.now(), E = Math.random().toString(36).substring(2, 9);
19643
19701
  return `${T}-${E}`;
19644
19702
  }
19645
- function PO(T) {
19703
+ function MO(T) {
19646
19704
  const E = T.dimensions || [], R = T.timeDimensions || [], A = T.measures || [];
19647
19705
  return {
19648
19706
  sortedDimensions: E,
@@ -19667,7 +19725,7 @@ function PO(T) {
19667
19725
  hasMultiStage: !1
19668
19726
  };
19669
19727
  }
19670
- function MO(T) {
19728
+ function UO(T) {
19671
19729
  if (T.hasExecutor()) {
19672
19730
  const E = T.databaseExecutor;
19673
19731
  if (E?.engineType)
@@ -19675,7 +19733,7 @@ function MO(T) {
19675
19733
  }
19676
19734
  return "postgres";
19677
19735
  }
19678
- async function GO(T, E, R) {
19736
+ async function lO(T, E, R) {
19679
19737
  const A = R.validateQuery(T);
19680
19738
  if (!A.isValid)
19681
19739
  throw new Error(`Query validation failed: ${A.errors.join(", ")}`);
@@ -19728,15 +19786,15 @@ async function GO(T, E, R) {
19728
19786
  sql: [N.sql],
19729
19787
  params: N.params || []
19730
19788
  },
19731
- complexity: aO(T),
19789
+ complexity: oO(T),
19732
19790
  valid: !0,
19733
19791
  cubesUsed: Array.from(e),
19734
19792
  joinType: S ? "multi_cube_join" : "single_cube",
19735
19793
  query: T
19736
19794
  };
19737
19795
  }
19738
- function lO(T, E, R) {
19739
- const A = MO(R), e = oO(), S = (/* @__PURE__ */ new Date()).toISOString(), N = PO(T);
19796
+ function cO(T, E, R) {
19797
+ const A = UO(R), e = PO(), S = (/* @__PURE__ */ new Date()).toISOString(), N = MO(T);
19740
19798
  return {
19741
19799
  queryType: "regularQuery",
19742
19800
  results: [{
@@ -19762,7 +19820,7 @@ function lO(T, E, R) {
19762
19820
  }
19763
19821
  function $T(T, E) {
19764
19822
  try {
19765
- return iO(T, {
19823
+ return DO(T, {
19766
19824
  language: {
19767
19825
  postgres: "postgresql",
19768
19826
  mysql: "mysql",
@@ -19778,25 +19836,25 @@ function $T(T, E) {
19778
19836
  return console.warn("SQL formatting failed:", R), T;
19779
19837
  }
19780
19838
  }
19781
- function cO(T, E) {
19839
+ function uO(T, E) {
19782
19840
  return {
19783
19841
  sql: E.sql,
19784
19842
  params: E.params || [],
19785
19843
  query: T
19786
19844
  };
19787
19845
  }
19788
- function uO(T) {
19846
+ function HO(T) {
19789
19847
  return {
19790
19848
  cubes: T
19791
19849
  };
19792
19850
  }
19793
- function HO(T, E = 500) {
19851
+ function BO(T, E = 500) {
19794
19852
  return {
19795
19853
  error: T instanceof Error ? T.message : T,
19796
19854
  status: E
19797
19855
  };
19798
19856
  }
19799
- class UO {
19857
+ class GO {
19800
19858
  cubes = /* @__PURE__ */ new Map();
19801
19859
  dbExecutor;
19802
19860
  metadataCache;
@@ -20025,10 +20083,10 @@ class UO {
20025
20083
  * Ensures all referenced cubes and fields exist
20026
20084
  */
20027
20085
  validateQuery(E) {
20028
- return tR(this.cubes, E);
20086
+ return CR(this.cubes, E);
20029
20087
  }
20030
20088
  }
20031
- function tR(T, E) {
20089
+ function CR(T, E) {
20032
20090
  const R = [], A = /* @__PURE__ */ new Set();
20033
20091
  if (E.measures)
20034
20092
  for (const e of E.measures) {
@@ -20077,17 +20135,17 @@ function tR(T, E) {
20077
20135
  }
20078
20136
  if (E.filters)
20079
20137
  for (const e of E.filters)
20080
- CR(e, T, R, A);
20138
+ LR(e, T, R, A);
20081
20139
  return A.size === 0 && R.push("Query must reference at least one cube through measures, dimensions, or filters"), {
20082
20140
  isValid: R.length === 0,
20083
20141
  errors: R
20084
20142
  };
20085
20143
  }
20086
- function CR(T, E, R, A) {
20144
+ function LR(T, E, R, A) {
20087
20145
  if ("and" in T || "or" in T) {
20088
20146
  const t = T.and || T.or || [];
20089
20147
  for (const r of t)
20090
- CR(r, E, R, A);
20148
+ LR(r, E, R, A);
20091
20149
  return;
20092
20150
  }
20093
20151
  if (!("member" in T)) {
@@ -20107,12 +20165,12 @@ function CR(T, E, R, A) {
20107
20165
  }
20108
20166
  !N.dimensions[S] && !N.measures[S] && R.push(`Filter field '${S}' not found on cube '${e}' (must be a dimension or measure)`);
20109
20167
  }
20110
- new UO();
20168
+ new GO();
20111
20169
  export {
20112
- UO as S,
20113
- uO as a,
20114
- cO as b,
20115
- HO as c,
20116
- lO as f,
20117
- GO as h
20170
+ GO as S,
20171
+ HO as a,
20172
+ uO as b,
20173
+ BO as c,
20174
+ cO as f,
20175
+ lO as h
20118
20176
  };