drizzle-cube 0.3.31 → 0.3.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,28 @@
1
- import { formatSqlString as Z, handleLoad as He, handleValidate as Ye, handleDiscover as Xe, generateRequestId as ht } from "./utils.js";
2
- const x = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
1
+ import { formatSqlString as te, handleLoad as Ze, handleValidate as et, handleDiscover as tt, generateRequestId as Ct } from "./utils.js";
2
+ const k = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
3
3
  function L(d, e) {
4
4
  if (!d || typeof d != "object")
5
5
  return !1;
6
6
  if (d instanceof e)
7
7
  return !0;
8
- if (!Object.prototype.hasOwnProperty.call(e, x))
8
+ if (!Object.prototype.hasOwnProperty.call(e, k))
9
9
  throw new Error(
10
10
  `Class "${e.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
11
11
  );
12
12
  let t = Object.getPrototypeOf(d).constructor;
13
13
  if (t)
14
14
  for (; t; ) {
15
- if (x in t && t[x] === e[x])
15
+ if (k in t && t[k] === e[k])
16
16
  return !0;
17
17
  t = Object.getPrototypeOf(t);
18
18
  }
19
19
  return !1;
20
20
  }
21
- class te {
21
+ class se {
22
22
  constructor(e, t) {
23
23
  this.table = e, this.config = t, this.name = t.name, this.keyAsName = t.keyAsName, this.notNull = t.notNull, this.default = t.default, this.defaultFn = t.defaultFn, this.onUpdateFn = t.onUpdateFn, this.hasDefault = t.hasDefault, this.primary = t.primaryKey, this.isUnique = t.isUnique, this.uniqueName = t.uniqueName, this.uniqueType = t.uniqueType, this.dataType = t.dataType, this.columnType = t.columnType, this.generated = t.generated, this.generatedIdentity = t.generatedIdentity;
24
24
  }
25
- static [x] = "Column";
25
+ static [k] = "Column";
26
26
  name;
27
27
  keyAsName;
28
28
  primary;
@@ -51,12 +51,12 @@ class te {
51
51
  return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
52
52
  }
53
53
  }
54
- const ge = /* @__PURE__ */ Symbol.for("drizzle:Name"), Fe = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
55
- function gt(d) {
56
- return !!d && typeof d == "function" && Fe in d && d[Fe] === !0;
54
+ const be = /* @__PURE__ */ Symbol.for("drizzle:Name"), Le = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
55
+ function wt(d) {
56
+ return !!d && typeof d == "function" && Le in d && d[Le] === !0;
57
57
  }
58
- class Ze {
59
- static [x] = "Subquery";
58
+ class nt {
59
+ static [k] = "Subquery";
60
60
  constructor(e, t, n, s = !1, i = []) {
61
61
  this._ = {
62
62
  brand: "Subquery",
@@ -71,66 +71,66 @@ class Ze {
71
71
  // return new SQL([this]);
72
72
  // }
73
73
  }
74
- const bt = {
74
+ const $t = {
75
75
  startActiveSpan(d, e) {
76
76
  return e();
77
77
  }
78
- }, ee = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig"), be = /* @__PURE__ */ Symbol.for("drizzle:Schema"), Oe = /* @__PURE__ */ Symbol.for("drizzle:Columns"), Ie = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns"), ye = /* @__PURE__ */ Symbol.for("drizzle:OriginalName"), Ce = /* @__PURE__ */ Symbol.for("drizzle:BaseName"), ue = /* @__PURE__ */ Symbol.for("drizzle:IsAlias"), Le = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder"), yt = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
79
- class B {
80
- static [x] = "Table";
78
+ }, ne = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig"), ye = /* @__PURE__ */ Symbol.for("drizzle:Schema"), Me = /* @__PURE__ */ Symbol.for("drizzle:Columns"), je = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns"), Ce = /* @__PURE__ */ Symbol.for("drizzle:OriginalName"), we = /* @__PURE__ */ Symbol.for("drizzle:BaseName"), le = /* @__PURE__ */ Symbol.for("drizzle:IsAlias"), Ue = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder"), Tt = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
79
+ class P {
80
+ static [k] = "Table";
81
81
  /** @internal */
82
82
  static Symbol = {
83
- Name: ge,
84
- Schema: be,
85
- OriginalName: ye,
86
- Columns: Oe,
87
- ExtraConfigColumns: Ie,
88
- BaseName: Ce,
89
- IsAlias: ue,
90
- ExtraConfigBuilder: Le
83
+ Name: be,
84
+ Schema: ye,
85
+ OriginalName: Ce,
86
+ Columns: Me,
87
+ ExtraConfigColumns: je,
88
+ BaseName: we,
89
+ IsAlias: le,
90
+ ExtraConfigBuilder: Ue
91
91
  };
92
92
  /**
93
93
  * @internal
94
94
  * Can be changed if the table is aliased.
95
95
  */
96
- [ge];
96
+ [be];
97
97
  /**
98
98
  * @internal
99
99
  * Used to store the original name of the table, before any aliasing.
100
100
  */
101
- [ye];
101
+ [Ce];
102
102
  /** @internal */
103
- [be];
103
+ [ye];
104
104
  /** @internal */
105
- [Oe];
105
+ [Me];
106
106
  /** @internal */
107
- [Ie];
107
+ [je];
108
108
  /**
109
109
  * @internal
110
110
  * Used to store the table name before the transformation via the `tableCreator` functions.
111
111
  */
112
- [Ce];
112
+ [we];
113
113
  /** @internal */
114
- [ue] = !1;
114
+ [le] = !1;
115
115
  /** @internal */
116
- [yt] = !0;
116
+ [Tt] = !0;
117
117
  /** @internal */
118
- [Le] = void 0;
118
+ [Ue] = void 0;
119
119
  constructor(e, t, n) {
120
- this[ge] = this[ye] = e, this[be] = t, this[Ce] = n;
120
+ this[be] = this[Ce] = e, this[ye] = t, this[we] = n;
121
121
  }
122
122
  }
123
- function et(d) {
123
+ function st(d) {
124
124
  return d != null && typeof d.getSQL == "function";
125
125
  }
126
- function Ct(d) {
126
+ function Et(d) {
127
127
  const e = { sql: "", params: [] };
128
128
  for (const t of d)
129
129
  e.sql += t.sql, e.params.push(...t.params), t.typings?.length && (e.typings || (e.typings = []), e.typings.push(...t.typings));
130
130
  return e;
131
131
  }
132
- class j {
133
- static [x] = "StringChunk";
132
+ class M {
133
+ static [k] = "StringChunk";
134
134
  value;
135
135
  constructor(e) {
136
136
  this.value = Array.isArray(e) ? e : [e];
@@ -143,16 +143,16 @@ class O {
143
143
  constructor(e) {
144
144
  this.queryChunks = e;
145
145
  for (const t of e)
146
- if (L(t, B)) {
147
- const n = t[B.Symbol.Schema];
146
+ if (L(t, P)) {
147
+ const n = t[P.Symbol.Schema];
148
148
  this.usedTables.push(
149
- n === void 0 ? t[B.Symbol.Name] : n + "." + t[B.Symbol.Name]
149
+ n === void 0 ? t[P.Symbol.Name] : n + "." + t[P.Symbol.Name]
150
150
  );
151
151
  }
152
152
  }
153
- static [x] = "SQL";
153
+ static [k] = "SQL";
154
154
  /** @internal */
155
- decoder = tt;
155
+ decoder = it;
156
156
  shouldInlineParams = !1;
157
157
  /** @internal */
158
158
  usedTables = [];
@@ -160,7 +160,7 @@ class O {
160
160
  return this.queryChunks.push(...e.queryChunks), this;
161
161
  }
162
162
  toQuery(e) {
163
- return bt.startActiveSpan("drizzle.buildSQL", (t) => {
163
+ return $t.startActiveSpan("drizzle.buildSQL", (t) => {
164
164
  const n = this.buildQueryFromSourceParams(this.queryChunks, e);
165
165
  return t?.setAttributes({
166
166
  "drizzle.query.text": n.sql,
@@ -180,50 +180,50 @@ class O {
180
180
  inlineParams: u,
181
181
  paramStartIndex: c
182
182
  } = n;
183
- return Ct(e.map((l) => {
184
- if (L(l, j))
183
+ return Et(e.map((l) => {
184
+ if (L(l, M))
185
185
  return { sql: l.value.join(""), params: [] };
186
- if (L(l, Ne))
186
+ if (L(l, De))
187
187
  return { sql: i(l.value), params: [] };
188
188
  if (l === void 0)
189
189
  return { sql: "", params: [] };
190
190
  if (Array.isArray(l)) {
191
- const m = [new j("(")];
191
+ const m = [new M("(")];
192
192
  for (const [p, f] of l.entries())
193
- m.push(f), p < l.length - 1 && m.push(new j(", "));
194
- return m.push(new j(")")), this.buildQueryFromSourceParams(m, n);
193
+ m.push(f), p < l.length - 1 && m.push(new M(", "));
194
+ return m.push(new M(")")), this.buildQueryFromSourceParams(m, n);
195
195
  }
196
196
  if (L(l, O))
197
197
  return this.buildQueryFromSourceParams(l.queryChunks, {
198
198
  ...n,
199
199
  inlineParams: u || l.shouldInlineParams
200
200
  });
201
- if (L(l, B)) {
202
- const m = l[B.Symbol.Schema], p = l[B.Symbol.Name];
201
+ if (L(l, P)) {
202
+ const m = l[P.Symbol.Schema], p = l[P.Symbol.Name];
203
203
  return {
204
- sql: m === void 0 || l[ue] ? i(p) : i(m) + "." + i(p),
204
+ sql: m === void 0 || l[le] ? i(p) : i(m) + "." + i(p),
205
205
  params: []
206
206
  };
207
207
  }
208
- if (L(l, te)) {
208
+ if (L(l, se)) {
209
209
  const m = s.getColumnCasing(l);
210
210
  if (t.invokeSource === "indexes")
211
211
  return { sql: i(m), params: [] };
212
- const p = l.table[B.Symbol.Schema];
212
+ const p = l.table[P.Symbol.Schema];
213
213
  return {
214
- sql: l.table[ue] || p === void 0 ? i(l.table[B.Symbol.Name]) + "." + i(m) : i(p) + "." + i(l.table[B.Symbol.Name]) + "." + i(m),
214
+ sql: l.table[le] || p === void 0 ? i(l.table[P.Symbol.Name]) + "." + i(m) : i(p) + "." + i(l.table[P.Symbol.Name]) + "." + i(m),
215
215
  params: []
216
216
  };
217
217
  }
218
- if (L(l, st)) {
219
- const m = l[ee].schema, p = l[ee].name;
218
+ if (L(l, ot)) {
219
+ const m = l[ne].schema, p = l[ne].name;
220
220
  return {
221
- sql: m === void 0 || l[ee].isAlias ? i(p) : i(m) + "." + i(p),
221
+ sql: m === void 0 || l[ne].isAlias ? i(p) : i(m) + "." + i(p),
222
222
  params: []
223
223
  };
224
224
  }
225
- if (L(l, le)) {
226
- if (L(l.value, ce))
225
+ if (L(l, ce)) {
226
+ if (L(l.value, de))
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
229
  if (L(m, O))
@@ -233,15 +233,15 @@ class O {
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, O.Aliased) && l.fieldAlias !== void 0 ? { sql: i(l.fieldAlias), params: [] } : L(l, Ze) ? l._.isWith ? { sql: i(l._.alias), params: [] } : this.buildQueryFromSourceParams([
237
- new j("("),
236
+ return L(l, de) ? { sql: r(c.value++, l), params: [l], typings: ["none"] } : L(l, O.Aliased) && l.fieldAlias !== void 0 ? { sql: i(l.fieldAlias), params: [] } : L(l, nt) ? l._.isWith ? { sql: i(l._.alias), params: [] } : this.buildQueryFromSourceParams([
237
+ new M("("),
238
238
  l._.sql,
239
- new j(") "),
240
- new Ne(l._.alias)
241
- ], n) : gt(l) ? l.schema ? { sql: i(l.schema) + "." + i(l.enumName), params: [] } : { sql: i(l.enumName), params: [] } : et(l) ? l.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([l.getSQL()], n) : this.buildQueryFromSourceParams([
242
- new j("("),
239
+ new M(") "),
240
+ new De(l._.alias)
241
+ ], n) : wt(l) ? l.schema ? { sql: i(l.schema) + "." + i(l.enumName), params: [] } : { sql: i(l.enumName), params: [] } : st(l) ? l.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([l.getSQL()], n) : this.buildQueryFromSourceParams([
242
+ new M("("),
243
243
  l.getSQL(),
244
- new j(")")
244
+ new M(")")
245
245
  ], n) : u ? { sql: this.mapInlineParam(l, n), params: [] } : { sql: r(c.value++, l), params: [l], typings: ["none"] };
246
246
  }));
247
247
  }
@@ -280,37 +280,37 @@ class O {
280
280
  return e ? this : void 0;
281
281
  }
282
282
  }
283
- class Ne {
283
+ class De {
284
284
  constructor(e) {
285
285
  this.value = e;
286
286
  }
287
- static [x] = "Name";
287
+ static [k] = "Name";
288
288
  brand;
289
289
  getSQL() {
290
290
  return new O([this]);
291
291
  }
292
292
  }
293
- function wt(d) {
293
+ function St(d) {
294
294
  return typeof d == "object" && d !== null && "mapToDriverValue" in d && typeof d.mapToDriverValue == "function";
295
295
  }
296
- const tt = {
296
+ const it = {
297
297
  mapFromDriverValue: (d) => d
298
- }, nt = {
298
+ }, rt = {
299
299
  mapToDriverValue: (d) => d
300
300
  };
301
301
  ({
302
- ...tt,
303
- ...nt
302
+ ...it,
303
+ ...rt
304
304
  });
305
- class le {
305
+ class ce {
306
306
  /**
307
307
  * @param value - Parameter value
308
308
  * @param encoder - Encoder to convert the value to a driver parameter
309
309
  */
310
- constructor(e, t = nt) {
310
+ constructor(e, t = rt) {
311
311
  this.value = e, this.encoder = t;
312
312
  }
313
- static [x] = "Param";
313
+ static [k] = "Param";
314
314
  brand;
315
315
  getSQL() {
316
316
  return new O([this]);
@@ -318,9 +318,9 @@ class le {
318
318
  }
319
319
  function o(d, ...e) {
320
320
  const t = [];
321
- (e.length > 0 || d.length > 0 && d[0] !== "") && t.push(new j(d[0]));
321
+ (e.length > 0 || d.length > 0 && d[0] !== "") && t.push(new M(d[0]));
322
322
  for (const [n, s] of e.entries())
323
- t.push(s, new j(d[n + 1]));
323
+ t.push(s, new M(d[n + 1]));
324
324
  return new O(t);
325
325
  }
326
326
  ((d) => {
@@ -333,7 +333,7 @@ function o(d, ...e) {
333
333
  }
334
334
  d.fromList = t;
335
335
  function n(u) {
336
- return new O([new j(u)]);
336
+ return new O([new M(u)]);
337
337
  }
338
338
  d.raw = n;
339
339
  function s(u, c) {
@@ -344,15 +344,15 @@ function o(d, ...e) {
344
344
  }
345
345
  d.join = s;
346
346
  function i(u) {
347
- return new Ne(u);
347
+ return new De(u);
348
348
  }
349
349
  d.identifier = i;
350
350
  function r(u) {
351
- return new ce(u);
351
+ return new de(u);
352
352
  }
353
353
  d.placeholder = r;
354
354
  function a(u, c) {
355
- return new le(u, c);
355
+ return new ce(u, c);
356
356
  }
357
357
  d.param = a;
358
358
  })(o || (o = {}));
@@ -361,7 +361,7 @@ function o(d, ...e) {
361
361
  constructor(n, s) {
362
362
  this.sql = n, this.fieldAlias = s;
363
363
  }
364
- static [x] = "SQL.Aliased";
364
+ static [k] = "SQL.Aliased";
365
365
  /** @internal */
366
366
  isSelectionField = !1;
367
367
  getSQL() {
@@ -374,24 +374,24 @@ function o(d, ...e) {
374
374
  }
375
375
  d.Aliased = e;
376
376
  })(O || (O = {}));
377
- class ce {
377
+ class de {
378
378
  constructor(e) {
379
379
  this.name = e;
380
380
  }
381
- static [x] = "Placeholder";
381
+ static [k] = "Placeholder";
382
382
  getSQL() {
383
383
  return new O([this]);
384
384
  }
385
385
  }
386
- const $t = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
387
- class st {
388
- static [x] = "View";
386
+ const Nt = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
387
+ class ot {
388
+ static [k] = "View";
389
389
  /** @internal */
390
- [ee];
390
+ [ne];
391
391
  /** @internal */
392
- [$t] = !0;
392
+ [Nt] = !0;
393
393
  constructor({ name: e, schema: t, selectedFields: n, query: s }) {
394
- this[ee] = {
394
+ this[ne] = {
395
395
  name: e,
396
396
  originalName: e,
397
397
  schema: t,
@@ -405,103 +405,103 @@ class st {
405
405
  return new O([this]);
406
406
  }
407
407
  }
408
- te.prototype.getSQL = function() {
408
+ se.prototype.getSQL = function() {
409
409
  return new O([this]);
410
410
  };
411
- B.prototype.getSQL = function() {
411
+ P.prototype.getSQL = function() {
412
412
  return new O([this]);
413
413
  };
414
- Ze.prototype.getSQL = function() {
414
+ nt.prototype.getSQL = function() {
415
415
  return new O([this]);
416
416
  };
417
- function U(d, e) {
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;
417
+ function x(d, e) {
418
+ return St(e) && !st(d) && !L(d, ce) && !L(d, de) && !L(d, se) && !L(d, P) && !L(d, ot) ? new ce(d, e) : d;
419
419
  }
420
- const Q = (d, e) => o`${d} = ${U(e, d)}`, Me = (d, e) => o`${d} <> ${U(e, d)}`;
421
- function D(...d) {
420
+ const Q = (d, e) => o`${d} = ${x(e, d)}`, xe = (d, e) => o`${d} <> ${x(e, d)}`;
421
+ function _(...d) {
422
422
  const e = d.filter(
423
423
  (t) => t !== void 0
424
424
  );
425
425
  if (e.length !== 0)
426
426
  return e.length === 1 ? new O(e) : new O([
427
- new j("("),
428
- o.join(e, new j(" and ")),
429
- new j(")")
427
+ new M("("),
428
+ o.join(e, new M(" and ")),
429
+ new M(")")
430
430
  ]);
431
431
  }
432
- function ie(...d) {
432
+ function re(...d) {
433
433
  const e = d.filter(
434
434
  (t) => t !== void 0
435
435
  );
436
436
  if (e.length !== 0)
437
437
  return e.length === 1 ? new O(e) : new O([
438
- new j("("),
439
- o.join(e, new j(" or ")),
440
- new j(")")
438
+ new M("("),
439
+ o.join(e, new M(" or ")),
440
+ new M(")")
441
441
  ]);
442
442
  }
443
- const we = (d, e) => o`${d} > ${U(e, d)}`, Y = (d, e) => o`${d} >= ${U(e, d)}`, $e = (d, e) => o`${d} < ${U(e, d)}`, X = (d, e) => o`${d} <= ${U(e, d)}`;
444
- function Te(d, e) {
445
- return Array.isArray(e) ? e.length === 0 ? o`false` : o`${d} in ${e.map((t) => U(t, d))}` : o`${d} in ${U(e, d)}`;
443
+ const $e = (d, e) => o`${d} > ${x(e, d)}`, Z = (d, e) => o`${d} >= ${x(e, d)}`, Te = (d, e) => o`${d} < ${x(e, d)}`, ee = (d, e) => o`${d} <= ${x(e, d)}`;
444
+ function Ee(d, e) {
445
+ return Array.isArray(e) ? e.length === 0 ? o`false` : o`${d} in ${e.map((t) => x(t, d))}` : o`${d} in ${x(e, d)}`;
446
446
  }
447
- function je(d, e) {
448
- return Array.isArray(e) ? e.length === 0 ? o`true` : o`${d} not in ${e.map((t) => U(t, d))}` : o`${d} not in ${U(e, d)}`;
447
+ function ke(d, e) {
448
+ return Array.isArray(e) ? e.length === 0 ? o`true` : o`${d} not in ${e.map((t) => x(t, d))}` : o`${d} not in ${x(e, d)}`;
449
449
  }
450
- function Ue(d) {
450
+ function Be(d) {
451
451
  return o`${d} is null`;
452
452
  }
453
- function ke(d) {
453
+ function Pe(d) {
454
454
  return o`${d} is not null`;
455
455
  }
456
- function Tt(d, e) {
456
+ function Dt(d, e) {
457
457
  if (Array.isArray(e)) {
458
458
  if (e.length === 0)
459
459
  throw new Error("arrayContains requires at least one value");
460
- const t = o`${U(e, d)}`;
460
+ const t = o`${x(e, d)}`;
461
461
  return o`${d} @> ${t}`;
462
462
  }
463
- return o`${d} @> ${U(e, d)}`;
463
+ return o`${d} @> ${x(e, d)}`;
464
464
  }
465
- function Et(d, e) {
465
+ function At(d, e) {
466
466
  if (Array.isArray(e)) {
467
467
  if (e.length === 0)
468
468
  throw new Error("arrayContained requires at least one value");
469
- const t = o`${U(e, d)}`;
469
+ const t = o`${x(e, d)}`;
470
470
  return o`${d} <@ ${t}`;
471
471
  }
472
- return o`${d} <@ ${U(e, d)}`;
472
+ return o`${d} <@ ${x(e, d)}`;
473
473
  }
474
- function St(d, e) {
474
+ function _t(d, e) {
475
475
  if (Array.isArray(e)) {
476
476
  if (e.length === 0)
477
477
  throw new Error("arrayOverlaps requires at least one value");
478
- const t = o`${U(e, d)}`;
478
+ const t = o`${x(e, d)}`;
479
479
  return o`${d} && ${t}`;
480
480
  }
481
- return o`${d} && ${U(e, d)}`;
481
+ return o`${d} && ${x(e, d)}`;
482
482
  }
483
- function xe(d) {
483
+ function Qe(d) {
484
484
  return o`${d} asc`;
485
485
  }
486
- function Nt(d) {
486
+ function vt(d) {
487
487
  return o`${d} desc`;
488
488
  }
489
- function De(d) {
489
+ function Ae(d) {
490
490
  return o`count(${d || o.raw("*")})`.mapWith(Number);
491
491
  }
492
- function Dt(d) {
492
+ function Rt(d) {
493
493
  return o`count(distinct ${d})`.mapWith(Number);
494
494
  }
495
- function K(d) {
495
+ function z(d) {
496
496
  return o`sum(${d})`.mapWith(String);
497
497
  }
498
- function V(d) {
499
- return o`max(${d})`.mapWith(L(d, te) ? d : String);
498
+ function G(d) {
499
+ return o`max(${d})`.mapWith(L(d, se) ? d : String);
500
500
  }
501
- function re(d) {
502
- return o`min(${d})`.mapWith(L(d, te) ? d : String);
501
+ function oe(d) {
502
+ return o`min(${d})`.mapWith(L(d, se) ? d : String);
503
503
  }
504
- class fe {
504
+ class pe {
505
505
  /**
506
506
  * Default implementation returns template unchanged
507
507
  * Override in specific adapters for database-specific preprocessing
@@ -549,7 +549,7 @@ class fe {
549
549
  return t.years * 365 * 24 * 60 * 60 + t.months * 30 * 24 * 60 * 60 + t.days * 24 * 60 * 60 + t.hours * 60 * 60 + t.minutes * 60 + t.seconds;
550
550
  }
551
551
  }
552
- class At extends fe {
552
+ class Ft extends pe {
553
553
  getEngineType() {
554
554
  return "postgres";
555
555
  }
@@ -820,7 +820,7 @@ class At extends fe {
820
820
  }
821
821
  }
822
822
  }
823
- class it extends fe {
823
+ class at extends pe {
824
824
  getEngineType() {
825
825
  return "mysql";
826
826
  }
@@ -1098,7 +1098,7 @@ class it extends fe {
1098
1098
  }
1099
1099
  }
1100
1100
  }
1101
- class _t extends fe {
1101
+ class Ot extends pe {
1102
1102
  getEngineType() {
1103
1103
  return "sqlite";
1104
1104
  }
@@ -1415,7 +1415,7 @@ class _t extends fe {
1415
1415
  }
1416
1416
  }
1417
1417
  }
1418
- class vt extends it {
1418
+ class It extends at {
1419
1419
  getEngineType() {
1420
1420
  return "singlestore";
1421
1421
  }
@@ -1428,7 +1428,7 @@ class vt extends it {
1428
1428
  // These limitations are typically handled at the query building level
1429
1429
  // rather than in the adapter, but can be addressed here if needed
1430
1430
  }
1431
- class Rt extends fe {
1431
+ class Lt extends pe {
1432
1432
  getEngineType() {
1433
1433
  return "duckdb";
1434
1434
  }
@@ -1693,31 +1693,31 @@ class Rt extends fe {
1693
1693
  }
1694
1694
  }
1695
1695
  }
1696
- function Ft(d) {
1696
+ function Mt(d) {
1697
1697
  switch (d) {
1698
1698
  case "postgres":
1699
- return new At();
1699
+ return new Ft();
1700
1700
  case "mysql":
1701
- return new it();
1701
+ return new at();
1702
1702
  case "sqlite":
1703
- return new _t();
1703
+ return new Ot();
1704
1704
  case "singlestore":
1705
- return new vt();
1705
+ return new It();
1706
1706
  case "duckdb":
1707
- return new Rt();
1707
+ return new Lt();
1708
1708
  default:
1709
1709
  throw new Error(`Unsupported database engine: ${d}`);
1710
1710
  }
1711
1711
  }
1712
- class pe {
1712
+ class he {
1713
1713
  constructor(e, t, n) {
1714
1714
  this.db = e, this.schema = t;
1715
1715
  const s = n || this.getEngineType();
1716
- this.databaseAdapter = Ft(s);
1716
+ this.databaseAdapter = Mt(s);
1717
1717
  }
1718
1718
  databaseAdapter;
1719
1719
  }
1720
- function Ot(d, e) {
1720
+ function jt(d, e) {
1721
1721
  const t = [], n = [];
1722
1722
  let s = !1, i, r, a;
1723
1723
  const u = [];
@@ -1732,7 +1732,7 @@ function Ot(d, e) {
1732
1732
  r = parseFloat(p[1]);
1733
1733
  continue;
1734
1734
  }
1735
- const f = It(l);
1735
+ const f = Ut(l);
1736
1736
  if (f) {
1737
1737
  f.type.includes("Seq Scan") && (s = !0), f.index && n.push(f.index), t.length === 0 && f.estimatedCost !== void 0 && (a = f.estimatedCost);
1738
1738
  const h = l.search(/\S/);
@@ -1764,7 +1764,7 @@ function Ot(d, e) {
1764
1764
  sql: e
1765
1765
  };
1766
1766
  }
1767
- function It(d) {
1767
+ function Ut(d) {
1768
1768
  const e = d.replace(/^[\s->]+/, "").trim();
1769
1769
  if (!e) return null;
1770
1770
  const t = e.match(
@@ -1784,7 +1784,7 @@ function It(d) {
1784
1784
  const l = d.match(/Filter:\s*(.+?)(?:\)|$)/i);
1785
1785
  return l && (c.filter = l[1].trim()), c;
1786
1786
  }
1787
- class Lt extends pe {
1787
+ class xt extends he {
1788
1788
  async execute(e, t) {
1789
1789
  if (e && typeof e == "object" && typeof e.execute == "function") {
1790
1790
  const s = await e.execute();
@@ -1854,7 +1854,7 @@ class Lt extends pe {
1854
1854
  typeof u == "string" && r.push(u);
1855
1855
  }
1856
1856
  }
1857
- return Ot(r, { sql: e, params: t });
1857
+ return jt(r, { sql: e, params: t });
1858
1858
  }
1859
1859
  /**
1860
1860
  * Get existing indexes for the specified tables
@@ -1895,10 +1895,10 @@ class Lt extends pe {
1895
1895
  }
1896
1896
  }
1897
1897
  }
1898
- function Be(d, e) {
1899
- return new Lt(d, e, "postgres");
1898
+ function We(d, e) {
1899
+ return new xt(d, e, "postgres");
1900
1900
  }
1901
- function Mt(d, e) {
1901
+ function kt(d, e) {
1902
1902
  const t = e?.toLowerCase() || "";
1903
1903
  switch (d.toLowerCase()) {
1904
1904
  case "all":
@@ -1920,11 +1920,11 @@ function Mt(d, e) {
1920
1920
  return `MySQL ${d}`;
1921
1921
  }
1922
1922
  }
1923
- function jt(d, e) {
1923
+ function Bt(d, e) {
1924
1924
  const t = [], n = [];
1925
1925
  let s = !1, i = 0;
1926
1926
  for (const u of d) {
1927
- const c = Mt(u.type, u.Extra);
1927
+ const c = kt(u.type, u.Extra);
1928
1928
  u.type.toLowerCase() === "all" && (s = !0), u.key && n.push(u.key);
1929
1929
  const l = {
1930
1930
  type: c,
@@ -1963,7 +1963,7 @@ function jt(d, e) {
1963
1963
  sql: e
1964
1964
  };
1965
1965
  }
1966
- class rt extends pe {
1966
+ class ut extends he {
1967
1967
  async execute(e, t) {
1968
1968
  if (e && typeof e == "object" && typeof e.execute == "function") {
1969
1969
  const s = await e.execute();
@@ -2031,7 +2031,7 @@ class rt extends pe {
2031
2031
  filtered: Number(c.filtered) || 100,
2032
2032
  Extra: c.Extra || null
2033
2033
  });
2034
- return jt(u, { sql: e, params: t });
2034
+ return Bt(u, { sql: e, params: t });
2035
2035
  }
2036
2036
  /**
2037
2037
  * Get existing indexes for the specified tables
@@ -2067,10 +2067,10 @@ class rt extends pe {
2067
2067
  }
2068
2068
  }
2069
2069
  }
2070
- function Ut(d, e) {
2071
- return new rt(d, e, "mysql");
2070
+ function Pt(d, e) {
2071
+ return new ut(d, e, "mysql");
2072
2072
  }
2073
- function kt(d) {
2073
+ function Qt(d) {
2074
2074
  const e = d.toLowerCase(), t = d.match(/^SCAN\s+(\S+)/i);
2075
2075
  if (t)
2076
2076
  return {
@@ -2102,12 +2102,12 @@ function kt(d) {
2102
2102
  table: i[1]
2103
2103
  } : e.includes("temp b-tree") ? e.includes("order by") ? { type: "Sort" } : e.includes("group by") ? { type: "Group" } : e.includes("distinct") ? { type: "Distinct" } : { type: "Temp B-Tree" } : e.includes("compound") ? { type: "Compound Query" } : e.includes("subquery") ? { type: "Subquery" } : e.includes("co-routine") ? { type: "Coroutine" } : { type: d };
2104
2104
  }
2105
- function xt(d, e) {
2105
+ function Wt(d, e) {
2106
2106
  const t = [], n = [];
2107
2107
  let s = !1;
2108
2108
  const i = /* @__PURE__ */ new Map();
2109
2109
  for (const u of d) {
2110
- const c = kt(u.detail);
2110
+ const c = Qt(u.detail);
2111
2111
  c.type === "Seq Scan" && (s = !0), c.index && n.push(c.index);
2112
2112
  const l = {
2113
2113
  type: c.type,
@@ -2145,7 +2145,7 @@ function xt(d, e) {
2145
2145
  sql: e
2146
2146
  };
2147
2147
  }
2148
- class Bt extends pe {
2148
+ class Kt extends he {
2149
2149
  async execute(e, t) {
2150
2150
  if (e && typeof e == "object" && typeof e.execute == "function") {
2151
2151
  const n = await e.execute();
@@ -2215,7 +2215,7 @@ class Bt extends pe {
2215
2215
  notused: Number(c.notused) || 0,
2216
2216
  detail: String(c.detail || "")
2217
2217
  });
2218
- return xt(u, { sql: e, params: t });
2218
+ return Wt(u, { sql: e, params: t });
2219
2219
  }
2220
2220
  /**
2221
2221
  * Get existing indexes for the specified tables
@@ -2256,10 +2256,10 @@ class Bt extends pe {
2256
2256
  }
2257
2257
  }
2258
2258
  }
2259
- function Pe(d, e) {
2260
- return new Bt(d, e, "sqlite");
2259
+ function Ke(d, e) {
2260
+ return new Kt(d, e, "sqlite");
2261
2261
  }
2262
- class Pt extends rt {
2262
+ class qt extends ut {
2263
2263
  getEngineType() {
2264
2264
  return "singlestore";
2265
2265
  }
@@ -2267,19 +2267,19 @@ class Pt extends rt {
2267
2267
  // For now, we inherit all behavior from MySQLExecutor since
2268
2268
  // SingleStore is largely MySQL-compatible
2269
2269
  }
2270
- function Qt(d, e) {
2271
- return new Pt(d, e);
2270
+ function zt(d, e) {
2271
+ return new qt(d, e);
2272
2272
  }
2273
- function Wt(d, e) {
2273
+ function Vt(d, e) {
2274
2274
  const t = [], n = [];
2275
2275
  let s = !1, i;
2276
2276
  const r = [];
2277
2277
  for (const u of d) {
2278
2278
  if (/^[┌├└│─┐┤┘]+$/.test(u.trim()) || /EXPLANATION|QUERY PLAN/i.test(u)) continue;
2279
- const c = qt(u);
2279
+ const c = Gt(u);
2280
2280
  if (c) {
2281
2281
  (c.type.includes("SEQ_SCAN") || c.type.includes("TABLE_SCAN")) && (s = !0), c.type.includes("INDEX_SCAN") && c.index && n.push(c.index), t.length === 0 && c.estimatedCost !== void 0 && (i = c.estimatedCost);
2282
- const l = Kt(u);
2282
+ const l = Jt(u);
2283
2283
  for (; r.length > 0 && r[r.length - 1].indent >= l; )
2284
2284
  r.pop();
2285
2285
  if (r.length === 0)
@@ -2307,7 +2307,7 @@ function Wt(d, e) {
2307
2307
  sql: e
2308
2308
  };
2309
2309
  }
2310
- function Kt(d) {
2310
+ function Jt(d) {
2311
2311
  let e = 0;
2312
2312
  for (const t of d)
2313
2313
  if (t === " " || t === "│" || t === "├" || t === "└" || t === "─")
@@ -2316,7 +2316,7 @@ function Kt(d) {
2316
2316
  break;
2317
2317
  return e;
2318
2318
  }
2319
- function qt(d) {
2319
+ function Gt(d) {
2320
2320
  const e = d.replace(/[┌├└│─┐┤┘]/g, "").replace(/^\s*/, "").trim();
2321
2321
  if (!e || e.match(/^\(cost=([\d.]+)\s+rows=(\d+)\)$/i))
2322
2322
  return null;
@@ -2345,7 +2345,7 @@ function qt(d) {
2345
2345
  estimatedCost: a
2346
2346
  };
2347
2347
  }
2348
- class zt extends pe {
2348
+ class Ht extends he {
2349
2349
  async execute(e, t) {
2350
2350
  if (e && typeof e == "object" && typeof e.execute == "function")
2351
2351
  try {
@@ -2450,7 +2450,7 @@ class zt extends pe {
2450
2450
  typeof u == "string" && r.push(u);
2451
2451
  }
2452
2452
  }
2453
- return Wt(r, { sql: e, params: t });
2453
+ return Vt(r, { sql: e, params: t });
2454
2454
  }
2455
2455
  /**
2456
2456
  * Get existing indexes for the specified tables
@@ -2486,33 +2486,33 @@ class zt extends pe {
2486
2486
  }
2487
2487
  }
2488
2488
  }
2489
- function Vt(d, e) {
2490
- return new zt(d, e, "duckdb");
2489
+ function Yt(d, e) {
2490
+ return new Ht(d, e, "duckdb");
2491
2491
  }
2492
- function Qe(d, e, t) {
2492
+ function qe(d, e, t) {
2493
2493
  if (t)
2494
2494
  switch (t) {
2495
2495
  case "postgres":
2496
- return Be(d, e);
2496
+ return We(d, e);
2497
2497
  case "mysql":
2498
- return Ut(d, e);
2498
+ return Pt(d, e);
2499
2499
  case "sqlite":
2500
- return Pe(d, e);
2500
+ return Ke(d, e);
2501
2501
  case "singlestore":
2502
- return Qt(d, e);
2502
+ return zt(d, e);
2503
2503
  case "duckdb":
2504
- return Vt(d, e);
2504
+ return Yt(d, e);
2505
2505
  }
2506
2506
  if (d.all && d.run)
2507
- return Pe(d, e);
2507
+ return Ke(d, e);
2508
2508
  if (d.execute)
2509
- return Be(d, e);
2509
+ return We(d, e);
2510
2510
  throw new Error("Unable to determine database engine type. Please specify engineType parameter.");
2511
2511
  }
2512
- function P(d) {
2512
+ function W(d) {
2513
2513
  return typeof d == "function" ? d() : d;
2514
2514
  }
2515
- function Ae(d, e) {
2515
+ function _e(d, e) {
2516
2516
  if (e) return e;
2517
2517
  switch (d) {
2518
2518
  case "belongsTo":
@@ -2531,14 +2531,14 @@ function Ae(d, e) {
2531
2531
  return "left";
2532
2532
  }
2533
2533
  }
2534
- function _e(d) {
2534
+ function ve(d) {
2535
2535
  return d && typeof d == "object" ? o`${o`${d}`}` : d;
2536
2536
  }
2537
2537
  function v(d, e) {
2538
2538
  const t = typeof d == "function" ? d(e) : d;
2539
- return _e(t);
2539
+ return ve(t);
2540
2540
  }
2541
- function Jt(d, e) {
2541
+ function Xt(d, e) {
2542
2542
  if (d.relationship !== "belongsToMany" || !d.through)
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 = [];
@@ -2556,38 +2556,38 @@ function Jt(d, e) {
2556
2556
  const l = i(e);
2557
2557
  u = Array.isArray(l) ? l : [l];
2558
2558
  }
2559
- const c = Ae("belongsToMany", d.sqlJoinType);
2559
+ const c = _e("belongsToMany", d.sqlJoinType);
2560
2560
  return {
2561
2561
  junctionJoins: [
2562
2562
  {
2563
2563
  joinType: c,
2564
2564
  table: t,
2565
- condition: D(...r)
2565
+ condition: _(...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: D(...a)
2571
+ condition: _(...a)
2572
2572
  }
2573
2573
  ],
2574
2574
  junctionSecurityConditions: u
2575
2575
  };
2576
2576
  }
2577
- function de(d) {
2577
+ function me(d) {
2578
2578
  if ("and" in d)
2579
- return `and:[${d.and.map(de).sort().join(",")}]`;
2579
+ return `and:[${d.and.map(me).sort().join(",")}]`;
2580
2580
  if ("or" in d)
2581
- return `or:[${d.or.map(de).sort().join(",")}]`;
2581
+ return `or:[${d.or.map(me).sort().join(",")}]`;
2582
2582
  const e = d, t = JSON.stringify(
2583
2583
  Array.isArray(e.values) ? [...e.values].sort() : e.values
2584
2584
  ), n = e.dateRange ? `:dr:${JSON.stringify(e.dateRange)}` : "";
2585
2585
  return `${e.member}:${e.operator}:${t}${n}`;
2586
2586
  }
2587
- function ot(d, e) {
2587
+ function lt(d, e) {
2588
2588
  return `timeDim:${d}:${JSON.stringify(e)}`;
2589
2589
  }
2590
- class We {
2590
+ class ze {
2591
2591
  cache = /* @__PURE__ */ new Map();
2592
2592
  stats = { hits: 0, misses: 0 };
2593
2593
  /**
@@ -2644,40 +2644,40 @@ class We {
2644
2644
  this.cache.clear(), this.stats = { hits: 0, misses: 0 };
2645
2645
  }
2646
2646
  }
2647
- function ve(d) {
2647
+ function Re(d) {
2648
2648
  const e = [];
2649
2649
  for (const t of d)
2650
- "and" in t && t.and ? e.push(...ve(t.and)) : "or" in t && t.or ? e.push(...ve(t.or)) : "member" in t && e.push(t);
2650
+ "and" in t && t.and ? e.push(...Re(t.and)) : "or" in t && t.or ? e.push(...Re(t.or)) : "member" in t && e.push(t);
2651
2651
  return e;
2652
2652
  }
2653
- function Gt(d, e, t = {}) {
2654
- const n = t.keyPrefix ?? "drizzle-cube:", s = Ht(d), i = Ke(JSON.stringify(s));
2653
+ function Zt(d, e, t = {}) {
2654
+ const n = t.keyPrefix ?? "drizzle-cube:", s = en(d), i = Ve(JSON.stringify(s));
2655
2655
  let r = `${n}query:${i}`;
2656
2656
  if (t.includeSecurityContext !== !1) {
2657
- const a = t.securityContextSerializer ? t.securityContextSerializer(e) : JSON.stringify(me(e)), u = Ke(a);
2657
+ const a = t.securityContextSerializer ? t.securityContextSerializer(e) : JSON.stringify(fe(e)), u = Ve(a);
2658
2658
  r += `:ctx:${u}`;
2659
2659
  }
2660
2660
  return r;
2661
2661
  }
2662
- function Ht(d) {
2662
+ function en(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 ? W(d.filters) : void 0,
2667
- timeDimensions: d.timeDimensions ? en(d.timeDimensions) : void 0,
2666
+ filters: d.filters ? K(d.filters) : void 0,
2667
+ timeDimensions: d.timeDimensions ? rn(d.timeDimensions) : void 0,
2668
2668
  limit: d.limit,
2669
2669
  offset: d.offset,
2670
- order: d.order ? me(d.order) : void 0,
2670
+ order: d.order ? fe(d.order) : void 0,
2671
2671
  fillMissingDatesValue: d.fillMissingDatesValue,
2672
2672
  // Include funnel config in cache key for proper cache invalidation
2673
- funnel: d.funnel ? Yt(d.funnel) : void 0,
2673
+ funnel: d.funnel ? tn(d.funnel) : void 0,
2674
2674
  // Include flow config in cache key for proper cache invalidation
2675
- flow: d.flow ? Xt(d.flow) : void 0,
2675
+ flow: d.flow ? nn(d.flow) : void 0,
2676
2676
  // Include retention config in cache key for proper cache invalidation
2677
- retention: d.retention ? Zt(d.retention) : void 0
2677
+ retention: d.retention ? sn(d.retention) : void 0
2678
2678
  };
2679
2679
  }
2680
- function Yt(d) {
2680
+ function tn(d) {
2681
2681
  return {
2682
2682
  bindingKey: d.bindingKey,
2683
2683
  timeDimension: d.timeDimension,
@@ -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) ? W(e.filter) : W([e.filter])[0] : void 0,
2688
+ filter: e.filter ? Array.isArray(e.filter) ? K(e.filter) : K([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;
@@ -2694,7 +2694,7 @@ function Yt(d) {
2694
2694
  globalTimeWindow: d.globalTimeWindow
2695
2695
  };
2696
2696
  }
2697
- function Xt(d) {
2697
+ function nn(d) {
2698
2698
  return {
2699
2699
  bindingKey: d.bindingKey,
2700
2700
  timeDimension: d.timeDimension,
@@ -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) ? W(d.startingStep.filter) : W([d.startingStep.filter])[0] : void 0
2705
+ filter: d.startingStep.filter ? Array.isArray(d.startingStep.filter) ? K(d.startingStep.filter) : K([d.startingStep.filter])[0] : void 0
2706
2706
  },
2707
2707
  // CRITICAL: Include step counts in cache key
2708
2708
  stepsBefore: d.stepsBefore,
@@ -2715,7 +2715,7 @@ function Xt(d) {
2715
2715
  joinStrategy: d.joinStrategy
2716
2716
  };
2717
2717
  }
2718
- function Zt(d) {
2718
+ function sn(d) {
2719
2719
  return {
2720
2720
  timeDimension: d.timeDimension,
2721
2721
  bindingKey: d.bindingKey,
@@ -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) ? 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,
2727
+ cohortFilters: d.cohortFilters ? Array.isArray(d.cohortFilters) ? K(d.cohortFilters) : K([d.cohortFilters])[0] : void 0,
2728
+ activityFilters: d.activityFilters ? Array.isArray(d.activityFilters) ? K(d.activityFilters) : K([d.activityFilters])[0] : void 0,
2729
2729
  // Include breakdown dimensions for cache key
2730
2730
  breakdownDimensions: d.breakdownDimensions
2731
2731
  };
2732
2732
  }
2733
- function W(d) {
2733
+ function K(d) {
2734
2734
  return [...d].map((e) => {
2735
2735
  if ("and" in e && e.and)
2736
- return { and: W(e.and) };
2736
+ return { and: K(e.and) };
2737
2737
  if ("or" in e && e.or)
2738
- return { or: W(e.or) };
2738
+ return { or: K(e.or) };
2739
2739
  const t = e;
2740
2740
  return {
2741
2741
  ...t,
@@ -2743,7 +2743,7 @@ function W(d) {
2743
2743
  };
2744
2744
  }).sort((e, t) => JSON.stringify(e).localeCompare(JSON.stringify(t)));
2745
2745
  }
2746
- function en(d) {
2746
+ function rn(d) {
2747
2747
  return [...d].map((e) => ({
2748
2748
  dimension: e.dimension,
2749
2749
  granularity: e.granularity,
@@ -2755,18 +2755,18 @@ function en(d) {
2755
2755
  }) : void 0
2756
2756
  })).sort((e, t) => e.dimension.localeCompare(t.dimension));
2757
2757
  }
2758
- function me(d) {
2759
- return d === null || typeof d != "object" ? d : Array.isArray(d) ? d.map(me) : Object.keys(d).sort().reduce((e, t) => (e[t] = me(
2758
+ function fe(d) {
2759
+ return d === null || typeof d != "object" ? d : Array.isArray(d) ? d.map(fe) : Object.keys(d).sort().reduce((e, t) => (e[t] = fe(
2760
2760
  d[t]
2761
2761
  ), e), {});
2762
2762
  }
2763
- function Ke(d) {
2763
+ function Ve(d) {
2764
2764
  let e = 2166136261;
2765
2765
  for (let t = 0; t < d.length; t++)
2766
2766
  e ^= d.charCodeAt(t), e = e * 16777619 >>> 0;
2767
2767
  return e.toString(16).padStart(8, "0");
2768
2768
  }
2769
- class ne {
2769
+ class ie {
2770
2770
  constructor(e) {
2771
2771
  this.databaseAdapter = e;
2772
2772
  }
@@ -2790,18 +2790,18 @@ 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 D(
2794
- Y(e, n),
2795
- X(e, s)
2793
+ return _(
2794
+ Z(e, n),
2795
+ ee(e, s)
2796
2796
  );
2797
2797
  }
2798
2798
  if (typeof t == "string") {
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()), D(
2803
- Y(e, l),
2804
- X(e, 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()), _(
2803
+ Z(e, l),
2804
+ ee(e, m)
2805
2805
  );
2806
2806
  }
2807
2807
  const s = this.normalizeDate(t);
@@ -2811,9 +2811,9 @@ 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()), D(
2815
- Y(e, u),
2816
- X(e, 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()), _(
2815
+ Z(e, u),
2816
+ ee(e, c)
2817
2817
  );
2818
2818
  }
2819
2819
  return null;
@@ -2927,7 +2927,7 @@ class ne {
2927
2927
  return isNaN(t.getTime()) ? null : this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(t.getTime() / 1e3) : t.getTime() : t.toISOString();
2928
2928
  }
2929
2929
  }
2930
- class he {
2930
+ class ge {
2931
2931
  constructor(e, t) {
2932
2932
  this.databaseAdapter = e, this.dateTimeBuilder = t;
2933
2933
  }
@@ -2957,16 +2957,16 @@ class he {
2957
2957
  if (r.length > 1) {
2958
2958
  if (s?.type === "time") {
2959
2959
  const u = r.map((c) => this.dateTimeBuilder.normalizeDate(c) || c);
2960
- return Te(e, u);
2960
+ return Ee(e, u);
2961
2961
  }
2962
- return Te(e, r);
2962
+ return Ee(e, r);
2963
2963
  } else if (r.length === 1) {
2964
2964
  const u = s?.type === "time" && this.dateTimeBuilder.normalizeDate(a) || a;
2965
2965
  return Q(e, u);
2966
2966
  }
2967
2967
  return this.databaseAdapter.buildBooleanLiteral(!1);
2968
2968
  case "notEquals":
2969
- return r.length > 1 ? je(e, r) : r.length === 1 ? Me(e, a) : null;
2969
+ return r.length > 1 ? ke(e, r) : r.length === 1 ? xe(e, a) : null;
2970
2970
  case "contains":
2971
2971
  return this.databaseAdapter.buildStringCondition(e, "contains", a);
2972
2972
  case "notContains":
@@ -2976,17 +2976,17 @@ class he {
2976
2976
  case "endsWith":
2977
2977
  return this.databaseAdapter.buildStringCondition(e, "endsWith", a);
2978
2978
  case "gt":
2979
- return we(e, a);
2979
+ return $e(e, a);
2980
2980
  case "gte":
2981
- return Y(e, a);
2981
+ return Z(e, a);
2982
2982
  case "lt":
2983
- return $e(e, a);
2983
+ return Te(e, a);
2984
2984
  case "lte":
2985
- return X(e, a);
2985
+ return ee(e, a);
2986
2986
  case "set":
2987
- return ke(e);
2987
+ return Pe(e);
2988
2988
  case "notSet":
2989
- return Ue(e);
2989
+ return Be(e);
2990
2990
  case "inDateRange":
2991
2991
  if (r.length >= 2) {
2992
2992
  const u = this.dateTimeBuilder.normalizeDate(r[0]);
@@ -2997,35 +2997,35 @@ 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 D(
3001
- Y(e, u),
3002
- X(e, c)
3000
+ return _(
3001
+ Z(e, u),
3002
+ ee(e, c)
3003
3003
  );
3004
3004
  }
3005
3005
  }
3006
3006
  return null;
3007
3007
  case "beforeDate": {
3008
3008
  const u = this.dateTimeBuilder.normalizeDate(a);
3009
- return u ? $e(e, u) : null;
3009
+ return u ? Te(e, u) : null;
3010
3010
  }
3011
3011
  case "afterDate": {
3012
3012
  const u = this.dateTimeBuilder.normalizeDate(a);
3013
- return u ? we(e, u) : null;
3013
+ return u ? $e(e, u) : null;
3014
3014
  }
3015
3015
  case "between":
3016
- return r.length >= 2 ? D(
3017
- Y(e, r[0]),
3018
- X(e, r[1])
3016
+ return r.length >= 2 ? _(
3017
+ Z(e, r[0]),
3018
+ ee(e, r[1])
3019
3019
  ) : null;
3020
3020
  case "notBetween":
3021
- return r.length >= 2 ? ie(
3022
- $e(e, r[0]),
3023
- we(e, r[1])
3021
+ return r.length >= 2 ? re(
3022
+ Te(e, r[0]),
3023
+ $e(e, r[1])
3024
3024
  ) : null;
3025
3025
  case "in":
3026
- return r.length > 0 ? Te(e, r) : null;
3026
+ return r.length > 0 ? Ee(e, r) : null;
3027
3027
  case "notIn":
3028
- return r.length > 0 ? je(e, r) : null;
3028
+ return r.length > 0 ? ke(e, r) : null;
3029
3029
  case "like":
3030
3030
  return this.databaseAdapter.buildStringCondition(e, "like", a);
3031
3031
  case "notLike":
@@ -3037,23 +3037,23 @@ class he {
3037
3037
  case "notRegex":
3038
3038
  return this.databaseAdapter.buildStringCondition(e, "notRegex", a);
3039
3039
  case "isEmpty":
3040
- return ie(
3041
- Ue(e),
3040
+ return re(
3041
+ Be(e),
3042
3042
  Q(e, "")
3043
3043
  );
3044
3044
  case "isNotEmpty":
3045
- return D(
3046
- ke(e),
3047
- Me(e, "")
3045
+ return _(
3046
+ Pe(e),
3047
+ xe(e, "")
3048
3048
  );
3049
3049
  // PostgreSQL array operators - silent no-op for other databases
3050
3050
  // These use Drizzle's built-in array operator functions
3051
3051
  case "arrayContains":
3052
- return this.databaseAdapter.getEngineType() === "postgres" ? Tt(e, r) : null;
3052
+ return this.databaseAdapter.getEngineType() === "postgres" ? Dt(e, r) : null;
3053
3053
  case "arrayOverlaps":
3054
- return this.databaseAdapter.getEngineType() === "postgres" ? St(e, r) : null;
3054
+ return this.databaseAdapter.getEngineType() === "postgres" ? _t(e, r) : null;
3055
3055
  case "arrayContained":
3056
- return this.databaseAdapter.getEngineType() === "postgres" ? Et(e, r) : null;
3056
+ return this.databaseAdapter.getEngineType() === "postgres" ? At(e, r) : null;
3057
3057
  default:
3058
3058
  return null;
3059
3059
  }
@@ -3065,11 +3065,11 @@ 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] : D(...s) : null;
3068
+ return s.length > 0 ? s.length === 1 ? s[0] : _(...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);
3072
- return s.length > 0 ? s.length === 1 ? s[0] : ie(...s) : null;
3072
+ return s.length > 0 ? s.length === 1 ? s[0] : re(...s) : null;
3073
3073
  }
3074
3074
  return null;
3075
3075
  }
@@ -3094,7 +3094,7 @@ class he {
3094
3094
  );
3095
3095
  }
3096
3096
  }
3097
- class G {
3097
+ class X {
3098
3098
  dependencyGraph;
3099
3099
  cubes;
3100
3100
  constructor(e) {
@@ -3314,21 +3314,21 @@ class G {
3314
3314
  return e.type === "calculated" && !!e.calculatedSql;
3315
3315
  }
3316
3316
  }
3317
- function tn(d, e) {
3318
- const { cube: t, allCubes: n, resolvedMeasures: s } = e, i = Re(d), r = /* @__PURE__ */ new Map();
3317
+ function on(d, e) {
3318
+ const { cube: t, allCubes: n, resolvedMeasures: s } = e, i = Fe(d), r = /* @__PURE__ */ new Map();
3319
3319
  for (const m of i) {
3320
3320
  const { originalRef: p, cubeName: f, fieldName: h } = m, g = f || t.name;
3321
3321
  if (!n.get(g))
3322
3322
  throw new Error(
3323
3323
  `Cannot substitute {${p}}: cube '${g}' not found`
3324
3324
  );
3325
- const b = `${g}.${h}`, w = s.get(b);
3326
- if (!w)
3325
+ const b = `${g}.${h}`, $ = s.get(b);
3326
+ if (!$)
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 A = w(), $ = o`${A}`;
3331
- r.set(p, $);
3330
+ const A = $(), w = o`${A}`;
3331
+ r.set(p, w);
3332
3332
  }
3333
3333
  const a = [], u = [];
3334
3334
  let c = 0;
@@ -3344,10 +3344,10 @@ function tn(d, e) {
3344
3344
  return o.raw(d);
3345
3345
  const l = [];
3346
3346
  for (let m = 0; m < a.length; m++)
3347
- a[m] && l.push(new j(a[m])), m < u.length && l.push(u[m]);
3347
+ a[m] && l.push(new M(a[m])), m < u.length && l.push(u[m]);
3348
3348
  return o.join(l, o.raw(""));
3349
3349
  }
3350
- function Re(d) {
3350
+ function Fe(d) {
3351
3351
  const e = /\{([^}]+)\}/g, t = d.matchAll(e), n = [];
3352
3352
  for (const s of t) {
3353
3353
  const i = s[1].trim();
@@ -3367,7 +3367,7 @@ function Re(d) {
3367
3367
  }
3368
3368
  return n;
3369
3369
  }
3370
- function nn(d) {
3370
+ function an(d) {
3371
3371
  const e = [];
3372
3372
  let t = 0;
3373
3373
  for (let r = 0; r < d.length; r++)
@@ -3378,7 +3378,7 @@ function nn(d) {
3378
3378
  break;
3379
3379
  }
3380
3380
  t > 0 && e.push("Unmatched opening brace in template"), /\{\s*\}/.test(d) && e.push("Empty member reference {} found in template"), /\{[^}]*\{/.test(d) && e.push("Nested braces are not allowed in member references");
3381
- const i = Re(d);
3381
+ const i = Fe(d);
3382
3382
  for (const r of i) {
3383
3383
  const a = r.cubeName ? `${r.cubeName}.${r.fieldName}` : r.fieldName;
3384
3384
  /^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(a) || e.push(
@@ -3392,8 +3392,8 @@ function nn(d) {
3392
3392
  errors: e
3393
3393
  };
3394
3394
  }
3395
- function Ee(d, e) {
3396
- const t = Re(d), n = /* @__PURE__ */ new Set();
3395
+ function Se(d, e) {
3396
+ const t = Fe(d), n = /* @__PURE__ */ new Set();
3397
3397
  for (const s of t) {
3398
3398
  const r = `${s.cubeName || e}.${s.fieldName}`;
3399
3399
  n.add(r);
@@ -3416,7 +3416,7 @@ class I {
3416
3416
  * @returns Map of measure names to SQL builder functions
3417
3417
  */
3418
3418
  buildResolvedMeasures(e, t, n, s) {
3419
- const i = /* @__PURE__ */ new Map(), r = [], a = [], u = new Set(e), c = new G(t);
3419
+ const i = /* @__PURE__ */ new Map(), r = [], a = [], u = new Set(e), c = new X(t);
3420
3420
  for (const l of t.values())
3421
3421
  c.buildGraph(l);
3422
3422
  for (const l of e) {
@@ -3428,11 +3428,11 @@ class I {
3428
3428
  g && u.add(g);
3429
3429
  continue;
3430
3430
  }
3431
- G.isCalculatedMeasure(h) ? (a.push(l), Ee(h.calculatedSql, m).forEach((b) => u.add(b)), c.getAllDependencies(l).forEach((b) => {
3432
- const [w, A] = b.split("."), $ = t.get(w);
3433
- if ($ && $.measures[A]) {
3434
- const C = $.measures[A];
3435
- G.isCalculatedMeasure(C) && Ee(C.calculatedSql, w).forEach((E) => u.add(E));
3431
+ X.isCalculatedMeasure(h) ? (a.push(l), Se(h.calculatedSql, m).forEach((b) => u.add(b)), c.getAllDependencies(l).forEach((b) => {
3432
+ const [$, A] = b.split("."), w = t.get($);
3433
+ if (w && w.measures[A]) {
3434
+ const C = w.measures[A];
3435
+ X.isCalculatedMeasure(C) && Se(C.calculatedSql, $).forEach((E) => u.add(E));
3436
3436
  }
3437
3437
  })) : r.push(l);
3438
3438
  }
@@ -3443,7 +3443,7 @@ class I {
3443
3443
  const h = f.measures[p];
3444
3444
  if (I.isPostAggregationWindow(h))
3445
3445
  continue;
3446
- G.isCalculatedMeasure(h) ? a.includes(l) || a.push(l) : r.includes(l) || r.push(l);
3446
+ X.isCalculatedMeasure(h) ? a.includes(l) || a.push(l) : r.includes(l) || r.push(l);
3447
3447
  }
3448
3448
  }
3449
3449
  for (const l of r) {
@@ -3479,7 +3479,7 @@ class I {
3479
3479
  `Calculated measure '${t.name}.${e.name}' missing calculatedSql property`
3480
3480
  );
3481
3481
  const r = this.databaseAdapter.preprocessCalculatedTemplate(e.calculatedSql);
3482
- return tn(r, {
3482
+ return on(r, {
3483
3483
  cube: t,
3484
3484
  allCubes: n,
3485
3485
  resolvedMeasures: s
@@ -3504,7 +3504,7 @@ class I {
3504
3504
  throw new Error(
3505
3505
  `Calculated measure '${t.name}.${e.name || "unknown"}' missing calculatedSql property`
3506
3506
  );
3507
- const r = /* @__PURE__ */ new Map(), a = Ee(e.calculatedSql, t.name);
3507
+ const r = /* @__PURE__ */ new Map(), a = Se(e.calculatedSql, t.name);
3508
3508
  for (const u of a) {
3509
3509
  const [c, l] = u.split("."), m = s.get(c);
3510
3510
  if (m && m.measures[l]) {
@@ -3516,22 +3516,22 @@ class I {
3516
3516
  case "count":
3517
3517
  case "countDistinct":
3518
3518
  case "sum":
3519
- h = K(f);
3519
+ h = z(f);
3520
3520
  break;
3521
3521
  case "avg":
3522
3522
  h = this.databaseAdapter.buildAvg(f);
3523
3523
  break;
3524
3524
  case "min":
3525
- h = re(f);
3525
+ h = oe(f);
3526
3526
  break;
3527
3527
  case "max":
3528
- h = V(f);
3528
+ h = G(f);
3529
3529
  break;
3530
3530
  case "number":
3531
- h = K(f);
3531
+ h = z(f);
3532
3532
  break;
3533
3533
  default:
3534
- h = K(f);
3534
+ h = z(f);
3535
3535
  }
3536
3536
  r.set(u, () => h);
3537
3537
  }
@@ -3573,17 +3573,17 @@ class I {
3573
3573
  case "count":
3574
3574
  case "countDistinct":
3575
3575
  case "sum":
3576
- return K(a);
3576
+ return z(a);
3577
3577
  case "avg":
3578
3578
  return this.databaseAdapter.buildAvg(a);
3579
3579
  case "min":
3580
- return re(a);
3580
+ return oe(a);
3581
3581
  case "max":
3582
- return V(a);
3582
+ return G(a);
3583
3583
  case "number":
3584
- return K(a);
3584
+ return z(a);
3585
3585
  default:
3586
- return K(a);
3586
+ return z(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] : D(...i);
3620
+ const r = i.length === 1 ? i[0] : _(...i);
3621
3621
  s = this.databaseAdapter.buildCaseWhen([
3622
3622
  { when: r, then: s }
3623
3623
  ]);
@@ -3625,17 +3625,17 @@ class I {
3625
3625
  }
3626
3626
  switch (e.type) {
3627
3627
  case "count":
3628
- return De(s);
3628
+ return Ae(s);
3629
3629
  case "countDistinct":
3630
- return Dt(s);
3630
+ return Rt(s);
3631
3631
  case "sum":
3632
- return K(s);
3632
+ return z(s);
3633
3633
  case "avg":
3634
3634
  return this.databaseAdapter.buildAvg(s);
3635
3635
  case "min":
3636
- return re(s);
3636
+ return oe(s);
3637
3637
  case "max":
3638
- return V(s);
3638
+ return G(s);
3639
3639
  case "number":
3640
3640
  return s;
3641
3641
  // Statistical functions (Phase 1)
@@ -3722,7 +3722,7 @@ class I {
3722
3722
  return u === null ? (console.warn(`[drizzle-cube] ${e.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), o`NULL`) : u;
3723
3723
  }
