drizzle-cube 0.3.0 → 0.3.1

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.
@@ -177,71 +177,71 @@ class G {
177
177
  escapeParam: s,
178
178
  prepareTyping: n,
179
179
  inlineParams: I,
180
- paramStartIndex: S
180
+ paramStartIndex: r
181
181
  } = t;
182
- return WT(E.map((r) => {
183
- if (H(r, V))
184
- return { sql: r.value.join(""), params: [] };
185
- if (H(r, Ae))
186
- return { sql: A(r.value), params: [] };
187
- if (r === void 0)
182
+ return WT(E.map((S) => {
183
+ if (H(S, V))
184
+ return { sql: S.value.join(""), params: [] };
185
+ if (H(S, Ae))
186
+ return { sql: A(S.value), params: [] };
187
+ if (S === void 0)
188
188
  return { sql: "", params: [] };
189
- if (Array.isArray(r)) {
189
+ if (Array.isArray(S)) {
190
190
  const O = [new V("(")];
191
- for (const [i, a] of r.entries())
192
- O.push(a), i < r.length - 1 && O.push(new V(", "));
191
+ for (const [i, a] of S.entries())
192
+ O.push(a), i < S.length - 1 && O.push(new V(", "));
193
193
  return O.push(new V(")")), this.buildQueryFromSourceParams(O, t);
194
194
  }
195
- if (H(r, G))
196
- return this.buildQueryFromSourceParams(r.queryChunks, {
195
+ if (H(S, G))
196
+ return this.buildQueryFromSourceParams(S.queryChunks, {
197
197
  ...t,
198
- inlineParams: I || r.shouldInlineParams
198
+ inlineParams: I || S.shouldInlineParams
199
199
  });
200
- if (H(r, X)) {
201
- const O = r[X.Symbol.Schema], i = r[X.Symbol.Name];
200
+ if (H(S, X)) {
201
+ const O = S[X.Symbol.Schema], i = S[X.Symbol.Name];
202
202
  return {
203
- sql: O === void 0 || r[DE] ? A(i) : A(O) + "." + A(i),
203
+ sql: O === void 0 || S[DE] ? A(i) : A(O) + "." + A(i),
204
204
  params: []
205
205
  };
206
206
  }
207
- if (H(r, nE)) {
208
- const O = R.getColumnCasing(r);
207
+ if (H(S, nE)) {
208
+ const O = R.getColumnCasing(S);
209
209
  if (e.invokeSource === "indexes")
210
210
  return { sql: A(O), params: [] };
211
- const i = r.table[X.Symbol.Schema];
211
+ const i = S.table[X.Symbol.Schema];
212
212
  return {
213
- sql: r.table[DE] || i === void 0 ? A(r.table[X.Symbol.Name]) + "." + A(O) : A(i) + "." + A(r.table[X.Symbol.Name]) + "." + A(O),
213
+ sql: S.table[DE] || i === void 0 ? A(S.table[X.Symbol.Name]) + "." + A(O) : A(i) + "." + A(S.table[X.Symbol.Name]) + "." + A(O),
214
214
  params: []
215
215
  };
216
216
  }
217
- if (H(r, oT)) {
218
- const O = r[RE].schema, i = r[RE].name;
217
+ if (H(S, oT)) {
218
+ const O = S[RE].schema, i = S[RE].name;
219
219
  return {
220
- sql: O === void 0 || r[RE].isAlias ? A(i) : A(O) + "." + A(i),
220
+ sql: O === void 0 || S[RE].isAlias ? A(i) : A(O) + "." + A(i),
221
221
  params: []
222
222
  };
223
223
  }
224
- if (H(r, PE)) {
225
- if (H(r.value, lE))
226
- return { sql: s(S.value++, r), params: [r], typings: ["none"] };
227
- const O = r.value === null ? null : r.encoder.mapToDriverValue(r.value);
224
+ if (H(S, PE)) {
225
+ if (H(S.value, lE))
226
+ return { sql: s(r.value++, S), params: [S], typings: ["none"] };
227
+ const O = S.value === null ? null : S.encoder.mapToDriverValue(S.value);
228
228
  if (H(O, G))
229
229
  return this.buildQueryFromSourceParams([O], t);
230
230
  if (I)
231
231
  return { sql: this.mapInlineParam(O, t), params: [] };
232
232
  let i = ["none"];
233
- return n && (i = [n(r.encoder)]), { sql: s(S.value++, O), params: [O], typings: i };
233
+ return n && (i = [n(S.encoder)]), { sql: s(r.value++, O), params: [O], typings: i };
234
234
  }
235
- return H(r, lE) ? { sql: s(S.value++, r), params: [r], typings: ["none"] } : H(r, G.Aliased) && r.fieldAlias !== void 0 ? { sql: A(r.fieldAlias), params: [] } : H(r, IT) ? r._.isWith ? { sql: A(r._.alias), params: [] } : this.buildQueryFromSourceParams([
235
+ return H(S, lE) ? { sql: s(r.value++, S), params: [S], typings: ["none"] } : H(S, G.Aliased) && S.fieldAlias !== void 0 ? { sql: A(S.fieldAlias), params: [] } : H(S, IT) ? S._.isWith ? { sql: A(S._.alias), params: [] } : this.buildQueryFromSourceParams([
236
236
  new V("("),
237
- r._.sql,
237
+ S._.sql,
238
238
  new V(") "),
239
- new Ae(r._.alias)
240
- ], t) : gT(r) ? r.schema ? { sql: A(r.schema) + "." + A(r.enumName), params: [] } : { sql: A(r.enumName), params: [] } : OT(r) ? r.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([r.getSQL()], t) : this.buildQueryFromSourceParams([
239
+ new Ae(S._.alias)
240
+ ], t) : gT(S) ? S.schema ? { sql: A(S.schema) + "." + A(S.enumName), params: [] } : { sql: A(S.enumName), params: [] } : OT(S) ? S.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([S.getSQL()], t) : this.buildQueryFromSourceParams([
241
241
  new V("("),
242
- r.getSQL(),
242
+ S.getSQL(),
243
243
  new V(")")
244
- ], t) : I ? { sql: this.mapInlineParam(r, t), params: [] } : { sql: s(S.value++, r), params: [r], typings: ["none"] };
244
+ ], t) : I ? { sql: this.mapInlineParam(S, t), params: [] } : { sql: s(r.value++, S), params: [S], typings: ["none"] };
245
245
  }));
246
246
  }
247
247
  mapInlineParam(E, { escapeString: e }) {
@@ -335,11 +335,11 @@ function N(T, ...E) {
335
335
  return new G([new V(I)]);
336
336
  }
337
337
  T.raw = t;
338
- function R(I, S) {
339
- const r = [];
338
+ function R(I, r) {
339
+ const S = [];
340
340
  for (const [O, i] of I.entries())
341
- O > 0 && S !== void 0 && r.push(S), r.push(i);
342
- return new G(r);
341
+ O > 0 && r !== void 0 && S.push(r), S.push(i);
342
+ return new G(S);
343
343
  }
344
344
  T.join = R;
345
345
  function A(I) {
@@ -350,8 +350,8 @@ function N(T, ...E) {
350
350
  return new lE(I);
351
351
  }
352
352
  T.placeholder = s;
353
- function n(I, S) {
354
- return new PE(I, S);
353
+ function n(I, r) {
354
+ return new PE(I, r);
355
355
  }
356
356
  T.param = n;
357
357
  })(N || (N = {}));
@@ -416,7 +416,7 @@ IT.prototype.getSQL = function() {
416
416
  function y(T, E) {
417
417
  return $T(E) && !OT(T) && !H(T, PE) && !H(T, lE) && !H(T, nE) && !H(T, X) && !H(T, oT) ? new PE(T, E) : T;
418
418
  }
419
- const x = (T, E) => N`${T} = ${y(E, T)}`, ue = (T, E) => N`${T} <> ${y(E, T)}`;
419
+ const J = (T, E) => N`${T} = ${y(E, T)}`, ue = (T, E) => N`${T} <> ${y(E, T)}`;
420
420
  function h(...T) {
421
421
  const E = T.filter(
422
422
  (e) => e !== void 0
@@ -482,13 +482,13 @@ function vT(T, E) {
482
482
  function de(T) {
483
483
  return N`${T} asc`;
484
484
  }
485
- function xT(T) {
485
+ function JT(T) {
486
486
  return N`${T} desc`;
487
487
  }
488
488
  function se(T) {
489
489
  return N`count(${T || N.raw("*")})`.mapWith(Number);
490
490
  }
491
- function JT(T) {
491
+ function xT(T) {
492
492
  return N`count(distinct ${T})`.mapWith(Number);
493
493
  }
494
494
  function w(T) {
@@ -759,9 +759,9 @@ class QT extends Ie {
759
759
  const { type: i, start: a, end: o } = A.frame, D = i.toUpperCase(), C = a === "unbounded" ? "UNBOUNDED PRECEDING" : typeof a == "number" ? `${a} PRECEDING` : "CURRENT ROW", P = o === "unbounded" ? "UNBOUNDED FOLLOWING" : o === "current" ? "CURRENT ROW" : typeof o == "number" ? `${o} FOLLOWING` : "CURRENT ROW";
760
760
  I = N`${N.raw(D)} BETWEEN ${N.raw(C)} AND ${N.raw(P)}`;
761
761
  }
762
- const S = [];
763
- t && t.length > 0 && S.push(s), R && R.length > 0 && S.push(n), A?.frame && S.push(I);
764
- const r = S.length > 0 ? N.join(S, N` `) : N``, O = N`OVER (${r})`;
762
+ const r = [];
763
+ t && t.length > 0 && r.push(s), R && R.length > 0 && r.push(n), A?.frame && r.push(I);
764
+ const S = r.length > 0 ? N.join(r, N` `) : N``, O = N`OVER (${S})`;
765
765
  switch (E) {
766
766
  case "lag":
767
767
  return N`LAG(${e}, ${A?.offset ?? 1}${A?.defaultValue !== void 0 ? N`, ${A.defaultValue}` : N``}) ${O}`;
@@ -1005,9 +1005,9 @@ class CT extends Ie {
1005
1005
  const { type: i, start: a, end: o } = A.frame, D = i.toUpperCase(), C = a === "unbounded" ? "UNBOUNDED PRECEDING" : typeof a == "number" ? `${a} PRECEDING` : "CURRENT ROW", P = o === "unbounded" ? "UNBOUNDED FOLLOWING" : o === "current" ? "CURRENT ROW" : typeof o == "number" ? `${o} FOLLOWING` : "CURRENT ROW";
1006
1006
  I = N`${N.raw(D)} BETWEEN ${N.raw(C)} AND ${N.raw(P)}`;
1007
1007
  }
1008
- const S = [];
1009
- t && t.length > 0 && S.push(s), R && R.length > 0 && S.push(n), A?.frame && S.push(I);
1010
- const r = S.length > 0 ? N.join(S, N` `) : N``, O = N`OVER (${r})`;
1008
+ const r = [];
1009
+ t && t.length > 0 && r.push(s), R && R.length > 0 && r.push(n), A?.frame && r.push(I);
1010
+ const S = r.length > 0 ? N.join(r, N` `) : N``, O = N`OVER (${S})`;
1011
1011
  switch (E) {
1012
1012
  case "lag":
1013
1013
  return N`LAG(${e}, ${A?.offset ?? 1}${A?.defaultValue !== void 0 ? N`, ${A.defaultValue}` : N``}) ${O}`;
@@ -1280,9 +1280,9 @@ class ZT extends Ie {
1280
1280
  const { type: i, start: a, end: o } = A.frame, D = i.toUpperCase(), C = a === "unbounded" ? "UNBOUNDED PRECEDING" : typeof a == "number" ? `${a} PRECEDING` : "CURRENT ROW", P = o === "unbounded" ? "UNBOUNDED FOLLOWING" : o === "current" ? "CURRENT ROW" : typeof o == "number" ? `${o} FOLLOWING` : "CURRENT ROW";
1281
1281
  I = N`${N.raw(D)} BETWEEN ${N.raw(C)} AND ${N.raw(P)}`;
1282
1282
  }
1283
- const S = [];
1284
- t && t.length > 0 && S.push(s), R && R.length > 0 && S.push(n), A?.frame && S.push(I);
1285
- const r = S.length > 0 ? N.join(S, N` `) : N``, O = N`OVER (${r})`;
1283
+ const r = [];
1284
+ t && t.length > 0 && r.push(s), R && R.length > 0 && r.push(n), A?.frame && r.push(I);
1285
+ const S = r.length > 0 ? N.join(r, N` `) : N``, O = N`OVER (${S})`;
1286
1286
  switch (E) {
1287
1287
  case "lag":
1288
1288
  return N`LAG(${e}, ${A?.offset ?? 1}${A?.defaultValue !== void 0 ? N`, ${A.defaultValue}` : N``}) ${O}`;
@@ -1550,30 +1550,30 @@ function tt(T, E) {
1550
1550
  if (T.relationship !== "belongsToMany" || !T.through)
1551
1551
  throw new Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
1552
1552
  const { table: e, sourceKey: t, targetKey: R, securitySql: A } = T.through, s = [];
1553
- for (const r of t) {
1554
- const O = r.as || x;
1555
- s.push(O(r.source, r.target));
1553
+ for (const S of t) {
1554
+ const O = S.as || J;
1555
+ s.push(O(S.source, S.target));
1556
1556
  }
1557
1557
  const n = [];
1558
- for (const r of R) {
1559
- const O = r.as || x;
1560
- n.push(O(r.source, r.target));
1558
+ for (const S of R) {
1559
+ const O = S.as || J;
1560
+ n.push(O(S.source, S.target));
1561
1561
  }
1562
1562
  let I;
1563
1563
  if (A) {
1564
- const r = A(E);
1565
- I = Array.isArray(r) ? r : [r];
1564
+ const S = A(E);
1565
+ I = Array.isArray(S) ? S : [S];
1566
1566
  }
1567
- const S = ne("belongsToMany", T.sqlJoinType);
1567
+ const r = ne("belongsToMany", T.sqlJoinType);
1568
1568
  return {
1569
1569
  junctionJoins: [
1570
1570
  {
1571
- joinType: S,
1571
+ joinType: r,
1572
1572
  table: e,
1573
1573
  condition: h(...s)
1574
1574
  },
1575
1575
  {
1576
- joinType: S,
1576
+ joinType: r,
1577
1577
  table: e,
1578
1578
  // This will be replaced with target cube table in query planner
1579
1579
  condition: h(...n)
@@ -1766,9 +1766,9 @@ class ie {
1766
1766
  if (typeof e == "string") {
1767
1767
  const t = this.parseRelativeDateRange(e);
1768
1768
  if (t) {
1769
- let r, O;
1770
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (r = Math.floor(t.start.getTime() / 1e3), O = Math.floor(t.end.getTime() / 1e3)) : (r = t.start.getTime(), O = t.end.getTime()) : (r = t.start.toISOString(), O = t.end.toISOString()), h(
1771
- EE(E, r),
1769
+ let S, O;
1770
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (S = Math.floor(t.start.getTime() / 1e3), O = Math.floor(t.end.getTime() / 1e3)) : (S = t.start.getTime(), O = t.end.getTime()) : (S = t.start.toISOString(), O = t.end.toISOString()), h(
1771
+ EE(E, S),
1772
1772
  eE(E, O)
1773
1773
  );
1774
1774
  }
@@ -1778,10 +1778,10 @@ class ie {
1778
1778
  s.setUTCHours(0, 0, 0, 0);
1779
1779
  const n = new Date(A);
1780
1780
  n.setUTCHours(23, 59, 59, 999);
1781
- let I, S;
1782
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (I = Math.floor(s.getTime() / 1e3), S = Math.floor(n.getTime() / 1e3)) : (I = s.getTime(), S = n.getTime()) : (I = s.toISOString(), S = n.toISOString()), h(
1781
+ let I, r;
1782
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (I = Math.floor(s.getTime() / 1e3), r = Math.floor(n.getTime() / 1e3)) : (I = s.getTime(), r = n.getTime()) : (I = s.toISOString(), r = n.toISOString()), h(
1783
1783
  EE(E, I),
1784
- eE(E, S)
1784
+ eE(E, r)
1785
1785
  );
1786
1786
  }
1787
1787
  return null;
@@ -1829,9 +1829,9 @@ class ie {
1829
1829
  const o = new Date(e);
1830
1830
  return o.setUTCHours(23, 59, 59, 999), { start: a, end: o };
1831
1831
  }
1832
- const S = t.match(/^last\s+(\d+)\s+weeks?$/);
1833
- if (S) {
1834
- const a = parseInt(S[1], 10) * 7, o = new Date(e);
1832
+ const r = t.match(/^last\s+(\d+)\s+weeks?$/);
1833
+ if (r) {
1834
+ const a = parseInt(r[1], 10) * 7, o = new Date(e);
1835
1835
  o.setUTCDate(s - a + 1), o.setUTCHours(0, 0, 0, 0);
1836
1836
  const D = new Date(e);
1837
1837
  return D.setUTCHours(23, 59, 59, 999), { start: o, end: D };
@@ -1858,9 +1858,9 @@ class ie {
1858
1858
  const i = new Date(Date.UTC(R, A - 11, 1, 0, 0, 0, 0)), a = new Date(e);
1859
1859
  return a.setUTCHours(23, 59, 59, 999), { start: i, end: a };
1860
1860
  }
1861
- const r = t.match(/^last\s+(\d+)\s+months?$/);
1862
- if (r) {
1863
- const i = parseInt(r[1], 10), a = new Date(Date.UTC(R, A - i + 1, 1, 0, 0, 0, 0)), o = new Date(e);
1861
+ const S = t.match(/^last\s+(\d+)\s+months?$/);
1862
+ if (S) {
1863
+ const i = parseInt(S[1], 10), a = new Date(Date.UTC(R, A - i + 1, 1, 0, 0, 0, 0)), o = new Date(e);
1864
1864
  return o.setUTCHours(23, 59, 59, 999), { start: a, end: o };
1865
1865
  }
1866
1866
  const O = t.match(/^last\s+(\d+)\s+years?$/);
@@ -1924,13 +1924,13 @@ class DT {
1924
1924
  case "equals":
1925
1925
  if (s.length > 1) {
1926
1926
  if (R?.type === "time") {
1927
- const I = s.map((S) => this.dateTimeBuilder.normalizeDate(S) || S);
1927
+ const I = s.map((r) => this.dateTimeBuilder.normalizeDate(r) || r);
1928
1928
  return FE(E, I);
1929
1929
  }
1930
1930
  return FE(E, s);
1931
1931
  } else if (s.length === 1) {
1932
1932
  const I = R?.type === "time" && this.dateTimeBuilder.normalizeDate(n) || n;
1933
- return x(E, I);
1933
+ return J(E, I);
1934
1934
  }
1935
1935
  return this.databaseAdapter.buildBooleanLiteral(!1);
1936
1936
  case "notEquals":
@@ -1958,16 +1958,16 @@ class DT {
1958
1958
  case "inDateRange":
1959
1959
  if (s.length >= 2) {
1960
1960
  const I = this.dateTimeBuilder.normalizeDate(s[0]);
1961
- let S = this.dateTimeBuilder.normalizeDate(s[1]);
1962
- if (I && S) {
1963
- const r = t[1];
1964
- if (typeof r == "string" && /^\d{4}-\d{2}-\d{2}$/.test(r.trim())) {
1965
- const O = typeof S == "number" ? new Date(S * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(S), i = new Date(O);
1966
- i.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? S = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(i.getTime() / 1e3) : i.getTime() : S = i.toISOString();
1961
+ let r = this.dateTimeBuilder.normalizeDate(s[1]);
1962
+ if (I && r) {
1963
+ const S = t[1];
1964
+ if (typeof S == "string" && /^\d{4}-\d{2}-\d{2}$/.test(S.trim())) {
1965
+ const O = typeof r == "number" ? new Date(r * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(r), i = new Date(O);
1966
+ i.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? r = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(i.getTime() / 1e3) : i.getTime() : r = i.toISOString();
1967
1967
  }
1968
1968
  return h(
1969
1969
  EE(E, I),
1970
- eE(E, S)
1970
+ eE(E, r)
1971
1971
  );
1972
1972
  }
1973
1973
  }
@@ -2007,7 +2007,7 @@ class DT {
2007
2007
  case "isEmpty":
2008
2008
  return IE(
2009
2009
  Me(E),
2010
- x(E, "")
2010
+ J(E, "")
2011
2011
  );
2012
2012
  case "isNotEmpty":
2013
2013
  return h(
@@ -2052,9 +2052,9 @@ class DT {
2052
2052
  if (!n) return null;
2053
2053
  const I = n.dimensions?.[s];
2054
2054
  if (!I) return null;
2055
- const S = F(I.sql, t);
2055
+ const r = F(I.sql, t);
2056
2056
  return this.buildFilterCondition(
2057
- S,
2057
+ r,
2058
2058
  R.operator,
2059
2059
  R.values,
2060
2060
  I,
@@ -2105,8 +2105,8 @@ class Z {
2105
2105
  if (t.type === "calculated" && t.calculatedSql) {
2106
2106
  const R = `${E.name}.${e}`, A = this.extractDependencies(t.calculatedSql), s = /* @__PURE__ */ new Set();
2107
2107
  for (const n of A) {
2108
- const S = `${n.cubeName || E.name}.${n.fieldName}`;
2109
- s.add(S);
2108
+ const r = `${n.cubeName || E.name}.${n.fieldName}`;
2109
+ s.add(r);
2110
2110
  }
2111
2111
  this.dependencyGraph.set(R, {
2112
2112
  id: R,
@@ -2299,21 +2299,21 @@ function St(T, E) {
2299
2299
  s.set(i, c);
2300
2300
  }
2301
2301
  const n = [], I = [];
2302
- let S = 0;
2302
+ let r = 0;
2303
2303
  for (const O of A) {
2304
- const i = `{${O.originalRef}}`, a = T.indexOf(i, S);
2304
+ const i = `{${O.originalRef}}`, a = T.indexOf(i, r);
2305
2305
  if (a >= 0) {
2306
- n.push(T.substring(S, a));
2306
+ n.push(T.substring(r, a));
2307
2307
  const o = s.get(O.originalRef);
2308
- o && I.push(o), S = a + i.length;
2308
+ o && I.push(o), r = a + i.length;
2309
2309
  }
2310
2310
  }
2311
- if (n.push(T.substring(S)), I.length === 0)
2311
+ if (n.push(T.substring(r)), I.length === 0)
2312
2312
  return N.raw(T);
2313
- const r = [];
2313
+ const S = [];
2314
2314
  for (let O = 0; O < n.length; O++)
2315
- n[O] && r.push(new V(n[O])), O < I.length && r.push(I[O]);
2316
- return N.join(r, N.raw(""));
2315
+ n[O] && S.push(new V(n[O])), O < I.length && S.push(I[O]);
2316
+ return N.join(S, N.raw(""));
2317
2317
  }
2318
2318
  function ae(T) {
2319
2319
  const E = /\{([^}]+)\}/g, e = T.matchAll(E), t = [];
@@ -2384,11 +2384,11 @@ class B {
2384
2384
  * @returns Map of measure names to SQL builder functions
2385
2385
  */
2386
2386
  buildResolvedMeasures(E, e, t, R) {
2387
- const A = /* @__PURE__ */ new Map(), s = [], n = [], I = new Set(E), S = new Z(e);
2388
- for (const r of e.values())
2389
- S.buildGraph(r);
2390
- for (const r of E) {
2391
- const [O, i] = r.split("."), a = e.get(O);
2387
+ const A = /* @__PURE__ */ new Map(), s = [], n = [], I = new Set(E), r = new Z(e);
2388
+ for (const S of e.values())
2389
+ r.buildGraph(S);
2390
+ for (const S of E) {
2391
+ const [O, i] = S.split("."), a = e.get(O);
2392
2392
  if (a && a.measures && a.measures[i]) {
2393
2393
  const o = a.measures[i];
2394
2394
  if (B.isPostAggregationWindow(o)) {
@@ -2396,35 +2396,35 @@ class B {
2396
2396
  D && I.add(D);
2397
2397
  continue;
2398
2398
  }
2399
- Z.isCalculatedMeasure(o) ? (n.push(r), YE(o.calculatedSql, O).forEach((P) => I.add(P)), S.getAllDependencies(r).forEach((P) => {
2399
+ Z.isCalculatedMeasure(o) ? (n.push(S), YE(o.calculatedSql, O).forEach((P) => I.add(P)), r.getAllDependencies(S).forEach((P) => {
2400
2400
  const [_, M] = P.split("."), c = e.get(_);
2401
2401
  if (c && c.measures[M]) {
2402
2402
  const d = c.measures[M];
2403
2403
  Z.isCalculatedMeasure(d) && YE(d.calculatedSql, _).forEach((f) => I.add(f));
2404
2404
  }
2405
- })) : s.push(r);
2405
+ })) : s.push(S);
2406
2406
  }
2407
2407
  }
2408
- for (const r of I) {
2409
- const [O, i] = r.split("."), a = e.get(O);
2408
+ for (const S of I) {
2409
+ const [O, i] = S.split("."), a = e.get(O);
2410
2410
  if (a && a.measures && a.measures[i]) {
2411
2411
  const o = a.measures[i];
2412
2412
  if (B.isPostAggregationWindow(o))
2413
2413
  continue;
2414
- Z.isCalculatedMeasure(o) ? n.includes(r) || n.push(r) : s.includes(r) || s.push(r);
2414
+ Z.isCalculatedMeasure(o) ? n.includes(S) || n.push(S) : s.includes(S) || s.push(S);
2415
2415
  }
2416
2416
  }
2417
- for (const r of s) {
2418
- const [O, i] = r.split("."), a = e.get(O), o = a.measures[i];
2417
+ for (const S of s) {
2418
+ const [O, i] = S.split("."), a = e.get(O), o = a.measures[i];
2419
2419
  if (R) {
2420
- const D = R(r, o, a);
2421
- A.set(r, () => D);
2420
+ const D = R(S, o, a);
2421
+ A.set(S, () => D);
2422
2422
  } else
2423
- A.set(r, () => this.buildMeasureExpression(o, t, a));
2423
+ A.set(S, () => this.buildMeasureExpression(o, t, a));
2424
2424
  }
2425
2425
  if (n.length > 0) {
2426
- const r = S.topologicalSort(n);
2427
- for (const O of r) {
2426
+ const S = r.topologicalSort(n);
2427
+ for (const O of S) {
2428
2428
  const [i, a] = O.split("."), o = e.get(i), D = o.measures[a];
2429
2429
  A.set(O, () => this.buildCalculatedMeasure(
2430
2430
  D,
@@ -2474,11 +2474,11 @@ class B {
2474
2474
  );
2475
2475
  const s = /* @__PURE__ */ new Map(), n = YE(E.calculatedSql, e.name);
2476
2476
  for (const I of n) {
2477
- const [S, r] = I.split("."), O = R.get(S);
2478
- if (O && O.measures[r]) {
2479
- const i = O.measures[r];
2477
+ const [r, S] = I.split("."), O = R.get(r);
2478
+ if (O && O.measures[S]) {
2479
+ const i = O.measures[S];
2480
2480
  if (t.measures.includes(I)) {
2481
- const a = N`${N.identifier(t.cteAlias)}.${N.identifier(r)}`;
2481
+ const a = N`${N.identifier(t.cteAlias)}.${N.identifier(S)}`;
2482
2482
  let o;
2483
2483
  switch (i.type) {
2484
2484
  case "count":
@@ -2521,13 +2521,13 @@ class B {
2521
2521
  const s = A.preAggregationCTEs.find((n) => n.cube.name === E);
2522
2522
  if (s && s.measures.includes(`${E}.${e}`))
2523
2523
  if (t.type === "calculated" && t.calculatedSql) {
2524
- const n = A.primaryCube.name === E ? A.primaryCube : A.joinCubes?.find((S) => S.cube.name === E)?.cube;
2524
+ const n = A.primaryCube.name === E ? A.primaryCube : A.joinCubes?.find((r) => r.cube.name === E)?.cube;
2525
2525
  if (!n)
2526
2526
  throw new Error(`Cube ${E} not found in query plan`);
2527
2527
  const I = /* @__PURE__ */ new Map([[A.primaryCube.name, A.primaryCube]]);
2528
2528
  if (A.joinCubes)
2529
- for (const S of A.joinCubes)
2530
- I.set(S.cube.name, S.cube);
2529
+ for (const r of A.joinCubes)
2530
+ I.set(r.cube.name, r.cube);
2531
2531
  return this.buildCTECalculatedMeasure(
2532
2532
  t,
2533
2533
  n,
@@ -2595,7 +2595,7 @@ class B {
2595
2595
  case "count":
2596
2596
  return se(R);
2597
2597
  case "countDistinct":
2598
- return JT(R);
2598
+ return xT(R);
2599
2599
  case "sum":
2600
2600
  return w(R);
2601
2601
  case "avg":
@@ -2652,28 +2652,28 @@ class B {
2652
2652
  const A = E.windowConfig || {};
2653
2653
  let s;
2654
2654
  if (A.partitionBy && A.partitionBy.length > 0 && t) {
2655
- const S = A.partitionBy.map((r) => {
2656
- const O = r.includes(".") ? r.split(".")[1] : r, i = t.dimensions?.[O];
2657
- return i ? F(i.sql, e) : (console.warn(`[drizzle-cube] Window function partition dimension '${r}' not found in cube '${t.name}'`), null);
2658
- }).filter((r) => r !== null);
2659
- S.length > 0 && (s = S);
2655
+ const r = A.partitionBy.map((S) => {
2656
+ const O = S.includes(".") ? S.split(".")[1] : S, i = t.dimensions?.[O];
2657
+ return i ? F(i.sql, e) : (console.warn(`[drizzle-cube] Window function partition dimension '${S}' not found in cube '${t.name}'`), null);
2658
+ }).filter((S) => S !== null);
2659
+ r.length > 0 && (s = r);
2660
2660
  }
2661
2661
  let n;
2662
2662
  if (A.orderBy && A.orderBy.length > 0 && t) {
2663
- const S = A.orderBy.map((r) => {
2664
- const O = r.field.includes(".") ? r.field.split(".")[1] : r.field, i = t.dimensions?.[O];
2663
+ const r = A.orderBy.map((S) => {
2664
+ const O = S.field.includes(".") ? S.field.split(".")[1] : S.field, i = t.dimensions?.[O];
2665
2665
  if (i)
2666
2666
  return {
2667
2667
  field: F(i.sql, e),
2668
- direction: r.direction
2668
+ direction: S.direction
2669
2669
  };
2670
2670
  const a = t.measures?.[O];
2671
2671
  return a && a.sql ? {
2672
2672
  field: F(a.sql, e),
2673
- direction: r.direction
2674
- } : (console.warn(`[drizzle-cube] Window function order field '${r.field}' not found in cube '${t.name}'`), null);
2675
- }).filter((r) => r !== null);
2676
- S.length > 0 && (n = S);
2673
+ direction: S.direction
2674
+ } : (console.warn(`[drizzle-cube] Window function order field '${S.field}' not found in cube '${t.name}'`), null);
2675
+ }).filter((S) => S !== null);
2676
+ r.length > 0 && (n = r);
2677
2677
  }
2678
2678
  const I = this.databaseAdapter.buildWindowFunction(
2679
2679
  E.type,
@@ -2733,8 +2733,8 @@ class B {
2733
2733
  for (const A of E) {
2734
2734
  const [s, n] = A.split("."), I = e.get(s);
2735
2735
  if (I?.measures?.[n]) {
2736
- const S = I.measures[n];
2737
- B.isWindowFunction(S.type) ? t.push(A) : R.push(A);
2736
+ const r = I.measures[n];
2737
+ B.isWindowFunction(r.type) ? t.push(A) : R.push(A);
2738
2738
  }
2739
2739
  }
2740
2740
  return { windowMeasures: t, aggregateMeasures: R };
@@ -2809,14 +2809,14 @@ class B {
2809
2809
  static categorizeForPostAggregation(E, e) {
2810
2810
  const t = [], R = [], A = /* @__PURE__ */ new Set();
2811
2811
  for (const s of E) {
2812
- const [n, I] = s.split("."), S = e.get(n);
2813
- if (S?.measures?.[I]) {
2814
- const r = S.measures[I];
2815
- if (B.isPostAggregationWindow(r)) {
2812
+ const [n, I] = s.split("."), r = e.get(n);
2813
+ if (r?.measures?.[I]) {
2814
+ const S = r.measures[I];
2815
+ if (B.isPostAggregationWindow(S)) {
2816
2816
  R.push(s);
2817
- const O = B.getWindowBaseMeasure(r, n);
2817
+ const O = B.getWindowBaseMeasure(S, n);
2818
2818
  O && A.add(O);
2819
- } else B.isWindowFunction(r.type) || t.push(s);
2819
+ } else B.isWindowFunction(S.type) || t.push(s);
2820
2820
  }
2821
2821
  }
2822
2822
  return { aggregateMeasures: t, postAggWindowMeasures: R, requiredBaseMeasures: A };
@@ -2891,14 +2891,14 @@ class Nt {
2891
2891
  * Window functions do not require GROUP BY and operate on individual rows.
2892
2892
  */
2893
2893
  buildGroupByFields(E, e, t, R) {
2894
- const A = [], s = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]), n = e.dimensions && e.dimensions.length > 0 || e.timeDimensions && e.timeDimensions.length > 0, I = e.measures && e.measures.length > 0, S = n && !I;
2895
- let r = !1;
2894
+ const A = [], s = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]), n = e.dimensions && e.dimensions.length > 0 || e.timeDimensions && e.timeDimensions.length > 0, I = e.measures && e.measures.length > 0, r = n && !I;
2895
+ let S = !1;
2896
2896
  for (const O of e.measures || []) {
2897
2897
  const [i, a] = O.split("."), o = s.get(i);
2898
2898
  if (o && o.measures && o.measures[a]) {
2899
2899
  const D = o.measures[a];
2900
2900
  if (this.isAggregateFunctionType(D.type) || D.type === "calculated") {
2901
- r = !0;
2901
+ S = !0;
2902
2902
  break;
2903
2903
  }
2904
2904
  if (B.isPostAggregationWindow(D)) {
@@ -2906,14 +2906,14 @@ class Nt {
2906
2906
  if (C) {
2907
2907
  const [P, _] = C.split("."), c = s.get(P)?.measures?.[_];
2908
2908
  if (c && this.isAggregateFunctionType(c.type)) {
2909
- r = !0;
2909
+ S = !0;
2910
2910
  break;
2911
2911
  }
2912
2912
  }
2913
2913
  }
2914
2914
  }
2915
2915
  }
2916
- if (!r && !S)
2916
+ if (!S && !r)
2917
2917
  return [];
2918
2918
  if (e.dimensions)
2919
2919
  for (const O of e.dimensions) {
@@ -2985,9 +2985,9 @@ class It {
2985
2985
  const R = {}, A = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]);
2986
2986
  if (e.dimensions)
2987
2987
  for (const s of e.dimensions) {
2988
- const [n, I] = s.split("."), S = A.get(n);
2989
- if (S && S.dimensions && S.dimensions[I]) {
2990
- const r = S.dimensions[I], O = F(r.sql, t);
2988
+ const [n, I] = s.split("."), r = A.get(n);
2989
+ if (r && r.dimensions && r.dimensions[I]) {
2990
+ const S = r.dimensions[I], O = F(S.sql, t);
2991
2991
  R[s] = N`${O}`.as(s);
2992
2992
  }
2993
2993
  }
@@ -3000,17 +3000,17 @@ class It {
3000
3000
  for (const n of e.measures) {
3001
3001
  const I = s.get(n);
3002
3002
  if (I) {
3003
- const S = I();
3004
- R[n] = N`${S}`.as(n);
3003
+ const r = I();
3004
+ R[n] = N`${r}`.as(n);
3005
3005
  }
3006
3006
  }
3007
3007
  }
3008
3008
  if (e.timeDimensions)
3009
3009
  for (const s of e.timeDimensions) {
3010
- const [n, I] = s.dimension.split("."), S = A.get(n);
3011
- if (S && S.dimensions && S.dimensions[I]) {
3012
- const r = S.dimensions[I], O = this.buildTimeDimensionExpression(
3013
- r.sql,
3010
+ const [n, I] = s.dimension.split("."), r = A.get(n);
3011
+ if (r && r.dimensions && r.dimensions[I]) {
3012
+ const S = r.dimensions[I], O = this.buildTimeDimensionExpression(
3013
+ S.sql,
3014
3014
  s.granularity,
3015
3015
  t
3016
3016
  );
@@ -3062,9 +3062,9 @@ class It {
3062
3062
  buildWhereConditions(E, e, t, R, A) {
3063
3063
  const s = [], n = E instanceof Map ? E : /* @__PURE__ */ new Map([[E.name, E]]), I = /* @__PURE__ */ new Set();
3064
3064
  if (e.filters && e.filters.length > 0)
3065
- for (const S of e.filters) {
3066
- if (A && "member" in S) {
3067
- const [O] = S.member.split(".");
3065
+ for (const r of e.filters) {
3066
+ if (A && "member" in r) {
3067
+ const [O] = r.member.split(".");
3068
3068
  if (n.has(O) && A.has(O) && !I.has(O)) {
3069
3069
  const a = A.get(O);
3070
3070
  s.push(...a), I.add(O);
@@ -3072,23 +3072,23 @@ class It {
3072
3072
  } else if (I.has(O))
3073
3073
  continue;
3074
3074
  }
3075
- const r = this.processFilter(S, n, t, "where", R);
3076
- r && s.push(r);
3075
+ const S = this.processFilter(r, n, t, "where", R);
3076
+ S && s.push(S);
3077
3077
  }
3078
3078
  if (e.timeDimensions)
3079
- for (const S of e.timeDimensions) {
3080
- const [r, O] = S.dimension.split("."), i = n.get(r);
3081
- if (i && i.dimensions[O] && S.dateRange) {
3082
- if (R?.preAggregationCTEs && R.preAggregationCTEs.some((P) => P.cube.name === r))
3079
+ for (const r of e.timeDimensions) {
3080
+ const [S, O] = r.dimension.split("."), i = n.get(S);
3081
+ if (i && i.dimensions[O] && r.dateRange) {
3082
+ if (R?.preAggregationCTEs && R.preAggregationCTEs.some((P) => P.cube.name === S))
3083
3083
  continue;
3084
3084
  if (t.filterCache) {
3085
- const C = _T(S.dimension, S.dateRange), P = t.filterCache.get(C);
3085
+ const C = _T(r.dimension, r.dateRange), P = t.filterCache.get(C);
3086
3086
  if (P) {
3087
3087
  s.push(P);
3088
3088
  continue;
3089
3089
  }
3090
3090
  }
3091
- const a = i.dimensions[O], o = F(a.sql, t), D = this.buildDateRangeCondition(o, S.dateRange);
3091
+ const a = i.dimensions[O], o = F(a.sql, t), D = this.buildDateRangeCondition(o, r.dateRange);
3092
3092
  D && s.push(D);
3093
3093
  }
3094
3094
  }
@@ -3123,11 +3123,11 @@ class It {
3123
3123
  return o.length > 0 ? IE(...o) : null;
3124
3124
  }
3125
3125
  }
3126
- const s = E, [n, I] = s.member.split("."), S = e.get(n);
3127
- if (!S) return null;
3128
- const r = S.dimensions[I], O = S.measures[I], i = r || O;
3126
+ const s = E, [n, I] = s.member.split("."), r = e.get(n);
3127
+ if (!r) return null;
3128
+ const S = r.dimensions[I], O = r.measures[I], i = S || O;
3129
3129
  if (!i) return null;
3130
- if (R === "where" && r) {
3130
+ if (R === "where" && S) {
3131
3131
  if (A?.preAggregationCTEs && A.preAggregationCTEs.some((C) => C.cube.name === n))
3132
3132
  return null;
3133
3133
  const a = ["arrayContains", "arrayOverlaps", "arrayContained"].includes(s.operator);
@@ -3136,7 +3136,7 @@ class It {
3136
3136
  if (C)
3137
3137
  return C;
3138
3138
  }
3139
- const o = a ? typeof r.sql == "function" ? r.sql(t) : r.sql : F(r.sql, t);
3139
+ const o = a ? typeof S.sql == "function" ? S.sql(t) : S.sql : F(S.sql, t);
3140
3140
  return this.buildFilterCondition(
3141
3141
  o,
3142
3142
  s.operator,
@@ -3194,7 +3194,7 @@ class It {
3194
3194
  for (const [A, s] of Object.entries(E.order)) {
3195
3195
  if (!R.includes(A))
3196
3196
  throw new Error(`Cannot order by '${A}': field is not selected in the query`);
3197
- const n = s === "desc" ? xT(N.identifier(A)) : de(N.identifier(A));
3197
+ const n = s === "desc" ? JT(N.identifier(A)) : de(N.identifier(A));
3198
3198
  t.push(n);
3199
3199
  }
3200
3200
  if (E.timeDimensions && E.timeDimensions.length > 0) {
@@ -3216,8 +3216,8 @@ class It {
3216
3216
  for (const A of e.dimensions) {
3217
3217
  const [s, n] = A.split("."), I = R.get(s);
3218
3218
  if (I) {
3219
- const S = I.dimensions[n];
3220
- S && S.type === "number" && t.push(A);
3219
+ const r = I.dimensions[n];
3220
+ r && r.type === "number" && t.push(A);
3221
3221
  }
3222
3222
  }
3223
3223
  return t;
@@ -3286,14 +3286,14 @@ class aE {
3286
3286
  { cube: E, path: [] }
3287
3287
  ], n = /* @__PURE__ */ new Set([E, ...t]);
3288
3288
  for (; s.length > 0; ) {
3289
- const { cube: I, path: S } = s.shift(), r = this.cubes.get(I);
3290
- if (r?.joins)
3291
- for (const [, O] of Object.entries(r.joins)) {
3289
+ const { cube: I, path: r } = s.shift(), S = this.cubes.get(I);
3290
+ if (S?.joins)
3291
+ for (const [, O] of Object.entries(S.joins)) {
3292
3292
  const a = uE(O.targetCube).name;
3293
3293
  if (n.has(a))
3294
3294
  continue;
3295
3295
  const o = [
3296
- ...S,
3296
+ ...r,
3297
3297
  {
3298
3298
  fromCube: I,
3299
3299
  toCube: a,
@@ -3334,7 +3334,7 @@ class aE {
3334
3334
  buildJoinCondition(E, e, t) {
3335
3335
  const R = [];
3336
3336
  for (const A of E.on) {
3337
- const s = e ? N`${N.identifier(e)}.${N.identifier(A.source.name)}` : Se(A.source), n = t ? N`${N.identifier(t)}.${N.identifier(A.target.name)}` : Se(A.target), I = A.as || x;
3337
+ const s = e ? N`${N.identifier(e)}.${N.identifier(A.source.name)}` : Se(A.source), n = t ? N`${N.identifier(t)}.${N.identifier(A.target.name)}` : Se(A.target), I = A.as || J;
3338
3338
  R.push(I(s, n));
3339
3339
  }
3340
3340
  return h(...R);
@@ -3471,7 +3471,7 @@ class PT {
3471
3471
  groupByFields: []
3472
3472
  // Will be built by QueryBuilder
3473
3473
  };
3474
- const I = this.buildJoinPlan(E, n, A, t), S = this.planPreAggregationCTEs(E, n, I, e);
3474
+ const I = this.buildJoinPlan(E, n, A, t), r = this.planPreAggregationCTEs(E, n, I, e);
3475
3475
  return {
3476
3476
  primaryCube: n,
3477
3477
  joinCubes: I,
@@ -3481,7 +3481,7 @@ class PT {
3481
3481
  // Will be built by QueryBuilder
3482
3482
  groupByFields: [],
3483
3483
  // Will be built by QueryBuilder
3484
- preAggregationCTEs: S
3484
+ preAggregationCTEs: r
3485
3485
  };
3486
3486
  }
3487
3487
  /**
@@ -3499,14 +3499,14 @@ class PT {
3499
3499
  * Supports both direct joins and transitive joins through intermediate cubes
3500
3500
  */
3501
3501
  buildJoinPlan(E, e, t, R) {
3502
- const A = this.getResolver(E), s = [], n = /* @__PURE__ */ new Set([e.name]), I = t.filter((S) => S !== e.name);
3503
- for (const S of I) {
3504
- if (n.has(S))
3502
+ const A = this.getResolver(E), s = [], n = /* @__PURE__ */ new Set([e.name]), I = t.filter((r) => r !== e.name);
3503
+ for (const r of I) {
3504
+ if (n.has(r))
3505
3505
  continue;
3506
- const r = A.findPath(e.name, S, n);
3507
- if (!r || r.length === 0)
3508
- throw new Error(`No join path found from '${e.name}' to '${S}'`);
3509
- for (const { toCube: O, joinDef: i } of r) {
3506
+ const S = A.findPath(e.name, r, n);
3507
+ if (!S || S.length === 0)
3508
+ throw new Error(`No join path found from '${e.name}' to '${r}'`);
3509
+ for (const { toCube: O, joinDef: i } of S) {
3510
3510
  if (n.has(O))
3511
3511
  continue;
3512
3512
  const a = E.get(O);
@@ -3564,8 +3564,8 @@ class PT {
3564
3564
  continue;
3565
3565
  const I = R.measures ? R.measures.filter(
3566
3566
  (P) => P.startsWith(s.cube.name + ".")
3567
- ) : [], S = this.extractMeasuresFromFilters(R, s.cube), r = [.../* @__PURE__ */ new Set([...I, ...S])];
3568
- if (r.length === 0)
3567
+ ) : [], r = this.extractMeasuresFromFilters(R, s.cube), S = [.../* @__PURE__ */ new Set([...I, ...r])];
3568
+ if (S.length === 0)
3569
3569
  continue;
3570
3570
  const O = n.on.map((P) => ({
3571
3571
  sourceColumn: P.source.name,
@@ -3573,7 +3573,7 @@ class PT {
3573
3573
  sourceColumnObj: P.source,
3574
3574
  targetColumnObj: P.target
3575
3575
  })), i = this.findPropagatingFilters(R, s.cube, E), a = /* @__PURE__ */ new Map([[s.cube.name, s.cube]]), { aggregateMeasures: o, requiredBaseMeasures: D } = B.categorizeForPostAggregation(
3576
- r,
3576
+ S,
3577
3577
  a
3578
3578
  ), C = [.../* @__PURE__ */ new Set([
3579
3579
  ...o,
@@ -3613,8 +3613,8 @@ class PT {
3613
3613
  const n = E.measures[s];
3614
3614
  if (n.type === "calculated" && n.calculatedSql) {
3615
3615
  const I = this.extractDependenciesFromTemplate(n.calculatedSql, E.name);
3616
- for (const S of I)
3617
- t.has(S) || R.push(S);
3616
+ for (const r of I)
3617
+ t.has(r) || R.push(r);
3618
3618
  }
3619
3619
  }
3620
3620
  return Array.from(t);
@@ -3666,7 +3666,7 @@ class PT {
3666
3666
  if (n?.joins) {
3667
3667
  for (const [, I] of Object.entries(n.joins))
3668
3668
  if (uE(I.targetCube).name === e.name && I.relationship === "hasMany") {
3669
- const r = this.extractFiltersForCube(E.filters, s), O = this.extractTimeDimensionFiltersForCube(E, s), i = [...r, ...O];
3669
+ const S = this.extractFiltersForCube(E.filters, s), O = this.extractTimeDimensionFiltersForCube(E, s), i = [...S, ...O];
3670
3670
  i.length > 0 && I.on.length > 0 && R.push({
3671
3671
  sourceCube: n,
3672
3672
  filters: i,
@@ -3814,16 +3814,16 @@ class PT {
3814
3814
  warnings: []
3815
3815
  };
3816
3816
  if (A.length > 1) {
3817
- const S = A.filter((D) => D !== n);
3818
- for (const D of S)
3817
+ const r = A.filter((D) => D !== n);
3818
+ for (const D of r)
3819
3819
  I.joinPaths.push(
3820
3820
  this.analyzeJoinPath(E, n, D)
3821
3821
  );
3822
- const r = E.get(n);
3823
- r && (I.preAggregations = this.analyzePreAggregations(
3822
+ const S = E.get(n);
3823
+ S && (I.preAggregations = this.analyzePreAggregations(
3824
3824
  E,
3825
- r,
3826
3825
  S,
3826
+ r,
3827
3827
  e
3828
3828
  ));
3829
3829
  const O = I.joinPaths.filter((D) => D.pathFound), i = I.joinPaths.filter((D) => !D.pathFound);
@@ -3858,23 +3858,23 @@ class PT {
3858
3858
  reason: "single_cube",
3859
3859
  explanation: "Only one cube is used in this query"
3860
3860
  };
3861
- const R = [], A = (e.dimensions || []).map((r) => r.split(".")[0]), s = /* @__PURE__ */ new Map();
3862
- for (const r of A)
3863
- s.set(r, (s.get(r) || 0) + 1);
3861
+ const R = [], A = (e.dimensions || []).map((S) => S.split(".")[0]), s = /* @__PURE__ */ new Map();
3862
+ for (const S of A)
3863
+ s.set(S, (s.get(S) || 0) + 1);
3864
3864
  const n = this.getResolver(t);
3865
- for (const r of E) {
3866
- const O = t.get(r), i = s.get(r) || 0, a = O?.joins ? Object.keys(O.joins).length : 0, o = n.canReachAll(r, E);
3865
+ for (const S of E) {
3866
+ const O = t.get(S), i = s.get(S) || 0, a = O?.joins ? Object.keys(O.joins).length : 0, o = n.canReachAll(S, E);
3867
3867
  R.push({
3868
- cubeName: r,
3868
+ cubeName: S,
3869
3869
  dimensionCount: i,
3870
3870
  joinCount: a,
3871
3871
  canReachAll: o
3872
3872
  });
3873
3873
  }
3874
3874
  if (e.dimensions && e.dimensions.length > 0) {
3875
- const r = Math.max(...R.map((O) => O.dimensionCount));
3876
- if (r > 0) {
3877
- const O = R.filter((i) => i.dimensionCount === r).sort((i, a) => i.cubeName.localeCompare(a.cubeName));
3875
+ const S = Math.max(...R.map((O) => O.dimensionCount));
3876
+ if (S > 0) {
3877
+ const O = R.filter((i) => i.dimensionCount === S).sort((i, a) => i.cubeName.localeCompare(a.cubeName));
3878
3878
  for (const i of O)
3879
3879
  if (i.canReachAll)
3880
3880
  return {
@@ -3885,9 +3885,9 @@ class PT {
3885
3885
  };
3886
3886
  }
3887
3887
  }
3888
- const I = R.filter((r) => r.canReachAll);
3888
+ const I = R.filter((S) => S.canReachAll);
3889
3889
  if (I.length > 0) {
3890
- const r = Math.max(...I.map((i) => i.joinCount)), O = I.filter((i) => i.joinCount === r).sort((i, a) => i.cubeName.localeCompare(a.cubeName))[0];
3890
+ const S = Math.max(...I.map((i) => i.joinCount)), O = I.filter((i) => i.joinCount === S).sort((i, a) => i.cubeName.localeCompare(a.cubeName))[0];
3891
3891
  return {
3892
3892
  selectedCube: O.cubeName,
3893
3893
  reason: "most_connected",
@@ -3921,15 +3921,15 @@ class PT {
3921
3921
  visitedCubes: s
3922
3922
  };
3923
3923
  const n = A.map((I) => {
3924
- const S = ne(I.joinDef.relationship, I.joinDef.sqlJoinType), r = I.joinDef.on.map((i) => ({
3924
+ const r = ne(I.joinDef.relationship, I.joinDef.sqlJoinType), S = I.joinDef.on.map((i) => ({
3925
3925
  sourceColumn: i.source.name,
3926
3926
  targetColumn: i.target.name
3927
3927
  })), O = {
3928
3928
  fromCube: I.fromCube,
3929
3929
  toCube: I.toCube,
3930
3930
  relationship: I.joinDef.relationship,
3931
- joinType: S,
3932
- joinColumns: r
3931
+ joinType: r,
3932
+ joinColumns: S
3933
3933
  };
3934
3934
  if (I.joinDef.relationship === "belongsToMany" && I.joinDef.through) {
3935
3935
  const i = I.joinDef.through;
@@ -3964,9 +3964,9 @@ class PT {
3964
3964
  const I = E.get(s);
3965
3965
  if (!I)
3966
3966
  continue;
3967
- const S = R.measures.filter(
3967
+ const r = R.measures.filter(
3968
3968
  (_) => _.startsWith(s + ".")
3969
- ), r = this.extractMeasuresFromFilters(R, I), O = [.../* @__PURE__ */ new Set([...S, ...r])];
3969
+ ), S = this.extractMeasuresFromFilters(R, I), O = [.../* @__PURE__ */ new Set([...r, ...S])];
3970
3970
  if (O.length === 0)
3971
3971
  continue;
3972
3972
  const i = n.on.map((_) => ({
@@ -4015,9 +4015,9 @@ class Ot {
4015
4015
  for (const [M, c] of Object.entries(s.dimensions || {}))
4016
4016
  c.sql === _.targetColumnObj && M !== _.targetColumn && (I[M] = N`${_.targetColumnObj}`.as(M));
4017
4017
  }
4018
- const S = s.name, r = /* @__PURE__ */ new Map([[S, s]]), O = this.queryBuilder.buildResolvedMeasures(
4018
+ const r = s.name, S = /* @__PURE__ */ new Map([[r, s]]), O = this.queryBuilder.buildResolvedMeasures(
4019
4019
  E.measures,
4020
- r,
4020
+ S,
4021
4021
  t
4022
4022
  );
4023
4023
  for (const _ of E.measures) {
@@ -4030,7 +4030,7 @@ class Ot {
4030
4030
  if (e.dimensions)
4031
4031
  for (const _ of e.dimensions) {
4032
4032
  const [M, c] = _.split(".");
4033
- if (M === S && s.dimensions && s.dimensions[c]) {
4033
+ if (M === r && s.dimensions && s.dimensions[c]) {
4034
4034
  const d = s.dimensions[c], p = this.queryBuilder.buildMeasureExpression({ sql: d.sql, type: "number" }, t);
4035
4035
  I[c] = N`${p}`.as(c);
4036
4036
  }
@@ -4038,7 +4038,7 @@ class Ot {
4038
4038
  if (e.timeDimensions)
4039
4039
  for (const _ of e.timeDimensions) {
4040
4040
  const [M, c] = _.dimension.split(".");
4041
- if (M === S && s.dimensions && s.dimensions[c]) {
4041
+ if (M === r && s.dimensions && s.dimensions[c]) {
4042
4042
  const d = s.dimensions[c], p = this.queryBuilder.buildTimeDimensionExpression(d.sql, _.granularity, t);
4043
4043
  I[c] = N`${p}`.as(c);
4044
4044
  }
@@ -4053,7 +4053,7 @@ class Ot {
4053
4053
  if (e.timeDimensions)
4054
4054
  for (const _ of e.timeDimensions) {
4055
4055
  const [M, c] = _.dimension.split(".");
4056
- if (M === S && s.dimensions && s.dimensions[c] && _.dateRange) {
4056
+ if (M === r && s.dimensions && s.dimensions[c] && _.dateRange) {
4057
4057
  const d = s.dimensions[c], p = this.queryBuilder.buildMeasureExpression({ sql: d.sql, type: "number" }, t), f = this.queryBuilder.buildDateRangeCondition(p, _.dateRange);
4058
4058
  f && D.push(f);
4059
4059
  }
@@ -4062,7 +4062,7 @@ class Ot {
4062
4062
  for (const _ of e.filters)
4063
4063
  if (!("and" in _) && !("or" in _) && "member" in _ && "operator" in _) {
4064
4064
  const M = _, [c, d] = M.member.split(".");
4065
- if (c === S && s.dimensions && s.dimensions[d]) {
4065
+ if (c === r && s.dimensions && s.dimensions[d]) {
4066
4066
  const p = s.dimensions[d];
4067
4067
  if (M.operator === "inDateRange") {
4068
4068
  const f = this.queryBuilder.buildMeasureExpression({ sql: p.sql, type: "number" }, t), $ = this.queryBuilder.buildDateRangeCondition(f, M.values);
@@ -4090,7 +4090,7 @@ class Ot {
4090
4090
  if (e.dimensions)
4091
4091
  for (const _ of e.dimensions) {
4092
4092
  const [M, c] = _.split(".");
4093
- if (M === S && s.dimensions && s.dimensions[c]) {
4093
+ if (M === r && s.dimensions && s.dimensions[c]) {
4094
4094
  const d = s.dimensions[c], p = F(d.sql, t);
4095
4095
  P.push(p);
4096
4096
  }
@@ -4098,7 +4098,7 @@ class Ot {
4098
4098
  if (e.timeDimensions)
4099
4099
  for (const _ of e.timeDimensions) {
4100
4100
  const [M, c] = _.dimension.split(".");
4101
- if (M === S && s.dimensions && s.dimensions[c]) {
4101
+ if (M === r && s.dimensions && s.dimensions[c]) {
4102
4102
  const d = s.dimensions[c], p = this.queryBuilder.buildTimeDimensionExpression(d.sql, _.granularity, t);
4103
4103
  P.push(p);
4104
4104
  }
@@ -4118,7 +4118,7 @@ class Ot {
4118
4118
  const A = [];
4119
4119
  for (const s of R.joinKeys) {
4120
4120
  const n = s.sourceColumnObj || N.identifier(s.sourceColumn), I = N`${N.identifier(e)}.${N.identifier(s.targetColumn)}`;
4121
- A.push(x(n, I));
4121
+ A.push(J(n, I));
4122
4122
  }
4123
4123
  return A.length === 1 ? A[0] : h(...A);
4124
4124
  }
@@ -4140,25 +4140,25 @@ class Ot {
4140
4140
  else {
4141
4141
  const I = {
4142
4142
  filters: E.filters
4143
- }, S = /* @__PURE__ */ new Map([[t.name, t]]), r = this.queryBuilder.buildWhereConditions(
4144
- S,
4143
+ }, r = /* @__PURE__ */ new Map([[t.name, t]]), S = this.queryBuilder.buildWhereConditions(
4144
+ r,
4145
4145
  I,
4146
4146
  e
4147
4147
  );
4148
- A.push(...r);
4148
+ A.push(...S);
4149
4149
  }
4150
4150
  if (A.length === 0)
4151
4151
  return null;
4152
4152
  const s = A.length === 1 ? A[0] : h(...A), n = E.joinConditions;
4153
4153
  if (n.length === 1) {
4154
- const { source: I, target: S } = n[0], r = e.db.select({ pk: I }).from(R.from).where(s);
4155
- return N`${S} IN ${r}`;
4154
+ const { source: I, target: r } = n[0], S = e.db.select({ pk: I }).from(R.from).where(s);
4155
+ return N`${r} IN ${S}`;
4156
4156
  } else {
4157
- const I = n.map((O) => x(O.source, O.target)), S = h(
4157
+ const I = n.map((O) => J(O.source, O.target)), r = h(
4158
4158
  ...I,
4159
4159
  s
4160
- ), r = e.db.select({ one: N`1` }).from(R.from).where(S);
4161
- return N`EXISTS ${r}`;
4160
+ ), S = e.db.select({ one: N`1` }).from(R.from).where(r);
4161
+ return N`EXISTS ${S}`;
4162
4162
  }
4163
4163
  }
4164
4164
  }
@@ -4251,19 +4251,19 @@ function Lt(T, E) {
4251
4251
  const { timeDimensionKey: e, granularity: t, dateRange: R, fillValue: A, measures: s, dimensions: n } = E, I = it(R[0], R[1], t);
4252
4252
  if (I.length === 0)
4253
4253
  return T;
4254
- const S = /* @__PURE__ */ new Map();
4254
+ const r = /* @__PURE__ */ new Map();
4255
4255
  for (const O of T) {
4256
4256
  const i = Ct(O, n), a = ot(O[e]);
4257
- S.has(i) || S.set(i, /* @__PURE__ */ new Map()), S.get(i).set(a, O);
4257
+ r.has(i) || r.set(i, /* @__PURE__ */ new Map()), r.get(i).set(a, O);
4258
4258
  }
4259
- S.size === 0 && n.length === 0 && S.set("__all__", /* @__PURE__ */ new Map());
4260
- const r = [];
4261
- for (const [O, i] of S) {
4259
+ r.size === 0 && n.length === 0 && r.set("__all__", /* @__PURE__ */ new Map());
4260
+ const S = [];
4261
+ for (const [O, i] of r) {
4262
4262
  const a = i.size > 0 ? i.values().next().value : null;
4263
4263
  for (const o of I) {
4264
4264
  const D = o.toISOString(), C = i.get(D);
4265
4265
  if (C)
4266
- r.push(C);
4266
+ S.push(C);
4267
4267
  else {
4268
4268
  const P = {
4269
4269
  [e]: D
@@ -4273,11 +4273,11 @@ function Lt(T, E) {
4273
4273
  P[_] = a[_];
4274
4274
  for (const _ of s)
4275
4275
  P[_] = A;
4276
- r.push(P);
4276
+ S.push(P);
4277
4277
  }
4278
4278
  }
4279
4279
  }
4280
- return r;
4280
+ return S;
4281
4281
  }
4282
4282
  function _t(T) {
4283
4283
  if (!T)
@@ -4295,26 +4295,26 @@ function He(T, E, e) {
4295
4295
  if (!E.timeDimensions || E.timeDimensions.length === 0)
4296
4296
  return T;
4297
4297
  const t = E.timeDimensions.filter((I) => {
4298
- const S = I.fillMissingDates !== !1, r = I.granularity && I.dateRange;
4299
- return S && r;
4298
+ const r = I.fillMissingDates !== !1, S = I.granularity && I.dateRange;
4299
+ return r && S;
4300
4300
  });
4301
4301
  if (t.length === 0)
4302
4302
  return T;
4303
4303
  const R = E.fillMissingDatesValue === void 0 ? 0 : E.fillMissingDatesValue, A = new Set(E.timeDimensions.map((I) => I.dimension)), s = (E.dimensions || []).filter((I) => !A.has(I));
4304
4304
  let n = T;
4305
4305
  for (const I of t) {
4306
- const S = _t(I.dateRange);
4307
- if (!S)
4306
+ const r = _t(I.dateRange);
4307
+ if (!r)
4308
4308
  continue;
4309
- const r = {
4309
+ const S = {
4310
4310
  timeDimensionKey: I.dimension,
4311
4311
  granularity: I.granularity,
4312
- dateRange: S,
4312
+ dateRange: r,
4313
4313
  fillValue: R,
4314
4314
  measures: e,
4315
4315
  dimensions: s
4316
4316
  };
4317
- n = Lt(n, r);
4317
+ n = Lt(n, S);
4318
4318
  }
4319
4319
  return n;
4320
4320
  }
@@ -4353,9 +4353,9 @@ class Dt {
4353
4353
  if (I)
4354
4354
  A = I.start, s = I.end, n = R;
4355
4355
  else {
4356
- const S = new Date(R);
4357
- if (!isNaN(S.getTime()))
4358
- A = new Date(S), A.setUTCHours(0, 0, 0, 0), s = new Date(S), s.setUTCHours(23, 59, 59, 999), n = R;
4356
+ const r = new Date(R);
4357
+ if (!isNaN(r.getTime()))
4358
+ A = new Date(r), A.setUTCHours(0, 0, 0, 0), s = new Date(r), s.setUTCHours(23, 59, 59, 999), n = R;
4359
4359
  else
4360
4360
  continue;
4361
4361
  }
@@ -4409,12 +4409,12 @@ class Dt {
4409
4409
  case "week":
4410
4410
  return Math.floor((s - A) / (1e3 * 60 * 60 * 24 * 7));
4411
4411
  case "month": {
4412
- const n = e.getUTCFullYear(), I = e.getUTCMonth(), S = R.getUTCFullYear(), r = R.getUTCMonth();
4413
- return (S - n) * 12 + (r - I);
4412
+ const n = e.getUTCFullYear(), I = e.getUTCMonth(), r = R.getUTCFullYear(), S = R.getUTCMonth();
4413
+ return (r - n) * 12 + (S - I);
4414
4414
  }
4415
4415
  case "quarter": {
4416
- const n = e.getUTCFullYear(), I = Math.floor(e.getUTCMonth() / 3), S = R.getUTCFullYear(), r = Math.floor(R.getUTCMonth() / 3);
4417
- return (S - n) * 4 + (r - I);
4416
+ const n = e.getUTCFullYear(), I = Math.floor(e.getUTCMonth() / 3), r = R.getUTCFullYear(), S = Math.floor(R.getUTCMonth() / 3);
4417
+ return (r - n) * 4 + (S - I);
4418
4418
  }
4419
4419
  case "year":
4420
4420
  return R.getUTCFullYear() - e.getUTCFullYear();
@@ -4458,14 +4458,14 @@ class Dt {
4458
4458
  timeDimensions: {}
4459
4459
  };
4460
4460
  const s = E.map((I) => I.period);
4461
- for (const { result: I, period: S } of E) {
4462
- const r = this.addPeriodMetadata(
4461
+ for (const { result: I, period: r } of E) {
4462
+ const S = this.addPeriodMetadata(
4463
4463
  I.data,
4464
- S,
4464
+ r,
4465
4465
  e.dimension,
4466
4466
  t
4467
4467
  );
4468
- R.push(...r), A = {
4468
+ R.push(...S), A = {
4469
4469
  measures: { ...A.measures, ...I.annotation.measures },
4470
4470
  dimensions: { ...A.dimensions, ...I.annotation.dimensions },
4471
4471
  segments: { ...A.segments, ...I.annotation.segments },
@@ -4552,17 +4552,17 @@ class Pt {
4552
4552
  let s;
4553
4553
  "cube" in A && A.cube ? s = A.cube : typeof E.bindingKey == "string" && ([s] = E.bindingKey.split("."));
4554
4554
  const n = s ? new aE(e) : null, I = Array.isArray(A.filter) ? A.filter : [A.filter];
4555
- for (const S of I)
4556
- if ("member" in S) {
4557
- const [r, O] = S.member.split("."), i = e.get(r);
4555
+ for (const r of I)
4556
+ if ("member" in r) {
4557
+ const [S, O] = r.member.split("."), i = e.get(S);
4558
4558
  if (!i)
4559
- t.push(`Step ${R} filter cube not found: ${r}`);
4559
+ t.push(`Step ${R} filter cube not found: ${S}`);
4560
4560
  else if (i.dimensions?.[O] || (i.measures?.[O] ? t.push(
4561
- `Step ${R} filter '${r}.${O}' is a measure. Funnel step filters only support dimensions, not measures.`
4562
- ) : t.push(`Step ${R} filter member not found: ${O} in cube ${r}`)), s && r !== s && n) {
4563
- const a = n.findPath(s, r);
4561
+ `Step ${R} filter '${S}.${O}' is a measure. Funnel step filters only support dimensions, not measures.`
4562
+ ) : t.push(`Step ${R} filter member not found: ${O} in cube ${S}`)), s && S !== s && n) {
4563
+ const a = n.findPath(s, S);
4564
4564
  (!a || a.length === 0) && t.push(
4565
- `Step ${R} filter '${r}.${O}' requires a join from '${s}' but no join path was found. Define a join relationship between these cubes.`
4565
+ `Step ${R} filter '${S}.${O}' requires a join from '${s}' but no join path was found. Define a join relationship between these cubes.`
4566
4566
  );
4567
4567
  }
4568
4568
  }
@@ -4583,9 +4583,9 @@ class Pt {
4583
4583
  */
4584
4584
  buildFunnelQuery(E, e, t) {
4585
4585
  const R = this.resolveSteps(E, e, t), A = [];
4586
- for (let S = 0; S < R.length; S++) {
4587
- const r = S > 0 ? A[S - 1] : void 0;
4588
- A.push(this.buildStepCTE(R[S], t, r));
4586
+ for (let r = 0; r < R.length; r++) {
4587
+ const S = r > 0 ? A[r - 1] : void 0;
4588
+ A.push(this.buildStepCTE(R[r], t, S));
4589
4589
  }
4590
4590
  const s = this.buildFunnelResultsCTE(A, R, E, t), n = this.buildAggregationCTE(s, A, R, E, t), I = [...A, s, n];
4591
4591
  return t.db.with(...I).select().from(n);
@@ -4598,14 +4598,14 @@ class Pt {
4598
4598
  return [];
4599
4599
  const t = E[0], R = [], A = Number(t.step_0_count) || 0;
4600
4600
  for (let s = 0; s < e.steps.length; s++) {
4601
- const n = e.steps[s], I = Number(t[`step_${s}_count`]) || 0, S = s > 0 && Number(t[`step_${s - 1}_count`]) || 0, r = {
4601
+ const n = e.steps[s], I = Number(t[`step_${s}_count`]) || 0, r = s > 0 && Number(t[`step_${s - 1}_count`]) || 0, S = {
4602
4602
  step: n.name,
4603
4603
  stepIndex: s,
4604
4604
  count: I,
4605
- conversionRate: s === 0 ? null : S > 0 ? I / S : 0,
4605
+ conversionRate: s === 0 ? null : r > 0 ? I / r : 0,
4606
4606
  cumulativeConversionRate: A > 0 ? I / A : 0
4607
4607
  };
4608
- e.includeTimeMetrics && s > 0 && (r.avgSecondsToConvert = t[`step_${s}_avg_seconds`] !== null ? Number(t[`step_${s}_avg_seconds`]) : null, r.minSecondsToConvert = t[`step_${s}_min_seconds`] !== null ? Number(t[`step_${s}_min_seconds`]) : null, r.maxSecondsToConvert = t[`step_${s}_max_seconds`] !== null ? Number(t[`step_${s}_max_seconds`]) : null, t[`step_${s}_median_seconds`] !== void 0 && (r.medianSecondsToConvert = t[`step_${s}_median_seconds`] !== null ? Number(t[`step_${s}_median_seconds`]) : null), t[`step_${s}_p90_seconds`] !== void 0 && (r.p90SecondsToConvert = t[`step_${s}_p90_seconds`] !== null ? Number(t[`step_${s}_p90_seconds`]) : null)), R.push(r);
4608
+ e.includeTimeMetrics && s > 0 && (S.avgSecondsToConvert = t[`step_${s}_avg_seconds`] !== null ? Number(t[`step_${s}_avg_seconds`]) : null, S.minSecondsToConvert = t[`step_${s}_min_seconds`] !== null ? Number(t[`step_${s}_min_seconds`]) : null, S.maxSecondsToConvert = t[`step_${s}_max_seconds`] !== null ? Number(t[`step_${s}_max_seconds`]) : null, t[`step_${s}_median_seconds`] !== void 0 && (S.medianSecondsToConvert = t[`step_${s}_median_seconds`] !== null ? Number(t[`step_${s}_median_seconds`]) : null), t[`step_${s}_p90_seconds`] !== void 0 && (S.p90SecondsToConvert = t[`step_${s}_p90_seconds`] !== null ? Number(t[`step_${s}_p90_seconds`]) : null)), R.push(S);
4609
4609
  }
4610
4610
  return R;
4611
4611
  }
@@ -4641,7 +4641,7 @@ class Pt {
4641
4641
  resolveSteps(E, e, t) {
4642
4642
  const R = new aE(e);
4643
4643
  return E.steps.map((A, s) => {
4644
- const n = this.resolveCubeForStep(A, E, e), I = this.resolveBindingKey(E, n, t), S = this.resolveTimeDimension(E, n, t), r = this.buildStepFilters(A, n, e, t), O = this.extractFilterCubeNames(A), i = [];
4644
+ const n = this.resolveCubeForStep(A, E, e), I = this.resolveBindingKey(E, n, t), r = this.resolveTimeDimension(E, n, t), S = this.buildStepFilters(A, n, e, t), O = this.extractFilterCubeNames(A), i = [];
4645
4645
  for (const a of O)
4646
4646
  if (a !== n.name) {
4647
4647
  const o = e.get(a);
@@ -4655,8 +4655,8 @@ class Pt {
4655
4655
  index: s,
4656
4656
  cube: n,
4657
4657
  bindingKeyExpr: I,
4658
- timeExpr: S,
4659
- filterConditions: r,
4658
+ timeExpr: r,
4659
+ filterConditions: S,
4660
4660
  timeToConvert: A.timeToConvert,
4661
4661
  joinedCubes: i
4662
4662
  };
@@ -4763,8 +4763,8 @@ class Pt {
4763
4763
  }
4764
4764
  return D.length === 0 ? null : D.length === 1 ? D[0] : C ? h(...D) : N`(${N.join(D, N` OR `)})`;
4765
4765
  }
4766
- const n = E, [I, S] = n.member.split("."), r = n.dateRange !== void 0;
4767
- if (n.operator !== "set" && n.operator !== "notSet" && !r && (!n.values || n.values.length === 0 || n.values[0] === void 0 || n.values[0] === ""))
4766
+ const n = E, [I, r] = n.member.split("."), S = n.dateRange !== void 0;
4767
+ if (n.operator !== "set" && n.operator !== "notSet" && !S && (!n.values || n.values.length === 0 || n.values[0] === void 0 || n.values[0] === ""))
4768
4768
  return null;
4769
4769
  const i = t.get(I);
4770
4770
  if (!i)
@@ -4773,10 +4773,10 @@ class Pt {
4773
4773
  const C = new aE(t).findPath(e.name, I);
4774
4774
  if (!C || C.length === 0)
4775
4775
  return console.warn(
4776
- `Funnel filter: Cannot filter by '${I}.${S}' in step using '${e.name}'. No join path found. Filter will be skipped.`
4776
+ `Funnel filter: Cannot filter by '${I}.${r}' in step using '${e.name}'. No join path found. Filter will be skipped.`
4777
4777
  ), null;
4778
4778
  }
4779
- const a = i.dimensions?.[S];
4779
+ const a = i.dimensions?.[r];
4780
4780
  if (!a) return null;
4781
4781
  const o = F(a.sql, R);
4782
4782
  return this.filterBuilder.buildFilterCondition(
@@ -4836,24 +4836,24 @@ class Pt {
4836
4836
  const R = `step_${E.index}`, A = `step_${E.index - 1}`, s = E.cube.sql(e), n = [];
4837
4837
  s.where && n.push(s.where), n.push(...E.filterConditions);
4838
4838
  const I = N`${N.identifier(A)}.step_time`;
4839
- let S = N`${E.timeExpr} > ${I}`;
4839
+ let r = N`${E.timeExpr} > ${I}`;
4840
4840
  if (E.timeToConvert) {
4841
4841
  const O = this.databaseAdapter.buildDateAddInterval(I, E.timeToConvert);
4842
- S = N`${S} AND ${E.timeExpr} <= ${O}`;
4842
+ r = N`${r} AND ${E.timeExpr} <= ${O}`;
4843
4843
  }
4844
- n.push(S);
4845
- let r = e.db.select({
4844
+ n.push(r);
4845
+ let S = e.db.select({
4846
4846
  binding_key: N`${E.bindingKeyExpr}`.as("binding_key"),
4847
4847
  step_time: N`MIN(${E.timeExpr})`.as("step_time")
4848
4848
  }).from(s.from).innerJoin(
4849
4849
  t,
4850
4850
  N`${E.bindingKeyExpr} = ${N.identifier(A)}.binding_key`
4851
4851
  );
4852
- if (r = this.addCrossJoinsToQuery(r, E, e, n), n.length > 0) {
4852
+ if (S = this.addCrossJoinsToQuery(S, E, e, n), n.length > 0) {
4853
4853
  const O = n.length === 1 ? n[0] : h(...n);
4854
- r = r.where(O);
4854
+ S = S.where(O);
4855
4855
  }
4856
- return r = r.groupBy(E.bindingKeyExpr), e.db.$with(R).as(r);
4856
+ return S = S.groupBy(E.bindingKeyExpr), e.db.$with(R).as(S);
4857
4857
  }
4858
4858
  /**
4859
4859
  * Helper to add cross-cube JOINs to a step query
@@ -4866,9 +4866,9 @@ class Pt {
4866
4866
  for (const s of A.joinPath) {
4867
4867
  const n = s.joinDef, I = [];
4868
4868
  for (const i of n.on)
4869
- i.as ? I.push(i.as(i.source, i.target)) : I.push(x(i.source, i.target));
4870
- const S = I.length === 1 ? I[0] : h(...I), O = A.cube.sql(t);
4871
- E = E.leftJoin(O.from, S), O.where && R.push(O.where);
4869
+ i.as ? I.push(i.as(i.source, i.target)) : I.push(J(i.source, i.target));
4870
+ const r = I.length === 1 ? I[0] : h(...I), O = A.cube.sql(t);
4871
+ E = E.leftJoin(O.from, r), O.where && R.push(O.where);
4872
4872
  }
4873
4873
  return E;
4874
4874
  }
@@ -4886,14 +4886,14 @@ class Pt {
4886
4886
  binding_key: N`s0.binding_key`,
4887
4887
  step_0_time: N`s0.step_time`
4888
4888
  };
4889
- for (let S = 1; S < e.length; S++)
4890
- A[`step_${S}_time`] = N`s${N.raw(String(S))}.step_time`;
4889
+ for (let r = 1; r < e.length; r++)
4890
+ A[`step_${r}_time`] = N`s${N.raw(String(r))}.step_time`;
4891
4891
  let s = N`${N.identifier("step_0")} s0`;
4892
- for (let S = 1; S < e.length; S++)
4892
+ for (let r = 1; r < e.length; r++)
4893
4893
  s = N`${s}
4894
- LEFT JOIN ${N.identifier(`step_${S}`)} s${N.raw(String(S))} ON s0.binding_key = s${N.raw(String(S))}.binding_key`;
4894
+ LEFT JOIN ${N.identifier(`step_${r}`)} s${N.raw(String(r))} ON s0.binding_key = s${N.raw(String(r))}.binding_key`;
4895
4895
  const n = Object.entries(A).map(
4896
- ([S, r]) => N`${r} AS ${N.identifier(S)}`
4896
+ ([r, S]) => N`${S} AS ${N.identifier(r)}`
4897
4897
  ), I = N`SELECT ${N.join(n, N`, `)} FROM ${s}`;
4898
4898
  return R.db.$with("funnel_joined").as(
4899
4899
  R.db.select({ _all: N`*` }).from(N`(${I}) as _inner`)
@@ -4921,15 +4921,15 @@ class Pt {
4921
4921
  s[`step_${I}_count`] = N`COUNT(${N.identifier(`step_${I}_time`)})`.as(`step_${I}_count`);
4922
4922
  if (R.includeTimeMetrics)
4923
4923
  for (let I = 1; I < t.length; I++) {
4924
- const S = N.identifier(`step_${I}_time`), r = N.identifier(`step_${I - 1}_time`), O = this.databaseAdapter.buildTimeDifferenceSeconds(
4925
- N`${S}`,
4926
- N`${r}`
4927
- ), i = N`${S} IS NOT NULL`;
4924
+ const r = N.identifier(`step_${I}_time`), S = N.identifier(`step_${I - 1}_time`), O = this.databaseAdapter.buildTimeDifferenceSeconds(
4925
+ N`${r}`,
4926
+ N`${S}`
4927
+ ), i = N`${r} IS NOT NULL`;
4928
4928
  s[`step_${I}_avg_seconds`] = this.databaseAdapter.buildConditionalAggregation("avg", O, i).as(`step_${I}_avg_seconds`), s[`step_${I}_min_seconds`] = this.databaseAdapter.buildConditionalAggregation("min", O, i).as(`step_${I}_min_seconds`), s[`step_${I}_max_seconds`] = this.databaseAdapter.buildConditionalAggregation("max", O, i).as(`step_${I}_max_seconds`);
4929
4929
  const a = this.databaseAdapter.buildPercentile(O, 50);
4930
- a && (s[`step_${I}_median_seconds`] = N`(SELECT ${a} FROM ${N.identifier("funnel_joined")} WHERE ${S} IS NOT NULL)`.as(`step_${I}_median_seconds`));
4930
+ a && (s[`step_${I}_median_seconds`] = N`(SELECT ${a} FROM ${N.identifier("funnel_joined")} WHERE ${r} IS NOT NULL)`.as(`step_${I}_median_seconds`));
4931
4931
  const o = this.databaseAdapter.buildPercentile(O, 90);
4932
- o && (s[`step_${I}_p90_seconds`] = N`(SELECT ${o} FROM ${N.identifier("funnel_joined")} WHERE ${S} IS NOT NULL)`.as(`step_${I}_p90_seconds`));
4932
+ o && (s[`step_${I}_p90_seconds`] = N`(SELECT ${o} FROM ${N.identifier("funnel_joined")} WHERE ${r} IS NOT NULL)`.as(`step_${I}_p90_seconds`));
4933
4933
  }
4934
4934
  const n = A.db.select(s).from(E);
4935
4935
  return A.db.$with("funnel_metrics").as(n);
@@ -5008,7 +5008,7 @@ class NE {
5008
5008
  this.preloadFilterCache(e, A, E, s);
5009
5009
  const n = this.queryPlanner.createQueryPlan(E, e, s);
5010
5010
  this.validateSecurityContext(n, s);
5011
- const I = this.buildUnifiedQuery(n, e, s), S = this.queryBuilder.collectNumericFields(E, e), r = await this.dbExecutor.execute(I, S), O = Array.isArray(r) ? r.map((C) => {
5011
+ const I = this.buildUnifiedQuery(n, e, s), r = this.queryBuilder.collectNumericFields(E, e), S = await this.dbExecutor.execute(I, r), O = Array.isArray(S) ? S.map((C) => {
5012
5012
  const P = { ...C };
5013
5013
  if (e.timeDimensions) {
5014
5014
  for (const _ of e.timeDimensions)
@@ -5022,7 +5022,7 @@ class NE {
5022
5022
  }
5023
5023
  }
5024
5024
  return P;
5025
- }) : [r], i = e.measures || [], a = He(O, e, i), o = this.generateAnnotations(n, e), D = {
5025
+ }) : [S], i = e.measures || [], a = He(O, e, i), o = this.generateAnnotations(n, e), D = {
5026
5026
  data: a,
5027
5027
  annotation: o
5028
5028
  };
@@ -5097,18 +5097,18 @@ class NE {
5097
5097
  );
5098
5098
  if (A.length < 2)
5099
5099
  throw new Error("compareDateRange requires at least 2 periods");
5100
- const s = R.granularity || "day", n = A.map(async (r) => {
5101
- const O = this.comparisonQueryBuilder.createPeriodQuery(e, r);
5102
- return { result: await this.executeStandardQuery(E, O, t), period: r };
5103
- }), I = await Promise.all(n), S = this.comparisonQueryBuilder.mergeComparisonResults(
5100
+ const s = R.granularity || "day", n = A.map(async (S) => {
5101
+ const O = this.comparisonQueryBuilder.createPeriodQuery(e, S);
5102
+ return { result: await this.executeStandardQuery(E, O, t), period: S };
5103
+ }), I = await Promise.all(n), r = this.comparisonQueryBuilder.mergeComparisonResults(
5104
5104
  I,
5105
5105
  R,
5106
5106
  s
5107
5107
  );
5108
- return S.data = this.comparisonQueryBuilder.sortComparisonResults(
5109
- S.data,
5108
+ return r.data = this.comparisonQueryBuilder.sortComparisonResults(
5109
+ r.data,
5110
5110
  R.dimension
5111
- ), S;
5111
+ ), r;
5112
5112
  }
5113
5113
  /**
5114
5114
  * Execute a funnel query with caching support
@@ -5148,13 +5148,13 @@ class NE {
5148
5148
  db: this.dbExecutor.db,
5149
5149
  schema: this.dbExecutor.schema,
5150
5150
  securityContext: t
5151
- }, I = await this.funnelQueryBuilder.buildFunnelQuery(R, E, s), S = this.funnelQueryBuilder.transformResult(I, R), r = {
5151
+ }, I = await this.funnelQueryBuilder.buildFunnelQuery(R, E, s), r = this.funnelQueryBuilder.transformResult(I, R), S = {
5152
5152
  measures: {},
5153
5153
  dimensions: {},
5154
5154
  segments: {},
5155
5155
  timeDimensions: {}
5156
5156
  };
5157
- return r.funnel = {
5157
+ return S.funnel = {
5158
5158
  config: R,
5159
5159
  steps: R.steps.map((O, i) => ({
5160
5160
  name: O.name,
@@ -5162,8 +5162,8 @@ class NE {
5162
5162
  timeToConvert: O.timeToConvert
5163
5163
  }))
5164
5164
  }, {
5165
- data: S,
5166
- annotation: r
5165
+ data: r,
5166
+ annotation: S
5167
5167
  };
5168
5168
  }
5169
5169
  /**
@@ -5178,7 +5178,7 @@ class NE {
5178
5178
  filterCache: R
5179
5179
  };
5180
5180
  this.preloadFilterCache(e, R, E, A);
5181
- const s = this.queryPlanner.createQueryPlan(E, e, A), n = this.buildUnifiedQuery(s, e, A), I = this.queryBuilder.collectNumericFields(E, e), S = await this.dbExecutor.execute(n, I), r = Array.isArray(S) ? S.map((o) => {
5181
+ const s = this.queryPlanner.createQueryPlan(E, e, A), n = this.buildUnifiedQuery(s, e, A), I = this.queryBuilder.collectNumericFields(E, e), r = await this.dbExecutor.execute(n, I), S = Array.isArray(r) ? r.map((o) => {
5182
5182
  const D = { ...o };
5183
5183
  if (e.timeDimensions) {
5184
5184
  for (const C of e.timeDimensions)
@@ -5192,7 +5192,7 @@ class NE {
5192
5192
  }
5193
5193
  }
5194
5194
  return D;
5195
- }) : [S], O = e.measures || [], i = He(r, e, O), a = this.generateAnnotations(s, e);
5195
+ }) : [r], O = e.measures || [], i = He(S, e, O), a = this.generateAnnotations(s, e);
5196
5196
  return {
5197
5197
  data: i,
5198
5198
  annotation: a
@@ -5256,7 +5256,7 @@ class NE {
5256
5256
  const P = this.cteBuilder.buildPreAggregationCTE(C, e, t, E, R);
5257
5257
  P && (A.push(P), s.set(C.cube.name, C.cteAlias));
5258
5258
  }
5259
- const n = E.primaryCube.sql(t), S = { ...this.queryBuilder.buildSelections(
5259
+ const n = E.primaryCube.sql(t), r = { ...this.queryBuilder.buildSelections(
5260
5260
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
5261
5261
  // Single cube
5262
5262
  e,
@@ -5266,7 +5266,7 @@ class NE {
5266
5266
  for (const C of E.preAggregationCTEs) {
5267
5267
  const P = C.cube.name;
5268
5268
  for (const _ of C.measures)
5269
- if (S[_]) {
5269
+ if (r[_]) {
5270
5270
  const [, M] = _.split("."), c = this.getCubesFromPlan(E).get(P);
5271
5271
  if (c && c.measures && c.measures[M]) {
5272
5272
  const d = c.measures[M], p = N`${N.identifier(C.cteAlias)}.${N.identifier(M)}`;
@@ -5302,20 +5302,20 @@ class NE {
5302
5302
  default:
5303
5303
  f = w(p);
5304
5304
  }
5305
- S[_] = N`${f}`.as(_);
5305
+ r[_] = N`${f}`.as(_);
5306
5306
  }
5307
5307
  }
5308
- for (const _ in S) {
5308
+ for (const _ in r) {
5309
5309
  const [M, c] = _.split(".");
5310
5310
  if (M === P) {
5311
5311
  const d = this.getCubesFromPlan(E).get(P), p = d && d.dimensions?.[c], f = _.startsWith(P + ".");
5312
5312
  if (p || f) {
5313
- let $ = C.joinKeys.find((J) => J.targetColumn === c);
5313
+ let $ = C.joinKeys.find((x) => x.targetColumn === c);
5314
5314
  if (!$ && d?.dimensions?.[c]) {
5315
- const J = d.dimensions[c].sql;
5316
- $ = C.joinKeys.find((mE) => mE.targetColumnObj === J);
5315
+ const x = d.dimensions[c].sql;
5316
+ $ = C.joinKeys.find((mE) => mE.targetColumnObj === x);
5317
5317
  }
5318
- $ ? S[_] = N`${N.identifier(C.cteAlias)}.${N.identifier(c)}`.as(_) : f && d?.dimensions?.[c] && (S[_] = N`${N.identifier(C.cteAlias)}.${N.identifier(c)}`.as(_));
5318
+ $ ? r[_] = N`${N.identifier(C.cteAlias)}.${N.identifier(c)}`.as(_) : f && d?.dimensions?.[c] && (r[_] = N`${N.identifier(C.cteAlias)}.${N.identifier(c)}`.as(_));
5319
5319
  }
5320
5320
  }
5321
5321
  }
@@ -5329,9 +5329,9 @@ class NE {
5329
5329
  if (B.isPostAggregationWindow(d)) {
5330
5330
  const p = B.getWindowBaseMeasure(d, _);
5331
5331
  if (p) {
5332
- const [f, $] = p.split("."), J = C.get(f);
5333
- if (J?.measures?.[$]) {
5334
- const mE = J.measures[$], Ce = E.preAggregationCTEs?.find(
5332
+ const [f, $] = p.split("."), x = C.get(f);
5333
+ if (x?.measures?.[$]) {
5334
+ const mE = x.measures[$], Ce = E.preAggregationCTEs?.find(
5335
5335
  (rE) => rE.cube?.name === f && rE.measures?.includes(p)
5336
5336
  );
5337
5337
  let SE;
@@ -5339,8 +5339,8 @@ class NE {
5339
5339
  const rE = N`${N.identifier(Ce.cteAlias)}.${N.identifier($)}`;
5340
5340
  SE = N`sum(${rE})`;
5341
5341
  } else
5342
- SE = this.queryBuilder.buildMeasureExpression(mE, t, J);
5343
- S[p] || (S[p] = N`${SE}`.as(p));
5342
+ SE = this.queryBuilder.buildMeasureExpression(mE, t, x);
5343
+ r[p] || (r[p] = N`${SE}`.as(p));
5344
5344
  const Le = this.buildPostAggregationWindowExpression(
5345
5345
  d,
5346
5346
  SE,
@@ -5349,16 +5349,16 @@ class NE {
5349
5349
  c,
5350
5350
  E
5351
5351
  );
5352
- Le && (S[P] = N`${Le}`.as(P));
5352
+ Le && (r[P] = N`${Le}`.as(P));
5353
5353
  }
5354
5354
  }
5355
5355
  }
5356
5356
  }
5357
5357
  }
5358
5358
  }
5359
- const r = [];
5360
- let O = t.db.select(S).from(n.from);
5361
- if (A.length > 0 && (O = t.db.with(...A).select(S).from(n.from)), n.joins)
5359
+ const S = [];
5360
+ let O = t.db.select(r).from(n.from);
5361
+ if (A.length > 0 && (O = t.db.with(...A).select(r).from(n.from)), n.joins)
5362
5362
  for (const C of n.joins)
5363
5363
  switch (C.type || "left") {
5364
5364
  case "left":
@@ -5398,7 +5398,7 @@ class NE {
5398
5398
  O = O.fullJoin(c.table, c.joinCondition);
5399
5399
  break;
5400
5400
  }
5401
- d.length > 0 && r.push(...d);
5401
+ d.length > 0 && S.push(...d);
5402
5402
  } catch {
5403
5403
  }
5404
5404
  }
@@ -5422,12 +5422,12 @@ class NE {
5422
5422
  } catch {
5423
5423
  }
5424
5424
  }
5425
- if (n.where && r.push(n.where), E.joinCubes && E.joinCubes.length > 0)
5425
+ if (n.where && S.push(n.where), E.joinCubes && E.joinCubes.length > 0)
5426
5426
  for (const C of E.joinCubes) {
5427
5427
  if (s.get(C.cube.name))
5428
5428
  continue;
5429
5429
  const _ = C.cube.sql(t);
5430
- _.where && r.push(_.where);
5430
+ _.where && S.push(_.where);
5431
5431
  }
5432
5432
  const i = this.queryBuilder.buildWhereConditions(
5433
5433
  E.joinCubes.length > 0 ? this.getCubesFromPlan(E) : E.primaryCube,
@@ -5439,8 +5439,8 @@ class NE {
5439
5439
  R
5440
5440
  // Reuse pre-built filters for parameter deduplication
5441
5441
  );
5442
- if (i.length > 0 && r.push(...i), r.length > 0) {
5443
- const C = r.length === 1 ? r[0] : h(...r);
5442
+ if (i.length > 0 && S.push(...i), S.length > 0) {
5443
+ const C = S.length === 1 ? S[0] : h(...S);
5444
5444
  O = O.where(C);
5445
5445
  }
5446
5446
  const a = this.queryBuilder.buildGroupByFields(
@@ -5531,36 +5531,36 @@ class NE {
5531
5531
  const t = {}, R = {}, A = {}, s = [E.primaryCube].filter(Boolean);
5532
5532
  if (E.joinCubes && E.joinCubes.length > 0 && s.push(...E.joinCubes.map((n) => n.cube).filter(Boolean)), e.measures)
5533
5533
  for (const n of e.measures) {
5534
- const [I, S] = n.split("."), r = s.find((O) => O?.name === I);
5535
- if (r && r.measures[S]) {
5536
- const O = r.measures[S];
5534
+ const [I, r] = n.split("."), S = s.find((O) => O?.name === I);
5535
+ if (S && S.measures[r]) {
5536
+ const O = S.measures[r];
5537
5537
  t[n] = {
5538
- title: O.title || S,
5539
- shortTitle: O.title || S,
5538
+ title: O.title || r,
5539
+ shortTitle: O.title || r,
5540
5540
  type: O.type
5541
5541
  };
5542
5542
  }
5543
5543
  }
5544
5544
  if (e.dimensions)
5545
5545
  for (const n of e.dimensions) {
5546
- const [I, S] = n.split("."), r = s.find((O) => O?.name === I);
5547
- if (r && r.dimensions?.[S]) {
5548
- const O = r.dimensions[S];
5546
+ const [I, r] = n.split("."), S = s.find((O) => O?.name === I);
5547
+ if (S && S.dimensions?.[r]) {
5548
+ const O = S.dimensions[r];
5549
5549
  R[n] = {
5550
- title: O.title || S,
5551
- shortTitle: O.title || S,
5550
+ title: O.title || r,
5551
+ shortTitle: O.title || r,
5552
5552
  type: O.type
5553
5553
  };
5554
5554
  }
5555
5555
  }
5556
5556
  if (e.timeDimensions)
5557
5557
  for (const n of e.timeDimensions) {
5558
- const [I, S] = n.dimension.split("."), r = s.find((O) => O?.name === I);
5559
- if (r && r.dimensions?.[S]) {
5560
- const O = r.dimensions[S];
5558
+ const [I, r] = n.dimension.split("."), S = s.find((O) => O?.name === I);
5559
+ if (S && S.dimensions?.[r]) {
5560
+ const O = S.dimensions[r];
5561
5561
  A[n.dimension] = {
5562
- title: O.title || S,
5563
- shortTitle: O.title || S,
5562
+ title: O.title || r,
5563
+ shortTitle: O.title || r,
5564
5564
  type: O.type,
5565
5565
  granularity: n.granularity
5566
5566
  };
@@ -5584,9 +5584,9 @@ class NE {
5584
5584
  for (const s of A) {
5585
5585
  const n = cE(s);
5586
5586
  if (e.has(n)) continue;
5587
- const [I, S] = s.member.split("."), r = t.get(I);
5588
- if (!r) continue;
5589
- const O = r.dimensions?.[S];
5587
+ const [I, r] = s.member.split("."), S = t.get(I);
5588
+ if (!S) continue;
5589
+ const O = S.dimensions?.[r];
5590
5590
  if (!O || ["arrayContains", "arrayOverlaps", "arrayContained"].includes(s.operator))
5591
5591
  continue;
5592
5592
  const a = F(O.sql, R), o = this.queryBuilder.buildFilterConditionPublic(
@@ -5604,11 +5604,11 @@ class NE {
5604
5604
  if (A.dateRange) {
5605
5605
  const s = _T(A.dimension, A.dateRange);
5606
5606
  if (e.has(s)) continue;
5607
- const [n, I] = A.dimension.split("."), S = t.get(n);
5608
- if (!S) continue;
5609
- const r = S.dimensions?.[I];
5607
+ const [n, I] = A.dimension.split("."), r = t.get(n);
5610
5608
  if (!r) continue;
5611
- const O = F(r.sql, R), i = this.queryBuilder.buildDateRangeCondition(O, A.dateRange);
5609
+ const S = r.dimensions?.[I];
5610
+ if (!S) continue;
5611
+ const O = F(S.sql, R), i = this.queryBuilder.buildDateRangeCondition(O, A.dateRange);
5612
5612
  i && e.set(s, i);
5613
5613
  }
5614
5614
  }
@@ -5634,9 +5634,9 @@ class NE {
5634
5634
  const D = s.preAggregationCTEs.find((C) => C.cube?.name === a);
5635
5635
  return D && D.cteAlias ? N`${N.identifier(D.cteAlias)}.${N.identifier(o)}` : null;
5636
5636
  };
5637
- let S;
5637
+ let r;
5638
5638
  if (n.orderBy && n.orderBy.length > 0)
5639
- S = n.orderBy.map((a) => {
5639
+ r = n.orderBy.map((a) => {
5640
5640
  const o = a.field.includes(".") ? a.field.split(".")[1] : a.field;
5641
5641
  if (t.timeDimensions)
5642
5642
  for (const P of t.timeDimensions) {
@@ -5675,7 +5675,7 @@ class NE {
5675
5675
  else if (t.timeDimensions && t.timeDimensions.length > 0) {
5676
5676
  const a = t.timeDimensions[0], [o, D] = a.dimension.split("."), C = I(o, D);
5677
5677
  if (C)
5678
- S = [{
5678
+ r = [{
5679
5679
  field: C,
5680
5680
  direction: "asc"
5681
5681
  }];
@@ -5683,7 +5683,7 @@ class NE {
5683
5683
  const P = A.name === o ? A : void 0;
5684
5684
  if (P?.dimensions?.[D]) {
5685
5685
  const _ = P.dimensions[D];
5686
- S = [{
5686
+ r = [{
5687
5687
  field: this.queryBuilder.buildTimeDimensionExpression(
5688
5688
  _.sql,
5689
5689
  a.granularity,
@@ -5694,16 +5694,16 @@ class NE {
5694
5694
  }
5695
5695
  }
5696
5696
  }
5697
- let r;
5698
- n.partitionBy && n.partitionBy.length > 0 && (r = n.partitionBy.map((a) => {
5697
+ let S;
5698
+ n.partitionBy && n.partitionBy.length > 0 && (S = n.partitionBy.map((a) => {
5699
5699
  const o = a.includes(".") ? a.split(".")[1] : a, D = A.dimensions?.[o];
5700
5700
  return D ? F(D.sql, R) : null;
5701
5701
  }).filter((a) => a !== null));
5702
5702
  const O = this.databaseAdapter.buildWindowFunction(
5703
5703
  E.type,
5704
5704
  e,
5705
- r,
5706
5705
  S,
5706
+ r,
5707
5707
  {
5708
5708
  offset: n.offset,
5709
5709
  defaultValue: n.defaultValue,
@@ -7413,7 +7413,7 @@ const wt = [
7413
7413
  "XMLNAMESPACES",
7414
7414
  "YEAR",
7415
7415
  "YEARS"
7416
- ], xt = [
7416
+ ], Jt = [
7417
7417
  // https://www.ibm.com/docs/en/db2-for-zos/12?topic=columns-data-types
7418
7418
  "ARRAY",
7419
7419
  "BIGINT",
@@ -7455,7 +7455,7 @@ const wt = [
7455
7455
  "VARBINARY",
7456
7456
  "VARCHAR",
7457
7457
  "VARGRAPHIC"
7458
- ], Jt = L(["SELECT [ALL | DISTINCT]"]), Qt = L([
7458
+ ], xt = L(["SELECT [ALL | DISTINCT]"]), Qt = L([
7459
7459
  // queries
7460
7460
  "WITH",
7461
7461
  "FROM",
@@ -7701,14 +7701,14 @@ const wt = [
7701
7701
  ]), kt = L([]), zt = {
7702
7702
  name: "db2",
7703
7703
  tokenizerOptions: {
7704
- reservedSelect: Jt,
7704
+ reservedSelect: xt,
7705
7705
  reservedClauses: [...Qt, ...be, ...gE],
7706
7706
  reservedSetOperations: Zt,
7707
7707
  reservedJoins: jt,
7708
7708
  reservedKeywordPhrases: qt,
7709
7709
  reservedDataTypePhrases: kt,
7710
7710
  reservedKeywords: vt,
7711
- reservedDataTypes: xt,
7711
+ reservedDataTypes: Jt,
7712
7712
  reservedFunctionNames: wt,
7713
7713
  extraParens: ["[]"],
7714
7714
  stringTypes: [
@@ -12151,7 +12151,7 @@ const hR = [
12151
12151
  "REPEAT",
12152
12152
  "RETURN",
12153
12153
  "WHILE"
12154
- ]), xR = L(["UNION [ALL | DISTINCT]"]), JR = L([
12154
+ ]), JR = L(["UNION [ALL | DISTINCT]"]), xR = L([
12155
12155
  "JOIN",
12156
12156
  "{LEFT | RIGHT} [OUTER] JOIN",
12157
12157
  "{INNER | CROSS} JOIN",
@@ -12169,8 +12169,8 @@ const hR = [
12169
12169
  tokenizerOptions: {
12170
12170
  reservedSelect: wR,
12171
12171
  reservedClauses: [...vR, ...$e, ...XE],
12172
- reservedSetOperations: xR,
12173
- reservedJoins: JR,
12172
+ reservedSetOperations: JR,
12173
+ reservedJoins: xR,
12174
12174
  reservedKeywordPhrases: QR,
12175
12175
  reservedDataTypePhrases: ZR,
12176
12176
  supportsXor: !0,
@@ -16033,9 +16033,9 @@ const pA = [
16033
16033
  "VALUES",
16034
16034
  // - update:
16035
16035
  "SET"
16036
- ]), xe = L([
16036
+ ]), Je = L([
16037
16037
  "CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]"
16038
- ]), xE = L([
16038
+ ]), JE = L([
16039
16039
  // - create:
16040
16040
  "CREATE [OR REPLACE | MATERIALIZED] VIEW",
16041
16041
  // - update:
@@ -16140,15 +16140,15 @@ const pA = [
16140
16140
  "HIVE METASTORE",
16141
16141
  // in window specifications
16142
16142
  "{ROWS | RANGE} BETWEEN"
16143
- ]), xA = L([]), JA = {
16143
+ ]), JA = L([]), xA = {
16144
16144
  name: "redshift",
16145
16145
  tokenizerOptions: {
16146
16146
  reservedSelect: $A,
16147
- reservedClauses: [...XA, ...xe, ...xE],
16147
+ reservedClauses: [...XA, ...Je, ...JE],
16148
16148
  reservedSetOperations: KA,
16149
16149
  reservedJoins: wA,
16150
16150
  reservedKeywordPhrases: vA,
16151
- reservedDataTypePhrases: xA,
16151
+ reservedDataTypePhrases: JA,
16152
16152
  reservedKeywords: yA,
16153
16153
  reservedDataTypes: WA,
16154
16154
  reservedFunctionNames: VA,
@@ -16175,8 +16175,8 @@ const pA = [
16175
16175
  },
16176
16176
  formatOptions: {
16177
16177
  alwaysDenseOperators: ["::"],
16178
- onelineClauses: [...xe, ...xE],
16179
- tabularOnelineClauses: xE
16178
+ onelineClauses: [...Je, ...JE],
16179
+ tabularOnelineClauses: JE
16180
16180
  }
16181
16181
  }, QA = [
16182
16182
  // https://deepkb.com/CO_000013/en/kb/IMPORT-fbfa59f0-2bf1-31fe-bb7b-0f9efe9932c6/spark-sql-keywords
@@ -16821,7 +16821,7 @@ const pA = [
16821
16821
  // https://spark.apache.org/docs/latest/sql-ref-syntax-dml-load.html
16822
16822
  "LOAD DATA [LOCAL] INPATH",
16823
16823
  "[OVERWRITE] INTO TABLE"
16824
- ]), Je = L(["CREATE [EXTERNAL] TABLE [IF NOT EXISTS]"]), JE = L([
16824
+ ]), xe = L(["CREATE [EXTERNAL] TABLE [IF NOT EXISTS]"]), xE = L([
16825
16825
  // - create:
16826
16826
  "CREATE [OR REPLACE] [GLOBAL TEMPORARY | TEMPORARY] VIEW [IF NOT EXISTS]",
16827
16827
  // - drop table:
@@ -16899,7 +16899,7 @@ const pA = [
16899
16899
  name: "spark",
16900
16900
  tokenizerOptions: {
16901
16901
  reservedSelect: qA,
16902
- reservedClauses: [...kA, ...Je, ...JE],
16902
+ reservedClauses: [...kA, ...xe, ...xE],
16903
16903
  reservedSetOperations: zA,
16904
16904
  reservedJoins: Es,
16905
16905
  reservedKeywordPhrases: es,
@@ -16922,8 +16922,8 @@ const pA = [
16922
16922
  postProcess: Rs
16923
16923
  },
16924
16924
  formatOptions: {
16925
- onelineClauses: [...Je, ...JE],
16926
- tabularOnelineClauses: JE
16925
+ onelineClauses: [...xe, ...xE],
16926
+ tabularOnelineClauses: xE
16927
16927
  }
16928
16928
  };
16929
16929
  function Rs(T) {
@@ -19560,7 +19560,7 @@ const As = [
19560
19560
  "XOR",
19561
19561
  "YEAR_MONTH",
19562
19562
  "ZEROFILL"
19563
- ], xs = [
19563
+ ], Js = [
19564
19564
  // https://docs.singlestore.com/cloud/reference/sql-reference/data-types/
19565
19565
  "BIGINT",
19566
19566
  "BINARY",
@@ -19609,7 +19609,7 @@ const As = [
19609
19609
  "VARCHAR",
19610
19610
  "VARCHARACTER",
19611
19611
  "YEAR"
19612
- ], Js = [
19612
+ ], xs = [
19613
19613
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/vector-functions/vector-functions.html
19614
19614
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/window-functions/window-functions.html
19615
19615
  // https://docs.singlestore.com/managed-service/en/reference/sql-reference/string-functions/string-functions.html
@@ -20118,8 +20118,8 @@ const As = [
20118
20118
  reservedKeywordPhrases: ks,
20119
20119
  reservedDataTypePhrases: zs,
20120
20120
  reservedKeywords: vs,
20121
- reservedDataTypes: xs,
20122
- reservedFunctionNames: Js,
20121
+ reservedDataTypes: Js,
20122
+ reservedFunctionNames: xs,
20123
20123
  // TODO: support _binary"some string" prefix
20124
20124
  stringTypes: [
20125
20125
  '""-qq-bs',
@@ -21236,7 +21236,7 @@ const As = [
21236
21236
  n1ql: CA,
21237
21237
  plsql: dA,
21238
21238
  postgresql: gA,
21239
- redshift: JA,
21239
+ redshift: xA,
21240
21240
  singlestoredb: En,
21241
21241
  snowflake: Nn,
21242
21242
  spark: ts,
@@ -21596,31 +21596,31 @@ class Un {
21596
21596
  {
21597
21597
  type: u.NAMED_PARAMETER,
21598
21598
  regex: ee(I.named, dT(E.paramChars || E.identChars)),
21599
- key: (S) => S.slice(1)
21599
+ key: (r) => r.slice(1)
21600
21600
  },
21601
21601
  {
21602
21602
  type: u.QUOTED_PARAMETER,
21603
21603
  regex: ee(I.quoted, UT(E.identTypes)),
21604
- key: (S) => (({ tokenKey: r, quoteChar: O }) => r.replace(new RegExp(K("\\" + O), "gu"), O))({
21605
- tokenKey: S.slice(2, -1),
21606
- quoteChar: S.slice(-1)
21604
+ key: (r) => (({ tokenKey: S, quoteChar: O }) => S.replace(new RegExp(K("\\" + O), "gu"), O))({
21605
+ tokenKey: r.slice(2, -1),
21606
+ quoteChar: r.slice(-1)
21607
21607
  })
21608
21608
  },
21609
21609
  {
21610
21610
  type: u.NUMBERED_PARAMETER,
21611
21611
  regex: ee(I.numbered, "[0-9]+"),
21612
- key: (S) => S.slice(1)
21612
+ key: (r) => r.slice(1)
21613
21613
  },
21614
21614
  {
21615
21615
  type: u.POSITIONAL_PARAMETER,
21616
21616
  regex: I.positional ? /[?]/y : void 0
21617
21617
  },
21618
- ...I.custom.map((S) => {
21619
- var r;
21618
+ ...I.custom.map((r) => {
21619
+ var S;
21620
21620
  return {
21621
21621
  type: u.CUSTOM_PARAMETER,
21622
- regex: q(S.regex),
21623
- key: (r = S.key) !== null && r !== void 0 ? r : ((O) => O)
21622
+ regex: q(r.regex),
21623
+ key: (S = r.key) !== null && S !== void 0 ? S : ((O) => O)
21624
21624
  };
21625
21625
  })
21626
21626
  ]);
@@ -21682,36 +21682,36 @@ function Hn() {
21682
21682
  (function(E, e) {
21683
21683
  T.exports ? T.exports = e() : E.nearley = e();
21684
21684
  })(Bn, function() {
21685
- function E(S, r, O) {
21686
- return this.id = ++E.highestId, this.name = S, this.symbols = r, this.postprocess = O, this;
21685
+ function E(r, S, O) {
21686
+ return this.id = ++E.highestId, this.name = r, this.symbols = S, this.postprocess = O, this;
21687
21687
  }
21688
- E.highestId = 0, E.prototype.toString = function(S) {
21689
- var r = typeof S > "u" ? this.symbols.map(I).join(" ") : this.symbols.slice(0, S).map(I).join(" ") + " ● " + this.symbols.slice(S).map(I).join(" ");
21690
- return this.name + " → " + r;
21688
+ E.highestId = 0, E.prototype.toString = function(r) {
21689
+ var S = typeof r > "u" ? this.symbols.map(I).join(" ") : this.symbols.slice(0, r).map(I).join(" ") + " ● " + this.symbols.slice(r).map(I).join(" ");
21690
+ return this.name + " → " + S;
21691
21691
  };
21692
- function e(S, r, O, i) {
21693
- this.rule = S, this.dot = r, this.reference = O, this.data = [], this.wantedBy = i, this.isComplete = this.dot === S.symbols.length;
21692
+ function e(r, S, O, i) {
21693
+ this.rule = r, this.dot = S, this.reference = O, this.data = [], this.wantedBy = i, this.isComplete = this.dot === r.symbols.length;
21694
21694
  }
21695
21695
  e.prototype.toString = function() {
21696
21696
  return "{" + this.rule.toString(this.dot) + "}, from: " + (this.reference || 0);
21697
- }, e.prototype.nextState = function(S) {
21698
- var r = new e(this.rule, this.dot + 1, this.reference, this.wantedBy);
21699
- return r.left = this, r.right = S, r.isComplete && (r.data = r.build(), r.right = void 0), r;
21697
+ }, e.prototype.nextState = function(r) {
21698
+ var S = new e(this.rule, this.dot + 1, this.reference, this.wantedBy);
21699
+ return S.left = this, S.right = r, S.isComplete && (S.data = S.build(), S.right = void 0), S;
21700
21700
  }, e.prototype.build = function() {
21701
- var S = [], r = this;
21701
+ var r = [], S = this;
21702
21702
  do
21703
- S.push(r.right.data), r = r.left;
21704
- while (r.left);
21705
- return S.reverse(), S;
21703
+ r.push(S.right.data), S = S.left;
21704
+ while (S.left);
21705
+ return r.reverse(), r;
21706
21706
  }, e.prototype.finish = function() {
21707
21707
  this.rule.postprocess && (this.data = this.rule.postprocess(this.data, this.reference, s.fail));
21708
21708
  };
21709
- function t(S, r) {
21710
- this.grammar = S, this.index = r, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
21709
+ function t(r, S) {
21710
+ this.grammar = r, this.index = S, this.states = [], this.wants = {}, this.scannable = [], this.completed = {};
21711
21711
  }
21712
- t.prototype.process = function(S) {
21713
- for (var r = this.states, O = this.wants, i = this.completed, a = 0; a < r.length; a++) {
21714
- var o = r[a];
21712
+ t.prototype.process = function(r) {
21713
+ for (var S = this.states, O = this.wants, i = this.completed, a = 0; a < S.length; a++) {
21714
+ var o = S[a];
21715
21715
  if (o.isComplete) {
21716
21716
  if (o.finish(), o.data !== s.fail) {
21717
21717
  for (var D = o.wantedBy, C = D.length; C--; ) {
@@ -21739,47 +21739,47 @@ function Hn() {
21739
21739
  O[_] = [o], this.predict(_);
21740
21740
  }
21741
21741
  }
21742
- }, t.prototype.predict = function(S) {
21743
- for (var r = this.grammar.byName[S] || [], O = 0; O < r.length; O++) {
21744
- var i = r[O], a = this.wants[S], o = new e(i, 0, this.index, a);
21742
+ }, t.prototype.predict = function(r) {
21743
+ for (var S = this.grammar.byName[r] || [], O = 0; O < S.length; O++) {
21744
+ var i = S[O], a = this.wants[r], o = new e(i, 0, this.index, a);
21745
21745
  this.states.push(o);
21746
21746
  }
21747
- }, t.prototype.complete = function(S, r) {
21748
- var O = S.nextState(r);
21747
+ }, t.prototype.complete = function(r, S) {
21748
+ var O = r.nextState(S);
21749
21749
  this.states.push(O);
21750
21750
  };
21751
- function R(S, r) {
21752
- this.rules = S, this.start = r || this.rules[0].name;
21751
+ function R(r, S) {
21752
+ this.rules = r, this.start = S || this.rules[0].name;
21753
21753
  var O = this.byName = {};
21754
21754
  this.rules.forEach(function(i) {
21755
21755
  O.hasOwnProperty(i.name) || (O[i.name] = []), O[i.name].push(i);
21756
21756
  });
21757
21757
  }
21758
- R.fromCompiled = function(i, r) {
21758
+ R.fromCompiled = function(i, S) {
21759
21759
  var O = i.Lexer;
21760
- i.ParserStart && (r = i.ParserStart, i = i.ParserRules);
21760
+ i.ParserStart && (S = i.ParserStart, i = i.ParserRules);
21761
21761
  var i = i.map(function(o) {
21762
21762
  return new E(o.name, o.symbols, o.postprocess);
21763
- }), a = new R(i, r);
21763
+ }), a = new R(i, S);
21764
21764
  return a.lexer = O, a;
21765
21765
  };
21766
21766
  function A() {
21767
21767
  this.reset("");
21768
21768
  }
21769
- A.prototype.reset = function(S, r) {
21770
- this.buffer = S, this.index = 0, this.line = r ? r.line : 1, this.lastLineBreak = r ? -r.col : 0;
21769
+ A.prototype.reset = function(r, S) {
21770
+ this.buffer = r, this.index = 0, this.line = S ? S.line : 1, this.lastLineBreak = S ? -S.col : 0;
21771
21771
  }, A.prototype.next = function() {
21772
21772
  if (this.index < this.buffer.length) {
21773
- var S = this.buffer[this.index++];
21774
- return S === `
21775
- ` && (this.line += 1, this.lastLineBreak = this.index), { value: S };
21773
+ var r = this.buffer[this.index++];
21774
+ return r === `
21775
+ ` && (this.line += 1, this.lastLineBreak = this.index), { value: r };
21776
21776
  }
21777
21777
  }, A.prototype.save = function() {
21778
21778
  return {
21779
21779
  line: this.line,
21780
21780
  col: this.index - this.lastLineBreak
21781
21781
  };
21782
- }, A.prototype.formatError = function(S, r) {
21782
+ }, A.prototype.formatError = function(r, S) {
21783
21783
  var O = this.buffer;
21784
21784
  if (typeof O == "string") {
21785
21785
  var i = O.split(`
@@ -21790,26 +21790,26 @@ function Hn() {
21790
21790
  `, this.index);
21791
21791
  a === -1 && (a = O.length);
21792
21792
  var o = this.index - this.lastLineBreak, D = String(this.line).length;
21793
- return r += " at line " + this.line + " col " + o + `:
21793
+ return S += " at line " + this.line + " col " + o + `:
21794
21794
 
21795
- `, r += i.map(function(P, _) {
21795
+ `, S += i.map(function(P, _) {
21796
21796
  return C(this.line - i.length + _ + 1, D) + " " + P;
21797
21797
  }, this).join(`
21798
- `), r += `
21798
+ `), S += `
21799
21799
  ` + C("", D + o) + `^
21800
- `, r;
21800
+ `, S;
21801
21801
  } else
21802
- return r + " at index " + (this.index - 1);
21802
+ return S + " at index " + (this.index - 1);
21803
21803
  function C(P, _) {
21804
21804
  var M = String(P);
21805
21805
  return Array(_ - M.length + 1).join(" ") + M;
21806
21806
  }
21807
21807
  };
21808
- function s(S, r, O) {
21809
- if (S instanceof R)
21810
- var i = S, O = r;
21808
+ function s(r, S, O) {
21809
+ if (r instanceof R)
21810
+ var i = r, O = S;
21811
21811
  else
21812
- var i = R.fromCompiled(S, r);
21812
+ var i = R.fromCompiled(r, S);
21813
21813
  this.grammar = i, this.options = {
21814
21814
  keepHistory: !1,
21815
21815
  lexer: i.lexer || new A()
@@ -21820,12 +21820,12 @@ function Hn() {
21820
21820
  var o = new t(i, 0);
21821
21821
  this.table = [o], o.wants[i.start] = [], o.predict(i.start), o.process(), this.current = 0;
21822
21822
  }
21823
- s.fail = {}, s.prototype.feed = function(S) {
21824
- var r = this.lexer;
21825
- r.reset(S, this.lexerState);
21823
+ s.fail = {}, s.prototype.feed = function(r) {
21824
+ var S = this.lexer;
21825
+ S.reset(r, this.lexerState);
21826
21826
  for (var O; ; ) {
21827
21827
  try {
21828
- if (O = r.next(), !O)
21828
+ if (O = S.next(), !O)
21829
21829
  break;
21830
21830
  } catch (f) {
21831
21831
  var D = new t(this.grammar, this.current + 1);
@@ -21837,7 +21837,7 @@ function Hn() {
21837
21837
  this.options.keepHistory || delete this.table[this.current - 1];
21838
21838
  var o = this.current + 1, D = new t(this.grammar, o);
21839
21839
  this.table.push(D);
21840
- for (var C = O.text !== void 0 ? O.text : O.value, P = r.constructor === A ? O.value : O, _ = a.scannable, M = _.length; M--; ) {
21840
+ for (var C = O.text !== void 0 ? O.text : O.value, P = S.constructor === A ? O.value : O, _ = a.scannable, M = _.length; M--; ) {
21841
21841
  var c = _[M], d = c.rule.symbols[c.dot];
21842
21842
  if (d.test ? d.test(P) : d.type ? d.type === O.type : d.literal === C) {
21843
21843
  var p = c.nextState({ data: P, token: O, isToken: !0, reference: o - 1 });
@@ -21848,27 +21848,27 @@ function Hn() {
21848
21848
  var i = new Error(this.reportError(O));
21849
21849
  throw i.offset = this.current, i.token = O, i;
21850
21850
  }
21851
- this.options.keepHistory && (a.lexerState = r.save()), this.current++;
21851
+ this.options.keepHistory && (a.lexerState = S.save()), this.current++;
21852
21852
  }
21853
- return a && (this.lexerState = r.save()), this.results = this.finish(), this;
21854
- }, s.prototype.reportLexerError = function(S) {
21855
- var r, O, i = S.token;
21856
- return i ? (r = "input " + JSON.stringify(i.text[0]) + " (lexer error)", O = this.lexer.formatError(i, "Syntax error")) : (r = "input (lexer error)", O = S.message), this.reportErrorCommon(O, r);
21857
- }, s.prototype.reportError = function(S) {
21858
- var r = (S.type ? S.type + " token: " : "") + JSON.stringify(S.value !== void 0 ? S.value : S), O = this.lexer.formatError(S, "Syntax error");
21859
- return this.reportErrorCommon(O, r);
21860
- }, s.prototype.reportErrorCommon = function(S, r) {
21853
+ return a && (this.lexerState = S.save()), this.results = this.finish(), this;
21854
+ }, s.prototype.reportLexerError = function(r) {
21855
+ var S, O, i = r.token;
21856
+ return i ? (S = "input " + JSON.stringify(i.text[0]) + " (lexer error)", O = this.lexer.formatError(i, "Syntax error")) : (S = "input (lexer error)", O = r.message), this.reportErrorCommon(O, S);
21857
+ }, s.prototype.reportError = function(r) {
21858
+ var S = (r.type ? r.type + " token: " : "") + JSON.stringify(r.value !== void 0 ? r.value : r), O = this.lexer.formatError(r, "Syntax error");
21859
+ return this.reportErrorCommon(O, S);
21860
+ }, s.prototype.reportErrorCommon = function(r, S) {
21861
21861
  var O = [];
21862
- O.push(S);
21862
+ O.push(r);
21863
21863
  var i = this.table.length - 2, a = this.table[i], o = a.states.filter(function(C) {
21864
21864
  var P = C.rule.symbols[C.dot];
21865
21865
  return P && typeof P != "string";
21866
21866
  });
21867
21867
  if (o.length === 0)
21868
- O.push("Unexpected " + r + `. I did not expect any more input. Here is the state of my parse table:
21868
+ O.push("Unexpected " + S + `. I did not expect any more input. Here is the state of my parse table:
21869
21869
  `), this.displayStateStack(a.states, O);
21870
21870
  else {
21871
- O.push("Unexpected " + r + `. Instead, I was expecting to see one of the following:
21871
+ O.push("Unexpected " + S + `. Instead, I was expecting to see one of the following:
21872
21872
  `);
21873
21873
  var D = o.map(function(C) {
21874
21874
  return this.buildFirstStateStack(C, []) || [C];
@@ -21880,68 +21880,68 @@ function Hn() {
21880
21880
  }
21881
21881
  return O.push(""), O.join(`
21882
21882
  `);
21883
- }, s.prototype.displayStateStack = function(S, r) {
21884
- for (var O, i = 0, a = 0; a < S.length; a++) {
21885
- var o = S[a], D = o.rule.toString(o.dot);
21886
- D === O ? i++ : (i > 0 && r.push(" ^ " + i + " more lines identical to this"), i = 0, r.push(" " + D)), O = D;
21883
+ }, s.prototype.displayStateStack = function(r, S) {
21884
+ for (var O, i = 0, a = 0; a < r.length; a++) {
21885
+ var o = r[a], D = o.rule.toString(o.dot);
21886
+ D === O ? i++ : (i > 0 && S.push(" ^ " + i + " more lines identical to this"), i = 0, S.push(" " + D)), O = D;
21887
21887
  }
21888
- }, s.prototype.getSymbolDisplay = function(S) {
21889
- return n(S);
21890
- }, s.prototype.buildFirstStateStack = function(S, r) {
21891
- if (r.indexOf(S) !== -1)
21888
+ }, s.prototype.getSymbolDisplay = function(r) {
21889
+ return n(r);
21890
+ }, s.prototype.buildFirstStateStack = function(r, S) {
21891
+ if (S.indexOf(r) !== -1)
21892
21892
  return null;
21893
- if (S.wantedBy.length === 0)
21894
- return [S];
21895
- var O = S.wantedBy[0], i = [S].concat(r), a = this.buildFirstStateStack(O, i);
21896
- return a === null ? null : [S].concat(a);
21893
+ if (r.wantedBy.length === 0)
21894
+ return [r];
21895
+ var O = r.wantedBy[0], i = [r].concat(S), a = this.buildFirstStateStack(O, i);
21896
+ return a === null ? null : [r].concat(a);
21897
21897
  }, s.prototype.save = function() {
21898
- var S = this.table[this.current];
21899
- return S.lexerState = this.lexerState, S;
21900
- }, s.prototype.restore = function(S) {
21901
- var r = S.index;
21902
- this.current = r, this.table[r] = S, this.table.splice(r + 1), this.lexerState = S.lexerState, this.results = this.finish();
21903
- }, s.prototype.rewind = function(S) {
21898
+ var r = this.table[this.current];
21899
+ return r.lexerState = this.lexerState, r;
21900
+ }, s.prototype.restore = function(r) {
21901
+ var S = r.index;
21902
+ this.current = S, this.table[S] = r, this.table.splice(S + 1), this.lexerState = r.lexerState, this.results = this.finish();
21903
+ }, s.prototype.rewind = function(r) {
21904
21904
  if (!this.options.keepHistory)
21905
21905
  throw new Error("set option `keepHistory` to enable rewinding");
21906
- this.restore(this.table[S]);
21906
+ this.restore(this.table[r]);
21907
21907
  }, s.prototype.finish = function() {
21908
- var S = [], r = this.grammar.start, O = this.table[this.table.length - 1];
21908
+ var r = [], S = this.grammar.start, O = this.table[this.table.length - 1];
21909
21909
  return O.states.forEach(function(i) {
21910
- i.rule.name === r && i.dot === i.rule.symbols.length && i.reference === 0 && i.data !== s.fail && S.push(i);
21911
- }), S.map(function(i) {
21910
+ i.rule.name === S && i.dot === i.rule.symbols.length && i.reference === 0 && i.data !== s.fail && r.push(i);
21911
+ }), r.map(function(i) {
21912
21912
  return i.data;
21913
21913
  });
21914
21914
  };
21915
- function n(S) {
21916
- var r = typeof S;
21917
- if (r === "string")
21918
- return S;
21919
- if (r === "object") {
21920
- if (S.literal)
21921
- return JSON.stringify(S.literal);
21922
- if (S instanceof RegExp)
21923
- return "character matching " + S;
21924
- if (S.type)
21925
- return S.type + " token";
21926
- if (S.test)
21927
- return "token matching " + String(S.test);
21928
- throw new Error("Unknown symbol type: " + S);
21915
+ function n(r) {
21916
+ var S = typeof r;
21917
+ if (S === "string")
21918
+ return r;
21919
+ if (S === "object") {
21920
+ if (r.literal)
21921
+ return JSON.stringify(r.literal);
21922
+ if (r instanceof RegExp)
21923
+ return "character matching " + r;
21924
+ if (r.type)
21925
+ return r.type + " token";
21926
+ if (r.test)
21927
+ return "token matching " + String(r.test);
21928
+ throw new Error("Unknown symbol type: " + r);
21929
21929
  }
21930
21930
  }
21931
- function I(S) {
21932
- var r = typeof S;
21933
- if (r === "string")
21934
- return S;
21935
- if (r === "object") {
21936
- if (S.literal)
21937
- return JSON.stringify(S.literal);
21938
- if (S instanceof RegExp)
21939
- return S.toString();
21940
- if (S.type)
21941
- return "%" + S.type;
21942
- if (S.test)
21943
- return "<" + String(S.test) + ">";
21944
- throw new Error("Unknown symbol type: " + S);
21931
+ function I(r) {
21932
+ var S = typeof r;
21933
+ if (S === "string")
21934
+ return r;
21935
+ if (S === "object") {
21936
+ if (r.literal)
21937
+ return JSON.stringify(r.literal);
21938
+ if (r instanceof RegExp)
21939
+ return r.toString();
21940
+ if (r.type)
21941
+ return "%" + r.type;
21942
+ if (r.test)
21943
+ return "<" + String(r.test) + ">";
21944
+ throw new Error("Unknown symbol type: " + r);
21945
21945
  }
21946
21946
  }
21947
21947
  return {
@@ -22444,13 +22444,13 @@ const m = new fT((T) => []), Q = ([[T]]) => T, b = (T) => ({
22444
22444
  }
22445
22445
  ],
22446
22446
  ParserStart: "main"
22447
- }, { Parser: xn, Grammar: Jn } = Yn;
22447
+ }, { Parser: Jn, Grammar: xn } = Yn;
22448
22448
  function Qn(T) {
22449
22449
  let E = {};
22450
22450
  const e = new fT((R) => [
22451
22451
  ...bn(T.tokenize(R, E)),
22452
22452
  lT(R.length)
22453
- ]), t = new xn(Jn.fromCompiled(vn), { lexer: e });
22453
+ ]), t = new Jn(xn.fromCompiled(vn), { lexer: e });
22454
22454
  return {
22455
22455
  parse: (R, A) => {
22456
22456
  E = A;
@@ -23112,31 +23112,31 @@ async function aS(T, E, e) {
23112
23112
  if (!t.isValid)
23113
23113
  throw new Error(`Query validation failed: ${t.errors.join(", ")}`);
23114
23114
  const R = /* @__PURE__ */ new Set();
23115
- T.measures?.forEach((S) => {
23116
- const r = S.split(".")[0];
23117
- R.add(r);
23118
- }), T.dimensions?.forEach((S) => {
23119
- const r = S.split(".")[0];
23120
- R.add(r);
23121
- }), T.timeDimensions?.forEach((S) => {
23122
- const r = S.dimension.split(".")[0];
23123
- R.add(r);
23124
- }), T.filters?.forEach((S) => {
23125
- FT(S, R);
23115
+ T.measures?.forEach((r) => {
23116
+ const S = r.split(".")[0];
23117
+ R.add(S);
23118
+ }), T.dimensions?.forEach((r) => {
23119
+ const S = r.split(".")[0];
23120
+ R.add(S);
23121
+ }), T.timeDimensions?.forEach((r) => {
23122
+ const S = r.dimension.split(".")[0];
23123
+ R.add(S);
23124
+ }), T.filters?.forEach((r) => {
23125
+ FT(r, R);
23126
23126
  });
23127
23127
  const A = R.size > 1;
23128
23128
  let s;
23129
23129
  if (A)
23130
23130
  s = await e.generateMultiCubeSQL(T, E);
23131
23131
  else {
23132
- const S = Array.from(R)[0];
23133
- s = await e.generateSQL(S, T, E);
23132
+ const r = Array.from(R)[0];
23133
+ s = await e.generateSQL(r, T, E);
23134
23134
  }
23135
- const n = Array.from(R).map((S) => ({
23136
- cube: S,
23135
+ const n = Array.from(R).map((r) => ({
23136
+ cube: r,
23137
23137
  query: {
23138
- measures: T.measures?.filter((r) => r.startsWith(S + ".")) || [],
23139
- dimensions: T.dimensions?.filter((r) => r.startsWith(S + ".")) || [],
23138
+ measures: T.measures?.filter((S) => S.startsWith(r + ".")) || [],
23139
+ dimensions: T.dimensions?.filter((S) => S.startsWith(r + ".")) || [],
23140
23140
  filters: T.filters || [],
23141
23141
  timeDimensions: T.timeDimensions || [],
23142
23142
  order: T.order || {},
@@ -23147,8 +23147,8 @@ async function aS(T, E, e) {
23147
23147
  let I;
23148
23148
  try {
23149
23149
  I = e.analyzeQuery(T, E);
23150
- } catch (S) {
23151
- console.warn("Query analysis failed:", S);
23150
+ } catch (r) {
23151
+ console.warn("Query analysis failed:", r);
23152
23152
  }
23153
23153
  return {
23154
23154
  queryType: "regularQuery",
@@ -23347,7 +23347,7 @@ class DS {
23347
23347
  * Validates calculated measures during registration
23348
23348
  */
23349
23349
  registerCube(E) {
23350
- this.validateCalculatedMeasures(E), new Z(this.cubes).populateDependencies(E), this.cubes.set(E.name, E), this.invalidateMetadataCache();
23350
+ E.meta && console.log(`[DEBUG] registerCube: ${E.name} has meta:`, JSON.stringify(E.meta)), this.validateCalculatedMeasures(E), new Z(this.cubes).populateDependencies(E), this.cubes.set(E.name, E), this.invalidateMetadataCache();
23351
23351
  }
23352
23352
  /**
23353
23353
  * Validate calculated measures in a cube
@@ -23466,24 +23466,24 @@ ${e.join(`
23466
23466
  */
23467
23467
  generateCubeMetadata(E) {
23468
23468
  const e = Object.keys(E.measures), t = Object.keys(E.dimensions), R = new Array(e.length), A = new Array(t.length);
23469
- for (let n = 0; n < e.length; n++) {
23470
- const I = e[n], S = E.measures[I];
23471
- R[n] = {
23472
- name: `${E.name}.${I}`,
23473
- title: S.title || I,
23474
- shortTitle: S.title || I,
23469
+ for (let I = 0; I < e.length; I++) {
23470
+ const r = e[I], S = E.measures[r];
23471
+ R[I] = {
23472
+ name: `${E.name}.${r}`,
23473
+ title: S.title || r,
23474
+ shortTitle: S.title || r,
23475
23475
  type: S.type,
23476
23476
  format: void 0,
23477
23477
  // Measure doesn't have format field
23478
23478
  description: S.description
23479
23479
  };
23480
23480
  }
23481
- for (let n = 0; n < t.length; n++) {
23482
- const I = t[n], S = E.dimensions[I];
23483
- A[n] = {
23484
- name: `${E.name}.${I}`,
23485
- title: S.title || I,
23486
- shortTitle: S.title || I,
23481
+ for (let I = 0; I < t.length; I++) {
23482
+ const r = t[I], S = E.dimensions[r];
23483
+ A[I] = {
23484
+ name: `${E.name}.${r}`,
23485
+ title: S.title || r,
23486
+ shortTitle: S.title || r,
23487
23487
  type: S.type,
23488
23488
  format: void 0,
23489
23489
  // Dimension doesn't have format field
@@ -23492,18 +23492,18 @@ ${e.join(`
23492
23492
  }
23493
23493
  const s = [];
23494
23494
  if (E.joins)
23495
- for (const [, n] of Object.entries(E.joins)) {
23496
- const I = typeof n.targetCube == "function" ? n.targetCube() : n.targetCube;
23495
+ for (const [, I] of Object.entries(E.joins)) {
23496
+ const r = typeof I.targetCube == "function" ? I.targetCube() : I.targetCube;
23497
23497
  s.push({
23498
- targetCube: I.name,
23499
- relationship: n.relationship,
23500
- joinFields: n.on.map((S) => ({
23498
+ targetCube: r.name,
23499
+ relationship: I.relationship,
23500
+ joinFields: I.on.map((S) => ({
23501
23501
  sourceField: this.getColumnName(S.source),
23502
23502
  targetField: this.getColumnName(S.target)
23503
23503
  }))
23504
23504
  });
23505
23505
  }
23506
- return {
23506
+ const n = {
23507
23507
  name: E.name,
23508
23508
  title: E.title || E.name,
23509
23509
  description: E.description,
@@ -23514,6 +23514,7 @@ ${e.join(`
23514
23514
  relationships: s.length > 0 ? s : void 0,
23515
23515
  meta: E.meta
23516
23516
  };
23517
+ return E.meta && console.log(`[DEBUG] Cube ${E.name} has meta:`, JSON.stringify(E.meta)), n;
23517
23518
  }
23518
23519
  /**
23519
23520
  * Get SQL for a query without executing it (debugging)