drizzle-cube 0.4.18 → 0.4.20
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 +6 -6
- package/dist/adapters/express/index.js +75 -74
- package/dist/adapters/fastify/index.cjs +5 -5
- package/dist/adapters/fastify/index.js +91 -90
- package/dist/adapters/{handler-DefTXJpi.js → handler-CbDMdSY5.js} +95 -82
- package/dist/adapters/{handler-hwoGzGex.cjs → handler-DtdjM1Vx.cjs} +18 -14
- package/dist/adapters/hono/index.cjs +6 -6
- package/dist/adapters/hono/index.js +66 -65
- package/dist/adapters/nextjs/index.cjs +5 -5
- package/dist/adapters/nextjs/index.js +116 -115
- package/dist/server/index.cjs +6 -2
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.js +14 -1
- package/package.json +1 -1
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { S as D, v as K, b as x, a as T, n as V, p as z, w as _, d as B, i as j, M as F, c as U, e as E, s as P } from "../mcp-transport-m1X1GtwG.js";
|
|
2
|
-
import { formatErrorResponse as
|
|
2
|
+
import { formatErrorResponse as d, formatCubeResponse as A, handleBatchRequest as X, formatMetaResponse as G, formatSqlResponse as I, handleDryRun as M } from "../utils.js";
|
|
3
3
|
const N = function(i, k, R) {
|
|
4
4
|
const {
|
|
5
5
|
cubes: S,
|
|
6
6
|
drizzle: O,
|
|
7
7
|
schema: J,
|
|
8
|
-
extractSecurityContext:
|
|
8
|
+
extractSecurityContext: p,
|
|
9
9
|
engineType: L,
|
|
10
10
|
cors: q,
|
|
11
|
-
basePath:
|
|
12
|
-
bodyLimit:
|
|
11
|
+
basePath: m = "/cubejs-api/v1",
|
|
12
|
+
bodyLimit: g = 10485760,
|
|
13
13
|
// 10MB
|
|
14
14
|
cache: H,
|
|
15
|
-
mcp:
|
|
16
|
-
agent:
|
|
15
|
+
mcp: C = { enabled: !0 },
|
|
16
|
+
agent: f
|
|
17
17
|
} = k;
|
|
18
18
|
if (!S || S.length === 0)
|
|
19
19
|
return R(new Error("At least one cube must be provided in the cubes array"));
|
|
@@ -28,8 +28,8 @@ const N = function(i, k, R) {
|
|
|
28
28
|
});
|
|
29
29
|
if (S.forEach((t) => {
|
|
30
30
|
c.registerCube(t);
|
|
31
|
-
}), i.post(`${
|
|
32
|
-
bodyLimit:
|
|
31
|
+
}), i.post(`${m}/load`, {
|
|
32
|
+
bodyLimit: g,
|
|
33
33
|
schema: {
|
|
34
34
|
body: {
|
|
35
35
|
type: "object",
|
|
@@ -38,21 +38,21 @@ const N = function(i, k, R) {
|
|
|
38
38
|
}
|
|
39
39
|
}, async (t, r) => {
|
|
40
40
|
try {
|
|
41
|
-
const e = t.body, a = e.query || e, n = await
|
|
41
|
+
const e = t.body, a = e.query || e, n = await p(t), s = c.validateQuery(a);
|
|
42
42
|
if (!s.isValid)
|
|
43
|
-
return r.status(400).send(
|
|
43
|
+
return r.status(400).send(d(
|
|
44
44
|
`Query validation failed: ${s.errors.join(", ")}`,
|
|
45
45
|
400
|
|
46
46
|
));
|
|
47
|
-
const o = t.headers["x-cache-control"] === "no-cache",
|
|
48
|
-
return A(a,
|
|
47
|
+
const o = t.headers["x-cache-control"] === "no-cache", u = await c.executeMultiCubeQuery(a, n, { skipCache: o });
|
|
48
|
+
return A(a, u, c);
|
|
49
49
|
} catch (e) {
|
|
50
|
-
return t.log.error(e, "Query execution error"), r.status(500).send(
|
|
50
|
+
return t.log.error(e, "Query execution error"), r.status(500).send(d(
|
|
51
51
|
e instanceof Error ? e.message : "Query execution failed",
|
|
52
52
|
500
|
|
53
53
|
));
|
|
54
54
|
}
|
|
55
|
-
}), i.get(`${
|
|
55
|
+
}), i.get(`${m}/load`, {
|
|
56
56
|
schema: {
|
|
57
57
|
querystring: {
|
|
58
58
|
type: "object",
|
|
@@ -69,27 +69,27 @@ const N = function(i, k, R) {
|
|
|
69
69
|
try {
|
|
70
70
|
a = JSON.parse(e);
|
|
71
71
|
} catch {
|
|
72
|
-
return r.status(400).send(
|
|
72
|
+
return r.status(400).send(d(
|
|
73
73
|
"Invalid JSON in query parameter",
|
|
74
74
|
400
|
|
75
75
|
));
|
|
76
76
|
}
|
|
77
|
-
const n = await
|
|
77
|
+
const n = await p(t), s = c.validateQuery(a);
|
|
78
78
|
if (!s.isValid)
|
|
79
|
-
return r.status(400).send(
|
|
79
|
+
return r.status(400).send(d(
|
|
80
80
|
`Query validation failed: ${s.errors.join(", ")}`,
|
|
81
81
|
400
|
|
82
82
|
));
|
|
83
|
-
const o = t.headers["x-cache-control"] === "no-cache",
|
|
84
|
-
return A(a,
|
|
83
|
+
const o = t.headers["x-cache-control"] === "no-cache", u = await c.executeMultiCubeQuery(a, n, { skipCache: o });
|
|
84
|
+
return A(a, u, c);
|
|
85
85
|
} catch (e) {
|
|
86
|
-
return t.log.error(e, "Query execution error"), r.status(500).send(
|
|
86
|
+
return t.log.error(e, "Query execution error"), r.status(500).send(d(
|
|
87
87
|
e instanceof Error ? e.message : "Query execution failed",
|
|
88
88
|
500
|
|
89
89
|
));
|
|
90
90
|
}
|
|
91
|
-
}), i.post(`${
|
|
92
|
-
bodyLimit:
|
|
91
|
+
}), i.post(`${m}/batch`, {
|
|
92
|
+
bodyLimit: g,
|
|
93
93
|
schema: {
|
|
94
94
|
body: {
|
|
95
95
|
type: "object",
|
|
@@ -106,35 +106,35 @@ const N = function(i, k, R) {
|
|
|
106
106
|
try {
|
|
107
107
|
const { queries: e } = t.body;
|
|
108
108
|
if (!e || !Array.isArray(e))
|
|
109
|
-
return r.status(400).send(
|
|
109
|
+
return r.status(400).send(d(
|
|
110
110
|
'Request body must contain a "queries" array',
|
|
111
111
|
400
|
|
112
112
|
));
|
|
113
113
|
if (e.length === 0)
|
|
114
|
-
return r.status(400).send(
|
|
114
|
+
return r.status(400).send(d(
|
|
115
115
|
"Queries array cannot be empty",
|
|
116
116
|
400
|
|
117
117
|
));
|
|
118
|
-
const a = await
|
|
118
|
+
const a = await p(t), n = t.headers["x-cache-control"] === "no-cache";
|
|
119
119
|
return await X(e, a, c, { skipCache: n });
|
|
120
120
|
} catch (e) {
|
|
121
|
-
return t.log.error(e, "Batch execution error"), r.status(500).send(
|
|
121
|
+
return t.log.error(e, "Batch execution error"), r.status(500).send(d(
|
|
122
122
|
e instanceof Error ? e.message : "Batch execution failed",
|
|
123
123
|
500
|
|
124
124
|
));
|
|
125
125
|
}
|
|
126
|
-
}), i.get(`${
|
|
126
|
+
}), i.get(`${m}/meta`, async (t, r) => {
|
|
127
127
|
try {
|
|
128
128
|
const e = c.getMetadata();
|
|
129
129
|
return G(e);
|
|
130
130
|
} catch (e) {
|
|
131
|
-
return t.log.error(e, "Metadata error"), r.status(500).send(
|
|
131
|
+
return t.log.error(e, "Metadata error"), r.status(500).send(d(
|
|
132
132
|
e instanceof Error ? e.message : "Failed to fetch metadata",
|
|
133
133
|
500
|
|
134
134
|
));
|
|
135
135
|
}
|
|
136
|
-
}), i.post(`${
|
|
137
|
-
bodyLimit:
|
|
136
|
+
}), i.post(`${m}/sql`, {
|
|
137
|
+
bodyLimit: g,
|
|
138
138
|
schema: {
|
|
139
139
|
body: {
|
|
140
140
|
type: "object",
|
|
@@ -143,27 +143,27 @@ const N = function(i, k, R) {
|
|
|
143
143
|
}
|
|
144
144
|
}, async (t, r) => {
|
|
145
145
|
try {
|
|
146
|
-
const e = t.body, a = await
|
|
146
|
+
const e = t.body, a = await p(t), n = c.validateQuery(e);
|
|
147
147
|
if (!n.isValid)
|
|
148
|
-
return r.status(400).send(
|
|
148
|
+
return r.status(400).send(d(
|
|
149
149
|
`Query validation failed: ${n.errors.join(", ")}`,
|
|
150
150
|
400
|
|
151
151
|
));
|
|
152
152
|
const s = e.measures?.[0] || e.dimensions?.[0];
|
|
153
153
|
if (!s)
|
|
154
|
-
return r.status(400).send(
|
|
154
|
+
return r.status(400).send(d(
|
|
155
155
|
"No measures or dimensions specified",
|
|
156
156
|
400
|
|
157
157
|
));
|
|
158
|
-
const o = s.split(".")[0],
|
|
159
|
-
return I(e,
|
|
158
|
+
const o = s.split(".")[0], u = await c.generateSQL(o, e, a);
|
|
159
|
+
return I(e, u);
|
|
160
160
|
} catch (e) {
|
|
161
|
-
return t.log.error(e, "SQL generation error"), r.status(500).send(
|
|
161
|
+
return t.log.error(e, "SQL generation error"), r.status(500).send(d(
|
|
162
162
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
163
163
|
500
|
|
164
164
|
));
|
|
165
165
|
}
|
|
166
|
-
}), i.get(`${
|
|
166
|
+
}), i.get(`${m}/sql`, {
|
|
167
167
|
schema: {
|
|
168
168
|
querystring: {
|
|
169
169
|
type: "object",
|
|
@@ -175,28 +175,28 @@ const N = function(i, k, R) {
|
|
|
175
175
|
}
|
|
176
176
|
}, async (t, r) => {
|
|
177
177
|
try {
|
|
178
|
-
const { query: e } = t.query, a = JSON.parse(e), n = await
|
|
178
|
+
const { query: e } = t.query, a = JSON.parse(e), n = await p(t), s = c.validateQuery(a);
|
|
179
179
|
if (!s.isValid)
|
|
180
|
-
return r.status(400).send(
|
|
180
|
+
return r.status(400).send(d(
|
|
181
181
|
`Query validation failed: ${s.errors.join(", ")}`,
|
|
182
182
|
400
|
|
183
183
|
));
|
|
184
184
|
const o = a.measures?.[0] || a.dimensions?.[0];
|
|
185
185
|
if (!o)
|
|
186
|
-
return r.status(400).send(
|
|
186
|
+
return r.status(400).send(d(
|
|
187
187
|
"No measures or dimensions specified",
|
|
188
188
|
400
|
|
189
189
|
));
|
|
190
|
-
const
|
|
191
|
-
return I(a,
|
|
190
|
+
const u = o.split(".")[0], b = await c.generateSQL(u, a, n);
|
|
191
|
+
return I(a, b);
|
|
192
192
|
} catch (e) {
|
|
193
|
-
return t.log.error(e, "SQL generation error"), r.status(500).send(
|
|
193
|
+
return t.log.error(e, "SQL generation error"), r.status(500).send(d(
|
|
194
194
|
e instanceof Error ? e.message : "SQL generation failed",
|
|
195
195
|
500
|
|
196
196
|
));
|
|
197
197
|
}
|
|
198
|
-
}), i.post(`${
|
|
199
|
-
bodyLimit:
|
|
198
|
+
}), i.post(`${m}/dry-run`, {
|
|
199
|
+
bodyLimit: g,
|
|
200
200
|
schema: {
|
|
201
201
|
body: {
|
|
202
202
|
type: "object",
|
|
@@ -205,7 +205,7 @@ const N = function(i, k, R) {
|
|
|
205
205
|
}
|
|
206
206
|
}, async (t, r) => {
|
|
207
207
|
try {
|
|
208
|
-
const e = t.body, a = e.query || e, n = await
|
|
208
|
+
const e = t.body, a = e.query || e, n = await p(t);
|
|
209
209
|
return await M(a, n, c);
|
|
210
210
|
} catch (e) {
|
|
211
211
|
return t.log.error(e, "Dry-run error"), r.status(400).send({
|
|
@@ -213,7 +213,7 @@ const N = function(i, k, R) {
|
|
|
213
213
|
valid: !1
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
|
-
}), i.get(`${
|
|
216
|
+
}), i.get(`${m}/dry-run`, {
|
|
217
217
|
schema: {
|
|
218
218
|
querystring: {
|
|
219
219
|
type: "object",
|
|
@@ -225,7 +225,7 @@ const N = function(i, k, R) {
|
|
|
225
225
|
}
|
|
226
226
|
}, async (t, r) => {
|
|
227
227
|
try {
|
|
228
|
-
const { query: e } = t.query, a = JSON.parse(e), n = await
|
|
228
|
+
const { query: e } = t.query, a = JSON.parse(e), n = await p(t);
|
|
229
229
|
return await M(a, n, c);
|
|
230
230
|
} catch (e) {
|
|
231
231
|
return t.log.error(e, "Dry-run error"), r.status(400).send({
|
|
@@ -233,8 +233,8 @@ const N = function(i, k, R) {
|
|
|
233
233
|
valid: !1
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
}), i.post(`${
|
|
237
|
-
bodyLimit:
|
|
236
|
+
}), i.post(`${m}/explain`, {
|
|
237
|
+
bodyLimit: g,
|
|
238
238
|
schema: {
|
|
239
239
|
body: {
|
|
240
240
|
type: "object",
|
|
@@ -243,7 +243,7 @@ const N = function(i, k, R) {
|
|
|
243
243
|
}
|
|
244
244
|
}, async (t, r) => {
|
|
245
245
|
try {
|
|
246
|
-
const e = t.body, a = e.query || e, n = e.options || {}, s = await
|
|
246
|
+
const e = t.body, a = e.query || e, n = e.options || {}, s = await p(t), o = c.validateQuery(a);
|
|
247
247
|
return o.isValid ? await c.explainQuery(a, s, n) : r.status(400).send({
|
|
248
248
|
error: `Query validation failed: ${o.errors.join(", ")}`
|
|
249
249
|
});
|
|
@@ -252,8 +252,8 @@ const N = function(i, k, R) {
|
|
|
252
252
|
error: e instanceof Error ? e.message : "Explain query failed"
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
|
-
}),
|
|
256
|
-
bodyLimit:
|
|
255
|
+
}), f && i.post(`${m}/agent/chat`, {
|
|
256
|
+
bodyLimit: g,
|
|
257
257
|
schema: {
|
|
258
258
|
body: {
|
|
259
259
|
type: "object",
|
|
@@ -262,42 +262,43 @@ const N = function(i, k, R) {
|
|
|
262
262
|
}
|
|
263
263
|
}, async (t, r) => {
|
|
264
264
|
try {
|
|
265
|
-
const { handleAgentChat: e } = await import("../handler-
|
|
265
|
+
const { handleAgentChat: e } = await import("../handler-CbDMdSY5.js"), a = t.body, { message: n, sessionId: s, history: o } = a;
|
|
266
266
|
if (!n || typeof n != "string")
|
|
267
267
|
return r.status(400).send({ error: "message is required and must be a string" });
|
|
268
|
-
let
|
|
269
|
-
if (
|
|
270
|
-
const
|
|
271
|
-
|
|
268
|
+
let u = (f.apiKey || "").trim();
|
|
269
|
+
if (f.allowClientApiKey) {
|
|
270
|
+
const y = t.headers["x-agent-api-key"];
|
|
271
|
+
y && (u = y.trim());
|
|
272
272
|
}
|
|
273
|
-
if (!
|
|
273
|
+
if (!u)
|
|
274
274
|
return r.status(401).send({
|
|
275
275
|
error: "No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."
|
|
276
276
|
});
|
|
277
|
-
const
|
|
277
|
+
const b = await p(t), l = f.buildSystemContext?.(b);
|
|
278
278
|
r.raw.writeHead(200, {
|
|
279
279
|
"Content-Type": "text/event-stream",
|
|
280
280
|
"Cache-Control": "no-cache",
|
|
281
281
|
Connection: "keep-alive"
|
|
282
282
|
});
|
|
283
283
|
try {
|
|
284
|
-
const
|
|
284
|
+
const y = e({
|
|
285
285
|
message: n,
|
|
286
286
|
sessionId: s,
|
|
287
287
|
history: o,
|
|
288
288
|
semanticLayer: c,
|
|
289
|
-
securityContext:
|
|
290
|
-
agentConfig:
|
|
291
|
-
apiKey:
|
|
289
|
+
securityContext: b,
|
|
290
|
+
agentConfig: f,
|
|
291
|
+
apiKey: u,
|
|
292
|
+
systemContext: l
|
|
292
293
|
});
|
|
293
|
-
for await (const h of
|
|
294
|
+
for await (const h of y)
|
|
294
295
|
r.raw.write(`data: ${JSON.stringify(h)}
|
|
295
296
|
|
|
296
297
|
`);
|
|
297
|
-
} catch (
|
|
298
|
+
} catch (y) {
|
|
298
299
|
const h = {
|
|
299
300
|
type: "error",
|
|
300
|
-
data: { message:
|
|
301
|
+
data: { message: y instanceof Error ? y.message : "Stream failed" }
|
|
301
302
|
};
|
|
302
303
|
r.raw.write(`data: ${JSON.stringify(h)}
|
|
303
304
|
|
|
@@ -311,10 +312,10 @@ const N = function(i, k, R) {
|
|
|
311
312
|
error: e instanceof Error ? e.message : "Agent chat failed"
|
|
312
313
|
});
|
|
313
314
|
}
|
|
314
|
-
}),
|
|
315
|
-
const t =
|
|
315
|
+
}), C.enabled !== !1) {
|
|
316
|
+
const t = C.basePath ?? "/mcp";
|
|
316
317
|
i.post(`${t}`, {
|
|
317
|
-
bodyLimit:
|
|
318
|
+
bodyLimit: g,
|
|
318
319
|
schema: {
|
|
319
320
|
body: {
|
|
320
321
|
type: "object",
|
|
@@ -324,7 +325,7 @@ const N = function(i, k, R) {
|
|
|
324
325
|
}, async (r, e) => {
|
|
325
326
|
const a = K(
|
|
326
327
|
r.headers.origin,
|
|
327
|
-
|
|
328
|
+
C.allowedOrigins ? { allowedOrigins: C.allowedOrigins } : {}
|
|
328
329
|
);
|
|
329
330
|
if (!a.valid)
|
|
330
331
|
return e.status(403).send(x(null, -32600, a.reason));
|
|
@@ -340,14 +341,14 @@ const N = function(i, k, R) {
|
|
|
340
341
|
const o = z(r.body);
|
|
341
342
|
if (!o)
|
|
342
343
|
return e.status(400).send(x(null, -32600, "Invalid JSON-RPC 2.0 request"));
|
|
343
|
-
const
|
|
344
|
+
const u = _(n), b = o.method === "initialize";
|
|
344
345
|
try {
|
|
345
|
-
const
|
|
346
|
+
const l = await B(
|
|
346
347
|
o.method,
|
|
347
348
|
o.params,
|
|
348
349
|
{
|
|
349
350
|
semanticLayer: c,
|
|
350
|
-
extractSecurityContext:
|
|
351
|
+
extractSecurityContext: p,
|
|
351
352
|
rawRequest: r,
|
|
352
353
|
rawResponse: e,
|
|
353
354
|
negotiatedProtocol: s.negotiated
|
|
@@ -355,23 +356,23 @@ const N = function(i, k, R) {
|
|
|
355
356
|
);
|
|
356
357
|
if (j(o))
|
|
357
358
|
return e.status(202).send();
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
359
|
+
const y = b && l && typeof l == "object" && "sessionId" in l ? l.sessionId : void 0;
|
|
360
|
+
y && e.header(F, y);
|
|
361
|
+
const h = U(o.id ?? null, l);
|
|
362
|
+
if (u) {
|
|
362
363
|
const w = E();
|
|
363
364
|
e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${w}
|
|
364
365
|
|
|
365
|
-
${P(
|
|
366
|
+
${P(h, w)}`);
|
|
366
367
|
return;
|
|
367
368
|
}
|
|
368
|
-
return e.send(
|
|
369
|
-
} catch (
|
|
369
|
+
return e.send(h);
|
|
370
|
+
} catch (l) {
|
|
370
371
|
if (j(o))
|
|
371
|
-
return r.log.error(
|
|
372
|
-
r.log.error(
|
|
373
|
-
const
|
|
374
|
-
if (
|
|
372
|
+
return r.log.error(l, "MCP notification processing error"), e.status(202).send();
|
|
373
|
+
r.log.error(l, "MCP RPC error");
|
|
374
|
+
const y = l?.code ?? -32603, h = l?.data, w = l.message || "MCP request failed", Q = x(o.id ?? null, y, w, h);
|
|
375
|
+
if (u) {
|
|
375
376
|
const $ = E();
|
|
376
377
|
e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${$}
|
|
377
378
|
|
|
@@ -404,17 +405,17 @@ ${P(Q, $)}`);
|
|
|
404
405
|
i.setErrorHandler(async (t, r, e) => {
|
|
405
406
|
r.log.error(t, "Fastify cube adapter error"), e.statusCode < 400 && e.status(500);
|
|
406
407
|
const a = t instanceof Error ? t : String(t);
|
|
407
|
-
return
|
|
408
|
+
return d(a, e.statusCode);
|
|
408
409
|
}), R();
|
|
409
410
|
};
|
|
410
|
-
async function Z(
|
|
411
|
-
await
|
|
411
|
+
async function Z(v, i) {
|
|
412
|
+
await v.register(N, i);
|
|
412
413
|
}
|
|
413
|
-
function ee(
|
|
414
|
+
function ee(v) {
|
|
414
415
|
const i = require("fastify")({
|
|
415
416
|
logger: !0
|
|
416
417
|
});
|
|
417
|
-
return i.register(N,
|
|
418
|
+
return i.register(N, v), i;
|
|
418
419
|
}
|
|
419
420
|
export {
|
|
420
421
|
ee as createCubeApp,
|