3724
3724
  default:
3725
- return De(s);
3725
+ return Ae(s);
3726
3726
  }
3727
3727
  }
3728
3728
  /**
@@ -3868,7 +3868,7 @@ class I {
3868
3868
  return n.length > 0;
3869
3869
  }
3870
3870
  }
3871
- class sn {
3871
+ class un {
3872
3872
  constructor(e) {
3873
3873
  this.dateTimeBuilder = e;
3874
3874
  }
@@ -3936,8 +3936,8 @@ class sn {
3936
3936
  if (I.isPostAggregationWindow(g)) {
3937
3937
  const y = I.getWindowBaseMeasure(g, p);
3938
3938
  if (y) {
3939
- const [b, w] = y.split("."), $ = r.get(b)?.measures?.[w];
3940
- if ($ && this.isAggregateFunctionType($.type)) {
3939
+ const [b, $] = y.split("."), w = r.get(b)?.measures?.[$];
3940
+ if (w && this.isAggregateFunctionType(w.type)) {
3941
3941
  l = !0;
3942
3942
  break;
3943
3943
  }
@@ -3952,12 +3952,12 @@ class sn {
3952
3952
  const [p, f] = m.split("."), h = r.get(p);
3953
3953
  if (h && h.dimensions && h.dimensions[f])
3954
3954
  if (s?.preAggregationCTEs?.some((y) => y.cube.name === p)) {
3955
- const y = s.preAggregationCTEs.find((w) => w.cube.name === p), b = y.joinKeys.find((w) => w.targetColumn === f);
3955
+ const y = s.preAggregationCTEs.find(($) => $.cube.name === p), b = y.joinKeys.find(($) => $.targetColumn === f);
3956
3956
  if (b && b.sourceColumnObj)
3957
3957
  i.push(b.sourceColumnObj);
3958
3958
  else {
3959
- const w = o`${o.identifier(y.cteAlias)}.${o.identifier(f)}`;
3960
- i.push(w);
3959
+ const $ = o`${o.identifier(y.cteAlias)}.${o.identifier(f)}`;
3960
+ i.push($);
3961
3961
  }
3962
3962
  } else {
3963
3963
  const y = h.dimensions[f], b = v(y.sql, n);
@@ -3969,17 +3969,17 @@ class sn {
3969
3969
  const [p, f] = m.dimension.split("."), h = r.get(p);
3970
3970
  if (h && h.dimensions && h.dimensions[f])
3971
3971
  if (s?.preAggregationCTEs?.some((y) => y.cube.name === p)) {
3972
- const y = s.preAggregationCTEs.find((w) => w.cube.name === p), b = y.joinKeys.find((w) => w.targetColumn === f);
3972
+ const y = s.preAggregationCTEs.find(($) => $.cube.name === p), b = y.joinKeys.find(($) => $.targetColumn === f);
3973
3973
  if (b && b.sourceColumnObj) {
3974
- const w = this.dateTimeBuilder.buildTimeDimensionExpression(
3974
+ const $ = this.dateTimeBuilder.buildTimeDimensionExpression(
3975
3975
  b.sourceColumnObj,
3976
3976
  m.granularity,
3977
3977
  n
3978
3978
  );
3979
- i.push(w);
3979
+ i.push($);
3980
3980
  } else {
3981
- const w = o`${o.identifier(y.cteAlias)}.${o.identifier(f)}`;
3982
- i.push(w);
3981
+ const $ = o`${o.identifier(y.cteAlias)}.${o.identifier(f)}`;
3982
+ i.push($);
3983
3983
  }
3984
3984
  } else {
3985
3985
  const y = h.dimensions[f], b = this.dateTimeBuilder.buildTimeDimensionExpression(
@@ -3993,13 +3993,13 @@ class sn {
3993
3993
  return i;
3994
3994
  }
3995
3995
  }
3996
- class rn {
3996
+ class ln {
3997
3997
  dateTimeBuilder;
3998
3998
  filterBuilder;
3999
3999
  groupByBuilder;
4000
4000
  measureBuilder;
4001
4001
  constructor(e) {
4002
- this.dateTimeBuilder = new ne(e), this.filterBuilder = new he(e, this.dateTimeBuilder), this.groupByBuilder = new sn(this.dateTimeBuilder), this.measureBuilder = new I(e);
4002
+ this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder), this.groupByBuilder = new un(this.dateTimeBuilder), this.measureBuilder = new I(e);
4003
4003
  }
4004
4004
  /**
4005
4005
  * Build resolvedMeasures map for a set of measures
@@ -4049,7 +4049,7 @@ class rn {
4049
4049
  s[r.dimension] = o`${m}`.as(r.dimension);
4050
4050
  }
4051
4051
  }
4052
- return Object.keys(s).length === 0 && (s.count = De()), s;
4052
+ return Object.keys(s).length === 0 && (s.count = Ae()), s;
4053
4053
  }
4054
4054
  /**
4055
4055
  * Build calculated measure expression by substituting {member} references
@@ -4114,7 +4114,7 @@ class rn {
4114
4114
  if (s?.preAggregationCTEs && s.preAggregationCTEs.some((b) => b.cube.name === l))
4115
4115
  continue;
4116
4116
  if (n.filterCache) {
4117
- const y = ot(c.dimension, c.dateRange), b = n.filterCache.get(y);
4117
+ const y = lt(c.dimension, c.dateRange), b = n.filterCache.get(y);
4118
4118
  if (b) {
4119
4119
  r.push(b);
4120
4120
  continue;
@@ -4148,11 +4148,11 @@ 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 ? D(...h) : null;
4151
+ return h.length > 0 ? _(...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);
4155
- return h.length > 0 ? ie(...h) : null;
4155
+ return h.length > 0 ? re(...h) : null;
4156
4156
  }
4157
4157
  }
4158
4158
  const r = e, [a, u] = r.member.split("."), c = t.get(a);
@@ -4164,7 +4164,7 @@ class rn {
4164
4164
  return null;
4165
4165
  const f = ["arrayContains", "arrayOverlaps", "arrayContained"].includes(r.operator);
4166
4166
  if (!f && n.filterCache) {
4167
- const g = de(e), y = n.filterCache.get(g);
4167
+ const g = me(e), y = n.filterCache.get(g);
4168
4168
  if (y)
4169
4169
  return y;
4170
4170
  }
@@ -4226,7 +4226,7 @@ class rn {
4226
4226
  for (const [i, r] of Object.entries(e.order)) {
4227
4227
  if (!s.includes(i))
4228
4228
  throw new Error(`Cannot order by '${i}': field is not selected in the query`);
4229
- const a = r === "desc" ? Nt(o.identifier(i)) : xe(o.identifier(i));
4229
+ const a = r === "desc" ? vt(o.identifier(i)) : Qe(o.identifier(i));
4230
4230
  n.push(a);
4231
4231
  }
4232
4232
  if (e.timeDimensions && e.timeDimensions.length > 0) {
@@ -4234,7 +4234,7 @@ class rn {
4234
4234
  (a, u) => a.dimension.localeCompare(u.dimension)
4235
4235
  );
4236
4236
  for (const a of r)
4237
- i.has(a.dimension) || n.push(xe(o.identifier(a.dimension)));
4237
+ i.has(a.dimension) || n.push(Qe(o.identifier(a.dimension)));
4238
4238
  }
4239
4239
  return n;
4240
4240
  }
@@ -4290,7 +4290,7 @@ class rn {
4290
4290
  return this.filterBuilder.buildLogicalFilter(e, t, n);
4291
4291
  }
4292
4292
  }
4293
- class oe {
4293
+ class ae {
4294
4294
  cubes;
4295
4295
  connectivityCache = /* @__PURE__ */ new Map();
