drizzle-cube 0.3.30 → 0.3.31

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.
@@ -136,10 +136,10 @@ class j {
136
136
  this.value = Array.isArray(e) ? e : [e];
137
137
  }
138
138
  getSQL() {
139
- return new F([this]);
139
+ return new O([this]);
140
140
  }
141
141
  }
142
- class F {
142
+ class O {
143
143
  constructor(e) {
144
144
  this.queryChunks = e;
145
145
  for (const t of e)
@@ -193,7 +193,7 @@ class F {
193
193
  m.push(f), p < l.length - 1 && m.push(new j(", "));
194
194
  return m.push(new j(")")), this.buildQueryFromSourceParams(m, n);
195
195
  }
196
- if (L(l, F))
196
+ if (L(l, O))
197
197
  return this.buildQueryFromSourceParams(l.queryChunks, {
198
198
  ...n,
199
199
  inlineParams: u || l.shouldInlineParams
@@ -226,14 +226,14 @@ class F {
226
226
  if (L(l.value, ce))
227
227
  return { sql: r(c.value++, l), params: [l], typings: ["none"] };
228
228
  const m = l.value === null ? null : l.encoder.mapToDriverValue(l.value);
229
- if (L(m, F))
229
+ if (L(m, O))
230
230
  return this.buildQueryFromSourceParams([m], n);
231
231
  if (u)
232
232
  return { sql: this.mapInlineParam(m, n), params: [] };
233
233
  let p = ["none"];
234
234
  return a && (p = [a(l.encoder)]), { sql: r(c.value++, m), params: [m], typings: p };
235
235
  }
236
- return L(l, ce) ? { sql: r(c.value++, l), params: [l], typings: ["none"] } : L(l, F.Aliased) && l.fieldAlias !== void 0 ? { sql: i(l.fieldAlias), params: [] } : L(l, Ze) ? l._.isWith ? { sql: i(l._.alias), params: [] } : this.buildQueryFromSourceParams([
236
+ return L(l, ce) ? { sql: r(c.value++, l), params: [l], typings: ["none"] } : L(l, O.Aliased) && l.fieldAlias !== void 0 ? { sql: i(l.fieldAlias), params: [] } : L(l, Ze) ? l._.isWith ? { sql: i(l._.alias), params: [] } : this.buildQueryFromSourceParams([
237
237
  new j("("),
238
238
  l._.sql,
239
239
  new j(") "),
@@ -262,7 +262,7 @@ class F {
262
262
  return this;
263
263
  }
264
264
  as(e) {
265
- return e === void 0 ? this : new F.Aliased(this, e);
265
+ return e === void 0 ? this : new O.Aliased(this, e);
266
266
  }
267
267
  mapWith(e) {
268
268
  return this.decoder = typeof e == "function" ? { mapFromDriverValue: e } : e, this;
@@ -287,7 +287,7 @@ class Ne {
287
287
  static [x] = "Name";
288
288
  brand;
289
289
  getSQL() {
290
- return new F([this]);
290
+ return new O([this]);
291
291
  }
292
292
  }
293
293
  function wt(d) {
@@ -313,7 +313,7 @@ class le {
313
313
  static [x] = "Param";
314
314
  brand;
315
315
  getSQL() {
316
- return new F([this]);
316
+ return new O([this]);
317
317
  }
318
318
  }
319
319
  function o(d, ...e) {
@@ -321,26 +321,26 @@ function o(d, ...e) {
321
321
  (e.length > 0 || d.length > 0 && d[0] !== "") && t.push(new j(d[0]));
322
322
  for (const [n, s] of e.entries())
323
323
  t.push(s, new j(d[n + 1]));
324
- return new F(t);
324
+ return new O(t);
325
325
  }
326
326
  ((d) => {
327
327
  function e() {
328
- return new F([]);
328
+ return new O([]);
329
329
  }
330
330
  d.empty = e;
331
331
  function t(u) {
332
- return new F(u);
332
+ return new O(u);
333
333
  }
334
334
  d.fromList = t;
335
335
  function n(u) {
336
- return new F([new j(u)]);
336
+ return new O([new j(u)]);
337
337
  }
338
338
  d.raw = n;
339
339
  function s(u, c) {
340
340
  const l = [];
341
341
  for (const [m, p] of u.entries())
342
342
  m > 0 && c !== void 0 && l.push(c), l.push(p);
343
- return new F(l);
343
+ return new O(l);
344
344
  }
345
345
  d.join = s;
346
346
  function i(u) {
@@ -373,14 +373,14 @@ function o(d, ...e) {
373
373
  }
374
374
  }
375
375
  d.Aliased = e;
376
- })(F || (F = {}));
376
+ })(O || (O = {}));
377
377
  class ce {
378
378
  constructor(e) {
379
379
  this.name = e;
380
380
  }
381
381
  static [x] = "Placeholder";
382
382
  getSQL() {
383
- return new F([this]);
383
+ return new O([this]);
384
384
  }
385
385
  }
386
386
  const $t = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
@@ -402,28 +402,28 @@ class st {
402
402
  };
403
403
  }
404
404
  getSQL() {
405
- return new F([this]);
405
+ return new O([this]);
406
406
  }
407
407
  }
408
408
  te.prototype.getSQL = function() {
409
- return new F([this]);
409
+ return new O([this]);
410
410
  };
411
411
  B.prototype.getSQL = function() {
412
- return new F([this]);
412
+ return new O([this]);
413
413
  };
414
414
  Ze.prototype.getSQL = function() {
415
- return new F([this]);
415
+ return new O([this]);
416
416
  };
417
417
  function U(d, e) {
418
418
  return wt(e) && !et(d) && !L(d, le) && !L(d, ce) && !L(d, te) && !L(d, B) && !L(d, st) ? new le(d, e) : d;
419
419
  }
420
- const P = (d, e) => o`${d} = ${U(e, d)}`, Me = (d, e) => o`${d} <> ${U(e, d)}`;
421
- function A(...d) {
420
+ const Q = (d, e) => o`${d} = ${U(e, d)}`, Me = (d, e) => o`${d} <> ${U(e, d)}`;
421
+ function D(...d) {
422
422
  const e = d.filter(
423
423
  (t) => t !== void 0
424
424
  );
425
425
  if (e.length !== 0)
426
- return e.length === 1 ? new F(e) : new F([
426
+ return e.length === 1 ? new O(e) : new O([
427
427
  new j("("),
428
428
  o.join(e, new j(" and ")),
429
429
  new j(")")
@@ -434,7 +434,7 @@ function ie(...d) {
434
434
  (t) => t !== void 0
435
435
  );
436
436
  if (e.length !== 0)
437
- return e.length === 1 ? new F(e) : new F([
437
+ return e.length === 1 ? new O(e) : new O([
438
438
  new j("("),
439
439
  o.join(e, new j(" or ")),
440
440
  new j(")")
@@ -492,7 +492,7 @@ function De(d) {
492
492
  function Dt(d) {
493
493
  return o`count(distinct ${d})`.mapWith(Number);
494
494
  }
495
- function W(d) {
495
+ function K(d) {
496
496
  return o`sum(${d})`.mapWith(String);
497
497
  }
498
498
  function V(d) {
@@ -2509,7 +2509,7 @@ function Qe(d, e, t) {
2509
2509
  return Be(d, e);
2510
2510
  throw new Error("Unable to determine database engine type. Please specify engineType parameter.");
2511
2511
  }
2512
- function K(d) {
2512
+ function P(d) {
2513
2513
  return typeof d == "function" ? d() : d;
2514
2514
  }
2515
2515
  function Ae(d, e) {
@@ -2543,12 +2543,12 @@ function Jt(d, e) {
2543
2543
  throw new Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
2544
2544
  const { table: t, sourceKey: n, targetKey: s, securitySql: i } = d.through, r = [];
2545
2545
  for (const l of n) {
2546
- const m = l.as || P;
2546
+ const m = l.as || Q;
2547
2547
  r.push(m(l.source, l.target));
2548
2548
  }
2549
2549
  const a = [];
2550
2550
  for (const l of s) {
2551
- const m = l.as || P;
2551
+ const m = l.as || Q;
2552
2552
  a.push(m(l.source, l.target));
2553
2553
  }
2554
2554
  let u;
@@ -2562,13 +2562,13 @@ function Jt(d, e) {
2562
2562
  {
2563
2563
  joinType: c,
2564
2564
  table: t,
2565
- condition: A(...r)
2565
+ condition: D(...r)
2566
2566
  },
2567
2567
  {
2568
2568
  joinType: c,
2569
2569
  table: t,
2570
2570
  // This will be replaced with target cube table in query planner
2571
- condition: A(...a)
2571
+ condition: D(...a)
2572
2572
  }
2573
2573
  ],
2574
2574
  junctionSecurityConditions: u
@@ -2663,7 +2663,7 @@ function Ht(d) {
2663
2663
  return {
2664
2664
  measures: d.measures ? [...d.measures].sort() : void 0,
2665
2665
  dimensions: d.dimensions ? [...d.dimensions].sort() : void 0,
2666
- filters: d.filters ? Q(d.filters) : void 0,
2666
+ filters: d.filters ? W(d.filters) : void 0,
2667
2667
  timeDimensions: d.timeDimensions ? en(d.timeDimensions) : void 0,
2668
2668
  limit: d.limit,
2669
2669
  offset: d.offset,
@@ -2685,7 +2685,7 @@ function Yt(d) {
2685
2685
  steps: d.steps.map((e) => {
2686
2686
  const t = {
2687
2687
  name: e.name,
2688
- filter: e.filter ? Array.isArray(e.filter) ? Q(e.filter) : Q([e.filter])[0] : void 0,
2688
+ filter: e.filter ? Array.isArray(e.filter) ? W(e.filter) : W([e.filter])[0] : void 0,
2689
2689
  timeToConvert: e.timeToConvert
2690
2690
  };
2691
2691
  return "cube" in e && e.cube && (t.cube = e.cube), t;
@@ -2702,7 +2702,7 @@ function Xt(d) {
2702
2702
  // Normalize starting step - sort filters for consistent hashing
2703
2703
  startingStep: {
2704
2704
  name: d.startingStep.name,
2705
- filter: d.startingStep.filter ? Array.isArray(d.startingStep.filter) ? Q(d.startingStep.filter) : Q([d.startingStep.filter])[0] : void 0
2705
+ filter: d.startingStep.filter ? Array.isArray(d.startingStep.filter) ? W(d.startingStep.filter) : W([d.startingStep.filter])[0] : void 0
2706
2706
  },
2707
2707
  // CRITICAL: Include step counts in cache key
2708
2708
  stepsBefore: d.stepsBefore,
@@ -2724,18 +2724,18 @@ function Zt(d) {
2724
2724
  periods: d.periods,
2725
2725
  retentionType: d.retentionType,
2726
2726
  // Normalize filters for consistent hashing
2727
- cohortFilters: d.cohortFilters ? Array.isArray(d.cohortFilters) ? Q(d.cohortFilters) : Q([d.cohortFilters])[0] : void 0,
2728
- activityFilters: d.activityFilters ? Array.isArray(d.activityFilters) ? Q(d.activityFilters) : Q([d.activityFilters])[0] : void 0,
2727
+ cohortFilters: d.cohortFilters ? Array.isArray(d.cohortFilters) ? W(d.cohortFilters) : W([d.cohortFilters])[0] : void 0,
2728
+ activityFilters: d.activityFilters ? Array.isArray(d.activityFilters) ? W(d.activityFilters) : W([d.activityFilters])[0] : void 0,
2729
2729
  // Include breakdown dimensions for cache key
2730
2730
  breakdownDimensions: d.breakdownDimensions
2731
2731
  };
2732
2732
  }
2733
- function Q(d) {
2733
+ function W(d) {
2734
2734
  return [...d].map((e) => {
2735
2735
  if ("and" in e && e.and)
2736
- return { and: Q(e.and) };
2736
+ return { and: W(e.and) };
2737
2737
  if ("or" in e && e.or)
2738
- return { or: Q(e.or) };
2738
+ return { or: W(e.or) };
2739
2739
  const t = e;
2740
2740
  return {
2741
2741
  ...t,
@@ -2775,7 +2775,7 @@ class ne {
2775
2775
  */
2776
2776
  buildTimeDimensionExpression(e, t, n) {
2777
2777
  const s = v(e, n);
2778
- return t ? this.databaseAdapter.buildTimeDimension(t, s) : s instanceof F ? s : o`${s}`;
2778
+ return t ? this.databaseAdapter.buildTimeDimension(t, s) : s instanceof O ? s : o`${s}`;
2779
2779
  }
2780
2780
  /**
2781
2781
  * Build date range condition for time dimensions
@@ -2790,7 +2790,7 @@ class ne {
2790
2790
  const i = typeof s == "number" ? new Date(s * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(s), r = new Date(i);
2791
2791
  r.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? s = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(r.getTime() / 1e3) : r.getTime() : s = r.toISOString();
2792
2792
  }
2793
- return A(
2793
+ return D(
2794
2794
  Y(e, n),
2795
2795
  X(e, s)
2796
2796
  );
@@ -2799,7 +2799,7 @@ class ne {
2799
2799
  const n = this.parseRelativeDateRange(t);
2800
2800
  if (n) {
2801
2801
  let l, m;
2802
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (l = Math.floor(n.start.getTime() / 1e3), m = Math.floor(n.end.getTime() / 1e3)) : (l = n.start.getTime(), m = n.end.getTime()) : (l = n.start.toISOString(), m = n.end.toISOString()), A(
2802
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (l = Math.floor(n.start.getTime() / 1e3), m = Math.floor(n.end.getTime() / 1e3)) : (l = n.start.getTime(), m = n.end.getTime()) : (l = n.start.toISOString(), m = n.end.toISOString()), D(
2803
2803
  Y(e, l),
2804
2804
  X(e, m)
2805
2805
  );
@@ -2811,7 +2811,7 @@ class ne {
2811
2811
  const a = new Date(i);
2812
2812
  a.setUTCHours(23, 59, 59, 999);
2813
2813
  let u, c;
2814
- return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (u = Math.floor(r.getTime() / 1e3), c = Math.floor(a.getTime() / 1e3)) : (u = r.getTime(), c = a.getTime()) : (u = r.toISOString(), c = a.toISOString()), A(
2814
+ return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (u = Math.floor(r.getTime() / 1e3), c = Math.floor(a.getTime() / 1e3)) : (u = r.getTime(), c = a.getTime()) : (u = r.toISOString(), c = a.toISOString()), D(
2815
2815
  Y(e, u),
2816
2816
  X(e, c)
2817
2817
  );
@@ -2962,7 +2962,7 @@ class he {
2962
2962
  return Te(e, r);
2963
2963
  } else if (r.length === 1) {
2964
2964
  const u = s?.type === "time" && this.dateTimeBuilder.normalizeDate(a) || a;
2965
- return P(e, u);
2965
+ return Q(e, u);
2966
2966
  }
2967
2967
  return this.databaseAdapter.buildBooleanLiteral(!1);
2968
2968
  case "notEquals":
@@ -2997,7 +2997,7 @@ class he {
2997
2997
  const m = typeof c == "number" ? new Date(c * (this.databaseAdapter.getEngineType() === "sqlite" ? 1e3 : 1)) : new Date(c), p = new Date(m);
2998
2998
  p.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? c = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(p.getTime() / 1e3) : p.getTime() : c = p.toISOString();
2999
2999
  }
3000
- return A(
3000
+ return D(
3001
3001
  Y(e, u),
3002
3002
  X(e, c)
3003
3003
  );
@@ -3013,7 +3013,7 @@ class he {
3013
3013
  return u ? we(e, u) : null;
3014
3014
  }
3015
3015
  case "between":
3016
- return r.length >= 2 ? A(
3016
+ return r.length >= 2 ? D(
3017
3017
  Y(e, r[0]),
3018
3018
  X(e, r[1])
3019
3019
  ) : null;
@@ -3039,10 +3039,10 @@ class he {
3039
3039
  case "isEmpty":
3040
3040
  return ie(
3041
3041
  Ue(e),
3042
- P(e, "")
3042
+ Q(e, "")
3043
3043
  );
3044
3044
  case "isNotEmpty":
3045
- return A(
3045
+ return D(
3046
3046
  ke(e),
3047
3047
  Me(e, "")
3048
3048
  );
@@ -3065,7 +3065,7 @@ class he {
3065
3065
  buildLogicalFilter(e, t, n) {
3066
3066
  if ("and" in e && e.and) {
3067
3067
  const s = e.and.map((i) => this.buildSingleFilter(i, t, n)).filter((i) => i !== null);
3068
- return s.length > 0 ? s.length === 1 ? s[0] : A(...s) : null;
3068
+ return s.length > 0 ? s.length === 1 ? s[0] : D(...s) : null;
3069
3069
  }
3070
3070
  if ("or" in e && e.or) {
3071
3071
  const s = e.or.map((i) => this.buildSingleFilter(i, t, n)).filter((i) => i !== null);
@@ -3327,7 +3327,7 @@ function tn(d, e) {
3327
3327
  throw new Error(
3328
3328
  `Cannot substitute {${p}}: measure '${b}' not resolved yet. Ensure measures are resolved in dependency order.`
3329
3329
  );
3330
- const _ = w(), $ = o`${_}`;
3330
+ const A = w(), $ = o`${A}`;
3331
3331
  r.set(p, $);
3332
3332
  }
3333
3333
  const a = [], u = [];
@@ -3429,9 +3429,9 @@ class I {
3429
3429
  continue;
3430
3430
  }
3431
3431
  G.isCalculatedMeasure(h) ? (a.push(l), Ee(h.calculatedSql, m).forEach((b) => u.add(b)), c.getAllDependencies(l).forEach((b) => {
3432
- const [w, _] = b.split("."), $ = t.get(w);
3433
- if ($ && $.measures[_]) {
3434
- const C = $.measures[_];
3432
+ const [w, A] = b.split("."), $ = t.get(w);
3433
+ if ($ && $.measures[A]) {
3434
+ const C = $.measures[A];
3435
3435
  G.isCalculatedMeasure(C) && Ee(C.calculatedSql, w).forEach((E) => u.add(E));
3436
3436
  }
3437
3437
  })) : r.push(l);
@@ -3516,7 +3516,7 @@ class I {
3516
3516
  case "count":
3517
3517
  case "countDistinct":
3518
3518
  case "sum":
3519
- h = W(f);
3519
+ h = K(f);
3520
3520
  break;
3521
3521
  case "avg":
3522
3522
  h = this.databaseAdapter.buildAvg(f);
@@ -3528,10 +3528,10 @@ class I {
3528
3528
  h = V(f);
3529
3529
  break;
3530
3530
  case "number":
3531
- h = W(f);
3531
+ h = K(f);
3532
3532
  break;
3533
3533
  default:
3534
- h = W(f);
3534
+ h = K(f);
3535
3535
  }
3536
3536
  r.set(u, () => h);
3537
3537
  }
@@ -3573,7 +3573,7 @@ class I {
3573
3573
  case "count":
3574
3574
  case "countDistinct":
3575
3575
  case "sum":
3576
- return W(a);
3576
+ return K(a);
3577
3577
  case "avg":
3578
3578
  return this.databaseAdapter.buildAvg(a);
3579
3579
  case "min":
@@ -3581,9 +3581,9 @@ class I {
3581
3581
  case "max":
3582
3582
  return V(a);
3583
3583
  case "number":
3584
- return W(a);
3584
+ return K(a);
3585
3585
  default:
3586
- return W(a);
3586
+ return K(a);
3587
3587
  }
3588
3588
  }
3589
3589
  }
@@ -3617,7 +3617,7 @@ class I {
3617
3617
  return a ? o`(${a})` : void 0;
3618
3618
  }).filter(Boolean);
3619
3619
  if (i.length > 0) {
3620
- const r = i.length === 1 ? i[0] : A(...i);
3620
+ const r = i.length === 1 ? i[0] : D(...i);
3621
3621
  s = this.databaseAdapter.buildCaseWhen([
3622
3622
  { when: r, then: s }
3623
3623
  ]);
@@ -3629,7 +3629,7 @@ class I {
3629
3629
  case "countDistinct":
3630
3630
  return Dt(s);
3631
3631
  case "sum":
3632
- return W(s);
3632
+ return K(s);
3633
3633
  case "avg":
3634
3634
  return this.databaseAdapter.buildAvg(s);
3635
3635
  case "min":
@@ -4148,7 +4148,7 @@ class rn {
4148
4148
  const f = e;
4149
4149
  if (f.and) {
4150
4150
  const h = f.and.map((g) => this.processFilter(g, t, n, s, i)).filter((g) => g !== null);
4151
- return h.length > 0 ? A(...h) : null;
4151
+ return h.length > 0 ? D(...h) : null;
4152
4152
  }
4153
4153
  if (f.or) {
4154
4154
  const h = f.or.map((g) => this.processFilter(g, t, n, s, i)).filter((g) => g !== null);
@@ -4321,7 +4321,7 @@ class oe {
4321
4321
  const { cube: u, path: c } = r.shift(), l = this.cubes.get(u);
4322
4322
  if (l?.joins)
4323
4323
  for (const [, m] of Object.entries(l.joins)) {
4324
- const f = K(m.targetCube).name;
4324
+ const f = P(m.targetCube).name;
4325
4325
  if (a.has(f))
4326
4326
  continue;
4327
4327
  const h = [
@@ -4401,7 +4401,7 @@ class oe {
4401
4401
  const l = this.cubes.get(a);
4402
4402
  if (l?.joins)
4403
4403
  for (const [, m] of Object.entries(l.joins)) {
4404
- const f = K(m.targetCube).name;
4404
+ const f = P(m.targetCube).name;
4405
4405
  if (c.has(f))
4406
4406
  continue;
4407
4407
  const h = [
@@ -4449,10 +4449,10 @@ class oe {
4449
4449
  buildJoinCondition(e, t, n) {
4450
4450
  const s = [];
4451
4451
  for (const i of e.on) {
4452
- const r = t ? o`${o.identifier(t)}.${o.identifier(i.source.name)}` : _e(i.source), a = n ? o`${o.identifier(n)}.${o.identifier(i.target.name)}` : _e(i.target), u = i.as || P;
4452
+ const r = t ? o`${o.identifier(t)}.${o.identifier(i.source.name)}` : _e(i.source), a = n ? o`${o.identifier(n)}.${o.identifier(i.target.name)}` : _e(i.target), u = i.as || Q;
4453
4453
  s.push(u(r, a));
4454
4454
  }
4455
- return A(...s);
4455
+ return D(...s);
4456
4456
  }
4457
4457
  /**
4458
4458
  * Get all reachable cubes from a starting cube
@@ -4467,7 +4467,7 @@ class oe {
4467
4467
  const s = n.shift(), i = this.cubes.get(s);
4468
4468
  if (i?.joins)
4469
4469
  for (const [, r] of Object.entries(i.joins)) {
4470
- const u = K(r.targetCube).name;
4470
+ const u = P(r.targetCube).name;
4471
4471
  t.has(u) || (t.add(u), n.push(u));
4472
4472
  }
4473
4473
  }
@@ -4674,11 +4674,11 @@ class at {
4674
4674
  // No source alias needed - use the actual column
4675
4675
  null
4676
4676
  // No target alias needed - use the actual column
4677
- ), _ = Ae(y.relationship, y.sqlJoinType);
4677
+ ), A = Ae(y.relationship, y.sqlJoinType);
4678
4678
  a.push({
4679
4679
  cube: b,
4680
4680
  alias: `${g.toLowerCase()}_cube`,
4681
- joinType: _,
4681
+ joinType: A,
4682
4682
  joinCondition: w
4683
4683
  });
4684
4684
  }
@@ -4738,24 +4738,24 @@ class at {
4738
4738
  if (y.length === 0)
4739
4739
  continue;
4740
4740
  const b = this.analyzeJoinPathToPrimary(e, t, l.name, i);
4741
- let w, _;
4741
+ let w, A;
4742
4742
  if (b?.hasIntermediateHasMany && b.intermediateJoins.length > 0)
4743
- w = b.correctJoinKeys, _ = b.intermediateJoins;
4743
+ w = b.correctJoinKeys, A = b.intermediateJoins;
4744
4744
  else {
4745
4745
  const S = p ? this.findJoinInfoToCube(e, t.name) : this.findJoinInfoForCube(e, t, l.name);
4746
4746
  if (!S)
4747
4747
  continue;
4748
- w = p ? S.joinDef.on.map((D) => ({
4749
- sourceColumn: D.target.name,
4750
- targetColumn: D.source.name,
4751
- sourceColumnObj: D.target,
4752
- targetColumnObj: D.source
4753
- })) : S.joinDef.on.map((D) => ({
4754
- sourceColumn: D.source.name,
4755
- targetColumn: D.target.name,
4756
- sourceColumnObj: D.source,
4757
- targetColumnObj: D.target
4758
- })), _ = void 0;
4748
+ w = p || "reversed" in S && S.reversed ? S.joinDef.on.map((_) => ({
4749
+ sourceColumn: _.target.name,
4750
+ targetColumn: _.source.name,
4751
+ sourceColumnObj: _.target,
4752
+ targetColumnObj: _.source
4753
+ })) : S.joinDef.on.map((_) => ({
4754
+ sourceColumn: _.source.name,
4755
+ targetColumn: _.target.name,
4756
+ sourceColumnObj: _.source,
4757
+ targetColumnObj: _.target
4758
+ })), A = void 0;
4759
4759
  }
4760
4760
  const $ = this.findPropagatingFilters(s, l, e), C = /* @__PURE__ */ new Map([[l.name, l]]), { aggregateMeasures: T, requiredBaseMeasures: E } = I.categorizeForPostAggregation(
4761
4761
  y,
@@ -4768,7 +4768,7 @@ class at {
4768
4768
  const S = this.expandCalculatedMeasureDependencies(
4769
4769
  l,
4770
4770
  N
4771
- ), D = this.findDownstreamJoinKeys(
4771
+ ), R = this.findDownstreamJoinKeys(
4772
4772
  l,
4773
4773
  s,
4774
4774
  e
@@ -4780,8 +4780,8 @@ class at {
4780
4780
  joinKeys: w,
4781
4781
  measures: S,
4782
4782
  propagatingFilters: $.length > 0 ? $ : void 0,
4783
- downstreamJoinKeys: D.length > 0 ? D : void 0,
4784
- intermediateJoins: _ && _.length > 0 ? _ : void 0,
4783
+ downstreamJoinKeys: R.length > 0 ? R : void 0,
4784
+ intermediateJoins: A && A.length > 0 ? A : void 0,
4785
4785
  cteType: "aggregate",
4786
4786
  cteReason: f
4787
4787
  });
@@ -4797,7 +4797,7 @@ class at {
4797
4797
  for (const [, n] of e)
4798
4798
  if (n.name !== t && n.joins) {
4799
4799
  for (const [, s] of Object.entries(n.joins))
4800
- if (K(s.targetCube).name === t)
4800
+ if (P(s.targetCube).name === t)
4801
4801
  return { sourceCube: n, joinDef: s };
4802
4802
  }
4803
4803
  return null;
@@ -4837,13 +4837,13 @@ class at {
4837
4837
  for (let f = 0; f < a.length - 1; f++) {
4838
4838
  const h = a[f], g = a[f + 1], y = e.get(h.toCube);
4839
4839
  if (!y) continue;
4840
- const w = y.sql(s).where, _ = g.joinDef.on[0]?.source, $ = h.joinDef.on[0]?.target;
4840
+ const w = y.sql(s).where, A = g.joinDef.on[0]?.source, $ = h.joinDef.on[0]?.target;
4841
4841
  l.push({
4842
4842
  cube: y,
4843
4843
  joinDef: g.joinDef,
4844
4844
  securityFilter: w,
4845
4845
  primaryJoinColumn: $,
4846
- cteJoinColumn: _
4846
+ cteJoinColumn: A
4847
4847
  });
4848
4848
  }
4849
4849
  const p = a[0].joinDef.on.map((f) => ({
@@ -4882,7 +4882,7 @@ class at {
4882
4882
  if (!i.has(a) && (i.add(a), !!u.joins)) {
4883
4883
  for (const [, c] of Object.entries(u.joins))
4884
4884
  if (c.relationship === "hasMany") {
4885
- const l = K(c.targetCube);
4885
+ const l = P(c.targetCube);
4886
4886
  (r.has(a) || r.has(l.name)) && s.push({
4887
4887
  fromCube: a,
4888
4888
  toCube: l.name,
@@ -4922,15 +4922,21 @@ class at {
4922
4922
  */
4923
4923
  findJoinInfoForCube(e, t, n) {
4924
4924
  if (t.joins) {
4925
- for (const [, s] of Object.entries(t.joins))
4926
- if (K(s.targetCube).name === n)
4927
- return { sourceCube: t, joinDef: s };
4928
- }
4929
- for (const [, s] of e)
4930
- if (s.name !== t.name && s.joins) {
4931
- for (const [, i] of Object.entries(s.joins))
4932
- if (K(i.targetCube).name === n)
4933
- return { sourceCube: s, joinDef: i };
4925
+ for (const [, i] of Object.entries(t.joins))
4926
+ if (P(i.targetCube).name === n)
4927
+ return { sourceCube: t, joinDef: i };
4928
+ }
4929
+ const s = e.get(n);
4930
+ if (s?.joins) {
4931
+ for (const [, i] of Object.entries(s.joins))
4932
+ if (P(i.targetCube).name === t.name)
4933
+ return { sourceCube: s, joinDef: i, reversed: !0 };
4934
+ }
4935
+ for (const [, i] of e)
4936
+ if (!(i.name === t.name || i.name === n) && i.joins) {
4937
+ for (const [, r] of Object.entries(i.joins))
4938
+ if (P(r.targetCube).name === n)
4939
+ return { sourceCube: i, joinDef: r };
4934
4940
  }
4935
4941
  return null;
4936
4942
  }
@@ -4961,7 +4967,7 @@ class at {
4961
4967
  }
4962
4968
  if (e.joins)
4963
4969
  for (const [, r] of Object.entries(e.joins)) {
4964
- const u = K(r.targetCube).name;
4970
+ const u = P(r.targetCube).name;
4965
4971
  if (i.has(u)) {
4966
4972
  const c = r.on.map((l) => ({
4967
4973
  sourceColumn: l.source.name,
@@ -5017,7 +5023,7 @@ class at {
5017
5023
  if (!e.joins)
5018
5024
  return null;
5019
5025
  for (const [, n] of Object.entries(e.joins))
5020
- if (K(n.targetCube).name === t && n.relationship === "hasMany")
5026
+ if (P(n.targetCube).name === t && n.relationship === "hasMany")
5021
5027
  return n;
5022
5028
  return null;
5023
5029
  }
@@ -5045,7 +5051,7 @@ class at {
5045
5051
  const a = n.get(r);
5046
5052
  if (a?.joins) {
5047
5053
  for (const [, u] of Object.entries(a.joins))
5048
- if (K(u.targetCube).name === t.name && u.relationship === "hasMany") {
5054
+ if (P(u.targetCube).name === t.name && u.relationship === "hasMany") {
5049
5055
  const l = this.extractFiltersForCube(e.filters, r), m = this.extractTimeDimensionFiltersForCube(e, r), p = [...l, ...m];
5050
5056
  p.length > 0 && u.on.length > 0 && s.push({
5051
5057
  sourceCube: a,
@@ -5488,10 +5494,10 @@ class on {
5488
5494
  let f = n.db.select(c).from(a.from);
5489
5495
  if (u && e.intermediateJoins)
5490
5496
  for (const C of e.intermediateJoins) {
5491
- const T = C.cube.sql(n), N = [P(C.cteJoinColumn, C.joinDef.on[0]?.target)];
5497
+ const T = C.cube.sql(n), N = [Q(C.cteJoinColumn, C.joinDef.on[0]?.target)];
5492
5498
  C.securityFilter && N.push(C.securityFilter), f = f.leftJoin(
5493
5499
  T.from,
5494
- A(...N)
5500
+ D(...N)
5495
5501
  );
5496
5502
  }
5497
5503
  const h = s ? {
@@ -5502,8 +5508,8 @@ class on {
5502
5508
  for (const C of t.timeDimensions) {
5503
5509
  const [T, E] = C.dimension.split(".");
5504
5510
  if (T === l && r.dimensions && r.dimensions[E] && C.dateRange) {
5505
- const N = r.dimensions[E], S = this.queryBuilder.buildMeasureExpression({ sql: N.sql, type: "number" }, n), D = this.queryBuilder.buildDateRangeCondition(S, C.dateRange);
5506
- D && y.push(D);
5511
+ const N = r.dimensions[E], S = this.queryBuilder.buildMeasureExpression({ sql: N.sql, type: "number" }, n), R = this.queryBuilder.buildDateRangeCondition(S, C.dateRange);
5512
+ R && y.push(R);
5507
5513
  }
5508
5514
  }
5509
5515
  if (t.filters) {
@@ -5513,8 +5519,8 @@ class on {
5513
5519
  if (E === l && r.dimensions && r.dimensions[N]) {
5514
5520
  const S = r.dimensions[N];
5515
5521
  if (T.operator === "inDateRange") {
5516
- const D = this.queryBuilder.buildMeasureExpression({ sql: S.sql, type: "number" }, n), O = this.queryBuilder.buildDateRangeCondition(D, T.values);
5517
- O && y.push(O);
5522
+ const R = this.queryBuilder.buildMeasureExpression({ sql: S.sql, type: "number" }, n), _ = this.queryBuilder.buildDateRangeCondition(R, T.values);
5523
+ _ && y.push(_);
5518
5524
  }
5519
5525
  }
5520
5526
  }
@@ -5529,12 +5535,12 @@ class on {
5529
5535
  }
5530
5536
  const b = [];
5531
5537
  if (a.where && b.push(a.where), b.push(...g, ...y), b.length > 0) {
5532
- const C = b.length === 1 ? b[0] : A(...b);
5538
+ const C = b.length === 1 ? b[0] : D(...b);
5533
5539
  f = f.where(C);
5534
5540
  }
5535
- const w = [], _ = /* @__PURE__ */ new Set(), $ = (C) => {
5541
+ const w = [], A = /* @__PURE__ */ new Set(), $ = (C) => {
5536
5542
  const T = C?.name || (typeof C == "string" ? C : null);
5537
- T && !_.has(T) ? (_.add(T), w.push(C)) : T || w.push(C);
5543
+ T && !A.has(T) ? (A.add(T), w.push(C)) : T || w.push(C);
5538
5544
  };
5539
5545
  if (u && e.intermediateJoins) {
5540
5546
  const C = e.intermediateJoins[0];
@@ -5582,13 +5588,13 @@ class on {
5582
5588
  const i = [];
5583
5589
  if (s.intermediateJoins && s.intermediateJoins.length > 0) {
5584
5590
  const r = s.intermediateJoins[0], a = s.joinKeys[0]?.sourceColumnObj, u = o`${o.identifier(t)}.${o.identifier(r.primaryJoinColumn.name)}`;
5585
- i.push(P(a, u));
5591
+ i.push(Q(a, u));
5586
5592
  } else
5587
5593
  for (const r of s.joinKeys) {
5588
5594
  const a = r.sourceColumnObj || o.identifier(r.sourceColumn), u = o`${o.identifier(t)}.${o.identifier(r.targetColumn)}`;
5589
- i.push(P(a, u));
5595
+ i.push(Q(a, u));
5590
5596
  }
5591
- return i.length === 1 ? i[0] : A(...i);
5597
+ return i.length === 1 ? i[0] : D(...i);
5592
5598
  }
5593
5599
  /**
5594
5600
  * Build a subquery filter for propagating filters from related cubes.
@@ -5617,12 +5623,12 @@ class on {
5617
5623
  }
5618
5624
  if (i.length === 0)
5619
5625
  return null;
5620
- const r = i.length === 1 ? i[0] : A(...i), a = e.joinConditions;
5626
+ const r = i.length === 1 ? i[0] : D(...i), a = e.joinConditions;
5621
5627
  if (a.length === 1) {
5622
5628
  const { source: u, target: c } = a[0], l = t.db.select({ pk: u }).from(s.from).where(r);
5623
5629
  return o`${c} IN ${l}`;
5624
5630
  } else {
5625
- const u = a.map((m) => P(m.source, m.target)), c = A(
5631
+ const u = a.map((m) => Q(m.source, m.target)), c = D(
5626
5632
  ...u,
5627
5633
  r
5628
5634
  ), l = t.db.select({ one: o`1` }).from(s.from).where(c);
@@ -6217,19 +6223,19 @@ class pn {
6217
6223
  const b = e;
6218
6224
  y = b.type === "and";
6219
6225
  for (const w of b.filters || []) {
6220
- const _ = this.buildFilterCondition(w, t, n, s);
6221
- _ && g.push(_);
6226
+ const A = this.buildFilterCondition(w, t, n, s);
6227
+ A && g.push(A);
6222
6228
  }
6223
6229
  } else {
6224
6230
  const b = e;
6225
6231
  y = "and" in b && !!b.and;
6226
6232
  const w = b.and || b.or || [];
6227
- for (const _ of w) {
6228
- const $ = this.buildFilterCondition(_, t, n, s);
6233
+ for (const A of w) {
6234
+ const $ = this.buildFilterCondition(A, t, n, s);
6229
6235
  $ && g.push($);
6230
6236
  }
6231
6237
  }
6232
- return g.length === 0 ? null : g.length === 1 ? g[0] : y ? A(...g) : o`(${o.join(g, o` OR `)})`;
6238
+ return g.length === 0 ? null : g.length === 1 ? g[0] : y ? D(...g) : o`(${o.join(g, o` OR `)})`;
6233
6239
  }
6234
6240
  const a = e, [u, c] = a.member.split("."), l = a.dateRange !== void 0;
6235
6241
  if (a.operator !== "set" && a.operator !== "notSet" && !l && (!a.values || a.values.length === 0 || a.values[0] === void 0 || a.values[0] === ""))
@@ -6285,7 +6291,7 @@ class pn {
6285
6291
  step_time: o`MIN(${e.timeExpr})`.as("step_time")
6286
6292
  }).from(s.from);
6287
6293
  if (r = this.addCrossJoinsToQuery(r, e, t, i), i.length > 0) {
6288
- const a = i.length === 1 ? i[0] : A(...i);
6294
+ const a = i.length === 1 ? i[0] : D(...i);
6289
6295
  r = r.where(a);
6290
6296
  }
6291
6297
  return r = r.groupBy(e.bindingKeyExpr), t.db.$with(n).as(r);
@@ -6318,7 +6324,7 @@ class pn {
6318
6324
  o`${e.bindingKeyExpr} = ${o.identifier(i)}.binding_key`
6319
6325
  );
6320
6326
  if (l = this.addCrossJoinsToQuery(l, e, t, a), a.length > 0) {
6321
- const m = a.length === 1 ? a[0] : A(...a);
6327
+ const m = a.length === 1 ? a[0] : D(...a);
6322
6328
  l = l.where(m);
6323
6329
  }
6324
6330
  return l = l.groupBy(e.bindingKeyExpr), t.db.$with(s).as(l);
@@ -6334,8 +6340,8 @@ class pn {
6334
6340
  for (const r of i.joinPath) {
6335
6341
  const a = r.joinDef, u = [];
6336
6342
  for (const p of a.on)
6337
- p.as ? u.push(p.as(p.source, p.target)) : u.push(P(p.source, p.target));
6338
- const c = u.length === 1 ? u[0] : A(...u), m = i.cube.sql(n);
6343
+ p.as ? u.push(p.as(p.source, p.target)) : u.push(Q(p.source, p.target));
6344
+ const c = u.length === 1 ? u[0] : D(...u), m = i.cube.sql(n);
6339
6345
  e = e.leftJoin(m.from, c), m.where && s.push(m.where);
6340
6346
  }
6341
6347
  return e;
@@ -6644,7 +6650,7 @@ class hn {
6644
6650
  const p = this.buildFilterCondition(m, t, n);
6645
6651
  p && c.push(p);
6646
6652
  }
6647
- return c.length === 0 ? null : c.length === 1 ? c[0] : "and" in e ? A(...c) : o`(${o.join(c, o` OR `)})`;
6653
+ return c.length === 0 ? null : c.length === 1 ? c[0] : "and" in e ? D(...c) : o`(${o.join(c, o` OR `)})`;
6648
6654
  }
6649
6655
  if ("type" in e && "filters" in e) {
6650
6656
  const u = e, c = [];
@@ -6652,7 +6658,7 @@ class hn {
6652
6658
  const m = this.buildFilterCondition(l, t, n);
6653
6659
  m && c.push(m);
6654
6660
  }
6655
- return c.length === 0 ? null : c.length === 1 ? c[0] : u.type === "and" ? A(...c) : o`(${o.join(c, o` OR `)})`;
6661
+ return c.length === 0 ? null : c.length === 1 ? c[0] : u.type === "and" ? D(...c) : o`(${o.join(c, o` OR `)})`;
6656
6662
  }
6657
6663
  const s = e, [, i] = s.member.split("."), r = t.dimensions?.[i];
6658
6664
  if (!r) return null;
@@ -6684,7 +6690,7 @@ class hn {
6684
6690
  event_path: o`${a}`.as("event_path")
6685
6691
  }).from(s.from);
6686
6692
  if (c.length > 0) {
6687
- const m = c.length === 1 ? c[0] : A(...c);
6693
+ const m = c.length === 1 ? c[0] : D(...c);
6688
6694
  l = l.where(m);
6689
6695
  }
6690
6696
  return l = l.groupBy(i, a), e.entityLimit && (l = l.limit(e.entityLimit)), n.db.$with("starting_entities").as(l);
@@ -6701,7 +6707,7 @@ class hn {
6701
6707
  o`${i} = ${o.identifier(m)}.binding_key`,
6702
6708
  o`${r} < ${o.identifier(m)}.${o.identifier(p)}`
6703
6709
  );
6704
- const g = h.length === 1 ? h[0] : A(...h), y = c ? o`${a} || ${"→"} || ${o.identifier(m)}.event_path` : o`${a}`, b = n.db.select({
6710
+ const g = h.length === 1 ? h[0] : D(...h), y = c ? o`${a} || ${"→"} || ${o.identifier(m)}.event_path` : o`${a}`, b = n.db.select({
6705
6711
  binding_key: o`${i}`.as("binding_key"),
6706
6712
  step_time: o`${r}`.as("step_time"),
6707
6713
  event_type: o`${a}`.as("event_type"),
@@ -6730,7 +6736,7 @@ class hn {
6730
6736
  o`${i} = ${o.identifier(m)}.binding_key`,
6731
6737
  o`${r} > ${o.identifier(m)}.${o.identifier(p)}`
6732
6738
  );
6733
- const g = h.length === 1 ? h[0] : A(...h), y = c ? o`${o.identifier(m)}.event_path || ${"→"} || ${a}` : o`${a}`, b = n.db.select({
6739
+ const g = h.length === 1 ? h[0] : D(...h), y = c ? o`${o.identifier(m)}.event_path || ${"→"} || ${a}` : o`${a}`, b = n.db.select({
6734
6740
  binding_key: o`${i}`.as("binding_key"),
6735
6741
  step_time: o`${r}`.as("step_time"),
6736
6742
  event_type: o`${a}`.as("event_type"),
@@ -6761,7 +6767,7 @@ class hn {
6761
6767
  s.where && h.push(s.where), h.push(
6762
6768
  o`${r} < ${o.identifier(m)}.${o.identifier(p)}`
6763
6769
  );
6764
- const g = h.length === 1 ? h[0] : A(...h), y = c ? o`${a} || ${"→"} || ${o.identifier(m)}.event_path` : o`${a}`, b = n.db.select({
6770
+ const g = h.length === 1 ? h[0] : D(...h), y = c ? o`${a} || ${"→"} || ${o.identifier(m)}.event_path` : o`${a}`, b = n.db.select({
6765
6771
  binding_key: o`${i}`.as("binding_key"),
6766
6772
  step_time: o`${r}`.as("step_time"),
6767
6773
  event_type: o`${a}`.as("event_type"),
@@ -6794,7 +6800,7 @@ class hn {
6794
6800
  s.where && h.push(s.where), h.push(
6795
6801
  o`${r} > ${o.identifier(m)}.${o.identifier(p)}`
6796
6802
  );
6797
- const g = h.length === 1 ? h[0] : A(...h), y = c ? o`${o.identifier(m)}.event_path || ${"→"} || ${a}` : o`${a}`, b = n.db.select({
6803
+ const g = h.length === 1 ? h[0] : D(...h), y = c ? o`${o.identifier(m)}.event_path || ${"→"} || ${a}` : o`${a}`, b = n.db.select({
6798
6804
  binding_key: o`${i}`.as("binding_key"),
6799
6805
  step_time: o`${r}`.as("step_time"),
6800
6806
  event_type: o`${a}`.as("event_type"),
@@ -7230,7 +7236,7 @@ class gn {
7230
7236
  const y = this.buildSingleFilterCondition(g, t, n, s);
7231
7237
  y && p.push(y);
7232
7238
  }
7233
- return p.length === 0 ? null : p.length === 1 ? p[0] : f ? A(...p) : o`(${o.join(p, o` OR `)})`;
7239
+ return p.length === 0 ? null : p.length === 1 ? p[0] : f ? D(...p) : o`(${o.join(p, o` OR `)})`;
7234
7240
  }
7235
7241
  const i = e, [r, a] = i.member.split("."), u = n.get(r);
7236
7242
  if (!u) return null;
@@ -7272,7 +7278,7 @@ class gn {
7272
7278
  }
7273
7279
  let u = n.db.select(a).from(s.from);
7274
7280
  if (i.length > 0) {
7275
- const l = i.length === 1 ? i[0] : A(...i);
7281
+ const l = i.length === 1 ? i[0] : D(...i);
7276
7282
  u = u.where(l);
7277
7283
  }
7278
7284
  const c = [t.bindingKeyExpr];
@@ -7327,7 +7333,7 @@ class gn {
7327
7333
  o`${t.bindingKeyExpr} = cohort_base.binding_key`
7328
7334
  );
7329
7335
  if (i.length > 0) {
7330
- const m = i.length === 1 ? i[0] : A(...i);
7336
+ const m = i.length === 1 ? i[0] : D(...i);
7331
7337
  c = c.where(m);
7332
7338
  }
7333
7339
  const l = [
@@ -7516,14 +7522,14 @@ class J {
7516
7522
  const c = this.buildUnifiedQuery(u, t, a), l = this.queryBuilder.collectNumericFields(e, t), m = await this.dbExecutor.execute(c, l), p = Array.isArray(m) ? m.map((b) => {
7517
7523
  const w = { ...b };
7518
7524
  if (t.timeDimensions) {
7519
- for (const _ of t.timeDimensions)
7520
- if (_.dimension in w) {
7521
- let $ = w[_.dimension];
7525
+ for (const A of t.timeDimensions)
7526
+ if (A.dimension in w) {
7527
+ let $ = w[A.dimension];
7522
7528
  if (typeof $ == "string" && $.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
7523
7529
  const C = $.replace(" ", "T"), T = !C.endsWith("Z") && !C.includes("+") ? C + "Z" : C;
7524
7530
  $ = new Date(T);
7525
7531
  }
7526
- $ = this.databaseAdapter.convertTimeDimensionResult($), w[_.dimension] = $;
7532
+ $ = this.databaseAdapter.convertTimeDimensionResult($), w[A.dimension] = $;
7527
7533
  }
7528
7534
  }
7529
7535
  return w;
@@ -7805,8 +7811,8 @@ class J {
7805
7811
  if (y.dimension in g) {
7806
7812
  let b = g[y.dimension];
7807
7813
  if (typeof b == "string" && b.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
7808
- const w = b.replace(" ", "T"), _ = !w.endsWith("Z") && !w.includes("+") ? w + "Z" : w;
7809
- b = new Date(_);
7814
+ const w = b.replace(" ", "T"), A = !w.endsWith("Z") && !w.includes("+") ? w + "Z" : w;
7815
+ b = new Date(A);
7810
7816
  }
7811
7817
  b = this.databaseAdapter.convertTimeDimensionResult(b), g[y.dimension] = b;
7812
7818
  }
@@ -7860,15 +7866,15 @@ class J {
7860
7866
  if (!s.has(T)) {
7861
7867
  const N = {
7862
7868
  filters: C.filters
7863
- }, S = /* @__PURE__ */ new Map([[T, C.sourceCube]]), D = this.queryBuilder.buildWhereConditions(
7869
+ }, S = /* @__PURE__ */ new Map([[T, C.sourceCube]]), R = this.queryBuilder.buildWhereConditions(
7864
7870
  S,
7865
7871
  N,
7866
7872
  n
7867
7873
  );
7868
- s.set(T, D);
7874
+ s.set(T, R);
7869
7875
  }
7870
7876
  const E = s.get(T);
7871
- E && E.length > 0 && (C.preBuiltFilterSQL = E.length === 1 ? E[0] : A(...E));
7877
+ E && E.length > 0 && (C.preBuiltFilterSQL = E.length === 1 ? E[0] : D(...E));
7872
7878
  }
7873
7879
  }
7874
7880
  const i = [], r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
@@ -7895,10 +7901,10 @@ class J {
7895
7901
  if (m[T]) {
7896
7902
  const [, E] = T.split("."), N = c.get(C);
7897
7903
  if (N && N.measures && N.measures[E]) {
7898
- const S = N.measures[E], D = o`${o.identifier($.cteAlias)}.${o.identifier(E)}`;
7899
- let O;
7904
+ const S = N.measures[E], R = o`${o.identifier($.cteAlias)}.${o.identifier(E)}`;
7905
+ let _;
7900
7906
  if (S.type === "calculated" && S.calculatedSql)
7901
- O = this.queryBuilder.buildCTECalculatedMeasure(
7907
+ _ = this.queryBuilder.buildCTECalculatedMeasure(
7902
7908
  S,
7903
7909
  N,
7904
7910
  $,
@@ -7906,47 +7912,47 @@ class J {
7906
7912
  n
7907
7913
  );
7908
7914
  else {
7909
- const R = $.cteReason === "fanOutPrevention", k = this.shouldUseMaxForHasManyAtJoinKeyGrain(
7915
+ const F = $.cteReason === "fanOutPrevention", k = this.shouldUseMaxForHasManyAtJoinKeyGrain(
7910
7916
  $,
7911
7917
  t,
7912
7918
  c
7913
- ), M = R || k;
7919
+ ), M = F || k;
7914
7920
  switch (S.type) {
7915
7921
  case "count":
7916
7922
  case "countDistinct":
7917
7923
  case "sum":
7918
- O = M ? V(D) : W(D);
7924
+ _ = M ? V(R) : K(R);
7919
7925
  break;
7920
7926
  case "avg":
7921
- O = M ? V(D) : this.databaseAdapter.buildAvg(D);
7927
+ _ = M ? V(R) : this.databaseAdapter.buildAvg(R);
7922
7928
  break;
7923
7929
  case "min":
7924
- O = re(D);
7930
+ _ = re(R);
7925
7931
  break;
7926
7932
  case "max":
7927
- O = V(D);
7933
+ _ = V(R);
7928
7934
  break;
7929
7935
  case "number":
7930
- O = M ? V(D) : W(D);
7936
+ _ = M ? V(R) : K(R);
7931
7937
  break;
7932
7938
  default:
7933
- O = M ? V(D) : W(D);
7939
+ _ = M ? V(R) : K(R);
7934
7940
  }
7935
7941
  }
7936
- m[T] = o`${O}`.as(T);
7942
+ m[T] = o`${_}`.as(T);
7937
7943
  }
7938
7944
  }
7939
7945
  for (const T in m) {
7940
7946
  const [E, N] = T.split(".");
7941
7947
  if (E === C) {
7942
- const S = c.get(C), D = S && S.dimensions?.[N], O = T.startsWith(C + ".");
7943
- if (D || O) {
7944
- let R = $.joinKeys.find((k) => k.targetColumn === N);
7945
- if (!R && S?.dimensions?.[N]) {
7948
+ const S = c.get(C), R = S && S.dimensions?.[N], _ = T.startsWith(C + ".");
7949
+ if (R || _) {
7950
+ let F = $.joinKeys.find((k) => k.targetColumn === N);
7951
+ if (!F && S?.dimensions?.[N]) {
7946
7952
  const k = S.dimensions[N].sql;
7947
- R = $.joinKeys.find((M) => M.targetColumnObj === k);
7953
+ F = $.joinKeys.find((M) => M.targetColumnObj === k);
7948
7954
  }
7949
- R ? m[T] = o`${o.identifier($.cteAlias)}.${o.identifier(N)}`.as(T) : O && S?.dimensions?.[N] && (m[T] = o`${o.identifier($.cteAlias)}.${o.identifier(N)}`.as(T));
7955
+ F ? m[T] = o`${o.identifier($.cteAlias)}.${o.identifier(N)}`.as(T) : _ && S?.dimensions?.[N] && (m[T] = o`${o.identifier($.cteAlias)}.${o.identifier(N)}`.as(T));
7950
7956
  }
7951
7957
  }
7952
7958
  }
@@ -7959,17 +7965,17 @@ class J {
7959
7965
  if (I.isPostAggregationWindow(N)) {
7960
7966
  const S = I.getWindowBaseMeasure(N, C);
7961
7967
  if (S) {
7962
- const [D, O] = S.split("."), R = c.get(D);
7963
- if (R?.measures?.[O]) {
7964
- const k = R.measures[O], M = e.preAggregationCTEs?.find(
7965
- (H) => H.cube?.name === D && H.measures?.includes(S)
7968
+ const [R, _] = S.split("."), F = c.get(R);
7969
+ if (F?.measures?.[_]) {
7970
+ const k = F.measures[_], M = e.preAggregationCTEs?.find(
7971
+ (H) => H.cube?.name === R && H.measures?.includes(S)
7966
7972
  );
7967
7973
  let z;
7968
7974
  if (M) {
7969
- const H = o`${o.identifier(M.cteAlias)}.${o.identifier(O)}`;
7975
+ const H = o`${o.identifier(M.cteAlias)}.${o.identifier(_)}`;
7970
7976
  z = o`sum(${H})`;
7971
7977
  } else
7972
- z = this.queryBuilder.buildMeasureExpression(k, n, R);
7978
+ z = this.queryBuilder.buildMeasureExpression(k, n, F);
7973
7979
  m[S] || (m[S] = o`${z}`.as(S));
7974
7980
  const se = this.buildPostAggregationWindowExpression(
7975
7981
  N,
@@ -8017,24 +8023,24 @@ class J {
8017
8023
  continue;
8018
8024
  const T = r.get($.cube.name);
8019
8025
  if ($.junctionTable) {
8020
- const R = $.junctionTable, k = [];
8021
- if (R.securitySql) {
8022
- const M = R.securitySql(n.securityContext);
8026
+ const F = $.junctionTable, k = [];
8027
+ if (F.securitySql) {
8028
+ const M = F.securitySql(n.securityContext);
8023
8029
  Array.isArray(M) ? k.push(...M) : k.push(M);
8024
8030
  }
8025
8031
  try {
8026
- switch (R.joinType || "left") {
8032
+ switch (F.joinType || "left") {
8027
8033
  case "left":
8028
- f = f.leftJoin(R.table, R.joinCondition);
8034
+ f = f.leftJoin(F.table, F.joinCondition);
8029
8035
  break;
8030
8036
  case "inner":
8031
- f = f.innerJoin(R.table, R.joinCondition);
8037
+ f = f.innerJoin(F.table, F.joinCondition);
8032
8038
  break;
8033
8039
  case "right":
8034
- f = f.rightJoin(R.table, R.joinCondition);
8040
+ f = f.rightJoin(F.table, F.joinCondition);
8035
8041
  break;
8036
8042
  case "full":
8037
- f = f.fullJoin(R.table, R.joinCondition);
8043
+ f = f.fullJoin(F.table, F.joinCondition);
8038
8044
  break;
8039
8045
  }
8040
8046
  k.length > 0 && p.push(...k);
@@ -8045,31 +8051,31 @@ class J {
8045
8051
  if (T)
8046
8052
  E = o`${o.identifier(T)}`, N = this.cteBuilder.buildCTEJoinCondition($, T, e), S = void 0;
8047
8053
  else {
8048
- const R = a.get($.cube.name), k = $.cube.sql(n);
8049
- if (E = k.from, S = k.where, R) {
8054
+ const F = a.get($.cube.name), k = $.cube.sql(n);
8055
+ if (E = k.from, S = k.where, F) {
8050
8056
  const M = [];
8051
- for (const z of R.joinKeys) {
8052
- const se = o`${o.identifier(R.cteAlias)}.${o.identifier(z.sourceColumn)}`, H = z.targetColumnObj || o.identifier(z.targetColumn);
8053
- M.push(P(se, H));
8057
+ for (const z of F.joinKeys) {
8058
+ const se = o`${o.identifier(F.cteAlias)}.${o.identifier(z.sourceColumn)}`, H = z.targetColumnObj || o.identifier(z.targetColumn);
8059
+ M.push(Q(se, H));
8054
8060
  }
8055
- N = M.length === 1 ? M[0] : A(...M);
8061
+ N = M.length === 1 ? M[0] : D(...M);
8056
8062
  } else
8057
8063
  N = $.joinCondition;
8058
8064
  }
8059
- const D = $.joinType || "left", O = D !== "inner" && S ? A(N, S) : N;
8065
+ const R = $.joinType || "left", _ = R !== "inner" && S ? D(N, S) : N;
8060
8066
  try {
8061
- switch (D) {
8067
+ switch (R) {
8062
8068
  case "left":
8063
- f = f.leftJoin(E, O), S && h.add($.cube.name);
8069
+ f = f.leftJoin(E, _), S && h.add($.cube.name);
8064
8070
  break;
8065
8071
  case "inner":
8066
8072
  f = f.innerJoin(E, N);
8067
8073
  break;
8068
8074
  case "right":
8069
- f = f.rightJoin(E, O), S && h.add($.cube.name);
8075
+ f = f.rightJoin(E, _), S && h.add($.cube.name);
8070
8076
  break;
8071
8077
  case "full":
8072
- f = f.fullJoin(E, O), S && h.add($.cube.name);
8078
+ f = f.fullJoin(E, _), S && h.add($.cube.name);
8073
8079
  break;
8074
8080
  }
8075
8081
  } catch {
@@ -8094,7 +8100,7 @@ class J {
8094
8100
  // Reuse pre-built filters for parameter deduplication
8095
8101
  );
8096
8102
  if (y.length > 0 && p.push(...y), p.length > 0) {
8097
- const $ = p.length === 1 ? p[0] : A(...p);
8103
+ const $ = p.length === 1 ? p[0] : D(...p);
8098
8104
  f = f.where($);
8099
8105
  }
8100
8106
  const b = this.queryBuilder.buildGroupByFields(
@@ -8115,11 +8121,11 @@ class J {
8115
8121
  // Pass the queryPlan to handle CTE scenarios
8116
8122
  );
8117
8123
  if (w.length > 0) {
8118
- const $ = w.length === 1 ? w[0] : A(...w);
8124
+ const $ = w.length === 1 ? w[0] : D(...w);
8119
8125
  f = f.having($);
8120
8126
  }
8121
- const _ = this.queryBuilder.buildOrderBy(t);
8122
- return _.length > 0 && (f = f.orderBy(..._)), f = this.queryBuilder.applyLimitAndOffset(f, t), f;
8127
+ const A = this.queryBuilder.buildOrderBy(t);
8128
+ return A.length > 0 && (f = f.orderBy(...A)), f = this.queryBuilder.applyLimitAndOffset(f, t), f;
8123
8129
  }
8124
8130
  /**
8125
8131
  * Convert query plan to cube map for QueryBuilder methods
@@ -8377,15 +8383,15 @@ class J {
8377
8383
  const h = f.field.includes(".") ? f.field.split(".")[1] : f.field;
8378
8384
  if (n.timeDimensions)
8379
8385
  for (const b of n.timeDimensions) {
8380
- const [w, _] = b.dimension.split(".");
8381
- if (_ === h) {
8386
+ const [w, A] = b.dimension.split(".");
8387
+ if (A === h) {
8382
8388
  const $ = u(w, h);
8383
8389
  if ($)
8384
8390
  return {
8385
8391
  field: $,
8386
8392
  direction: f.direction
8387
8393
  };
8388
- const C = i.dimensions?.[_];
8394
+ const C = i.dimensions?.[A];
8389
8395
  if (C)
8390
8396
  return {
8391
8397
  field: this.queryBuilder.buildTimeDimensionExpression(