drizzle-cube 0.3.23 → 0.3.25

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.
Files changed (129) hide show
  1. package/dist/adapters/express/index.cjs +4 -4
  2. package/dist/adapters/express/index.js +26 -25
  3. package/dist/adapters/fastify/index.cjs +4 -4
  4. package/dist/adapters/fastify/index.js +38 -37
  5. package/dist/adapters/hono/index.cjs +4 -4
  6. package/dist/adapters/hono/index.js +40 -39
  7. package/dist/adapters/mcp-transport-B4BZSsMC.js +9723 -0
  8. package/dist/adapters/mcp-transport-C8pLznZG.cjs +257 -0
  9. package/dist/adapters/nextjs/index.cjs +3 -3
  10. package/dist/adapters/nextjs/index.js +44 -43
  11. package/dist/adapters/types.cjs +1 -0
  12. package/dist/adapters/types.js +1 -0
  13. package/dist/adapters/utils.cjs +19 -0
  14. package/dist/adapters/utils.d.ts +24 -0
  15. package/dist/adapters/utils.js +21342 -0
  16. package/dist/client/charts.d.ts +1 -1
  17. package/dist/client/charts.js +172 -40
  18. package/dist/client/charts.js.map +1 -1
  19. package/dist/client/chunks/{components-vl_fdWud.js → DashboardEditModal-CVMSvpJ-.js} +2737 -3099
  20. package/dist/client/chunks/DashboardEditModal-CVMSvpJ-.js.map +1 -0
  21. package/dist/client/chunks/{RetentionCombinedChart-DpEKFYsd.js → RetentionCombinedChart-BVKWmxc-.js} +2 -2
  22. package/dist/client/chunks/{RetentionCombinedChart-DpEKFYsd.js.map → RetentionCombinedChart-BVKWmxc-.js.map} +1 -1
  23. package/dist/client/chunks/{analysis-builder-DiaxkEY-.js → analysis-builder-CuTR61Ct.js} +2814 -3547
  24. package/dist/client/chunks/analysis-builder-CuTR61Ct.js.map +1 -0
  25. package/dist/client/chunks/analysis-builder-shared-D7iqklYk.js +3211 -0
  26. package/dist/client/chunks/analysis-builder-shared-D7iqklYk.js.map +1 -0
  27. package/dist/client/chunks/{chart-activity-grid-CCGyWo1c.js → chart-activity-grid-BcMRkaq4.js} +2 -2
  28. package/dist/client/chunks/{chart-activity-grid-CCGyWo1c.js.map → chart-activity-grid-BcMRkaq4.js.map} +1 -1
  29. package/dist/client/chunks/{chart-area-ZZp1libT.js → chart-area-KlBSb_ur.js} +3 -3
  30. package/dist/client/chunks/{chart-area-ZZp1libT.js.map → chart-area-KlBSb_ur.js.map} +1 -1
  31. package/dist/client/chunks/{chart-bar-B4grbo6Q.js → chart-bar-D1i2jmIg.js} +2 -2
  32. package/dist/client/chunks/{chart-bar-B4grbo6Q.js.map → chart-bar-D1i2jmIg.js.map} +1 -1
  33. package/dist/client/chunks/{chart-bubble-BGGAQQUQ.js → chart-bubble-BFjnOwNZ.js} +2 -2
  34. package/dist/client/chunks/{chart-bubble-BGGAQQUQ.js.map → chart-bubble-BFjnOwNZ.js.map} +1 -1
  35. package/dist/client/chunks/{chart-data-table-BcH_h6kZ.js → chart-data-table-CYMMAHau.js} +39 -30
  36. package/dist/client/chunks/{chart-data-table-BcH_h6kZ.js.map → chart-data-table-CYMMAHau.js.map} +1 -1
  37. package/dist/client/chunks/{chart-funnel-DI8RMacf.js → chart-funnel-BH7r4HWZ.js} +2 -2
  38. package/dist/client/chunks/{chart-funnel-DI8RMacf.js.map → chart-funnel-BH7r4HWZ.js.map} +1 -1
  39. package/dist/client/chunks/{chart-heat-map-D3xNV9ep.js → chart-heat-map-DyGtODLE.js} +2 -2
  40. package/dist/client/chunks/{chart-heat-map-D3xNV9ep.js.map → chart-heat-map-DyGtODLE.js.map} +1 -1
  41. package/dist/client/chunks/{chart-kpi-delta-BJMQKPor.js → chart-kpi-delta-Bk396suk.js} +3 -3
  42. package/dist/client/chunks/{chart-kpi-delta-BJMQKPor.js.map → chart-kpi-delta-Bk396suk.js.map} +1 -1
  43. package/dist/client/chunks/{chart-kpi-number-B8u4tWmu.js → chart-kpi-number-CIGqZ5Dw.js} +34 -31
  44. package/dist/client/chunks/{chart-kpi-number-B8u4tWmu.js.map → chart-kpi-number-CIGqZ5Dw.js.map} +1 -1
  45. package/dist/client/chunks/{chart-kpi-text--r1d4zAz.js → chart-kpi-text-iwlaSQCi.js} +3 -3
  46. package/dist/client/chunks/{chart-kpi-text--r1d4zAz.js.map → chart-kpi-text-iwlaSQCi.js.map} +1 -1
  47. package/dist/client/chunks/chart-line-BKqhoW9A.js +450 -0
  48. package/dist/client/chunks/{chart-line-K0ACw4cV.js.map → chart-line-BKqhoW9A.js.map} +1 -1
  49. package/dist/client/chunks/{chart-pie-DC7axSwd.js → chart-pie-BNr-GgTh.js} +2 -2
  50. package/dist/client/chunks/{chart-pie-DC7axSwd.js.map → chart-pie-BNr-GgTh.js.map} +1 -1
  51. package/dist/client/chunks/{chart-radar-BDKgpLw5.js → chart-radar-CYrGVYEQ.js} +2 -2
  52. package/dist/client/chunks/{chart-radar-BDKgpLw5.js.map → chart-radar-CYrGVYEQ.js.map} +1 -1
  53. package/dist/client/chunks/{chart-radial-bar-BYNng7Nz.js → chart-radial-bar-2PR3ucIR.js} +2 -2
  54. package/dist/client/chunks/{chart-radial-bar-BYNng7Nz.js.map → chart-radial-bar-2PR3ucIR.js.map} +1 -1
  55. package/dist/client/chunks/{chart-sankey-CpsKerey.js → chart-sankey-C7w7h2ZV.js} +2 -2
  56. package/dist/client/chunks/{chart-sankey-CpsKerey.js.map → chart-sankey-C7w7h2ZV.js.map} +1 -1
  57. package/dist/client/chunks/{chart-scatter-CXqFltJg.js → chart-scatter-D3Z9bl8H.js} +2 -2
  58. package/dist/client/chunks/{chart-scatter-CXqFltJg.js.map → chart-scatter-D3Z9bl8H.js.map} +1 -1
  59. package/dist/client/chunks/{chart-sunburst-DSsO2CzY.js → chart-sunburst-C4ydFeaK.js} +2 -2
  60. package/dist/client/chunks/{chart-sunburst-DSsO2CzY.js.map → chart-sunburst-C4ydFeaK.js.map} +1 -1
  61. package/dist/client/chunks/{chart-tree-map-D_SeBBD-.js → chart-tree-map-DCCmMyz1.js} +2 -2
  62. package/dist/client/chunks/{chart-tree-map-D_SeBBD-.js.map → chart-tree-map-DCCmMyz1.js.map} +1 -1
  63. package/dist/client/chunks/{charts-core-8jDh3mKC.js → charts-core-DIW3Dd7n.js} +133 -112
  64. package/dist/client/chunks/{charts-core-8jDh3mKC.js.map → charts-core-DIW3Dd7n.js.map} +1 -1
  65. package/dist/client/chunks/{charts-loader-DpJr9z2e.js → charts-loader-BCBnMYjH.js} +20 -20
  66. package/dist/client/chunks/{charts-loader-DpJr9z2e.js.map → charts-loader-BCBnMYjH.js.map} +1 -1
  67. package/dist/client/chunks/{core-BRC075EG.js → core-BITzuqYm.js} +2 -2
  68. package/dist/client/chunks/{core-BRC075EG.js.map → core-BITzuqYm.js.map} +1 -1
  69. package/dist/client/chunks/hooks-Dd_nnv0J.js +236 -0
  70. package/dist/client/chunks/hooks-Dd_nnv0J.js.map +1 -0
  71. package/dist/client/chunks/index-CApFCBF9.js +81 -0
  72. package/dist/client/chunks/index-CApFCBF9.js.map +1 -0
  73. package/dist/client/chunks/{providers-BBrUJB2U.js → providers-BjxD1ZmC.js} +119 -113
  74. package/dist/client/chunks/{providers-BBrUJB2U.js.map → providers-BjxD1ZmC.js.map} +1 -1
  75. package/dist/client/chunks/syntaxHighlighting-Cmqp7_Mx.js +34 -0
  76. package/dist/client/chunks/syntaxHighlighting-Cmqp7_Mx.js.map +1 -0
  77. package/dist/client/chunks/useDirtyStateTracking-B5g-bw7a.js +1231 -0
  78. package/dist/client/chunks/useDirtyStateTracking-B5g-bw7a.js.map +1 -0
  79. package/dist/client/chunks/{vendor-cTQhZ_G3.js → vendor-CJRtj0__.js} +145 -145
  80. package/dist/client/chunks/vendor-CJRtj0__.js.map +1 -0
  81. package/dist/client/components/AnalysisBuilder/types.d.ts +5 -0
  82. package/dist/client/components/charts/index.d.ts +1 -0
  83. package/dist/client/components/shared/DateRangeFilter.d.ts +1 -1
  84. package/dist/client/components/shared/FilterBuilder.d.ts +1 -1
  85. package/dist/client/components/shared/FilterGroup.d.ts +1 -1
  86. package/dist/client/components/shared/FilterItem.d.ts +1 -1
  87. package/dist/client/components/shared/FilterValueSelector.d.ts +1 -1
  88. package/dist/client/components/shared/types.d.ts +60 -0
  89. package/dist/client/components/shared/utils.d.ts +1 -1
  90. package/dist/client/components.d.ts +1 -1
  91. package/dist/client/components.js +352 -15
  92. package/dist/client/components.js.map +1 -1
  93. package/dist/client/hooks/queries/useCubeLoadQuery.d.ts +3 -0
  94. package/dist/client/hooks/useAnalysisBuilderHook.d.ts +5 -0
  95. package/dist/client/hooks/useAnalysisQueryExecution.d.ts +5 -0
  96. package/dist/client/hooks.d.ts +2 -2
  97. package/dist/client/hooks.js +20 -12
  98. package/dist/client/index.d.ts +16 -3
  99. package/dist/client/index.js +176 -138
  100. package/dist/client/index.js.map +1 -1
  101. package/dist/client/providers.js +1 -1
  102. package/dist/client/shared/types.d.ts +29 -0
  103. package/dist/client/styles.css +1 -1
  104. package/dist/client/utils.d.ts +1 -1
  105. package/dist/client/utils.js +73 -1
  106. package/dist/client/utils.js.map +1 -1
  107. package/dist/client-bundle-stats.html +1 -1
  108. package/dist/server/index.cjs +85 -85
  109. package/dist/server/index.d.ts +170 -4
  110. package/dist/server/index.js +3492 -3206
  111. package/package.json +12 -2
  112. package/dist/adapters/mcp-transport-lkEjNwDH.js +0 -30769
  113. package/dist/adapters/mcp-transport-oPf8JYHv.cjs +0 -275
  114. package/dist/client/chunks/analysis-builder-DiaxkEY-.js.map +0 -1
  115. package/dist/client/chunks/analysis-builder-shared-BzM5Vwpr.js +0 -2779
  116. package/dist/client/chunks/analysis-builder-shared-BzM5Vwpr.js.map +0 -1
  117. package/dist/client/chunks/chart-line-K0ACw4cV.js +0 -413
  118. package/dist/client/chunks/charts-T6qNi6FO.js +0 -230
  119. package/dist/client/chunks/charts-T6qNi6FO.js.map +0 -1
  120. package/dist/client/chunks/components-vl_fdWud.js.map +0 -1
  121. package/dist/client/chunks/hooks-CKYzVf_7.js +0 -150
  122. package/dist/client/chunks/hooks-CKYzVf_7.js.map +0 -1
  123. package/dist/client/chunks/useDirtyStateTracking-DDQ_Lbki.js +0 -795
  124. package/dist/client/chunks/useDirtyStateTracking-DDQ_Lbki.js.map +0 -1
  125. package/dist/client/chunks/vendor-cTQhZ_G3.js.map +0 -1
  126. package/dist/client/components/AxisDropZone.d.ts +0 -27
  127. package/dist/client/components/ChartConfigPanel.d.ts +0 -16
  128. package/dist/client/components/QueryBuilder/types.d.ts +0 -152
  129. package/dist/client/components/QueryBuilderShim.d.ts +0 -3
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("express"),M=require("cors"),r=require("../mcp-transport-oPf8JYHv.cjs");function S(f){const{cubes:m,drizzle:E,schema:$,extractSecurityContext:d,engineType:I,cors:g,basePath:p="/cubejs-api/v1",jsonLimit:x="10mb",cache:P,mcp:h={enabled:!0}}=f;if(!m||m.length===0)throw new Error("At least one cube must be provided in the cubes array");const u=R.Router();g&&u.use(M(g)),u.use(R.json({limit:x})),u.use(R.urlencoded({extended:!0,limit:x}));const c=new r.SemanticLayerCompiler({drizzle:E,schema:$,engineType:I,cache:P});if(m.forEach(o=>{c.registerCube(o)}),u.post(`${p}/load`,async(o,t)=>{try{const e=o.body.query||o.body,s=await d(o,t),n=c.validateQuery(e);if(!n.isValid)return t.status(400).json(r.formatErrorResponse(`Query validation failed: ${n.errors.join(", ")}`,400));const a=o.headers["x-cache-control"]==="no-cache",i=await c.executeMultiCubeQuery(e,s,{skipCache:a});t.json(r.formatCubeResponse(e,i,c))}catch(e){console.error("Query execution error:",e),t.status(500).json(r.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),u.get(`${p}/load`,async(o,t)=>{try{const e=o.query.query;if(!e)return t.status(400).json(r.formatErrorResponse("Query parameter is required",400));let s;try{s=JSON.parse(e)}catch{return t.status(400).json(r.formatErrorResponse("Invalid JSON in query parameter",400))}const n=await d(o,t),a=c.validateQuery(s);if(!a.isValid)return t.status(400).json(r.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const i=o.headers["x-cache-control"]==="no-cache",y=await c.executeMultiCubeQuery(s,n,{skipCache:i});t.json(r.formatCubeResponse(s,y,c))}catch(e){console.error("Query execution error:",e),t.status(500).json(r.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),u.post(`${p}/batch`,async(o,t)=>{try{const{queries:e}=o.body;if(!e||!Array.isArray(e))return t.status(400).json(r.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return t.status(400).json(r.formatErrorResponse("Queries array cannot be empty",400));const s=await d(o,t),n=o.headers["x-cache-control"]==="no-cache",a=await r.handleBatchRequest(e,s,c,{skipCache:n});t.json(a)}catch(e){console.error("Batch execution error:",e),t.status(500).json(r.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),u.get(`${p}/meta`,(o,t)=>{try{const e=c.getMetadata();t.json(r.formatMetaResponse(e))}catch(e){console.error("Metadata error:",e),t.status(500).json(r.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),u.post(`${p}/sql`,async(o,t)=>{try{const e=o.body,s=await d(o,t),n=c.validateQuery(e);if(!n.isValid)return t.status(400).json(r.formatErrorResponse(`Query validation failed: ${n.errors.join(", ")}`,400));const a=e.measures?.[0]||e.dimensions?.[0];if(!a)return t.status(400).json(r.formatErrorResponse("No measures or dimensions specified",400));const i=a.split(".")[0],y=await c.generateSQL(i,e,s);t.json(r.formatSqlResponse(e,y))}catch(e){console.error("SQL generation error:",e),t.status(500).json(r.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),u.get(`${p}/sql`,async(o,t)=>{try{const e=o.query.query;if(!e)return t.status(400).json(r.formatErrorResponse("Query parameter is required",400));const s=JSON.parse(e),n=await d(o,t),a=c.validateQuery(s);if(!a.isValid)return t.status(400).json(r.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const i=s.measures?.[0]||s.dimensions?.[0];if(!i)return t.status(400).json(r.formatErrorResponse("No measures or dimensions specified",400));const y=i.split(".")[0],C=await c.generateSQL(y,s,n);t.json(r.formatSqlResponse(s,C))}catch(e){console.error("SQL generation error:",e),t.status(500).json(r.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),u.post(`${p}/dry-run`,async(o,t)=>{try{const e=o.body.query||o.body,s=await d(o,t),n=await r.handleDryRun(e,s,c);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})}}),u.get(`${p}/dry-run`,async(o,t)=>{try{const e=o.query.query;if(!e)return t.status(400).json({error:"Query parameter is required",valid:!1});const s=JSON.parse(e),n=await d(o,t),a=await r.handleDryRun(s,n,c);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})}}),u.post(`${p}/explain`,async(o,t)=>{try{const e=o.body.query||o.body,s=o.body.options||{},n=await d(o,t),a=c.validateQuery(e);if(!a.isValid)return t.status(400).json({error:`Query validation failed: ${a.errors.join(", ")}`});const i=await c.explainQuery(e,n,s);t.json(i)}catch(e){console.error("Explain error:",e),t.status(500).json({error:e instanceof Error?e.message:"Explain query failed"})}}),h.enabled!==!1){const o=h.basePath??"/mcp";u.post(`${o}`,async(t,e)=>{const s=r.validateOriginHeader(t.headers.origin,h.allowedOrigins?{allowedOrigins:h.allowedOrigins}:{});if(!s.valid)return e.status(403).json(r.buildJsonRpcError(null,-32600,s.reason));const n=t.headers.accept;if(!r.validateAcceptHeader(n))return e.status(400).json(r.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const a=r.negotiateProtocol(t.headers);if(!a.ok)return e.status(426).json({error:"Unsupported MCP protocol version",supported:a.supported});const i=r.parseJsonRpc(t.body);if(!i)return e.status(400).json(r.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const y=r.wantsEventStream(n),C=i.method==="initialize";try{const l=await r.dispatchMcpMethod(i.method,i.params,{semanticLayer:c,extractSecurityContext:d,rawRequest:t,rawResponse:e,negotiatedProtocol:a.negotiated});if(r.isNotification(i))return e.status(202).end();const j=C&&l&&typeof l=="object"&&"sessionId"in l?l.sessionId:void 0;j&&e.setHeader(r.MCP_SESSION_ID_HEADER,j);const v=r.buildJsonRpcResult(i.id??null,l);if(y){const b=r.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: ${b}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("express"),H=require("cors"),i=require("../mcp-transport-C8pLznZG.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
- `),e.write(r.serializeSseEvent(v,b)),e.end()}return e.json(v)}catch(l){if(r.isNotification(i))return console.error("MCP notification processing error:",l),e.status(202).end();console.error("MCP RPC error:",l);const j=l?.code??-32603,v=l?.data,b=l.message||"MCP request failed",w=r.buildJsonRpcError(i.id??null,j,b,v);if(y){const Q=r.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: ${Q}
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
 
5
- `),e.write(r.serializeSseEvent(w,Q)),e.end()}return e.status(200).json(w)}}),u.get(`${o}`,async(t,e)=>{const s=r.primeEventId();e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(r.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},s,15e3));const n=setInterval(()=>{e.write(`: keep-alive
5
+ `),e.write(i.serializeSseEvent(Q,S)),e.end()}return e.status(200).json(Q)}}),l.get(`${r}`,async(t,e)=>{const o=i.primeEventId();e.status(200),e.setHeader("Content-Type","text/event-stream"),e.setHeader("Cache-Control","no-cache"),e.setHeader("Connection","keep-alive"),e.write(i.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const n=setInterval(()=>{e.write(`: keep-alive
6
6
 
7
- `)},15e3);t.on("close",()=>{clearInterval(n)})}),u.delete(`${o}`,(t,e)=>e.status(405).json({error:"Session termination not supported"}))}return u.use((o,t,e,s)=>{console.error("Express adapter error:",o),e.headersSent||e.status(500).json(r.formatErrorResponse(o,500))}),u}function q(f,m){const E=S(m);return f.use("/",E),f}function H(f){const m=R();return q(m,f)}exports.createCubeApp=H;exports.createCubeRouter=S;exports.mountCubeRoutes=q;
7
+ `)},15e3);t.on("close",()=>{clearInterval(n)})}),l.delete(`${r}`,(t,e)=>e.status(405).json({error:"Session termination not supported"}))}return l.use((r,t,e,o)=>{console.error("Express adapter error:",r),e.headersSent||e.status(500).json(s.formatErrorResponse(r,500))}),l}function $(h,f){const C=q(f);return h.use("/",C),h}function N(h){const f=E();return $(f,h)}exports.createCubeApp=N;exports.createCubeRouter=q;exports.mountCubeRoutes=$;
@@ -1,17 +1,18 @@
1
1
  import R, { Router as L } from "express";
2
2
  import A from "cors";
3
- import { S as J, o as c, f as M, h as D, a as _, b as P, c as H, v as V, d as C, e as z, n as B, p as T, w as F, g as U, k as I, M as G, l as K, m as w, s as Q } from "../mcp-transport-lkEjNwDH.js";
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-B4BZSsMC.js";
4
+ import { formatErrorResponse as c, formatCubeResponse as P, handleBatchRequest as G, formatMetaResponse as K, formatSqlResponse as H, handleDryRun as I } from "../utils.js";
4
5
  function W(f) {
5
6
  const {
6
7
  cubes: m,
7
8
  drizzle: g,
8
9
  schema: N,
9
10
  extractSecurityContext: l,
10
- engineType: k,
11
+ engineType: O,
11
12
  cors: E,
12
13
  basePath: y = "/cubejs-api/v1",
13
14
  jsonLimit: S = "10mb",
14
- cache: O,
15
+ cache: k,
15
16
  mcp: h = { enabled: !0 }
16
17
  } = f;
17
18
  if (!m || m.length === 0)
@@ -21,8 +22,8 @@ function W(f) {
21
22
  const i = new J({
22
23
  drizzle: g,
23
24
  schema: N,
24
- engineType: k,
25
- cache: O
25
+ engineType: O,
26
+ cache: k
26
27
  });
27
28
  if (m.forEach((r) => {
28
29
  i.registerCube(r);
@@ -35,7 +36,7 @@ function W(f) {
35
36
  400
36
37
  ));
37
38
  const s = r.headers["x-cache-control"] === "no-cache", n = await i.executeMultiCubeQuery(e, o, { skipCache: s });
38
- t.json(M(e, n, i));
39
+ t.json(P(e, n, i));
39
40
  } catch (e) {
40
41
  console.error("Query execution error:", e), t.status(500).json(c(
41
42
  e instanceof Error ? e.message : "Query execution failed",
@@ -66,7 +67,7 @@ function W(f) {
66
67
  400
67
68
  ));
68
69
  const n = r.headers["x-cache-control"] === "no-cache", p = await i.executeMultiCubeQuery(o, a, { skipCache: n });
69
- t.json(M(o, p, i));
70
+ t.json(P(o, p, i));
70
71
  } catch (e) {
71
72
  console.error("Query execution error:", e), t.status(500).json(c(
72
73
  e instanceof Error ? e.message : "Query execution failed",
@@ -86,7 +87,7 @@ function W(f) {
86
87
  "Queries array cannot be empty",
87
88
  400
88
89
  ));
89
- const o = await l(r, t), a = r.headers["x-cache-control"] === "no-cache", s = await D(e, o, i, { skipCache: a });
90
+ const o = await l(r, t), a = r.headers["x-cache-control"] === "no-cache", s = await G(e, o, i, { skipCache: a });
90
91
  t.json(s);
91
92
  } catch (e) {
92
93
  console.error("Batch execution error:", e), t.status(500).json(c(
@@ -97,7 +98,7 @@ function W(f) {
97
98
  }), u.get(`${y}/meta`, (r, t) => {
98
99
  try {
99
100
  const e = i.getMetadata();
100
- t.json(_(e));
101
+ t.json(K(e));
101
102
  } catch (e) {
102
103
  console.error("Metadata error:", e), t.status(500).json(c(
103
104
  e instanceof Error ? e.message : "Failed to fetch metadata",
@@ -119,7 +120,7 @@ function W(f) {
119
120
  400
120
121
  ));
121
122
  const n = s.split(".")[0], p = await i.generateSQL(n, e, o);
122
- t.json(P(e, p));
123
+ t.json(H(e, p));
123
124
  } catch (e) {
124
125
  console.error("SQL generation error:", e), t.status(500).json(c(
125
126
  e instanceof Error ? e.message : "SQL generation failed",
@@ -147,7 +148,7 @@ function W(f) {
147
148
  400
148
149
  ));
149
150
  const p = n.split(".")[0], x = await i.generateSQL(p, o, a);
150
- t.json(P(o, x));
151
+ t.json(H(o, x));
151
152
  } catch (e) {
152
153
  console.error("SQL generation error:", e), t.status(500).json(c(
153
154
  e instanceof Error ? e.message : "SQL generation failed",
@@ -156,7 +157,7 @@ function W(f) {
156
157
  }
157
158
  }), u.post(`${y}/dry-run`, async (r, t) => {
158
159
  try {
159
- const e = r.body.query || r.body, o = await l(r, t), a = await H(e, o, i);
160
+ const e = r.body.query || r.body, o = await l(r, t), a = await I(e, o, i);
160
161
  t.json(a);
161
162
  } catch (e) {
162
163
  console.error("Dry-run error:", e), t.status(400).json({
@@ -172,7 +173,7 @@ function W(f) {
172
173
  error: "Query parameter is required",
173
174
  valid: !1
174
175
  });
175
- const o = JSON.parse(e), a = await l(r, t), s = await H(o, a, i);
176
+ const o = JSON.parse(e), a = await l(r, t), s = await I(o, a, i);
176
177
  t.json(s);
177
178
  } catch (e) {
178
179
  console.error("Dry-run error:", e), t.status(400).json({
@@ -197,27 +198,27 @@ function W(f) {
197
198
  }), h.enabled !== !1) {
198
199
  const r = h.basePath ?? "/mcp";
199
200
  u.post(`${r}`, async (t, e) => {
200
- const o = V(
201
+ const o = D(
201
202
  t.headers.origin,
202
203
  h.allowedOrigins ? { allowedOrigins: h.allowedOrigins } : {}
203
204
  );
204
205
  if (!o.valid)
205
206
  return e.status(403).json(C(null, -32600, o.reason));
206
207
  const a = t.headers.accept;
207
- if (!z(a))
208
+ if (!_(a))
208
209
  return e.status(400).json(C(null, -32600, "Accept header must include both application/json and text/event-stream"));
209
- const s = B(t.headers);
210
+ const s = V(t.headers);
210
211
  if (!s.ok)
211
212
  return e.status(426).json({
212
213
  error: "Unsupported MCP protocol version",
213
214
  supported: s.supported
214
215
  });
215
- const n = T(t.body);
216
+ const n = z(t.body);
216
217
  if (!n)
217
218
  return e.status(400).json(C(null, -32600, "Invalid JSON-RPC 2.0 request"));
218
- const p = F(a), x = n.method === "initialize";
219
+ const p = B(a), x = n.method === "initialize";
219
220
  try {
220
- const d = await U(
221
+ const d = await T(
221
222
  n.method,
222
223
  n.params,
223
224
  {
@@ -228,11 +229,11 @@ function W(f) {
228
229
  negotiatedProtocol: s.negotiated
229
230
  }
230
231
  );
231
- if (I(n))
232
+ if (M(n))
232
233
  return e.status(202).end();
233
234
  const j = x && d && typeof d == "object" && "sessionId" in d ? d.sessionId : void 0;
234
- j && e.setHeader(G, j);
235
- const v = K(n.id ?? null, d);
235
+ j && e.setHeader(F, j);
236
+ const v = U(n.id ?? null, d);
236
237
  if (p) {
237
238
  const b = w();
238
239
  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: ${b}
@@ -241,7 +242,7 @@ function W(f) {
241
242
  }
242
243
  return e.json(v);
243
244
  } catch (d) {
244
- if (I(n))
245
+ if (M(n))
245
246
  return console.error("MCP notification processing error:", d), e.status(202).end();
246
247
  console.error("MCP RPC error:", d);
247
248
  const j = d?.code ?? -32603, v = d?.data, b = d.message || "MCP request failed", q = C(n.id ?? null, j, b, v);
@@ -278,12 +279,12 @@ function X(f, m) {
278
279
  const g = W(m);
279
280
  return f.use("/", g), f;
280
281
  }
281
- function te(f) {
282
+ function re(f) {
282
283
  const m = R();
283
284
  return X(m, f);
284
285
  }
285
286
  export {
286
- te as createCubeApp,
287
+ re as createCubeApp,
287
288
  W as createCubeRouter,
288
289
  X as mountCubeRoutes
289
290
  };
@@ -1,7 +1,7 @@
1
- "use strict";var N=Object.create;var Q=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var L=(d,n,g,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let y of J(n))!A.call(d,y)&&y!==g&&Q(d,y,{get:()=>n[y],enumerable:!(f=O(n,y))||f.enumerable});return d};var D=(d,n,g)=>(g=d!=null?N(k(d)):{},L(n||!d||!d.__esModule?Q(g,"default",{value:d,enumerable:!0}):g,d));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("../mcp-transport-oPf8JYHv.cjs"),x=function(n,g,f){const{cubes:y,drizzle:$,schema:j,extractSecurityContext:m,engineType:I,cors:q,basePath:h="/cubejs-api/v1",bodyLimit:b=10485760,cache:M,mcp:v={enabled:!0}}=g;if(!y||y.length===0)return f(new Error("At least one cube must be provided in the cubes array"));q&&n.register(import("@fastify/cors"),q),n.addHook("onRequest",async(r,o)=>{r.method==="POST"&&(r.body=void 0)});const u=new t.SemanticLayerCompiler({drizzle:$,schema:j,engineType:I,cache:M});if(y.forEach(r=>{u.registerCube(r)}),n.post(`${h}/load`,{bodyLimit:b,schema:{body:{type:"object",additionalProperties:!0}}},async(r,o)=>{try{const e=r.body,s=e.query||e,a=await m(r),i=u.validateQuery(s);if(!i.isValid)return o.status(400).send(t.formatErrorResponse(`Query validation failed: ${i.errors.join(", ")}`,400));const c=r.headers["x-cache-control"]==="no-cache",l=await u.executeMultiCubeQuery(s,a,{skipCache:c});return t.formatCubeResponse(s,l,u)}catch(e){return r.log.error(e,"Query execution error"),o.status(500).send(t.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.get(`${h}/load`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,o)=>{try{const{query:e}=r.query;let s;try{s=JSON.parse(e)}catch{return o.status(400).send(t.formatErrorResponse("Invalid JSON in query parameter",400))}const a=await m(r),i=u.validateQuery(s);if(!i.isValid)return o.status(400).send(t.formatErrorResponse(`Query validation failed: ${i.errors.join(", ")}`,400));const c=r.headers["x-cache-control"]==="no-cache",l=await u.executeMultiCubeQuery(s,a,{skipCache:c});return t.formatCubeResponse(s,l,u)}catch(e){return r.log.error(e,"Query execution error"),o.status(500).send(t.formatErrorResponse(e instanceof Error?e.message:"Query execution failed",500))}}),n.post(`${h}/batch`,{bodyLimit:b,schema:{body:{type:"object",required:["queries"],properties:{queries:{type:"array",items:{type:"object"}}}}}},async(r,o)=>{try{const{queries:e}=r.body;if(!e||!Array.isArray(e))return o.status(400).send(t.formatErrorResponse('Request body must contain a "queries" array',400));if(e.length===0)return o.status(400).send(t.formatErrorResponse("Queries array cannot be empty",400));const s=await m(r),a=r.headers["x-cache-control"]==="no-cache";return await t.handleBatchRequest(e,s,u,{skipCache:a})}catch(e){return r.log.error(e,"Batch execution error"),o.status(500).send(t.formatErrorResponse(e instanceof Error?e.message:"Batch execution failed",500))}}),n.get(`${h}/meta`,async(r,o)=>{try{const e=u.getMetadata();return t.formatMetaResponse(e)}catch(e){return r.log.error(e,"Metadata error"),o.status(500).send(t.formatErrorResponse(e instanceof Error?e.message:"Failed to fetch metadata",500))}}),n.post(`${h}/sql`,{bodyLimit:b,schema:{body:{type:"object",additionalProperties:!0}}},async(r,o)=>{try{const e=r.body,s=await m(r),a=u.validateQuery(e);if(!a.isValid)return o.status(400).send(t.formatErrorResponse(`Query validation failed: ${a.errors.join(", ")}`,400));const i=e.measures?.[0]||e.dimensions?.[0];if(!i)return o.status(400).send(t.formatErrorResponse("No measures or dimensions specified",400));const c=i.split(".")[0],l=await u.generateSQL(c,e,s);return t.formatSqlResponse(e,l)}catch(e){return r.log.error(e,"SQL generation error"),o.status(500).send(t.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.get(`${h}/sql`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,o)=>{try{const{query:e}=r.query,s=JSON.parse(e),a=await m(r),i=u.validateQuery(s);if(!i.isValid)return o.status(400).send(t.formatErrorResponse(`Query validation failed: ${i.errors.join(", ")}`,400));const c=s.measures?.[0]||s.dimensions?.[0];if(!c)return o.status(400).send(t.formatErrorResponse("No measures or dimensions specified",400));const l=c.split(".")[0],w=await u.generateSQL(l,s,a);return t.formatSqlResponse(s,w)}catch(e){return r.log.error(e,"SQL generation error"),o.status(500).send(t.formatErrorResponse(e instanceof Error?e.message:"SQL generation failed",500))}}),n.post(`${h}/dry-run`,{bodyLimit:b,schema:{body:{type:"object",additionalProperties:!0}}},async(r,o)=>{try{const e=r.body,s=e.query||e,a=await m(r);return await t.handleDryRun(s,a,u)}catch(e){return r.log.error(e,"Dry-run error"),o.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.get(`${h}/dry-run`,{schema:{querystring:{type:"object",properties:{query:{type:"string"}},required:["query"]}}},async(r,o)=>{try{const{query:e}=r.query,s=JSON.parse(e),a=await m(r);return await t.handleDryRun(s,a,u)}catch(e){return r.log.error(e,"Dry-run error"),o.status(400).send({error:e instanceof Error?e.message:"Dry-run validation failed",valid:!1})}}),n.post(`${h}/explain`,{bodyLimit:b,schema:{body:{type:"object",additionalProperties:!0}}},async(r,o)=>{try{const e=r.body,s=e.query||e,a=e.options||{},i=await m(r),c=u.validateQuery(s);return c.isValid?await u.explainQuery(s,i,a):o.status(400).send({error:`Query validation failed: ${c.errors.join(", ")}`})}catch(e){return r.log.error(e,"Explain error"),o.status(500).send({error:e instanceof Error?e.message:"Explain query failed"})}}),v.enabled!==!1){const r=v.basePath??"/mcp";n.post(`${r}`,{bodyLimit:b,schema:{body:{type:"object",additionalProperties:!0}}},async(o,e)=>{const s=t.validateOriginHeader(o.headers.origin,v.allowedOrigins?{allowedOrigins:v.allowedOrigins}:{});if(!s.valid)return e.status(403).send(t.buildJsonRpcError(null,-32600,s.reason));const a=o.headers.accept;if(!t.validateAcceptHeader(a))return e.status(400).send(t.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"));const i=t.negotiateProtocol(o.headers);if(!i.ok)return e.status(426).send({error:"Unsupported MCP protocol version",supported:i.supported});const c=t.parseJsonRpc(o.body);if(!c)return e.status(400).send(t.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"));const l=t.wantsEventStream(a),w=c.method==="initialize";try{const p=await t.dispatchMcpMethod(c.method,c.params,{semanticLayer:u,extractSecurityContext:m,rawRequest:o,rawResponse:e,negotiatedProtocol:i.negotiated});if(t.isNotification(c))return e.status(202).send();const R=w&&p&&typeof p=="object"&&"sessionId"in p?p.sessionId:void 0;R&&e.header(t.MCP_SESSION_ID_HEADER,R);const E=t.buildJsonRpcResult(c.id??null,p);if(l){const C=t.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${C}
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-C8pLznZG.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
- ${t.serializeSseEvent(E,C)}`);return}return e.send(E)}catch(p){if(t.isNotification(c))return o.log.error(p,"MCP notification processing error"),e.status(202).send();o.log.error(p,"MCP RPC error");const R=p?.code??-32603,E=p?.data,C=p.message||"MCP request failed",S=t.buildJsonRpcError(c.id??null,R,C,E);if(l){const P=t.primeEventId();e.header("Content-Type","text/event-stream").header("Cache-Control","no-cache").header("Connection","keep-alive").send(`id: ${P}
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
 
5
- ${t.serializeSseEvent(S,P)}`);return}return e.send(S)}}),n.get(`${r}`,async(o,e)=>{const s=t.primeEventId();e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),e.raw.write(t.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},s,15e3));const a=setInterval(()=>{e.raw.write(`: keep-alive
5
+ ${i.serializeSseEvent(P,Q)}`);return}return e.send(P)}}),s.get(`${r}`,async(t,e)=>{const o=i.primeEventId();e.raw.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}),e.raw.write(i.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},o,15e3));const a=setInterval(()=>{e.raw.write(`: keep-alive
6
6
 
7
- `)},15e3);o.raw.on("close",()=>{clearInterval(a)})}),n.delete(`${r}`,async(o,e)=>e.status(405).send({error:"Session termination not supported"}))}n.setErrorHandler(async(r,o,e)=>{o.log.error(r,"Fastify cube adapter error"),e.statusCode<400&&e.status(500);const s=r instanceof Error?r:String(r);return t.formatErrorResponse(s,e.statusCode)}),f()};async function z(d,n){await d.register(x,n)}function H(d){const n=require("fastify")({logger:!0});return n.register(x,d),n}exports.createCubeApp=H;exports.cubePlugin=x;exports.registerCubeRoutes=z;
7
+ `)},15e3);t.raw.on("close",()=>{clearInterval(a)})}),s.delete(`${r}`,async(t,e)=>e.status(405).send({error:"Session termination not supported"}))}s.setErrorHandler(async(r,t,e)=>{t.log.error(r,"Fastify cube adapter error"),e.statusCode<400&&e.status(500);const o=r instanceof Error?r:String(r);return n.formatErrorResponse(o,e.statusCode)}),v()};async function H(l,s){await l.register(q,s)}function T(l){const s=require("fastify")({logger:!0});return s.register(q,l),s}exports.createCubeApp=T;exports.cubePlugin=q;exports.registerCubeRoutes=H;
@@ -1,25 +1,26 @@
1
- import { S as D, o as u, f as $, h as H, a as V, b as j, c as M, v as z, d as C, e as T, n as _, p as B, w as F, g as U, k as I, M as G, l as K, m as q, s as R } from "../mcp-transport-lkEjNwDH.js";
2
- const k = function(n, N, E) {
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-B4BZSsMC.js";
2
+ import { formatErrorResponse as u, formatCubeResponse as j, handleBatchRequest as G, formatMetaResponse as K, formatSqlResponse as M, handleDryRun as I } from "../utils.js";
3
+ const N = function(n, O, E) {
3
4
  const {
4
5
  cubes: w,
5
- drizzle: O,
6
+ drizzle: k,
6
7
  schema: A,
7
8
  extractSecurityContext: y,
8
9
  engineType: L,
9
10
  cors: Q,
10
11
  basePath: p = "/cubejs-api/v1",
11
- bodyLimit: h = 10485760,
12
+ bodyLimit: m = 10485760,
12
13
  // 10MB
13
14
  cache: J,
14
15
  mcp: g = { enabled: !0 }
15
- } = N;
16
+ } = O;
16
17
  if (!w || w.length === 0)
17
18
  return E(new Error("At least one cube must be provided in the cubes array"));
18
19
  Q && n.register(import("@fastify/cors"), Q), n.addHook("onRequest", async (r, t) => {
19
20
  r.method === "POST" && (r.body = void 0);
20
21
  });
21
22
  const c = new D({
22
- drizzle: O,
23
+ drizzle: k,
23
24
  schema: A,
24
25
  engineType: L,
25
26
  cache: J
@@ -27,7 +28,7 @@ const k = function(n, N, E) {
27
28
  if (w.forEach((r) => {
28
29
  c.registerCube(r);
29
30
  }), n.post(`${p}/load`, {
30
- bodyLimit: h,
31
+ bodyLimit: m,
31
32
  schema: {
32
33
  body: {
33
34
  type: "object",
@@ -43,7 +44,7 @@ const k = function(n, N, E) {
43
44
  400
44
45
  ));
45
46
  const i = r.headers["x-cache-control"] === "no-cache", d = await c.executeMultiCubeQuery(a, s, { skipCache: i });
46
- return $(a, d, c);
47
+ return j(a, d, c);
47
48
  } catch (e) {
48
49
  return r.log.error(e, "Query execution error"), t.status(500).send(u(
49
50
  e instanceof Error ? e.message : "Query execution failed",
@@ -79,7 +80,7 @@ const k = function(n, N, E) {
79
80
  400
80
81
  ));
81
82
  const i = r.headers["x-cache-control"] === "no-cache", d = await c.executeMultiCubeQuery(a, s, { skipCache: i });
82
- return $(a, d, c);
83
+ return j(a, d, c);
83
84
  } catch (e) {
84
85
  return r.log.error(e, "Query execution error"), t.status(500).send(u(
85
86
  e instanceof Error ? e.message : "Query execution failed",
@@ -87,7 +88,7 @@ const k = function(n, N, E) {
87
88
  ));
88
89
  }
89
90
  }), n.post(`${p}/batch`, {
90
- bodyLimit: h,
91
+ bodyLimit: m,
91
92
  schema: {
92
93
  body: {
93
94
  type: "object",
@@ -114,7 +115,7 @@ const k = function(n, N, E) {
114
115
  400
115
116
  ));
116
117
  const a = await y(r), s = r.headers["x-cache-control"] === "no-cache";
117
- return await H(e, a, c, { skipCache: s });
118
+ return await G(e, a, c, { skipCache: s });
118
119
  } catch (e) {
119
120
  return r.log.error(e, "Batch execution error"), t.status(500).send(u(
120
121
  e instanceof Error ? e.message : "Batch execution failed",
@@ -124,7 +125,7 @@ const k = function(n, N, E) {
124
125
  }), n.get(`${p}/meta`, async (r, t) => {
125
126
  try {
126
127
  const e = c.getMetadata();
127
- return V(e);
128
+ return K(e);
128
129
  } catch (e) {
129
130
  return r.log.error(e, "Metadata error"), t.status(500).send(u(
130
131
  e instanceof Error ? e.message : "Failed to fetch metadata",
@@ -132,7 +133,7 @@ const k = function(n, N, E) {
132
133
  ));
133
134
  }
134
135
  }), n.post(`${p}/sql`, {
135
- bodyLimit: h,
136
+ bodyLimit: m,
136
137
  schema: {
137
138
  body: {
138
139
  type: "object",
@@ -154,7 +155,7 @@ const k = function(n, N, E) {
154
155
  400
155
156
  ));
156
157
  const i = o.split(".")[0], d = await c.generateSQL(i, e, a);
157
- return j(e, d);
158
+ return M(e, d);
158
159
  } catch (e) {
159
160
  return r.log.error(e, "SQL generation error"), t.status(500).send(u(
160
161
  e instanceof Error ? e.message : "SQL generation failed",
@@ -186,7 +187,7 @@ const k = function(n, N, E) {
186
187
  400
187
188
  ));
188
189
  const d = i.split(".")[0], x = await c.generateSQL(d, a, s);
189
- return j(a, x);
190
+ return M(a, x);
190
191
  } catch (e) {
191
192
  return r.log.error(e, "SQL generation error"), t.status(500).send(u(
192
193
  e instanceof Error ? e.message : "SQL generation failed",
@@ -194,7 +195,7 @@ const k = function(n, N, E) {
194
195
  ));
195
196
  }
196
197
  }), n.post(`${p}/dry-run`, {
197
- bodyLimit: h,
198
+ bodyLimit: m,
198
199
  schema: {
199
200
  body: {
200
201
  type: "object",
@@ -204,7 +205,7 @@ const k = function(n, N, E) {
204
205
  }, async (r, t) => {
205
206
  try {
206
207
  const e = r.body, a = e.query || e, s = await y(r);
207
- return await M(a, s, c);
208
+ return await I(a, s, c);
208
209
  } catch (e) {
209
210
  return r.log.error(e, "Dry-run error"), t.status(400).send({
210
211
  error: e instanceof Error ? e.message : "Dry-run validation failed",
@@ -224,7 +225,7 @@ const k = function(n, N, E) {
224
225
  }, async (r, t) => {
225
226
  try {
226
227
  const { query: e } = r.query, a = JSON.parse(e), s = await y(r);
227
- return await M(a, s, c);
228
+ return await I(a, s, c);
228
229
  } catch (e) {
229
230
  return r.log.error(e, "Dry-run error"), t.status(400).send({
230
231
  error: e instanceof Error ? e.message : "Dry-run validation failed",
@@ -232,7 +233,7 @@ const k = function(n, N, E) {
232
233
  });
233
234
  }
234
235
  }), n.post(`${p}/explain`, {
235
- bodyLimit: h,
236
+ bodyLimit: m,
236
237
  schema: {
237
238
  body: {
238
239
  type: "object",
@@ -253,7 +254,7 @@ const k = function(n, N, E) {
253
254
  }), g.enabled !== !1) {
254
255
  const r = g.basePath ?? "/mcp";
255
256
  n.post(`${r}`, {
256
- bodyLimit: h,
257
+ bodyLimit: m,
257
258
  schema: {
258
259
  body: {
259
260
  type: "object",
@@ -261,27 +262,27 @@ const k = function(n, N, E) {
261
262
  }
262
263
  }
263
264
  }, async (t, e) => {
264
- const a = z(
265
+ const a = H(
265
266
  t.headers.origin,
266
267
  g.allowedOrigins ? { allowedOrigins: g.allowedOrigins } : {}
267
268
  );
268
269
  if (!a.valid)
269
270
  return e.status(403).send(C(null, -32600, a.reason));
270
271
  const s = t.headers.accept;
271
- if (!T(s))
272
+ if (!V(s))
272
273
  return e.status(400).send(C(null, -32600, "Accept header must include both application/json and text/event-stream"));
273
- const o = _(t.headers);
274
+ const o = z(t.headers);
274
275
  if (!o.ok)
275
276
  return e.status(426).send({
276
277
  error: "Unsupported MCP protocol version",
277
278
  supported: o.supported
278
279
  });
279
- const i = B(t.body);
280
+ const i = T(t.body);
280
281
  if (!i)
281
282
  return e.status(400).send(C(null, -32600, "Invalid JSON-RPC 2.0 request"));
282
- const d = F(s), x = i.method === "initialize";
283
+ const d = _(s), x = i.method === "initialize";
283
284
  try {
284
- const l = await U(
285
+ const l = await B(
285
286
  i.method,
286
287
  i.params,
287
288
  {
@@ -292,11 +293,11 @@ const k = function(n, N, E) {
292
293
  negotiatedProtocol: o.negotiated
293
294
  }
294
295
  );
295
- if (I(i))
296
+ if ($(i))
296
297
  return e.status(202).send();
297
298
  const b = x && l && typeof l == "object" && "sessionId" in l ? l.sessionId : void 0;
298
- b && e.header(G, b);
299
- const v = K(i.id ?? null, l);
299
+ b && e.header(F, b);
300
+ const v = U(i.id ?? null, l);
300
301
  if (d) {
301
302
  const f = q();
302
303
  e.header("Content-Type", "text/event-stream").header("Cache-Control", "no-cache").header("Connection", "keep-alive").send(`id: ${f}
@@ -306,7 +307,7 @@ ${R(v, f)}`);
306
307
  }
307
308
  return e.send(v);
308
309
  } catch (l) {
309
- if (I(i))
310
+ if ($(i))
310
311
  return t.log.error(l, "MCP notification processing error"), e.status(202).send();
311
312
  t.log.error(l, "MCP RPC error");
312
313
  const b = l?.code ?? -32603, v = l?.data, f = l.message || "MCP request failed", S = C(i.id ?? null, b, f, v);
@@ -346,17 +347,17 @@ ${R(S, P)}`);
346
347
  return u(a, e.statusCode);
347
348
  }), E();
348
349
  };
