drizzle-cube 0.4.15 → 0.4.16

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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("hono"),a=require("../mcp-transport-8u9G5oNa.cjs"),b=require("../utils.cjs");var D=j=>{const p={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...j},I=(d=>typeof d=="string"?d==="*"?()=>d:c=>d===c?c:null:typeof d=="function"?d:c=>d.includes(c)?c:null)(p.origin),m=(d=>typeof d=="function"?d:Array.isArray(d)?()=>d:()=>[])(p.allowMethods);return async function(c,h){function g(C,i){c.res.headers.set(C,i)}const x=await I(c.req.header("origin")||"",c);if(x&&g("Access-Control-Allow-Origin",x),p.credentials&&g("Access-Control-Allow-Credentials","true"),p.exposeHeaders?.length&&g("Access-Control-Expose-Headers",p.exposeHeaders.join(",")),c.req.method==="OPTIONS"){p.origin!=="*"&&g("Vary","Origin"),p.maxAge!=null&&g("Access-Control-Max-Age",p.maxAge.toString());const C=await m(c.req.header("origin")||"",c);C.length&&g("Access-Control-Allow-Methods",C.join(","));let i=p.allowHeaders;if(!i?.length){const s=c.req.header("Access-Control-Request-Headers");s&&(i=s.split(/\s*,\s*/))}return i?.length&&(g("Access-Control-Allow-Headers",i.join(",")),c.res.headers.append("Vary","Access-Control-Request-Headers")),c.res.headers.delete("Content-Length"),c.res.headers.delete("Content-Type"),new Response(null,{headers:c.res.headers,status:204,statusText:"No Content"})}await h(),p.origin!=="*"&&c.header("Vary","Origin",{append:!0})}};function O(j){const{cubes:v,drizzle:p,schema:I,extractSecurityContext:m,engineType:d,cors:c,basePath:h="/cubejs-api/v1",cache:g,mcp:x={enabled:!0},agent:C}=j;if(!v||v.length===0)throw new Error("At least one cube must be provided in the cubes array");const i=new N.Hono;c&&i.use("/*",D(c));const s=new a.SemanticLayerCompiler({drizzle:p,schema:I,engineType:d,cache:g});if(v.forEach(r=>{s.registerCube(r)}),i.post(`${h}/load`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=r.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return r.json(b.formatCubeResponse(n,l,s))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),i.get(`${h}/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 o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=r.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return r.json(b.formatCubeResponse(n,l,s))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),i.post(`${h}/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 o=await m(r),t=r.req.header("x-cache-control")==="no-cache",u=await b.handleBatchRequest(n,o,s,{skipCache:t});return r.json(u)}catch(e){return console.error("Batch execution error:",e),r.json({error:e instanceof Error?e.message:"Batch execution failed"},500)}}),i.get(`${h}/meta`,r=>{try{const e=s.getMetadata();return r.json(b.formatMetaResponse(e))}catch(e){return console.error("Metadata error:",e),r.json({error:e instanceof Error?e.message:"Failed to fetch metadata"},500)}}),i.post(`${h}/sql`,async r=>{try{const e=await r.req.json(),n=await m(r),o=s.validateQuery(e);if(!o.isValid)return r.json({error:`Query validation failed: ${o.errors.join(", ")}`},400);const t=e.measures?.[0]||e.dimensions?.[0];if(!t)return r.json({error:"No measures or dimensions specified"},400);const u=t.split(".")[0],l=await s.generateSQL(u,e,n);return r.json(b.formatSqlResponse(e,l))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),i.get(`${h}/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),o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=n.measures?.[0]||n.dimensions?.[0];if(!u)return r.json({error:"No measures or dimensions specified"},400);const l=u.split(".")[0],q=await s.generateSQL(l,n,o);return r.json(b.formatSqlResponse(n,q))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),i.post(`${h}/dry-run`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=await m(r),t=await b.handleDryRun(n,o,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)}}),i.get(`${h}/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),o=await m(r),t=await b.handleDryRun(n,o,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)}}),i.post(`${h}/explain`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=e.options||{},t=await m(r),u=s.validateQuery(n);if(!u.isValid)return r.json({error:`Query validation failed: ${u.errors.join(", ")}`},400);const l=await s.explainQuery(n,t,o);return r.json(l)}catch(e){return console.error("Explain error:",e),r.json({error:e instanceof Error?e.message:"Explain query failed"},500)}}),C&&i.post(`${h}/agent/chat`,async r=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-ZDYlokiM.cjs")),n=await r.req.json(),{message:o,sessionId:t,history:u}=n;if(!o||typeof o!="string")return r.json({error:"message is required and must be a string"},400);let l=(C.apiKey||"").trim();if(C.allowClientApiKey){const w=r.req.header("x-agent-api-key");w&&(l=w.trim())}if(!l)return r.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},401);const q=await m(r),R=new TextEncoder,f=new ReadableStream({async start(w){try{const E=e({message:o,sessionId:t,history:u,semanticLayer:s,securityContext:q,agentConfig:C,apiKey:l});for await(const y of E){const S=`data: ${JSON.stringify(y)}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("hono"),a=require("../mcp-transport-8u9G5oNa.cjs"),b=require("../utils.cjs");var D=j=>{const p={...{origin:"*",allowMethods:["GET","HEAD","PUT","POST","DELETE","PATCH"],allowHeaders:[],exposeHeaders:[]},...j},I=(d=>typeof d=="string"?d==="*"?()=>d:c=>d===c?c:null:typeof d=="function"?d:c=>d.includes(c)?c:null)(p.origin),m=(d=>typeof d=="function"?d:Array.isArray(d)?()=>d:()=>[])(p.allowMethods);return async function(c,h){function g(C,i){c.res.headers.set(C,i)}const x=await I(c.req.header("origin")||"",c);if(x&&g("Access-Control-Allow-Origin",x),p.credentials&&g("Access-Control-Allow-Credentials","true"),p.exposeHeaders?.length&&g("Access-Control-Expose-Headers",p.exposeHeaders.join(",")),c.req.method==="OPTIONS"){p.origin!=="*"&&g("Vary","Origin"),p.maxAge!=null&&g("Access-Control-Max-Age",p.maxAge.toString());const C=await m(c.req.header("origin")||"",c);C.length&&g("Access-Control-Allow-Methods",C.join(","));let i=p.allowHeaders;if(!i?.length){const s=c.req.header("Access-Control-Request-Headers");s&&(i=s.split(/\s*,\s*/))}return i?.length&&(g("Access-Control-Allow-Headers",i.join(",")),c.res.headers.append("Vary","Access-Control-Request-Headers")),c.res.headers.delete("Content-Length"),c.res.headers.delete("Content-Type"),new Response(null,{headers:c.res.headers,status:204,statusText:"No Content"})}await h(),p.origin!=="*"&&c.header("Vary","Origin",{append:!0})}};function O(j){const{cubes:v,drizzle:p,schema:I,extractSecurityContext:m,engineType:d,cors:c,basePath:h="/cubejs-api/v1",cache:g,mcp:x={enabled:!0},agent:C}=j;if(!v||v.length===0)throw new Error("At least one cube must be provided in the cubes array");const i=new N.Hono;c&&i.use("/*",D(c));const s=new a.SemanticLayerCompiler({drizzle:p,schema:I,engineType:d,cache:g});if(v.forEach(r=>{s.registerCube(r)}),i.post(`${h}/load`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=r.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return r.json(b.formatCubeResponse(n,l,s))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),i.get(`${h}/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 o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=r.req.header("x-cache-control")==="no-cache",l=await s.executeMultiCubeQuery(n,o,{skipCache:u});return r.json(b.formatCubeResponse(n,l,s))}catch(e){return console.error("Query execution error:",e),r.json({error:e instanceof Error?e.message:"Query execution failed"},500)}}),i.post(`${h}/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 o=await m(r),t=r.req.header("x-cache-control")==="no-cache",u=await b.handleBatchRequest(n,o,s,{skipCache:t});return r.json(u)}catch(e){return console.error("Batch execution error:",e),r.json({error:e instanceof Error?e.message:"Batch execution failed"},500)}}),i.get(`${h}/meta`,r=>{try{const e=s.getMetadata();return r.json(b.formatMetaResponse(e))}catch(e){return console.error("Metadata error:",e),r.json({error:e instanceof Error?e.message:"Failed to fetch metadata"},500)}}),i.post(`${h}/sql`,async r=>{try{const e=await r.req.json(),n=await m(r),o=s.validateQuery(e);if(!o.isValid)return r.json({error:`Query validation failed: ${o.errors.join(", ")}`},400);const t=e.measures?.[0]||e.dimensions?.[0];if(!t)return r.json({error:"No measures or dimensions specified"},400);const u=t.split(".")[0],l=await s.generateSQL(u,e,n);return r.json(b.formatSqlResponse(e,l))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),i.get(`${h}/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),o=await m(r),t=s.validateQuery(n);if(!t.isValid)return r.json({error:`Query validation failed: ${t.errors.join(", ")}`},400);const u=n.measures?.[0]||n.dimensions?.[0];if(!u)return r.json({error:"No measures or dimensions specified"},400);const l=u.split(".")[0],q=await s.generateSQL(l,n,o);return r.json(b.formatSqlResponse(n,q))}catch(e){return console.error("SQL generation error:",e),r.json({error:e instanceof Error?e.message:"SQL generation failed"},500)}}),i.post(`${h}/dry-run`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=await m(r),t=await b.handleDryRun(n,o,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)}}),i.get(`${h}/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),o=await m(r),t=await b.handleDryRun(n,o,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)}}),i.post(`${h}/explain`,async r=>{try{const e=await r.req.json(),n=e.query||e,o=e.options||{},t=await m(r),u=s.validateQuery(n);if(!u.isValid)return r.json({error:`Query validation failed: ${u.errors.join(", ")}`},400);const l=await s.explainQuery(n,t,o);return r.json(l)}catch(e){return console.error("Explain error:",e),r.json({error:e instanceof Error?e.message:"Explain query failed"},500)}}),C&&i.post(`${h}/agent/chat`,async r=>{try{const{handleAgentChat:e}=await Promise.resolve().then(()=>require("../handler-B6yAJw_O.cjs")),n=await r.req.json(),{message:o,sessionId:t,history:u}=n;if(!o||typeof o!="string")return r.json({error:"message is required and must be a string"},400);let l=(C.apiKey||"").trim();if(C.allowClientApiKey){const w=r.req.header("x-agent-api-key");w&&(l=w.trim())}if(!l)return r.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},401);const q=await m(r),R=new TextEncoder,f=new ReadableStream({async start(w){try{const E=e({message:o,sessionId:t,history:u,semanticLayer:s,securityContext:q,agentConfig:C,apiKey:l});for await(const y of E){const S=`data: ${JSON.stringify(y)}
2
2
 
3
3
  `;w.enqueue(R.encode(S))}}catch(E){const y={type:"error",data:{message:E instanceof Error?E.message:"Stream failed"}};w.enqueue(R.encode(`data: ${JSON.stringify(y)}
4
4
 
@@ -212,7 +212,7 @@ function te(C) {
212
212
  }
213
213
  }), q && a.post(`${m}/agent/chat`, async (r) => {
214
214
  try {
215
- const { handleAgentChat: e } = await import("../handler-DZnCbydH.js"), n = await r.req.json(), { message: o, sessionId: t, history: c } = n;
215
+ const { handleAgentChat: e } = await import("../handler-BmTtVoRu.js"), n = await r.req.json(), { message: o, sessionId: t, history: c } = n;
216
216
  if (!o || typeof o != "string")
217
217
  return r.json({ error: "message is required and must be a string" }, 400);
218
218
  let u = (q.apiKey || "").trim();
@@ -2,7 +2,7 @@
2
2
 
3
3
  `)),H.enqueue(h.encode(f.serializeSseEvent(x,E))),H.close()}}),O=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive",...g});if(s){const H=R(t,s);Object.entries(H).forEach(([b,P])=>O.set(b,P))}return new r.NextResponse(S,{status:200,headers:O})}return v(x,200,g)}catch(m){if(f.isNotification(p))return process.env.NODE_ENV!=="test"&&console.error("Next.js MCP notification processing error:",m),new r.NextResponse(null,{status:202});process.env.NODE_ENV!=="test"&&console.error("Next.js MCP RPC handler error:",m);const C=m?.code??-32603,g=m?.data,x=m.message||"MCP request failed",h=f.buildJsonRpcError(p.id??null,C,x,g);if(w){const E=new TextEncoder,S=f.primeEventId(),O=new ReadableStream({start(b){b.enqueue(E.encode(`id: ${S}
4
4
 
5
- `)),b.enqueue(E.encode(f.serializeSseEvent(h,S))),b.close()}}),H=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const b=R(t,s);Object.entries(b).forEach(([P,I])=>H.set(P,I))}return new r.NextResponse(O,{status:200,headers:H})}return v(h,200)}}}function Q(n){const{extractSecurityContext:o,cors:s,agent:c}=n;if(!c)throw new Error("agent config is required for createAgentChatHandler");const d=j(n);return async function(t,e){try{if(t.method!=="POST")return r.NextResponse.json({error:"Method not allowed - use POST"},{status:405});const{handleAgentChat:l}=await Promise.resolve().then(()=>require("../handler-ZDYlokiM.cjs")),y=await t.json(),{message:u,sessionId:p,history:w}=y;if(!u||typeof u!="string")return r.NextResponse.json({error:"message is required and must be a string"},{status:400});let N=(c.apiKey||"").trim();if(c.allowClientApiKey){const x=t.headers.get("x-agent-api-key");x&&(N=x.trim())}if(!N)return r.NextResponse.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},{status:401});const v=await o(t,e),m=new TextEncoder,C=new ReadableStream({async start(x){try{const h=l({message:u,sessionId:p,history:w,semanticLayer:d,securityContext:v,agentConfig:c,apiKey:N});for await(const E of h){const S=`data: ${JSON.stringify(E)}
5
+ `)),b.enqueue(E.encode(f.serializeSseEvent(h,S))),b.close()}}),H=new Headers({"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"});if(s){const b=R(t,s);Object.entries(b).forEach(([P,I])=>H.set(P,I))}return new r.NextResponse(O,{status:200,headers:H})}return v(h,200)}}}function Q(n){const{extractSecurityContext:o,cors:s,agent:c}=n;if(!c)throw new Error("agent config is required for createAgentChatHandler");const d=j(n);return async function(t,e){try{if(t.method!=="POST")return r.NextResponse.json({error:"Method not allowed - use POST"},{status:405});const{handleAgentChat:l}=await Promise.resolve().then(()=>require("../handler-B6yAJw_O.cjs")),y=await t.json(),{message:u,sessionId:p,history:w}=y;if(!u||typeof u!="string")return r.NextResponse.json({error:"message is required and must be a string"},{status:400});let N=(c.apiKey||"").trim();if(c.allowClientApiKey){const x=t.headers.get("x-agent-api-key");x&&(N=x.trim())}if(!N)return r.NextResponse.json({error:"No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header."},{status:401});const v=await o(t,e),m=new TextEncoder,C=new ReadableStream({async start(x){try{const h=l({message:u,sessionId:p,history:w,semanticLayer:d,securityContext:v,agentConfig:c,apiKey:N});for await(const E of h){const S=`data: ${JSON.stringify(E)}
6
6
 
7
7
  `;x.enqueue(m.encode(S))}}catch(h){const E={type:"error",data:{message:h instanceof Error?h.message:"Stream failed"}};x.enqueue(m.encode(`data: ${JSON.stringify(E)}
8
8
 
@@ -519,7 +519,7 @@ function oe(n) {
519
519
  { error: "Method not allowed - use POST" },
520
520
  { status: 405 }
521
521
  );
522
- const { handleAgentChat: u } = await import("../handler-DZnCbydH.js"), y = await r.json(), { message: l, sessionId: f, history: v } = y;
522
+ const { handleAgentChat: u } = await import("../handler-BmTtVoRu.js"), y = await r.json(), { message: l, sessionId: f, history: v } = y;
523
523
  if (!l || typeof l != "string")
524
524
  return t.json(
525
525
  { error: "message is required and must be a string" },