drizzle-cube 0.1.35 → 0.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,27 @@
1
- const h = Symbol.for("drizzle:entityKind");
2
- function H(T, E) {
1
+ const f = Symbol.for("drizzle:entityKind");
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];
@@ -142,14 +142,14 @@ class u {
142
142
  constructor(E) {
143
143
  this.queryChunks = E;
144
144
  for (const R of E)
145
- if (H(R, W)) {
145
+ if (m(R, W)) {
146
146
  const A = R[W.Symbol.Schema];
147
147
  this.usedTables.push(
148
148
  A === void 0 ? R[W.Symbol.Name] : A + "." + R[W.Symbol.Name]
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,
@@ -177,71 +177,71 @@ class u {
177
177
  escapeParam: N,
178
178
  prepareTyping: t,
179
179
  inlineParams: r,
180
- paramStartIndex: I
180
+ paramStartIndex: O
181
181
  } = A;
182
- return iR(E.map((O) => {
183
- if (H(O, d))
184
- return { sql: O.value.join(""), params: [] };
185
- if (H(O, JE))
186
- return { sql: S(O.value), params: [] };
187
- if (O === void 0)
182
+ return DR(E.map((I) => {
183
+ if (m(I, d))
184
+ return { sql: I.value.join(""), params: [] };
185
+ if (m(I, JE))
186
+ return { sql: S(I.value), params: [] };
187
+ if (I === void 0)
188
188
  return { sql: "", params: [] };
189
- if (Array.isArray(O)) {
189
+ if (Array.isArray(I)) {
190
190
  const s = [new d("(")];
191
- for (const [L, a] of O.entries())
192
- s.push(a), L < O.length - 1 && s.push(new d(", "));
191
+ for (const [L, a] of I.entries())
192
+ s.push(a), L < I.length - 1 && s.push(new d(", "));
193
193
  return s.push(new d(")")), this.buildQueryFromSourceParams(s, A);
194
194
  }
195
- if (H(O, u))
196
- return this.buildQueryFromSourceParams(O.queryChunks, {
195
+ if (m(I, u))
196
+ return this.buildQueryFromSourceParams(I.queryChunks, {
197
197
  ...A,
198
- inlineParams: r || O.shouldInlineParams
198
+ inlineParams: r || I.shouldInlineParams
199
199
  });
200
- if (H(O, W)) {
201
- const s = O[W.Symbol.Schema], L = O[W.Symbol.Name];
200
+ if (m(I, W)) {
201
+ const s = I[W.Symbol.Schema], L = I[W.Symbol.Name];
202
202
  return {
203
- sql: s === void 0 || O[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 (H(O, TE)) {
208
- const s = e.getColumnCasing(O);
207
+ if (m(I, RE)) {
208
+ const s = e.getColumnCasing(I);
209
209
  if (R.invokeSource === "indexes")
210
210
  return { sql: S(s), params: [] };
211
- const L = O.table[W.Symbol.Schema];
211
+ const L = I.table[W.Symbol.Schema];
212
212
  return {
213
- sql: O.table[IE] || L === void 0 ? S(O.table[W.Symbol.Name]) + "." + S(s) : S(L) + "." + S(O.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
- if (H(O, vT)) {
218
- const s = O[z].schema, L = O[z].name;
217
+ if (m(I, vT)) {
218
+ const s = I[EE].schema, L = I[EE].name;
219
219
  return {
220
- sql: s === void 0 || O[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 (H(O, OE)) {
225
- if (H(O.value, NE))
226
- return { sql: N(I.value++, O), params: [O], typings: ["none"] };
227
- const s = O.value === null ? null : O.encoder.mapToDriverValue(O.value);
228
- if (H(s, u))
224
+ if (m(I, NE)) {
225
+ if (m(I.value, sE))
226
+ return { sql: N(O.value++, I), params: [I], typings: ["none"] };
227
+ const s = I.value === null ? null : I.encoder.mapToDriverValue(I.value);
228
+ if (m(s, u))
229
229
  return this.buildQueryFromSourceParams([s], A);
230
230
  if (r)
231
231
  return { sql: this.mapInlineParam(s, A), params: [] };
232
232
  let L = ["none"];
233
- return t && (L = [t(O.encoder)]), { sql: N(I.value++, s), params: [s], typings: L };
233
+ return t && (L = [t(I.encoder)]), { sql: N(O.value++, s), params: [s], typings: L };
234
234
  }
235
- return H(O, NE) ? { sql: N(I.value++, O), params: [O], typings: ["none"] } : H(O, u.Aliased) && O.fieldAlias !== void 0 ? { sql: S(O.fieldAlias), params: [] } : H(O, gT) ? O._.isWith ? { sql: S(O._.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
- O._.sql,
237
+ I._.sql,
238
238
  new d(") "),
239
- new JE(O._.alias)
240
- ], A) : _R(O) ? O.schema ? { sql: S(O.schema) + "." + S(O.enumName), params: [] } : { sql: S(O.enumName), params: [] } : wT(O) ? O.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([O.getSQL()], A) : this.buildQueryFromSourceParams([
239
+ new JE(I._.alias)
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
- O.getSQL(),
242
+ I.getSQL(),
243
243
  new d(")")
244
- ], A) : r ? { sql: this.mapInlineParam(O, A), params: [] } : { sql: N(I.value++, O), params: [O], typings: ["none"] };
244
+ ], A) : r ? { sql: this.mapInlineParam(I, A), params: [] } : { sql: N(O.value++, I), params: [I], typings: ["none"] };
245
245
  }));
246
246
  }
247
247
  mapInlineParam(E, { escapeString: R }) {
@@ -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]);
@@ -335,11 +335,11 @@ function C(T, ...E) {
335
335
  return new u([new d(r)]);
336
336
  }
337
337
  T.raw = A;
338
- function e(r, I) {
339
- const O = [];
338
+ function e(r, O) {
339
+ const I = [];
340
340
  for (const [s, L] of r.entries())
341
- s > 0 && I !== void 0 && O.push(I), O.push(L);
342
- return new u(O);
341
+ s > 0 && O !== void 0 && I.push(O), I.push(L);
342
+ return new u(I);
343
343
  }
344
344
  T.join = e;
345
345
  function S(r) {
@@ -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
- function t(r, I) {
354
- return new OE(r, I);
353
+ function t(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) && !H(T, OE) && !H(T, NE) && !H(T, TE) && !H(T, W) && !H(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(H(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(H(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":
@@ -1100,6 +1100,9 @@ function FR(T, E) {
1100
1100
  case "hasMany":
1101
1101
  return "left";
1102
1102
  // Parent may have no children
1103
+ case "belongsToMany":
1104
+ return "left";
1105
+ // Many-to-many through junction table
1103
1106
  default:
1104
1107
  return "left";
1105
1108
  }
@@ -1107,7 +1110,43 @@ function FR(T, E) {
1107
1110
  function $(T, E) {
1108
1111
  return typeof T == "function" ? T(E) : T;
1109
1112
  }
1110
- 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 {
1111
1150
  constructor(E) {
1112
1151
  this.databaseAdapter = E;
1113
1152
  }
@@ -1119,26 +1158,26 @@ class YR {
1119
1158
  const e = {}, S = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1120
1159
  if (R.dimensions)
1121
1160
  for (const N of R.dimensions) {
1122
- const [t, r] = N.split("."), I = S.get(t);
1123
- if (I && I.dimensions && I.dimensions[r]) {
1124
- const O = I.dimensions[r], s = $(O.sql, A);
1161
+ const [t, r] = N.split("."), O = S.get(t);
1162
+ if (O && O.dimensions && O.dimensions[r]) {
1163
+ const I = O.dimensions[r], s = $(I.sql, A);
1125
1164
  e[N] = C`${s}`.as(N);
1126
1165
  }
1127
1166
  }
1128
1167
  if (R.measures)
1129
1168
  for (const N of R.measures) {
1130
- const [t, r] = N.split("."), I = S.get(t);
1131
- if (I && I.measures && I.measures[r]) {
1132
- const O = I.measures[r], s = this.buildMeasureExpression(O, A);
1169
+ const [t, r] = N.split("."), O = S.get(t);
1170
+ if (O && O.measures && O.measures[r]) {
1171
+ const I = O.measures[r], s = this.buildMeasureExpression(I, A);
1133
1172
  e[N] = C`${s}`.as(N);
1134
1173
  }
1135
1174
  }
1136
1175
  if (R.timeDimensions)
1137
1176
  for (const N of R.timeDimensions) {
1138
- const [t, r] = N.dimension.split("."), I = S.get(t);
1139
- if (I && I.dimensions && I.dimensions[r]) {
1140
- const O = I.dimensions[r], s = this.buildTimeDimensionExpression(
1141
- O.sql,
1177
+ const [t, r] = N.dimension.split("."), O = S.get(t);
1178
+ if (O && O.dimensions && O.dimensions[r]) {
1179
+ const I = O.dimensions[r], s = this.buildTimeDimensionExpression(
1180
+ I.sql,
1142
1181
  N.granularity,
1143
1182
  A
1144
1183
  );
@@ -1183,7 +1222,7 @@ class YR {
1183
1222
  if (E.filters && E.filters.length > 0) {
1184
1223
  const e = E.filters.map((S) => S(R)).filter(Boolean);
1185
1224
  if (e.length > 0) {
1186
- const S = e.length === 1 ? e[0] : f(...e);
1225
+ const S = e.length === 1 ? e[0] : h(...e);
1187
1226
  A = this.databaseAdapter.buildCaseWhen([
1188
1227
  { when: S, then: A }
1189
1228
  ]);
@@ -1193,7 +1232,7 @@ class YR {
1193
1232
  case "count":
1194
1233
  return ME(A);
1195
1234
  case "countDistinct":
1196
- return PR(A);
1235
+ return MR(A);
1197
1236
  case "sum":
1198
1237
  return g(A);
1199
1238
  case "avg":
@@ -1228,11 +1267,11 @@ class YR {
1228
1267
  }
1229
1268
  if (R.timeDimensions)
1230
1269
  for (const t of R.timeDimensions) {
1231
- const [r, I] = t.dimension.split("."), O = N.get(r);
1232
- if (O && O.dimensions[I] && t.dateRange) {
1270
+ const [r, O] = t.dimension.split("."), I = N.get(r);
1271
+ if (I && I.dimensions[O] && t.dateRange) {
1233
1272
  if (e?.preAggregationCTEs && e.preAggregationCTEs.some((n) => n.cube.name === r))
1234
1273
  continue;
1235
- const s = O.dimensions[I], L = $(s.sql, A), a = this.buildDateRangeCondition(L, t.dateRange);
1274
+ const s = I.dimensions[O], L = $(s.sql, A), a = this.buildDateRangeCondition(L, t.dateRange);
1236
1275
  a && S.push(a);
1237
1276
  }
1238
1277
  }
@@ -1260,21 +1299,21 @@ class YR {
1260
1299
  const a = E;
1261
1300
  if (a.and) {
1262
1301
  const o = a.and.map((n) => this.processFilter(n, R, A, e, S)).filter((n) => n !== null);
1263
- return o.length > 0 ? f(...o) : null;
1302
+ return o.length > 0 ? h(...o) : null;
1264
1303
  }
1265
1304
  if (a.or) {
1266
1305
  const o = a.or.map((n) => this.processFilter(n, R, A, e, S)).filter((n) => n !== null);
1267
1306
  return o.length > 0 ? DE(...o) : null;
1268
1307
  }
1269
1308
  }
1270
- const N = E, [t, r] = N.member.split("."), I = R.get(t);
1271
- if (!I) return null;
1272
- const O = I.dimensions[r], s = I.measures[r], L = O || s;
1309
+ const N = E, [t, r] = N.member.split("."), O = R.get(t);
1310
+ if (!O) return null;
1311
+ const I = O.dimensions[r], s = O.measures[r], L = I || s;
1273
1312
  if (!L) return null;
1274
- if (e === "where" && O) {
1313
+ if (e === "where" && I) {
1275
1314
  if (S?.preAggregationCTEs && S.preAggregationCTEs.some((n) => n.cube.name === t))
1276
1315
  return null;
1277
- const a = $(O.sql, A);
1316
+ const a = $(I.sql, A);
1278
1317
  return this.buildFilterCondition(a, N.operator, N.values, L);
1279
1318
  } else {
1280
1319
  if (e === "where" && s)
@@ -1306,7 +1345,7 @@ class YR {
1306
1345
  return PE(E, S);
1307
1346
  } else if (S.length === 1) {
1308
1347
  const t = e?.type === "time" && this.normalizeDate(N) || N;
1309
- return sE(E, t);
1348
+ return j(E, t);
1310
1349
  }
1311
1350
  return this.databaseAdapter.buildBooleanLiteral(!1);
1312
1351
  case "notEquals":
@@ -1335,7 +1374,7 @@ class YR {
1335
1374
  if (S.length >= 2) {
1336
1375
  const t = this.normalizeDate(S[0]), r = this.normalizeDate(S[1]);
1337
1376
  if (t && r)
1338
- return f(
1377
+ return h(
1339
1378
  v(E, t),
1340
1379
  Q(E, r)
1341
1380
  );
@@ -1350,7 +1389,7 @@ class YR {
1350
1389
  return t ? aE(E, t) : null;
1351
1390
  }
1352
1391
  case "between":
1353
- return S.length >= 2 ? f(
1392
+ return S.length >= 2 ? h(
1354
1393
  v(E, S[0]),
1355
1394
  Q(E, S[1])
1356
1395
  ) : null;
@@ -1376,10 +1415,10 @@ class YR {
1376
1415
  case "isEmpty":
1377
1416
  return DE(
1378
1417
  eT(E),
1379
- sE(E, "")
1418
+ j(E, "")
1380
1419
  );
1381
1420
  case "isNotEmpty":
1382
- return f(
1421
+ return h(
1383
1422
  ST(E),
1384
1423
  RT(E, "")
1385
1424
  );
@@ -1394,7 +1433,7 @@ class YR {
1394
1433
  if (!R) return null;
1395
1434
  if (Array.isArray(R) && R.length >= 2) {
1396
1435
  const A = this.normalizeDate(R[0]), e = this.normalizeDate(R[1]);
1397
- return !A || !e ? null : f(
1436
+ return !A || !e ? null : h(
1398
1437
  v(E, A),
1399
1438
  Q(E, e)
1400
1439
  );
@@ -1402,7 +1441,7 @@ class YR {
1402
1441
  if (typeof R == "string") {
1403
1442
  const A = this.parseRelativeDateRange(R);
1404
1443
  if (A)
1405
- return f(
1444
+ return h(
1406
1445
  v(E, A.start),
1407
1446
  Q(E, A.end)
1408
1447
  );
@@ -1411,7 +1450,7 @@ class YR {
1411
1450
  const S = new Date(e);
1412
1451
  S.setUTCHours(0, 0, 0, 0);
1413
1452
  const N = new Date(e);
1414
- return N.setUTCHours(23, 59, 59, 999), f(
1453
+ return N.setUTCHours(23, 59, 59, 999), h(
1415
1454
  v(E, S),
1416
1455
  Q(E, N)
1417
1456
  );
@@ -1483,14 +1522,14 @@ class YR {
1483
1522
  const s = new Date(Date.UTC(e, S - 11, 1, 0, 0, 0, 0)), L = new Date(R);
1484
1523
  return L.setUTCHours(23, 59, 59, 999), { start: s, end: L };
1485
1524
  }
1486
- const I = A.match(/^last\s+(\d+)\s+months?$/);
1487
- if (I) {
1488
- const s = parseInt(I[1], 10), L = new Date(Date.UTC(e, S - s + 1, 1, 0, 0, 0, 0)), a = new Date(R);
1525
+ const O = A.match(/^last\s+(\d+)\s+months?$/);
1526
+ if (O) {
1527
+ const s = parseInt(O[1], 10), L = new Date(Date.UTC(e, S - s + 1, 1, 0, 0, 0, 0)), a = new Date(R);
1489
1528
  return a.setUTCHours(23, 59, 59, 999), { start: L, end: a };
1490
1529
  }
1491
- const O = A.match(/^last\s+(\d+)\s+years?$/);
1492
- if (O) {
1493
- const s = parseInt(O[1], 10), L = new Date(Date.UTC(e - s, 0, 1, 0, 0, 0, 0)), a = new Date(R);
1530
+ const I = A.match(/^last\s+(\d+)\s+years?$/);
1531
+ if (I) {
1532
+ const s = parseInt(I[1], 10), L = new Date(Date.UTC(e - s, 0, 1, 0, 0, 0, 0)), a = new Date(R);
1494
1533
  return a.setUTCHours(23, 59, 59, 999), { start: L, end: a };
1495
1534
  }
1496
1535
  return null;
@@ -1526,27 +1565,27 @@ class YR {
1526
1565
  const t = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
1527
1566
  if (R.dimensions)
1528
1567
  for (const r of R.dimensions) {
1529
- const [I, O] = r.split("."), s = t.get(I);
1530
- if (s && s.dimensions && s.dimensions[O])
1531
- if (e?.preAggregationCTEs?.some((a) => a.cube.name === I)) {
1532
- const a = e.preAggregationCTEs.find((n) => n.cube.name === I), o = a.joinKeys.find((n) => n.targetColumn === O);
1568
+ const [O, I] = r.split("."), s = t.get(O);
1569
+ if (s && s.dimensions && s.dimensions[I])
1570
+ if (e?.preAggregationCTEs?.some((a) => a.cube.name === O)) {
1571
+ const a = e.preAggregationCTEs.find((n) => n.cube.name === O), o = a.joinKeys.find((n) => n.targetColumn === I);
1533
1572
  if (o && o.sourceColumnObj)
1534
1573
  S.push(o.sourceColumnObj);
1535
1574
  else {
1536
- const n = C`${C.identifier(a.cteAlias)}.${C.identifier(O)}`;
1575
+ const n = C`${C.identifier(a.cteAlias)}.${C.identifier(I)}`;
1537
1576
  S.push(n);
1538
1577
  }
1539
1578
  } else {
1540
- const a = s.dimensions[O], o = $(a.sql, A);
1579
+ const a = s.dimensions[I], o = $(a.sql, A);
1541
1580
  S.push(o);
1542
1581
  }
1543
1582
  }
1544
1583
  if (R.timeDimensions)
1545
1584
  for (const r of R.timeDimensions) {
1546
- const [I, O] = r.dimension.split("."), s = t.get(I);
1547
- if (s && s.dimensions && s.dimensions[O])
1548
- if (e?.preAggregationCTEs?.some((a) => a.cube.name === I)) {
1549
- const a = e.preAggregationCTEs.find((n) => n.cube.name === I), o = a.joinKeys.find((n) => n.targetColumn === O);
1585
+ const [O, I] = r.dimension.split("."), s = t.get(O);
1586
+ if (s && s.dimensions && s.dimensions[I])
1587
+ if (e?.preAggregationCTEs?.some((a) => a.cube.name === O)) {
1588
+ const a = e.preAggregationCTEs.find((n) => n.cube.name === O), o = a.joinKeys.find((n) => n.targetColumn === I);
1550
1589
  if (o && o.sourceColumnObj) {
1551
1590
  const n = this.buildTimeDimensionExpression(
1552
1591
  o.sourceColumnObj,
@@ -1555,11 +1594,11 @@ class YR {
1555
1594
  );
1556
1595
  S.push(n);
1557
1596
  } else {
1558
- const n = C`${C.identifier(a.cteAlias)}.${C.identifier(O)}`;
1597
+ const n = C`${C.identifier(a.cteAlias)}.${C.identifier(I)}`;
1559
1598
  S.push(n);
1560
1599
  }
1561
1600
  } else {
1562
- const a = s.dimensions[O], o = this.buildTimeDimensionExpression(
1601
+ const a = s.dimensions[I], o = this.buildTimeDimensionExpression(
1563
1602
  a.sql,
1564
1603
  r.granularity,
1565
1604
  A
@@ -1582,7 +1621,7 @@ class YR {
1582
1621
  for (const [S, N] of Object.entries(E.order)) {
1583
1622
  if (!e.includes(S))
1584
1623
  throw new Error(`Cannot order by '${S}': field is not selected in the query`);
1585
- 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));
1586
1625
  A.push(t);
1587
1626
  }
1588
1627
  if (E.timeDimensions && E.timeDimensions.length > 0) {
@@ -1604,8 +1643,8 @@ class YR {
1604
1643
  for (const S of R.dimensions) {
1605
1644
  const [N, t] = S.split("."), r = e.get(N);
1606
1645
  if (r) {
1607
- const I = r.dimensions[t];
1608
- I && I.type === "number" && A.push(S);
1646
+ const O = r.dimensions[t];
1647
+ O && O.type === "number" && A.push(S);
1609
1648
  }
1610
1649
  }
1611
1650
  return A;
@@ -1631,7 +1670,7 @@ class YR {
1631
1670
  return e;
1632
1671
  }
1633
1672
  }
1634
- class pR {
1673
+ class dR {
1635
1674
  /**
1636
1675
  * Analyze a semantic query to determine which cubes are involved
1637
1676
  */
@@ -1720,7 +1759,7 @@ class pR {
1720
1759
  groupByFields: []
1721
1760
  // Will be built by QueryBuilder
1722
1761
  };
1723
- const r = this.buildJoinPlan(E, t, S), I = this.planPreAggregationCTEs(E, t, r, R);
1762
+ const r = this.buildJoinPlan(E, t, S, A), O = this.planPreAggregationCTEs(E, t, r, R);
1724
1763
  return {
1725
1764
  primaryCube: t,
1726
1765
  joinCubes: r,
@@ -1730,7 +1769,7 @@ class pR {
1730
1769
  // Will be built by QueryBuilder
1731
1770
  groupByFields: [],
1732
1771
  // Will be built by QueryBuilder
1733
- preAggregationCTEs: I
1772
+ preAggregationCTEs: O
1734
1773
  };
1735
1774
  }
1736
1775
  /**
@@ -1779,36 +1818,56 @@ class pR {
1779
1818
  * Build join plan for multi-cube query
1780
1819
  * Supports both direct joins and transitive joins through intermediate cubes
1781
1820
  */
1782
- buildJoinPlan(E, R, A) {
1783
- const e = [], S = /* @__PURE__ */ new Set([R.name]), N = A.filter((t) => t !== R.name);
1784
- for (const t of N) {
1785
- 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))
1786
1825
  continue;
1787
- const r = this.findJoinPath(E, R.name, t, S);
1788
- if (!r || r.length === 0)
1789
- throw new Error(`No join path found from '${R.name}' to '${t}'`);
1790
- for (const { toCube: I, joinDef: O } of r) {
1791
- if (S.has(I))
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))
1792
1831
  continue;
1793
- const s = E.get(I);
1794
- if (!s)
1832
+ const L = E.get(I);
1833
+ if (!L)
1795
1834
  throw new Error(`Cube '${I}' not found`);
1796
- const L = this.buildJoinCondition(
1797
- O,
1798
- null,
1799
- // No source alias needed - use the actual column
1800
- null
1801
- // No target alias needed - use the actual column
1802
- ), a = FR(O.relationship, O.sqlJoinType);
1803
- e.push({
1804
- cube: s,
1805
- alias: `${I.toLowerCase()}_cube`,
1806
- joinType: a,
1807
- joinCondition: L
1808
- }), S.add(I);
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);
1809
1868
  }
1810
1869
  }
1811
- return e;
1870
+ return S;
1812
1871
  }
1813
1872
  /**
1814
1873
  * Build join condition from new array-based join definition
@@ -1816,10 +1875,10 @@ class pR {
1816
1875
  buildJoinCondition(E, R, A) {
1817
1876
  const e = [];
1818
1877
  for (const S of E.on) {
1819
- 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;
1820
1879
  e.push(r(N, t));
1821
1880
  }
1822
- return f(...e);
1881
+ return h(...e);
1823
1882
  }
1824
1883
  /**
1825
1884
  * Find join path from source cube to target cube
@@ -1832,16 +1891,16 @@ class pR {
1832
1891
  { cube: R, path: [] }
1833
1892
  ], N = /* @__PURE__ */ new Set([R, ...e]);
1834
1893
  for (; S.length > 0; ) {
1835
- const { cube: t, path: r } = S.shift(), I = E.get(t);
1836
- if (I?.joins)
1837
- for (const [, O] of Object.entries(I.joins)) {
1838
- const L = tT(O.targetCube).name;
1894
+ const { cube: t, path: r } = S.shift(), O = E.get(t);
1895
+ if (O?.joins)
1896
+ for (const [, I] of Object.entries(O.joins)) {
1897
+ const L = tT(I.targetCube).name;
1839
1898
  if (N.has(L))
1840
1899
  continue;
1841
1900
  const a = [...r, {
1842
1901
  fromCube: t,
1843
1902
  toCube: L,
1844
- joinDef: O
1903
+ joinDef: I
1845
1904
  }];
1846
1905
  if (L === A)
1847
1906
  return a;
@@ -1852,6 +1911,8 @@ class pR {
1852
1911
  }
1853
1912
  /**
1854
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
1855
1916
  */
1856
1917
  planPreAggregationCTEs(E, R, A, e) {
1857
1918
  const S = [];
@@ -1863,8 +1924,8 @@ class pR {
1863
1924
  continue;
1864
1925
  const r = e.measures ? e.measures.filter(
1865
1926
  (L) => L.startsWith(N.cube.name + ".")
1866
- ) : [], I = this.extractMeasuresFromFilters(e, N.cube.name), O = [.../* @__PURE__ */ new Set([...r, ...I])];
1867
- if (O.length === 0)
1927
+ ) : [], O = this.extractMeasuresFromFilters(e, N.cube.name), I = [.../* @__PURE__ */ new Set([...r, ...O])];
1928
+ if (I.length === 0)
1868
1929
  continue;
1869
1930
  const s = t.on.map((L) => ({
1870
1931
  sourceColumn: L.source.name,
@@ -1877,7 +1938,7 @@ class pR {
1877
1938
  alias: N.alias,
1878
1939
  cteAlias: `${N.cube.name.toLowerCase()}_agg`,
1879
1940
  joinKeys: s,
1880
- measures: O
1941
+ measures: I
1881
1942
  });
1882
1943
  }
1883
1944
  return S;
@@ -1898,7 +1959,7 @@ class UE {
1898
1959
  constructor(E) {
1899
1960
  if (this.dbExecutor = E, this.databaseAdapter = E.databaseAdapter, !this.databaseAdapter)
1900
1961
  throw new Error("DatabaseExecutor must have a databaseAdapter property");
1901
- this.queryBuilder = new YR(this.databaseAdapter), this.queryPlanner = new pR();
1962
+ this.queryBuilder = new pR(this.databaseAdapter), this.queryPlanner = new dR();
1902
1963
  }
1903
1964
  queryBuilder;
1904
1965
  queryPlanner;
@@ -1908,14 +1969,14 @@ class UE {
1908
1969
  */
1909
1970
  async execute(E, R, A) {
1910
1971
  try {
1911
- const e = tR(E, R);
1972
+ const e = CR(E, R);
1912
1973
  if (!e.isValid)
1913
1974
  throw new Error(`Query validation failed: ${e.errors.join(", ")}`);
1914
1975
  const S = {
1915
1976
  db: this.dbExecutor.db,
1916
1977
  schema: this.dbExecutor.schema,
1917
1978
  securityContext: A
1918
- }, N = this.queryPlanner.createQueryPlan(E, R, S), t = this.buildUnifiedQuery(N, R, S), r = this.queryBuilder.collectNumericFields(E, R), I = await this.dbExecutor.execute(t, r), O = Array.isArray(I) ? I.map((L) => {
1979
+ }, N = this.queryPlanner.createQueryPlan(E, R, S), t = this.buildUnifiedQuery(N, R, S), r = this.queryBuilder.collectNumericFields(E, R), O = await this.dbExecutor.execute(t, r), I = Array.isArray(O) ? O.map((L) => {
1919
1980
  const a = { ...L };
1920
1981
  if (R.timeDimensions) {
1921
1982
  for (const o of R.timeDimensions)
@@ -1929,9 +1990,9 @@ class UE {
1929
1990
  }
1930
1991
  }
1931
1992
  return a;
1932
- }) : [I], s = this.generateAnnotations(N, R);
1993
+ }) : [O], s = this.generateAnnotations(N, R);
1933
1994
  return {
1934
- data: O,
1995
+ data: I,
1935
1996
  annotation: s
1936
1997
  };
1937
1998
  } catch (e) {
@@ -1959,8 +2020,8 @@ class UE {
1959
2020
  for (const n of E.measures) {
1960
2021
  const [, U] = n.split(".");
1961
2022
  if (S.measures && S.measures[U]) {
1962
- const P = S.measures[U], l = this.queryBuilder.buildMeasureExpression(P, A);
1963
- t[U] = C`${l}`.as(U);
2023
+ const P = S.measures[U], c = this.queryBuilder.buildMeasureExpression(P, A);
2024
+ t[U] = C`${c}`.as(U);
1964
2025
  }
1965
2026
  }
1966
2027
  const r = S.name;
@@ -1968,50 +2029,50 @@ class UE {
1968
2029
  for (const n of R.dimensions) {
1969
2030
  const [U, P] = n.split(".");
1970
2031
  if (U === r && S.dimensions && S.dimensions[P]) {
1971
- const l = S.dimensions[P], c = this.queryBuilder.buildMeasureExpression({ sql: l.sql, type: "number" }, A);
1972
- t[P] = C`${c}`.as(P);
2032
+ const c = S.dimensions[P], l = this.queryBuilder.buildMeasureExpression({ sql: c.sql, type: "number" }, A);
2033
+ t[P] = C`${l}`.as(P);
1973
2034
  }
1974
2035
  }
1975
2036
  if (R.timeDimensions)
1976
2037
  for (const n of R.timeDimensions) {
1977
2038
  const [U, P] = n.dimension.split(".");
1978
2039
  if (U === r && S.dimensions && S.dimensions[P]) {
1979
- const l = S.dimensions[P], c = this.queryBuilder.buildTimeDimensionExpression(l.sql, n.granularity, A);
1980
- t[P] = C`${c}`.as(P);
2040
+ const c = S.dimensions[P], l = this.queryBuilder.buildTimeDimensionExpression(c.sql, n.granularity, A);
2041
+ t[P] = C`${l}`.as(P);
1981
2042
  }
1982
2043
  }
1983
2044
  if (Object.keys(t).length === 0)
1984
2045
  return null;
1985
- let I = A.db.select(t).from(N.from);
1986
- const O = e ? {
2046
+ let O = A.db.select(t).from(N.from);
2047
+ const I = e ? {
1987
2048
  ...e,
1988
2049
  preAggregationCTEs: e.preAggregationCTEs?.filter((n) => n.cube.name !== S.name)
1989
- } : void 0, s = this.queryBuilder.buildWhereConditions(S, R, A, O), L = [];
2050
+ } : void 0, s = this.queryBuilder.buildWhereConditions(S, R, A, I), L = [];
1990
2051
  if (R.timeDimensions)
1991
2052
  for (const n of R.timeDimensions) {
1992
2053
  const [U, P] = n.dimension.split(".");
1993
2054
  if (U === r && S.dimensions && S.dimensions[P] && n.dateRange) {
1994
- const l = S.dimensions[P], c = this.queryBuilder.buildMeasureExpression({ sql: l.sql, type: "number" }, A), m = this.queryBuilder.buildDateRangeCondition(c, n.dateRange);
1995
- m && L.push(m);
2055
+ const c = S.dimensions[P], l = this.queryBuilder.buildMeasureExpression({ sql: c.sql, type: "number" }, A), H = this.queryBuilder.buildDateRangeCondition(l, n.dateRange);
2056
+ H && L.push(H);
1996
2057
  }
1997
2058
  }
1998
2059
  if (R.filters) {
1999
2060
  for (const n of R.filters)
2000
2061
  if (!("and" in n) && !("or" in n) && "member" in n && "operator" in n) {
2001
- const U = n, [P, l] = U.member.split(".");
2002
- if (P === r && S.dimensions && S.dimensions[l]) {
2003
- const c = S.dimensions[l];
2062
+ const U = n, [P, c] = U.member.split(".");
2063
+ if (P === r && S.dimensions && S.dimensions[c]) {
2064
+ const l = S.dimensions[c];
2004
2065
  if (U.operator === "inDateRange") {
2005
- const m = this.queryBuilder.buildMeasureExpression({ sql: c.sql, type: "number" }, A), p = this.queryBuilder.buildDateRangeCondition(m, U.values);
2006
- p && L.push(p);
2066
+ const H = this.queryBuilder.buildMeasureExpression({ sql: l.sql, type: "number" }, A), B = this.queryBuilder.buildDateRangeCondition(H, U.values);
2067
+ B && L.push(B);
2007
2068
  }
2008
2069
  }
2009
2070
  }
2010
2071
  }
2011
2072
  const a = [];
2012
2073
  if (N.where && a.push(N.where), a.push(...s, ...L), a.length > 0) {
2013
- const n = a.length === 1 ? a[0] : f(...a);
2014
- I = I.where(n);
2074
+ const n = a.length === 1 ? a[0] : h(...a);
2075
+ O = O.where(n);
2015
2076
  }
2016
2077
  const o = [];
2017
2078
  for (const n of E.joinKeys)
@@ -2020,19 +2081,19 @@ class UE {
2020
2081
  for (const n of R.dimensions) {
2021
2082
  const [U, P] = n.split(".");
2022
2083
  if (U === r && S.dimensions && S.dimensions[P]) {
2023
- const l = S.dimensions[P], c = $(l.sql, A);
2024
- o.push(c);
2084
+ const c = S.dimensions[P], l = $(c.sql, A);
2085
+ o.push(l);
2025
2086
  }
2026
2087
  }
2027
2088
  if (R.timeDimensions)
2028
2089
  for (const n of R.timeDimensions) {
2029
2090
  const [U, P] = n.dimension.split(".");
2030
2091
  if (U === r && S.dimensions && S.dimensions[P]) {
2031
- const l = S.dimensions[P], c = this.queryBuilder.buildTimeDimensionExpression(l.sql, n.granularity, A);
2032
- o.push(c);
2092
+ const c = S.dimensions[P], l = this.queryBuilder.buildTimeDimensionExpression(c.sql, n.granularity, A);
2093
+ o.push(l);
2033
2094
  }
2034
2095
  }
2035
- return o.length > 0 && (I = I.groupBy(...o)), A.db.$with(E.cteAlias).as(I);
2096
+ return o.length > 0 && (O = O.groupBy(...o)), A.db.$with(E.cteAlias).as(O);
2036
2097
  }
2037
2098
  // Removed unused getActualJoinTargetColumn method
2038
2099
  /**
@@ -2045,9 +2106,9 @@ class UE {
2045
2106
  const S = [];
2046
2107
  for (const N of e.joinKeys) {
2047
2108
  const t = N.sourceColumnObj || C.identifier(N.sourceColumn), r = C`${C.identifier(R)}.${C.identifier(N.targetColumn)}`;
2048
- S.push(sE(t, r));
2109
+ S.push(j(t, r));
2049
2110
  }
2050
- return S.length === 1 ? S[0] : f(...S);
2111
+ return S.length === 1 ? S[0] : h(...S);
2051
2112
  }
2052
2113
  /**
2053
2114
  * Build unified query that works for both single and multi-cube queries
@@ -2070,49 +2131,50 @@ class UE {
2070
2131
  const U = n.cube.name;
2071
2132
  for (const P of n.measures)
2072
2133
  if (r[P]) {
2073
- const [, l] = P.split("."), c = this.getCubesFromPlan(E).get(U);
2074
- if (c && c.measures && c.measures[l]) {
2075
- const m = c.measures[l], p = C`${C.identifier(n.cteAlias)}.${C.identifier(l)}`;
2134
+ const [, c] = P.split("."), l = this.getCubesFromPlan(E).get(U);
2135
+ if (l && l.measures && l.measures[c]) {
2136
+ const H = l.measures[c], B = C`${C.identifier(n.cteAlias)}.${C.identifier(c)}`;
2076
2137
  let V;
2077
- switch (m.type) {
2138
+ switch (H.type) {
2078
2139
  case "count":
2079
2140
  case "countDistinct":
2080
2141
  case "sum":
2081
- V = g(p);
2142
+ V = g(B);
2082
2143
  break;
2083
2144
  case "avg":
2084
- V = this.databaseAdapter.buildAvg(p);
2145
+ V = this.databaseAdapter.buildAvg(B);
2085
2146
  break;
2086
2147
  case "min":
2087
- V = vE(p);
2148
+ V = vE(B);
2088
2149
  break;
2089
2150
  case "max":
2090
- V = xE(p);
2151
+ V = xE(B);
2091
2152
  break;
2092
2153
  case "number":
2093
- V = g(p);
2154
+ V = g(B);
2094
2155
  break;
2095
2156
  default:
2096
- V = g(p);
2157
+ V = g(B);
2097
2158
  }
2098
2159
  r[P] = C`${V}`.as(P);
2099
2160
  }
2100
2161
  }
2101
2162
  for (const P in r) {
2102
- const [l, c] = P.split(".");
2103
- if (l === U) {
2104
- const m = this.getCubesFromPlan(E).get(U), p = m && m.dimensions?.[c], V = P.startsWith(U + ".");
2105
- if (p || V) {
2106
- let x = n.joinKeys.find((LE) => LE.targetColumn === c);
2107
- if (!x && m?.dimensions?.[c]) {
2108
- const LE = m.dimensions[c].sql;
2109
- x = n.joinKeys.find((LR) => LR.targetColumnObj === LE);
2163
+ const [c, l] = P.split(".");
2164
+ if (c === U) {
2165
+ const H = this.getCubesFromPlan(E).get(U), B = H && H.dimensions?.[l], V = P.startsWith(U + ".");
2166
+ if (B || V) {
2167
+ let x = n.joinKeys.find((LE) => LE.targetColumn === l);
2168
+ if (!x && H?.dimensions?.[l]) {
2169
+ const LE = H.dimensions[l].sql;
2170
+ x = n.joinKeys.find((_R) => _R.targetColumnObj === LE);
2110
2171
  }
2111
- x ? r[P] = C`${C.identifier(n.cteAlias)}.${C.identifier(c)}`.as(P) : V && m?.dimensions?.[c] && (r[P] = C`${C.identifier(n.cteAlias)}.${C.identifier(c)}`.as(P));
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));
2112
2173
  }
2113
2174
  }
2114
2175
  }
2115
2176
  }
2177
+ const O = [];
2116
2178
  let I = A.db.select(r).from(N.from);
2117
2179
  if (e.length > 0 && (I = A.db.with(...e).select(r).from(N.from)), N.joins)
2118
2180
  for (const n of N.joins)
@@ -2133,27 +2195,51 @@ class UE {
2133
2195
  if (E.joinCubes && E.joinCubes.length > 0)
2134
2196
  for (const n of E.joinCubes) {
2135
2197
  const U = S.get(n.cube.name);
2136
- let P, l;
2137
- U ? (P = C`${C.identifier(U)}`, l = this.buildCTEJoinCondition(n, U, E)) : (P = n.cube.sql(A).from, l = n.joinCondition);
2198
+ if (n.junctionTable) {
2199
+ const l = n.junctionTable, H = [];
2200
+ if (l.securitySql) {
2201
+ const B = l.securitySql(A.securityContext);
2202
+ Array.isArray(B) ? H.push(...B) : H.push(B);
2203
+ }
2204
+ try {
2205
+ switch (l.joinType || "left") {
2206
+ case "left":
2207
+ I = I.leftJoin(l.table, l.joinCondition);
2208
+ break;
2209
+ case "inner":
2210
+ I = I.innerJoin(l.table, l.joinCondition);
2211
+ break;
2212
+ case "right":
2213
+ I = I.rightJoin(l.table, l.joinCondition);
2214
+ break;
2215
+ case "full":
2216
+ I = I.fullJoin(l.table, l.joinCondition);
2217
+ break;
2218
+ }
2219
+ H.length > 0 && O.push(...H);
2220
+ } catch {
2221
+ }
2222
+ }
2223
+ let P, c;
2224
+ U ? (P = C`${C.identifier(U)}`, c = this.buildCTEJoinCondition(n, U, E)) : (P = n.cube.sql(A).from, c = n.joinCondition);
2138
2225
  try {
2139
2226
  switch (n.joinType || "left") {
2140
2227
  case "left":
2141
- I = I.leftJoin(P, l);
2228
+ I = I.leftJoin(P, c);
2142
2229
  break;
2143
2230
  case "inner":
2144
- I = I.innerJoin(P, l);
2231
+ I = I.innerJoin(P, c);
2145
2232
  break;
2146
2233
  case "right":
2147
- I = I.rightJoin(P, l);
2234
+ I = I.rightJoin(P, c);
2148
2235
  break;
2149
2236
  case "full":
2150
- I = I.fullJoin(P, l);
2237
+ I = I.fullJoin(P, c);
2151
2238
  break;
2152
2239
  }
2153
2240
  } catch {
2154
2241
  }
2155
2242
  }
2156
- const O = [];
2157
2243
  if (N.where && O.push(N.where), E.joinCubes && E.joinCubes.length > 0)
2158
2244
  for (const n of E.joinCubes) {
2159
2245
  if (S.get(n.cube.name))
@@ -2170,7 +2256,7 @@ class UE {
2170
2256
  // Pass the queryPlan to handle CTE scenarios
2171
2257
  );
2172
2258
  if (s.length > 0 && O.push(...s), O.length > 0) {
2173
- const n = O.length === 1 ? O[0] : f(...O);
2259
+ const n = O.length === 1 ? O[0] : h(...O);
2174
2260
  I = I.where(n);
2175
2261
  }
2176
2262
  const L = this.queryBuilder.buildGroupByFields(
@@ -2191,7 +2277,7 @@ class UE {
2191
2277
  // Pass the queryPlan to handle CTE scenarios
2192
2278
  );
2193
2279
  if (a.length > 0) {
2194
- const n = a.length === 1 ? a[0] : f(...a);
2280
+ const n = a.length === 1 ? a[0] : h(...a);
2195
2281
  I = I.having(n);
2196
2282
  }
2197
2283
  const o = this.queryBuilder.buildOrderBy(R);
@@ -2241,36 +2327,36 @@ class UE {
2241
2327
  const A = {}, e = {}, S = {}, N = [E.primaryCube];
2242
2328
  if (E.joinCubes && E.joinCubes.length > 0 && N.push(...E.joinCubes.map((t) => t.cube)), R.measures)
2243
2329
  for (const t of R.measures) {
2244
- const [r, I] = t.split("."), O = N.find((s) => s.name === r);
2245
- if (O && O.measures[I]) {
2246
- const s = O.measures[I];
2330
+ const [r, O] = t.split("."), I = N.find((s) => s.name === r);
2331
+ if (I && I.measures[O]) {
2332
+ const s = I.measures[O];
2247
2333
  A[t] = {
2248
- title: s.title || I,
2249
- shortTitle: s.title || I,
2334
+ title: s.title || O,
2335
+ shortTitle: s.title || O,
2250
2336
  type: s.type
2251
2337
  };
2252
2338
  }
2253
2339
  }
2254
2340
  if (R.dimensions)
2255
2341
  for (const t of R.dimensions) {
2256
- const [r, I] = t.split("."), O = N.find((s) => s.name === r);
2257
- if (O && O.dimensions[I]) {
2258
- const s = O.dimensions[I];
2342
+ const [r, O] = t.split("."), I = N.find((s) => s.name === r);
2343
+ if (I && I.dimensions[O]) {
2344
+ const s = I.dimensions[O];
2259
2345
  e[t] = {
2260
- title: s.title || I,
2261
- shortTitle: s.title || I,
2346
+ title: s.title || O,
2347
+ shortTitle: s.title || O,
2262
2348
  type: s.type
2263
2349
  };
2264
2350
  }
2265
2351
  }
2266
2352
  if (R.timeDimensions)
2267
2353
  for (const t of R.timeDimensions) {
2268
- const [r, I] = t.dimension.split("."), O = N.find((s) => s.name === r);
2269
- if (O && O.dimensions && O.dimensions[I]) {
2270
- const s = O.dimensions[I];
2354
+ const [r, O] = t.dimension.split("."), I = N.find((s) => s.name === r);
2355
+ if (I && I.dimensions && I.dimensions[O]) {
2356
+ const s = I.dimensions[O];
2271
2357
  S[t.dimension] = {
2272
- title: s.title || I,
2273
- shortTitle: s.title || I,
2358
+ title: s.title || O,
2359
+ shortTitle: s.title || O,
2274
2360
  type: s.type,
2275
2361
  granularity: t.granularity
2276
2362
  };
@@ -2284,13 +2370,13 @@ class UE {
2284
2370
  };
2285
2371
  }
2286
2372
  }
2287
- 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) => ({
2288
2374
  type: "mandatory_block",
2289
2375
  items: jE(T, 0)[0]
2290
2376
  }), jE = (T, E, R) => {
2291
2377
  const A = [];
2292
2378
  for (; T[E]; ) {
2293
- const [e, S] = VR(T, E);
2379
+ const [e, S] = WR(T, E);
2294
2380
  if (A.push(e), E = S, T[E] === "|")
2295
2381
  E++;
2296
2382
  else if (T[E] === "}" || T[E] === "]") {
@@ -2305,44 +2391,44 @@ const _ = (T) => T.flatMap(dR), dR = (T) => RE(fR(T)).map(hR), hR = (T) => T.rep
2305
2391
  throw new Error(`Unexpected "${T[E]}"`);
2306
2392
  }
2307
2393
  return [A, E];
2308
- }, VR = (T, E) => {
2394
+ }, WR = (T, E) => {
2309
2395
  const R = [];
2310
2396
  for (; ; ) {
2311
- const [A, e] = WR(T, E);
2397
+ const [A, e] = XR(T, E);
2312
2398
  if (A)
2313
2399
  R.push(A), E = e;
2314
2400
  else
2315
2401
  break;
2316
2402
  }
2317
2403
  return R.length === 1 ? [R[0], E] : [{ type: "concatenation", items: R }, E];
2318
- }, WR = (T, E) => {
2404
+ }, XR = (T, E) => {
2319
2405
  if (T[E] === "{")
2320
- return XR(T, E + 1);
2321
- if (T[E] === "[")
2322
2406
  return bR(T, E + 1);
2407
+ if (T[E] === "[")
2408
+ return yR(T, E + 1);
2323
2409
  {
2324
2410
  let R = "";
2325
2411
  for (; T[E] && /[A-Za-z0-9_ ]/.test(T[E]); )
2326
2412
  R += T[E], E++;
2327
2413
  return [R, E];
2328
2414
  }
2329
- }, XR = (T, E) => {
2415
+ }, bR = (T, E) => {
2330
2416
  const [R, A] = jE(T, E, "}");
2331
2417
  return [{ type: "mandatory_block", items: R }, A];
2332
- }, bR = (T, E) => {
2418
+ }, yR = (T, E) => {
2333
2419
  const [R, A] = jE(T, E, "]");
2334
2420
  return [{ type: "optional_block", items: R }, A];
2335
- }, RE = (T) => {
2421
+ }, AE = (T) => {
2336
2422
  if (typeof T == "string")
2337
2423
  return [T];
2338
2424
  if (T.type === "concatenation")
2339
- return T.items.map(RE).reduce(yR, [""]);
2425
+ return T.items.map(AE).reduce(KR, [""]);
2340
2426
  if (T.type === "mandatory_block")
2341
- return T.items.flatMap(RE);
2427
+ return T.items.flatMap(AE);
2342
2428
  if (T.type === "optional_block")
2343
- return ["", ...T.items.flatMap(RE)];
2429
+ return ["", ...T.items.flatMap(AE)];
2344
2430
  throw new Error(`Unknown node type: ${T}`);
2345
- }, yR = (T, E) => {
2431
+ }, KR = (T, E) => {
2346
2432
  const R = [];
2347
2433
  for (const A of T)
2348
2434
  for (const e of E)
@@ -2353,19 +2439,19 @@ var D;
2353
2439
  (function(T) {
2354
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";
2355
2441
  })(D = D || (D = {}));
2356
- const qT = (T) => ({
2442
+ const jT = (T) => ({
2357
2443
  type: D.EOF,
2358
2444
  raw: "«EOF»",
2359
2445
  text: "«EOF»",
2360
2446
  start: T
2361
- }), 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 = {
2362
2448
  ARRAY: Z({ text: "ARRAY", type: D.RESERVED_DATA_TYPE }),
2363
2449
  BY: Z({ text: "BY", type: D.RESERVED_KEYWORD }),
2364
2450
  SET: Z({ text: "SET", type: D.RESERVED_CLAUSE }),
2365
2451
  STRUCT: Z({ text: "STRUCT", type: D.RESERVED_DATA_TYPE }),
2366
2452
  WINDOW: Z({ text: "WINDOW", type: D.RESERVED_CLAUSE }),
2367
2453
  VALUES: Z({ text: "VALUES", type: D.RESERVED_CLAUSE })
2368
- }, 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 = [
2369
2455
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/aead_encryption_functions
2370
2456
  "KEYS.NEW_KEYSET",
2371
2457
  "KEYS.ADD_KEY_FROM_RAW_BYTES",
@@ -2909,7 +2995,7 @@ const qT = (T) => ({
2909
2995
  // pivot
2910
2996
  "PIVOT",
2911
2997
  "UNPIVOT"
2912
- ], gR = [
2998
+ ], wR = [
2913
2999
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#reserved_keywords
2914
3000
  "ALL",
2915
3001
  "AND",
@@ -3017,7 +3103,7 @@ const qT = (T) => ({
3017
3103
  "CASCADE",
3018
3104
  "RESTRICT",
3019
3105
  "DETERMINISTIC"
3020
- ], wR = [
3106
+ ], JR = [
3021
3107
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
3022
3108
  "ARRAY",
3023
3109
  "BOOL",
@@ -3042,7 +3128,7 @@ const qT = (T) => ({
3042
3128
  "STRUCT",
3043
3129
  "TIME",
3044
3130
  "TIMEZONE"
3045
- ], JR = _(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), xR = _([
3131
+ ], xR = _(["SELECT [ALL | DISTINCT] [AS STRUCT | AS VALUE]"]), vR = _([
3046
3132
  // Queries: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax
3047
3133
  "WITH [RECURSIVE]",
3048
3134
  "FROM",
@@ -3161,15 +3247,15 @@ const qT = (T) => ({
3161
3247
  "ASSERT",
3162
3248
  // Other, https://cloud.google.com/bigquery/docs/reference/standard-sql/other-statements
3163
3249
  "EXPORT DATA"
3164
- ]), vR = _([
3250
+ ]), QR = _([
3165
3251
  "UNION {ALL | DISTINCT}",
3166
3252
  "EXCEPT DISTINCT",
3167
3253
  "INTERSECT DISTINCT"
3168
- ]), QR = _([
3254
+ ]), ZR = _([
3169
3255
  "JOIN",
3170
3256
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
3171
3257
  "{INNER | CROSS} JOIN"
3172
- ]), ZR = _([
3258
+ ]), qR = _([
3173
3259
  // https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#tablesample_operator
3174
3260
  "TABLESAMPLE SYSTEM",
3175
3261
  // From DDL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
@@ -3180,18 +3266,18 @@ const qT = (T) => ({
3180
3266
  "{ROWS | RANGE} BETWEEN",
3181
3267
  // comparison operator
3182
3268
  "IS [NOT] DISTINCT FROM"
3183
- ]), qR = _([]), jR = {
3269
+ ]), jR = _([]), kR = {
3184
3270
  name: "bigquery",
3185
3271
  tokenizerOptions: {
3186
- reservedSelect: JR,
3187
- reservedClauses: [...xR, ...GE, ...CT],
3188
- reservedSetOperations: vR,
3189
- reservedJoins: QR,
3190
- reservedKeywordPhrases: ZR,
3191
- reservedDataTypePhrases: qR,
3192
- reservedKeywords: gR,
3193
- reservedDataTypes: wR,
3194
- 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,
3195
3281
  extraParens: ["[]"],
3196
3282
  stringTypes: [
3197
3283
  // The triple-quoted strings are listed first, so they get matched first.
@@ -3209,27 +3295,27 @@ const qT = (T) => ({
3209
3295
  variableTypes: [{ regex: String.raw`@@\w+` }],
3210
3296
  lineCommentTypes: ["--", "#"],
3211
3297
  operators: ["&", "|", "^", "~", ">>", "<<", "||", "=>"],
3212
- postProcess: kR
3298
+ postProcess: zR
3213
3299
  },
3214
3300
  formatOptions: {
3215
3301
  onelineClauses: [...CT, ...GE],
3216
3302
  tabularOnelineClauses: GE
3217
3303
  }
3218
3304
  };
3219
- function kR(T) {
3220
- return zR(EA(T));
3221
- }
3222
3305
  function zR(T) {
3223
- let E = j;
3224
- 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));
3225
3307
  }
3226
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) {
3227
3313
  var E;
3228
3314
  const R = [];
3229
3315
  for (let A = 0; A < T.length; A++) {
3230
3316
  const e = T[A];
3231
3317
  if ((w.ARRAY(e) || w.STRUCT(e)) && ((E = T[A + 1]) === null || E === void 0 ? void 0 : E.text) === "<") {
3232
- 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);
3233
3319
  R.push({
3234
3320
  type: D.IDENTIFIER,
3235
3321
  raw: N.map(LT("raw")).join(""),
@@ -3242,7 +3328,7 @@ function EA(T) {
3242
3328
  return R;
3243
3329
  }
3244
3330
  const LT = (T) => (E) => E.type === D.IDENTIFIER || E.type === D.COMMA ? E[T] + " " : E[T];
3245
- function TA(T, E) {
3331
+ function RA(T, E) {
3246
3332
  let R = 0;
3247
3333
  for (let A = E; A < T.length; A++) {
3248
3334
  const e = T[A];
@@ -3251,7 +3337,7 @@ function TA(T, E) {
3251
3337
  }
3252
3338
  return T.length - 1;
3253
3339
  }
3254
- const RA = [
3340
+ const AA = [
3255
3341
  // https://www.ibm.com/docs/en/db2/11.5?topic=bif-aggregate-functions
3256
3342
  "ARRAY_AGG",
3257
3343
  "AVG",
@@ -3571,7 +3657,7 @@ const RA = [
3571
3657
  "RATIO_TO_REPORT",
3572
3658
  // Type casting
3573
3659
  "CAST"
3574
- ], AA = [
3660
+ ], eA = [
3575
3661
  // https://www.ibm.com/docs/en/db2/11.5?topic=sql-reserved-schema-names-reserved-words
3576
3662
  "ACTIVATE",
3577
3663
  "ADD",
@@ -3972,7 +4058,7 @@ const RA = [
3972
4058
  "XMLNAMESPACES",
3973
4059
  "YEAR",
3974
4060
  "YEARS"
3975
- ], eA = [
4061
+ ], SA = [
3976
4062
  // https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
3977
4063
  "ARRAY",
3978
4064
  "BIGINT",
@@ -4014,7 +4100,7 @@ const RA = [
4014
4100
  "VARBINARY",
4015
4101
  "VARCHAR",
4016
4102
  "VARGRAPHIC"
4017
- ], SA = _(["SELECT [ALL | DISTINCT]"]), IA = _([
4103
+ ], IA = _(["SELECT [ALL | DISTINCT]"]), OA = _([
4018
4104
  // queries
4019
4105
  "WITH",
4020
4106
  "FROM",
@@ -4248,27 +4334,27 @@ const RA = [
4248
4334
  "TRANSFER OWNERSHIP OF",
4249
4335
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}",
4250
4336
  "WHILE"
4251
- ]), OA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), NA = _([
4337
+ ]), NA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), sA = _([
4252
4338
  "JOIN",
4253
4339
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
4254
4340
  "{INNER | CROSS} JOIN"
4255
- ]), sA = _([
4341
+ ]), tA = _([
4256
4342
  "ON DELETE",
4257
4343
  "ON UPDATE",
4258
4344
  "SET NULL",
4259
4345
  "{ROWS | RANGE} BETWEEN"
4260
- ]), tA = _([]), CA = {
4346
+ ]), CA = _([]), LA = {
4261
4347
  name: "db2",
4262
4348
  tokenizerOptions: {
4263
- reservedSelect: SA,
4264
- reservedClauses: [...IA, ..._T, ...lE],
4265
- reservedSetOperations: OA,
4266
- reservedJoins: NA,
4267
- reservedKeywordPhrases: sA,
4268
- reservedDataTypePhrases: tA,
4269
- reservedKeywords: AA,
4270
- reservedDataTypes: eA,
4271
- 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,
4272
4358
  extraParens: ["[]"],
4273
4359
  stringTypes: [
4274
4360
  { quote: "''-qq", prefixes: ["G", "N", "U&"] },
@@ -4302,7 +4388,7 @@ const RA = [
4302
4388
  onelineClauses: [..._T, ...lE],
4303
4389
  tabularOnelineClauses: lE
4304
4390
  }
4305
- }, LA = [
4391
+ }, _A = [
4306
4392
  // https://www.ibm.com/docs/en/i/7.5?topic=functions-aggregate
4307
4393
  // TODO: 'ANY', - conflicts with test for ANY predicate in 'operators.ys'!!
4308
4394
  "ARRAY_AGG",
@@ -4636,7 +4722,7 @@ const RA = [
4636
4722
  "ROW_NUMBER",
4637
4723
  // Type casting
4638
4724
  "CAST"
4639
- ], _A = [
4725
+ ], rA = [
4640
4726
  // https://www.ibm.com/docs/en/i/7.5?topic=words-reserved
4641
4727
  // TODO: This list likely contains all keywords, not only the reserved ones,
4642
4728
  // try to filter it down to just the reserved keywords.
@@ -5132,7 +5218,7 @@ const RA = [
5132
5218
  "YEARS",
5133
5219
  "YES",
5134
5220
  "ZONE"
5135
- ], rA = [
5221
+ ], nA = [
5136
5222
  // https://www.ibm.com/docs/en/i/7.2?topic=iaodsd-odbc-data-types-how-they-correspond-db2-i-database-types
5137
5223
  "ARRAY",
5138
5224
  "BIGINT",
@@ -5168,7 +5254,7 @@ const RA = [
5168
5254
  "VARCHAR",
5169
5255
  "VARGRAPHIC",
5170
5256
  "XML"
5171
- ], nA = _(["SELECT [ALL | DISTINCT]"]), iA = _([
5257
+ ], iA = _(["SELECT [ALL | DISTINCT]"]), DA = _([
5172
5258
  // queries
5173
5259
  "WITH [RECURSIVE]",
5174
5260
  "INTO",
@@ -5294,28 +5380,28 @@ const RA = [
5294
5380
  "TAG",
5295
5381
  "TRANSFER OWNERSHIP OF",
5296
5382
  "WHENEVER {NOT FOUND | SQLERROR | SQLWARNING}"
5297
- ]), DA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), aA = _([
5383
+ ]), aA = _(["UNION [ALL]", "EXCEPT [ALL]", "INTERSECT [ALL]"]), oA = _([
5298
5384
  "JOIN",
5299
5385
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
5300
5386
  "[LEFT | RIGHT] EXCEPTION JOIN",
5301
5387
  "{INNER | CROSS} JOIN"
5302
- ]), oA = _([
5388
+ ]), PA = _([
5303
5389
  "ON DELETE",
5304
5390
  "ON UPDATE",
5305
5391
  "SET NULL",
5306
5392
  "{ROWS | RANGE} BETWEEN"
5307
- ]), PA = _([]), MA = {
5393
+ ]), MA = _([]), UA = {
5308
5394
  name: "db2i",
5309
5395
  tokenizerOptions: {
5310
- reservedSelect: nA,
5311
- reservedClauses: [...iA, ...rT, ...cE],
5312
- reservedSetOperations: DA,
5313
- reservedJoins: aA,
5314
- reservedKeywordPhrases: oA,
5315
- reservedDataTypePhrases: PA,
5316
- reservedKeywords: _A,
5317
- reservedDataTypes: rA,
5318
- 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,
5319
5405
  nestedBlockComments: !0,
5320
5406
  extraParens: ["[]"],
5321
5407
  stringTypes: [
@@ -5332,7 +5418,7 @@ const RA = [
5332
5418
  onelineClauses: [...rT, ...cE],
5333
5419
  tabularOnelineClauses: cE
5334
5420
  }
5335
- }, UA = [
5421
+ }, GA = [
5336
5422
  // Functions from DuckDB (excluding those that start with an underscore):
5337
5423
  // SELECT DISTINCT upper(function_name) AS function_name
5338
5424
  // FROM duckdb_functions()
@@ -5995,7 +6081,7 @@ const RA = [
5995
6081
  // 'NULL', we really prefer treating it as keyword
5996
6082
  "RANK",
5997
6083
  "ROW_NUMBER"
5998
- ], GA = [
6084
+ ], lA = [
5999
6085
  // Keywords from DuckDB:
6000
6086
  // SELECT upper(keyword_name)
6001
6087
  // FROM duckdb_keywords()
@@ -6077,7 +6163,7 @@ const RA = [
6077
6163
  "WHERE",
6078
6164
  "WINDOW",
6079
6165
  "WITH"
6080
- ], lA = [
6166
+ ], cA = [
6081
6167
  // Types from DuckDB:
6082
6168
  // SELECT DISTINCT upper(type_name)
6083
6169
  // FROM duckdb_types()
@@ -6157,7 +6243,7 @@ const RA = [
6157
6243
  "UUID",
6158
6244
  "VARBINARY",
6159
6245
  "VARCHAR"
6160
- ], cA = _(["SELECT [ALL | DISTINCT]"]), uA = _([
6246
+ ], uA = _(["SELECT [ALL | DISTINCT]"]), HA = _([
6161
6247
  // queries
6162
6248
  "WITH [RECURSIVE]",
6163
6249
  "FROM",
@@ -6261,11 +6347,11 @@ const RA = [
6261
6347
  "PREPARE",
6262
6348
  "EXECUTE",
6263
6349
  "DEALLOCATE [PREPARE]"
6264
- ]), HA = _([
6350
+ ]), BA = _([
6265
6351
  "UNION [ALL | BY NAME]",
6266
6352
  "EXCEPT [ALL]",
6267
6353
  "INTERSECT [ALL]"
6268
- ]), BA = _([
6354
+ ]), mA = _([
6269
6355
  "JOIN",
6270
6356
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6271
6357
  "{INNER | CROSS} JOIN",
@@ -6274,23 +6360,23 @@ const RA = [
6274
6360
  "POSITIONAL JOIN",
6275
6361
  "ANTI JOIN",
6276
6362
  "SEMI JOIN"
6277
- ]), mA = _([
6363
+ ]), FA = _([
6278
6364
  "{ROWS | RANGE | GROUPS} BETWEEN",
6279
6365
  "SIMILAR TO",
6280
6366
  "IS [NOT] DISTINCT FROM"
6281
- ]), FA = _(["TIMESTAMP WITH TIME ZONE"]), YA = {
6367
+ ]), YA = _(["TIMESTAMP WITH TIME ZONE"]), pA = {
6282
6368
  name: "duckdb",
6283
6369
  tokenizerOptions: {
6284
- reservedSelect: cA,
6285
- reservedClauses: [...uA, ...nT, ...uE],
6286
- reservedSetOperations: HA,
6287
- reservedJoins: BA,
6288
- reservedKeywordPhrases: mA,
6289
- reservedDataTypePhrases: FA,
6370
+ reservedSelect: uA,
6371
+ reservedClauses: [...HA, ...nT, ...uE],
6372
+ reservedSetOperations: BA,
6373
+ reservedJoins: mA,
6374
+ reservedKeywordPhrases: FA,
6375
+ reservedDataTypePhrases: YA,
6290
6376
  supportsXor: !0,
6291
- reservedKeywords: GA,
6292
- reservedDataTypes: lA,
6293
- reservedFunctionNames: UA,
6377
+ reservedKeywords: lA,
6378
+ reservedDataTypes: cA,
6379
+ reservedFunctionNames: GA,
6294
6380
  nestedBlockComments: !0,
6295
6381
  extraParens: ["[]", "{}"],
6296
6382
  underscoresInNumbers: !0,
@@ -6354,7 +6440,7 @@ const RA = [
6354
6440
  onelineClauses: [...nT, ...uE],
6355
6441
  tabularOnelineClauses: uE
6356
6442
  }
6357
- }, pA = [
6443
+ }, dA = [
6358
6444
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
6359
6445
  // math
6360
6446
  "ABS",
@@ -6562,7 +6648,7 @@ const RA = [
6562
6648
  "CUME_DIST",
6563
6649
  "PERCENT_RANK",
6564
6650
  "NTILE"
6565
- ], dA = [
6651
+ ], hA = [
6566
6652
  // https://cwiki.apache.org/confluence/display/hive/languagemanual+ddl
6567
6653
  // Non-reserved keywords have proscribed meanings in. HiveQL, but can still be used as table or column names
6568
6654
  "ADD",
@@ -6877,7 +6963,7 @@ const RA = [
6877
6963
  "JSONFILE",
6878
6964
  "INPUTFORMAT",
6879
6965
  "OUTPUTFORMAT"
6880
- ], hA = [
6966
+ ], fA = [
6881
6967
  // https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types
6882
6968
  "ARRAY",
6883
6969
  "BIGINT",
@@ -6898,7 +6984,7 @@ const RA = [
6898
6984
  "STRUCT",
6899
6985
  "TIMESTAMP",
6900
6986
  "VARCHAR"
6901
- ], fA = _(["SELECT [ALL | DISTINCT]"]), VA = _([
6987
+ ], VA = _(["SELECT [ALL | DISTINCT]"]), WA = _([
6902
6988
  // queries
6903
6989
  "WITH",
6904
6990
  "FROM",
@@ -6959,24 +7045,24 @@ const RA = [
6959
7045
  "STORED AS",
6960
7046
  "STORED BY",
6961
7047
  "ROW FORMAT"
6962
- ]), WA = _(["UNION [ALL | DISTINCT]"]), XA = _([
7048
+ ]), XA = _(["UNION [ALL | DISTINCT]"]), bA = _([
6963
7049
  "JOIN",
6964
7050
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
6965
7051
  "{INNER | CROSS} JOIN",
6966
7052
  // non-standard joins
6967
7053
  "LEFT SEMI JOIN"
6968
- ]), bA = _(["{ROWS | RANGE} BETWEEN"]), yA = _([]), KA = {
7054
+ ]), yA = _(["{ROWS | RANGE} BETWEEN"]), KA = _([]), $A = {
6969
7055
  name: "hive",
6970
7056
  tokenizerOptions: {
6971
- reservedSelect: fA,
6972
- reservedClauses: [...VA, ...iT, ...HE],
6973
- reservedSetOperations: WA,
6974
- reservedJoins: XA,
6975
- reservedKeywordPhrases: bA,
6976
- reservedDataTypePhrases: yA,
6977
- reservedKeywords: dA,
6978
- reservedDataTypes: hA,
6979
- 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,
6980
7066
  extraParens: ["[]"],
6981
7067
  stringTypes: ['""-bs', "''-bs"],
6982
7068
  identTypes: ["``"],
@@ -6990,14 +7076,14 @@ const RA = [
6990
7076
  };
6991
7077
  function CE(T) {
6992
7078
  return T.map((E, R) => {
6993
- const A = T[R + 1] || j;
7079
+ const A = T[R + 1] || k;
6994
7080
  if (w.SET(E) && A.text === "(")
6995
7081
  return Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME });
6996
- const e = T[R - 1] || j;
7082
+ const e = T[R - 1] || k;
6997
7083
  return w.VALUES(E) && e.text === "=" ? Object.assign(Object.assign({}, E), { type: D.RESERVED_FUNCTION_NAME }) : E;
6998
7084
  });
6999
7085
  }
7000
- const $A = [
7086
+ const gA = [
7001
7087
  // https://mariadb.com/kb/en/reserved-words/
7002
7088
  "ACCESSIBLE",
7003
7089
  "ADD",
@@ -7214,7 +7300,7 @@ const $A = [
7214
7300
  "XOR",
7215
7301
  "YEAR_MONTH",
7216
7302
  "ZEROFILL"
7217
- ], gA = [
7303
+ ], wA = [
7218
7304
  // https://mariadb.com/kb/en/data-types/
7219
7305
  "BIGINT",
7220
7306
  "BINARY",
@@ -7265,7 +7351,7 @@ const $A = [
7265
7351
  "YEAR"
7266
7352
  // 'NUMBER', // ?? In oracle mode only
7267
7353
  // 'SET' // handled as special-case in postProcess
7268
- ], wA = [
7354
+ ], JA = [
7269
7355
  // https://mariadb.com/kb/en/information-schema-sql_functions-table/
7270
7356
  "ADDDATE",
7271
7357
  "ADD_MONTHS",
@@ -7503,7 +7589,7 @@ const $A = [
7503
7589
  // CASE expression shorthands
7504
7590
  "COALESCE",
7505
7591
  "NULLIF"
7506
- ], JA = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), xA = _([
7592
+ ], xA = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), vA = _([
7507
7593
  // queries
7508
7594
  "WITH [RECURSIVE]",
7509
7595
  "FROM",
@@ -7734,12 +7820,12 @@ const $A = [
7734
7820
  "XA RECOVER",
7735
7821
  "XA ROLLBACK",
7736
7822
  "XA START"
7737
- ]), vA = _([
7823
+ ]), QA = _([
7738
7824
  "UNION [ALL | DISTINCT]",
7739
7825
  "EXCEPT [ALL | DISTINCT]",
7740
7826
  "INTERSECT [ALL | DISTINCT]",
7741
7827
  "MINUS [ALL | DISTINCT]"
7742
- ]), QA = _([
7828
+ ]), ZA = _([
7743
7829
  "JOIN",
7744
7830
  "{LEFT | RIGHT} [OUTER] JOIN",
7745
7831
  "{INNER | CROSS} JOIN",
@@ -7747,24 +7833,24 @@ const $A = [
7747
7833
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
7748
7834
  // non-standard joins
7749
7835
  "STRAIGHT_JOIN"
7750
- ]), ZA = _([
7836
+ ]), qA = _([
7751
7837
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
7752
7838
  "CHARACTER SET",
7753
7839
  "{ROWS | RANGE} BETWEEN",
7754
7840
  "IDENTIFIED BY"
7755
- ]), qA = _([]), jA = {
7841
+ ]), jA = _([]), kA = {
7756
7842
  name: "mariadb",
7757
7843
  tokenizerOptions: {
7758
- reservedSelect: JA,
7759
- reservedClauses: [...xA, ...DT, ...BE],
7760
- reservedSetOperations: vA,
7761
- reservedJoins: QA,
7762
- reservedKeywordPhrases: ZA,
7763
- reservedDataTypePhrases: qA,
7844
+ reservedSelect: xA,
7845
+ reservedClauses: [...vA, ...DT, ...BE],
7846
+ reservedSetOperations: QA,
7847
+ reservedJoins: ZA,
7848
+ reservedKeywordPhrases: qA,
7849
+ reservedDataTypePhrases: jA,
7764
7850
  supportsXor: !0,
7765
- reservedKeywords: $A,
7766
- reservedDataTypes: gA,
7767
- reservedFunctionNames: wA,
7851
+ reservedKeywords: gA,
7852
+ reservedDataTypes: wA,
7853
+ reservedFunctionNames: JA,
7768
7854
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
7769
7855
  stringTypes: [
7770
7856
  '""-qq-bs',
@@ -7803,7 +7889,7 @@ const $A = [
7803
7889
  onelineClauses: [...DT, ...BE],
7804
7890
  tabularOnelineClauses: BE
7805
7891
  }
7806
- }, kA = [
7892
+ }, zA = [
7807
7893
  // https://dev.mysql.com/doc/refman/8.0/en/keywords.html
7808
7894
  "ACCESSIBLE",
7809
7895
  "ADD",
@@ -8034,7 +8120,7 @@ const $A = [
8034
8120
  "YEAR_MONTH",
8035
8121
  "ZEROFILL"
8036
8122
  // (R)
8037
- ], zA = [
8123
+ ], Ee = [
8038
8124
  // https://dev.mysql.com/doc/refman/8.0/en/data-types.html
8039
8125
  "BIGINT",
8040
8126
  "BINARY",
@@ -8086,7 +8172,7 @@ const $A = [
8086
8172
  "VARYING",
8087
8173
  "YEAR"
8088
8174
  // 'SET' // handled as special-case in postProcess
8089
- ], Ee = [
8175
+ ], Te = [
8090
8176
  // https://dev.mysql.com/doc/refman/8.0/en/built-in-function-reference.html
8091
8177
  "ABS",
8092
8178
  "ACOS",
@@ -8509,7 +8595,7 @@ const $A = [
8509
8595
  // 'XOR',
8510
8596
  "YEAR",
8511
8597
  "YEARWEEK"
8512
- ], Te = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Re = _([
8598
+ ], Re = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Ae = _([
8513
8599
  // queries
8514
8600
  "WITH [RECURSIVE]",
8515
8601
  "FROM",
@@ -8710,7 +8796,7 @@ const $A = [
8710
8796
  "REPEAT",
8711
8797
  "RETURN",
8712
8798
  "WHILE"
8713
- ]), Ae = _(["UNION [ALL | DISTINCT]"]), ee = _([
8799
+ ]), ee = _(["UNION [ALL | DISTINCT]"]), Se = _([
8714
8800
  "JOIN",
8715
8801
  "{LEFT | RIGHT} [OUTER] JOIN",
8716
8802
  "{INNER | CROSS} JOIN",
@@ -8718,24 +8804,24 @@ const $A = [
8718
8804
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
8719
8805
  // non-standard joins
8720
8806
  "STRAIGHT_JOIN"
8721
- ]), Se = _([
8807
+ ]), Ie = _([
8722
8808
  "ON {UPDATE | DELETE} [SET NULL]",
8723
8809
  "CHARACTER SET",
8724
8810
  "{ROWS | RANGE} BETWEEN",
8725
8811
  "IDENTIFIED BY"
8726
- ]), Ie = _([]), Oe = {
8812
+ ]), Oe = _([]), Ne = {
8727
8813
  name: "mysql",
8728
8814
  tokenizerOptions: {
8729
- reservedSelect: Te,
8730
- reservedClauses: [...Re, ...aT, ...mE],
8731
- reservedSetOperations: Ae,
8732
- reservedJoins: ee,
8733
- reservedKeywordPhrases: Se,
8734
- reservedDataTypePhrases: Ie,
8815
+ reservedSelect: Re,
8816
+ reservedClauses: [...Ae, ...aT, ...mE],
8817
+ reservedSetOperations: ee,
8818
+ reservedJoins: Se,
8819
+ reservedKeywordPhrases: Ie,
8820
+ reservedDataTypePhrases: Oe,
8735
8821
  supportsXor: !0,
8736
- reservedKeywords: kA,
8737
- reservedDataTypes: zA,
8738
- reservedFunctionNames: Ee,
8822
+ reservedKeywords: zA,
8823
+ reservedDataTypes: Ee,
8824
+ reservedFunctionNames: Te,
8739
8825
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
8740
8826
  stringTypes: [
8741
8827
  '""-qq-bs',
@@ -8776,7 +8862,7 @@ const $A = [
8776
8862
  onelineClauses: [...aT, ...mE],
8777
8863
  tabularOnelineClauses: mE
8778
8864
  }
8779
- }, Ne = [
8865
+ }, se = [
8780
8866
  // https://docs.pingcap.com/tidb/stable/keywords
8781
8867
  "ADD",
8782
8868
  "ALL",
@@ -8968,7 +9054,7 @@ const $A = [
8968
9054
  "YEAR_MONTH",
8969
9055
  "ZEROFILL"
8970
9056
  // (R)
8971
- ], se = [
9057
+ ], te = [
8972
9058
  // https://docs.pingcap.com/tidb/stable/data-type-overview
8973
9059
  "BIGINT",
8974
9060
  "BINARY",
@@ -9015,7 +9101,7 @@ const $A = [
9015
9101
  "VARYING",
9016
9102
  "YEAR"
9017
9103
  // 'SET' // handled as special-case in postProcess
9018
- ], te = [
9104
+ ], Ce = [
9019
9105
  // https://docs.pingcap.com/tidb/stable/sql-statement-show-builtins
9020
9106
  // https://docs.pingcap.com/tidb/stable/functions-and-operators-overview
9021
9107
  // + MySQL aggregate functions: https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html
@@ -9341,7 +9427,7 @@ const $A = [
9341
9427
  // 'XOR',
9342
9428
  "YEAR",
9343
9429
  "YEARWEEK"
9344
- ], Ce = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), Le = _([
9430
+ ], Le = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), _e = _([
9345
9431
  // queries
9346
9432
  "WITH [RECURSIVE]",
9347
9433
  "FROM",
@@ -9476,7 +9562,7 @@ const $A = [
9476
9562
  "UNLOCK TABLES",
9477
9563
  // https://docs.pingcap.com/tidb/stable/sql-statement-use
9478
9564
  "USE"
9479
- ]), _e = _(["UNION [ALL | DISTINCT]"]), re = _([
9565
+ ]), re = _(["UNION [ALL | DISTINCT]"]), ne = _([
9480
9566
  "JOIN",
9481
9567
  "{LEFT | RIGHT} [OUTER] JOIN",
9482
9568
  "{INNER | CROSS} JOIN",
@@ -9484,24 +9570,24 @@ const $A = [
9484
9570
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
9485
9571
  // non-standard joins
9486
9572
  "STRAIGHT_JOIN"
9487
- ]), ne = _([
9573
+ ]), ie = _([
9488
9574
  "ON {UPDATE | DELETE} [SET NULL]",
9489
9575
  "CHARACTER SET",
9490
9576
  "{ROWS | RANGE} BETWEEN",
9491
9577
  "IDENTIFIED BY"
9492
- ]), ie = _([]), De = {
9578
+ ]), De = _([]), ae = {
9493
9579
  name: "tidb",
9494
9580
  tokenizerOptions: {
9495
- reservedSelect: Ce,
9496
- reservedClauses: [...Le, ...oT, ...FE],
9497
- reservedSetOperations: _e,
9498
- reservedJoins: re,
9499
- reservedKeywordPhrases: ne,
9500
- reservedDataTypePhrases: ie,
9581
+ reservedSelect: Le,
9582
+ reservedClauses: [..._e, ...oT, ...FE],
9583
+ reservedSetOperations: re,
9584
+ reservedJoins: ne,
9585
+ reservedKeywordPhrases: ie,
9586
+ reservedDataTypePhrases: De,
9501
9587
  supportsXor: !0,
9502
- reservedKeywords: Ne,
9503
- reservedDataTypes: se,
9504
- reservedFunctionNames: te,
9588
+ reservedKeywords: se,
9589
+ reservedDataTypes: te,
9590
+ reservedFunctionNames: Ce,
9505
9591
  // TODO: support _ char set prefixes such as _utf8, _latin1, _binary, _utf8mb4, etc.
9506
9592
  stringTypes: [
9507
9593
  '""-qq-bs',
@@ -9542,7 +9628,7 @@ const $A = [
9542
9628
  onelineClauses: [...oT, ...FE],
9543
9629
  tabularOnelineClauses: FE
9544
9630
  }
9545
- }, ae = [
9631
+ }, oe = [
9546
9632
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/functions.html
9547
9633
  "ABORT",
9548
9634
  "ABS",
@@ -9772,7 +9858,7 @@ const $A = [
9772
9858
  // not implemented in N1QL, but added here now for the sake of tests
9773
9859
  // https://docs.couchbase.com/server/current/analytics/3_query.html#Vs_SQL-92
9774
9860
  "CAST"
9775
- ], oe = [
9861
+ ], Pe = [
9776
9862
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/reservedwords.html
9777
9863
  "ADVISE",
9778
9864
  "ALL",
@@ -9978,7 +10064,7 @@ const $A = [
9978
10064
  "WITHIN",
9979
10065
  "WORK",
9980
10066
  "XOR"
9981
- ], Pe = [
10067
+ ], Me = [
9982
10068
  // N1QL does not support any way of declaring types for columns.
9983
10069
  // It does not support the CREATE TABLE statement nor the CAST() expression.
9984
10070
  //
@@ -9987,7 +10073,7 @@ const $A = [
9987
10073
  // which it actually doesn't use.
9988
10074
  //
9989
10075
  // https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/datatypes.html
9990
- ], Me = _(["SELECT [ALL | DISTINCT]"]), Ue = _([
10076
+ ], Ue = _(["SELECT [ALL | DISTINCT]"]), Ge = _([
9991
10077
  // queries
9992
10078
  "WITH",
9993
10079
  "FROM",
@@ -10054,19 +10140,19 @@ const $A = [
10054
10140
  "SET CURRENT SCHEMA",
10055
10141
  "SHOW",
10056
10142
  "USE [PRIMARY] KEYS"
10057
- ]), 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 = {
10058
10144
  name: "n1ql",
10059
10145
  tokenizerOptions: {
10060
- reservedSelect: Me,
10061
- reservedClauses: [...Ue, ...PT],
10062
- reservedSetOperations: Ge,
10063
- reservedJoins: le,
10064
- reservedKeywordPhrases: ce,
10065
- reservedDataTypePhrases: ue,
10146
+ reservedSelect: Ue,
10147
+ reservedClauses: [...Ge, ...PT],
10148
+ reservedSetOperations: le,
10149
+ reservedJoins: ce,
10150
+ reservedKeywordPhrases: ue,
10151
+ reservedDataTypePhrases: He,
10066
10152
  supportsXor: !0,
10067
- reservedKeywords: oe,
10068
- reservedDataTypes: Pe,
10069
- reservedFunctionNames: ae,
10153
+ reservedKeywords: Pe,
10154
+ reservedDataTypes: Me,
10155
+ reservedFunctionNames: oe,
10070
10156
  // NOTE: single quotes are actually not supported in N1QL,
10071
10157
  // but we support them anyway as all other SQL dialects do,
10072
10158
  // which simplifies writing tests that are shared between all dialects.
@@ -10080,7 +10166,7 @@ const $A = [
10080
10166
  formatOptions: {
10081
10167
  onelineClauses: PT
10082
10168
  }
10083
- }, Be = [
10169
+ }, me = [
10084
10170
  // https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/reservewords.htm
10085
10171
  // 'A',
10086
10172
  "ADD",
@@ -10385,7 +10471,7 @@ const $A = [
10385
10471
  "WRITE",
10386
10472
  "YEAR",
10387
10473
  "ZONE"
10388
- ], me = [
10474
+ ], Fe = [
10389
10475
  // https://www.ibm.com/docs/en/db2/10.5?topic=plsql-data-types
10390
10476
  "ARRAY",
10391
10477
  "BFILE_BASE",
@@ -10423,7 +10509,7 @@ const $A = [
10423
10509
  "UROWID",
10424
10510
  "VARCHAR",
10425
10511
  "VARCHAR2"
10426
- ], Fe = [
10512
+ ], Ye = [
10427
10513
  // https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm
10428
10514
  // numeric
10429
10515
  "ABS",
@@ -10688,7 +10774,7 @@ const $A = [
10688
10774
  "PRESENTNNV",
10689
10775
  "PRESENTV",
10690
10776
  "PREVIOUS"
10691
- ], Ye = _(["SELECT [ALL | DISTINCT | UNIQUE]"]), pe = _([
10777
+ ], pe = _(["SELECT [ALL | DISTINCT | UNIQUE]"]), de = _([
10692
10778
  // queries
10693
10779
  "WITH",
10694
10780
  "FROM",
@@ -10742,7 +10828,7 @@ const $A = [
10742
10828
  "EXCEPTION",
10743
10829
  "LOOP",
10744
10830
  "START WITH"
10745
- ]), de = _(["UNION [ALL]", "MINUS", "INTERSECT"]), he = _([
10831
+ ]), he = _(["UNION [ALL]", "MINUS", "INTERSECT"]), fe = _([
10746
10832
  "JOIN",
10747
10833
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
10748
10834
  "{INNER | CROSS} JOIN",
@@ -10750,23 +10836,23 @@ const $A = [
10750
10836
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN",
10751
10837
  // non-standard joins
10752
10838
  "{CROSS | OUTER} APPLY"
10753
- ]), fe = _([
10839
+ ]), Ve = _([
10754
10840
  "ON {UPDATE | DELETE} [SET NULL]",
10755
10841
  "ON COMMIT",
10756
10842
  "{ROWS | RANGE} BETWEEN"
10757
- ]), Ve = _([]), We = {
10843
+ ]), We = _([]), Xe = {
10758
10844
  name: "plsql",
10759
10845
  tokenizerOptions: {
10760
- reservedSelect: Ye,
10761
- reservedClauses: [...pe, ...MT, ...YE],
10762
- reservedSetOperations: de,
10763
- reservedJoins: he,
10764
- reservedKeywordPhrases: fe,
10765
- reservedDataTypePhrases: Ve,
10846
+ reservedSelect: pe,
10847
+ reservedClauses: [...de, ...MT, ...YE],
10848
+ reservedSetOperations: he,
10849
+ reservedJoins: fe,
10850
+ reservedKeywordPhrases: Ve,
10851
+ reservedDataTypePhrases: We,
10766
10852
  supportsXor: !0,
10767
- reservedKeywords: Be,
10768
- reservedDataTypes: me,
10769
- reservedFunctionNames: Fe,
10853
+ reservedKeywords: me,
10854
+ reservedDataTypes: Fe,
10855
+ reservedFunctionNames: Ye,
10770
10856
  stringTypes: [
10771
10857
  { quote: "''-qq", prefixes: ["N"] },
10772
10858
  { quote: "q''", prefixes: ["N"] }
@@ -10791,7 +10877,7 @@ const $A = [
10791
10877
  "@",
10792
10878
  "||"
10793
10879
  ],
10794
- postProcess: Xe
10880
+ postProcess: be
10795
10881
  },
10796
10882
  formatOptions: {
10797
10883
  alwaysDenseOperators: ["@"],
@@ -10799,11 +10885,11 @@ const $A = [
10799
10885
  tabularOnelineClauses: YE
10800
10886
  }
10801
10887
  };
10802
- function Xe(T) {
10803
- let E = j;
10804
- 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));
10805
10891
  }
10806
- const be = [
10892
+ const ye = [
10807
10893
  // https://www.postgresql.org/docs/14/functions.html
10808
10894
  //
10809
10895
  // https://www.postgresql.org/docs/14/functions-math.html
@@ -11487,7 +11573,7 @@ const be = [
11487
11573
  "PG_MCV_LIST_ITEMS",
11488
11574
  // cast
11489
11575
  "CAST"
11490
- ], ye = [
11576
+ ], Ke = [
11491
11577
  // https://www.postgresql.org/docs/14/sql-keywords-appendix.html
11492
11578
  "ALL",
11493
11579
  "ANALYSE",
@@ -11606,7 +11692,7 @@ const be = [
11606
11692
  "WITHOUT",
11607
11693
  "YEAR"
11608
11694
  // requires AS
11609
- ], Ke = [
11695
+ ], $e = [
11610
11696
  // https://www.postgresql.org/docs/current/datatype.html
11611
11697
  "ARRAY",
11612
11698
  "BIGINT",
@@ -11640,7 +11726,7 @@ const be = [
11640
11726
  "VARCHAR",
11641
11727
  "XML",
11642
11728
  "ZONE"
11643
- ], $e = _(["SELECT [ALL | DISTINCT]"]), ge = _([
11729
+ ], ge = _(["SELECT [ALL | DISTINCT]"]), we = _([
11644
11730
  // queries
11645
11731
  "WITH [RECURSIVE]",
11646
11732
  "FROM",
@@ -11863,17 +11949,17 @@ const be = [
11863
11949
  "START TRANSACTION",
11864
11950
  "UNLISTEN",
11865
11951
  "VACUUM"
11866
- ]), we = _([
11952
+ ]), Je = _([
11867
11953
  "UNION [ALL | DISTINCT]",
11868
11954
  "EXCEPT [ALL | DISTINCT]",
11869
11955
  "INTERSECT [ALL | DISTINCT]"
11870
- ]), Je = _([
11956
+ ]), xe = _([
11871
11957
  "JOIN",
11872
11958
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
11873
11959
  "{INNER | CROSS} JOIN",
11874
11960
  "NATURAL [INNER] JOIN",
11875
11961
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
11876
- ]), xe = _([
11962
+ ]), ve = _([
11877
11963
  "PRIMARY KEY",
11878
11964
  "GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY",
11879
11965
  "ON {UPDATE | DELETE} [NO ACTION | RESTRICT | CASCADE | SET NULL | SET DEFAULT]",
@@ -11884,21 +11970,21 @@ const be = [
11884
11970
  "IS [NOT] DISTINCT FROM",
11885
11971
  "NULLS {FIRST | LAST}",
11886
11972
  "WITH ORDINALITY"
11887
- ]), ve = _([
11973
+ ]), Qe = _([
11888
11974
  // https://www.postgresql.org/docs/current/datatype-datetime.html
11889
11975
  "[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE"
11890
- ]), Qe = {
11976
+ ]), Ze = {
11891
11977
  name: "postgresql",
11892
11978
  tokenizerOptions: {
11893
- reservedSelect: $e,
11894
- reservedClauses: [...ge, ...UT, ...pE],
11895
- reservedSetOperations: we,
11896
- reservedJoins: Je,
11897
- reservedKeywordPhrases: xe,
11898
- reservedDataTypePhrases: ve,
11899
- reservedKeywords: ye,
11900
- reservedDataTypes: Ke,
11901
- 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,
11902
11988
  nestedBlockComments: !0,
11903
11989
  extraParens: ["[]"],
11904
11990
  underscoresInNumbers: !0,
@@ -12013,7 +12099,7 @@ const be = [
12013
12099
  onelineClauses: [...UT, ...pE],
12014
12100
  tabularOnelineClauses: pE
12015
12101
  }
12016
- }, Ze = [
12102
+ }, qe = [
12017
12103
  // https://docs.aws.amazon.com/redshift/latest/dg/c_Aggregate_Functions.html
12018
12104
  "ANY_VALUE",
12019
12105
  "APPROXIMATE PERCENTILE_DISC",
@@ -12359,7 +12445,7 @@ const be = [
12359
12445
  "SLICE_NUM",
12360
12446
  "USER",
12361
12447
  "VERSION"
12362
- ], qe = [
12448
+ ], je = [
12363
12449
  // https://docs.aws.amazon.com/redshift/latest/dg/r_pg_keywords.html
12364
12450
  "AES128",
12365
12451
  "AES256",
@@ -12548,7 +12634,7 @@ const be = [
12548
12634
  * SVL: https://docs.aws.amazon.com/redshift/latest/dg/svl_views.html
12549
12635
  * SVV: https://docs.aws.amazon.com/redshift/latest/dg/svv_views.html
12550
12636
  */
12551
- ], je = [
12637
+ ], ke = [
12552
12638
  // https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-text-and-bpchar-types
12553
12639
  "ARRAY",
12554
12640
  "BIGINT",
@@ -12569,7 +12655,7 @@ const be = [
12569
12655
  "TEXT",
12570
12656
  "VARBYTE",
12571
12657
  "VARCHAR"
12572
- ], ke = _(["SELECT [ALL | DISTINCT]"]), ze = _([
12658
+ ], ze = _(["SELECT [ALL | DISTINCT]"]), ES = _([
12573
12659
  // queries
12574
12660
  "WITH [RECURSIVE]",
12575
12661
  "FROM",
@@ -12680,13 +12766,13 @@ const be = [
12680
12766
  "START TRANSACTION",
12681
12767
  "UNLOAD",
12682
12768
  "VACUUM"
12683
- ]), ES = _(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), TS = _([
12769
+ ]), TS = _(["UNION [ALL]", "EXCEPT", "INTERSECT", "MINUS"]), RS = _([
12684
12770
  "JOIN",
12685
12771
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
12686
12772
  "{INNER | CROSS} JOIN",
12687
12773
  "NATURAL [INNER] JOIN",
12688
12774
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
12689
- ]), RS = _([
12775
+ ]), AS = _([
12690
12776
  // https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html
12691
12777
  "NULL AS",
12692
12778
  // https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_SCHEMA.html
@@ -12694,18 +12780,18 @@ const be = [
12694
12780
  "HIVE METASTORE",
12695
12781
  // in window specifications
12696
12782
  "{ROWS | RANGE} BETWEEN"
12697
- ]), AS = _([]), eS = {
12783
+ ]), eS = _([]), SS = {
12698
12784
  name: "redshift",
12699
12785
  tokenizerOptions: {
12700
- reservedSelect: ke,
12701
- reservedClauses: [...ze, ...GT, ...dE],
12702
- reservedSetOperations: ES,
12703
- reservedJoins: TS,
12704
- reservedKeywordPhrases: RS,
12705
- reservedDataTypePhrases: AS,
12706
- reservedKeywords: qe,
12707
- reservedDataTypes: je,
12708
- 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,
12709
12795
  extraParens: ["[]"],
12710
12796
  stringTypes: ["''-qq"],
12711
12797
  identTypes: ['""-qq'],
@@ -12732,7 +12818,7 @@ const be = [
12732
12818
  onelineClauses: [...GT, ...dE],
12733
12819
  tabularOnelineClauses: dE
12734
12820
  }
12735
- }, SS = [
12821
+ }, IS = [
12736
12822
  // https://deepkb.com/CO_000013/en/kb/IMPORT-fbfa59f0-2bf1-31fe-bb7b-0f9efe9932c6/spark-sql-keywords
12737
12823
  "ADD",
12738
12824
  "AFTER",
@@ -12999,7 +13085,7 @@ const be = [
12999
13085
  "UNSIGNED",
13000
13086
  "VARIABLES",
13001
13087
  "YEAR_MONTH"
13002
- ], IS = [
13088
+ ], OS = [
13003
13089
  // https://spark.apache.org/docs/latest/sql-ref-datatypes.html
13004
13090
  "ARRAY",
13005
13091
  "BIGINT",
@@ -13029,7 +13115,7 @@ const be = [
13029
13115
  "TINYINT",
13030
13116
  "VARCHAR"
13031
13117
  // No varchar type in Spark, only STRING. Added for the sake of tests
13032
- ], OS = [
13118
+ ], NS = [
13033
13119
  // http://spark.apache.org/docs/latest/sql-ref-functions.html
13034
13120
  //
13035
13121
  // http://spark.apache.org/docs/latest/sql-ref-functions-builtin.html#aggregate-functions
@@ -13350,7 +13436,7 @@ const be = [
13350
13436
  // Shorthand functions to use in place of CASE expression
13351
13437
  "COALESCE",
13352
13438
  "NULLIF"
13353
- ], NS = _(["SELECT [ALL | DISTINCT]"]), sS = _([
13439
+ ], sS = _(["SELECT [ALL | DISTINCT]"]), tS = _([
13354
13440
  // queries
13355
13441
  "WITH",
13356
13442
  "FROM",
@@ -13431,11 +13517,11 @@ const be = [
13431
13517
  "SHOW TBLPROPERTIES",
13432
13518
  "SHOW VIEWS",
13433
13519
  "UNCACHE TABLE"
13434
- ]), tS = _([
13520
+ ]), CS = _([
13435
13521
  "UNION [ALL | DISTINCT]",
13436
13522
  "EXCEPT [ALL | DISTINCT]",
13437
13523
  "INTERSECT [ALL | DISTINCT]"
13438
- ]), CS = _([
13524
+ ]), LS = _([
13439
13525
  "JOIN",
13440
13526
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13441
13527
  "{INNER | CROSS} JOIN",
@@ -13444,24 +13530,24 @@ const be = [
13444
13530
  // non-standard-joins
13445
13531
  "[LEFT] {ANTI | SEMI} JOIN",
13446
13532
  "NATURAL [LEFT] {ANTI | SEMI} JOIN"
13447
- ]), LS = _([
13533
+ ]), _S = _([
13448
13534
  "ON DELETE",
13449
13535
  "ON UPDATE",
13450
13536
  "CURRENT ROW",
13451
13537
  "{ROWS | RANGE} BETWEEN"
13452
- ]), _S = _([]), rS = {
13538
+ ]), rS = _([]), nS = {
13453
13539
  name: "spark",
13454
13540
  tokenizerOptions: {
13455
- reservedSelect: NS,
13456
- reservedClauses: [...sS, ...lT, ...hE],
13457
- reservedSetOperations: tS,
13458
- reservedJoins: CS,
13459
- reservedKeywordPhrases: LS,
13460
- reservedDataTypePhrases: _S,
13541
+ reservedSelect: sS,
13542
+ reservedClauses: [...tS, ...lT, ...hE],
13543
+ reservedSetOperations: CS,
13544
+ reservedJoins: LS,
13545
+ reservedKeywordPhrases: _S,
13546
+ reservedDataTypePhrases: rS,
13461
13547
  supportsXor: !0,
13462
- reservedKeywords: SS,
13463
- reservedDataTypes: IS,
13464
- reservedFunctionNames: OS,
13548
+ reservedKeywords: IS,
13549
+ reservedDataTypes: OS,
13550
+ reservedFunctionNames: NS,
13465
13551
  extraParens: ["[]"],
13466
13552
  stringTypes: [
13467
13553
  "''-bs",
@@ -13473,20 +13559,20 @@ const be = [
13473
13559
  identChars: { allowFirstCharNumber: !0 },
13474
13560
  variableTypes: [{ quote: "{}", prefixes: ["$"], requirePrefix: !0 }],
13475
13561
  operators: ["%", "~", "^", "|", "&", "<=>", "==", "!", "||", "->"],
13476
- postProcess: nS
13562
+ postProcess: iS
13477
13563
  },
13478
13564
  formatOptions: {
13479
13565
  onelineClauses: [...lT, ...hE],
13480
13566
  tabularOnelineClauses: hE
13481
13567
  }
13482
13568
  };
13483
- function nS(T) {
13569
+ function iS(T) {
13484
13570
  return T.map((E, R) => {
13485
- const A = T[R - 1] || j, e = T[R + 1] || j;
13571
+ const A = T[R - 1] || k, e = T[R + 1] || k;
13486
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;
13487
13573
  });
13488
13574
  }
13489
- const iS = [
13575
+ const DS = [
13490
13576
  // https://www.sqlite.org/lang_corefunc.html
13491
13577
  "ABS",
13492
13578
  "CHANGES",
@@ -13610,7 +13696,7 @@ const iS = [
13610
13696
  "JSON_TREE",
13611
13697
  // cast
13612
13698
  "CAST"
13613
- ], DS = [
13699
+ ], aS = [
13614
13700
  // https://www.sqlite.org/lang_keywords.html
13615
13701
  // Note: The keywords listed on that URL are not all reserved keywords.
13616
13702
  // We'll need to clean up this list to only include reserved keywords.
@@ -13763,7 +13849,7 @@ const iS = [
13763
13849
  "WINDOW",
13764
13850
  "WITH",
13765
13851
  "WITHOUT"
13766
- ], aS = [
13852
+ ], oS = [
13767
13853
  // SQLite allows any word as a data type, e.g. CREATE TABLE foo (col1 madeupname(123));
13768
13854
  // Here we just list some common ones as SQL Formatter
13769
13855
  // is only able to detect a predefined list of data types.
@@ -13784,7 +13870,7 @@ const iS = [
13784
13870
  "TEXT",
13785
13871
  "VARCHAR",
13786
13872
  "VARYING CHARACTER"
13787
- ], oS = _(["SELECT [ALL | DISTINCT]"]), PS = _([
13873
+ ], PS = _(["SELECT [ALL | DISTINCT]"]), MS = _([
13788
13874
  // queries
13789
13875
  "WITH [RECURSIVE]",
13790
13876
  "FROM",
@@ -13824,28 +13910,28 @@ const iS = [
13824
13910
  "RENAME TO",
13825
13911
  // - set schema
13826
13912
  "SET SCHEMA"
13827
- ]), MS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), US = _([
13913
+ ]), US = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), GS = _([
13828
13914
  "JOIN",
13829
13915
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
13830
13916
  "{INNER | CROSS} JOIN",
13831
13917
  "NATURAL [INNER] JOIN",
13832
13918
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
13833
- ]), GS = _([
13919
+ ]), lS = _([
13834
13920
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
13835
13921
  "{ROWS | RANGE | GROUPS} BETWEEN",
13836
13922
  "DO UPDATE"
13837
- ]), lS = _([]), cS = {
13923
+ ]), cS = _([]), uS = {
13838
13924
  name: "sqlite",
13839
13925
  tokenizerOptions: {
13840
- reservedSelect: oS,
13841
- reservedClauses: [...PS, ...cT, ...fE],
13842
- reservedSetOperations: MS,
13843
- reservedJoins: US,
13844
- reservedKeywordPhrases: GS,
13845
- reservedDataTypePhrases: lS,
13846
- reservedKeywords: DS,
13847
- reservedDataTypes: aS,
13848
- 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,
13849
13935
  stringTypes: [
13850
13936
  "''-qq",
13851
13937
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -13861,7 +13947,7 @@ const iS = [
13861
13947
  onelineClauses: [...cT, ...fE],
13862
13948
  tabularOnelineClauses: fE
13863
13949
  }
13864
- }, uS = [
13950
+ }, HS = [
13865
13951
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_9_set_function_specification
13866
13952
  "GROUPING",
13867
13953
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_10_window_function
@@ -13958,7 +14044,7 @@ const iS = [
13958
14044
  "ASIN",
13959
14045
  "ACOS",
13960
14046
  "ATAN"
13961
- ], HS = [
14047
+ ], BS = [
13962
14048
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#reserved-word
13963
14049
  "ALL",
13964
14050
  "ALLOCATE",
@@ -14156,7 +14242,7 @@ const iS = [
14156
14242
  "WITHIN",
14157
14243
  "WITHOUT",
14158
14244
  "YEAR"
14159
- ], BS = [
14245
+ ], mS = [
14160
14246
  // https://jakewheat.github.io/sql-overview/sql-2008-foundation-grammar.html#_6_1_data_type
14161
14247
  "ARRAY",
14162
14248
  "BIGINT",
@@ -14196,7 +14282,7 @@ const iS = [
14196
14282
  "TIMESTAMP",
14197
14283
  "VARBINARY",
14198
14284
  "VARCHAR"
14199
- ], mS = _(["SELECT [ALL | DISTINCT]"]), FS = _([
14285
+ ], FS = _(["SELECT [ALL | DISTINCT]"]), YS = _([
14200
14286
  // queries
14201
14287
  "WITH [RECURSIVE]",
14202
14288
  "FROM",
@@ -14240,31 +14326,31 @@ const iS = [
14240
14326
  "TRUNCATE TABLE",
14241
14327
  // other
14242
14328
  "SET SCHEMA"
14243
- ]), YS = _([
14329
+ ]), pS = _([
14244
14330
  "UNION [ALL | DISTINCT]",
14245
14331
  "EXCEPT [ALL | DISTINCT]",
14246
14332
  "INTERSECT [ALL | DISTINCT]"
14247
- ]), pS = _([
14333
+ ]), dS = _([
14248
14334
  "JOIN",
14249
14335
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
14250
14336
  "{INNER | CROSS} JOIN",
14251
14337
  "NATURAL [INNER] JOIN",
14252
14338
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
14253
- ]), dS = _([
14339
+ ]), hS = _([
14254
14340
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
14255
14341
  "{ROWS | RANGE} BETWEEN"
14256
- ]), hS = _([]), fS = {
14342
+ ]), fS = _([]), VS = {
14257
14343
  name: "sql",
14258
14344
  tokenizerOptions: {
14259
- reservedSelect: mS,
14260
- reservedClauses: [...FS, ...uT, ...VE],
14261
- reservedSetOperations: YS,
14262
- reservedJoins: pS,
14263
- reservedKeywordPhrases: dS,
14264
- reservedDataTypePhrases: hS,
14265
- reservedKeywords: HS,
14266
- reservedDataTypes: BS,
14267
- 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,
14268
14354
  stringTypes: [
14269
14355
  { quote: "''-qq-bs", prefixes: ["N", "U&"] },
14270
14356
  { quote: "''-raw", prefixes: ["X"], requirePrefix: !0 }
@@ -14277,7 +14363,7 @@ const iS = [
14277
14363
  onelineClauses: [...uT, ...VE],
14278
14364
  tabularOnelineClauses: VE
14279
14365
  }
14280
- }, VS = [
14366
+ }, WS = [
14281
14367
  // https://github.com/trinodb/trino/tree/432d2897bdef99388c1a47188743a061c4ac1f34/docs/src/main/sphinx/functions
14282
14368
  // rg '^\.\. function::' ./docs/src/main/sphinx/functions | cut -d' ' -f 3 | cut -d '(' -f 1 | sort | uniq
14283
14369
  // rg '\* ' ./docs/src/main/sphinx/functions/list-by-topic.rst | grep '\* :func:' | cut -d'`' -f 2
@@ -14711,7 +14797,7 @@ const iS = [
14711
14797
  "NEXT",
14712
14798
  "PERMUTE",
14713
14799
  "PREV"
14714
- ], WS = [
14800
+ ], XS = [
14715
14801
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-parser/src/main/antlr4/io/trino/sql/parser/SqlBase.g4#L858-L1128
14716
14802
  "ABSENT",
14717
14803
  "ADD",
@@ -14948,7 +15034,7 @@ const iS = [
14948
15034
  "WRAPPER",
14949
15035
  "WRITE",
14950
15036
  "ZONE"
14951
- ], XS = [
15037
+ ], bS = [
14952
15038
  // https://github.com/trinodb/trino/blob/432d2897bdef99388c1a47188743a061c4ac1f34/core/trino-main/src/main/java/io/trino/metadata/TypeRegistry.java#L131-L168
14953
15039
  // or https://trino.io/docs/current/language/types.html
14954
15040
  "BIGINT",
@@ -14987,7 +15073,7 @@ const iS = [
14987
15073
  "CODEPOINTS",
14988
15074
  "FUNCTION",
14989
15075
  "JSONPATH"
14990
- ], bS = _(["SELECT [ALL | DISTINCT]"]), yS = _([
15076
+ ], yS = _(["SELECT [ALL | DISTINCT]"]), KS = _([
14991
15077
  // queries
14992
15078
  "WITH [RECURSIVE]",
14993
15079
  "FROM",
@@ -15073,32 +15159,32 @@ const iS = [
15073
15159
  "SHOW ROLE GRANTS",
15074
15160
  "SHOW FUNCTIONS",
15075
15161
  "SHOW SESSION"
15076
- ]), KS = _([
15162
+ ]), $S = _([
15077
15163
  "UNION [ALL | DISTINCT]",
15078
15164
  "EXCEPT [ALL | DISTINCT]",
15079
15165
  "INTERSECT [ALL | DISTINCT]"
15080
- ]), $S = _([
15166
+ ]), gS = _([
15081
15167
  "JOIN",
15082
15168
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15083
15169
  "{INNER | CROSS} JOIN",
15084
15170
  "NATURAL [INNER] JOIN",
15085
15171
  "NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN"
15086
- ]), gS = _([
15172
+ ]), wS = _([
15087
15173
  "{ROWS | RANGE | GROUPS} BETWEEN",
15088
15174
  // comparison operator
15089
15175
  "IS [NOT] DISTINCT FROM"
15090
- ]), wS = _([]), JS = {
15176
+ ]), JS = _([]), xS = {
15091
15177
  name: "trino",
15092
15178
  tokenizerOptions: {
15093
- reservedSelect: bS,
15094
- reservedClauses: [...yS, ...HT, ...WE],
15095
- reservedSetOperations: KS,
15096
- reservedJoins: $S,
15097
- reservedKeywordPhrases: gS,
15098
- reservedDataTypePhrases: wS,
15099
- reservedKeywords: WS,
15100
- reservedDataTypes: XS,
15101
- 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,
15102
15188
  // Trino also supports {- ... -} parenthesis.
15103
15189
  // The formatting of these currently works out as a result of { and -
15104
15190
  // not getting a space added in-between.
@@ -15130,7 +15216,7 @@ const iS = [
15130
15216
  onelineClauses: [...HT, ...WE],
15131
15217
  tabularOnelineClauses: WE
15132
15218
  }
15133
- }, xS = [
15219
+ }, vS = [
15134
15220
  // https://docs.microsoft.com/en-us/sql/t-sql/functions/functions?view=sql-server-ver15
15135
15221
  // aggregate
15136
15222
  "APPROX_COUNT_DISTINCT",
@@ -15435,7 +15521,7 @@ const iS = [
15435
15521
  // Shorthand functions to use in place of CASE expression
15436
15522
  "COALESCE",
15437
15523
  "NULLIF"
15438
- ], vS = [
15524
+ ], QS = [
15439
15525
  // https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-server-ver15
15440
15526
  // standard
15441
15527
  "ADD",
@@ -15616,7 +15702,7 @@ const iS = [
15616
15702
  "WRITETEXT",
15617
15703
  // https://learn.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql?view=sql-server-ver16#action
15618
15704
  "$ACTION"
15619
- ], QS = [
15705
+ ], ZS = [
15620
15706
  // https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver15
15621
15707
  "BINARY",
15622
15708
  "BIT",
@@ -15643,7 +15729,7 @@ const iS = [
15643
15729
  "TIMESTAMP",
15644
15730
  "VARBINARY",
15645
15731
  "VARCHAR"
15646
- ], ZS = _(["SELECT [ALL | DISTINCT]"]), qS = _([
15732
+ ], qS = _(["SELECT [ALL | DISTINCT]"]), jS = _([
15647
15733
  // queries
15648
15734
  "WITH",
15649
15735
  "INTO",
@@ -15848,27 +15934,27 @@ const iS = [
15848
15934
  "XACT_ABORT",
15849
15935
  "XML INDEX",
15850
15936
  "XML SCHEMA COLLECTION"
15851
- ]), jS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), kS = _([
15937
+ ]), kS = _(["UNION [ALL]", "EXCEPT", "INTERSECT"]), zS = _([
15852
15938
  "JOIN",
15853
15939
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
15854
15940
  "{INNER | CROSS} JOIN",
15855
15941
  // non-standard joins
15856
15942
  "{CROSS | OUTER} APPLY"
15857
- ]), zS = _([
15943
+ ]), EI = _([
15858
15944
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]",
15859
15945
  "{ROWS | RANGE} BETWEEN"
15860
- ]), EI = _([]), TI = {
15946
+ ]), TI = _([]), RI = {
15861
15947
  name: "transactsql",
15862
15948
  tokenizerOptions: {
15863
- reservedSelect: ZS,
15864
- reservedClauses: [...qS, ...BT, ...XE],
15865
- reservedSetOperations: jS,
15866
- reservedJoins: kS,
15867
- reservedKeywordPhrases: zS,
15868
- reservedDataTypePhrases: EI,
15869
- reservedKeywords: vS,
15870
- reservedDataTypes: QS,
15871
- 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,
15872
15958
  nestedBlockComments: !0,
15873
15959
  stringTypes: [{ quote: "''-qq", prefixes: ["N"] }, "{}"],
15874
15960
  identTypes: ['""-qq', "[]"],
@@ -15901,7 +15987,7 @@ const iS = [
15901
15987
  onelineClauses: [...BT, ...XE],
15902
15988
  tabularOnelineClauses: XE
15903
15989
  }
15904
- }, RI = [
15990
+ }, AI = [
15905
15991
  // List of all keywords taken from:
15906
15992
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/restricted-keywords/list-of-restricted-keywords.html
15907
15993
  // Then filtered down to reserved keywords by running
@@ -16114,7 +16200,7 @@ const iS = [
16114
16200
  "XOR",
16115
16201
  "YEAR_MONTH",
16116
16202
  "ZEROFILL"
16117
- ], AI = [
16203
+ ], eI = [
16118
16204
  // https://docs.singlestore.com/cloud/reference/sql-reference/data-types/
16119
16205
  "BIGINT",
16120
16206
  "BINARY",
@@ -16163,7 +16249,7 @@ const iS = [
16163
16249
  "VARCHAR",
16164
16250
  "VARCHARACTER",
16165
16251
  "YEAR"
16166
- ], eI = [
16252
+ ], SI = [
16167
16253
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions/vector-functions.html
16168
16254
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/window-functions/window-functions.html
16169
16255
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/string-functions/string-functions.html
@@ -16443,7 +16529,7 @@ const iS = [
16443
16529
  "WEEKDAY",
16444
16530
  "WEEKOFYEAR",
16445
16531
  "YEAR"
16446
- ], SI = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), II = _([
16532
+ ], II = _(["SELECT [ALL | DISTINCT | DISTINCTROW]"]), OI = _([
16447
16533
  // queries
16448
16534
  "WITH",
16449
16535
  "FROM",
@@ -16644,36 +16730,36 @@ const iS = [
16644
16730
  "REPEAT",
16645
16731
  "RETURN",
16646
16732
  "WHILE"
16647
- ]), OI = _([
16733
+ ]), NI = _([
16648
16734
  "UNION [ALL | DISTINCT]",
16649
16735
  "EXCEPT",
16650
16736
  "INTERSECT",
16651
16737
  "MINUS"
16652
- ]), NI = _([
16738
+ ]), sI = _([
16653
16739
  "JOIN",
16654
16740
  "{LEFT | RIGHT | FULL} [OUTER] JOIN",
16655
16741
  "{INNER | CROSS} JOIN",
16656
16742
  "NATURAL {LEFT | RIGHT} [OUTER] JOIN",
16657
16743
  // non-standard joins
16658
16744
  "STRAIGHT_JOIN"
16659
- ]), sI = _([
16745
+ ]), tI = _([
16660
16746
  "ON DELETE",
16661
16747
  "ON UPDATE",
16662
16748
  "CHARACTER SET",
16663
16749
  "{ROWS | RANGE} BETWEEN",
16664
16750
  "IDENTIFIED BY"
16665
- ]), tI = _([]), CI = {
16751
+ ]), CI = _([]), LI = {
16666
16752
  name: "singlestoredb",
16667
16753
  tokenizerOptions: {
16668
- reservedSelect: SI,
16669
- reservedClauses: [...II, ...mT, ...bE],
16670
- reservedSetOperations: OI,
16671
- reservedJoins: NI,
16672
- reservedKeywordPhrases: sI,
16673
- reservedDataTypePhrases: tI,
16674
- reservedKeywords: RI,
16675
- reservedDataTypes: AI,
16676
- 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,
16677
16763
  // TODO: support _binary"some string" prefix
16678
16764
  stringTypes: [
16679
16765
  '""-qq-bs',
@@ -16713,7 +16799,7 @@ const iS = [
16713
16799
  onelineClauses: [...mT, ...bE],
16714
16800
  tabularOnelineClauses: bE
16715
16801
  }
16716
- }, LI = [
16802
+ }, _I = [
16717
16803
  // https://docs.snowflake.com/en/sql-reference-functions.html
16718
16804
  //
16719
16805
  // https://docs.snowflake.com/en/sql-reference/functions-all.html
@@ -17321,7 +17407,7 @@ const iS = [
17321
17407
  "QUARTER",
17322
17408
  "ZEROIFNULL",
17323
17409
  "ZIPF"
17324
- ], _I = [
17410
+ ], rI = [
17325
17411
  // https://docs.snowflake.com/en/sql-reference/reserved-keywords.html
17326
17412
  //
17327
17413
  // run in console on this page: $x('//tbody/tr/*[1]/p/text()').map(x => x.nodeValue)
@@ -17418,7 +17504,7 @@ const iS = [
17418
17504
  "WITH",
17419
17505
  // These are definitely keywords, but haven't found a definite list in the docs
17420
17506
  "COMMENT"
17421
- ], rI = [
17507
+ ], nI = [
17422
17508
  "NUMBER",
17423
17509
  "DECIMAL",
17424
17510
  "NUMERIC",
@@ -17455,7 +17541,7 @@ const iS = [
17455
17541
  "ARRAY",
17456
17542
  "GEOGRAPHY",
17457
17543
  "GEOMETRY"
17458
- ], nI = _(["SELECT [ALL | DISTINCT]"]), iI = _([
17544
+ ], iI = _(["SELECT [ALL | DISTINCT]"]), DI = _([
17459
17545
  // queries
17460
17546
  "WITH [RECURSIVE]",
17461
17547
  "FROM",
@@ -17727,25 +17813,25 @@ const iS = [
17727
17813
  "USE SCHEMA",
17728
17814
  "USE SECONDARY ROLES",
17729
17815
  "USE WAREHOUSE"
17730
- ]), DI = _(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), aI = _([
17816
+ ]), aI = _(["UNION [ALL]", "MINUS", "EXCEPT", "INTERSECT"]), oI = _([
17731
17817
  "[INNER] JOIN",
17732
17818
  "[NATURAL] {LEFT | RIGHT | FULL} [OUTER] JOIN",
17733
17819
  "{CROSS | NATURAL} JOIN"
17734
- ]), oI = _([
17820
+ ]), PI = _([
17735
17821
  "{ROWS | RANGE} BETWEEN",
17736
17822
  "ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]"
17737
- ]), PI = _([]), MI = {
17823
+ ]), MI = _([]), UI = {
17738
17824
  name: "snowflake",
17739
17825
  tokenizerOptions: {
17740
- reservedSelect: nI,
17741
- reservedClauses: [...iI, ...FT, ...yE],
17742
- reservedSetOperations: DI,
17743
- reservedJoins: aI,
17744
- reservedKeywordPhrases: oI,
17745
- reservedDataTypePhrases: PI,
17746
- reservedKeywords: _I,
17747
- reservedDataTypes: rI,
17748
- 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,
17749
17835
  stringTypes: ["$$", "''-qq-bs"],
17750
17836
  identTypes: ['""-qq'],
17751
17837
  variableTypes: [
@@ -17778,43 +17864,43 @@ const iS = [
17778
17864
  onelineClauses: [...FT, ...yE],
17779
17865
  tabularOnelineClauses: yE
17780
17866
  }
17781
- }, UI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17867
+ }, GI = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
17782
17868
  __proto__: null,
17783
- bigquery: jR,
17784
- db2: CA,
17785
- db2i: MA,
17786
- duckdb: YA,
17787
- hive: KA,
17788
- mariadb: jA,
17789
- mysql: Oe,
17790
- n1ql: He,
17791
- plsql: We,
17792
- postgresql: Qe,
17793
- redshift: eS,
17794
- singlestoredb: CI,
17795
- snowflake: MI,
17796
- spark: rS,
17797
- sql: fS,
17798
- sqlite: cS,
17799
- tidb: De,
17800
- transactsql: TI,
17801
- trino: JS
17802
- }, 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
17803
17889
  |\r|
17804
17890
  |$)`, "uy"), pT = (T, E = []) => {
17805
17891
  const R = T === "open" ? 0 : 1, A = ["()", ...E].map((e) => e[R]);
17806
17892
  return J(A.map(X).join("|"));
17807
- }, 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 = {}) => {
17808
17894
  if (T.length === 0)
17809
17895
  return /^\b$/u;
17810
- 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+");
17811
17897
  return new RegExp(`(?:${A})${R}\\b`, "iuy");
17812
17898
  }, $E = (T, E) => {
17813
17899
  if (!T.length)
17814
17900
  return;
17815
17901
  const R = T.map(X).join("|");
17816
17902
  return J(`(?:${R})(?:${E})`);
17817
- }, BI = () => {
17903
+ }, mI = () => {
17818
17904
  const T = {
17819
17905
  "<": ">",
17820
17906
  "[": "]",
@@ -17846,16 +17932,16 @@ const iS = [
17846
17932
  // Hive and Spark variables: ${name}
17847
17933
  "{}": String.raw`(?:\{[^\}]*\})`,
17848
17934
  // Oracle q'' strings: q'<text>' q'|text|' ...
17849
- "q''": BI()
17850
- }, 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 } = {}) => {
17851
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}]*`;
17852
- return R ? lI(r) : r;
17938
+ return R ? cI(r) : r;
17853
17939
  };
17854
- function RR(T, E) {
17940
+ function AR(T, E) {
17855
17941
  const R = T.slice(0, E).split(/\n/);
17856
17942
  return { line: R.length, col: R[R.length - 1].length + 1 };
17857
17943
  }
17858
- class YI {
17944
+ class pI {
17859
17945
  constructor(E, R) {
17860
17946
  this.rules = E, this.dialectName = R, this.input = "", this.index = 0;
17861
17947
  }
@@ -17881,7 +17967,7 @@ class YI {
17881
17967
  return R;
17882
17968
  }
17883
17969
  createParseError() {
17884
- 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);
17885
17971
  return new Error(`Parse error: Unexpected "${E}" at line ${R} column ${A}.
17886
17972
  ${this.dialectInfo()}`);
17887
17973
  }
@@ -17917,8 +18003,8 @@ If possible, please select a more specific dialect (like sqlite, postgresql, etc
17917
18003
  }
17918
18004
  }
17919
18005
  }
17920
- const VT = /\/\*/uy, pI = /[\s\S]/uy, dI = /\*\//uy;
17921
- class hI {
18006
+ const VT = /\/\*/uy, dI = /[\s\S]/uy, hI = /\*\//uy;
18007
+ class fI {
17922
18008
  constructor() {
17923
18009
  this.lastIndex = 0;
17924
18010
  }
@@ -17931,9 +18017,9 @@ class hI {
17931
18017
  for (; e > 0; )
17932
18018
  if (A = this.matchSection(VT, E))
17933
18019
  R += A, e++;
17934
- else if (A = this.matchSection(dI, E))
18020
+ else if (A = this.matchSection(hI, E))
17935
18021
  R += A, e--;
17936
- else if (A = this.matchSection(pI, E))
18022
+ else if (A = this.matchSection(dI, E))
17937
18023
  R += A;
17938
18024
  else
17939
18025
  return null;
@@ -17945,7 +18031,7 @@ class hI {
17945
18031
  return A && (this.lastIndex += A[0].length), A ? A[0] : null;
17946
18032
  }
17947
18033
  }
17948
- class fI {
18034
+ class VI {
17949
18035
  constructor(E, R) {
17950
18036
  this.cfg = E, this.dialectName = R, this.rulesBeforeParams = this.buildRulesBeforeParams(E), this.rulesAfterParams = this.buildRulesAfterParams(E);
17951
18037
  }
@@ -17954,7 +18040,7 @@ class fI {
17954
18040
  ...this.rulesBeforeParams,
17955
18041
  ...this.buildParamRules(this.cfg, R),
17956
18042
  ...this.rulesAfterParams
17957
- ], e = new YI(A, this.dialectName).tokenize(E);
18043
+ ], e = new pI(A, this.dialectName).tokenize(E);
17958
18044
  return this.cfg.postProcess ? this.cfg.postProcess(e) : e;
17959
18045
  }
17960
18046
  // These rules can be cached as they only depend on
@@ -17968,11 +18054,11 @@ class fI {
17968
18054
  },
17969
18055
  {
17970
18056
  type: D.BLOCK_COMMENT,
17971
- regex: E.nestedBlockComments ? new hI() : /(\/\*[^]*?\*\/)/uy
18057
+ regex: E.nestedBlockComments ? new fI() : /(\/\*[^]*?\*\/)/uy
17972
18058
  },
17973
18059
  {
17974
18060
  type: D.LINE_COMMENT,
17975
- regex: uI((R = E.lineCommentTypes) !== null && R !== void 0 ? R : ["--"])
18061
+ regex: HI((R = E.lineCommentTypes) !== null && R !== void 0 ? R : ["--"])
17976
18062
  },
17977
18063
  {
17978
18064
  type: D.QUOTED_IDENTIFIER,
@@ -17987,82 +18073,82 @@ class fI {
17987
18073
  {
17988
18074
  type: D.RESERVED_KEYWORD_PHRASE,
17989
18075
  regex: y((A = E.reservedKeywordPhrases) !== null && A !== void 0 ? A : [], E.identChars),
17990
- text: B
18076
+ text: F
17991
18077
  },
17992
18078
  {
17993
18079
  type: D.RESERVED_DATA_TYPE_PHRASE,
17994
18080
  regex: y((e = E.reservedDataTypePhrases) !== null && e !== void 0 ? e : [], E.identChars),
17995
- text: B
18081
+ text: F
17996
18082
  },
17997
18083
  {
17998
18084
  type: D.CASE,
17999
18085
  regex: /CASE\b/iuy,
18000
- text: B
18086
+ text: F
18001
18087
  },
18002
18088
  {
18003
18089
  type: D.END,
18004
18090
  regex: /END\b/iuy,
18005
- text: B
18091
+ text: F
18006
18092
  },
18007
18093
  {
18008
18094
  type: D.BETWEEN,
18009
18095
  regex: /BETWEEN\b/iuy,
18010
- text: B
18096
+ text: F
18011
18097
  },
18012
18098
  {
18013
18099
  type: D.LIMIT,
18014
18100
  regex: E.reservedClauses.includes("LIMIT") ? /LIMIT\b/iuy : void 0,
18015
- text: B
18101
+ text: F
18016
18102
  },
18017
18103
  {
18018
18104
  type: D.RESERVED_CLAUSE,
18019
18105
  regex: y(E.reservedClauses, E.identChars),
18020
- text: B
18106
+ text: F
18021
18107
  },
18022
18108
  {
18023
18109
  type: D.RESERVED_SELECT,
18024
18110
  regex: y(E.reservedSelect, E.identChars),
18025
- text: B
18111
+ text: F
18026
18112
  },
18027
18113
  {
18028
18114
  type: D.RESERVED_SET_OPERATION,
18029
18115
  regex: y(E.reservedSetOperations, E.identChars),
18030
- text: B
18116
+ text: F
18031
18117
  },
18032
18118
  {
18033
18119
  type: D.WHEN,
18034
18120
  regex: /WHEN\b/iuy,
18035
- text: B
18121
+ text: F
18036
18122
  },
18037
18123
  {
18038
18124
  type: D.ELSE,
18039
18125
  regex: /ELSE\b/iuy,
18040
- text: B
18126
+ text: F
18041
18127
  },
18042
18128
  {
18043
18129
  type: D.THEN,
18044
18130
  regex: /THEN\b/iuy,
18045
- text: B
18131
+ text: F
18046
18132
  },
18047
18133
  {
18048
18134
  type: D.RESERVED_JOIN,
18049
18135
  regex: y(E.reservedJoins, E.identChars),
18050
- text: B
18136
+ text: F
18051
18137
  },
18052
18138
  {
18053
18139
  type: D.AND,
18054
18140
  regex: /AND\b/iuy,
18055
- text: B
18141
+ text: F
18056
18142
  },
18057
18143
  {
18058
18144
  type: D.OR,
18059
18145
  regex: /OR\b/iuy,
18060
- text: B
18146
+ text: F
18061
18147
  },
18062
18148
  {
18063
18149
  type: D.XOR,
18064
18150
  regex: E.supportsXor ? /XOR\b/iuy : void 0,
18065
- text: B
18151
+ text: F
18066
18152
  },
18067
18153
  ...E.operatorKeyword ? [
18068
18154
  {
@@ -18073,17 +18159,17 @@ class fI {
18073
18159
  {
18074
18160
  type: D.RESERVED_FUNCTION_NAME,
18075
18161
  regex: y(E.reservedFunctionNames, E.identChars),
18076
- text: B
18162
+ text: F
18077
18163
  },
18078
18164
  {
18079
18165
  type: D.RESERVED_DATA_TYPE,
18080
18166
  regex: y(E.reservedDataTypes, E.identChars),
18081
- text: B
18167
+ text: F
18082
18168
  },
18083
18169
  {
18084
18170
  type: D.RESERVED_KEYWORD,
18085
18171
  regex: y(E.reservedKeywords, E.identChars),
18086
- text: B
18172
+ text: F
18087
18173
  }
18088
18174
  ]);
18089
18175
  }
@@ -18094,12 +18180,12 @@ class fI {
18094
18180
  return this.validRules([
18095
18181
  {
18096
18182
  type: D.VARIABLE,
18097
- regex: E.variableTypes ? mI(E.variableTypes) : void 0
18183
+ regex: E.variableTypes ? FI(E.variableTypes) : void 0
18098
18184
  },
18099
18185
  { type: D.STRING, regex: fT(E.stringTypes) },
18100
18186
  {
18101
18187
  type: D.IDENTIFIER,
18102
- regex: FI(E.identChars)
18188
+ regex: YI(E.identChars)
18103
18189
  },
18104
18190
  { type: D.DELIMITER, regex: /[;]/uy },
18105
18191
  { type: D.COMMA, regex: /[,]/y },
@@ -18149,32 +18235,32 @@ class fI {
18149
18235
  return this.validRules([
18150
18236
  {
18151
18237
  type: D.NAMED_PARAMETER,
18152
- regex: $E(r.named, TR(E.paramChars || E.identChars)),
18153
- key: (I) => I.slice(1)
18238
+ regex: $E(r.named, RR(E.paramChars || E.identChars)),
18239
+ key: (O) => O.slice(1)
18154
18240
  },
18155
18241
  {
18156
18242
  type: D.QUOTED_PARAMETER,
18157
- regex: $E(r.quoted, ER(E.identTypes)),
18158
- key: (I) => (({ tokenKey: O, quoteChar: s }) => O.replace(new RegExp(X("\\" + s), "gu"), s))({
18159
- tokenKey: I.slice(2, -1),
18160
- quoteChar: I.slice(-1)
18243
+ regex: $E(r.quoted, TR(E.identTypes)),
18244
+ key: (O) => (({ tokenKey: I, quoteChar: s }) => I.replace(new RegExp(X("\\" + s), "gu"), s))({
18245
+ tokenKey: O.slice(2, -1),
18246
+ quoteChar: O.slice(-1)
18161
18247
  })
18162
18248
  },
18163
18249
  {
18164
18250
  type: D.NUMBERED_PARAMETER,
18165
18251
  regex: $E(r.numbered, "[0-9]+"),
18166
- key: (I) => I.slice(1)
18252
+ key: (O) => O.slice(1)
18167
18253
  },
18168
18254
  {
18169
18255
  type: D.POSITIONAL_PARAMETER,
18170
18256
  regex: r.positional ? /[?]/y : void 0
18171
18257
  },
18172
- ...r.custom.map((I) => {
18173
- var O;
18258
+ ...r.custom.map((O) => {
18259
+ var I;
18174
18260
  return {
18175
18261
  type: D.CUSTOM_PARAMETER,
18176
- regex: J(I.regex),
18177
- key: (O = I.key) !== null && O !== void 0 ? O : ((s) => s)
18262
+ regex: J(O.regex),
18263
+ key: (I = O.key) !== null && I !== void 0 ? I : ((s) => s)
18178
18264
  };
18179
18265
  })
18180
18266
  ]);
@@ -18184,13 +18270,13 @@ class fI {
18184
18270
  return E.filter((R) => !!R.regex);
18185
18271
  }
18186
18272
  }
18187
- const B = (T) => AE(T.toUpperCase()), WT = /* @__PURE__ */ new Map(), VI = (T) => {
18273
+ const F = (T) => eE(T.toUpperCase()), WT = /* @__PURE__ */ new Map(), WI = (T) => {
18188
18274
  let E = WT.get(T);
18189
- return E || (E = WI(T), WT.set(T, E)), E;
18190
- }, WI = (T) => ({
18191
- tokenizer: new fI(T.tokenizerOptions, T.name),
18192
- formatOptions: XI(T.formatOptions)
18193
- }), 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) => {
18194
18280
  var E;
18195
18281
  return {
18196
18282
  alwaysDenseOperators: T.alwaysDenseOperators || [],
@@ -18198,13 +18284,13 @@ const B = (T) => AE(T.toUpperCase()), WT = /* @__PURE__ */ new Map(), VI = (T) =
18198
18284
  tabularOnelineClauses: Object.fromEntries(((E = T.tabularOnelineClauses) !== null && E !== void 0 ? E : T.onelineClauses).map((R) => [R, !0]))
18199
18285
  };
18200
18286
  };
18201
- function bI(T) {
18287
+ function yI(T) {
18202
18288
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight" ? " ".repeat(10) : T.useTabs ? " " : " ".repeat(T.tabWidth);
18203
18289
  }
18204
18290
  function q(T) {
18205
18291
  return T.indentStyle === "tabularLeft" || T.indentStyle === "tabularRight";
18206
18292
  }
18207
- class yI {
18293
+ class KI {
18208
18294
  constructor(E) {
18209
18295
  this.params = E, this.index = 0;
18210
18296
  }
@@ -18227,45 +18313,45 @@ class yI {
18227
18313
  this.index = E;
18228
18314
  }
18229
18315
  }
18230
- function KI(T) {
18316
+ function $I(T) {
18231
18317
  return T && T.__esModule && Object.prototype.hasOwnProperty.call(T, "default") ? T.default : T;
18232
18318
  }
18233
- var eE = { exports: {} }, $I = eE.exports, XT;
18234
- function gI() {
18319
+ var SE = { exports: {} }, gI = SE.exports, XT;
18320
+ function wI() {
18235
18321
  return XT || (XT = 1, (function(T) {
18236
18322
  (function(E, R) {
18237
18323
  T.exports ? T.exports = R() : E.nearley = R();
18238
- })($I, function() {
18239
- function E(I, O, s) {
18240
- return this.id = ++E.highestId, this.name = I, this.symbols = O, this.postprocess = s, this;
18324
+ })(gI, function() {
18325
+ function E(O, I, s) {
18326
+ return this.id = ++E.highestId, this.name = O, this.symbols = I, this.postprocess = s, this;
18241
18327
  }
18242
- E.highestId = 0, E.prototype.toString = function(I) {
18243
- var O = typeof I > "u" ? this.symbols.map(r).join(" ") : this.symbols.slice(0, I).map(r).join(" ") + " ● " + this.symbols.slice(I).map(r).join(" ");
18244
- return this.name + " → " + O;
18328
+ E.highestId = 0, E.prototype.toString = function(O) {
18329
+ var I = typeof O > "u" ? this.symbols.map(r).join(" ") : this.symbols.slice(0, O).map(r).join(" ") + " ● " + this.symbols.slice(O).map(r).join(" ");
18330
+ return this.name + " → " + I;
18245
18331
  };
18246
- function R(I, O, s, L) {
18247
- this.rule = I, this.dot = O, this.reference = s, this.data = [], this.wantedBy = L, this.isComplete = this.dot === I.symbols.length;
18332
+ function R(O, I, s, L) {
18333
+ this.rule = O, this.dot = I, this.reference = s, this.data = [], this.wantedBy = L, this.isComplete = this.dot === O.symbols.length;
18248
18334
  }
18249
18335
  R.prototype.toString = function() {
18250
18336
  return "{" + this.rule.toString(this.dot) + "}, from: " + (this.reference || 0);
18251
- }, R.prototype.nextState = function(I) {
18252
- var O = new R(this.rule, this.dot + 1, this.reference, this.wantedBy);
18253
- return O.left = this, O.right = I, O.isComplete && (O.data = O.build(), O.right = void 0), O;
18337
+ }, R.prototype.nextState = function(O) {
18338
+ var I = new R(this.rule, this.dot + 1, this.reference, this.wantedBy);
18339
+ return I.left = this, I.right = O, I.isComplete && (I.data = I.build(), I.right = void 0), I;
18254
18340
  }, R.prototype.build = function() {
18255
- var I = [], O = this;
18341
+ var O = [], I = this;
18256
18342
  do
18257
- I.push(O.right.data), O = O.left;
18258
- while (O.left);
18259
- return I.reverse(), I;
18343
+ O.push(I.right.data), I = I.left;
18344
+ while (I.left);
18345
+ return O.reverse(), O;
18260
18346
  }, R.prototype.finish = function() {
18261
18347
  this.rule.postprocess && (this.data = this.rule.postprocess(this.data, this.reference, N.fail));
18262
18348
  };
18263
- function A(I, O) {
18264
- this.grammar = I, this.index = O, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
18349
+ function A(O, I) {
18350
+ this.grammar = O, this.index = I, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
18265
18351
  }
18266
- A.prototype.process = function(I) {
18267
- for (var O = this.states, s = this.wants, L = this.completed, a = 0; a < O.length; a++) {
18268
- var o = O[a];
18352
+ A.prototype.process = function(O) {
18353
+ for (var I = this.states, s = this.wants, L = this.completed, a = 0; a < I.length; a++) {
18354
+ var o = I[a];
18269
18355
  if (o.isComplete) {
18270
18356
  if (o.finish(), o.data !== N.fail) {
18271
18357
  for (var n = o.wantedBy, U = n.length; U--; ) {
@@ -18273,67 +18359,67 @@ function gI() {
18273
18359
  this.complete(P, o);
18274
18360
  }
18275
18361
  if (o.reference === this.index) {
18276
- var l = o.rule.name;
18277
- (this.completed[l] = this.completed[l] || []).push(o);
18362
+ var c = o.rule.name;
18363
+ (this.completed[c] = this.completed[c] || []).push(o);
18278
18364
  }
18279
18365
  }
18280
18366
  } else {
18281
- var l = o.rule.symbols[o.dot];
18282
- if (typeof l != "string") {
18367
+ var c = o.rule.symbols[o.dot];
18368
+ if (typeof c != "string") {
18283
18369
  this.scannable.push(o);
18284
18370
  continue;
18285
18371
  }
18286
- if (s[l]) {
18287
- if (s[l].push(o), L.hasOwnProperty(l))
18288
- for (var c = L[l], U = 0; U < c.length; U++) {
18289
- var m = c[U];
18290
- this.complete(o, m);
18372
+ if (s[c]) {
18373
+ if (s[c].push(o), L.hasOwnProperty(c))
18374
+ for (var l = L[c], U = 0; U < l.length; U++) {
18375
+ var H = l[U];
18376
+ this.complete(o, H);
18291
18377
  }
18292
18378
  } else
18293
- s[l] = [o], this.predict(l);
18379
+ s[c] = [o], this.predict(c);
18294
18380
  }
18295
18381
  }
18296
- }, A.prototype.predict = function(I) {
18297
- for (var O = this.grammar.byName[I] || [], s = 0; s < O.length; s++) {
18298
- var L = O[s], a = this.wants[I], o = new R(L, 0, this.index, a);
18382
+ }, A.prototype.predict = function(O) {
18383
+ for (var I = this.grammar.byName[O] || [], s = 0; s < I.length; s++) {
18384
+ var L = I[s], a = this.wants[O], o = new R(L, 0, this.index, a);
18299
18385
  this.states.push(o);
18300
18386
  }
18301
- }, A.prototype.complete = function(I, O) {
18302
- var s = I.nextState(O);
18387
+ }, A.prototype.complete = function(O, I) {
18388
+ var s = O.nextState(I);
18303
18389
  this.states.push(s);
18304
18390
  };
18305
- function e(I, O) {
18306
- this.rules = I, this.start = O || this.rules[0].name;
18391
+ function e(O, I) {
18392
+ this.rules = O, this.start = I || this.rules[0].name;
18307
18393
  var s = this.byName = {};
18308
18394
  this.rules.forEach(function(L) {
18309
18395
  s.hasOwnProperty(L.name) || (s[L.name] = []), s[L.name].push(L);
18310
18396
  });
18311
18397
  }
18312
- e.fromCompiled = function(L, O) {
18398
+ e.fromCompiled = function(L, I) {
18313
18399
  var s = L.Lexer;
18314
- L.ParserStart && (O = L.ParserStart, L = L.ParserRules);
18400
+ L.ParserStart && (I = L.ParserStart, L = L.ParserRules);
18315
18401
  var L = L.map(function(o) {
18316
18402
  return new E(o.name, o.symbols, o.postprocess);
18317
- }), a = new e(L, O);
18403
+ }), a = new e(L, I);
18318
18404
  return a.lexer = s, a;
18319
18405
  };
18320
18406
  function S() {
18321
18407
  this.reset("");
18322
18408
  }
18323
- S.prototype.reset = function(I, O) {
18324
- this.buffer = I, this.index = 0, this.line = O ? O.line : 1, this.lastLineBreak = O ? -O.col : 0;
18409
+ S.prototype.reset = function(O, I) {
18410
+ this.buffer = O, this.index = 0, this.line = I ? I.line : 1, this.lastLineBreak = I ? -I.col : 0;
18325
18411
  }, S.prototype.next = function() {
18326
18412
  if (this.index < this.buffer.length) {
18327
- var I = this.buffer[this.index++];
18328
- return I === `
18329
- ` && (this.line += 1, this.lastLineBreak = this.index), { value: I };
18413
+ var O = this.buffer[this.index++];
18414
+ return O === `
18415
+ ` && (this.line += 1, this.lastLineBreak = this.index), { value: O };
18330
18416
  }
18331
18417
  }, S.prototype.save = function() {
18332
18418
  return {
18333
18419
  line: this.line,
18334
18420
  col: this.index - this.lastLineBreak
18335
18421
  };
18336
- }, S.prototype.formatError = function(I, O) {
18422
+ }, S.prototype.formatError = function(O, I) {
18337
18423
  var s = this.buffer;
18338
18424
  if (typeof s == "string") {
18339
18425
  var L = s.split(`
@@ -18344,26 +18430,26 @@ function gI() {
18344
18430
  `, this.index);
18345
18431
  a === -1 && (a = s.length);
18346
18432
  var o = this.index - this.lastLineBreak, n = String(this.line).length;
18347
- return O += " at line " + this.line + " col " + o + `:
18433
+ return I += " at line " + this.line + " col " + o + `:
18348
18434
 
18349
- `, O += L.map(function(P, l) {
18350
- return U(this.line - L.length + l + 1, n) + " " + P;
18435
+ `, I += L.map(function(P, c) {
18436
+ return U(this.line - L.length + c + 1, n) + " " + P;
18351
18437
  }, this).join(`
18352
- `), O += `
18438
+ `), I += `
18353
18439
  ` + U("", n + o) + `^
18354
- `, O;
18440
+ `, I;
18355
18441
  } else
18356
- return O + " at index " + (this.index - 1);
18357
- function U(P, l) {
18358
- var c = String(P);
18359
- return Array(l - c.length + 1).join(" ") + c;
18442
+ return I + " at index " + (this.index - 1);
18443
+ function U(P, c) {
18444
+ var l = String(P);
18445
+ return Array(c - l.length + 1).join(" ") + l;
18360
18446
  }
18361
18447
  };
18362
- function N(I, O, s) {
18363
- if (I instanceof e)
18364
- var L = I, s = O;
18448
+ function N(O, I, s) {
18449
+ if (O instanceof e)
18450
+ var L = O, s = I;
18365
18451
  else
18366
- var L = e.fromCompiled(I, O);
18452
+ var L = e.fromCompiled(O, I);
18367
18453
  this.grammar = L, this.options = {
18368
18454
  keepHistory: !1,
18369
18455
  lexer: L.lexer || new S()
@@ -18374,12 +18460,12 @@ function gI() {
18374
18460
  var o = new A(L, 0);
18375
18461
  this.table = [o], o.wants[L.start] = [], o.predict(L.start), o.process(), this.current = 0;
18376
18462
  }
18377
- N.fail = {}, N.prototype.feed = function(I) {
18378
- var O = this.lexer;
18379
- O.reset(I, this.lexerState);
18463
+ N.fail = {}, N.prototype.feed = function(O) {
18464
+ var I = this.lexer;
18465
+ I.reset(O, this.lexerState);
18380
18466
  for (var s; ; ) {
18381
18467
  try {
18382
- if (s = O.next(), !s)
18468
+ if (s = I.next(), !s)
18383
18469
  break;
18384
18470
  } catch (x) {
18385
18471
  var n = new A(this.grammar, this.current + 1);
@@ -18391,10 +18477,10 @@ function gI() {
18391
18477
  this.options.keepHistory || delete this.table[this.current - 1];
18392
18478
  var o = this.current + 1, n = new A(this.grammar, o);
18393
18479
  this.table.push(n);
18394
- for (var U = s.text !== void 0 ? s.text : s.value, P = O.constructor === S ? s.value : s, l = a.scannable, c = l.length; c--; ) {
18395
- var m = l[c], p = m.rule.symbols[m.dot];
18396
- if (p.test ? p.test(P) : p.type ? p.type === s.type : p.literal === U) {
18397
- var V = m.nextState({ data: P, token: s, isToken: !0, reference: o - 1 });
18480
+ for (var U = s.text !== void 0 ? s.text : s.value, P = I.constructor === S ? s.value : s, c = a.scannable, l = c.length; l--; ) {
18481
+ var H = c[l], B = H.rule.symbols[H.dot];
18482
+ if (B.test ? B.test(P) : B.type ? B.type === s.type : B.literal === U) {
18483
+ var V = H.nextState({ data: P, token: s, isToken: !0, reference: o - 1 });
18398
18484
  n.states.push(V);
18399
18485
  }
18400
18486
  }
@@ -18402,100 +18488,100 @@ function gI() {
18402
18488
  var L = new Error(this.reportError(s));
18403
18489
  throw L.offset = this.current, L.token = s, L;
18404
18490
  }
18405
- this.options.keepHistory && (a.lexerState = O.save()), this.current++;
18491
+ this.options.keepHistory && (a.lexerState = I.save()), this.current++;
18406
18492
  }
18407
- return a && (this.lexerState = O.save()), this.results = this.finish(), this;
18408
- }, N.prototype.reportLexerError = function(I) {
18409
- var O, s, L = I.token;
18410
- return L ? (O = "input " + JSON.stringify(L.text[0]) + " (lexer error)", s = this.lexer.formatError(L, "Syntax error")) : (O = "input (lexer error)", s = I.message), this.reportErrorCommon(s, O);
18411
- }, N.prototype.reportError = function(I) {
18412
- var O = (I.type ? I.type + " token: " : "") + JSON.stringify(I.value !== void 0 ? I.value : I), s = this.lexer.formatError(I, "Syntax error");
18413
- return this.reportErrorCommon(s, O);
18414
- }, N.prototype.reportErrorCommon = function(I, O) {
18493
+ return a && (this.lexerState = I.save()), this.results = this.finish(), this;
18494
+ }, N.prototype.reportLexerError = function(O) {
18495
+ var I, s, L = O.token;
18496
+ return L ? (I = "input " + JSON.stringify(L.text[0]) + " (lexer error)", s = this.lexer.formatError(L, "Syntax error")) : (I = "input (lexer error)", s = O.message), this.reportErrorCommon(s, I);
18497
+ }, N.prototype.reportError = function(O) {
18498
+ var I = (O.type ? O.type + " token: " : "") + JSON.stringify(O.value !== void 0 ? O.value : O), s = this.lexer.formatError(O, "Syntax error");
18499
+ return this.reportErrorCommon(s, I);
18500
+ }, N.prototype.reportErrorCommon = function(O, I) {
18415
18501
  var s = [];
18416
- s.push(I);
18502
+ s.push(O);
18417
18503
  var L = this.table.length - 2, a = this.table[L], o = a.states.filter(function(U) {
18418
18504
  var P = U.rule.symbols[U.dot];
18419
18505
  return P && typeof P != "string";
18420
18506
  });
18421
18507
  if (o.length === 0)
18422
- s.push("Unexpected " + O + `. I did not expect any more input. Here is the state of my parse table:
18508
+ s.push("Unexpected " + I + `. I did not expect any more input. Here is the state of my parse table:
18423
18509
  `), this.displayStateStack(a.states, s);
18424
18510
  else {
18425
- s.push("Unexpected " + O + `. Instead, I was expecting to see one of the following:
18511
+ s.push("Unexpected " + I + `. Instead, I was expecting to see one of the following:
18426
18512
  `);
18427
18513
  var n = o.map(function(U) {
18428
18514
  return this.buildFirstStateStack(U, []) || [U];
18429
18515
  }, this);
18430
18516
  n.forEach(function(U) {
18431
- var P = U[0], l = P.rule.symbols[P.dot], c = this.getSymbolDisplay(l);
18432
- s.push("A " + c + " based on:"), this.displayStateStack(U, s);
18517
+ var P = U[0], c = P.rule.symbols[P.dot], l = this.getSymbolDisplay(c);
18518
+ s.push("A " + l + " based on:"), this.displayStateStack(U, s);
18433
18519
  }, this);
18434
18520
  }
18435
18521
  return s.push(""), s.join(`
18436
18522
  `);
18437
- }, N.prototype.displayStateStack = function(I, O) {
18438
- for (var s, L = 0, a = 0; a < I.length; a++) {
18439
- var o = I[a], n = o.rule.toString(o.dot);
18440
- n === s ? L++ : (L > 0 && O.push(" ^ " + L + " more lines identical to this"), L = 0, O.push(" " + n)), s = n;
18523
+ }, N.prototype.displayStateStack = function(O, I) {
18524
+ for (var s, L = 0, a = 0; a < O.length; a++) {
18525
+ var o = O[a], n = o.rule.toString(o.dot);
18526
+ n === s ? L++ : (L > 0 && I.push(" ^ " + L + " more lines identical to this"), L = 0, I.push(" " + n)), s = n;
18441
18527
  }
18442
- }, N.prototype.getSymbolDisplay = function(I) {
18443
- return t(I);
18444
- }, N.prototype.buildFirstStateStack = function(I, O) {
18445
- if (O.indexOf(I) !== -1)
18528
+ }, N.prototype.getSymbolDisplay = function(O) {
18529
+ return t(O);
18530
+ }, N.prototype.buildFirstStateStack = function(O, I) {
18531
+ if (I.indexOf(O) !== -1)
18446
18532
  return null;
18447
- if (I.wantedBy.length === 0)
18448
- return [I];
18449
- var s = I.wantedBy[0], L = [I].concat(O), a = this.buildFirstStateStack(s, L);
18450
- return a === null ? null : [I].concat(a);
18533
+ if (O.wantedBy.length === 0)
18534
+ return [O];
18535
+ var s = O.wantedBy[0], L = [O].concat(I), a = this.buildFirstStateStack(s, L);
18536
+ return a === null ? null : [O].concat(a);
18451
18537
  }, N.prototype.save = function() {
18452
- var I = this.table[this.current];
18453
- return I.lexerState = this.lexerState, I;
18454
- }, N.prototype.restore = function(I) {
18455
- var O = I.index;
18456
- this.current = O, this.table[O] = I, this.table.splice(O + 1), this.lexerState = I.lexerState, this.results = this.finish();
18457
- }, N.prototype.rewind = function(I) {
18538
+ var O = this.table[this.current];
18539
+ return O.lexerState = this.lexerState, O;
18540
+ }, N.prototype.restore = function(O) {
18541
+ var I = O.index;
18542
+ this.current = I, this.table[I] = O, this.table.splice(I + 1), this.lexerState = O.lexerState, this.results = this.finish();
18543
+ }, N.prototype.rewind = function(O) {
18458
18544
  if (!this.options.keepHistory)
18459
18545
  throw new Error("set option `keepHistory` to enable rewinding");
18460
- this.restore(this.table[I]);
18546
+ this.restore(this.table[O]);
18461
18547
  }, N.prototype.finish = function() {
18462
- var I = [], O = this.grammar.start, s = this.table[this.table.length - 1];
18548
+ var O = [], I = this.grammar.start, s = this.table[this.table.length - 1];
18463
18549
  return s.states.forEach(function(L) {
18464
- L.rule.name === O && L.dot === L.rule.symbols.length && L.reference === 0 && L.data !== N.fail && I.push(L);
18465
- }), I.map(function(L) {
18550
+ L.rule.name === I && L.dot === L.rule.symbols.length && L.reference === 0 && L.data !== N.fail && O.push(L);
18551
+ }), O.map(function(L) {
18466
18552
  return L.data;
18467
18553
  });
18468
18554
  };
18469
- function t(I) {
18470
- var O = typeof I;
18471
- if (O === "string")
18472
- return I;
18473
- if (O === "object") {
18474
- if (I.literal)
18475
- return JSON.stringify(I.literal);
18476
- if (I instanceof RegExp)
18477
- return "character matching " + I;
18478
- if (I.type)
18479
- return I.type + " token";
18480
- if (I.test)
18481
- return "token matching " + String(I.test);
18482
- throw new Error("Unknown symbol type: " + I);
18555
+ function t(O) {
18556
+ var I = typeof O;
18557
+ if (I === "string")
18558
+ return O;
18559
+ if (I === "object") {
18560
+ if (O.literal)
18561
+ return JSON.stringify(O.literal);
18562
+ if (O instanceof RegExp)
18563
+ return "character matching " + O;
18564
+ if (O.type)
18565
+ return O.type + " token";
18566
+ if (O.test)
18567
+ return "token matching " + String(O.test);
18568
+ throw new Error("Unknown symbol type: " + O);
18483
18569
  }
18484
18570
  }
18485
- function r(I) {
18486
- var O = typeof I;
18487
- if (O === "string")
18488
- return I;
18489
- if (O === "object") {
18490
- if (I.literal)
18491
- return JSON.stringify(I.literal);
18492
- if (I instanceof RegExp)
18493
- return I.toString();
18494
- if (I.type)
18495
- return "%" + I.type;
18496
- if (I.test)
18497
- return "<" + String(I.test) + ">";
18498
- throw new Error("Unknown symbol type: " + I);
18571
+ function r(O) {
18572
+ var I = typeof O;
18573
+ if (I === "string")
18574
+ return O;
18575
+ if (I === "object") {
18576
+ if (O.literal)
18577
+ return JSON.stringify(O.literal);
18578
+ if (O instanceof RegExp)
18579
+ return O.toString();
18580
+ if (O.type)
18581
+ return "%" + O.type;
18582
+ if (O.test)
18583
+ return "<" + String(O.test) + ">";
18584
+ throw new Error("Unknown symbol type: " + O);
18499
18585
  }
18500
18586
  }
18501
18587
  return {
@@ -18504,58 +18590,58 @@ function gI() {
18504
18590
  Rule: E
18505
18591
  };
18506
18592
  });
18507
- })(eE)), eE.exports;
18593
+ })(SE)), SE.exports;
18508
18594
  }
18509
- var wI = gI();
18510
- const JI = /* @__PURE__ */ KI(wI);
18511
- function xI(T) {
18512
- 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);
18513
18599
  }
18514
- const vI = (T, E, R) => {
18515
- if (jT(T.type)) {
18516
- const A = kI(R, E);
18600
+ const QI = (T, E, R) => {
18601
+ if (kT(T.type)) {
18602
+ const A = zI(R, E);
18517
18603
  if (A && A.type === D.PROPERTY_ACCESS_OPERATOR)
18518
18604
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18519
- const e = k(R, E);
18605
+ const e = z(R, E);
18520
18606
  if (e && e.type === D.PROPERTY_ACCESS_OPERATOR)
18521
18607
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18522
18608
  }
18523
18609
  return T;
18524
- }, QI = (T, E, R) => {
18610
+ }, ZI = (T, E, R) => {
18525
18611
  if (T.type === D.RESERVED_FUNCTION_NAME) {
18526
- const A = k(R, E);
18527
- if (!A || !AR(A))
18612
+ const A = z(R, E);
18613
+ if (!A || !eR(A))
18528
18614
  return Object.assign(Object.assign({}, T), { type: D.IDENTIFIER, text: T.raw });
18529
18615
  }
18530
18616
  return T;
18531
- }, ZI = (T, E, R) => {
18617
+ }, qI = (T, E, R) => {
18532
18618
  if (T.type === D.RESERVED_DATA_TYPE) {
18533
- const A = k(R, E);
18534
- if (A && AR(A))
18619
+ const A = z(R, E);
18620
+ if (A && eR(A))
18535
18621
  return Object.assign(Object.assign({}, T), { type: D.RESERVED_PARAMETERIZED_DATA_TYPE });
18536
18622
  }
18537
18623
  return T;
18538
- }, qI = (T, E, R) => {
18624
+ }, jI = (T, E, R) => {
18539
18625
  if (T.type === D.IDENTIFIER) {
18540
- const A = k(R, E);
18541
- if (A && eR(A))
18626
+ const A = z(R, E);
18627
+ if (A && SR(A))
18542
18628
  return Object.assign(Object.assign({}, T), { type: D.ARRAY_IDENTIFIER });
18543
18629
  }
18544
18630
  return T;
18545
- }, jI = (T, E, R) => {
18631
+ }, kI = (T, E, R) => {
18546
18632
  if (T.type === D.RESERVED_DATA_TYPE) {
18547
- const A = k(R, E);
18548
- if (A && eR(A))
18633
+ const A = z(R, E);
18634
+ if (A && SR(A))
18549
18635
  return Object.assign(Object.assign({}, T), { type: D.ARRAY_KEYWORD });
18550
18636
  }
18551
18637
  return T;
18552
- }, 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) => {
18553
18639
  let A = 1;
18554
- for (; T[E + A * R] && zI(T[E + A * R]); )
18640
+ for (; T[E + A * R] && EO(T[E + A * R]); )
18555
18641
  A++;
18556
18642
  return T[E + A * R];
18557
- }, 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;
18558
- 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 {
18559
18645
  constructor(E) {
18560
18646
  this.tokenize = E, this.index = 0, this.tokens = [], this.input = "";
18561
18647
  }
@@ -18568,7 +18654,7 @@ class SR {
18568
18654
  save() {
18569
18655
  }
18570
18656
  formatError(E) {
18571
- const { line: R, col: A } = RR(this.input, E.start);
18657
+ const { line: R, col: A } = AR(this.input, E.start);
18572
18658
  return `Parse error at token: ${E.text} at line ${R} column ${A}`;
18573
18659
  }
18574
18660
  has(E) {
@@ -18582,7 +18668,7 @@ var M;
18582
18668
  function gE(T) {
18583
18669
  return T[0];
18584
18670
  }
18585
- const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18671
+ const G = new IR((T) => []), K = ([[T]]) => T, Y = (T) => ({
18586
18672
  type: M.keyword,
18587
18673
  tokenType: T.type,
18588
18674
  text: T.text,
@@ -18591,17 +18677,17 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18591
18677
  type: M.data_type,
18592
18678
  text: T.text,
18593
18679
  raw: T.raw
18594
- }), Y = (T, { leading: E, trailing: R }) => (E?.length && (T = Object.assign(Object.assign({}, T), { leadingComments: E })), R?.length && (T = Object.assign(Object.assign({}, T), { trailingComments: R })), T), 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 }) => {
18595
18681
  if (E?.length) {
18596
18682
  const [A, ...e] = T;
18597
- T = [Y(A, { leading: E }), ...e];
18683
+ T = [p(A, { leading: E }), ...e];
18598
18684
  }
18599
18685
  if (R?.length) {
18600
18686
  const A = T.slice(0, -1), e = T[T.length - 1];
18601
- T = [...A, Y(e, { trailing: R })];
18687
+ T = [...A, p(e, { trailing: R })];
18602
18688
  }
18603
18689
  return T;
18604
- }, TO = {
18690
+ }, RO = {
18605
18691
  Lexer: G,
18606
18692
  ParserRules: [
18607
18693
  { name: "main$ebnf$1", symbols: [] },
@@ -18652,14 +18738,14 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18652
18738
  const [e, S] = A;
18653
18739
  return {
18654
18740
  type: M.limit_clause,
18655
- limitKw: Y(F(T), { trailing: E }),
18741
+ limitKw: p(Y(T), { trailing: E }),
18656
18742
  offset: R,
18657
18743
  count: S
18658
18744
  };
18659
18745
  } else
18660
18746
  return {
18661
18747
  type: M.limit_clause,
18662
- limitKw: Y(F(T), { trailing: E }),
18748
+ limitKw: p(Y(T), { trailing: E }),
18663
18749
  count: R
18664
18750
  };
18665
18751
  }
@@ -18675,7 +18761,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18675
18761
  symbols: [G.has("RESERVED_SELECT") ? { type: "RESERVED_SELECT" } : RESERVED_SELECT, "select_clause$subexpression$1"],
18676
18762
  postprocess: ([T, [E, R]]) => ({
18677
18763
  type: M.clause,
18678
- nameKw: F(T),
18764
+ nameKw: Y(T),
18679
18765
  children: [E, ...R]
18680
18766
  })
18681
18767
  },
@@ -18684,7 +18770,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18684
18770
  symbols: [G.has("RESERVED_SELECT") ? { type: "RESERVED_SELECT" } : RESERVED_SELECT],
18685
18771
  postprocess: ([T]) => ({
18686
18772
  type: M.clause,
18687
- nameKw: F(T),
18773
+ nameKw: Y(T),
18688
18774
  children: []
18689
18775
  })
18690
18776
  },
@@ -18700,7 +18786,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18700
18786
  symbols: [G.has("RESERVED_CLAUSE") ? { type: "RESERVED_CLAUSE" } : RESERVED_CLAUSE, "other_clause$ebnf$1"],
18701
18787
  postprocess: ([T, E]) => ({
18702
18788
  type: M.clause,
18703
- nameKw: F(T),
18789
+ nameKw: Y(T),
18704
18790
  children: E
18705
18791
  })
18706
18792
  },
@@ -18711,7 +18797,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18711
18797
  symbols: [G.has("RESERVED_SET_OPERATION") ? { type: "RESERVED_SET_OPERATION" } : RESERVED_SET_OPERATION, "set_operation$ebnf$1"],
18712
18798
  postprocess: ([T, E]) => ({
18713
18799
  type: M.set_operation,
18714
- nameKw: F(T),
18800
+ nameKw: Y(T),
18715
18801
  children: E
18716
18802
  })
18717
18803
  },
@@ -18735,17 +18821,17 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18735
18821
  {
18736
18822
  name: "expression_with_comments_",
18737
18823
  symbols: ["expression", "_"],
18738
- postprocess: ([T, E]) => Y(T, { trailing: E })
18824
+ postprocess: ([T, E]) => p(T, { trailing: E })
18739
18825
  },
18740
18826
  {
18741
18827
  name: "_expression_with_comments",
18742
18828
  symbols: ["_", "expression"],
18743
- postprocess: ([T, E]) => Y(E, { leading: T })
18829
+ postprocess: ([T, E]) => p(E, { leading: T })
18744
18830
  },
18745
18831
  {
18746
18832
  name: "_andless_expression_with_comments",
18747
18833
  symbols: ["_", "andless_expression"],
18748
- postprocess: ([T, E]) => Y(E, { leading: T })
18834
+ postprocess: ([T, E]) => p(E, { leading: T })
18749
18835
  },
18750
18836
  { name: "free_form_sql$subexpression$1", symbols: ["asteriskless_free_form_sql"] },
18751
18837
  { name: "free_form_sql$subexpression$1", symbols: ["asterisk"] },
@@ -18784,7 +18870,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18784
18870
  symbols: [G.has("ARRAY_IDENTIFIER") ? { type: "ARRAY_IDENTIFIER" } : ARRAY_IDENTIFIER, "_", "square_brackets"],
18785
18871
  postprocess: ([T, E, R]) => ({
18786
18872
  type: M.array_subscript,
18787
- array: Y({ type: M.identifier, quoted: !1, text: T.text }, { trailing: E }),
18873
+ array: p({ type: M.identifier, quoted: !1, text: T.text }, { trailing: E }),
18788
18874
  parenthesis: R
18789
18875
  })
18790
18876
  },
@@ -18793,7 +18879,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18793
18879
  symbols: [G.has("ARRAY_KEYWORD") ? { type: "ARRAY_KEYWORD" } : ARRAY_KEYWORD, "_", "square_brackets"],
18794
18880
  postprocess: ([T, E, R]) => ({
18795
18881
  type: M.array_subscript,
18796
- array: Y(F(T), { trailing: E }),
18882
+ array: p(Y(T), { trailing: E }),
18797
18883
  parenthesis: R
18798
18884
  })
18799
18885
  },
@@ -18802,7 +18888,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18802
18888
  symbols: [G.has("RESERVED_FUNCTION_NAME") ? { type: "RESERVED_FUNCTION_NAME" } : RESERVED_FUNCTION_NAME, "_", "parenthesis"],
18803
18889
  postprocess: ([T, E, R]) => ({
18804
18890
  type: M.function_call,
18805
- nameKw: Y(F(T), { trailing: E }),
18891
+ nameKw: p(Y(T), { trailing: E }),
18806
18892
  parenthesis: R
18807
18893
  })
18808
18894
  },
@@ -18854,9 +18940,9 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18854
18940
  // %ARRAY_IDENTIFIER on the left side of <array_subscript>.
18855
18941
  ([T, E, R, A, [e]]) => ({
18856
18942
  type: M.property_access,
18857
- object: Y(T, { trailing: E }),
18943
+ object: p(T, { trailing: E }),
18858
18944
  operator: R.text,
18859
- property: Y(e, { leading: A })
18945
+ property: p(e, { leading: A })
18860
18946
  })
18861
18947
  )
18862
18948
  },
@@ -18865,10 +18951,10 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18865
18951
  symbols: [G.has("BETWEEN") ? { type: "BETWEEN" } : BETWEEN, "_", "andless_expression_chain", "_", G.has("AND") ? { type: "AND" } : AND, "_", "andless_expression"],
18866
18952
  postprocess: ([T, E, R, A, e, S, N]) => ({
18867
18953
  type: M.between_predicate,
18868
- betweenKw: F(T),
18869
- expr1: EO(R, { leading: E, trailing: A }),
18870
- andKw: F(e),
18871
- expr2: [Y(N, { leading: S })]
18954
+ betweenKw: Y(T),
18955
+ expr1: TO(R, { leading: E, trailing: A }),
18956
+ andKw: Y(e),
18957
+ expr2: [p(N, { leading: S })]
18872
18958
  })
18873
18959
  },
18874
18960
  { name: "case_expression$ebnf$1", symbols: ["expression_chain_"], postprocess: gE },
@@ -18880,8 +18966,8 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18880
18966
  symbols: [G.has("CASE") ? { type: "CASE" } : CASE, "_", "case_expression$ebnf$1", "case_expression$ebnf$2", G.has("END") ? { type: "END" } : END],
18881
18967
  postprocess: ([T, E, R, A, e]) => ({
18882
18968
  type: M.case_expression,
18883
- caseKw: Y(F(T), { trailing: E }),
18884
- endKw: F(e),
18969
+ caseKw: p(Y(T), { trailing: E }),
18970
+ endKw: Y(e),
18885
18971
  expr: R || [],
18886
18972
  clauses: A
18887
18973
  })
@@ -18891,8 +18977,8 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18891
18977
  symbols: [G.has("WHEN") ? { type: "WHEN" } : WHEN, "_", "expression_chain_", G.has("THEN") ? { type: "THEN" } : THEN, "_", "expression_chain_"],
18892
18978
  postprocess: ([T, E, R, A, e, S]) => ({
18893
18979
  type: M.case_when,
18894
- whenKw: Y(F(T), { trailing: E }),
18895
- thenKw: Y(F(A), { trailing: e }),
18980
+ whenKw: p(Y(T), { trailing: E }),
18981
+ thenKw: p(Y(A), { trailing: e }),
18896
18982
  condition: R,
18897
18983
  result: S
18898
18984
  })
@@ -18902,7 +18988,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18902
18988
  symbols: [G.has("ELSE") ? { type: "ELSE" } : ELSE, "_", "expression_chain_"],
18903
18989
  postprocess: ([T, E, R]) => ({
18904
18990
  type: M.case_else,
18905
- elseKw: Y(F(T), { trailing: E }),
18991
+ elseKw: p(Y(T), { trailing: E }),
18906
18992
  result: R
18907
18993
  })
18908
18994
  },
@@ -18931,7 +19017,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18931
19017
  {
18932
19018
  name: "keyword",
18933
19019
  symbols: ["keyword$subexpression$1"],
18934
- postprocess: ([[T]]) => F(T)
19020
+ postprocess: ([[T]]) => Y(T)
18935
19021
  },
18936
19022
  { name: "data_type$subexpression$1", symbols: [G.has("RESERVED_DATA_TYPE") ? { type: "RESERVED_DATA_TYPE" } : RESERVED_DATA_TYPE] },
18937
19023
  { name: "data_type$subexpression$1", symbols: [G.has("RESERVED_DATA_TYPE_PHRASE") ? { type: "RESERVED_DATA_TYPE_PHRASE" } : RESERVED_DATA_TYPE_PHRASE] },
@@ -18945,7 +19031,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18945
19031
  symbols: [G.has("RESERVED_PARAMETERIZED_DATA_TYPE") ? { type: "RESERVED_PARAMETERIZED_DATA_TYPE" } : RESERVED_PARAMETERIZED_DATA_TYPE, "_", "parenthesis"],
18946
19032
  postprocess: ([T, E, R]) => ({
18947
19033
  type: M.parameterized_data_type,
18948
- dataType: Y(bT(T), { trailing: E }),
19034
+ dataType: p(bT(T), { trailing: E }),
18949
19035
  parenthesis: R
18950
19036
  })
18951
19037
  },
@@ -18955,7 +19041,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18955
19041
  {
18956
19042
  name: "logic_operator",
18957
19043
  symbols: ["logic_operator$subexpression$1"],
18958
- postprocess: ([[T]]) => F(T)
19044
+ postprocess: ([[T]]) => Y(T)
18959
19045
  },
18960
19046
  { name: "other_keyword$subexpression$1", symbols: [G.has("WHEN") ? { type: "WHEN" } : WHEN] },
18961
19047
  { name: "other_keyword$subexpression$1", symbols: [G.has("THEN") ? { type: "THEN" } : THEN] },
@@ -18964,7 +19050,7 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18964
19050
  {
18965
19051
  name: "other_keyword",
18966
19052
  symbols: ["other_keyword$subexpression$1"],
18967
- postprocess: ([[T]]) => F(T)
19053
+ postprocess: ([[T]]) => Y(T)
18968
19054
  },
18969
19055
  { name: "_$ebnf$1", symbols: [] },
18970
19056
  { name: "_$ebnf$1", symbols: ["_$ebnf$1", "comment"], postprocess: (T) => T[0].concat([T[1]]) },
@@ -18998,13 +19084,13 @@ const G = new SR((T) => []), K = ([[T]]) => T, F = (T) => ({
18998
19084
  }
18999
19085
  ],
19000
19086
  ParserStart: "main"
19001
- }, { Parser: RO, Grammar: AO } = JI;
19002
- function eO(T) {
19087
+ }, { Parser: AO, Grammar: eO } = xI;
19088
+ function SO(T) {
19003
19089
  let E = {};
19004
- const R = new SR((e) => [
19005
- ...xI(T.tokenize(e, E)),
19006
- qT(e.length)
19007
- ]), 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 });
19008
19094
  return {
19009
19095
  parse: (e, S) => {
19010
19096
  E = S;
@@ -19020,7 +19106,7 @@ var i;
19020
19106
  (function(T) {
19021
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";
19022
19108
  })(i = i || (i = {}));
19023
- class IR {
19109
+ class NR {
19024
19110
  constructor(E) {
19025
19111
  this.indentation = E, this.items = [];
19026
19112
  }
@@ -19056,16 +19142,16 @@ class IR {
19056
19142
  }
19057
19143
  }
19058
19144
  trimHorizontalWhitespace() {
19059
- for (; SO(EE(this.items)); )
19145
+ for (; IO(TE(this.items)); )
19060
19146
  this.items.pop();
19061
19147
  }
19062
19148
  trimWhitespace() {
19063
- for (; IO(EE(this.items)); )
19149
+ for (; OO(TE(this.items)); )
19064
19150
  this.items.pop();
19065
19151
  }
19066
19152
  addNewline(E) {
19067
19153
  if (this.items.length > 0)
19068
- switch (EE(this.items)) {
19154
+ switch (TE(this.items)) {
19069
19155
  case i.NEWLINE:
19070
19156
  this.items.pop(), this.items.push(E);
19071
19157
  break;
@@ -19107,7 +19193,7 @@ class IR {
19107
19193
  }
19108
19194
  }
19109
19195
  }
19110
- 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;
19111
19197
  function yT(T, E) {
19112
19198
  if (E === "standard")
19113
19199
  return T;
@@ -19115,10 +19201,10 @@ function yT(T, E) {
19115
19201
  return T.length >= 10 && T.includes(" ") && ([T, ...R] = T.split(" ")), E === "tabularLeft" ? T = T.padEnd(9, " ") : T = T.padStart(9, " "), T + ["", ...R].join(" ");
19116
19202
  }
19117
19203
  function KT(T) {
19118
- 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;
19119
19205
  }
19120
- const wE = "top-level", OO = "block-level";
19121
- class NR {
19206
+ const wE = "top-level", NO = "block-level";
19207
+ class sR {
19122
19208
  /**
19123
19209
  * @param {string} indent A string to indent with
19124
19210
  */
@@ -19147,14 +19233,14 @@ class NR {
19147
19233
  * Increases indentation by one block-level indent.
19148
19234
  */
19149
19235
  increaseBlockLevel() {
19150
- this.indentTypes.push(OO);
19236
+ this.indentTypes.push(NO);
19151
19237
  }
19152
19238
  /**
19153
19239
  * Decreases indentation by one top-level indent.
19154
19240
  * Does nothing when the previous indent is not top-level.
19155
19241
  */
19156
19242
  decreaseTopLevel() {
19157
- this.indentTypes.length > 0 && EE(this.indentTypes) === wE && this.indentTypes.pop();
19243
+ this.indentTypes.length > 0 && TE(this.indentTypes) === wE && this.indentTypes.pop();
19158
19244
  }
19159
19245
  /**
19160
19246
  * Decreases indentation by one block-level indent.
@@ -19166,9 +19252,9 @@ class NR {
19166
19252
  ;
19167
19253
  }
19168
19254
  }
19169
- class NO extends IR {
19255
+ class sO extends NR {
19170
19256
  constructor(E) {
19171
- 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;
19172
19258
  }
19173
19259
  add(...E) {
19174
19260
  if (E.forEach((R) => this.addToLength(R)), this.length > this.expressionWidth)
@@ -19361,7 +19447,7 @@ class tE {
19361
19447
  // first line starts with /* or /**
19362
19448
  /^\/\*\*?$/.test(R[0]) && // intermediate lines start with *
19363
19449
  R.slice(1, R.length - 1).every((A) => /^\s*\*/.test(A)) && // last line ends with */
19364
- /^\s*\*\/$/.test(EE(R))
19450
+ /^\s*\*\/$/.test(TE(R))
19365
19451
  );
19366
19452
  }
19367
19453
  // Breaks up block comment to multiple lines.
@@ -19410,7 +19496,7 @@ class tE {
19410
19496
  cfg: this.cfg,
19411
19497
  dialectCfg: this.dialectCfg,
19412
19498
  params: this.params,
19413
- layout: new NO(this.cfg.expressionWidth),
19499
+ layout: new sO(this.cfg.expressionWidth),
19414
19500
  inline: !0
19415
19501
  }).format(E);
19416
19502
  } catch (A) {
@@ -19452,7 +19538,7 @@ class tE {
19452
19538
  showNonTabularKw(E) {
19453
19539
  switch (this.cfg.keywordCase) {
19454
19540
  case "preserve":
19455
- return AE(E.raw);
19541
+ return eE(E.raw);
19456
19542
  case "upper":
19457
19543
  return E.text;
19458
19544
  case "lower":
@@ -19466,7 +19552,7 @@ class tE {
19466
19552
  showNonTabularFunctionKw(E) {
19467
19553
  switch (this.cfg.functionCase) {
19468
19554
  case "preserve":
19469
- return AE(E.raw);
19555
+ return eE(E.raw);
19470
19556
  case "upper":
19471
19557
  return E.text;
19472
19558
  case "lower":
@@ -19488,7 +19574,7 @@ class tE {
19488
19574
  showDataType(E) {
19489
19575
  switch (this.cfg.dataTypeCase) {
19490
19576
  case "preserve":
19491
- return AE(E.raw);
19577
+ return eE(E.raw);
19492
19578
  case "upper":
19493
19579
  return E.text;
19494
19580
  case "lower":
@@ -19496,9 +19582,9 @@ class tE {
19496
19582
  }
19497
19583
  }
19498
19584
  }
19499
- class sO {
19585
+ class tO {
19500
19586
  constructor(E, R) {
19501
- 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);
19502
19588
  }
19503
19589
  /**
19504
19590
  * Formats an SQL query.
@@ -19510,7 +19596,7 @@ class sO {
19510
19596
  return this.formatAst(R).trimEnd();
19511
19597
  }
19512
19598
  parse(E) {
19513
- return eO(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19599
+ return SO(this.dialect.tokenizer).parse(E, this.cfg.paramTypes || {});
19514
19600
  }
19515
19601
  formatAst(E) {
19516
19602
  return E.map((R) => this.formatStatement(R)).join(`
@@ -19521,14 +19607,14 @@ class sO {
19521
19607
  cfg: this.cfg,
19522
19608
  dialectCfg: this.dialect.formatOptions,
19523
19609
  params: this.params,
19524
- layout: new IR(new NR(bI(this.cfg)))
19610
+ layout: new NR(new sR(yI(this.cfg)))
19525
19611
  }).format(E.children);
19526
19612
  return E.hasSemicolon && (this.cfg.newlineBeforeSemicolon ? R.add(i.NEWLINE, ";") : R.add(i.NO_NEWLINE, ";")), R.toString();
19527
19613
  }
19528
19614
  }
19529
- class SE extends Error {
19615
+ class IE extends Error {
19530
19616
  }
19531
- function tO(T) {
19617
+ function CO(T) {
19532
19618
  const E = [
19533
19619
  "multilineLists",
19534
19620
  "newlineBeforeOpenParen",
@@ -19539,20 +19625,20 @@ function tO(T) {
19539
19625
  ];
19540
19626
  for (const R of E)
19541
19627
  if (R in T)
19542
- throw new SE(`${R} config is no more supported.`);
19628
+ throw new IE(`${R} config is no more supported.`);
19543
19629
  if (T.expressionWidth <= 0)
19544
- throw new SE(`expressionWidth config must be positive number. Received ${T.expressionWidth} instead.`);
19545
- if (T.params && !CO(T.params) && console.warn('WARNING: All "params" option values should be strings.'), T.paramTypes && !LO(T.paramTypes))
19546
- 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.");
19547
19633
  return T;
19548
19634
  }
19549
- function CO(T) {
19635
+ function LO(T) {
19550
19636
  return (T instanceof Array ? T : Object.values(T)).every((R) => typeof R == "string");
19551
19637
  }
19552
- function LO(T) {
19638
+ function _O(T) {
19553
19639
  return T.custom && Array.isArray(T.custom) ? T.custom.every((E) => E.regex !== "") : !0;
19554
19640
  }
19555
- var _O = function(T, E) {
19641
+ var rO = function(T, E) {
19556
19642
  var R = {};
19557
19643
  for (var A in T) Object.prototype.hasOwnProperty.call(T, A) && E.indexOf(A) < 0 && (R[A] = T[A]);
19558
19644
  if (T != null && typeof Object.getOwnPropertySymbols == "function")
@@ -19560,7 +19646,7 @@ var _O = function(T, E) {
19560
19646
  E.indexOf(A[e]) < 0 && Object.prototype.propertyIsEnumerable.call(T, A[e]) && (R[A[e]] = T[A[e]]);
19561
19647
  return R;
19562
19648
  };
19563
- const sR = {
19649
+ const tR = {
19564
19650
  bigquery: "bigquery",
19565
19651
  db2: "db2",
19566
19652
  db2i: "db2i",
@@ -19581,7 +19667,7 @@ const sR = {
19581
19667
  tsql: "transactsql",
19582
19668
  singlestoredb: "singlestoredb",
19583
19669
  snowflake: "snowflake"
19584
- }, rO = Object.keys(sR), nO = {
19670
+ }, nO = Object.keys(tR), iO = {
19585
19671
  tabWidth: 2,
19586
19672
  useTabs: !1,
19587
19673
  keywordCase: "preserve",
@@ -19594,27 +19680,27 @@ const sR = {
19594
19680
  linesBetweenQueries: 1,
19595
19681
  denseOperators: !1,
19596
19682
  newlineBeforeSemicolon: !1
19597
- }, iO = (T, E = {}) => {
19598
- if (typeof E.language == "string" && !rO.includes(E.language))
19599
- throw new SE(`Unsupported SQL dialect: ${E.language}`);
19600
- const R = sR[E.language || "sql"];
19601
- return DO(T, Object.assign(Object.assign({}, E), { dialect: UI[R] }));
19602
- }, DO = (T, E) => {
19603
- 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"]);
19604
19690
  if (typeof T != "string")
19605
19691
  throw new Error("Invalid query argument. Expected string, instead got " + typeof T);
19606
- const e = tO(Object.assign(Object.assign({}, nO), A));
19607
- 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);
19608
19694
  };
19609
- function aO(T) {
19695
+ function oO(T) {
19610
19696
  let E = 0;
19611
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";
19612
19698
  }
19613
- function oO() {
19699
+ function PO() {
19614
19700
  const T = Date.now(), E = Math.random().toString(36).substring(2, 9);
19615
19701
  return `${T}-${E}`;
19616
19702
  }
19617
- function PO(T) {
19703
+ function MO(T) {
19618
19704
  const E = T.dimensions || [], R = T.timeDimensions || [], A = T.measures || [];
19619
19705
  return {
19620
19706
  sortedDimensions: E,
@@ -19639,7 +19725,7 @@ function PO(T) {
19639
19725
  hasMultiStage: !1
19640
19726
  };
19641
19727
  }
19642
- function MO(T) {
19728
+ function UO(T) {
19643
19729
  if (T.hasExecutor()) {
19644
19730
  const E = T.databaseExecutor;
19645
19731
  if (E?.engineType)
@@ -19647,24 +19733,24 @@ function MO(T) {
19647
19733
  }
19648
19734
  return "postgres";
19649
19735
  }
19650
- async function GO(T, E, R) {
19736
+ async function lO(T, E, R) {
19651
19737
  const A = R.validateQuery(T);
19652
19738
  if (!A.isValid)
19653
19739
  throw new Error(`Query validation failed: ${A.errors.join(", ")}`);
19654
19740
  const e = /* @__PURE__ */ new Set();
19655
19741
  T.measures?.forEach((r) => {
19656
- const I = r.split(".")[0];
19657
- e.add(I);
19742
+ const O = r.split(".")[0];
19743
+ e.add(O);
19658
19744
  }), T.dimensions?.forEach((r) => {
19659
- const I = r.split(".")[0];
19660
- e.add(I);
19745
+ const O = r.split(".")[0];
19746
+ e.add(O);
19661
19747
  }), T.timeDimensions?.forEach((r) => {
19662
- const I = r.dimension.split(".")[0];
19663
- e.add(I);
19748
+ const O = r.dimension.split(".")[0];
19749
+ e.add(O);
19664
19750
  }), T.filters?.forEach((r) => {
19665
19751
  if ("member" in r) {
19666
- const I = r.member.split(".")[0];
19667
- e.add(I);
19752
+ const O = r.member.split(".")[0];
19753
+ e.add(O);
19668
19754
  }
19669
19755
  });
19670
19756
  const S = e.size > 1;
@@ -19678,8 +19764,8 @@ async function GO(T, E, R) {
19678
19764
  const t = Array.from(e).map((r) => ({
19679
19765
  cube: r,
19680
19766
  query: {
19681
- measures: T.measures?.filter((I) => I.startsWith(r + ".")) || [],
19682
- dimensions: T.dimensions?.filter((I) => I.startsWith(r + ".")) || [],
19767
+ measures: T.measures?.filter((O) => O.startsWith(r + ".")) || [],
19768
+ dimensions: T.dimensions?.filter((O) => O.startsWith(r + ".")) || [],
19683
19769
  filters: T.filters || [],
19684
19770
  timeDimensions: T.timeDimensions || [],
19685
19771
  order: T.order || {},
@@ -19700,15 +19786,15 @@ async function GO(T, E, R) {
19700
19786
  sql: [N.sql],
19701
19787
  params: N.params || []
19702
19788
  },
19703
- complexity: aO(T),
19789
+ complexity: oO(T),
19704
19790
  valid: !0,
19705
19791
  cubesUsed: Array.from(e),
19706
19792
  joinType: S ? "multi_cube_join" : "single_cube",
19707
19793
  query: T
19708
19794
  };
19709
19795
  }
19710
- function lO(T, E, R) {
19711
- 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);
19712
19798
  return {
19713
19799
  queryType: "regularQuery",
19714
19800
  results: [{
@@ -19734,7 +19820,7 @@ function lO(T, E, R) {
19734
19820
  }
19735
19821
  function $T(T, E) {
19736
19822
  try {
19737
- return iO(T, {
19823
+ return DO(T, {
19738
19824
  language: {
19739
19825
  postgres: "postgresql",
19740
19826
  mysql: "mysql",
@@ -19750,25 +19836,25 @@ function $T(T, E) {
19750
19836
  return console.warn("SQL formatting failed:", R), T;
19751
19837
  }
19752
19838
  }
19753
- function cO(T, E) {
19839
+ function uO(T, E) {
19754
19840
  return {
19755
19841
  sql: E.sql,
19756
19842
  params: E.params || [],
19757
19843
  query: T
19758
19844
  };
19759
19845
  }
19760
- function uO(T) {
19846
+ function HO(T) {
19761
19847
  return {
19762
19848
  cubes: T
19763
19849
  };
19764
19850
  }
19765
- function HO(T, E = 500) {
19851
+ function BO(T, E = 500) {
19766
19852
  return {
19767
19853
  error: T instanceof Error ? T.message : T,
19768
19854
  status: E
19769
19855
  };
19770
19856
  }
19771
- class UO {
19857
+ class GO {
19772
19858
  cubes = /* @__PURE__ */ new Map();
19773
19859
  dbExecutor;
19774
19860
  metadataCache;
@@ -19886,27 +19972,27 @@ class UO {
19886
19972
  generateCubeMetadata(E) {
19887
19973
  const R = Object.keys(E.measures), A = Object.keys(E.dimensions), e = new Array(R.length), S = new Array(A.length);
19888
19974
  for (let t = 0; t < R.length; t++) {
19889
- const r = R[t], I = E.measures[r];
19975
+ const r = R[t], O = E.measures[r];
19890
19976
  e[t] = {
19891
19977
  name: `${E.name}.${r}`,
19892
- title: I.title || r,
19893
- shortTitle: I.title || r,
19894
- type: I.type,
19978
+ title: O.title || r,
19979
+ shortTitle: O.title || r,
19980
+ type: O.type,
19895
19981
  format: void 0,
19896
19982
  // Measure doesn't have format field
19897
- description: I.description
19983
+ description: O.description
19898
19984
  };
19899
19985
  }
19900
19986
  for (let t = 0; t < A.length; t++) {
19901
- const r = A[t], I = E.dimensions[r];
19987
+ const r = A[t], O = E.dimensions[r];
19902
19988
  S[t] = {
19903
19989
  name: `${E.name}.${r}`,
19904
- title: I.title || r,
19905
- shortTitle: I.title || r,
19906
- type: I.type,
19990
+ title: O.title || r,
19991
+ shortTitle: O.title || r,
19992
+ type: O.type,
19907
19993
  format: void 0,
19908
19994
  // Dimension doesn't have format field
19909
- description: I.description
19995
+ description: O.description
19910
19996
  };
19911
19997
  }
19912
19998
  const N = [];
@@ -19916,9 +20002,9 @@ class UO {
19916
20002
  N.push({
19917
20003
  targetCube: r.name,
19918
20004
  relationship: t.relationship,
19919
- joinFields: t.on.map((I) => ({
19920
- sourceField: this.getColumnName(I.source),
19921
- targetField: this.getColumnName(I.target)
20005
+ joinFields: t.on.map((O) => ({
20006
+ sourceField: this.getColumnName(O.source),
20007
+ targetField: this.getColumnName(O.target)
19922
20008
  }))
19923
20009
  });
19924
20010
  }
@@ -19997,10 +20083,10 @@ class UO {
19997
20083
  * Ensures all referenced cubes and fields exist
19998
20084
  */
19999
20085
  validateQuery(E) {
20000
- return tR(this.cubes, E);
20086
+ return CR(this.cubes, E);
20001
20087
  }
20002
20088
  }
20003
- function tR(T, E) {
20089
+ function CR(T, E) {
20004
20090
  const R = [], A = /* @__PURE__ */ new Set();
20005
20091
  if (E.measures)
20006
20092
  for (const e of E.measures) {
@@ -20049,17 +20135,17 @@ function tR(T, E) {
20049
20135
  }
20050
20136
  if (E.filters)
20051
20137
  for (const e of E.filters)
20052
- CR(e, T, R, A);
20138
+ LR(e, T, R, A);
20053
20139
  return A.size === 0 && R.push("Query must reference at least one cube through measures, dimensions, or filters"), {
20054
20140
  isValid: R.length === 0,
20055
20141
  errors: R
20056
20142
  };
20057
20143
  }
20058
- function CR(T, E, R, A) {
20144
+ function LR(T, E, R, A) {
20059
20145
  if ("and" in T || "or" in T) {
20060
20146
  const t = T.and || T.or || [];
20061
20147
  for (const r of t)
20062
- CR(r, E, R, A);
20148
+ LR(r, E, R, A);
20063
20149
  return;
20064
20150
  }
20065
20151
  if (!("member" in T)) {
@@ -20079,12 +20165,12 @@ function CR(T, E, R, A) {
20079
20165
  }
20080
20166
  !N.dimensions[S] && !N.measures[S] && R.push(`Filter field '${S}' not found on cube '${e}' (must be a dimension or measure)`);
20081
20167
  }
20082
- new UO();
20168
+ new GO();
20083
20169
  export {
20084
- UO as S,
20085
- uO as a,
20086
- cO as b,
20087
- HO as c,
20088
- lO as f,
20089
- 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
20090
20176
  };