drizzle-cube 0.1.0 → 0.1.2

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,583 +1,3487 @@
1
- var u = Object.defineProperty;
2
- var y = (l, e, n) => e in l ? u(l, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : l[e] = n;
3
- var c = (l, e, n) => y(l, typeof e != "symbol" ? e + "" : e, n);
4
- class f {
1
+ var kr = Object.defineProperty;
2
+ var eo = (n, e, t) => e in n ? kr(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var r = (n, e, t) => eo(n, typeof e != "symbol" ? e + "" : e, t);
4
+ import { and as B, sql as y, eq as di, count as Y, max as to, min as no, avg as so, sum as io, countDistinct as ro, or as oo, gt as re, lt as oe, gte as ae, lte as ue, isNull as ao, isNotNull as uo, ne as co, relations as J } from "drizzle-orm";
5
+ import { parse as lo, stringify as mo } from "yaml";
6
+ function Sa(n, e) {
7
+ return {
8
+ ...e,
9
+ name: e.name
10
+ };
11
+ }
12
+ class ee {
13
+ constructor(e, t) {
14
+ this.db = e, this.schema = t;
15
+ }
16
+ }
17
+ class fo extends ee {
18
+ async execute(e) {
19
+ if (e && typeof e == "object") {
20
+ if (typeof e.execute == "function") {
21
+ const s = await e.execute();
22
+ return Array.isArray(s) ? s.map((i) => this.convertNumericFields(i)) : s;
23
+ }
24
+ if (this.db && typeof this.db.execute == "function")
25
+ try {
26
+ const s = await this.db.execute(e);
27
+ return Array.isArray(s) ? s.map((i) => this.convertNumericFields(i)) : s;
28
+ } catch (s) {
29
+ if (typeof e.getSQL == "function") {
30
+ const i = e.getSQL(), o = await this.db.execute(i);
31
+ return Array.isArray(o) ? o.map((l) => this.convertNumericFields(l)) : o;
32
+ }
33
+ throw s;
34
+ }
35
+ }
36
+ if (!this.db.execute)
37
+ throw new Error("PostgreSQL database instance must have an execute method");
38
+ const t = await this.db.execute(e);
39
+ return Array.isArray(t) ? t.map((s) => this.convertNumericFields(s)) : t;
40
+ }
41
+ /**
42
+ * Convert numeric string fields to numbers
43
+ */
44
+ convertNumericFields(e) {
45
+ if (!e || typeof e != "object") return e;
46
+ const t = {};
47
+ for (const [s, i] of Object.entries(e))
48
+ typeof i == "string" && /^\d+(\.\d+)?$/.test(i) ? t[s] = i.includes(".") ? parseFloat(i) : parseInt(i, 10) : t[s] = i;
49
+ return t;
50
+ }
51
+ getEngineType() {
52
+ return "postgres";
53
+ }
54
+ }
55
+ class po extends ee {
56
+ async execute(e) {
57
+ if (e && typeof e == "object" && typeof e.execute == "function")
58
+ return await e.execute();
59
+ try {
60
+ if (this.db.all)
61
+ return this.db.all(e);
62
+ if (this.db.run)
63
+ return this.db.run(e);
64
+ throw new Error("SQLite database instance must have an all() or run() method");
65
+ } catch (t) {
66
+ throw new Error(`SQLite execution failed: ${t instanceof Error ? t.message : "Unknown error"}`);
67
+ }
68
+ }
69
+ getEngineType() {
70
+ return "sqlite";
71
+ }
72
+ }
73
+ class ho extends ee {
74
+ async execute(e) {
75
+ if (e && typeof e == "object" && typeof e.execute == "function")
76
+ return await e.execute();
77
+ if (!this.db.execute)
78
+ throw new Error("MySQL database instance must have an execute method");
79
+ return await this.db.execute(e);
80
+ }
81
+ getEngineType() {
82
+ return "mysql";
83
+ }
84
+ }
85
+ function ce(n, e) {
86
+ return new fo(n, e);
87
+ }
88
+ function le(n, e) {
89
+ return new po(n, e);
90
+ }
91
+ function go(n, e) {
92
+ return new ho(n, e);
93
+ }
94
+ function me(n, e, t) {
95
+ if (t)
96
+ switch (t) {
97
+ case "postgres":
98
+ return ce(n, e);
99
+ case "mysql":
100
+ return go(n, e);
101
+ case "sqlite":
102
+ return le(n, e);
103
+ }
104
+ if (n.all && n.run)
105
+ return le(n, e);
106
+ if (n.execute)
107
+ return ce(n, e);
108
+ throw new Error("Unable to determine database engine type. Please specify engineType parameter.");
109
+ }
110
+ function Pa(n, e) {
111
+ return {
112
+ name: n,
113
+ ...e
114
+ };
115
+ }
116
+ function v(n, e) {
117
+ return typeof n == "function" ? n(e) : n;
118
+ }
119
+ function bo(n, e, t) {
120
+ return {
121
+ ...n,
122
+ cubes: e,
123
+ currentCube: t
124
+ };
125
+ }
126
+ class yo {
127
+ /**
128
+ * Analyze a semantic query to determine which cubes are involved
129
+ */
130
+ analyzeCubeUsage(e) {
131
+ const t = /* @__PURE__ */ new Set();
132
+ if (e.measures)
133
+ for (const s of e.measures) {
134
+ const [i] = s.split(".");
135
+ t.add(i);
136
+ }
137
+ if (e.dimensions)
138
+ for (const s of e.dimensions) {
139
+ const [i] = s.split(".");
140
+ t.add(i);
141
+ }
142
+ if (e.timeDimensions)
143
+ for (const s of e.timeDimensions) {
144
+ const [i] = s.dimension.split(".");
145
+ t.add(i);
146
+ }
147
+ return t;
148
+ }
149
+ /**
150
+ * Build a multi-cube query plan
151
+ */
152
+ buildMultiCubeQueryPlan(e, t, s) {
153
+ const i = this.analyzeCubeUsage(t), o = Array.from(i);
154
+ if (o.length === 1)
155
+ throw new Error("Single cube query should use QueryExecutor directly");
156
+ const l = this.choosePrimaryCube(o, t), a = e.get(l);
157
+ if (!a)
158
+ throw new Error(`Primary cube '${l}' not found`);
159
+ const m = this.buildJoinPlan(e, a, o, s.securityContext), d = this.buildMultiCubeSelections(e, t, s.securityContext), u = this.buildMultiCubeWhereConditions(e, t, s), f = this.buildMultiCubeGroupByFields(e, t, s.securityContext);
160
+ return {
161
+ primaryCube: a,
162
+ joinCubes: m,
163
+ selections: d,
164
+ whereConditions: u,
165
+ groupByFields: f
166
+ };
167
+ }
168
+ /**
169
+ * Choose the primary cube based on query analysis
170
+ */
171
+ choosePrimaryCube(e, t) {
172
+ if (t.measures && t.measures.length > 0) {
173
+ const [s] = t.measures[0].split(".");
174
+ return s;
175
+ }
176
+ if (t.dimensions && t.dimensions.length > 0) {
177
+ const [s] = t.dimensions[0].split(".");
178
+ return s;
179
+ }
180
+ return e[0];
181
+ }
182
+ /**
183
+ * Build join plan for multi-cube query
184
+ */
185
+ buildJoinPlan(e, t, s, i) {
186
+ var a;
187
+ const o = [], l = s.filter((m) => m !== t.name);
188
+ for (const m of l) {
189
+ const d = e.get(m);
190
+ if (!d)
191
+ throw new Error(`Cube '${m}' not found`);
192
+ const u = (a = t.joins) == null ? void 0 : a[m];
193
+ if (!u)
194
+ throw new Error(`No join definition found from '${t.name}' to '${m}'`);
195
+ const f = bo(
196
+ {
197
+ db: {},
198
+ // Will be filled in during execution
199
+ schema: {},
200
+ // Will be filled in during execution
201
+ securityContext: i
202
+ },
203
+ e,
204
+ d
205
+ ), p = u.condition(f);
206
+ o.push({
207
+ cube: d,
208
+ alias: `${m.toLowerCase()}_cube`,
209
+ joinType: u.type || "left",
210
+ joinCondition: p
211
+ });
212
+ }
213
+ return o;
214
+ }
215
+ /**
216
+ * Build selections across multiple cubes
217
+ */
218
+ buildMultiCubeSelections(e, t, s) {
219
+ const i = {}, o = {
220
+ db: {},
221
+ // Filled during execution
222
+ schema: {},
223
+ // Filled during execution
224
+ securityContext: s
225
+ };
226
+ if (t.dimensions)
227
+ for (const l of t.dimensions) {
228
+ const [a, m] = l.split("."), d = e.get(a);
229
+ if (d && d.dimensions[m]) {
230
+ const u = d.dimensions[m], f = v(u.sql, o);
231
+ i[l] = f;
232
+ }
233
+ }
234
+ if (t.measures)
235
+ for (const l of t.measures) {
236
+ const [a, m] = l.split("."), d = e.get(a);
237
+ if (d && d.measures[m]) {
238
+ const u = d.measures[m], f = this.buildMeasureExpression(u, o);
239
+ i[l] = f;
240
+ }
241
+ }
242
+ if (t.timeDimensions)
243
+ for (const l of t.timeDimensions) {
244
+ const [a, m] = l.dimension.split("."), d = e.get(a);
245
+ if (d && d.dimensions[m]) {
246
+ const u = d.dimensions[m], f = this.buildTimeDimensionExpression(
247
+ u.sql,
248
+ l.granularity,
249
+ o
250
+ );
251
+ i[l.dimension] = f;
252
+ }
253
+ }
254
+ return i;
255
+ }
256
+ /**
257
+ * Build measure expression with aggregation (similar to single-cube approach)
258
+ */
259
+ buildMeasureExpression(e, t) {
260
+ let s = v(e.sql, t);
261
+ if (e.filters && e.filters.length > 0) {
262
+ const i = e.filters.map((o) => o(t));
263
+ s = y`CASE WHEN ${B(...i)} THEN ${s} END`;
264
+ }
265
+ switch (e.type) {
266
+ case "count":
267
+ return y`COUNT(${s})`;
268
+ case "countDistinct":
269
+ return y`COUNT(DISTINCT ${s})`;
270
+ case "sum":
271
+ return y`SUM(${s})`;
272
+ case "avg":
273
+ return y`AVG(${s})`;
274
+ case "min":
275
+ return y`MIN(${s})`;
276
+ case "max":
277
+ return y`MAX(${s})`;
278
+ case "number":
279
+ return s;
280
+ default:
281
+ return y`COUNT(${s})`;
282
+ }
283
+ }
284
+ /**
285
+ * Build time dimension expression (similar to single-cube approach)
286
+ */
287
+ buildTimeDimensionExpression(e, t, s) {
288
+ const i = v(e, s);
289
+ if (!t)
290
+ return i;
291
+ switch (t) {
292
+ case "year":
293
+ return y`DATE_TRUNC('year', ${i}::timestamptz)`;
294
+ case "quarter":
295
+ return y`DATE_TRUNC('quarter', ${i}::timestamptz)`;
296
+ case "month":
297
+ return y`DATE_TRUNC('month', ${i}::timestamptz)`;
298
+ case "week":
299
+ return y`DATE_TRUNC('week', ${i}::timestamptz)`;
300
+ case "day":
301
+ return y`DATE_TRUNC('day', ${i}::timestamptz)`;
302
+ case "hour":
303
+ return y`DATE_TRUNC('hour', ${i}::timestamptz)`;
304
+ case "minute":
305
+ return y`DATE_TRUNC('minute', ${i}::timestamptz)`;
306
+ case "second":
307
+ return y`DATE_TRUNC('second', ${i}::timestamptz)`;
308
+ default:
309
+ return i;
310
+ }
311
+ }
312
+ /**
313
+ * Build WHERE conditions for multi-cube query
314
+ */
315
+ buildMultiCubeWhereConditions(e, t, s) {
316
+ const i = [];
317
+ if (t.filters) {
318
+ for (const o of t.filters)
319
+ if ("member" in o) {
320
+ const [l] = o.member.split("."), a = e.get(l);
321
+ if (a) {
322
+ const m = this.buildFilterCondition(o, a, s);
323
+ m && i.push(m);
324
+ }
325
+ }
326
+ }
327
+ return i;
328
+ }
329
+ /**
330
+ * Filter condition builder (would reuse logic from DrizzleExecutor)
331
+ */
332
+ buildFilterCondition(e, t, s) {
333
+ if (e.operator === "equals" && e.values && e.values.length > 0) {
334
+ const [i, o] = e.member.split(".");
335
+ if (i === t.name) {
336
+ const l = t.dimensions[o] || t.measures[o];
337
+ if (l) {
338
+ const a = typeof l.sql == "function" ? l.sql(s) : l.sql;
339
+ return di(a, e.values[0]);
340
+ }
341
+ }
342
+ }
343
+ return null;
344
+ }
345
+ /**
346
+ * Build GROUP BY fields for multi-cube query
347
+ */
348
+ buildMultiCubeGroupByFields(e, t, s) {
349
+ const i = [];
350
+ if (!(t.measures && t.measures.length > 0))
351
+ return [];
352
+ const l = {
353
+ db: {},
354
+ schema: {},
355
+ securityContext: s
356
+ };
357
+ if (t.dimensions)
358
+ for (const a of t.dimensions) {
359
+ const [m, d] = a.split("."), u = e.get(m);
360
+ if (u && u.dimensions[d]) {
361
+ const f = u.dimensions[d], p = v(f.sql, l);
362
+ i.push(p);
363
+ }
364
+ }
365
+ if (t.timeDimensions)
366
+ for (const a of t.timeDimensions) {
367
+ const [m, d] = a.dimension.split("."), u = e.get(m);
368
+ if (u && u.dimensions[d]) {
369
+ const f = u.dimensions[d], p = this.buildTimeDimensionExpression(
370
+ f.sql,
371
+ a.granularity,
372
+ l
373
+ );
374
+ i.push(p);
375
+ }
376
+ }
377
+ return i;
378
+ }
379
+ }
380
+ class de {
5
381
  constructor(e) {
6
- this.dbExecutor = e;
382
+ r(this, "multiCubeBuilder");
383
+ this.dbExecutor = e, this.multiCubeBuilder = new yo();
384
+ }
385
+ /**
386
+ * Unified query execution method that handles both single and multi-cube queries
387
+ */
388
+ async execute(e, t, s) {
389
+ try {
390
+ const i = this.multiCubeBuilder.analyzeCubeUsage(t);
391
+ if (i.size === 0)
392
+ throw new Error("No cubes found for query");
393
+ if (i.size === 1) {
394
+ const o = Array.from(i)[0], l = e.get(o);
395
+ if (!l)
396
+ throw new Error(`Cube '${o}' not found`);
397
+ return this.executeSingleCube(l, t, s);
398
+ } else
399
+ return this.executeMultiCube(e, t, s);
400
+ } catch (i) {
401
+ throw new Error(`Query execution failed: ${i instanceof Error ? i.message : "Unknown error"}`);
402
+ }
403
+ }
404
+ /**
405
+ * Legacy interface for single cube queries
406
+ */
407
+ async executeQuery(e, t, s) {
408
+ const i = /* @__PURE__ */ new Map();
409
+ return i.set(e.name, e), this.execute(i, t, s);
410
+ }
411
+ /**
412
+ * Execute a single cube query
413
+ */
414
+ async executeSingleCube(e, t, s) {
415
+ return this.executeCube(e, t, s);
7
416
  }
8
- async executeQuery(e, n, i) {
417
+ /**
418
+ * Execute a Cube query (dynamic query building)
419
+ */
420
+ async executeCube(e, t, s) {
9
421
  try {
10
- const t = this.generateSQL(e, n, i), s = await this.dbExecutor.execute(t.sql, t.params), a = this.generateAnnotations(e, n);
422
+ const i = {
423
+ db: this.dbExecutor.db,
424
+ schema: this.dbExecutor.schema,
425
+ securityContext: s
426
+ }, o = e.sql(i), l = this.buildSelections(e, t, i);
427
+ let a = i.db.select(l).from(o.from);
428
+ if (o.joins)
429
+ for (const h of o.joins)
430
+ switch (h.type || "left") {
431
+ case "left":
432
+ a = a.leftJoin(h.table, h.on);
433
+ break;
434
+ case "inner":
435
+ a = a.innerJoin(h.table, h.on);
436
+ break;
437
+ case "right":
438
+ a = a.rightJoin(h.table, h.on);
439
+ break;
440
+ case "full":
441
+ a = a.fullJoin(h.table, h.on);
442
+ break;
443
+ }
444
+ o.where && (a = a.where(o.where));
445
+ const m = this.buildWhereConditions(e, t, i);
446
+ if (m.length > 0) {
447
+ const h = m.length === 1 ? m[0] : B(...m);
448
+ a = a.where(h);
449
+ }
450
+ const d = this.buildGroupByFields(e, t, i);
451
+ d.length > 0 && (a = a.groupBy(...d));
452
+ const u = this.buildOrderBy(t);
453
+ u.length > 0 && (a = a.orderBy(...u)), t.limit && (a = a.limit(t.limit)), t.offset && (a = a.offset(t.offset));
454
+ const f = await this.dbExecutor.execute(a), p = this.generateAnnotations(e, t);
11
455
  return {
12
- data: s,
13
- annotation: a
456
+ data: Array.isArray(f) ? f : [f],
457
+ annotation: p
14
458
  };
15
- } catch (t) {
16
- throw new Error(`Query execution failed: ${t instanceof Error ? t.message : "Unknown error"}`);
459
+ } catch (i) {
460
+ throw new Error(`Cube query execution failed: ${i instanceof Error ? i.message : "Unknown error"}`);
17
461
  }
18
462
  }
19
- generateSQL(e, n, i) {
20
- const t = this.substituteSecurityVariables(
21
- typeof e.sql == "string" ? e.sql : e.sql.toString(),
22
- i
23
- ), s = this.buildSelectClause(e, n), a = this.buildWhereClause(e, n), r = this.buildGroupByClause(e, n), o = this.buildOrderByClause(n), m = this.buildLimitClause(n), p = [
24
- `SELECT ${s.join(", ")}`,
25
- `FROM (${t}) as base_query`
26
- ];
27
- return a && p.push(`WHERE ${a}`), r && p.push(`GROUP BY ${r}`), o && p.push(`ORDER BY ${o}`), m && p.push(m), { sql: p.join(" "), params: [] };
463
+ /**
464
+ * Execute multi-cube query using JOIN resolution
465
+ */
466
+ async executeMultiCube(e, t, s) {
467
+ const i = {
468
+ db: this.dbExecutor.db,
469
+ schema: this.dbExecutor.schema,
470
+ securityContext: s
471
+ }, o = this.multiCubeBuilder.buildMultiCubeQueryPlan(e, t, i), l = o.primaryCube.sql(i);
472
+ let a = i.db.select(o.selections).from(l.from);
473
+ if (l.joins)
474
+ for (const h of l.joins)
475
+ switch (h.type || "left") {
476
+ case "left":
477
+ a = a.leftJoin(h.table, h.on);
478
+ break;
479
+ case "inner":
480
+ a = a.innerJoin(h.table, h.on);
481
+ break;
482
+ case "right":
483
+ a = a.rightJoin(h.table, h.on);
484
+ break;
485
+ case "full":
486
+ a = a.fullJoin(h.table, h.on);
487
+ break;
488
+ }
489
+ if (o.joinCubes && o.joinCubes.length > 0)
490
+ for (const h of o.joinCubes) {
491
+ const A = h.cube.sql(i);
492
+ switch (h.joinType || "left") {
493
+ case "left":
494
+ a = a.leftJoin(A.from, h.joinCondition);
495
+ break;
496
+ case "inner":
497
+ a = a.innerJoin(A.from, h.joinCondition);
498
+ break;
499
+ case "right":
500
+ a = a.rightJoin(A.from, h.joinCondition);
501
+ break;
502
+ case "full":
503
+ a = a.fullJoin(A.from, h.joinCondition);
504
+ break;
505
+ }
506
+ }
507
+ const m = [];
508
+ if (l.where && m.push(l.where), o.whereConditions.length > 0 && m.push(...o.whereConditions), m.length > 0) {
509
+ const h = m.length === 1 ? m[0] : B(...m);
510
+ a = a.where(h);
511
+ }
512
+ o.groupByFields.length > 0 && (a = a.groupBy(...o.groupByFields));
513
+ const d = this.buildOrderBy(t);
514
+ d.length > 0 && (a = a.orderBy(...d)), t.limit && (a = a.limit(t.limit)), t.offset && (a = a.offset(t.offset));
515
+ const u = a, f = await this.dbExecutor.execute(u), p = this.generateMultiCubeAnnotations(o, t);
516
+ return {
517
+ data: Array.isArray(f) ? f : [f],
518
+ annotation: p
519
+ };
520
+ }
521
+ /**
522
+ * Generate raw SQL for debugging (without execution)
523
+ */
524
+ async generateSQL(e, t, s) {
525
+ return this.generateCubeSQL(e, t, s);
28
526
  }
29
- substituteSecurityVariables(e, n) {
30
- let i = e;
31
- return Object.entries(n).forEach(([t, s]) => {
32
- const a = `\${SECURITY_CONTEXT.${t}}`;
33
- i = i.replaceAll(a, `'${s}'`);
34
- }), i;
527
+ /**
528
+ * Generate SQL for Cube
529
+ */
530
+ async generateCubeSQL(e, t, s) {
531
+ const i = {
532
+ db: this.dbExecutor.db,
533
+ schema: this.dbExecutor.schema,
534
+ securityContext: s
535
+ }, o = e.sql(i), l = this.buildSelections(e, t, i);
536
+ let a = i.db.select(l).from(o.from);
537
+ if (o.joins)
538
+ for (const p of o.joins)
539
+ switch (p.type || "left") {
540
+ case "left":
541
+ a = a.leftJoin(p.table, p.on);
542
+ break;
543
+ case "inner":
544
+ a = a.innerJoin(p.table, p.on);
545
+ break;
546
+ case "right":
547
+ a = a.rightJoin(p.table, p.on);
548
+ break;
549
+ case "full":
550
+ a = a.fullJoin(p.table, p.on);
551
+ break;
552
+ }
553
+ o.where && (a = a.where(o.where));
554
+ const m = this.buildWhereConditions(e, t, i);
555
+ if (m.length > 0) {
556
+ const p = m.length === 1 ? m[0] : B(...m);
557
+ a = a.where(p);
558
+ }
559
+ const d = this.buildGroupByFields(e, t, i);
560
+ d.length > 0 && (a = a.groupBy(...d));
561
+ const u = this.buildOrderBy(t);
562
+ u.length > 0 && (a = a.orderBy(...u)), t.limit && (a = a.limit(t.limit)), t.offset && (a = a.offset(t.offset));
563
+ const f = a.toSQL();
564
+ return {
565
+ sql: f.sql,
566
+ params: f.params
567
+ };
35
568
  }
36
- buildSelectClause(e, n) {
37
- const i = [];
38
- if (n.measures)
39
- for (const t of n.measures) {
40
- const [s, a] = t.split(".");
41
- if (s === e.name && e.measures[a]) {
42
- const r = e.measures[a], o = this.buildMeasureSQL(r, a);
43
- i.push(`${o} as "${t}"`);
569
+ /**
570
+ * Build dynamic selections for Cube measures and dimensions
571
+ */
572
+ buildSelections(e, t, s) {
573
+ const i = {};
574
+ if (t.dimensions)
575
+ for (const o of t.dimensions) {
576
+ const [l, a] = o.split(".");
577
+ if (l === e.name && e.dimensions[a]) {
578
+ const m = e.dimensions[a], d = v(m.sql, s);
579
+ i[o] = d;
44
580
  }
45
581
  }
46
- if (n.dimensions)
47
- for (const t of n.dimensions) {
48
- const [s, a] = t.split(".");
49
- if (s === e.name && e.dimensions[a]) {
50
- const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
51
- i.push(`${o} as "${t}"`);
582
+ if (t.measures)
583
+ for (const o of t.measures) {
584
+ const [l, a] = o.split(".");
585
+ if (l === e.name && e.measures[a]) {
586
+ const m = e.measures[a], d = this.buildMeasureExpression(m, s);
587
+ i[o] = d;
52
588
  }
53
589
  }
54
- if (n.timeDimensions)
55
- for (const t of n.timeDimensions) {
56
- const [s, a] = t.dimension.split(".");
57
- if (s === e.name && e.dimensions[a]) {
58
- const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
59
- if (t.granularity) {
60
- const m = `DATE_TRUNC('${t.granularity}', ${o})`;
61
- i.push(`${m} as "${t.dimension}"`);
62
- } else
63
- i.push(`${o} as "${t.dimension}"`);
590
+ if (t.timeDimensions)
591
+ for (const o of t.timeDimensions) {
592
+ const [l, a] = o.dimension.split(".");
593
+ if (l === e.name && e.dimensions[a]) {
594
+ const m = e.dimensions[a], d = this.buildTimeDimensionExpression(
595
+ m.sql,
596
+ o.granularity,
597
+ s
598
+ );
599
+ i[o.dimension] = d;
64
600
  }
65
601
  }
66
- return i.length > 0 ? i : ["1"];
602
+ return Object.keys(i).length === 0 && (i.count = Y()), i;
67
603
  }
68
- buildMeasureSQL(e, n) {
69
- const i = typeof e.sql == "string" ? e.sql : e.sql.toString();
604
+ /**
605
+ * Build measure expression with aggregation and filters for Cube
606
+ */
607
+ buildMeasureExpression(e, t) {
608
+ let s = v(e.sql, t);
609
+ if (e.filters && e.filters.length > 0) {
610
+ const i = e.filters.map((o) => o(t));
611
+ s = y`CASE WHEN ${B(...i)} THEN ${s} END`;
612
+ }
70
613
  switch (e.type) {
71
614
  case "count":
72
- return `COUNT(${i})`;
615
+ return Y(s);
73
616
  case "countDistinct":
74
- return `COUNT(DISTINCT ${i})`;
617
+ return ro(s);
75
618
  case "sum":
76
- return `SUM(${i})`;
619
+ return io(s);
77
620
  case "avg":
78
- return `AVG(${i})`;
621
+ return so(s);
79
622
  case "min":
80
- return `MIN(${i})`;
623
+ return no(s);
81
624
  case "max":
82
- return `MAX(${i})`;
625
+ return to(s);
83
626
  case "number":
84
- return i;
627
+ return s;
628
+ default:
629
+ return Y(s);
630
+ }
631
+ }
632
+ /**
633
+ * Build time dimension expression with granularity
634
+ */
635
+ buildTimeDimensionExpression(e, t, s) {
636
+ const i = v(e, s);
637
+ if (!t)
638
+ return i;
639
+ switch (t) {
640
+ case "year":
641
+ return y`DATE_TRUNC('year', ${i}::timestamptz)`;
642
+ case "quarter":
643
+ return y`DATE_TRUNC('quarter', ${i}::timestamptz)`;
644
+ case "month":
645
+ return y`DATE_TRUNC('month', ${i}::timestamptz)`;
646
+ case "week":
647
+ return y`DATE_TRUNC('week', ${i}::timestamptz)`;
648
+ case "day":
649
+ return y`DATE_TRUNC('day', ${i}::timestamptz)`;
650
+ case "hour":
651
+ return y`DATE_TRUNC('hour', ${i}::timestamptz)`;
652
+ case "minute":
653
+ return y`DATE_TRUNC('minute', ${i}::timestamptz)`;
654
+ case "second":
655
+ return y`DATE_TRUNC('second', ${i}::timestamptz)`;
85
656
  default:
86
- return `COUNT(${i})`;
657
+ return i;
87
658
  }
88
659
  }
89
- buildWhereClause(e, n) {
90
- if (!n.filters || n.filters.length === 0)
91
- return null;
660
+ /**
661
+ * Build WHERE conditions from semantic query filters (Cube)
662
+ */
663
+ buildWhereConditions(e, t, s) {
664
+ if (!t.filters || t.filters.length === 0)
665
+ return [];
92
666
  const i = [];
93
- for (const t of n.filters) {
94
- const [s, a] = t.member.split(".");
95
- if (s !== e.name) continue;
96
- const r = e.dimensions[a] || e.measures[a];
97
- if (!r) continue;
98
- const o = typeof r.sql == "string" ? r.sql : r.sql.toString(), m = this.buildFilterCondition(o, t.operator, t.values);
99
- m && i.push(m);
100
- }
101
- return i.length > 0 ? i.join(" AND ") : null;
102
- }
103
- buildFilterCondition(e, n, i) {
104
- const t = i[0], s = typeof t == "string" ? `'${t.replace(/'/g, "''")}'` : t;
105
- switch (n) {
667
+ for (const o of t.filters) {
668
+ const l = this.processFilter(o, e, s);
669
+ l && i.push(l);
670
+ }
671
+ return i;
672
+ }
673
+ /**
674
+ * Process a single filter for Cube (basic or logical)
675
+ */
676
+ processFilter(e, t, s) {
677
+ if ("and" in e || "or" in e) {
678
+ const d = e;
679
+ if (d.and) {
680
+ const u = d.and.map((f) => this.processFilter(f, t, s)).filter((f) => f !== null);
681
+ return u.length > 0 ? B(...u) : null;
682
+ }
683
+ if (d.or) {
684
+ const u = d.or.map((f) => this.processFilter(f, t, s)).filter((f) => f !== null);
685
+ return u.length > 0 ? oo(...u) : null;
686
+ }
687
+ }
688
+ const i = e, [o, l] = i.member.split(".");
689
+ if (o !== t.name) return null;
690
+ const a = t.dimensions[l] || t.measures[l];
691
+ if (!a) return null;
692
+ const m = v(a.sql, s);
693
+ return this.buildFilterCondition(m, i.operator, i.values);
694
+ }
695
+ /**
696
+ * Build filter condition using Drizzle operators
697
+ */
698
+ buildFilterCondition(e, t, s) {
699
+ const i = s[0];
700
+ switch (t) {
106
701
  case "equals":
107
- return `${e} = ${s}`;
702
+ return s.length > 1 ? y`${e} IN ${s}` : di(e, i);
108
703
  case "notEquals":
109
- return `${e} != ${s}`;
704
+ return s.length > 1 ? y`${e} NOT IN ${s}` : co(e, i);
110
705
  case "contains":
111
- return `${e} ILIKE '%${t}%'`;
706
+ return y`${e} ILIKE ${"%" + i + "%"}`;
112
707
  case "notContains":
113
- return `${e} NOT ILIKE '%${t}%'`;
708
+ return y`${e} NOT ILIKE ${"%" + i + "%"}`;
114
709
  case "startsWith":
115
- return `${e} ILIKE '${t}%'`;
710
+ return y`${e} ILIKE ${i + "%"}`;
116
711
  case "endsWith":
117
- return `${e} ILIKE '%${t}'`;
712
+ return y`${e} ILIKE ${"%" + i}`;
118
713
  case "gt":
119
- return `${e} > ${s}`;
714
+ return re(e, i);
120
715
  case "gte":
121
- return `${e} >= ${s}`;
716
+ return ae(e, i);
122
717
  case "lt":
123
- return `${e} < ${s}`;
718
+ return oe(e, i);
124
719
  case "lte":
125
- return `${e} <= ${s}`;
720
+ return ue(e, i);
126
721
  case "set":
127
- return `${e} IS NOT NULL`;
722
+ return uo(e);
128
723
  case "notSet":
129
- return `${e} IS NULL`;
724
+ return ao(e);
130
725
  case "inDateRange":
131
- return i.length >= 2 ? `${e} BETWEEN '${i[0]}' AND '${i[1]}'` : null;
726
+ return s.length >= 2 ? B(
727
+ ae(e, s[0]),
728
+ ue(e, s[1])
729
+ ) : null;
132
730
  case "beforeDate":
133
- return `${e} < '${t}'`;
731
+ return oe(e, i);
134
732
  case "afterDate":
135
- return `${e} > '${t}'`;
733
+ return re(e, i);
136
734
  default:
137
735
  return null;
138
736
  }
139
737
  }
140
- buildGroupByClause(e, n) {
738
+ /**
739
+ * Build GROUP BY fields from dimensions and time dimensions (Cube)
740
+ */
741
+ buildGroupByFields(e, t, s) {
141
742
  const i = [];
142
- if (n.dimensions)
143
- for (const t of n.dimensions) {
144
- const [s, a] = t.split(".");
145
- if (s === e.name && e.dimensions[a]) {
146
- const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
147
- i.push(o);
743
+ if (t.dimensions)
744
+ for (const o of t.dimensions) {
745
+ const [l, a] = o.split(".");
746
+ if (l === e.name && e.dimensions[a]) {
747
+ const m = e.dimensions[a], d = v(m.sql, s);
748
+ i.push(d);
148
749
  }
149
750
  }
150
- if (n.timeDimensions)
151
- for (const t of n.timeDimensions) {
152
- const [s, a] = t.dimension.split(".");
153
- if (s === e.name && e.dimensions[a]) {
154
- const r = e.dimensions[a], o = typeof r.sql == "string" ? r.sql : r.sql.toString();
155
- t.granularity ? i.push(`DATE_TRUNC('${t.granularity}', ${o})`) : i.push(o);
751
+ if (t.timeDimensions)
752
+ for (const o of t.timeDimensions) {
753
+ const [l, a] = o.dimension.split(".");
754
+ if (l === e.name && e.dimensions[a]) {
755
+ const m = e.dimensions[a], d = this.buildTimeDimensionExpression(
756
+ m.sql,
757
+ o.granularity,
758
+ s
759
+ );
760
+ i.push(d);
156
761
  }
157
762
  }
158
- return i.length > 0 ? i.join(", ") : null;
763
+ return i;
159
764
  }
160
- buildOrderByClause(e) {
765
+ /**
766
+ * Build ORDER BY clause
767
+ */
768
+ buildOrderBy(e) {
161
769
  if (!e.order || Object.keys(e.order).length === 0)
162
- return null;
163
- const n = [];
164
- for (const [i, t] of Object.entries(e.order))
165
- n.push(`"${i}" ${t.toUpperCase()}`);
166
- return n.join(", ");
167
- }
168
- buildLimitClause(e) {
169
- if (!e.limit)
170
- return null;
171
- let n = `LIMIT ${e.limit}`;
172
- return e.offset && (n += ` OFFSET ${e.offset}`), n;
173
- }
174
- generateAnnotations(e, n) {
175
- const i = {}, t = {}, s = {};
176
- if (n.measures)
177
- for (const a of n.measures) {
178
- const [r, o] = a.split(".");
179
- if (r === e.name && e.measures[o]) {
180
- const m = e.measures[o];
181
- i[a] = {
182
- title: m.title || o,
183
- shortTitle: m.title || o,
184
- type: m.type,
185
- format: m.format
770
+ return [];
771
+ const t = [];
772
+ for (const [s, i] of Object.entries(e.order)) {
773
+ const o = y.identifier(s), l = i === "desc" ? y`DESC` : y`ASC`;
774
+ t.push(y`${o} ${l}`);
775
+ }
776
+ return t;
777
+ }
778
+ /**
779
+ * Generate annotations for UI metadata
780
+ */
781
+ generateAnnotations(e, t) {
782
+ const s = {}, i = {}, o = {};
783
+ if (t.measures)
784
+ for (const l of t.measures) {
785
+ const [a, m] = l.split(".");
786
+ if (a === e.name && e.measures[m]) {
787
+ const d = e.measures[m];
788
+ s[l] = {
789
+ title: d.title || m,
790
+ shortTitle: d.title || m,
791
+ type: d.type
792
+ };
793
+ }
794
+ }
795
+ if (t.dimensions)
796
+ for (const l of t.dimensions) {
797
+ const [a, m] = l.split(".");
798
+ if (a === e.name && e.dimensions[m]) {
799
+ const d = e.dimensions[m];
800
+ i[l] = {
801
+ title: d.title || m,
802
+ shortTitle: d.title || m,
803
+ type: d.type
804
+ };
805
+ }
806
+ }
807
+ if (t.timeDimensions)
808
+ for (const l of t.timeDimensions) {
809
+ const [a, m] = l.dimension.split(".");
810
+ if (a === e.name && e.dimensions[m]) {
811
+ const d = e.dimensions[m];
812
+ o[l.dimension] = {
813
+ title: d.title || m,
814
+ shortTitle: d.title || m,
815
+ type: d.type,
816
+ granularity: l.granularity
817
+ };
818
+ }
819
+ }
820
+ return {
821
+ measures: s,
822
+ dimensions: i,
823
+ segments: {},
824
+ timeDimensions: o
825
+ };
826
+ }
827
+ /**
828
+ * Generate annotations for multi-cube queries
829
+ */
830
+ generateMultiCubeAnnotations(e, t) {
831
+ const s = {}, i = {}, o = {}, l = [e.primaryCube];
832
+ if (e.joinCubes && l.push(...e.joinCubes.map((a) => a.cube)), t.measures)
833
+ for (const a of t.measures) {
834
+ const [m, d] = a.split("."), u = l.find((f) => f.name === m);
835
+ if (u && u.measures[d]) {
836
+ const f = u.measures[d];
837
+ s[a] = {
838
+ title: f.title || d,
839
+ shortTitle: f.title || d,
840
+ type: f.type
186
841
  };
187
842
  }
188
843
  }
189
- if (n.dimensions)
190
- for (const a of n.dimensions) {
191
- const [r, o] = a.split(".");
192
- if (r === e.name && e.dimensions[o]) {
193
- const m = e.dimensions[o];
194
- t[a] = {
195
- title: m.title || o,
196
- shortTitle: m.title || o,
197
- type: m.type,
198
- format: m.format
844
+ if (t.dimensions)
845
+ for (const a of t.dimensions) {
846
+ const [m, d] = a.split("."), u = l.find((f) => f.name === m);
847
+ if (u && u.dimensions[d]) {
848
+ const f = u.dimensions[d];
849
+ i[a] = {
850
+ title: f.title || d,
851
+ shortTitle: f.title || d,
852
+ type: f.type
199
853
  };
200
854
  }
201
855
  }
202
- if (n.timeDimensions)
203
- for (const a of n.timeDimensions) {
204
- const [r, o] = a.dimension.split(".");
205
- if (r === e.name && e.dimensions[o]) {
206
- const m = e.dimensions[o];
207
- s[a.dimension] = {
208
- title: m.title || o,
209
- shortTitle: m.title || o,
210
- type: m.type,
856
+ if (t.timeDimensions)
857
+ for (const a of t.timeDimensions) {
858
+ const [m, d] = a.dimension.split("."), u = l.find((f) => f.name === m);
859
+ if (u && u.dimensions && u.dimensions[d]) {
860
+ const f = u.dimensions[d];
861
+ o[a.dimension] = {
862
+ title: f.title || d,
863
+ shortTitle: f.title || d,
864
+ type: f.type,
211
865
  granularity: a.granularity
212
866
  };
213
867
  }
214
868
  }
215
869
  return {
216
- measures: i,
217
- dimensions: t,
870
+ measures: s,
871
+ dimensions: i,
218
872
  segments: {},
219
- timeDimensions: s
873
+ timeDimensions: o
220
874
  };
221
875
  }
222
876
  }
223
- class d {
877
+ class te {
224
878
  constructor(e) {
225
- c(this, "cubes", /* @__PURE__ */ new Map());
226
- c(this, "dbExecutor");
227
- this.dbExecutor = e;
879
+ r(this, "cubes", /* @__PURE__ */ new Map());
880
+ r(this, "dbExecutor");
881
+ e != null && e.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e != null && e.drizzle && (this.dbExecutor = me(
882
+ e.drizzle,
883
+ e.schema,
884
+ e.engineType
885
+ ));
228
886
  }
887
+ /**
888
+ * Set or update the database executor
889
+ */
229
890
  setDatabaseExecutor(e) {
230
891
  this.dbExecutor = e;
231
892
  }
893
+ /**
894
+ * Set Drizzle instance and schema directly
895
+ */
896
+ setDrizzle(e, t, s) {
897
+ this.dbExecutor = me(e, t, s);
898
+ }
899
+ /**
900
+ * Check if database executor is configured
901
+ */
902
+ hasExecutor() {
903
+ return !!this.dbExecutor;
904
+ }
905
+ /**
906
+ * Register a simplified cube with dynamic query building
907
+ */
232
908
  registerCube(e) {
233
- this.validateCube(e);
234
- const n = this.compileCube(e);
235
- this.cubes.set(e.name, n);
909
+ this.cubes.set(e.name, e);
236
910
  }
911
+ /**
912
+ * Get a cube by name
913
+ */
237
914
  getCube(e) {
238
915
  return this.cubes.get(e);
239
916
  }
917
+ /**
918
+ * Get all registered cubes
919
+ */
240
920
  getAllCubes() {
241
921
  return Array.from(this.cubes.values());
242
922
  }
243
- getMetadata() {
244
- return Array.from(this.cubes.values()).map((e) => this.generateCubeMetadata(e));
923
+ /**
924
+ * Get all cubes as a Map for multi-cube queries
925
+ */
926
+ getAllCubesMap() {
927
+ return this.cubes;
928
+ }
929
+ /**
930
+ * Unified query execution method that handles both single and multi-cube queries
931
+ */
932
+ async execute(e, t) {
933
+ if (!this.dbExecutor)
934
+ throw new Error("Database executor not configured");
935
+ return new de(this.dbExecutor).execute(this.cubes, e, t);
245
936
  }
246
- validateCube(e) {
247
- if (!e.name)
248
- throw new Error("Cube must have a name");
249
- if (!e.sql)
250
- throw new Error(`Cube ${e.name} must have SQL definition`);
251
- if (!e.measures || Object.keys(e.measures).length === 0)
252
- throw new Error(`Cube ${e.name} must have at least one measure`);
937
+ /**
938
+ * Execute a multi-cube query
939
+ */
940
+ async executeMultiCubeQuery(e, t) {
941
+ return this.execute(e, t);
253
942
  }
254
- compileCube(e) {
255
- return {
256
- ...e,
257
- queryFn: async (i, t) => {
258
- if (!this.dbExecutor)
259
- throw new Error("Database executor not configured. Call setDatabaseExecutor() first.");
260
- return new f(this.dbExecutor).executeQuery(e, i, t);
261
- }
262
- };
943
+ /**
944
+ * Execute a single cube query
945
+ */
946
+ async executeQuery(e, t, s) {
947
+ if (!this.cubes.get(e))
948
+ throw new Error(`Cube '${e}' not found`);
949
+ return this.execute(t, s);
950
+ }
951
+ /**
952
+ * Get metadata for all cubes (for API responses)
953
+ */
954
+ getMetadata() {
955
+ return Array.from(this.cubes.values()).map((e) => this.generateCubeMetadata(e));
263
956
  }
957
+ /**
958
+ * Generate cube metadata for API responses from cubes
959
+ */
264
960
  generateCubeMetadata(e) {
265
- const n = Object.entries(e.measures).map(([t, s]) => ({
266
- name: `${e.name}.${t}`,
267
- title: s.title || t,
268
- shortTitle: s.title || t,
269
- type: s.type,
270
- format: s.format,
271
- description: s.description
272
- })), i = Object.entries(e.dimensions).map(([t, s]) => ({
273
- name: `${e.name}.${t}`,
274
- title: s.title || t,
275
- shortTitle: s.title || t,
276
- type: s.type,
277
- format: s.format,
278
- description: s.description
961
+ const t = Object.entries(e.measures).map(([i, o]) => ({
962
+ name: `${e.name}.${i}`,
963
+ title: o.title || i,
964
+ shortTitle: o.title || i,
965
+ type: o.type,
966
+ format: void 0,
967
+ // Measure doesn't have format field
968
+ description: o.description
969
+ })), s = Object.entries(e.dimensions).map(([i, o]) => ({
970
+ name: `${e.name}.${i}`,
971
+ title: o.title || i,
972
+ shortTitle: o.title || i,
973
+ type: o.type,
974
+ format: void 0,
975
+ // Dimension doesn't have format field
976
+ description: o.description
279
977
  }));
280
978
  return {
281
979
  name: e.name,
282
980
  title: e.title || e.name,
283
981
  description: e.description,
284
- measures: n,
285
- dimensions: i,
982
+ measures: t,
983
+ dimensions: s,
286
984
  segments: []
287
985
  // Add segments support later if needed
288
986
  };
289
987
  }
290
- }
291
- const E = new d(), g = {
292
- name: "Employees",
293
- title: "Employee Analytics",
294
- description: "Employee data for workforce analysis",
295
- sql: `
296
- SELECT
297
- e.id,
298
- e.name,
299
- e.email,
300
- e.active,
301
- e.fte_basis,
302
- e.start_date,
303
- e.end_date,
304
- d.name as department_name,
305
- s.name as supplier_name,
306
- s.internal as supplier_internal
307
- FROM employees e
308
- LEFT JOIN departments d ON e.department = d.id
309
- LEFT JOIN suppliers s ON e.supplier = s.id
310
- WHERE e.organisation = \${SECURITY_CONTEXT.organisation}
311
- `,
312
- dimensions: {
313
- id: {
314
- name: "id",
315
- title: "Employee ID",
316
- type: "string",
317
- sql: "id",
318
- primaryKey: !0
319
- },
320
- name: {
321
- name: "name",
322
- title: "Employee Name",
323
- type: "string",
324
- sql: "name"
325
- },
326
- email: {
327
- name: "email",
328
- title: "Email",
329
- type: "string",
330
- sql: "email"
331
- },
332
- active: {
333
- name: "active",
334
- title: "Active Status",
335
- type: "boolean",
336
- sql: "active"
337
- },
338
- departmentName: {
339
- name: "departmentName",
340
- title: "Department",
341
- type: "string",
342
- sql: "department_name"
343
- },
344
- supplierName: {
345
- name: "supplierName",
346
- title: "Supplier",
347
- type: "string",
348
- sql: "supplier_name"
349
- },
350
- supplierType: {
351
- name: "supplierType",
352
- title: "Supplier Type",
353
- type: "string",
354
- sql: "CASE WHEN supplier_internal THEN 'Internal' ELSE 'External' END"
355
- },
356
- startDate: {
357
- name: "startDate",
358
- title: "Start Date",
359
- type: "time",
360
- sql: "start_date"
361
- }
362
- },
363
- measures: {
364
- count: {
365
- name: "count",
366
- title: "Employee Count",
367
- type: "count",
368
- sql: "id"
369
- },
370
- activeCount: {
371
- name: "activeCount",
372
- title: "Active Employees",
373
- type: "count",
374
- sql: "id",
375
- filters: [{ sql: "active = true" }]
376
- },
377
- totalFte: {
378
- name: "totalFte",
379
- title: "Total FTE",
380
- type: "sum",
381
- sql: "fte_basis",
382
- format: "number"
383
- },
384
- averageFte: {
385
- name: "averageFte",
386
- title: "Average FTE",
387
- type: "avg",
388
- sql: "fte_basis",
389
- format: "number"
390
- }
391
- }
392
- }, C = {
393
- name: "Departments",
394
- title: "Department Analytics",
395
- description: "Organizational department data",
396
- sql: `
397
- SELECT
398
- d.id,
399
- d.name,
400
- d.description,
401
- COUNT(e.id) as employee_count
402
- FROM departments d
403
- LEFT JOIN employees e ON d.id = e.department AND e.active = true
404
- WHERE d.organisation = \${SECURITY_CONTEXT.organisation}
405
- GROUP BY d.id, d.name, d.description
406
- `,
407
- dimensions: {
408
- id: {
409
- name: "id",
410
- title: "Department ID",
411
- type: "string",
412
- sql: "id",
413
- primaryKey: !0
414
- },
415
- name: {
416
- name: "name",
417
- title: "Department Name",
418
- type: "string",
419
- sql: "name"
420
- },
421
- description: {
422
- name: "description",
423
- title: "Description",
424
- type: "string",
425
- sql: "description"
426
- }
427
- },
428
- measures: {
429
- count: {
430
- name: "count",
431
- title: "Department Count",
432
- type: "count",
433
- sql: "id"
434
- },
435
- employeeCount: {
436
- name: "employeeCount",
437
- title: "Employee Count",
438
- type: "sum",
439
- sql: "employee_count"
440
- }
441
- }
442
- }, $ = {
443
- name: "EmployeeDepartments",
444
- title: "Employee Department Analysis",
445
- description: "Combined employee and department analytics",
446
- sql: `
447
- SELECT
448
- e.id as employee_id,
449
- e.name as employee_name,
450
- e.active,
451
- e.fte_basis,
452
- d.id as department_id,
453
- d.name as department_name
454
- FROM employees e
455
- LEFT JOIN departments d ON e.department = d.id
456
- WHERE e.organisation = \${SECURITY_CONTEXT.organisation}
457
- `,
458
- dimensions: {
459
- employeeName: {
460
- name: "employeeName",
461
- title: "Employee Name",
462
- type: "string",
463
- sql: "employee_name"
464
- },
465
- departmentName: {
466
- name: "departmentName",
467
- title: "Department Name",
468
- type: "string",
469
- sql: "department_name"
470
- },
471
- active: {
472
- name: "active",
473
- title: "Active",
474
- type: "boolean",
475
- sql: "active"
476
- }
477
- },
478
- measures: {
479
- employeeCount: {
480
- name: "employeeCount",
481
- title: "Employee Count",
482
- type: "count",
483
- sql: "employee_id"
484
- },
485
- activeEmployeeCount: {
486
- name: "activeEmployeeCount",
487
- title: "Active Employee Count",
488
- type: "count",
489
- sql: "employee_id",
490
- filters: [{ sql: "active = true" }]
491
- },
492
- totalFte: {
493
- name: "totalFte",
494
- title: "Total FTE",
495
- type: "sum",
496
- sql: "fte_basis"
497
- }
498
- }
499
- }, T = [
500
- g,
501
- C,
502
- $
503
- ], v = E;
504
- function q(l) {
505
- return new d(l);
506
- }
507
- const D = {
508
988
  /**
509
- * Create a simple query builder
989
+ * Get SQL for a query without executing it (debugging)
510
990
  */
511
- query: (l) => {
512
- const e = (n, i = [], t = [], s = [], a, r) => ({
513
- measures: n,
514
- dimensions: i,
515
- filters: t,
516
- timeDimensions: s,
517
- limit: a,
518
- order: r
991
+ async generateSQL(e, t, s) {
992
+ const i = this.getCube(e);
993
+ if (!i)
994
+ throw new Error(`Cube '${e}' not found`);
995
+ if (!this.dbExecutor)
996
+ throw new Error("Database executor not configured");
997
+ return new de(this.dbExecutor).generateSQL(i, t, s);
998
+ }
999
+ /**
1000
+ * Check if a cube exists
1001
+ */
1002
+ hasCube(e) {
1003
+ return this.cubes.has(e);
1004
+ }
1005
+ /**
1006
+ * Remove a cube
1007
+ */
1008
+ removeCube(e) {
1009
+ return this.cubes.delete(e);
1010
+ }
1011
+ /**
1012
+ * Clear all cubes
1013
+ */
1014
+ clearCubes() {
1015
+ this.cubes.clear();
1016
+ }
1017
+ /**
1018
+ * Get cube names
1019
+ */
1020
+ getCubeNames() {
1021
+ return Array.from(this.cubes.keys());
1022
+ }
1023
+ }
1024
+ function Da(n) {
1025
+ return new te(n);
1026
+ }
1027
+ const wo = new te();
1028
+ function xo(n) {
1029
+ const e = {
1030
+ valid: !0,
1031
+ errors: [],
1032
+ warnings: [],
1033
+ cubes: []
1034
+ };
1035
+ try {
1036
+ const t = lo(n);
1037
+ if (!t)
1038
+ return e.valid = !1, e.errors.push("Invalid YAML: empty or malformed content"), e;
1039
+ if (t.cubes && Array.isArray(t.cubes))
1040
+ e.cubes = t.cubes;
1041
+ else if (t.name)
1042
+ e.cubes = [t];
1043
+ else
1044
+ return e.valid = !1, e.errors.push('YAML must contain either a "cubes" array or cube properties at root level'), e;
1045
+ for (const s of e.cubes) {
1046
+ const i = No(s);
1047
+ e.errors.push(...i);
1048
+ }
1049
+ e.valid = e.errors.length === 0;
1050
+ } catch (t) {
1051
+ e.valid = !1, e.errors.push(`YAML parsing error: ${t instanceof Error ? t.message : String(t)}`);
1052
+ }
1053
+ return e;
1054
+ }
1055
+ function No(n) {
1056
+ const e = [];
1057
+ return n.name || e.push("Cube name is required"), !n.sql && !n.sql_table && !n.sqlTable && e.push('Cube must have either "sql", "sql_table", or "sqlTable" property'), n.dimensions && n.dimensions.forEach((t, s) => {
1058
+ t.name || e.push(`Dimension at index ${s} is missing name`), t.type || e.push(`Dimension "${t.name}" is missing type`), t.sql || e.push(`Dimension "${t.name}" is missing sql`);
1059
+ }), n.measures && n.measures.forEach((t, s) => {
1060
+ t.name || e.push(`Measure at index ${s} is missing name`), t.type || e.push(`Measure "${t.name}" is missing type`), t.sql || e.push(`Measure "${t.name}" is missing sql`);
1061
+ }), n.joins && n.joins.forEach((t, s) => {
1062
+ t.name || e.push(`Join at index ${s} is missing name`), t.relationship || e.push(`Join "${t.name}" is missing relationship`), t.sql || e.push(`Join "${t.name}" is missing sql`);
1063
+ }), e;
1064
+ }
1065
+ function To(n) {
1066
+ const e = {};
1067
+ n.dimensions && n.dimensions.forEach((a) => {
1068
+ e[a.name] = Co(a);
1069
+ });
1070
+ const t = {};
1071
+ n.measures && n.measures.forEach((a) => {
1072
+ t[a.name] = So(a);
1073
+ });
1074
+ const s = {};
1075
+ n.joins && n.joins.forEach((a) => {
1076
+ s[a.name] = vo(a);
1077
+ });
1078
+ const i = {};
1079
+ (n.pre_aggregations || n.preAggregations) && (n.pre_aggregations || n.preAggregations || []).forEach((m) => {
1080
+ i[m.name] = Eo(m);
1081
+ });
1082
+ let o = n.sql;
1083
+ !o && (n.sql_table || n.sqlTable) && (o = `SELECT * FROM ${n.sql_table || n.sqlTable}`);
1084
+ const l = n.refresh_key || n.refreshKey;
1085
+ return {
1086
+ name: n.name,
1087
+ title: n.title,
1088
+ description: n.description,
1089
+ sql: o || "",
1090
+ sqlAlias: n.sql_alias || n.sqlAlias,
1091
+ dataSource: n.data_source || n.dataSource,
1092
+ refreshKey: l ? {
1093
+ every: l.every,
1094
+ sql: l.sql
1095
+ } : void 0,
1096
+ dimensions: e,
1097
+ measures: t,
1098
+ joins: Object.keys(s).length > 0 ? s : void 0,
1099
+ preAggregations: Object.keys(i).length > 0 ? i : void 0,
1100
+ meta: n.meta
1101
+ };
1102
+ }
1103
+ function Co(n) {
1104
+ return {
1105
+ name: n.name,
1106
+ title: n.title,
1107
+ description: n.description,
1108
+ type: n.type,
1109
+ sql: n.sql,
1110
+ primaryKey: n.primary_key || n.primaryKey,
1111
+ shown: n.shown,
1112
+ format: n.format,
1113
+ meta: n.meta
1114
+ };
1115
+ }
1116
+ function So(n) {
1117
+ var s;
1118
+ const e = (s = n.filters) == null ? void 0 : s.map((i) => ({
1119
+ sql: i.sql
1120
+ })), t = n.rolling_window || n.rollingWindow;
1121
+ return {
1122
+ name: n.name,
1123
+ title: n.title,
1124
+ description: n.description,
1125
+ type: n.type,
1126
+ sql: n.sql,
1127
+ format: n.format,
1128
+ shown: n.shown,
1129
+ filters: e,
1130
+ rollingWindow: t,
1131
+ meta: n.meta
1132
+ };
1133
+ }
1134
+ function Po(n) {
1135
+ switch (n) {
1136
+ case "one_to_one":
1137
+ return "hasOne";
1138
+ case "one_to_many":
1139
+ return "hasMany";
1140
+ case "many_to_one":
1141
+ return "belongsTo";
1142
+ default:
1143
+ return "belongsTo";
1144
+ }
1145
+ }
1146
+ function Do(n) {
1147
+ switch (n) {
1148
+ case "hasOne":
1149
+ return "one_to_one";
1150
+ case "hasMany":
1151
+ return "one_to_many";
1152
+ case "belongsTo":
1153
+ return "many_to_one";
1154
+ default:
1155
+ return "many_to_one";
1156
+ }
1157
+ }
1158
+ function vo(n) {
1159
+ return {
1160
+ name: n.name,
1161
+ type: n.type,
1162
+ relationship: Po(n.relationship),
1163
+ sql: n.sql
1164
+ };
1165
+ }
1166
+ function Eo(n) {
1167
+ const e = n.time_dimension || n.timeDimension, t = n.refresh_key || n.refreshKey;
1168
+ return {
1169
+ name: n.name,
1170
+ measures: n.measures,
1171
+ dimensions: n.dimensions,
1172
+ timeDimension: e,
1173
+ refreshKey: t,
1174
+ indexes: n.indexes
1175
+ };
1176
+ }
1177
+ async function $o() {
1178
+ try {
1179
+ const { promises: n } = await import("fs"), e = await n.readFile("non-existent-file.txt", "utf-8").catch((t) => t.message);
1180
+ return !(typeof e == "string" && e.includes("not implemented"));
1181
+ } catch {
1182
+ return !1;
1183
+ }
1184
+ }
1185
+ function Bo(n) {
1186
+ const e = xo(n);
1187
+ if (!e.valid)
1188
+ throw new Error(`Invalid YAML cube definition:
1189
+ ${e.errors.join(`
1190
+ `)}`);
1191
+ return e.cubes.map((t) => To(t));
1192
+ }
1193
+ async function va(n) {
1194
+ if (!await $o())
1195
+ return console.log("ℹ️ YAML file loading not supported in this environment (Cloudflare Workers/Edge Runtime). Use inline YAML strings or build-time transformations instead."), [];
1196
+ try {
1197
+ const { promises: t } = await import("fs"), s = await t.readFile(n, "utf-8");
1198
+ return Bo(s);
1199
+ } catch (t) {
1200
+ return console.log(`ℹ️ Could not load YAML file ${n}:`, t instanceof Error ? t.message : t), [];
1201
+ }
1202
+ }
1203
+ function Ea(n) {
1204
+ let e = n;
1205
+ 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;
1206
+ }
1207
+ function $a(n) {
1208
+ const e = {
1209
+ name: n.name,
1210
+ title: n.title,
1211
+ description: n.description,
1212
+ sql: typeof n.sql == "string" ? n.sql : void 0,
1213
+ dimensions: Object.values(n.dimensions).map((t) => ({
1214
+ name: t.name,
1215
+ title: t.title,
1216
+ description: t.description,
1217
+ type: t.type,
1218
+ sql: typeof t.sql == "string" ? t.sql : "",
1219
+ primary_key: t.primaryKey,
1220
+ shown: t.shown,
1221
+ format: t.format,
1222
+ meta: t.meta
1223
+ })),
1224
+ measures: Object.values(n.measures).map((t) => {
1225
+ var s;
1226
+ return {
1227
+ name: t.name,
1228
+ title: t.title,
1229
+ description: t.description,
1230
+ type: t.type,
1231
+ sql: typeof t.sql == "string" ? t.sql : "",
1232
+ format: t.format,
1233
+ shown: t.shown,
1234
+ filters: (s = t.filters) == null ? void 0 : s.map((i) => ({
1235
+ sql: typeof i.sql == "string" ? i.sql : ""
1236
+ })),
1237
+ rolling_window: t.rollingWindow,
1238
+ meta: t.meta
1239
+ };
1240
+ }),
1241
+ joins: n.joins ? Object.values(n.joins).map((t) => ({
1242
+ name: t.name || "",
1243
+ type: t.type,
1244
+ relationship: Do(t.relationship),
1245
+ sql: typeof t.sql == "string" ? t.sql : ""
1246
+ })) : void 0,
1247
+ meta: n.meta
1248
+ };
1249
+ return mo(e, {
1250
+ indent: 2,
1251
+ lineWidth: 120,
1252
+ minContentWidth: 40
1253
+ });
1254
+ }
1255
+ const c = Symbol.for("drizzle:entityKind");
1256
+ function T(n, e) {
1257
+ if (!n || typeof n != "object")
1258
+ return !1;
1259
+ if (n instanceof e)
1260
+ return !0;
1261
+ if (!Object.prototype.hasOwnProperty.call(e, c))
1262
+ throw new Error(
1263
+ `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.`
1264
+ );
1265
+ let t = Object.getPrototypeOf(n).constructor;
1266
+ if (t)
1267
+ for (; t; ) {
1268
+ if (c in t && t[c] === e[c])
1269
+ return !0;
1270
+ t = Object.getPrototypeOf(t);
1271
+ }
1272
+ return !1;
1273
+ }
1274
+ var xe;
1275
+ xe = c;
1276
+ class K {
1277
+ constructor(e, t) {
1278
+ r(this, "name");
1279
+ r(this, "keyAsName");
1280
+ r(this, "primary");
1281
+ r(this, "notNull");
1282
+ r(this, "default");
1283
+ r(this, "defaultFn");
1284
+ r(this, "onUpdateFn");
1285
+ r(this, "hasDefault");
1286
+ r(this, "isUnique");
1287
+ r(this, "uniqueName");
1288
+ r(this, "uniqueType");
1289
+ r(this, "dataType");
1290
+ r(this, "columnType");
1291
+ r(this, "enumValues");
1292
+ r(this, "generated");
1293
+ r(this, "generatedIdentity");
1294
+ r(this, "config");
1295
+ 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;
1296
+ }
1297
+ mapFromDriverValue(e) {
1298
+ return e;
1299
+ }
1300
+ mapToDriverValue(e) {
1301
+ return e;
1302
+ }
1303
+ // ** @internal */
1304
+ shouldDisableInsert() {
1305
+ return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
1306
+ }
1307
+ }
1308
+ r(K, xe, "Column");
1309
+ var Ne;
1310
+ Ne = c;
1311
+ class fi {
1312
+ constructor(e, t, s) {
1313
+ r(this, "config");
1314
+ /**
1315
+ * Alias for {@link $defaultFn}.
1316
+ */
1317
+ r(this, "$default", this.$defaultFn);
1318
+ /**
1319
+ * Alias for {@link $onUpdateFn}.
1320
+ */
1321
+ r(this, "$onUpdate", this.$onUpdateFn);
1322
+ this.config = {
1323
+ name: e,
1324
+ keyAsName: e === "",
1325
+ notNull: !1,
1326
+ default: void 0,
1327
+ hasDefault: !1,
1328
+ primaryKey: !1,
1329
+ isUnique: !1,
1330
+ uniqueName: void 0,
1331
+ uniqueType: void 0,
1332
+ dataType: t,
1333
+ columnType: s,
1334
+ generated: void 0
1335
+ };
1336
+ }
1337
+ /**
1338
+ * Changes the data type of the column. Commonly used with `json` columns. Also, useful for branded types.
1339
+ *
1340
+ * @example
1341
+ * ```ts
1342
+ * const users = pgTable('users', {
1343
+ * id: integer('id').$type<UserId>().primaryKey(),
1344
+ * details: json('details').$type<UserDetails>().notNull(),
1345
+ * });
1346
+ * ```
1347
+ */
1348
+ $type() {
1349
+ return this;
1350
+ }
1351
+ /**
1352
+ * Adds a `not null` clause to the column definition.
1353
+ *
1354
+ * Affects the `select` model of the table - columns *without* `not null` will be nullable on select.
1355
+ */
1356
+ notNull() {
1357
+ return this.config.notNull = !0, this;
1358
+ }
1359
+ /**
1360
+ * Adds a `default <value>` clause to the column definition.
1361
+ *
1362
+ * Affects the `insert` model of the table - columns *with* `default` are optional on insert.
1363
+ *
1364
+ * If you need to set a dynamic default value, use {@link $defaultFn} instead.
1365
+ */
1366
+ default(e) {
1367
+ return this.config.default = e, this.config.hasDefault = !0, this;
1368
+ }
1369
+ /**
1370
+ * Adds a dynamic default value to the column.
1371
+ * The function will be called when the row is inserted, and the returned value will be used as the column value.
1372
+ *
1373
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
1374
+ */
1375
+ $defaultFn(e) {
1376
+ return this.config.defaultFn = e, this.config.hasDefault = !0, this;
1377
+ }
1378
+ /**
1379
+ * Adds a dynamic update value to the column.
1380
+ * The function will be called when the row is updated, and the returned value will be used as the column value if none is provided.
1381
+ * If no `default` (or `$defaultFn`) value is provided, the function will be called when the row is inserted as well, and the returned value will be used as the column value.
1382
+ *
1383
+ * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
1384
+ */
1385
+ $onUpdateFn(e) {
1386
+ return this.config.onUpdateFn = e, this.config.hasDefault = !0, this;
1387
+ }
1388
+ /**
1389
+ * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
1390
+ *
1391
+ * In SQLite, `integer primary key` implicitly makes the column auto-incrementing.
1392
+ */
1393
+ primaryKey() {
1394
+ return this.config.primaryKey = !0, this.config.notNull = !0, this;
1395
+ }
1396
+ /** @internal Sets the name of the column to the key within the table definition if a name was not given. */
1397
+ setName(e) {
1398
+ this.config.name === "" && (this.config.name = e);
1399
+ }
1400
+ }
1401
+ r(fi, Ne, "ColumnBuilder");
1402
+ const Q = Symbol.for("drizzle:Name");
1403
+ var Te;
1404
+ Te = c;
1405
+ class pi {
1406
+ constructor(e, t) {
1407
+ /** @internal */
1408
+ r(this, "reference");
1409
+ /** @internal */
1410
+ r(this, "_onUpdate", "no action");
1411
+ /** @internal */
1412
+ r(this, "_onDelete", "no action");
1413
+ this.reference = () => {
1414
+ const { name: s, columns: i, foreignColumns: o } = e();
1415
+ return { name: s, columns: i, foreignTable: o[0].table, foreignColumns: o };
1416
+ }, t && (this._onUpdate = t.onUpdate, this._onDelete = t.onDelete);
1417
+ }
1418
+ onUpdate(e) {
1419
+ return this._onUpdate = e === void 0 ? "no action" : e, this;
1420
+ }
1421
+ onDelete(e) {
1422
+ return this._onDelete = e === void 0 ? "no action" : e, this;
1423
+ }
1424
+ /** @internal */
1425
+ build(e) {
1426
+ return new hi(e, this);
1427
+ }
1428
+ }
1429
+ r(pi, Te, "PgForeignKeyBuilder");
1430
+ var Ce;
1431
+ Ce = c;
1432
+ class hi {
1433
+ constructor(e, t) {
1434
+ r(this, "reference");
1435
+ r(this, "onUpdate");
1436
+ r(this, "onDelete");
1437
+ this.table = e, this.reference = t.reference, this.onUpdate = t._onUpdate, this.onDelete = t._onDelete;
1438
+ }
1439
+ getName() {
1440
+ const { name: e, columns: t, foreignColumns: s } = this.reference(), i = t.map((a) => a.name), o = s.map((a) => a.name), l = [
1441
+ this.table[Q],
1442
+ ...i,
1443
+ s[0].table[Q],
1444
+ ...o
1445
+ ];
1446
+ return e ?? `${l.join("_")}_fk`;
1447
+ }
1448
+ }
1449
+ r(hi, Ce, "PgForeignKey");
1450
+ function zo(n, ...e) {
1451
+ return n(...e);
1452
+ }
1453
+ function Fo(n, e) {
1454
+ return `${n[Q]}_${e.join("_")}_unique`;
1455
+ }
1456
+ function fe(n, e, t) {
1457
+ for (let s = e; s < n.length; s++) {
1458
+ const i = n[s];
1459
+ if (i === "\\") {
1460
+ s++;
1461
+ continue;
1462
+ }
1463
+ if (i === '"')
1464
+ return [n.slice(e, s).replace(/\\/g, ""), s + 1];
1465
+ if (!t && (i === "," || i === "}"))
1466
+ return [n.slice(e, s).replace(/\\/g, ""), s];
1467
+ }
1468
+ return [n.slice(e).replace(/\\/g, ""), n.length];
1469
+ }
1470
+ function gi(n, e = 0) {
1471
+ const t = [];
1472
+ let s = e, i = !1;
1473
+ for (; s < n.length; ) {
1474
+ const o = n[s];
1475
+ if (o === ",") {
1476
+ (i || s === e) && t.push(""), i = !0, s++;
1477
+ continue;
1478
+ }
1479
+ if (i = !1, o === "\\") {
1480
+ s += 2;
1481
+ continue;
1482
+ }
1483
+ if (o === '"') {
1484
+ const [m, d] = fe(n, s + 1, !0);
1485
+ t.push(m), s = d;
1486
+ continue;
1487
+ }
1488
+ if (o === "}")
1489
+ return [t, s + 1];
1490
+ if (o === "{") {
1491
+ const [m, d] = gi(n, s + 1);
1492
+ t.push(m), s = d;
1493
+ continue;
1494
+ }
1495
+ const [l, a] = fe(n, s, !1);
1496
+ t.push(l), s = a;
1497
+ }
1498
+ return [t, s];
1499
+ }
1500
+ function Lo(n) {
1501
+ const [e] = gi(n, 1);
1502
+ return e;
1503
+ }
1504
+ function bi(n) {
1505
+ return `{${n.map((e) => Array.isArray(e) ? bi(e) : typeof e == "string" ? `"${e.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"` : `${e}`).join(",")}}`;
1506
+ }
1507
+ var Se, Pe;
1508
+ class b extends (Pe = fi, Se = c, Pe) {
1509
+ constructor() {
1510
+ super(...arguments);
1511
+ r(this, "foreignKeyConfigs", []);
1512
+ }
1513
+ array(t) {
1514
+ return new wi(this.config.name, this, t);
1515
+ }
1516
+ references(t, s = {}) {
1517
+ return this.foreignKeyConfigs.push({ ref: t, actions: s }), this;
1518
+ }
1519
+ unique(t, s) {
1520
+ return this.config.isUnique = !0, this.config.uniqueName = t, this.config.uniqueType = s == null ? void 0 : s.nulls, this;
1521
+ }
1522
+ generatedAlwaysAs(t) {
1523
+ return this.config.generated = {
1524
+ as: t,
1525
+ type: "always",
1526
+ mode: "stored"
1527
+ }, this;
1528
+ }
1529
+ /** @internal */
1530
+ buildForeignKeys(t, s) {
1531
+ return this.foreignKeyConfigs.map(({ ref: i, actions: o }) => zo(
1532
+ (l, a) => {
1533
+ const m = new pi(() => {
1534
+ const d = l();
1535
+ return { columns: [t], foreignColumns: [d] };
1536
+ });
1537
+ return a.onUpdate && m.onUpdate(a.onUpdate), a.onDelete && m.onDelete(a.onDelete), m.build(s);
1538
+ },
1539
+ i,
1540
+ o
1541
+ ));
1542
+ }
1543
+ /** @internal */
1544
+ buildExtraConfigColumn(t) {
1545
+ return new yi(t, this.config);
1546
+ }
1547
+ }
1548
+ r(b, Se, "PgColumnBuilder");
1549
+ var De, ve;
1550
+ class g extends (ve = K, De = c, ve) {
1551
+ constructor(e, t) {
1552
+ t.uniqueName || (t.uniqueName = Fo(e, [t.name])), super(e, t), this.table = e;
1553
+ }
1554
+ }
1555
+ r(g, De, "PgColumn");
1556
+ var Ee, $e;
1557
+ class yi extends ($e = g, Ee = c, $e) {
1558
+ constructor() {
1559
+ super(...arguments);
1560
+ r(this, "indexConfig", {
1561
+ order: this.config.order ?? "asc",
1562
+ nulls: this.config.nulls ?? "last",
1563
+ opClass: this.config.opClass
1564
+ });
1565
+ r(this, "defaultConfig", {
1566
+ order: "asc",
1567
+ nulls: "last",
1568
+ opClass: void 0
1569
+ });
1570
+ }
1571
+ getSQLType() {
1572
+ return this.getSQLType();
1573
+ }
1574
+ asc() {
1575
+ return this.indexConfig.order = "asc", this;
1576
+ }
1577
+ desc() {
1578
+ return this.indexConfig.order = "desc", this;
1579
+ }
1580
+ nullsFirst() {
1581
+ return this.indexConfig.nulls = "first", this;
1582
+ }
1583
+ nullsLast() {
1584
+ return this.indexConfig.nulls = "last", this;
1585
+ }
1586
+ /**
1587
+ * ### PostgreSQL documentation quote
1588
+ *
1589
+ * > An operator class with optional parameters can be specified for each column of an index.
1590
+ * The operator class identifies the operators to be used by the index for that column.
1591
+ * For example, a B-tree index on four-byte integers would use the int4_ops class;
1592
+ * this operator class includes comparison functions for four-byte integers.
1593
+ * In practice the default operator class for the column's data type is usually sufficient.
1594
+ * The main point of having operator classes is that for some data types, there could be more than one meaningful ordering.
1595
+ * For example, we might want to sort a complex-number data type either by absolute value or by real part.
1596
+ * We could do this by defining two operator classes for the data type and then selecting the proper class when creating an index.
1597
+ * More information about operator classes check:
1598
+ *
1599
+ * ### Useful links
1600
+ * https://www.postgresql.org/docs/current/sql-createindex.html
1601
+ *
1602
+ * https://www.postgresql.org/docs/current/indexes-opclass.html
1603
+ *
1604
+ * https://www.postgresql.org/docs/current/xindex.html
1605
+ *
1606
+ * ### Additional types
1607
+ * If you have the `pg_vector` extension installed in your database, you can use the
1608
+ * `vector_l2_ops`, `vector_ip_ops`, `vector_cosine_ops`, `vector_l1_ops`, `bit_hamming_ops`, `bit_jaccard_ops`, `halfvec_l2_ops`, `sparsevec_l2_ops` options, which are predefined types.
1609
+ *
1610
+ * **You can always specify any string you want in the operator class, in case Drizzle doesn't have it natively in its types**
1611
+ *
1612
+ * @param opClass
1613
+ * @returns
1614
+ */
1615
+ op(t) {
1616
+ return this.indexConfig.opClass = t, this;
1617
+ }
1618
+ }
1619
+ r(yi, Ee, "ExtraConfigColumn");
1620
+ var Be, ze;
1621
+ class wi extends (ze = b, Be = c, ze) {
1622
+ constructor(e, t, s) {
1623
+ super(e, "array", "PgArray"), this.config.baseBuilder = t, this.config.size = s;
1624
+ }
1625
+ /** @internal */
1626
+ build(e) {
1627
+ const t = this.config.baseBuilder.build(e);
1628
+ return new X(
1629
+ e,
1630
+ this.config,
1631
+ t
1632
+ );
1633
+ }
1634
+ }
1635
+ r(wi, Be, "PgArrayBuilder");
1636
+ var Fe, Le;
1637
+ const R = class R extends (Le = g, Fe = c, Le) {
1638
+ constructor(t, s, i, o) {
1639
+ super(t, s);
1640
+ r(this, "size");
1641
+ this.baseColumn = i, this.range = o, this.size = s.size;
1642
+ }
1643
+ getSQLType() {
1644
+ return `${this.baseColumn.getSQLType()}[${typeof this.size == "number" ? this.size : ""}]`;
1645
+ }
1646
+ mapFromDriverValue(t) {
1647
+ return typeof t == "string" && (t = Lo(t)), t.map((s) => this.baseColumn.mapFromDriverValue(s));
1648
+ }
1649
+ mapToDriverValue(t, s = !1) {
1650
+ const i = t.map(
1651
+ (o) => o === null ? null : T(this.baseColumn, R) ? this.baseColumn.mapToDriverValue(o, !0) : this.baseColumn.mapToDriverValue(o)
1652
+ );
1653
+ return s ? i : bi(i);
1654
+ }
1655
+ };
1656
+ r(R, Fe, "PgArray");
1657
+ let X = R;
1658
+ const pe = Symbol.for("drizzle:isPgEnum");
1659
+ function Ao(n) {
1660
+ return !!n && typeof n == "function" && pe in n && n[pe] === !0;
1661
+ }
1662
+ var Ae;
1663
+ Ae = c;
1664
+ class ne {
1665
+ constructor(e, t, s, i = !1, o = []) {
1666
+ this._ = {
1667
+ brand: "Subquery",
1668
+ sql: e,
1669
+ selectedFields: t,
1670
+ alias: s,
1671
+ isWith: i,
1672
+ usedTables: o
1673
+ };
1674
+ }
1675
+ // getSQL(): SQL<unknown> {
1676
+ // return new SQL([this]);
1677
+ // }
1678
+ }
1679
+ r(ne, Ae, "Subquery");
1680
+ const Qo = {
1681
+ startActiveSpan(n, e) {
1682
+ return e();
1683
+ }
1684
+ }, I = Symbol.for("drizzle:ViewBaseConfig"), G = Symbol.for("drizzle:Schema"), he = Symbol.for("drizzle:Columns"), ge = Symbol.for("drizzle:ExtraConfigColumns"), H = Symbol.for("drizzle:OriginalName"), Z = Symbol.for("drizzle:BaseName"), _ = Symbol.for("drizzle:IsAlias"), be = Symbol.for("drizzle:ExtraConfigBuilder"), Vo = Symbol.for("drizzle:IsDrizzleTable");
1685
+ var Qe, Ve, Ie, je, _e, Ue, qe, Oe, Me, Re;
1686
+ Re = c, Me = Q, Oe = H, qe = G, Ue = he, _e = ge, je = Z, Ie = _, Ve = Vo, Qe = be;
1687
+ class w {
1688
+ constructor(e, t, s) {
1689
+ /**
1690
+ * @internal
1691
+ * Can be changed if the table is aliased.
1692
+ */
1693
+ r(this, Me);
1694
+ /**
1695
+ * @internal
1696
+ * Used to store the original name of the table, before any aliasing.
1697
+ */
1698
+ r(this, Oe);
1699
+ /** @internal */
1700
+ r(this, qe);
1701
+ /** @internal */
1702
+ r(this, Ue);
1703
+ /** @internal */
1704
+ r(this, _e);
1705
+ /**
1706
+ * @internal
1707
+ * Used to store the table name before the transformation via the `tableCreator` functions.
1708
+ */
1709
+ r(this, je);
1710
+ /** @internal */
1711
+ r(this, Ie, !1);
1712
+ /** @internal */
1713
+ r(this, Ve, !0);
1714
+ /** @internal */
1715
+ r(this, Qe);
1716
+ this[Q] = this[H] = e, this[G] = t, this[Z] = s;
1717
+ }
1718
+ }
1719
+ r(w, Re, "Table"), /** @internal */
1720
+ r(w, "Symbol", {
1721
+ Name: Q,
1722
+ Schema: G,
1723
+ OriginalName: H,
1724
+ Columns: he,
1725
+ ExtraConfigColumns: ge,
1726
+ BaseName: Z,
1727
+ IsAlias: _,
1728
+ ExtraConfigBuilder: be
1729
+ });
1730
+ function Io(n) {
1731
+ return n != null && typeof n.getSQL == "function";
1732
+ }
1733
+ function jo(n) {
1734
+ var t;
1735
+ const e = { sql: "", params: [] };
1736
+ for (const s of n)
1737
+ e.sql += s.sql, e.params.push(...s.params), (t = s.typings) != null && t.length && (e.typings || (e.typings = []), e.typings.push(...s.typings));
1738
+ return e;
1739
+ }
1740
+ var Je;
1741
+ Je = c;
1742
+ class C {
1743
+ constructor(e) {
1744
+ r(this, "value");
1745
+ this.value = Array.isArray(e) ? e : [e];
1746
+ }
1747
+ getSQL() {
1748
+ return new N([this]);
1749
+ }
1750
+ }
1751
+ r(C, Je, "StringChunk");
1752
+ var Ke;
1753
+ Ke = c;
1754
+ const z = class z {
1755
+ constructor(e) {
1756
+ /** @internal */
1757
+ r(this, "decoder", xi);
1758
+ r(this, "shouldInlineParams", !1);
1759
+ /** @internal */
1760
+ r(this, "usedTables", []);
1761
+ this.queryChunks = e;
1762
+ for (const t of e)
1763
+ if (T(t, w)) {
1764
+ const s = t[w.Symbol.Schema];
1765
+ this.usedTables.push(
1766
+ s === void 0 ? t[w.Symbol.Name] : s + "." + t[w.Symbol.Name]
1767
+ );
1768
+ }
1769
+ }
1770
+ append(e) {
1771
+ return this.queryChunks.push(...e.queryChunks), this;
1772
+ }
1773
+ toQuery(e) {
1774
+ return Qo.startActiveSpan("drizzle.buildSQL", (t) => {
1775
+ const s = this.buildQueryFromSourceParams(this.queryChunks, e);
1776
+ return t == null || t.setAttributes({
1777
+ "drizzle.query.text": s.sql,
1778
+ "drizzle.query.params": JSON.stringify(s.params)
1779
+ }), s;
1780
+ });
1781
+ }
1782
+ buildQueryFromSourceParams(e, t) {
1783
+ const s = Object.assign({}, t, {
1784
+ inlineParams: t.inlineParams || this.shouldInlineParams,
1785
+ paramStartIndex: t.paramStartIndex || { value: 0 }
1786
+ }), {
1787
+ casing: i,
1788
+ escapeName: o,
1789
+ escapeParam: l,
1790
+ prepareTyping: a,
1791
+ inlineParams: m,
1792
+ paramStartIndex: d
1793
+ } = s;
1794
+ return jo(e.map((u) => {
1795
+ var f;
1796
+ if (T(u, C))
1797
+ return { sql: u.value.join(""), params: [] };
1798
+ if (T(u, U))
1799
+ return { sql: o(u.value), params: [] };
1800
+ if (u === void 0)
1801
+ return { sql: "", params: [] };
1802
+ if (Array.isArray(u)) {
1803
+ const p = [new C("(")];
1804
+ for (const [h, A] of u.entries())
1805
+ p.push(A), h < u.length - 1 && p.push(new C(", "));
1806
+ return p.push(new C(")")), this.buildQueryFromSourceParams(p, s);
1807
+ }
1808
+ if (T(u, z))
1809
+ return this.buildQueryFromSourceParams(u.queryChunks, {
1810
+ ...s,
1811
+ inlineParams: m || u.shouldInlineParams
1812
+ });
1813
+ if (T(u, w)) {
1814
+ const p = u[w.Symbol.Schema], h = u[w.Symbol.Name];
1815
+ return {
1816
+ sql: p === void 0 || u[_] ? o(h) : o(p) + "." + o(h),
1817
+ params: []
1818
+ };
1819
+ }
1820
+ if (T(u, K)) {
1821
+ const p = i.getColumnCasing(u);
1822
+ if (t.invokeSource === "indexes")
1823
+ return { sql: o(p), params: [] };
1824
+ const h = u.table[w.Symbol.Schema];
1825
+ return {
1826
+ sql: u.table[_] || h === void 0 ? o(u.table[w.Symbol.Name]) + "." + o(p) : o(h) + "." + o(u.table[w.Symbol.Name]) + "." + o(p),
1827
+ params: []
1828
+ };
1829
+ }
1830
+ if (T(u, Ti)) {
1831
+ const p = u[I].schema, h = u[I].name;
1832
+ return {
1833
+ sql: p === void 0 || u[I].isAlias ? o(h) : o(p) + "." + o(h),
1834
+ params: []
1835
+ };
1836
+ }
1837
+ if (T(u, se)) {
1838
+ if (T(u.value, O))
1839
+ return { sql: l(d.value++, u), params: [u], typings: ["none"] };
1840
+ const p = u.value === null ? null : u.encoder.mapToDriverValue(u.value);
1841
+ if (T(p, z))
1842
+ return this.buildQueryFromSourceParams([p], s);
1843
+ if (m)
1844
+ return { sql: this.mapInlineParam(p, s), params: [] };
1845
+ let h = ["none"];
1846
+ return a && (h = [a(u.encoder)]), { sql: l(d.value++, p), params: [p], typings: h };
1847
+ }
1848
+ return T(u, O) ? { sql: l(d.value++, u), params: [u], typings: ["none"] } : T(u, z.Aliased) && u.fieldAlias !== void 0 ? { sql: o(u.fieldAlias), params: [] } : T(u, ne) ? u._.isWith ? { sql: o(u._.alias), params: [] } : this.buildQueryFromSourceParams([
1849
+ new C("("),
1850
+ u._.sql,
1851
+ new C(") "),
1852
+ new U(u._.alias)
1853
+ ], s) : Ao(u) ? u.schema ? { sql: o(u.schema) + "." + o(u.enumName), params: [] } : { sql: o(u.enumName), params: [] } : Io(u) ? (f = u.shouldOmitSQLParens) != null && f.call(u) ? this.buildQueryFromSourceParams([u.getSQL()], s) : this.buildQueryFromSourceParams([
1854
+ new C("("),
1855
+ u.getSQL(),
1856
+ new C(")")
1857
+ ], s) : m ? { sql: this.mapInlineParam(u, s), params: [] } : { sql: l(d.value++, u), params: [u], typings: ["none"] };
1858
+ }));
1859
+ }
1860
+ mapInlineParam(e, { escapeString: t }) {
1861
+ if (e === null)
1862
+ return "null";
1863
+ if (typeof e == "number" || typeof e == "boolean")
1864
+ return e.toString();
1865
+ if (typeof e == "string")
1866
+ return t(e);
1867
+ if (typeof e == "object") {
1868
+ const s = e.toString();
1869
+ return t(s === "[object Object]" ? JSON.stringify(e) : s);
1870
+ }
1871
+ throw new Error("Unexpected param value: " + e);
1872
+ }
1873
+ getSQL() {
1874
+ return this;
1875
+ }
1876
+ as(e) {
1877
+ return e === void 0 ? this : new z.Aliased(this, e);
1878
+ }
1879
+ mapWith(e) {
1880
+ return this.decoder = typeof e == "function" ? { mapFromDriverValue: e } : e, this;
1881
+ }
1882
+ inlineParams() {
1883
+ return this.shouldInlineParams = !0, this;
1884
+ }
1885
+ /**
1886
+ * This method is used to conditionally include a part of the query.
1887
+ *
1888
+ * @param condition - Condition to check
1889
+ * @returns itself if the condition is `true`, otherwise `undefined`
1890
+ */
1891
+ if(e) {
1892
+ return e ? this : void 0;
1893
+ }
1894
+ };
1895
+ r(z, Ke, "SQL");
1896
+ let N = z;
1897
+ var We;
1898
+ We = c;
1899
+ class U {
1900
+ constructor(e) {
1901
+ r(this, "brand");
1902
+ this.value = e;
1903
+ }
1904
+ getSQL() {
1905
+ return new N([this]);
1906
+ }
1907
+ }
1908
+ r(U, We, "Name");
1909
+ const xi = {
1910
+ mapFromDriverValue: (n) => n
1911
+ }, Ni = {
1912
+ mapToDriverValue: (n) => n
1913
+ };
1914
+ ({
1915
+ ...xi,
1916
+ ...Ni
1917
+ });
1918
+ var Ye;
1919
+ Ye = c;
1920
+ class se {
1921
+ /**
1922
+ * @param value - Parameter value
1923
+ * @param encoder - Encoder to convert the value to a driver parameter
1924
+ */
1925
+ constructor(e, t = Ni) {
1926
+ r(this, "brand");
1927
+ this.value = e, this.encoder = t;
1928
+ }
1929
+ getSQL() {
1930
+ return new N([this]);
1931
+ }
1932
+ }
1933
+ r(se, Ye, "Param");
1934
+ function q(n, ...e) {
1935
+ const t = [];
1936
+ (e.length > 0 || n.length > 0 && n[0] !== "") && t.push(new C(n[0]));
1937
+ for (const [s, i] of e.entries())
1938
+ t.push(i, new C(n[s + 1]));
1939
+ return new N(t);
1940
+ }
1941
+ ((n) => {
1942
+ function e() {
1943
+ return new N([]);
1944
+ }
1945
+ n.empty = e;
1946
+ function t(m) {
1947
+ return new N(m);
1948
+ }
1949
+ n.fromList = t;
1950
+ function s(m) {
1951
+ return new N([new C(m)]);
1952
+ }
1953
+ n.raw = s;
1954
+ function i(m, d) {
1955
+ const u = [];
1956
+ for (const [f, p] of m.entries())
1957
+ f > 0 && d !== void 0 && u.push(d), u.push(p);
1958
+ return new N(u);
1959
+ }
1960
+ n.join = i;
1961
+ function o(m) {
1962
+ return new U(m);
1963
+ }
1964
+ n.identifier = o;
1965
+ function l(m) {
1966
+ return new O(m);
1967
+ }
1968
+ n.placeholder = l;
1969
+ function a(m, d) {
1970
+ return new se(m, d);
1971
+ }
1972
+ n.param = a;
1973
+ })(q || (q = {}));
1974
+ ((n) => {
1975
+ var t;
1976
+ t = c;
1977
+ const s = class s {
1978
+ constructor(o, l) {
1979
+ /** @internal */
1980
+ r(this, "isSelectionField", !1);
1981
+ this.sql = o, this.fieldAlias = l;
1982
+ }
1983
+ getSQL() {
1984
+ return this.sql;
1985
+ }
1986
+ /** @internal */
1987
+ clone() {
1988
+ return new s(this.sql, this.fieldAlias);
1989
+ }
1990
+ };
1991
+ r(s, t, "SQL.Aliased");
1992
+ let e = s;
1993
+ n.Aliased = e;
1994
+ })(N || (N = {}));
1995
+ var Ge;
1996
+ Ge = c;
1997
+ class O {
1998
+ constructor(e) {
1999
+ this.name = e;
2000
+ }
2001
+ getSQL() {
2002
+ return new N([this]);
2003
+ }
2004
+ }
2005
+ r(O, Ge, "Placeholder");
2006
+ const _o = Symbol.for("drizzle:IsDrizzleView");
2007
+ var He, Ze, Xe;
2008
+ Xe = c, Ze = I, He = _o;
2009
+ class Ti {
2010
+ constructor({ name: e, schema: t, selectedFields: s, query: i }) {
2011
+ /** @internal */
2012
+ r(this, Ze);
2013
+ /** @internal */
2014
+ r(this, He, !0);
2015
+ this[I] = {
2016
+ name: e,
2017
+ originalName: e,
2018
+ schema: t,
2019
+ selectedFields: s,
2020
+ query: i,
2021
+ isExisting: !i,
2022
+ isAlias: !1
2023
+ };
2024
+ }
2025
+ getSQL() {
2026
+ return new N([this]);
2027
+ }
2028
+ }
2029
+ r(Ti, Xe, "View");
2030
+ K.prototype.getSQL = function() {
2031
+ return new N([this]);
2032
+ };
2033
+ w.prototype.getSQL = function() {
2034
+ return new N([this]);
2035
+ };
2036
+ ne.prototype.getSQL = function() {
2037
+ return new N([this]);
2038
+ };
2039
+ function x(n, e) {
2040
+ return {
2041
+ name: typeof n == "string" && n.length > 0 ? n : "",
2042
+ config: typeof n == "object" ? n : e
2043
+ };
2044
+ }
2045
+ var ke, et;
2046
+ class j extends (et = b, ke = c, et) {
2047
+ generatedAlwaysAsIdentity(e) {
2048
+ if (e) {
2049
+ const { name: t, ...s } = e;
2050
+ this.config.generatedIdentity = {
2051
+ type: "always",
2052
+ sequenceName: t,
2053
+ sequenceOptions: s
2054
+ };
2055
+ } else
2056
+ this.config.generatedIdentity = {
2057
+ type: "always"
2058
+ };
2059
+ return this.config.hasDefault = !0, this.config.notNull = !0, this;
2060
+ }
2061
+ generatedByDefaultAsIdentity(e) {
2062
+ if (e) {
2063
+ const { name: t, ...s } = e;
2064
+ this.config.generatedIdentity = {
2065
+ type: "byDefault",
2066
+ sequenceName: t,
2067
+ sequenceOptions: s
2068
+ };
2069
+ } else
2070
+ this.config.generatedIdentity = {
2071
+ type: "byDefault"
2072
+ };
2073
+ return this.config.hasDefault = !0, this.config.notNull = !0, this;
2074
+ }
2075
+ }
2076
+ r(j, ke, "PgIntColumnBaseBuilder");
2077
+ var tt, nt;
2078
+ class Ci extends (nt = j, tt = c, nt) {
2079
+ constructor(e) {
2080
+ super(e, "number", "PgBigInt53");
2081
+ }
2082
+ /** @internal */
2083
+ build(e) {
2084
+ return new Si(e, this.config);
2085
+ }
2086
+ }
2087
+ r(Ci, tt, "PgBigInt53Builder");
2088
+ var st, it;
2089
+ class Si extends (it = g, st = c, it) {
2090
+ getSQLType() {
2091
+ return "bigint";
2092
+ }
2093
+ mapFromDriverValue(e) {
2094
+ return typeof e == "number" ? e : Number(e);
2095
+ }
2096
+ }
2097
+ r(Si, st, "PgBigInt53");
2098
+ var rt, ot;
2099
+ class Pi extends (ot = j, rt = c, ot) {
2100
+ constructor(e) {
2101
+ super(e, "bigint", "PgBigInt64");
2102
+ }
2103
+ /** @internal */
2104
+ build(e) {
2105
+ return new Di(
2106
+ e,
2107
+ this.config
2108
+ );
2109
+ }
2110
+ }
2111
+ r(Pi, rt, "PgBigInt64Builder");
2112
+ var at, ut;
2113
+ class Di extends (ut = g, at = c, ut) {
2114
+ getSQLType() {
2115
+ return "bigint";
2116
+ }
2117
+ // eslint-disable-next-line unicorn/prefer-native-coercion-functions
2118
+ mapFromDriverValue(e) {
2119
+ return BigInt(e);
2120
+ }
2121
+ }
2122
+ r(Di, at, "PgBigInt64");
2123
+ function Uo(n, e) {
2124
+ const { name: t, config: s } = x(n, e);
2125
+ return s.mode === "number" ? new Ci(t) : new Pi(t);
2126
+ }
2127
+ var ct, lt;
2128
+ class vi extends (lt = b, ct = c, lt) {
2129
+ constructor(e) {
2130
+ super(e, "number", "PgBigSerial53"), this.config.hasDefault = !0, this.config.notNull = !0;
2131
+ }
2132
+ /** @internal */
2133
+ build(e) {
2134
+ return new Ei(
2135
+ e,
2136
+ this.config
2137
+ );
2138
+ }
2139
+ }
2140
+ r(vi, ct, "PgBigSerial53Builder");
2141
+ var mt, dt;
2142
+ class Ei extends (dt = g, mt = c, dt) {
2143
+ getSQLType() {
2144
+ return "bigserial";
2145
+ }
2146
+ mapFromDriverValue(e) {
2147
+ return typeof e == "number" ? e : Number(e);
2148
+ }
2149
+ }
2150
+ r(Ei, mt, "PgBigSerial53");
2151
+ var ft, pt;
2152
+ class $i extends (pt = b, ft = c, pt) {
2153
+ constructor(e) {
2154
+ super(e, "bigint", "PgBigSerial64"), this.config.hasDefault = !0;
2155
+ }
2156
+ /** @internal */
2157
+ build(e) {
2158
+ return new Bi(
2159
+ e,
2160
+ this.config
2161
+ );
2162
+ }
2163
+ }
2164
+ r($i, ft, "PgBigSerial64Builder");
2165
+ var ht, gt;
2166
+ class Bi extends (gt = g, ht = c, gt) {
2167
+ getSQLType() {
2168
+ return "bigserial";
2169
+ }
2170
+ // eslint-disable-next-line unicorn/prefer-native-coercion-functions
2171
+ mapFromDriverValue(e) {
2172
+ return BigInt(e);
2173
+ }
2174
+ }
2175
+ r(Bi, ht, "PgBigSerial64");
2176
+ function qo(n, e) {
2177
+ const { name: t, config: s } = x(n, e);
2178
+ return s.mode === "number" ? new vi(t) : new $i(t);
2179
+ }
2180
+ var bt, yt;
2181
+ class zi extends (yt = b, bt = c, yt) {
2182
+ constructor(e) {
2183
+ super(e, "boolean", "PgBoolean");
2184
+ }
2185
+ /** @internal */
2186
+ build(e) {
2187
+ return new Fi(e, this.config);
2188
+ }
2189
+ }
2190
+ r(zi, bt, "PgBooleanBuilder");
2191
+ var wt, xt;
2192
+ class Fi extends (xt = g, wt = c, xt) {
2193
+ getSQLType() {
2194
+ return "boolean";
2195
+ }
2196
+ }
2197
+ r(Fi, wt, "PgBoolean");
2198
+ function ie(n) {
2199
+ return new zi(n ?? "");
2200
+ }
2201
+ var Nt, Tt;
2202
+ class Li extends (Tt = b, Nt = c, Tt) {
2203
+ constructor(e, t) {
2204
+ super(e, "string", "PgChar"), this.config.length = t.length, this.config.enumValues = t.enum;
2205
+ }
2206
+ /** @internal */
2207
+ build(e) {
2208
+ return new Ai(
2209
+ e,
2210
+ this.config
2211
+ );
2212
+ }
2213
+ }
2214
+ r(Li, Nt, "PgCharBuilder");
2215
+ var Ct, St;
2216
+ class Ai extends (St = g, Ct = c, St) {
2217
+ constructor() {
2218
+ super(...arguments);
2219
+ r(this, "length", this.config.length);
2220
+ r(this, "enumValues", this.config.enumValues);
2221
+ }
2222
+ getSQLType() {
2223
+ return this.length === void 0 ? "char" : `char(${this.length})`;
2224
+ }
2225
+ }
2226
+ r(Ai, Ct, "PgChar");
2227
+ function Oo(n, e = {}) {
2228
+ const { name: t, config: s } = x(n, e);
2229
+ return new Li(t, s);
2230
+ }
2231
+ var Pt, Dt;
2232
+ class Qi extends (Dt = b, Pt = c, Dt) {
2233
+ constructor(e) {
2234
+ super(e, "string", "PgCidr");
2235
+ }
2236
+ /** @internal */
2237
+ build(e) {
2238
+ return new Vi(e, this.config);
2239
+ }
2240
+ }
2241
+ r(Qi, Pt, "PgCidrBuilder");
2242
+ var vt, Et;
2243
+ class Vi extends (Et = g, vt = c, Et) {
2244
+ getSQLType() {
2245
+ return "cidr";
2246
+ }
2247
+ }
2248
+ r(Vi, vt, "PgCidr");
2249
+ function Mo(n) {
2250
+ return new Qi(n ?? "");
2251
+ }
2252
+ var $t, Bt;
2253
+ class Ii extends (Bt = b, $t = c, Bt) {
2254
+ constructor(e, t, s) {
2255
+ super(e, "custom", "PgCustomColumn"), this.config.fieldConfig = t, this.config.customTypeParams = s;
2256
+ }
2257
+ /** @internal */
2258
+ build(e) {
2259
+ return new ji(
2260
+ e,
2261
+ this.config
2262
+ );
2263
+ }
2264
+ }
2265
+ r(Ii, $t, "PgCustomColumnBuilder");
2266
+ var zt, Ft;
2267
+ class ji extends (Ft = g, zt = c, Ft) {
2268
+ constructor(t, s) {
2269
+ super(t, s);
2270
+ r(this, "sqlName");
2271
+ r(this, "mapTo");
2272
+ r(this, "mapFrom");
2273
+ this.sqlName = s.customTypeParams.dataType(s.fieldConfig), this.mapTo = s.customTypeParams.toDriver, this.mapFrom = s.customTypeParams.fromDriver;
2274
+ }
2275
+ getSQLType() {
2276
+ return this.sqlName;
2277
+ }
2278
+ mapFromDriverValue(t) {
2279
+ return typeof this.mapFrom == "function" ? this.mapFrom(t) : t;
2280
+ }
2281
+ mapToDriverValue(t) {
2282
+ return typeof this.mapTo == "function" ? this.mapTo(t) : t;
2283
+ }
2284
+ }
2285
+ r(ji, zt, "PgCustomColumn");
2286
+ function Ro(n) {
2287
+ return (e, t) => {
2288
+ const { name: s, config: i } = x(e, t);
2289
+ return new Ii(s, i, n);
2290
+ };
2291
+ }
2292
+ var Lt, At;
2293
+ class V extends (At = b, Lt = c, At) {
2294
+ defaultNow() {
2295
+ return this.default(q`now()`);
2296
+ }
2297
+ }
2298
+ r(V, Lt, "PgDateColumnBaseBuilder");
2299
+ var Qt, Vt;
2300
+ class _i extends (Vt = V, Qt = c, Vt) {
2301
+ constructor(e) {
2302
+ super(e, "date", "PgDate");
2303
+ }
2304
+ /** @internal */
2305
+ build(e) {
2306
+ return new Ui(e, this.config);
2307
+ }
2308
+ }
2309
+ r(_i, Qt, "PgDateBuilder");
2310
+ var It, jt;
2311
+ class Ui extends (jt = g, It = c, jt) {
2312
+ getSQLType() {
2313
+ return "date";
2314
+ }
2315
+ mapFromDriverValue(e) {
2316
+ return new Date(e);
2317
+ }
2318
+ mapToDriverValue(e) {
2319
+ return e.toISOString();
2320
+ }
2321
+ }
2322
+ r(Ui, It, "PgDate");
2323
+ var _t, Ut;
2324
+ class qi extends (Ut = V, _t = c, Ut) {
2325
+ constructor(e) {
2326
+ super(e, "string", "PgDateString");
2327
+ }
2328
+ /** @internal */
2329
+ build(e) {
2330
+ return new Oi(
2331
+ e,
2332
+ this.config
2333
+ );
2334
+ }
2335
+ }
2336
+ r(qi, _t, "PgDateStringBuilder");
2337
+ var qt, Ot;
2338
+ class Oi extends (Ot = g, qt = c, Ot) {
2339
+ getSQLType() {
2340
+ return "date";
2341
+ }
2342
+ }
2343
+ r(Oi, qt, "PgDateString");
2344
+ function Jo(n, e) {
2345
+ const { name: t, config: s } = x(n, e);
2346
+ return (s == null ? void 0 : s.mode) === "date" ? new _i(t) : new qi(t);
2347
+ }
2348
+ var Mt, Rt;
2349
+ class Mi extends (Rt = b, Mt = c, Rt) {
2350
+ constructor(e) {
2351
+ super(e, "number", "PgDoublePrecision");
2352
+ }
2353
+ /** @internal */
2354
+ build(e) {
2355
+ return new Ri(
2356
+ e,
2357
+ this.config
2358
+ );
2359
+ }
2360
+ }
2361
+ r(Mi, Mt, "PgDoublePrecisionBuilder");
2362
+ var Jt, Kt;
2363
+ class Ri extends (Kt = g, Jt = c, Kt) {
2364
+ getSQLType() {
2365
+ return "double precision";
2366
+ }
2367
+ mapFromDriverValue(e) {
2368
+ return typeof e == "string" ? Number.parseFloat(e) : e;
2369
+ }
2370
+ }
2371
+ r(Ri, Jt, "PgDoublePrecision");
2372
+ function Ko(n) {
2373
+ return new Mi(n ?? "");
2374
+ }
2375
+ var Wt, Yt;
2376
+ class Ji extends (Yt = b, Wt = c, Yt) {
2377
+ constructor(e) {
2378
+ super(e, "string", "PgInet");
2379
+ }
2380
+ /** @internal */
2381
+ build(e) {
2382
+ return new Ki(e, this.config);
2383
+ }
2384
+ }
2385
+ r(Ji, Wt, "PgInetBuilder");
2386
+ var Gt, Ht;
2387
+ class Ki extends (Ht = g, Gt = c, Ht) {
2388
+ getSQLType() {
2389
+ return "inet";
2390
+ }
2391
+ }
2392
+ r(Ki, Gt, "PgInet");
2393
+ function Wo(n) {
2394
+ return new Ji(n ?? "");
2395
+ }
2396
+ var Zt, Xt;
2397
+ class Wi extends (Xt = j, Zt = c, Xt) {
2398
+ constructor(e) {
2399
+ super(e, "number", "PgInteger");
2400
+ }
2401
+ /** @internal */
2402
+ build(e) {
2403
+ return new Yi(e, this.config);
2404
+ }
2405
+ }
2406
+ r(Wi, Zt, "PgIntegerBuilder");
2407
+ var kt, en;
2408
+ class Yi extends (en = g, kt = c, en) {
2409
+ getSQLType() {
2410
+ return "integer";
2411
+ }
2412
+ mapFromDriverValue(e) {
2413
+ return typeof e == "string" ? Number.parseInt(e) : e;
2414
+ }
2415
+ }
2416
+ r(Yi, kt, "PgInteger");
2417
+ function D(n) {
2418
+ return new Wi(n ?? "");
2419
+ }
2420
+ var tn, nn;
2421
+ class Gi extends (nn = b, tn = c, nn) {
2422
+ constructor(e, t) {
2423
+ super(e, "string", "PgInterval"), this.config.intervalConfig = t;
2424
+ }
2425
+ /** @internal */
2426
+ build(e) {
2427
+ return new Hi(e, this.config);
2428
+ }
2429
+ }
2430
+ r(Gi, tn, "PgIntervalBuilder");
2431
+ var sn, rn;
2432
+ class Hi extends (rn = g, sn = c, rn) {
2433
+ constructor() {
2434
+ super(...arguments);
2435
+ r(this, "fields", this.config.intervalConfig.fields);
2436
+ r(this, "precision", this.config.intervalConfig.precision);
2437
+ }
2438
+ getSQLType() {
2439
+ const t = this.fields ? ` ${this.fields}` : "", s = this.precision ? `(${this.precision})` : "";
2440
+ return `interval${t}${s}`;
2441
+ }
2442
+ }
2443
+ r(Hi, sn, "PgInterval");
2444
+ function Yo(n, e = {}) {
2445
+ const { name: t, config: s } = x(n, e);
2446
+ return new Gi(t, s);
2447
+ }
2448
+ var on, an;
2449
+ class Zi extends (an = b, on = c, an) {
2450
+ constructor(e) {
2451
+ super(e, "json", "PgJson");
2452
+ }
2453
+ /** @internal */
2454
+ build(e) {
2455
+ return new Xi(e, this.config);
2456
+ }
2457
+ }
2458
+ r(Zi, on, "PgJsonBuilder");
2459
+ var un, cn;
2460
+ class Xi extends (cn = g, un = c, cn) {
2461
+ constructor(e, t) {
2462
+ super(e, t);
2463
+ }
2464
+ getSQLType() {
2465
+ return "json";
2466
+ }
2467
+ mapToDriverValue(e) {
2468
+ return JSON.stringify(e);
2469
+ }
2470
+ mapFromDriverValue(e) {
2471
+ if (typeof e == "string")
2472
+ try {
2473
+ return JSON.parse(e);
2474
+ } catch {
2475
+ return e;
2476
+ }
2477
+ return e;
2478
+ }
2479
+ }
2480
+ r(Xi, un, "PgJson");
2481
+ function Go(n) {
2482
+ return new Zi(n ?? "");
2483
+ }
2484
+ var ln, mn;
2485
+ class ki extends (mn = b, ln = c, mn) {
2486
+ constructor(e) {
2487
+ super(e, "json", "PgJsonb");
2488
+ }
2489
+ /** @internal */
2490
+ build(e) {
2491
+ return new er(e, this.config);
2492
+ }
2493
+ }
2494
+ r(ki, ln, "PgJsonbBuilder");
2495
+ var dn, fn;
2496
+ class er extends (fn = g, dn = c, fn) {
2497
+ constructor(e, t) {
2498
+ super(e, t);
2499
+ }
2500
+ getSQLType() {
2501
+ return "jsonb";
2502
+ }
2503
+ mapToDriverValue(e) {
2504
+ return JSON.stringify(e);
2505
+ }
2506
+ mapFromDriverValue(e) {
2507
+ if (typeof e == "string")
2508
+ try {
2509
+ return JSON.parse(e);
2510
+ } catch {
2511
+ return e;
2512
+ }
2513
+ return e;
2514
+ }
2515
+ }
2516
+ r(er, dn, "PgJsonb");
2517
+ function Ho(n) {
2518
+ return new ki(n ?? "");
2519
+ }
2520
+ var pn, hn;
2521
+ class tr extends (hn = b, pn = c, hn) {
2522
+ constructor(e) {
2523
+ super(e, "array", "PgLine");
2524
+ }
2525
+ /** @internal */
2526
+ build(e) {
2527
+ return new nr(
2528
+ e,
2529
+ this.config
2530
+ );
2531
+ }
2532
+ }
2533
+ r(tr, pn, "PgLineBuilder");
2534
+ var gn, bn;
2535
+ class nr extends (bn = g, gn = c, bn) {
2536
+ getSQLType() {
2537
+ return "line";
2538
+ }
2539
+ mapFromDriverValue(e) {
2540
+ const [t, s, i] = e.slice(1, -1).split(",");
2541
+ return [Number.parseFloat(t), Number.parseFloat(s), Number.parseFloat(i)];
2542
+ }
2543
+ mapToDriverValue(e) {
2544
+ return `{${e[0]},${e[1]},${e[2]}}`;
2545
+ }
2546
+ }
2547
+ r(nr, gn, "PgLine");
2548
+ var yn, wn;
2549
+ class sr extends (wn = b, yn = c, wn) {
2550
+ constructor(e) {
2551
+ super(e, "json", "PgLineABC");
2552
+ }
2553
+ /** @internal */
2554
+ build(e) {
2555
+ return new ir(
2556
+ e,
2557
+ this.config
2558
+ );
2559
+ }
2560
+ }
2561
+ r(sr, yn, "PgLineABCBuilder");
2562
+ var xn, Nn;
2563
+ class ir extends (Nn = g, xn = c, Nn) {
2564
+ getSQLType() {
2565
+ return "line";
2566
+ }
2567
+ mapFromDriverValue(e) {
2568
+ const [t, s, i] = e.slice(1, -1).split(",");
2569
+ return { a: Number.parseFloat(t), b: Number.parseFloat(s), c: Number.parseFloat(i) };
2570
+ }
2571
+ mapToDriverValue(e) {
2572
+ return `{${e.a},${e.b},${e.c}}`;
2573
+ }
2574
+ }
2575
+ r(ir, xn, "PgLineABC");
2576
+ function Zo(n, e) {
2577
+ const { name: t, config: s } = x(n, e);
2578
+ return !(s != null && s.mode) || s.mode === "tuple" ? new tr(t) : new sr(t);
2579
+ }
2580
+ var Tn, Cn;
2581
+ class rr extends (Cn = b, Tn = c, Cn) {
2582
+ constructor(e) {
2583
+ super(e, "string", "PgMacaddr");
2584
+ }
2585
+ /** @internal */
2586
+ build(e) {
2587
+ return new or(e, this.config);
2588
+ }
2589
+ }
2590
+ r(rr, Tn, "PgMacaddrBuilder");
2591
+ var Sn, Pn;
2592
+ class or extends (Pn = g, Sn = c, Pn) {
2593
+ getSQLType() {
2594
+ return "macaddr";
2595
+ }
2596
+ }
2597
+ r(or, Sn, "PgMacaddr");
2598
+ function Xo(n) {
2599
+ return new rr(n ?? "");
2600
+ }
2601
+ var Dn, vn;
2602
+ class ar extends (vn = b, Dn = c, vn) {
2603
+ constructor(e) {
2604
+ super(e, "string", "PgMacaddr8");
2605
+ }
2606
+ /** @internal */
2607
+ build(e) {
2608
+ return new ur(e, this.config);
2609
+ }
2610
+ }
2611
+ r(ar, Dn, "PgMacaddr8Builder");
2612
+ var En, $n;
2613
+ class ur extends ($n = g, En = c, $n) {
2614
+ getSQLType() {
2615
+ return "macaddr8";
2616
+ }
2617
+ }
2618
+ r(ur, En, "PgMacaddr8");
2619
+ function ko(n) {
2620
+ return new ar(n ?? "");
2621
+ }
2622
+ var Bn, zn;
2623
+ class cr extends (zn = b, Bn = c, zn) {
2624
+ constructor(e, t, s) {
2625
+ super(e, "string", "PgNumeric"), this.config.precision = t, this.config.scale = s;
2626
+ }
2627
+ /** @internal */
2628
+ build(e) {
2629
+ return new lr(e, this.config);
2630
+ }
2631
+ }
2632
+ r(cr, Bn, "PgNumericBuilder");
2633
+ var Fn, Ln;
2634
+ class lr extends (Ln = g, Fn = c, Ln) {
2635
+ constructor(t, s) {
2636
+ super(t, s);
2637
+ r(this, "precision");
2638
+ r(this, "scale");
2639
+ this.precision = s.precision, this.scale = s.scale;
2640
+ }
2641
+ mapFromDriverValue(t) {
2642
+ return typeof t == "string" ? t : String(t);
2643
+ }
2644
+ getSQLType() {
2645
+ return this.precision !== void 0 && this.scale !== void 0 ? `numeric(${this.precision}, ${this.scale})` : this.precision === void 0 ? "numeric" : `numeric(${this.precision})`;
2646
+ }
2647
+ }
2648
+ r(lr, Fn, "PgNumeric");
2649
+ var An, Qn;
2650
+ class mr extends (Qn = b, An = c, Qn) {
2651
+ constructor(e, t, s) {
2652
+ super(e, "number", "PgNumericNumber"), this.config.precision = t, this.config.scale = s;
2653
+ }
2654
+ /** @internal */
2655
+ build(e) {
2656
+ return new dr(
2657
+ e,
2658
+ this.config
2659
+ );
2660
+ }
2661
+ }
2662
+ r(mr, An, "PgNumericNumberBuilder");
2663
+ var Vn, In;
2664
+ class dr extends (In = g, Vn = c, In) {
2665
+ constructor(t, s) {
2666
+ super(t, s);
2667
+ r(this, "precision");
2668
+ r(this, "scale");
2669
+ r(this, "mapToDriverValue", String);
2670
+ this.precision = s.precision, this.scale = s.scale;
2671
+ }
2672
+ mapFromDriverValue(t) {
2673
+ return typeof t == "number" ? t : Number(t);
2674
+ }
2675
+ getSQLType() {
2676
+ return this.precision !== void 0 && this.scale !== void 0 ? `numeric(${this.precision}, ${this.scale})` : this.precision === void 0 ? "numeric" : `numeric(${this.precision})`;
2677
+ }
2678
+ }
2679
+ r(dr, Vn, "PgNumericNumber");
2680
+ var jn, _n;
2681
+ class fr extends (_n = b, jn = c, _n) {
2682
+ constructor(e, t, s) {
2683
+ super(e, "bigint", "PgNumericBigInt"), this.config.precision = t, this.config.scale = s;
2684
+ }
2685
+ /** @internal */
2686
+ build(e) {
2687
+ return new pr(
2688
+ e,
2689
+ this.config
2690
+ );
2691
+ }
2692
+ }
2693
+ r(fr, jn, "PgNumericBigIntBuilder");
2694
+ var Un, qn;
2695
+ class pr extends (qn = g, Un = c, qn) {
2696
+ constructor(t, s) {
2697
+ super(t, s);
2698
+ r(this, "precision");
2699
+ r(this, "scale");
2700
+ r(this, "mapFromDriverValue", BigInt);
2701
+ r(this, "mapToDriverValue", String);
2702
+ this.precision = s.precision, this.scale = s.scale;
2703
+ }
2704
+ getSQLType() {
2705
+ return this.precision !== void 0 && this.scale !== void 0 ? `numeric(${this.precision}, ${this.scale})` : this.precision === void 0 ? "numeric" : `numeric(${this.precision})`;
2706
+ }
2707
+ }
2708
+ r(pr, Un, "PgNumericBigInt");
2709
+ function hr(n, e) {
2710
+ const { name: t, config: s } = x(n, e), i = s == null ? void 0 : s.mode;
2711
+ return i === "number" ? new mr(t, s == null ? void 0 : s.precision, s == null ? void 0 : s.scale) : i === "bigint" ? new fr(t, s == null ? void 0 : s.precision, s == null ? void 0 : s.scale) : new cr(t, s == null ? void 0 : s.precision, s == null ? void 0 : s.scale);
2712
+ }
2713
+ const ea = hr;
2714
+ var On, Mn;
2715
+ class gr extends (Mn = b, On = c, Mn) {
2716
+ constructor(e) {
2717
+ super(e, "array", "PgPointTuple");
2718
+ }
2719
+ /** @internal */
2720
+ build(e) {
2721
+ return new br(
2722
+ e,
2723
+ this.config
2724
+ );
2725
+ }
2726
+ }
2727
+ r(gr, On, "PgPointTupleBuilder");
2728
+ var Rn, Jn;
2729
+ class br extends (Jn = g, Rn = c, Jn) {
2730
+ getSQLType() {
2731
+ return "point";
2732
+ }
2733
+ mapFromDriverValue(e) {
2734
+ if (typeof e == "string") {
2735
+ const [t, s] = e.slice(1, -1).split(",");
2736
+ return [Number.parseFloat(t), Number.parseFloat(s)];
2737
+ }
2738
+ return [e.x, e.y];
2739
+ }
2740
+ mapToDriverValue(e) {
2741
+ return `(${e[0]},${e[1]})`;
2742
+ }
2743
+ }
2744
+ r(br, Rn, "PgPointTuple");
2745
+ var Kn, Wn;
2746
+ class yr extends (Wn = b, Kn = c, Wn) {
2747
+ constructor(e) {
2748
+ super(e, "json", "PgPointObject");
2749
+ }
2750
+ /** @internal */
2751
+ build(e) {
2752
+ return new wr(
2753
+ e,
2754
+ this.config
2755
+ );
2756
+ }
2757
+ }
2758
+ r(yr, Kn, "PgPointObjectBuilder");
2759
+ var Yn, Gn;
2760
+ class wr extends (Gn = g, Yn = c, Gn) {
2761
+ getSQLType() {
2762
+ return "point";
2763
+ }
2764
+ mapFromDriverValue(e) {
2765
+ if (typeof e == "string") {
2766
+ const [t, s] = e.slice(1, -1).split(",");
2767
+ return { x: Number.parseFloat(t), y: Number.parseFloat(s) };
2768
+ }
2769
+ return e;
2770
+ }
2771
+ mapToDriverValue(e) {
2772
+ return `(${e.x},${e.y})`;
2773
+ }
2774
+ }
2775
+ r(wr, Yn, "PgPointObject");
2776
+ function ta(n, e) {
2777
+ const { name: t, config: s } = x(n, e);
2778
+ return !(s != null && s.mode) || s.mode === "tuple" ? new gr(t) : new yr(t);
2779
+ }
2780
+ function na(n) {
2781
+ const e = [];
2782
+ for (let t = 0; t < n.length; t += 2)
2783
+ e.push(Number.parseInt(n.slice(t, t + 2), 16));
2784
+ return new Uint8Array(e);
2785
+ }
2786
+ function ye(n, e) {
2787
+ const t = new ArrayBuffer(8), s = new DataView(t);
2788
+ for (let i = 0; i < 8; i++)
2789
+ s.setUint8(i, n[e + i]);
2790
+ return s.getFloat64(0, !0);
2791
+ }
2792
+ function xr(n) {
2793
+ const e = na(n);
2794
+ let t = 0;
2795
+ const s = e[t];
2796
+ t += 1;
2797
+ const i = new DataView(e.buffer), o = i.getUint32(t, s === 1);
2798
+ if (t += 4, o & 536870912 && (i.getUint32(t, s === 1), t += 4), (o & 65535) === 1) {
2799
+ const l = ye(e, t);
2800
+ t += 8;
2801
+ const a = ye(e, t);
2802
+ return t += 8, [l, a];
2803
+ }
2804
+ throw new Error("Unsupported geometry type");
2805
+ }
2806
+ var Hn, Zn;
2807
+ class Nr extends (Zn = b, Hn = c, Zn) {
2808
+ constructor(e) {
2809
+ super(e, "array", "PgGeometry");
2810
+ }
2811
+ /** @internal */
2812
+ build(e) {
2813
+ return new Tr(
2814
+ e,
2815
+ this.config
2816
+ );
2817
+ }
2818
+ }
2819
+ r(Nr, Hn, "PgGeometryBuilder");
2820
+ var Xn, kn;
2821
+ class Tr extends (kn = g, Xn = c, kn) {
2822
+ getSQLType() {
2823
+ return "geometry(point)";
2824
+ }
2825
+ mapFromDriverValue(e) {
2826
+ return xr(e);
2827
+ }
2828
+ mapToDriverValue(e) {
2829
+ return `point(${e[0]} ${e[1]})`;
2830
+ }
2831
+ }
2832
+ r(Tr, Xn, "PgGeometry");
2833
+ var es, ts;
2834
+ class Cr extends (ts = b, es = c, ts) {
2835
+ constructor(e) {
2836
+ super(e, "json", "PgGeometryObject");
2837
+ }
2838
+ /** @internal */
2839
+ build(e) {
2840
+ return new Sr(
2841
+ e,
2842
+ this.config
2843
+ );
2844
+ }
2845
+ }
2846
+ r(Cr, es, "PgGeometryObjectBuilder");
2847
+ var ns, ss;
2848
+ class Sr extends (ss = g, ns = c, ss) {
2849
+ getSQLType() {
2850
+ return "geometry(point)";
2851
+ }
2852
+ mapFromDriverValue(e) {
2853
+ const t = xr(e);
2854
+ return { x: t[0], y: t[1] };
2855
+ }
2856
+ mapToDriverValue(e) {
2857
+ return `point(${e.x} ${e.y})`;
2858
+ }
2859
+ }
2860
+ r(Sr, ns, "PgGeometryObject");
2861
+ function sa(n, e) {
2862
+ const { name: t, config: s } = x(n, e);
2863
+ return !(s != null && s.mode) || s.mode === "tuple" ? new Nr(t) : new Cr(t);
2864
+ }
2865
+ var is, rs;
2866
+ class Pr extends (rs = b, is = c, rs) {
2867
+ constructor(e, t) {
2868
+ super(e, "number", "PgReal"), this.config.length = t;
2869
+ }
2870
+ /** @internal */
2871
+ build(e) {
2872
+ return new Dr(e, this.config);
2873
+ }
2874
+ }
2875
+ r(Pr, is, "PgRealBuilder");
2876
+ var os, as;
2877
+ class Dr extends (as = g, os = c, as) {
2878
+ constructor(t, s) {
2879
+ super(t, s);
2880
+ r(this, "mapFromDriverValue", (t) => typeof t == "string" ? Number.parseFloat(t) : t);
2881
+ }
2882
+ getSQLType() {
2883
+ return "real";
2884
+ }
2885
+ }
2886
+ r(Dr, os, "PgReal");
2887
+ function ia(n) {
2888
+ return new Pr(n ?? "");
2889
+ }
2890
+ var us, cs;
2891
+ class vr extends (cs = b, us = c, cs) {
2892
+ constructor(e) {
2893
+ super(e, "number", "PgSerial"), this.config.hasDefault = !0, this.config.notNull = !0;
2894
+ }
2895
+ /** @internal */
2896
+ build(e) {
2897
+ return new Er(e, this.config);
2898
+ }
2899
+ }
2900
+ r(vr, us, "PgSerialBuilder");
2901
+ var ls, ms;
2902
+ class Er extends (ms = g, ls = c, ms) {
2903
+ getSQLType() {
2904
+ return "serial";
2905
+ }
2906
+ }
2907
+ r(Er, ls, "PgSerial");
2908
+ function ra(n) {
2909
+ return new vr(n ?? "");
2910
+ }
2911
+ var ds, fs;
2912
+ class $r extends (fs = j, ds = c, fs) {
2913
+ constructor(e) {
2914
+ super(e, "number", "PgSmallInt");
2915
+ }
2916
+ /** @internal */
2917
+ build(e) {
2918
+ return new Br(e, this.config);
2919
+ }
2920
+ }
2921
+ r($r, ds, "PgSmallIntBuilder");
2922
+ var ps, hs;
2923
+ class Br extends (hs = g, ps = c, hs) {
2924
+ constructor() {
2925
+ super(...arguments);
2926
+ r(this, "mapFromDriverValue", (t) => typeof t == "string" ? Number(t) : t);
2927
+ }
2928
+ getSQLType() {
2929
+ return "smallint";
2930
+ }
2931
+ }
2932
+ r(Br, ps, "PgSmallInt");
2933
+ function oa(n) {
2934
+ return new $r(n ?? "");
2935
+ }
2936
+ var gs, bs;
2937
+ class zr extends (bs = b, gs = c, bs) {
2938
+ constructor(e) {
2939
+ super(e, "number", "PgSmallSerial"), this.config.hasDefault = !0, this.config.notNull = !0;
2940
+ }
2941
+ /** @internal */
2942
+ build(e) {
2943
+ return new Fr(
2944
+ e,
2945
+ this.config
2946
+ );
2947
+ }
2948
+ }
2949
+ r(zr, gs, "PgSmallSerialBuilder");
2950
+ var ys, ws;
2951
+ class Fr extends (ws = g, ys = c, ws) {
2952
+ getSQLType() {
2953
+ return "smallserial";
2954
+ }
2955
+ }
2956
+ r(Fr, ys, "PgSmallSerial");
2957
+ function aa(n) {
2958
+ return new zr(n ?? "");
2959
+ }
2960
+ var xs, Ns;
2961
+ class Lr extends (Ns = b, xs = c, Ns) {
2962
+ constructor(e, t) {
2963
+ super(e, "string", "PgText"), this.config.enumValues = t.enum;
2964
+ }
2965
+ /** @internal */
2966
+ build(e) {
2967
+ return new Ar(e, this.config);
2968
+ }
2969
+ }
2970
+ r(Lr, xs, "PgTextBuilder");
2971
+ var Ts, Cs;
2972
+ class Ar extends (Cs = g, Ts = c, Cs) {
2973
+ constructor() {
2974
+ super(...arguments);
2975
+ r(this, "enumValues", this.config.enumValues);
2976
+ }
2977
+ getSQLType() {
2978
+ return "text";
2979
+ }
2980
+ }
2981
+ r(Ar, Ts, "PgText");
2982
+ function E(n, e = {}) {
2983
+ const { name: t, config: s } = x(n, e);
2984
+ return new Lr(t, s);
2985
+ }
2986
+ var Ss, Ps;
2987
+ class Qr extends (Ps = V, Ss = c, Ps) {
2988
+ constructor(e, t, s) {
2989
+ super(e, "string", "PgTime"), this.withTimezone = t, this.precision = s, this.config.withTimezone = t, this.config.precision = s;
2990
+ }
2991
+ /** @internal */
2992
+ build(e) {
2993
+ return new Vr(e, this.config);
2994
+ }
2995
+ }
2996
+ r(Qr, Ss, "PgTimeBuilder");
2997
+ var Ds, vs;
2998
+ class Vr extends (vs = g, Ds = c, vs) {
2999
+ constructor(t, s) {
3000
+ super(t, s);
3001
+ r(this, "withTimezone");
3002
+ r(this, "precision");
3003
+ this.withTimezone = s.withTimezone, this.precision = s.precision;
3004
+ }
3005
+ getSQLType() {
3006
+ return `time${this.precision === void 0 ? "" : `(${this.precision})`}${this.withTimezone ? " with time zone" : ""}`;
3007
+ }
3008
+ }
3009
+ r(Vr, Ds, "PgTime");
3010
+ function ua(n, e = {}) {
3011
+ const { name: t, config: s } = x(n, e);
3012
+ return new Qr(t, s.withTimezone ?? !1, s.precision);
3013
+ }
3014
+ var Es, $s;
3015
+ class Ir extends ($s = V, Es = c, $s) {
3016
+ constructor(e, t, s) {
3017
+ super(e, "date", "PgTimestamp"), this.config.withTimezone = t, this.config.precision = s;
3018
+ }
3019
+ /** @internal */
3020
+ build(e) {
3021
+ return new jr(e, this.config);
3022
+ }
3023
+ }
3024
+ r(Ir, Es, "PgTimestampBuilder");
3025
+ var Bs, zs;
3026
+ class jr extends (zs = g, Bs = c, zs) {
3027
+ constructor(t, s) {
3028
+ super(t, s);
3029
+ r(this, "withTimezone");
3030
+ r(this, "precision");
3031
+ r(this, "mapFromDriverValue", (t) => new Date(this.withTimezone ? t : t + "+0000"));
3032
+ r(this, "mapToDriverValue", (t) => t.toISOString());
3033
+ this.withTimezone = s.withTimezone, this.precision = s.precision;
3034
+ }
3035
+ getSQLType() {
3036
+ return `timestamp${this.precision === void 0 ? "" : ` (${this.precision})`}${this.withTimezone ? " with time zone" : ""}`;
3037
+ }
3038
+ }
3039
+ r(jr, Bs, "PgTimestamp");
3040
+ var Fs, Ls;
3041
+ class _r extends (Ls = V, Fs = c, Ls) {
3042
+ constructor(e, t, s) {
3043
+ super(e, "string", "PgTimestampString"), this.config.withTimezone = t, this.config.precision = s;
3044
+ }
3045
+ /** @internal */
3046
+ build(e) {
3047
+ return new Ur(
3048
+ e,
3049
+ this.config
3050
+ );
3051
+ }
3052
+ }
3053
+ r(_r, Fs, "PgTimestampStringBuilder");
3054
+ var As, Qs;
3055
+ class Ur extends (Qs = g, As = c, Qs) {
3056
+ constructor(t, s) {
3057
+ super(t, s);
3058
+ r(this, "withTimezone");
3059
+ r(this, "precision");
3060
+ this.withTimezone = s.withTimezone, this.precision = s.precision;
3061
+ }
3062
+ getSQLType() {
3063
+ return `timestamp${this.precision === void 0 ? "" : `(${this.precision})`}${this.withTimezone ? " with time zone" : ""}`;
3064
+ }
3065
+ }
3066
+ r(Ur, As, "PgTimestampString");
3067
+ function S(n, e = {}) {
3068
+ const { name: t, config: s } = x(n, e);
3069
+ return (s == null ? void 0 : s.mode) === "string" ? new _r(t, s.withTimezone ?? !1, s.precision) : new Ir(t, (s == null ? void 0 : s.withTimezone) ?? !1, s == null ? void 0 : s.precision);
3070
+ }
3071
+ var Vs, Is;
3072
+ class qr extends (Is = b, Vs = c, Is) {
3073
+ constructor(e) {
3074
+ super(e, "string", "PgUUID");
3075
+ }
3076
+ /**
3077
+ * Adds `default gen_random_uuid()` to the column definition.
3078
+ */
3079
+ defaultRandom() {
3080
+ return this.default(q`gen_random_uuid()`);
3081
+ }
3082
+ /** @internal */
3083
+ build(e) {
3084
+ return new Or(e, this.config);
3085
+ }
3086
+ }
3087
+ r(qr, Vs, "PgUUIDBuilder");
3088
+ var js, _s;
3089
+ class Or extends (_s = g, js = c, _s) {
3090
+ getSQLType() {
3091
+ return "uuid";
3092
+ }
3093
+ }
3094
+ r(Or, js, "PgUUID");
3095
+ function ca(n) {
3096
+ return new qr(n ?? "");
3097
+ }
3098
+ var Us, qs;
3099
+ class Mr extends (qs = b, Us = c, qs) {
3100
+ constructor(e, t) {
3101
+ super(e, "string", "PgVarchar"), this.config.length = t.length, this.config.enumValues = t.enum;
3102
+ }
3103
+ /** @internal */
3104
+ build(e) {
3105
+ return new Rr(
3106
+ e,
3107
+ this.config
3108
+ );
3109
+ }
3110
+ }
3111
+ r(Mr, Us, "PgVarcharBuilder");
3112
+ var Os, Ms;
3113
+ class Rr extends (Ms = g, Os = c, Ms) {
3114
+ constructor() {
3115
+ super(...arguments);
3116
+ r(this, "length", this.config.length);
3117
+ r(this, "enumValues", this.config.enumValues);
3118
+ }
3119
+ getSQLType() {
3120
+ return this.length === void 0 ? "varchar" : `varchar(${this.length})`;
3121
+ }
3122
+ }
3123
+ r(Rr, Os, "PgVarchar");
3124
+ function la(n, e = {}) {
3125
+ const { name: t, config: s } = x(n, e);
3126
+ return new Mr(t, s);
3127
+ }
3128
+ var Rs, Js;
3129
+ class Jr extends (Js = b, Rs = c, Js) {
3130
+ constructor(e, t) {
3131
+ super(e, "string", "PgBinaryVector"), this.config.dimensions = t.dimensions;
3132
+ }
3133
+ /** @internal */
3134
+ build(e) {
3135
+ return new Kr(
3136
+ e,
3137
+ this.config
3138
+ );
3139
+ }
3140
+ }
3141
+ r(Jr, Rs, "PgBinaryVectorBuilder");
3142
+ var Ks, Ws;
3143
+ class Kr extends (Ws = g, Ks = c, Ws) {
3144
+ constructor() {
3145
+ super(...arguments);
3146
+ r(this, "dimensions", this.config.dimensions);
3147
+ }
3148
+ getSQLType() {
3149
+ return `bit(${this.dimensions})`;
3150
+ }
3151
+ }
3152
+ r(Kr, Ks, "PgBinaryVector");
3153
+ function ma(n, e) {
3154
+ const { name: t, config: s } = x(n, e);
3155
+ return new Jr(t, s);
3156
+ }
3157
+ var Ys, Gs;
3158
+ class Wr extends (Gs = b, Ys = c, Gs) {
3159
+ constructor(e, t) {
3160
+ super(e, "array", "PgHalfVector"), this.config.dimensions = t.dimensions;
3161
+ }
3162
+ /** @internal */
3163
+ build(e) {
3164
+ return new Yr(
3165
+ e,
3166
+ this.config
3167
+ );
3168
+ }
3169
+ }
3170
+ r(Wr, Ys, "PgHalfVectorBuilder");
3171
+ var Hs, Zs;
3172
+ class Yr extends (Zs = g, Hs = c, Zs) {
3173
+ constructor() {
3174
+ super(...arguments);
3175
+ r(this, "dimensions", this.config.dimensions);
3176
+ }
3177
+ getSQLType() {
3178
+ return `halfvec(${this.dimensions})`;
3179
+ }
3180
+ mapToDriverValue(t) {
3181
+ return JSON.stringify(t);
3182
+ }
3183
+ mapFromDriverValue(t) {
3184
+ return t.slice(1, -1).split(",").map((s) => Number.parseFloat(s));
3185
+ }
3186
+ }
3187
+ r(Yr, Hs, "PgHalfVector");
3188
+ function da(n, e) {
3189
+ const { name: t, config: s } = x(n, e);
3190
+ return new Wr(t, s);
3191
+ }
3192
+ var Xs, ks;
3193
+ class Gr extends (ks = b, Xs = c, ks) {
3194
+ constructor(e, t) {
3195
+ super(e, "string", "PgSparseVector"), this.config.dimensions = t.dimensions;
3196
+ }
3197
+ /** @internal */
3198
+ build(e) {
3199
+ return new Hr(
3200
+ e,
3201
+ this.config
3202
+ );
3203
+ }
3204
+ }
3205
+ r(Gr, Xs, "PgSparseVectorBuilder");
3206
+ var ei, ti;
3207
+ class Hr extends (ti = g, ei = c, ti) {
3208
+ constructor() {
3209
+ super(...arguments);
3210
+ r(this, "dimensions", this.config.dimensions);
3211
+ }
3212
+ getSQLType() {
3213
+ return `sparsevec(${this.dimensions})`;
3214
+ }
3215
+ }
3216
+ r(Hr, ei, "PgSparseVector");
3217
+ function fa(n, e) {
3218
+ const { name: t, config: s } = x(n, e);
3219
+ return new Gr(t, s);
3220
+ }
3221
+ var ni, si;
3222
+ class Zr extends (si = b, ni = c, si) {
3223
+ constructor(e, t) {
3224
+ super(e, "array", "PgVector"), this.config.dimensions = t.dimensions;
3225
+ }
3226
+ /** @internal */
3227
+ build(e) {
3228
+ return new Xr(
3229
+ e,
3230
+ this.config
3231
+ );
3232
+ }
3233
+ }
3234
+ r(Zr, ni, "PgVectorBuilder");
3235
+ var ii, ri;
3236
+ class Xr extends (ri = g, ii = c, ri) {
3237
+ constructor() {
3238
+ super(...arguments);
3239
+ r(this, "dimensions", this.config.dimensions);
3240
+ }
3241
+ getSQLType() {
3242
+ return `vector(${this.dimensions})`;
3243
+ }
3244
+ mapToDriverValue(t) {
3245
+ return JSON.stringify(t);
3246
+ }
3247
+ mapFromDriverValue(t) {
3248
+ return t.slice(1, -1).split(",").map((s) => Number.parseFloat(s));
3249
+ }
3250
+ }
3251
+ r(Xr, ii, "PgVector");
3252
+ function pa(n, e) {
3253
+ const { name: t, config: s } = x(n, e);
3254
+ return new Zr(t, s);
3255
+ }
3256
+ function ha() {
3257
+ return {
3258
+ bigint: Uo,
3259
+ bigserial: qo,
3260
+ boolean: ie,
3261
+ char: Oo,
3262
+ cidr: Mo,
3263
+ customType: Ro,
3264
+ date: Jo,
3265
+ doublePrecision: Ko,
3266
+ inet: Wo,
3267
+ integer: D,
3268
+ interval: Yo,
3269
+ json: Go,
3270
+ jsonb: Ho,
3271
+ line: Zo,
3272
+ macaddr: Xo,
3273
+ macaddr8: ko,
3274
+ numeric: hr,
3275
+ point: ta,
3276
+ geometry: sa,
3277
+ real: ia,
3278
+ serial: ra,
3279
+ smallint: oa,
3280
+ smallserial: aa,
3281
+ text: E,
3282
+ time: ua,
3283
+ timestamp: S,
3284
+ uuid: ca,
3285
+ varchar: la,
3286
+ bit: ma,
3287
+ halfvec: da,
3288
+ sparsevec: fa,
3289
+ vector: pa
3290
+ };
3291
+ }
3292
+ const k = Symbol.for("drizzle:PgInlineForeignKeys"), we = Symbol.for("drizzle:EnableRLS");
3293
+ var oi, ai, ui, ci, li, mi;
3294
+ class M extends (mi = w, li = c, ci = k, ui = we, ai = w.Symbol.ExtraConfigBuilder, oi = w.Symbol.ExtraConfigColumns, mi) {
3295
+ constructor() {
3296
+ super(...arguments);
3297
+ /**@internal */
3298
+ r(this, ci, []);
3299
+ /** @internal */
3300
+ r(this, ui, !1);
3301
+ /** @internal */
3302
+ r(this, ai);
3303
+ /** @internal */
3304
+ r(this, oi, {});
3305
+ }
3306
+ }
3307
+ r(M, li, "PgTable"), /** @internal */
3308
+ r(M, "Symbol", Object.assign({}, w.Symbol, {
3309
+ InlineForeignKeys: k,
3310
+ EnableRLS: we
3311
+ }));
3312
+ function ga(n, e, t, s, i = n) {
3313
+ const o = new M(n, s, i), l = typeof e == "function" ? e(ha()) : e, a = Object.fromEntries(
3314
+ Object.entries(l).map(([u, f]) => {
3315
+ const p = f;
3316
+ p.setName(u);
3317
+ const h = p.build(o);
3318
+ return o[k].push(...p.buildForeignKeys(h, o)), [u, h];
3319
+ })
3320
+ ), m = Object.fromEntries(
3321
+ Object.entries(l).map(([u, f]) => {
3322
+ const p = f;
3323
+ p.setName(u);
3324
+ const h = p.buildExtraConfigColumn(o);
3325
+ return [u, h];
3326
+ })
3327
+ ), d = Object.assign(o, a);
3328
+ return d[w.Symbol.Columns] = a, d[w.Symbol.ExtraConfigColumns] = m, Object.assign(d, {
3329
+ enableRLS: () => (d[M.Symbol.EnableRLS] = !0, d)
3330
+ });
3331
+ }
3332
+ const W = (n, e, t) => ga(n, e, t, void 0), P = W("organisations", {
3333
+ id: D("id").primaryKey(),
3334
+ name: E("name").notNull(),
3335
+ description: E("description"),
3336
+ createdAt: S("created_at").defaultNow(),
3337
+ updatedAt: S("updated_at").defaultNow()
3338
+ }), F = W("departments", {
3339
+ id: D("id").primaryKey(),
3340
+ name: E("name").notNull(),
3341
+ description: E("description"),
3342
+ organisation: D("organisation").notNull().references(() => P.id),
3343
+ createdAt: S("created_at").defaultNow(),
3344
+ updatedAt: S("updated_at").defaultNow()
3345
+ }), L = W("suppliers", {
3346
+ id: D("id").primaryKey(),
3347
+ name: E("name").notNull(),
3348
+ description: E("description"),
3349
+ internal: ie("internal").default(!1),
3350
+ organisation: D("organisation").notNull().references(() => P.id),
3351
+ createdAt: S("created_at").defaultNow(),
3352
+ updatedAt: S("updated_at").defaultNow()
3353
+ }), $ = W("employees", {
3354
+ id: D("id").primaryKey(),
3355
+ name: E("name").notNull(),
3356
+ email: E("email").notNull(),
3357
+ active: ie("active").default(!0),
3358
+ fteBasis: ea("fte_basis", { precision: 3, scale: 2 }).default("1.00"),
3359
+ startDate: S("start_date"),
3360
+ endDate: S("end_date"),
3361
+ department: D("department").references(() => F.id),
3362
+ supplier: D("supplier").references(() => L.id),
3363
+ organisation: D("organisation").notNull().references(() => P.id),
3364
+ createdAt: S("created_at").defaultNow(),
3365
+ updatedAt: S("updated_at").defaultNow()
3366
+ }), ba = J(P, ({ many: n }) => ({
3367
+ departments: n(F),
3368
+ suppliers: n(L),
3369
+ employees: n($)
3370
+ })), ya = J(F, ({ one: n, many: e }) => ({
3371
+ organisation: n(P, {
3372
+ fields: [F.organisation],
3373
+ references: [P.id]
3374
+ }),
3375
+ employees: e($)
3376
+ })), wa = J(L, ({ one: n, many: e }) => ({
3377
+ organisation: n(P, {
3378
+ fields: [L.organisation],
3379
+ references: [P.id]
3380
+ }),
3381
+ employees: e($)
3382
+ })), xa = J($, ({ one: n }) => ({
3383
+ organisation: n(P, {
3384
+ fields: [$.organisation],
3385
+ references: [P.id]
3386
+ }),
3387
+ department: n(F, {
3388
+ fields: [$.department],
3389
+ references: [F.id]
3390
+ }),
3391
+ supplier: n(L, {
3392
+ fields: [$.supplier],
3393
+ references: [L.id]
3394
+ })
3395
+ })), Ba = {
3396
+ organisations: P,
3397
+ departments: F,
3398
+ suppliers: L,
3399
+ employees: $,
3400
+ organisationsRelations: ba,
3401
+ departmentsRelations: ya,
3402
+ suppliersRelations: wa,
3403
+ employeesRelations: xa
3404
+ }, za = wo;
3405
+ function Fa(n) {
3406
+ return new te({
3407
+ drizzle: n.drizzle,
3408
+ schema: n.schema
3409
+ });
3410
+ }
3411
+ const La = {
3412
+ /**
3413
+ * Create a simple query builder
3414
+ */
3415
+ query: () => {
3416
+ const n = (e, t = [], s = [], i = [], o, l) => ({
3417
+ measures: e,
3418
+ dimensions: t,
3419
+ filters: s,
3420
+ timeDimensions: i,
3421
+ limit: o,
3422
+ order: l
519
3423
  });
520
3424
  return {
521
- measures: (n) => ({
522
- dimensions: (i = []) => ({
523
- filters: (t = []) => ({
524
- timeDimensions: (s = []) => ({
525
- limit: (a) => ({
526
- order: (r) => e(n, i, t, s, a, r)
3425
+ measures: (e) => ({
3426
+ dimensions: (t = []) => ({
3427
+ filters: (s = []) => ({
3428
+ timeDimensions: (i = []) => ({
3429
+ limit: (o) => ({
3430
+ order: (l) => n(e, t, s, i, o, l)
527
3431
  }),
528
- order: (a) => e(n, i, t, s, void 0, a)
3432
+ order: (o) => n(e, t, s, i, void 0, o)
529
3433
  }),
530
- limit: (s) => ({
531
- order: (a) => e(n, i, t, [], s, a)
3434
+ limit: (i) => ({
3435
+ order: (o) => n(e, t, s, [], i, o)
532
3436
  }),
533
- order: (s) => e(n, i, t, [], void 0, s)
3437
+ order: (i) => n(e, t, s, [], void 0, i)
534
3438
  }),
535
- timeDimensions: (t = []) => ({
536
- filters: (s = []) => ({
537
- limit: (a) => ({
538
- order: (r) => e(n, i, s, t, a, r)
3439
+ timeDimensions: (s = []) => ({
3440
+ filters: (i = []) => ({
3441
+ limit: (o) => ({
3442
+ order: (l) => n(e, t, i, s, o, l)
539
3443
  }),
540
- order: (a) => e(n, i, s, t, void 0, a)
3444
+ order: (o) => n(e, t, i, s, void 0, o)
541
3445
  }),
542
- limit: (s) => ({
543
- order: (a) => e(n, i, [], t, s, a)
3446
+ limit: (i) => ({
3447
+ order: (o) => n(e, t, [], s, i, o)
544
3448
  }),
545
- order: (s) => e(n, i, [], t, void 0, s)
3449
+ order: (i) => n(e, t, [], s, void 0, i)
546
3450
  }),
547
- limit: (t) => ({
548
- order: (s) => e(n, i, [], [], t, s)
3451
+ limit: (s) => ({
3452
+ order: (i) => n(e, t, [], [], s, i)
549
3453
  }),
550
- order: (t) => e(n, i, [], [], void 0, t)
3454
+ order: (s) => n(e, t, [], [], void 0, s)
551
3455
  }),
552
- filters: (i = []) => ({
553
- dimensions: (t = []) => ({
554
- timeDimensions: (s = []) => ({
555
- limit: (a) => ({
556
- order: (r) => e(n, t, i, s, a, r)
3456
+ filters: (t = []) => ({
3457
+ dimensions: (s = []) => ({
3458
+ timeDimensions: (i = []) => ({
3459
+ limit: (o) => ({
3460
+ order: (l) => n(e, s, t, i, o, l)
557
3461
  }),
558
- order: (a) => e(n, t, i, s, void 0, a)
3462
+ order: (o) => n(e, s, t, i, void 0, o)
559
3463
  }),
560
- limit: (s) => ({
561
- order: (a) => e(n, t, i, [], s, a)
3464
+ limit: (i) => ({
3465
+ order: (o) => n(e, s, t, [], i, o)
562
3466
  }),
563
- order: (s) => e(n, t, i, [], void 0, s)
3467
+ order: (i) => n(e, s, t, [], void 0, i)
564
3468
  }),
565
- timeDimensions: (t = []) => ({
566
- dimensions: (s = []) => ({
567
- limit: (a) => ({
568
- order: (r) => e(n, s, i, t, a, r)
3469
+ timeDimensions: (s = []) => ({
3470
+ dimensions: (i = []) => ({
3471
+ limit: (o) => ({
3472
+ order: (l) => n(e, i, t, s, o, l)
569
3473
  }),
570
- order: (a) => e(n, s, i, t, void 0, a)
3474
+ order: (o) => n(e, i, t, s, void 0, o)
571
3475
  }),
572
- limit: (s) => ({
573
- order: (a) => e(n, [], i, t, s, a)
3476
+ limit: (i) => ({
3477
+ order: (o) => n(e, [], t, s, i, o)
574
3478
  }),
575
- order: (s) => e(n, [], i, t, void 0, s)
3479
+ order: (i) => n(e, [], t, s, void 0, i)
576
3480
  }),
577
- limit: (t) => ({
578
- order: (s) => e(n, [], i, [], t, s)
3481
+ limit: (s) => ({
3482
+ order: (i) => n(e, [], t, [], s, i)
579
3483
  }),
580
- order: (t) => e(n, [], i, [], void 0, t)
3484
+ order: (s) => n(e, [], t, [], void 0, s)
581
3485
  })
582
3486
  })
583
3487
  };
@@ -586,39 +3490,64 @@ const D = {
586
3490
  * Create filters
587
3491
  */
588
3492
  filters: {
589
- equals: (l, e) => ({ member: l, operator: "equals", values: [e] }),
590
- notEquals: (l, e) => ({ member: l, operator: "notEquals", values: [e] }),
591
- contains: (l, e) => ({ member: l, operator: "contains", values: [e] }),
592
- greaterThan: (l, e) => ({ member: l, operator: "gt", values: [e] }),
593
- lessThan: (l, e) => ({ member: l, operator: "lt", values: [e] }),
594
- inDateRange: (l, e, n) => ({
595
- member: l,
3493
+ equals: (n, e) => ({ member: n, operator: "equals", values: [e] }),
3494
+ notEquals: (n, e) => ({ member: n, operator: "notEquals", values: [e] }),
3495
+ contains: (n, e) => ({ member: n, operator: "contains", values: [e] }),
3496
+ greaterThan: (n, e) => ({ member: n, operator: "gt", values: [e] }),
3497
+ lessThan: (n, e) => ({ member: n, operator: "lt", values: [e] }),
3498
+ inDateRange: (n, e, t) => ({
3499
+ member: n,
596
3500
  operator: "inDateRange",
597
- values: [e, n]
3501
+ values: [e, t]
598
3502
  }),
599
- set: (l) => ({ member: l, operator: "set", values: [] }),
600
- notSet: (l) => ({ member: l, operator: "notSet", values: [] })
3503
+ set: (n) => ({ member: n, operator: "set", values: [] }),
3504
+ notSet: (n) => ({ member: n, operator: "notSet", values: [] })
601
3505
  },
602
3506
  /**
603
3507
  * Create time dimensions
604
3508
  */
605
3509
  timeDimensions: {
606
- create: (l, e, n) => ({
607
- dimension: l,
3510
+ create: (n, e, t) => ({
3511
+ dimension: n,
608
3512
  granularity: e,
609
- dateRange: n
3513
+ dateRange: t
610
3514
  })
611
3515
  }
612
3516
  };
613
3517
  export {
614
- d as SemanticLayerCompiler,
615
- D as SemanticLayerUtils,
616
- f as SemanticQueryExecutor,
617
- q as createSemanticLayer,
618
- v as defaultSemanticLayer,
619
- C as departmentsCube,
620
- $ as employeeDepartmentsCube,
621
- g as employeesCube,
622
- T as exampleCubes,
623
- E as semanticLayer
3518
+ ee as BaseDatabaseExecutor,
3519
+ yo as MultiCubeBuilder,
3520
+ ho as MySQLExecutor,
3521
+ fo as PostgresExecutor,
3522
+ de as QueryExecutor,
3523
+ po as SQLiteExecutor,
3524
+ te as SemanticLayerCompiler,
3525
+ La as SemanticLayerUtils,
3526
+ Ea as convertCubeReferences,
3527
+ me as createDatabaseExecutor,
3528
+ Fa as createDrizzleSemanticLayer,
3529
+ bo as createMultiCubeContext,
3530
+ go as createMySQLExecutor,
3531
+ ce as createPostgresExecutor,
3532
+ le as createSQLiteExecutor,
3533
+ Da as createSemanticLayer,
3534
+ za as defaultSemanticLayer,
3535
+ Pa as defineCube,
3536
+ Sa as defineLegacyCube,
3537
+ F as departments,
3538
+ ya as departmentsRelations,
3539
+ $ as employees,
3540
+ xa as employeesRelations,
3541
+ Ba as exampleSchema,
3542
+ Bo as loadYamlCubes,
3543
+ va as loadYamlCubesFromFile,
3544
+ P as organisations,
3545
+ ba as organisationsRelations,
3546
+ xo as parseYamlCubes,
3547
+ v as resolveSqlExpression,
3548
+ $a as semanticCubeToYaml,
3549
+ wo as semanticLayer,
3550
+ L as suppliers,
3551
+ wa as suppliersRelations,
3552
+ To as yamlCubeToSemanticCube
624
3553
  };