drizzle-cube 0.4.28 → 0.4.29
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 +2 -2
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +2 -2
- package/dist/adapters/{handler-BV2_dul8.js → handler-BHguLZOY.js} +1 -1
- package/dist/adapters/{handler-LMRPeTNJ.cjs → handler-DOIyiFPg.cjs} +1 -1
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +2 -2
- package/dist/adapters/mcp-transport-CWGqDQSI.cjs +259 -0
- package/dist/adapters/{mcp-transport-B6ZudTSk.js → mcp-transport-CyeHMDPl.js} +115 -70
- package/dist/adapters/nextjs/index.cjs +2 -2
- package/dist/adapters/nextjs/index.js +2 -2
- package/dist/server/index.cjs +13 -11
- package/dist/server/index.d.ts +13 -4
- package/dist/server/index.js +98 -53
- package/package.json +1 -1
- package/dist/adapters/mcp-transport-DCiSGtp1.cjs +0 -257
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { formatSqlString as $t, handleLoad as tt, handleValidate as nt, handleDiscover as it, generateRequestId as Tt } from "./utils.js";
|
|
2
|
-
const
|
|
2
|
+
const U = /* @__PURE__ */ Symbol.for("drizzle:entityKind");
|
|
3
3
|
function I(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, U))
|
|
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 (U in t && t[U] === e[U])
|
|
16
16
|
return !0;
|
|
17
17
|
t = Object.getPrototypeOf(t);
|
|
18
18
|
}
|
|
@@ -22,7 +22,7 @@ class ie {
|
|
|
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 [U] = "Column";
|
|
26
26
|
name;
|
|
27
27
|
keyAsName;
|
|
28
28
|
primary;
|
|
@@ -56,7 +56,7 @@ function Et(d) {
|
|
|
56
56
|
return !!d && typeof d == "function" && Le in d && d[Le] === !0;
|
|
57
57
|
}
|
|
58
58
|
class st {
|
|
59
|
-
static [
|
|
59
|
+
static [U] = "Subquery";
|
|
60
60
|
constructor(e, t, n, i = !1, s = []) {
|
|
61
61
|
this._ = {
|
|
62
62
|
brand: "Subquery",
|
|
@@ -76,8 +76,8 @@ const St = {
|
|
|
76
76
|
return e();
|
|
77
77
|
}
|
|
78
78
|
}, ne = /* @__PURE__ */ Symbol.for("drizzle:ViewBaseConfig"), Ce = /* @__PURE__ */ Symbol.for("drizzle:Schema"), Pe = /* @__PURE__ */ Symbol.for("drizzle:Columns"), Be = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigColumns"), we = /* @__PURE__ */ Symbol.for("drizzle:OriginalName"), $e = /* @__PURE__ */ Symbol.for("drizzle:BaseName"), le = /* @__PURE__ */ Symbol.for("drizzle:IsAlias"), ke = /* @__PURE__ */ Symbol.for("drizzle:ExtraConfigBuilder"), Dt = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleTable");
|
|
79
|
-
class
|
|
80
|
-
static [
|
|
79
|
+
class K {
|
|
80
|
+
static [U] = "Table";
|
|
81
81
|
/** @internal */
|
|
82
82
|
static Symbol = {
|
|
83
83
|
Name: ye,
|
|
@@ -130,7 +130,7 @@ function Nt(d) {
|
|
|
130
130
|
return e;
|
|
131
131
|
}
|
|
132
132
|
class P {
|
|
133
|
-
static [
|
|
133
|
+
static [U] = "StringChunk";
|
|
134
134
|
value;
|
|
135
135
|
constructor(e) {
|
|
136
136
|
this.value = Array.isArray(e) ? e : [e];
|
|
@@ -143,14 +143,14 @@ class O {
|
|
|
143
143
|
constructor(e) {
|
|
144
144
|
this.queryChunks = e;
|
|
145
145
|
for (const t of e)
|
|
146
|
-
if (I(t,
|
|
147
|
-
const n = t[
|
|
146
|
+
if (I(t, K)) {
|
|
147
|
+
const n = t[K.Symbol.Schema];
|
|
148
148
|
this.usedTables.push(
|
|
149
|
-
n === void 0 ? t[
|
|
149
|
+
n === void 0 ? t[K.Symbol.Name] : n + "." + t[K.Symbol.Name]
|
|
150
150
|
);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
static [
|
|
153
|
+
static [U] = "SQL";
|
|
154
154
|
/** @internal */
|
|
155
155
|
decoder = ot;
|
|
156
156
|
shouldInlineParams = !1;
|
|
@@ -198,8 +198,8 @@ class O {
|
|
|
198
198
|
...n,
|
|
199
199
|
inlineParams: u || l.shouldInlineParams
|
|
200
200
|
});
|
|
201
|
-
if (I(l,
|
|
202
|
-
const m = l[
|
|
201
|
+
if (I(l, K)) {
|
|
202
|
+
const m = l[K.Symbol.Schema], p = l[K.Symbol.Name];
|
|
203
203
|
return {
|
|
204
204
|
sql: m === void 0 || l[le] ? s(p) : s(m) + "." + s(p),
|
|
205
205
|
params: []
|
|
@@ -209,9 +209,9 @@ class O {
|
|
|
209
209
|
const m = i.getColumnCasing(l);
|
|
210
210
|
if (t.invokeSource === "indexes")
|
|
211
211
|
return { sql: s(m), params: [] };
|
|
212
|
-
const p = l.table[
|
|
212
|
+
const p = l.table[K.Symbol.Schema];
|
|
213
213
|
return {
|
|
214
|
-
sql: l.table[le] || p === void 0 ? s(l.table[
|
|
214
|
+
sql: l.table[le] || p === void 0 ? s(l.table[K.Symbol.Name]) + "." + s(m) : s(p) + "." + s(l.table[K.Symbol.Name]) + "." + s(m),
|
|
215
215
|
params: []
|
|
216
216
|
};
|
|
217
217
|
}
|
|
@@ -284,7 +284,7 @@ class _e {
|
|
|
284
284
|
constructor(e) {
|
|
285
285
|
this.value = e;
|
|
286
286
|
}
|
|
287
|
-
static [
|
|
287
|
+
static [U] = "Name";
|
|
288
288
|
brand;
|
|
289
289
|
getSQL() {
|
|
290
290
|
return new O([this]);
|
|
@@ -310,7 +310,7 @@ class ce {
|
|
|
310
310
|
constructor(e, t = at) {
|
|
311
311
|
this.value = e, this.encoder = t;
|
|
312
312
|
}
|
|
313
|
-
static [
|
|
313
|
+
static [U] = "Param";
|
|
314
314
|
brand;
|
|
315
315
|
getSQL() {
|
|
316
316
|
return new O([this]);
|
|
@@ -361,7 +361,7 @@ function o(d, ...e) {
|
|
|
361
361
|
constructor(n, i) {
|
|
362
362
|
this.sql = n, this.fieldAlias = i;
|
|
363
363
|
}
|
|
364
|
-
static [
|
|
364
|
+
static [U] = "SQL.Aliased";
|
|
365
365
|
/** @internal */
|
|
366
366
|
isSelectionField = !1;
|
|
367
367
|
getSQL() {
|
|
@@ -378,14 +378,14 @@ class de {
|
|
|
378
378
|
constructor(e) {
|
|
379
379
|
this.name = e;
|
|
380
380
|
}
|
|
381
|
-
static [
|
|
381
|
+
static [U] = "Placeholder";
|
|
382
382
|
getSQL() {
|
|
383
383
|
return new O([this]);
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
const _t = /* @__PURE__ */ Symbol.for("drizzle:IsDrizzleView");
|
|
387
387
|
class ut {
|
|
388
|
-
static [
|
|
388
|
+
static [U] = "View";
|
|
389
389
|
/** @internal */
|
|
390
390
|
[ne];
|
|
391
391
|
/** @internal */
|
|
@@ -408,14 +408,14 @@ class ut {
|
|
|
408
408
|
ie.prototype.getSQL = function() {
|
|
409
409
|
return new O([this]);
|
|
410
410
|
};
|
|
411
|
-
|
|
411
|
+
K.prototype.getSQL = function() {
|
|
412
412
|
return new O([this]);
|
|
413
413
|
};
|
|
414
414
|
st.prototype.getSQL = function() {
|
|
415
415
|
return new O([this]);
|
|
416
416
|
};
|
|
417
417
|
function B(d, e) {
|
|
418
|
-
return At(e) && !rt(d) && !I(d, ce) && !I(d, de) && !I(d, ie) && !I(d,
|
|
418
|
+
return At(e) && !rt(d) && !I(d, ce) && !I(d, de) && !I(d, ie) && !I(d, K) && !I(d, ut) ? new ce(d, e) : d;
|
|
419
419
|
}
|
|
420
420
|
const k = (d, e) => o`${d} = ${B(e, d)}`, xe = (d, e) => o`${d} <> ${B(e, d)}`;
|
|
421
421
|
function A(...d) {
|
|
@@ -2509,7 +2509,17 @@ function qe(d, e, t) {
|
|
|
2509
2509
|
return Je(d, e);
|
|
2510
2510
|
throw new Error("Unable to determine database engine type. Please specify engineType parameter.");
|
|
2511
2511
|
}
|
|
2512
|
-
function
|
|
2512
|
+
function x(d, e) {
|
|
2513
|
+
if (typeof d == "string") {
|
|
2514
|
+
if (!e)
|
|
2515
|
+
return console.warn(
|
|
2516
|
+
`[drizzle-cube] Cannot resolve string cube reference '${d}': no cube registry provided. Join will be skipped.`
|
|
2517
|
+
), null;
|
|
2518
|
+
const t = e.get(d);
|
|
2519
|
+
return t || (console.warn(
|
|
2520
|
+
`[drizzle-cube] Cannot resolve cube reference '${d}': no cube with that name is registered. Registered cubes: ${Array.from(e.keys()).join(", ") || "(none)"}. Join will be skipped.`
|
|
2521
|
+
), null);
|
|
2522
|
+
}
|
|
2513
2523
|
return typeof d == "function" ? d() : d;
|
|
2514
2524
|
}
|
|
2515
2525
|
function De(d) {
|
|
@@ -4334,7 +4344,9 @@ class ae {
|
|
|
4334
4344
|
if (n.joins)
|
|
4335
4345
|
for (const [, i] of Object.entries(n.joins)) {
|
|
4336
4346
|
if (i.relationship === "belongsToMany") continue;
|
|
4337
|
-
const
|
|
4347
|
+
const s = x(i.targetCube, this.cubes);
|
|
4348
|
+
if (!s) continue;
|
|
4349
|
+
const r = s.name;
|
|
4338
4350
|
let a = e.get(r);
|
|
4339
4351
|
a || (a = [], e.set(r, a)), a.push({ definingCube: t, joinDef: i });
|
|
4340
4352
|
}
|
|
@@ -4362,7 +4374,9 @@ class ae {
|
|
|
4362
4374
|
const { cube: u, path: c } = r.shift(), l = this.cubes.get(u);
|
|
4363
4375
|
if (l?.joins)
|
|
4364
4376
|
for (const [, p] of Object.entries(l.joins)) {
|
|
4365
|
-
const
|
|
4377
|
+
const f = x(p.targetCube, this.cubes);
|
|
4378
|
+
if (!f) continue;
|
|
4379
|
+
const h = f.name;
|
|
4366
4380
|
if (a.has(h))
|
|
4367
4381
|
continue;
|
|
4368
4382
|
const g = [
|
|
@@ -4497,7 +4511,9 @@ class ae {
|
|
|
4497
4511
|
const l = this.cubes.get(a);
|
|
4498
4512
|
if (l?.joins)
|
|
4499
4513
|
for (const [, p] of Object.entries(l.joins)) {
|
|
4500
|
-
const
|
|
4514
|
+
const f = x(p.targetCube, this.cubes);
|
|
4515
|
+
if (!f) continue;
|
|
4516
|
+
const h = f.name;
|
|
4501
4517
|
if (c.has(h))
|
|
4502
4518
|
continue;
|
|
4503
4519
|
const g = [
|
|
@@ -4567,7 +4583,9 @@ class ae {
|
|
|
4567
4583
|
const { cube: r, path: a } = i.shift(), u = this.cubes.get(r);
|
|
4568
4584
|
if (u?.joins)
|
|
4569
4585
|
for (const [, c] of Object.entries(u.joins)) {
|
|
4570
|
-
const
|
|
4586
|
+
const l = x(c.targetCube, this.cubes);
|
|
4587
|
+
if (!l) continue;
|
|
4588
|
+
const m = l.name;
|
|
4571
4589
|
if (s.has(m)) continue;
|
|
4572
4590
|
const p = [
|
|
4573
4591
|
...a,
|
|
@@ -4608,7 +4626,9 @@ class ae {
|
|
|
4608
4626
|
const i = n.shift(), s = this.cubes.get(i);
|
|
4609
4627
|
if (s?.joins)
|
|
4610
4628
|
for (const [, a] of Object.entries(s.joins)) {
|
|
4611
|
-
const
|
|
4629
|
+
const u = x(a.targetCube, this.cubes);
|
|
4630
|
+
if (!u) continue;
|
|
4631
|
+
const c = u.name;
|
|
4612
4632
|
t.has(c) || (t.add(c), n.push(c));
|
|
4613
4633
|
}
|
|
4614
4634
|
const r = this.reverseIndex.get(i) || [];
|
|
@@ -4786,7 +4806,7 @@ class fn {
|
|
|
4786
4806
|
const l = this.collectPathHintCubes(s), m = /* @__PURE__ */ new Set();
|
|
4787
4807
|
for (const f of c) {
|
|
4788
4808
|
if (f === t.name) continue;
|
|
4789
|
-
this.findHasManyJoinDef(t, f) && m.add(f);
|
|
4809
|
+
this.findHasManyJoinDef(t, f, e) && m.add(f);
|
|
4790
4810
|
}
|
|
4791
4811
|
const p = n.filter((f) => f !== t.name);
|
|
4792
4812
|
for (const f of p) {
|
|
@@ -4956,11 +4976,12 @@ class fn {
|
|
|
4956
4976
|
*/
|
|
4957
4977
|
findJoinInfoToCube(e, t) {
|
|
4958
4978
|
for (const [, n] of e)
|
|
4959
|
-
if (n.name !== t && n.joins)
|
|
4960
|
-
for (const [, i] of Object.entries(n.joins))
|
|
4961
|
-
|
|
4979
|
+
if (n.name !== t && n.joins)
|
|
4980
|
+
for (const [, i] of Object.entries(n.joins)) {
|
|
4981
|
+
const s = x(i.targetCube, e);
|
|
4982
|
+
if (s && s.name === t)
|
|
4962
4983
|
return { sourceCube: n, joinDef: i };
|
|
4963
|
-
|
|
4984
|
+
}
|
|
4964
4985
|
return null;
|
|
4965
4986
|
}
|
|
4966
4987
|
/**
|
|
@@ -5061,23 +5082,26 @@ class fn {
|
|
|
5061
5082
|
* and to search from any source cube, not just the primary
|
|
5062
5083
|
*/
|
|
5063
5084
|
findJoinInfoForCube(e, t, n) {
|
|
5064
|
-
if (t.joins)
|
|
5065
|
-
for (const [, s] of Object.entries(t.joins))
|
|
5066
|
-
|
|
5085
|
+
if (t.joins)
|
|
5086
|
+
for (const [, s] of Object.entries(t.joins)) {
|
|
5087
|
+
const r = x(s.targetCube, e);
|
|
5088
|
+
if (r && r.name === n)
|
|
5067
5089
|
return { sourceCube: t, joinDef: s };
|
|
5068
|
-
|
|
5090
|
+
}
|
|
5069
5091
|
const i = e.get(n);
|
|
5070
|
-
if (i?.joins)
|
|
5071
|
-
for (const [, s] of Object.entries(i.joins))
|
|
5072
|
-
|
|
5092
|
+
if (i?.joins)
|
|
5093
|
+
for (const [, s] of Object.entries(i.joins)) {
|
|
5094
|
+
const r = x(s.targetCube, e);
|
|
5095
|
+
if (r && r.name === t.name)
|
|
5073
5096
|
return { sourceCube: i, joinDef: s, reversed: !0 };
|
|
5074
|
-
|
|
5097
|
+
}
|
|
5075
5098
|
for (const [, s] of e)
|
|
5076
|
-
if (!(s.name === t.name || s.name === n) && s.joins)
|
|
5077
|
-
for (const [, r] of Object.entries(s.joins))
|
|
5078
|
-
|
|
5099
|
+
if (!(s.name === t.name || s.name === n) && s.joins)
|
|
5100
|
+
for (const [, r] of Object.entries(s.joins)) {
|
|
5101
|
+
const a = x(r.targetCube, e);
|
|
5102
|
+
if (a && a.name === n)
|
|
5079
5103
|
return { sourceCube: s, joinDef: r };
|
|
5080
|
-
|
|
5104
|
+
}
|
|
5081
5105
|
return null;
|
|
5082
5106
|
}
|
|
5083
5107
|
/**
|
|
@@ -5112,7 +5136,9 @@ class fn {
|
|
|
5112
5136
|
}
|
|
5113
5137
|
if (e.joins)
|
|
5114
5138
|
for (const [, r] of Object.entries(e.joins)) {
|
|
5115
|
-
const
|
|
5139
|
+
const a = x(r.targetCube, n);
|
|
5140
|
+
if (!a) continue;
|
|
5141
|
+
const u = a.name;
|
|
5116
5142
|
if (s.has(u)) {
|
|
5117
5143
|
let c;
|
|
5118
5144
|
r.relationship === "belongsToMany" && r.through ? c = r.through.sourceKey.map((l) => ({
|
|
@@ -5169,12 +5195,14 @@ class fn {
|
|
|
5169
5195
|
/**
|
|
5170
5196
|
* Find hasMany join definition from primary cube to target cube
|
|
5171
5197
|
*/
|
|
5172
|
-
findHasManyJoinDef(e, t) {
|
|
5198
|
+
findHasManyJoinDef(e, t, n) {
|
|
5173
5199
|
if (!e.joins)
|
|
5174
5200
|
return null;
|
|
5175
|
-
for (const [,
|
|
5176
|
-
|
|
5177
|
-
|
|
5201
|
+
for (const [, i] of Object.entries(e.joins)) {
|
|
5202
|
+
const s = x(i.targetCube, n);
|
|
5203
|
+
if (s && s.name === t && i.relationship === "hasMany")
|
|
5204
|
+
return i;
|
|
5205
|
+
}
|
|
5178
5206
|
return null;
|
|
5179
5207
|
}
|
|
5180
5208
|
/**
|
|
@@ -5199,9 +5227,10 @@ class fn {
|
|
|
5199
5227
|
for (const r of s) {
|
|
5200
5228
|
if (r === t.name) continue;
|
|
5201
5229
|
const a = n.get(r);
|
|
5202
|
-
if (a?.joins)
|
|
5203
|
-
for (const [, u] of Object.entries(a.joins))
|
|
5204
|
-
|
|
5230
|
+
if (a?.joins)
|
|
5231
|
+
for (const [, u] of Object.entries(a.joins)) {
|
|
5232
|
+
const c = x(u.targetCube, n);
|
|
5233
|
+
if (c && c.name === t.name && u.relationship === "hasMany") {
|
|
5205
5234
|
const l = this.extractFiltersForCube(e.filters, r), m = this.extractTimeDimensionFiltersForCube(e, r), p = [...l, ...m];
|
|
5206
5235
|
p.length > 0 && u.on.length > 0 && i.push({
|
|
5207
5236
|
sourceCube: a,
|
|
@@ -5215,7 +5244,7 @@ class fn {
|
|
|
5215
5244
|
}))
|
|
5216
5245
|
});
|
|
5217
5246
|
}
|
|
5218
|
-
|
|
5247
|
+
}
|
|
5219
5248
|
}
|
|
5220
5249
|
return i;
|
|
5221
5250
|
}
|
|
@@ -5579,8 +5608,8 @@ class pn {
|
|
|
5579
5608
|
if (D === l && r.dimensions && r.dimensions[N]) {
|
|
5580
5609
|
const F = r.dimensions[N];
|
|
5581
5610
|
if ($.operator === "inDateRange") {
|
|
5582
|
-
const v = this.queryBuilder.buildMeasureExpression({ sql: F.sql, type: "number" }, n),
|
|
5583
|
-
|
|
5611
|
+
const v = this.queryBuilder.buildMeasureExpression({ sql: F.sql, type: "number" }, n), Q = this.queryBuilder.buildDateRangeCondition(v, $.values);
|
|
5612
|
+
Q && y.push(Q);
|
|
5584
5613
|
}
|
|
5585
5614
|
}
|
|
5586
5615
|
}
|
|
@@ -7734,7 +7763,7 @@ class Dn {
|
|
|
7734
7763
|
return null;
|
|
7735
7764
|
const u = Array.from(i);
|
|
7736
7765
|
if (!u.every(
|
|
7737
|
-
(h) => this.hasDirectJoinToSharedDimension(t.get(h), r)
|
|
7766
|
+
(h) => this.hasDirectJoinToSharedDimension(t.get(h), r, t)
|
|
7738
7767
|
))
|
|
7739
7768
|
return null;
|
|
7740
7769
|
const l = this.buildDimensionRefs(e, t), m = this.buildTimeDimensionRefs(e, t), p = {
|
|
@@ -7763,12 +7792,12 @@ class Dn {
|
|
|
7763
7792
|
mergeStrategy: "fullJoin"
|
|
7764
7793
|
};
|
|
7765
7794
|
}
|
|
7766
|
-
hasDirectJoinToSharedDimension(e, t) {
|
|
7795
|
+
hasDirectJoinToSharedDimension(e, t, n) {
|
|
7767
7796
|
if (!e?.joins)
|
|
7768
7797
|
return !1;
|
|
7769
|
-
for (const [,
|
|
7770
|
-
const
|
|
7771
|
-
if (!(!s || s.name !== t) && (
|
|
7798
|
+
for (const [, i] of Object.entries(e.joins)) {
|
|
7799
|
+
const s = x(i.targetCube, n);
|
|
7800
|
+
if (!(!s || s.name !== t) && (i.relationship === "belongsTo" || i.relationship === "hasOne"))
|
|
7772
7801
|
return !0;
|
|
7773
7802
|
}
|
|
7774
7803
|
return !1;
|
|
@@ -8349,8 +8378,8 @@ function On(d, e, t, n, i, s) {
|
|
|
8349
8378
|
if (D && D.joinKeys.length > 0) {
|
|
8350
8379
|
const N = [];
|
|
8351
8380
|
for (const F of D.joinKeys) {
|
|
8352
|
-
const v = o`${o.identifier(S)}.${o.identifier(F.sourceColumn)}`,
|
|
8353
|
-
|
|
8381
|
+
const v = o`${o.identifier(S)}.${o.identifier(F.sourceColumn)}`, Q = F.targetColumnObj;
|
|
8382
|
+
Q && N.push(k(Q, v));
|
|
8354
8383
|
}
|
|
8355
8384
|
N.length > 0 && (T = A(...N));
|
|
8356
8385
|
}
|
|
@@ -8799,11 +8828,11 @@ class In {
|
|
|
8799
8828
|
$[J] = o`sum(${L})`.as(J), $[z] = o`count(${L})`.as(z);
|
|
8800
8829
|
}
|
|
8801
8830
|
let v = n.db.select($).from(C.from);
|
|
8802
|
-
const
|
|
8803
|
-
C.where &&
|
|
8831
|
+
const Q = [];
|
|
8832
|
+
C.where && Q.push(C.where), Q.push(
|
|
8804
8833
|
...i.queryBuilder.buildWhereConditions(a, t, n)
|
|
8805
|
-
),
|
|
8806
|
-
|
|
8834
|
+
), Q.length > 0 && (v = v.where(
|
|
8835
|
+
Q.length === 1 ? Q[0] : A(...Q)
|
|
8807
8836
|
)), D.length > 0 && (v = v.groupBy(...D));
|
|
8808
8837
|
const Ct = n.db.$with(l).as(v), X = {};
|
|
8809
8838
|
for (const E of t.dimensions ?? [])
|
|
@@ -10118,6 +10147,22 @@ class ft {
|
|
|
10118
10147
|
registerCube(e) {
|
|
10119
10148
|
this.validateCalculatedMeasures(e), new Y(this.cubes).populateDependencies(e), this.cubes.set(e.name, e), this.invalidateMetadataCache();
|
|
10120
10149
|
}
|
|
10150
|
+
/**
|
|
10151
|
+
* Validate that all string-based cube references in joins resolve to registered cubes.
|
|
10152
|
+
* Call after all cubes are registered for strict startup validation.
|
|
10153
|
+
* Throws an error listing all unresolved references.
|
|
10154
|
+
*/
|
|
10155
|
+
validateCubeReferences() {
|
|
10156
|
+
const e = [];
|
|
10157
|
+
for (const [t, n] of this.cubes)
|
|
10158
|
+
if (n.joins)
|
|
10159
|
+
for (const [i, s] of Object.entries(n.joins))
|
|
10160
|
+
typeof s.targetCube == "string" && !this.cubes.has(s.targetCube) && e.push(`${t}.joins.${i}: target cube '${s.targetCube}' is not registered`);
|
|
10161
|
+
if (e.length > 0)
|
|
10162
|
+
throw new Error(`Unresolved cube references:
|
|
10163
|
+
${e.map((t) => ` - ${t}`).join(`
|
|
10164
|
+
`)}`);
|
|
10165
|
+
}
|
|
10121
10166
|
/**
|
|
10122
10167
|
* Validate calculated measures in a cube
|
|
10123
10168
|
* Checks template syntax, dependency existence, and circular dependencies
|
|
@@ -10281,8 +10326,8 @@ ${t.join(`
|
|
|
10281
10326
|
const r = [];
|
|
10282
10327
|
if (e.joins)
|
|
10283
10328
|
for (const [, c] of Object.entries(e.joins)) {
|
|
10284
|
-
const l =
|
|
10285
|
-
r.push({
|
|
10329
|
+
const l = x(c.targetCube, this.cubes);
|
|
10330
|
+
l && r.push({
|
|
10286
10331
|
targetCube: l.name,
|
|
10287
10332
|
relationship: c.relationship,
|
|
10288
10333
|
joinFields: c.on.map((m) => ({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("next/server"),f=require("../mcp-transport-DCiSGtp1.cjs"),i=require("../utils.cjs");function v(n){const{cubes:o,drizzle:s,schema:c,engineType:d,cache:a}=n;if(!o||o.length===0)throw new Error("At least one cube must be provided in the cubes array");const t=new f.SemanticLayerCompiler({drizzle:s,schema:c,engineType:d,cache:a});return o.forEach(e=>{t.registerCube(e)}),t}function h(n,o){const s=n.headers.get("origin"),c={};return o.origin&&(typeof o.origin=="string"?c["Access-Control-Allow-Origin"]=o.origin:Array.isArray(o.origin)?s&&o.origin.includes(s)&&(c["Access-Control-Allow-Origin"]=s):typeof o.origin=="function"&&s&&o.origin(s)&&(c["Access-Control-Allow-Origin"]=s)),o.methods&&(c["Access-Control-Allow-Methods"]=o.methods.join(", ")),o.allowedHeaders&&(c["Access-Control-Allow-Headers"]=o.allowedHeaders.join(", ")),o.credentials&&(c["Access-Control-Allow-Credentials"]="true"),c}function J(n){return async function(s){const c=h(s,n);return new Response(null,{status:200,headers:c})}}function T(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{let e;if(a.method==="POST"){const N=await a.json();e=N.query||N}else if(a.method==="GET"){const N=a.nextUrl.searchParams.get("query");if(!N)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(N)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=a.headers.get("x-cache-control")==="no-cache",p=await c.executeMultiCubeQuery(e,l,{skipCache:u}),w=i.formatCubeResponse(e,p,c);return r.NextResponse.json(w,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function A(n){const{cors:o}=n,s=v(n);return async function(d,a){try{const t=s.getMetadata(),e=i.formatMetaResponse(t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js meta handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Failed to fetch metadata",500),{status:500})}}}function M(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{let e;if(a.method==="POST"){const C=await a.json();e=C.query||C}else if(a.method==="GET"){const C=a.nextUrl.searchParams.get("query");if(!C)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(C)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=e.measures?.[0]||e.dimensions?.[0];if(!u)return r.NextResponse.json(i.formatErrorResponse("No measures or dimensions specified",400),{status:400});const p=u.split(".")[0],w=await c.generateSQL(p,e,l),N=i.formatSqlResponse(e,w);return r.NextResponse.json(N,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js SQL handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500),{status:500})}}}function L(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{let e;if(a.method==="POST"){const u=await a.json();e=u.query||u}else if(a.method==="GET"){const u=a.nextUrl.searchParams.get("query");if(!u)return r.NextResponse.json({error:"Query parameter is required",valid:!1},{status:400});try{e=JSON.parse(u)}catch{return r.NextResponse.json({error:"Invalid JSON in query parameter",valid:!1},{status:400})}}else return r.NextResponse.json({error:"Method not allowed",valid:!1},{status:405});const l=await o(a,t),y=await i.handleDryRun(e,l,c);return r.NextResponse.json(y,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js dry-run handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},{status:400})}}}function D(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json(),{queries:l}=e;if(!l||!Array.isArray(l))return r.NextResponse.json(i.formatErrorResponse('Request body must contain a "queries" array',400),{status:400});if(l.length===0)return r.NextResponse.json(i.formatErrorResponse("Queries array cannot be empty",400),{status:400});const y=await o(a,t),u=a.headers.get("x-cache-control")==="no-cache",p=await i.handleBatchRequest(l,y,c,{skipCache:u});return r.NextResponse.json(p,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js batch handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500),{status:500})}}}function V(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json({error:"Method not allowed"},{status:405});const e=await a.json(),l=e.query||e,y=e.options||{},u=await o(a,t),p=c.validateQuery(l);if(!p.isValid)return r.NextResponse.json({error:`Query validation failed: ${p.errors.join(", ")}`},{status:400});const w=await c.explainQuery(l,u,y);return r.NextResponse.json(w,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js explain handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Explain query failed"},{status:500})}}}function k(n){const{cors:o}=n,s=v(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json(),e=await i.handleDiscover(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js discover handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Discovery failed",500),{status:500})}}}function K(n){const{cors:o}=n,s=v(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.naturalLanguage)return r.NextResponse.json(i.formatErrorResponse("naturalLanguage field is required",400),{status:400});const e=await i.handleSuggest(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js suggest handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query suggestion failed",500),{status:500})}}}function z(n){const{cors:o}=n,s=v(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const e=await i.handleValidate(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js validate handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query validation failed",500),{status:500})}}}function $(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json();if(!e.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const l=await o(a,t),y=await i.handleLoad(c,l,e);return r.NextResponse.json(y,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function _(n){const{extractSecurityContext:o,cors:s,mcp:c={enabled:!0}}=n,d=v(n);return async function(t){if(t.method==="DELETE")return r.NextResponse.json({error:"Session termination not supported"},{status:405});if(t.method==="GET"){const m=new TextEncoder,S=f.primeEventId(),j=new ReadableStream({start(R){R.enqueue(m.encode(f.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},S,15e3)))}}),H=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const R=h(t,s);Object.entries(R).forEach(([b,O])=>H.set(b,O))}return new r.NextResponse(j,{status:200,headers:H})}if(t.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=f.validateOriginHeader(t.headers.get("origin"),c.allowedOrigins?{allowedOrigins:c.allowedOrigins}:{});if(!e.valid)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,e.reason),{status:403});const l=t.headers.get("accept");if(!f.validateAcceptHeader(l))return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),{status:400});const y=f.negotiateProtocol(Object.fromEntries(t.headers.entries()));if(!y.ok)return r.NextResponse.json({error:"Unsupported MCP protocol version",supported:y.supported},{status:426});let u;try{u=await t.json()}catch{u=null}const p=f.parseJsonRpc(u);if(!p)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),{status:400});const w=f.wantsEventStream(l),N=p.method==="initialize",C=(m,S=200,j={})=>r.NextResponse.json(m,{status:S,headers:{...s?h(t,s):{},...j}});try{const m=await f.dispatchMcpMethod(p.method,p.params,{semanticLayer:d,extractSecurityContext:R=>o(R),rawRequest:t,rawResponse:null});if(f.isNotification(p))return new r.NextResponse(null,{status:202});const S=N&&m&&typeof m=="object"&&"sessionId"in m?m.sessionId:void 0,j={};S&&(j[f.MCP_SESSION_ID_HEADER]=S);const H=f.buildJsonRpcResult(p.id??null,m);if(w){const R=new TextEncoder,b=f.primeEventId(),O=new ReadableStream({start(x){x.enqueue(R.encode(`id: ${b}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("next/server"),f=require("../mcp-transport-CWGqDQSI.cjs"),i=require("../utils.cjs");function v(n){const{cubes:o,drizzle:s,schema:c,engineType:d,cache:a}=n;if(!o||o.length===0)throw new Error("At least one cube must be provided in the cubes array");const t=new f.SemanticLayerCompiler({drizzle:s,schema:c,engineType:d,cache:a});return o.forEach(e=>{t.registerCube(e)}),t}function h(n,o){const s=n.headers.get("origin"),c={};return o.origin&&(typeof o.origin=="string"?c["Access-Control-Allow-Origin"]=o.origin:Array.isArray(o.origin)?s&&o.origin.includes(s)&&(c["Access-Control-Allow-Origin"]=s):typeof o.origin=="function"&&s&&o.origin(s)&&(c["Access-Control-Allow-Origin"]=s)),o.methods&&(c["Access-Control-Allow-Methods"]=o.methods.join(", ")),o.allowedHeaders&&(c["Access-Control-Allow-Headers"]=o.allowedHeaders.join(", ")),o.credentials&&(c["Access-Control-Allow-Credentials"]="true"),c}function J(n){return async function(s){const c=h(s,n);return new Response(null,{status:200,headers:c})}}function T(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{let e;if(a.method==="POST"){const N=await a.json();e=N.query||N}else if(a.method==="GET"){const N=a.nextUrl.searchParams.get("query");if(!N)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(N)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=a.headers.get("x-cache-control")==="no-cache",p=await c.executeMultiCubeQuery(e,l,{skipCache:u}),w=i.formatCubeResponse(e,p,c);return r.NextResponse.json(w,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function A(n){const{cors:o}=n,s=v(n);return async function(d,a){try{const t=s.getMetadata(),e=i.formatMetaResponse(t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js meta handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Failed to fetch metadata",500),{status:500})}}}function M(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{let e;if(a.method==="POST"){const C=await a.json();e=C.query||C}else if(a.method==="GET"){const C=a.nextUrl.searchParams.get("query");if(!C)return r.NextResponse.json(i.formatErrorResponse("Query parameter is required",400),{status:400});try{e=JSON.parse(C)}catch{return r.NextResponse.json(i.formatErrorResponse("Invalid JSON in query parameter",400),{status:400})}}else return r.NextResponse.json(i.formatErrorResponse("Method not allowed",405),{status:405});const l=await o(a,t),y=c.validateQuery(e);if(!y.isValid)return r.NextResponse.json(i.formatErrorResponse(`Query validation failed: ${y.errors.join(", ")}`,400),{status:400});const u=e.measures?.[0]||e.dimensions?.[0];if(!u)return r.NextResponse.json(i.formatErrorResponse("No measures or dimensions specified",400),{status:400});const p=u.split(".")[0],w=await c.generateSQL(p,e,l),N=i.formatSqlResponse(e,w);return r.NextResponse.json(N,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js SQL handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500),{status:500})}}}function L(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{let e;if(a.method==="POST"){const u=await a.json();e=u.query||u}else if(a.method==="GET"){const u=a.nextUrl.searchParams.get("query");if(!u)return r.NextResponse.json({error:"Query parameter is required",valid:!1},{status:400});try{e=JSON.parse(u)}catch{return r.NextResponse.json({error:"Invalid JSON in query parameter",valid:!1},{status:400})}}else return r.NextResponse.json({error:"Method not allowed",valid:!1},{status:405});const l=await o(a,t),y=await i.handleDryRun(e,l,c);return r.NextResponse.json(y,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js dry-run handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},{status:400})}}}function D(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json(),{queries:l}=e;if(!l||!Array.isArray(l))return r.NextResponse.json(i.formatErrorResponse('Request body must contain a "queries" array',400),{status:400});if(l.length===0)return r.NextResponse.json(i.formatErrorResponse("Queries array cannot be empty",400),{status:400});const y=await o(a,t),u=a.headers.get("x-cache-control")==="no-cache",p=await i.handleBatchRequest(l,y,c,{skipCache:u});return r.NextResponse.json(p,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js batch handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500),{status:500})}}}function V(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json({error:"Method not allowed"},{status:405});const e=await a.json(),l=e.query||e,y=e.options||{},u=await o(a,t),p=c.validateQuery(l);if(!p.isValid)return r.NextResponse.json({error:`Query validation failed: ${p.errors.join(", ")}`},{status:400});const w=await c.explainQuery(l,u,y);return r.NextResponse.json(w,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js explain handler error:",e),r.NextResponse.json({error:e instanceof Error?e.message:"Explain query failed"},{status:500})}}}function k(n){const{cors:o}=n,s=v(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json(),e=await i.handleDiscover(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js discover handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Discovery failed",500),{status:500})}}}function K(n){const{cors:o}=n,s=v(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.naturalLanguage)return r.NextResponse.json(i.formatErrorResponse("naturalLanguage field is required",400),{status:400});const e=await i.handleSuggest(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js suggest handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query suggestion failed",500),{status:500})}}}function z(n){const{cors:o}=n,s=v(n);return async function(d,a){try{if(d.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const t=await d.json();if(!t.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const e=await i.handleValidate(s,t);return r.NextResponse.json(e,{headers:o?h(d,o):{}})}catch(t){return process.env.NODE_ENV!=="test"&&console.error("Next.js validate handler error:",t),r.NextResponse.json(i.formatErrorResponse(t instanceof Error?t.message:"Query validation failed",500),{status:500})}}}function $(n){const{extractSecurityContext:o,cors:s}=n,c=v(n);return async function(a,t){try{if(a.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=await a.json();if(!e.query)return r.NextResponse.json(i.formatErrorResponse("query field is required",400),{status:400});const l=await o(a,t),y=await i.handleLoad(c,l,e);return r.NextResponse.json(y,{headers:s?h(a,s):{}})}catch(e){return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP load handler error:",e),r.NextResponse.json(i.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500),{status:500})}}}function _(n){const{extractSecurityContext:o,cors:s,mcp:c={enabled:!0}}=n,d=v(n);return async function(t){if(t.method==="DELETE")return r.NextResponse.json({error:"Session termination not supported"},{status:405});if(t.method==="GET"){const m=new TextEncoder,S=f.primeEventId(),j=new ReadableStream({start(R){R.enqueue(m.encode(f.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},S,15e3)))}}),H=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const R=h(t,s);Object.entries(R).forEach(([b,O])=>H.set(b,O))}return new r.NextResponse(j,{status:200,headers:H})}if(t.method!=="POST")return r.NextResponse.json(i.formatErrorResponse("Method not allowed - use POST",405),{status:405});const e=f.validateOriginHeader(t.headers.get("origin"),c.allowedOrigins?{allowedOrigins:c.allowedOrigins}:{});if(!e.valid)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,e.reason),{status:403});const l=t.headers.get("accept");if(!f.validateAcceptHeader(l))return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),{status:400});const y=f.negotiateProtocol(Object.fromEntries(t.headers.entries()));if(!y.ok)return r.NextResponse.json({error:"Unsupported MCP protocol version",supported:y.supported},{status:426});let u;try{u=await t.json()}catch{u=null}const p=f.parseJsonRpc(u);if(!p)return r.NextResponse.json(f.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),{status:400});const w=f.wantsEventStream(l),N=p.method==="initialize",C=(m,S=200,j={})=>r.NextResponse.json(m,{status:S,headers:{...s?h(t,s):{},...j}});try{const m=await f.dispatchMcpMethod(p.method,p.params,{semanticLayer:d,extractSecurityContext:R=>o(R),rawRequest:t,rawResponse:null});if(f.isNotification(p))return new r.NextResponse(null,{status:202});const S=N&&m&&typeof m=="object"&&"sessionId"in m?m.sessionId:void 0,j={};S&&(j[f.MCP_SESSION_ID_HEADER]=S);const H=f.buildJsonRpcResult(p.id??null,m);if(w){const R=new TextEncoder,b=f.primeEventId(),O=new ReadableStream({start(x){x.enqueue(R.encode(`id: ${b}
|
|
2
2
|
|
|
3
3
|
`)),x.enqueue(R.encode(f.serializeSseEvent(H,b))),x.close()}}),E=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...j});if(s){const x=h(t,s);Object.entries(x).forEach(([g,P])=>E.set(g,P))}return new r.NextResponse(O,{status:200,headers:E})}return C(H,200,j)}catch(m){if(f.isNotification(p))return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP notification processing error:",m),new r.NextResponse(null,{status:202});process.env.NODE_ENV!=="test"&&console.error("Next.js MCP RPC handler error:",m);const S=m?.code??-32603,j=m?.data,H=m.message||"MCP request failed",R=f.buildJsonRpcError(p.id??null,S,H,j);if(w){const b=new TextEncoder,O=f.primeEventId(),E=new ReadableStream({start(g){g.enqueue(b.encode(`id: ${O}
|
|
4
4
|
|
|
5
|
-
`)),g.enqueue(b.encode(f.serializeSseEvent(R,O))),g.close()}}),x=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const g=h(t,s);Object.entries(g).forEach(([P,I])=>x.set(P,I))}return new r.NextResponse(E,{status:200,headers:x})}return C(R,200)}}}function Q(n){const{extractSecurityContext:o,cors:s,agent:c}=n;if(!c)throw new Error("agent config is required for createAgentChatHandler");const d=v(n);return async function(t,e){try{if(t.method!=="POST")return r.NextResponse.json({error:"Method not allowed - use POST"},{status:405});const{handleAgentChat:l}=await Promise.resolve().then(()=>require("../handler-
|
|
5
|
+
`)),g.enqueue(b.encode(f.serializeSseEvent(R,O))),g.close()}}),x=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const g=h(t,s);Object.entries(g).forEach(([P,I])=>x.set(P,I))}return new r.NextResponse(E,{status:200,headers:x})}return C(R,200)}}}function Q(n){const{extractSecurityContext:o,cors:s,agent:c}=n;if(!c)throw new Error("agent config is required for createAgentChatHandler");const d=v(n);return async function(t,e){try{if(t.method!=="POST")return r.NextResponse.json({error:"Method not allowed - use POST"},{status:405});const{handleAgentChat:l}=await Promise.resolve().then(()=>require("../handler-DOIyiFPg.cjs")),y=await t.json(),{message:u,sessionId:p,history:w}=y;if(!u||typeof u!="string")return r.NextResponse.json({error:"message is required and must be a string"},{status:400});let N=(c.apiKey||"").trim();if(c.allowClientApiKey){const E=t.headers.get("x-agent-api-key");E&&(N=E.trim())}if(!N)return r.NextResponse.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},{status:401});const C=c.allowClientApiKey&&t.headers.get("x-agent-provider")||void 0,m=c.allowClientApiKey&&t.headers.get("x-agent-model")||void 0,S=c.allowClientApiKey&&t.headers.get("x-agent-provider-endpoint")||void 0,j=await o(t,e),H=c.buildSystemContext?.(j),R=new TextEncoder,b=new ReadableStream({async start(E){try{const x=l({message:u,sessionId:p,history:w,semanticLayer:d,securityContext:j,agentConfig:c,apiKey:N,systemContext:H,providerOverride:C,modelOverride:m,baseURLOverride:S});for await(const g of x){const P=`data: ${JSON.stringify(g)}
|
|
6
6
|
|
|
7
7
|
`;E.enqueue(R.encode(P))}}catch(x){const g={type:"error",data:{message:x instanceof Error?x.message:"Stream failed"}};E.enqueue(R.encode(`data: ${JSON.stringify(g)}
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextResponse as r } from "next/server";
|
|
2
|
-
import { e as T, s as A, v as D, b as R, a as _, n as Q, p as V, w as I, d as J, i as M, M as k, c as K, S as $ } from "../mcp-transport-
|
|
2
|
+
import { e as T, s as A, v as D, b as R, a as _, n as Q, p as V, w as I, d as J, i as M, M as k, c as K, S as $ } from "../mcp-transport-CyeHMDPl.js";
|
|
3
3
|
import { formatErrorResponse as i, formatCubeResponse as z, formatMetaResponse as U, formatSqlResponse as G, handleDryRun as B, handleBatchRequest as F, handleDiscover as X, handleSuggest as q, handleValidate as W, handleLoad as Y } from "../utils.js";
|
|
4
4
|
function E(n) {
|
|
5
5
|
const { cubes: a, drizzle: s, schema: c, engineType: d, cache: o } = n;
|
|
@@ -519,7 +519,7 @@ function oe(n) {
|
|
|
519
519
|
{ error: "Method not allowed - use POST" },
|
|
520
520
|
{ status: 405 }
|
|
521
521
|
);
|
|
522
|
-
const { handleAgentChat: l } = await import("../handler-
|
|
522
|
+
const { handleAgentChat: l } = await import("../handler-BHguLZOY.js"), y = await t.json(), { message: u, sessionId: f, history: C } = y;
|
|
523
523
|
if (!u || typeof u != "string")
|
|
524
524
|
return r.json(
|
|
525
525
|
{ error: "message is required and must be a string" },
|