drizzle-cube 0.4.47 → 0.4.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/{compiler-O3T1u7jl.js → compiler-B_Nl7ZZb.js} +1 -1
- package/dist/adapters/{compiler-CA6iopu7.cjs → compiler-CdL3ksb3.cjs} +1 -1
- package/dist/adapters/express/index.cjs +1 -1
- package/dist/adapters/express/index.js +4 -4
- package/dist/adapters/fastify/index.cjs +1 -1
- package/dist/adapters/fastify/index.js +39 -39
- package/dist/adapters/{handler-BO2nq6IS.cjs → handler-DumFgnNM.cjs} +10 -10
- package/dist/adapters/{handler-CjVc3ytc.js → handler-RItnSaEl.js} +128 -350
- package/dist/adapters/hono/index.cjs +1 -1
- package/dist/adapters/hono/index.js +4 -4
- package/dist/adapters/mcp-prompts-BUFyQLHQ.js +377 -0
- package/dist/adapters/mcp-prompts-B_NvEJT_.cjs +111 -0
- package/dist/adapters/mcp-tools.cjs +1 -1
- package/dist/adapters/mcp-tools.js +2 -2
- package/dist/adapters/mcp-transport-CG5Aw2cs.js +515 -0
- package/dist/adapters/mcp-transport-DlFvZl2c.cjs +35 -0
- package/dist/adapters/mcp-transport.d.ts +310 -5
- package/dist/adapters/nextjs/index.cjs +1 -1
- package/dist/adapters/nextjs/index.js +4 -4
- package/dist/adapters/utils-CyBt-as9.cjs +15 -0
- package/dist/adapters/{utils-C7Nrw9Wb.js → utils-IH1ePsBd.js} +707 -655
- package/dist/adapters/utils.cjs +1 -1
- package/dist/adapters/utils.d.ts +11 -0
- package/dist/adapters/utils.js +2 -2
- package/dist/mcp-app/mcp-app.html +78 -44
- package/dist/server/index.cjs +144 -38
- package/dist/server/index.d.ts +24 -19
- package/dist/server/index.js +538 -674
- package/package.json +1 -1
- package/dist/adapters/mcp-prompts-BAutSQYA.js +0 -344
- package/dist/adapters/mcp-prompts-DsAkafVn.cjs +0 -5
- package/dist/adapters/mcp-transport-Cim_5cBN.js +0 -424
- package/dist/adapters/mcp-transport-DPpBCNea.cjs +0 -70
- package/dist/adapters/utils-tNZ6Cvzw.cjs +0 -15
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./utils-tNZ6Cvzw.cjs`);var t=Symbol.for(`drizzle:entityKind`);function n(e,n){if(!e||typeof e!=`object`)return!1;if(e instanceof n)return!0;if(!Object.prototype.hasOwnProperty.call(n,t))throw Error(`Class "${n.name??`<unknown>`}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);let r=Object.getPrototypeOf(e).constructor;if(r)for(;r;){if(t in r&&r[t]===n[t])return!0;r=Object.getPrototypeOf(r)}return!1}var r=class{constructor(e,t){this.table=e,this.config=t,this.name=t.name,this.keyAsName=t.keyAsName,this.notNull=t.notNull,this.default=t.default,this.defaultFn=t.defaultFn,this.onUpdateFn=t.onUpdateFn,this.hasDefault=t.hasDefault,this.primary=t.primaryKey,this.isUnique=t.isUnique,this.uniqueName=t.uniqueName,this.uniqueType=t.uniqueType,this.dataType=t.dataType,this.columnType=t.columnType,this.generated=t.generated,this.generatedIdentity=t.generatedIdentity}static[t]=`Column`;name;keyAsName;primary;notNull;default;defaultFn;onUpdateFn;hasDefault;isUnique;uniqueName;uniqueType;dataType;columnType;enumValues=void 0;generated=void 0;generatedIdentity=void 0;config;mapFromDriverValue(e){return e}mapToDriverValue(e){return e}shouldDisableInsert(){return this.config.generated!==void 0&&this.config.generated.type!==`byDefault`}},i=Symbol.for(`drizzle:Name`),a=Symbol.for(`drizzle:isPgEnum`);function o(e){return!!e&&typeof e==`function`&&a in e&&e[a]===!0}var s=class{static[t]=`Subquery`;constructor(e,t,n,r=!1,i=[]){this._={brand:`Subquery`,sql:e,selectedFields:t,alias:n,isWith:r,usedTables:i}}},c={startActiveSpan(e,t){return t()}},l=Symbol.for(`drizzle:ViewBaseConfig`),u=Symbol.for(`drizzle:Schema`),d=Symbol.for(`drizzle:Columns`),f=Symbol.for(`drizzle:ExtraConfigColumns`),p=Symbol.for(`drizzle:OriginalName`),m=Symbol.for(`drizzle:BaseName`),h=Symbol.for(`drizzle:IsAlias`),g=Symbol.for(`drizzle:ExtraConfigBuilder`),_=Symbol.for(`drizzle:IsDrizzleTable`),v=class{static[t]=`Table`;static Symbol={Name:i,Schema:u,OriginalName:p,Columns:d,ExtraConfigColumns:f,BaseName:m,IsAlias:h,ExtraConfigBuilder:g};[i];[p];[u];[d];[f];[m];[h]=!1;[_]=!0;[g]=void 0;constructor(e,t,n){this[i]=this[p]=e,this[u]=t,this[m]=n}};function y(e){return e!=null&&typeof e.getSQL==`function`}function b(e){let t={sql:``,params:[]};for(let n of e)t.sql+=n.sql,t.params.push(...n.params),n.typings?.length&&(t.typings||=[],t.typings.push(...n.typings));return t}var x=class{static[t]=`StringChunk`;value;constructor(e){this.value=Array.isArray(e)?e:[e]}getSQL(){return new S([this])}},S=class e{constructor(e){this.queryChunks=e;for(let t of e)if(n(t,v)){let e=t[v.Symbol.Schema];this.usedTables.push(e===void 0?t[v.Symbol.Name]:e+`.`+t[v.Symbol.Name])}}static[t]=`SQL`;decoder=w;shouldInlineParams=!1;usedTables=[];append(e){return this.queryChunks.push(...e.queryChunks),this}toQuery(e){return c.startActiveSpan(`drizzle.buildSQL`,t=>{let n=this.buildQueryFromSourceParams(this.queryChunks,e);return t?.setAttributes({"drizzle.query.text":n.sql,"drizzle.query.params":JSON.stringify(n.params)}),n})}buildQueryFromSourceParams(t,i){let a=Object.assign({},i,{inlineParams:i.inlineParams||this.shouldInlineParams,paramStartIndex:i.paramStartIndex||{value:0}}),{casing:c,escapeName:u,escapeParam:d,prepareTyping:f,inlineParams:p,paramStartIndex:m}=a;return b(t.map(t=>{if(n(t,x))return{sql:t.value.join(``),params:[]};if(n(t,C))return{sql:u(t.value),params:[]};if(t===void 0)return{sql:``,params:[]};if(Array.isArray(t)){let e=[new x(`(`)];for(let[n,r]of t.entries())e.push(r),n<t.length-1&&e.push(new x(`, `));return e.push(new x(`)`)),this.buildQueryFromSourceParams(e,a)}if(n(t,e))return this.buildQueryFromSourceParams(t.queryChunks,{...a,inlineParams:p||t.shouldInlineParams});if(n(t,v)){let e=t[v.Symbol.Schema],n=t[v.Symbol.Name];return{sql:e===void 0||t[h]?u(n):u(e)+`.`+u(n),params:[]}}if(n(t,r)){let e=c.getColumnCasing(t);if(i.invokeSource===`indexes`)return{sql:u(e),params:[]};let n=t.table[v.Symbol.Schema];return{sql:t.table[h]||n===void 0?u(t.table[v.Symbol.Name])+`.`+u(e):u(n)+`.`+u(t.table[v.Symbol.Name])+`.`+u(e),params:[]}}if(n(t,A)){let e=t[l].schema,n=t[l].name;return{sql:e===void 0||t[l].isAlias?u(n):u(e)+`.`+u(n),params:[]}}if(n(t,E)){if(n(t.value,O))return{sql:d(m.value++,t),params:[t],typings:[`none`]};let r=t.value===null?null:t.encoder.mapToDriverValue(t.value);if(n(r,e))return this.buildQueryFromSourceParams([r],a);if(p)return{sql:this.mapInlineParam(r,a),params:[]};let i=[`none`];return f&&(i=[f(t.encoder)]),{sql:d(m.value++,r),params:[r],typings:i}}return n(t,O)?{sql:d(m.value++,t),params:[t],typings:[`none`]}:n(t,e.Aliased)&&t.fieldAlias!==void 0?{sql:u(t.fieldAlias),params:[]}:n(t,s)?t._.isWith?{sql:u(t._.alias),params:[]}:this.buildQueryFromSourceParams([new x(`(`),t._.sql,new x(`) `),new C(t._.alias)],a):o(t)?t.schema?{sql:u(t.schema)+`.`+u(t.enumName),params:[]}:{sql:u(t.enumName),params:[]}:y(t)?t.shouldOmitSQLParens?.()?this.buildQueryFromSourceParams([t.getSQL()],a):this.buildQueryFromSourceParams([new x(`(`),t.getSQL(),new x(`)`)],a):p?{sql:this.mapInlineParam(t,a),params:[]}:{sql:d(m.value++,t),params:[t],typings:[`none`]}}))}mapInlineParam(e,{escapeString:t}){if(e===null)return`null`;if(typeof e==`number`||typeof e==`boolean`)return e.toString();if(typeof e==`string`)return t(e);if(typeof e==`object`){let n=e.toString();return t(n===`[object Object]`?JSON.stringify(e):n)}throw Error(`Unexpected param value: `+e)}getSQL(){return this}as(t){return t===void 0?this:new e.Aliased(this,t)}mapWith(e){return this.decoder=typeof e==`function`?{mapFromDriverValue:e}:e,this}inlineParams(){return this.shouldInlineParams=!0,this}if(e){return e?this:void 0}},C=class{constructor(e){this.value=e}static[t]=`Name`;brand;getSQL(){return new S([this])}};function ee(e){return typeof e==`object`&&!!e&&`mapToDriverValue`in e&&typeof e.mapToDriverValue==`function`}var w={mapFromDriverValue:e=>e},T={mapToDriverValue:e=>e};({...w,...T});var E=class{constructor(e,t=T){this.value=e,this.encoder=t}static[t]=`Param`;brand;getSQL(){return new S([this])}};function D(e,...t){let n=[];(t.length>0||e.length>0&&e[0]!==``)&&n.push(new x(e[0]));for(let[r,i]of t.entries())n.push(i,new x(e[r+1]));return new S(n)}(e=>{function t(){return new S([])}e.empty=t;function n(e){return new S(e)}e.fromList=n;function r(e){return new S([new x(e)])}e.raw=r;function i(e,t){let n=[];for(let[r,i]of e.entries())r>0&&t!==void 0&&n.push(t),n.push(i);return new S(n)}e.join=i;function a(e){return new C(e)}e.identifier=a;function o(e){return new O(e)}e.placeholder=o;function s(e,t){return new E(e,t)}e.param=s})(D||={}),(e=>{class n{constructor(e,t){this.sql=e,this.fieldAlias=t}static[t]=`SQL.Aliased`;isSelectionField=!1;getSQL(){return this.sql}clone(){return new n(this.sql,this.fieldAlias)}}e.Aliased=n})(S||={});var O=class{constructor(e){this.name=e}static[t]=`Placeholder`;getSQL(){return new S([this])}},k=Symbol.for(`drizzle:IsDrizzleView`),A=class{static[t]=`View`;[l];[k]=!0;constructor({name:e,schema:t,selectedFields:n,query:r}){this[l]={name:e,originalName:e,schema:t,selectedFields:n,query:r,isExisting:!r,isAlias:!1}}getSQL(){return new S([this])}};r.prototype.getSQL=function(){return new S([this])},v.prototype.getSQL=function(){return new S([this])},s.prototype.getSQL=function(){return new S([this])};function j(e,t){return ee(t)&&!y(e)&&!n(e,E)&&!n(e,O)&&!n(e,r)&&!n(e,v)&&!n(e,A)?new E(e,t):e}var M=(e,t)=>D`${e} = ${j(t,e)}`,N=(e,t)=>D`${e} <> ${j(t,e)}`;function P(...e){let t=e.filter(e=>e!==void 0);if(t.length!==0)return t.length===1?new S(t):new S([new x(`(`),D.join(t,new x(` and `)),new x(`)`)])}function F(...e){let t=e.filter(e=>e!==void 0);if(t.length!==0)return t.length===1?new S(t):new S([new x(`(`),D.join(t,new x(` or `)),new x(`)`)])}var te=(e,t)=>D`${e} > ${j(t,e)}`,I=(e,t)=>D`${e} >= ${j(t,e)}`,ne=(e,t)=>D`${e} < ${j(t,e)}`,L=(e,t)=>D`${e} <= ${j(t,e)}`;function re(e,t){return Array.isArray(t)?t.length===0?D`false`:D`${e} in ${t.map(t=>j(t,e))}`:D`${e} in ${j(t,e)}`}function ie(e,t){return Array.isArray(t)?t.length===0?D`true`:D`${e} not in ${t.map(t=>j(t,e))}`:D`${e} not in ${j(t,e)}`}function ae(e){return D`${e} is null`}function oe(e){return D`${e} is not null`}function se(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayContains requires at least one value`);return D`${e} @> ${D`${j(t,e)}`}`}return D`${e} @> ${j(t,e)}`}function ce(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayContained requires at least one value`);return D`${e} <@ ${D`${j(t,e)}`}`}return D`${e} <@ ${j(t,e)}`}function le(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayOverlaps requires at least one value`);return D`${e} && ${D`${j(t,e)}`}`}return D`${e} && ${j(t,e)}`}function ue(e){return D`${e} asc`}function de(e){return D`${e} desc`}function fe(e){return D`count(${e||D.raw(`*`)})`.mapWith(Number)}function pe(e){return D`count(distinct ${e})`.mapWith(Number)}function R(e){return D`sum(${e})`.mapWith(String)}function z(e){return D`max(${e})`.mapWith(n(e,r)?e:String)}function B(e){return D`min(${e})`.mapWith(n(e,r)?e:String)}var V=class{preprocessCalculatedTemplate(e){return e}buildPattern(e,t){switch(e){case`contains`:case`notContains`:return`%${t}%`;case`startsWith`:return`${t}%`;case`endsWith`:return`%${t}`;default:return t}}parseISODuration(e){let t={years:0,months:0,days:0,hours:0,minutes:0,seconds:0},n=e.match(/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/);if(!n)throw Error(`Invalid ISO 8601 duration format: ${e}`);return t.years=parseInt(n[1]||`0`,10),t.months=parseInt(n[2]||`0`,10),t.days=parseInt(n[3]||`0`,10),t.hours=parseInt(n[4]||`0`,10),t.minutes=parseInt(n[5]||`0`,10),t.seconds=parseFloat(n[6]||`0`),t}durationToSeconds(e){let t=this.parseISODuration(e);return t.years*365*24*60*60+t.months*30*24*60*60+t.days*24*60*60+t.hours*60*60+t.minutes*60+t.seconds}},me=class extends V{getEngineType(){return`postgres`}supportsLateralJoins(){return!0}buildIntervalFromISO(e){let t=this.parseISODuration(e),n=[];t.years&&n.push(`${t.years} years`),t.months&&n.push(`${t.months} months`),t.days&&n.push(`${t.days} days`),t.hours&&n.push(`${t.hours} hours`),t.minutes&&n.push(`${t.minutes} minutes`),t.seconds&&n.push(`${t.seconds} seconds`);let r=n.join(` `)||`0 seconds`;return D`INTERVAL '${D.raw(r)}'`}buildTimeDifferenceSeconds(e,t){return D`EXTRACT(EPOCH FROM (${e} - ${t}))`}buildDateAddInterval(e,t){return D`(${e} + ${this.buildIntervalFromISO(t)})`}buildConditionalAggregation(e,t,n){let r=e.toUpperCase();return e===`count`&&!t?D`COUNT(*) FILTER (WHERE ${n})`:D`${D.raw(r)}(${t}) FILTER (WHERE ${n})`}buildDateDiffPeriods(e,t,n){switch(n){case`day`:return D`(${t}::date - ${e}::date)`;case`week`:return D`FLOOR((${t}::date - ${e}::date) / 7)`;case`month`:return D`(EXTRACT(YEAR FROM AGE(${t}::timestamp, ${e}::timestamp)) * 12 + EXTRACT(MONTH FROM AGE(${t}::timestamp, ${e}::timestamp)))::integer`;default:throw Error(`Unsupported date diff unit: ${n}`)}}buildPeriodSeriesSubquery(e){return D`(SELECT generate_series(0, ${e}) as period_number) p`}buildTimeDimension(e,t){switch(e){case`year`:return D`DATE_TRUNC('year', ${t}::timestamp)`;case`quarter`:return D`DATE_TRUNC('quarter', ${t}::timestamp)`;case`month`:return D`DATE_TRUNC('month', ${t}::timestamp)`;case`week`:return D`DATE_TRUNC('week', ${t}::timestamp)`;case`day`:return D`DATE_TRUNC('day', ${t}::timestamp)::timestamp`;case`hour`:return D`DATE_TRUNC('hour', ${t}::timestamp)`;case`minute`:return D`DATE_TRUNC('minute', ${t}::timestamp)`;case`second`:return D`DATE_TRUNC('second', ${t}::timestamp)`;default:return t}}buildStringCondition(e,t,n){switch(t){case`contains`:return D`${e} ILIKE ${`%${n}%`}`;case`notContains`:return D`${e} NOT ILIKE ${`%${n}%`}`;case`startsWith`:return D`${e} ILIKE ${`${n}%`}`;case`endsWith`:return D`${e} ILIKE ${`%${n}`}`;case`like`:return D`${e} LIKE ${n}`;case`notLike`:return D`${e} NOT LIKE ${n}`;case`ilike`:return D`${e} ILIKE ${n}`;case`regex`:return D`${e} ~* ${n}`;case`notRegex`:return D`${e} !~* ${n}`;default:throw Error(`Unsupported string operator: ${t}`)}}castToType(e,t){switch(t){case`timestamp`:return D`${e}::timestamp`;case`decimal`:return D`${e}::decimal`;case`integer`:return D`${e}::integer`;default:throw Error(`Unsupported cast type: ${t}`)}}buildAvg(e){return D`COALESCE(AVG(${e}), 0)`}buildCaseWhen(e,t){let n=e.map(e=>D`WHEN ${e.when} THEN ${e.then}`).reduce((e,t)=>D`${e} ${t}`);return t===void 0?D`CASE ${n} END`:D`CASE ${n} ELSE ${t} END`}buildBooleanLiteral(e){return e?D`TRUE`:D`FALSE`}convertFilterValue(e){return e}prepareDateValue(e){return e}isTimestampInteger(){return!1}convertTimeDimensionResult(e){return e}getCapabilities(){return{supportsStddev:!0,supportsVariance:!0,supportsPercentile:!0,supportsWindowFunctions:!0,supportsFrameClause:!0,supportsLateralJoins:!0,supportsPercentileSubqueries:!0,supportsDerivedTablesInCTE:!0,supportsLateralSubqueriesInCTE:!0}}buildStddev(e,t=!1){let n=t?`STDDEV_SAMP`:`STDDEV_POP`;return D`COALESCE(${D.raw(n)}(${e}), 0)`}buildVariance(e,t=!1){let n=t?`VAR_SAMP`:`VAR_POP`;return D`COALESCE(${D.raw(n)}(${e}), 0)`}buildPercentile(e,t){return D`PERCENTILE_CONT(${t/100}) WITHIN GROUP (ORDER BY ${e})`}buildWindowFunction(e,t,n,r,i){let a=n&&n.length>0?D`PARTITION BY ${D.join(n,D`, `)}`:D``,o=r&&r.length>0?D`ORDER BY ${D.join(r.map(e=>e.direction===`desc`?D`${e.field} DESC`:D`${e.field} ASC`),D`, `)}`:D``,s=D``;if(i?.frame){let{type:e,start:t,end:n}=i.frame,r=e.toUpperCase(),a=t===`unbounded`?`UNBOUNDED PRECEDING`:typeof t==`number`?`${t} PRECEDING`:`CURRENT ROW`,o=n===`unbounded`?`UNBOUNDED FOLLOWING`:n===`current`?`CURRENT ROW`:typeof n==`number`?`${n} FOLLOWING`:`CURRENT ROW`;s=D`${D.raw(r)} BETWEEN ${D.raw(a)} AND ${D.raw(o)}`}let c=[];n&&n.length>0&&c.push(a),r&&r.length>0&&c.push(o),i?.frame&&c.push(s);let l=D`OVER (${c.length>0?D.join(c,D` `):D``})`;switch(e){case`lag`:return D`LAG(${t}, ${i?.offset??1}${i?.defaultValue===void 0?D``:D`, ${i.defaultValue}`}) ${l}`;case`lead`:return D`LEAD(${t}, ${i?.offset??1}${i?.defaultValue===void 0?D``:D`, ${i.defaultValue}`}) ${l}`;case`rank`:return D`RANK() ${l}`;case`denseRank`:return D`DENSE_RANK() ${l}`;case`rowNumber`:return D`ROW_NUMBER() ${l}`;case`ntile`:return D`NTILE(${i?.nTile??4}) ${l}`;case`firstValue`:return D`FIRST_VALUE(${t}) ${l}`;case`lastValue`:return D`LAST_VALUE(${t}) ${l}`;case`movingAvg`:return D`AVG(${t}) ${l}`;case`movingSum`:return D`SUM(${t}) ${l}`;default:throw Error(`Unsupported window function: ${e}`)}}},he=class extends V{getEngineType(){return`mysql`}supportsLateralJoins(){return!0}buildIntervalFromISO(e){let t=this.parseISODuration(e),n=[];return t.years&&n.push(`${t.years} YEAR`),t.months&&n.push(`${t.months} MONTH`),t.days&&n.push(`${t.days} DAY`),t.hours&&n.push(`${t.hours} HOUR`),t.minutes&&n.push(`${t.minutes} MINUTE`),t.seconds&&n.push(`${t.seconds} SECOND`),D`${this.durationToSeconds(e)}`}buildTimeDifferenceSeconds(e,t){return D`TIMESTAMPDIFF(SECOND, ${t}, ${e})`}buildDateAddInterval(e,t){let n=this.parseISODuration(t),r=e;return n.years&&(r=D`DATE_ADD(${r}, INTERVAL ${n.years} YEAR)`),n.months&&(r=D`DATE_ADD(${r}, INTERVAL ${n.months} MONTH)`),n.days&&(r=D`DATE_ADD(${r}, INTERVAL ${n.days} DAY)`),n.hours&&(r=D`DATE_ADD(${r}, INTERVAL ${n.hours} HOUR)`),n.minutes&&(r=D`DATE_ADD(${r}, INTERVAL ${n.minutes} MINUTE)`),n.seconds&&(r=D`DATE_ADD(${r}, INTERVAL ${n.seconds} SECOND)`),r}buildConditionalAggregation(e,t,n){let r=e.toUpperCase();return e===`count`&&!t?D`COUNT(CASE WHEN ${n} THEN 1 END)`:D`${D.raw(r)}(CASE WHEN ${n} THEN ${t} END)`}buildDateDiffPeriods(e,t,n){let r=n.toUpperCase();return D`TIMESTAMPDIFF(${D.raw(r)}, ${e}, ${t})`}buildPeriodSeriesSubquery(e){return D`(
|
|
1
|
+
const e=require(`./utils-CyBt-as9.cjs`);var t=Symbol.for(`drizzle:entityKind`);function n(e,n){if(!e||typeof e!=`object`)return!1;if(e instanceof n)return!0;if(!Object.prototype.hasOwnProperty.call(n,t))throw Error(`Class "${n.name??`<unknown>`}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);let r=Object.getPrototypeOf(e).constructor;if(r)for(;r;){if(t in r&&r[t]===n[t])return!0;r=Object.getPrototypeOf(r)}return!1}var r=class{constructor(e,t){this.table=e,this.config=t,this.name=t.name,this.keyAsName=t.keyAsName,this.notNull=t.notNull,this.default=t.default,this.defaultFn=t.defaultFn,this.onUpdateFn=t.onUpdateFn,this.hasDefault=t.hasDefault,this.primary=t.primaryKey,this.isUnique=t.isUnique,this.uniqueName=t.uniqueName,this.uniqueType=t.uniqueType,this.dataType=t.dataType,this.columnType=t.columnType,this.generated=t.generated,this.generatedIdentity=t.generatedIdentity}static[t]=`Column`;name;keyAsName;primary;notNull;default;defaultFn;onUpdateFn;hasDefault;isUnique;uniqueName;uniqueType;dataType;columnType;enumValues=void 0;generated=void 0;generatedIdentity=void 0;config;mapFromDriverValue(e){return e}mapToDriverValue(e){return e}shouldDisableInsert(){return this.config.generated!==void 0&&this.config.generated.type!==`byDefault`}},i=Symbol.for(`drizzle:Name`),a=Symbol.for(`drizzle:isPgEnum`);function o(e){return!!e&&typeof e==`function`&&a in e&&e[a]===!0}var s=class{static[t]=`Subquery`;constructor(e,t,n,r=!1,i=[]){this._={brand:`Subquery`,sql:e,selectedFields:t,alias:n,isWith:r,usedTables:i}}},c={startActiveSpan(e,t){return t()}},l=Symbol.for(`drizzle:ViewBaseConfig`),u=Symbol.for(`drizzle:Schema`),d=Symbol.for(`drizzle:Columns`),f=Symbol.for(`drizzle:ExtraConfigColumns`),p=Symbol.for(`drizzle:OriginalName`),m=Symbol.for(`drizzle:BaseName`),h=Symbol.for(`drizzle:IsAlias`),g=Symbol.for(`drizzle:ExtraConfigBuilder`),_=Symbol.for(`drizzle:IsDrizzleTable`),v=class{static[t]=`Table`;static Symbol={Name:i,Schema:u,OriginalName:p,Columns:d,ExtraConfigColumns:f,BaseName:m,IsAlias:h,ExtraConfigBuilder:g};[i];[p];[u];[d];[f];[m];[h]=!1;[_]=!0;[g]=void 0;constructor(e,t,n){this[i]=this[p]=e,this[u]=t,this[m]=n}};function y(e){return e!=null&&typeof e.getSQL==`function`}function b(e){let t={sql:``,params:[]};for(let n of e)t.sql+=n.sql,t.params.push(...n.params),n.typings?.length&&(t.typings||=[],t.typings.push(...n.typings));return t}var x=class{static[t]=`StringChunk`;value;constructor(e){this.value=Array.isArray(e)?e:[e]}getSQL(){return new S([this])}},S=class e{constructor(e){this.queryChunks=e;for(let t of e)if(n(t,v)){let e=t[v.Symbol.Schema];this.usedTables.push(e===void 0?t[v.Symbol.Name]:e+`.`+t[v.Symbol.Name])}}static[t]=`SQL`;decoder=w;shouldInlineParams=!1;usedTables=[];append(e){return this.queryChunks.push(...e.queryChunks),this}toQuery(e){return c.startActiveSpan(`drizzle.buildSQL`,t=>{let n=this.buildQueryFromSourceParams(this.queryChunks,e);return t?.setAttributes({"drizzle.query.text":n.sql,"drizzle.query.params":JSON.stringify(n.params)}),n})}buildQueryFromSourceParams(t,i){let a=Object.assign({},i,{inlineParams:i.inlineParams||this.shouldInlineParams,paramStartIndex:i.paramStartIndex||{value:0}}),{casing:c,escapeName:u,escapeParam:d,prepareTyping:f,inlineParams:p,paramStartIndex:m}=a;return b(t.map(t=>{if(n(t,x))return{sql:t.value.join(``),params:[]};if(n(t,C))return{sql:u(t.value),params:[]};if(t===void 0)return{sql:``,params:[]};if(Array.isArray(t)){let e=[new x(`(`)];for(let[n,r]of t.entries())e.push(r),n<t.length-1&&e.push(new x(`, `));return e.push(new x(`)`)),this.buildQueryFromSourceParams(e,a)}if(n(t,e))return this.buildQueryFromSourceParams(t.queryChunks,{...a,inlineParams:p||t.shouldInlineParams});if(n(t,v)){let e=t[v.Symbol.Schema],n=t[v.Symbol.Name];return{sql:e===void 0||t[h]?u(n):u(e)+`.`+u(n),params:[]}}if(n(t,r)){let e=c.getColumnCasing(t);if(i.invokeSource===`indexes`)return{sql:u(e),params:[]};let n=t.table[v.Symbol.Schema];return{sql:t.table[h]||n===void 0?u(t.table[v.Symbol.Name])+`.`+u(e):u(n)+`.`+u(t.table[v.Symbol.Name])+`.`+u(e),params:[]}}if(n(t,A)){let e=t[l].schema,n=t[l].name;return{sql:e===void 0||t[l].isAlias?u(n):u(e)+`.`+u(n),params:[]}}if(n(t,E)){if(n(t.value,O))return{sql:d(m.value++,t),params:[t],typings:[`none`]};let r=t.value===null?null:t.encoder.mapToDriverValue(t.value);if(n(r,e))return this.buildQueryFromSourceParams([r],a);if(p)return{sql:this.mapInlineParam(r,a),params:[]};let i=[`none`];return f&&(i=[f(t.encoder)]),{sql:d(m.value++,r),params:[r],typings:i}}return n(t,O)?{sql:d(m.value++,t),params:[t],typings:[`none`]}:n(t,e.Aliased)&&t.fieldAlias!==void 0?{sql:u(t.fieldAlias),params:[]}:n(t,s)?t._.isWith?{sql:u(t._.alias),params:[]}:this.buildQueryFromSourceParams([new x(`(`),t._.sql,new x(`) `),new C(t._.alias)],a):o(t)?t.schema?{sql:u(t.schema)+`.`+u(t.enumName),params:[]}:{sql:u(t.enumName),params:[]}:y(t)?t.shouldOmitSQLParens?.()?this.buildQueryFromSourceParams([t.getSQL()],a):this.buildQueryFromSourceParams([new x(`(`),t.getSQL(),new x(`)`)],a):p?{sql:this.mapInlineParam(t,a),params:[]}:{sql:d(m.value++,t),params:[t],typings:[`none`]}}))}mapInlineParam(e,{escapeString:t}){if(e===null)return`null`;if(typeof e==`number`||typeof e==`boolean`)return e.toString();if(typeof e==`string`)return t(e);if(typeof e==`object`){let n=e.toString();return t(n===`[object Object]`?JSON.stringify(e):n)}throw Error(`Unexpected param value: `+e)}getSQL(){return this}as(t){return t===void 0?this:new e.Aliased(this,t)}mapWith(e){return this.decoder=typeof e==`function`?{mapFromDriverValue:e}:e,this}inlineParams(){return this.shouldInlineParams=!0,this}if(e){return e?this:void 0}},C=class{constructor(e){this.value=e}static[t]=`Name`;brand;getSQL(){return new S([this])}};function ee(e){return typeof e==`object`&&!!e&&`mapToDriverValue`in e&&typeof e.mapToDriverValue==`function`}var w={mapFromDriverValue:e=>e},T={mapToDriverValue:e=>e};({...w,...T});var E=class{constructor(e,t=T){this.value=e,this.encoder=t}static[t]=`Param`;brand;getSQL(){return new S([this])}};function D(e,...t){let n=[];(t.length>0||e.length>0&&e[0]!==``)&&n.push(new x(e[0]));for(let[r,i]of t.entries())n.push(i,new x(e[r+1]));return new S(n)}(e=>{function t(){return new S([])}e.empty=t;function n(e){return new S(e)}e.fromList=n;function r(e){return new S([new x(e)])}e.raw=r;function i(e,t){let n=[];for(let[r,i]of e.entries())r>0&&t!==void 0&&n.push(t),n.push(i);return new S(n)}e.join=i;function a(e){return new C(e)}e.identifier=a;function o(e){return new O(e)}e.placeholder=o;function s(e,t){return new E(e,t)}e.param=s})(D||={}),(e=>{class n{constructor(e,t){this.sql=e,this.fieldAlias=t}static[t]=`SQL.Aliased`;isSelectionField=!1;getSQL(){return this.sql}clone(){return new n(this.sql,this.fieldAlias)}}e.Aliased=n})(S||={});var O=class{constructor(e){this.name=e}static[t]=`Placeholder`;getSQL(){return new S([this])}},k=Symbol.for(`drizzle:IsDrizzleView`),A=class{static[t]=`View`;[l];[k]=!0;constructor({name:e,schema:t,selectedFields:n,query:r}){this[l]={name:e,originalName:e,schema:t,selectedFields:n,query:r,isExisting:!r,isAlias:!1}}getSQL(){return new S([this])}};r.prototype.getSQL=function(){return new S([this])},v.prototype.getSQL=function(){return new S([this])},s.prototype.getSQL=function(){return new S([this])};function j(e,t){return ee(t)&&!y(e)&&!n(e,E)&&!n(e,O)&&!n(e,r)&&!n(e,v)&&!n(e,A)?new E(e,t):e}var M=(e,t)=>D`${e} = ${j(t,e)}`,N=(e,t)=>D`${e} <> ${j(t,e)}`;function P(...e){let t=e.filter(e=>e!==void 0);if(t.length!==0)return t.length===1?new S(t):new S([new x(`(`),D.join(t,new x(` and `)),new x(`)`)])}function F(...e){let t=e.filter(e=>e!==void 0);if(t.length!==0)return t.length===1?new S(t):new S([new x(`(`),D.join(t,new x(` or `)),new x(`)`)])}var te=(e,t)=>D`${e} > ${j(t,e)}`,I=(e,t)=>D`${e} >= ${j(t,e)}`,ne=(e,t)=>D`${e} < ${j(t,e)}`,L=(e,t)=>D`${e} <= ${j(t,e)}`;function re(e,t){return Array.isArray(t)?t.length===0?D`false`:D`${e} in ${t.map(t=>j(t,e))}`:D`${e} in ${j(t,e)}`}function ie(e,t){return Array.isArray(t)?t.length===0?D`true`:D`${e} not in ${t.map(t=>j(t,e))}`:D`${e} not in ${j(t,e)}`}function ae(e){return D`${e} is null`}function oe(e){return D`${e} is not null`}function se(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayContains requires at least one value`);return D`${e} @> ${D`${j(t,e)}`}`}return D`${e} @> ${j(t,e)}`}function ce(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayContained requires at least one value`);return D`${e} <@ ${D`${j(t,e)}`}`}return D`${e} <@ ${j(t,e)}`}function le(e,t){if(Array.isArray(t)){if(t.length===0)throw Error(`arrayOverlaps requires at least one value`);return D`${e} && ${D`${j(t,e)}`}`}return D`${e} && ${j(t,e)}`}function ue(e){return D`${e} asc`}function de(e){return D`${e} desc`}function fe(e){return D`count(${e||D.raw(`*`)})`.mapWith(Number)}function pe(e){return D`count(distinct ${e})`.mapWith(Number)}function R(e){return D`sum(${e})`.mapWith(String)}function z(e){return D`max(${e})`.mapWith(n(e,r)?e:String)}function B(e){return D`min(${e})`.mapWith(n(e,r)?e:String)}var V=class{preprocessCalculatedTemplate(e){return e}buildPattern(e,t){switch(e){case`contains`:case`notContains`:return`%${t}%`;case`startsWith`:return`${t}%`;case`endsWith`:return`%${t}`;default:return t}}parseISODuration(e){let t={years:0,months:0,days:0,hours:0,minutes:0,seconds:0},n=e.match(/^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+(?:\.\d+)?)S)?)?$/);if(!n)throw Error(`Invalid ISO 8601 duration format: ${e}`);return t.years=parseInt(n[1]||`0`,10),t.months=parseInt(n[2]||`0`,10),t.days=parseInt(n[3]||`0`,10),t.hours=parseInt(n[4]||`0`,10),t.minutes=parseInt(n[5]||`0`,10),t.seconds=parseFloat(n[6]||`0`),t}durationToSeconds(e){let t=this.parseISODuration(e);return t.years*365*24*60*60+t.months*30*24*60*60+t.days*24*60*60+t.hours*60*60+t.minutes*60+t.seconds}},me=class extends V{getEngineType(){return`postgres`}supportsLateralJoins(){return!0}buildIntervalFromISO(e){let t=this.parseISODuration(e),n=[];t.years&&n.push(`${t.years} years`),t.months&&n.push(`${t.months} months`),t.days&&n.push(`${t.days} days`),t.hours&&n.push(`${t.hours} hours`),t.minutes&&n.push(`${t.minutes} minutes`),t.seconds&&n.push(`${t.seconds} seconds`);let r=n.join(` `)||`0 seconds`;return D`INTERVAL '${D.raw(r)}'`}buildTimeDifferenceSeconds(e,t){return D`EXTRACT(EPOCH FROM (${e} - ${t}))`}buildDateAddInterval(e,t){return D`(${e} + ${this.buildIntervalFromISO(t)})`}buildConditionalAggregation(e,t,n){let r=e.toUpperCase();return e===`count`&&!t?D`COUNT(*) FILTER (WHERE ${n})`:D`${D.raw(r)}(${t}) FILTER (WHERE ${n})`}buildDateDiffPeriods(e,t,n){switch(n){case`day`:return D`(${t}::date - ${e}::date)`;case`week`:return D`FLOOR((${t}::date - ${e}::date) / 7)`;case`month`:return D`(EXTRACT(YEAR FROM AGE(${t}::timestamp, ${e}::timestamp)) * 12 + EXTRACT(MONTH FROM AGE(${t}::timestamp, ${e}::timestamp)))::integer`;default:throw Error(`Unsupported date diff unit: ${n}`)}}buildPeriodSeriesSubquery(e){return D`(SELECT generate_series(0, ${e}) as period_number) p`}buildTimeDimension(e,t){switch(e){case`year`:return D`DATE_TRUNC('year', ${t}::timestamp)`;case`quarter`:return D`DATE_TRUNC('quarter', ${t}::timestamp)`;case`month`:return D`DATE_TRUNC('month', ${t}::timestamp)`;case`week`:return D`DATE_TRUNC('week', ${t}::timestamp)`;case`day`:return D`DATE_TRUNC('day', ${t}::timestamp)::timestamp`;case`hour`:return D`DATE_TRUNC('hour', ${t}::timestamp)`;case`minute`:return D`DATE_TRUNC('minute', ${t}::timestamp)`;case`second`:return D`DATE_TRUNC('second', ${t}::timestamp)`;default:return t}}buildStringCondition(e,t,n){switch(t){case`contains`:return D`${e} ILIKE ${`%${n}%`}`;case`notContains`:return D`${e} NOT ILIKE ${`%${n}%`}`;case`startsWith`:return D`${e} ILIKE ${`${n}%`}`;case`endsWith`:return D`${e} ILIKE ${`%${n}`}`;case`like`:return D`${e} LIKE ${n}`;case`notLike`:return D`${e} NOT LIKE ${n}`;case`ilike`:return D`${e} ILIKE ${n}`;case`regex`:return D`${e} ~* ${n}`;case`notRegex`:return D`${e} !~* ${n}`;default:throw Error(`Unsupported string operator: ${t}`)}}castToType(e,t){switch(t){case`timestamp`:return D`${e}::timestamp`;case`decimal`:return D`${e}::decimal`;case`integer`:return D`${e}::integer`;default:throw Error(`Unsupported cast type: ${t}`)}}buildAvg(e){return D`COALESCE(AVG(${e}), 0)`}buildCaseWhen(e,t){let n=e.map(e=>D`WHEN ${e.when} THEN ${e.then}`).reduce((e,t)=>D`${e} ${t}`);return t===void 0?D`CASE ${n} END`:D`CASE ${n} ELSE ${t} END`}buildBooleanLiteral(e){return e?D`TRUE`:D`FALSE`}convertFilterValue(e){return e}prepareDateValue(e){return e}isTimestampInteger(){return!1}convertTimeDimensionResult(e){return e}getCapabilities(){return{supportsStddev:!0,supportsVariance:!0,supportsPercentile:!0,supportsWindowFunctions:!0,supportsFrameClause:!0,supportsLateralJoins:!0,supportsPercentileSubqueries:!0,supportsDerivedTablesInCTE:!0,supportsLateralSubqueriesInCTE:!0}}buildStddev(e,t=!1){let n=t?`STDDEV_SAMP`:`STDDEV_POP`;return D`COALESCE(${D.raw(n)}(${e}), 0)`}buildVariance(e,t=!1){let n=t?`VAR_SAMP`:`VAR_POP`;return D`COALESCE(${D.raw(n)}(${e}), 0)`}buildPercentile(e,t){return D`PERCENTILE_CONT(${t/100}) WITHIN GROUP (ORDER BY ${e})`}buildWindowFunction(e,t,n,r,i){let a=n&&n.length>0?D`PARTITION BY ${D.join(n,D`, `)}`:D``,o=r&&r.length>0?D`ORDER BY ${D.join(r.map(e=>e.direction===`desc`?D`${e.field} DESC`:D`${e.field} ASC`),D`, `)}`:D``,s=D``;if(i?.frame){let{type:e,start:t,end:n}=i.frame,r=e.toUpperCase(),a=t===`unbounded`?`UNBOUNDED PRECEDING`:typeof t==`number`?`${t} PRECEDING`:`CURRENT ROW`,o=n===`unbounded`?`UNBOUNDED FOLLOWING`:n===`current`?`CURRENT ROW`:typeof n==`number`?`${n} FOLLOWING`:`CURRENT ROW`;s=D`${D.raw(r)} BETWEEN ${D.raw(a)} AND ${D.raw(o)}`}let c=[];n&&n.length>0&&c.push(a),r&&r.length>0&&c.push(o),i?.frame&&c.push(s);let l=D`OVER (${c.length>0?D.join(c,D` `):D``})`;switch(e){case`lag`:return D`LAG(${t}, ${i?.offset??1}${i?.defaultValue===void 0?D``:D`, ${i.defaultValue}`}) ${l}`;case`lead`:return D`LEAD(${t}, ${i?.offset??1}${i?.defaultValue===void 0?D``:D`, ${i.defaultValue}`}) ${l}`;case`rank`:return D`RANK() ${l}`;case`denseRank`:return D`DENSE_RANK() ${l}`;case`rowNumber`:return D`ROW_NUMBER() ${l}`;case`ntile`:return D`NTILE(${i?.nTile??4}) ${l}`;case`firstValue`:return D`FIRST_VALUE(${t}) ${l}`;case`lastValue`:return D`LAST_VALUE(${t}) ${l}`;case`movingAvg`:return D`AVG(${t}) ${l}`;case`movingSum`:return D`SUM(${t}) ${l}`;default:throw Error(`Unsupported window function: ${e}`)}}},he=class extends V{getEngineType(){return`mysql`}supportsLateralJoins(){return!0}buildIntervalFromISO(e){let t=this.parseISODuration(e),n=[];return t.years&&n.push(`${t.years} YEAR`),t.months&&n.push(`${t.months} MONTH`),t.days&&n.push(`${t.days} DAY`),t.hours&&n.push(`${t.hours} HOUR`),t.minutes&&n.push(`${t.minutes} MINUTE`),t.seconds&&n.push(`${t.seconds} SECOND`),D`${this.durationToSeconds(e)}`}buildTimeDifferenceSeconds(e,t){return D`TIMESTAMPDIFF(SECOND, ${t}, ${e})`}buildDateAddInterval(e,t){let n=this.parseISODuration(t),r=e;return n.years&&(r=D`DATE_ADD(${r}, INTERVAL ${n.years} YEAR)`),n.months&&(r=D`DATE_ADD(${r}, INTERVAL ${n.months} MONTH)`),n.days&&(r=D`DATE_ADD(${r}, INTERVAL ${n.days} DAY)`),n.hours&&(r=D`DATE_ADD(${r}, INTERVAL ${n.hours} HOUR)`),n.minutes&&(r=D`DATE_ADD(${r}, INTERVAL ${n.minutes} MINUTE)`),n.seconds&&(r=D`DATE_ADD(${r}, INTERVAL ${n.seconds} SECOND)`),r}buildConditionalAggregation(e,t,n){let r=e.toUpperCase();return e===`count`&&!t?D`COUNT(CASE WHEN ${n} THEN 1 END)`:D`${D.raw(r)}(CASE WHEN ${n} THEN ${t} END)`}buildDateDiffPeriods(e,t,n){let r=n.toUpperCase();return D`TIMESTAMPDIFF(${D.raw(r)}, ${e}, ${t})`}buildPeriodSeriesSubquery(e){return D`(
|
|
2
2
|
WITH RECURSIVE periods(period_number) AS (
|
|
3
3
|
SELECT 0
|
|
4
4
|
UNION ALL
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-CyBt-as9.cjs`),t=require(`../compiler-CdL3ksb3.cjs`),n=require(`../mcp-transport-DlFvZl2c.cjs`);let r=require(`express`);r=e._(r);let i=require(`cors`);i=e._(i);function a(a){let{cubes:o,drizzle:s,schema:c,extractSecurityContext:l,engineType:u,cors:d,basePath:f=`/cubejs-api/v1`,jsonLimit:p=`10mb`,cache:m,mcp:h={enabled:!0},agent:g}=a;if(!o||o.length===0)throw Error(`At least one cube must be provided in the cubes array`);let _=(0,r.Router)();d&&_.use((0,i.default)(d)),_.use(r.default.json({limit:p})),_.use(r.default.urlencoded({extended:!0,limit:p}));let v=new t.t({drizzle:s,schema:c,engineType:u,cache:m,rlsSetup:a.rlsSetup});if(o.forEach(e=>{v.registerCube(e)}),_.post(`${f}/load`,async(t,n)=>{try{let r=t.body.query||t.body,i=await l(t,n),a=v.validateQuery(r);if(!a.isValid)return n.status(400).json(e.i(`Query validation failed: ${a.errors.join(`, `)}`,400));let o=t.headers[`x-cache-control`]===`no-cache`,s=await v.executeMultiCubeQuery(r,i,{skipCache:o});n.json(e.r(r,s,v))}catch(t){console.error(`Query execution error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Query execution failed`,500))}}),_.get(`${f}/load`,async(t,n)=>{try{let r=t.query.query;if(!r)return n.status(400).json(e.i(`Query parameter is required`,400));let i;try{i=JSON.parse(r)}catch{return n.status(400).json(e.i(`Invalid JSON in query parameter`,400))}let a=await l(t,n),o=v.validateQuery(i);if(!o.isValid)return n.status(400).json(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=t.headers[`x-cache-control`]===`no-cache`,c=await v.executeMultiCubeQuery(i,a,{skipCache:s});n.json(e.r(i,c,v))}catch(t){console.error(`Query execution error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Query execution failed`,500))}}),_.post(`${f}/batch`,async(t,n)=>{try{let{queries:r}=t.body;if(!r||!Array.isArray(r))return n.status(400).json(e.i(`Request body must contain a "queries" array`,400));if(r.length===0)return n.status(400).json(e.i(`Queries array cannot be empty`,400));let i=await e.u(r,await l(t,n),v,{skipCache:t.headers[`x-cache-control`]===`no-cache`});n.json(i)}catch(t){console.error(`Batch execution error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Batch execution failed`,500))}}),_.get(`${f}/meta`,(t,n)=>{try{let t=v.getMetadata();n.json(e.a(t))}catch(t){console.error(`Metadata error:`,t),n.status(500).json(e.i(t instanceof Error?t.message:`Failed to fetch metadata`,500))}}),_.post(`${f}/sql`,async(t,n)=>{try{let r=t.body,i=await l(t,n),a=v.validateQuery(r);if(!a.isValid)return n.status(400).json(e.i(`Query validation failed: ${a.errors.join(`, `)}`,400));let o=r.measures?.[0]||r.dimensions?.[0];if(!o)return n.status(400).json(e.i(`No measures or dimensions specified`,400));let s=o.split(`.`)[0],c=await v.generateSQL(s,r,i);n.json(e.o(r,c))}catch(t){console.error(`SQL generation error:`,String(t).replace(/\n|\r/g,``)),n.status(500).json(e.i(t instanceof Error?t.message:`SQL generation failed`,500))}}),_.get(`${f}/sql`,async(t,n)=>{try{let r=t.query.query;if(!r)return n.status(400).json(e.i(`Query parameter is required`,400));let i=JSON.parse(r),a=await l(t,n),o=v.validateQuery(i);if(!o.isValid)return n.status(400).json(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=i.measures?.[0]||i.dimensions?.[0];if(!s)return n.status(400).json(e.i(`No measures or dimensions specified`,400));let c=s.split(`.`)[0],u=await v.generateSQL(c,i,a);n.json(e.o(i,u))}catch(t){console.error(`SQL generation error:`,String(t).replace(/\n|\r/g,``)),n.status(500).json(e.i(t instanceof Error?t.message:`SQL generation failed`,500))}}),_.post(`${f}/dry-run`,async(t,n)=>{try{let r=await e.f(t.body.query||t.body,await l(t,n),v);n.json(r)}catch(e){console.error(`Dry-run error:`,e),n.status(400).json({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),_.get(`${f}/dry-run`,async(t,n)=>{try{let r=t.query.query;if(!r)return n.status(400).json({error:`Query parameter is required`,valid:!1});let i=await e.f(JSON.parse(r),await l(t,n),v);n.json(i)}catch(e){console.error(`Dry-run error:`,e),n.status(400).json({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),_.post(`${f}/explain`,async(e,t)=>{try{let n=e.body.query||e.body,r=e.body.options||{},i=await l(e,t),a=v.validateQuery(n);if(!a.isValid)return t.status(400).json({error:`Query validation failed: ${a.errors.join(`, `)}`});let o=await v.explainQuery(n,i,r);t.json(o)}catch(e){console.error(`Explain error:`,e),t.status(500).json({error:e instanceof Error?e.message:`Explain query failed`})}}),g&&_.post(`${f}/agent/chat`,async(e,t)=>{try{let{handleAgentChat:n}=await Promise.resolve().then(()=>require(`../handler-DumFgnNM.cjs`)),{message:r,sessionId:i,history:a}=e.body;if(!r||typeof r!=`string`)return t.status(400).json({error:`message is required and must be a string`});let o=(g.apiKey||``).trim();if(g.allowClientApiKey){let t=e.headers[`x-agent-api-key`];t&&(o=t.trim())}if(!o)return t.status(401).json({error:`No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header.`});let s=g.allowClientApiKey?e.headers[`x-agent-provider`]:void 0,c=g.allowClientApiKey?e.headers[`x-agent-model`]:void 0,u=g.allowClientApiKey?e.headers[`x-agent-provider-endpoint`]:void 0,d=await l(e,t),f=g.buildSystemContext?.(d);t.writeHead(200,{"Content-Type":`text/event-stream`,"Cache-Control":`no-cache`,Connection:`keep-alive`});try{let e=n({message:r,sessionId:i,history:a,semanticLayer:v,securityContext:d,agentConfig:g,apiKey:o,systemContext:f,providerOverride:s,modelOverride:c,baseURLOverride:u});for await(let n of e)t.write(`data: ${JSON.stringify(n)}\n\n`)}catch(e){let n={type:`error`,data:{message:e instanceof Error?e.message:`Stream failed`}};t.write(`data: ${JSON.stringify(n)}\n\n`)}finally{t.end()}}catch(e){console.error(`Agent chat error:`,e),t.headersSent||t.status(500).json({error:e instanceof Error?e.message:`Agent chat failed`})}}),h.enabled!==!1){let e=h.basePath??`/mcp`;_.post(`${e}`,async(e,t)=>{let r=n._(e.headers.origin,h.allowedOrigins?{allowedOrigins:h.allowedOrigins}:{});if(!r.valid)return t.status(403).json(n.i(null,-32600,r.reason));let i=e.headers.accept;if(!n.g(i))return t.status(400).json(n.i(null,-32600,`Accept header must include both application/json and text/event-stream`));let a=n.f(e.headers);if(!a.ok)return t.status(426).json({error:`Unsupported MCP protocol version`,supported:a.supported});let o=n.p(e.body);if(!o)return t.status(400).json(n.i(null,-32600,`Invalid JSON-RPC 2.0 request`));let s=n.v(i),c=o.method===`initialize`;try{let r=await n.s(o.method,o.params,{semanticLayer:v,extractSecurityContext:l,rawRequest:e,rawResponse:t,negotiatedProtocol:a.negotiated,appEnabled:!!h.app});if(n.d(o))return t.status(202).end();let i=c&&r&&typeof r==`object`&&`sessionId`in r?r.sessionId:void 0;i&&t.setHeader(n.r,i);let u=n.a(o.id??null,r);if(s){let e=n.m();return t.status(200),t.setHeader(`Content-Type`,`text/event-stream`),t.setHeader(`Cache-Control`,`no-cache`),t.setHeader(`Connection`,`keep-alive`),t.write(`id: ${e}\n\n`),t.write(n.h(u,e)),t.end()}return t.json(u)}catch(e){if(n.d(o))return console.error(`MCP notification processing error:`,String(e).replace(/\n|\r/g,``)),t.status(202).end();console.error(`MCP RPC error:`,String(e).replace(/\n|\r/g,``));let r=e?.code??-32603,i=e?.data,a=e.message||`MCP request failed`,c=n.i(o.id??null,r,a,i);if(s){let e=n.m();return t.status(200),t.setHeader(`Content-Type`,`text/event-stream`),t.setHeader(`Cache-Control`,`no-cache`),t.setHeader(`Connection`,`keep-alive`),t.write(`id: ${e}\n\n`),t.write(n.h(c,e)),t.end()}return t.status(200).json(c)}}),_.get(`${e}`,async(e,t)=>{let r=n.m();t.status(200),t.setHeader(`Content-Type`,`text/event-stream`),t.setHeader(`Cache-Control`,`no-cache`),t.setHeader(`Connection`,`keep-alive`),t.write(n.h({jsonrpc:`2.0`,method:`mcp/ready`,params:{protocol:`streamable-http`}},r,15e3));let i=setInterval(()=>{t.write(`: keep-alive
|
|
2
2
|
|
|
3
3
|
`)},15e3);e.on(`close`,()=>{clearInterval(i)})}),_.delete(`${e}`,(e,t)=>t.status(405).json({error:`Session termination not supported`}))}return _.use((t,n,r,i)=>{console.error(`Express adapter error:`,t),r.headersSent||r.status(500).json(e.i(t,500))}),_}function o(e,t){let n=a(t);return e.use(`/`,n),e}function s(e){return o((0,r.default)(),e)}exports.createCubeApp=s,exports.createCubeRouter=a,exports.mountCubeRoutes=o;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as e, f as t, i as n, o as r, r as i, u as a } from "../utils-
|
|
2
|
-
import { t as o } from "../compiler-
|
|
3
|
-
import { _ as s, a as c, d as l, f as u, g as d, h as f, i as p, m, p as h, r as g, s as _, v } from "../mcp-transport-
|
|
1
|
+
import { a as e, f as t, i as n, o as r, r as i, u as a } from "../utils-IH1ePsBd.js";
|
|
2
|
+
import { t as o } from "../compiler-B_Nl7ZZb.js";
|
|
3
|
+
import { _ as s, a as c, d as l, f as u, g as d, h as f, i as p, m, p as h, r as g, s as _, v } from "../mcp-transport-CG5Aw2cs.js";
|
|
4
4
|
import y, { Router as b } from "express";
|
|
5
5
|
import x from "cors";
|
|
6
6
|
//#region src/adapters/express/index.ts
|
|
@@ -124,7 +124,7 @@ function S(S) {
|
|
|
124
124
|
}
|
|
125
125
|
}), N && P.post(`${k}/agent/chat`, async (e, t) => {
|
|
126
126
|
try {
|
|
127
|
-
let { handleAgentChat: n } = await import("../handler-
|
|
127
|
+
let { handleAgentChat: n } = await import("../handler-RItnSaEl.js"), { message: r, sessionId: i, history: a } = e.body;
|
|
128
128
|
if (!r || typeof r != "string") return t.status(400).json({ error: "message is required and must be a string" });
|
|
129
129
|
let o = (N.apiKey || "").trim();
|
|
130
130
|
if (N.allowClientApiKey) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../utils-CyBt-as9.cjs`),t=require(`../compiler-CdL3ksb3.cjs`),n=require(`../mcp-transport-DlFvZl2c.cjs`);var r=function(r,i,a){let{cubes:o,drizzle:s,schema:c,extractSecurityContext:l,engineType:u,cors:d,basePath:f=`/cubejs-api/v1`,bodyLimit:p=10485760,cache:m,mcp:h={enabled:!0},agent:g}=i;if(!o||o.length===0)return a(Error(`At least one cube must be provided in the cubes array`));d&&r.register(import(`@fastify/cors`),d),r.addHook(`onRequest`,async(e,t)=>{e.method===`POST`&&(e.body=void 0)});let _=new t.t({drizzle:s,schema:c,engineType:u,cache:m,rlsSetup:i.rlsSetup});if(o.forEach(e=>{_.registerCube(e)}),r.post(`${f}/load`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(t,n)=>{try{let r=t.body,i=r.query||r,a=await l(t),o=_.validateQuery(i);if(!o.isValid)return n.status(400).send(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=t.headers[`x-cache-control`]===`no-cache`;return e.r(i,await _.executeMultiCubeQuery(i,a,{skipCache:s}),_)}catch(r){return t.log.error(r,`Query execution error`),n.status(500).send(e.i(r instanceof Error?r.message:`Query execution failed`,500))}}),r.get(`${f}/load`,{schema:{querystring:{type:`object`,properties:{query:{type:`string`}},required:[`query`]}}},async(t,n)=>{try{let{query:r}=t.query,i;try{i=JSON.parse(r)}catch{return n.status(400).send(e.i(`Invalid JSON in query parameter`,400))}let a=await l(t),o=_.validateQuery(i);if(!o.isValid)return n.status(400).send(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=t.headers[`x-cache-control`]===`no-cache`,c=await _.executeMultiCubeQuery(i,a,{skipCache:s});return e.r(i,c,_)}catch(r){return t.log.error(r,`Query execution error`),n.status(500).send(e.i(r instanceof Error?r.message:`Query execution failed`,500))}}),r.post(`${f}/batch`,{bodyLimit:p,schema:{body:{type:`object`,required:[`queries`],properties:{queries:{type:`array`,items:{type:`object`}}}}}},async(t,n)=>{try{let{queries:r}=t.body;return!r||!Array.isArray(r)?n.status(400).send(e.i(`Request body must contain a "queries" array`,400)):r.length===0?n.status(400).send(e.i(`Queries array cannot be empty`,400)):await e.u(r,await l(t),_,{skipCache:t.headers[`x-cache-control`]===`no-cache`})}catch(r){return t.log.error(r,`Batch execution error`),n.status(500).send(e.i(r instanceof Error?r.message:`Batch execution failed`,500))}}),r.get(`${f}/meta`,async(t,n)=>{try{return e.a(_.getMetadata())}catch(r){return t.log.error(r,`Metadata error`),n.status(500).send(e.i(r instanceof Error?r.message:`Failed to fetch metadata`,500))}}),r.post(`${f}/sql`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(t,n)=>{try{let r=t.body,i=await l(t),a=_.validateQuery(r);if(!a.isValid)return n.status(400).send(e.i(`Query validation failed: ${a.errors.join(`, `)}`,400));let o=r.measures?.[0]||r.dimensions?.[0];if(!o)return n.status(400).send(e.i(`No measures or dimensions specified`,400));let s=o.split(`.`)[0];return e.o(r,await _.generateSQL(s,r,i))}catch(r){return t.log.error({err:String(r).replace(/\n|\r/g,``)},`SQL generation error`),n.status(500).send(e.i(r instanceof Error?r.message:`SQL generation failed`,500))}}),r.get(`${f}/sql`,{schema:{querystring:{type:`object`,properties:{query:{type:`string`}},required:[`query`]}}},async(t,n)=>{try{let{query:r}=t.query,i=JSON.parse(r),a=await l(t),o=_.validateQuery(i);if(!o.isValid)return n.status(400).send(e.i(`Query validation failed: ${o.errors.join(`, `)}`,400));let s=i.measures?.[0]||i.dimensions?.[0];if(!s)return n.status(400).send(e.i(`No measures or dimensions specified`,400));let c=s.split(`.`)[0];return e.o(i,await _.generateSQL(c,i,a))}catch(r){return t.log.error({err:String(r).replace(/\n|\r/g,``)},`SQL generation error`),n.status(500).send(e.i(r instanceof Error?r.message:`SQL generation failed`,500))}}),r.post(`${f}/dry-run`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(t,n)=>{try{let n=t.body;return await e.f(n.query||n,await l(t),_)}catch(e){return t.log.error(e,`Dry-run error`),n.status(400).send({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),r.get(`${f}/dry-run`,{schema:{querystring:{type:`object`,properties:{query:{type:`string`}},required:[`query`]}}},async(t,n)=>{try{let{query:n}=t.query;return await e.f(JSON.parse(n),await l(t),_)}catch(e){return t.log.error(e,`Dry-run error`),n.status(400).send({error:e instanceof Error?e.message:`Dry-run validation failed`,valid:!1})}}),r.post(`${f}/explain`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(e,t)=>{try{let n=e.body,r=n.query||n,i=n.options||{},a=await l(e),o=_.validateQuery(r);return o.isValid?await _.explainQuery(r,a,i):t.status(400).send({error:`Query validation failed: ${o.errors.join(`, `)}`})}catch(n){return e.log.error(n,`Explain error`),t.status(500).send({error:n instanceof Error?n.message:`Explain query failed`})}}),g&&r.post(`${f}/agent/chat`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(e,t)=>{try{let{handleAgentChat:n}=await Promise.resolve().then(()=>require(`../handler-DumFgnNM.cjs`)),{message:r,sessionId:i,history:a}=e.body;if(!r||typeof r!=`string`)return t.status(400).send({error:`message is required and must be a string`});let o=(g.apiKey||``).trim();if(g.allowClientApiKey){let t=e.headers[`x-agent-api-key`];t&&(o=t.trim())}if(!o)return t.status(401).send({error:`No API key configured. Set agent.apiKey in server config or send X-Agent-Api-Key header.`});let s=g.allowClientApiKey?e.headers[`x-agent-provider`]:void 0,c=g.allowClientApiKey?e.headers[`x-agent-model`]:void 0,u=g.allowClientApiKey?e.headers[`x-agent-provider-endpoint`]:void 0,d=await l(e),f=g.buildSystemContext?.(d);t.raw.writeHead(200,{"Content-Type":`text/event-stream`,"Cache-Control":`no-cache`,Connection:`keep-alive`});try{let e=n({message:r,sessionId:i,history:a,semanticLayer:_,securityContext:d,agentConfig:g,apiKey:o,systemContext:f,providerOverride:s,modelOverride:c,baseURLOverride:u});for await(let n of e)t.raw.write(`data: ${JSON.stringify(n)}\n\n`)}catch(e){let n={type:`error`,data:{message:e instanceof Error?e.message:`Stream failed`}};t.raw.write(`data: ${JSON.stringify(n)}\n\n`)}finally{t.raw.end()}}catch(n){if(e.log.error(n,`Agent chat error`),!t.raw.headersSent)return t.status(500).send({error:n instanceof Error?n.message:`Agent chat failed`})}}),h.enabled!==!1){let e=h.basePath??`/mcp`;r.post(`${e}`,{bodyLimit:p,schema:{body:{type:`object`,additionalProperties:!0}}},async(e,t)=>{let r=n._(e.headers.origin,h.allowedOrigins?{allowedOrigins:h.allowedOrigins}:{});if(!r.valid)return t.status(403).send(n.i(null,-32600,r.reason));let i=e.headers.accept;if(!n.g(i))return t.status(400).send(n.i(null,-32600,`Accept header must include both application/json and text/event-stream`));let a=n.f(e.headers);if(!a.ok)return t.status(426).send({error:`Unsupported MCP protocol version`,supported:a.supported});let o=n.p(e.body);if(!o)return t.status(400).send(n.i(null,-32600,`Invalid JSON-RPC 2.0 request`));let s=n.v(i),c=o.method===`initialize`;try{let r=await n.s(o.method,o.params,{semanticLayer:_,extractSecurityContext:l,rawRequest:e,rawResponse:t,negotiatedProtocol:a.negotiated,appEnabled:!!h.app});if(n.d(o))return t.status(202).send();let i=c&&r&&typeof r==`object`&&`sessionId`in r?r.sessionId:void 0;i&&t.header(n.r,i);let u=n.a(o.id??null,r);if(s){let e=n.m();t.header(`Content-Type`,`text/event-stream`).header(`Cache-Control`,`no-cache`).header(`Connection`,`keep-alive`).send(`id: ${e}\n\n${n.h(u,e)}`);return}return t.send(u)}catch(r){if(n.d(o))return e.log.error({err:String(r).replace(/\n|\r/g,``)},`MCP notification processing error`),t.status(202).send();e.log.error({err:String(r).replace(/\n|\r/g,``)},`MCP RPC error`);let i=r?.code??-32603,a=r?.data,c=r.message||`MCP request failed`,l=n.i(o.id??null,i,c,a);if(s){let e=n.m();t.header(`Content-Type`,`text/event-stream`).header(`Cache-Control`,`no-cache`).header(`Connection`,`keep-alive`).send(`id: ${e}\n\n${n.h(l,e)}`);return}return t.send(l)}}),r.get(`${e}`,async(e,t)=>{let r=n.m();t.raw.writeHead(200,{"Content-Type":`text/event-stream`,"Cache-Control":`no-cache`,Connection:`keep-alive`}),t.raw.write(n.h({jsonrpc:`2.0`,method:`mcp/ready`,params:{protocol:`streamable-http`}},r,15e3));let i=setInterval(()=>{t.raw.write(`: keep-alive
|
|
2
2
|
|
|
3
3
|
`)},15e3);e.raw.on(`close`,()=>{clearInterval(i)})}),r.delete(`${e}`,async(e,t)=>t.status(405).send({error:`Session termination not supported`}))}r.setErrorHandler(async(t,n,r)=>(n.log.error(t,`Fastify cube adapter error`),r.statusCode<400&&r.status(500),e.i(t instanceof Error?t:String(t),r.statusCode))),a()};async function i(e,t){await e.register(r,t)}function a(e){let t=require(`fastify`)({logger:!0});return t.register(r,e),t}exports.createCubeApp=a,exports.cubePlugin=r,exports.registerCubeRoutes=i;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as s } from "../compiler-
|
|
3
|
-
import { _ as c, a as l, d as u, f as d, g as f, h as p, i as m, m as h, p as g, r as _, s as v, v as y } from "../mcp-transport-
|
|
1
|
+
import { _ as e, a as t, f as n, i as r, o as i, r as a, u as o } from "../utils-IH1ePsBd.js";
|
|
2
|
+
import { t as s } from "../compiler-B_Nl7ZZb.js";
|
|
3
|
+
import { _ as c, a as l, d as u, f as d, g as f, h as p, i as m, m as h, p as g, r as _, s as v, v as y } from "../mcp-transport-CG5Aw2cs.js";
|
|
4
4
|
//#region src/adapters/fastify/index.ts
|
|
5
|
-
var b = function(
|
|
5
|
+
var b = function(e, b, x) {
|
|
6
6
|
let { cubes: S, drizzle: C, schema: w, extractSecurityContext: T, engineType: E, cors: D, basePath: O = "/cubejs-api/v1", bodyLimit: k = 10485760, cache: A, mcp: j = { enabled: !0 }, agent: M } = b;
|
|
7
7
|
if (!S || S.length === 0) return x(/* @__PURE__ */ Error("At least one cube must be provided in the cubes array"));
|
|
8
|
-
D &&
|
|
8
|
+
D && e.register(import("@fastify/cors"), D), e.addHook("onRequest", async (e, t) => {
|
|
9
9
|
e.method === "POST" && (e.body = void 0);
|
|
10
10
|
});
|
|
11
11
|
let N = new s({
|
|
@@ -17,7 +17,7 @@ var b = function(n, b, x) {
|
|
|
17
17
|
});
|
|
18
18
|
if (S.forEach((e) => {
|
|
19
19
|
N.registerCube(e);
|
|
20
|
-
}),
|
|
20
|
+
}), e.post(`${O}/load`, {
|
|
21
21
|
bodyLimit: k,
|
|
22
22
|
schema: { body: {
|
|
23
23
|
type: "object",
|
|
@@ -32,7 +32,7 @@ var b = function(n, b, x) {
|
|
|
32
32
|
} catch (n) {
|
|
33
33
|
return e.log.error(n, "Query execution error"), t.status(500).send(r(n instanceof Error ? n.message : "Query execution failed", 500));
|
|
34
34
|
}
|
|
35
|
-
}),
|
|
35
|
+
}), e.get(`${O}/load`, { schema: { querystring: {
|
|
36
36
|
type: "object",
|
|
37
37
|
properties: { query: { type: "string" } },
|
|
38
38
|
required: ["query"]
|
|
@@ -51,7 +51,7 @@ var b = function(n, b, x) {
|
|
|
51
51
|
} catch (n) {
|
|
52
52
|
return e.log.error(n, "Query execution error"), t.status(500).send(r(n instanceof Error ? n.message : "Query execution failed", 500));
|
|
53
53
|
}
|
|
54
|
-
}),
|
|
54
|
+
}), e.post(`${O}/batch`, {
|
|
55
55
|
bodyLimit: k,
|
|
56
56
|
schema: { body: {
|
|
57
57
|
type: "object",
|
|
@@ -68,13 +68,13 @@ var b = function(n, b, x) {
|
|
|
68
68
|
} catch (n) {
|
|
69
69
|
return e.log.error(n, "Batch execution error"), t.status(500).send(r(n instanceof Error ? n.message : "Batch execution failed", 500));
|
|
70
70
|
}
|
|
71
|
-
}),
|
|
71
|
+
}), e.get(`${O}/meta`, async (e, n) => {
|
|
72
72
|
try {
|
|
73
|
-
return
|
|
74
|
-
} catch (
|
|
75
|
-
return
|
|
73
|
+
return t(N.getMetadata());
|
|
74
|
+
} catch (t) {
|
|
75
|
+
return e.log.error(t, "Metadata error"), n.status(500).send(r(t instanceof Error ? t.message : "Failed to fetch metadata", 500));
|
|
76
76
|
}
|
|
77
|
-
}),
|
|
77
|
+
}), e.post(`${O}/sql`, {
|
|
78
78
|
bodyLimit: k,
|
|
79
79
|
schema: { body: {
|
|
80
80
|
type: "object",
|
|
@@ -91,7 +91,7 @@ var b = function(n, b, x) {
|
|
|
91
91
|
} catch (n) {
|
|
92
92
|
return e.log.error({ err: String(n).replace(/\n|\r/g, "") }, "SQL generation error"), t.status(500).send(r(n instanceof Error ? n.message : "SQL generation failed", 500));
|
|
93
93
|
}
|
|
94
|
-
}),
|
|
94
|
+
}), e.get(`${O}/sql`, { schema: { querystring: {
|
|
95
95
|
type: "object",
|
|
96
96
|
properties: { query: { type: "string" } },
|
|
97
97
|
required: ["query"]
|
|
@@ -106,37 +106,37 @@ var b = function(n, b, x) {
|
|
|
106
106
|
} catch (n) {
|
|
107
107
|
return e.log.error({ err: String(n).replace(/\n|\r/g, "") }, "SQL generation error"), t.status(500).send(r(n instanceof Error ? n.message : "SQL generation failed", 500));
|
|
108
108
|
}
|
|
109
|
-
}),
|
|
109
|
+
}), e.post(`${O}/dry-run`, {
|
|
110
110
|
bodyLimit: k,
|
|
111
111
|
schema: { body: {
|
|
112
112
|
type: "object",
|
|
113
113
|
additionalProperties: !0
|
|
114
114
|
} }
|
|
115
|
-
}, async (e,
|
|
115
|
+
}, async (e, t) => {
|
|
116
116
|
try {
|
|
117
|
-
let
|
|
118
|
-
return await t
|
|
119
|
-
} catch (
|
|
120
|
-
return e.log.error(
|
|
121
|
-
error:
|
|
117
|
+
let t = e.body;
|
|
118
|
+
return await n(t.query || t, await T(e), N);
|
|
119
|
+
} catch (n) {
|
|
120
|
+
return e.log.error(n, "Dry-run error"), t.status(400).send({
|
|
121
|
+
error: n instanceof Error ? n.message : "Dry-run validation failed",
|
|
122
122
|
valid: !1
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
}),
|
|
125
|
+
}), e.get(`${O}/dry-run`, { schema: { querystring: {
|
|
126
126
|
type: "object",
|
|
127
127
|
properties: { query: { type: "string" } },
|
|
128
128
|
required: ["query"]
|
|
129
|
-
} } }, async (e,
|
|
129
|
+
} } }, async (e, t) => {
|
|
130
130
|
try {
|
|
131
|
-
let { query:
|
|
132
|
-
return await
|
|
133
|
-
} catch (
|
|
134
|
-
return e.log.error(
|
|
135
|
-
error:
|
|
131
|
+
let { query: t } = e.query;
|
|
132
|
+
return await n(JSON.parse(t), await T(e), N);
|
|
133
|
+
} catch (n) {
|
|
134
|
+
return e.log.error(n, "Dry-run error"), t.status(400).send({
|
|
135
|
+
error: n instanceof Error ? n.message : "Dry-run validation failed",
|
|
136
136
|
valid: !1
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
}),
|
|
139
|
+
}), e.post(`${O}/explain`, {
|
|
140
140
|
bodyLimit: k,
|
|
141
141
|
schema: { body: {
|
|
142
142
|
type: "object",
|
|
@@ -149,7 +149,7 @@ var b = function(n, b, x) {
|
|
|
149
149
|
} catch (n) {
|
|
150
150
|
return e.log.error(n, "Explain error"), t.status(500).send({ error: n instanceof Error ? n.message : "Explain query failed" });
|
|
151
151
|
}
|
|
152
|
-
}), M &&
|
|
152
|
+
}), M && e.post(`${O}/agent/chat`, {
|
|
153
153
|
bodyLimit: k,
|
|
154
154
|
schema: { body: {
|
|
155
155
|
type: "object",
|
|
@@ -157,7 +157,7 @@ var b = function(n, b, x) {
|
|
|
157
157
|
} }
|
|
158
158
|
}, async (e, t) => {
|
|
159
159
|
try {
|
|
160
|
-
let { handleAgentChat: n } = await import("../handler-
|
|
160
|
+
let { handleAgentChat: n } = await import("../handler-RItnSaEl.js"), { message: r, sessionId: i, history: a } = e.body;
|
|
161
161
|
if (!r || typeof r != "string") return t.status(400).send({ error: "message is required and must be a string" });
|
|
162
162
|
let o = (M.apiKey || "").trim();
|
|
163
163
|
if (M.allowClientApiKey) {
|
|
@@ -199,8 +199,8 @@ var b = function(n, b, x) {
|
|
|
199
199
|
if (e.log.error(n, "Agent chat error"), !t.raw.headersSent) return t.status(500).send({ error: n instanceof Error ? n.message : "Agent chat failed" });
|
|
200
200
|
}
|
|
201
201
|
}), j.enabled !== !1) {
|
|
202
|
-
let
|
|
203
|
-
|
|
202
|
+
let t = j.basePath ?? "/mcp";
|
|
203
|
+
e.post(`${t}`, {
|
|
204
204
|
bodyLimit: k,
|
|
205
205
|
schema: { body: {
|
|
206
206
|
type: "object",
|
|
@@ -249,7 +249,7 @@ var b = function(n, b, x) {
|
|
|
249
249
|
}
|
|
250
250
|
return t.send(c);
|
|
251
251
|
}
|
|
252
|
-
}),
|
|
252
|
+
}), e.get(`${t}`, async (e, t) => {
|
|
253
253
|
let n = h();
|
|
254
254
|
t.raw.writeHead(200, {
|
|
255
255
|
"Content-Type": "text/event-stream",
|
|
@@ -266,16 +266,16 @@ var b = function(n, b, x) {
|
|
|
266
266
|
e.raw.on("close", () => {
|
|
267
267
|
clearInterval(r);
|
|
268
268
|
});
|
|
269
|
-
}),
|
|
269
|
+
}), e.delete(`${t}`, async (e, t) => t.status(405).send({ error: "Session termination not supported" }));
|
|
270
270
|
}
|
|
271
|
-
|
|
271
|
+
e.setErrorHandler(async (e, t, n) => (t.log.error(e, "Fastify cube adapter error"), n.statusCode < 400 && n.status(500), r(e instanceof Error ? e : String(e), n.statusCode))), x();
|
|
272
272
|
};
|
|
273
273
|
async function x(e, t) {
|
|
274
274
|
await e.register(b, t);
|
|
275
275
|
}
|
|
276
|
-
function S(
|
|
277
|
-
let
|
|
278
|
-
return
|
|
276
|
+
function S(t) {
|
|
277
|
+
let n = e("fastify")({ logger: !0 });
|
|
278
|
+
return n.register(b, t), n;
|
|
279
279
|
}
|
|
280
280
|
//#endregion
|
|
281
281
|
export { S as createCubeApp, b as cubePlugin, x as registerCubeRoutes };
|