4296
4296
  /**
@@ -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 = P(m.targetCube).name;
4324
+ const f = W(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 = P(m.targetCube).name;
4404
+ const f = W(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 || Q;
4452
+ const r = t ? o`${o.identifier(t)}.${o.identifier(i.source.name)}` : ve(i.source), a = n ? o`${o.identifier(n)}.${o.identifier(i.target.name)}` : ve(i.target), u = i.as || Q;
4453
4453
  s.push(u(r, a));
4454
4454
  }
4455
- return D(...s);
4455
+ return _(...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 = P(r.targetCube).name;
4470
+ const u = W(r.targetCube).name;
4471
4471
  t.has(u) || (t.add(u), n.push(u));
4472
4472
  }
4473
4473
  }
@@ -4487,7 +4487,7 @@ class oe {
4487
4487
  this.connectivityCache.set(e, { path: t });
4488
4488
  }
4489
4489
  }
4490
- class at {
4490
+ class ct {
4491
4491
  // Cache resolver per cubes map to avoid repeated instantiation
4492
4492
  resolverCache = /* @__PURE__ */ new WeakMap();
4493
4493
  /**
@@ -4495,7 +4495,7 @@ class at {
4495
4495
  */
4496
4496
  getResolver(e) {
4497
4497
  let t = this.resolverCache.get(e);
4498
- return t || (t = new oe(e), this.resolverCache.set(e, t)), t;
4498
+ return t || (t = new ae(e), this.resolverCache.set(e, t)), t;
4499
4499
  }
