drizzle-cube 0.1.8 → 0.1.9

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,34 +1,34 @@
1
- var z = Object.defineProperty;
2
- var U = (s, e, t) => e in s ? z(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var C = (s, e, t) => U(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { sql as f, and as p, eq as v, count as y, max as B, min as O, avg as R, sum as I, countDistinct as Y, or as J, gt as A, lt as F, gte as w, lte as N, isNull as W, isNotNull as K, notInArray as H, ne as V, inArray as Z } from "drizzle-orm";
1
+ var O = Object.defineProperty;
2
+ var B = (o, e, t) => e in o ? O(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
+ var D = (o, e, t) => B(o, typeof e != "symbol" ? e + "" : e, t);
4
+ import { sql as f, and as h, or as j, gt as E, lt as $, gte as C, lte as w, isNull as L, isNotNull as z, eq as v, count as T, max as R, min as Y, avg as W, sum as J, countDistinct as K, notInArray as H, ne as V, inArray as Z } from "drizzle-orm";
5
5
  import { parse as G, stringify as P } from "yaml";
6
- function we(s, e) {
6
+ function we(o, e) {
7
7
  return {
8
8
  ...e,
9
9
  name: e.name
10
10
  };
11
11
  }
12
- class x {
12
+ class A {
13
13
  constructor(e, t) {
14
14
  this.db = e, this.schema = t;
15
15
  }
16
16
  }
17
- class X extends x {
17
+ class X extends A {
18
18
  async execute(e, t) {
19
19
  if (e && typeof e == "object") {
20
20
  if (typeof e.execute == "function") {
21
21
  const n = await e.execute();
22
- return Array.isArray(n) ? n.map((o) => this.convertNumericFields(o, t)) : n;
22
+ return Array.isArray(n) ? n.map((r) => this.convertNumericFields(r, t)) : n;
23
23
  }
24
24
  if (this.db && typeof this.db.execute == "function")
25
25
  try {
26
26
  const n = await this.db.execute(e);
27
- return Array.isArray(n) ? n.map((o) => this.convertNumericFields(o, t)) : n;
27
+ return Array.isArray(n) ? n.map((r) => this.convertNumericFields(r, t)) : n;
28
28
  } catch (n) {
29
29
  if (typeof e.getSQL == "function") {
30
- const o = e.getSQL(), a = await this.db.execute(o);
31
- return Array.isArray(a) ? a.map((r) => this.convertNumericFields(r, t)) : a;
30
+ const r = e.getSQL(), a = await this.db.execute(r);
31
+ return Array.isArray(a) ? a.map((s) => this.convertNumericFields(s, t)) : a;
32
32
  }
33
33
  throw n;
34
34
  }
@@ -44,8 +44,8 @@ class X extends x {
44
44
  convertNumericFields(e, t) {
45
45
  if (!e || typeof e != "object") return e;
46
46
  const i = {};
47
- for (const [n, o] of Object.entries(e))
48
- t && t.includes(n) ? i[n] = this.coerceToNumber(o) : i[n] = o;
47
+ for (const [n, r] of Object.entries(e))
48
+ t && t.includes(n) ? i[n] = this.coerceToNumber(r) : i[n] = r;
49
49
  return i;
50
50
  }
51
51
  /**
@@ -79,7 +79,7 @@ class X extends x {
79
79
  return "postgres";
80
80
  }
81
81
  }
82
- class q extends x {
82
+ class q extends A {
83
83
  async execute(e, t) {
84
84
  if (e && typeof e == "object" && typeof e.execute == "function") {
85
85
  const i = await e.execute();
@@ -104,8 +104,8 @@ class q extends x {
104
104
  convertNumericFields(e, t) {
105
105
  if (!e || typeof e != "object") return e;
106
106
  const i = {};
107
- for (const [n, o] of Object.entries(e))
108
- t && t.includes(n) ? i[n] = this.coerceToNumber(o) : i[n] = o;
107
+ for (const [n, r] of Object.entries(e))
108
+ t && t.includes(n) ? i[n] = this.coerceToNumber(r) : i[n] = r;
109
109
  return i;
110
110
  }
111
111
  /**
@@ -125,11 +125,11 @@ class q extends x {
125
125
  return "sqlite";
126
126
  }
127
127
  }
128
- class ee extends x {
128
+ class ee extends A {
129
129
  async execute(e, t) {
130
130
  if (e && typeof e == "object" && typeof e.execute == "function") {
131
131
  const n = await e.execute();
132
- return Array.isArray(n) ? n.map((o) => this.convertNumericFields(o, t)) : n;
132
+ return Array.isArray(n) ? n.map((r) => this.convertNumericFields(r, t)) : n;
133
133
  }
134
134
  if (!this.db.execute)
135
135
  throw new Error("MySQL database instance must have an execute method");
@@ -142,8 +142,8 @@ class ee extends x {
142
142
  convertNumericFields(e, t) {
143
143
  if (!e || typeof e != "object") return e;
144
144
  const i = {};
145
- for (const [n, o] of Object.entries(e))
146
- t && t.includes(n) ? i[n] = this.coerceToNumber(o) : i[n] = o;
145
+ for (const [n, r] of Object.entries(e))
146
+ t && t.includes(n) ? i[n] = this.coerceToNumber(r) : i[n] = r;
147
147
  return i;
148
148
  }
149
149
  /**
@@ -163,43 +163,43 @@ class ee extends x {
163
163
  return "mysql";
164
164
  }
165
165
  }
166
- function S(s, e) {
167
- return new X(s, e);
166
+ function S(o, e) {
167
+ return new X(o, e);
168
168
  }
169
- function M(s, e) {
170
- return new q(s, e);
169
+ function M(o, e) {
170
+ return new q(o, e);
171
171
  }
172
- function te(s, e) {
173
- return new ee(s, e);
172
+ function te(o, e) {
173
+ return new ee(o, e);
174
174
  }
175
- function _(s, e, t) {
175
+ function _(o, e, t) {
176
176
  if (t)
177
177
  switch (t) {
178
178
  case "postgres":
179
- return S(s, e);
179
+ return S(o, e);
180
180
  case "mysql":
181
- return te(s, e);
181
+ return te(o, e);
182
182
  case "sqlite":
183
- return M(s, e);
183
+ return M(o, e);
184
184
  }
185
- if (s.all && s.run)
186
- return M(s, e);
187
- if (s.execute)
188
- return S(s, e);
185
+ if (o.all && o.run)
186
+ return M(o, e);
187
+ if (o.execute)
188
+ return S(o, e);
189
189
  throw new Error("Unable to determine database engine type. Please specify engineType parameter.");
190
190
  }
191
- function Ne(s, e) {
191
+ function De(o, e) {
192
192
  return {
193
- name: s,
193
+ name: o,
194
194
  ...e
195
195
  };
196
196
  }
197
- function b(s, e) {
198
- return typeof s == "function" ? s(e) : s;
197
+ function b(o, e) {
198
+ return typeof o == "function" ? o(e) : o;
199
199
  }
200
- function ne(s, e, t) {
200
+ function ne(o, e, t) {
201
201
  return {
202
- ...s,
202
+ ...o,
203
203
  cubes: e,
204
204
  currentCube: t
205
205
  };
@@ -231,15 +231,15 @@ class ie {
231
231
  * Build a multi-cube query plan
232
232
  */
233
233
  buildMultiCubeQueryPlan(e, t, i) {
234
- const n = this.analyzeCubeUsage(t), o = Array.from(n);
235
- if (o.length === 1)
234
+ const n = this.analyzeCubeUsage(t), r = Array.from(n);
235
+ if (r.length === 1)
236
236
  throw new Error("Single cube query should use QueryExecutor directly");
237
- const a = this.choosePrimaryCube(o, t), r = e.get(a);
238
- if (!r)
237
+ const a = this.choosePrimaryCube(r, t), s = e.get(a);
238
+ if (!s)
239
239
  throw new Error(`Primary cube '${a}' not found`);
240
- const c = this.buildJoinPlan(e, r, o, i.securityContext), l = this.buildMultiCubeSelections(e, t, i.securityContext), u = this.buildMultiCubeWhereConditions(e, t, i), m = this.buildMultiCubeGroupByFields(e, t, i.securityContext);
240
+ const c = this.buildJoinPlan(e, s, r, i.securityContext), l = this.buildMultiCubeSelections(e, t, i.securityContext), u = this.buildMultiCubeWhereConditions(e, t, i), m = this.buildMultiCubeGroupByFields(e, t, i.securityContext);
241
241
  return {
242
- primaryCube: r,
242
+ primaryCube: s,
243
243
  joinCubes: c,
244
244
  selections: l,
245
245
  whereConditions: u,
@@ -264,13 +264,13 @@ class ie {
264
264
  * Build join plan for multi-cube query
265
265
  */
266
266
  buildJoinPlan(e, t, i, n) {
267
- var r;
268
- const o = [], a = i.filter((c) => c !== t.name);
267
+ var s;
268
+ const r = [], a = i.filter((c) => c !== t.name);
269
269
  for (const c of a) {
270
270
  const l = e.get(c);
271
271
  if (!l)
272
272
  throw new Error(`Cube '${c}' not found`);
273
- const u = (r = t.joins) == null ? void 0 : r[c];
273
+ const u = (s = t.joins) == null ? void 0 : s[c];
274
274
  if (!u)
275
275
  throw new Error(`No join definition found from '${t.name}' to '${c}'`);
276
276
  const m = ne(
@@ -284,20 +284,20 @@ class ie {
284
284
  e,
285
285
  l
286
286
  ), d = u.condition(m);
287
- o.push({
287
+ r.push({
288
288
  cube: l,
289
289
  alias: `${c.toLowerCase()}_cube`,
290
290
  joinType: u.type || "left",
291
291
  joinCondition: d
292
292
  });
293
293
  }
294
- return o;
294
+ return r;
295
295
  }
296
296
  /**
297
297
  * Build selections across multiple cubes
298
298
  */
299
299
  buildMultiCubeSelections(e, t, i) {
300
- const n = {}, o = {
300
+ const n = {}, r = {
301
301
  db: {},
302
302
  // Filled during execution
303
303
  schema: {},
@@ -306,28 +306,28 @@ class ie {
306
306
  };
307
307
  if (t.dimensions)
308
308
  for (const a of t.dimensions) {
309
- const [r, c] = a.split("."), l = e.get(r);
309
+ const [s, c] = a.split("."), l = e.get(s);
310
310
  if (l && l.dimensions[c]) {
311
- const u = l.dimensions[c], m = b(u.sql, o);
311
+ const u = l.dimensions[c], m = b(u.sql, r);
312
312
  n[a] = f`${m}`.as(a);
313
313
  }
314
314
  }
315
315
  if (t.measures)
316
316
  for (const a of t.measures) {
317
- const [r, c] = a.split("."), l = e.get(r);
317
+ const [s, c] = a.split("."), l = e.get(s);
318
318
  if (l && l.measures[c]) {
319
- const u = l.measures[c], m = this.buildMeasureExpression(u, o);
319
+ const u = l.measures[c], m = this.buildMeasureExpression(u, r);
320
320
  n[a] = f`${m}`.as(a);
321
321
  }
322
322
  }
323
323
  if (t.timeDimensions)
324
324
  for (const a of t.timeDimensions) {
325
- const [r, c] = a.dimension.split("."), l = e.get(r);
325
+ const [s, c] = a.dimension.split("."), l = e.get(s);
326
326
  if (l && l.dimensions[c]) {
327
327
  const u = l.dimensions[c], m = this.buildTimeDimensionExpression(
328
328
  u.sql,
329
329
  a.granularity,
330
- o
330
+ r
331
331
  );
332
332
  n[a.dimension] = f`${m}`.as(a.dimension);
333
333
  }
@@ -340,8 +340,8 @@ class ie {
340
340
  buildMeasureExpression(e, t) {
341
341
  let i = b(e.sql, t);
342
342
  if (e.filters && e.filters.length > 0) {
343
- const n = e.filters.map((o) => o(t));
344
- i = f`CASE WHEN ${p(...n)} THEN ${i} END`;
343
+ const n = e.filters.map((r) => r(t));
344
+ i = f`CASE WHEN ${h(...n)} THEN ${i} END`;
345
345
  }
346
346
  switch (e.type) {
347
347
  case "count":
@@ -395,31 +395,158 @@ class ie {
395
395
  */
396
396
  buildMultiCubeWhereConditions(e, t, i) {
397
397
  const n = [];
398
- if (t.filters) {
399
- for (const o of t.filters)
400
- if ("member" in o) {
401
- const [a] = o.member.split("."), r = e.get(a);
402
- if (r) {
403
- const c = this.buildFilterCondition(o, r, i);
404
- c && n.push(c);
398
+ if (t.filters)
399
+ for (const r of t.filters) {
400
+ const a = this.processMultiCubeFilter(r, e, i);
401
+ a && n.push(a);
402
+ }
403
+ if (t.timeDimensions) {
404
+ for (const r of t.timeDimensions)
405
+ if (r.dateRange) {
406
+ const [a, s] = r.dimension.split("."), c = e.get(a);
407
+ if (c && c.dimensions[s]) {
408
+ const l = c.dimensions[s], u = b(l.sql, i), m = this.buildDateRangeCondition(u, r.dateRange);
409
+ m && n.push(m);
405
410
  }
406
411
  }
407
412
  }
408
413
  return n;
409
414
  }
410
415
  /**
411
- * Filter condition builder (would reuse logic from DrizzleExecutor)
416
+ * Process a single filter for multi-cube queries (handles logical and simple filters)
417
+ */
418
+ processMultiCubeFilter(e, t, i) {
419
+ if ("and" in e || "or" in e) {
420
+ if (e.and) {
421
+ const n = e.and.map((r) => this.processMultiCubeFilter(r, t, i)).filter((r) => r !== null);
422
+ return n.length > 0 ? h(...n) : null;
423
+ }
424
+ if (e.or) {
425
+ const n = e.or.map((r) => this.processMultiCubeFilter(r, t, i)).filter((r) => r !== null);
426
+ return n.length > 0 ? j(...n) : null;
427
+ }
428
+ }
429
+ if ("member" in e) {
430
+ const [n] = e.member.split("."), r = t.get(n);
431
+ if (r)
432
+ return this.buildFilterCondition(e, r, i);
433
+ }
434
+ return null;
435
+ }
436
+ /**
437
+ * Filter condition builder with comprehensive operator support
412
438
  */
413
439
  buildFilterCondition(e, t, i) {
414
- if (e.operator === "equals" && e.values && e.values.length > 0) {
415
- const [n, o] = e.member.split(".");
416
- if (n === t.name) {
417
- const a = t.dimensions[o] || t.measures[o];
418
- if (a) {
419
- const r = typeof a.sql == "function" ? a.sql(i) : a.sql;
420
- return v(r, e.values[0]);
440
+ if (!e.member || !e.operator)
441
+ return null;
442
+ const [n, r] = e.member.split(".");
443
+ if (n !== t.name)
444
+ return null;
445
+ const a = t.dimensions[r] || t.measures[r];
446
+ if (!a)
447
+ return null;
448
+ const s = b(a.sql, i), l = (e.values || []).filter((m) => m != null);
449
+ if (l.length === 0 && !["set", "notSet"].includes(e.operator))
450
+ return null;
451
+ const u = l[0];
452
+ switch (e.operator) {
453
+ case "equals":
454
+ if (l.length === 0)
455
+ return f`1 = 0`;
456
+ if (l.length === 1) {
457
+ const m = a.type === "time" && this.normalizeDate(u) || u;
458
+ return v(s, m);
459
+ } else if (a.type === "time") {
460
+ const m = l.map((d) => this.normalizeDate(d) || d);
461
+ return f`${s} IN (${f.join(m.map((d) => f`${d}`), f`, `)})`;
462
+ } else
463
+ return f`${s} IN (${f.join(l.map((m) => f`${m}`), f`, `)})`;
464
+ case "notEquals":
465
+ return l.length === 1 ? f`${s} <> ${u}` : l.length > 1 ? f`${s} NOT IN (${f.join(l.map((m) => f`${m}`), f`, `)})` : null;
466
+ case "contains":
467
+ return f`${s} ILIKE ${"%" + u + "%"}`;
468
+ case "notContains":
469
+ return f`${s} NOT ILIKE ${"%" + u + "%"}`;
470
+ case "startsWith":
471
+ return f`${s} ILIKE ${u + "%"}`;
472
+ case "endsWith":
473
+ return f`${s} ILIKE ${"%" + u}`;
474
+ case "gt":
475
+ return E(s, u);
476
+ case "gte":
477
+ return C(s, u);
478
+ case "lt":
479
+ return $(s, u);
480
+ case "lte":
481
+ return w(s, u);
482
+ case "set":
483
+ return z(s);
484
+ case "notSet":
485
+ return L(s);
486
+ case "inDateRange":
487
+ if (l.length >= 2) {
488
+ const m = this.normalizeDate(l[0]), d = this.normalizeDate(l[1]);
489
+ if (m && d)
490
+ return h(
491
+ C(s, m),
492
+ w(s, d)
493
+ );
421
494
  }
495
+ return null;
496
+ case "beforeDate": {
497
+ const m = this.normalizeDate(u);
498
+ return m ? $(s, m) : null;
499
+ }
500
+ case "afterDate": {
501
+ const m = this.normalizeDate(u);
502
+ return m ? E(s, m) : null;
422
503
  }
504
+ default:
505
+ return null;
506
+ }
507
+ }
508
+ /**
509
+ * Build date range condition for time dimensions
510
+ */
511
+ buildDateRangeCondition(e, t) {
512
+ if (!t) return null;
513
+ if (Array.isArray(t) && t.length >= 2) {
514
+ const i = this.normalizeDate(t[0]), n = this.normalizeDate(t[1]);
515
+ return !i || !n ? null : h(
516
+ C(e, i),
517
+ w(e, n)
518
+ );
519
+ }
520
+ if (typeof t == "string") {
521
+ const i = this.normalizeDate(t);
522
+ if (!i) return null;
523
+ const n = new Date(i);
524
+ n.setUTCHours(0, 0, 0, 0);
525
+ const r = new Date(i);
526
+ return r.setUTCHours(23, 59, 59, 999), h(
527
+ C(e, n),
528
+ w(e, r)
529
+ );
530
+ }
531
+ return null;
532
+ }
533
+ /**
534
+ * Normalize date values to handle both string and Date objects
535
+ * For PostgreSQL timestamp fields, Drizzle expects Date objects
536
+ */
537
+ normalizeDate(e) {
538
+ if (!e) return null;
539
+ if (e instanceof Date)
540
+ return isNaN(e.getTime()) ? null : e;
541
+ if (typeof e == "string") {
542
+ const t = new Date(e);
543
+ return isNaN(t.getTime()) ? null : t;
544
+ }
545
+ try {
546
+ const t = new Date(e);
547
+ if (!isNaN(t.getTime()))
548
+ return t;
549
+ } catch {
423
550
  }
424
551
  return null;
425
552
  }
@@ -436,20 +563,20 @@ class ie {
436
563
  securityContext: i
437
564
  };
438
565
  if (t.dimensions)
439
- for (const r of t.dimensions) {
440
- const [c, l] = r.split("."), u = e.get(c);
566
+ for (const s of t.dimensions) {
567
+ const [c, l] = s.split("."), u = e.get(c);
441
568
  if (u && u.dimensions[l]) {
442
569
  const m = u.dimensions[l], d = b(m.sql, a);
443
570
  n.push(d);
444
571
  }
445
572
  }
446
573
  if (t.timeDimensions)
447
- for (const r of t.timeDimensions) {
448
- const [c, l] = r.dimension.split("."), u = e.get(c);
574
+ for (const s of t.timeDimensions) {
575
+ const [c, l] = s.dimension.split("."), u = e.get(c);
449
576
  if (u && u.dimensions[l]) {
450
577
  const m = u.dimensions[l], d = this.buildTimeDimensionExpression(
451
578
  m.sql,
452
- r.granularity,
579
+ s.granularity,
453
580
  a
454
581
  );
455
582
  n.push(d);
@@ -458,9 +585,9 @@ class ie {
458
585
  return n;
459
586
  }
460
587
  }
461
- class $ {
588
+ class x {
462
589
  constructor(e) {
463
- C(this, "multiCubeBuilder");
590
+ D(this, "multiCubeBuilder");
464
591
  this.dbExecutor = e, this.multiCubeBuilder = new ie();
465
592
  }
466
593
  /**
@@ -468,17 +595,17 @@ class $ {
468
595
  */
469
596
  async execute(e, t, i) {
470
597
  try {
471
- const n = j(e, t);
598
+ const n = Q(e, t);
472
599
  if (!n.isValid)
473
600
  throw new Error(`Query validation failed: ${n.errors.join(", ")}`);
474
- const o = this.multiCubeBuilder.analyzeCubeUsage(t);
475
- if (o.size === 0)
601
+ const r = this.multiCubeBuilder.analyzeCubeUsage(t);
602
+ if (r.size === 0)
476
603
  throw new Error("No cubes found for query");
477
- if (o.size === 1) {
478
- const a = Array.from(o)[0], r = e.get(a);
479
- if (!r)
604
+ if (r.size === 1) {
605
+ const a = Array.from(r)[0], s = e.get(a);
606
+ if (!s)
480
607
  throw new Error(`Cube '${a}' not found`);
481
- return this.executeSingleCube(r, t, i);
608
+ return this.executeSingleCube(s, t, i);
482
609
  } else
483
610
  return this.executeMultiCube(e, t, i);
484
611
  } catch (n) {
@@ -507,57 +634,57 @@ class $ {
507
634
  db: this.dbExecutor.db,
508
635
  schema: this.dbExecutor.schema,
509
636
  securityContext: i
510
- }, o = e.sql(n), a = this.buildSelections(e, t, n);
511
- let r = n.db.select(a).from(o.from);
512
- if (o.joins)
513
- for (const h of o.joins)
514
- switch (h.type || "left") {
637
+ }, r = e.sql(n), a = this.buildSelections(e, t, n);
638
+ let s = n.db.select(a).from(r.from);
639
+ if (r.joins)
640
+ for (const p of r.joins)
641
+ switch (p.type || "left") {
515
642
  case "left":
516
- r = r.leftJoin(h.table, h.on);
643
+ s = s.leftJoin(p.table, p.on);
517
644
  break;
518
645
  case "inner":
519
- r = r.innerJoin(h.table, h.on);
646
+ s = s.innerJoin(p.table, p.on);
520
647
  break;
521
648
  case "right":
522
- r = r.rightJoin(h.table, h.on);
649
+ s = s.rightJoin(p.table, p.on);
523
650
  break;
524
651
  case "full":
525
- r = r.fullJoin(h.table, h.on);
652
+ s = s.fullJoin(p.table, p.on);
526
653
  break;
527
654
  }
528
- o.where && (r = r.where(o.where));
655
+ r.where && (s = s.where(r.where));
529
656
  const c = this.buildWhereConditions(e, t, n);
530
657
  if (c.length > 0) {
531
- const h = c.length === 1 ? c[0] : p(...c);
532
- r = r.where(h);
658
+ const p = c.length === 1 ? c[0] : h(...c);
659
+ s = s.where(p);
533
660
  }
534
661
  const l = this.buildGroupByFields(e, t, n);
535
- l.length > 0 && (r = r.groupBy(...l));
662
+ l.length > 0 && (s = s.groupBy(...l));
536
663
  const u = this.buildOrderBy(t);
537
- if (u.length > 0 && (r = r.orderBy(...u)), t.limit !== void 0) {
664
+ if (u.length > 0 && (s = s.orderBy(...u)), t.limit !== void 0) {
538
665
  if (t.limit < 0)
539
666
  throw new Error("Limit must be non-negative");
540
- r = r.limit(t.limit);
667
+ s = s.limit(t.limit);
541
668
  }
542
669
  if (t.offset !== void 0) {
543
670
  if (t.offset < 0)
544
671
  throw new Error("Offset must be non-negative");
545
- r = r.offset(t.offset);
672
+ s = s.offset(t.offset);
546
673
  }
547
- const m = t.measures || [], d = await this.dbExecutor.execute(r, m), Q = Array.isArray(d) ? d.map((h) => {
548
- const E = { ...h };
674
+ const m = t.measures || [], d = await this.dbExecutor.execute(s, m), U = Array.isArray(d) ? d.map((p) => {
675
+ const N = { ...p };
549
676
  if (t.timeDimensions) {
550
- for (const D of t.timeDimensions)
551
- if (D.dimension in E) {
552
- let g = E[D.dimension];
553
- typeof g == "string" && g.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/) && (g = g.replace(" ", "T"), !g.endsWith("Z") && !g.includes("+") && (g = g + "Z")), E[D.dimension] = g;
677
+ for (const y of t.timeDimensions)
678
+ if (y.dimension in N) {
679
+ let g = N[y.dimension];
680
+ typeof g == "string" && g.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/) && (g = g.replace(" ", "T"), !g.endsWith("Z") && !g.includes("+") && (g = g + "Z")), N[y.dimension] = g;
554
681
  }
555
682
  }
556
- return E;
557
- }) : [d], k = this.generateAnnotations(e, t);
683
+ return N;
684
+ }) : [d], I = this.generateAnnotations(e, t);
558
685
  return {
559
- data: Q,
560
- annotation: k
686
+ data: U,
687
+ annotation: I
561
688
  };
562
689
  } catch (n) {
563
690
  throw new Error(`Cube query execution failed: ${n instanceof Error ? n.message : "Unknown error"}`);
@@ -567,11 +694,11 @@ class $ {
567
694
  * Execute multi-cube query using JOIN resolution
568
695
  */
569
696
  async executeMultiCube(e, t, i) {
570
- const n = this.buildMultiCubeQuery(e, t, i), o = t.measures || [], a = await this.dbExecutor.execute(n, o), r = {
697
+ const n = this.buildMultiCubeQuery(e, t, i), r = t.measures || [], a = await this.dbExecutor.execute(n, r), s = {
571
698
  db: this.dbExecutor.db,
572
699
  schema: this.dbExecutor.schema,
573
700
  securityContext: i
574
- }, c = this.multiCubeBuilder.buildMultiCubeQueryPlan(e, t, r), l = this.generateMultiCubeAnnotations(c, t);
701
+ }, c = this.multiCubeBuilder.buildMultiCubeQueryPlan(e, t, s), l = this.generateMultiCubeAnnotations(c, t);
575
702
  return {
576
703
  data: Array.isArray(a) ? a : [a],
577
704
  annotation: l
@@ -587,10 +714,10 @@ class $ {
587
714
  * Generate raw SQL for multi-cube queries without execution
588
715
  */
589
716
  async generateMultiCubeSQL(e, t, i) {
590
- const o = this.buildMultiCubeQuery(e, t, i).toSQL();
717
+ const r = this.buildMultiCubeQuery(e, t, i).toSQL();
591
718
  return {
592
- sql: o.sql,
593
- params: o.params
719
+ sql: r.sql,
720
+ params: r.params
594
721
  };
595
722
  }
596
723
  /**
@@ -601,42 +728,42 @@ class $ {
601
728
  db: this.dbExecutor.db,
602
729
  schema: this.dbExecutor.schema,
603
730
  securityContext: i
604
- }, o = this.multiCubeBuilder.buildMultiCubeQueryPlan(e, t, n), a = o.primaryCube.sql(n);
605
- let r = n.db.select(o.selections).from(a.from);
731
+ }, r = this.multiCubeBuilder.buildMultiCubeQueryPlan(e, t, n), a = r.primaryCube.sql(n);
732
+ let s = n.db.select(r.selections).from(a.from);
606
733
  if (a.joins)
607
734
  for (const u of a.joins)
608
735
  switch (u.type || "left") {
609
736
  case "left":
610
- r = r.leftJoin(u.table, u.on);
737
+ s = s.leftJoin(u.table, u.on);
611
738
  break;
612
739
  case "inner":
613
- r = r.innerJoin(u.table, u.on);
740
+ s = s.innerJoin(u.table, u.on);
614
741
  break;
615
742
  case "right":
616
- r = r.rightJoin(u.table, u.on);
743
+ s = s.rightJoin(u.table, u.on);
617
744
  break;
618
745
  case "full":
619
- r = r.fullJoin(u.table, u.on);
746
+ s = s.fullJoin(u.table, u.on);
620
747
  break;
621
748
  default:
622
- r = r.leftJoin(u.table, u.on);
749
+ s = s.leftJoin(u.table, u.on);
623
750
  }
624
- if (o.joinCubes && o.joinCubes.length > 0)
625
- for (const u of o.joinCubes) {
751
+ if (r.joinCubes && r.joinCubes.length > 0)
752
+ for (const u of r.joinCubes) {
626
753
  const m = u.cube.sql(n);
627
754
  try {
628
755
  switch (u.joinType || "left") {
629
756
  case "left":
630
- r = r.leftJoin(m.from, u.joinCondition);
757
+ s = s.leftJoin(m.from, u.joinCondition);
631
758
  break;
632
759
  case "inner":
633
- r = r.innerJoin(m.from, u.joinCondition);
760
+ s = s.innerJoin(m.from, u.joinCondition);
634
761
  break;
635
762
  case "right":
636
- r = r.rightJoin(m.from, u.joinCondition);
763
+ s = s.rightJoin(m.from, u.joinCondition);
637
764
  break;
638
765
  case "full":
639
- r = r.fullJoin(m.from, u.joinCondition);
766
+ s = s.fullJoin(m.from, u.joinCondition);
640
767
  break;
641
768
  }
642
769
  } catch (d) {
@@ -644,23 +771,23 @@ class $ {
644
771
  }
645
772
  }
646
773
  const c = [];
647
- if (a.where && c.push(a.where), o.whereConditions.length > 0 && c.push(...o.whereConditions), c.length > 0) {
648
- const u = c.length === 1 ? c[0] : p(...c);
649
- r = r.where(u);
774
+ if (a.where && c.push(a.where), r.whereConditions.length > 0 && c.push(...r.whereConditions), c.length > 0) {
775
+ const u = c.length === 1 ? c[0] : h(...c);
776
+ s = s.where(u);
650
777
  }
651
- o.groupByFields.length > 0 && (r = r.groupBy(...o.groupByFields));
778
+ r.groupByFields.length > 0 && (s = s.groupBy(...r.groupByFields));
652
779
  const l = this.buildOrderBy(t);
653
- if (l.length > 0 && (r = r.orderBy(...l)), t.limit !== void 0) {
780
+ if (l.length > 0 && (s = s.orderBy(...l)), t.limit !== void 0) {
654
781
  if (t.limit < 0)
655
782
  throw new Error("Limit must be non-negative");
656
- r = r.limit(t.limit);
783
+ s = s.limit(t.limit);
657
784
  }
658
785
  if (t.offset !== void 0) {
659
786
  if (t.offset < 0)
660
787
  throw new Error("Offset must be non-negative");
661
- r = r.offset(t.offset);
788
+ s = s.offset(t.offset);
662
789
  }
663
- return r;
790
+ return s;
664
791
  }
665
792
  /**
666
793
  * Generate SQL for Cube
@@ -670,44 +797,44 @@ class $ {
670
797
  db: this.dbExecutor.db,
671
798
  schema: this.dbExecutor.schema,
672
799
  securityContext: i
673
- }, o = e.sql(n), a = this.buildSelections(e, t, n);
674
- let r = n.db.select(a).from(o.from);
675
- if (o.joins)
676
- for (const d of o.joins)
800
+ }, r = e.sql(n), a = this.buildSelections(e, t, n);
801
+ let s = n.db.select(a).from(r.from);
802
+ if (r.joins)
803
+ for (const d of r.joins)
677
804
  switch (d.type || "left") {
678
805
  case "left":
679
- r = r.leftJoin(d.table, d.on);
806
+ s = s.leftJoin(d.table, d.on);
680
807
  break;
681
808
  case "inner":
682
- r = r.innerJoin(d.table, d.on);
809
+ s = s.innerJoin(d.table, d.on);
683
810
  break;
684
811
  case "right":
685
- r = r.rightJoin(d.table, d.on);
812
+ s = s.rightJoin(d.table, d.on);
686
813
  break;
687
814
  case "full":
688
- r = r.fullJoin(d.table, d.on);
815
+ s = s.fullJoin(d.table, d.on);
689
816
  break;
690
817
  }
691
- o.where && (r = r.where(o.where));
818
+ r.where && (s = s.where(r.where));
692
819
  const c = this.buildWhereConditions(e, t, n);
693
820
  if (c.length > 0) {
694
- const d = c.length === 1 ? c[0] : p(...c);
695
- r = r.where(d);
821
+ const d = c.length === 1 ? c[0] : h(...c);
822
+ s = s.where(d);
696
823
  }
697
824
  const l = this.buildGroupByFields(e, t, n);
698
- l.length > 0 && (r = r.groupBy(...l));
825
+ l.length > 0 && (s = s.groupBy(...l));
699
826
  const u = this.buildOrderBy(t);
700
- if (u.length > 0 && (r = r.orderBy(...u)), t.limit !== void 0) {
827
+ if (u.length > 0 && (s = s.orderBy(...u)), t.limit !== void 0) {
701
828
  if (t.limit < 0)
702
829
  throw new Error("Limit must be non-negative");
703
- r = r.limit(t.limit);
830
+ s = s.limit(t.limit);
704
831
  }
705
832
  if (t.offset !== void 0) {
706
833
  if (t.offset < 0)
707
834
  throw new Error("Offset must be non-negative");
708
- r = r.offset(t.offset);
835
+ s = s.offset(t.offset);
709
836
  }
710
- const m = r.toSQL();
837
+ const m = s.toSQL();
711
838
  return {
712
839
  sql: m.sql,
713
840
  params: m.params
@@ -719,34 +846,34 @@ class $ {
719
846
  buildSelections(e, t, i) {
720
847
  const n = {};
721
848
  if (t.dimensions)
722
- for (const o of t.dimensions) {
723
- const [a, r] = o.split(".");
724
- if (a === e.name && e.dimensions[r]) {
725
- const c = e.dimensions[r], l = b(c.sql, i);
726
- n[o] = f`${l}`.as(o);
849
+ for (const r of t.dimensions) {
850
+ const [a, s] = r.split(".");
851
+ if (a === e.name && e.dimensions[s]) {
852
+ const c = e.dimensions[s], l = b(c.sql, i);
853
+ n[r] = f`${l}`.as(r);
727
854
  }
728
855
  }
729
856
  if (t.measures)
730
- for (const o of t.measures) {
731
- const [a, r] = o.split(".");
732
- if (a === e.name && e.measures[r]) {
733
- const c = e.measures[r], l = this.buildMeasureExpression(c, i);
734
- n[o] = f`${l}`.as(o);
857
+ for (const r of t.measures) {
858
+ const [a, s] = r.split(".");
859
+ if (a === e.name && e.measures[s]) {
860
+ const c = e.measures[s], l = this.buildMeasureExpression(c, i);
861
+ n[r] = f`${l}`.as(r);
735
862
  }
736
863
  }
737
864
  if (t.timeDimensions)
738
- for (const o of t.timeDimensions) {
739
- const [a, r] = o.dimension.split(".");
740
- if (a === e.name && e.dimensions[r]) {
741
- const c = e.dimensions[r], l = this.buildTimeDimensionExpression(
865
+ for (const r of t.timeDimensions) {
866
+ const [a, s] = r.dimension.split(".");
867
+ if (a === e.name && e.dimensions[s]) {
868
+ const c = e.dimensions[s], l = this.buildTimeDimensionExpression(
742
869
  c.sql,
743
- o.granularity,
870
+ r.granularity,
744
871
  i
745
872
  );
746
- n[o.dimension] = f`${l}`.as(o.dimension);
873
+ n[r.dimension] = f`${l}`.as(r.dimension);
747
874
  }
748
875
  }
749
- return Object.keys(n).length === 0 && (n.count = y()), n;
876
+ return Object.keys(n).length === 0 && (n.count = T()), n;
750
877
  }
751
878
  /**
752
879
  * Build measure expression with aggregation and filters for Cube
@@ -754,26 +881,26 @@ class $ {
754
881
  buildMeasureExpression(e, t) {
755
882
  let i = b(e.sql, t);
756
883
  if (e.filters && e.filters.length > 0) {
757
- const n = e.filters.map((o) => o(t));
758
- i = f`CASE WHEN ${p(...n)} THEN ${i} END`;
884
+ const n = e.filters.map((r) => r(t));
885
+ i = f`CASE WHEN ${h(...n)} THEN ${i} END`;
759
886
  }
760
887
  switch (e.type) {
761
888
  case "count":
762
- return y(i);
889
+ return T(i);
763
890
  case "countDistinct":
764
- return Y(i);
891
+ return K(i);
765
892
  case "sum":
766
- return I(i);
893
+ return J(i);
767
894
  case "avg":
768
- return R(i);
895
+ return W(i);
769
896
  case "min":
770
- return O(i);
897
+ return Y(i);
771
898
  case "max":
772
- return B(i);
899
+ return R(i);
773
900
  case "number":
774
901
  return i;
775
902
  default:
776
- return y(i);
903
+ return T(i);
777
904
  }
778
905
  }
779
906
  /**
@@ -810,15 +937,15 @@ class $ {
810
937
  buildWhereConditions(e, t, i) {
811
938
  const n = [];
812
939
  if (t.filters && t.filters.length > 0)
813
- for (const o of t.filters) {
814
- const a = this.processFilter(o, e, i);
940
+ for (const r of t.filters) {
941
+ const a = this.processFilter(r, e, i);
815
942
  a && n.push(a);
816
943
  }
817
944
  if (t.timeDimensions)
818
- for (const o of t.timeDimensions) {
819
- const [a, r] = o.dimension.split(".");
820
- if (a === e.name && e.dimensions[r] && o.dateRange) {
821
- const c = e.dimensions[r], l = b(c.sql, i), u = this.buildDateRangeCondition(l, o.dateRange);
945
+ for (const r of t.timeDimensions) {
946
+ const [a, s] = r.dimension.split(".");
947
+ if (a === e.name && e.dimensions[s] && r.dateRange) {
948
+ const c = e.dimensions[s], l = b(c.sql, i), u = this.buildDateRangeCondition(l, r.dateRange);
822
949
  u && n.push(u);
823
950
  }
824
951
  }
@@ -832,18 +959,18 @@ class $ {
832
959
  const l = e;
833
960
  if (l.and) {
834
961
  const u = l.and.map((m) => this.processFilter(m, t, i)).filter((m) => m !== null);
835
- return u.length > 0 ? p(...u) : null;
962
+ return u.length > 0 ? h(...u) : null;
836
963
  }
837
964
  if (l.or) {
838
965
  const u = l.or.map((m) => this.processFilter(m, t, i)).filter((m) => m !== null);
839
- return u.length > 0 ? J(...u) : null;
966
+ return u.length > 0 ? j(...u) : null;
840
967
  }
841
968
  }
842
- const n = e, [o, a] = n.member.split(".");
843
- if (o !== t.name) return null;
844
- const r = t.dimensions[a] || t.measures[a];
845
- if (!r) return null;
846
- const c = b(r.sql, i);
969
+ const n = e, [r, a] = n.member.split(".");
970
+ if (r !== t.name) return null;
971
+ const s = t.dimensions[a] || t.measures[a];
972
+ if (!s) return null;
973
+ const c = b(s.sql, i);
847
974
  return this.buildFilterCondition(c, n.operator, n.values);
848
975
  }
849
976
  /**
@@ -855,49 +982,49 @@ class $ {
855
982
  const n = i.filter((a) => !(a == null || a === "" || typeof a == "string" && a.includes("\0")));
856
983
  if (n.length === 0 && !["set", "notSet"].includes(t))
857
984
  return t === "equals" ? f`FALSE` : null;
858
- const o = n[0];
985
+ const r = n[0];
859
986
  switch (t) {
860
987
  case "equals":
861
- return n.length > 1 ? Z(e, n) : n.length === 1 ? v(e, o) : f`FALSE`;
988
+ return n.length > 1 ? Z(e, n) : n.length === 1 ? v(e, r) : f`FALSE`;
862
989
  case "notEquals":
863
- return n.length > 1 ? H(e, n) : n.length === 1 ? V(e, o) : null;
990
+ return n.length > 1 ? H(e, n) : n.length === 1 ? V(e, r) : null;
864
991
  case "contains":
865
- return f`${e} ILIKE ${"%" + o + "%"}`;
992
+ return f`${e} ILIKE ${"%" + r + "%"}`;
866
993
  case "notContains":
867
- return f`${e} NOT ILIKE ${"%" + o + "%"}`;
994
+ return f`${e} NOT ILIKE ${"%" + r + "%"}`;
868
995
  case "startsWith":
869
- return f`${e} ILIKE ${o + "%"}`;
996
+ return f`${e} ILIKE ${r + "%"}`;
870
997
  case "endsWith":
871
- return f`${e} ILIKE ${"%" + o}`;
998
+ return f`${e} ILIKE ${"%" + r}`;
872
999
  case "gt":
873
- return A(e, o);
1000
+ return E(e, r);
874
1001
  case "gte":
875
- return w(e, o);
1002
+ return C(e, r);
876
1003
  case "lt":
877
- return F(e, o);
1004
+ return $(e, r);
878
1005
  case "lte":
879
- return N(e, o);
1006
+ return w(e, r);
880
1007
  case "set":
881
- return K(e);
1008
+ return z(e);
882
1009
  case "notSet":
883
- return W(e);
1010
+ return L(e);
884
1011
  case "inDateRange":
885
1012
  if (n.length >= 2) {
886
- const a = this.normalizeDate(n[0]), r = this.normalizeDate(n[1]);
887
- if (a && r)
888
- return p(
889
- w(e, a),
890
- N(e, r)
1013
+ const a = this.normalizeDate(n[0]), s = this.normalizeDate(n[1]);
1014
+ if (a && s)
1015
+ return h(
1016
+ C(e, a),
1017
+ w(e, s)
891
1018
  );
892
1019
  }
893
1020
  return null;
894
1021
  case "beforeDate": {
895
- const a = this.normalizeDate(o);
896
- return a ? F(e, a) : null;
1022
+ const a = this.normalizeDate(r);
1023
+ return a ? $(e, a) : null;
897
1024
  }
898
1025
  case "afterDate": {
899
- const a = this.normalizeDate(o);
900
- return a ? A(e, a) : null;
1026
+ const a = this.normalizeDate(r);
1027
+ return a ? E(e, a) : null;
901
1028
  }
902
1029
  default:
903
1030
  return null;
@@ -910,26 +1037,26 @@ class $ {
910
1037
  if (!t) return null;
911
1038
  if (Array.isArray(t) && t.length >= 2) {
912
1039
  const i = this.normalizeDate(t[0]), n = this.normalizeDate(t[1]);
913
- return !i || !n ? null : p(
914
- w(e, i),
915
- N(e, n)
1040
+ return !i || !n ? null : h(
1041
+ C(e, i),
1042
+ w(e, n)
916
1043
  );
917
1044
  }
918
1045
  if (typeof t == "string") {
919
1046
  const i = this.parseRelativeDateRange(t);
920
1047
  if (i)
921
- return p(
922
- w(e, i.start),
923
- N(e, i.end)
1048
+ return h(
1049
+ C(e, i.start),
1050
+ w(e, i.end)
924
1051
  );
925
1052
  const n = this.normalizeDate(t);
926
1053
  if (!n) return null;
927
- const o = new Date(n);
928
- o.setUTCHours(0, 0, 0, 0);
1054
+ const r = new Date(n);
1055
+ r.setUTCHours(0, 0, 0, 0);
929
1056
  const a = new Date(n);
930
- return a.setUTCHours(23, 59, 59, 999), p(
931
- w(e, o),
932
- N(e, a)
1057
+ return a.setUTCHours(23, 59, 59, 999), h(
1058
+ C(e, r),
1059
+ w(e, a)
933
1060
  );
934
1061
  }
935
1062
  return null;
@@ -940,27 +1067,27 @@ class $ {
940
1067
  parseRelativeDateRange(e) {
941
1068
  const t = /* @__PURE__ */ new Date(), i = e.toLowerCase().trim(), n = i.match(/^last\s+(\d+)\s+days?$/);
942
1069
  if (n) {
943
- const r = parseInt(n[1], 10), c = new Date(t);
944
- c.setDate(t.getDate() - r), c.setHours(0, 0, 0, 0);
1070
+ const s = parseInt(n[1], 10), c = new Date(t);
1071
+ c.setDate(t.getDate() - s), c.setHours(0, 0, 0, 0);
945
1072
  const l = new Date(t);
946
1073
  return l.setHours(23, 59, 59, 999), { start: c, end: l };
947
1074
  }
948
1075
  if (i === "this month") {
949
- const r = new Date(t.getFullYear(), t.getMonth(), 1, 0, 0, 0, 0), c = new Date(t.getFullYear(), t.getMonth() + 1, 0, 23, 59, 59, 999);
950
- return { start: r, end: c };
1076
+ const s = new Date(t.getFullYear(), t.getMonth(), 1, 0, 0, 0, 0), c = new Date(t.getFullYear(), t.getMonth() + 1, 0, 23, 59, 59, 999);
1077
+ return { start: s, end: c };
951
1078
  }
952
- const o = i.match(/^last\s+(\d+)\s+months?$/);
953
- if (o) {
954
- const r = parseInt(o[1], 10), c = new Date(t.getFullYear(), t.getMonth() - r, 1, 0, 0, 0, 0), l = new Date(t);
1079
+ const r = i.match(/^last\s+(\d+)\s+months?$/);
1080
+ if (r) {
1081
+ const s = parseInt(r[1], 10), c = new Date(t.getFullYear(), t.getMonth() - s, 1, 0, 0, 0, 0), l = new Date(t);
955
1082
  return l.setHours(23, 59, 59, 999), { start: c, end: l };
956
1083
  }
957
1084
  if (i === "this year") {
958
- const r = new Date(t.getFullYear(), 0, 1, 0, 0, 0, 0), c = new Date(t.getFullYear(), 11, 31, 23, 59, 59, 999);
959
- return { start: r, end: c };
1085
+ const s = new Date(t.getFullYear(), 0, 1, 0, 0, 0, 0), c = new Date(t.getFullYear(), 11, 31, 23, 59, 59, 999);
1086
+ return { start: s, end: c };
960
1087
  }
961
1088
  const a = i.match(/^last\s+(\d+)\s+years?$/);
962
1089
  if (a) {
963
- const r = parseInt(a[1], 10), c = new Date(t.getFullYear() - r, 0, 1, 0, 0, 0, 0), l = new Date(t);
1090
+ const s = parseInt(a[1], 10), c = new Date(t.getFullYear() - s, 0, 1, 0, 0, 0, 0), l = new Date(t);
964
1091
  return l.setHours(23, 59, 59, 999), { start: c, end: l };
965
1092
  }
966
1093
  return null;
@@ -986,20 +1113,20 @@ class $ {
986
1113
  buildGroupByFields(e, t, i) {
987
1114
  const n = [];
988
1115
  if (t.dimensions)
989
- for (const o of t.dimensions) {
990
- const [a, r] = o.split(".");
991
- if (a === e.name && e.dimensions[r]) {
992
- const c = e.dimensions[r], l = b(c.sql, i);
1116
+ for (const r of t.dimensions) {
1117
+ const [a, s] = r.split(".");
1118
+ if (a === e.name && e.dimensions[s]) {
1119
+ const c = e.dimensions[s], l = b(c.sql, i);
993
1120
  n.push(l);
994
1121
  }
995
1122
  }
996
1123
  if (t.timeDimensions)
997
- for (const o of t.timeDimensions) {
998
- const [a, r] = o.dimension.split(".");
999
- if (a === e.name && e.dimensions[r]) {
1000
- const c = e.dimensions[r], l = this.buildTimeDimensionExpression(
1124
+ for (const r of t.timeDimensions) {
1125
+ const [a, s] = r.dimension.split(".");
1126
+ if (a === e.name && e.dimensions[s]) {
1127
+ const c = e.dimensions[s], l = this.buildTimeDimensionExpression(
1001
1128
  c.sql,
1002
- o.granularity,
1129
+ r.granularity,
1003
1130
  i
1004
1131
  );
1005
1132
  n.push(l);
@@ -1011,24 +1138,24 @@ class $ {
1011
1138
  * Build ORDER BY clause with automatic time dimension sorting
1012
1139
  */
1013
1140
  buildOrderBy(e, t) {
1014
- var o;
1141
+ var r;
1015
1142
  const i = [], n = t || [
1016
1143
  ...e.measures || [],
1017
1144
  ...e.dimensions || [],
1018
- ...((o = e.timeDimensions) == null ? void 0 : o.map((a) => a.dimension)) || []
1145
+ ...((r = e.timeDimensions) == null ? void 0 : r.map((a) => a.dimension)) || []
1019
1146
  ];
1020
1147
  if (e.order && Object.keys(e.order).length > 0)
1021
- for (const [a, r] of Object.entries(e.order)) {
1148
+ for (const [a, s] of Object.entries(e.order)) {
1022
1149
  if (!n.includes(a))
1023
1150
  throw new Error(`Cannot order by '${a}': field is not selected in the query`);
1024
- const c = r === "desc" ? f`DESC` : f`ASC`;
1151
+ const c = s === "desc" ? f`DESC` : f`ASC`;
1025
1152
  i.push(f`${f.identifier(a)} ${c}`);
1026
1153
  }
1027
1154
  if (e.timeDimensions && e.timeDimensions.length > 0) {
1028
- const a = new Set(Object.keys(e.order || {})), r = [...e.timeDimensions].sort(
1155
+ const a = new Set(Object.keys(e.order || {})), s = [...e.timeDimensions].sort(
1029
1156
  (c, l) => c.dimension.localeCompare(l.dimension)
1030
1157
  );
1031
- for (const c of r)
1158
+ for (const c of s)
1032
1159
  a.has(c.dimension) || i.push(f`${f.identifier(c.dimension)} ASC`);
1033
1160
  }
1034
1161
  return i;
@@ -1037,11 +1164,11 @@ class $ {
1037
1164
  * Generate annotations for UI metadata
1038
1165
  */
1039
1166
  generateAnnotations(e, t) {
1040
- const i = {}, n = {}, o = {};
1167
+ const i = {}, n = {}, r = {};
1041
1168
  if (t.measures)
1042
1169
  for (const a of t.measures) {
1043
- const [r, c] = a.split(".");
1044
- if (r === e.name && e.measures[c]) {
1170
+ const [s, c] = a.split(".");
1171
+ if (s === e.name && e.measures[c]) {
1045
1172
  const l = e.measures[c];
1046
1173
  i[a] = {
1047
1174
  title: l.title || c,
@@ -1052,8 +1179,8 @@ class $ {
1052
1179
  }
1053
1180
  if (t.dimensions)
1054
1181
  for (const a of t.dimensions) {
1055
- const [r, c] = a.split(".");
1056
- if (r === e.name && e.dimensions[c]) {
1182
+ const [s, c] = a.split(".");
1183
+ if (s === e.name && e.dimensions[c]) {
1057
1184
  const l = e.dimensions[c];
1058
1185
  n[a] = {
1059
1186
  title: l.title || c,
@@ -1064,10 +1191,10 @@ class $ {
1064
1191
  }
1065
1192
  if (t.timeDimensions)
1066
1193
  for (const a of t.timeDimensions) {
1067
- const [r, c] = a.dimension.split(".");
1068
- if (r === e.name && e.dimensions[c]) {
1194
+ const [s, c] = a.dimension.split(".");
1195
+ if (s === e.name && e.dimensions[c]) {
1069
1196
  const l = e.dimensions[c];
1070
- o[a.dimension] = {
1197
+ r[a.dimension] = {
1071
1198
  title: l.title || c,
1072
1199
  shortTitle: l.title || c,
1073
1200
  type: l.type,
@@ -1079,20 +1206,20 @@ class $ {
1079
1206
  measures: i,
1080
1207
  dimensions: n,
1081
1208
  segments: {},
1082
- timeDimensions: o
1209
+ timeDimensions: r
1083
1210
  };
1084
1211
  }
1085
1212
  /**
1086
1213
  * Generate annotations for multi-cube queries
1087
1214
  */
1088
1215
  generateMultiCubeAnnotations(e, t) {
1089
- const i = {}, n = {}, o = {}, a = [e.primaryCube];
1090
- if (e.joinCubes && a.push(...e.joinCubes.map((r) => r.cube)), t.measures)
1091
- for (const r of t.measures) {
1092
- const [c, l] = r.split("."), u = a.find((m) => m.name === c);
1216
+ const i = {}, n = {}, r = {}, a = [e.primaryCube];
1217
+ if (e.joinCubes && a.push(...e.joinCubes.map((s) => s.cube)), t.measures)
1218
+ for (const s of t.measures) {
1219
+ const [c, l] = s.split("."), u = a.find((m) => m.name === c);
1093
1220
  if (u && u.measures[l]) {
1094
1221
  const m = u.measures[l];
1095
- i[r] = {
1222
+ i[s] = {
1096
1223
  title: m.title || l,
1097
1224
  shortTitle: m.title || l,
1098
1225
  type: m.type
@@ -1100,11 +1227,11 @@ class $ {
1100
1227
  }
1101
1228
  }
1102
1229
  if (t.dimensions)
1103
- for (const r of t.dimensions) {
1104
- const [c, l] = r.split("."), u = a.find((m) => m.name === c);
1230
+ for (const s of t.dimensions) {
1231
+ const [c, l] = s.split("."), u = a.find((m) => m.name === c);
1105
1232
  if (u && u.dimensions[l]) {
1106
1233
  const m = u.dimensions[l];
1107
- n[r] = {
1234
+ n[s] = {
1108
1235
  title: m.title || l,
1109
1236
  shortTitle: m.title || l,
1110
1237
  type: m.type
@@ -1112,15 +1239,15 @@ class $ {
1112
1239
  }
1113
1240
  }
1114
1241
  if (t.timeDimensions)
1115
- for (const r of t.timeDimensions) {
1116
- const [c, l] = r.dimension.split("."), u = a.find((m) => m.name === c);
1242
+ for (const s of t.timeDimensions) {
1243
+ const [c, l] = s.dimension.split("."), u = a.find((m) => m.name === c);
1117
1244
  if (u && u.dimensions && u.dimensions[l]) {
1118
1245
  const m = u.dimensions[l];
1119
- o[r.dimension] = {
1246
+ r[s.dimension] = {
1120
1247
  title: m.title || l,
1121
1248
  shortTitle: m.title || l,
1122
1249
  type: m.type,
1123
- granularity: r.granularity
1250
+ granularity: s.granularity
1124
1251
  };
1125
1252
  }
1126
1253
  }
@@ -1128,18 +1255,18 @@ class $ {
1128
1255
  measures: i,
1129
1256
  dimensions: n,
1130
1257
  segments: {},
1131
- timeDimensions: o
1258
+ timeDimensions: r
1132
1259
  };
1133
1260
  }
1134
1261
  }
1135
- class T {
1262
+ class F {
1136
1263
  // 5 minutes in milliseconds
1137
1264
  constructor(e) {
1138
- C(this, "cubes", /* @__PURE__ */ new Map());
1139
- C(this, "dbExecutor");
1140
- C(this, "metadataCache");
1141
- C(this, "metadataCacheTimestamp");
1142
- C(this, "METADATA_CACHE_TTL", 5 * 60 * 1e3);
1265
+ D(this, "cubes", /* @__PURE__ */ new Map());
1266
+ D(this, "dbExecutor");
1267
+ D(this, "metadataCache");
1268
+ D(this, "metadataCacheTimestamp");
1269
+ D(this, "METADATA_CACHE_TTL", 5 * 60 * 1e3);
1143
1270
  e != null && e.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e != null && e.drizzle && (this.dbExecutor = _(
1144
1271
  e.drizzle,
1145
1272
  e.schema,
@@ -1194,7 +1321,7 @@ class T {
1194
1321
  async execute(e, t) {
1195
1322
  if (!this.dbExecutor)
1196
1323
  throw new Error("Database executor not configured");
1197
- return new $(this.dbExecutor).execute(this.cubes, e, t);
1324
+ return new x(this.dbExecutor).execute(this.cubes, e, t);
1198
1325
  }
1199
1326
  /**
1200
1327
  * Execute a multi-cube query
@@ -1226,13 +1353,13 @@ class T {
1226
1353
  * Optimized version that minimizes object iterations
1227
1354
  */
1228
1355
  generateCubeMetadata(e) {
1229
- const t = Object.keys(e.measures), i = Object.keys(e.dimensions), n = new Array(t.length), o = new Array(i.length);
1356
+ const t = Object.keys(e.measures), i = Object.keys(e.dimensions), n = new Array(t.length), r = new Array(i.length);
1230
1357
  for (let a = 0; a < t.length; a++) {
1231
- const r = t[a], c = e.measures[r];
1358
+ const s = t[a], c = e.measures[s];
1232
1359
  n[a] = {
1233
- name: `${e.name}.${r}`,
1234
- title: c.title || r,
1235
- shortTitle: c.title || r,
1360
+ name: `${e.name}.${s}`,
1361
+ title: c.title || s,
1362
+ shortTitle: c.title || s,
1236
1363
  type: c.type,
1237
1364
  format: void 0,
1238
1365
  // Measure doesn't have format field
@@ -1240,11 +1367,11 @@ class T {
1240
1367
  };
1241
1368
  }
1242
1369
  for (let a = 0; a < i.length; a++) {
1243
- const r = i[a], c = e.dimensions[r];
1244
- o[a] = {
1245
- name: `${e.name}.${r}`,
1246
- title: c.title || r,
1247
- shortTitle: c.title || r,
1370
+ const s = i[a], c = e.dimensions[s];
1371
+ r[a] = {
1372
+ name: `${e.name}.${s}`,
1373
+ title: c.title || s,
1374
+ shortTitle: c.title || s,
1248
1375
  type: c.type,
1249
1376
  format: void 0,
1250
1377
  // Dimension doesn't have format field
@@ -1256,7 +1383,7 @@ class T {
1256
1383
  title: e.title || e.name,
1257
1384
  description: e.description,
1258
1385
  measures: n,
1259
- dimensions: o,
1386
+ dimensions: r,
1260
1387
  segments: []
1261
1388
  // Add segments support later if needed
1262
1389
  };
@@ -1270,7 +1397,7 @@ class T {
1270
1397
  throw new Error(`Cube '${e}' not found`);
1271
1398
  if (!this.dbExecutor)
1272
1399
  throw new Error("Database executor not configured");
1273
- return new $(this.dbExecutor).generateSQL(n, t, i);
1400
+ return new x(this.dbExecutor).generateSQL(n, t, i);
1274
1401
  }
1275
1402
  /**
1276
1403
  * Get SQL for a multi-cube query without executing it (debugging)
@@ -1278,7 +1405,7 @@ class T {
1278
1405
  async generateMultiCubeSQL(e, t) {
1279
1406
  if (!this.dbExecutor)
1280
1407
  throw new Error("Database executor not configured");
1281
- return new $(this.dbExecutor).generateMultiCubeSQL(this.cubes, e, t);
1408
+ return new x(this.dbExecutor).generateMultiCubeSQL(this.cubes, e, t);
1282
1409
  }
1283
1410
  /**
1284
1411
  * Check if a cube exists
@@ -1317,93 +1444,93 @@ class T {
1317
1444
  * Ensures all referenced cubes and fields exist
1318
1445
  */
1319
1446
  validateQuery(e) {
1320
- return j(this.cubes, e);
1447
+ return Q(this.cubes, e);
1321
1448
  }
1322
1449
  }
1323
- function j(s, e) {
1450
+ function Q(o, e) {
1324
1451
  const t = [], i = /* @__PURE__ */ new Set();
1325
1452
  if (e.measures)
1326
1453
  for (const n of e.measures) {
1327
- const [o, a] = n.split(".");
1328
- if (!o || !a) {
1454
+ const [r, a] = n.split(".");
1455
+ if (!r || !a) {
1329
1456
  t.push(`Invalid measure format: ${n}. Expected format: 'CubeName.fieldName'`);
1330
1457
  continue;
1331
1458
  }
1332
- i.add(o);
1333
- const r = s.get(o);
1334
- if (!r) {
1335
- t.push(`Cube '${o}' not found (referenced in measure '${n}')`);
1459
+ i.add(r);
1460
+ const s = o.get(r);
1461
+ if (!s) {
1462
+ t.push(`Cube '${r}' not found (referenced in measure '${n}')`);
1336
1463
  continue;
1337
1464
  }
1338
- r.measures[a] || t.push(`Measure '${a}' not found on cube '${o}'`);
1465
+ s.measures[a] || t.push(`Measure '${a}' not found on cube '${r}'`);
1339
1466
  }
1340
1467
  if (e.dimensions)
1341
1468
  for (const n of e.dimensions) {
1342
- const [o, a] = n.split(".");
1343
- if (!o || !a) {
1469
+ const [r, a] = n.split(".");
1470
+ if (!r || !a) {
1344
1471
  t.push(`Invalid dimension format: ${n}. Expected format: 'CubeName.fieldName'`);
1345
1472
  continue;
1346
1473
  }
1347
- i.add(o);
1348
- const r = s.get(o);
1349
- if (!r) {
1350
- t.push(`Cube '${o}' not found (referenced in dimension '${n}')`);
1474
+ i.add(r);
1475
+ const s = o.get(r);
1476
+ if (!s) {
1477
+ t.push(`Cube '${r}' not found (referenced in dimension '${n}')`);
1351
1478
  continue;
1352
1479
  }
1353
- r.dimensions[a] || t.push(`Dimension '${a}' not found on cube '${o}'`);
1480
+ s.dimensions[a] || t.push(`Dimension '${a}' not found on cube '${r}'`);
1354
1481
  }
1355
1482
  if (e.timeDimensions)
1356
1483
  for (const n of e.timeDimensions) {
1357
- const [o, a] = n.dimension.split(".");
1358
- if (!o || !a) {
1484
+ const [r, a] = n.dimension.split(".");
1485
+ if (!r || !a) {
1359
1486
  t.push(`Invalid timeDimension format: ${n.dimension}. Expected format: 'CubeName.fieldName'`);
1360
1487
  continue;
1361
1488
  }
1362
- i.add(o);
1363
- const r = s.get(o);
1364
- if (!r) {
1365
- t.push(`Cube '${o}' not found (referenced in timeDimension '${n.dimension}')`);
1489
+ i.add(r);
1490
+ const s = o.get(r);
1491
+ if (!s) {
1492
+ t.push(`Cube '${r}' not found (referenced in timeDimension '${n.dimension}')`);
1366
1493
  continue;
1367
1494
  }
1368
- r.dimensions[a] || t.push(`TimeDimension '${a}' not found on cube '${o}' (must be a dimension with time type)`);
1495
+ s.dimensions[a] || t.push(`TimeDimension '${a}' not found on cube '${r}' (must be a dimension with time type)`);
1369
1496
  }
1370
1497
  if (e.filters)
1371
1498
  for (const n of e.filters)
1372
- L(n, s, t, i);
1499
+ k(n, o, t, i);
1373
1500
  return i.size === 0 && t.push("Query must reference at least one cube through measures, dimensions, or filters"), {
1374
1501
  isValid: t.length === 0,
1375
1502
  errors: t
1376
1503
  };
1377
1504
  }
1378
- function L(s, e, t, i) {
1379
- if ("and" in s || "or" in s) {
1380
- const r = s.and || s.or || [];
1381
- for (const c of r)
1382
- L(c, e, t, i);
1505
+ function k(o, e, t, i) {
1506
+ if ("and" in o || "or" in o) {
1507
+ const s = o.and || o.or || [];
1508
+ for (const c of s)
1509
+ k(c, e, t, i);
1383
1510
  return;
1384
1511
  }
1385
- if (!("member" in s)) {
1512
+ if (!("member" in o)) {
1386
1513
  t.push("Filter must have a member field");
1387
1514
  return;
1388
1515
  }
1389
- const [n, o] = s.member.split(".");
1390
- if (!n || !o) {
1391
- t.push(`Invalid filter member format: ${s.member}. Expected format: 'CubeName.fieldName'`);
1516
+ const [n, r] = o.member.split(".");
1517
+ if (!n || !r) {
1518
+ t.push(`Invalid filter member format: ${o.member}. Expected format: 'CubeName.fieldName'`);
1392
1519
  return;
1393
1520
  }
1394
1521
  i.add(n);
1395
1522
  const a = e.get(n);
1396
1523
  if (!a) {
1397
- t.push(`Cube '${n}' not found (referenced in filter '${s.member}')`);
1524
+ t.push(`Cube '${n}' not found (referenced in filter '${o.member}')`);
1398
1525
  return;
1399
1526
  }
1400
- !a.dimensions[o] && !a.measures[o] && t.push(`Filter field '${o}' not found on cube '${n}' (must be a dimension or measure)`);
1527
+ !a.dimensions[r] && !a.measures[r] && t.push(`Filter field '${r}' not found on cube '${n}' (must be a dimension or measure)`);
1401
1528
  }
1402
- function Ee(s) {
1403
- return new T(s);
1529
+ function Ne(o) {
1530
+ return new F(o);
1404
1531
  }
1405
- const se = new T();
1406
- function re(s) {
1532
+ const se = new F();
1533
+ function re(o) {
1407
1534
  const e = {
1408
1535
  valid: !0,
1409
1536
  errors: [],
@@ -1411,7 +1538,7 @@ function re(s) {
1411
1538
  cubes: []
1412
1539
  };
1413
1540
  try {
1414
- const t = G(s);
1541
+ const t = G(o);
1415
1542
  if (!t)
1416
1543
  return e.valid = !1, e.errors.push("Invalid YAML: empty or malformed content"), e;
1417
1544
  if (t.cubes && Array.isArray(t.cubes))
@@ -1430,43 +1557,43 @@ function re(s) {
1430
1557
  }
1431
1558
  return e;
1432
1559
  }
1433
- function oe(s) {
1560
+ function oe(o) {
1434
1561
  const e = [];
1435
- return s.name || e.push("Cube name is required"), !s.sql && !s.sql_table && !s.sqlTable && e.push('Cube must have either "sql", "sql_table", or "sqlTable" property'), s.dimensions && s.dimensions.forEach((t, i) => {
1562
+ return o.name || e.push("Cube name is required"), !o.sql && !o.sql_table && !o.sqlTable && e.push('Cube must have either "sql", "sql_table", or "sqlTable" property'), o.dimensions && o.dimensions.forEach((t, i) => {
1436
1563
  t.name || e.push(`Dimension at index ${i} is missing name`), t.type || e.push(`Dimension "${t.name}" is missing type`), t.sql || e.push(`Dimension "${t.name}" is missing sql`);
1437
- }), s.measures && s.measures.forEach((t, i) => {
1564
+ }), o.measures && o.measures.forEach((t, i) => {
1438
1565
  t.name || e.push(`Measure at index ${i} is missing name`), t.type || e.push(`Measure "${t.name}" is missing type`), t.sql || e.push(`Measure "${t.name}" is missing sql`);
1439
- }), s.joins && s.joins.forEach((t, i) => {
1566
+ }), o.joins && o.joins.forEach((t, i) => {
1440
1567
  t.name || e.push(`Join at index ${i} is missing name`), t.relationship || e.push(`Join "${t.name}" is missing relationship`), t.sql || e.push(`Join "${t.name}" is missing sql`);
1441
1568
  }), e;
1442
1569
  }
1443
- function ae(s) {
1570
+ function ae(o) {
1444
1571
  const e = {};
1445
- s.dimensions && s.dimensions.forEach((r) => {
1446
- e[r.name] = ce(r);
1572
+ o.dimensions && o.dimensions.forEach((s) => {
1573
+ e[s.name] = ce(s);
1447
1574
  });
1448
1575
  const t = {};
1449
- s.measures && s.measures.forEach((r) => {
1450
- t[r.name] = le(r);
1576
+ o.measures && o.measures.forEach((s) => {
1577
+ t[s.name] = le(s);
1451
1578
  });
1452
1579
  const i = {};
1453
- s.joins && s.joins.forEach((r) => {
1454
- i[r.name] = fe(r);
1580
+ o.joins && o.joins.forEach((s) => {
1581
+ i[s.name] = fe(s);
1455
1582
  });
1456
1583
  const n = {};
1457
- (s.pre_aggregations || s.preAggregations) && (s.pre_aggregations || s.preAggregations || []).forEach((c) => {
1584
+ (o.pre_aggregations || o.preAggregations) && (o.pre_aggregations || o.preAggregations || []).forEach((c) => {
1458
1585
  n[c.name] = de(c);
1459
1586
  });
1460
- let o = s.sql;
1461
- !o && (s.sql_table || s.sqlTable) && (o = `SELECT * FROM ${s.sql_table || s.sqlTable}`);
1462
- const a = s.refresh_key || s.refreshKey;
1587
+ let r = o.sql;
1588
+ !r && (o.sql_table || o.sqlTable) && (r = `SELECT * FROM ${o.sql_table || o.sqlTable}`);
1589
+ const a = o.refresh_key || o.refreshKey;
1463
1590
  return {
1464
- name: s.name,
1465
- title: s.title,
1466
- description: s.description,
1467
- sql: o || "",
1468
- sqlAlias: s.sql_alias || s.sqlAlias,
1469
- dataSource: s.data_source || s.dataSource,
1591
+ name: o.name,
1592
+ title: o.title,
1593
+ description: o.description,
1594
+ sql: r || "",
1595
+ sqlAlias: o.sql_alias || o.sqlAlias,
1596
+ dataSource: o.data_source || o.dataSource,
1470
1597
  refreshKey: a ? {
1471
1598
  every: a.every,
1472
1599
  sql: a.sql
@@ -1475,42 +1602,42 @@ function ae(s) {
1475
1602
  measures: t,
1476
1603
  joins: Object.keys(i).length > 0 ? i : void 0,
1477
1604
  preAggregations: Object.keys(n).length > 0 ? n : void 0,
1478
- meta: s.meta
1605
+ meta: o.meta
1479
1606
  };
1480
1607
  }
1481
- function ce(s) {
1608
+ function ce(o) {
1482
1609
  return {
1483
- name: s.name,
1484
- title: s.title,
1485
- description: s.description,
1486
- type: s.type,
1487
- sql: s.sql,
1488
- primaryKey: s.primary_key || s.primaryKey,
1489
- shown: s.shown,
1490
- format: s.format,
1491
- meta: s.meta
1610
+ name: o.name,
1611
+ title: o.title,
1612
+ description: o.description,
1613
+ type: o.type,
1614
+ sql: o.sql,
1615
+ primaryKey: o.primary_key || o.primaryKey,
1616
+ shown: o.shown,
1617
+ format: o.format,
1618
+ meta: o.meta
1492
1619
  };
1493
1620
  }
1494
- function le(s) {
1621
+ function le(o) {
1495
1622
  var i;
1496
- const e = (i = s.filters) == null ? void 0 : i.map((n) => ({
1623
+ const e = (i = o.filters) == null ? void 0 : i.map((n) => ({
1497
1624
  sql: n.sql
1498
- })), t = s.rolling_window || s.rollingWindow;
1625
+ })), t = o.rolling_window || o.rollingWindow;
1499
1626
  return {
1500
- name: s.name,
1501
- title: s.title,
1502
- description: s.description,
1503
- type: s.type,
1504
- sql: s.sql,
1505
- format: s.format,
1506
- shown: s.shown,
1627
+ name: o.name,
1628
+ title: o.title,
1629
+ description: o.description,
1630
+ type: o.type,
1631
+ sql: o.sql,
1632
+ format: o.format,
1633
+ shown: o.shown,
1507
1634
  filters: e,
1508
1635
  rollingWindow: t,
1509
- meta: s.meta
1636
+ meta: o.meta
1510
1637
  };
1511
1638
  }
1512
- function ue(s) {
1513
- switch (s) {
1639
+ function ue(o) {
1640
+ switch (o) {
1514
1641
  case "one_to_one":
1515
1642
  return "hasOne";
1516
1643
  case "one_to_many":
@@ -1521,8 +1648,8 @@ function ue(s) {
1521
1648
  return "belongsTo";
1522
1649
  }
1523
1650
  }
1524
- function me(s) {
1525
- switch (s) {
1651
+ function me(o) {
1652
+ switch (o) {
1526
1653
  case "hasOne":
1527
1654
  return "one_to_one";
1528
1655
  case "hasMany":
@@ -1533,62 +1660,62 @@ function me(s) {
1533
1660
  return "many_to_one";
1534
1661
  }
1535
1662
  }
1536
- function fe(s) {
1663
+ function fe(o) {
1537
1664
  return {
1538
- name: s.name,
1539
- type: s.type,
1540
- relationship: ue(s.relationship),
1541
- sql: s.sql
1665
+ name: o.name,
1666
+ type: o.type,
1667
+ relationship: ue(o.relationship),
1668
+ sql: o.sql
1542
1669
  };
1543
1670
  }
1544
- function de(s) {
1545
- const e = s.time_dimension || s.timeDimension, t = s.refresh_key || s.refreshKey;
1671
+ function de(o) {
1672
+ const e = o.time_dimension || o.timeDimension, t = o.refresh_key || o.refreshKey;
1546
1673
  return {
1547
- name: s.name,
1548
- measures: s.measures,
1549
- dimensions: s.dimensions,
1674
+ name: o.name,
1675
+ measures: o.measures,
1676
+ dimensions: o.dimensions,
1550
1677
  timeDimension: e,
1551
1678
  refreshKey: t,
1552
- indexes: s.indexes
1679
+ indexes: o.indexes
1553
1680
  };
1554
1681
  }
1555
1682
  async function he() {
1556
1683
  try {
1557
- const { promises: s } = await import("fs"), e = await s.readFile("non-existent-file.txt", "utf-8").catch((t) => t.message);
1684
+ const { promises: o } = await import("fs"), e = await o.readFile("non-existent-file.txt", "utf-8").catch((t) => t.message);
1558
1685
  return !(typeof e == "string" && e.includes("not implemented"));
1559
1686
  } catch {
1560
1687
  return !1;
1561
1688
  }
1562
1689
  }
1563
- function pe(s) {
1564
- const e = re(s);
1690
+ function pe(o) {
1691
+ const e = re(o);
1565
1692
  if (!e.valid)
1566
1693
  throw new Error(`Invalid YAML cube definition:
1567
1694
  ${e.errors.join(`
1568
1695
  `)}`);
1569
1696
  return e.cubes.map((t) => ae(t));
1570
1697
  }
1571
- async function De(s) {
1698
+ async function Ee(o) {
1572
1699
  if (!await he())
1573
1700
  return console.log("ℹ️ YAML file loading not supported in this environment (Cloudflare Workers/Edge Runtime). Use inline YAML strings or build-time transformations instead."), [];
1574
1701
  try {
1575
- const { promises: t } = await import("fs"), i = await t.readFile(s, "utf-8");
1702
+ const { promises: t } = await import("fs"), i = await t.readFile(o, "utf-8");
1576
1703
  return pe(i);
1577
1704
  } catch (t) {
1578
- return console.log(`ℹ️ Could not load YAML file ${s}:`, t instanceof Error ? t.message : t), [];
1705
+ return console.log(`ℹ️ Could not load YAML file ${o}:`, t instanceof Error ? t.message : t), [];
1579
1706
  }
1580
1707
  }
1581
- function ye(s) {
1582
- let e = s;
1708
+ function $e(o) {
1709
+ let e = o;
1583
1710
  return e = e.replace(/\{CUBE\}/g, "${CUBE}"), e = e.replace(/\{([A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*)\}/g, "${$1}"), e = e.replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, "${$1}"), e = e.replace(/\$\$\{/g, "${"), e;
1584
1711
  }
1585
- function $e(s) {
1712
+ function ye(o) {
1586
1713
  const e = {
1587
- name: s.name,
1588
- title: s.title,
1589
- description: s.description,
1590
- sql: typeof s.sql == "string" ? s.sql : void 0,
1591
- dimensions: Object.values(s.dimensions).map((t) => ({
1714
+ name: o.name,
1715
+ title: o.title,
1716
+ description: o.description,
1717
+ sql: typeof o.sql == "string" ? o.sql : void 0,
1718
+ dimensions: Object.values(o.dimensions).map((t) => ({
1592
1719
  name: t.name,
1593
1720
  title: t.title,
1594
1721
  description: t.description,
@@ -1599,7 +1726,7 @@ function $e(s) {
1599
1726
  format: t.format,
1600
1727
  meta: t.meta
1601
1728
  })),
1602
- measures: Object.values(s.measures).map((t) => {
1729
+ measures: Object.values(o.measures).map((t) => {
1603
1730
  var i;
1604
1731
  return {
1605
1732
  name: t.name,
@@ -1616,13 +1743,13 @@ function $e(s) {
1616
1743
  meta: t.meta
1617
1744
  };
1618
1745
  }),
1619
- joins: s.joins ? Object.values(s.joins).map((t) => ({
1746
+ joins: o.joins ? Object.values(o.joins).map((t) => ({
1620
1747
  name: t.name || "",
1621
1748
  type: t.type,
1622
1749
  relationship: me(t.relationship),
1623
1750
  sql: typeof t.sql == "string" ? t.sql : ""
1624
1751
  })) : void 0,
1625
- meta: s.meta
1752
+ meta: o.meta
1626
1753
  };
1627
1754
  return P(e, {
1628
1755
  indent: 2,
@@ -1630,11 +1757,11 @@ function $e(s) {
1630
1757
  minContentWidth: 40
1631
1758
  });
1632
1759
  }
1633
- const xe = se;
1634
- function Te(s) {
1635
- return new T({
1636
- drizzle: s.drizzle,
1637
- schema: s.schema
1760
+ const Te = se;
1761
+ function xe(o) {
1762
+ return new F({
1763
+ drizzle: o.drizzle,
1764
+ schema: o.schema
1638
1765
  });
1639
1766
  }
1640
1767
  const Ae = {
@@ -1642,12 +1769,12 @@ const Ae = {
1642
1769
  * Create a simple query builder
1643
1770
  */
1644
1771
  query: () => {
1645
- const s = (e, t = [], i = [], n = [], o, a) => ({
1772
+ const o = (e, t = [], i = [], n = [], r, a) => ({
1646
1773
  measures: e,
1647
1774
  dimensions: t,
1648
1775
  filters: i,
1649
1776
  timeDimensions: n,
1650
- limit: o,
1777
+ limit: r,
1651
1778
  order: a
1652
1779
  });
1653
1780
  return {
@@ -1655,62 +1782,62 @@ const Ae = {
1655
1782
  dimensions: (t = []) => ({
1656
1783
  filters: (i = []) => ({
1657
1784
  timeDimensions: (n = []) => ({
1658
- limit: (o) => ({
1659
- order: (a) => s(e, t, i, n, o, a)
1785
+ limit: (r) => ({
1786
+ order: (a) => o(e, t, i, n, r, a)
1660
1787
  }),
1661
- order: (o) => s(e, t, i, n, void 0, o)
1788
+ order: (r) => o(e, t, i, n, void 0, r)
1662
1789
  }),
1663
1790
  limit: (n) => ({
1664
- order: (o) => s(e, t, i, [], n, o)
1791
+ order: (r) => o(e, t, i, [], n, r)
1665
1792
  }),
1666
- order: (n) => s(e, t, i, [], void 0, n)
1793
+ order: (n) => o(e, t, i, [], void 0, n)
1667
1794
  }),
1668
1795
  timeDimensions: (i = []) => ({
1669
1796
  filters: (n = []) => ({
1670
- limit: (o) => ({
1671
- order: (a) => s(e, t, n, i, o, a)
1797
+ limit: (r) => ({
1798
+ order: (a) => o(e, t, n, i, r, a)
1672
1799
  }),
1673
- order: (o) => s(e, t, n, i, void 0, o)
1800
+ order: (r) => o(e, t, n, i, void 0, r)
1674
1801
  }),
1675
1802
  limit: (n) => ({
1676
- order: (o) => s(e, t, [], i, n, o)
1803
+ order: (r) => o(e, t, [], i, n, r)
1677
1804
  }),
1678
- order: (n) => s(e, t, [], i, void 0, n)
1805
+ order: (n) => o(e, t, [], i, void 0, n)
1679
1806
  }),
1680
1807
  limit: (i) => ({
1681
- order: (n) => s(e, t, [], [], i, n)
1808
+ order: (n) => o(e, t, [], [], i, n)
1682
1809
  }),
1683
- order: (i) => s(e, t, [], [], void 0, i)
1810
+ order: (i) => o(e, t, [], [], void 0, i)
1684
1811
  }),
1685
1812
  filters: (t = []) => ({
1686
1813
  dimensions: (i = []) => ({
1687
1814
  timeDimensions: (n = []) => ({
1688
- limit: (o) => ({
1689
- order: (a) => s(e, i, t, n, o, a)
1815
+ limit: (r) => ({
1816
+ order: (a) => o(e, i, t, n, r, a)
1690
1817
  }),
1691
- order: (o) => s(e, i, t, n, void 0, o)
1818
+ order: (r) => o(e, i, t, n, void 0, r)
1692
1819
  }),
1693
1820
  limit: (n) => ({
1694
- order: (o) => s(e, i, t, [], n, o)
1821
+ order: (r) => o(e, i, t, [], n, r)
1695
1822
  }),
1696
- order: (n) => s(e, i, t, [], void 0, n)
1823
+ order: (n) => o(e, i, t, [], void 0, n)
1697
1824
  }),
1698
1825
  timeDimensions: (i = []) => ({
1699
1826
  dimensions: (n = []) => ({
1700
- limit: (o) => ({
1701
- order: (a) => s(e, n, t, i, o, a)
1827
+ limit: (r) => ({
1828
+ order: (a) => o(e, n, t, i, r, a)
1702
1829
  }),
1703
- order: (o) => s(e, n, t, i, void 0, o)
1830
+ order: (r) => o(e, n, t, i, void 0, r)
1704
1831
  }),
1705
1832
  limit: (n) => ({
1706
- order: (o) => s(e, [], t, i, n, o)
1833
+ order: (r) => o(e, [], t, i, n, r)
1707
1834
  }),
1708
- order: (n) => s(e, [], t, i, void 0, n)
1835
+ order: (n) => o(e, [], t, i, void 0, n)
1709
1836
  }),
1710
1837
  limit: (i) => ({
1711
- order: (n) => s(e, [], t, [], i, n)
1838
+ order: (n) => o(e, [], t, [], i, n)
1712
1839
  }),
1713
- order: (i) => s(e, [], t, [], void 0, i)
1840
+ order: (i) => o(e, [], t, [], void 0, i)
1714
1841
  })
1715
1842
  })
1716
1843
  };
@@ -1719,55 +1846,55 @@ const Ae = {
1719
1846
  * Create filters
1720
1847
  */
1721
1848
  filters: {
1722
- equals: (s, e) => ({ member: s, operator: "equals", values: [e] }),
1723
- notEquals: (s, e) => ({ member: s, operator: "notEquals", values: [e] }),
1724
- contains: (s, e) => ({ member: s, operator: "contains", values: [e] }),
1725
- greaterThan: (s, e) => ({ member: s, operator: "gt", values: [e] }),
1726
- lessThan: (s, e) => ({ member: s, operator: "lt", values: [e] }),
1727
- inDateRange: (s, e, t) => ({
1728
- member: s,
1849
+ equals: (o, e) => ({ member: o, operator: "equals", values: [e] }),
1850
+ notEquals: (o, e) => ({ member: o, operator: "notEquals", values: [e] }),
1851
+ contains: (o, e) => ({ member: o, operator: "contains", values: [e] }),
1852
+ greaterThan: (o, e) => ({ member: o, operator: "gt", values: [e] }),
1853
+ lessThan: (o, e) => ({ member: o, operator: "lt", values: [e] }),
1854
+ inDateRange: (o, e, t) => ({
1855
+ member: o,
1729
1856
  operator: "inDateRange",
1730
1857
  values: [e, t]
1731
1858
  }),
1732
- set: (s) => ({ member: s, operator: "set", values: [] }),
1733
- notSet: (s) => ({ member: s, operator: "notSet", values: [] })
1859
+ set: (o) => ({ member: o, operator: "set", values: [] }),
1860
+ notSet: (o) => ({ member: o, operator: "notSet", values: [] })
1734
1861
  },
1735
1862
  /**
1736
1863
  * Create time dimensions
1737
1864
  */
1738
1865
  timeDimensions: {
1739
- create: (s, e, t) => ({
1740
- dimension: s,
1866
+ create: (o, e, t) => ({
1867
+ dimension: o,
1741
1868
  granularity: e,
1742
1869
  dateRange: t
1743
1870
  })
1744
1871
  }
1745
1872
  };
1746
1873
  export {
1747
- x as BaseDatabaseExecutor,
1874
+ A as BaseDatabaseExecutor,
1748
1875
  ie as MultiCubeBuilder,
1749
1876
  ee as MySQLExecutor,
1750
1877
  X as PostgresExecutor,
1751
- $ as QueryExecutor,
1878
+ x as QueryExecutor,
1752
1879
  q as SQLiteExecutor,
1753
- T as SemanticLayerCompiler,
1880
+ F as SemanticLayerCompiler,
1754
1881
  Ae as SemanticLayerUtils,
1755
- ye as convertCubeReferences,
1882
+ $e as convertCubeReferences,
1756
1883
  _ as createDatabaseExecutor,
1757
- Te as createDrizzleSemanticLayer,
1884
+ xe as createDrizzleSemanticLayer,
1758
1885
  ne as createMultiCubeContext,
1759
1886
  te as createMySQLExecutor,
1760
1887
  S as createPostgresExecutor,
1761
1888
  M as createSQLiteExecutor,
1762
- Ee as createSemanticLayer,
1763
- xe as defaultSemanticLayer,
1764
- Ne as defineCube,
1889
+ Ne as createSemanticLayer,
1890
+ Te as defaultSemanticLayer,
1891
+ De as defineCube,
1765
1892
  we as defineLegacyCube,
1766
1893
  pe as loadYamlCubes,
1767
- De as loadYamlCubesFromFile,
1894
+ Ee as loadYamlCubesFromFile,
1768
1895
  re as parseYamlCubes,
1769
1896
  b as resolveSqlExpression,
1770
- $e as semanticCubeToYaml,
1897
+ ye as semanticCubeToYaml,
1771
1898
  se as semanticLayer,
1772
1899
  ae as yamlCubeToSemanticCube
1773
1900
  };