drizzle-cube 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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-Bbz3qrIy.js → mcp-transport-Dmolep14.js} +31 -26
- package/dist/adapters/{mcp-transport-CXF4E5QJ.cjs → mcp-transport-h__yKJm9.cjs} +3 -3
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/client/chunks/{DashboardEditModal-Bv7e3Q7O.js → DashboardEditModal-D6TDeTBa.js} +1947 -1980
- package/dist/client/chunks/DashboardEditModal-D6TDeTBa.js.map +1 -0
- package/dist/client/chunks/{analysis-builder-BfH-w92z.js → analysis-builder-CIuNLos1.js} +101 -101
- package/dist/client/chunks/{analysis-builder-BfH-w92z.js.map → analysis-builder-CIuNLos1.js.map} +1 -1
- package/dist/client/chunks/{analysis-builder-shared-DsbdRCzz.js → analysis-builder-shared-gky0SKQH.js} +160 -159
- package/dist/client/chunks/analysis-builder-shared-gky0SKQH.js.map +1 -0
- package/dist/client/components/PortletAnalysisModal.d.ts +2 -2
- package/dist/client/components.js +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/utils/filterUtils.d.ts +6 -0
- package/dist/client-bundle-stats.html +1 -1
- package/dist/server/index.cjs +31 -31
- package/dist/server/index.js +1512 -1507
- package/package.json +1 -1
- package/dist/client/chunks/DashboardEditModal-Bv7e3Q7O.js.map +0 -1
- package/dist/client/chunks/analysis-builder-shared-DsbdRCzz.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("express"),H=require("cors"),i=require("../mcp-transport-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("express"),H=require("cors"),i=require("../mcp-transport-h__yKJm9.cjs"),s=require("../utils.cjs");function q(h){const{cubes:f,drizzle:C,schema:I,extractSecurityContext:p,engineType:P,cors:x,basePath:y="/cubejs-api/v1",jsonLimit:w="10mb",cache:M,mcp:j={enabled:!0}}=h;if(!f||f.length===0)throw new Error("At least one cube must be provided in the cubes array");const l=E.Router();x&&l.use(H(x)),l.use(E.json({limit:w})),l.use(E.urlencoded({extended:!0,limit:w}));const u=new i.SemanticLayerCompiler({drizzle:C,schema:I,engineType:P,cache:M});if(f.forEach(r=>{u.registerCube(r)}),l.post(`${y}/load`,async(r,t)=>{try{const e=r.body.query||r.body,o=await p(r,t),n=u.validateQuery(e);if(!n.isValid)return t.status(400).json(s.formatErrorResponse(`Query validation failed: ${n.errors.join(", ")}`,400));const a=r.headers["x-cache-control"]==="no-cache",c=await u.executeMultiCubeQuery(e,o,{skipCache:a});t.json(s.formatCubeResponse(e,c,u))}catch(e){console.error("Query execution error:",e),t.status(500).json(s.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),l.get(`${y}/load`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json(s.formatErrorResponse("Query parameter is required",400));let o;try{o=JSON.parse(e)}catch{return t.status(400).json(s.formatErrorResponse("Invalid JSON in query parameter",400))}const n=await p(r,t),a=u.validateQuery(o);if(!a.isValid)return t.status(400).json(s.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const c=r.headers["x-cache-control"]==="no-cache",m=await u.executeMultiCubeQuery(o,n,{skipCache:c});t.json(s.formatCubeResponse(o,m,u))}catch(e){console.error("Query execution error:",e),t.status(500).json(s.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),l.post(`${y}/batch`,async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).json(s.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).json(s.formatErrorResponse("Queries array cannot be empty",400));const o=await p(r,t),n=r.headers["x-cache-control"]==="no-cache",a=await s.handleBatchRequest(e,o,u,{skipCache:n});t.json(a)}catch(e){console.error("Batch execution error:",e),t.status(500).json(s.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),l.get(`${y}/meta`,(r,t)=>{try{const e=u.getMetadata();t.json(s.formatMetaResponse(e))}catch(e){console.error("Metadata error:",e),t.status(500).json(s.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),l.post(`${y}/sql`,async(r,t)=>{try{const e=r.body,o=await p(r,t),n=u.validateQuery(e);if(!n.isValid)return t.status(400).json(s.formatErrorResponse(`Query validation failed: ${n.errors.join(", ")}`,400));const a=e.measures?.[0]||e.dimensions?.[0];if(!a)return t.status(400).json(s.formatErrorResponse("No measures or dimensions specified",400));const c=a.split(".")[0],m=await u.generateSQL(c,e,o);t.json(s.formatSqlResponse(e,m))}catch(e){console.error("SQL generation error:",e),t.status(500).json(s.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),l.get(`${y}/sql`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json(s.formatErrorResponse("Query parameter is required",400));const o=JSON.parse(e),n=await p(r,t),a=u.validateQuery(o);if(!a.isValid)return t.status(400).json(s.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const c=o.measures?.[0]||o.dimensions?.[0];if(!c)return t.status(400).json(s.formatErrorResponse("No measures or dimensions specified",400));const m=c.split(".")[0],g=await u.generateSQL(m,o,n);t.json(s.formatSqlResponse(o,g))}catch(e){console.error("SQL generation error:",e),t.status(500).json(s.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),l.post(`${y}/dry-run`,async(r,t)=>{try{const e=r.body.query||r.body,o=await p(r,t),n=await s.handleDryRun(e,o,u);t.json(n)}catch(e){console.error("Dry-run error:",e),t.status(400).json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),l.get(`${y}/dry-run`,async(r,t)=>{try{const e=r.query.query;if(!e)return t.status(400).json({error:"Query parameter is required",valid:!1});const o=JSON.parse(e),n=await p(r,t),a=await s.handleDryRun(o,n,u);t.json(a)}catch(e){console.error("Dry-run error:",e),t.status(400).json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),l.post(`${y}/explain`,async(r,t)=>{try{const e=r.body.query||r.body,o=r.body.options||{},n=await p(r,t),a=u.validateQuery(e);if(!a.isValid)return t.status(400).json({error:`Query validation failed: ${a.errors.join(", ")}`});const c=await u.explainQuery(e,n,o);t.json(c)}catch(e){console.error("Explain error:",e),t.status(500).json({error:e instanceof Error?e.message:"Explain query failed"})}}),j.enabled!==!1){const r=j.basePath??"/mcp";l.post(`${r}`,async(t,e)=>{const o=i.validateOriginHeader(t.headers.origin,j.allowedOrigins?{allowedOrigins:j.allowedOrigins}:{});if(!o.valid)return e.status(403).json(i.buildJsonRpcError(null,-32600,o.reason));const n=t.headers.accept;if(!i.validateAcceptHeader(n))return e.status(400).json(i.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const a=i.negotiateProtocol(t.headers);if(!a.ok)return e.status(426).json({error:"Unsupported MCP protocol version",supported:a.supported});const c=i.parseJsonRpc(t.body);if(!c)return e.status(400).json(i.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const m=i.wantsEventStream(n),g=c.method==="initialize";try{const d=await i.dispatchMcpMethod(c.method,c.params,{semanticLayer:u,extractSecurityContext:p,rawRequest:t,rawResponse:e,negotiatedProtocol:a.negotiated});if(i.isNotification(c))return e.status(202).end();const v=g&&d&&typeof d=="object"&&"sessionId"in d?d.sessionId:void 0;v&&e.setHeader(i.MCP_SESSION_ID_HEADER,v);const b=i.buildJsonRpcResult(c.id??null,d);if(m){const R=i.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${R}
|
|
2
2
|
|
|
3
3
|
`),e.write(i.serializeSseEvent(b,R)),e.end()}return e.json(b)}catch(d){if(i.isNotification(c))return console.error("MCP notification processing error:",d),e.status(202).end();console.error("MCP RPC error:",d);const v=d?.code??-32603,b=d?.data,R=d.message||"MCP request failed",Q=i.buildJsonRpcError(c.id??null,v,R,b);if(m){const S=i.primeEventId();return e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(`id: ${S}
|
|
4
4
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import R, { Router as L } from "express";
|
|
2
2
|
import A from "cors";
|
|
3
|
-
import { S as J, v as D, b as C, a as _, n as V, p as z, w as B, d as T, i as M, M as F, c as U, e as w, s as Q } from "../mcp-transport-
|
|
3
|
+
import { S as J, v as D, b as C, a as _, n as V, p as z, w as B, d as T, i as M, M as F, c as U, e as w, s as Q } from "../mcp-transport-Dmolep14.js";
|
|
4
4
|
import { formatErrorResponse as c, formatCubeResponse as P, handleBatchRequest as G, formatMetaResponse as K, formatSqlResponse as H, handleDryRun as I } from "../utils.js";
|
|
5
5
|
function W(f) {
|
|
6
6
|
const {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var O=Object.create;var $=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var D=(l,s,b,v)=>{if(s&&typeof s=="object"||typeof s=="function")for(let m of k(s))!L.call(l,m)&&m!==b&&$(l,m,{get:()=>s[m],enumerable:!(v=J(s,m))||v.enumerable});return l};var z=(l,s,b)=>(b=l!=null?O(A(l)):{},D(s||!l||!l.__esModule?$(b,"default",{value:l,enumerable:!0}):b,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../mcp-transport-
|
|
1
|
+
"use strict";var O=Object.create;var $=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var D=(l,s,b,v)=>{if(s&&typeof s=="object"||typeof s=="function")for(let m of k(s))!L.call(l,m)&&m!==b&&$(l,m,{get:()=>s[m],enumerable:!(v=J(s,m))||v.enumerable});return l};var z=(l,s,b)=>(b=l!=null?O(A(l)):{},D(s||!l||!l.__esModule?$(b,"default",{value:l,enumerable:!0}):b,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../mcp-transport-h__yKJm9.cjs"),n=require("../utils.cjs"),q=function(s,b,v){const{cubes:m,drizzle:j,schema:I,extractSecurityContext:h,engineType:M,cors:S,basePath:g="/cubejs-api/v1",bodyLimit:f=10485760,cache:N,mcp:R={enabled:!0}}=b;if(!m||m.length===0)return v(new Error("At least one cube must be provided in the cubes array"));S&&s.register(import("@fastify/cors"),S),s.addHook("onRequest",async(r,t)=>{r.method==="POST"&&(r.body=void 0)});const d=new i.SemanticLayerCompiler({drizzle:j,schema:I,engineType:M,cache:N});if(m.forEach(r=>{d.registerCube(r)}),s.post(`${g}/load`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,a=await h(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const u=r.headers["x-cache-control"]==="no-cache",p=await d.executeMultiCubeQuery(o,a,{skipCache:u});return n.formatCubeResponse(o,p,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),s.get(`${g}/load`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query;let o;try{o=JSON.parse(e)}catch{return t.status(400).send(n.formatErrorResponse("Invalid JSON in query parameter",400))}const a=await h(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const u=r.headers["x-cache-control"]==="no-cache",p=await d.executeMultiCubeQuery(o,a,{skipCache:u});return n.formatCubeResponse(o,p,d)}catch(e){return r.log.error(e,"Query execution error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),s.post(`${g}/batch`,{bodyLimit:f,schema:{body:{type:"object",required:["queries"],properties:{queries:{type:"array",items:{type:"object"}}}}}},async(r,t)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return t.status(400).send(n.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).send(n.formatErrorResponse("Queries array cannot be empty",400));const o=await h(r),a=r.headers["x-cache-control"]==="no-cache";return await n.handleBatchRequest(e,o,d,{skipCache:a})}catch(e){return r.log.error(e,"Batch execution error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),s.get(`${g}/meta`,async(r,t)=>{try{const e=d.getMetadata();return n.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),s.post(`${g}/sql`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=await h(r),a=d.validateQuery(e);if(!a.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const c=e.measures?.[0]||e.dimensions?.[0];if(!c)return t.status(400).send(n.formatErrorResponse("No measures or dimensions specified",400));const u=c.split(".")[0],p=await d.generateSQL(u,e,o);return n.formatSqlResponse(e,p)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),s.get(`${g}/sql`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query,o=JSON.parse(e),a=await h(r),c=d.validateQuery(o);if(!c.isValid)return t.status(400).send(n.formatErrorResponse(`Query validation failed: ${c.errors.join(", ")}`,400));const u=o.measures?.[0]||o.dimensions?.[0];if(!u)return t.status(400).send(n.formatErrorResponse("No measures or dimensions specified",400));const p=u.split(".")[0],x=await d.generateSQL(p,o,a);return n.formatSqlResponse(o,x)}catch(e){return r.log.error(e,"SQL generation error"),t.status(500).send(n.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),s.post(`${g}/dry-run`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,a=await h(r);return await n.handleDryRun(o,a,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),s.get(`${g}/dry-run`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,t)=>{try{const{query:e}=r.query,o=JSON.parse(e),a=await h(r);return await n.handleDryRun(o,a,d)}catch(e){return r.log.error(e,"Dry-run error"),t.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),s.post(`${g}/explain`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(r,t)=>{try{const e=r.body,o=e.query||e,a=e.options||{},c=await h(r),u=d.validateQuery(o);return u.isValid?await d.explainQuery(o,c,a):t.status(400).send({error:`Query validation failed: ${u.errors.join(", ")}`})}catch(e){return r.log.error(e,"Explain error"),t.status(500).send({error:e instanceof Error?e.message:"Explain query failed"})}}),R.enabled!==!1){const r=R.basePath??"/mcp";s.post(`${r}`,{bodyLimit:f,schema:{body:{type:"object",additionalProperties:!0}}},async(t,e)=>{const o=i.validateOriginHeader(t.headers.origin,R.allowedOrigins?{allowedOrigins:R.allowedOrigins}:{});if(!o.valid)return e.status(403).send(i.buildJsonRpcError(null,-32600,o.reason));const a=t.headers.accept;if(!i.validateAcceptHeader(a))return e.status(400).send(i.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const c=i.negotiateProtocol(t.headers);if(!c.ok)return e.status(426).send({error:"Unsupported MCP protocol version",supported:c.supported});const u=i.parseJsonRpc(t.body);if(!u)return e.status(400).send(i.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const p=i.wantsEventStream(a),x=u.method==="initialize";try{const y=await i.dispatchMcpMethod(u.method,u.params,{semanticLayer:d,extractSecurityContext:h,rawRequest:t,rawResponse:e,negotiatedProtocol:c.negotiated});if(i.isNotification(u))return e.status(202).send();const E=x&&y&&typeof y=="object"&&"sessionId"in y?y.sessionId:void 0;E&&e.header(i.MCP_SESSION_ID_HEADER,E);const C=i.buildJsonRpcResult(u.id??null,y);if(p){const w=i.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${w}
|
|
2
2
|
|
|
3
3
|
${i.serializeSseEvent(C,w)}`);return}return e.send(C)}catch(y){if(i.isNotification(u))return t.log.error(y,"MCP notification processing error"),e.status(202).send();t.log.error(y,"MCP RPC error");const E=y?.code??-32603,C=y?.data,w=y.message||"MCP request failed",P=i.buildJsonRpcError(u.id??null,E,w,C);if(p){const Q=i.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${Q}
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as D, v as H, b as C, a as V, n as z, p as T, w as _, d as B, i as $, M as F, c as U, e as q, s as R } from "../mcp-transport-
|
|
1
|
+
import { S as D, v as H, b as C, a as V, n as z, p as T, w as _, d as B, i as $, M as F, c as U, e as q, s as R } from "../mcp-transport-Dmolep14.js";
|
|
2
2
|
import { formatErrorResponse as u, formatCubeResponse as j, handleBatchRequest as G, formatMetaResponse as K, formatSqlResponse as M, handleDryRun as I } from "../utils.js";
|
|
3
3
|
const N = function(n, O, E) {
|
|
4
4
|
const {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("hono"),s=require("../mcp-transport-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("hono"),s=require("../mcp-transport-h__yKJm9.cjs"),w=require("../utils.cjs");var J=C=>{const d={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...C},P=(l=>typeof l=="string"?l==="*"?()=>l:a=>l===a?a:null:typeof l=="function"?l:a=>l.includes(a)?a:null)(d.origin),y=(l=>typeof l=="function"?l:Array.isArray(l)?()=>l:()=>[])(d.allowMethods);return async function(a,f){function q(u,o){a.res.headers.set(u,o)}const v=await P(a.req.header("origin")||"",a);if(v&&q("Access-Control-Allow-Origin",v),d.credentials&&q("Access-Control-Allow-Credentials","true"),d.exposeHeaders?.length&&q("Access-Control-Expose-Headers",d.exposeHeaders.join(",")),a.req.method==="OPTIONS"){d.origin!=="*"&&q("Vary","Origin"),d.maxAge!=null&&q("Access-Control-Max-Age",d.maxAge.toString());const u=await y(a.req.header("origin")||"",a);u.length&&q("Access-Control-Allow-Methods",u.join(","));let o=d.allowHeaders;if(!o?.length){const r=a.req.header("Access-Control-Request-Headers");r&&(o=r.split(/\s*,\s*/))}return o?.length&&(q("Access-Control-Allow-Headers",o.join(",")),a.res.headers.append("Vary","Access-Control-Request-Headers")),a.res.headers.delete("Content-Length"),a.res.headers.delete("Content-Type"),new Response(null,{headers:a.res.headers,status:204,statusText:"No Content"})}await f(),d.origin!=="*"&&a.header("Vary","Origin",{append:!0})}};function I(C){const{cubes:j,drizzle:d,schema:P,extractSecurityContext:y,engineType:l,cors:a,basePath:f="/cubejs-api/v1",cache:q,mcp:v={enabled:!0}}=C;if(!j||j.length===0)throw new Error("At least one cube must be provided in the cubes array");const u=new T.Hono;a&&u.use("/*",J(a));const o=new s.SemanticLayerCompiler({drizzle:d,schema:P,engineType:l,cache:q});if(j.forEach(r=>{o.registerCube(r)}),u.post(`${f}/load`,async r=>{try{const e=await r.req.json(),n=e.query||e,i=await y(r),t=o.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const c=r.req.header("x-cache-control")==="no-cache",p=await o.executeMultiCubeQuery(n,i,{skipCache:c});return r.json(w.formatCubeResponse(n,p,o))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),u.get(`${f}/load`,async r=>{try{const e=r.req.query("query");if(!e)return r.json({error:"Query parameter is required"},400);let n;try{n=JSON.parse(e)}catch{return r.json({error:"Invalid JSON in query parameter"},400)}const i=await y(r),t=o.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const c=r.req.header("x-cache-control")==="no-cache",p=await o.executeMultiCubeQuery(n,i,{skipCache:c});return r.json(w.formatCubeResponse(n,p,o))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),u.post(`${f}/batch`,async r=>{try{const e=await r.req.json(),{queries:n}=e;if(!n||!Array.isArray(n))return r.json({error:'Request body must contain a "queries" array'},400);if(n.length===0)return r.json({error:"Queries array cannot be empty"},400);const i=await y(r),t=r.req.header("x-cache-control")==="no-cache",c=await w.handleBatchRequest(n,i,o,{skipCache:t});return r.json(c)}catch(e){return console.error("Batch execution error:",e),r.json({error:e instanceof Error?e.message:"Batch execution failed"},500)}}),u.get(`${f}/meta`,r=>{try{const e=o.getMetadata();return r.json(w.formatMetaResponse(e))}catch(e){return console.error("Metadata error:",e),r.json({error:e instanceof Error?e.message:"Failed to fetch metadata"},500)}}),u.post(`${f}/sql`,async r=>{try{const e=await r.req.json(),n=await y(r),i=o.validateQuery(e);if(!i.isValid)return r.json({error:`Query validation failed: ${i.errors.join(", ")}`},400);const t=e.measures?.[0]||e.dimensions?.[0];if(!t)return r.json({error:"No measures or dimensions specified"},400);const c=t.split(".")[0],p=await o.generateSQL(c,e,n);return r.json(w.formatSqlResponse(e,p))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),u.get(`${f}/sql`,async r=>{try{const e=r.req.query("query");if(!e)return r.json({error:"Query parameter is required"},400);const n=JSON.parse(e),i=await y(r),t=o.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const c=n.measures?.[0]||n.dimensions?.[0];if(!c)return r.json({error:"No measures or dimensions specified"},400);const p=c.split(".")[0],g=await o.generateSQL(p,n,i);return r.json(w.formatSqlResponse(n,g))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),u.post(`${f}/dry-run`,async r=>{try{const e=await r.req.json(),n=e.query||e,i=await y(r),t=await w.handleDryRun(n,i,o);return r.json(t)}catch(e){return console.error("Dry-run error:",e),r.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},400)}}),u.get(`${f}/dry-run`,async r=>{try{const e=r.req.query("query");if(!e)return r.json({error:"Query parameter is required",valid:!1},400);const n=JSON.parse(e),i=await y(r),t=await w.handleDryRun(n,i,o);return r.json(t)}catch(e){return console.error("Dry-run error:",e),r.json({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1},400)}}),u.post(`${f}/explain`,async r=>{try{const e=await r.req.json(),n=e.query||e,i=e.options||{},t=await y(r),c=o.validateQuery(n);if(!c.isValid)return r.json({error:`Query validation failed: ${c.errors.join(", ")}`},400);const p=await o.explainQuery(n,t,i);return r.json(p)}catch(e){return console.error("Explain error:",e),r.json({error:e instanceof Error?e.message:"Explain query failed"},500)}}),v.enabled!==!1){const r={uri:"drizzle-cube://schema",name:"Cube Schema",description:"Current cube metadata as JSON",mimeType:"application/json",text:JSON.stringify(o.getMetadata(),null,2)},e=[...s.getDefaultResources(),r],n=s.getDefaultPrompts(),i=v.basePath??"/mcp";u.post(`${i}`,async t=>{const c=s.validateOriginHeader(t.req.header("origin"),v.allowedOrigins?{allowedOrigins:v.allowedOrigins}:{});if(!c.valid)return t.json(s.buildJsonRpcError(null,-32600,c.reason),403);const p=t.req.header("accept");if(!s.validateAcceptHeader(p))return t.json(s.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),400);const g=s.negotiateProtocol(t.req.header());if(!g.ok)return t.json({error:"Unsupported MCP protocol version",supported:g.supported},426);const H=await t.req.json().catch(()=>null),m=s.parseJsonRpc(H);if(!m)return t.json(s.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),400);const $=s.wantsEventStream(p),O=m.method==="initialize";try{const h=await s.dispatchMcpMethod(m.method,m.params,{semanticLayer:o,extractSecurityContext:y,rawRequest:t,rawResponse:null,negotiatedProtocol:g.negotiated,resources:e,prompts:n});if(s.isNotification(m))return t.body(null,202);const S=s.buildJsonRpcResult(m.id??null,h),A=O&&h&&typeof h=="object"&&"sessionId"in h?h.sessionId:void 0,b={};if(A&&(b[s.MCP_SESSION_ID_HEADER]=A),$){const R=new TextEncoder,x=s.primeEventId(),Q=new ReadableStream({start(E){E.enqueue(R.encode(`id: ${x}
|
|
2
2
|
|
|
3
3
|
`)),E.enqueue(R.encode(s.serializeSseEvent(S,x))),E.close()}});return new Response(Q,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...b}})}return t.json(S,200,b)}catch(h){if(s.isNotification(m))return console.error("MCP notification processing error:",h),t.body(null,202);console.error("MCP RPC error:",h);const S=h?.code??-32603,A=h?.data,b=h.message||"MCP request failed",R=s.buildJsonRpcError(m.id??null,S,b,A);if($){const x=new TextEncoder,Q=s.primeEventId(),E=new ReadableStream({start(M){M.enqueue(x.encode(`id: ${Q}
|
|
4
4
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Hono as J } from "hono";
|
|
2
|
-
import { S as k, v as V, b as Q, a as B, n as z, p as _, w as U, d as F, g as G, f as K, i as I, c as W, M as X, e as $, s as H } from "../mcp-transport-
|
|
2
|
+
import { S as k, v as V, b as Q, a as B, n as z, p as _, w as U, d as F, g as G, f as K, i as I, c as W, M as X, e as $, s as H } from "../mcp-transport-Dmolep14.js";
|
|
3
3
|
import { formatCubeResponse as N, handleBatchRequest as Y, formatMetaResponse as Z, formatSqlResponse as O, handleDryRun as D } from "../utils.js";
|
|
4
4
|
var ee = (q) => {
|
|
5
5
|
const l = {
|
|
@@ -492,7 +492,7 @@ function _e(d) {
|
|
|
492
492
|
function Mt(d) {
|
|
493
493
|
return r`count(distinct ${d})`.mapWith(Number);
|
|
494
494
|
}
|
|
495
|
-
function
|
|
495
|
+
function V(d) {
|
|
496
496
|
return r`sum(${d})`.mapWith(String);
|
|
497
497
|
}
|
|
498
498
|
function H(d) {
|
|
@@ -2509,7 +2509,7 @@ function ze(d, e, t) {
|
|
|
2509
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 z(d) {
|
|
2513
2513
|
return typeof d == "function" ? d() : d;
|
|
2514
2514
|
}
|
|
2515
2515
|
function ve(d, e) {
|
|
@@ -3516,7 +3516,7 @@ class L {
|
|
|
3516
3516
|
case "count":
|
|
3517
3517
|
case "countDistinct":
|
|
3518
3518
|
case "sum":
|
|
3519
|
-
h =
|
|
3519
|
+
h = V(f);
|
|
3520
3520
|
break;
|
|
3521
3521
|
case "avg":
|
|
3522
3522
|
h = this.databaseAdapter.buildAvg(f);
|
|
@@ -3528,10 +3528,10 @@ class L {
|
|
|
3528
3528
|
h = H(f);
|
|
3529
3529
|
break;
|
|
3530
3530
|
case "number":
|
|
3531
|
-
h =
|
|
3531
|
+
h = V(f);
|
|
3532
3532
|
break;
|
|
3533
3533
|
default:
|
|
3534
|
-
h =
|
|
3534
|
+
h = V(f);
|
|
3535
3535
|
}
|
|
3536
3536
|
o.set(u, () => h);
|
|
3537
3537
|
}
|
|
@@ -3573,7 +3573,7 @@ class L {
|
|
|
3573
3573
|
case "count":
|
|
3574
3574
|
case "countDistinct":
|
|
3575
3575
|
case "sum":
|
|
3576
|
-
return
|
|
3576
|
+
return V(a);
|
|
3577
3577
|
case "avg":
|
|
3578
3578
|
return this.databaseAdapter.buildAvg(a);
|
|
3579
3579
|
case "min":
|
|
@@ -3581,9 +3581,9 @@ class L {
|
|
|
3581
3581
|
case "max":
|
|
3582
3582
|
return H(a);
|
|
3583
3583
|
case "number":
|
|
3584
|
-
return
|
|
3584
|
+
return V(a);
|
|
3585
3585
|
default:
|
|
3586
|
-
return
|
|
3586
|
+
return V(a);
|
|
3587
3587
|
}
|
|
3588
3588
|
}
|
|
3589
3589
|
}
|
|
@@ -3629,7 +3629,7 @@ class L {
|
|
|
3629
3629
|
case "countDistinct":
|
|
3630
3630
|
return Mt(i);
|
|
3631
3631
|
case "sum":
|
|
3632
|
-
return
|
|
3632
|
+
return V(i);
|
|
3633
3633
|
case "avg":
|
|
3634
3634
|
return this.databaseAdapter.buildAvg(i);
|
|
3635
3635
|
case "min":
|
|
@@ -4325,7 +4325,7 @@ class ae {
|
|
|
4325
4325
|
const { cube: u, path: c } = o.shift(), l = this.cubes.get(u);
|
|
4326
4326
|
if (l?.joins)
|
|
4327
4327
|
for (const [, m] of Object.entries(l.joins)) {
|
|
4328
|
-
const f =
|
|
4328
|
+
const f = z(m.targetCube).name;
|
|
4329
4329
|
if (a.has(f))
|
|
4330
4330
|
continue;
|
|
4331
4331
|
const h = [
|
|
@@ -4445,7 +4445,7 @@ class ae {
|
|
|
4445
4445
|
const l = this.cubes.get(a);
|
|
4446
4446
|
if (l?.joins)
|
|
4447
4447
|
for (const [, m] of Object.entries(l.joins)) {
|
|
4448
|
-
const f =
|
|
4448
|
+
const f = z(m.targetCube).name;
|
|
4449
4449
|
if (c.has(f))
|
|
4450
4450
|
continue;
|
|
4451
4451
|
const h = [
|
|
@@ -4511,7 +4511,7 @@ class ae {
|
|
|
4511
4511
|
const i = n.shift(), s = this.cubes.get(i);
|
|
4512
4512
|
if (s?.joins)
|
|
4513
4513
|
for (const [, o] of Object.entries(s.joins)) {
|
|
4514
|
-
const u =
|
|
4514
|
+
const u = z(o.targetCube).name;
|
|
4515
4515
|
t.has(u) || (t.add(u), n.push(u));
|
|
4516
4516
|
}
|
|
4517
4517
|
}
|
|
@@ -4856,7 +4856,7 @@ class mn {
|
|
|
4856
4856
|
for (const [, n] of e)
|
|
4857
4857
|
if (n.name !== t && n.joins) {
|
|
4858
4858
|
for (const [, i] of Object.entries(n.joins))
|
|
4859
|
-
if (
|
|
4859
|
+
if (z(i.targetCube).name === t)
|
|
4860
4860
|
return { sourceCube: n, joinDef: i };
|
|
4861
4861
|
}
|
|
4862
4862
|
return null;
|
|
@@ -4960,19 +4960,19 @@ class mn {
|
|
|
4960
4960
|
findJoinInfoForCube(e, t, n) {
|
|
4961
4961
|
if (t.joins) {
|
|
4962
4962
|
for (const [, s] of Object.entries(t.joins))
|
|
4963
|
-
if (
|
|
4963
|
+
if (z(s.targetCube).name === n)
|
|
4964
4964
|
return { sourceCube: t, joinDef: s };
|
|
4965
4965
|
}
|
|
4966
4966
|
const i = e.get(n);
|
|
4967
4967
|
if (i?.joins) {
|
|
4968
4968
|
for (const [, s] of Object.entries(i.joins))
|
|
4969
|
-
if (
|
|
4969
|
+
if (z(s.targetCube).name === t.name)
|
|
4970
4970
|
return { sourceCube: i, joinDef: s, reversed: !0 };
|
|
4971
4971
|
}
|
|
4972
4972
|
for (const [, s] of e)
|
|
4973
4973
|
if (!(s.name === t.name || s.name === n) && s.joins) {
|
|
4974
4974
|
for (const [, o] of Object.entries(s.joins))
|
|
4975
|
-
if (
|
|
4975
|
+
if (z(o.targetCube).name === n)
|
|
4976
4976
|
return { sourceCube: s, joinDef: o };
|
|
4977
4977
|
}
|
|
4978
4978
|
return null;
|
|
@@ -5002,9 +5002,14 @@ class mn {
|
|
|
5002
5002
|
const [a] = o.dimension.split(".");
|
|
5003
5003
|
a !== e.name && s.add(a);
|
|
5004
5004
|
}
|
|
5005
|
+
if (t.filters) {
|
|
5006
|
+
for (const o of t.filters)
|
|
5007
|
+
this.extractCubeNamesFromFilter(o, s);
|
|
5008
|
+
s.delete(e.name);
|
|
5009
|
+
}
|
|
5005
5010
|
if (e.joins)
|
|
5006
5011
|
for (const [, o] of Object.entries(e.joins)) {
|
|
5007
|
-
const u =
|
|
5012
|
+
const u = z(o.targetCube).name;
|
|
5008
5013
|
if (s.has(u)) {
|
|
5009
5014
|
let c;
|
|
5010
5015
|
o.relationship === "belongsToMany" && o.through ? c = o.through.sourceKey.map((l) => ({
|
|
@@ -5065,7 +5070,7 @@ class mn {
|
|
|
5065
5070
|
if (!e.joins)
|
|
5066
5071
|
return null;
|
|
5067
5072
|
for (const [, n] of Object.entries(e.joins))
|
|
5068
|
-
if (
|
|
5073
|
+
if (z(n.targetCube).name === t && n.relationship === "hasMany")
|
|
5069
5074
|
return n;
|
|
5070
5075
|
return null;
|
|
5071
5076
|
}
|
|
@@ -5093,7 +5098,7 @@ class mn {
|
|
|
5093
5098
|
const a = n.get(o);
|
|
5094
5099
|
if (a?.joins) {
|
|
5095
5100
|
for (const [, u] of Object.entries(a.joins))
|
|
5096
|
-
if (
|
|
5101
|
+
if (z(u.targetCube).name === t.name && u.relationship === "hasMany") {
|
|
5097
5102
|
const l = this.extractFiltersForCube(e.filters, o), m = this.extractTimeDimensionFiltersForCube(e, o), p = [...l, ...m];
|
|
5098
5103
|
p.length > 0 && u.on.length > 0 && i.push({
|
|
5099
5104
|
sourceCube: a,
|
|
@@ -8137,7 +8142,7 @@ function vn(d, e, t, n, i) {
|
|
|
8137
8142
|
case "count":
|
|
8138
8143
|
case "countDistinct":
|
|
8139
8144
|
case "sum":
|
|
8140
|
-
h = b ? H(f) :
|
|
8145
|
+
h = b ? H(f) : V(f);
|
|
8141
8146
|
break;
|
|
8142
8147
|
case "avg":
|
|
8143
8148
|
h = b ? H(f) : i.databaseAdapter.buildAvg(f);
|
|
@@ -8149,10 +8154,10 @@ function vn(d, e, t, n, i) {
|
|
|
8149
8154
|
h = H(f);
|
|
8150
8155
|
break;
|
|
8151
8156
|
case "number":
|
|
8152
|
-
h =
|
|
8157
|
+
h = H(f);
|
|
8153
8158
|
break;
|
|
8154
8159
|
default:
|
|
8155
|
-
h = b ? H(f) :
|
|
8160
|
+
h = b ? H(f) : V(f);
|
|
8156
8161
|
}
|
|
8157
8162
|
}
|
|
8158
8163
|
o[c] = r`${h}`.as(c);
|
|
@@ -8720,23 +8725,23 @@ class Ln {
|
|
|
8720
8725
|
E
|
|
8721
8726
|
);
|
|
8722
8727
|
}
|
|
8723
|
-
let
|
|
8728
|
+
let q = n.db.with(S, yt).select(X).from(r`${r.identifier(c)}`);
|
|
8724
8729
|
const be = f.map(
|
|
8725
8730
|
(E, _) => k(
|
|
8726
8731
|
r`${r.identifier(c)}.${r.identifier(E)}`,
|
|
8727
8732
|
r`${r.identifier(l)}.${r.identifier(u[_])}`
|
|
8728
8733
|
)
|
|
8729
8734
|
), Ct = be.length === 1 ? be[0] : A(...be);
|
|
8730
|
-
|
|
8735
|
+
q = q.leftJoin(r`${r.identifier(l)}`, Ct);
|
|
8731
8736
|
const Oe = [
|
|
8732
8737
|
...(t.dimensions ?? []).map((E) => r`${r.identifier(c)}.${r.identifier(E)}`),
|
|
8733
8738
|
...(t.timeDimensions ?? []).map(
|
|
8734
8739
|
(E) => r`${r.identifier(c)}.${r.identifier(E.dimension)}`
|
|
8735
8740
|
)
|
|
8736
8741
|
];
|
|
8737
|
-
Oe.length > 0 && (
|
|
8742
|
+
Oe.length > 0 && (q = q.groupBy(...Oe));
|
|
8738
8743
|
const Le = i.queryBuilder.buildOrderBy(t, Object.keys(X));
|
|
8739
|
-
return Le.length > 0 && (
|
|
8744
|
+
return Le.length > 0 && (q = q.orderBy(...Le)), q = i.queryBuilder.applyLimitAndOffset(q, t), q;
|
|
8740
8745
|
}
|
|
8741
8746
|
tryBuildMultiFactMergeQuery(e, t, n, i) {
|
|
8742
8747
|
const s = e.multiFactMerge;
|