@rushdb/javascript-sdk 3.0.1 → 3.1.0
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/README.md +2 -1
- package/dist/api/api.d.ts +44 -4
- package/dist/direct/capabilities.d.ts +1 -0
- package/dist/index.cjs +7 -7
- package/dist/index.mjs +6 -6
- package/dist/index.node.mjs +3 -3
- package/dist/types/value.d.ts +99 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var Ct=Object.defineProperty,kt=Object.defineProperties;var _t=Object.getOwnPropertyDescriptors;var me=Object.getOwnPropertySymbols;var Ye=Object.prototype.hasOwnProperty,
|
|
2
|
-
`)?`"${o.replace(/"/g,'""')}"`:o},
|
|
3
|
-
`)}setProperties(e,r){return h(this,null,function*(){let
|
|
1
|
+
var Ct=Object.defineProperty,kt=Object.defineProperties;var _t=Object.getOwnPropertyDescriptors;var me=Object.getOwnPropertySymbols;var Ye=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable;var Ge=Math.pow,Ke=(t,e,r)=>e in t?Ct(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l=(t,e)=>{for(var r in e||(e={}))Ye.call(e,r)&&Ke(t,r,e[r]);if(me)for(var r of me(e))Je.call(e,r)&&Ke(t,r,e[r]);return t},g=(t,e)=>kt(t,_t(e));var z=(t,e)=>{var r={};for(var n in t)Ye.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&me)for(var n of me(t))e.indexOf(n)<0&&Je.call(t,n)&&(r[n]=t[n]);return r};var h=(t,e,r)=>new Promise((n,s)=>{var a=d=>{try{i(r.next(d))}catch(c){s(c)}},o=d=>{try{i(r.throw(d))}catch(c){s(c)}},i=d=>d.done?n(d.value):Promise.resolve(d.value).then(a,o);i((r=r.apply(t,e)).next())});var Bt="string",vt="datetime",jt="boolean",Lt="number",ze=[Bt,vt,jt,Lt];var j=class t{makeRequest(e,{headers:r,method:n,protocol:s,requestData:a,timeout:o}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(t.TIMEOUT_ERROR_CODE);return e.code=t.TIMEOUT_ERROR_CODE,e}};j.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];j.TIMEOUT_ERROR_CODE="ETIMEDOUT";var ge=class{constructor(e,r){this._statusCode=e,this._headers=r}getStatusCode(){return this._statusCode}getHeaders(){return this._headers}getRawResponse(){throw new Error("getRawResponse not implemented.")}toStream(e){throw new Error("toStream not implemented.")}toJSON(){throw new Error("toJSON not implemented.")}},Oe=class{constructor(e){this._res=e}getStatusCode(){throw new Error("getStatusCode not implemented.")}getHeaders(){throw new Error("getHeaders not implemented.")}getRawResponse(){throw new Error("getRawResponse not implemented.")}toStream(e){throw new Error("toStream not implemented.")}toJSON(){throw new Error("toJSON not implemented.")}};var ye=class t extends j{constructor(e){if(super(),!e){if(!globalThis.fetch)throw new Error("fetch() function not provided and is not defined in the global scope. You must provide a fetch implementation.");e=globalThis.fetch}globalThis.AbortController?this._fetchFn=t.makeFetchWithAbortTimeout(e):this._fetchFn=t.makeFetchWithRaceTimeout(e)}static makeFetchWithRaceTimeout(e){return(r,n,s)=>{let a,o=new Promise((d,c)=>{a=setTimeout(()=>{a=null,c(j.makeTimeoutError())},s)}),i=e(r,n);return Promise.race([i,o]).finally(()=>{a&&clearTimeout(a)})}}static makeFetchWithAbortTimeout(e){return(r,n,s)=>h(this,null,function*(){let a=new AbortController,o=setTimeout(()=>{o=null,a.abort(j.makeTimeoutError())},s);try{return yield e(r,g(l({},n),{signal:a.signal}))}catch(i){throw i.name==="AbortError"?j.makeTimeoutError():i}finally{o&&clearTimeout(o)}})}makeRequest(i,d){return h(this,arguments,function*(e,{headers:r,method:n,protocol:s,requestData:a,timeout:o}){let c=n=="POST"||n=="PUT"||n=="PATCH",u=JSON.stringify(a)||(c?"":void 0),p=yield this._fetchFn(e,{body:u,headers:r,method:n},o!=null?o:8e4);return new Ae(p)})}},Ae=class t extends ge{constructor(e){super(e.status,t._transformHeadersToObject(e.headers)),this._res=e}getRawResponse(){return this._res}toStream(e){return e(),this._res.body}toJSON(){return this._res.json()}static _transformHeadersToObject(e){let r={};for(let n of e){if(!Array.isArray(n)||n.length!=2)throw new Error("Response objects produced by the fetch function given to FetchHttpClient do not have an iterable headers map. Response#headers should be an iterable object.");r[n[0]]=n[1]}return r}};var A=t=>typeof t=="object"&&Array.isArray(t)&&t!==null,q=t=>t!==null&&Object.prototype.toString.call(t)==="[object Object]",re=t=>q(t)&&Object.keys(t).length===0,qe=t=>typeof t=="number"||typeof t=="string"||typeof t=="boolean"||t===null;function Ut(t,e){let r=l({},t);return e.forEach(n=>{delete r[n]}),r}var ne=t=>q(t)?Ut(t,["__label","__id","__proptypes"]):t,X=t=>A(t)?t.map(X):q(t)?Object.fromEntries(Object.entries(t).filter(([e,r])=>r!==void 0).map(([e,r])=>[e,X(r)])):t,$e=t=>A(t)?t.every(qe):qe(t),se=t=>q(t)&&Object.values(t).every($e),Mt=t=>q(t)||A(t)&&!t.every(qe),Ze=t=>{if(A(t)||!q(t))return!0;let e=Object.values(t);return e.length===0?!0:e.some(r=>!Mt(r))},U=t=>typeof t=="string",k=t=>{if(typeof t=="string"){if(t.toLowerCase()==="true")return!0;if(t.toLowerCase()==="false")return!1}return A(t)&&t.length===0||q(t)&&Object.keys(t).length===0?!1:!!t};var Ce=["httpClient","timeout","host","port","protocol","url","logger","options","direct","engineUrl","scope"];var Q=class t extends Error{constructor(e,r){super(`Record with label "${e}" and properties ${JSON.stringify(r)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,t.prototype)}},L=class t extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,t.prototype)}},fe=class t extends Error{constructor(e,r){super(`Expected a unique result but found ${e} matches for the provided SearchQuery: ${JSON.stringify(r)}. Ensure your search parameters uniquely identify a single result.`),this.name="NonUniqueResultError",Object.setPrototypeOf(this,t.prototype)}},ae=class t extends Error{constructor(r,n){super(`${r} requires RushDB Cloud: ${n}. It is not available in direct mode.`);this.method=r;this.reason=n;this.code="CLOUD_ONLY";this.name="CloudOnlyError",Object.setPrototypeOf(this,t.prototype)}},he=class t extends Error{constructor(r){super(r);this.code="DIRECT_MODE_UNSUPPORTED";this.name="DirectModeError",Object.setPrototypeOf(this,t.prototype)}};var Se=(t,e)=>h(void 0,null,function*(){let r=Object.entries(t).map(i=>h(void 0,[i],function*([a,o]){return o.default&&typeof o.default!="undefined"&&typeof e[a]=="undefined"?{key:a,value:typeof o.default=="function"?yield o.default():o.default}:{key:a,value:void 0}})),s=(yield Promise.all(r)).reduce((a,{key:o,value:i})=>(i!==void 0&&(a[o]=i),a),{});return l(l({},s),e)}),ke=(t,e)=>Object.entries(e).filter(([r])=>{var n;return(n=t[r])==null?void 0:n.unique}).reduce((r,[n,s])=>(n in t&&(r[n]=s),r),{}),et=(t,e,r)=>{let n={},s=Object.entries(e).filter(([,a])=>a.unique).reduce((a,[o])=>(a[o]=!0,a),{});return t.forEach(a=>{Object.entries(a).forEach(([o,i])=>{if(o in s)if(n[o]){if(n[o].includes(i))throw new Q(r,{[o]:i});n[o]=[...n[o],i]}else n[o]=[i]})}),n},tt=t=>{if(!t)return{};if(!q(t))throw new Error("Config must be an object");if(Object.keys(t).filter(r=>!Ce.includes(r)).length>0)throw new Error(`Config object may only contain the following: ${Ce.join(", ")}`);return t};function rt(t,e,r){if(!Number.isInteger(e)){if(r!==void 0)return r;throw new Error(`${t} must be an integer`)}return e}function _e(t){let e=t.split("-"),r=e[0]+e[1].slice(0,4);return parseInt(r,16)}function nt(t){return new Date(_e(t))}var E=class{constructor(e={}){this.data=e}get exists(){return k(this.data.__id)&&k(this.data.__label)}get id(){if(!k(this.data.__id))throw new Error("DBRecordInstance: Unable to access 'id'. The Record's `data.__id` is missing or incorrect.");return this.data.__id}get label(){if(!k(this.data.__label))throw new Error("DBRecordInstance: Unable to access 'label'. The Record's `data.__label` is missing or incorrect.");return this.data.__label}get proptypes(){if(!k(this.data.__proptypes))throw new Error("DBRecordInstance: Unable to access 'proptypes'. The Record's `data.__proptypes` is missing or incorrect.");return this.data.__proptypes}get date(){try{return nt(this.id)}catch(e){throw new Error("DBRecordInstance: Unable to access 'date'. The Record's `data.__id` is missing or incorrect.")}}get timestamp(){try{return _e(this.id)}catch(e){throw new Error("DBRecordInstance: Unable to access 'timestamp'. The Record's `data.__id` is missing or invalid.")}}get score(){return this.data.__score}delete(e){return h(this,null,function*(){if(!k(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return yield D.getInstance().records.deleteById(this.id,e)})}update(e,r){return h(this,null,function*(){if(!k(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return D.getInstance().records.update({label:this.label,target:this.id,data:e},r)})}set(e,r){return h(this,null,function*(){if(!k(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return D.getInstance().records.set({label:this.label,target:this.id,data:e},r)})}attach(e,r,n){return h(this,null,function*(){if(!k(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return D.getInstance().records.attach({source:this.id,target:e,options:r},n)})}detach(e,r,n){return h(this,null,function*(){if(!k(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return D.getInstance().records.detach({source:this.id,target:e,options:r},n)})}},B=class{constructor(e=[],r=0,n,s){this.data=e,this.total=r,this.searchQuery=n,this.warnings=s}deleteAll(e){return h(this,null,function*(){let r=this.data.map(s=>s.id);return r.length?yield D.getInstance().records.deleteById(r,e):{success:!0}})}next(e){return h(this,null,function*(){var i,d;if(!this.searchQuery)throw new Error("DBRecordsArrayInstance: Cannot paginate \u2014 no searchQuery was provided.");let r=(i=this.searchQuery.skip)!=null?i:0,n=(d=this.searchQuery.limit)!=null?d:100,s=g(l({},this.searchQuery),{skip:r+n}),o=yield D.getInstance().records.find(s,void 0);return e!=null&&e.preserveData?(this.data=[...this.data,...o.data],this.total=o.total,this.searchQuery=s,this):o})}exportCsv(){if(!this.data.length)return"";let e=new Set(["__id","__label","__proptypes"]),r=Object.keys(this.data[0].data).filter(a=>!e.has(a)),n=a=>{let o=a==null?"":String(a);return o.includes(",")||o.includes('"')||o.includes(`
|
|
2
|
+
`)?`"${o.replace(/"/g,'""')}"`:o},s=this.data.map(a=>r.map(o=>n(a.data[o])).join(","));return[r.join(","),...s].join(`
|
|
3
|
+
`)}setProperties(e,r){return h(this,null,function*(){let s=D.getInstance();for(let a=0;a<this.data.length;a+=100){let o=this.data.slice(a,a+100);yield Promise.all(o.map(i=>s.records.update({target:i.id,label:i.data.__label,data:e},r)))}})}};var Re=class{constructor(e){this.baseUrl=e.engineUrl.replace(/\/$/,""),this.token=e.token,this.httpClient=e.httpClient,this.scope=e.scope}execute(e){return h(this,null,function*(){var i,d;let r=g(l({protocolVersion:1},this.scope?{context:{scope:this.scope}}:{}),{operation:e}),n={"Content-Type":"application/json",Authorization:`Bearer ${this.token}`};this.scope&&(n["X-RushDB-Tenant"]=this.scope);let s=yield this.httpClient.makeRequest(`${this.baseUrl}/protocol/v1/execute`,{method:"POST",headers:n,requestData:r}),a=s.getStatusCode(),o=yield s.toJSON().catch(()=>{});if(a>=400||o!=null&&o.error||!(o!=null&&o.response)){let c=(d=(i=o==null?void 0:o.error)==null?void 0:i.message)!=null?d:"engine request failed",u=new Error(`${a} ${c}`);throw u.status=a,u.body=o,u}return o.response})}};var we={"ai.search":"natural-language search turns the prompt into a query with an LLM","ai.getJoinCandidates":"join suggestions are computed by the platform (its heuristics over the engine's value overlap)","relationships.patterns.list":"relationship-pattern suggestions are produced and stored by the platform","relationships.patterns.analyze":"relationship-pattern suggestions are produced and stored by the platform","relationships.patterns.approve":"relationship-pattern suggestions are produced and stored by the platform","relationships.patterns.ignore":"relationship-pattern suggestions are produced and stored by the platform","relationships.patterns.delete":"relationship-pattern suggestions are produced and stored by the platform","settings.get":"project settings belong to the platform"},xe={"records.vectorSearch":"a text `query` is embedded with the managed embedding model; in direct mode pass `queryVector`","ai.indexes.create":"a managed index is filled by the managed embedding model; in direct mode create an external index (`external: true`) and supply vectors"},Vt=t=>Object.prototype.hasOwnProperty.call(we,t);var Be=(t,e,r)=>h(void 0,null,function*(){var p,m,f,y,R,I,C,V,N,J,de,le,F,H,G,pe,Ne,Fe,He,Qe;let[n,s]=yield Promise.all([t.execute({kind:"describe",describe:{kind:"schema",query:{labels:[],predicate:{},offset:0}}}),t.execute({kind:"describe",describe:{kind:"vectorIndexes"}})]),a=(p=n.schema)!=null?p:{labels:[],properties:[],relationships:[]},o=new Map;for(let S of(m=a.properties)!=null?m:[]){let O=(f=S.label)!=null?f:"";if(!O)continue;let P={id:String(S.id),name:String(S.name),type:String((y=S.type)!=null?y:"string"),recordsCount:Number((R=S.recordsCount)!=null?R:0),isArray:(I=S.isArray)!=null?I:void 0};if(P.type==="boolean")P.values=["true","false"];else if(P.type==="string"){let $t=((C=S.sampleValues)!=null?C:[]).filter(We=>We!=null).map(String);P.values=[...new Set($t)].slice(0,10)}S.min!==void 0&&S.min!==null&&(P.min=P.type==="number"?Number(S.min):String(S.min)),S.max!==void 0&&S.max!==null&&(P.max=P.type==="number"?Number(S.max):String(S.max));let te=(V=o.get(O))!=null?V:[];te.push(P),o.set(O,te)}let i=((N=a.labels)!=null?N:[]).map(S=>{var O,P;return{label:S.name,count:Number((O=S.recordsCount)!=null?O:0),properties:(P=o.get(S.name))!=null?P:[],relationships:[]}}),d=new Map(i.map(S=>[S.label,S])),c=(S,O)=>{let P=d.get(S);P&&!P.relationships.some(te=>te.direction===O.direction&&te.label===O.label&&te.type===O.type)&&P.relationships.push(O)};for(let S of(J=a.relationships)!=null?J:[]){let O=(de=S.properties)!=null&&de.length?S.properties:void 0;c(S.sourceLabel,{label:S.targetLabel,type:S.type,direction:"out",count:S.count,properties:O}),S.sourceLabel!==S.targetLabel&&c(S.targetLabel,{label:S.sourceLabel,type:S.type,direction:"in",count:S.count,properties:O})}let u=new Map;for(let S of((le=s.indexes)!=null?le:[]).map(r)){let O=`${S.label}|${S.propertyName}`,P=(F=u.get(O))!=null?F:[];P.push({id:String((H=S.id)!=null?H:""),name:String((G=S.name)!=null?G:""),sourceType:String((pe=S.sourceType)!=null?pe:"external"),similarityFunction:String((Ne=S.similarityFunction)!=null?Ne:"cosine"),dimensions:Number((Fe=S.dimensions)!=null?Fe:0),status:String((He=S.status)!=null?He:"pending"),modelKey:String((Qe=S.modelKey)!=null?Qe:"")}),u.set(O,P)}for(let S of i){S.relationships.sort((O,P)=>`${O.direction}|${O.label}|${O.type}`.localeCompare(`${P.direction}|${P.label}|${P.type}`));for(let O of S.properties){let P=u.get(`${S.label}|${O.name}`);P!=null&&P.length&&(O.vectorIndexes=P)}}return i.sort((S,O)=>O.count-S.count),e!=null&&e.length?i.filter(S=>e.includes(S.label)):i}),st=t=>{var i,d;let e=c=>String(c).replace(/\|/g,"\\|").replace(/`/g,"\\`"),s=c=>c.length>48?c.slice(0,48)+"\u2026":c,a=c=>{let u=(c.type||"").toLowerCase();if(u==="number"||u==="datetime")return c.min!==void 0&&c.max!==void 0?`\`${c.min}\`..\`${c.max}\``:"\u2014";if(Array.isArray(c.values)&&c.values.length>0){let p=c.values.slice(0,5),m=c.values.length>5?` (+${c.values.length-5} more)`:"";return p.map(f=>`\`${e(s(String(f)))}\``).join(", ")+m}return"\u2014"},o=`# Graph Schema
|
|
4
4
|
|
|
5
5
|
## Labels
|
|
6
6
|
|
|
@@ -16,12 +16,12 @@ var Ct=Object.defineProperty,kt=Object.defineProperties;var _t=Object.getOwnProp
|
|
|
16
16
|
|
|
17
17
|
`,o+=`| Property | Type | Values / Range | Semantic Search |
|
|
18
18
|
|----------|------|----------------|-----------------|
|
|
19
|
-
`;for(let
|
|
19
|
+
`;for(let p of c.properties){let m=(i=p.vectorIndexes)!=null&&i.length?p.vectorIndexes.map(y=>`\`${y.name}\` (${y.sourceType}, ${y.similarityFunction}, ${y.dimensions}d) [${y.status}]`).join(", "):"\u2014",f=p.isArray?`${p.type}[]`:p.type;o+=`| \`${e(p.name)}\` | ${e(f)} | ${a(p)} | ${m} |
|
|
20
20
|
`}o+=`
|
|
21
21
|
`}if(c.relationships.length>0){o+=`### Relationships
|
|
22
22
|
|
|
23
23
|
`,o+=`| Traversal | Count | Edge Properties |
|
|
24
24
|
|-----------|------:|-----------------|
|
|
25
|
-
`;for(let
|
|
25
|
+
`;for(let p of c.relationships){let m=(d=p.properties)!=null&&d.length?p.properties.map(R=>`\`${e(R.name)}:${e(R.type)}\``).join(", "):"\u2014",f=p.direction==="out"?`(${c.label})-[:${p.type}]->(${p.label})`:`(${c.label})<-[:${p.type}]-(${p.label})`,y=typeof p.count=="number"?String(p.count):"\u2014";o+=`| \`${e(f)}\` | ${y} | ${m} |
|
|
26
26
|
`}o+=`
|
|
27
|
-
`}}return o.trim()};var x=(t,e={})=>p({success:!0,data:t},e),_=(t,e)=>{let r=new Error(`${t} ${e}`);return r.status=t,r.body={statusCode:t,message:e},r},X=t=>()=>h(void 0,null,function*(){throw new ae(t,we[t])}),W=(t,e)=>{if(t)throw new he(`${e} inside a transaction is not supported in direct mode: the engine stages record creates, updates, deletes, links and imports. Run it outside the transaction.`)},ht="__RUSHDB__RELATION__DEFAULT__",Z=(t,e,r)=>t.execute({kind:"transaction",transaction:{kind:"stage",transactionId:e,mutation:r}}),ve=(t,e,r)=>h(void 0,null,function*(){var n;let{record:s}=yield Z(t,e,{kind:"getRecord",record:{id:r}});return f(p({},(n=s==null?void 0:s.properties)!=null?n:{}),{__id:r,__label:s==null?void 0:s.__label,__proptypes:{}})}),ut=(t,e)=>{t&&Array.isArray(e)&&e.length>0&&W(t,"A write with inline vectors")},Ie=t=>{var r,s;if(!t)return t;let e=p({},(r=t.properties)!=null?r:{});return e.__id=t.id,e.__label=t.label,e.__proptypes=(s=t.propertyTypes)!=null?s:{},t.score!==void 0&&(e.__score=t.score),e},Pe=t=>(t!=null?t:[]).map(e=>Ie(e)),Le=t=>t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:Array.isArray(t.properties)?Object.fromEntries(t.properties.map(e=>[e.name,e.value])):t.properties&&typeof t.properties=="object"?t.properties:{},Vt=t=>t==null||typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0?"desc":typeof t!="object"||Array.isArray(t)?t:Object.fromEntries(Object.entries(t).map(([e,r])=>[e==="__id"?"id":e,r])),oe=(t={})=>{var s,n,a,o,i,d;let e=(s=t.pagination)!=null?s:{},r={labels:(n=t.labels)!=null?n:[],predicate:(a=t.where)!=null?a:{},select:t.select,order:Vt(t.orderBy),offset:(i=(o=t.skip)!=null?o:e.skip)!=null?i:0,limit:(d=t.limit)!=null?d:e.limit};return Array.isArray(t.groupBy)&&t.groupBy.length>0&&(r.groupBy=t.groupBy),r},be=t=>t==null||typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0,Ne=(t,e)=>h(void 0,null,function*(){return(yield t.execute({kind:"query",query:{kind:"record",id:e}})).record}),mt=(t,e)=>h(void 0,null,function*(){var s,n,a;let r=yield t.execute({kind:"query",query:{kind:"records",query:oe(e)}});return r.kind==="rows"?{data:(s=r.rows)!=null?s:[],total:(n=r.total)!=null?n:0}:{data:Pe(r.records),total:(a=r.total)!=null?a:0}}),ie=t=>h(void 0,null,function*(){var e;return(e=(yield t.execute({kind:"describe",describe:{kind:"vectorIndexes"}})).indexes)!=null?e:[]}),Ue=t=>h(void 0,null,function*(){var e;return(e=(yield t.execute({kind:"describe",describe:{kind:"indexes"}})).indexes)!=null?e:[]}),ue=t=>{var r;let e=Number((r=t.dimensions)!=null?r:0);return{id:t.name,name:t.name,label:t.label,propertyName:t.property,vectorPropertyName:`_emb_external_${t.similarity}_${e}`,similarityFunction:t.similarity,dimensions:e,sourceType:"external",status:t.status}},gt=t=>{var e,r;return{name:t.name,label:t.label,property:t.property,consistency:(e=t.consistency)!=null?e:"eventual",status:t.state,pending:(r=t.pending)!=null?r:0}},Me=t=>h(void 0,null,function*(){return(yield Ue(t)).filter(e=>e.kind==="text").map(gt)}),yt=64,ft=t=>t.join(".").slice(0,yt).replace(/[.:-]+$/,""),De=t=>t.replace(/[^A-Za-z0-9_-]/g,"-"),je=(t,e)=>{if(!e.has(t))return t;for(let r=2;;r++){let s=`-${r}`,n=t.slice(0,yt-s.length)+s;if(!e.has(n))return n}},at=({label:t,property:e})=>ft([De(t),e==="*"?"all":De(e),"text"]),Ft=(t,e,r)=>ft([De(t.label),De(t.propertyName),"external",String(e),r]).replace(/^emb__/,"emb_"),Ee=(t,e,r,s)=>h(void 0,null,function*(){if(!Array.isArray(e)||e.length===0)return[];let n=s!=null?s:yield ie(t);return e.map(a=>{if(typeof(a==null?void 0:a.index)=="string")return a;if(!r)throw _(422,"inline vectors require a record label to select their index");let o=Array.isArray(a.vector)?a.vector.length:void 0,i=n.filter(d=>d.label===r&&d.property===a.propertyName&&(a.similarityFunction===void 0||d.similarity===a.similarityFunction)&&(o===void 0||Number(d.dimensions)===o));if(i.length!==1)throw _(i.length===0?404:422,i.length===0?`No vector index matches label "${r}", property "${a.propertyName}"`:`${i.length} vector indexes match label "${r}", property "${a.propertyName}"; name one with \`index\``);return f(p({},a),{index:i[0].name})})}),Ht=(t,e,r)=>h(void 0,null,function*(){let s=Array.isArray(e)?e:[e],n=i=>Array.isArray(i==null?void 0:i.$vectors)&&i.$vectors.length>0;if(!s.some(n))return e;let a=yield ie(t),o=yield Promise.all(s.map(i=>h(void 0,null,function*(){return n(i)?f(p({},i),{$vectors:yield Ee(t,i.$vectors,r,a)}):i})));return Array.isArray(e)?o:o[0]}),Qt=()=>{var s;let t=new Uint8Array(16);if(typeof((s=globalThis.crypto)==null?void 0:s.getRandomValues)=="function")globalThis.crypto.getRandomValues(t);else for(let n=0;n<16;n++)t[n]=Math.floor(Math.random()*256);let e=Date.now();for(let n=0;n<6;n++)t[n]=Math.floor(e/Je(2,8*(5-n)))&255;t[6]=t[6]&15|112,t[8]=t[8]&63|128;let r=Array.from(t,n=>n.toString(16).padStart(2,"0")).join("");return`${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20)}`},Wt=s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){var d,c,u,l,m,y;let n=!!((d=t.options)!=null&&d.mergeStrategy)||Array.isArray((c=t.options)==null?void 0:c.mergeBy),a=Le(t);if(r){n&&W(r,"An upsert"),ut(r,t.vectors);let g=Qt();return yield Z(e,r,{kind:"createRecord",label:t.label,id:g,properties:a,options:(u=t.options)!=null?u:{}}),x(yield ve(e,r,g))}let o=n?f(p({},t.options),{mergeBy:(m=(l=t.options)==null?void 0:l.mergeBy)!=null?m:[]}):(y=t.options)!=null?y:{},i=yield e.execute({kind:"mutate",mutation:{kind:"putRecord",mode:"create",label:t.label,properties:a,vectors:yield Ee(e,t.vectors,t.label),options:o}});return x(Ie(i.record))}),ot=t=>a=>h(void 0,[a],function*({body:e,params:[r],engine:s,txId:n}){var c,u;let o=typeof e.label=="string"&&e.label?e.label:void 0;if(n){if(ut(n,e.vectors),o){let l=yield ve(s,n,r);l.__label&&l.__label!==o&&(yield Z(s,n,{kind:"retypeRecord",record:{id:r},fromLabel:l.__label,toLabel:o}))}return yield Z(s,n,{kind:"updateRecord",record:{id:r},properties:Le(e),replace:t==="replace"}),x(yield ve(s,n,r))}let i=o;if(o||(c=e.vectors)!=null&&c.length){let l=yield Ne(s,r);o&&(l!=null&&l.label)&&l.label!==o&&(yield s.execute({kind:"mutate",mutation:{kind:"retypeRecord",id:r,fromLabel:l.label,toLabel:o}})),i=o!=null?o:l==null?void 0:l.label}let d=yield s.execute({kind:"mutate",mutation:{kind:"putRecord",mode:t,id:r,properties:Le(e),vectors:yield Ee(s,e.vectors,i),options:(u=e.options)!=null?u:{}}});return x(Ie(d.record))}),Kt=(t,e,r)=>h(void 0,null,function*(){var o;if(!e)return r;let s;try{s=(o=yield Ne(t,e))==null?void 0:o.label}catch(i){if((i==null?void 0:i.status)===404)return;throw i}let n={[s]:{$id:e}},a=r.where;return f(p({},r),{where:be(a)?n:{$and:[a,n]}})}),it=s=>h(void 0,[s],function*({body:t,params:[e],engine:r}){let n=yield Kt(r,e,t);if(!n)return x([],{total:0});let{data:a,total:o}=yield mt(r,n);return x(a,{total:o})}),ct=(t,e,r)=>e?Z(t,e,{kind:"ingest",ingest:r}):t.execute({kind:"ingest",ingest:r}),dt=(t,e)=>{var r,s;return e&&((r=t.records)!=null&&r.length)?x(Pe(t.records)):x({message:"Records have been successfully imported",count:Number((s=t.count)!=null?s:0)})},Yt=["delimiter","header","skipEmptyLines","dynamicTyping","quoteChar","escapeChar","newline"],lt=t=>{var e,r,s,n,a,o,i,d,c,u,l,m;return{relationType:(e=t.type)!=null?e:ht,direction:String((r=t.direction)!=null?r:"").toLowerCase()==="in"?"in":"out",allowCartesian:(s=t.manyToMany)!=null?s:!1,properties:(n=t.properties)!=null?n:{},source:{label:(a=t.source)==null?void 0:a.label,property:(o=t.source)==null?void 0:o.key,predicate:(d=(i=t.source)==null?void 0:i.where)!=null?d:{}},target:{label:(c=t.target)==null?void 0:c.label,property:(u=t.target)==null?void 0:u.key,predicate:(m=(l=t.target)==null?void 0:l.where)!=null?m:{}}}},Te=t=>Array.isArray(t)?t:[t],Gt=t=>{var r,s;let e=new Map;for(let n of t){let a=e.get(n.id);if(a){a.recordsCount+=Number((r=n.recordsCount)!=null?r:0),a.isArray||(a.isArray=n.isArray===!0);continue}e.set(n.id,{id:n.id,name:n.name,type:n.type,recordsCount:Number((s=n.recordsCount)!=null?s:0),isArray:n.isArray===!0})}return Array.from(e.values(),o=>{var i=o,{isArray:n}=i,a=J(i,["isArray"]);return f(p({},a),{metadata:JSON.stringify({cardinality:n?"OrderedMany":"Single",nullability:"Nullable"})})})},St=(r,...s)=>h(void 0,[r,...s],function*(t,e={}){var a;let n=yield t.execute({kind:"describe",describe:p({kind:"properties",query:oe(e)},be(e.where)?{detail:"catalog"}:{})});return Gt((a=n.properties)!=null?a:[])}),pt=(t,e)=>h(void 0,null,function*(){var s;let r=(yield St(t)).find(n=>n.name===e||n.id===e);return r&&f(p({},r),{id:(s=r.id)!=null?s:r.name})}),Rt=(t,e,r)=>h(void 0,null,function*(){var a,o;if(typeof e.query!="string"||e.query.trim()==="")throw _(422,"text.query is required");let s=yield Me(t),n;if(e.index!==void 0){if(n=s.find(i=>i.name===e.index),!n)throw _(404,`No text index named "${e.index}"`)}else{let i=r[0];if(!i)throw _(422,"Name a text index with `index`, or give `labels`");let d=s.filter(c=>c.label===i&&c.status==="ready"&&(e.property===void 0||c.property===e.property));if(d.length===0)throw _(404,`No ready text index on label "${i}"`);if(d.length>1)throw _(422,`Label "${i}" has several text indexes (${d.map(c=>c.name).join(", ")}); name one with \`index\``);n=d[0]}return{index:n.name,label:n.label,query:e.query,allTerms:(a=e.allTerms)!=null?a:!1,phrase:(o=e.phrase)!=null?o:!1}}),Jt=r=>h(void 0,[r],function*({body:t,engine:e}){var m,y,g,R,I,C,N,V,Y,de,le;let s=(m=t.queryVector)!=null?m:[];if(s.length===0)throw new ae("records.vectorSearch",xe["records.vectorSearch"]);let n=yield ie(e),a;if(typeof t.index=="string"){if(a=n.find(F=>F.name===t.index),!a)throw _(404,`No vector index named "${t.index}"`)}else{let F=((y=t.labels)!=null?y:[])[0],H=n.filter(G=>{var pe;return G.label===F&&G.property===t.propertyName&&(t.similarityFunction===void 0||G.similarity===t.similarityFunction)&&Number(G.dimensions)===((pe=t.dimensions)!=null?pe:s.length)});if(H.length!==1)throw _(H.length===0?404:422,H.length===0?`No vector index matches label "${F}", property "${t.propertyName}"`:`${H.length} vector indexes match label "${F}", property "${t.propertyName}"; name one with \`index\``);a=H[0]}let o=(g=t.labels)!=null&&g.length?t.labels:[a.label],i={property:a.property,vector:s,similarity:(R=a.similarity)!=null?R:"cosine",index:a.name,mode:t.mode,ef:t.ef,scoreThreshold:t.scoreThreshold},d=t.text?yield Rt(e,f(p({},t.text),{query:(I=t.text.query)!=null?I:t.query}),o):void 0,c=d?{kind:"hybrid",query:{labels:o,predicate:(C=t.where)!=null?C:{},vector:f(p({},i),{weight:t.weight,prefetchLimit:t.prefetchLimit}),text:{index:d.index,query:d.query,allTerms:d.allTerms,phrase:d.phrase,weight:t.text.weight,prefetchLimit:t.text.prefetchLimit},fusion:t.fusion,rrfK:t.rrfK,offset:(N=t.skip)!=null?N:0,limit:(V=t.limit)!=null?V:10}}:{kind:"vector",query:f(p({},i),{labels:o,predicate:(Y=t.where)!=null?Y:{},offset:(de=t.skip)!=null?de:0,limit:(le=t.limit)!=null?le:10})},u=yield e.execute({kind:"query",query:c}),l=Pe(u.records);return x(l,{total:l.length,meta:{vectorSearch:u.vectorSearch,textSearch:u.textSearch,fusion:u.fusion}})}),$="([^/]+)",wt=[{method:"GET",pattern:new RegExp(`^/records/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){return x(Ie(yield Ne(e,t)))})},{method:"POST",pattern:/^\/records$/,handle:Wt},{method:"PATCH",pattern:new RegExp(`^/records/${$}$`),handle:ot("merge")},{method:"PUT",pattern:new RegExp(`^/records/${$}$`),handle:ot("replace")},{method:"DELETE",pattern:new RegExp(`^/records/${$}$`),handle:s=>h(void 0,[s],function*({params:[t],engine:e,txId:r}){return r?yield Z(e,r,{kind:"deleteRecord",record:{id:t}}):yield e.execute({kind:"mutate",mutation:{kind:"deleteRecord",id:t}}),x({message:"Record deleted"})})},{method:"POST",pattern:/^\/records\/delete$/,handle:s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){var a;W(r,"records.delete");let n=yield e.execute({kind:"mutate",mutation:{kind:"deleteRecords",query:oe(t)}});return x({message:`${(a=n.affected)!=null?a:0} records deleted`})})},{method:"POST",pattern:/^\/records\/search$/,handle:it},{method:"POST",pattern:new RegExp(`^/records/${$}/search$`),handle:it},{method:"POST",pattern:/^\/records\/import\/json$/,handle:s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){var a,o;let n=yield ct(e,r,{kind:"documents",label:t.label,documents:yield Ht(e,t.data,t.label),options:(a=t.options)!=null?a:{}});return dt(n,(o=t.options)==null?void 0:o.returnResult)})},{method:"POST",pattern:/^\/records\/import\/csv$/,handle:s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){var d,c,u,l,m,y,g;let n=(d=t.vectors)!=null&&d.length?yield ie(e):[],a=yield Promise.all(((c=t.vectors)!=null?c:[]).map(R=>Ee(e,R,t.label,n))),o=Object.fromEntries(Object.entries((u=t.parseConfig)!=null?u:{}).filter(([R])=>Yt.includes(R))),i=yield ct(e,r,{kind:"csv",label:t.label,data:(l=t.data)!=null?l:"",parseConfig:o,options:(m=t.options)!=null?m:{},vectors:a});return Number((y=i.count)!=null?y:0)===0?x(!0):dt(i,(g=t.options)==null?void 0:g.returnResult)})},{method:"POST",pattern:/^\/records\/export\/csv$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){let s=yield e.execute({kind:"query",query:{kind:"exportCsv",query:oe({labels:t.labels,where:t.where,orderBy:t.orderBy,skip:typeof t.skip=="number"?t.skip:0,limit:typeof t.limit=="number"?t.limit:100})}});return x({fileContent:s.content,dateTime:new Date().toISOString()})})},{method:"POST",pattern:new RegExp(`^/relationships/${$}$`),handle:n=>h(void 0,[n],function*({body:t,params:[e],engine:r,txId:s}){var i,d,c,u;let a=(i=t.type)!=null?i:ht,o=String((d=t.direction)!=null?d:"").toLowerCase()==="in";if(s)for(let l of Te(t.targetIds))yield Z(r,s,{kind:"createRelationship",relationType:a,source:{id:o?l:e},target:{id:o?e:l},properties:(c=t.properties)!=null?c:{}});else yield r.execute({kind:"mutate",mutation:{kind:"linkRecordsById",command:{relationType:a,direction:o?"in":"out",sourceIds:[e],targetIds:Te(t.targetIds),properties:(u=t.properties)!=null?u:{}}}});return x({message:`Relations to Record ${e} have been successfully created`})})},{method:"PUT",pattern:new RegExp(`^/relationships/${$}$`),handle:n=>h(void 0,[n],function*({body:t,params:[e],engine:r,txId:s}){var o;W(s,"records.detach");let a=String((o=t.direction)!=null?o:"").toLowerCase();return yield r.execute({kind:"mutate",mutation:{kind:"unlinkRecordsById",command:f(p({relationTypes:Te(t.typeOrTypes).filter(Boolean)},a==="in"||a==="out"?{direction:a}:{}),{sourceIds:[e],targetIds:Te(t.targetIds)})}}),x({message:`Relations to Record ${e} have been successfully deleted`})})},{method:"POST",pattern:/^\/relationships\/create-many$/,handle:s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){return W(r,"relationships.createMany"),yield e.execute({kind:"mutate",mutation:{kind:"linkRecords",command:lt(t)}}),x({message:"Relations have been successfully created"})})},{method:"POST",pattern:/^\/relationships\/delete-many$/,handle:s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){return W(r,"relationships.deleteMany"),yield e.execute({kind:"mutate",mutation:{kind:"unlinkRecords",command:lt(t)}}),x({message:"Relations have been successfully deleted"})})},{method:"POST",pattern:/^\/relationships\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var n,a,o,i,d,c,u,l,m,y,g;let s=yield e.execute({kind:"query",query:{kind:"relationships",query:{sourceLabels:(a=(n=t.source)==null?void 0:n.labels)!=null?a:[],targetLabels:(i=(o=t.target)==null?void 0:o.labels)!=null?i:[],relationType:(d=t.where)==null?void 0:d.type,predicate:Object.fromEntries(Object.entries((c=t.where)!=null?c:{}).filter(([R])=>R!=="type")),sourcePredicate:be((u=t.source)==null?void 0:u.where)?void 0:t.source.where,targetPredicate:be((l=t.target)==null?void 0:l.where)?void 0:t.target.where,offset:(m=t.skip)!=null?m:0,limit:t.limit}}});return x((y=s.relationships)!=null?y:[],{total:(g=s.total)!=null?g:0})})},{method:"GET",pattern:/^\/relationships\/patterns$/,handle:X("relationships.patterns.list")},{method:"POST",pattern:/^\/relationships\/patterns\/analyze$/,handle:X("relationships.patterns.analyze")},{method:"POST",pattern:new RegExp(`^/relationships/patterns/${$}/approve$`),handle:X("relationships.patterns.approve")},{method:"POST",pattern:new RegExp(`^/relationships/patterns/${$}/ignore$`),handle:X("relationships.patterns.ignore")},{method:"DELETE",pattern:new RegExp(`^/relationships/patterns/${$}$`),handle:X("relationships.patterns.delete")},{method:"POST",pattern:/^\/properties\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var s,n;return x(yield St(e,{labels:(s=t.labels)!=null?s:[],where:(n=t.where)!=null?n:{}}))})},{method:"GET",pattern:new RegExp(`^/properties/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){let s=yield pt(e,t);if(!s)throw _(404,`property \`${t}\` does not exist`);return x(s)})},{method:"DELETE",pattern:new RegExp(`^/properties/${$}$`),handle:s=>h(void 0,[s],function*({params:[t],engine:e,txId:r}){W(r,"properties.delete");let n=yield pt(e,t);if(!n)throw _(404,`property \`${t}\` does not exist`);return yield e.execute({kind:"mutate",mutation:{kind:"deleteProperty",name:n.name}}),x({message:`Property (${t}) has been successfully deleted.`})})},{method:"POST",pattern:new RegExp(`^/properties/${$}/values$`),handle:s=>h(void 0,[s],function*({body:t,params:[e],engine:r}){var a,o,i;let n=yield r.execute({kind:"query",query:{kind:"propertyValues",property:e,query:oe({labels:(a=t.labels)!=null?a:[],where:(o=t.where)!=null?o:{}})}});return x({values:(i=n.values)!=null?i:[]})})},{method:"POST",pattern:/^\/labels\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var a;let s=yield e.execute({kind:"describe",describe:{kind:"labels",query:oe(t)}}),n={};for(let o of(a=s.labels)!=null?a:[])n[o]=(yield mt(e,f(p({},t),{labels:[o],skip:0,limit:1}))).total;return x(n)})},{method:"POST",pattern:/^\/tx$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var n;let s=yield e.execute({kind:"transaction",transaction:{kind:"begin",ttlMs:t.ttl,autocommit:(n=t.autocommit)!=null?n:!1}});return x({id:s.transactionId})})},{method:"GET",pattern:new RegExp(`^/tx/${$}$`),handle:e=>h(void 0,[e],function*({params:[t]}){return x({id:t})})},{method:"POST",pattern:new RegExp(`^/tx/${$}/commit$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){var n;let s=yield e.execute({kind:"transaction",transaction:{kind:"commit",transactionId:t}});if(s.status!=="committed")throw _(409,`Transaction commit failed: ${(n=s.reason)!=null?n:s.status}`);return x({message:`Transaction (${t}) has been successfully committed.`})})},{method:"POST",pattern:new RegExp(`^/tx/${$}/rollback$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){return yield e.execute({kind:"transaction",transaction:{kind:"rollback",transactionId:t}}),x({message:`Transaction (${t}) has been rolled back.`})})},{method:"POST",pattern:/^\/query\/raw$/,handle:s=>h(void 0,[s],function*({body:t,engine:e,txId:r}){var a,o;W(r,"query.raw");let n=yield e.execute({kind:"query",query:{kind:"statement",language:"cypher",statement:t.query,parameters:(a=t.params)!=null?a:null}});return x({records:(o=n.rows)!=null?o:[]})})},{method:"GET",pattern:/^\/text-indexes$/,handle:e=>h(void 0,[e],function*({engine:t}){return x(yield Me(t))})},{method:"POST",pattern:/^\/text-indexes$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var a,o;let s=new Set((yield Ue(e)).map(i=>String(i.name)));if(t.name!==void 0&&s.has(t.name))throw _(409,`An index named "${t.name}" already exists`);let n=yield e.execute({kind:"index",index:{kind:"create",definition:{name:(a=t.name)!=null?a:je(at(t),s),label:t.label,property:t.property,kind:"text",consistency:(o=t.consistency)!=null?o:"eventual"}}});return x(gt(n.index))})},{method:"POST",pattern:/^\/text-indexes\/name-suggestion$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){let s=new Set((yield Ue(e)).map(n=>String(n.name)));return x({name:je(at(t),s)})})},{method:"DELETE",pattern:new RegExp(`^/text-indexes/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){let s=decodeURIComponent(t);if(!(yield Me(e)).some(n=>n.name===s))throw _(404,`No text index named "${s}"`);return yield e.execute({kind:"index",index:{kind:"drop",name:s}}),x({deleted:!0})})},{method:"POST",pattern:/^\/search\/text$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var o,i,d,c,u,l,m;if(typeof t.query!="string"||t.query.trim()==="")throw _(422,"query is required");let s=yield Rt(e,t,(o=t.labels)!=null?o:[]),n=yield e.execute({kind:"query",query:{kind:"hybrid",query:{labels:(i=t.labels)!=null&&i.length?t.labels:[s.label],predicate:(d=t.where)!=null?d:{},text:{index:s.index,query:s.query,allTerms:s.allTerms,phrase:s.phrase},offset:(c=t.skip)!=null?c:0,limit:(u=t.limit)!=null?u:10}}}),a=Pe(n.records);return x(a,{total:(m=(l=n.textSearch)==null?void 0:l.matches)!=null?m:a.length,meta:{textSearch:n.textSearch}})})},{method:"POST",pattern:/^\/ai\/schema$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){return x(yield Be(e,t.labels,ue))})},{method:"POST",pattern:/^\/ai\/schema\/md$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){return x(st(yield Be(e,t.labels,ue)))})},{method:"POST",pattern:/^\/ai\/search-query$/,handle:X("ai.search")},{method:"POST",pattern:/^\/ai\/search$/,handle:Jt},{method:"GET",pattern:/^\/ai\/indexes$/,handle:e=>h(void 0,[e],function*({engine:t}){return x((yield ie(t)).map(ue))})},{method:"POST",pattern:/^\/ai\/indexes$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var c,u;if(t.sourceType!=="external")throw new ae("ai.indexes.create",xe["ai.indexes.create"]);let s=Number(t.dimensions);if(!Number.isInteger(s)||s<1||s>4096)throw _(422,"dimensions must be an integer between 1 and 4096");let n=(c=t.similarityFunction)!=null?c:"cosine",a=yield ie(e),o=a.find(l=>l.label===t.label&&l.property===t.propertyName&&l.similarity===n&&Number(l.dimensions)===s);if(o)throw _(409,`An embedding index for label "${t.label}", property "${t.propertyName}", sourceType "external", similarityFunction "${n}", and dimensions ${s} already exists ("${o.name}")`);let i=new Set(a.map(l=>String(l.name)));if(t.name!==void 0&&i.has(t.name))throw _(409,`An embedding index named "${t.name}" already exists`);let d=yield e.execute({kind:"index",index:{kind:"createVector",definition:{label:t.label,property:t.propertyName,dimensions:s,similarity:n,name:(u=t.name)!=null?u:je(Ft(t,s,n),i)}}});return x(ue(d.index))})},{method:"DELETE",pattern:new RegExp(`^/ai/indexes/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){return yield e.execute({kind:"index",index:{kind:"dropVector",name:decodeURIComponent(t)}}),x({deleted:!0,queued:!1})})},{method:"GET",pattern:new RegExp(`^/ai/indexes/${$}/stats$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){var n,a;let s=yield e.execute({kind:"describe",describe:{kind:"vectorIndex",name:decodeURIComponent(t)}});return x(f(p({},s.stats),{index:ue((a=(n=s.stats)==null?void 0:n.index)!=null?a:{})}))})},{method:"POST",pattern:new RegExp(`^/ai/indexes/${$}/vectors/upsert$`),handle:s=>h(void 0,[s],function*({body:t,params:[e],engine:r}){var a;let n=yield r.execute({kind:"index",index:{kind:"upsertVectors",name:decodeURIComponent(e),items:(a=t.items)!=null?a:[]}});return x({updated:n.updated,requested:n.requested})})},{method:"GET",pattern:/^\/sdk\/settings$/,handle:X("settings.get")}],Or=wt.map(t=>`${t.method} ${t.pattern.source}`),xt=t=>(a,o)=>h(void 0,[a,o],function*(e,{method:r="GET",headers:s,requestData:n}){var l;let i=new URL(String(e),"http://direct"),d=wt.filter(m=>m.method===r&&m.pattern.test(i.pathname)).sort((m,y)=>m.pattern.source.split("(").length-y.pattern.source.split("(").length)[0];if(!d)throw new he(`${r} ${i.pathname} has no direct-mode mapping`);let c=((l=d.pattern.exec(i.pathname))!=null?l:[]).slice(1),u=s==null?void 0:s["x-transaction-id"];return yield d.handle({body:n!=null?n:{},params:c,query:i.searchParams,txId:u,engine:t})});var zt={"Content-Type":"application/json"},Tt=({httpClient:t,token:e,url:r})=>(s,o)=>h(void 0,null,function*(){var i=o,{headers:n}=i,a=J(i,["headers"]);var m;let d=yield t.makeRequest(`${r}${s}`,p({credentials:"omit",headers:Object.assign(p(p({},zt),n),typeof e!="undefined"?{Authorization:`Bearer ${e}`}:{})},a));if(d.getStatusCode()>=200&&d.getStatusCode()<300)return yield d.toJSON();let c="",u;try{let y=yield d.toJSON();u=y;let g=(m=y==null?void 0:y.message)!=null?m:y==null?void 0:y.error;Array.isArray(g)?c=g.join("; "):typeof g=="string"&&(c=g)}catch(y){}let l=new Error(c?`${d.getStatusCode()} ${c}`:`${d.getStatusCode()}`);throw l.status=d.getStatusCode(),l.body=u,l});var K=class{constructor(e){this.id=e}rollback(){return h(this,null,function*(){return yield D.getInstance().tx.rollback(this.id)})}commit(){return h(this,null,function*(){return yield D.getInstance().tx.commit(this.id)})}};var bt="api.rushdb.com";var Dt="https",It="/api/v1";var b=t=>t?{"x-transaction-id":t}:void 0,Zt=t=>U(t)||t instanceof K,T=t=>Zt(t)?t instanceof K?t.id:t:void 0,Pt=t=>/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/.test(t),j=t=>{if(U(t)&&Pt(t))return t;if(t instanceof E&&t.data)return t.data.__id;if(q(t)&&"__id"in t&&Pt(t.__id))return t.__id},ee=t=>!(!q(t)||q(t)&&"name"in t&&!U(t.name)||q(t)&&"type"in t&&(!U(t.type)||!ze.includes(t.type))||!("value"in t)||!$e(t.value)||"metadata"in t&&!U(t.metadata)||"valueSeparator"in t&&!U(t.valueSeparator)),Et=t=>{let e=Dt,r=bt,s=443,n=It;if("url"in t){let o=new URL(t.url);e=o.protocol.replace(":",""),r=o.hostname,s=parseInt(o.port||(e==="http"?"80":e==="https"?"443":""))}"host"in t&&"port"in t&&"protocol"in t&&(e=t.protocol.replace(":",""),r=t.host,s=t.port),n&&!n.startsWith("/")&&(n="/"+n);let a="";return e==="http"&&s===80||e==="https"&&s===443||(a=":"+s),`${e}://${r}${a}${n}`},w=(t=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r="";for(let s=0;s<t;s++){let n=Math.floor(Math.random()*e.length);r+=e[n]}return r};var ce=class{constructor(e,r){this.records={attach:(a,o)=>h(this,[a,o],function*({source:e,target:r,options:s},n){var y,g;let i=T(n),c=`/relationships/${j(e)}`,u={headers:Object.assign({},b(i)),method:"POST",requestData:p(p(p({targetIds:this._extractTargetIds(r,"Attach")},(s==null?void 0:s.type)&&{type:s.type}),(s==null?void 0:s.direction)&&{direction:s.direction}),(s==null?void 0:s.properties)&&{properties:s.properties})},l=typeof this.logger=="function"?w():"";(y=this.logger)==null||y.call(this,p({requestId:l,path:c},u));let m=yield this.fetcher(c,u);return(g=this.logger)==null||g.call(this,f(p({requestId:l,path:c},u),{responseData:m.data})),m}),detach:(a,o)=>h(this,[a,o],function*({source:e,target:r,options:s},n){var y,g;let i=T(n),c=`/relationships/${j(e)}`,u={headers:Object.assign({},b(i)),method:"PUT",requestData:p(p({targetIds:this._extractTargetIds(r,"Detach")},(s==null?void 0:s.typeOrTypes)&&{typeOrTypes:s.typeOrTypes}),(s==null?void 0:s.direction)&&{direction:s.direction})},l=typeof this.logger=="function"?w():"";(y=this.logger)==null||y.call(this,p({requestId:l,path:c},u));let m=yield this.fetcher(c,u);return(g=this.logger)==null||g.call(this,f(p({requestId:l,path:c},u),{responseData:m.data})),m}),create:(o,i)=>h(this,[o,i],function*({label:e,data:r,options:s,vectors:n},a){var g,R;let d=T(a),c="/records",u={headers:Object.assign({},b(d)),method:"POST",requestData:{}},l=typeof this.logger=="function"?w():"",m=ne(z(r));if(A(m)&&m.every(ee))u.requestData=p({label:e,properties:m,options:s},(n==null?void 0:n.length)&&{vectors:n});else if(se(m))u.requestData=p({label:e,data:m,options:s},(n==null?void 0:n.length)&&{vectors:n});else throw q(m)?new Error("Provided data is not a flat object. Consider using the `importJson` method for nested objects or arrays of nested objects, or use `createMany` for arrays of flat objects."):new Error("Provided data is not valid.");(g=this.logger)==null||g.call(this,p({requestId:l,path:c},u));let y=yield this.fetcher(c,u);return(R=this.logger)==null||R.call(this,f(p({requestId:l,path:c},u),{responseData:y.data})),y!=null&&y.success&&(y!=null&&y.data)?new E(y.data):new E}),createMany:(e,r)=>h(this,null,function*(){var m,y,g;let s=A(e.data)?e.data:[e.data];if(!s.every(R=>se(R)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");let a=e.vectors?A(e.vectors[0])?e.vectors:[e.vectors]:void 0;if(a&&a.length>s.length)throw new Error(`records.createMany: vectors length (${a.length}) exceeds the number of data rows (${s.length}).`);let o=a!=null&&a.length?s.map((R,I)=>{var C;return(C=a[I])!=null&&C.length?f(p({},R),{$vectors:a[I]}):R}):s,i=T(r),d="/records/import/json",c={headers:Object.assign({},b(i)),method:"POST",requestData:{label:e.label,data:o,options:e.options}},u=typeof this.logger=="function"?w():"";(m=this.logger)==null||m.call(this,p({requestId:u,path:d},c));let l=yield this.fetcher(d,c);if((y=this.logger)==null||y.call(this,f(p({requestId:u,path:d},c),{responseData:l.data})),l!=null&&l.success&&(l!=null&&l.data)){let R=A(l.data)?(g=l.data)==null?void 0:g.map(I=>new E(I)):[];return new B(R,l.total)}return new B([])}),importJson:(e,r)=>h(this,null,function*(){var m,y,g;let{data:s,options:n}=e,{label:a}=e,o=s;if(!a){let R=q(s)&&!A(s)?ne(s):s;if(Ze(R))throw new Error("records.importJson: Missing `label`. Provide `label` for top-level arrays or objects with primitive top-level properties, or pass a container object whose top-level values are objects or arrays, e.g. { ITEM: [...], USER: [...] }.")}let i=T(r),d="/records/import/json",c={headers:Object.assign({},b(i)),method:"POST",requestData:{label:a,data:o,options:n}},u=typeof this.logger=="function"?w():"";(m=this.logger)==null||m.call(this,p({requestId:u,path:d},c));let l=yield this.fetcher(d,c);if((y=this.logger)==null||y.call(this,f(p({requestId:u,path:d},c),{responseData:l.data})),l!=null&&l.success&&(l!=null&&l.data)){let R=A(l.data)?(g=l.data)==null?void 0:g.map(I=>new E(I)):[];return new B(R,l.total)}return new B([])}),importCsv:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/records/import/csv",a={headers:Object.assign({},b(s)),method:"POST",requestData:e},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);if((c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i!=null&&i.success&&(i!=null&&i.data)){let u=A(i.data)?i.data.map(l=>new E(l)):[];return new B(u,i.total)}return new B([])}),delete:(e,r)=>h(this,null,function*(){var d,c,u;if(re(e.where)&&!((d=this==null?void 0:this.options)!=null&&d.allowForceDelete))throw new L("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let s=T(r),n="/records/delete",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(u=this.logger)==null||u.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),deleteById:(e,r)=>h(this,null,function*(){var c,u;let s=T(r),n=A(e),a=n?"/records/delete":`/records/${e}`,o={headers:Object.assign({},b(s)),method:n?"POST":"DELETE",requestData:n?{limit:1e3,where:{$id:{$in:e}}}:void 0},i=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:a},o));let d=yield this.fetcher(a,o);return(u=this.logger)==null||u.call(this,f(p({requestId:i,path:a},o),{responseData:d.data})),d}),export:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/records/export/csv",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),find:(e,r)=>h(this,null,function*(){var m,y;let l=e,{id:s}=l,n=J(l,["id"]),a=T(r),o=s?`/records/${s}/search`:"/records/search",i={headers:Object.assign({},b(a)),method:"POST",requestData:n!=null?n:{}},d=typeof this.logger=="function"?w():"";(m=this.logger)==null||m.call(this,p({requestId:d,path:o},i));let c=yield this.fetcher(o,i);(y=this.logger)==null||y.call(this,f(p({requestId:d,path:o},i),{responseData:c.data}));let u=c.data.map(g=>new E(g));return new B(u,c.total,e)}),vectorSearch:(e,r)=>h(this,null,function*(){var u,l,m,y,g,R,I;let s=T(r),n="/ai/search",a={method:"POST",headers:Object.assign({},b(s)),requestData:e},o=typeof this.logger=="function"?w():"";(u=this.logger)==null||u.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);(l=this.logger)==null||l.call(this,f(p({requestId:o,path:n},a),{responseData:i.data}));let d=((m=i.data)!=null?m:[]).map(C=>new E(C)),c=new B(d,(y=i.total)!=null?y:0);return c.vectorSearch=(g=i.meta)==null?void 0:g.vectorSearch,c.textSearch=(R=i.meta)==null?void 0:R.textSearch,c.fusion=(I=i.meta)==null?void 0:I.fusion,c}),textSearch:(e,r)=>h(this,null,function*(){var u,l,m,y,g;let s=T(r),n="/search/text",a={method:"POST",headers:Object.assign({},b(s)),requestData:e},o=typeof this.logger=="function"?w():"";(u=this.logger)==null||u.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);(l=this.logger)==null||l.call(this,f(p({requestId:o,path:n},a),{responseData:i.data}));let d=((m=i.data)!=null?m:[]).map(R=>new E(R)),c=new B(d,(y=i.total)!=null?y:0);return c.textSearch=(g=i.meta)==null?void 0:g.textSearch,c}),findById:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n=A(e)?"/records/search":`/records/${e}`,a={headers:Object.assign({},b(s)),method:A(e)?"POST":"GET",requestData:A(e)?{where:{$id:{$in:e}},limit:e.length}:void 0},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);if((c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),A(e)){let u=i.data.map(l=>new E(l));return new B(u,i.total)}else return new E(i.data)}),findOne:(e,r)=>h(this,null,function*(){var c,u;let s=T(r),n="/records/search",a={headers:Object.assign({},b(s)),method:"POST",requestData:f(p({},e),{limit:1,skip:0})},o=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);(u=this.logger)==null||u.call(this,f(p({requestId:o,path:n},a),{responseData:i.data}));let[d]=i.data;return new E(d)}),findUniq:(e,r)=>h(this,null,function*(){var c,u;let s=T(r),n="/records/search",a={headers:Object.assign({},b(s)),method:"POST",requestData:f(p({},e),{limit:1,skip:0})},o=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);if((u=this.logger)==null||u.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),typeof i.total!="undefined"&&i.total>1)throw new fe(i.total,e);let[d]=i.data;return new E(d)}),set:(i,d)=>h(this,[i,d],function*({target:e,label:r,data:s,options:n,vectors:a},o){var I,C;let c=T(o),l=`/records/${j(e)}`,m={headers:Object.assign({},b(c)),method:"PUT",requestData:{}},y=typeof this.logger=="function"?w():"",g=ne(z(s));if(A(g)&&g.every(ee))m.requestData=p({label:r,properties:g},(a==null?void 0:a.length)&&{vectors:a});else if(se(g))m.requestData=p({label:r,data:g,options:n},(a==null?void 0:a.length)&&{vectors:a});else throw q(g)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(I=this.logger)==null||I.call(this,p({requestId:y,path:l},m));let R=yield this.fetcher(l,m);return(C=this.logger)==null||C.call(this,f(p({requestId:y,path:l},m),{responseData:R.data})),R!=null&&R.success&&(R!=null&&R.data)?new E(R.data):new E}),update:(o,i)=>h(this,[o,i],function*({target:e,label:r,data:s,options:n},a){var R,I;let d=j(e),c=T(a),u=`/records/${d}`,l={headers:Object.assign({},b(c)),method:"PATCH",requestData:{}},m=typeof this.logger=="function"?w():"",y=ne(z(s));if(A(y)&&y.every(ee))l.requestData={label:r,properties:y};else if(se(y))l.requestData={label:r,data:y,options:n};else throw q(y)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(R=this.logger)==null||R.call(this,p({requestId:m,path:u},l));let g=yield this.fetcher(u,l);return(I=this.logger)==null||I.call(this,f(p({requestId:m,path:u},l),{responseData:g.data})),g!=null&&g.success&&(g!=null&&g.data)?new E(g.data):new E}),upsert:(o,i)=>h(this,[o,i],function*({label:e,data:r,options:s,vectors:n},a){var R,I,C;let d=T(a),c="/records",u={headers:Object.assign({},b(d)),method:"POST",requestData:{}},l=typeof this.logger=="function"?w():"",m=ne(z(r)),y=f(p({},s),{mergeBy:(R=s==null?void 0:s.mergeBy)!=null?R:[]});if(A(m)&&m.every(ee))u.requestData=p({label:e,properties:m,options:y},(n==null?void 0:n.length)&&{vectors:n});else if(se(m))u.requestData=p({label:e,data:m,options:y},(n==null?void 0:n.length)&&{vectors:n});else throw q(m)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(I=this.logger)==null||I.call(this,p({requestId:l,path:c},u));let g=yield this.fetcher(c,u);return(C=this.logger)==null||C.call(this,f(p({requestId:l,path:c},u),{responseData:g.data})),g!=null&&g.success&&(g!=null&&g.data)?new E(g.data):new E})};this.relationships={patterns:{list:()=>h(this,null,function*(){var a,o;let e="/relationships/patterns",r={method:"GET",headers:{}},s=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,p({requestId:s,path:e},r));let n=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,f(p({requestId:s,path:e},r),{responseData:n.data})),n}),analyze:()=>h(this,null,function*(){var a,o;let e="/relationships/patterns/analyze",r={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,p({requestId:s,path:e},r));let n=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,f(p({requestId:s,path:e},r),{responseData:n.data})),n}),approve:e=>h(this,null,function*(){var o,i;let r=`/relationships/patterns/${encodeURIComponent(e)}/approve`,s={method:"POST",headers:{},requestData:{}},n=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,p({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(i=this.logger)==null||i.call(this,f(p({requestId:n,path:r},s),{responseData:a.data})),a}),ignore:e=>h(this,null,function*(){var o,i;let r=`/relationships/patterns/${encodeURIComponent(e)}/ignore`,s={method:"POST",headers:{},requestData:{}},n=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,p({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(i=this.logger)==null||i.call(this,f(p({requestId:n,path:r},s),{responseData:a.data})),a}),delete:(e,r)=>h(this,null,function*(){var d,c;let s=r!=null&&r.deleteExisting?"?deleteExisting=true":"",n=`/relationships/patterns/${encodeURIComponent(e)}${s}`,a={method:"DELETE",headers:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i})},createMany:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/relationships/create-many",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),deleteMany:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/relationships/delete-many",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),find:(...s)=>h(this,[...s],function*(e={},r){var c,u;let n=T(r),a="/relationships/search",o={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:a},o));let d=yield this.fetcher(a,o);return(u=this.logger)==null||u.call(this,f(p({requestId:i,path:a},o),{responseData:d.data})),d})};this.properties={delete:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n=`/properties/${e}`,a={headers:Object.assign({},b(s)),method:"DELETE"},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),find:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/properties/search",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),findById:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n=`/properties/${e}`,a={headers:Object.assign({},b(s)),method:"GET"},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),values:(e,r,s)=>h(this,null,function*(){var c,u;let n=T(s),a=`/properties/${e}/values`,o={headers:Object.assign({},b(n)),method:"POST",requestData:r!=null?r:{}},i=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:a},o));let d=yield this.fetcher(a,o);return(u=this.logger)==null||u.call(this,f(p({requestId:i,path:a},o),{responseData:d.data})),d})};this.labels={find:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/labels/search",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i})};this.tx={begin:e=>h(this,null,function*(){var o,i;let r="/tx",s={method:"POST",requestData:q(e)?e:{}},n=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,p({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(i=this.logger)==null||i.call(this,f(p({requestId:n,path:r},s),{responseData:a.data})),new K(a.data.id)}),commit:e=>h(this,null,function*(){var i,d;let s=`/tx/${T(e)}/commit`,n={method:"POST",requestData:{}},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,p({requestId:a,path:s},n));let o=yield this.fetcher(s,n);return(d=this.logger)==null||d.call(this,f(p({requestId:a,path:s},n),{responseData:o.data})),o}),get:e=>h(this,null,function*(){var i,d;let s=`/tx/${T(e)}`,n={method:"GET"},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,p({requestId:a,path:s},n));let o=yield this.fetcher(s,n);return(d=this.logger)==null||d.call(this,f(p({requestId:a,path:s},n),{responseData:o.data})),new K(o.data.id)}),rollback:e=>h(this,null,function*(){var i,d;let s=`/tx/${T(e)}/rollback`,n={method:"POST",requestData:{}},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,p({requestId:a,path:s},n));let o=yield this.fetcher(s,n);return(d=this.logger)==null||d.call(this,f(p({requestId:a,path:s},n),{responseData:o.data})),o})};this.settings={get:()=>h(this,null,function*(){var a,o;let e="/sdk/settings",r={method:"GET"},s=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,p({requestId:s,path:e},r));let n=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,f(p({requestId:s,path:e},r),{responseData:n.data})),n})};this.query={raw:(n,a)=>h(this,[n,a],function*({query:e,params:r},s){var l,m;let o=T(s),i="/query/raw",d={headers:Object.assign({},b(o)),method:"POST",requestData:{query:e,params:r}},c=typeof this.logger=="function"?w():"";(l=this.logger)==null||l.call(this,p({requestId:c,path:i},d));let u=yield this.fetcher(i,d);return(m=this.logger)==null||m.call(this,f(p({requestId:c,path:i},d),{responseData:u.data})),u})};this.textIndexes={find:()=>h(this,null,function*(){return this.textIndexRequest("/text-indexes","GET")}),create:e=>h(this,null,function*(){return this.textIndexRequest("/text-indexes","POST",e)}),suggestName:e=>h(this,null,function*(){return this.textIndexRequest("/text-indexes/name-suggestion","POST",e)}),delete:e=>h(this,null,function*(){return this.textIndexRequest(`/text-indexes/${encodeURIComponent(e)}`,"DELETE")})};this.ai={getSchema:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/ai/schema",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),getSchemaMarkdown:(e,r)=>h(this,null,function*(){var d,c;let s=T(r),n="/ai/schema/md",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);return(c=this.logger)==null||c.call(this,f(p({requestId:o,path:n},a),{responseData:i.data})),i}),indexes:{find:()=>h(this,null,function*(){var a,o;let e="/ai/indexes",r={method:"GET",headers:{}},s=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,p({requestId:s,path:e},r));let n=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,f(p({requestId:s,path:e},r),{responseData:n.data})),n}),create:e=>h(this,null,function*(){var u,l;let r="/ai/indexes",c=e,{external:s}=c,n=J(c,["external"]),a=s===!0?f(p({},n),{sourceType:"external"}):n,o={method:"POST",headers:{},requestData:a},i=typeof this.logger=="function"?w():"";(u=this.logger)==null||u.call(this,p({requestId:i,path:r},o));let d=yield this.fetcher(r,o);return(l=this.logger)==null||l.call(this,f(p({requestId:i,path:r},o),{responseData:d.data})),d}),upsertVectors:(e,r)=>h(this,null,function*(){var i,d;let s=`/ai/indexes/${e}/vectors/upsert`,n={method:"POST",headers:{},requestData:r},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,p({requestId:a,path:s},n));let o=yield this.fetcher(s,n);return(d=this.logger)==null||d.call(this,f(p({requestId:a,path:s},n),{responseData:o.data})),o}),delete:e=>h(this,null,function*(){var o,i;let r=`/ai/indexes/${e}`,s={method:"DELETE",headers:{}},n=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,p({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(i=this.logger)==null||i.call(this,f(p({requestId:n,path:r},s),{responseData:a.data})),a}),stats:e=>h(this,null,function*(){var o,i;let r=`/ai/indexes/${e}/stats`,s={method:"GET",headers:{}},n=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,p({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(i=this.logger)==null||i.call(this,f(p({requestId:n,path:r},s),{responseData:a.data})),a})},search:(e,r)=>h(this,null,function*(){var g,R,I,C,N,V;let s=T(r==null?void 0:r.transaction),n="/ai/search-query",a={method:"POST",headers:Object.assign({},b(s)),requestData:{prompt:e,currentQuery:r==null?void 0:r.currentQuery}},o=typeof this.logger=="function"?w():"";(g=this.logger)==null||g.call(this,p({requestId:o,path:n},a));let i=yield this.fetcher(n,a);(R=this.logger)==null||R.call(this,f(p({requestId:o,path:n},a),{responseData:i.data}));let d=i.data.searchQuery,c="/records/search",u={method:"POST",headers:Object.assign({},b(s)),requestData:d!=null?d:{}},l=typeof this.logger=="function"?w():"";(I=this.logger)==null||I.call(this,p({requestId:l,path:c},u));let m=yield this.fetcher(c,u);(C=this.logger)==null||C.call(this,f(p({requestId:l,path:c},u),{responseData:m.data}));let y=((N=m.data)!=null?N:[]).map(Y=>new E(Y));return new B(y,(V=m.total)!=null?V:0,d,i.data.warnings)})};if(this.fetcher=null,r!=null&&r.direct){if(!r.engineUrl)throw new Error("Direct mode requires `engineUrl`, the standalone engine base URL.");if(!r.httpClient)throw new Error("Direct mode requires an HTTP client; import the SDK from its Node or browser entry.");this.direct=new Re({engineUrl:r.engineUrl,token:e!=null?e:"",httpClient:r.httpClient,scope:r.scope}),this.fetcher=xt(this.direct)}else if(r!=null&&r.httpClient){let s=Et(r);this.fetcher=Tt({httpClient:r.httpClient,token:e,url:s})}r!=null&&r.options&&(this.options=r==null?void 0:r.options),r!=null&&r.logger&&(this.logger=r==null?void 0:r.logger)}_extractTargetIds(e,r){var s;if(e instanceof E){let n=j(e);if(!n)throw new L(`${r} error: Target id is empty`);return[n]}if(A(e)&&e.every(n=>n instanceof E)){let n=e.map(j).filter(k);if(!n.length)throw new L(`${r} error: Target ids are empty`);return n}if(e instanceof B){let n=(s=e.data)==null?void 0:s.map(j).filter(k);if(!(n!=null&&n.length))throw new L(`${r} error: Target ids are empty`);return n}if(q(e)&&"__id"in e)return[e.__id];if(A(e)&&e.every(n=>q(n)&&"__id"in n)){let n=e.map(j).filter(k);if(!n.length)throw new L(`${r} error: Target ids are empty`);return n}return A(e)?e:U(e)?[e]:[]}textIndexRequest(e,r,s){return h(this,null,function*(){var i,d;let n=p({method:r,headers:{}},s===void 0?{}:{requestData:s}),a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,p({requestId:a,path:e},n));let o=yield this.fetcher(e,n);return(d=this.logger)==null||d.call(this,f(p({requestId:a,path:e},n),{responseData:o.data})),o})}};var Ot,M=class M extends ce{constructor(e,r){var a,o;let s=e!=null?e:typeof process!="undefined"?(a=process.env)==null?void 0:a.RUSHDB_API_KEY:void 0,n=tt(r);super(s,f(p({},n),{httpClient:(o=n.httpClient)!=null?o:Ot})),M.instance=this,this.initializeSync(s,n)}initializeSync(e,r){M.state={initialized:!0,debug:!1,timeout:rt("timeout",r==null?void 0:r.timeout,8e4),token:e,direct:(r==null?void 0:r.direct)===!0,engineUrl:r==null?void 0:r.engineUrl}}static getInstance(){if(M.instance)return M.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static isInitialized(){return k(M.instance)}toDBRecordInstance(e){return new E(e)}};M.instance=null,M.state={initialized:!1,debug:!1,timeout:8e4};var D=M,At=t=>{Ot=t};var qt=class{constructor(e,r,s){this.label=e,this.schema=r,this.config=s!=null?s:{}}getLabel(){return this.label}toDBRecordInstance(e){return h(this,null,function*(){try{return D.getInstance().toDBRecordInstance(e)}catch(r){throw new Error("No RushDB instance was provided during model initialization.")}})}find(e,r){return h(this,null,function*(){let s=e!=null?e:{};return D.getInstance().records.find(f(p({},s),{labels:[this.label]}),r)})}findOne(e,r){return h(this,null,function*(){let s=e!=null?e:{};return D.getInstance().records.findOne(f(p({},s),{labels:[this.label]}),r)})}findById(e,r){return h(this,null,function*(){return this.findOne({where:{$id:e}},r)})}findUniq(e,r){return h(this,null,function*(){let s=e!=null?e:{};return D.getInstance().records.findUniq(f(p({},s),{labels:[this.label]}),r)})}create(e,r,s){return h(this,null,function*(){var d,c;let n=yield Se(this.schema,e),a=ke(this.schema,n),o=k(a),i=D.getInstance();if(o){let u=r!=null?r:yield i.tx.begin(),l=yield this.find({where:a},u),m=typeof r!="undefined";if(!((d=l==null?void 0:l.data)!=null&&d.length)){let g=yield i.records.create({label:this.label,data:n},u);return m||(yield u.commit()),g}else switch((c=s==null?void 0:s.onConflict)!=null?c:"throw"){case"upsert":{let R=l.data[0],I=yield i.records.set({target:R.id,label:this.label,data:n},u);return m||(yield u.commit()),I}case"skip":return m||(yield u.commit()),null;default:throw m||(yield u.commit()),new Q(this.label,a)}}return yield i.records.create({label:this.label,data:n},r)})}attach(a,o){return h(this,arguments,function*({source:e,target:r,options:s},n){return yield D.getInstance().records.attach({source:e,target:r,options:s},n)})}detach(a,o){return h(this,arguments,function*({source:e,target:r,options:s},n){return yield D.getInstance().records.detach({source:e,target:r,options:s},n)})}validateTargetLabel(e,r){return h(this,null,function*(){let s=j(e);if(!s)return;let a=yield D.getInstance().records.findById(s,r);if(!a)throw new Error(`Record with id "${s}" not found.`);if(a.data.__label!==this.label)throw new TypeError(`Target record label "${a.data.__label}" does not match model label "${this.label}".`)})}handleSetOrUpdate(e,r,s,n){return h(this,null,function*(){var d,c;if(this.config.validateTargetLabel&&(yield this.validateTargetLabel(e,n)),A(r)&&r.every(ee))return yield D.getInstance().records[s]({label:this.label,target:e,data:r},n);let a=D.getInstance(),o=yield Se(this.schema,r),i=ke(this.schema,o);if(!re(i)){let u=n!=null?n:yield a.tx.begin(),l=yield this.find({where:i},u),m=typeof n!="undefined";if(!((d=l==null?void 0:l.data)!=null&&d.length)||l.data.length===1&&((c=l.data[0])==null?void 0:c.id)===j(e)){let g=yield a.records[s]({target:e,label:this.label,data:o},u);return m||(yield u.commit()),g}else throw m||(yield u.commit()),new Q(this.label,i)}return yield a.records[s]({label:this.label,target:e,data:o},n)})}set(e,r,s){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,r,"set",s)})}update(e,r,s){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,r,"update",s)})}createMany(e,r){return h(this,null,function*(){var o;let s=D.getInstance(),n=typeof r!="undefined",a=r!=null?r:yield s.tx.begin();try{let i=yield Promise.all(e.map(u=>h(this,null,function*(){return yield Se(this.schema,u)}))),d=et(i,this.schema,this.label);if(!re(d)){let u=Object.entries(d).map(([m,y])=>({[m]:{$in:y}})),l=yield this.find({where:{$or:u}},a);if((o=l==null?void 0:l.data)!=null&&o.length)throw new Q(this.label,Object.keys(d))}let c=yield s.records.createMany({label:this.label,data:i},a);return n||(yield a.commit()),c}catch(i){throw n||(yield a.rollback()),i}})}delete(e,r){return h(this,null,function*(){if(re(e.where))throw new L(`You must specify criteria to delete records of type '${this.label}'. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.`);return yield D.getInstance().records.delete(f(p({},e),{labels:[this.label]}),r)})}deleteById(e,r){return h(this,null,function*(){return yield D.getInstance().records.deleteById(e,r)})}};At(new ye);var Rn=D;export{xe as CLOUD_ONLY_FORMS,we as CLOUD_ONLY_METHODS,ae as CloudOnlyError,E as DBRecordInstance,B as DBRecordsArrayInstance,he as DirectModeError,L as EmptyTargetError,v as HttpClient,Oe as HttpClientResponse,qt as Model,fe as NonUniqueResultError,ce as RestAPI,D as RushDB,K as Transaction,Q as UniquenessError,Rn as default,nt as idToDate,_e as idToTimestamp,At as initSDK,Nt as isCloudOnlyMethod,Se as mergeDefaultsWithPayload,tt as parseConfig,ke as pickUniqFieldsFromRecord,et as pickUniqFieldsFromRecords,rt as validateInteger};
|
|
27
|
+
`}}return o.trim()};var x=(t,e={})=>l({success:!0,data:t},e),_=(t,e)=>{let r=new Error(`${t} ${e}`);return r.status=t,r.body={statusCode:t,message:e},r},W=t=>()=>h(void 0,null,function*(){throw new ae(t,we[t])}),K=(t,e)=>{if(t)throw new he(`${e} inside a transaction is not supported in direct mode: the engine stages record creates, updates, deletes, links and imports. Run it outside the transaction.`)},ht="__RUSHDB__RELATION__DEFAULT__",Z=(t,e,r)=>t.execute({kind:"transaction",transaction:{kind:"stage",transactionId:e,mutation:r}}),je=(t,e,r)=>h(void 0,null,function*(){var s;let{record:n}=yield Z(t,e,{kind:"getRecord",record:{id:r}});return g(l({},(s=n==null?void 0:n.properties)!=null?s:{}),{__id:r,__label:n==null?void 0:n.__label,__proptypes:{}})}),ut=(t,e)=>{t&&Array.isArray(e)&&e.length>0&&K(t,"A write with inline vectors")},Ie=t=>{var r,n;if(!t)return t;let e=l({},(r=t.properties)!=null?r:{});return e.__id=t.id,e.__label=t.label,e.__proptypes=(n=t.propertyTypes)!=null?n:{},t.score!==void 0&&(e.__score=t.score),e},Pe=t=>(t!=null?t:[]).map(e=>Ie(e)),Le=t=>t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:Array.isArray(t.properties)?Object.fromEntries(t.properties.map(e=>[e.name,e.value])):t.properties&&typeof t.properties=="object"?t.properties:{},Nt=t=>t==null||typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0?"desc":typeof t!="object"||Array.isArray(t)?t:Object.fromEntries(Object.entries(t).map(([e,r])=>[e==="__id"?"id":e,r])),oe=(t={})=>{var n,s,a,o,i,d;let e=(n=t.pagination)!=null?n:{},r={labels:(s=t.labels)!=null?s:[],predicate:(a=t.where)!=null?a:{},select:t.select,order:Nt(t.orderBy),offset:(i=(o=t.skip)!=null?o:e.skip)!=null?i:0,limit:(d=t.limit)!=null?d:e.limit};return Array.isArray(t.groupBy)&&t.groupBy.length>0&&(r.groupBy=t.groupBy),r},be=t=>t==null||typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0,Ve=(t,e)=>h(void 0,null,function*(){return(yield t.execute({kind:"query",query:{kind:"record",id:e}})).record}),mt=(t,e)=>h(void 0,null,function*(){var n,s,a;let r=yield t.execute({kind:"query",query:{kind:"records",query:oe(e)}});return r.kind==="rows"?{data:(n=r.rows)!=null?n:[],total:(s=r.total)!=null?s:0}:{data:Pe(r.records),total:(a=r.total)!=null?a:0}}),ie=t=>h(void 0,null,function*(){var e;return(e=(yield t.execute({kind:"describe",describe:{kind:"vectorIndexes"}})).indexes)!=null?e:[]}),Ue=t=>h(void 0,null,function*(){var e;return(e=(yield t.execute({kind:"describe",describe:{kind:"indexes"}})).indexes)!=null?e:[]}),ue=t=>{var r;let e=Number((r=t.dimensions)!=null?r:0);return{id:t.name,name:t.name,label:t.label,propertyName:t.property,vectorPropertyName:`_emb_external_${t.similarity}_${e}`,similarityFunction:t.similarity,dimensions:e,sourceType:"external",status:t.status}},gt=t=>{var e,r;return{name:t.name,label:t.label,property:t.property,consistency:(e=t.consistency)!=null?e:"eventual",status:t.state,pending:(r=t.pending)!=null?r:0}},Me=t=>h(void 0,null,function*(){return(yield Ue(t)).filter(e=>e.kind==="text").map(gt)}),yt=64,ft=t=>t.join(".").slice(0,yt).replace(/[.:-]+$/,""),De=t=>t.replace(/[^A-Za-z0-9_-]/g,"-"),ve=(t,e)=>{if(!e.has(t))return t;for(let r=2;;r++){let n=`-${r}`,s=t.slice(0,yt-n.length)+n;if(!e.has(s))return s}},at=({label:t,property:e})=>ft([De(t),e==="*"?"all":De(e),"text"]),Ft=(t,e,r)=>ft([De(t.label),De(t.propertyName),"external",String(e),r]).replace(/^emb__/,"emb_"),Ee=(t,e,r,n)=>h(void 0,null,function*(){if(!Array.isArray(e)||e.length===0)return[];let s=n!=null?n:yield ie(t);return e.map(a=>{if(typeof(a==null?void 0:a.index)=="string")return a;if(!r)throw _(422,"inline vectors require a record label to select their index");let o=Array.isArray(a.vector)?a.vector.length:void 0,i=s.filter(d=>d.label===r&&d.property===a.propertyName&&(a.similarityFunction===void 0||d.similarity===a.similarityFunction)&&(o===void 0||Number(d.dimensions)===o));if(i.length!==1)throw _(i.length===0?404:422,i.length===0?`No vector index matches label "${r}", property "${a.propertyName}"`:`${i.length} vector indexes match label "${r}", property "${a.propertyName}"; name one with \`index\``);return g(l({},a),{index:i[0].name})})}),Ht=(t,e,r)=>h(void 0,null,function*(){let n=Array.isArray(e)?e:[e],s=i=>Array.isArray(i==null?void 0:i.$vectors)&&i.$vectors.length>0;if(!n.some(s))return e;let a=yield ie(t),o=yield Promise.all(n.map(i=>h(void 0,null,function*(){return s(i)?g(l({},i),{$vectors:yield Ee(t,i.$vectors,r,a)}):i})));return Array.isArray(e)?o:o[0]}),Qt=()=>{var n;let t=new Uint8Array(16);if(typeof((n=globalThis.crypto)==null?void 0:n.getRandomValues)=="function")globalThis.crypto.getRandomValues(t);else for(let s=0;s<16;s++)t[s]=Math.floor(Math.random()*256);let e=Date.now();for(let s=0;s<6;s++)t[s]=Math.floor(e/Ge(2,8*(5-s)))&255;t[6]=t[6]&15|112,t[8]=t[8]&63|128;let r=Array.from(t,s=>s.toString(16).padStart(2,"0")).join("");return`${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20)}`},Wt=n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){var d,c,u,p,m,f;let s=!!((d=t.options)!=null&&d.mergeStrategy)||Array.isArray((c=t.options)==null?void 0:c.mergeBy),a=Le(t);if(r){s&&K(r,"An upsert"),ut(r,t.vectors);let y=Qt();return yield Z(e,r,{kind:"createRecord",label:t.label,id:y,properties:a,options:(u=t.options)!=null?u:{}}),x(yield je(e,r,y))}let o=s?g(l({},t.options),{mergeBy:(m=(p=t.options)==null?void 0:p.mergeBy)!=null?m:[]}):(f=t.options)!=null?f:{},i=yield e.execute({kind:"mutate",mutation:{kind:"putRecord",mode:"create",label:t.label,properties:a,vectors:yield Ee(e,t.vectors,t.label),options:o}});return x(Ie(i.record))}),ot=t=>a=>h(void 0,[a],function*({body:e,params:[r],engine:n,txId:s}){var c,u;let o=typeof e.label=="string"&&e.label?e.label:void 0;if(s){if(ut(s,e.vectors),o){let p=yield je(n,s,r);p.__label&&p.__label!==o&&(yield Z(n,s,{kind:"retypeRecord",record:{id:r},fromLabel:p.__label,toLabel:o}))}return yield Z(n,s,{kind:"updateRecord",record:{id:r},properties:Le(e),replace:t==="replace"}),x(yield je(n,s,r))}let i=o;if(o||(c=e.vectors)!=null&&c.length){let p=yield Ve(n,r);o&&(p!=null&&p.label)&&p.label!==o&&(yield n.execute({kind:"mutate",mutation:{kind:"retypeRecord",id:r,fromLabel:p.label,toLabel:o}})),i=o!=null?o:p==null?void 0:p.label}let d=yield n.execute({kind:"mutate",mutation:{kind:"putRecord",mode:t,id:r,properties:Le(e),vectors:yield Ee(n,e.vectors,i),options:(u=e.options)!=null?u:{}}});return x(Ie(d.record))}),Kt=(t,e,r)=>h(void 0,null,function*(){var o;if(!e)return r;let n;try{n=(o=yield Ve(t,e))==null?void 0:o.label}catch(i){if((i==null?void 0:i.status)===404)return;throw i}let s={[n]:{$id:e}},a=r.where;return g(l({},r),{where:be(a)?s:{$and:[a,s]}})}),it=n=>h(void 0,[n],function*({body:t,params:[e],engine:r}){let s=yield Kt(r,e,t);if(!s)return x([],{total:0});let{data:a,total:o}=yield mt(r,s);return x(a,{total:o})}),ct=(t,e,r)=>e?Z(t,e,{kind:"ingest",ingest:r}):t.execute({kind:"ingest",ingest:r}),dt=(t,e)=>{var r,n;return e&&((r=t.records)!=null&&r.length)?x(Pe(t.records)):x({message:"Records have been successfully imported",count:Number((n=t.count)!=null?n:0)})},Yt=["delimiter","header","skipEmptyLines","dynamicTyping","quoteChar","escapeChar","newline"],lt=t=>{var e,r,n,s,a,o,i,d,c,u,p,m;return{relationType:(e=t.type)!=null?e:ht,direction:String((r=t.direction)!=null?r:"").toLowerCase()==="in"?"in":"out",allowCartesian:(n=t.manyToMany)!=null?n:!1,properties:(s=t.properties)!=null?s:{},source:{label:(a=t.source)==null?void 0:a.label,property:(o=t.source)==null?void 0:o.key,predicate:(d=(i=t.source)==null?void 0:i.where)!=null?d:{}},target:{label:(c=t.target)==null?void 0:c.label,property:(u=t.target)==null?void 0:u.key,predicate:(m=(p=t.target)==null?void 0:p.where)!=null?m:{}}}},Te=t=>Array.isArray(t)?t:[t],Jt=t=>{var r,n;let e=new Map;for(let s of t){let a=e.get(s.id);if(a){a.recordsCount+=Number((r=s.recordsCount)!=null?r:0),a.isArray||(a.isArray=s.isArray===!0);continue}e.set(s.id,{id:s.id,name:s.name,type:s.type,recordsCount:Number((n=s.recordsCount)!=null?n:0),isArray:s.isArray===!0})}return Array.from(e.values(),o=>{var i=o,{isArray:s}=i,a=z(i,["isArray"]);return g(l({},a),{metadata:JSON.stringify({cardinality:s?"OrderedMany":"Single",nullability:"Nullable"})})})},St=(r,...n)=>h(void 0,[r,...n],function*(t,e={}){var a;let s=yield t.execute({kind:"describe",describe:l({kind:"properties",query:oe(e)},be(e.where)?{detail:"catalog"}:{})});return Jt((a=s.properties)!=null?a:[])}),pt=(t,e)=>h(void 0,null,function*(){var n;let r=(yield St(t)).find(s=>s.name===e||s.id===e);return r&&g(l({},r),{id:(n=r.id)!=null?n:r.name})}),Rt=(t,e,r)=>h(void 0,null,function*(){var a,o;if(typeof e.query!="string"||e.query.trim()==="")throw _(422,"text.query is required");let n=yield Me(t),s;if(e.index!==void 0){if(s=n.find(i=>i.name===e.index),!s)throw _(404,`No text index named "${e.index}"`)}else{let i=r[0];if(!i)throw _(422,"Name a text index with `index`, or give `labels`");let d=n.filter(c=>c.label===i&&c.status==="ready"&&(e.property===void 0||c.property===e.property));if(d.length===0)throw _(404,`No ready text index on label "${i}"`);if(d.length>1)throw _(422,`Label "${i}" has several text indexes (${d.map(c=>c.name).join(", ")}); name one with \`index\``);s=d[0]}return{index:s.name,label:s.label,query:e.query,allTerms:(a=e.allTerms)!=null?a:!1,phrase:(o=e.phrase)!=null?o:!1}}),Gt=r=>h(void 0,[r],function*({body:t,engine:e}){var m,f,y,R,I,C,V,N,J,de,le;let n=(m=t.queryVector)!=null?m:[];if(n.length===0)throw new ae("records.vectorSearch",xe["records.vectorSearch"]);let s=yield ie(e),a;if(typeof t.index=="string"){if(a=s.find(F=>F.name===t.index),!a)throw _(404,`No vector index named "${t.index}"`)}else{let F=((f=t.labels)!=null?f:[])[0],H=s.filter(G=>{var pe;return G.label===F&&G.property===t.propertyName&&(t.similarityFunction===void 0||G.similarity===t.similarityFunction)&&Number(G.dimensions)===((pe=t.dimensions)!=null?pe:n.length)});if(H.length!==1)throw _(H.length===0?404:422,H.length===0?`No vector index matches label "${F}", property "${t.propertyName}"`:`${H.length} vector indexes match label "${F}", property "${t.propertyName}"; name one with \`index\``);a=H[0]}let o=(y=t.labels)!=null&&y.length?t.labels:[a.label],i={property:a.property,vector:n,similarity:(R=a.similarity)!=null?R:"cosine",index:a.name,mode:t.mode,ef:t.ef,scoreThreshold:t.scoreThreshold},d=t.text?yield Rt(e,g(l({},t.text),{query:(I=t.text.query)!=null?I:t.query}),o):void 0,c=d?{kind:"hybrid",query:{labels:o,predicate:(C=t.where)!=null?C:{},vector:g(l({},i),{weight:t.weight,prefetchLimit:t.prefetchLimit}),text:{index:d.index,query:d.query,allTerms:d.allTerms,phrase:d.phrase,weight:t.text.weight,prefetchLimit:t.text.prefetchLimit},fusion:t.fusion,rrfK:t.rrfK,offset:(V=t.skip)!=null?V:0,limit:(N=t.limit)!=null?N:10}}:{kind:"vector",query:g(l({},i),{labels:o,predicate:(J=t.where)!=null?J:{},offset:(de=t.skip)!=null?de:0,limit:(le=t.limit)!=null?le:10})},u=yield e.execute({kind:"query",query:c}),p=Pe(u.records);return x(p,{total:p.length,meta:{vectorSearch:u.vectorSearch,textSearch:u.textSearch,fusion:u.fusion}})}),$="([^/]+)",wt=[{method:"GET",pattern:new RegExp(`^/records/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){return x(Ie(yield Ve(e,t)))})},{method:"POST",pattern:/^\/records$/,handle:Wt},{method:"PATCH",pattern:new RegExp(`^/records/${$}$`),handle:ot("merge")},{method:"PUT",pattern:new RegExp(`^/records/${$}$`),handle:ot("replace")},{method:"DELETE",pattern:new RegExp(`^/records/${$}$`),handle:n=>h(void 0,[n],function*({params:[t],engine:e,txId:r}){return r?yield Z(e,r,{kind:"deleteRecord",record:{id:t}}):yield e.execute({kind:"mutate",mutation:{kind:"deleteRecord",id:t}}),x({message:"Record deleted"})})},{method:"POST",pattern:/^\/records\/delete$/,handle:n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){var a;K(r,"records.delete");let s=yield e.execute({kind:"mutate",mutation:{kind:"deleteRecords",query:oe(t)}});return x({message:`${(a=s.affected)!=null?a:0} records deleted`})})},{method:"POST",pattern:/^\/records\/search$/,handle:it},{method:"POST",pattern:new RegExp(`^/records/${$}/search$`),handle:it},{method:"POST",pattern:/^\/records\/import\/json$/,handle:n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){var a,o;let s=yield ct(e,r,{kind:"documents",label:t.label,documents:yield Ht(e,t.data,t.label),options:(a=t.options)!=null?a:{}});return dt(s,(o=t.options)==null?void 0:o.returnResult)})},{method:"POST",pattern:/^\/records\/import\/csv$/,handle:n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){var d,c,u,p,m,f,y;let s=(d=t.vectors)!=null&&d.length?yield ie(e):[],a=yield Promise.all(((c=t.vectors)!=null?c:[]).map(R=>Ee(e,R,t.label,s))),o=Object.fromEntries(Object.entries((u=t.parseConfig)!=null?u:{}).filter(([R])=>Yt.includes(R))),i=yield ct(e,r,{kind:"csv",label:t.label,data:(p=t.data)!=null?p:"",parseConfig:o,options:(m=t.options)!=null?m:{},vectors:a});return Number((f=i.count)!=null?f:0)===0?x(!0):dt(i,(y=t.options)==null?void 0:y.returnResult)})},{method:"POST",pattern:/^\/records\/export\/csv$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){let n=yield e.execute({kind:"query",query:{kind:"exportCsv",query:oe({labels:t.labels,where:t.where,orderBy:t.orderBy,skip:typeof t.skip=="number"?t.skip:0,limit:typeof t.limit=="number"?t.limit:100})}});return x({fileContent:n.content,dateTime:new Date().toISOString()})})},{method:"POST",pattern:new RegExp(`^/relationships/${$}$`),handle:s=>h(void 0,[s],function*({body:t,params:[e],engine:r,txId:n}){var i,d,c,u;let a=(i=t.type)!=null?i:ht,o=String((d=t.direction)!=null?d:"").toLowerCase()==="in";if(n)for(let p of Te(t.targetIds))yield Z(r,n,{kind:"createRelationship",relationType:a,source:{id:o?p:e},target:{id:o?e:p},properties:(c=t.properties)!=null?c:{}});else yield r.execute({kind:"mutate",mutation:{kind:"linkRecordsById",command:{relationType:a,direction:o?"in":"out",sourceIds:[e],targetIds:Te(t.targetIds),properties:(u=t.properties)!=null?u:{}}}});return x({message:`Relations to Record ${e} have been successfully created`})})},{method:"PUT",pattern:new RegExp(`^/relationships/${$}$`),handle:s=>h(void 0,[s],function*({body:t,params:[e],engine:r,txId:n}){var o;K(n,"records.detach");let a=String((o=t.direction)!=null?o:"").toLowerCase();return yield r.execute({kind:"mutate",mutation:{kind:"unlinkRecordsById",command:g(l({relationTypes:Te(t.typeOrTypes).filter(Boolean)},a==="in"||a==="out"?{direction:a}:{}),{sourceIds:[e],targetIds:Te(t.targetIds)})}}),x({message:`Relations to Record ${e} have been successfully deleted`})})},{method:"POST",pattern:/^\/relationships\/create-many$/,handle:n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){return K(r,"relationships.createMany"),yield e.execute({kind:"mutate",mutation:{kind:"linkRecords",command:lt(t)}}),x({message:"Relations have been successfully created"})})},{method:"POST",pattern:/^\/relationships\/delete-many$/,handle:n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){return K(r,"relationships.deleteMany"),yield e.execute({kind:"mutate",mutation:{kind:"unlinkRecords",command:lt(t)}}),x({message:"Relations have been successfully deleted"})})},{method:"POST",pattern:/^\/relationships\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var s,a,o,i,d,c,u,p,m,f,y;let n=yield e.execute({kind:"query",query:{kind:"relationships",query:{sourceLabels:(a=(s=t.source)==null?void 0:s.labels)!=null?a:[],targetLabels:(i=(o=t.target)==null?void 0:o.labels)!=null?i:[],relationType:(d=t.where)==null?void 0:d.type,predicate:Object.fromEntries(Object.entries((c=t.where)!=null?c:{}).filter(([R])=>R!=="type")),sourcePredicate:be((u=t.source)==null?void 0:u.where)?void 0:t.source.where,targetPredicate:be((p=t.target)==null?void 0:p.where)?void 0:t.target.where,offset:(m=t.skip)!=null?m:0,limit:t.limit}}});return x((f=n.relationships)!=null?f:[],{total:(y=n.total)!=null?y:0})})},{method:"GET",pattern:/^\/relationships\/patterns$/,handle:W("relationships.patterns.list")},{method:"POST",pattern:/^\/relationships\/patterns\/analyze$/,handle:W("relationships.patterns.analyze")},{method:"POST",pattern:new RegExp(`^/relationships/patterns/${$}/approve$`),handle:W("relationships.patterns.approve")},{method:"POST",pattern:new RegExp(`^/relationships/patterns/${$}/ignore$`),handle:W("relationships.patterns.ignore")},{method:"DELETE",pattern:new RegExp(`^/relationships/patterns/${$}$`),handle:W("relationships.patterns.delete")},{method:"POST",pattern:/^\/properties\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var n,s;return x(yield St(e,{labels:(n=t.labels)!=null?n:[],where:(s=t.where)!=null?s:{}}))})},{method:"GET",pattern:new RegExp(`^/properties/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){let n=yield pt(e,t);if(!n)throw _(404,`property \`${t}\` does not exist`);return x(n)})},{method:"DELETE",pattern:new RegExp(`^/properties/${$}$`),handle:n=>h(void 0,[n],function*({params:[t],engine:e,txId:r}){K(r,"properties.delete");let s=yield pt(e,t);if(!s)throw _(404,`property \`${t}\` does not exist`);return yield e.execute({kind:"mutate",mutation:{kind:"deleteProperty",name:s.name}}),x({message:`Property (${t}) has been successfully deleted.`})})},{method:"POST",pattern:new RegExp(`^/properties/${$}/values$`),handle:n=>h(void 0,[n],function*({body:t,params:[e],engine:r}){var o,i,d,c,u,p;let s=!!t.query||!!t.limit,a=yield r.execute({kind:"query",query:l(l({kind:"propertyValues",property:e,query:oe({labels:(o=t.labels)!=null?o:[],where:(i=t.where)!=null?i:{}})},s?{mode:"topK",limit:(d=t.limit)!=null?d:100}:{}),t.query?{search:l(l({text:t.query,match:(c=t.match)!=null?c:"contains"},t.domainOnMiss?{domainOnMiss:t.domainOnMiss}:{}),t.minSimilarity!==void 0?{minSimilarity:t.minSimilarity}:{})}:{})});return x(l(l(l({values:(u=a.values)!=null?u:[]},(p=a.counts)!=null&&p.length?{counts:a.counts}:{}),s&&a.distinctCount!==void 0?{distinctCount:a.distinctCount}:{}),a.searchMissed?{searchMissed:!0}:{}))})},{method:"POST",pattern:/^\/labels\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var a;let n=yield e.execute({kind:"describe",describe:{kind:"labels",query:oe(t)}}),s={};for(let o of(a=n.labels)!=null?a:[])s[o]=(yield mt(e,g(l({},t),{labels:[o],skip:0,limit:1}))).total;return x(s)})},{method:"POST",pattern:/^\/tx$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var s;let n=yield e.execute({kind:"transaction",transaction:{kind:"begin",ttlMs:t.ttl,autocommit:(s=t.autocommit)!=null?s:!1}});return x({id:n.transactionId})})},{method:"GET",pattern:new RegExp(`^/tx/${$}$`),handle:e=>h(void 0,[e],function*({params:[t]}){return x({id:t})})},{method:"POST",pattern:new RegExp(`^/tx/${$}/commit$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){var s;let n=yield e.execute({kind:"transaction",transaction:{kind:"commit",transactionId:t}});if(n.status!=="committed")throw _(409,`Transaction commit failed: ${(s=n.reason)!=null?s:n.status}`);return x({message:`Transaction (${t}) has been successfully committed.`})})},{method:"POST",pattern:new RegExp(`^/tx/${$}/rollback$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){return yield e.execute({kind:"transaction",transaction:{kind:"rollback",transactionId:t}}),x({message:`Transaction (${t}) has been rolled back.`})})},{method:"POST",pattern:/^\/query\/raw$/,handle:n=>h(void 0,[n],function*({body:t,engine:e,txId:r}){var a,o;K(r,"query.raw");let s=yield e.execute({kind:"query",query:{kind:"statement",language:"cypher",statement:t.query,parameters:(a=t.params)!=null?a:null}});return x({records:(o=s.rows)!=null?o:[]})})},{method:"GET",pattern:/^\/text-indexes$/,handle:e=>h(void 0,[e],function*({engine:t}){return x(yield Me(t))})},{method:"POST",pattern:/^\/text-indexes$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var a,o;let n=new Set((yield Ue(e)).map(i=>String(i.name)));if(t.name!==void 0&&n.has(t.name))throw _(409,`An index named "${t.name}" already exists`);let s=yield e.execute({kind:"index",index:{kind:"create",definition:{name:(a=t.name)!=null?a:ve(at(t),n),label:t.label,property:t.property,kind:"text",consistency:(o=t.consistency)!=null?o:"eventual"}}});return x(gt(s.index))})},{method:"POST",pattern:/^\/text-indexes\/name-suggestion$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){let n=new Set((yield Ue(e)).map(s=>String(s.name)));return x({name:ve(at(t),n)})})},{method:"DELETE",pattern:new RegExp(`^/text-indexes/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){let n=decodeURIComponent(t);if(!(yield Me(e)).some(s=>s.name===n))throw _(404,`No text index named "${n}"`);return yield e.execute({kind:"index",index:{kind:"drop",name:n}}),x({deleted:!0})})},{method:"POST",pattern:/^\/search\/text$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var o,i,d,c,u,p,m;if(typeof t.query!="string"||t.query.trim()==="")throw _(422,"query is required");let n=yield Rt(e,t,(o=t.labels)!=null?o:[]),s=yield e.execute({kind:"query",query:{kind:"hybrid",query:{labels:(i=t.labels)!=null&&i.length?t.labels:[n.label],predicate:(d=t.where)!=null?d:{},text:{index:n.index,query:n.query,allTerms:n.allTerms,phrase:n.phrase},offset:(c=t.skip)!=null?c:0,limit:(u=t.limit)!=null?u:10}}}),a=Pe(s.records);return x(a,{total:(m=(p=s.textSearch)==null?void 0:p.matches)!=null?m:a.length,meta:{textSearch:s.textSearch}})})},{method:"POST",pattern:/^\/ai\/schema$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){return x(yield Be(e,t.labels,ue))})},{method:"POST",pattern:/^\/ai\/schema\/md$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){return x(st(yield Be(e,t.labels,ue)))})},{method:"POST",pattern:/^\/ai\/search-query$/,handle:W("ai.search")},{method:"POST",pattern:/^\/ai\/search$/,handle:Gt},{method:"GET",pattern:/^\/ai\/indexes$/,handle:e=>h(void 0,[e],function*({engine:t}){return x((yield ie(t)).map(ue))})},{method:"POST",pattern:/^\/ai\/indexes$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var c,u;if(t.sourceType!=="external")throw new ae("ai.indexes.create",xe["ai.indexes.create"]);let n=Number(t.dimensions);if(!Number.isInteger(n)||n<1||n>4096)throw _(422,"dimensions must be an integer between 1 and 4096");let s=(c=t.similarityFunction)!=null?c:"cosine",a=yield ie(e),o=a.find(p=>p.label===t.label&&p.property===t.propertyName&&p.similarity===s&&Number(p.dimensions)===n);if(o)throw _(409,`An embedding index for label "${t.label}", property "${t.propertyName}", sourceType "external", similarityFunction "${s}", and dimensions ${n} already exists ("${o.name}")`);let i=new Set(a.map(p=>String(p.name)));if(t.name!==void 0&&i.has(t.name))throw _(409,`An embedding index named "${t.name}" already exists`);let d=yield e.execute({kind:"index",index:{kind:"createVector",definition:{label:t.label,property:t.propertyName,dimensions:n,similarity:s,name:(u=t.name)!=null?u:ve(Ft(t,n,s),i)}}});return x(ue(d.index))})},{method:"DELETE",pattern:new RegExp(`^/ai/indexes/${$}$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){return yield e.execute({kind:"index",index:{kind:"dropVector",name:decodeURIComponent(t)}}),x({deleted:!0,queued:!1})})},{method:"GET",pattern:new RegExp(`^/ai/indexes/${$}/stats$`),handle:r=>h(void 0,[r],function*({params:[t],engine:e}){var s,a;let n=yield e.execute({kind:"describe",describe:{kind:"vectorIndex",name:decodeURIComponent(t)}});return x(g(l({},n.stats),{index:ue((a=(s=n.stats)==null?void 0:s.index)!=null?a:{})}))})},{method:"POST",pattern:new RegExp(`^/ai/indexes/${$}/vectors/upsert$`),handle:n=>h(void 0,[n],function*({body:t,params:[e],engine:r}){var a;let s=yield r.execute({kind:"index",index:{kind:"upsertVectors",name:decodeURIComponent(e),items:(a=t.items)!=null?a:[]}});return x({updated:s.updated,requested:s.requested})})},{method:"POST",pattern:/^\/ai\/values\/search$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var s,a,o,i;let n=yield e.execute({kind:"query",query:l(l({kind:"searchValues",search:l(l({text:t.text,match:(s=t.match)!=null?s:"contains"},t.caseSensitive?{caseSensitive:!0}:{}),t.minSimilarity!==void 0?{minSimilarity:t.minSimilarity}:{})},(a=t.labels)!=null&&a.length?{labels:t.labels}:{}),t.limit?{limit:t.limit}:{})});return x(l({matches:(o=n.matches)!=null?o:[],total:(i=n.total)!=null?i:0},n.skipped?{skipped:n.skipped}:{}))})},{method:"POST",pattern:/^\/ai\/schema\/summary$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var s,a;let n=yield e.execute({kind:"describe",describe:l(l({kind:"schemaSummary"},(s=t.labels)!=null&&s.length?{labels:t.labels}:{}),t.fewValues!==void 0?{fewValues:t.fewValues}:{})});return x((a=n.labels)!=null?a:[])})},{method:"POST",pattern:/^\/ai\/schema\/names$/,handle:r=>h(void 0,[r],function*({body:t,engine:e}){var s;let n=yield e.execute({kind:"describe",describe:l({kind:"names",text:t.text},t.limit?{limit:t.limit}:{})});return x((s=n.names)!=null?s:[])})},{method:"POST",pattern:/^\/ai\/schema\/join-candidates$/,handle:W("ai.getJoinCandidates")},{method:"GET",pattern:/^\/sdk\/settings$/,handle:W("settings.get")}],Or=wt.map(t=>`${t.method} ${t.pattern.source}`),xt=t=>(a,o)=>h(void 0,[a,o],function*(e,{method:r="GET",headers:n,requestData:s}){var p;let i=new URL(String(e),"http://direct"),d=wt.filter(m=>m.method===r&&m.pattern.test(i.pathname)).sort((m,f)=>m.pattern.source.split("(").length-f.pattern.source.split("(").length)[0];if(!d)throw new he(`${r} ${i.pathname} has no direct-mode mapping`);let c=((p=d.pattern.exec(i.pathname))!=null?p:[]).slice(1),u=n==null?void 0:n["x-transaction-id"];return yield d.handle({body:s!=null?s:{},params:c,query:i.searchParams,txId:u,engine:t})});var zt={"Content-Type":"application/json"},Tt=({httpClient:t,token:e,url:r})=>(n,o)=>h(void 0,null,function*(){var i=o,{headers:s}=i,a=z(i,["headers"]);var m;let d=yield t.makeRequest(`${r}${n}`,l({credentials:"omit",headers:Object.assign(l(l({},zt),s),typeof e!="undefined"?{Authorization:`Bearer ${e}`}:{})},a));if(d.getStatusCode()>=200&&d.getStatusCode()<300)return yield d.toJSON();let c="",u;try{let f=yield d.toJSON();u=f;let y=(m=f==null?void 0:f.message)!=null?m:f==null?void 0:f.error;Array.isArray(y)?c=y.join("; "):typeof y=="string"&&(c=y)}catch(f){}let p=new Error(c?`${d.getStatusCode()} ${c}`:`${d.getStatusCode()}`);throw p.status=d.getStatusCode(),p.body=u,p});var Y=class{constructor(e){this.id=e}rollback(){return h(this,null,function*(){return yield D.getInstance().tx.rollback(this.id)})}commit(){return h(this,null,function*(){return yield D.getInstance().tx.commit(this.id)})}};var bt="api.rushdb.com";var Dt="https",It="/api/v1";var b=t=>t?{"x-transaction-id":t}:void 0,Zt=t=>U(t)||t instanceof Y,T=t=>Zt(t)?t instanceof Y?t.id:t:void 0,Pt=t=>/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/.test(t),v=t=>{if(U(t)&&Pt(t))return t;if(t instanceof E&&t.data)return t.data.__id;if(q(t)&&"__id"in t&&Pt(t.__id))return t.__id},ee=t=>!(!q(t)||q(t)&&"name"in t&&!U(t.name)||q(t)&&"type"in t&&(!U(t.type)||!ze.includes(t.type))||!("value"in t)||!$e(t.value)||"metadata"in t&&!U(t.metadata)||"valueSeparator"in t&&!U(t.valueSeparator)),Et=t=>{let e=Dt,r=bt,n=443,s=It;if("url"in t){let o=new URL(t.url);e=o.protocol.replace(":",""),r=o.hostname,n=parseInt(o.port||(e==="http"?"80":e==="https"?"443":""))}"host"in t&&"port"in t&&"protocol"in t&&(e=t.protocol.replace(":",""),r=t.host,n=t.port),s&&!s.startsWith("/")&&(s="/"+s);let a="";return e==="http"&&n===80||e==="https"&&n===443||(a=":"+n),`${e}://${r}${a}${s}`},w=(t=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",r="";for(let n=0;n<t;n++){let s=Math.floor(Math.random()*e.length);r+=e[s]}return r};var ce=class{constructor(e,r){this.records={attach:(a,o)=>h(this,[a,o],function*({source:e,target:r,options:n},s){var f,y;let i=T(s),c=`/relationships/${v(e)}`,u={headers:Object.assign({},b(i)),method:"POST",requestData:l(l(l({targetIds:this._extractTargetIds(r,"Attach")},(n==null?void 0:n.type)&&{type:n.type}),(n==null?void 0:n.direction)&&{direction:n.direction}),(n==null?void 0:n.properties)&&{properties:n.properties})},p=typeof this.logger=="function"?w():"";(f=this.logger)==null||f.call(this,l({requestId:p,path:c},u));let m=yield this.fetcher(c,u);return(y=this.logger)==null||y.call(this,g(l({requestId:p,path:c},u),{responseData:m.data})),m}),detach:(a,o)=>h(this,[a,o],function*({source:e,target:r,options:n},s){var f,y;let i=T(s),c=`/relationships/${v(e)}`,u={headers:Object.assign({},b(i)),method:"PUT",requestData:l(l({targetIds:this._extractTargetIds(r,"Detach")},(n==null?void 0:n.typeOrTypes)&&{typeOrTypes:n.typeOrTypes}),(n==null?void 0:n.direction)&&{direction:n.direction})},p=typeof this.logger=="function"?w():"";(f=this.logger)==null||f.call(this,l({requestId:p,path:c},u));let m=yield this.fetcher(c,u);return(y=this.logger)==null||y.call(this,g(l({requestId:p,path:c},u),{responseData:m.data})),m}),create:(o,i)=>h(this,[o,i],function*({label:e,data:r,options:n,vectors:s},a){var y,R;let d=T(a),c="/records",u={headers:Object.assign({},b(d)),method:"POST",requestData:{}},p=typeof this.logger=="function"?w():"",m=ne(X(r));if(A(m)&&m.every(ee))u.requestData=l({label:e,properties:m,options:n},(s==null?void 0:s.length)&&{vectors:s});else if(se(m))u.requestData=l({label:e,data:m,options:n},(s==null?void 0:s.length)&&{vectors:s});else throw q(m)?new Error("Provided data is not a flat object. Consider using the `importJson` method for nested objects or arrays of nested objects, or use `createMany` for arrays of flat objects."):new Error("Provided data is not valid.");(y=this.logger)==null||y.call(this,l({requestId:p,path:c},u));let f=yield this.fetcher(c,u);return(R=this.logger)==null||R.call(this,g(l({requestId:p,path:c},u),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new E(f.data):new E}),createMany:(e,r)=>h(this,null,function*(){var m,f,y;let n=A(e.data)?e.data:[e.data];if(!n.every(R=>se(R)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");let a=e.vectors?A(e.vectors[0])?e.vectors:[e.vectors]:void 0;if(a&&a.length>n.length)throw new Error(`records.createMany: vectors length (${a.length}) exceeds the number of data rows (${n.length}).`);let o=a!=null&&a.length?n.map((R,I)=>{var C;return(C=a[I])!=null&&C.length?g(l({},R),{$vectors:a[I]}):R}):n,i=T(r),d="/records/import/json",c={headers:Object.assign({},b(i)),method:"POST",requestData:{label:e.label,data:o,options:e.options}},u=typeof this.logger=="function"?w():"";(m=this.logger)==null||m.call(this,l({requestId:u,path:d},c));let p=yield this.fetcher(d,c);if((f=this.logger)==null||f.call(this,g(l({requestId:u,path:d},c),{responseData:p.data})),p!=null&&p.success&&(p!=null&&p.data)){let R=A(p.data)?(y=p.data)==null?void 0:y.map(I=>new E(I)):[];return new B(R,p.total)}return new B([])}),importJson:(e,r)=>h(this,null,function*(){var m,f,y;let{data:n,options:s}=e,{label:a}=e,o=n;if(!a){let R=q(n)&&!A(n)?ne(n):n;if(Ze(R))throw new Error("records.importJson: Missing `label`. Provide `label` for top-level arrays or objects with primitive top-level properties, or pass a container object whose top-level values are objects or arrays, e.g. { ITEM: [...], USER: [...] }.")}let i=T(r),d="/records/import/json",c={headers:Object.assign({},b(i)),method:"POST",requestData:{label:a,data:o,options:s}},u=typeof this.logger=="function"?w():"";(m=this.logger)==null||m.call(this,l({requestId:u,path:d},c));let p=yield this.fetcher(d,c);if((f=this.logger)==null||f.call(this,g(l({requestId:u,path:d},c),{responseData:p.data})),p!=null&&p.success&&(p!=null&&p.data)){let R=A(p.data)?(y=p.data)==null?void 0:y.map(I=>new E(I)):[];return new B(R,p.total)}return new B([])}),importCsv:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/records/import/csv",a={headers:Object.assign({},b(n)),method:"POST",requestData:e},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);if((c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i!=null&&i.success&&(i!=null&&i.data)){let u=A(i.data)?i.data.map(p=>new E(p)):[];return new B(u,i.total)}return new B([])}),delete:(e,r)=>h(this,null,function*(){var d,c,u;if(re(e.where)&&!((d=this==null?void 0:this.options)!=null&&d.allowForceDelete))throw new L("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let n=T(r),s="/records/delete",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(u=this.logger)==null||u.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),deleteById:(e,r)=>h(this,null,function*(){var c,u;let n=T(r),s=A(e),a=s?"/records/delete":`/records/${e}`,o={headers:Object.assign({},b(n)),method:s?"POST":"DELETE",requestData:s?{limit:1e3,where:{$id:{$in:e}}}:void 0},i=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,l({requestId:i,path:a},o));let d=yield this.fetcher(a,o);return(u=this.logger)==null||u.call(this,g(l({requestId:i,path:a},o),{responseData:d.data})),d}),export:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/records/export/csv",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),find:(e,r)=>h(this,null,function*(){var m,f;let p=e,{id:n}=p,s=z(p,["id"]),a=T(r),o=n?`/records/${n}/search`:"/records/search",i={headers:Object.assign({},b(a)),method:"POST",requestData:s!=null?s:{}},d=typeof this.logger=="function"?w():"";(m=this.logger)==null||m.call(this,l({requestId:d,path:o},i));let c=yield this.fetcher(o,i);(f=this.logger)==null||f.call(this,g(l({requestId:d,path:o},i),{responseData:c.data}));let u=c.data.map(y=>new E(y));return new B(u,c.total,e)}),vectorSearch:(e,r)=>h(this,null,function*(){var u,p,m,f,y,R,I;let n=T(r),s="/ai/search",a={method:"POST",headers:Object.assign({},b(n)),requestData:e},o=typeof this.logger=="function"?w():"";(u=this.logger)==null||u.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);(p=this.logger)==null||p.call(this,g(l({requestId:o,path:s},a),{responseData:i.data}));let d=((m=i.data)!=null?m:[]).map(C=>new E(C)),c=new B(d,(f=i.total)!=null?f:0);return c.vectorSearch=(y=i.meta)==null?void 0:y.vectorSearch,c.textSearch=(R=i.meta)==null?void 0:R.textSearch,c.fusion=(I=i.meta)==null?void 0:I.fusion,c}),textSearch:(e,r)=>h(this,null,function*(){var u,p,m,f,y;let n=T(r),s="/search/text",a={method:"POST",headers:Object.assign({},b(n)),requestData:e},o=typeof this.logger=="function"?w():"";(u=this.logger)==null||u.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);(p=this.logger)==null||p.call(this,g(l({requestId:o,path:s},a),{responseData:i.data}));let d=((m=i.data)!=null?m:[]).map(R=>new E(R)),c=new B(d,(f=i.total)!=null?f:0);return c.textSearch=(y=i.meta)==null?void 0:y.textSearch,c}),findById:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s=A(e)?"/records/search":`/records/${e}`,a={headers:Object.assign({},b(n)),method:A(e)?"POST":"GET",requestData:A(e)?{where:{$id:{$in:e}},limit:e.length}:void 0},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);if((c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),A(e)){let u=i.data.map(p=>new E(p));return new B(u,i.total)}else return new E(i.data)}),findOne:(e,r)=>h(this,null,function*(){var c,u;let n=T(r),s="/records/search",a={headers:Object.assign({},b(n)),method:"POST",requestData:g(l({},e),{limit:1,skip:0})},o=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);(u=this.logger)==null||u.call(this,g(l({requestId:o,path:s},a),{responseData:i.data}));let[d]=i.data;return new E(d)}),findUniq:(e,r)=>h(this,null,function*(){var c,u;let n=T(r),s="/records/search",a={headers:Object.assign({},b(n)),method:"POST",requestData:g(l({},e),{limit:1,skip:0})},o=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);if((u=this.logger)==null||u.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),typeof i.total!="undefined"&&i.total>1)throw new fe(i.total,e);let[d]=i.data;return new E(d)}),set:(i,d)=>h(this,[i,d],function*({target:e,label:r,data:n,options:s,vectors:a},o){var I,C;let c=T(o),p=`/records/${v(e)}`,m={headers:Object.assign({},b(c)),method:"PUT",requestData:{}},f=typeof this.logger=="function"?w():"",y=ne(X(n));if(A(y)&&y.every(ee))m.requestData=l({label:r,properties:y},(a==null?void 0:a.length)&&{vectors:a});else if(se(y))m.requestData=l({label:r,data:y,options:s},(a==null?void 0:a.length)&&{vectors:a});else throw q(y)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(I=this.logger)==null||I.call(this,l({requestId:f,path:p},m));let R=yield this.fetcher(p,m);return(C=this.logger)==null||C.call(this,g(l({requestId:f,path:p},m),{responseData:R.data})),R!=null&&R.success&&(R!=null&&R.data)?new E(R.data):new E}),update:(o,i)=>h(this,[o,i],function*({target:e,label:r,data:n,options:s},a){var R,I;let d=v(e),c=T(a),u=`/records/${d}`,p={headers:Object.assign({},b(c)),method:"PATCH",requestData:{}},m=typeof this.logger=="function"?w():"",f=ne(X(n));if(A(f)&&f.every(ee))p.requestData={label:r,properties:f};else if(se(f))p.requestData={label:r,data:f,options:s};else throw q(f)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(R=this.logger)==null||R.call(this,l({requestId:m,path:u},p));let y=yield this.fetcher(u,p);return(I=this.logger)==null||I.call(this,g(l({requestId:m,path:u},p),{responseData:y.data})),y!=null&&y.success&&(y!=null&&y.data)?new E(y.data):new E}),upsert:(o,i)=>h(this,[o,i],function*({label:e,data:r,options:n,vectors:s},a){var R,I,C;let d=T(a),c="/records",u={headers:Object.assign({},b(d)),method:"POST",requestData:{}},p=typeof this.logger=="function"?w():"",m=ne(X(r)),f=g(l({},n),{mergeBy:(R=n==null?void 0:n.mergeBy)!=null?R:[]});if(A(m)&&m.every(ee))u.requestData=l({label:e,properties:m,options:f},(s==null?void 0:s.length)&&{vectors:s});else if(se(m))u.requestData=l({label:e,data:m,options:f},(s==null?void 0:s.length)&&{vectors:s});else throw q(m)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(I=this.logger)==null||I.call(this,l({requestId:p,path:c},u));let y=yield this.fetcher(c,u);return(C=this.logger)==null||C.call(this,g(l({requestId:p,path:c},u),{responseData:y.data})),y!=null&&y.success&&(y!=null&&y.data)?new E(y.data):new E})};this.relationships={patterns:{list:()=>h(this,null,function*(){var a,o;let e="/relationships/patterns",r={method:"GET",headers:{}},n=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,l({requestId:n,path:e},r));let s=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,g(l({requestId:n,path:e},r),{responseData:s.data})),s}),analyze:()=>h(this,null,function*(){var a,o;let e="/relationships/patterns/analyze",r={method:"POST",headers:{},requestData:{}},n=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,l({requestId:n,path:e},r));let s=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,g(l({requestId:n,path:e},r),{responseData:s.data})),s}),approve:e=>h(this,null,function*(){var o,i;let r=`/relationships/patterns/${encodeURIComponent(e)}/approve`,n={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),ignore:e=>h(this,null,function*(){var o,i;let r=`/relationships/patterns/${encodeURIComponent(e)}/ignore`,n={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),delete:(e,r)=>h(this,null,function*(){var d,c;let n=r!=null&&r.deleteExisting?"?deleteExisting=true":"",s=`/relationships/patterns/${encodeURIComponent(e)}${n}`,a={method:"DELETE",headers:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i})},createMany:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/relationships/create-many",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),deleteMany:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/relationships/delete-many",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),find:(...n)=>h(this,[...n],function*(e={},r){var c,u;let s=T(r),a="/relationships/search",o={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,l({requestId:i,path:a},o));let d=yield this.fetcher(a,o);return(u=this.logger)==null||u.call(this,g(l({requestId:i,path:a},o),{responseData:d.data})),d})};this.properties={delete:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s=`/properties/${e}`,a={headers:Object.assign({},b(n)),method:"DELETE"},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),find:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/properties/search",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),findById:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s=`/properties/${e}`,a={headers:Object.assign({},b(n)),method:"GET"},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),values:(e,r,n)=>h(this,null,function*(){var c,u;let s=T(n),a=`/properties/${e}/values`,o={headers:Object.assign({},b(s)),method:"POST",requestData:r!=null?r:{}},i=typeof this.logger=="function"?w():"";(c=this.logger)==null||c.call(this,l({requestId:i,path:a},o));let d=yield this.fetcher(a,o);return(u=this.logger)==null||u.call(this,g(l({requestId:i,path:a},o),{responseData:d.data})),d})};this.labels={find:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/labels/search",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i})};this.tx={begin:e=>h(this,null,function*(){var o,i;let r="/tx",n={method:"POST",requestData:q(e)?e:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),new Y(a.data.id)}),commit:e=>h(this,null,function*(){var i,d;let n=`/tx/${T(e)}/commit`,s={method:"POST",requestData:{}},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,l({requestId:a,path:n},s));let o=yield this.fetcher(n,s);return(d=this.logger)==null||d.call(this,g(l({requestId:a,path:n},s),{responseData:o.data})),o}),get:e=>h(this,null,function*(){var i,d;let n=`/tx/${T(e)}`,s={method:"GET"},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,l({requestId:a,path:n},s));let o=yield this.fetcher(n,s);return(d=this.logger)==null||d.call(this,g(l({requestId:a,path:n},s),{responseData:o.data})),new Y(o.data.id)}),rollback:e=>h(this,null,function*(){var i,d;let n=`/tx/${T(e)}/rollback`,s={method:"POST",requestData:{}},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,l({requestId:a,path:n},s));let o=yield this.fetcher(n,s);return(d=this.logger)==null||d.call(this,g(l({requestId:a,path:n},s),{responseData:o.data})),o})};this.settings={get:()=>h(this,null,function*(){var a,o;let e="/sdk/settings",r={method:"GET"},n=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,l({requestId:n,path:e},r));let s=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,g(l({requestId:n,path:e},r),{responseData:s.data})),s})};this.query={raw:(s,a)=>h(this,[s,a],function*({query:e,params:r},n){var p,m;let o=T(n),i="/query/raw",d={headers:Object.assign({},b(o)),method:"POST",requestData:{query:e,params:r}},c=typeof this.logger=="function"?w():"";(p=this.logger)==null||p.call(this,l({requestId:c,path:i},d));let u=yield this.fetcher(i,d);return(m=this.logger)==null||m.call(this,g(l({requestId:c,path:i},d),{responseData:u.data})),u})};this.textIndexes={find:()=>h(this,null,function*(){return this.textIndexRequest("/text-indexes","GET")}),create:e=>h(this,null,function*(){return this.textIndexRequest("/text-indexes","POST",e)}),suggestName:e=>h(this,null,function*(){return this.textIndexRequest("/text-indexes/name-suggestion","POST",e)}),delete:e=>h(this,null,function*(){return this.textIndexRequest(`/text-indexes/${encodeURIComponent(e)}`,"DELETE")})};this.ai={searchValues:e=>h(this,null,function*(){var o,i;let r="/ai/values/search",n={headers:{},method:"POST",requestData:e},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),getSchemaSummary:e=>h(this,null,function*(){var o,i;let r="/ai/schema/summary",n={headers:{},method:"POST",requestData:e!=null?e:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),resolveNames:e=>h(this,null,function*(){var o,i;let r="/ai/schema/names",n={headers:{},method:"POST",requestData:e},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),getJoinCandidates:e=>h(this,null,function*(){var o,i;let r="/ai/schema/join-candidates",n={headers:{},method:"POST",requestData:e!=null?e:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),getSchema:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/ai/schema",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),getSchemaMarkdown:(e,r)=>h(this,null,function*(){var d,c;let n=T(r),s="/ai/schema/md",a={headers:Object.assign({},b(n)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?w():"";(d=this.logger)==null||d.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(l({requestId:o,path:s},a),{responseData:i.data})),i}),indexes:{find:()=>h(this,null,function*(){var a,o;let e="/ai/indexes",r={method:"GET",headers:{}},n=typeof this.logger=="function"?w():"";(a=this.logger)==null||a.call(this,l({requestId:n,path:e},r));let s=yield this.fetcher(e,r);return(o=this.logger)==null||o.call(this,g(l({requestId:n,path:e},r),{responseData:s.data})),s}),create:e=>h(this,null,function*(){var u,p;let r="/ai/indexes",c=e,{external:n}=c,s=z(c,["external"]),a=n===!0?g(l({},s),{sourceType:"external"}):s,o={method:"POST",headers:{},requestData:a},i=typeof this.logger=="function"?w():"";(u=this.logger)==null||u.call(this,l({requestId:i,path:r},o));let d=yield this.fetcher(r,o);return(p=this.logger)==null||p.call(this,g(l({requestId:i,path:r},o),{responseData:d.data})),d}),upsertVectors:(e,r)=>h(this,null,function*(){var i,d;let n=`/ai/indexes/${e}/vectors/upsert`,s={method:"POST",headers:{},requestData:r},a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,l({requestId:a,path:n},s));let o=yield this.fetcher(n,s);return(d=this.logger)==null||d.call(this,g(l({requestId:a,path:n},s),{responseData:o.data})),o}),delete:e=>h(this,null,function*(){var o,i;let r=`/ai/indexes/${e}`,n={method:"DELETE",headers:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a}),stats:e=>h(this,null,function*(){var o,i;let r=`/ai/indexes/${e}/stats`,n={method:"GET",headers:{}},s=typeof this.logger=="function"?w():"";(o=this.logger)==null||o.call(this,l({requestId:s,path:r},n));let a=yield this.fetcher(r,n);return(i=this.logger)==null||i.call(this,g(l({requestId:s,path:r},n),{responseData:a.data})),a})},search:(e,r)=>h(this,null,function*(){var y,R,I,C,V,N;let n=T(r==null?void 0:r.transaction),s="/ai/search-query",a={method:"POST",headers:Object.assign({},b(n)),requestData:{prompt:e,currentQuery:r==null?void 0:r.currentQuery}},o=typeof this.logger=="function"?w():"";(y=this.logger)==null||y.call(this,l({requestId:o,path:s},a));let i=yield this.fetcher(s,a);(R=this.logger)==null||R.call(this,g(l({requestId:o,path:s},a),{responseData:i.data}));let d=i.data.searchQuery,c="/records/search",u={method:"POST",headers:Object.assign({},b(n)),requestData:d!=null?d:{}},p=typeof this.logger=="function"?w():"";(I=this.logger)==null||I.call(this,l({requestId:p,path:c},u));let m=yield this.fetcher(c,u);(C=this.logger)==null||C.call(this,g(l({requestId:p,path:c},u),{responseData:m.data}));let f=((V=m.data)!=null?V:[]).map(J=>new E(J));return new B(f,(N=m.total)!=null?N:0,d,i.data.warnings)})};if(this.fetcher=null,r!=null&&r.direct){if(!r.engineUrl)throw new Error("Direct mode requires `engineUrl`, the standalone engine base URL.");if(!r.httpClient)throw new Error("Direct mode requires an HTTP client; import the SDK from its Node or browser entry.");this.direct=new Re({engineUrl:r.engineUrl,token:e!=null?e:"",httpClient:r.httpClient,scope:r.scope}),this.fetcher=xt(this.direct)}else if(r!=null&&r.httpClient){let n=Et(r);this.fetcher=Tt({httpClient:r.httpClient,token:e,url:n})}r!=null&&r.options&&(this.options=r==null?void 0:r.options),r!=null&&r.logger&&(this.logger=r==null?void 0:r.logger)}_extractTargetIds(e,r){var n;if(e instanceof E){let s=v(e);if(!s)throw new L(`${r} error: Target id is empty`);return[s]}if(A(e)&&e.every(s=>s instanceof E)){let s=e.map(v).filter(k);if(!s.length)throw new L(`${r} error: Target ids are empty`);return s}if(e instanceof B){let s=(n=e.data)==null?void 0:n.map(v).filter(k);if(!(s!=null&&s.length))throw new L(`${r} error: Target ids are empty`);return s}if(q(e)&&"__id"in e)return[e.__id];if(A(e)&&e.every(s=>q(s)&&"__id"in s)){let s=e.map(v).filter(k);if(!s.length)throw new L(`${r} error: Target ids are empty`);return s}return A(e)?e:U(e)?[e]:[]}textIndexRequest(e,r,n){return h(this,null,function*(){var i,d;let s=l({method:r,headers:{}},n===void 0?{}:{requestData:n}),a=typeof this.logger=="function"?w():"";(i=this.logger)==null||i.call(this,l({requestId:a,path:e},s));let o=yield this.fetcher(e,s);return(d=this.logger)==null||d.call(this,g(l({requestId:a,path:e},s),{responseData:o.data})),o})}};var Ot,M=class M extends ce{constructor(e,r){var a,o;let n=e!=null?e:typeof process!="undefined"?(a=process.env)==null?void 0:a.RUSHDB_API_KEY:void 0,s=tt(r);super(n,g(l({},s),{httpClient:(o=s.httpClient)!=null?o:Ot})),M.instance=this,this.initializeSync(n,s)}initializeSync(e,r){M.state={initialized:!0,debug:!1,timeout:rt("timeout",r==null?void 0:r.timeout,8e4),token:e,direct:(r==null?void 0:r.direct)===!0,engineUrl:r==null?void 0:r.engineUrl}}static getInstance(){if(M.instance)return M.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static isInitialized(){return k(M.instance)}toDBRecordInstance(e){return new E(e)}};M.instance=null,M.state={initialized:!1,debug:!1,timeout:8e4};var D=M,At=t=>{Ot=t};var qt=class{constructor(e,r,n){this.label=e,this.schema=r,this.config=n!=null?n:{}}getLabel(){return this.label}toDBRecordInstance(e){return h(this,null,function*(){try{return D.getInstance().toDBRecordInstance(e)}catch(r){throw new Error("No RushDB instance was provided during model initialization.")}})}find(e,r){return h(this,null,function*(){let n=e!=null?e:{};return D.getInstance().records.find(g(l({},n),{labels:[this.label]}),r)})}findOne(e,r){return h(this,null,function*(){let n=e!=null?e:{};return D.getInstance().records.findOne(g(l({},n),{labels:[this.label]}),r)})}findById(e,r){return h(this,null,function*(){return this.findOne({where:{$id:e}},r)})}findUniq(e,r){return h(this,null,function*(){let n=e!=null?e:{};return D.getInstance().records.findUniq(g(l({},n),{labels:[this.label]}),r)})}create(e,r,n){return h(this,null,function*(){var d,c;let s=yield Se(this.schema,e),a=ke(this.schema,s),o=k(a),i=D.getInstance();if(o){let u=r!=null?r:yield i.tx.begin(),p=yield this.find({where:a},u),m=typeof r!="undefined";if(!((d=p==null?void 0:p.data)!=null&&d.length)){let y=yield i.records.create({label:this.label,data:s},u);return m||(yield u.commit()),y}else switch((c=n==null?void 0:n.onConflict)!=null?c:"throw"){case"upsert":{let R=p.data[0],I=yield i.records.set({target:R.id,label:this.label,data:s},u);return m||(yield u.commit()),I}case"skip":return m||(yield u.commit()),null;default:throw m||(yield u.commit()),new Q(this.label,a)}}return yield i.records.create({label:this.label,data:s},r)})}attach(a,o){return h(this,arguments,function*({source:e,target:r,options:n},s){return yield D.getInstance().records.attach({source:e,target:r,options:n},s)})}detach(a,o){return h(this,arguments,function*({source:e,target:r,options:n},s){return yield D.getInstance().records.detach({source:e,target:r,options:n},s)})}validateTargetLabel(e,r){return h(this,null,function*(){let n=v(e);if(!n)return;let a=yield D.getInstance().records.findById(n,r);if(!a)throw new Error(`Record with id "${n}" not found.`);if(a.data.__label!==this.label)throw new TypeError(`Target record label "${a.data.__label}" does not match model label "${this.label}".`)})}handleSetOrUpdate(e,r,n,s){return h(this,null,function*(){var d,c;if(this.config.validateTargetLabel&&(yield this.validateTargetLabel(e,s)),A(r)&&r.every(ee))return yield D.getInstance().records[n]({label:this.label,target:e,data:r},s);let a=D.getInstance(),o=yield Se(this.schema,r),i=ke(this.schema,o);if(!re(i)){let u=s!=null?s:yield a.tx.begin(),p=yield this.find({where:i},u),m=typeof s!="undefined";if(!((d=p==null?void 0:p.data)!=null&&d.length)||p.data.length===1&&((c=p.data[0])==null?void 0:c.id)===v(e)){let y=yield a.records[n]({target:e,label:this.label,data:o},u);return m||(yield u.commit()),y}else throw m||(yield u.commit()),new Q(this.label,i)}return yield a.records[n]({label:this.label,target:e,data:o},s)})}set(e,r,n){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,r,"set",n)})}update(e,r,n){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,r,"update",n)})}createMany(e,r){return h(this,null,function*(){var o;let n=D.getInstance(),s=typeof r!="undefined",a=r!=null?r:yield n.tx.begin();try{let i=yield Promise.all(e.map(u=>h(this,null,function*(){return yield Se(this.schema,u)}))),d=et(i,this.schema,this.label);if(!re(d)){let u=Object.entries(d).map(([m,f])=>({[m]:{$in:f}})),p=yield this.find({where:{$or:u}},a);if((o=p==null?void 0:p.data)!=null&&o.length)throw new Q(this.label,Object.keys(d))}let c=yield n.records.createMany({label:this.label,data:i},a);return s||(yield a.commit()),c}catch(i){throw s||(yield a.rollback()),i}})}delete(e,r){return h(this,null,function*(){if(re(e.where))throw new L(`You must specify criteria to delete records of type '${this.label}'. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.`);return yield D.getInstance().records.delete(g(l({},e),{labels:[this.label]}),r)})}deleteById(e,r){return h(this,null,function*(){return yield D.getInstance().records.deleteById(e,r)})}};At(new ye);var Rn=D;export{xe as CLOUD_ONLY_FORMS,we as CLOUD_ONLY_METHODS,ae as CloudOnlyError,E as DBRecordInstance,B as DBRecordsArrayInstance,he as DirectModeError,L as EmptyTargetError,j as HttpClient,Oe as HttpClientResponse,qt as Model,fe as NonUniqueResultError,ce as RestAPI,D as RushDB,Y as Transaction,Q as UniquenessError,Rn as default,nt as idToDate,_e as idToTimestamp,At as initSDK,Vt as isCloudOnlyMethod,Se as mergeDefaultsWithPayload,tt as parseConfig,ke as pickUniqFieldsFromRecord,et as pickUniqFieldsFromRecords,rt as validateInteger};
|