4500
4500
  /**
4501
4501
  * Analyze a semantic query to determine which cubes are involved
@@ -4644,45 +4644,46 @@ class at {
4644
4644
  );
4645
4645
  if (!h || h.length === 0)
4646
4646
  throw new Error(`No join path found from '${t.name}' to '${p}'`);
4647
- for (const { toCube: g, joinDef: y } of h) {
4648
- if (u.has(g))
4647
+ for (const { fromCube: g, toCube: y, joinDef: b } of h) {
4648
+ if (u.has(y))
4649
4649
  continue;
4650
- const b = e.get(g);
4651
- if (!b)
4652
- throw new Error(`Cube '${g}' not found`);
4653
- if (y.relationship === "belongsToMany" && y.through) {
4654
- const w = Jt(y, s.securityContext);
4650
+ const $ = e.get(y);
4651
+ if (!$)
4652
+ throw new Error(`Cube '${y}' not found`);
4653
+ if (b.relationship === "belongsToMany" && b.through) {
4654
+ const A = Xt(b, s.securityContext);
4655
4655
  a.push({
4656
- cube: b,
4657
- alias: `${g.toLowerCase()}_cube`,
4658
- joinType: w.junctionJoins[1].joinType,
4656
+ cube: $,
4657
+ alias: `${y.toLowerCase()}_cube`,
4658
+ joinType: A.junctionJoins[1].joinType,
4659
4659
  // Use the target join type
4660
- joinCondition: w.junctionJoins[1].condition,
4660
+ joinCondition: A.junctionJoins[1].condition,
4661
4661
  // Target join condition
4662
4662
  junctionTable: {
4663
- table: y.through.table,
4664
- alias: `junction_${g.toLowerCase()}`,
4665
- joinType: w.junctionJoins[0].joinType,
4666
- joinCondition: w.junctionJoins[0].condition,
4667
- securitySql: y.through.securitySql
4663
+ table: b.through.table,
4664
+ alias: `junction_${y.toLowerCase()}`,
4665
+ joinType: A.junctionJoins[0].joinType,
4666
+ joinCondition: A.junctionJoins[0].condition,
4667
+ securitySql: b.through.securitySql,
4668
+ sourceCubeName: g
4668
4669
  }
4669
4670
  });
4670
4671
  } else {
4671
- const w = r.buildJoinCondition(
4672
- y,
4672
+ const A = r.buildJoinCondition(
4673
+ b,
4673
4674
  null,
4674
4675
  // No source alias needed - use the actual column
4675
4676
  null
4676
4677
  // No target alias needed - use the actual column
4677
- ), A = Ae(y.relationship, y.sqlJoinType);
4678
+ ), w = _e(b.relationship, b.sqlJoinType);
4678
4679
  a.push({
4679
- cube: b,
4680
- alias: `${g.toLowerCase()}_cube`,
4681
- joinType: A,
4682
- joinCondition: w
4680
+ cube: $,
4681
+ alias: `${y.toLowerCase()}_cube`,
4682
+ joinType: w,
4683
+ joinCondition: A
4683
4684
  });
4684
4685
  }
4685
- u.add(g);
4686
+ u.add(y);
4686
4687
  }
4687
4688
  }
4688
4689
  return a;
@@ -4738,26 +4739,38 @@ class at {
4738
4739
  if (y.length === 0)
4739
4740
  continue;
4740
4741
  const b = this.analyzeJoinPathToPrimary(e, t, l.name, i);
4741
- let w, A;
4742
+ let $, A;
4742
4743
  if (b?.hasIntermediateHasMany && b.intermediateJoins.length > 0)
4743
- w = b.correctJoinKeys, A = b.intermediateJoins;
4744
+ $ = b.correctJoinKeys, A = b.intermediateJoins;
4744
4745
  else {
4745
4746
  const S = p ? this.findJoinInfoToCube(e, t.name) : this.findJoinInfoForCube(e, t, l.name);
4746
4747
  if (!S)
4747
4748
  continue;
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
4749
+ S.joinDef.relationship === "belongsToMany" && S.joinDef.through ? S.sourceCube?.name === t.name && !("reversed" in S && S.reversed) ? $ = S.joinDef.through.targetKey.map((D) => ({
4750
+ sourceColumn: D.source.name,
4751
+ // junction table column
4752
+ targetColumn: D.target.name,
4753
+ // CTE cube column
4754
+ sourceColumnObj: D.source,
4755
+ targetColumnObj: D.target
4756
+ })) : $ = S.joinDef.through.sourceKey.map((D) => ({
4757
+ sourceColumn: D.target.name,
4758
+ targetColumn: D.source.name,
4759
+ sourceColumnObj: D.target,
4760
+ targetColumnObj: D.source
4761
+ })) : $ = p || "reversed" in S && S.reversed ? S.joinDef.on.map((D) => ({
4762
+ sourceColumn: D.target.name,
4763
+ targetColumn: D.source.name,
4764
+ sourceColumnObj: D.target,
4765
+ targetColumnObj: D.source
4766
+ })) : S.joinDef.on.map((D) => ({
4767
+ sourceColumn: D.source.name,
4768
+ targetColumn: D.target.name,
4769
+ sourceColumnObj: D.source,
4770
+ targetColumnObj: D.target
4758
4771
  })), A = void 0;
4759
4772
  }
4760
- const $ = this.findPropagatingFilters(s, l, e), C = /* @__PURE__ */ new Map([[l.name, l]]), { aggregateMeasures: T, requiredBaseMeasures: E } = I.categorizeForPostAggregation(
4773
+ const w = this.findPropagatingFilters(s, l, e), C = /* @__PURE__ */ new Map([[l.name, l]]), { aggregateMeasures: T, requiredBaseMeasures: E } = I.categorizeForPostAggregation(
4761
4774
  y,
4762
4775
  C
4763
4776
  ), N = [.../* @__PURE__ */ new Set([
@@ -4777,9 +4790,9 @@ class at {
4777
4790
  cube: l,
4778
4791
  alias: m,
4779
4792
  cteAlias: `${l.name.toLowerCase()}_agg`,
4780
- joinKeys: w,
4793
+ joinKeys: $,
4781
4794
  measures: S,
4782
- propagatingFilters: $.length > 0 ? $ : void 0,
4795
+ propagatingFilters: w.length > 0 ? w : void 0,
4783
4796
  downstreamJoinKeys: R.length > 0 ? R : void 0,
4784
4797
  intermediateJoins: A && A.length > 0 ? A : void 0,
4785
4798
  cteType: "aggregate",
@@ -4797,7 +4810,7 @@ class at {
4797
4810
  for (const [, n] of e)
4798
4811
  if (n.name !== t && n.joins) {
4799
4812
  for (const [, s] of Object.entries(n.joins))
4800
- if (P(s.targetCube).name === t)
4813
+ if (W(s.targetCube).name === t)
4801
4814
  return { sourceCube: n, joinDef: s };
4802
4815
  }
4803
4816
  return null;
@@ -4837,12 +4850,12 @@ class at {
4837
4850
  for (let f = 0; f < a.length - 1; f++) {
4838
4851
  const h = a[f], g = a[f + 1], y = e.get(h.toCube);
4839
4852
  if (!y) continue;
4840
- const w = y.sql(s).where, A = g.joinDef.on[0]?.source, $ = h.joinDef.on[0]?.target;
4853
+ const $ = y.sql(s).where, A = g.joinDef.on[0]?.source, w = h.joinDef.on[0]?.target;
4841
4854
  l.push({
4842
4855
  cube: y,
4843
4856
  joinDef: g.joinDef,
4844
- securityFilter: w,
4845
- primaryJoinColumn: $,
4857
+ securityFilter: $,
4858
+ primaryJoinColumn: w,
4846
4859
  cteJoinColumn: A
4847
4860
  });
4848
4861
  }
@@ -4882,7 +4895,7 @@ class at {
4882
4895
  if (!i.has(a) && (i.add(a), !!u.joins)) {
4883
4896
  for (const [, c] of Object.entries(u.joins))
4884
4897
  if (c.relationship === "hasMany") {
4885
- const l = P(c.targetCube);
4898
+ const l = W(c.targetCube);
4886
4899
  (r.has(a) || r.has(l.name)) && s.push({
4887
4900
  fromCube: a,
4888
4901
  toCube: l.name,
@@ -4923,19 +4936,19 @@ class at {
4923
4936
  findJoinInfoForCube(e, t, n) {
4924
4937
  if (t.joins) {
4925
4938
  for (const [, i] of Object.entries(t.joins))
4926
- if (P(i.targetCube).name === n)
4939
+ if (W(i.targetCube).name === n)
4927
4940
  return { sourceCube: t, joinDef: i };
4928
4941
  }
4929
4942
  const s = e.get(n);
4930
4943
  if (s?.joins) {
4931
4944
  for (const [, i] of Object.entries(s.joins))
4932
- if (P(i.targetCube).name === t.name)
4945
+ if (W(i.targetCube).name === t.name)
4933
4946
  return { sourceCube: s, joinDef: i, reversed: !0 };
4934
4947
  }
4935
4948
  for (const [, i] of e)
4936
4949
  if (!(i.name === t.name || i.name === n) && i.joins) {
4937
4950
  for (const [, r] of Object.entries(i.joins))
4938
- if (P(r.targetCube).name === n)
4951
+ if (W(r.targetCube).name === n)
4939
4952
  return { sourceCube: i, joinDef: r };
4940
4953
  }
4941
4954
  return null;
@@ -4967,15 +4980,20 @@ class at {
4967
4980
  }
4968
4981
  if (e.joins)
4969
4982
  for (const [, r] of Object.entries(e.joins)) {
4970
- const u = P(r.targetCube).name;
4983
+ const u = W(r.targetCube).name;
4971
4984
  if (i.has(u)) {
4972
- const c = r.on.map((l) => ({
4985
+ let c;
4986
+ r.relationship === "belongsToMany" && r.through ? c = r.through.sourceKey.map((l) => ({
4973
4987
  sourceColumn: l.source.name,
4974
4988
  targetColumn: l.target.name,
4975
4989
  sourceColumnObj: l.source,
4976
4990
  targetColumnObj: l.target
4977
- }));
4978
- s.push({
4991
+ })) : c = r.on.map((l) => ({
4992
+ sourceColumn: l.source.name,
4993
+ targetColumn: l.target.name,
4994
+ sourceColumnObj: l.source,
4995
+ targetColumnObj: l.target
4996
+ })), s.push({
4979
4997
  targetCubeName: u,
4980
4998
  joinKeys: c
4981
4999
  });
@@ -5023,7 +5041,7 @@ class at {
5023
5041
  if (!e.joins)
5024
5042
  return null;
5025
5043
  for (const [, n] of Object.entries(e.joins))
5026
- if (P(n.targetCube).name === t && n.relationship === "hasMany")
5044
+ if (W(n.targetCube).name === t && n.relationship === "hasMany")
5027
5045
  return n;
5028
5046
  return null;
5029
5047
  }
@@ -5051,7 +5069,7 @@ class at {
5051
5069
  const a = n.get(r);
5052
5070
  if (a?.joins) {
5053
5071
  for (const [, u] of Object.entries(a.joins))
5054
- if (P(u.targetCube).name === t.name && u.relationship === "hasMany") {
5072
+ if (W(u.targetCube).name === t.name && u.relationship === "hasMany") {
5055
5073
  const l = this.extractFiltersForCube(e.filters, r), m = this.extractTimeDimensionFiltersForCube(e, r), p = [...l, ...m];
5056
5074
  p.length > 0 && u.on.length > 0 && s.push({
5057
5075
  sourceCube: a,
@@ -5307,7 +5325,7 @@ class at {
5307
5325
  visitedCubes: r
5308
5326
  };
5309
5327
  const a = i.map((u) => {
5310
- const c = Ae(u.joinDef.relationship, u.joinDef.sqlJoinType), l = u.joinDef.on.map((p) => ({
5328
+ const c = _e(u.joinDef.relationship, u.joinDef.sqlJoinType), l = u.joinDef.on.map((p) => ({
5311
5329
  sourceColumn: p.source.name,
5312
5330
  targetColumn: p.target.name
5313
5331
  })), m = {
@@ -5351,26 +5369,26 @@ class at {
5351
5369
  if (!u)
5352
5370
  continue;
5353
5371
  const c = s.measures.filter(
5354
- (w) => w.startsWith(r + ".")
5372
+ ($) => $.startsWith(r + ".")
5355
5373
  ), l = this.extractMeasuresFromFilters(s, u), m = [.../* @__PURE__ */ new Set([...c, ...l])];
5356
5374
  if (m.length === 0)
5357
5375
  continue;
5358
- const p = a.on.map((w) => ({
5359
- sourceColumn: w.source.name,
5360
- targetColumn: w.target.name
5376
+ const p = a.on.map(($) => ({
5377
+ sourceColumn: $.source.name,
5378
+ targetColumn: $.target.name
5361
5379
  })), f = /* @__PURE__ */ new Map([[r, u]]), { aggregateMeasures: h, postAggWindowMeasures: g, requiredBaseMeasures: y } = I.categorizeForPostAggregation(
5362
5380
  m,
5363
5381
  f
5364
5382
  ), b = [.../* @__PURE__ */ new Set([
5365
5383
  ...h,
5366
- ...Array.from(y).filter((w) => w.startsWith(r + "."))
5384
+ ...Array.from(y).filter(($) => $.startsWith(r + "."))
5367
5385
  ])];
5368
5386
  if (b.length > 0) {
5369
- const w = g.length > 0;
5387
+ const $ = g.length > 0;
5370
5388
  i.push({
5371
5389
  cubeName: r,
5372
5390
  cteAlias: `${r.toLowerCase()}_agg`,
5373
- reason: w ? `hasMany relationship from ${t.name} - requires pre-aggregation; includes base measures for post-aggregation window functions` : `hasMany relationship from ${t.name} - requires pre-aggregation to prevent row duplication (fan-out)`,
5391
+ reason: $ ? `hasMany relationship from ${t.name} - requires pre-aggregation; includes base measures for post-aggregation window functions` : `hasMany relationship from ${t.name} - requires pre-aggregation to prevent row duplication (fan-out)`,
5374
5392
  reasonType: "hasMany",
5375
5393
  measures: b,
5376
5394
  joinKeys: p,
@@ -5428,7 +5446,7 @@ class at {
5428
5446
  };
5429
5447
  }
5430
5448
  }
5431
- class on {
5449
+ class cn {
5432
5450
  constructor(e) {
5433
5451
  this.queryBuilder = e;
5434
5452
  }
@@ -5497,7 +5515,7 @@ class on {
5497
5515
  const T = C.cube.sql(n), N = [Q(C.cteJoinColumn, C.joinDef.on[0]?.target)];
5498
5516
  C.securityFilter && N.push(C.securityFilter), f = f.leftJoin(
5499
5517
  T.from,
5500
- D(...N)
5518
+ _(...N)
5501
5519
  );
5502
5520
  }
5503
5521
  const h = s ? {
@@ -5519,8 +5537,8 @@ class on {
5519
5537
  if (E === l && r.dimensions && r.dimensions[N]) {
5520
5538
  const S = r.dimensions[N];
5521
5539
  if (T.operator === "inDateRange") {
5522
- const R = this.queryBuilder.buildMeasureExpression({ sql: S.sql, type: "number" }, n), _ = this.queryBuilder.buildDateRangeCondition(R, T.values);
5523
- _ && y.push(_);
5540
+ const R = this.queryBuilder.buildMeasureExpression({ sql: S.sql, type: "number" }, n), D = this.queryBuilder.buildDateRangeCondition(R, T.values);
5541
+ D && y.push(D);
5524
5542
  }
5525
5543
  }
5526
5544
  }
@@ -5535,29 +5553,29 @@ class on {
5535
5553
  }
5536
5554
  const b = [];
5537
5555
  if (a.where && b.push(a.where), b.push(...g, ...y), b.length > 0) {
5538
- const C = b.length === 1 ? b[0] : D(...b);
5556
+ const C = b.length === 1 ? b[0] : _(...b);
5539
5557
  f = f.where(C);
5540
5558
  }
5541
- const w = [], A = /* @__PURE__ */ new Set(), $ = (C) => {
5559
+ const $ = [], A = /* @__PURE__ */ new Set(), w = (C) => {
5542
5560
  const T = C?.name || (typeof C == "string" ? C : null);
5543
- T && !A.has(T) ? (A.add(T), w.push(C)) : T || w.push(C);
5561
+ T && !A.has(T) ? (A.add(T), $.push(C)) : T || $.push(C);
5544
5562
  };
5545
5563
  if (u && e.intermediateJoins) {
5546
5564
  const C = e.intermediateJoins[0];
5547
- C.primaryJoinColumn && $(C.primaryJoinColumn);
5565
+ C.primaryJoinColumn && w(C.primaryJoinColumn);
5548
5566
  } else
5549
5567
  for (const C of e.joinKeys)
5550
- C.targetColumnObj && $(C.targetColumnObj);
5568
+ C.targetColumnObj && w(C.targetColumnObj);
5551
5569
  if (e.downstreamJoinKeys)
5552
5570
  for (const C of e.downstreamJoinKeys)
5553
5571
  for (const T of C.joinKeys)
5554
- T.sourceColumnObj && $(T.sourceColumnObj);
5572
+ T.sourceColumnObj && w(T.sourceColumnObj);
5555
5573
  if (t.dimensions)
5556
5574
  for (const C of t.dimensions) {
5557
5575
  const [T, E] = C.split(".");
5558
5576
  if (T === l && r.dimensions && r.dimensions[E]) {
5559
5577
  const N = r.dimensions[E], S = v(N.sql, n);
5560
- w.push(S);
5578
+ $.push(S);
5561
5579
  }
5562
5580
  }
5563
5581
  if (t.timeDimensions)
@@ -5565,10 +5583,10 @@ class on {
5565
5583
  const [T, E] = C.dimension.split(".");
5566
5584
  if (T === l && r.dimensions && r.dimensions[E]) {
5567
5585
  const N = r.dimensions[E], S = this.queryBuilder.buildTimeDimensionExpression(N.sql, C.granularity, n);
5568
- w.push(S);
5586
+ $.push(S);
5569
5587
  }
5570
5588
  }
5571
- return w.length > 0 && (f = f.groupBy(...w)), n.db.$with(e.cteAlias).as(f);
5589
+ return $.length > 0 && (f = f.groupBy(...$)), n.db.$with(e.cteAlias).as(f);
5572
5590
  }
5573
5591
  /**
5574
5592
  * Build join condition for CTE
@@ -5594,7 +5612,7 @@ class on {
5594
5612
  const a = r.sourceColumnObj || o.identifier(r.sourceColumn), u = o`${o.identifier(t)}.${o.identifier(r.targetColumn)}`;
5595
5613
  i.push(Q(a, u));
5596
5614
  }
5597
- return i.length === 1 ? i[0] : D(...i);
5615
+ return i.length === 1 ? i[0] : _(...i);
5598
5616
  }
5599
5617
  /**
5600
5618
  * Build a subquery filter for propagating filters from related cubes.
@@ -5623,12 +5641,12 @@ class on {
5623
5641
  }
5624
5642
  if (i.length === 0)
5625
5643
  return null;
5626
- const r = i.length === 1 ? i[0] : D(...i), a = e.joinConditions;
5644
+ const r = i.length === 1 ? i[0] : _(...i), a = e.joinConditions;
5627
5645
  if (a.length === 1) {
5628
5646
  const { source: u, target: c } = a[0], l = t.db.select({ pk: u }).from(s.from).where(r);
5629
5647
  return o`${c} IN ${l}`;
5630
5648
  } else {
5631
- const u = a.map((m) => Q(m.source, m.target)), c = D(
5649
+ const u = a.map((m) => Q(m.source, m.target)), c = _(
5632
5650
  ...u,
5633
5651
  r
5634
5652
  ), l = t.db.select({ one: o`1` }).from(s.from).where(c);
@@ -5636,15 +5654,15 @@ class on {
5636
5654
  }
5637
5655
  }
5638
5656
  }
5639
- function an(d, e, t) {
5657
+ function dn(d, e, t) {
5640
5658
  const n = [];
5641
- let s = qe(new Date(d), t);
5642
- const i = qe(new Date(e), t), r = 1e4;
5659
+ let s = Je(new Date(d), t);
5660
+ const i = Je(new Date(e), t), r = 1e4;
5643
5661
  for (; s <= i && n.length < r; )
5644
- n.push(new Date(s)), s = un(s, t);
5662
+ n.push(new Date(s)), s = mn(s, t);
5645
5663
  return n;
5646
5664
  }
5647
- function qe(d, e) {
5665
+ function Je(d, e) {
5648
5666
  const t = new Date(d);
5649
5667
  switch (e) {
5650
5668
  case "second":
@@ -5678,7 +5696,7 @@ function qe(d, e) {
5678
5696
  }
5679
5697
  return t;
5680
5698
  }
5681
- function un(d, e) {
5699
+ function mn(d, e) {
5682
5700
  const t = new Date(d);
5683
5701
  switch (e) {
5684
5702
  case "second":
@@ -5708,7 +5726,7 @@ function un(d, e) {
5708
5726
  }
5709
5727
  return t;
5710
5728
  }
5711
- function ln(d) {
5729
+ function fn(d) {
5712
5730
  if (d instanceof Date)
5713
5731
  return d.toISOString();
5714
5732
  if (typeof d == "string") {
@@ -5718,16 +5736,16 @@ function ln(d) {
5718
5736
  }
5719
5737
  return String(d);
5720
5738
  }
5721
- function cn(d, e) {
5739
+ function pn(d, e) {
5722
5740
  return e.length === 0 ? "__all__" : e.map((t) => String(d[t] ?? "")).join("|||");
5723
5741
  }
5724
- function dn(d, e) {
5725
- const { timeDimensionKey: t, granularity: n, dateRange: s, fillValue: i, measures: r, dimensions: a } = e, u = an(s[0], s[1], n);
5742
+ function hn(d, e) {
5743
+ const { timeDimensionKey: t, granularity: n, dateRange: s, fillValue: i, measures: r, dimensions: a } = e, u = dn(s[0], s[1], n);
5726
5744
  if (u.length === 0)
5727
5745
  return d;
5728
5746
  const c = /* @__PURE__ */ new Map();
5729
5747
  for (const m of d) {
5730
- const p = cn(m, a), f = ln(m[t]);
5748
+ const p = pn(m, a), f = fn(m[t]);
5731
5749
  c.has(p) || c.set(p, /* @__PURE__ */ new Map()), c.get(p).set(f, m);
5732
5750
  }
5733
5751
  c.size === 0 && a.length === 0 && c.set("__all__", /* @__PURE__ */ new Map());
@@ -5743,17 +5761,17 @@ function dn(d, e) {
5743
5761
  [t]: g
5744
5762
  };
5745
5763
  if (f)
5746
- for (const w of a)
5747
- b[w] = f[w];
5748
- for (const w of r)
5749
- b[w] = i;
5764
+ for (const $ of a)
5765
+ b[$] = f[$];
5766
+ for (const $ of r)
5767
+ b[$] = i;
5750
5768
  l.push(b);
5751
5769
  }
5752
5770
  }
5753
5771
  }
5754
5772
  return l;
5755
5773
  }
5756
- function mn(d) {
5774
+ function gn(d) {
5757
5775
  if (!d)
5758
5776
  return null;
5759
5777
  if (Array.isArray(d)) {
@@ -5765,7 +5783,7 @@ function mn(d) {
5765
5783
  const e = new Date(d);
5766
5784
  return isNaN(e.getTime()) ? null : [e, e];
5767
5785
  }
5768
- function ze(d, e, t) {
5786
+ function Ge(d, e, t) {
5769
5787
  if (!e.timeDimensions || e.timeDimensions.length === 0)
5770
5788
  return d;
5771
5789
  const n = e.timeDimensions.filter((u) => {
@@ -5777,7 +5795,7 @@ function ze(d, e, t) {
5777
5795
  const s = e.fillMissingDatesValue === void 0 ? 0 : e.fillMissingDatesValue, i = new Set(e.timeDimensions.map((u) => u.dimension)), r = (e.dimensions || []).filter((u) => !i.has(u));
5778
5796
  let a = d;
5779
5797
  for (const u of n) {
5780
- const c = mn(u.dateRange);
5798
+ const c = gn(u.dateRange);
5781
5799
  if (!c)
5782
5800
  continue;
5783
5801
  const l = {
@@ -5788,14 +5806,14 @@ function ze(d, e, t) {
5788
5806
  measures: t,
5789
5807
  dimensions: r
5790
5808
  };
5791
- a = dn(a, l);
5809
+ a = hn(a, l);
5792
5810
  }
5793
5811
  return a;
5794
5812
  }
5795
- class fn {
5813
+ class bn {
5796
5814
  dateTimeBuilder;
5797
5815
  constructor(e) {
5798
- this.dateTimeBuilder = new ne(e);
5816
+ this.dateTimeBuilder = new ie(e);
5799
5817
  }
5800
5818
  /**
5801
5819
  * Check if a query contains compareDateRange
@@ -5976,9 +5994,9 @@ class fn {
5976
5994
  });
5977
5995
  }
5978
5996
  }
5979
- class pn {
5997
+ class yn {
5980
5998
  constructor(e) {
5981
- this.databaseAdapter = e, this.dateTimeBuilder = new ne(e), this.filterBuilder = new he(e, this.dateTimeBuilder);
5999
+ this.databaseAdapter = e, this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder);
5982
6000
  }
5983
6001
  filterBuilder;
5984
6002
  dateTimeBuilder;
@@ -6025,7 +6043,7 @@ class pn {
6025
6043
  if (i.name || n.push(`Step ${s} must have a name`), "cube" in i && i.cube && (t.get(i.cube) || n.push(`Step ${s} cube not found: ${i.cube}`)), i.filter) {
6026
6044
  let r;
6027
6045
  "cube" in i && i.cube ? r = i.cube : typeof e.bindingKey == "string" && ([r] = e.bindingKey.split("."));
6028
- const a = r ? new oe(t) : null, u = Array.isArray(i.filter) ? i.filter : [i.filter];
6046
+ const a = r ? new ae(t) : null, u = Array.isArray(i.filter) ? i.filter : [i.filter];
6029
6047
  for (const c of u)
6030
6048
  if ("member" in c) {
6031
6049
  const [l, m] = c.member.split("."), p = t.get(l);
@@ -6113,7 +6131,7 @@ class pn {
6113
6131
  * Resolve steps with their cube, SQL expressions, and filter conditions
6114
6132
  */
6115
6133
  resolveSteps(e, t, n) {
6116
- const s = new oe(t);
6134
+ const s = new ae(t);
6117
6135
  return e.steps.map((i, r) => {
6118
6136
  const a = this.resolveCubeForStep(i, e, t), u = this.resolveBindingKey(e, a, n), c = this.resolveTimeDimension(e, a, n), l = this.buildStepFilters(i, a, t, n), m = this.extractFilterCubeNames(i), p = [];
6119
6137
  for (const f of m)
@@ -6222,20 +6240,20 @@ class pn {
6222
6240
  if (r) {
6223
6241
  const b = e;
6224
6242
  y = b.type === "and";
6225
- for (const w of b.filters || []) {
6226
- const A = this.buildFilterCondition(w, t, n, s);
6243
+ for (const $ of b.filters || []) {
6244
+ const A = this.buildFilterCondition($, t, n, s);
6227
6245
  A && g.push(A);
6228
6246
  }
6229
6247
  } else {
6230
6248
  const b = e;
6231
6249
  y = "and" in b && !!b.and;
6232
- const w = b.and || b.or || [];
6233
- for (const A of w) {
6234
- const $ = this.buildFilterCondition(A, t, n, s);
6235
- $ && g.push($);
6250
+ const $ = b.and || b.or || [];
6251
+ for (const A of $) {
6252
+ const w = this.buildFilterCondition(A, t, n, s);
6253
+ w && g.push(w);
6236
6254
  }
6237
6255
  }
6238
- return g.length === 0 ? null : g.length === 1 ? g[0] : y ? D(...g) : o`(${o.join(g, o` OR `)})`;
6256
+ return g.length === 0 ? null : g.length === 1 ? g[0] : y ? _(...g) : o`(${o.join(g, o` OR `)})`;
6239
6257
  }
6240
6258
  const a = e, [u, c] = a.member.split("."), l = a.dateRange !== void 0;
6241
6259
  if (a.operator !== "set" && a.operator !== "notSet" && !l && (!a.values || a.values.length === 0 || a.values[0] === void 0 || a.values[0] === ""))
@@ -6244,7 +6262,7 @@ class pn {
6244
6262
  if (!p)
6245
6263
  return null;
6246
6264
  if (u !== t.name) {
6247
- const y = new oe(n).findPath(t.name, u);
6265
+ const y = new ae(n).findPath(t.name, u);
6248
6266
  if (!y || y.length === 0)
6249
6267
  return console.warn(
6250
6268
  `Funnel filter: Cannot filter by '${u}.${c}' in step using '${t.name}'. No join path found. Filter will be skipped.`
@@ -6291,7 +6309,7 @@ class pn {
6291
6309
  step_time: o`MIN(${e.timeExpr})`.as("step_time")
6292
6310
  }).from(s.from);
6293
6311
  if (r = this.addCrossJoinsToQuery(r, e, t, i), i.length > 0) {
6294
- const a = i.length === 1 ? i[0] : D(...i);
6312
+ const a = i.length === 1 ? i[0] : _(...i);
6295
6313
  r = r.where(a);
6296
6314
  }
6297
6315
  return r = r.groupBy(e.bindingKeyExpr), t.db.$with(n).as(r);
@@ -6324,7 +6342,7 @@ class pn {
6324
6342
  o`${e.bindingKeyExpr} = ${o.identifier(i)}.binding_key`
6325
6343
  );
6326
6344
  if (l = this.addCrossJoinsToQuery(l, e, t, a), a.length > 0) {
6327
- const m = a.length === 1 ? a[0] : D(...a);
6345
+ const m = a.length === 1 ? a[0] : _(...a);
6328
6346
  l = l.where(m);
6329
6347
  }
6330
6348
  return l = l.groupBy(e.bindingKeyExpr), t.db.$with(s).as(l);
@@ -6341,7 +6359,7 @@ class pn {
6341
6359
  const a = r.joinDef, u = [];
6342
6360
  for (const p of a.on)
6343
6361
  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);
6362
+ const c = u.length === 1 ? u[0] : _(...u), m = i.cube.sql(n);
6345
6363
  e = e.leftJoin(m.from, c), m.where && s.push(m.where);
6346
6364
  }
6347
6365
  return e;
@@ -6414,12 +6432,12 @@ class pn {
6414
6432
  return i.db.$with("funnel_metrics").as(a);
6415
6433
  }
6416
6434
  }
6417
- class hn {
6435
+ class Cn {
6418
6436
  filterBuilder;
6419
6437
  dateTimeBuilder;
6420
6438
  databaseAdapter;
6421
6439
  constructor(e) {
6422
- this.databaseAdapter = e, this.dateTimeBuilder = new ne(e), this.filterBuilder = new he(e, this.dateTimeBuilder);
6440
+ this.databaseAdapter = e, this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder);
6423
6441
  }
6424
6442
  /**
6425
6443
  * Check if query contains flow configuration
@@ -6650,7 +6668,7 @@ class hn {
6650
6668
  const p = this.buildFilterCondition(m, t, n);
6651
6669
  p && c.push(p);
6652
6670
  }
6653
- return c.length === 0 ? null : c.length === 1 ? c[0] : "and" in e ? D(...c) : o`(${o.join(c, o` OR `)})`;
6671
+ return c.length === 0 ? null : c.length === 1 ? c[0] : "and" in e ? _(...c) : o`(${o.join(c, o` OR `)})`;
6654
6672
  }
6655
6673
  if ("type" in e && "filters" in e) {
6656
6674
  const u = e, c = [];
@@ -6658,7 +6676,7 @@ class hn {
6658
6676
  const m = this.buildFilterCondition(l, t, n);
6659
6677
  m && c.push(m);
6660
6678
  }
6661
- return c.length === 0 ? null : c.length === 1 ? c[0] : u.type === "and" ? D(...c) : o`(${o.join(c, o` OR `)})`;
6679
+ return c.length === 0 ? null : c.length === 1 ? c[0] : u.type === "and" ? _(...c) : o`(${o.join(c, o` OR `)})`;
6662
6680
  }
6663
6681
  const s = e, [, i] = s.member.split("."), r = t.dimensions?.[i];
6664
6682
  if (!r) return null;
@@ -6690,7 +6708,7 @@ class hn {
6690
6708
  event_path: o`${a}`.as("event_path")
6691
6709
  }).from(s.from);
6692
6710
  if (c.length > 0) {
6693
- const m = c.length === 1 ? c[0] : D(...c);
6711
+ const m = c.length === 1 ? c[0] : _(...c);
6694
6712
  l = l.where(m);
6695
6713
  }
6696
6714
  return l = l.groupBy(i, a), e.entityLimit && (l = l.limit(e.entityLimit)), n.db.$with("starting_entities").as(l);
@@ -6707,12 +6725,12 @@ class hn {
6707
6725
  o`${i} = ${o.identifier(m)}.binding_key`,
6708
6726
  o`${r} < ${o.identifier(m)}.${o.identifier(p)}`
6709
6727
  );
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({
6728
+ const g = h.length === 1 ? h[0] : _(...h), y = c ? o`${a} || ${"→"} || ${o.identifier(m)}.event_path` : o`${a}`, b = n.db.select({
6711
6729
  binding_key: o`${i}`.as("binding_key"),
6712
6730
  step_time: o`${r}`.as("step_time"),
6713
6731
  event_type: o`${a}`.as("event_type"),
6714
6732
  event_path: y.as("event_path")
6715
- }).from(s.from).where(g).orderBy(o`${r} DESC`).limit(1), w = n.db.$with(f).as(
6733
+ }).from(s.from).where(g).orderBy(o`${r} DESC`).limit(1), $ = n.db.$with(f).as(
6716
6734
  n.db.select({
6717
6735
  binding_key: o`e.binding_key`.as("binding_key"),
6718
6736
  step_time: o`e.step_time`.as("step_time"),
@@ -6720,7 +6738,7 @@ class hn {
6720
6738
  event_path: o`e.event_path`.as("event_path")
6721
6739
  }).from(o`${o.identifier(m)}`).crossJoinLateral(b.as("e"))
6722
6740
  );
6723
- u.push(w);
6741
+ u.push($);
6724
6742
  }
6725
6743
  return u;
6726
6744
  }
@@ -6736,12 +6754,12 @@ class hn {
6736
6754
  o`${i} = ${o.identifier(m)}.binding_key`,
6737
6755
  o`${r} > ${o.identifier(m)}.${o.identifier(p)}`
6738
6756
  );
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({
6757
+ const g = h.length === 1 ? h[0] : _(...h), y = c ? o`${o.identifier(m)}.event_path || ${"→"} || ${a}` : o`${a}`, b = n.db.select({
6740
6758
  binding_key: o`${i}`.as("binding_key"),
6741
6759
  step_time: o`${r}`.as("step_time"),
6742
6760
  event_type: o`${a}`.as("event_type"),
6743
6761
  event_path: y.as("event_path")
6744
- }).from(s.from).where(g).orderBy(o`${r} ASC`).limit(1), w = n.db.$with(f).as(
6762
+ }).from(s.from).where(g).orderBy(o`${r} ASC`).limit(1), $ = n.db.$with(f).as(
6745
6763
  n.db.select({
6746
6764
  binding_key: o`e.binding_key`.as("binding_key"),
6747
6765
  step_time: o`e.step_time`.as("step_time"),
@@ -6749,7 +6767,7 @@ class hn {
6749
6767
  event_path: o`e.event_path`.as("event_path")
6750
6768
  }).from(o`${o.identifier(m)}`).crossJoinLateral(b.as("e"))
6751
6769
  );
6752
- u.push(w);
6770
+ u.push($);
6753
6771
  }
6754
6772
  return u;
6755
6773
  }
@@ -6767,7 +6785,7 @@ class hn {
6767
6785
  s.where && h.push(s.where), h.push(
6768
6786
  o`${r} < ${o.identifier(m)}.${o.identifier(p)}`
6769
6787
  );
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({
6788
+ const g = h.length === 1 ? h[0] : _(...h), y = c ? o`${a} || ${"→"} || ${o.identifier(m)}.event_path` : o`${a}`, b = n.db.select({
6771
6789
  binding_key: o`${i}`.as("binding_key"),
6772
6790
  step_time: o`${r}`.as("step_time"),
6773
6791
  event_type: o`${a}`.as("event_type"),
@@ -6776,13 +6794,13 @@ class hn {
6776
6794
  }).from(s.from).innerJoin(
6777
6795
  o`${o.identifier(m)}`,
6778
6796
  o`${i} = ${o.identifier(m)}.binding_key`
6779
- ).where(g), w = n.db.select({
6797
+ ).where(g), $ = n.db.select({
6780
6798
  binding_key: o`binding_key`.as("binding_key"),
6781
6799
  step_time: o`step_time`.as("step_time"),
6782
6800
  event_type: o`event_type`.as("event_type"),
6783
6801
  event_path: o`event_path`.as("event_path")
6784
6802
  }).from(b.as("ranked")).where(o`rn = 1`);
6785
- u.push(n.db.$with(f).as(w));
6803
+ u.push(n.db.$with(f).as($));
6786
6804
  }
6787
6805
  return u;
6788
6806
  }
@@ -6800,7 +6818,7 @@ class hn {
6800
6818
  s.where && h.push(s.where), h.push(
6801
6819
  o`${r} > ${o.identifier(m)}.${o.identifier(p)}`
6802
6820
  );
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({
6821
+ const g = h.length === 1 ? h[0] : _(...h), y = c ? o`${o.identifier(m)}.event_path || ${"→"} || ${a}` : o`${a}`, b = n.db.select({
6804
6822
  binding_key: o`${i}`.as("binding_key"),
6805
6823
  step_time: o`${r}`.as("step_time"),
6806
6824
  event_type: o`${a}`.as("event_type"),
@@ -6809,13 +6827,13 @@ class hn {
6809
6827
  }).from(s.from).innerJoin(
6810
6828
  o`${o.identifier(m)}`,
6811
6829
  o`${i} = ${o.identifier(m)}.binding_key`
6812
- ).where(g), w = n.db.select({
6830
+ ).where(g), $ = n.db.select({
6813
6831
  binding_key: o`binding_key`.as("binding_key"),
6814
6832
  step_time: o`step_time`.as("step_time"),
6815
6833
  event_type: o`event_type`.as("event_type"),
6816
6834
  event_path: o`event_path`.as("event_path")
6817
6835
  }).from(b.as("ranked")).where(o`rn = 1`);
6818
- u.push(n.db.$with(f).as(w));
6836
+ u.push(n.db.$with(f).as($));
6819
6837
  }
6820
6838
  return u;
6821
6839
  }
@@ -7016,31 +7034,31 @@ class hn {
7016
7034
  return e.db.$with("final_result").as(n);
7017
7035
  }
7018
7036
  }
7019
- function Ve(d) {
7037
+ function He(d) {
7020
7038
  return Array.isArray(d);
7021
7039
  }
7022
- function ut(d) {
7040
+ function dt(d) {
7023
7041
  return typeof d == "object" && d !== null && "cube" in d;
7024
7042
  }
7025
- function Je(d) {
7026
- if (ut(d))
7043
+ function Ye(d) {
7044
+ if (dt(d))
7027
7045
  return d.cube;
7028
7046
  const e = d.indexOf(".");
7029
7047
  if (e === -1)
7030
7048
  throw new Error(`Invalid time dimension format: ${d}. Expected 'CubeName.dimensionName'`);
7031
7049
  return d.substring(0, e);
7032
7050
  }
7033
- function Ge(d) {
7034
- if (ut(d))
7051
+ function Xe(d) {
7052
+ if (dt(d))
7035
7053
  return d.dimension;
7036
7054
  const e = d.indexOf(".");
7037
7055
  if (e === -1)
7038
7056
  throw new Error(`Invalid time dimension format: ${d}. Expected 'CubeName.dimensionName'`);
7039
7057
  return d.substring(e + 1);
7040
7058
  }
7041
- class gn {
7059
+ class wn {
7042
7060
  constructor(e) {
7043
- this.databaseAdapter = e, this.dateTimeBuilder = new ne(e), this.filterBuilder = new he(e, this.dateTimeBuilder);
7061
+ this.databaseAdapter = e, this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder);
7044
7062
  }
7045
7063
  filterBuilder;
7046
7064
  dateTimeBuilder;
@@ -7056,12 +7074,12 @@ class gn {
7056
7074
  validateConfig(e, t) {
7057
7075
  const n = [];
7058
7076
  try {
7059
- const r = Je(e.timeDimension), a = Ge(e.timeDimension), u = t.get(r);
7077
+ const r = Ye(e.timeDimension), a = Xe(e.timeDimension), u = t.get(r);
7060
7078
  u ? u.dimensions?.[a] || n.push(`Time dimension not found: ${a} in cube ${r}`) : n.push(`Cube not found: ${r}`);
7061
7079
  } catch {
7062
7080
  n.push(`Invalid time dimension format: ${e.timeDimension}`);
7063
7081
  }
7064
- if (Ve(e.bindingKey))
7082
+ if (He(e.bindingKey))
7065
7083
  for (const r of e.bindingKey) {
7066
7084
  const a = t.get(r.cube);
7067
7085
  if (!a)
@@ -7173,7 +7191,7 @@ class gn {
7173
7191
  * Same cube/dimension used for both cohort entry and activity detection
7174
7192
  */
7175
7193
  resolveConfig(e, t, n) {
7176
- const s = Je(e.timeDimension), i = Ge(e.timeDimension), r = t.get(s);
7194
+ const s = Ye(e.timeDimension), i = Xe(e.timeDimension), r = t.get(s);
7177
7195
  if (!r)
7178
7196
  throw new Error(`Cube not found: ${s}`);
7179
7197
  const a = r.dimensions?.[i];
@@ -7194,7 +7212,7 @@ class gn {
7194
7212
  * Resolve binding key expression for a cube
7195
7213
  */
7196
7214
  resolveBindingKey(e, t, n, s) {
7197
- if (Ve(e)) {
7215
+ if (He(e)) {
7198
7216
  const c = e.find((f) => f.cube === t.name);
7199
7217
  if (!c)
7200
7218
  throw new Error(`No binding key mapping found for cube: ${t.name}`);
@@ -7236,7 +7254,7 @@ class gn {
7236
7254
  const y = this.buildSingleFilterCondition(g, t, n, s);
7237
7255
  y && p.push(y);
7238
7256
  }
7239
- return p.length === 0 ? null : p.length === 1 ? p[0] : f ? D(...p) : o`(${o.join(p, o` OR `)})`;
7257
+ return p.length === 0 ? null : p.length === 1 ? p[0] : f ? _(...p) : o`(${o.join(p, o` OR `)})`;
7240
7258
  }
7241
7259
  const i = e, [r, a] = i.member.split("."), u = n.get(r);
7242
7260
  if (!u) return null;
@@ -7278,7 +7296,7 @@ class gn {
7278
7296
  }
7279
7297
  let u = n.db.select(a).from(s.from);
7280
7298
  if (i.length > 0) {
7281
- const l = i.length === 1 ? i[0] : D(...i);
7299
+ const l = i.length === 1 ? i[0] : _(...i);
7282
7300
  u = u.where(l);
7283
7301
  }
7284
7302
  const c = [t.bindingKeyExpr];
@@ -7333,7 +7351,7 @@ class gn {
7333
7351
  o`${t.bindingKeyExpr} = cohort_base.binding_key`
7334
7352
  );
7335
7353
  if (i.length > 0) {
7336
- const m = i.length === 1 ? i[0] : D(...i);
7354
+ const m = i.length === 1 ? i[0] : _(...i);
7337
7355
  c = c.where(m);
7338
7356
  }
7339
7357
  const l = [
@@ -7426,11 +7444,11 @@ class gn {
7426
7444
  return t.length > 1 ? t[1] : t[0];
7427
7445
  }
7428
7446
  }
7429
- class J {
7447
+ class Y {
7430
7448
  constructor(e, t) {
7431
7449
  if (this.dbExecutor = e, this.databaseAdapter = e.databaseAdapter, !this.databaseAdapter)
7432
7450
  throw new Error("DatabaseExecutor must have a databaseAdapter property");
7433
- this.queryBuilder = new rn(this.databaseAdapter), this.queryPlanner = new at(), this.cteBuilder = new on(this.queryBuilder), this.comparisonQueryBuilder = new fn(this.databaseAdapter), this.funnelQueryBuilder = new pn(this.databaseAdapter), this.flowQueryBuilder = new hn(this.databaseAdapter), this.retentionQueryBuilder = new gn(this.databaseAdapter), this.cacheConfig = t;
7451
+ this.queryBuilder = new ln(this.databaseAdapter), this.queryPlanner = new ct(), this.cteBuilder = new cn(this.queryBuilder), this.comparisonQueryBuilder = new bn(this.databaseAdapter), this.funnelQueryBuilder = new yn(this.databaseAdapter), this.flowQueryBuilder = new Cn(this.databaseAdapter), this.retentionQueryBuilder = new wn(this.databaseAdapter), this.cacheConfig = t;
7434
7452
  }
7435
7453
  queryBuilder;
7436
7454
  queryPlanner;
@@ -7460,13 +7478,13 @@ class J {
7460
7478
  if (!b.isValid)
7461
7479
  throw new Error(`Retention validation failed: ${b.errors.join(", ")}`);
7462
7480
  } else {
7463
- const b = ct(e, t);
7481
+ const b = ft(e, t);
7464
7482
  if (!b.isValid)
7465
7483
  throw new Error(`Query validation failed: ${b.errors.join(", ")}`);
7466
7484
  }
7467
7485
  let i;
7468
7486
  if (this.cacheConfig?.enabled !== !1 && this.cacheConfig?.provider)
7469
- if (i = Gt(t, n, this.cacheConfig), s?.skipCache)
7487
+ if (i = Zt(t, n, this.cacheConfig), s?.skipCache)
7470
7488
  this.cacheConfig.onCacheEvent?.({
7471
7489
  type: "miss",
7472
7490
  key: i,
@@ -7474,19 +7492,19 @@ class J {
7474
7492
  });
7475
7493
  else
7476
7494
  try {
7477
- const b = Date.now(), w = await this.cacheConfig.provider.get(i);
7478
- if (w)
7495
+ const b = Date.now(), $ = await this.cacheConfig.provider.get(i);
7496
+ if ($)
7479
7497
  return this.cacheConfig.onCacheEvent?.({
7480
7498
  type: "hit",
7481
7499
  key: i,
7482
7500
  durationMs: Date.now() - b
7483
7501
  }), {
7484
- ...w.value,
7485
- cache: w.metadata ? {
7502
+ ...$.value,
7503
+ cache: $.metadata ? {
7486
7504
  hit: !0,
7487
- cachedAt: new Date(w.metadata.cachedAt).toISOString(),
7488
- ttlMs: w.metadata.ttlMs,
7489
- ttlRemainingMs: w.metadata.ttlRemainingMs
7505
+ cachedAt: new Date($.metadata.cachedAt).toISOString(),
7506
+ ttlMs: $.metadata.ttlMs,
7507
+ ttlRemainingMs: $.metadata.ttlRemainingMs
7490
7508
  } : {
7491
7509
  hit: !0,
7492
7510
  cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -7510,7 +7528,7 @@ class J {
7510
7528
  return this.executeFlowQueryWithCache(e, t, n, i);
7511
7529
  if (this.retentionQueryBuilder.hasRetention(t))
7512
7530
  return this.executeRetentionQueryWithCache(e, t, n, i);
7513
- const r = new We(), a = {
7531
+ const r = new ze(), a = {
7514
7532
  db: this.dbExecutor.db,
7515
7533
  schema: this.dbExecutor.schema,
7516
7534
  securityContext: n,
@@ -7520,20 +7538,20 @@ class J {
7520
7538
  const u = this.queryPlanner.createQueryPlan(e, t, a);
7521
7539
  this.validateSecurityContext(u, a);
7522
7540
  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) => {
7523
- const w = { ...b };
7541
+ const $ = { ...b };
7524
7542
  if (t.timeDimensions) {
7525
7543
  for (const A of t.timeDimensions)
7526
- if (A.dimension in w) {
7527
- let $ = w[A.dimension];
7528
- if (typeof $ == "string" && $.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
7529
- const C = $.replace(" ", "T"), T = !C.endsWith("Z") && !C.includes("+") ? C + "Z" : C;
7530
- $ = new Date(T);
7544
+ if (A.dimension in $) {
7545
+ let w = $[A.dimension];
7546
+ if (typeof w == "string" && w.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
7547
+ const C = w.replace(" ", "T"), T = !C.endsWith("Z") && !C.includes("+") ? C + "Z" : C;
7548
+ w = new Date(T);
7531
7549
  }
7532
- $ = this.databaseAdapter.convertTimeDimensionResult($), w[A.dimension] = $;
7550
+ w = this.databaseAdapter.convertTimeDimensionResult(w), $[A.dimension] = w;
7533
7551
  }
7534
7552
  }
7535
- return w;
7536
- }) : [m], f = t.measures || [], h = ze(p, t, f), g = this.generateAnnotations(u, t), y = {
7553
+ return $;
7554
+ }) : [m], f = t.measures || [], h = Ge(p, t, f), g = this.generateAnnotations(u, t), y = {
7537
7555
  data: h,
7538
7556
  annotation: g,
7539
7557
  // Include warnings from query planning (e.g., fan-out without dimensions)
@@ -7797,7 +7815,7 @@ class J {
7797
7815
  * This is the core execution logic extracted for use by comparison queries
7798
7816
  */
7799
7817
  async executeStandardQuery(e, t, n) {
7800
- const s = new We(), i = {
7818
+ const s = new ze(), i = {
7801
7819
  db: this.dbExecutor.db,
7802
7820
  schema: this.dbExecutor.schema,
7803
7821
  securityContext: n,
@@ -7811,14 +7829,14 @@ class J {
7811
7829
  if (y.dimension in g) {
7812
7830
  let b = g[y.dimension];
7813
7831
  if (typeof b == "string" && b.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
7814
- const w = b.replace(" ", "T"), A = !w.endsWith("Z") && !w.includes("+") ? w + "Z" : w;
7832
+ const $ = b.replace(" ", "T"), A = !$.endsWith("Z") && !$.includes("+") ? $ + "Z" : $;
7815
7833
  b = new Date(A);
7816
7834
  }
7817
7835
  b = this.databaseAdapter.convertTimeDimensionResult(b), g[y.dimension] = b;
7818
7836
  }
7819
7837
  }
7820
7838
  return g;
7821
- }) : [c], m = t.measures || [], p = ze(l, t, m), f = this.generateAnnotations(r, t);
7839
+ }) : [c], m = t.measures || [], p = Ge(l, t, m), f = this.generateAnnotations(r, t);
7822
7840
  return {
7823
7841
  data: p,
7824
7842
  annotation: f
@@ -7859,9 +7877,9 @@ class J {
7859
7877
  buildUnifiedQuery(e, t, n) {
7860
7878
  const s = /* @__PURE__ */ new Map();
7861
7879
  if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0) {
7862
- for (const $ of e.preAggregationCTEs)
7863
- if ($.propagatingFilters && $.propagatingFilters.length > 0)
7864
- for (const C of $.propagatingFilters) {
7880
+ for (const w of e.preAggregationCTEs)
7881
+ if (w.propagatingFilters && w.propagatingFilters.length > 0)
7882
+ for (const C of w.propagatingFilters) {
7865
7883
  const T = C.sourceCube.name;
7866
7884
  if (!s.has(T)) {
7867
7885
  const N = {
@@ -7874,17 +7892,17 @@ class J {
7874
7892
  s.set(T, R);
7875
7893
  }
7876
7894
  const E = s.get(T);
7877
- E && E.length > 0 && (C.preBuiltFilterSQL = E.length === 1 ? E[0] : D(...E));
7895
+ E && E.length > 0 && (C.preBuiltFilterSQL = E.length === 1 ? E[0] : _(...E));
7878
7896
  }
7879
7897
  }
7880
7898
  const i = [], r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
7881
7899
  if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0)
7882
- for (const $ of e.preAggregationCTEs) {
7883
- const C = this.cteBuilder.buildPreAggregationCTE($, t, n, e, s);
7884
- if (C && (i.push(C), r.set($.cube.name, $.cteAlias), $.downstreamJoinKeys))
7885
- for (const T of $.downstreamJoinKeys)
7900
+ for (const w of e.preAggregationCTEs) {
7901
+ const C = this.cteBuilder.buildPreAggregationCTE(w, t, n, e, s);
7902
+ if (C && (i.push(C), r.set(w.cube.name, w.cteAlias), w.downstreamJoinKeys))
7903
+ for (const T of w.downstreamJoinKeys)
7886
7904
  a.set(T.targetCubeName, {
7887
- cteAlias: $.cteAlias,
7905
+ cteAlias: w.cteAlias,
7888
7906
  joinKeys: T.joinKeys
7889
7907
  });
7890
7908
  }
@@ -7895,97 +7913,97 @@ class J {
7895
7913
  n
7896
7914
  ) };
7897
7915
  if (e.preAggregationCTEs)
7898
- for (const $ of e.preAggregationCTEs) {
7899
- const C = $.cube.name;
7900
- for (const T of $.measures)
7916
+ for (const w of e.preAggregationCTEs) {
7917
+ const C = w.cube.name;
7918
+ for (const T of w.measures)
7901
7919
  if (m[T]) {
7902
7920
  const [, E] = T.split("."), N = c.get(C);
7903
7921
  if (N && N.measures && N.measures[E]) {
7904
- const S = N.measures[E], R = o`${o.identifier($.cteAlias)}.${o.identifier(E)}`;
7905
- let _;
7922
+ const S = N.measures[E], R = o`${o.identifier(w.cteAlias)}.${o.identifier(E)}`;
7923
+ let D;
7906
7924
  if (S.type === "calculated" && S.calculatedSql)
7907
- _ = this.queryBuilder.buildCTECalculatedMeasure(
7925
+ D = this.queryBuilder.buildCTECalculatedMeasure(
7908
7926
  S,
7909
7927
  N,
7910
- $,
7928
+ w,
7911
7929
  c,
7912
7930
  n
7913
7931
  );
7914
7932
  else {
7915
- const F = $.cteReason === "fanOutPrevention", k = this.shouldUseMaxForHasManyAtJoinKeyGrain(
7916
- $,
7933
+ const F = w.cteReason === "fanOutPrevention", U = this.shouldUseMaxForHasManyAtJoinKeyGrain(
7934
+ w,
7917
7935
  t,
7918
7936
  c
7919
- ), M = F || k;
7937
+ ), j = F || U;
7920
7938
  switch (S.type) {
7921
7939
  case "count":
7922
7940
  case "countDistinct":
7923
7941
  case "sum":
7924
- _ = M ? V(R) : K(R);
7942
+ D = j ? G(R) : z(R);
7925
7943
  break;
7926
7944
  case "avg":
7927
- _ = M ? V(R) : this.databaseAdapter.buildAvg(R);
7945
+ D = j ? G(R) : this.databaseAdapter.buildAvg(R);
7928
7946
  break;
7929
7947
  case "min":
7930
- _ = re(R);
7948
+ D = oe(R);
7931
7949
  break;
7932
7950
  case "max":
7933
- _ = V(R);
7951
+ D = G(R);
7934
7952
  break;
7935
7953
  case "number":
7936
- _ = M ? V(R) : K(R);
7954
+ D = j ? G(R) : z(R);
7937
7955
  break;
7938
7956
  default:
7939
- _ = M ? V(R) : K(R);
7957
+ D = j ? G(R) : z(R);
7940
7958
  }
7941
7959
  }
7942
- m[T] = o`${_}`.as(T);
7960
+ m[T] = o`${D}`.as(T);
7943
7961
  }
7944
7962
  }
7945
7963
  for (const T in m) {
7946
7964
  const [E, N] = T.split(".");
7947
7965
  if (E === C) {
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);
7966
+ const S = c.get(C), R = S && S.dimensions?.[N], D = T.startsWith(C + ".");
7967
+ if (R || D) {
7968
+ let F = w.joinKeys.find((U) => U.targetColumn === N);
7951
7969
  if (!F && S?.dimensions?.[N]) {
7952
- const k = S.dimensions[N].sql;
7953
- F = $.joinKeys.find((M) => M.targetColumnObj === k);
7970
+ const U = S.dimensions[N].sql;
7971
+ F = w.joinKeys.find((j) => j.targetColumnObj === U);
7954
7972
  }
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));
7973
+ F ? m[T] = o`${o.identifier(w.cteAlias)}.${o.identifier(N)}`.as(T) : D && S?.dimensions?.[N] && (m[T] = o`${o.identifier(w.cteAlias)}.${o.identifier(N)}`.as(T));
7956
7974
  }
7957
7975
  }
7958
7976
  }
7959
7977
  }
7960
7978
  if (t.measures)
7961
- for (const $ of t.measures) {
7962
- const [C, T] = $.split("."), E = c.get(C);
7979
+ for (const w of t.measures) {
7980
+ const [C, T] = w.split("."), E = c.get(C);
7963
7981
  if (E?.measures?.[T]) {
7964
7982
  const N = E.measures[T];
7965
7983
  if (I.isPostAggregationWindow(N)) {
7966
7984
  const S = I.getWindowBaseMeasure(N, C);
7967
7985
  if (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)
7986
+ const [R, D] = S.split("."), F = c.get(R);
7987
+ if (F?.measures?.[D]) {
7988
+ const U = F.measures[D], j = e.preAggregationCTEs?.find(
7989
+ (q) => q.cube?.name === R && q.measures?.includes(S)
7972
7990
  );
7973
- let z;
7974
- if (M) {
7975
- const H = o`${o.identifier(M.cteAlias)}.${o.identifier(_)}`;
7976
- z = o`sum(${H})`;
7991
+ let B;
7992
+ if (j) {
7993
+ const q = o`${o.identifier(j.cteAlias)}.${o.identifier(D)}`;
7994
+ B = o`sum(${q})`;
7977
7995
  } else
7978
- z = this.queryBuilder.buildMeasureExpression(k, n, F);
7979
- m[S] || (m[S] = o`${z}`.as(S));
7980
- const se = this.buildPostAggregationWindowExpression(
7996
+ B = this.queryBuilder.buildMeasureExpression(U, n, F);
7997
+ m[S] || (m[S] = o`${B}`.as(S));
7998
+ const V = this.buildPostAggregationWindowExpression(
7981
7999
  N,
7982
- z,
8000
+ B,
7983
8001
  t,
7984
8002
  n,
7985
8003
  E,
7986
8004
  e
7987
8005
  );
7988
- se && (m[$] = o`${se}`.as($));
8006
+ V && (m[w] = o`${V}`.as(w));
7989
8007
  }
7990
8008
  }
7991
8009
  }
@@ -7994,99 +8012,117 @@ class J {
7994
8012
  const p = [];
7995
8013
  let f = n.db.select(m).from(u.from);
7996
8014
  if (i.length > 0 && (f = n.db.with(...i).select(m).from(u.from)), u.joins)
7997
- for (const $ of u.joins)
7998
- switch ($.type || "left") {
8015
+ for (const w of u.joins)
8016
+ switch (w.type || "left") {
7999
8017
  case "left":
8000
- f = f.leftJoin($.table, $.on);
8018
+ f = f.leftJoin(w.table, w.on);
8001
8019
  break;
8002
8020
  case "inner":
8003
- f = f.innerJoin($.table, $.on);
8021
+ f = f.innerJoin(w.table, w.on);
8004
8022
  break;
8005
8023
  case "right":
8006
- f = f.rightJoin($.table, $.on);
8024
+ f = f.rightJoin(w.table, w.on);
8007
8025
  break;
8008
8026
  case "full":
8009
- f = f.fullJoin($.table, $.on);
8027
+ f = f.fullJoin(w.table, w.on);
8010
8028
  break;
8011
8029
  }
8012
8030
  const h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set();
8013
8031
  if (e.preAggregationCTEs) {
8014
- for (const $ of e.preAggregationCTEs)
8015
- if ($.intermediateJoins && $.intermediateJoins.length > 0)
8016
- for (const C of $.intermediateJoins)
8032
+ for (const w of e.preAggregationCTEs)
8033
+ if (w.intermediateJoins && w.intermediateJoins.length > 0)
8034
+ for (const C of w.intermediateJoins)
8017
8035
  g.add(C.cube.name);
8018
8036
  }
8019
8037
  if (e.joinCubes && e.joinCubes.length > 0)
8020
- for (const $ of e.joinCubes) {
8021
- const C = $.cube.name;
8038
+ for (const w of e.joinCubes) {
8039
+ const C = w.cube.name;
8022
8040
  if (g.has(C) && !r.has(C))
8023
8041
  continue;
8024
- const T = r.get($.cube.name);
8025
- if ($.junctionTable) {
8026
- const F = $.junctionTable, k = [];
8042
+ const T = r.get(w.cube.name);
8043
+ if (w.junctionTable) {
8044
+ const F = w.junctionTable;
8045
+ let U = F.joinCondition;
8046
+ const j = F.sourceCubeName ? r.get(F.sourceCubeName) : void 0;
8047
+ if (j) {
8048
+ const q = e.preAggregationCTEs?.find(
8049
+ (H) => H.cube.name === F.sourceCubeName
8050
+ )?.downstreamJoinKeys?.find(
8051
+ (H) => H.targetCubeName === w.cube.name
8052
+ );
8053
+ if (q && q.joinKeys.length > 0) {
8054
+ const H = [];
8055
+ for (const Oe of q.joinKeys) {
8056
+ const yt = o`${o.identifier(j)}.${o.identifier(Oe.sourceColumn)}`, Ie = Oe.targetColumnObj;
8057
+ Ie && H.push(Q(Ie, yt));
8058
+ }
8059
+ H.length > 0 && (U = _(...H));
8060
+ }
8061
+ }
8062
+ const B = [];
8027
8063
  if (F.securitySql) {
8028
- const M = F.securitySql(n.securityContext);
8029
- Array.isArray(M) ? k.push(...M) : k.push(M);
8064
+ const V = F.securitySql(n.securityContext);
8065
+ Array.isArray(V) ? B.push(...V) : B.push(V);
8030
8066
  }
8031
8067
  try {
8032
8068
  switch (F.joinType || "left") {
8033
8069
  case "left":
8034
- f = f.leftJoin(F.table, F.joinCondition);
8070
+ f = f.leftJoin(F.table, U);
8035
8071
  break;
8036
8072
  case "inner":
8037
- f = f.innerJoin(F.table, F.joinCondition);
8073
+ f = f.innerJoin(F.table, U);
8038
8074
  break;
8039
8075
  case "right":
8040
- f = f.rightJoin(F.table, F.joinCondition);
8076
+ f = f.rightJoin(F.table, U);
8041
8077
  break;
8042
8078
  case "full":
8043
- f = f.fullJoin(F.table, F.joinCondition);
8079
+ f = f.fullJoin(F.table, U);
8044
8080
  break;
8045
8081
  }
8046
- k.length > 0 && p.push(...k);
8082
+ B.length > 0 && p.push(...B);
8047
8083
  } catch {
8048
8084
  }
8049
8085
  }
8050
8086
  let E, N, S;
8051
8087
  if (T)
8052
- E = o`${o.identifier(T)}`, N = this.cteBuilder.buildCTEJoinCondition($, T, e), S = void 0;
8088
+ E = o`${o.identifier(T)}`, N = this.cteBuilder.buildCTEJoinCondition(w, T, e), S = void 0;
8053
8089
  else {
8054
- const F = a.get($.cube.name), k = $.cube.sql(n);
8055
- if (E = k.from, S = k.where, F) {
8056
- const M = [];
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));
8090
+ const F = a.get(w.cube.name), U = w.cube.sql(n);
8091
+ if (E = U.from, S = U.where, F && !w.junctionTable) {
8092
+ const j = [];
8093
+ for (const B of F.joinKeys) {
8094
+ const V = o`${o.identifier(F.cteAlias)}.${o.identifier(B.sourceColumn)}`, q = B.targetColumnObj || o.identifier(B.targetColumn);
8095
+ j.push(Q(V, q));
8060
8096
  }
8061
- N = M.length === 1 ? M[0] : D(...M);
8097
+ N = j.length === 1 ? j[0] : _(...j);
8062
8098
  } else
8063
- N = $.joinCondition;
8099
+ N = w.joinCondition;
8064
8100
  }
8065
- const R = $.joinType || "left", _ = R !== "inner" && S ? D(N, S) : N;
8101
+ const R = w.joinType || "left", D = R !== "inner" && S ? _(N, S) : N;
8066
8102
  try {
8067
8103
  switch (R) {
8068
8104
  case "left":
8069
- f = f.leftJoin(E, _), S && h.add($.cube.name);
8105
+ f = f.leftJoin(E, D), S && h.add(w.cube.name);
8070
8106
  break;
8071
8107
  case "inner":
8072
8108
  f = f.innerJoin(E, N);
8073
8109
  break;
8074
8110
  case "right":
8075
- f = f.rightJoin(E, _), S && h.add($.cube.name);
8111
+ f = f.rightJoin(E, D), S && h.add(w.cube.name);
8076
8112
  break;
8077
8113
  case "full":
8078
- f = f.fullJoin(E, _), S && h.add($.cube.name);
8114
+ f = f.fullJoin(E, D), S && h.add(w.cube.name);
8079
8115
  break;
8080
8116
  }
8081
8117
  } catch {
8082
8118
  }
8083
8119
  }
8084
8120
  if (u.where && p.push(u.where), e.joinCubes && e.joinCubes.length > 0)
8085
- for (const $ of e.joinCubes) {
8086
- const C = $.cube.name;
8121
+ for (const w of e.joinCubes) {
8122
+ const C = w.cube.name;
8087
8123
  if (r.get(C) || g.has(C) || h.has(C))
8088
8124
  continue;
8089
- const E = $.cube.sql(n);
8125
+ const E = w.cube.sql(n);
8090
8126
  E.where && p.push(E.where);
8091
8127
  }
8092
8128
  const y = this.queryBuilder.buildWhereConditions(
@@ -8100,8 +8136,8 @@ class J {
8100
8136
  // Reuse pre-built filters for parameter deduplication
8101
8137
  );
8102
8138
  if (y.length > 0 && p.push(...y), p.length > 0) {
8103
- const $ = p.length === 1 ? p[0] : D(...p);
8104
- f = f.where($);
8139
+ const w = p.length === 1 ? p[0] : _(...p);
8140
+ f = f.where(w);
8105
8141
  }
8106
8142
  const b = this.queryBuilder.buildGroupByFields(
8107
8143
  e.joinCubes.length > 0 ? this.getCubesFromPlan(e) : e.primaryCube,
@@ -8112,7 +8148,7 @@ class J {
8112
8148
  // Pass the queryPlan to handle CTE scenarios
8113
8149
  );
8114
8150
  b.length > 0 && (f = f.groupBy(...b));
8115
- const w = this.queryBuilder.buildHavingConditions(
8151
+ const $ = this.queryBuilder.buildHavingConditions(
8116
8152
  e.joinCubes.length > 0 ? this.getCubesFromPlan(e) : e.primaryCube,
8117
8153
  // Single cube
8118
8154
  t,
@@ -8120,9 +8156,9 @@ class J {
8120
8156
  e
8121
8157
  // Pass the queryPlan to handle CTE scenarios
8122
8158
  );
8123
- if (w.length > 0) {
8124
- const $ = w.length === 1 ? w[0] : D(...w);
8125
- f = f.having($);
8159
+ if ($.length > 0) {
8160
+ const w = $.length === 1 ? $[0] : _(...$);
8161
+ f = f.having(w);
8126
8162
  }
8127
8163
  const A = this.queryBuilder.buildOrderBy(t);
8128
8164
  return A.length > 0 && (f = f.orderBy(...A)), f = this.queryBuilder.applyLimitAndOffset(f, t), f;
@@ -8323,9 +8359,9 @@ class J {
8323
8359
  */
8324
8360
  preloadFilterCache(e, t, n, s) {
8325
8361
  if (e.filters && e.filters.length > 0) {
8326
- const i = ve(e.filters);
8362
+ const i = Re(e.filters);
8327
8363
  for (const r of i) {
8328
- const a = de(r);
8364
+ const a = me(r);
8329
8365
  if (t.has(a)) continue;
8330
8366
  const [u, c] = r.member.split("."), l = n.get(u);
8331
8367
  if (!l) continue;
@@ -8345,7 +8381,7 @@ class J {
8345
8381
  if (e.timeDimensions) {
8346
8382
  for (const i of e.timeDimensions)
8347
8383
  if (i.dateRange) {
8348
- const r = ot(i.dimension, i.dateRange);
8384
+ const r = lt(i.dimension, i.dateRange);
8349
8385
  if (t.has(r)) continue;
8350
8386
  const [a, u] = i.dimension.split("."), c = n.get(a);
8351
8387
  if (!c) continue;
@@ -8383,12 +8419,12 @@ class J {
8383
8419
  const h = f.field.includes(".") ? f.field.split(".")[1] : f.field;
8384
8420
  if (n.timeDimensions)
8385
8421
  for (const b of n.timeDimensions) {
8386
- const [w, A] = b.dimension.split(".");
8422
+ const [$, A] = b.dimension.split(".");
8387
8423
  if (A === h) {
8388
- const $ = u(w, h);
8389
- if ($)
8424
+ const w = u($, h);
8425
+ if (w)
8390
8426
  return {
8391
- field: $,
8427
+ field: w,
8392
8428
  direction: f.direction
8393
8429
  };
8394
8430
  const C = i.dimensions?.[A];
@@ -8425,10 +8461,10 @@ class J {
8425
8461
  else {
8426
8462
  const b = i.name === h ? i : void 0;
8427
8463
  if (b?.dimensions?.[g]) {
8428
- const w = b.dimensions[g];
8464
+ const $ = b.dimensions[g];
8429
8465
  c = [{
8430
8466
  field: this.queryBuilder.buildTimeDimensionExpression(
8431
- w.sql,
8467
+ $.sql,
8432
8468
  f.granularity,
8433
8469
  s
8434
8470
  ),
@@ -8468,7 +8504,7 @@ class J {
8468
8504
  }
8469
8505
  }
8470
8506
  }
8471
- const bn = {
8507
+ const $n = {
8472
8508
  name: "drizzle-cube-mcp-guide",
8473
8509
  description: "How to use drizzle-cube MCP tools to generate and run queries",
8474
8510
  messages: [
@@ -8510,7 +8546,7 @@ const bn = {
8510
8546
  }
8511
8547
  }
8512
8548
  ]
8513
- }, yn = {
8549
+ }, Tn = {
8514
8550
  name: "drizzle-cube-query-rules",
8515
8551
  description: "Key generation rules aligned with Gemini single-step prompt",
8516
8552
  messages: [
@@ -8533,7 +8569,7 @@ const bn = {
8533
8569
  }
8534
8570
  }
8535
8571
  ]
8536
- }, Cn = {
8572
+ }, En = {
8537
8573
  name: "drizzle-cube-query-building",
8538
8574
  description: "CRITICAL: Complete guide for building valid queries of all types with examples",
8539
8575
  messages: [
@@ -8719,7 +8755,7 @@ const bn = {
8719
8755
  }
8720
8756
  }
8721
8757
  ]
8722
- }, wn = {
8758
+ }, Sn = {
8723
8759
  name: "drizzle-cube-date-filtering",
8724
8760
  description: "CRITICAL: How to correctly filter by date vs group by time period - the #1 source of query mistakes",
8725
8761
  messages: [
@@ -8812,22 +8848,22 @@ const bn = {
8812
8848
  }
8813
8849
  }
8814
8850
  ]
8815
- }, $n = [
8816
- bn,
8817
- yn,
8818
- Cn,
8819
- wn
8851
+ }, Nn = [
8852
+ $n,
8853
+ Tn,
8854
+ En,
8855
+ Sn
8820
8856
  ];
8821
- function Tn() {
8822
- return $n;
8857
+ function Dn() {
8858
+ return Nn;
8823
8859
  }
8824
- class lt {
8860
+ class mt {
8825
8861
  cubes = /* @__PURE__ */ new Map();
8826
8862
  dbExecutor;
8827
8863
  metadataCache;
8828
8864
  cacheConfig;
8829
8865
  constructor(e) {
8830
- e?.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e?.drizzle && (this.dbExecutor = Qe(
8866
+ e?.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e?.drizzle && (this.dbExecutor = qe(
8831
8867
  e.drizzle,
8832
8868
  e.schema,
8833
8869
  e.engineType
@@ -8849,7 +8885,7 @@ class lt {
8849
8885
  * Set Drizzle instance and schema directly
8850
8886
  */
8851
8887
  setDrizzle(e, t, n) {
8852
- this.dbExecutor = Qe(e, t, n);
8888
+ this.dbExecutor = qe(e, t, n);
8853
8889
  }
8854
8890
  /**
8855
8891
  * Check if database executor is configured
@@ -8862,7 +8898,7 @@ class lt {
8862
8898
  * Validates calculated measures during registration
8863
8899
  */
8864
8900
  registerCube(e) {
8865
- this.validateCalculatedMeasures(e), new G(this.cubes).populateDependencies(e), this.cubes.set(e.name, e), this.invalidateMetadataCache();
8901
+ this.validateCalculatedMeasures(e), new X(this.cubes).populateDependencies(e), this.cubes.set(e.name, e), this.invalidateMetadataCache();
8866
8902
  }
8867
8903
  /**
8868
8904
  * Validate calculated measures in a cube
@@ -8878,7 +8914,7 @@ class lt {
8878
8914
  );
8879
8915
  continue;
8880
8916
  }
8881
- const i = nn(s.calculatedSql);
8917
+ const i = an(s.calculatedSql);
8882
8918
  if (!i.isValid) {
8883
8919
  t.push(
8884
8920
  `Invalid calculatedSql syntax in '${e.name}.${n}': ${i.errors.join(", ")}`
@@ -8887,7 +8923,7 @@ class lt {
8887
8923
  }
8888
8924
  const r = new Map(this.cubes);
8889
8925
  r.set(e.name, e);
8890
- const a = new G(r);
8926
+ const a = new X(r);
8891
8927
  try {
8892
8928
  a.validateDependencies(e);
8893
8929
  } catch (u) {
@@ -8897,7 +8933,7 @@ class lt {
8897
8933
  if (t.length === 0) {
8898
8934
  const n = new Map(this.cubes);
8899
8935
  n.set(e.name, e);
8900
- const s = new G(n);
8936
+ const s = new X(n);
8901
8937
  s.buildGraph(e);
8902
8938
  const i = s.detectCycle();
8903
8939
  i && t.push(
@@ -8936,7 +8972,7 @@ ${t.join(`
8936
8972
  async execute(e, t, n) {
8937
8973
  if (!this.dbExecutor)
8938
8974
  throw new Error("Database executor not configured");
8939
- return new J(this.dbExecutor, this.cacheConfig).execute(this.cubes, e, t, n);
8975
+ return new Y(this.dbExecutor, this.cacheConfig).execute(this.cubes, e, t, n);
8940
8976
  }
8941
8977
  /**
8942
8978
  * Execute a multi-cube query
@@ -9014,7 +9050,7 @@ ${t.join(`
9014
9050
  for (let c = 0; c < n.length; c++) {
9015
9051
  const l = n[c], m = e.dimensions[l];
9016
9052
  let p;
9017
- m.type === "time" && (p = m.granularities || lt.DEFAULT_TIME_GRANULARITIES), i[c] = {
9053
+ m.type === "time" && (p = m.granularities || mt.DEFAULT_TIME_GRANULARITIES), i[c] = {
9018
9054
  name: `${e.name}.${l}`,
9019
9055
  title: m.title || l,
9020
9056
  shortTitle: m.title || l,
@@ -9072,9 +9108,9 @@ ${t.join(`
9072
9108
  throw new Error(`Cube '${e}' not found`);
9073
9109
  if (!this.dbExecutor)
9074
9110
  throw new Error("Database executor not configured");
9075
- const r = await new J(this.dbExecutor).generateSQL(s, t, n), a = this.dbExecutor.getEngineType();
9111
+ const r = await new Y(this.dbExecutor).generateSQL(s, t, n), a = this.dbExecutor.getEngineType();
9076
9112
  return {
9077
- sql: Z(r.sql, a),
9113
+ sql: te(r.sql, a),
9078
9114
  params: r.params
9079
9115
  };
9080
9116
  }
@@ -9084,9 +9120,9 @@ ${t.join(`
9084
9120
  async generateMultiCubeSQL(e, t) {
9085
9121
  if (!this.dbExecutor)
9086
9122
  throw new Error("Database executor not configured");
9087
- const s = await new J(this.dbExecutor).generateMultiCubeSQL(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9123
+ const s = await new Y(this.dbExecutor).generateMultiCubeSQL(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9088
9124
  return {
9089
- sql: Z(s.sql, i),
9125
+ sql: te(s.sql, i),
9090
9126
  params: s.params
9091
9127
  };
9092
9128
  }
@@ -9097,9 +9133,9 @@ ${t.join(`
9097
9133
  async dryRunFunnel(e, t) {
9098
9134
  if (!this.dbExecutor)
9099
9135
  throw new Error("Database executor not configured");
9100
- const s = await new J(this.dbExecutor).dryRunFunnel(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9136
+ const s = await new Y(this.dbExecutor).dryRunFunnel(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9101
9137
  return {
9102
- sql: Z(s.sql, i),
9138
+ sql: te(s.sql, i),
9103
9139
  params: s.params
9104
9140
  };
9105
9141
  }
@@ -9110,9 +9146,9 @@ ${t.join(`
9110
9146
  async dryRunFlow(e, t) {
9111
9147
  if (!this.dbExecutor)
9112
9148
  throw new Error("Database executor not configured");
9113
- const s = await new J(this.dbExecutor).dryRunFlow(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9149
+ const s = await new Y(this.dbExecutor).dryRunFlow(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9114
9150
  return {
9115
- sql: Z(s.sql, i),
9151
+ sql: te(s.sql, i),
9116
9152
  params: s.params
9117
9153
  };
9118
9154
  }
@@ -9123,9 +9159,9 @@ ${t.join(`
9123
9159
  async dryRunRetention(e, t) {
9124
9160
  if (!this.dbExecutor)
9125
9161
  throw new Error("Database executor not configured");
9126
- const s = await new J(this.dbExecutor).dryRunRetention(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9162
+ const s = await new Y(this.dbExecutor).dryRunRetention(this.cubes, e, t), i = this.dbExecutor.getEngineType();
9127
9163
  return {
9128
- sql: Z(s.sql, i),
9164
+ sql: te(s.sql, i),
9129
9165
  params: s.params
9130
9166
  };
9131
9167
  }
@@ -9137,7 +9173,7 @@ ${t.join(`
9137
9173
  async explainQuery(e, t, n) {
9138
9174
  if (!this.dbExecutor)
9139
9175
  throw new Error("Database executor not configured");
9140
- return new J(this.dbExecutor).explainQuery(this.cubes, e, t, n);
9176
+ return new Y(this.dbExecutor).explainQuery(this.cubes, e, t, n);
9141
9177
  }
9142
9178
  /**
9143
9179
  * Check if a cube exists
@@ -9176,7 +9212,7 @@ ${t.join(`
9176
9212
  * Ensures all referenced cubes and fields exist
9177
9213
  */
9178
9214
  validateQuery(e) {
9179
- return ct(this.cubes, e);
9215
+ return ft(this.cubes, e);
9180
9216
  }
9181
9217
  /**
9182
9218
  * Analyze query planning decisions for debugging and transparency
@@ -9186,7 +9222,7 @@ ${t.join(`
9186
9222
  analyzeQuery(e, t) {
9187
9223
  if (!this.dbExecutor)
9188
9224
  throw new Error("Database executor not configured");
9189
- const n = new at(), s = {
9225
+ const n = new ct(), s = {
9190
9226
  db: this.dbExecutor.db,
9191
9227
  schema: this.dbExecutor.schema,
9192
9228
  securityContext: t
@@ -9194,7 +9230,7 @@ ${t.join(`
9194
9230
  return n.analyzeQueryPlan(this.cubes, e, s);
9195
9231
  }
9196
9232
  }
9197
- function ct(d, e) {
9233
+ function ft(d, e) {
9198
9234
  const t = [];
9199
9235
  if (e.funnel !== void 0 && e.funnel.steps?.length >= 2) {
9200
9236
  const s = e.funnel.bindingKey;
@@ -9215,7 +9251,7 @@ function ct(d, e) {
9215
9251
  return { isValid: t.length === 0, errors: t };
9216
9252
  }
9217
9253
  if (e.retention !== void 0 && e.retention.timeDimension != null && e.retention.bindingKey != null) {
9218
- const s = En(e.retention.timeDimension);
9254
+ const s = An(e.retention.timeDimension);
9219
9255
  s && !d.has(s) && t.push(`Retention cube not found: ${s}`);
9220
9256
  const i = e.retention.bindingKey;
9221
9257
  if (typeof i == "string") {
@@ -9279,17 +9315,17 @@ function ct(d, e) {
9279
9315
  }
9280
9316
  if (e.filters)
9281
9317
  for (const s of e.filters)
9282
- dt(s, d, t, n);
9318
+ pt(s, d, t, n);
9283
9319
  return n.size === 0 && t.push("Query must reference at least one cube through measures, dimensions, or filters"), {
9284
9320
  isValid: t.length === 0,
9285
9321
  errors: t
9286
9322
  };
9287
9323
  }
9288
- function dt(d, e, t, n) {
9324
+ function pt(d, e, t, n) {
9289
9325
  if ("and" in d || "or" in d) {
9290
9326
  const a = d.and || d.or || [];
9291
9327
  for (const u of a)
9292
- dt(u, e, t, n);
9328
+ pt(u, e, t, n);
9293
9329
  return;
9294
9330
  }
9295
9331
  if (!("member" in d)) {
@@ -9309,34 +9345,34 @@ function dt(d, e, t, n) {
9309
9345
  }
9310
9346
  !r.dimensions[i] && !r.measures[i] && t.push(`Filter field '${i}' not found on cube '${s}' (must be a dimension or measure)`);
9311
9347
  }
9312
- function En(d) {
9348
+ function An(d) {
9313
9349
  if (typeof d == "string") {
9314
9350
  const [e] = d.split(".");
9315
9351
  return e || null;
9316
9352
  }
9317
9353
  return d.cube;
9318
9354
  }
9319
- const ae = ["2025-11-25", "2025-06-18", "2025-03-26"], mt = "2025-11-25";
9320
- function vn(d) {
9321
- const t = Sn(d["mcp-protocol-version"]) || mt;
9355
+ const ue = ["2025-11-25", "2025-06-18", "2025-03-26"], ht = "2025-11-25";
9356
+ function In(d) {
9357
+ const t = _n(d["mcp-protocol-version"]) || ht;
9322
9358
  return {
9323
- ok: ae.includes(t),
9324
- negotiated: ae.includes(t) ? t : null,
9325
- supported: ae
9359
+ ok: ue.includes(t),
9360
+ negotiated: ue.includes(t) ? t : null,
9361
+ supported: ue
9326
9362
  };
9327
9363
  }
9328
- function Rn(d) {
9364
+ function Ln(d) {
9329
9365
  if (!d) return !1;
9330
9366
  const e = d.split(",").map((s) => s.trim().toLowerCase()), t = e.includes("text/event-stream"), n = e.includes("application/json");
9331
9367
  return t && !n;
9332
9368
  }
9333
- const Fn = "mcp-session-id";
9334
- function On(d) {
9369
+ const Mn = "mcp-session-id";
9370
+ function jn(d) {
9335
9371
  if (!d) return !1;
9336
9372
  const e = d.split(",").map((s) => s.trim().toLowerCase().split(";")[0]), t = e.some((s) => s === "application/json"), n = e.some((s) => s === "text/event-stream");
9337
9373
  return t && n;
9338
9374
  }
9339
- function In(d, e = {}) {
9375
+ function Un(d, e = {}) {
9340
9376
  const { allowMissingOrigin: t = !0, allowedOrigins: n } = e;
9341
9377
  if (!d)
9342
9378
  return t ? { valid: !0 } : { valid: !1, reason: "Origin header is required" };
@@ -9356,26 +9392,26 @@ function In(d, e = {}) {
9356
9392
  }
9357
9393
  }).includes(s.origin) ? { valid: !0 } : { valid: !1, reason: "Origin not in allowed list" };
9358
9394
  }
9359
- function Ln(d, e, t) {
9395
+ function xn(d, e, t) {
9360
9396
  const n = [];
9361
9397
  return e && n.push(`id: ${e}`), t && t > 0 && n.push(`retry: ${t}`), n.push("event: message"), n.push(`data: ${JSON.stringify(d)}`), n.push(""), n.join(`
9362
9398
  `);
9363
9399
  }
9364
- function Mn(d, e, t, n) {
9400
+ function kn(d, e, t, n) {
9365
9401
  return {
9366
9402
  jsonrpc: "2.0",
9367
9403
  id: d ?? null,
9368
9404
  error: { code: e, message: t, ...n !== void 0 ? { data: n } : {} }
9369
9405
  };
9370
9406
  }
9371
- function jn(d, e) {
9407
+ function Bn(d, e) {
9372
9408
  return {
9373
9409
  jsonrpc: "2.0",
9374
9410
  id: d ?? null,
9375
9411
  result: e
9376
9412
  };
9377
9413
  }
9378
- function Un(d) {
9414
+ function Pn(d) {
9379
9415
  if (!d || typeof d != "object") return null;
9380
9416
  const e = d;
9381
9417
  return e.jsonrpc !== "2.0" || typeof e.method != "string" ? null : {
@@ -9385,13 +9421,13 @@ function Un(d) {
9385
9421
  params: e.params
9386
9422
  };
9387
9423
  }
9388
- async function kn(d, e, t) {
9389
- const { semanticLayer: n, extractSecurityContext: s, rawRequest: i, rawResponse: r } = t, a = t.prompts ?? ft, u = t.resources ?? pt;
9424
+ async function Qn(d, e, t) {
9425
+ const { semanticLayer: n, extractSecurityContext: s, rawRequest: i, rawResponse: r } = t, a = t.prompts ?? gt, u = t.resources ?? bt;
9390
9426
  switch (d) {
9391
9427
  case "initialize": {
9392
9428
  const c = e?.protocolVersion;
9393
9429
  let l;
9394
- return c && ae.includes(c) ? l = c : l = mt, {
9430
+ return c && ue.includes(c) ? l = c : l = ht, {
9395
9431
  protocolVersion: l,
9396
9432
  capabilities: {
9397
9433
  tools: {
@@ -9405,7 +9441,7 @@ async function kn(d, e, t) {
9405
9441
  },
9406
9442
  sampling: {}
9407
9443
  },
9408
- sessionId: Nn(),
9444
+ sessionId: vn(),
9409
9445
  serverInfo: {
9410
9446
  name: "drizzle-cube",
9411
9447
  // Use safe check for process.env to support edge runtimes (Cloudflare Workers, etc.)
@@ -9415,10 +9451,10 @@ async function kn(d, e, t) {
9415
9451
  }
9416
9452
  case "list_tools":
9417
9453
  case "tools/list":
9418
- return { tools: Dn(), nextCursor: "" };
9454
+ return { tools: Rn(), nextCursor: "" };
9419
9455
  case "call_tool":
9420
9456
  case "tools/call":
9421
- return An(e, t);
9457
+ return Fn(e, t);
9422
9458
  case "resources/list":
9423
9459
  return {
9424
9460
  resources: u.map(({ uri: c, name: l, description: m, mimeType: p }) => ({
@@ -9433,7 +9469,7 @@ async function kn(d, e, t) {
9433
9469
  return { resourceTemplates: [], nextCursor: "" };
9434
9470
  case "resources/read": {
9435
9471
  const c = e?.uri, l = u.find((m) => m.uri === c) || u[0];
9436
- if (!l) throw q(-32602, "resource not found");
9472
+ if (!l) throw J(-32602, "resource not found");
9437
9473
  return {
9438
9474
  contents: [
9439
9475
  {
@@ -9456,7 +9492,7 @@ async function kn(d, e, t) {
9456
9492
  return {};
9457
9493
  case "prompts/get": {
9458
9494
  const c = e?.name, l = a.find((m) => m.name === c) || a[0];
9459
- if (!l) throw q(-32602, "prompt not found");
9495
+ if (!l) throw J(-32602, "prompt not found");
9460
9496
  return {
9461
9497
  name: l.name,
9462
9498
  description: l.description,
@@ -9464,38 +9500,38 @@ async function kn(d, e, t) {
9464
9500
  };
9465
9501
  }
9466
9502
  case "discover":
9467
- return Xe(n, e || {});
9503
+ return tt(n, e || {});
9468
9504
  case "validate": {
9469
9505
  const c = e || {};
9470
9506
  if (!c.query)
9471
- throw q(-32602, "query is required");
9472
- return Ye(n, c);
9507
+ throw J(-32602, "query is required");
9508
+ return et(n, c);
9473
9509
  }
9474
9510
  case "load": {
9475
9511
  const c = e || {};
9476
9512
  if (!c.query)
9477
- throw q(-32602, "query is required");
9513
+ throw J(-32602, "query is required");
9478
9514
  const l = await s(i, r);
9479
- return He(n, l, c);
9515
+ return Ze(n, l, c);
9480
9516
  }
9481
9517
  default:
9482
- throw q(-32601, `Unknown MCP method: ${d}`);
9518
+ throw J(-32601, `Unknown MCP method: ${d}`);
9483
9519
  }
9484
9520
  }
9485
- function q(d, e, t) {
9521
+ function J(d, e, t) {
9486
9522
  const n = new Error(e);
9487
9523
  return n.code = d, n;
9488
9524
  }
9489
- function Sn(d) {
9525
+ function _n(d) {
9490
9526
  return d ? Array.isArray(d) ? d[0] || null : d : null;
9491
9527
  }
9492
- function xn(d) {
9528
+ function Wn(d) {
9493
9529
  return d.id === void 0 || d.id === null;
9494
9530
  }
9495
- function Nn() {
9496
- return `evt-${ht()}`;
9531
+ function vn() {
9532
+ return `evt-${Ct()}`;
9497
9533
  }
9498
- function Dn() {
9534
+ function Rn() {
9499
9535
  return [
9500
9536
  {
9501
9537
  name: "discover",
@@ -9594,30 +9630,30 @@ QUERY CONSTRUCTION RULES:
9594
9630
  }
9595
9631
  ];
9596
9632
  }
9597
- async function An(d, e) {
9633
+ async function Fn(d, e) {
9598
9634
  const { semanticLayer: t, extractSecurityContext: n, rawRequest: s, rawResponse: i } = e, r = d || {};
9599
9635
  if (!r.name)
9600
- throw q(-32602, "name is required for tools/call");
9636
+ throw J(-32602, "name is required for tools/call");
9601
9637
  const a = r.arguments;
9602
9638
  switch (r.name) {
9603
9639
  case "discover":
9604
- return Se(await Xe(t, a || {}));
9640
+ return Ne(await tt(t, a || {}));
9605
9641
  case "validate": {
9606
9642
  const u = a || {};
9607
- if (!u.query) throw q(-32602, "query is required");
9608
- return Se(await Ye(t, u));
9643
+ if (!u.query) throw J(-32602, "query is required");
9644
+ return Ne(await et(t, u));
9609
9645
  }
9610
9646
  case "load": {
9611
9647
  const u = a || {};
9612
- if (!u.query) throw q(-32602, "query is required");
9648
+ if (!u.query) throw J(-32602, "query is required");
9613
9649
  const c = await n(s, i);
9614
- return Se(await He(t, c, u));
9650
+ return Ne(await Ze(t, c, u));
9615
9651
  }
9616
9652
  default:
9617
- throw q(-32601, `Unknown tool: ${r.name}`);
9653
+ throw J(-32601, `Unknown tool: ${r.name}`);
9618
9654
  }
9619
9655
  }
9620
- function Se(d) {
9656
+ function Ne(d) {
9621
9657
  return {
9622
9658
  content: [
9623
9659
  {
@@ -9628,7 +9664,7 @@ function Se(d) {
9628
9664
  isError: !1
9629
9665
  };
9630
9666
  }
9631
- const ft = Tn(), pt = [
9667
+ const gt = Dn(), bt = [
9632
9668
  {
9633
9669
  uri: "drizzle-cube://quickstart",
9634
9670
  name: "Drizzle Cube MCP Quickstart",
@@ -9734,26 +9770,26 @@ const ft = Tn(), pt = [
9734
9770
  `)
9735
9771
  }
9736
9772
  ];
9737
- function Bn() {
9738
- return pt;
9773
+ function Kn() {
9774
+ return bt;
9739
9775
  }
9740
- function Pn() {
9741
- return ft;
9776
+ function qn() {
9777
+ return gt;
9742
9778
  }
9743
9779
  export {
9744
- Fn as M,
9745
- lt as S,
9746
- On as a,
9747
- Mn as b,
9748
- jn as c,
9749
- kn as d,
9750
- Nn as e,
9751
- Bn as f,
9752
- Pn as g,
9753
- xn as i,
9754
- vn as n,
9755
- Un as p,
9756
- Ln as s,
9757
- In as v,
9758
- Rn as w
9780
+ Mn as M,
9781
+ mt as S,
9782
+ jn as a,
9783
+ kn as b,
9784
+ Bn as c,
9785
+ Qn as d,
9786
+ vn as e,
9787
+ Kn as f,
9788
+ qn as g,
9789
+ Wn as i,
9790
+ In as n,
9791
+ Pn as p,
9792
+ xn as s,
9793
+ Un as v,
9794
+ Ln as w
9759
9795
  };