import{r as e}from"./chunk-Bdh3yLIe.js";import{t}from"./client-types-CJfvFcC7.js";var n=e({FmMcpAdapter:()=>s}),r=Object.defineProperty,i=(e,t,n)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,a=(e,t,n)=>i(e,typeof t==`symbol`?t:t+``,n);const o=/\/+$/;var s=class{constructor(e){a(this,`baseUrl`),a(this,`connectedFileName`),a(this,`scriptName`),a(this,`request`,async e=>{let{action:n=`read`,layout:r,body:i,fetchOptions:a={}}=e,o={...i};`_offset`in o&&(o.offset=o._offset,o._offset=void 0),`_limit`in o&&(o.limit=o._limit,o._limit=void 0),`_sort`in o&&(o.sort=o._sort,o._sort=void 0);let s=JSON.stringify({...o,layouts:r,action:n,version:`vLatest`}),c=new AbortController,l=null;e.timeout&&(l=setTimeout(()=>c.abort(),e.timeout));let u=new Headers(a?.headers);u.set(`Content-Type`,`application/json`);let d;try{d=await fetch(`${this.baseUrl}/callScript`,{...a,method:`POST`,headers:u,body:JSON.stringify({connectedFileName:this.connectedFileName,scriptName:this.scriptName,data:s}),signal:c.signal})}finally{l&&clearTimeout(l)}if(!d.ok)throw new t(String(d.status),`FM MCP request failed (${d.status}): ${await d.text()}`);let f=await d.json(),p;try{p=typeof f.result==`string`?JSON.parse(f.result):f.result??f}catch(e){throw new t(`500`,`FM MCP response parse failed: ${e instanceof Error?e.message:String(e)}`)}let m=p,h=m.messages?.[0]?.code;if(h!==void 0&&h!==`0`)throw new t(h,`Filemaker Data API failed with (${h}): ${JSON.stringify(m,null,2)}`);return m.response}),a(this,`list`,async e=>await this.request({body:e.data,layout:e.layout,timeout:e.timeout,fetchOptions:e.fetch})),a(this,`get`,async e=>await this.request({body:e.data,layout:e.layout,timeout:e.timeout,fetchOptions:e.fetch})),a(this,`find`,async e=>await this.request({body:e.data,layout:e.layout,timeout:e.timeout,fetchOptions:e.fetch})),a(this,`create`,async e=>await this.request({action:`create`,body:e.data,layout:e.layout,timeout:e.timeout,fetchOptions:e.fetch})),a(this,`update`,async e=>await this.request({action:`update`,body:e.data,layout:e.layout,timeout:e.timeout,fetchOptions:e.fetch})),a(this,`delete`,async e=>await this.request({action:`delete`,body:e.data,layout:e.layout,timeout:e.timeout,fetchOptions:e.fetch})),a(this,`layoutMetadata`,async e=>await this.request({action:`metaData`,layout:e.layout,body:{},timeout:e.timeout,fetchOptions:e.fetch})),a(this,`executeScript`,async e=>{let n=await fetch(`${this.baseUrl}/callScript`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({connectedFileName:this.connectedFileName,scriptName:e.script,data:e.scriptParam})});if(!n.ok)throw new t(String(n.status),`FM MCP executeScript failed (${n.status}): ${await n.text()}`);let r=await n.json();return{scriptResult:typeof r.result==`string`?r.result:JSON.stringify(r.result)}}),a(this,`containerUpload`,()=>{throw Error(`Container upload is not supported via FM MCP adapter`)}),this.baseUrl=e.baseUrl.replace(o,``),this.connectedFileName=e.connectedFileName,this.scriptName=e.scriptName??`execute_data_api`}};export{n,s as t};
//# sourceMappingURL=fm-mcp-ISzxRLm9.js.map