349
- async function X(m, n) {
350
- await m.register(k, n);
350
+ async function Y(h, n) {
351
+ await h.register(N, n);
351
352
  }
352
- function Y(m) {
353
+ function Z(h) {
353
354
  const n = require("fastify")({
354
355
  logger: !0
355
356
  });
356
- return n.register(k, m), n;
357
+ return n.register(N, h), n;
357
358
  }
358
359
  export {
359
- Y as createCubeApp,
360
- k as cubePlugin,
361
- X as registerCubeRoutes
360
+ Z as createCubeApp,
361
+ N as cubePlugin,
362
+ Y as registerCubeRoutes
362
363
  };
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("hono"),n=require("../mcp-transport-oPf8JYHv.cjs");var O=C=>{const d={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...C},Q=(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,s){a.res.headers.set(u,s)}const w=await Q(a.req.header("origin")||"",a);if(w&&q("Access-Control-Allow-Origin",w),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 s=d.allowHeaders;if(!s?.length){const r=a.req.header("Access-Control-Request-Headers");r&&(s=r.split(/\s*,\s*/))}return s?.length&&(q("Access-Control-Allow-Headers",s.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 T(C){const{cubes:j,drizzle:d,schema:Q,extractSecurityContext:y,engineType:l,cors:a,basePath:f="/cubejs-api/v1",cache:q,mcp:w={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 $.Hono;a&&u.use("/*",O(a));const s=new n.SemanticLayerCompiler({drizzle:d,schema:Q,engineType:l,cache:q});if(j.forEach(r=>{s.registerCube(r)}),u.post(`${f}/load`,async r=>{try{const e=await r.req.json(),o=e.query||e,i=await y(r),t=s.validateQuery(o);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 s.executeMultiCubeQuery(o,i,{skipCache:c});return r.json(n.formatCubeResponse(o,p,s))}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 o;try{o=JSON.parse(e)}catch{return r.json({error:"Invalid JSON in query parameter"},400)}const i=await y(r),t=s.validateQuery(o);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 s.executeMultiCubeQuery(o,i,{skipCache:c});return r.json(n.formatCubeResponse(o,p,s))}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:o}=e;if(!o||!Array.isArray(o))return r.json({error:'Request body must contain a "queries" array'},400);if(o.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 n.handleBatchRequest(o,i,s,{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=s.getMetadata();return r.json(n.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(),o=await y(r),i=s.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 s.generateSQL(c,e,o);return r.json(n.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 o=JSON.parse(e),i=await y(r),t=s.validateQuery(o);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const c=o.measures?.[0]||o.dimensions?.[0];if(!c)return r.json({error:"No measures or dimensions specified"},400);const p=c.split(".")[0],g=await s.generateSQL(p,o,i);return r.json(n.formatSqlResponse(o,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(),o=e.query||e,i=await y(r),t=await n.handleDryRun(o,i,s);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 o=JSON.parse(e),i=await y(r),t=await n.handleDryRun(o,i,s);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(),o=e.query||e,i=e.options||{},t=await y(r),c=s.validateQuery(o);if(!c.isValid)return r.json({error:`Query validation failed: ${c.errors.join(", ")}`},400);const p=await s.explainQuery(o,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)}}),w.enabled!==!1){const r={uri:"drizzle-cube://schema",name:"Cube Schema",description:"Current cube metadata as JSON",mimeType:"application/json",text:JSON.stringify(s.getMetadata(),null,2)},e=[...n.getDefaultResources(),r],o=n.getDefaultPrompts(),i=w.basePath??"/mcp";u.post(`${i}`,async t=>{const c=n.validateOriginHeader(t.req.header("origin"),w.allowedOrigins?{allowedOrigins:w.allowedOrigins}:{});if(!c.valid)return t.json(n.buildJsonRpcError(null,-32600,c.reason),403);const p=t.req.header("accept");if(!n.validateAcceptHeader(p))return t.json(n.buildJsonRpcError(null,-32600,"Accept header must include both application/json and text/event-stream"),400);const g=n.negotiateProtocol(t.req.header());if(!g.ok)return t.json({error:"Unsupported MCP protocol version",supported:g.supported},426);const P=await t.req.json().catch(()=>null),m=n.parseJsonRpc(P);if(!m)return t.json(n.buildJsonRpcError(null,-32600,"Invalid JSON-RPC 2.0 request"),400);const M=n.wantsEventStream(p),N=m.method==="initialize";try{const h=await n.dispatchMcpMethod(m.method,m.params,{semanticLayer:s,extractSecurityContext:y,rawRequest:t,rawResponse:null,negotiatedProtocol:g.negotiated,resources:e,prompts:o});if(n.isNotification(m))return t.body(null,202);const E=n.buildJsonRpcResult(m.id??null,h),S=N&&h&&typeof h=="object"&&"sessionId"in h?h.sessionId:void 0,v={};if(S&&(v[n.MCP_SESSION_ID_HEADER]=S),M){const b=new TextEncoder,R=n.primeEventId(),A=new ReadableStream({start(x){x.enqueue(b.encode(`id: ${R}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("hono"),s=require("../mcp-transport-C8pLznZG.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
- `)),x.enqueue(b.encode(n.serializeSseEvent(E,R))),x.close()}});return new Response(A,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...v}})}return t.json(E,200,v)}catch(h){if(n.isNotification(m))return console.error("MCP notification processing error:",h),t.body(null,202);console.error("MCP RPC error:",h);const E=h?.code??-32603,S=h?.data,v=h.message||"MCP request failed",b=n.buildJsonRpcError(m.id??null,E,v,S);if(M){const R=new TextEncoder,A=n.primeEventId(),x=new ReadableStream({start(H){H.enqueue(R.encode(`id: ${A}
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
 
5
- `)),H.enqueue(R.encode(n.serializeSseEvent(b,A))),H.close()}});return new Response(x,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}return t.json(b,200)}}),u.delete(`${i}`,t=>t.json({error:"Session termination not supported"},405)),u.get(`${i}`,t=>{const c=new TextEncoder,p=n.primeEventId();let g;const P=new ReadableStream({start(m){m.enqueue(c.encode(n.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},p,15e3))),g=setInterval(()=>{m.enqueue(c.encode(`: keep-alive
5
+ `)),M.enqueue(x.encode(s.serializeSseEvent(R,Q))),M.close()}});return new Response(E,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}return t.json(R,200)}}),u.delete(`${i}`,t=>t.json({error:"Session termination not supported"},405)),u.get(`${i}`,t=>{const c=new TextEncoder,p=s.primeEventId();let g;const H=new ReadableStream({start(m){m.enqueue(c.encode(s.serializeSseEvent({jsonrpc:"2.0",method:"mcp/ready",params:{protocol:"streamable-http"}},p,15e3))),g=setInterval(()=>{m.enqueue(c.encode(`: keep-alive
6
6
 
7
- `))},15e3)},cancel(){clearInterval(g)}});return new Response(P,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})})}return u}function I(C,j){const d=T(j);return C.route("/",d),C}function J(C){const j=new $.Hono;return I(j,C)}exports.createCubeApp=J;exports.createCubeRoutes=T;exports.mountCubeRoutes=I;
7
+ `))},15e3)},cancel(){clearInterval(g)}});return new Response(H,{status:200,headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})})}return u}function N(C,j){const d=I(j);return C.route("/",d),C}function D(C){const j=new T.Hono;return N(j,C)}exports.createCubeApp=D;exports.createCubeRoutes=I;exports.mountCubeRoutes=N;