drizzle-cube 0.3.30 → 0.3.32
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.
- package/dist/adapters/express/index.cjs +1 -1
- package/dist/adapters/express/index.js +1 -1
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +1 -1
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +1 -1
- package/dist/adapters/{mcp-transport-DkdMX4bA.js → mcp-transport-B2rGcu1X.js} +795 -760
- package/dist/adapters/mcp-transport-DeD7YevT.cjs +257 -0
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/server/index.cjs +31 -31
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +1670 -1635
- package/package.json +1 -1
- package/dist/adapters/mcp-transport-BOb26Vbq.cjs +0 -257
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { formatSqlString as
|
|
2
|
-
const
|
|
1
|
+
import { formatSqlString as te, handleLoad as Ze, handleValidate as et, handleDiscover as tt, generateRequestId as Ct } from "./utils.js";
|
|
2
|
+
const k = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
3
3
|
function L(d, e) {
|
|
4
4
|
if (!d || typeof d != "object")
|
|
5
5
|
return !1;
|
|
6
6
|
if (d instanceof e)
|
|
7
7
|
return !0;
|
|
8
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
8
|
+
if (!Object.prototype.hasOwnProperty.call(e, k))
|
|
9
9
|
throw new Error(
|
|
10
10
|
`Class "${e.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
|
|
11
11
|
);
|
|
12
12
|
let t = Object.getPrototypeOf(d).constructor;
|
|
13
13
|
if (t)
|
|
14
14
|
for (; t; ) {
|
|
15
|
-
if (
|
|
15
|
+
if (k in t && t[k] === e[k])
|
|
16
16
|
return !0;
|
|
17
17
|
t = Object.getPrototypeOf(t);
|
|
18
18
|
}
|
|
19
19
|
return !1;
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class se {
|
|
22
22
|
constructor(e, t) {
|
|
23
23
|
this.table = e, this.config = t, this.name = t.name, this.keyAsName = t.keyAsName, this.notNull = t.notNull, this.default = t.default, this.defaultFn = t.defaultFn, this.onUpdateFn = t.onUpdateFn, this.hasDefault = t.hasDefault, this.primary = t.primaryKey, this.isUnique = t.isUnique, this.uniqueName = t.uniqueName, this.uniqueType = t.uniqueType, this.dataType = t.dataType, this.columnType = t.columnType, this.generated = t.generated, this.generatedIdentity = t.generatedIdentity;
|
|
24
24
|
}
|
|
25
|
-
static [
|
|
25
|
+
static [k] = "Column";
|
|
26
26
|
name;
|
|
27
27
|
keyAsName;
|
|
28
28
|
primary;
|
|
@@ -51,12 +51,12 @@ class te {
|
|
|
51
51
|
return this.config.generated !== void 0 && this.config.generated.type !== "byDefault";
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const
|
|
55
|
-
function
|
|
56
|
-
return !!d && typeof d == "function" &&
|
|
54
|
+
const be = /* @__PURE__ */ Symbol.for("drizzle:Name"), Le = /* @__PURE__ */ Symbol.for("drizzle:isPgEnum");
|
|
55
|
+
function wt(d) {
|
|
56
|
+
return !!d && typeof d == "function" && Le in d && d[Le] === !0;
|
|
57
57
|
}
|
|
58
|
-
class
|
|
59
|
-
static [
|
|
58
|
+
class nt {
|
|
59
|
+
static [k] = "Subquery";
|
|
60
60
|
constructor(e, t, n, s = !1, i = []) {
|
|
61
61
|
this._ = {
|
|
62
62
|
brand: "Subquery",
|
|
@@ -71,88 +71,88 @@ class Ze {
|
|
|
71
71
|
// return new SQL([this]);
|
|
72
72
|
// }
|
|
73
73
|
}
|
|
74
|
-
const
|
|
74
|
+
const $t = {
|
|
75
75
|
startActiveSpan(d, e) {
|
|
76
76
|
return e();
|
|
77
77
|
}
|
|
78
|
-
},
|
|
79
|
-
class
|
|
80
|
-
static [
|
|
78
|
+
}, ne = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig"), ye = /* @__PURE__ */ Symbol.for("drizzle:Schema"), Me = /* @__PURE__ */ Symbol.for("drizzle:Columns"), je = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns"), Ce = /* @__PURE__ */ Symbol.for("drizzle:OriginalName"), we = /* @__PURE__ */ Symbol.for("drizzle:BaseName"), le = /* @__PURE__ */ Symbol.for("drizzle:IsAlias"), Ue = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder"), Tt = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
|
|
79
|
+
class P {
|
|
80
|
+
static [k] = "Table";
|
|
81
81
|
/** @internal */
|
|
82
82
|
static Symbol = {
|
|
83
|
-
Name:
|
|
84
|
-
Schema:
|
|
85
|
-
OriginalName:
|
|
86
|
-
Columns:
|
|
87
|
-
ExtraConfigColumns:
|
|
88
|
-
BaseName:
|
|
89
|
-
IsAlias:
|
|
90
|
-
ExtraConfigBuilder:
|
|
83
|
+
Name: be,
|
|
84
|
+
Schema: ye,
|
|
85
|
+
OriginalName: Ce,
|
|
86
|
+
Columns: Me,
|
|
87
|
+
ExtraConfigColumns: je,
|
|
88
|
+
BaseName: we,
|
|
89
|
+
IsAlias: le,
|
|
90
|
+
ExtraConfigBuilder: Ue
|
|
91
91
|
};
|
|
92
92
|
/**
|
|
93
93
|
* @internal
|
|
94
94
|
* Can be changed if the table is aliased.
|
|
95
95
|
*/
|
|
96
|
-
[
|
|
96
|
+
[be];
|
|
97
97
|
/**
|
|
98
98
|
* @internal
|
|
99
99
|
* Used to store the original name of the table, before any aliasing.
|
|
100
100
|
*/
|
|
101
|
-
[
|
|
101
|
+
[Ce];
|
|
102
102
|
/** @internal */
|
|
103
|
-
[
|
|
103
|
+
[ye];
|
|
104
104
|
/** @internal */
|
|
105
|
-
[
|
|
105
|
+
[Me];
|
|
106
106
|
/** @internal */
|
|
107
|
-
[
|
|
107
|
+
[je];
|
|
108
108
|
/**
|
|
109
109
|
* @internal
|
|
110
110
|
* Used to store the table name before the transformation via the `tableCreator` functions.
|
|
111
111
|
*/
|
|
112
|
-
[
|
|
112
|
+
[we];
|
|
113
113
|
/** @internal */
|
|
114
|
-
[
|
|
114
|
+
[le] = !1;
|
|
115
115
|
/** @internal */
|
|
116
|
-
[
|
|
116
|
+
[Tt] = !0;
|
|
117
117
|
/** @internal */
|
|
118
|
-
[
|
|
118
|
+
[Ue] = void 0;
|
|
119
119
|
constructor(e, t, n) {
|
|
120
|
-
this[
|
|
120
|
+
this[be] = this[Ce] = e, this[ye] = t, this[we] = n;
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function st(d) {
|
|
124
124
|
return d != null && typeof d.getSQL == "function";
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function Et(d) {
|
|
127
127
|
const e = { sql: "", params: [] };
|
|
128
128
|
for (const t of d)
|
|
129
129
|
e.sql += t.sql, e.params.push(...t.params), t.typings?.length && (e.typings || (e.typings = []), e.typings.push(...t.typings));
|
|
130
130
|
return e;
|
|
131
131
|
}
|
|
132
|
-
class
|
|
133
|
-
static [
|
|
132
|
+
class M {
|
|
133
|
+
static [k] = "StringChunk";
|
|
134
134
|
value;
|
|
135
135
|
constructor(e) {
|
|
136
136
|
this.value = Array.isArray(e) ? e : [e];
|
|
137
137
|
}
|
|
138
138
|
getSQL() {
|
|
139
|
-
return new
|
|
139
|
+
return new O([this]);
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
class
|
|
142
|
+
class O {
|
|
143
143
|
constructor(e) {
|
|
144
144
|
this.queryChunks = e;
|
|
145
145
|
for (const t of e)
|
|
146
|
-
if (L(t,
|
|
147
|
-
const n = t[
|
|
146
|
+
if (L(t, P)) {
|
|
147
|
+
const n = t[P.Symbol.Schema];
|
|
148
148
|
this.usedTables.push(
|
|
149
|
-
n === void 0 ? t[
|
|
149
|
+
n === void 0 ? t[P.Symbol.Name] : n + "." + t[P.Symbol.Name]
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
static [
|
|
153
|
+
static [k] = "SQL";
|
|
154
154
|
/** @internal */
|
|
155
|
-
decoder =
|
|
155
|
+
decoder = it;
|
|
156
156
|
shouldInlineParams = !1;
|
|
157
157
|
/** @internal */
|
|
158
158
|
usedTables = [];
|
|
@@ -160,7 +160,7 @@ class F {
|
|
|
160
160
|
return this.queryChunks.push(...e.queryChunks), this;
|
|
161
161
|
}
|
|
162
162
|
toQuery(e) {
|
|
163
|
-
return
|
|
163
|
+
return $t.startActiveSpan("drizzle.buildSQL", (t) => {
|
|
164
164
|
const n = this.buildQueryFromSourceParams(this.queryChunks, e);
|
|
165
165
|
return t?.setAttributes({
|
|
166
166
|
"drizzle.query.text": n.sql,
|
|
@@ -180,68 +180,68 @@ class F {
|
|
|
180
180
|
inlineParams: u,
|
|
181
181
|
paramStartIndex: c
|
|
182
182
|
} = n;
|
|
183
|
-
return
|
|
184
|
-
if (L(l,
|
|
183
|
+
return Et(e.map((l) => {
|
|
184
|
+
if (L(l, M))
|
|
185
185
|
return { sql: l.value.join(""), params: [] };
|
|
186
|
-
if (L(l,
|
|
186
|
+
if (L(l, De))
|
|
187
187
|
return { sql: i(l.value), params: [] };
|
|
188
188
|
if (l === void 0)
|
|
189
189
|
return { sql: "", params: [] };
|
|
190
190
|
if (Array.isArray(l)) {
|
|
191
|
-
const m = [new
|
|
191
|
+
const m = [new M("(")];
|
|
192
192
|
for (const [p, f] of l.entries())
|
|
193
|
-
m.push(f), p < l.length - 1 && m.push(new
|
|
194
|
-
return m.push(new
|
|
193
|
+
m.push(f), p < l.length - 1 && m.push(new M(", "));
|
|
194
|
+
return m.push(new M(")")), this.buildQueryFromSourceParams(m, n);
|
|
195
195
|
}
|
|
196
|
-
if (L(l,
|
|
196
|
+
if (L(l, O))
|
|
197
197
|
return this.buildQueryFromSourceParams(l.queryChunks, {
|
|
198
198
|
...n,
|
|
199
199
|
inlineParams: u || l.shouldInlineParams
|
|
200
200
|
});
|
|
201
|
-
if (L(l,
|
|
202
|
-
const m = l[
|
|
201
|
+
if (L(l, P)) {
|
|
202
|
+
const m = l[P.Symbol.Schema], p = l[P.Symbol.Name];
|
|
203
203
|
return {
|
|
204
|
-
sql: m === void 0 || l[
|
|
204
|
+
sql: m === void 0 || l[le] ? i(p) : i(m) + "." + i(p),
|
|
205
205
|
params: []
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
if (L(l,
|
|
208
|
+
if (L(l, se)) {
|
|
209
209
|
const m = s.getColumnCasing(l);
|
|
210
210
|
if (t.invokeSource === "indexes")
|
|
211
211
|
return { sql: i(m), params: [] };
|
|
212
|
-
const p = l.table[
|
|
212
|
+
const p = l.table[P.Symbol.Schema];
|
|
213
213
|
return {
|
|
214
|
-
sql: l.table[
|
|
214
|
+
sql: l.table[le] || p === void 0 ? i(l.table[P.Symbol.Name]) + "." + i(m) : i(p) + "." + i(l.table[P.Symbol.Name]) + "." + i(m),
|
|
215
215
|
params: []
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
|
-
if (L(l,
|
|
219
|
-
const m = l[
|
|
218
|
+
if (L(l, ot)) {
|
|
219
|
+
const m = l[ne].schema, p = l[ne].name;
|
|
220
220
|
return {
|
|
221
|
-
sql: m === void 0 || l[
|
|
221
|
+
sql: m === void 0 || l[ne].isAlias ? i(p) : i(m) + "." + i(p),
|
|
222
222
|
params: []
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
|
-
if (L(l,
|
|
226
|
-
if (L(l.value,
|
|
225
|
+
if (L(l, ce)) {
|
|
226
|
+
if (L(l.value, de))
|
|
227
227
|
return { sql: r(c.value++, l), params: [l], typings: ["none"] };
|
|
228
228
|
const m = l.value === null ? null : l.encoder.mapToDriverValue(l.value);
|
|
229
|
-
if (L(m,
|
|
229
|
+
if (L(m, O))
|
|
230
230
|
return this.buildQueryFromSourceParams([m], n);
|
|
231
231
|
if (u)
|
|
232
232
|
return { sql: this.mapInlineParam(m, n), params: [] };
|
|
233
233
|
let p = ["none"];
|
|
234
234
|
return a && (p = [a(l.encoder)]), { sql: r(c.value++, m), params: [m], typings: p };
|
|
235
235
|
}
|
|
236
|
-
return L(l,
|
|
237
|
-
new
|
|
236
|
+
return L(l, de) ? { sql: r(c.value++, l), params: [l], typings: ["none"] } : L(l, O.Aliased) && l.fieldAlias !== void 0 ? { sql: i(l.fieldAlias), params: [] } : L(l, nt) ? l._.isWith ? { sql: i(l._.alias), params: [] } : this.buildQueryFromSourceParams([
|
|
237
|
+
new M("("),
|
|
238
238
|
l._.sql,
|
|
239
|
-
new
|
|
240
|
-
new
|
|
241
|
-
], n) :
|
|
242
|
-
new
|
|
239
|
+
new M(") "),
|
|
240
|
+
new De(l._.alias)
|
|
241
|
+
], n) : wt(l) ? l.schema ? { sql: i(l.schema) + "." + i(l.enumName), params: [] } : { sql: i(l.enumName), params: [] } : st(l) ? l.shouldOmitSQLParens?.() ? this.buildQueryFromSourceParams([l.getSQL()], n) : this.buildQueryFromSourceParams([
|
|
242
|
+
new M("("),
|
|
243
243
|
l.getSQL(),
|
|
244
|
-
new
|
|
244
|
+
new M(")")
|
|
245
245
|
], n) : u ? { sql: this.mapInlineParam(l, n), params: [] } : { sql: r(c.value++, l), params: [l], typings: ["none"] };
|
|
246
246
|
}));
|
|
247
247
|
}
|
|
@@ -262,7 +262,7 @@ class F {
|
|
|
262
262
|
return this;
|
|
263
263
|
}
|
|
264
264
|
as(e) {
|
|
265
|
-
return e === void 0 ? this : new
|
|
265
|
+
return e === void 0 ? this : new O.Aliased(this, e);
|
|
266
266
|
}
|
|
267
267
|
mapWith(e) {
|
|
268
268
|
return this.decoder = typeof e == "function" ? { mapFromDriverValue: e } : e, this;
|
|
@@ -280,79 +280,79 @@ class F {
|
|
|
280
280
|
return e ? this : void 0;
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
class
|
|
283
|
+
class De {
|
|
284
284
|
constructor(e) {
|
|
285
285
|
this.value = e;
|
|
286
286
|
}
|
|
287
|
-
static [
|
|
287
|
+
static [k] = "Name";
|
|
288
288
|
brand;
|
|
289
289
|
getSQL() {
|
|
290
|
-
return new
|
|
290
|
+
return new O([this]);
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
-
function
|
|
293
|
+
function St(d) {
|
|
294
294
|
return typeof d == "object" && d !== null && "mapToDriverValue" in d && typeof d.mapToDriverValue == "function";
|
|
295
295
|
}
|
|
296
|
-
const
|
|
296
|
+
const it = {
|
|
297
297
|
mapFromDriverValue: (d) => d
|
|
298
|
-
},
|
|
298
|
+
}, rt = {
|
|
299
299
|
mapToDriverValue: (d) => d
|
|
300
300
|
};
|
|
301
301
|
({
|
|
302
|
-
...
|
|
303
|
-
...
|
|
302
|
+
...it,
|
|
303
|
+
...rt
|
|
304
304
|
});
|
|
305
|
-
class
|
|
305
|
+
class ce {
|
|
306
306
|
/**
|
|
307
307
|
* @param value - Parameter value
|
|
308
308
|
* @param encoder - Encoder to convert the value to a driver parameter
|
|
309
309
|
*/
|
|
310
|
-
constructor(e, t =
|
|
310
|
+
constructor(e, t = rt) {
|
|
311
311
|
this.value = e, this.encoder = t;
|
|
312
312
|
}
|
|
313
|
-
static [
|
|
313
|
+
static [k] = "Param";
|
|
314
314
|
brand;
|
|
315
315
|
getSQL() {
|
|
316
|
-
return new
|
|
316
|
+
return new O([this]);
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
function o(d, ...e) {
|
|
320
320
|
const t = [];
|
|
321
|
-
(e.length > 0 || d.length > 0 && d[0] !== "") && t.push(new
|
|
321
|
+
(e.length > 0 || d.length > 0 && d[0] !== "") && t.push(new M(d[0]));
|
|
322
322
|
for (const [n, s] of e.entries())
|
|
323
|
-
t.push(s, new
|
|
324
|
-
return new
|
|
323
|
+
t.push(s, new M(d[n + 1]));
|
|
324
|
+
return new O(t);
|
|
325
325
|
}
|
|
326
326
|
((d) => {
|
|
327
327
|
function e() {
|
|
328
|
-
return new
|
|
328
|
+
return new O([]);
|
|
329
329
|
}
|
|
330
330
|
d.empty = e;
|
|
331
331
|
function t(u) {
|
|
332
|
-
return new
|
|
332
|
+
return new O(u);
|
|
333
333
|
}
|
|
334
334
|
d.fromList = t;
|
|
335
335
|
function n(u) {
|
|
336
|
-
return new
|
|
336
|
+
return new O([new M(u)]);
|
|
337
337
|
}
|
|
338
338
|
d.raw = n;
|
|
339
339
|
function s(u, c) {
|
|
340
340
|
const l = [];
|
|
341
341
|
for (const [m, p] of u.entries())
|
|
342
342
|
m > 0 && c !== void 0 && l.push(c), l.push(p);
|
|
343
|
-
return new
|
|
343
|
+
return new O(l);
|
|
344
344
|
}
|
|
345
345
|
d.join = s;
|
|
346
346
|
function i(u) {
|
|
347
|
-
return new
|
|
347
|
+
return new De(u);
|
|
348
348
|
}
|
|
349
349
|
d.identifier = i;
|
|
350
350
|
function r(u) {
|
|
351
|
-
return new
|
|
351
|
+
return new de(u);
|
|
352
352
|
}
|
|
353
353
|
d.placeholder = r;
|
|
354
354
|
function a(u, c) {
|
|
355
|
-
return new
|
|
355
|
+
return new ce(u, c);
|
|
356
356
|
}
|
|
357
357
|
d.param = a;
|
|
358
358
|
})(o || (o = {}));
|
|
@@ -361,7 +361,7 @@ function o(d, ...e) {
|
|
|
361
361
|
constructor(n, s) {
|
|
362
362
|
this.sql = n, this.fieldAlias = s;
|
|
363
363
|
}
|
|
364
|
-
static [
|
|
364
|
+
static [k] = "SQL.Aliased";
|
|
365
365
|
/** @internal */
|
|
366
366
|
isSelectionField = !1;
|
|
367
367
|
getSQL() {
|
|
@@ -373,25 +373,25 @@ function o(d, ...e) {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
d.Aliased = e;
|
|
376
|
-
})(
|
|
377
|
-
class
|
|
376
|
+
})(O || (O = {}));
|
|
377
|
+
class de {
|
|
378
378
|
constructor(e) {
|
|
379
379
|
this.name = e;
|
|
380
380
|
}
|
|
381
|
-
static [
|
|
381
|
+
static [k] = "Placeholder";
|
|
382
382
|
getSQL() {
|
|
383
|
-
return new
|
|
383
|
+
return new O([this]);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
const
|
|
387
|
-
class
|
|
388
|
-
static [
|
|
386
|
+
const Nt = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
|
|
387
|
+
class ot {
|
|
388
|
+
static [k] = "View";
|
|
389
389
|
/** @internal */
|
|
390
|
-
[
|
|
390
|
+
[ne];
|
|
391
391
|
/** @internal */
|
|
392
|
-
[
|
|
392
|
+
[Nt] = !0;
|
|
393
393
|
constructor({ name: e, schema: t, selectedFields: n, query: s }) {
|
|
394
|
-
this[
|
|
394
|
+
this[ne] = {
|
|
395
395
|
name: e,
|
|
396
396
|
originalName: e,
|
|
397
397
|
schema: t,
|
|
@@ -402,106 +402,106 @@ class st {
|
|
|
402
402
|
};
|
|
403
403
|
}
|
|
404
404
|
getSQL() {
|
|
405
|
-
return new
|
|
405
|
+
return new O([this]);
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
|
|
409
|
-
return new
|
|
408
|
+
se.prototype.getSQL = function() {
|
|
409
|
+
return new O([this]);
|
|
410
410
|
};
|
|
411
|
-
|
|
412
|
-
return new
|
|
411
|
+
P.prototype.getSQL = function() {
|
|
412
|
+
return new O([this]);
|
|
413
413
|
};
|
|
414
|
-
|
|
415
|
-
return new
|
|
414
|
+
nt.prototype.getSQL = function() {
|
|
415
|
+
return new O([this]);
|
|
416
416
|
};
|
|
417
|
-
function
|
|
418
|
-
return
|
|
417
|
+
function x(d, e) {
|
|
418
|
+
return St(e) && !st(d) && !L(d, ce) && !L(d, de) && !L(d, se) && !L(d, P) && !L(d, ot) ? new ce(d, e) : d;
|
|
419
419
|
}
|
|
420
|
-
const
|
|
420
|
+
const Q = (d, e) => o`${d} = ${x(e, d)}`, xe = (d, e) => o`${d} <> ${x(e, d)}`;
|
|
421
421
|
function A(...d) {
|
|
422
422
|
const e = d.filter(
|
|
423
423
|
(t) => t !== void 0
|
|
424
424
|
);
|
|
425
425
|
if (e.length !== 0)
|
|
426
|
-
return e.length === 1 ? new
|
|
427
|
-
new
|
|
428
|
-
o.join(e, new
|
|
429
|
-
new
|
|
426
|
+
return e.length === 1 ? new O(e) : new O([
|
|
427
|
+
new M("("),
|
|
428
|
+
o.join(e, new M(" and ")),
|
|
429
|
+
new M(")")
|
|
430
430
|
]);
|
|
431
431
|
}
|
|
432
|
-
function
|
|
432
|
+
function re(...d) {
|
|
433
433
|
const e = d.filter(
|
|
434
434
|
(t) => t !== void 0
|
|
435
435
|
);
|
|
436
436
|
if (e.length !== 0)
|
|
437
|
-
return e.length === 1 ? new
|
|
438
|
-
new
|
|
439
|
-
o.join(e, new
|
|
440
|
-
new
|
|
437
|
+
return e.length === 1 ? new O(e) : new O([
|
|
438
|
+
new M("("),
|
|
439
|
+
o.join(e, new M(" or ")),
|
|
440
|
+
new M(")")
|
|
441
441
|
]);
|
|
442
442
|
}
|
|
443
|
-
const
|
|
444
|
-
function
|
|
445
|
-
return Array.isArray(e) ? e.length === 0 ? o`false` : o`${d} in ${e.map((t) =>
|
|
443
|
+
const $e = (d, e) => o`${d} > ${x(e, d)}`, Z = (d, e) => o`${d} >= ${x(e, d)}`, Te = (d, e) => o`${d} < ${x(e, d)}`, ee = (d, e) => o`${d} <= ${x(e, d)}`;
|
|
444
|
+
function Ee(d, e) {
|
|
445
|
+
return Array.isArray(e) ? e.length === 0 ? o`false` : o`${d} in ${e.map((t) => x(t, d))}` : o`${d} in ${x(e, d)}`;
|
|
446
446
|
}
|
|
447
|
-
function
|
|
448
|
-
return Array.isArray(e) ? e.length === 0 ? o`true` : o`${d} not in ${e.map((t) =>
|
|
447
|
+
function ke(d, e) {
|
|
448
|
+
return Array.isArray(e) ? e.length === 0 ? o`true` : o`${d} not in ${e.map((t) => x(t, d))}` : o`${d} not in ${x(e, d)}`;
|
|
449
449
|
}
|
|
450
|
-
function
|
|
450
|
+
function Be(d) {
|
|
451
451
|
return o`${d} is null`;
|
|
452
452
|
}
|
|
453
|
-
function
|
|
453
|
+
function Pe(d) {
|
|
454
454
|
return o`${d} is not null`;
|
|
455
455
|
}
|
|
456
|
-
function
|
|
456
|
+
function Dt(d, e) {
|
|
457
457
|
if (Array.isArray(e)) {
|
|
458
458
|
if (e.length === 0)
|
|
459
459
|
throw new Error("arrayContains requires at least one value");
|
|
460
|
-
const t = o`${
|
|
460
|
+
const t = o`${x(e, d)}`;
|
|
461
461
|
return o`${d} @> ${t}`;
|
|
462
462
|
}
|
|
463
|
-
return o`${d} @> ${
|
|
463
|
+
return o`${d} @> ${x(e, d)}`;
|
|
464
464
|
}
|
|
465
|
-
function
|
|
465
|
+
function At(d, e) {
|
|
466
466
|
if (Array.isArray(e)) {
|
|
467
467
|
if (e.length === 0)
|
|
468
468
|
throw new Error("arrayContained requires at least one value");
|
|
469
|
-
const t = o`${
|
|
469
|
+
const t = o`${x(e, d)}`;
|
|
470
470
|
return o`${d} <@ ${t}`;
|
|
471
471
|
}
|
|
472
|
-
return o`${d} <@ ${
|
|
472
|
+
return o`${d} <@ ${x(e, d)}`;
|
|
473
473
|
}
|
|
474
|
-
function
|
|
474
|
+
function _t(d, e) {
|
|
475
475
|
if (Array.isArray(e)) {
|
|
476
476
|
if (e.length === 0)
|
|
477
477
|
throw new Error("arrayOverlaps requires at least one value");
|
|
478
|
-
const t = o`${
|
|
478
|
+
const t = o`${x(e, d)}`;
|
|
479
479
|
return o`${d} && ${t}`;
|
|
480
480
|
}
|
|
481
|
-
return o`${d} && ${
|
|
481
|
+
return o`${d} && ${x(e, d)}`;
|
|
482
482
|
}
|
|
483
|
-
function
|
|
483
|
+
function Qe(d) {
|
|
484
484
|
return o`${d} asc`;
|
|
485
485
|
}
|
|
486
|
-
function
|
|
486
|
+
function vt(d) {
|
|
487
487
|
return o`${d} desc`;
|
|
488
488
|
}
|
|
489
|
-
function
|
|
489
|
+
function Ae(d) {
|
|
490
490
|
return o`count(${d || o.raw("*")})`.mapWith(Number);
|
|
491
491
|
}
|
|
492
|
-
function
|
|
492
|
+
function Rt(d) {
|
|
493
493
|
return o`count(distinct ${d})`.mapWith(Number);
|
|
494
494
|
}
|
|
495
|
-
function
|
|
495
|
+
function z(d) {
|
|
496
496
|
return o`sum(${d})`.mapWith(String);
|
|
497
497
|
}
|
|
498
|
-
function
|
|
499
|
-
return o`max(${d})`.mapWith(L(d,
|
|
498
|
+
function G(d) {
|
|
499
|
+
return o`max(${d})`.mapWith(L(d, se) ? d : String);
|
|
500
500
|
}
|
|
501
|
-
function
|
|
502
|
-
return o`min(${d})`.mapWith(L(d,
|
|
501
|
+
function oe(d) {
|
|
502
|
+
return o`min(${d})`.mapWith(L(d, se) ? d : String);
|
|
503
503
|
}
|
|
504
|
-
class
|
|
504
|
+
class pe {
|
|
505
505
|
/**
|
|
506
506
|
* Default implementation returns template unchanged
|
|
507
507
|
* Override in specific adapters for database-specific preprocessing
|
|
@@ -549,7 +549,7 @@ class fe {
|
|
|
549
549
|
return t.years * 365 * 24 * 60 * 60 + t.months * 30 * 24 * 60 * 60 + t.days * 24 * 60 * 60 + t.hours * 60 * 60 + t.minutes * 60 + t.seconds;
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
class
|
|
552
|
+
class Ft extends pe {
|
|
553
553
|
getEngineType() {
|
|
554
554
|
return "postgres";
|
|
555
555
|
}
|
|
@@ -820,7 +820,7 @@ class At extends fe {
|
|
|
820
820
|
}
|
|
821
821
|
}
|
|
822
822
|
}
|
|
823
|
-
class
|
|
823
|
+
class at extends pe {
|
|
824
824
|
getEngineType() {
|
|
825
825
|
return "mysql";
|
|
826
826
|
}
|
|
@@ -1098,7 +1098,7 @@ class it extends fe {
|
|
|
1098
1098
|
}
|
|
1099
1099
|
}
|
|
1100
1100
|
}
|
|
1101
|
-
class
|
|
1101
|
+
class Ot extends pe {
|
|
1102
1102
|
getEngineType() {
|
|
1103
1103
|
return "sqlite";
|
|
1104
1104
|
}
|
|
@@ -1415,7 +1415,7 @@ class _t extends fe {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
}
|
|
1418
|
-
class
|
|
1418
|
+
class It extends at {
|
|
1419
1419
|
getEngineType() {
|
|
1420
1420
|
return "singlestore";
|
|
1421
1421
|
}
|
|
@@ -1428,7 +1428,7 @@ class vt extends it {
|
|
|
1428
1428
|
// These limitations are typically handled at the query building level
|
|
1429
1429
|
// rather than in the adapter, but can be addressed here if needed
|
|
1430
1430
|
}
|
|
1431
|
-
class
|
|
1431
|
+
class Lt extends pe {
|
|
1432
1432
|
getEngineType() {
|
|
1433
1433
|
return "duckdb";
|
|
1434
1434
|
}
|
|
@@ -1693,31 +1693,31 @@ class Rt extends fe {
|
|
|
1693
1693
|
}
|
|
1694
1694
|
}
|
|
1695
1695
|
}
|
|
1696
|
-
function
|
|
1696
|
+
function Mt(d) {
|
|
1697
1697
|
switch (d) {
|
|
1698
1698
|
case "postgres":
|
|
1699
|
-
return new
|
|
1699
|
+
return new Ft();
|
|
1700
1700
|
case "mysql":
|
|
1701
|
-
return new
|
|
1701
|
+
return new at();
|
|
1702
1702
|
case "sqlite":
|
|
1703
|
-
return new
|
|
1703
|
+
return new Ot();
|
|
1704
1704
|
case "singlestore":
|
|
1705
|
-
return new
|
|
1705
|
+
return new It();
|
|
1706
1706
|
case "duckdb":
|
|
1707
|
-
return new
|
|
1707
|
+
return new Lt();
|
|
1708
1708
|
default:
|
|
1709
1709
|
throw new Error(`Unsupported database engine: ${d}`);
|
|
1710
1710
|
}
|
|
1711
1711
|
}
|
|
1712
|
-
class
|
|
1712
|
+
class he {
|
|
1713
1713
|
constructor(e, t, n) {
|
|
1714
1714
|
this.db = e, this.schema = t;
|
|
1715
1715
|
const s = n || this.getEngineType();
|
|
1716
|
-
this.databaseAdapter =
|
|
1716
|
+
this.databaseAdapter = Mt(s);
|
|
1717
1717
|
}
|
|
1718
1718
|
databaseAdapter;
|
|
1719
1719
|
}
|
|
1720
|
-
function
|
|
1720
|
+
function jt(d, e) {
|
|
1721
1721
|
const t = [], n = [];
|
|
1722
1722
|
let s = !1, i, r, a;
|
|
1723
1723
|
const u = [];
|
|
@@ -1732,7 +1732,7 @@ function Ot(d, e) {
|
|
|
1732
1732
|
r = parseFloat(p[1]);
|
|
1733
1733
|
continue;
|
|
1734
1734
|
}
|
|
1735
|
-
const f =
|
|
1735
|
+
const f = Ut(l);
|
|
1736
1736
|
if (f) {
|
|
1737
1737
|
f.type.includes("Seq Scan") && (s = !0), f.index && n.push(f.index), t.length === 0 && f.estimatedCost !== void 0 && (a = f.estimatedCost);
|
|
1738
1738
|
const h = l.search(/\S/);
|
|
@@ -1764,7 +1764,7 @@ function Ot(d, e) {
|
|
|
1764
1764
|
sql: e
|
|
1765
1765
|
};
|
|
1766
1766
|
}
|
|
1767
|
-
function
|
|
1767
|
+
function Ut(d) {
|
|
1768
1768
|
const e = d.replace(/^[\s->]+/, "").trim();
|
|
1769
1769
|
if (!e) return null;
|
|
1770
1770
|
const t = e.match(
|
|
@@ -1784,7 +1784,7 @@ function It(d) {
|
|
|
1784
1784
|
const l = d.match(/Filter:\s*(.+?)(?:\)|$)/i);
|
|
1785
1785
|
return l && (c.filter = l[1].trim()), c;
|
|
1786
1786
|
}
|
|
1787
|
-
class
|
|
1787
|
+
class xt extends he {
|
|
1788
1788
|
async execute(e, t) {
|
|
1789
1789
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1790
1790
|
const s = await e.execute();
|
|
@@ -1854,7 +1854,7 @@ class Lt extends pe {
|
|
|
1854
1854
|
typeof u == "string" && r.push(u);
|
|
1855
1855
|
}
|
|
1856
1856
|
}
|
|
1857
|
-
return
|
|
1857
|
+
return jt(r, { sql: e, params: t });
|
|
1858
1858
|
}
|
|
1859
1859
|
/**
|
|
1860
1860
|
* Get existing indexes for the specified tables
|
|
@@ -1895,10 +1895,10 @@ class Lt extends pe {
|
|
|
1895
1895
|
}
|
|
1896
1896
|
}
|
|
1897
1897
|
}
|
|
1898
|
-
function
|
|
1899
|
-
return new
|
|
1898
|
+
function We(d, e) {
|
|
1899
|
+
return new xt(d, e, "postgres");
|
|
1900
1900
|
}
|
|
1901
|
-
function
|
|
1901
|
+
function kt(d, e) {
|
|
1902
1902
|
const t = e?.toLowerCase() || "";
|
|
1903
1903
|
switch (d.toLowerCase()) {
|
|
1904
1904
|
case "all":
|
|
@@ -1920,11 +1920,11 @@ function Mt(d, e) {
|
|
|
1920
1920
|
return `MySQL ${d}`;
|
|
1921
1921
|
}
|
|
1922
1922
|
}
|
|
1923
|
-
function
|
|
1923
|
+
function Bt(d, e) {
|
|
1924
1924
|
const t = [], n = [];
|
|
1925
1925
|
let s = !1, i = 0;
|
|
1926
1926
|
for (const u of d) {
|
|
1927
|
-
const c =
|
|
1927
|
+
const c = kt(u.type, u.Extra);
|
|
1928
1928
|
u.type.toLowerCase() === "all" && (s = !0), u.key && n.push(u.key);
|
|
1929
1929
|
const l = {
|
|
1930
1930
|
type: c,
|
|
@@ -1963,7 +1963,7 @@ function jt(d, e) {
|
|
|
1963
1963
|
sql: e
|
|
1964
1964
|
};
|
|
1965
1965
|
}
|
|
1966
|
-
class
|
|
1966
|
+
class ut extends he {
|
|
1967
1967
|
async execute(e, t) {
|
|
1968
1968
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
1969
1969
|
const s = await e.execute();
|
|
@@ -2031,7 +2031,7 @@ class rt extends pe {
|
|
|
2031
2031
|
filtered: Number(c.filtered) || 100,
|
|
2032
2032
|
Extra: c.Extra || null
|
|
2033
2033
|
});
|
|
2034
|
-
return
|
|
2034
|
+
return Bt(u, { sql: e, params: t });
|
|
2035
2035
|
}
|
|
2036
2036
|
/**
|
|
2037
2037
|
* Get existing indexes for the specified tables
|
|
@@ -2067,10 +2067,10 @@ class rt extends pe {
|
|
|
2067
2067
|
}
|
|
2068
2068
|
}
|
|
2069
2069
|
}
|
|
2070
|
-
function
|
|
2071
|
-
return new
|
|
2070
|
+
function Pt(d, e) {
|
|
2071
|
+
return new ut(d, e, "mysql");
|
|
2072
2072
|
}
|
|
2073
|
-
function
|
|
2073
|
+
function Qt(d) {
|
|
2074
2074
|
const e = d.toLowerCase(), t = d.match(/^SCAN\s+(\S+)/i);
|
|
2075
2075
|
if (t)
|
|
2076
2076
|
return {
|
|
@@ -2102,12 +2102,12 @@ function kt(d) {
|
|
|
2102
2102
|
table: i[1]
|
|
2103
2103
|
} : e.includes("temp b-tree") ? e.includes("order by") ? { type: "Sort" } : e.includes("group by") ? { type: "Group" } : e.includes("distinct") ? { type: "Distinct" } : { type: "Temp B-Tree" } : e.includes("compound") ? { type: "Compound Query" } : e.includes("subquery") ? { type: "Subquery" } : e.includes("co-routine") ? { type: "Coroutine" } : { type: d };
|
|
2104
2104
|
}
|
|
2105
|
-
function
|
|
2105
|
+
function Wt(d, e) {
|
|
2106
2106
|
const t = [], n = [];
|
|
2107
2107
|
let s = !1;
|
|
2108
2108
|
const i = /* @__PURE__ */ new Map();
|
|
2109
2109
|
for (const u of d) {
|
|
2110
|
-
const c =
|
|
2110
|
+
const c = Qt(u.detail);
|
|
2111
2111
|
c.type === "Seq Scan" && (s = !0), c.index && n.push(c.index);
|
|
2112
2112
|
const l = {
|
|
2113
2113
|
type: c.type,
|
|
@@ -2145,7 +2145,7 @@ function xt(d, e) {
|
|
|
2145
2145
|
sql: e
|
|
2146
2146
|
};
|
|
2147
2147
|
}
|
|
2148
|
-
class
|
|
2148
|
+
class Kt extends he {
|
|
2149
2149
|
async execute(e, t) {
|
|
2150
2150
|
if (e && typeof e == "object" && typeof e.execute == "function") {
|
|
2151
2151
|
const n = await e.execute();
|
|
@@ -2215,7 +2215,7 @@ class Bt extends pe {
|
|
|
2215
2215
|
notused: Number(c.notused) || 0,
|
|
2216
2216
|
detail: String(c.detail || "")
|
|
2217
2217
|
});
|
|
2218
|
-
return
|
|
2218
|
+
return Wt(u, { sql: e, params: t });
|
|
2219
2219
|
}
|
|
2220
2220
|
/**
|
|
2221
2221
|
* Get existing indexes for the specified tables
|
|
@@ -2256,10 +2256,10 @@ class Bt extends pe {
|
|
|
2256
2256
|
}
|
|
2257
2257
|
}
|
|
2258
2258
|
}
|
|
2259
|
-
function
|
|
2260
|
-
return new
|
|
2259
|
+
function Ke(d, e) {
|
|
2260
|
+
return new Kt(d, e, "sqlite");
|
|
2261
2261
|
}
|
|
2262
|
-
class
|
|
2262
|
+
class qt extends ut {
|
|
2263
2263
|
getEngineType() {
|
|
2264
2264
|
return "singlestore";
|
|
2265
2265
|
}
|
|
@@ -2267,19 +2267,19 @@ class Pt extends rt {
|
|
|
2267
2267
|
// For now, we inherit all behavior from MySQLExecutor since
|
|
2268
2268
|
// SingleStore is largely MySQL-compatible
|
|
2269
2269
|
}
|
|
2270
|
-
function
|
|
2271
|
-
return new
|
|
2270
|
+
function zt(d, e) {
|
|
2271
|
+
return new qt(d, e);
|
|
2272
2272
|
}
|
|
2273
|
-
function
|
|
2273
|
+
function Vt(d, e) {
|
|
2274
2274
|
const t = [], n = [];
|
|
2275
2275
|
let s = !1, i;
|
|
2276
2276
|
const r = [];
|
|
2277
2277
|
for (const u of d) {
|
|
2278
2278
|
if (/^[┌├└│─┐┤┘]+$/.test(u.trim()) || /EXPLANATION|QUERY PLAN/i.test(u)) continue;
|
|
2279
|
-
const c =
|
|
2279
|
+
const c = Gt(u);
|
|
2280
2280
|
if (c) {
|
|
2281
2281
|
(c.type.includes("SEQ_SCAN") || c.type.includes("TABLE_SCAN")) && (s = !0), c.type.includes("INDEX_SCAN") && c.index && n.push(c.index), t.length === 0 && c.estimatedCost !== void 0 && (i = c.estimatedCost);
|
|
2282
|
-
const l =
|
|
2282
|
+
const l = Jt(u);
|
|
2283
2283
|
for (; r.length > 0 && r[r.length - 1].indent >= l; )
|
|
2284
2284
|
r.pop();
|
|
2285
2285
|
if (r.length === 0)
|
|
@@ -2307,7 +2307,7 @@ function Wt(d, e) {
|
|
|
2307
2307
|
sql: e
|
|
2308
2308
|
};
|
|
2309
2309
|
}
|
|
2310
|
-
function
|
|
2310
|
+
function Jt(d) {
|
|
2311
2311
|
let e = 0;
|
|
2312
2312
|
for (const t of d)
|
|
2313
2313
|
if (t === " " || t === "│" || t === "├" || t === "└" || t === "─")
|
|
@@ -2316,7 +2316,7 @@ function Kt(d) {
|
|
|
2316
2316
|
break;
|
|
2317
2317
|
return e;
|
|
2318
2318
|
}
|
|
2319
|
-
function
|
|
2319
|
+
function Gt(d) {
|
|
2320
2320
|
const e = d.replace(/[┌├└│─┐┤┘]/g, "").replace(/^\s*/, "").trim();
|
|
2321
2321
|
if (!e || e.match(/^\(cost=([\d.]+)\s+rows=(\d+)\)$/i))
|
|
2322
2322
|
return null;
|
|
@@ -2345,7 +2345,7 @@ function qt(d) {
|
|
|
2345
2345
|
estimatedCost: a
|
|
2346
2346
|
};
|
|
2347
2347
|
}
|
|
2348
|
-
class
|
|
2348
|
+
class Ht extends he {
|
|
2349
2349
|
async execute(e, t) {
|
|
2350
2350
|
if (e && typeof e == "object" && typeof e.execute == "function")
|
|
2351
2351
|
try {
|
|
@@ -2450,7 +2450,7 @@ class zt extends pe {
|
|
|
2450
2450
|
typeof u == "string" && r.push(u);
|
|
2451
2451
|
}
|
|
2452
2452
|
}
|
|
2453
|
-
return
|
|
2453
|
+
return Vt(r, { sql: e, params: t });
|
|
2454
2454
|
}
|
|
2455
2455
|
/**
|
|
2456
2456
|
* Get existing indexes for the specified tables
|
|
@@ -2486,33 +2486,33 @@ class zt extends pe {
|
|
|
2486
2486
|
}
|
|
2487
2487
|
}
|
|
2488
2488
|
}
|
|
2489
|
-
function
|
|
2490
|
-
return new
|
|
2489
|
+
function Yt(d, e) {
|
|
2490
|
+
return new Ht(d, e, "duckdb");
|
|
2491
2491
|
}
|
|
2492
|
-
function
|
|
2492
|
+
function qe(d, e, t) {
|
|
2493
2493
|
if (t)
|
|
2494
2494
|
switch (t) {
|
|
2495
2495
|
case "postgres":
|
|
2496
|
-
return
|
|
2496
|
+
return We(d, e);
|
|
2497
2497
|
case "mysql":
|
|
2498
|
-
return
|
|
2498
|
+
return Pt(d, e);
|
|
2499
2499
|
case "sqlite":
|
|
2500
|
-
return
|
|
2500
|
+
return Ke(d, e);
|
|
2501
2501
|
case "singlestore":
|
|
2502
|
-
return
|
|
2502
|
+
return zt(d, e);
|
|
2503
2503
|
case "duckdb":
|
|
2504
|
-
return
|
|
2504
|
+
return Yt(d, e);
|
|
2505
2505
|
}
|
|
2506
2506
|
if (d.all && d.run)
|
|
2507
|
-
return
|
|
2507
|
+
return Ke(d, e);
|
|
2508
2508
|
if (d.execute)
|
|
2509
|
-
return
|
|
2509
|
+
return We(d, e);
|
|
2510
2510
|
throw new Error("Unable to determine database engine type. Please specify engineType parameter.");
|
|
2511
2511
|
}
|
|
2512
|
-
function
|
|
2512
|
+
function W(d) {
|
|
2513
2513
|
return typeof d == "function" ? d() : d;
|
|
2514
2514
|
}
|
|
2515
|
-
function
|
|
2515
|
+
function _e(d, e) {
|
|
2516
2516
|
if (e) return e;
|
|
2517
2517
|
switch (d) {
|
|
2518
2518
|
case "belongsTo":
|
|
@@ -2531,24 +2531,24 @@ function Ae(d, e) {
|
|
|
2531
2531
|
return "left";
|
|
2532
2532
|
}
|
|
2533
2533
|
}
|
|
2534
|
-
function
|
|
2534
|
+
function ve(d) {
|
|
2535
2535
|
return d && typeof d == "object" ? o`${o`${d}`}` : d;
|
|
2536
2536
|
}
|
|
2537
|
-
function
|
|
2537
|
+
function R(d, e) {
|
|
2538
2538
|
const t = typeof d == "function" ? d(e) : d;
|
|
2539
|
-
return
|
|
2539
|
+
return ve(t);
|
|
2540
2540
|
}
|
|
2541
|
-
function
|
|
2541
|
+
function Xt(d, e) {
|
|
2542
2542
|
if (d.relationship !== "belongsToMany" || !d.through)
|
|
2543
2543
|
throw new Error("expandBelongsToManyJoin can only be called on belongsToMany relationships with through configuration");
|
|
2544
2544
|
const { table: t, sourceKey: n, targetKey: s, securitySql: i } = d.through, r = [];
|
|
2545
2545
|
for (const l of n) {
|
|
2546
|
-
const m = l.as ||
|
|
2546
|
+
const m = l.as || Q;
|
|
2547
2547
|
r.push(m(l.source, l.target));
|
|
2548
2548
|
}
|
|
2549
2549
|
const a = [];
|
|
2550
2550
|
for (const l of s) {
|
|
2551
|
-
const m = l.as ||
|
|
2551
|
+
const m = l.as || Q;
|
|
2552
2552
|
a.push(m(l.source, l.target));
|
|
2553
2553
|
}
|
|
2554
2554
|
let u;
|
|
@@ -2556,7 +2556,7 @@ function Jt(d, e) {
|
|
|
2556
2556
|
const l = i(e);
|
|
2557
2557
|
u = Array.isArray(l) ? l : [l];
|
|
2558
2558
|
}
|
|
2559
|
-
const c =
|
|
2559
|
+
const c = _e("belongsToMany", d.sqlJoinType);
|
|
2560
2560
|
return {
|
|
2561
2561
|
junctionJoins: [
|
|
2562
2562
|
{
|
|
@@ -2574,20 +2574,20 @@ function Jt(d, e) {
|
|
|
2574
2574
|
junctionSecurityConditions: u
|
|
2575
2575
|
};
|
|
2576
2576
|
}
|
|
2577
|
-
function
|
|
2577
|
+
function me(d) {
|
|
2578
2578
|
if ("and" in d)
|
|
2579
|
-
return `and:[${d.and.map(
|
|
2579
|
+
return `and:[${d.and.map(me).sort().join(",")}]`;
|
|
2580
2580
|
if ("or" in d)
|
|
2581
|
-
return `or:[${d.or.map(
|
|
2581
|
+
return `or:[${d.or.map(me).sort().join(",")}]`;
|
|
2582
2582
|
const e = d, t = JSON.stringify(
|
|
2583
2583
|
Array.isArray(e.values) ? [...e.values].sort() : e.values
|
|
2584
2584
|
), n = e.dateRange ? `:dr:${JSON.stringify(e.dateRange)}` : "";
|
|
2585
2585
|
return `${e.member}:${e.operator}:${t}${n}`;
|
|
2586
2586
|
}
|
|
2587
|
-
function
|
|
2587
|
+
function lt(d, e) {
|
|
2588
2588
|
return `timeDim:${d}:${JSON.stringify(e)}`;
|
|
2589
2589
|
}
|
|
2590
|
-
class
|
|
2590
|
+
class ze {
|
|
2591
2591
|
cache = /* @__PURE__ */ new Map();
|
|
2592
2592
|
stats = { hits: 0, misses: 0 };
|
|
2593
2593
|
/**
|
|
@@ -2644,40 +2644,40 @@ class We {
|
|
|
2644
2644
|
this.cache.clear(), this.stats = { hits: 0, misses: 0 };
|
|
2645
2645
|
}
|
|
2646
2646
|
}
|
|
2647
|
-
function
|
|
2647
|
+
function Re(d) {
|
|
2648
2648
|
const e = [];
|
|
2649
2649
|
for (const t of d)
|
|
2650
|
-
"and" in t && t.and ? e.push(...
|
|
2650
|
+
"and" in t && t.and ? e.push(...Re(t.and)) : "or" in t && t.or ? e.push(...Re(t.or)) : "member" in t && e.push(t);
|
|
2651
2651
|
return e;
|
|
2652
2652
|
}
|
|
2653
|
-
function
|
|
2654
|
-
const n = t.keyPrefix ?? "drizzle-cube:", s =
|
|
2653
|
+
function Zt(d, e, t = {}) {
|
|
2654
|
+
const n = t.keyPrefix ?? "drizzle-cube:", s = en(d), i = Ve(JSON.stringify(s));
|
|
2655
2655
|
let r = `${n}query:${i}`;
|
|
2656
2656
|
if (t.includeSecurityContext !== !1) {
|
|
2657
|
-
const a = t.securityContextSerializer ? t.securityContextSerializer(e) : JSON.stringify(
|
|
2657
|
+
const a = t.securityContextSerializer ? t.securityContextSerializer(e) : JSON.stringify(fe(e)), u = Ve(a);
|
|
2658
2658
|
r += `:ctx:${u}`;
|
|
2659
2659
|
}
|
|
2660
2660
|
return r;
|
|
2661
2661
|
}
|
|
2662
|
-
function
|
|
2662
|
+
function en(d) {
|
|
2663
2663
|
return {
|
|
2664
2664
|
measures: d.measures ? [...d.measures].sort() : void 0,
|
|
2665
2665
|
dimensions: d.dimensions ? [...d.dimensions].sort() : void 0,
|
|
2666
|
-
filters: d.filters ?
|
|
2667
|
-
timeDimensions: d.timeDimensions ?
|
|
2666
|
+
filters: d.filters ? K(d.filters) : void 0,
|
|
2667
|
+
timeDimensions: d.timeDimensions ? rn(d.timeDimensions) : void 0,
|
|
2668
2668
|
limit: d.limit,
|
|
2669
2669
|
offset: d.offset,
|
|
2670
|
-
order: d.order ?
|
|
2670
|
+
order: d.order ? fe(d.order) : void 0,
|
|
2671
2671
|
fillMissingDatesValue: d.fillMissingDatesValue,
|
|
2672
2672
|
// Include funnel config in cache key for proper cache invalidation
|
|
2673
|
-
funnel: d.funnel ?
|
|
2673
|
+
funnel: d.funnel ? tn(d.funnel) : void 0,
|
|
2674
2674
|
// Include flow config in cache key for proper cache invalidation
|
|
2675
|
-
flow: d.flow ?
|
|
2675
|
+
flow: d.flow ? nn(d.flow) : void 0,
|
|
2676
2676
|
// Include retention config in cache key for proper cache invalidation
|
|
2677
|
-
retention: d.retention ?
|
|
2677
|
+
retention: d.retention ? sn(d.retention) : void 0
|
|
2678
2678
|
};
|
|
2679
2679
|
}
|
|
2680
|
-
function
|
|
2680
|
+
function tn(d) {
|
|
2681
2681
|
return {
|
|
2682
2682
|
bindingKey: d.bindingKey,
|
|
2683
2683
|
timeDimension: d.timeDimension,
|
|
@@ -2685,7 +2685,7 @@ function Yt(d) {
|
|
|
2685
2685
|
steps: d.steps.map((e) => {
|
|
2686
2686
|
const t = {
|
|
2687
2687
|
name: e.name,
|
|
2688
|
-
filter: e.filter ? Array.isArray(e.filter) ?
|
|
2688
|
+
filter: e.filter ? Array.isArray(e.filter) ? K(e.filter) : K([e.filter])[0] : void 0,
|
|
2689
2689
|
timeToConvert: e.timeToConvert
|
|
2690
2690
|
};
|
|
2691
2691
|
return "cube" in e && e.cube && (t.cube = e.cube), t;
|
|
@@ -2694,7 +2694,7 @@ function Yt(d) {
|
|
|
2694
2694
|
globalTimeWindow: d.globalTimeWindow
|
|
2695
2695
|
};
|
|
2696
2696
|
}
|
|
2697
|
-
function
|
|
2697
|
+
function nn(d) {
|
|
2698
2698
|
return {
|
|
2699
2699
|
bindingKey: d.bindingKey,
|
|
2700
2700
|
timeDimension: d.timeDimension,
|
|
@@ -2702,7 +2702,7 @@ function Xt(d) {
|
|
|
2702
2702
|
// Normalize starting step - sort filters for consistent hashing
|
|
2703
2703
|
startingStep: {
|
|
2704
2704
|
name: d.startingStep.name,
|
|
2705
|
-
filter: d.startingStep.filter ? Array.isArray(d.startingStep.filter) ?
|
|
2705
|
+
filter: d.startingStep.filter ? Array.isArray(d.startingStep.filter) ? K(d.startingStep.filter) : K([d.startingStep.filter])[0] : void 0
|
|
2706
2706
|
},
|
|
2707
2707
|
// CRITICAL: Include step counts in cache key
|
|
2708
2708
|
stepsBefore: d.stepsBefore,
|
|
@@ -2715,7 +2715,7 @@ function Xt(d) {
|
|
|
2715
2715
|
joinStrategy: d.joinStrategy
|
|
2716
2716
|
};
|
|
2717
2717
|
}
|
|
2718
|
-
function
|
|
2718
|
+
function sn(d) {
|
|
2719
2719
|
return {
|
|
2720
2720
|
timeDimension: d.timeDimension,
|
|
2721
2721
|
bindingKey: d.bindingKey,
|
|
@@ -2724,18 +2724,18 @@ function Zt(d) {
|
|
|
2724
2724
|
periods: d.periods,
|
|
2725
2725
|
retentionType: d.retentionType,
|
|
2726
2726
|
// Normalize filters for consistent hashing
|
|
2727
|
-
cohortFilters: d.cohortFilters ? Array.isArray(d.cohortFilters) ?
|
|
2728
|
-
activityFilters: d.activityFilters ? Array.isArray(d.activityFilters) ?
|
|
2727
|
+
cohortFilters: d.cohortFilters ? Array.isArray(d.cohortFilters) ? K(d.cohortFilters) : K([d.cohortFilters])[0] : void 0,
|
|
2728
|
+
activityFilters: d.activityFilters ? Array.isArray(d.activityFilters) ? K(d.activityFilters) : K([d.activityFilters])[0] : void 0,
|
|
2729
2729
|
// Include breakdown dimensions for cache key
|
|
2730
2730
|
breakdownDimensions: d.breakdownDimensions
|
|
2731
2731
|
};
|
|
2732
2732
|
}
|
|
2733
|
-
function
|
|
2733
|
+
function K(d) {
|
|
2734
2734
|
return [...d].map((e) => {
|
|
2735
2735
|
if ("and" in e && e.and)
|
|
2736
|
-
return { and:
|
|
2736
|
+
return { and: K(e.and) };
|
|
2737
2737
|
if ("or" in e && e.or)
|
|
2738
|
-
return { or:
|
|
2738
|
+
return { or: K(e.or) };
|
|
2739
2739
|
const t = e;
|
|
2740
2740
|
return {
|
|
2741
2741
|
...t,
|
|
@@ -2743,7 +2743,7 @@ function Q(d) {
|
|
|
2743
2743
|
};
|
|
2744
2744
|
}).sort((e, t) => JSON.stringify(e).localeCompare(JSON.stringify(t)));
|
|
2745
2745
|
}
|
|
2746
|
-
function
|
|
2746
|
+
function rn(d) {
|
|
2747
2747
|
return [...d].map((e) => ({
|
|
2748
2748
|
dimension: e.dimension,
|
|
2749
2749
|
granularity: e.granularity,
|
|
@@ -2755,18 +2755,18 @@ function en(d) {
|
|
|
2755
2755
|
}) : void 0
|
|
2756
2756
|
})).sort((e, t) => e.dimension.localeCompare(t.dimension));
|
|
2757
2757
|
}
|
|
2758
|
-
function
|
|
2759
|
-
return d === null || typeof d != "object" ? d : Array.isArray(d) ? d.map(
|
|
2758
|
+
function fe(d) {
|
|
2759
|
+
return d === null || typeof d != "object" ? d : Array.isArray(d) ? d.map(fe) : Object.keys(d).sort().reduce((e, t) => (e[t] = fe(
|
|
2760
2760
|
d[t]
|
|
2761
2761
|
), e), {});
|
|
2762
2762
|
}
|
|
2763
|
-
function
|
|
2763
|
+
function Ve(d) {
|
|
2764
2764
|
let e = 2166136261;
|
|
2765
2765
|
for (let t = 0; t < d.length; t++)
|
|
2766
2766
|
e ^= d.charCodeAt(t), e = e * 16777619 >>> 0;
|
|
2767
2767
|
return e.toString(16).padStart(8, "0");
|
|
2768
2768
|
}
|
|
2769
|
-
class
|
|
2769
|
+
class ie {
|
|
2770
2770
|
constructor(e) {
|
|
2771
2771
|
this.databaseAdapter = e;
|
|
2772
2772
|
}
|
|
@@ -2774,8 +2774,8 @@ class ne {
|
|
|
2774
2774
|
* Build time dimension expression with granularity using database adapter
|
|
2775
2775
|
*/
|
|
2776
2776
|
buildTimeDimensionExpression(e, t, n) {
|
|
2777
|
-
const s =
|
|
2778
|
-
return t ? this.databaseAdapter.buildTimeDimension(t, s) : s instanceof
|
|
2777
|
+
const s = R(e, n);
|
|
2778
|
+
return t ? this.databaseAdapter.buildTimeDimension(t, s) : s instanceof O ? s : o`${s}`;
|
|
2779
2779
|
}
|
|
2780
2780
|
/**
|
|
2781
2781
|
* Build date range condition for time dimensions
|
|
@@ -2791,8 +2791,8 @@ class ne {
|
|
|
2791
2791
|
r.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? s = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(r.getTime() / 1e3) : r.getTime() : s = r.toISOString();
|
|
2792
2792
|
}
|
|
2793
2793
|
return A(
|
|
2794
|
-
|
|
2795
|
-
|
|
2794
|
+
Z(e, n),
|
|
2795
|
+
ee(e, s)
|
|
2796
2796
|
);
|
|
2797
2797
|
}
|
|
2798
2798
|
if (typeof t == "string") {
|
|
@@ -2800,8 +2800,8 @@ class ne {
|
|
|
2800
2800
|
if (n) {
|
|
2801
2801
|
let l, m;
|
|
2802
2802
|
return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (l = Math.floor(n.start.getTime() / 1e3), m = Math.floor(n.end.getTime() / 1e3)) : (l = n.start.getTime(), m = n.end.getTime()) : (l = n.start.toISOString(), m = n.end.toISOString()), A(
|
|
2803
|
-
|
|
2804
|
-
|
|
2803
|
+
Z(e, l),
|
|
2804
|
+
ee(e, m)
|
|
2805
2805
|
);
|
|
2806
2806
|
}
|
|
2807
2807
|
const s = this.normalizeDate(t);
|
|
@@ -2812,8 +2812,8 @@ class ne {
|
|
|
2812
2812
|
a.setUTCHours(23, 59, 59, 999);
|
|
2813
2813
|
let u, c;
|
|
2814
2814
|
return this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? (u = Math.floor(r.getTime() / 1e3), c = Math.floor(a.getTime() / 1e3)) : (u = r.getTime(), c = a.getTime()) : (u = r.toISOString(), c = a.toISOString()), A(
|
|
2815
|
-
|
|
2816
|
-
|
|
2815
|
+
Z(e, u),
|
|
2816
|
+
ee(e, c)
|
|
2817
2817
|
);
|
|
2818
2818
|
}
|
|
2819
2819
|
return null;
|
|
@@ -2927,7 +2927,7 @@ class ne {
|
|
|
2927
2927
|
return isNaN(t.getTime()) ? null : this.databaseAdapter.isTimestampInteger() ? this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(t.getTime() / 1e3) : t.getTime() : t.toISOString();
|
|
2928
2928
|
}
|
|
2929
2929
|
}
|
|
2930
|
-
class
|
|
2930
|
+
class ge {
|
|
2931
2931
|
constructor(e, t) {
|
|
2932
2932
|
this.databaseAdapter = e, this.dateTimeBuilder = t;
|
|
2933
2933
|
}
|
|
@@ -2957,16 +2957,16 @@ class he {
|
|
|
2957
2957
|
if (r.length > 1) {
|
|
2958
2958
|
if (s?.type === "time") {
|
|
2959
2959
|
const u = r.map((c) => this.dateTimeBuilder.normalizeDate(c) || c);
|
|
2960
|
-
return
|
|
2960
|
+
return Ee(e, u);
|
|
2961
2961
|
}
|
|
2962
|
-
return
|
|
2962
|
+
return Ee(e, r);
|
|
2963
2963
|
} else if (r.length === 1) {
|
|
2964
2964
|
const u = s?.type === "time" && this.dateTimeBuilder.normalizeDate(a) || a;
|
|
2965
|
-
return
|
|
2965
|
+
return Q(e, u);
|
|
2966
2966
|
}
|
|
2967
2967
|
return this.databaseAdapter.buildBooleanLiteral(!1);
|
|
2968
2968
|
case "notEquals":
|
|
2969
|
-
return r.length > 1 ?
|
|
2969
|
+
return r.length > 1 ? ke(e, r) : r.length === 1 ? xe(e, a) : null;
|
|
2970
2970
|
case "contains":
|
|
2971
2971
|
return this.databaseAdapter.buildStringCondition(e, "contains", a);
|
|
2972
2972
|
case "notContains":
|
|
@@ -2976,17 +2976,17 @@ class he {
|
|
|
2976
2976
|
case "endsWith":
|
|
2977
2977
|
return this.databaseAdapter.buildStringCondition(e, "endsWith", a);
|
|
2978
2978
|
case "gt":
|
|
2979
|
-
return
|
|
2979
|
+
return $e(e, a);
|
|
2980
2980
|
case "gte":
|
|
2981
|
-
return
|
|
2981
|
+
return Z(e, a);
|
|
2982
2982
|
case "lt":
|
|
2983
|
-
return
|
|
2983
|
+
return Te(e, a);
|
|
2984
2984
|
case "lte":
|
|
2985
|
-
return
|
|
2985
|
+
return ee(e, a);
|
|
2986
2986
|
case "set":
|
|
2987
|
-
return
|
|
2987
|
+
return Pe(e);
|
|
2988
2988
|
case "notSet":
|
|
2989
|
-
return
|
|
2989
|
+
return Be(e);
|
|
2990
2990
|
case "inDateRange":
|
|
2991
2991
|
if (r.length >= 2) {
|
|
2992
2992
|
const u = this.dateTimeBuilder.normalizeDate(r[0]);
|
|
@@ -2998,34 +2998,34 @@ class he {
|
|
|
2998
2998
|
p.setUTCHours(23, 59, 59, 999), this.databaseAdapter.isTimestampInteger() ? c = this.databaseAdapter.getEngineType() === "sqlite" ? Math.floor(p.getTime() / 1e3) : p.getTime() : c = p.toISOString();
|
|
2999
2999
|
}
|
|
3000
3000
|
return A(
|
|
3001
|
-
|
|
3002
|
-
|
|
3001
|
+
Z(e, u),
|
|
3002
|
+
ee(e, c)
|
|
3003
3003
|
);
|
|
3004
3004
|
}
|
|
3005
3005
|
}
|
|
3006
3006
|
return null;
|
|
3007
3007
|
case "beforeDate": {
|
|
3008
3008
|
const u = this.dateTimeBuilder.normalizeDate(a);
|
|
3009
|
-
return u ?
|
|
3009
|
+
return u ? Te(e, u) : null;
|
|
3010
3010
|
}
|
|
3011
3011
|
case "afterDate": {
|
|
3012
3012
|
const u = this.dateTimeBuilder.normalizeDate(a);
|
|
3013
|
-
return u ?
|
|
3013
|
+
return u ? $e(e, u) : null;
|
|
3014
3014
|
}
|
|
3015
3015
|
case "between":
|
|
3016
3016
|
return r.length >= 2 ? A(
|
|
3017
|
-
|
|
3018
|
-
|
|
3017
|
+
Z(e, r[0]),
|
|
3018
|
+
ee(e, r[1])
|
|
3019
3019
|
) : null;
|
|
3020
3020
|
case "notBetween":
|
|
3021
|
-
return r.length >= 2 ?
|
|
3022
|
-
|
|
3023
|
-
|
|
3021
|
+
return r.length >= 2 ? re(
|
|
3022
|
+
Te(e, r[0]),
|
|
3023
|
+
$e(e, r[1])
|
|
3024
3024
|
) : null;
|
|
3025
3025
|
case "in":
|
|
3026
|
-
return r.length > 0 ?
|
|
3026
|
+
return r.length > 0 ? Ee(e, r) : null;
|
|
3027
3027
|
case "notIn":
|
|
3028
|
-
return r.length > 0 ?
|
|
3028
|
+
return r.length > 0 ? ke(e, r) : null;
|
|
3029
3029
|
case "like":
|
|
3030
3030
|
return this.databaseAdapter.buildStringCondition(e, "like", a);
|
|
3031
3031
|
case "notLike":
|
|
@@ -3037,23 +3037,23 @@ class he {
|
|
|
3037
3037
|
case "notRegex":
|
|
3038
3038
|
return this.databaseAdapter.buildStringCondition(e, "notRegex", a);
|
|
3039
3039
|
case "isEmpty":
|
|
3040
|
-
return
|
|
3041
|
-
|
|
3042
|
-
|
|
3040
|
+
return re(
|
|
3041
|
+
Be(e),
|
|
3042
|
+
Q(e, "")
|
|
3043
3043
|
);
|
|
3044
3044
|
case "isNotEmpty":
|
|
3045
3045
|
return A(
|
|
3046
|
-
|
|
3047
|
-
|
|
3046
|
+
Pe(e),
|
|
3047
|
+
xe(e, "")
|
|
3048
3048
|
);
|
|
3049
3049
|
// PostgreSQL array operators - silent no-op for other databases
|
|
3050
3050
|
// These use Drizzle's built-in array operator functions
|
|
3051
3051
|
case "arrayContains":
|
|
3052
|
-
return this.databaseAdapter.getEngineType() === "postgres" ?
|
|
3052
|
+
return this.databaseAdapter.getEngineType() === "postgres" ? Dt(e, r) : null;
|
|
3053
3053
|
case "arrayOverlaps":
|
|
3054
|
-
return this.databaseAdapter.getEngineType() === "postgres" ?
|
|
3054
|
+
return this.databaseAdapter.getEngineType() === "postgres" ? _t(e, r) : null;
|
|
3055
3055
|
case "arrayContained":
|
|
3056
|
-
return this.databaseAdapter.getEngineType() === "postgres" ?
|
|
3056
|
+
return this.databaseAdapter.getEngineType() === "postgres" ? At(e, r) : null;
|
|
3057
3057
|
default:
|
|
3058
3058
|
return null;
|
|
3059
3059
|
}
|
|
@@ -3069,7 +3069,7 @@ class he {
|
|
|
3069
3069
|
}
|
|
3070
3070
|
if ("or" in e && e.or) {
|
|
3071
3071
|
const s = e.or.map((i) => this.buildSingleFilter(i, t, n)).filter((i) => i !== null);
|
|
3072
|
-
return s.length > 0 ? s.length === 1 ? s[0] :
|
|
3072
|
+
return s.length > 0 ? s.length === 1 ? s[0] : re(...s) : null;
|
|
3073
3073
|
}
|
|
3074
3074
|
return null;
|
|
3075
3075
|
}
|
|
@@ -3084,7 +3084,7 @@ class he {
|
|
|
3084
3084
|
if (!a) return null;
|
|
3085
3085
|
const u = a.dimensions?.[r];
|
|
3086
3086
|
if (!u) return null;
|
|
3087
|
-
const c =
|
|
3087
|
+
const c = R(u.sql, n);
|
|
3088
3088
|
return this.buildFilterCondition(
|
|
3089
3089
|
c,
|
|
3090
3090
|
s.operator,
|
|
@@ -3094,7 +3094,7 @@ class he {
|
|
|
3094
3094
|
);
|
|
3095
3095
|
}
|
|
3096
3096
|
}
|
|
3097
|
-
class
|
|
3097
|
+
class X {
|
|
3098
3098
|
dependencyGraph;
|
|
3099
3099
|
cubes;
|
|
3100
3100
|
constructor(e) {
|
|
@@ -3314,21 +3314,21 @@ class G {
|
|
|
3314
3314
|
return e.type === "calculated" && !!e.calculatedSql;
|
|
3315
3315
|
}
|
|
3316
3316
|
}
|
|
3317
|
-
function
|
|
3318
|
-
const { cube: t, allCubes: n, resolvedMeasures: s } = e, i =
|
|
3317
|
+
function on(d, e) {
|
|
3318
|
+
const { cube: t, allCubes: n, resolvedMeasures: s } = e, i = Fe(d), r = /* @__PURE__ */ new Map();
|
|
3319
3319
|
for (const m of i) {
|
|
3320
3320
|
const { originalRef: p, cubeName: f, fieldName: h } = m, g = f || t.name;
|
|
3321
3321
|
if (!n.get(g))
|
|
3322
3322
|
throw new Error(
|
|
3323
3323
|
`Cannot substitute {${p}}: cube '${g}' not found`
|
|
3324
3324
|
);
|
|
3325
|
-
const b = `${g}.${h}`,
|
|
3326
|
-
if (
|
|
3325
|
+
const b = `${g}.${h}`, $ = s.get(b);
|
|
3326
|
+
if (!$)
|
|
3327
3327
|
throw new Error(
|
|
3328
3328
|
`Cannot substitute {${p}}: measure '${b}' not resolved yet. Ensure measures are resolved in dependency order.`
|
|
3329
3329
|
);
|
|
3330
|
-
const
|
|
3331
|
-
r.set(p,
|
|
3330
|
+
const D = $(), w = o`${D}`;
|
|
3331
|
+
r.set(p, w);
|
|
3332
3332
|
}
|
|
3333
3333
|
const a = [], u = [];
|
|
3334
3334
|
let c = 0;
|
|
@@ -3344,10 +3344,10 @@ function tn(d, e) {
|
|
|
3344
3344
|
return o.raw(d);
|
|
3345
3345
|
const l = [];
|
|
3346
3346
|
for (let m = 0; m < a.length; m++)
|
|
3347
|
-
a[m] && l.push(new
|
|
3347
|
+
a[m] && l.push(new M(a[m])), m < u.length && l.push(u[m]);
|
|
3348
3348
|
return o.join(l, o.raw(""));
|
|
3349
3349
|
}
|
|
3350
|
-
function
|
|
3350
|
+
function Fe(d) {
|
|
3351
3351
|
const e = /\{([^}]+)\}/g, t = d.matchAll(e), n = [];
|
|
3352
3352
|
for (const s of t) {
|
|
3353
3353
|
const i = s[1].trim();
|
|
@@ -3367,7 +3367,7 @@ function Re(d) {
|
|
|
3367
3367
|
}
|
|
3368
3368
|
return n;
|
|
3369
3369
|
}
|
|
3370
|
-
function
|
|
3370
|
+
function an(d) {
|
|
3371
3371
|
const e = [];
|
|
3372
3372
|
let t = 0;
|
|
3373
3373
|
for (let r = 0; r < d.length; r++)
|
|
@@ -3378,7 +3378,7 @@ function nn(d) {
|
|
|
3378
3378
|
break;
|
|
3379
3379
|
}
|
|
3380
3380
|
t > 0 && e.push("Unmatched opening brace in template"), /\{\s*\}/.test(d) && e.push("Empty member reference {} found in template"), /\{[^}]*\{/.test(d) && e.push("Nested braces are not allowed in member references");
|
|
3381
|
-
const i =
|
|
3381
|
+
const i = Fe(d);
|
|
3382
3382
|
for (const r of i) {
|
|
3383
3383
|
const a = r.cubeName ? `${r.cubeName}.${r.fieldName}` : r.fieldName;
|
|
3384
3384
|
/^[a-zA-Z_][a-zA-Z0-9_.]*$/.test(a) || e.push(
|
|
@@ -3392,8 +3392,8 @@ function nn(d) {
|
|
|
3392
3392
|
errors: e
|
|
3393
3393
|
};
|
|
3394
3394
|
}
|
|
3395
|
-
function
|
|
3396
|
-
const t =
|
|
3395
|
+
function Se(d, e) {
|
|
3396
|
+
const t = Fe(d), n = /* @__PURE__ */ new Set();
|
|
3397
3397
|
for (const s of t) {
|
|
3398
3398
|
const r = `${s.cubeName || e}.${s.fieldName}`;
|
|
3399
3399
|
n.add(r);
|
|
@@ -3416,7 +3416,7 @@ class I {
|
|
|
3416
3416
|
* @returns Map of measure names to SQL builder functions
|
|
3417
3417
|
*/
|
|
3418
3418
|
buildResolvedMeasures(e, t, n, s) {
|
|
3419
|
-
const i = /* @__PURE__ */ new Map(), r = [], a = [], u = new Set(e), c = new
|
|
3419
|
+
const i = /* @__PURE__ */ new Map(), r = [], a = [], u = new Set(e), c = new X(t);
|
|
3420
3420
|
for (const l of t.values())
|
|
3421
3421
|
c.buildGraph(l);
|
|
3422
3422
|
for (const l of e) {
|
|
@@ -3428,11 +3428,11 @@ class I {
|
|
|
3428
3428
|
g && u.add(g);
|
|
3429
3429
|
continue;
|
|
3430
3430
|
}
|
|
3431
|
-
|
|
3432
|
-
const [
|
|
3433
|
-
if (
|
|
3434
|
-
const C =
|
|
3435
|
-
|
|
3431
|
+
X.isCalculatedMeasure(h) ? (a.push(l), Se(h.calculatedSql, m).forEach((b) => u.add(b)), c.getAllDependencies(l).forEach((b) => {
|
|
3432
|
+
const [$, D] = b.split("."), w = t.get($);
|
|
3433
|
+
if (w && w.measures[D]) {
|
|
3434
|
+
const C = w.measures[D];
|
|
3435
|
+
X.isCalculatedMeasure(C) && Se(C.calculatedSql, $).forEach((E) => u.add(E));
|
|
3436
3436
|
}
|
|
3437
3437
|
})) : r.push(l);
|
|
3438
3438
|
}
|
|
@@ -3443,7 +3443,7 @@ class I {
|
|
|
3443
3443
|
const h = f.measures[p];
|
|
3444
3444
|
if (I.isPostAggregationWindow(h))
|
|
3445
3445
|
continue;
|
|
3446
|
-
|
|
3446
|
+
X.isCalculatedMeasure(h) ? a.includes(l) || a.push(l) : r.includes(l) || r.push(l);
|
|
3447
3447
|
}
|
|
3448
3448
|
}
|
|
3449
3449
|
for (const l of r) {
|
|
@@ -3479,7 +3479,7 @@ class I {
|
|
|
3479
3479
|
`Calculated measure '${t.name}.${e.name}' missing calculatedSql property`
|
|
3480
3480
|
);
|
|
3481
3481
|
const r = this.databaseAdapter.preprocessCalculatedTemplate(e.calculatedSql);
|
|
3482
|
-
return
|
|
3482
|
+
return on(r, {
|
|
3483
3483
|
cube: t,
|
|
3484
3484
|
allCubes: n,
|
|
3485
3485
|
resolvedMeasures: s
|
|
@@ -3504,7 +3504,7 @@ class I {
|
|
|
3504
3504
|
throw new Error(
|
|
3505
3505
|
`Calculated measure '${t.name}.${e.name || "unknown"}' missing calculatedSql property`
|
|
3506
3506
|
);
|
|
3507
|
-
const r = /* @__PURE__ */ new Map(), a =
|
|
3507
|
+
const r = /* @__PURE__ */ new Map(), a = Se(e.calculatedSql, t.name);
|
|
3508
3508
|
for (const u of a) {
|
|
3509
3509
|
const [c, l] = u.split("."), m = s.get(c);
|
|
3510
3510
|
if (m && m.measures[l]) {
|
|
@@ -3516,22 +3516,22 @@ class I {
|
|
|
3516
3516
|
case "count":
|
|
3517
3517
|
case "countDistinct":
|
|
3518
3518
|
case "sum":
|
|
3519
|
-
h =
|
|
3519
|
+
h = z(f);
|
|
3520
3520
|
break;
|
|
3521
3521
|
case "avg":
|
|
3522
3522
|
h = this.databaseAdapter.buildAvg(f);
|
|
3523
3523
|
break;
|
|
3524
3524
|
case "min":
|
|
3525
|
-
h =
|
|
3525
|
+
h = oe(f);
|
|
3526
3526
|
break;
|
|
3527
3527
|
case "max":
|
|
3528
|
-
h =
|
|
3528
|
+
h = G(f);
|
|
3529
3529
|
break;
|
|
3530
3530
|
case "number":
|
|
3531
|
-
h =
|
|
3531
|
+
h = z(f);
|
|
3532
3532
|
break;
|
|
3533
3533
|
default:
|
|
3534
|
-
h =
|
|
3534
|
+
h = z(f);
|
|
3535
3535
|
}
|
|
3536
3536
|
r.set(u, () => h);
|
|
3537
3537
|
}
|
|
@@ -3573,17 +3573,17 @@ class I {
|
|
|
3573
3573
|
case "count":
|
|
3574
3574
|
case "countDistinct":
|
|
3575
3575
|
case "sum":
|
|
3576
|
-
return
|
|
3576
|
+
return z(a);
|
|
3577
3577
|
case "avg":
|
|
3578
3578
|
return this.databaseAdapter.buildAvg(a);
|
|
3579
3579
|
case "min":
|
|
3580
|
-
return
|
|
3580
|
+
return oe(a);
|
|
3581
3581
|
case "max":
|
|
3582
|
-
return
|
|
3582
|
+
return G(a);
|
|
3583
3583
|
case "number":
|
|
3584
|
-
return
|
|
3584
|
+
return z(a);
|
|
3585
3585
|
default:
|
|
3586
|
-
return
|
|
3586
|
+
return z(a);
|
|
3587
3587
|
}
|
|
3588
3588
|
}
|
|
3589
3589
|
}
|
|
@@ -3610,7 +3610,7 @@ class I {
|
|
|
3610
3610
|
throw new Error(
|
|
3611
3611
|
`Measure '${e.name}' of type '${e.type}' is missing required 'sql' property. Only calculated measures and post-aggregation window functions can omit 'sql'.`
|
|
3612
3612
|
);
|
|
3613
|
-
let s =
|
|
3613
|
+
let s = R(e.sql, t);
|
|
3614
3614
|
if (e.filters && e.filters.length > 0) {
|
|
3615
3615
|
const i = e.filters.map((r) => {
|
|
3616
3616
|
const a = r(t);
|
|
@@ -3625,17 +3625,17 @@ class I {
|
|
|
3625
3625
|
}
|
|
3626
3626
|
switch (e.type) {
|
|
3627
3627
|
case "count":
|
|
3628
|
-
return
|
|
3628
|
+
return Ae(s);
|
|
3629
3629
|
case "countDistinct":
|
|
3630
|
-
return
|
|
3630
|
+
return Rt(s);
|
|
3631
3631
|
case "sum":
|
|
3632
|
-
return
|
|
3632
|
+
return z(s);
|
|
3633
3633
|
case "avg":
|
|
3634
3634
|
return this.databaseAdapter.buildAvg(s);
|
|
3635
3635
|
case "min":
|
|
3636
|
-
return
|
|
3636
|
+
return oe(s);
|
|
3637
3637
|
case "max":
|
|
3638
|
-
return
|
|
3638
|
+
return G(s);
|
|
3639
3639
|
case "number":
|
|
3640
3640
|
return s;
|
|
3641
3641
|
// Statistical functions (Phase 1)
|
|
@@ -3686,7 +3686,7 @@ class I {
|
|
|
3686
3686
|
if (i.partitionBy && i.partitionBy.length > 0 && n) {
|
|
3687
3687
|
const c = i.partitionBy.map((l) => {
|
|
3688
3688
|
const m = l.includes(".") ? l.split(".")[1] : l, p = n.dimensions?.[m];
|
|
3689
|
-
return p ?
|
|
3689
|
+
return p ? R(p.sql, t) : (console.warn(`[drizzle-cube] Window function partition dimension '${l}' not found in cube '${n.name}'`), null);
|
|
3690
3690
|
}).filter((l) => l !== null);
|
|
3691
3691
|
c.length > 0 && (r = c);
|
|
3692
3692
|
}
|
|
@@ -3696,12 +3696,12 @@ class I {
|
|
|
3696
3696
|
const m = l.field.includes(".") ? l.field.split(".")[1] : l.field, p = n.dimensions?.[m];
|
|
3697
3697
|
if (p)
|
|
3698
3698
|
return {
|
|
3699
|
-
field:
|
|
3699
|
+
field: R(p.sql, t),
|
|
3700
3700
|
direction: l.direction
|
|
3701
3701
|
};
|
|
3702
3702
|
const f = n.measures?.[m];
|
|
3703
3703
|
return f && f.sql ? {
|
|
3704
|
-
field:
|
|
3704
|
+
field: R(f.sql, t),
|
|
3705
3705
|
direction: l.direction
|
|
3706
3706
|
} : (console.warn(`[drizzle-cube] Window function order field '${l.field}' not found in cube '${n.name}'`), null);
|
|
3707
3707
|
}).filter((l) => l !== null);
|
|
@@ -3722,7 +3722,7 @@ class I {
|
|
|
3722
3722
|
return u === null ? (console.warn(`[drizzle-cube] ${e.type} not supported on ${this.databaseAdapter.getEngineType()}, returning NULL`), o`NULL`) : u;
|
|
3723
3723
|
}
|
|
3724
3724
|
default:
|
|
3725
|
-
return
|
|
3725
|
+
return Ae(s);
|
|
3726
3726
|
}
|
|
3727
3727
|
}
|
|
3728
3728
|
/**
|
|
@@ -3868,7 +3868,7 @@ class I {
|
|
|
3868
3868
|
return n.length > 0;
|
|
3869
3869
|
}
|
|
3870
3870
|
}
|
|
3871
|
-
class
|
|
3871
|
+
class un {
|
|
3872
3872
|
constructor(e) {
|
|
3873
3873
|
this.dateTimeBuilder = e;
|
|
3874
3874
|
}
|
|
@@ -3936,8 +3936,8 @@ class sn {
|
|
|
3936
3936
|
if (I.isPostAggregationWindow(g)) {
|
|
3937
3937
|
const y = I.getWindowBaseMeasure(g, p);
|
|
3938
3938
|
if (y) {
|
|
3939
|
-
const [b,
|
|
3940
|
-
if (
|
|
3939
|
+
const [b, $] = y.split("."), w = r.get(b)?.measures?.[$];
|
|
3940
|
+
if (w && this.isAggregateFunctionType(w.type)) {
|
|
3941
3941
|
l = !0;
|
|
3942
3942
|
break;
|
|
3943
3943
|
}
|
|
@@ -3952,15 +3952,15 @@ class sn {
|
|
|
3952
3952
|
const [p, f] = m.split("."), h = r.get(p);
|
|
3953
3953
|
if (h && h.dimensions && h.dimensions[f])
|
|
3954
3954
|
if (s?.preAggregationCTEs?.some((y) => y.cube.name === p)) {
|
|
3955
|
-
const y = s.preAggregationCTEs.find((
|
|
3955
|
+
const y = s.preAggregationCTEs.find(($) => $.cube.name === p), b = y.joinKeys.find(($) => $.targetColumn === f);
|
|
3956
3956
|
if (b && b.sourceColumnObj)
|
|
3957
3957
|
i.push(b.sourceColumnObj);
|
|
3958
3958
|
else {
|
|
3959
|
-
const
|
|
3960
|
-
i.push(
|
|
3959
|
+
const $ = o`${o.identifier(y.cteAlias)}.${o.identifier(f)}`;
|
|
3960
|
+
i.push($);
|
|
3961
3961
|
}
|
|
3962
3962
|
} else {
|
|
3963
|
-
const y = h.dimensions[f], b =
|
|
3963
|
+
const y = h.dimensions[f], b = R(y.sql, n);
|
|
3964
3964
|
i.push(b);
|
|
3965
3965
|
}
|
|
3966
3966
|
}
|
|
@@ -3969,17 +3969,17 @@ class sn {
|
|
|
3969
3969
|
const [p, f] = m.dimension.split("."), h = r.get(p);
|
|
3970
3970
|
if (h && h.dimensions && h.dimensions[f])
|
|
3971
3971
|
if (s?.preAggregationCTEs?.some((y) => y.cube.name === p)) {
|
|
3972
|
-
const y = s.preAggregationCTEs.find((
|
|
3972
|
+
const y = s.preAggregationCTEs.find(($) => $.cube.name === p), b = y.joinKeys.find(($) => $.targetColumn === f);
|
|
3973
3973
|
if (b && b.sourceColumnObj) {
|
|
3974
|
-
const
|
|
3974
|
+
const $ = this.dateTimeBuilder.buildTimeDimensionExpression(
|
|
3975
3975
|
b.sourceColumnObj,
|
|
3976
3976
|
m.granularity,
|
|
3977
3977
|
n
|
|
3978
3978
|
);
|
|
3979
|
-
i.push(
|
|
3979
|
+
i.push($);
|
|
3980
3980
|
} else {
|
|
3981
|
-
const
|
|
3982
|
-
i.push(
|
|
3981
|
+
const $ = o`${o.identifier(y.cteAlias)}.${o.identifier(f)}`;
|
|
3982
|
+
i.push($);
|
|
3983
3983
|
}
|
|
3984
3984
|
} else {
|
|
3985
3985
|
const y = h.dimensions[f], b = this.dateTimeBuilder.buildTimeDimensionExpression(
|
|
@@ -3993,13 +3993,13 @@ class sn {
|
|
|
3993
3993
|
return i;
|
|
3994
3994
|
}
|
|
3995
3995
|
}
|
|
3996
|
-
class
|
|
3996
|
+
class ln {
|
|
3997
3997
|
dateTimeBuilder;
|
|
3998
3998
|
filterBuilder;
|
|
3999
3999
|
groupByBuilder;
|
|
4000
4000
|
measureBuilder;
|
|
4001
4001
|
constructor(e) {
|
|
4002
|
-
this.dateTimeBuilder = new
|
|
4002
|
+
this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder), this.groupByBuilder = new un(this.dateTimeBuilder), this.measureBuilder = new I(e);
|
|
4003
4003
|
}
|
|
4004
4004
|
/**
|
|
4005
4005
|
* Build resolvedMeasures map for a set of measures
|
|
@@ -4019,7 +4019,7 @@ class rn {
|
|
|
4019
4019
|
for (const r of t.dimensions) {
|
|
4020
4020
|
const [a, u] = r.split("."), c = i.get(a);
|
|
4021
4021
|
if (c && c.dimensions && c.dimensions[u]) {
|
|
4022
|
-
const l = c.dimensions[u], m =
|
|
4022
|
+
const l = c.dimensions[u], m = R(l.sql, n);
|
|
4023
4023
|
s[r] = o`${m}`.as(r);
|
|
4024
4024
|
}
|
|
4025
4025
|
}
|
|
@@ -4049,7 +4049,7 @@ class rn {
|
|
|
4049
4049
|
s[r.dimension] = o`${m}`.as(r.dimension);
|
|
4050
4050
|
}
|
|
4051
4051
|
}
|
|
4052
|
-
return Object.keys(s).length === 0 && (s.count =
|
|
4052
|
+
return Object.keys(s).length === 0 && (s.count = Ae()), s;
|
|
4053
4053
|
}
|
|
4054
4054
|
/**
|
|
4055
4055
|
* Build calculated measure expression by substituting {member} references
|
|
@@ -4114,13 +4114,13 @@ class rn {
|
|
|
4114
4114
|
if (s?.preAggregationCTEs && s.preAggregationCTEs.some((b) => b.cube.name === l))
|
|
4115
4115
|
continue;
|
|
4116
4116
|
if (n.filterCache) {
|
|
4117
|
-
const y =
|
|
4117
|
+
const y = lt(c.dimension, c.dateRange), b = n.filterCache.get(y);
|
|
4118
4118
|
if (b) {
|
|
4119
4119
|
r.push(b);
|
|
4120
4120
|
continue;
|
|
4121
4121
|
}
|
|
4122
4122
|
}
|
|
4123
|
-
const f = p.dimensions[m], h =
|
|
4123
|
+
const f = p.dimensions[m], h = R(f.sql, n), g = this.buildDateRangeCondition(h, c.dateRange);
|
|
4124
4124
|
g && r.push(g);
|
|
4125
4125
|
}
|
|
4126
4126
|
}
|
|
@@ -4152,7 +4152,7 @@ class rn {
|
|
|
4152
4152
|
}
|
|
4153
4153
|
if (f.or) {
|
|
4154
4154
|
const h = f.or.map((g) => this.processFilter(g, t, n, s, i)).filter((g) => g !== null);
|
|
4155
|
-
return h.length > 0 ?
|
|
4155
|
+
return h.length > 0 ? re(...h) : null;
|
|
4156
4156
|
}
|
|
4157
4157
|
}
|
|
4158
4158
|
const r = e, [a, u] = r.member.split("."), c = t.get(a);
|
|
@@ -4164,11 +4164,11 @@ class rn {
|
|
|
4164
4164
|
return null;
|
|
4165
4165
|
const f = ["arrayContains", "arrayOverlaps", "arrayContained"].includes(r.operator);
|
|
4166
4166
|
if (!f && n.filterCache) {
|
|
4167
|
-
const g =
|
|
4167
|
+
const g = me(e), y = n.filterCache.get(g);
|
|
4168
4168
|
if (y)
|
|
4169
4169
|
return y;
|
|
4170
4170
|
}
|
|
4171
|
-
const h = f ? typeof l.sql == "function" ? l.sql(n) : l.sql :
|
|
4171
|
+
const h = f ? typeof l.sql == "function" ? l.sql(n) : l.sql : R(l.sql, n);
|
|
4172
4172
|
return this.buildFilterCondition(
|
|
4173
4173
|
h,
|
|
4174
4174
|
r.operator,
|
|
@@ -4226,7 +4226,7 @@ class rn {
|
|
|
4226
4226
|
for (const [i, r] of Object.entries(e.order)) {
|
|
4227
4227
|
if (!s.includes(i))
|
|
4228
4228
|
throw new Error(`Cannot order by '${i}': field is not selected in the query`);
|
|
4229
|
-
const a = r === "desc" ?
|
|
4229
|
+
const a = r === "desc" ? vt(o.identifier(i)) : Qe(o.identifier(i));
|
|
4230
4230
|
n.push(a);
|
|
4231
4231
|
}
|
|
4232
4232
|
if (e.timeDimensions && e.timeDimensions.length > 0) {
|
|
@@ -4234,7 +4234,7 @@ class rn {
|
|
|
4234
4234
|
(a, u) => a.dimension.localeCompare(u.dimension)
|
|
4235
4235
|
);
|
|
4236
4236
|
for (const a of r)
|
|
4237
|
-
i.has(a.dimension) || n.push(
|
|
4237
|
+
i.has(a.dimension) || n.push(Qe(o.identifier(a.dimension)));
|
|
4238
4238
|
}
|
|
4239
4239
|
return n;
|
|
4240
4240
|
}
|
|
@@ -4290,7 +4290,7 @@ class rn {
|
|
|
4290
4290
|
return this.filterBuilder.buildLogicalFilter(e, t, n);
|
|
4291
4291
|
}
|
|
4292
4292
|
}
|
|
4293
|
-
class
|
|
4293
|
+
class ae {
|
|
4294
4294
|
cubes;
|
|
4295
4295
|
connectivityCache = /* @__PURE__ */ new Map();
|
|
4296
4296
|
/**
|
|
@@ -4321,7 +4321,7 @@ class oe {
|
|
|
4321
4321
|
const { cube: u, path: c } = r.shift(), l = this.cubes.get(u);
|
|
4322
4322
|
if (l?.joins)
|
|
4323
4323
|
for (const [, m] of Object.entries(l.joins)) {
|
|
4324
|
-
const f =
|
|
4324
|
+
const f = W(m.targetCube).name;
|
|
4325
4325
|
if (a.has(f))
|
|
4326
4326
|
continue;
|
|
4327
4327
|
const h = [
|
|
@@ -4401,7 +4401,7 @@ class oe {
|
|
|
4401
4401
|
const l = this.cubes.get(a);
|
|
4402
4402
|
if (l?.joins)
|
|
4403
4403
|
for (const [, m] of Object.entries(l.joins)) {
|
|
4404
|
-
const f =
|
|
4404
|
+
const f = W(m.targetCube).name;
|
|
4405
4405
|
if (c.has(f))
|
|
4406
4406
|
continue;
|
|
4407
4407
|
const h = [
|
|
@@ -4449,7 +4449,7 @@ class oe {
|
|
|
4449
4449
|
buildJoinCondition(e, t, n) {
|
|
4450
4450
|
const s = [];
|
|
4451
4451
|
for (const i of e.on) {
|
|
4452
|
-
const r = t ? o`${o.identifier(t)}.${o.identifier(i.source.name)}` :
|
|
4452
|
+
const r = t ? o`${o.identifier(t)}.${o.identifier(i.source.name)}` : ve(i.source), a = n ? o`${o.identifier(n)}.${o.identifier(i.target.name)}` : ve(i.target), u = i.as || Q;
|
|
4453
4453
|
s.push(u(r, a));
|
|
4454
4454
|
}
|
|
4455
4455
|
return A(...s);
|
|
@@ -4467,7 +4467,7 @@ class oe {
|
|
|
4467
4467
|
const s = n.shift(), i = this.cubes.get(s);
|
|
4468
4468
|
if (i?.joins)
|
|
4469
4469
|
for (const [, r] of Object.entries(i.joins)) {
|
|
4470
|
-
const u =
|
|
4470
|
+
const u = W(r.targetCube).name;
|
|
4471
4471
|
t.has(u) || (t.add(u), n.push(u));
|
|
4472
4472
|
}
|
|
4473
4473
|
}
|
|
@@ -4487,7 +4487,7 @@ class oe {
|
|
|
4487
4487
|
this.connectivityCache.set(e, { path: t });
|
|
4488
4488
|
}
|
|
4489
4489
|
}
|
|
4490
|
-
class
|
|
4490
|
+
class ct {
|
|
4491
4491
|
// Cache resolver per cubes map to avoid repeated instantiation
|
|
4492
4492
|
resolverCache = /* @__PURE__ */ new WeakMap();
|
|
4493
4493
|
/**
|
|
@@ -4495,7 +4495,7 @@ class at {
|
|
|
4495
4495
|
*/
|
|
4496
4496
|
getResolver(e) {
|
|
4497
4497
|
let t = this.resolverCache.get(e);
|
|
4498
|
-
return t || (t = new
|
|
4498
|
+
return t || (t = new ae(e), this.resolverCache.set(e, t)), t;
|
|
4499
4499
|
}
|
|
4500
4500
|
/**
|
|
4501
4501
|
* Analyze a semantic query to determine which cubes are involved
|
|
@@ -4644,45 +4644,46 @@ class at {
|
|
|
4644
4644
|
);
|
|
4645
4645
|
if (!h || h.length === 0)
|
|
4646
4646
|
throw new Error(`No join path found from '${t.name}' to '${p}'`);
|
|
4647
|
-
for (const {
|
|
4648
|
-
if (u.has(
|
|
4647
|
+
for (const { fromCube: g, toCube: y, joinDef: b } of h) {
|
|
4648
|
+
if (u.has(y))
|
|
4649
4649
|
continue;
|
|
4650
|
-
const
|
|
4651
|
-
if (
|
|
4652
|
-
throw new Error(`Cube '${
|
|
4653
|
-
if (
|
|
4654
|
-
const
|
|
4650
|
+
const $ = e.get(y);
|
|
4651
|
+
if (!$)
|
|
4652
|
+
throw new Error(`Cube '${y}' not found`);
|
|
4653
|
+
if (b.relationship === "belongsToMany" && b.through) {
|
|
4654
|
+
const D = Xt(b, s.securityContext);
|
|
4655
4655
|
a.push({
|
|
4656
|
-
cube:
|
|
4657
|
-
alias: `${
|
|
4658
|
-
joinType:
|
|
4656
|
+
cube: $,
|
|
4657
|
+
alias: `${y.toLowerCase()}_cube`,
|
|
4658
|
+
joinType: D.junctionJoins[1].joinType,
|
|
4659
4659
|
// Use the target join type
|
|
4660
|
-
joinCondition:
|
|
4660
|
+
joinCondition: D.junctionJoins[1].condition,
|
|
4661
4661
|
// Target join condition
|
|
4662
4662
|
junctionTable: {
|
|
4663
|
-
table:
|
|
4664
|
-
alias: `junction_${
|
|
4665
|
-
joinType:
|
|
4666
|
-
joinCondition:
|
|
4667
|
-
securitySql:
|
|
4663
|
+
table: b.through.table,
|
|
4664
|
+
alias: `junction_${y.toLowerCase()}`,
|
|
4665
|
+
joinType: D.junctionJoins[0].joinType,
|
|
4666
|
+
joinCondition: D.junctionJoins[0].condition,
|
|
4667
|
+
securitySql: b.through.securitySql,
|
|
4668
|
+
sourceCubeName: g
|
|
4668
4669
|
}
|
|
4669
4670
|
});
|
|
4670
4671
|
} else {
|
|
4671
|
-
const
|
|
4672
|
-
|
|
4672
|
+
const D = r.buildJoinCondition(
|
|
4673
|
+
b,
|
|
4673
4674
|
null,
|
|
4674
4675
|
// No source alias needed - use the actual column
|
|
4675
4676
|
null
|
|
4676
4677
|
// No target alias needed - use the actual column
|
|
4677
|
-
),
|
|
4678
|
+
), w = _e(b.relationship, b.sqlJoinType);
|
|
4678
4679
|
a.push({
|
|
4679
|
-
cube:
|
|
4680
|
-
alias: `${
|
|
4681
|
-
joinType:
|
|
4682
|
-
joinCondition:
|
|
4680
|
+
cube: $,
|
|
4681
|
+
alias: `${y.toLowerCase()}_cube`,
|
|
4682
|
+
joinType: w,
|
|
4683
|
+
joinCondition: D
|
|
4683
4684
|
});
|
|
4684
4685
|
}
|
|
4685
|
-
u.add(
|
|
4686
|
+
u.add(y);
|
|
4686
4687
|
}
|
|
4687
4688
|
}
|
|
4688
4689
|
return a;
|
|
@@ -4738,26 +4739,31 @@ class at {
|
|
|
4738
4739
|
if (y.length === 0)
|
|
4739
4740
|
continue;
|
|
4740
4741
|
const b = this.analyzeJoinPathToPrimary(e, t, l.name, i);
|
|
4741
|
-
let
|
|
4742
|
+
let $, D;
|
|
4742
4743
|
if (b?.hasIntermediateHasMany && b.intermediateJoins.length > 0)
|
|
4743
|
-
|
|
4744
|
+
$ = b.correctJoinKeys, D = b.intermediateJoins;
|
|
4744
4745
|
else {
|
|
4745
4746
|
const S = p ? this.findJoinInfoToCube(e, t.name) : this.findJoinInfoForCube(e, t, l.name);
|
|
4746
4747
|
if (!S)
|
|
4747
4748
|
continue;
|
|
4748
|
-
|
|
4749
|
-
sourceColumn:
|
|
4750
|
-
targetColumn:
|
|
4751
|
-
sourceColumnObj:
|
|
4752
|
-
targetColumnObj:
|
|
4753
|
-
})) : S.joinDef.on.map((
|
|
4754
|
-
sourceColumn:
|
|
4755
|
-
targetColumn:
|
|
4756
|
-
sourceColumnObj:
|
|
4757
|
-
targetColumnObj:
|
|
4758
|
-
}))
|
|
4759
|
-
|
|
4760
|
-
|
|
4749
|
+
S.joinDef.relationship === "belongsToMany" && S.joinDef.through ? $ = S.joinDef.through.sourceKey.map((_) => ({
|
|
4750
|
+
sourceColumn: _.target.name,
|
|
4751
|
+
targetColumn: _.source.name,
|
|
4752
|
+
sourceColumnObj: _.target,
|
|
4753
|
+
targetColumnObj: _.source
|
|
4754
|
+
})) : $ = p || "reversed" in S && S.reversed ? S.joinDef.on.map((v) => ({
|
|
4755
|
+
sourceColumn: v.target.name,
|
|
4756
|
+
targetColumn: v.source.name,
|
|
4757
|
+
sourceColumnObj: v.target,
|
|
4758
|
+
targetColumnObj: v.source
|
|
4759
|
+
})) : S.joinDef.on.map((v) => ({
|
|
4760
|
+
sourceColumn: v.source.name,
|
|
4761
|
+
targetColumn: v.target.name,
|
|
4762
|
+
sourceColumnObj: v.source,
|
|
4763
|
+
targetColumnObj: v.target
|
|
4764
|
+
})), D = void 0;
|
|
4765
|
+
}
|
|
4766
|
+
const w = this.findPropagatingFilters(s, l, e), C = /* @__PURE__ */ new Map([[l.name, l]]), { aggregateMeasures: T, requiredBaseMeasures: E } = I.categorizeForPostAggregation(
|
|
4761
4767
|
y,
|
|
4762
4768
|
C
|
|
4763
4769
|
), N = [.../* @__PURE__ */ new Set([
|
|
@@ -4768,7 +4774,7 @@ class at {
|
|
|
4768
4774
|
const S = this.expandCalculatedMeasureDependencies(
|
|
4769
4775
|
l,
|
|
4770
4776
|
N
|
|
4771
|
-
),
|
|
4777
|
+
), _ = this.findDownstreamJoinKeys(
|
|
4772
4778
|
l,
|
|
4773
4779
|
s,
|
|
4774
4780
|
e
|
|
@@ -4777,11 +4783,11 @@ class at {
|
|
|
4777
4783
|
cube: l,
|
|
4778
4784
|
alias: m,
|
|
4779
4785
|
cteAlias: `${l.name.toLowerCase()}_agg`,
|
|
4780
|
-
joinKeys:
|
|
4786
|
+
joinKeys: $,
|
|
4781
4787
|
measures: S,
|
|
4782
|
-
propagatingFilters:
|
|
4783
|
-
downstreamJoinKeys:
|
|
4784
|
-
intermediateJoins:
|
|
4788
|
+
propagatingFilters: w.length > 0 ? w : void 0,
|
|
4789
|
+
downstreamJoinKeys: _.length > 0 ? _ : void 0,
|
|
4790
|
+
intermediateJoins: D && D.length > 0 ? D : void 0,
|
|
4785
4791
|
cteType: "aggregate",
|
|
4786
4792
|
cteReason: f
|
|
4787
4793
|
});
|
|
@@ -4797,7 +4803,7 @@ class at {
|
|
|
4797
4803
|
for (const [, n] of e)
|
|
4798
4804
|
if (n.name !== t && n.joins) {
|
|
4799
4805
|
for (const [, s] of Object.entries(n.joins))
|
|
4800
|
-
if (
|
|
4806
|
+
if (W(s.targetCube).name === t)
|
|
4801
4807
|
return { sourceCube: n, joinDef: s };
|
|
4802
4808
|
}
|
|
4803
4809
|
return null;
|
|
@@ -4837,13 +4843,13 @@ class at {
|
|
|
4837
4843
|
for (let f = 0; f < a.length - 1; f++) {
|
|
4838
4844
|
const h = a[f], g = a[f + 1], y = e.get(h.toCube);
|
|
4839
4845
|
if (!y) continue;
|
|
4840
|
-
const
|
|
4846
|
+
const $ = y.sql(s).where, D = g.joinDef.on[0]?.source, w = h.joinDef.on[0]?.target;
|
|
4841
4847
|
l.push({
|
|
4842
4848
|
cube: y,
|
|
4843
4849
|
joinDef: g.joinDef,
|
|
4844
|
-
securityFilter:
|
|
4845
|
-
primaryJoinColumn:
|
|
4846
|
-
cteJoinColumn:
|
|
4850
|
+
securityFilter: $,
|
|
4851
|
+
primaryJoinColumn: w,
|
|
4852
|
+
cteJoinColumn: D
|
|
4847
4853
|
});
|
|
4848
4854
|
}
|
|
4849
4855
|
const p = a[0].joinDef.on.map((f) => ({
|
|
@@ -4882,7 +4888,7 @@ class at {
|
|
|
4882
4888
|
if (!i.has(a) && (i.add(a), !!u.joins)) {
|
|
4883
4889
|
for (const [, c] of Object.entries(u.joins))
|
|
4884
4890
|
if (c.relationship === "hasMany") {
|
|
4885
|
-
const l =
|
|
4891
|
+
const l = W(c.targetCube);
|
|
4886
4892
|
(r.has(a) || r.has(l.name)) && s.push({
|
|
4887
4893
|
fromCube: a,
|
|
4888
4894
|
toCube: l.name,
|
|
@@ -4922,15 +4928,21 @@ class at {
|
|
|
4922
4928
|
*/
|
|
4923
4929
|
findJoinInfoForCube(e, t, n) {
|
|
4924
4930
|
if (t.joins) {
|
|
4925
|
-
for (const [,
|
|
4926
|
-
if (
|
|
4927
|
-
return { sourceCube: t, joinDef:
|
|
4928
|
-
}
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4931
|
+
for (const [, i] of Object.entries(t.joins))
|
|
4932
|
+
if (W(i.targetCube).name === n)
|
|
4933
|
+
return { sourceCube: t, joinDef: i };
|
|
4934
|
+
}
|
|
4935
|
+
const s = e.get(n);
|
|
4936
|
+
if (s?.joins) {
|
|
4937
|
+
for (const [, i] of Object.entries(s.joins))
|
|
4938
|
+
if (W(i.targetCube).name === t.name)
|
|
4939
|
+
return { sourceCube: s, joinDef: i, reversed: !0 };
|
|
4940
|
+
}
|
|
4941
|
+
for (const [, i] of e)
|
|
4942
|
+
if (!(i.name === t.name || i.name === n) && i.joins) {
|
|
4943
|
+
for (const [, r] of Object.entries(i.joins))
|
|
4944
|
+
if (W(r.targetCube).name === n)
|
|
4945
|
+
return { sourceCube: i, joinDef: r };
|
|
4934
4946
|
}
|
|
4935
4947
|
return null;
|
|
4936
4948
|
}
|
|
@@ -4961,15 +4973,20 @@ class at {
|
|
|
4961
4973
|
}
|
|
4962
4974
|
if (e.joins)
|
|
4963
4975
|
for (const [, r] of Object.entries(e.joins)) {
|
|
4964
|
-
const u =
|
|
4976
|
+
const u = W(r.targetCube).name;
|
|
4965
4977
|
if (i.has(u)) {
|
|
4966
|
-
|
|
4978
|
+
let c;
|
|
4979
|
+
r.relationship === "belongsToMany" && r.through ? c = r.through.sourceKey.map((l) => ({
|
|
4980
|
+
sourceColumn: l.source.name,
|
|
4981
|
+
targetColumn: l.target.name,
|
|
4982
|
+
sourceColumnObj: l.source,
|
|
4983
|
+
targetColumnObj: l.target
|
|
4984
|
+
})) : c = r.on.map((l) => ({
|
|
4967
4985
|
sourceColumn: l.source.name,
|
|
4968
4986
|
targetColumn: l.target.name,
|
|
4969
4987
|
sourceColumnObj: l.source,
|
|
4970
4988
|
targetColumnObj: l.target
|
|
4971
|
-
}))
|
|
4972
|
-
s.push({
|
|
4989
|
+
})), s.push({
|
|
4973
4990
|
targetCubeName: u,
|
|
4974
4991
|
joinKeys: c
|
|
4975
4992
|
});
|
|
@@ -5017,7 +5034,7 @@ class at {
|
|
|
5017
5034
|
if (!e.joins)
|
|
5018
5035
|
return null;
|
|
5019
5036
|
for (const [, n] of Object.entries(e.joins))
|
|
5020
|
-
if (
|
|
5037
|
+
if (W(n.targetCube).name === t && n.relationship === "hasMany")
|
|
5021
5038
|
return n;
|
|
5022
5039
|
return null;
|
|
5023
5040
|
}
|
|
@@ -5045,7 +5062,7 @@ class at {
|
|
|
5045
5062
|
const a = n.get(r);
|
|
5046
5063
|
if (a?.joins) {
|
|
5047
5064
|
for (const [, u] of Object.entries(a.joins))
|
|
5048
|
-
if (
|
|
5065
|
+
if (W(u.targetCube).name === t.name && u.relationship === "hasMany") {
|
|
5049
5066
|
const l = this.extractFiltersForCube(e.filters, r), m = this.extractTimeDimensionFiltersForCube(e, r), p = [...l, ...m];
|
|
5050
5067
|
p.length > 0 && u.on.length > 0 && s.push({
|
|
5051
5068
|
sourceCube: a,
|
|
@@ -5301,7 +5318,7 @@ class at {
|
|
|
5301
5318
|
visitedCubes: r
|
|
5302
5319
|
};
|
|
5303
5320
|
const a = i.map((u) => {
|
|
5304
|
-
const c =
|
|
5321
|
+
const c = _e(u.joinDef.relationship, u.joinDef.sqlJoinType), l = u.joinDef.on.map((p) => ({
|
|
5305
5322
|
sourceColumn: p.source.name,
|
|
5306
5323
|
targetColumn: p.target.name
|
|
5307
5324
|
})), m = {
|
|
@@ -5345,26 +5362,26 @@ class at {
|
|
|
5345
5362
|
if (!u)
|
|
5346
5363
|
continue;
|
|
5347
5364
|
const c = s.measures.filter(
|
|
5348
|
-
(
|
|
5365
|
+
($) => $.startsWith(r + ".")
|
|
5349
5366
|
), l = this.extractMeasuresFromFilters(s, u), m = [.../* @__PURE__ */ new Set([...c, ...l])];
|
|
5350
5367
|
if (m.length === 0)
|
|
5351
5368
|
continue;
|
|
5352
|
-
const p = a.on.map((
|
|
5353
|
-
sourceColumn:
|
|
5354
|
-
targetColumn:
|
|
5369
|
+
const p = a.on.map(($) => ({
|
|
5370
|
+
sourceColumn: $.source.name,
|
|
5371
|
+
targetColumn: $.target.name
|
|
5355
5372
|
})), f = /* @__PURE__ */ new Map([[r, u]]), { aggregateMeasures: h, postAggWindowMeasures: g, requiredBaseMeasures: y } = I.categorizeForPostAggregation(
|
|
5356
5373
|
m,
|
|
5357
5374
|
f
|
|
5358
5375
|
), b = [.../* @__PURE__ */ new Set([
|
|
5359
5376
|
...h,
|
|
5360
|
-
...Array.from(y).filter((
|
|
5377
|
+
...Array.from(y).filter(($) => $.startsWith(r + "."))
|
|
5361
5378
|
])];
|
|
5362
5379
|
if (b.length > 0) {
|
|
5363
|
-
const
|
|
5380
|
+
const $ = g.length > 0;
|
|
5364
5381
|
i.push({
|
|
5365
5382
|
cubeName: r,
|
|
5366
5383
|
cteAlias: `${r.toLowerCase()}_agg`,
|
|
5367
|
-
reason:
|
|
5384
|
+
reason: $ ? `hasMany relationship from ${t.name} - requires pre-aggregation; includes base measures for post-aggregation window functions` : `hasMany relationship from ${t.name} - requires pre-aggregation to prevent row duplication (fan-out)`,
|
|
5368
5385
|
reasonType: "hasMany",
|
|
5369
5386
|
measures: b,
|
|
5370
5387
|
joinKeys: p,
|
|
@@ -5422,7 +5439,7 @@ class at {
|
|
|
5422
5439
|
};
|
|
5423
5440
|
}
|
|
5424
5441
|
}
|
|
5425
|
-
class
|
|
5442
|
+
class cn {
|
|
5426
5443
|
constructor(e) {
|
|
5427
5444
|
this.queryBuilder = e;
|
|
5428
5445
|
}
|
|
@@ -5488,7 +5505,7 @@ class on {
|
|
|
5488
5505
|
let f = n.db.select(c).from(a.from);
|
|
5489
5506
|
if (u && e.intermediateJoins)
|
|
5490
5507
|
for (const C of e.intermediateJoins) {
|
|
5491
|
-
const T = C.cube.sql(n), N = [
|
|
5508
|
+
const T = C.cube.sql(n), N = [Q(C.cteJoinColumn, C.joinDef.on[0]?.target)];
|
|
5492
5509
|
C.securityFilter && N.push(C.securityFilter), f = f.leftJoin(
|
|
5493
5510
|
T.from,
|
|
5494
5511
|
A(...N)
|
|
@@ -5502,8 +5519,8 @@ class on {
|
|
|
5502
5519
|
for (const C of t.timeDimensions) {
|
|
5503
5520
|
const [T, E] = C.dimension.split(".");
|
|
5504
5521
|
if (T === l && r.dimensions && r.dimensions[E] && C.dateRange) {
|
|
5505
|
-
const N = r.dimensions[E], S = this.queryBuilder.buildMeasureExpression({ sql: N.sql, type: "number" }, n),
|
|
5506
|
-
|
|
5522
|
+
const N = r.dimensions[E], S = this.queryBuilder.buildMeasureExpression({ sql: N.sql, type: "number" }, n), _ = this.queryBuilder.buildDateRangeCondition(S, C.dateRange);
|
|
5523
|
+
_ && y.push(_);
|
|
5507
5524
|
}
|
|
5508
5525
|
}
|
|
5509
5526
|
if (t.filters) {
|
|
@@ -5513,8 +5530,8 @@ class on {
|
|
|
5513
5530
|
if (E === l && r.dimensions && r.dimensions[N]) {
|
|
5514
5531
|
const S = r.dimensions[N];
|
|
5515
5532
|
if (T.operator === "inDateRange") {
|
|
5516
|
-
const
|
|
5517
|
-
|
|
5533
|
+
const _ = this.queryBuilder.buildMeasureExpression({ sql: S.sql, type: "number" }, n), v = this.queryBuilder.buildDateRangeCondition(_, T.values);
|
|
5534
|
+
v && y.push(v);
|
|
5518
5535
|
}
|
|
5519
5536
|
}
|
|
5520
5537
|
}
|
|
@@ -5532,26 +5549,26 @@ class on {
|
|
|
5532
5549
|
const C = b.length === 1 ? b[0] : A(...b);
|
|
5533
5550
|
f = f.where(C);
|
|
5534
5551
|
}
|
|
5535
|
-
const
|
|
5552
|
+
const $ = [], D = /* @__PURE__ */ new Set(), w = (C) => {
|
|
5536
5553
|
const T = C?.name || (typeof C == "string" ? C : null);
|
|
5537
|
-
T && !
|
|
5554
|
+
T && !D.has(T) ? (D.add(T), $.push(C)) : T || $.push(C);
|
|
5538
5555
|
};
|
|
5539
5556
|
if (u && e.intermediateJoins) {
|
|
5540
5557
|
const C = e.intermediateJoins[0];
|
|
5541
|
-
C.primaryJoinColumn &&
|
|
5558
|
+
C.primaryJoinColumn && w(C.primaryJoinColumn);
|
|
5542
5559
|
} else
|
|
5543
5560
|
for (const C of e.joinKeys)
|
|
5544
|
-
C.targetColumnObj &&
|
|
5561
|
+
C.targetColumnObj && w(C.targetColumnObj);
|
|
5545
5562
|
if (e.downstreamJoinKeys)
|
|
5546
5563
|
for (const C of e.downstreamJoinKeys)
|
|
5547
5564
|
for (const T of C.joinKeys)
|
|
5548
|
-
T.sourceColumnObj &&
|
|
5565
|
+
T.sourceColumnObj && w(T.sourceColumnObj);
|
|
5549
5566
|
if (t.dimensions)
|
|
5550
5567
|
for (const C of t.dimensions) {
|
|
5551
5568
|
const [T, E] = C.split(".");
|
|
5552
5569
|
if (T === l && r.dimensions && r.dimensions[E]) {
|
|
5553
|
-
const N = r.dimensions[E], S =
|
|
5554
|
-
|
|
5570
|
+
const N = r.dimensions[E], S = R(N.sql, n);
|
|
5571
|
+
$.push(S);
|
|
5555
5572
|
}
|
|
5556
5573
|
}
|
|
5557
5574
|
if (t.timeDimensions)
|
|
@@ -5559,10 +5576,10 @@ class on {
|
|
|
5559
5576
|
const [T, E] = C.dimension.split(".");
|
|
5560
5577
|
if (T === l && r.dimensions && r.dimensions[E]) {
|
|
5561
5578
|
const N = r.dimensions[E], S = this.queryBuilder.buildTimeDimensionExpression(N.sql, C.granularity, n);
|
|
5562
|
-
|
|
5579
|
+
$.push(S);
|
|
5563
5580
|
}
|
|
5564
5581
|
}
|
|
5565
|
-
return
|
|
5582
|
+
return $.length > 0 && (f = f.groupBy(...$)), n.db.$with(e.cteAlias).as(f);
|
|
5566
5583
|
}
|
|
5567
5584
|
/**
|
|
5568
5585
|
* Build join condition for CTE
|
|
@@ -5582,11 +5599,11 @@ class on {
|
|
|
5582
5599
|
const i = [];
|
|
5583
5600
|
if (s.intermediateJoins && s.intermediateJoins.length > 0) {
|
|
5584
5601
|
const r = s.intermediateJoins[0], a = s.joinKeys[0]?.sourceColumnObj, u = o`${o.identifier(t)}.${o.identifier(r.primaryJoinColumn.name)}`;
|
|
5585
|
-
i.push(
|
|
5602
|
+
i.push(Q(a, u));
|
|
5586
5603
|
} else
|
|
5587
5604
|
for (const r of s.joinKeys) {
|
|
5588
5605
|
const a = r.sourceColumnObj || o.identifier(r.sourceColumn), u = o`${o.identifier(t)}.${o.identifier(r.targetColumn)}`;
|
|
5589
|
-
i.push(
|
|
5606
|
+
i.push(Q(a, u));
|
|
5590
5607
|
}
|
|
5591
5608
|
return i.length === 1 ? i[0] : A(...i);
|
|
5592
5609
|
}
|
|
@@ -5622,7 +5639,7 @@ class on {
|
|
|
5622
5639
|
const { source: u, target: c } = a[0], l = t.db.select({ pk: u }).from(s.from).where(r);
|
|
5623
5640
|
return o`${c} IN ${l}`;
|
|
5624
5641
|
} else {
|
|
5625
|
-
const u = a.map((m) =>
|
|
5642
|
+
const u = a.map((m) => Q(m.source, m.target)), c = A(
|
|
5626
5643
|
...u,
|
|
5627
5644
|
r
|
|
5628
5645
|
), l = t.db.select({ one: o`1` }).from(s.from).where(c);
|
|
@@ -5630,15 +5647,15 @@ class on {
|
|
|
5630
5647
|
}
|
|
5631
5648
|
}
|
|
5632
5649
|
}
|
|
5633
|
-
function
|
|
5650
|
+
function dn(d, e, t) {
|
|
5634
5651
|
const n = [];
|
|
5635
|
-
let s =
|
|
5636
|
-
const i =
|
|
5652
|
+
let s = Je(new Date(d), t);
|
|
5653
|
+
const i = Je(new Date(e), t), r = 1e4;
|
|
5637
5654
|
for (; s <= i && n.length < r; )
|
|
5638
|
-
n.push(new Date(s)), s =
|
|
5655
|
+
n.push(new Date(s)), s = mn(s, t);
|
|
5639
5656
|
return n;
|
|
5640
5657
|
}
|
|
5641
|
-
function
|
|
5658
|
+
function Je(d, e) {
|
|
5642
5659
|
const t = new Date(d);
|
|
5643
5660
|
switch (e) {
|
|
5644
5661
|
case "second":
|
|
@@ -5672,7 +5689,7 @@ function qe(d, e) {
|
|
|
5672
5689
|
}
|
|
5673
5690
|
return t;
|
|
5674
5691
|
}
|
|
5675
|
-
function
|
|
5692
|
+
function mn(d, e) {
|
|
5676
5693
|
const t = new Date(d);
|
|
5677
5694
|
switch (e) {
|
|
5678
5695
|
case "second":
|
|
@@ -5702,7 +5719,7 @@ function un(d, e) {
|
|
|
5702
5719
|
}
|
|
5703
5720
|
return t;
|
|
5704
5721
|
}
|
|
5705
|
-
function
|
|
5722
|
+
function fn(d) {
|
|
5706
5723
|
if (d instanceof Date)
|
|
5707
5724
|
return d.toISOString();
|
|
5708
5725
|
if (typeof d == "string") {
|
|
@@ -5712,16 +5729,16 @@ function ln(d) {
|
|
|
5712
5729
|
}
|
|
5713
5730
|
return String(d);
|
|
5714
5731
|
}
|
|
5715
|
-
function
|
|
5732
|
+
function pn(d, e) {
|
|
5716
5733
|
return e.length === 0 ? "__all__" : e.map((t) => String(d[t] ?? "")).join("|||");
|
|
5717
5734
|
}
|
|
5718
|
-
function
|
|
5719
|
-
const { timeDimensionKey: t, granularity: n, dateRange: s, fillValue: i, measures: r, dimensions: a } = e, u =
|
|
5735
|
+
function hn(d, e) {
|
|
5736
|
+
const { timeDimensionKey: t, granularity: n, dateRange: s, fillValue: i, measures: r, dimensions: a } = e, u = dn(s[0], s[1], n);
|
|
5720
5737
|
if (u.length === 0)
|
|
5721
5738
|
return d;
|
|
5722
5739
|
const c = /* @__PURE__ */ new Map();
|
|
5723
5740
|
for (const m of d) {
|
|
5724
|
-
const p =
|
|
5741
|
+
const p = pn(m, a), f = fn(m[t]);
|
|
5725
5742
|
c.has(p) || c.set(p, /* @__PURE__ */ new Map()), c.get(p).set(f, m);
|
|
5726
5743
|
}
|
|
5727
5744
|
c.size === 0 && a.length === 0 && c.set("__all__", /* @__PURE__ */ new Map());
|
|
@@ -5737,17 +5754,17 @@ function dn(d, e) {
|
|
|
5737
5754
|
[t]: g
|
|
5738
5755
|
};
|
|
5739
5756
|
if (f)
|
|
5740
|
-
for (const
|
|
5741
|
-
b[
|
|
5742
|
-
for (const
|
|
5743
|
-
b[
|
|
5757
|
+
for (const $ of a)
|
|
5758
|
+
b[$] = f[$];
|
|
5759
|
+
for (const $ of r)
|
|
5760
|
+
b[$] = i;
|
|
5744
5761
|
l.push(b);
|
|
5745
5762
|
}
|
|
5746
5763
|
}
|
|
5747
5764
|
}
|
|
5748
5765
|
return l;
|
|
5749
5766
|
}
|
|
5750
|
-
function
|
|
5767
|
+
function gn(d) {
|
|
5751
5768
|
if (!d)
|
|
5752
5769
|
return null;
|
|
5753
5770
|
if (Array.isArray(d)) {
|
|
@@ -5759,7 +5776,7 @@ function mn(d) {
|
|
|
5759
5776
|
const e = new Date(d);
|
|
5760
5777
|
return isNaN(e.getTime()) ? null : [e, e];
|
|
5761
5778
|
}
|
|
5762
|
-
function
|
|
5779
|
+
function Ge(d, e, t) {
|
|
5763
5780
|
if (!e.timeDimensions || e.timeDimensions.length === 0)
|
|
5764
5781
|
return d;
|
|
5765
5782
|
const n = e.timeDimensions.filter((u) => {
|
|
@@ -5771,7 +5788,7 @@ function ze(d, e, t) {
|
|
|
5771
5788
|
const s = e.fillMissingDatesValue === void 0 ? 0 : e.fillMissingDatesValue, i = new Set(e.timeDimensions.map((u) => u.dimension)), r = (e.dimensions || []).filter((u) => !i.has(u));
|
|
5772
5789
|
let a = d;
|
|
5773
5790
|
for (const u of n) {
|
|
5774
|
-
const c =
|
|
5791
|
+
const c = gn(u.dateRange);
|
|
5775
5792
|
if (!c)
|
|
5776
5793
|
continue;
|
|
5777
5794
|
const l = {
|
|
@@ -5782,14 +5799,14 @@ function ze(d, e, t) {
|
|
|
5782
5799
|
measures: t,
|
|
5783
5800
|
dimensions: r
|
|
5784
5801
|
};
|
|
5785
|
-
a =
|
|
5802
|
+
a = hn(a, l);
|
|
5786
5803
|
}
|
|
5787
5804
|
return a;
|
|
5788
5805
|
}
|
|
5789
|
-
class
|
|
5806
|
+
class bn {
|
|
5790
5807
|
dateTimeBuilder;
|
|
5791
5808
|
constructor(e) {
|
|
5792
|
-
this.dateTimeBuilder = new
|
|
5809
|
+
this.dateTimeBuilder = new ie(e);
|
|
5793
5810
|
}
|
|
5794
5811
|
/**
|
|
5795
5812
|
* Check if a query contains compareDateRange
|
|
@@ -5970,9 +5987,9 @@ class fn {
|
|
|
5970
5987
|
});
|
|
5971
5988
|
}
|
|
5972
5989
|
}
|
|
5973
|
-
class
|
|
5990
|
+
class yn {
|
|
5974
5991
|
constructor(e) {
|
|
5975
|
-
this.databaseAdapter = e, this.dateTimeBuilder = new
|
|
5992
|
+
this.databaseAdapter = e, this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder);
|
|
5976
5993
|
}
|
|
5977
5994
|
filterBuilder;
|
|
5978
5995
|
dateTimeBuilder;
|
|
@@ -6019,7 +6036,7 @@ class pn {
|
|
|
6019
6036
|
if (i.name || n.push(`Step ${s} must have a name`), "cube" in i && i.cube && (t.get(i.cube) || n.push(`Step ${s} cube not found: ${i.cube}`)), i.filter) {
|
|
6020
6037
|
let r;
|
|
6021
6038
|
"cube" in i && i.cube ? r = i.cube : typeof e.bindingKey == "string" && ([r] = e.bindingKey.split("."));
|
|
6022
|
-
const a = r ? new
|
|
6039
|
+
const a = r ? new ae(t) : null, u = Array.isArray(i.filter) ? i.filter : [i.filter];
|
|
6023
6040
|
for (const c of u)
|
|
6024
6041
|
if ("member" in c) {
|
|
6025
6042
|
const [l, m] = c.member.split("."), p = t.get(l);
|
|
@@ -6107,7 +6124,7 @@ class pn {
|
|
|
6107
6124
|
* Resolve steps with their cube, SQL expressions, and filter conditions
|
|
6108
6125
|
*/
|
|
6109
6126
|
resolveSteps(e, t, n) {
|
|
6110
|
-
const s = new
|
|
6127
|
+
const s = new ae(t);
|
|
6111
6128
|
return e.steps.map((i, r) => {
|
|
6112
6129
|
const a = this.resolveCubeForStep(i, e, t), u = this.resolveBindingKey(e, a, n), c = this.resolveTimeDimension(e, a, n), l = this.buildStepFilters(i, a, t, n), m = this.extractFilterCubeNames(i), p = [];
|
|
6113
6130
|
for (const f of m)
|
|
@@ -6156,7 +6173,7 @@ class pn {
|
|
|
6156
6173
|
const [, a] = e.bindingKey.split("."), u = t.dimensions?.[a];
|
|
6157
6174
|
if (!u)
|
|
6158
6175
|
throw new Error(`Binding key dimension not found: ${e.bindingKey}`);
|
|
6159
|
-
return
|
|
6176
|
+
return R(u.sql, n);
|
|
6160
6177
|
}
|
|
6161
6178
|
const s = e.bindingKey.find((a) => a.cube === t.name);
|
|
6162
6179
|
if (!s)
|
|
@@ -6164,7 +6181,7 @@ class pn {
|
|
|
6164
6181
|
const [, i] = s.dimension.split("."), r = t.dimensions?.[i];
|
|
6165
6182
|
if (!r)
|
|
6166
6183
|
throw new Error(`Binding key dimension not found: ${s.dimension}`);
|
|
6167
|
-
return
|
|
6184
|
+
return R(r.sql, n);
|
|
6168
6185
|
}
|
|
6169
6186
|
/**
|
|
6170
6187
|
* Resolve time dimension expression for a cube
|
|
@@ -6174,7 +6191,7 @@ class pn {
|
|
|
6174
6191
|
const [, a] = e.timeDimension.split("."), u = t.dimensions?.[a];
|
|
6175
6192
|
if (!u)
|
|
6176
6193
|
throw new Error(`Time dimension not found: ${e.timeDimension}`);
|
|
6177
|
-
return
|
|
6194
|
+
return R(u.sql, n);
|
|
6178
6195
|
}
|
|
6179
6196
|
const s = e.timeDimension.find((a) => a.cube === t.name);
|
|
6180
6197
|
if (!s)
|
|
@@ -6182,7 +6199,7 @@ class pn {
|
|
|
6182
6199
|
const [, i] = s.dimension.split("."), r = t.dimensions?.[i];
|
|
6183
6200
|
if (!r)
|
|
6184
6201
|
throw new Error(`Time dimension not found: ${s.dimension}`);
|
|
6185
|
-
return
|
|
6202
|
+
return R(r.sql, n);
|
|
6186
6203
|
}
|
|
6187
6204
|
/**
|
|
6188
6205
|
* Build filter conditions for a step
|
|
@@ -6216,17 +6233,17 @@ class pn {
|
|
|
6216
6233
|
if (r) {
|
|
6217
6234
|
const b = e;
|
|
6218
6235
|
y = b.type === "and";
|
|
6219
|
-
for (const
|
|
6220
|
-
const
|
|
6221
|
-
|
|
6236
|
+
for (const $ of b.filters || []) {
|
|
6237
|
+
const D = this.buildFilterCondition($, t, n, s);
|
|
6238
|
+
D && g.push(D);
|
|
6222
6239
|
}
|
|
6223
6240
|
} else {
|
|
6224
6241
|
const b = e;
|
|
6225
6242
|
y = "and" in b && !!b.and;
|
|
6226
|
-
const
|
|
6227
|
-
for (const
|
|
6228
|
-
const
|
|
6229
|
-
|
|
6243
|
+
const $ = b.and || b.or || [];
|
|
6244
|
+
for (const D of $) {
|
|
6245
|
+
const w = this.buildFilterCondition(D, t, n, s);
|
|
6246
|
+
w && g.push(w);
|
|
6230
6247
|
}
|
|
6231
6248
|
}
|
|
6232
6249
|
return g.length === 0 ? null : g.length === 1 ? g[0] : y ? A(...g) : o`(${o.join(g, o` OR `)})`;
|
|
@@ -6238,7 +6255,7 @@ class pn {
|
|
|
6238
6255
|
if (!p)
|
|
6239
6256
|
return null;
|
|
6240
6257
|
if (u !== t.name) {
|
|
6241
|
-
const y = new
|
|
6258
|
+
const y = new ae(n).findPath(t.name, u);
|
|
6242
6259
|
if (!y || y.length === 0)
|
|
6243
6260
|
return console.warn(
|
|
6244
6261
|
`Funnel filter: Cannot filter by '${u}.${c}' in step using '${t.name}'. No join path found. Filter will be skipped.`
|
|
@@ -6246,7 +6263,7 @@ class pn {
|
|
|
6246
6263
|
}
|
|
6247
6264
|
const f = p.dimensions?.[c];
|
|
6248
6265
|
if (!f) return null;
|
|
6249
|
-
const h =
|
|
6266
|
+
const h = R(f.sql, s);
|
|
6250
6267
|
return this.filterBuilder.buildFilterCondition(
|
|
6251
6268
|
h,
|
|
6252
6269
|
a.operator,
|
|
@@ -6334,7 +6351,7 @@ class pn {
|
|
|
6334
6351
|
for (const r of i.joinPath) {
|
|
6335
6352
|
const a = r.joinDef, u = [];
|
|
6336
6353
|
for (const p of a.on)
|
|
6337
|
-
p.as ? u.push(p.as(p.source, p.target)) : u.push(
|
|
6354
|
+
p.as ? u.push(p.as(p.source, p.target)) : u.push(Q(p.source, p.target));
|
|
6338
6355
|
const c = u.length === 1 ? u[0] : A(...u), m = i.cube.sql(n);
|
|
6339
6356
|
e = e.leftJoin(m.from, c), m.where && s.push(m.where);
|
|
6340
6357
|
}
|
|
@@ -6408,12 +6425,12 @@ class pn {
|
|
|
6408
6425
|
return i.db.$with("funnel_metrics").as(a);
|
|
6409
6426
|
}
|
|
6410
6427
|
}
|
|
6411
|
-
class
|
|
6428
|
+
class Cn {
|
|
6412
6429
|
filterBuilder;
|
|
6413
6430
|
dateTimeBuilder;
|
|
6414
6431
|
databaseAdapter;
|
|
6415
6432
|
constructor(e) {
|
|
6416
|
-
this.databaseAdapter = e, this.dateTimeBuilder = new
|
|
6433
|
+
this.databaseAdapter = e, this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder);
|
|
6417
6434
|
}
|
|
6418
6435
|
/**
|
|
6419
6436
|
* Check if query contains flow configuration
|
|
@@ -6584,7 +6601,7 @@ class hn {
|
|
|
6584
6601
|
const [, a] = e.bindingKey.split("."), u = t.dimensions?.[a];
|
|
6585
6602
|
if (!u)
|
|
6586
6603
|
throw new Error(`Binding key dimension not found: ${e.bindingKey}`);
|
|
6587
|
-
return
|
|
6604
|
+
return R(u.sql, n);
|
|
6588
6605
|
}
|
|
6589
6606
|
const s = e.bindingKey.find((a) => a.cube === t.name);
|
|
6590
6607
|
if (!s)
|
|
@@ -6592,7 +6609,7 @@ class hn {
|
|
|
6592
6609
|
const [, i] = s.dimension.split("."), r = t.dimensions?.[i];
|
|
6593
6610
|
if (!r)
|
|
6594
6611
|
throw new Error(`Binding key dimension not found: ${s.dimension}`);
|
|
6595
|
-
return
|
|
6612
|
+
return R(r.sql, n);
|
|
6596
6613
|
}
|
|
6597
6614
|
/**
|
|
6598
6615
|
* Resolve time dimension expression
|
|
@@ -6602,7 +6619,7 @@ class hn {
|
|
|
6602
6619
|
const [, a] = e.timeDimension.split("."), u = t.dimensions?.[a];
|
|
6603
6620
|
if (!u)
|
|
6604
6621
|
throw new Error(`Time dimension not found: ${e.timeDimension}`);
|
|
6605
|
-
return
|
|
6622
|
+
return R(u.sql, n);
|
|
6606
6623
|
}
|
|
6607
6624
|
const s = e.timeDimension.find((a) => a.cube === t.name);
|
|
6608
6625
|
if (!s)
|
|
@@ -6610,7 +6627,7 @@ class hn {
|
|
|
6610
6627
|
const [, i] = s.dimension.split("."), r = t.dimensions?.[i];
|
|
6611
6628
|
if (!r)
|
|
6612
6629
|
throw new Error(`Time dimension not found: ${s.dimension}`);
|
|
6613
|
-
return
|
|
6630
|
+
return R(r.sql, n);
|
|
6614
6631
|
}
|
|
6615
6632
|
/**
|
|
6616
6633
|
* Resolve event dimension expression
|
|
@@ -6619,7 +6636,7 @@ class hn {
|
|
|
6619
6636
|
const [, s] = e.eventDimension.split("."), i = t.dimensions?.[s];
|
|
6620
6637
|
if (!i)
|
|
6621
6638
|
throw new Error(`Event dimension not found: ${e.eventDimension}`);
|
|
6622
|
-
return
|
|
6639
|
+
return R(i.sql, n);
|
|
6623
6640
|
}
|
|
6624
6641
|
/**
|
|
6625
6642
|
* Build filter conditions for the starting step
|
|
@@ -6656,7 +6673,7 @@ class hn {
|
|
|
6656
6673
|
}
|
|
6657
6674
|
const s = e, [, i] = s.member.split("."), r = t.dimensions?.[i];
|
|
6658
6675
|
if (!r) return null;
|
|
6659
|
-
const a =
|
|
6676
|
+
const a = R(r.sql, n);
|
|
6660
6677
|
return this.filterBuilder.buildFilterCondition(
|
|
6661
6678
|
a,
|
|
6662
6679
|
s.operator,
|
|
@@ -6706,7 +6723,7 @@ class hn {
|
|
|
6706
6723
|
step_time: o`${r}`.as("step_time"),
|
|
6707
6724
|
event_type: o`${a}`.as("event_type"),
|
|
6708
6725
|
event_path: y.as("event_path")
|
|
6709
|
-
}).from(s.from).where(g).orderBy(o`${r} DESC`).limit(1),
|
|
6726
|
+
}).from(s.from).where(g).orderBy(o`${r} DESC`).limit(1), $ = n.db.$with(f).as(
|
|
6710
6727
|
n.db.select({
|
|
6711
6728
|
binding_key: o`e.binding_key`.as("binding_key"),
|
|
6712
6729
|
step_time: o`e.step_time`.as("step_time"),
|
|
@@ -6714,7 +6731,7 @@ class hn {
|
|
|
6714
6731
|
event_path: o`e.event_path`.as("event_path")
|
|
6715
6732
|
}).from(o`${o.identifier(m)}`).crossJoinLateral(b.as("e"))
|
|
6716
6733
|
);
|
|
6717
|
-
u.push(
|
|
6734
|
+
u.push($);
|
|
6718
6735
|
}
|
|
6719
6736
|
return u;
|
|
6720
6737
|
}
|
|
@@ -6735,7 +6752,7 @@ class hn {
|
|
|
6735
6752
|
step_time: o`${r}`.as("step_time"),
|
|
6736
6753
|
event_type: o`${a}`.as("event_type"),
|
|
6737
6754
|
event_path: y.as("event_path")
|
|
6738
|
-
}).from(s.from).where(g).orderBy(o`${r} ASC`).limit(1),
|
|
6755
|
+
}).from(s.from).where(g).orderBy(o`${r} ASC`).limit(1), $ = n.db.$with(f).as(
|
|
6739
6756
|
n.db.select({
|
|
6740
6757
|
binding_key: o`e.binding_key`.as("binding_key"),
|
|
6741
6758
|
step_time: o`e.step_time`.as("step_time"),
|
|
@@ -6743,7 +6760,7 @@ class hn {
|
|
|
6743
6760
|
event_path: o`e.event_path`.as("event_path")
|
|
6744
6761
|
}).from(o`${o.identifier(m)}`).crossJoinLateral(b.as("e"))
|
|
6745
6762
|
);
|
|
6746
|
-
u.push(
|
|
6763
|
+
u.push($);
|
|
6747
6764
|
}
|
|
6748
6765
|
return u;
|
|
6749
6766
|
}
|
|
@@ -6770,13 +6787,13 @@ class hn {
|
|
|
6770
6787
|
}).from(s.from).innerJoin(
|
|
6771
6788
|
o`${o.identifier(m)}`,
|
|
6772
6789
|
o`${i} = ${o.identifier(m)}.binding_key`
|
|
6773
|
-
).where(g),
|
|
6790
|
+
).where(g), $ = n.db.select({
|
|
6774
6791
|
binding_key: o`binding_key`.as("binding_key"),
|
|
6775
6792
|
step_time: o`step_time`.as("step_time"),
|
|
6776
6793
|
event_type: o`event_type`.as("event_type"),
|
|
6777
6794
|
event_path: o`event_path`.as("event_path")
|
|
6778
6795
|
}).from(b.as("ranked")).where(o`rn = 1`);
|
|
6779
|
-
u.push(n.db.$with(f).as(
|
|
6796
|
+
u.push(n.db.$with(f).as($));
|
|
6780
6797
|
}
|
|
6781
6798
|
return u;
|
|
6782
6799
|
}
|
|
@@ -6803,13 +6820,13 @@ class hn {
|
|
|
6803
6820
|
}).from(s.from).innerJoin(
|
|
6804
6821
|
o`${o.identifier(m)}`,
|
|
6805
6822
|
o`${i} = ${o.identifier(m)}.binding_key`
|
|
6806
|
-
).where(g),
|
|
6823
|
+
).where(g), $ = n.db.select({
|
|
6807
6824
|
binding_key: o`binding_key`.as("binding_key"),
|
|
6808
6825
|
step_time: o`step_time`.as("step_time"),
|
|
6809
6826
|
event_type: o`event_type`.as("event_type"),
|
|
6810
6827
|
event_path: o`event_path`.as("event_path")
|
|
6811
6828
|
}).from(b.as("ranked")).where(o`rn = 1`);
|
|
6812
|
-
u.push(n.db.$with(f).as(
|
|
6829
|
+
u.push(n.db.$with(f).as($));
|
|
6813
6830
|
}
|
|
6814
6831
|
return u;
|
|
6815
6832
|
}
|
|
@@ -7010,31 +7027,31 @@ class hn {
|
|
|
7010
7027
|
return e.db.$with("final_result").as(n);
|
|
7011
7028
|
}
|
|
7012
7029
|
}
|
|
7013
|
-
function
|
|
7030
|
+
function He(d) {
|
|
7014
7031
|
return Array.isArray(d);
|
|
7015
7032
|
}
|
|
7016
|
-
function
|
|
7033
|
+
function dt(d) {
|
|
7017
7034
|
return typeof d == "object" && d !== null && "cube" in d;
|
|
7018
7035
|
}
|
|
7019
|
-
function
|
|
7020
|
-
if (
|
|
7036
|
+
function Ye(d) {
|
|
7037
|
+
if (dt(d))
|
|
7021
7038
|
return d.cube;
|
|
7022
7039
|
const e = d.indexOf(".");
|
|
7023
7040
|
if (e === -1)
|
|
7024
7041
|
throw new Error(`Invalid time dimension format: ${d}. Expected 'CubeName.dimensionName'`);
|
|
7025
7042
|
return d.substring(0, e);
|
|
7026
7043
|
}
|
|
7027
|
-
function
|
|
7028
|
-
if (
|
|
7044
|
+
function Xe(d) {
|
|
7045
|
+
if (dt(d))
|
|
7029
7046
|
return d.dimension;
|
|
7030
7047
|
const e = d.indexOf(".");
|
|
7031
7048
|
if (e === -1)
|
|
7032
7049
|
throw new Error(`Invalid time dimension format: ${d}. Expected 'CubeName.dimensionName'`);
|
|
7033
7050
|
return d.substring(e + 1);
|
|
7034
7051
|
}
|
|
7035
|
-
class
|
|
7052
|
+
class wn {
|
|
7036
7053
|
constructor(e) {
|
|
7037
|
-
this.databaseAdapter = e, this.dateTimeBuilder = new
|
|
7054
|
+
this.databaseAdapter = e, this.dateTimeBuilder = new ie(e), this.filterBuilder = new ge(e, this.dateTimeBuilder);
|
|
7038
7055
|
}
|
|
7039
7056
|
filterBuilder;
|
|
7040
7057
|
dateTimeBuilder;
|
|
@@ -7050,12 +7067,12 @@ class gn {
|
|
|
7050
7067
|
validateConfig(e, t) {
|
|
7051
7068
|
const n = [];
|
|
7052
7069
|
try {
|
|
7053
|
-
const r =
|
|
7070
|
+
const r = Ye(e.timeDimension), a = Xe(e.timeDimension), u = t.get(r);
|
|
7054
7071
|
u ? u.dimensions?.[a] || n.push(`Time dimension not found: ${a} in cube ${r}`) : n.push(`Cube not found: ${r}`);
|
|
7055
7072
|
} catch {
|
|
7056
7073
|
n.push(`Invalid time dimension format: ${e.timeDimension}`);
|
|
7057
7074
|
}
|
|
7058
|
-
if (
|
|
7075
|
+
if (He(e.bindingKey))
|
|
7059
7076
|
for (const r of e.bindingKey) {
|
|
7060
7077
|
const a = t.get(r.cube);
|
|
7061
7078
|
if (!a)
|
|
@@ -7167,18 +7184,18 @@ class gn {
|
|
|
7167
7184
|
* Same cube/dimension used for both cohort entry and activity detection
|
|
7168
7185
|
*/
|
|
7169
7186
|
resolveConfig(e, t, n) {
|
|
7170
|
-
const s =
|
|
7187
|
+
const s = Ye(e.timeDimension), i = Xe(e.timeDimension), r = t.get(s);
|
|
7171
7188
|
if (!r)
|
|
7172
7189
|
throw new Error(`Cube not found: ${s}`);
|
|
7173
7190
|
const a = r.dimensions?.[i];
|
|
7174
7191
|
if (!a)
|
|
7175
7192
|
throw new Error(`Time dimension not found: ${i}`);
|
|
7176
|
-
const u =
|
|
7193
|
+
const u = R(a.sql, n), c = this.resolveBindingKey(e.bindingKey, r, t, n), l = this.buildFilterConditions(e.cohortFilters, r, t, n), m = this.buildFilterConditions(e.activityFilters, r, t, n), p = [];
|
|
7177
7194
|
if (e.breakdownDimensions && e.breakdownDimensions.length > 0)
|
|
7178
7195
|
for (const f of e.breakdownDimensions) {
|
|
7179
7196
|
const [h, g] = f.split("."), y = t.get(h);
|
|
7180
7197
|
if (y && y.dimensions?.[g]) {
|
|
7181
|
-
const b =
|
|
7198
|
+
const b = R(y.dimensions[g].sql, n);
|
|
7182
7199
|
p.push({ dimension: f, expr: b });
|
|
7183
7200
|
}
|
|
7184
7201
|
}
|
|
@@ -7188,7 +7205,7 @@ class gn {
|
|
|
7188
7205
|
* Resolve binding key expression for a cube
|
|
7189
7206
|
*/
|
|
7190
7207
|
resolveBindingKey(e, t, n, s) {
|
|
7191
|
-
if (
|
|
7208
|
+
if (He(e)) {
|
|
7192
7209
|
const c = e.find((f) => f.cube === t.name);
|
|
7193
7210
|
if (!c)
|
|
7194
7211
|
throw new Error(`No binding key mapping found for cube: ${t.name}`);
|
|
@@ -7198,7 +7215,7 @@ class gn {
|
|
|
7198
7215
|
const p = m.dimensions?.[l];
|
|
7199
7216
|
if (!p)
|
|
7200
7217
|
throw new Error(`Binding key dimension not found: ${c.dimension}`);
|
|
7201
|
-
return
|
|
7218
|
+
return R(p.sql, s);
|
|
7202
7219
|
}
|
|
7203
7220
|
const [i, r] = e.split("."), a = n.get(i);
|
|
7204
7221
|
if (!a)
|
|
@@ -7206,7 +7223,7 @@ class gn {
|
|
|
7206
7223
|
const u = a.dimensions?.[r];
|
|
7207
7224
|
if (!u)
|
|
7208
7225
|
throw new Error(`Binding key dimension not found: ${e}`);
|
|
7209
|
-
return
|
|
7226
|
+
return R(u.sql, s);
|
|
7210
7227
|
}
|
|
7211
7228
|
/**
|
|
7212
7229
|
* Build filter conditions from config filters
|
|
@@ -7236,7 +7253,7 @@ class gn {
|
|
|
7236
7253
|
if (!u) return null;
|
|
7237
7254
|
const c = u.dimensions?.[a];
|
|
7238
7255
|
if (!c) return null;
|
|
7239
|
-
const l =
|
|
7256
|
+
const l = R(c.sql, s);
|
|
7240
7257
|
return this.filterBuilder.buildFilterCondition(
|
|
7241
7258
|
l,
|
|
7242
7259
|
i.operator,
|
|
@@ -7420,11 +7437,11 @@ class gn {
|
|
|
7420
7437
|
return t.length > 1 ? t[1] : t[0];
|
|
7421
7438
|
}
|
|
7422
7439
|
}
|
|
7423
|
-
class
|
|
7440
|
+
class Y {
|
|
7424
7441
|
constructor(e, t) {
|
|
7425
7442
|
if (this.dbExecutor = e, this.databaseAdapter = e.databaseAdapter, !this.databaseAdapter)
|
|
7426
7443
|
throw new Error("DatabaseExecutor must have a databaseAdapter property");
|
|
7427
|
-
this.queryBuilder = new
|
|
7444
|
+
this.queryBuilder = new ln(this.databaseAdapter), this.queryPlanner = new ct(), this.cteBuilder = new cn(this.queryBuilder), this.comparisonQueryBuilder = new bn(this.databaseAdapter), this.funnelQueryBuilder = new yn(this.databaseAdapter), this.flowQueryBuilder = new Cn(this.databaseAdapter), this.retentionQueryBuilder = new wn(this.databaseAdapter), this.cacheConfig = t;
|
|
7428
7445
|
}
|
|
7429
7446
|
queryBuilder;
|
|
7430
7447
|
queryPlanner;
|
|
@@ -7454,13 +7471,13 @@ class J {
|
|
|
7454
7471
|
if (!b.isValid)
|
|
7455
7472
|
throw new Error(`Retention validation failed: ${b.errors.join(", ")}`);
|
|
7456
7473
|
} else {
|
|
7457
|
-
const b =
|
|
7474
|
+
const b = ft(e, t);
|
|
7458
7475
|
if (!b.isValid)
|
|
7459
7476
|
throw new Error(`Query validation failed: ${b.errors.join(", ")}`);
|
|
7460
7477
|
}
|
|
7461
7478
|
let i;
|
|
7462
7479
|
if (this.cacheConfig?.enabled !== !1 && this.cacheConfig?.provider)
|
|
7463
|
-
if (i =
|
|
7480
|
+
if (i = Zt(t, n, this.cacheConfig), s?.skipCache)
|
|
7464
7481
|
this.cacheConfig.onCacheEvent?.({
|
|
7465
7482
|
type: "miss",
|
|
7466
7483
|
key: i,
|
|
@@ -7468,19 +7485,19 @@ class J {
|
|
|
7468
7485
|
});
|
|
7469
7486
|
else
|
|
7470
7487
|
try {
|
|
7471
|
-
const b = Date.now(),
|
|
7472
|
-
if (
|
|
7488
|
+
const b = Date.now(), $ = await this.cacheConfig.provider.get(i);
|
|
7489
|
+
if ($)
|
|
7473
7490
|
return this.cacheConfig.onCacheEvent?.({
|
|
7474
7491
|
type: "hit",
|
|
7475
7492
|
key: i,
|
|
7476
7493
|
durationMs: Date.now() - b
|
|
7477
7494
|
}), {
|
|
7478
|
-
|
|
7479
|
-
cache:
|
|
7495
|
+
...$.value,
|
|
7496
|
+
cache: $.metadata ? {
|
|
7480
7497
|
hit: !0,
|
|
7481
|
-
cachedAt: new Date(
|
|
7482
|
-
ttlMs:
|
|
7483
|
-
ttlRemainingMs:
|
|
7498
|
+
cachedAt: new Date($.metadata.cachedAt).toISOString(),
|
|
7499
|
+
ttlMs: $.metadata.ttlMs,
|
|
7500
|
+
ttlRemainingMs: $.metadata.ttlRemainingMs
|
|
7484
7501
|
} : {
|
|
7485
7502
|
hit: !0,
|
|
7486
7503
|
cachedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -7504,7 +7521,7 @@ class J {
|
|
|
7504
7521
|
return this.executeFlowQueryWithCache(e, t, n, i);
|
|
7505
7522
|
if (this.retentionQueryBuilder.hasRetention(t))
|
|
7506
7523
|
return this.executeRetentionQueryWithCache(e, t, n, i);
|
|
7507
|
-
const r = new
|
|
7524
|
+
const r = new ze(), a = {
|
|
7508
7525
|
db: this.dbExecutor.db,
|
|
7509
7526
|
schema: this.dbExecutor.schema,
|
|
7510
7527
|
securityContext: n,
|
|
@@ -7514,20 +7531,20 @@ class J {
|
|
|
7514
7531
|
const u = this.queryPlanner.createQueryPlan(e, t, a);
|
|
7515
7532
|
this.validateSecurityContext(u, a);
|
|
7516
7533
|
const c = this.buildUnifiedQuery(u, t, a), l = this.queryBuilder.collectNumericFields(e, t), m = await this.dbExecutor.execute(c, l), p = Array.isArray(m) ? m.map((b) => {
|
|
7517
|
-
const
|
|
7534
|
+
const $ = { ...b };
|
|
7518
7535
|
if (t.timeDimensions) {
|
|
7519
|
-
for (const
|
|
7520
|
-
if (
|
|
7521
|
-
let
|
|
7522
|
-
if (typeof
|
|
7523
|
-
const C =
|
|
7524
|
-
|
|
7536
|
+
for (const D of t.timeDimensions)
|
|
7537
|
+
if (D.dimension in $) {
|
|
7538
|
+
let w = $[D.dimension];
|
|
7539
|
+
if (typeof w == "string" && w.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
|
|
7540
|
+
const C = w.replace(" ", "T"), T = !C.endsWith("Z") && !C.includes("+") ? C + "Z" : C;
|
|
7541
|
+
w = new Date(T);
|
|
7525
7542
|
}
|
|
7526
|
-
|
|
7543
|
+
w = this.databaseAdapter.convertTimeDimensionResult(w), $[D.dimension] = w;
|
|
7527
7544
|
}
|
|
7528
7545
|
}
|
|
7529
|
-
return
|
|
7530
|
-
}) : [m], f = t.measures || [], h =
|
|
7546
|
+
return $;
|
|
7547
|
+
}) : [m], f = t.measures || [], h = Ge(p, t, f), g = this.generateAnnotations(u, t), y = {
|
|
7531
7548
|
data: h,
|
|
7532
7549
|
annotation: g,
|
|
7533
7550
|
// Include warnings from query planning (e.g., fan-out without dimensions)
|
|
@@ -7791,7 +7808,7 @@ class J {
|
|
|
7791
7808
|
* This is the core execution logic extracted for use by comparison queries
|
|
7792
7809
|
*/
|
|
7793
7810
|
async executeStandardQuery(e, t, n) {
|
|
7794
|
-
const s = new
|
|
7811
|
+
const s = new ze(), i = {
|
|
7795
7812
|
db: this.dbExecutor.db,
|
|
7796
7813
|
schema: this.dbExecutor.schema,
|
|
7797
7814
|
securityContext: n,
|
|
@@ -7805,14 +7822,14 @@ class J {
|
|
|
7805
7822
|
if (y.dimension in g) {
|
|
7806
7823
|
let b = g[y.dimension];
|
|
7807
7824
|
if (typeof b == "string" && b.match(/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/)) {
|
|
7808
|
-
const
|
|
7809
|
-
b = new Date(
|
|
7825
|
+
const $ = b.replace(" ", "T"), D = !$.endsWith("Z") && !$.includes("+") ? $ + "Z" : $;
|
|
7826
|
+
b = new Date(D);
|
|
7810
7827
|
}
|
|
7811
7828
|
b = this.databaseAdapter.convertTimeDimensionResult(b), g[y.dimension] = b;
|
|
7812
7829
|
}
|
|
7813
7830
|
}
|
|
7814
7831
|
return g;
|
|
7815
|
-
}) : [c], m = t.measures || [], p =
|
|
7832
|
+
}) : [c], m = t.measures || [], p = Ge(l, t, m), f = this.generateAnnotations(r, t);
|
|
7816
7833
|
return {
|
|
7817
7834
|
data: p,
|
|
7818
7835
|
annotation: f
|
|
@@ -7853,19 +7870,19 @@ class J {
|
|
|
7853
7870
|
buildUnifiedQuery(e, t, n) {
|
|
7854
7871
|
const s = /* @__PURE__ */ new Map();
|
|
7855
7872
|
if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0) {
|
|
7856
|
-
for (const
|
|
7857
|
-
if (
|
|
7858
|
-
for (const C of
|
|
7873
|
+
for (const w of e.preAggregationCTEs)
|
|
7874
|
+
if (w.propagatingFilters && w.propagatingFilters.length > 0)
|
|
7875
|
+
for (const C of w.propagatingFilters) {
|
|
7859
7876
|
const T = C.sourceCube.name;
|
|
7860
7877
|
if (!s.has(T)) {
|
|
7861
7878
|
const N = {
|
|
7862
7879
|
filters: C.filters
|
|
7863
|
-
}, S = /* @__PURE__ */ new Map([[T, C.sourceCube]]),
|
|
7880
|
+
}, S = /* @__PURE__ */ new Map([[T, C.sourceCube]]), _ = this.queryBuilder.buildWhereConditions(
|
|
7864
7881
|
S,
|
|
7865
7882
|
N,
|
|
7866
7883
|
n
|
|
7867
7884
|
);
|
|
7868
|
-
s.set(T,
|
|
7885
|
+
s.set(T, _);
|
|
7869
7886
|
}
|
|
7870
7887
|
const E = s.get(T);
|
|
7871
7888
|
E && E.length > 0 && (C.preBuiltFilterSQL = E.length === 1 ? E[0] : A(...E));
|
|
@@ -7873,12 +7890,12 @@ class J {
|
|
|
7873
7890
|
}
|
|
7874
7891
|
const i = [], r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
|
|
7875
7892
|
if (e.preAggregationCTEs && e.preAggregationCTEs.length > 0)
|
|
7876
|
-
for (const
|
|
7877
|
-
const C = this.cteBuilder.buildPreAggregationCTE(
|
|
7878
|
-
if (C && (i.push(C), r.set(
|
|
7879
|
-
for (const T of
|
|
7893
|
+
for (const w of e.preAggregationCTEs) {
|
|
7894
|
+
const C = this.cteBuilder.buildPreAggregationCTE(w, t, n, e, s);
|
|
7895
|
+
if (C && (i.push(C), r.set(w.cube.name, w.cteAlias), w.downstreamJoinKeys))
|
|
7896
|
+
for (const T of w.downstreamJoinKeys)
|
|
7880
7897
|
a.set(T.targetCubeName, {
|
|
7881
|
-
cteAlias:
|
|
7898
|
+
cteAlias: w.cteAlias,
|
|
7882
7899
|
joinKeys: T.joinKeys
|
|
7883
7900
|
});
|
|
7884
7901
|
}
|
|
@@ -7889,97 +7906,97 @@ class J {
|
|
|
7889
7906
|
n
|
|
7890
7907
|
) };
|
|
7891
7908
|
if (e.preAggregationCTEs)
|
|
7892
|
-
for (const
|
|
7893
|
-
const C =
|
|
7894
|
-
for (const T of
|
|
7909
|
+
for (const w of e.preAggregationCTEs) {
|
|
7910
|
+
const C = w.cube.name;
|
|
7911
|
+
for (const T of w.measures)
|
|
7895
7912
|
if (m[T]) {
|
|
7896
7913
|
const [, E] = T.split("."), N = c.get(C);
|
|
7897
7914
|
if (N && N.measures && N.measures[E]) {
|
|
7898
|
-
const S = N.measures[E],
|
|
7899
|
-
let
|
|
7915
|
+
const S = N.measures[E], _ = o`${o.identifier(w.cteAlias)}.${o.identifier(E)}`;
|
|
7916
|
+
let v;
|
|
7900
7917
|
if (S.type === "calculated" && S.calculatedSql)
|
|
7901
|
-
|
|
7918
|
+
v = this.queryBuilder.buildCTECalculatedMeasure(
|
|
7902
7919
|
S,
|
|
7903
7920
|
N,
|
|
7904
|
-
|
|
7921
|
+
w,
|
|
7905
7922
|
c,
|
|
7906
7923
|
n
|
|
7907
7924
|
);
|
|
7908
7925
|
else {
|
|
7909
|
-
const
|
|
7910
|
-
|
|
7926
|
+
const F = w.cteReason === "fanOutPrevention", U = this.shouldUseMaxForHasManyAtJoinKeyGrain(
|
|
7927
|
+
w,
|
|
7911
7928
|
t,
|
|
7912
7929
|
c
|
|
7913
|
-
),
|
|
7930
|
+
), j = F || U;
|
|
7914
7931
|
switch (S.type) {
|
|
7915
7932
|
case "count":
|
|
7916
7933
|
case "countDistinct":
|
|
7917
7934
|
case "sum":
|
|
7918
|
-
|
|
7935
|
+
v = j ? G(_) : z(_);
|
|
7919
7936
|
break;
|
|
7920
7937
|
case "avg":
|
|
7921
|
-
|
|
7938
|
+
v = j ? G(_) : this.databaseAdapter.buildAvg(_);
|
|
7922
7939
|
break;
|
|
7923
7940
|
case "min":
|
|
7924
|
-
|
|
7941
|
+
v = oe(_);
|
|
7925
7942
|
break;
|
|
7926
7943
|
case "max":
|
|
7927
|
-
|
|
7944
|
+
v = G(_);
|
|
7928
7945
|
break;
|
|
7929
7946
|
case "number":
|
|
7930
|
-
|
|
7947
|
+
v = j ? G(_) : z(_);
|
|
7931
7948
|
break;
|
|
7932
7949
|
default:
|
|
7933
|
-
|
|
7950
|
+
v = j ? G(_) : z(_);
|
|
7934
7951
|
}
|
|
7935
7952
|
}
|
|
7936
|
-
m[T] = o`${
|
|
7953
|
+
m[T] = o`${v}`.as(T);
|
|
7937
7954
|
}
|
|
7938
7955
|
}
|
|
7939
7956
|
for (const T in m) {
|
|
7940
7957
|
const [E, N] = T.split(".");
|
|
7941
7958
|
if (E === C) {
|
|
7942
|
-
const S = c.get(C),
|
|
7943
|
-
if (
|
|
7944
|
-
let
|
|
7945
|
-
if (!
|
|
7946
|
-
const
|
|
7947
|
-
|
|
7959
|
+
const S = c.get(C), _ = S && S.dimensions?.[N], v = T.startsWith(C + ".");
|
|
7960
|
+
if (_ || v) {
|
|
7961
|
+
let F = w.joinKeys.find((U) => U.targetColumn === N);
|
|
7962
|
+
if (!F && S?.dimensions?.[N]) {
|
|
7963
|
+
const U = S.dimensions[N].sql;
|
|
7964
|
+
F = w.joinKeys.find((j) => j.targetColumnObj === U);
|
|
7948
7965
|
}
|
|
7949
|
-
|
|
7966
|
+
F ? m[T] = o`${o.identifier(w.cteAlias)}.${o.identifier(N)}`.as(T) : v && S?.dimensions?.[N] && (m[T] = o`${o.identifier(w.cteAlias)}.${o.identifier(N)}`.as(T));
|
|
7950
7967
|
}
|
|
7951
7968
|
}
|
|
7952
7969
|
}
|
|
7953
7970
|
}
|
|
7954
7971
|
if (t.measures)
|
|
7955
|
-
for (const
|
|
7956
|
-
const [C, T] =
|
|
7972
|
+
for (const w of t.measures) {
|
|
7973
|
+
const [C, T] = w.split("."), E = c.get(C);
|
|
7957
7974
|
if (E?.measures?.[T]) {
|
|
7958
7975
|
const N = E.measures[T];
|
|
7959
7976
|
if (I.isPostAggregationWindow(N)) {
|
|
7960
7977
|
const S = I.getWindowBaseMeasure(N, C);
|
|
7961
7978
|
if (S) {
|
|
7962
|
-
const [
|
|
7963
|
-
if (
|
|
7964
|
-
const
|
|
7965
|
-
(
|
|
7979
|
+
const [_, v] = S.split("."), F = c.get(_);
|
|
7980
|
+
if (F?.measures?.[v]) {
|
|
7981
|
+
const U = F.measures[v], j = e.preAggregationCTEs?.find(
|
|
7982
|
+
(q) => q.cube?.name === _ && q.measures?.includes(S)
|
|
7966
7983
|
);
|
|
7967
|
-
let
|
|
7968
|
-
if (
|
|
7969
|
-
const
|
|
7970
|
-
|
|
7984
|
+
let B;
|
|
7985
|
+
if (j) {
|
|
7986
|
+
const q = o`${o.identifier(j.cteAlias)}.${o.identifier(v)}`;
|
|
7987
|
+
B = o`sum(${q})`;
|
|
7971
7988
|
} else
|
|
7972
|
-
|
|
7973
|
-
m[S] || (m[S] = o`${
|
|
7974
|
-
const
|
|
7989
|
+
B = this.queryBuilder.buildMeasureExpression(U, n, F);
|
|
7990
|
+
m[S] || (m[S] = o`${B}`.as(S));
|
|
7991
|
+
const V = this.buildPostAggregationWindowExpression(
|
|
7975
7992
|
N,
|
|
7976
|
-
|
|
7993
|
+
B,
|
|
7977
7994
|
t,
|
|
7978
7995
|
n,
|
|
7979
7996
|
E,
|
|
7980
7997
|
e
|
|
7981
7998
|
);
|
|
7982
|
-
|
|
7999
|
+
V && (m[w] = o`${V}`.as(w));
|
|
7983
8000
|
}
|
|
7984
8001
|
}
|
|
7985
8002
|
}
|
|
@@ -7988,99 +8005,117 @@ class J {
|
|
|
7988
8005
|
const p = [];
|
|
7989
8006
|
let f = n.db.select(m).from(u.from);
|
|
7990
8007
|
if (i.length > 0 && (f = n.db.with(...i).select(m).from(u.from)), u.joins)
|
|
7991
|
-
for (const
|
|
7992
|
-
switch (
|
|
8008
|
+
for (const w of u.joins)
|
|
8009
|
+
switch (w.type || "left") {
|
|
7993
8010
|
case "left":
|
|
7994
|
-
f = f.leftJoin(
|
|
8011
|
+
f = f.leftJoin(w.table, w.on);
|
|
7995
8012
|
break;
|
|
7996
8013
|
case "inner":
|
|
7997
|
-
f = f.innerJoin(
|
|
8014
|
+
f = f.innerJoin(w.table, w.on);
|
|
7998
8015
|
break;
|
|
7999
8016
|
case "right":
|
|
8000
|
-
f = f.rightJoin(
|
|
8017
|
+
f = f.rightJoin(w.table, w.on);
|
|
8001
8018
|
break;
|
|
8002
8019
|
case "full":
|
|
8003
|
-
f = f.fullJoin(
|
|
8020
|
+
f = f.fullJoin(w.table, w.on);
|
|
8004
8021
|
break;
|
|
8005
8022
|
}
|
|
8006
8023
|
const h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Set();
|
|
8007
8024
|
if (e.preAggregationCTEs) {
|
|
8008
|
-
for (const
|
|
8009
|
-
if (
|
|
8010
|
-
for (const C of
|
|
8025
|
+
for (const w of e.preAggregationCTEs)
|
|
8026
|
+
if (w.intermediateJoins && w.intermediateJoins.length > 0)
|
|
8027
|
+
for (const C of w.intermediateJoins)
|
|
8011
8028
|
g.add(C.cube.name);
|
|
8012
8029
|
}
|
|
8013
8030
|
if (e.joinCubes && e.joinCubes.length > 0)
|
|
8014
|
-
for (const
|
|
8015
|
-
const C =
|
|
8031
|
+
for (const w of e.joinCubes) {
|
|
8032
|
+
const C = w.cube.name;
|
|
8016
8033
|
if (g.has(C) && !r.has(C))
|
|
8017
8034
|
continue;
|
|
8018
|
-
const T = r.get(
|
|
8019
|
-
if (
|
|
8020
|
-
const
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8035
|
+
const T = r.get(w.cube.name);
|
|
8036
|
+
if (w.junctionTable) {
|
|
8037
|
+
const F = w.junctionTable;
|
|
8038
|
+
let U = F.joinCondition;
|
|
8039
|
+
const j = F.sourceCubeName ? r.get(F.sourceCubeName) : void 0;
|
|
8040
|
+
if (j) {
|
|
8041
|
+
const q = e.preAggregationCTEs?.find(
|
|
8042
|
+
(H) => H.cube.name === F.sourceCubeName
|
|
8043
|
+
)?.downstreamJoinKeys?.find(
|
|
8044
|
+
(H) => H.targetCubeName === w.cube.name
|
|
8045
|
+
);
|
|
8046
|
+
if (q && q.joinKeys.length > 0) {
|
|
8047
|
+
const H = [];
|
|
8048
|
+
for (const Oe of q.joinKeys) {
|
|
8049
|
+
const yt = o`${o.identifier(j)}.${o.identifier(Oe.sourceColumn)}`, Ie = Oe.targetColumnObj;
|
|
8050
|
+
Ie && H.push(Q(Ie, yt));
|
|
8051
|
+
}
|
|
8052
|
+
H.length > 0 && (U = A(...H));
|
|
8053
|
+
}
|
|
8054
|
+
}
|
|
8055
|
+
const B = [];
|
|
8056
|
+
if (F.securitySql) {
|
|
8057
|
+
const V = F.securitySql(n.securityContext);
|
|
8058
|
+
Array.isArray(V) ? B.push(...V) : B.push(V);
|
|
8024
8059
|
}
|
|
8025
8060
|
try {
|
|
8026
|
-
switch (
|
|
8061
|
+
switch (F.joinType || "left") {
|
|
8027
8062
|
case "left":
|
|
8028
|
-
f = f.leftJoin(
|
|
8063
|
+
f = f.leftJoin(F.table, U);
|
|
8029
8064
|
break;
|
|
8030
8065
|
case "inner":
|
|
8031
|
-
f = f.innerJoin(
|
|
8066
|
+
f = f.innerJoin(F.table, U);
|
|
8032
8067
|
break;
|
|
8033
8068
|
case "right":
|
|
8034
|
-
f = f.rightJoin(
|
|
8069
|
+
f = f.rightJoin(F.table, U);
|
|
8035
8070
|
break;
|
|
8036
8071
|
case "full":
|
|
8037
|
-
f = f.fullJoin(
|
|
8072
|
+
f = f.fullJoin(F.table, U);
|
|
8038
8073
|
break;
|
|
8039
8074
|
}
|
|
8040
|
-
|
|
8075
|
+
B.length > 0 && p.push(...B);
|
|
8041
8076
|
} catch {
|
|
8042
8077
|
}
|
|
8043
8078
|
}
|
|
8044
8079
|
let E, N, S;
|
|
8045
8080
|
if (T)
|
|
8046
|
-
E = o`${o.identifier(T)}`, N = this.cteBuilder.buildCTEJoinCondition(
|
|
8081
|
+
E = o`${o.identifier(T)}`, N = this.cteBuilder.buildCTEJoinCondition(w, T, e), S = void 0;
|
|
8047
8082
|
else {
|
|
8048
|
-
const
|
|
8049
|
-
if (E =
|
|
8050
|
-
const
|
|
8051
|
-
for (const
|
|
8052
|
-
const
|
|
8053
|
-
|
|
8083
|
+
const F = a.get(w.cube.name), U = w.cube.sql(n);
|
|
8084
|
+
if (E = U.from, S = U.where, F && !w.junctionTable) {
|
|
8085
|
+
const j = [];
|
|
8086
|
+
for (const B of F.joinKeys) {
|
|
8087
|
+
const V = o`${o.identifier(F.cteAlias)}.${o.identifier(B.sourceColumn)}`, q = B.targetColumnObj || o.identifier(B.targetColumn);
|
|
8088
|
+
j.push(Q(V, q));
|
|
8054
8089
|
}
|
|
8055
|
-
N =
|
|
8090
|
+
N = j.length === 1 ? j[0] : A(...j);
|
|
8056
8091
|
} else
|
|
8057
|
-
N =
|
|
8092
|
+
N = w.joinCondition;
|
|
8058
8093
|
}
|
|
8059
|
-
const
|
|
8094
|
+
const _ = w.joinType || "left", v = _ !== "inner" && S ? A(N, S) : N;
|
|
8060
8095
|
try {
|
|
8061
|
-
switch (
|
|
8096
|
+
switch (_) {
|
|
8062
8097
|
case "left":
|
|
8063
|
-
f = f.leftJoin(E,
|
|
8098
|
+
f = f.leftJoin(E, v), S && h.add(w.cube.name);
|
|
8064
8099
|
break;
|
|
8065
8100
|
case "inner":
|
|
8066
8101
|
f = f.innerJoin(E, N);
|
|
8067
8102
|
break;
|
|
8068
8103
|
case "right":
|
|
8069
|
-
f = f.rightJoin(E,
|
|
8104
|
+
f = f.rightJoin(E, v), S && h.add(w.cube.name);
|
|
8070
8105
|
break;
|
|
8071
8106
|
case "full":
|
|
8072
|
-
f = f.fullJoin(E,
|
|
8107
|
+
f = f.fullJoin(E, v), S && h.add(w.cube.name);
|
|
8073
8108
|
break;
|
|
8074
8109
|
}
|
|
8075
8110
|
} catch {
|
|
8076
8111
|
}
|
|
8077
8112
|
}
|
|
8078
8113
|
if (u.where && p.push(u.where), e.joinCubes && e.joinCubes.length > 0)
|
|
8079
|
-
for (const
|
|
8080
|
-
const C =
|
|
8114
|
+
for (const w of e.joinCubes) {
|
|
8115
|
+
const C = w.cube.name;
|
|
8081
8116
|
if (r.get(C) || g.has(C) || h.has(C))
|
|
8082
8117
|
continue;
|
|
8083
|
-
const E =
|
|
8118
|
+
const E = w.cube.sql(n);
|
|
8084
8119
|
E.where && p.push(E.where);
|
|
8085
8120
|
}
|
|
8086
8121
|
const y = this.queryBuilder.buildWhereConditions(
|
|
@@ -8094,8 +8129,8 @@ class J {
|
|
|
8094
8129
|
// Reuse pre-built filters for parameter deduplication
|
|
8095
8130
|
);
|
|
8096
8131
|
if (y.length > 0 && p.push(...y), p.length > 0) {
|
|
8097
|
-
const
|
|
8098
|
-
f = f.where(
|
|
8132
|
+
const w = p.length === 1 ? p[0] : A(...p);
|
|
8133
|
+
f = f.where(w);
|
|
8099
8134
|
}
|
|
8100
8135
|
const b = this.queryBuilder.buildGroupByFields(
|
|
8101
8136
|
e.joinCubes.length > 0 ? this.getCubesFromPlan(e) : e.primaryCube,
|
|
@@ -8106,7 +8141,7 @@ class J {
|
|
|
8106
8141
|
// Pass the queryPlan to handle CTE scenarios
|
|
8107
8142
|
);
|
|
8108
8143
|
b.length > 0 && (f = f.groupBy(...b));
|
|
8109
|
-
const
|
|
8144
|
+
const $ = this.queryBuilder.buildHavingConditions(
|
|
8110
8145
|
e.joinCubes.length > 0 ? this.getCubesFromPlan(e) : e.primaryCube,
|
|
8111
8146
|
// Single cube
|
|
8112
8147
|
t,
|
|
@@ -8114,12 +8149,12 @@ class J {
|
|
|
8114
8149
|
e
|
|
8115
8150
|
// Pass the queryPlan to handle CTE scenarios
|
|
8116
8151
|
);
|
|
8117
|
-
if (
|
|
8118
|
-
const
|
|
8119
|
-
f = f.having(
|
|
8152
|
+
if ($.length > 0) {
|
|
8153
|
+
const w = $.length === 1 ? $[0] : A(...$);
|
|
8154
|
+
f = f.having(w);
|
|
8120
8155
|
}
|
|
8121
|
-
const
|
|
8122
|
-
return
|
|
8156
|
+
const D = this.queryBuilder.buildOrderBy(t);
|
|
8157
|
+
return D.length > 0 && (f = f.orderBy(...D)), f = this.queryBuilder.applyLimitAndOffset(f, t), f;
|
|
8123
8158
|
}
|
|
8124
8159
|
/**
|
|
8125
8160
|
* Convert query plan to cube map for QueryBuilder methods
|
|
@@ -8317,16 +8352,16 @@ class J {
|
|
|
8317
8352
|
*/
|
|
8318
8353
|
preloadFilterCache(e, t, n, s) {
|
|
8319
8354
|
if (e.filters && e.filters.length > 0) {
|
|
8320
|
-
const i =
|
|
8355
|
+
const i = Re(e.filters);
|
|
8321
8356
|
for (const r of i) {
|
|
8322
|
-
const a =
|
|
8357
|
+
const a = me(r);
|
|
8323
8358
|
if (t.has(a)) continue;
|
|
8324
8359
|
const [u, c] = r.member.split("."), l = n.get(u);
|
|
8325
8360
|
if (!l) continue;
|
|
8326
8361
|
const m = l.dimensions?.[c];
|
|
8327
8362
|
if (!m || ["arrayContains", "arrayOverlaps", "arrayContained"].includes(r.operator))
|
|
8328
8363
|
continue;
|
|
8329
|
-
const f =
|
|
8364
|
+
const f = R(m.sql, s), h = this.queryBuilder.buildFilterConditionPublic(
|
|
8330
8365
|
f,
|
|
8331
8366
|
r.operator,
|
|
8332
8367
|
r.values,
|
|
@@ -8339,13 +8374,13 @@ class J {
|
|
|
8339
8374
|
if (e.timeDimensions) {
|
|
8340
8375
|
for (const i of e.timeDimensions)
|
|
8341
8376
|
if (i.dateRange) {
|
|
8342
|
-
const r =
|
|
8377
|
+
const r = lt(i.dimension, i.dateRange);
|
|
8343
8378
|
if (t.has(r)) continue;
|
|
8344
8379
|
const [a, u] = i.dimension.split("."), c = n.get(a);
|
|
8345
8380
|
if (!c) continue;
|
|
8346
8381
|
const l = c.dimensions?.[u];
|
|
8347
8382
|
if (!l) continue;
|
|
8348
|
-
const m =
|
|
8383
|
+
const m = R(l.sql, s), p = this.queryBuilder.buildDateRangeCondition(m, i.dateRange);
|
|
8349
8384
|
p && t.set(r, p);
|
|
8350
8385
|
}
|
|
8351
8386
|
}
|
|
@@ -8377,15 +8412,15 @@ class J {
|
|
|
8377
8412
|
const h = f.field.includes(".") ? f.field.split(".")[1] : f.field;
|
|
8378
8413
|
if (n.timeDimensions)
|
|
8379
8414
|
for (const b of n.timeDimensions) {
|
|
8380
|
-
const [
|
|
8381
|
-
if (
|
|
8382
|
-
const
|
|
8383
|
-
if (
|
|
8415
|
+
const [$, D] = b.dimension.split(".");
|
|
8416
|
+
if (D === h) {
|
|
8417
|
+
const w = u($, h);
|
|
8418
|
+
if (w)
|
|
8384
8419
|
return {
|
|
8385
|
-
field:
|
|
8420
|
+
field: w,
|
|
8386
8421
|
direction: f.direction
|
|
8387
8422
|
};
|
|
8388
|
-
const C = i.dimensions?.[
|
|
8423
|
+
const C = i.dimensions?.[D];
|
|
8389
8424
|
if (C)
|
|
8390
8425
|
return {
|
|
8391
8426
|
field: this.queryBuilder.buildTimeDimensionExpression(
|
|
@@ -8400,7 +8435,7 @@ class J {
|
|
|
8400
8435
|
const g = i.dimensions?.[h];
|
|
8401
8436
|
if (g)
|
|
8402
8437
|
return {
|
|
8403
|
-
field:
|
|
8438
|
+
field: R(g.sql, s),
|
|
8404
8439
|
direction: f.direction
|
|
8405
8440
|
};
|
|
8406
8441
|
const y = a.measure?.includes(".") ? a.measure.split(".")[1] : a.measure;
|
|
@@ -8419,10 +8454,10 @@ class J {
|
|
|
8419
8454
|
else {
|
|
8420
8455
|
const b = i.name === h ? i : void 0;
|
|
8421
8456
|
if (b?.dimensions?.[g]) {
|
|
8422
|
-
const
|
|
8457
|
+
const $ = b.dimensions[g];
|
|
8423
8458
|
c = [{
|
|
8424
8459
|
field: this.queryBuilder.buildTimeDimensionExpression(
|
|
8425
|
-
|
|
8460
|
+
$.sql,
|
|
8426
8461
|
f.granularity,
|
|
8427
8462
|
s
|
|
8428
8463
|
),
|
|
@@ -8434,7 +8469,7 @@ class J {
|
|
|
8434
8469
|
let l;
|
|
8435
8470
|
a.partitionBy && a.partitionBy.length > 0 && (l = a.partitionBy.map((f) => {
|
|
8436
8471
|
const h = f.includes(".") ? f.split(".")[1] : f, g = i.dimensions?.[h];
|
|
8437
|
-
return g ?
|
|
8472
|
+
return g ? R(g.sql, s) : null;
|
|
8438
8473
|
}).filter((f) => f !== null));
|
|
8439
8474
|
const m = this.databaseAdapter.buildWindowFunction(
|
|
8440
8475
|
e.type,
|
|
@@ -8462,7 +8497,7 @@ class J {
|
|
|
8462
8497
|
}
|
|
8463
8498
|
}
|
|
8464
8499
|
}
|
|
8465
|
-
const
|
|
8500
|
+
const $n = {
|
|
8466
8501
|
name: "drizzle-cube-mcp-guide",
|
|
8467
8502
|
description: "How to use drizzle-cube MCP tools to generate and run queries",
|
|
8468
8503
|
messages: [
|
|
@@ -8504,7 +8539,7 @@ const bn = {
|
|
|
8504
8539
|
}
|
|
8505
8540
|
}
|
|
8506
8541
|
]
|
|
8507
|
-
},
|
|
8542
|
+
}, Tn = {
|
|
8508
8543
|
name: "drizzle-cube-query-rules",
|
|
8509
8544
|
description: "Key generation rules aligned with Gemini single-step prompt",
|
|
8510
8545
|
messages: [
|
|
@@ -8527,7 +8562,7 @@ const bn = {
|
|
|
8527
8562
|
}
|
|
8528
8563
|
}
|
|
8529
8564
|
]
|
|
8530
|
-
},
|
|
8565
|
+
}, En = {
|
|
8531
8566
|
name: "drizzle-cube-query-building",
|
|
8532
8567
|
description: "CRITICAL: Complete guide for building valid queries of all types with examples",
|
|
8533
8568
|
messages: [
|
|
@@ -8713,7 +8748,7 @@ const bn = {
|
|
|
8713
8748
|
}
|
|
8714
8749
|
}
|
|
8715
8750
|
]
|
|
8716
|
-
},
|
|
8751
|
+
}, Sn = {
|
|
8717
8752
|
name: "drizzle-cube-date-filtering",
|
|
8718
8753
|
description: "CRITICAL: How to correctly filter by date vs group by time period - the #1 source of query mistakes",
|
|
8719
8754
|
messages: [
|
|
@@ -8806,22 +8841,22 @@ const bn = {
|
|
|
8806
8841
|
}
|
|
8807
8842
|
}
|
|
8808
8843
|
]
|
|
8809
|
-
},
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8844
|
+
}, Nn = [
|
|
8845
|
+
$n,
|
|
8846
|
+
Tn,
|
|
8847
|
+
En,
|
|
8848
|
+
Sn
|
|
8814
8849
|
];
|
|
8815
|
-
function
|
|
8816
|
-
return
|
|
8850
|
+
function Dn() {
|
|
8851
|
+
return Nn;
|
|
8817
8852
|
}
|
|
8818
|
-
class
|
|
8853
|
+
class mt {
|
|
8819
8854
|
cubes = /* @__PURE__ */ new Map();
|
|
8820
8855
|
dbExecutor;
|
|
8821
8856
|
metadataCache;
|
|
8822
8857
|
cacheConfig;
|
|
8823
8858
|
constructor(e) {
|
|
8824
|
-
e?.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e?.drizzle && (this.dbExecutor =
|
|
8859
|
+
e?.databaseExecutor ? this.dbExecutor = e.databaseExecutor : e?.drizzle && (this.dbExecutor = qe(
|
|
8825
8860
|
e.drizzle,
|
|
8826
8861
|
e.schema,
|
|
8827
8862
|
e.engineType
|
|
@@ -8843,7 +8878,7 @@ class lt {
|
|
|
8843
8878
|
* Set Drizzle instance and schema directly
|
|
8844
8879
|
*/
|
|
8845
8880
|
setDrizzle(e, t, n) {
|
|
8846
|
-
this.dbExecutor =
|
|
8881
|
+
this.dbExecutor = qe(e, t, n);
|
|
8847
8882
|
}
|
|
8848
8883
|
/**
|
|
8849
8884
|
* Check if database executor is configured
|
|
@@ -8856,7 +8891,7 @@ class lt {
|
|
|
8856
8891
|
* Validates calculated measures during registration
|
|
8857
8892
|
*/
|
|
8858
8893
|
registerCube(e) {
|
|
8859
|
-
this.validateCalculatedMeasures(e), new
|
|
8894
|
+
this.validateCalculatedMeasures(e), new X(this.cubes).populateDependencies(e), this.cubes.set(e.name, e), this.invalidateMetadataCache();
|
|
8860
8895
|
}
|
|
8861
8896
|
/**
|
|
8862
8897
|
* Validate calculated measures in a cube
|
|
@@ -8872,7 +8907,7 @@ class lt {
|
|
|
8872
8907
|
);
|
|
8873
8908
|
continue;
|
|
8874
8909
|
}
|
|
8875
|
-
const i =
|
|
8910
|
+
const i = an(s.calculatedSql);
|
|
8876
8911
|
if (!i.isValid) {
|
|
8877
8912
|
t.push(
|
|
8878
8913
|
`Invalid calculatedSql syntax in '${e.name}.${n}': ${i.errors.join(", ")}`
|
|
@@ -8881,7 +8916,7 @@ class lt {
|
|
|
8881
8916
|
}
|
|
8882
8917
|
const r = new Map(this.cubes);
|
|
8883
8918
|
r.set(e.name, e);
|
|
8884
|
-
const a = new
|
|
8919
|
+
const a = new X(r);
|
|
8885
8920
|
try {
|
|
8886
8921
|
a.validateDependencies(e);
|
|
8887
8922
|
} catch (u) {
|
|
@@ -8891,7 +8926,7 @@ class lt {
|
|
|
8891
8926
|
if (t.length === 0) {
|
|
8892
8927
|
const n = new Map(this.cubes);
|
|
8893
8928
|
n.set(e.name, e);
|
|
8894
|
-
const s = new
|
|
8929
|
+
const s = new X(n);
|
|
8895
8930
|
s.buildGraph(e);
|
|
8896
8931
|
const i = s.detectCycle();
|
|
8897
8932
|
i && t.push(
|
|
@@ -8930,7 +8965,7 @@ ${t.join(`
|
|
|
8930
8965
|
async execute(e, t, n) {
|
|
8931
8966
|
if (!this.dbExecutor)
|
|
8932
8967
|
throw new Error("Database executor not configured");
|
|
8933
|
-
return new
|
|
8968
|
+
return new Y(this.dbExecutor, this.cacheConfig).execute(this.cubes, e, t, n);
|
|
8934
8969
|
}
|
|
8935
8970
|
/**
|
|
8936
8971
|
* Execute a multi-cube query
|
|
@@ -9008,7 +9043,7 @@ ${t.join(`
|
|
|
9008
9043
|
for (let c = 0; c < n.length; c++) {
|
|
9009
9044
|
const l = n[c], m = e.dimensions[l];
|
|
9010
9045
|
let p;
|
|
9011
|
-
m.type === "time" && (p = m.granularities ||
|
|
9046
|
+
m.type === "time" && (p = m.granularities || mt.DEFAULT_TIME_GRANULARITIES), i[c] = {
|
|
9012
9047
|
name: `${e.name}.${l}`,
|
|
9013
9048
|
title: m.title || l,
|
|
9014
9049
|
shortTitle: m.title || l,
|
|
@@ -9066,9 +9101,9 @@ ${t.join(`
|
|
|
9066
9101
|
throw new Error(`Cube '${e}' not found`);
|
|
9067
9102
|
if (!this.dbExecutor)
|
|
9068
9103
|
throw new Error("Database executor not configured");
|
|
9069
|
-
const r = await new
|
|
9104
|
+
const r = await new Y(this.dbExecutor).generateSQL(s, t, n), a = this.dbExecutor.getEngineType();
|
|
9070
9105
|
return {
|
|
9071
|
-
sql:
|
|
9106
|
+
sql: te(r.sql, a),
|
|
9072
9107
|
params: r.params
|
|
9073
9108
|
};
|
|
9074
9109
|
}
|
|
@@ -9078,9 +9113,9 @@ ${t.join(`
|
|
|
9078
9113
|
async generateMultiCubeSQL(e, t) {
|
|
9079
9114
|
if (!this.dbExecutor)
|
|
9080
9115
|
throw new Error("Database executor not configured");
|
|
9081
|
-
const s = await new
|
|
9116
|
+
const s = await new Y(this.dbExecutor).generateMultiCubeSQL(this.cubes, e, t), i = this.dbExecutor.getEngineType();
|
|
9082
9117
|
return {
|
|
9083
|
-
sql:
|
|
9118
|
+
sql: te(s.sql, i),
|
|
9084
9119
|
params: s.params
|
|
9085
9120
|
};
|
|
9086
9121
|
}
|
|
@@ -9091,9 +9126,9 @@ ${t.join(`
|
|
|
9091
9126
|
async dryRunFunnel(e, t) {
|
|
9092
9127
|
if (!this.dbExecutor)
|
|
9093
9128
|
throw new Error("Database executor not configured");
|
|
9094
|
-
const s = await new
|
|
9129
|
+
const s = await new Y(this.dbExecutor).dryRunFunnel(this.cubes, e, t), i = this.dbExecutor.getEngineType();
|
|
9095
9130
|
return {
|
|
9096
|
-
sql:
|
|
9131
|
+
sql: te(s.sql, i),
|
|
9097
9132
|
params: s.params
|
|
9098
9133
|
};
|
|
9099
9134
|
}
|
|
@@ -9104,9 +9139,9 @@ ${t.join(`
|
|
|
9104
9139
|
async dryRunFlow(e, t) {
|
|
9105
9140
|
if (!this.dbExecutor)
|
|
9106
9141
|
throw new Error("Database executor not configured");
|
|
9107
|
-
const s = await new
|
|
9142
|
+
const s = await new Y(this.dbExecutor).dryRunFlow(this.cubes, e, t), i = this.dbExecutor.getEngineType();
|
|
9108
9143
|
return {
|
|
9109
|
-
sql:
|
|
9144
|
+
sql: te(s.sql, i),
|
|
9110
9145
|
params: s.params
|
|
9111
9146
|
};
|
|
9112
9147
|
}
|
|
@@ -9117,9 +9152,9 @@ ${t.join(`
|
|
|
9117
9152
|
async dryRunRetention(e, t) {
|
|
9118
9153
|
if (!this.dbExecutor)
|
|
9119
9154
|
throw new Error("Database executor not configured");
|
|
9120
|
-
const s = await new
|
|
9155
|
+
const s = await new Y(this.dbExecutor).dryRunRetention(this.cubes, e, t), i = this.dbExecutor.getEngineType();
|
|
9121
9156
|
return {
|
|
9122
|
-
sql:
|
|
9157
|
+
sql: te(s.sql, i),
|
|
9123
9158
|
params: s.params
|
|
9124
9159
|
};
|
|
9125
9160
|
}
|
|
@@ -9131,7 +9166,7 @@ ${t.join(`
|
|
|
9131
9166
|
async explainQuery(e, t, n) {
|
|
9132
9167
|
if (!this.dbExecutor)
|
|
9133
9168
|
throw new Error("Database executor not configured");
|
|
9134
|
-
return new
|
|
9169
|
+
return new Y(this.dbExecutor).explainQuery(this.cubes, e, t, n);
|
|
9135
9170
|
}
|
|
9136
9171
|
/**
|
|
9137
9172
|
* Check if a cube exists
|
|
@@ -9170,7 +9205,7 @@ ${t.join(`
|
|
|
9170
9205
|
* Ensures all referenced cubes and fields exist
|
|
9171
9206
|
*/
|
|
9172
9207
|
validateQuery(e) {
|
|
9173
|
-
return
|
|
9208
|
+
return ft(this.cubes, e);
|
|
9174
9209
|
}
|
|
9175
9210
|
/**
|
|
9176
9211
|
* Analyze query planning decisions for debugging and transparency
|
|
@@ -9180,7 +9215,7 @@ ${t.join(`
|
|
|
9180
9215
|
analyzeQuery(e, t) {
|
|
9181
9216
|
if (!this.dbExecutor)
|
|
9182
9217
|
throw new Error("Database executor not configured");
|
|
9183
|
-
const n = new
|
|
9218
|
+
const n = new ct(), s = {
|
|
9184
9219
|
db: this.dbExecutor.db,
|
|
9185
9220
|
schema: this.dbExecutor.schema,
|
|
9186
9221
|
securityContext: t
|
|
@@ -9188,7 +9223,7 @@ ${t.join(`
|
|
|
9188
9223
|
return n.analyzeQueryPlan(this.cubes, e, s);
|
|
9189
9224
|
}
|
|
9190
9225
|
}
|
|
9191
|
-
function
|
|
9226
|
+
function ft(d, e) {
|
|
9192
9227
|
const t = [];
|
|
9193
9228
|
if (e.funnel !== void 0 && e.funnel.steps?.length >= 2) {
|
|
9194
9229
|
const s = e.funnel.bindingKey;
|
|
@@ -9209,7 +9244,7 @@ function ct(d, e) {
|
|
|
9209
9244
|
return { isValid: t.length === 0, errors: t };
|
|
9210
9245
|
}
|
|
9211
9246
|
if (e.retention !== void 0 && e.retention.timeDimension != null && e.retention.bindingKey != null) {
|
|
9212
|
-
const s =
|
|
9247
|
+
const s = An(e.retention.timeDimension);
|
|
9213
9248
|
s && !d.has(s) && t.push(`Retention cube not found: ${s}`);
|
|
9214
9249
|
const i = e.retention.bindingKey;
|
|
9215
9250
|
if (typeof i == "string") {
|
|
@@ -9273,17 +9308,17 @@ function ct(d, e) {
|
|
|
9273
9308
|
}
|
|
9274
9309
|
if (e.filters)
|
|
9275
9310
|
for (const s of e.filters)
|
|
9276
|
-
|
|
9311
|
+
pt(s, d, t, n);
|
|
9277
9312
|
return n.size === 0 && t.push("Query must reference at least one cube through measures, dimensions, or filters"), {
|
|
9278
9313
|
isValid: t.length === 0,
|
|
9279
9314
|
errors: t
|
|
9280
9315
|
};
|
|
9281
9316
|
}
|
|
9282
|
-
function
|
|
9317
|
+
function pt(d, e, t, n) {
|
|
9283
9318
|
if ("and" in d || "or" in d) {
|
|
9284
9319
|
const a = d.and || d.or || [];
|
|
9285
9320
|
for (const u of a)
|
|
9286
|
-
|
|
9321
|
+
pt(u, e, t, n);
|
|
9287
9322
|
return;
|
|
9288
9323
|
}
|
|
9289
9324
|
if (!("member" in d)) {
|
|
@@ -9303,34 +9338,34 @@ function dt(d, e, t, n) {
|
|
|
9303
9338
|
}
|
|
9304
9339
|
!r.dimensions[i] && !r.measures[i] && t.push(`Filter field '${i}' not found on cube '${s}' (must be a dimension or measure)`);
|
|
9305
9340
|
}
|
|
9306
|
-
function
|
|
9341
|
+
function An(d) {
|
|
9307
9342
|
if (typeof d == "string") {
|
|
9308
9343
|
const [e] = d.split(".");
|
|
9309
9344
|
return e || null;
|
|
9310
9345
|
}
|
|
9311
9346
|
return d.cube;
|
|
9312
9347
|
}
|
|
9313
|
-
const
|
|
9314
|
-
function
|
|
9315
|
-
const t =
|
|
9348
|
+
const ue = ["2025-11-25", "2025-06-18", "2025-03-26"], ht = "2025-11-25";
|
|
9349
|
+
function In(d) {
|
|
9350
|
+
const t = _n(d["mcp-protocol-version"]) || ht;
|
|
9316
9351
|
return {
|
|
9317
|
-
ok:
|
|
9318
|
-
negotiated:
|
|
9319
|
-
supported:
|
|
9352
|
+
ok: ue.includes(t),
|
|
9353
|
+
negotiated: ue.includes(t) ? t : null,
|
|
9354
|
+
supported: ue
|
|
9320
9355
|
};
|
|
9321
9356
|
}
|
|
9322
|
-
function
|
|
9357
|
+
function Ln(d) {
|
|
9323
9358
|
if (!d) return !1;
|
|
9324
9359
|
const e = d.split(",").map((s) => s.trim().toLowerCase()), t = e.includes("text/event-stream"), n = e.includes("application/json");
|
|
9325
9360
|
return t && !n;
|
|
9326
9361
|
}
|
|
9327
|
-
const
|
|
9328
|
-
function
|
|
9362
|
+
const Mn = "mcp-session-id";
|
|
9363
|
+
function jn(d) {
|
|
9329
9364
|
if (!d) return !1;
|
|
9330
9365
|
const e = d.split(",").map((s) => s.trim().toLowerCase().split(";")[0]), t = e.some((s) => s === "application/json"), n = e.some((s) => s === "text/event-stream");
|
|
9331
9366
|
return t && n;
|
|
9332
9367
|
}
|
|
9333
|
-
function
|
|
9368
|
+
function Un(d, e = {}) {
|
|
9334
9369
|
const { allowMissingOrigin: t = !0, allowedOrigins: n } = e;
|
|
9335
9370
|
if (!d)
|
|
9336
9371
|
return t ? { valid: !0 } : { valid: !1, reason: "Origin header is required" };
|
|
@@ -9350,26 +9385,26 @@ function In(d, e = {}) {
|
|
|
9350
9385
|
}
|
|
9351
9386
|
}).includes(s.origin) ? { valid: !0 } : { valid: !1, reason: "Origin not in allowed list" };
|
|
9352
9387
|
}
|
|
9353
|
-
function
|
|
9388
|
+
function xn(d, e, t) {
|
|
9354
9389
|
const n = [];
|
|
9355
9390
|
return e && n.push(`id: ${e}`), t && t > 0 && n.push(`retry: ${t}`), n.push("event: message"), n.push(`data: ${JSON.stringify(d)}`), n.push(""), n.join(`
|
|
9356
9391
|
`);
|
|
9357
9392
|
}
|
|
9358
|
-
function
|
|
9393
|
+
function kn(d, e, t, n) {
|
|
9359
9394
|
return {
|
|
9360
9395
|
jsonrpc: "2.0",
|
|
9361
9396
|
id: d ?? null,
|
|
9362
9397
|
error: { code: e, message: t, ...n !== void 0 ? { data: n } : {} }
|
|
9363
9398
|
};
|
|
9364
9399
|
}
|
|
9365
|
-
function
|
|
9400
|
+
function Bn(d, e) {
|
|
9366
9401
|
return {
|
|
9367
9402
|
jsonrpc: "2.0",
|
|
9368
9403
|
id: d ?? null,
|
|
9369
9404
|
result: e
|
|
9370
9405
|
};
|
|
9371
9406
|
}
|
|
9372
|
-
function
|
|
9407
|
+
function Pn(d) {
|
|
9373
9408
|
if (!d || typeof d != "object") return null;
|
|
9374
9409
|
const e = d;
|
|
9375
9410
|
return e.jsonrpc !== "2.0" || typeof e.method != "string" ? null : {
|
|
@@ -9379,13 +9414,13 @@ function Un(d) {
|
|
|
9379
9414
|
params: e.params
|
|
9380
9415
|
};
|
|
9381
9416
|
}
|
|
9382
|
-
async function
|
|
9383
|
-
const { semanticLayer: n, extractSecurityContext: s, rawRequest: i, rawResponse: r } = t, a = t.prompts ??
|
|
9417
|
+
async function Qn(d, e, t) {
|
|
9418
|
+
const { semanticLayer: n, extractSecurityContext: s, rawRequest: i, rawResponse: r } = t, a = t.prompts ?? gt, u = t.resources ?? bt;
|
|
9384
9419
|
switch (d) {
|
|
9385
9420
|
case "initialize": {
|
|
9386
9421
|
const c = e?.protocolVersion;
|
|
9387
9422
|
let l;
|
|
9388
|
-
return c &&
|
|
9423
|
+
return c && ue.includes(c) ? l = c : l = ht, {
|
|
9389
9424
|
protocolVersion: l,
|
|
9390
9425
|
capabilities: {
|
|
9391
9426
|
tools: {
|
|
@@ -9399,7 +9434,7 @@ async function kn(d, e, t) {
|
|
|
9399
9434
|
},
|
|
9400
9435
|
sampling: {}
|
|
9401
9436
|
},
|
|
9402
|
-
sessionId:
|
|
9437
|
+
sessionId: vn(),
|
|
9403
9438
|
serverInfo: {
|
|
9404
9439
|
name: "drizzle-cube",
|
|
9405
9440
|
// Use safe check for process.env to support edge runtimes (Cloudflare Workers, etc.)
|
|
@@ -9409,10 +9444,10 @@ async function kn(d, e, t) {
|
|
|
9409
9444
|
}
|
|
9410
9445
|
case "list_tools":
|
|
9411
9446
|
case "tools/list":
|
|
9412
|
-
return { tools:
|
|
9447
|
+
return { tools: Rn(), nextCursor: "" };
|
|
9413
9448
|
case "call_tool":
|
|
9414
9449
|
case "tools/call":
|
|
9415
|
-
return
|
|
9450
|
+
return Fn(e, t);
|
|
9416
9451
|
case "resources/list":
|
|
9417
9452
|
return {
|
|
9418
9453
|
resources: u.map(({ uri: c, name: l, description: m, mimeType: p }) => ({
|
|
@@ -9427,7 +9462,7 @@ async function kn(d, e, t) {
|
|
|
9427
9462
|
return { resourceTemplates: [], nextCursor: "" };
|
|
9428
9463
|
case "resources/read": {
|
|
9429
9464
|
const c = e?.uri, l = u.find((m) => m.uri === c) || u[0];
|
|
9430
|
-
if (!l) throw
|
|
9465
|
+
if (!l) throw J(-32602, "resource not found");
|
|
9431
9466
|
return {
|
|
9432
9467
|
contents: [
|
|
9433
9468
|
{
|
|
@@ -9450,7 +9485,7 @@ async function kn(d, e, t) {
|
|
|
9450
9485
|
return {};
|
|
9451
9486
|
case "prompts/get": {
|
|
9452
9487
|
const c = e?.name, l = a.find((m) => m.name === c) || a[0];
|
|
9453
|
-
if (!l) throw
|
|
9488
|
+
if (!l) throw J(-32602, "prompt not found");
|
|
9454
9489
|
return {
|
|
9455
9490
|
name: l.name,
|
|
9456
9491
|
description: l.description,
|
|
@@ -9458,38 +9493,38 @@ async function kn(d, e, t) {
|
|
|
9458
9493
|
};
|
|
9459
9494
|
}
|
|
9460
9495
|
case "discover":
|
|
9461
|
-
return
|
|
9496
|
+
return tt(n, e || {});
|
|
9462
9497
|
case "validate": {
|
|
9463
9498
|
const c = e || {};
|
|
9464
9499
|
if (!c.query)
|
|
9465
|
-
throw
|
|
9466
|
-
return
|
|
9500
|
+
throw J(-32602, "query is required");
|
|
9501
|
+
return et(n, c);
|
|
9467
9502
|
}
|
|
9468
9503
|
case "load": {
|
|
9469
9504
|
const c = e || {};
|
|
9470
9505
|
if (!c.query)
|
|
9471
|
-
throw
|
|
9506
|
+
throw J(-32602, "query is required");
|
|
9472
9507
|
const l = await s(i, r);
|
|
9473
|
-
return
|
|
9508
|
+
return Ze(n, l, c);
|
|
9474
9509
|
}
|
|
9475
9510
|
default:
|
|
9476
|
-
throw
|
|
9511
|
+
throw J(-32601, `Unknown MCP method: ${d}`);
|
|
9477
9512
|
}
|
|
9478
9513
|
}
|
|
9479
|
-
function
|
|
9514
|
+
function J(d, e, t) {
|
|
9480
9515
|
const n = new Error(e);
|
|
9481
9516
|
return n.code = d, n;
|
|
9482
9517
|
}
|
|
9483
|
-
function
|
|
9518
|
+
function _n(d) {
|
|
9484
9519
|
return d ? Array.isArray(d) ? d[0] || null : d : null;
|
|
9485
9520
|
}
|
|
9486
|
-
function
|
|
9521
|
+
function Wn(d) {
|
|
9487
9522
|
return d.id === void 0 || d.id === null;
|
|
9488
9523
|
}
|
|
9489
|
-
function
|
|
9490
|
-
return `evt-${
|
|
9524
|
+
function vn() {
|
|
9525
|
+
return `evt-${Ct()}`;
|
|
9491
9526
|
}
|
|
9492
|
-
function
|
|
9527
|
+
function Rn() {
|
|
9493
9528
|
return [
|
|
9494
9529
|
{
|
|
9495
9530
|
name: "discover",
|
|
@@ -9588,30 +9623,30 @@ QUERY CONSTRUCTION RULES:
|
|
|
9588
9623
|
}
|
|
9589
9624
|
];
|
|
9590
9625
|
}
|
|
9591
|
-
async function
|
|
9626
|
+
async function Fn(d, e) {
|
|
9592
9627
|
const { semanticLayer: t, extractSecurityContext: n, rawRequest: s, rawResponse: i } = e, r = d || {};
|
|
9593
9628
|
if (!r.name)
|
|
9594
|
-
throw
|
|
9629
|
+
throw J(-32602, "name is required for tools/call");
|
|
9595
9630
|
const a = r.arguments;
|
|
9596
9631
|
switch (r.name) {
|
|
9597
9632
|
case "discover":
|
|
9598
|
-
return
|
|
9633
|
+
return Ne(await tt(t, a || {}));
|
|
9599
9634
|
case "validate": {
|
|
9600
9635
|
const u = a || {};
|
|
9601
|
-
if (!u.query) throw
|
|
9602
|
-
return
|
|
9636
|
+
if (!u.query) throw J(-32602, "query is required");
|
|
9637
|
+
return Ne(await et(t, u));
|
|
9603
9638
|
}
|
|
9604
9639
|
case "load": {
|
|
9605
9640
|
const u = a || {};
|
|
9606
|
-
if (!u.query) throw
|
|
9641
|
+
if (!u.query) throw J(-32602, "query is required");
|
|
9607
9642
|
const c = await n(s, i);
|
|
9608
|
-
return
|
|
9643
|
+
return Ne(await Ze(t, c, u));
|
|
9609
9644
|
}
|
|
9610
9645
|
default:
|
|
9611
|
-
throw
|
|
9646
|
+
throw J(-32601, `Unknown tool: ${r.name}`);
|
|
9612
9647
|
}
|
|
9613
9648
|
}
|
|
9614
|
-
function
|
|
9649
|
+
function Ne(d) {
|
|
9615
9650
|
return {
|
|
9616
9651
|
content: [
|
|
9617
9652
|
{
|
|
@@ -9622,7 +9657,7 @@ function Se(d) {
|
|
|
9622
9657
|
isError: !1
|
|
9623
9658
|
};
|
|
9624
9659
|
}
|
|
9625
|
-
const
|
|
9660
|
+
const gt = Dn(), bt = [
|
|
9626
9661
|
{
|
|
9627
9662
|
uri: "drizzle-cube://quickstart",
|
|
9628
9663
|
name: "Drizzle Cube MCP Quickstart",
|
|
@@ -9728,26 +9763,26 @@ const ft = Tn(), pt = [
|
|
|
9728
9763
|
`)
|
|
9729
9764
|
}
|
|
9730
9765
|
];
|
|
9731
|
-
function
|
|
9732
|
-
return
|
|
9766
|
+
function Kn() {
|
|
9767
|
+
return bt;
|
|
9733
9768
|
}
|
|
9734
|
-
function
|
|
9735
|
-
return
|
|
9769
|
+
function qn() {
|
|
9770
|
+
return gt;
|
|
9736
9771
|
}
|
|
9737
9772
|
export {
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9773
|
+
Mn as M,
|
|
9774
|
+
mt as S,
|
|
9775
|
+
jn as a,
|
|
9776
|
+
kn as b,
|
|
9777
|
+
Bn as c,
|
|
9778
|
+
Qn as d,
|
|
9779
|
+
vn as e,
|
|
9780
|
+
Kn as f,
|
|
9781
|
+
qn as g,
|
|
9782
|
+
Wn as i,
|
|
9783
|
+
In as n,
|
|
9784
|
+
Pn as p,
|
|
9785
|
+
xn as s,
|
|
9786
|
+
Un as v,
|
|
9787
|
+
Ln as w
|
|
9753
9788
|
};
|