@rushdb/javascript-sdk 2.9.1 → 2.10.1
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 +1 -1
- package/dist/api/api.d.ts +21 -7
- package/dist/api/index.d.ts +1 -1
- package/dist/api/types.d.ts +22 -5
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/index.node.d.ts +2 -2
- package/dist/index.worker.d.ts +2 -2
- package/dist/sdk/record.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ await db.records.create({
|
|
|
71
71
|
})
|
|
72
72
|
|
|
73
73
|
// 3. Recall by meaning, scoped by graph
|
|
74
|
-
const memories = await db.
|
|
74
|
+
const memories = await db.records.vectorSearch({
|
|
75
75
|
labels: ['MEMORY'],
|
|
76
76
|
propertyName: 'output',
|
|
77
77
|
query: 'what did we decide about Q4?',
|
package/dist/api/api.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { DBRecordInstance, DBRecordsArrayInstance } from '../sdk/record.js';
|
|
|
4
4
|
import type { SDKConfig } from '../sdk/types.js';
|
|
5
5
|
import type { FlatObject, InferSchemaTypesWrite, MaybeArray, OrderDirection, Property, PropertyDraft, PropertyValuesData, Schema, RelationshipSearchQuery, SearchQuery, Where } from '../types/index.js';
|
|
6
6
|
import type { ApiResponse } from './types.js';
|
|
7
|
-
import type { CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPatternListResponse,
|
|
7
|
+
import type { CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPatternListResponse, SmartSearchOptions, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult, VectorEntry, VectorSearchParams } from './types.js';
|
|
8
8
|
import { createFetcher } from '../network/index.js';
|
|
9
9
|
import { Transaction } from '../sdk/transaction.js';
|
|
10
10
|
export declare class RestAPI {
|
|
@@ -178,6 +178,15 @@ export declare class RestAPI {
|
|
|
178
178
|
find: <S extends Schema = any, Q extends SearchQuery<S> = SearchQuery<S>>(searchQueryWithEntryPoint: Q & {
|
|
179
179
|
id?: string;
|
|
180
180
|
}, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S, Q>>;
|
|
181
|
+
/**
|
|
182
|
+
* Performs vector similarity search over records whose `propertyName` has an embedding index.
|
|
183
|
+
*
|
|
184
|
+
* RushDB narrows candidates by `labels` and optional `where` filters first, then ranks them by
|
|
185
|
+
* similarity. Pass either `query` for managed indexes or `queryVector` for external/custom vectors.
|
|
186
|
+
*
|
|
187
|
+
* @param params - Vector search parameters including the indexed property, labels, and query input
|
|
188
|
+
*/
|
|
189
|
+
vectorSearch: <S extends Schema = any>(params: VectorSearchParams, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S>>;
|
|
181
190
|
/**
|
|
182
191
|
* Retrieves record(s) by ID
|
|
183
192
|
* @param idOrIds - Single ID or array of IDs to retrieve
|
|
@@ -475,7 +484,7 @@ export declare class RestAPI {
|
|
|
475
484
|
* and cross-label relationships with direction.
|
|
476
485
|
* Properties may include a `vectorIndexes` array when one or more embedding indexes
|
|
477
486
|
* exist for that property — a non-empty array means the property is queryable with
|
|
478
|
-
* `db.
|
|
487
|
+
* `db.records.vectorSearch()`. Each entry exposes: id, sourceType, similarityFunction, dimensions,
|
|
479
488
|
* status, and modelKey.
|
|
480
489
|
* Use property `id` fields to pass to db.properties.values() for deeper drill-down.
|
|
481
490
|
* @param params - Optional filter. `labels` scopes to specific labels only.
|
|
@@ -536,13 +545,18 @@ export declare class RestAPI {
|
|
|
536
545
|
stats: (id: string) => Promise<ApiResponse<EmbeddingIndexStats>>;
|
|
537
546
|
};
|
|
538
547
|
/**
|
|
539
|
-
* Performs
|
|
548
|
+
* Performs AI-assisted smart search from natural language.
|
|
549
|
+
*
|
|
550
|
+
* RushDB converts the prompt into a SearchQuery using the project schema, executes it,
|
|
551
|
+
* and returns matching records with the generated SearchQuery attached to the result.
|
|
540
552
|
*
|
|
541
|
-
*
|
|
542
|
-
* then ranked by similarity. You can pass either query text or queryVector.
|
|
553
|
+
* Use `db.records.vectorSearch({ ... })` for direct vector similarity over embedding indexes.
|
|
543
554
|
*
|
|
544
|
-
* @param
|
|
555
|
+
* @param prompt - Natural-language search request to convert into a SearchQuery and execute
|
|
556
|
+
* @param options - Optional smart-search context and transaction
|
|
545
557
|
*/
|
|
546
|
-
search: <S extends Schema = any>(
|
|
558
|
+
search: <S extends Schema = any>(prompt: string, options?: SmartSearchOptions<S> & {
|
|
559
|
+
transaction?: Transaction | string;
|
|
560
|
+
}) => Promise<DBRecordsArrayInstance<S>>;
|
|
547
561
|
};
|
|
548
562
|
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { RestAPI } from './api.js';
|
|
2
|
-
export { ApiResponse, CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPattern, RelationshipPatternDirection, RelationshipPatternDto, RelationshipPatternEndpoint, RelationshipPatternListResponse, RelationshipPatternMode, RelationshipPatternOrigin, RelationshipPatternStatus, SemanticSearchParams, SemanticSearchResult, UpsertEmbeddingVectorItem, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult } from './types.js';
|
|
2
|
+
export { ApiResponse, CreateEmbeddingIndexParams, DeleteRelationshipPatternOptions, EmbeddingIndex, EmbeddingIndexStats, RelationshipPattern, RelationshipPatternDirection, RelationshipPatternDto, RelationshipPatternEndpoint, RelationshipPatternListResponse, RelationshipPatternMode, RelationshipPatternOrigin, RelationshipPatternStatus, SemanticSearchParams, SemanticSearchResult, SmartSearchOptions, SmartSearchQueryResponse, UpsertEmbeddingVectorItem, UpsertEmbeddingVectorsParams, UpsertEmbeddingVectorsResult, VectorSearchParams, VectorSearchResult } from './types.js';
|
package/dist/api/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DBRecord } from '../sdk/record.js';
|
|
2
|
-
import type { Schema, Where } from '../types/index.js';
|
|
2
|
+
import type { Schema, SearchQuery, Where } from '../types/index.js';
|
|
3
3
|
export type ApiResponse<T, E = Record<string, any>> = {
|
|
4
4
|
data: T;
|
|
5
5
|
success: boolean;
|
|
@@ -68,8 +68,8 @@ export type EmbeddingIndexStats = {
|
|
|
68
68
|
totalRecords: number;
|
|
69
69
|
indexedRecords: number;
|
|
70
70
|
};
|
|
71
|
-
/** Parameters for
|
|
72
|
-
export type
|
|
71
|
+
/** Parameters for vector search over an embedding index. */
|
|
72
|
+
export type VectorSearchParams = {
|
|
73
73
|
/** Name of the indexed property to search against. */
|
|
74
74
|
propertyName: string;
|
|
75
75
|
/** Free-text query that will be embedded and compared against indexed vectors. */
|
|
@@ -92,19 +92,36 @@ export type SemanticSearchParams = {
|
|
|
92
92
|
where?: Record<string, unknown>;
|
|
93
93
|
/** Number of results to skip for pagination (default 0). */
|
|
94
94
|
skip?: number;
|
|
95
|
+
/** Max candidates to fetch from the vector index in direct vector-index mode. */
|
|
96
|
+
topK?: number;
|
|
95
97
|
/** Maximum number of results to return (default 20). */
|
|
96
98
|
limit?: number;
|
|
97
99
|
};
|
|
98
100
|
/**
|
|
99
|
-
* A record returned by db.
|
|
101
|
+
* A record returned by db.records.vectorSearch().
|
|
100
102
|
* Identical to DBRecord but with __score guaranteed present — never optional.
|
|
101
103
|
* __score is the cosine similarity between the query vector and this record's embedding (0–1,
|
|
102
104
|
* higher = more similar). It is only injected by the semantic search path; regular
|
|
103
105
|
* db.records.find() / db.records.search() results are plain DBRecord and never carry __score.
|
|
104
106
|
*/
|
|
105
|
-
export type
|
|
107
|
+
export type VectorSearchResult<S extends Schema = Schema> = DBRecord<S> & {
|
|
106
108
|
readonly __score: number;
|
|
107
109
|
};
|
|
110
|
+
/** @deprecated Use VectorSearchParams. */
|
|
111
|
+
export type SemanticSearchParams = VectorSearchParams;
|
|
112
|
+
/** @deprecated Use VectorSearchResult. */
|
|
113
|
+
export type SemanticSearchResult<S extends Schema = Schema> = VectorSearchResult<S>;
|
|
114
|
+
export type SmartSearchOptions<S extends Schema = Schema> = {
|
|
115
|
+
/**
|
|
116
|
+
* Optional current dashboard/query-builder state. The server may use it as context
|
|
117
|
+
* when converting the natural-language prompt into a SearchQuery.
|
|
118
|
+
*/
|
|
119
|
+
currentQuery?: SearchQuery<S>;
|
|
120
|
+
};
|
|
121
|
+
export type SmartSearchQueryResponse<S extends Schema = Schema> = {
|
|
122
|
+
searchQuery: SearchQuery<S>;
|
|
123
|
+
warnings: string[];
|
|
124
|
+
};
|
|
108
125
|
export type RelationshipPatternStatus = 'suggested' | 'approved' | 'ignored' | 'error';
|
|
109
126
|
export type RelationshipPatternOrigin = 'llm' | 'manual';
|
|
110
127
|
export type RelationshipPatternDirection = 'in' | 'out';
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var be=Object.create;var H=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var Pe=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var Ee=(i,e)=>{for(var t in e)H(i,t,{get:e[t],enumerable:!0})},ce=(i,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of xe(e))!Oe.call(i,r)&&r!==t&&H(i,r,{get:()=>e[r],enumerable:!(s=Ie(e,r))||s.enumerable});return i};var de=(i,e,t)=>(t=i!=null?be(Pe(i)):{},ce(e||!i||!i.__esModule?H(t,"default",{value:i,enumerable:!0}):t,i)),Ae=i=>ce(H({},"__esModule",{value:!0}),i);var He={};Ee(He,{DBRecordInstance:()=>S,DBRecordsArrayInstance:()=>I,EmptyTargetError:()=>O,HttpClient:()=>E,HttpClientResponse:()=>Q,Model:()=>ae,NonUniqueResultError:()=>$,RestAPI:()=>U,RushDB:()=>m,Transaction:()=>_,UniquenessError:()=>q,default:()=>Fe,idToDate:()=>se,idToTimestamp:()=>K,initSDK:()=>ne,mergeDefaultsWithPayload:()=>F,parseConfig:()=>te,pickUniqFieldsFromRecord:()=>N,pickUniqFieldsFromRecords:()=>ee,validateInteger:()=>re});module.exports=Ae(He);var E=class i{makeRequest(e,{headers:t,method:s,protocol:r,requestData:n,timeout:a}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(i.TIMEOUT_ERROR_CODE);return e.code=i.TIMEOUT_ERROR_CODE,e}};E.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];E.TIMEOUT_ERROR_CODE="ETIMEDOUT";var V=class{constructor(e,t){this._statusCode=e,this._headers=t}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.")}},Q=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 z=de(require("http"),1),Y=de(require("https"),1);var qe="string",_e="datetime",Be="boolean",Ce="number",pe=[qe,_e,Be,Ce];var he=z.default||z,ge=Y.default||Y,je=new he.Agent({keepAlive:!0}),Ue=new ge.Agent({keepAlive:!0}),W=class extends E{constructor(e){super(),this._agent=e}makeRequest(e,{headers:t,method:s,protocol:r,requestData:n,timeout:a}){let o=new URL(e),c=r==="http"||o.protocol==="http:",d=this._agent;return d||(d=c?je:Ue),new Promise((p,l)=>{let h=(c?he:ge).request({agent:d,ciphers:"DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5",headers:t,host:o.hostname,method:s,path:o.pathname+o.search,port:o.port});h.setTimeout(a!=null?a:8e4,()=>{h.destroy(E.makeTimeoutError())}),h.on("response",u=>{p(new J(u))}),h.on("error",u=>{l(u)}),h.once("socket",u=>{let R=n?JSON.stringify(n):"";u.connecting?u.once(c?"connect":"secureConnect",()=>{h.write(R),h.end()}):(h.write(R),h.end())})})}},J=class extends V{constructor(e){super(e.statusCode,e.headers||{}),this._res=e}getRawResponse(){return this._res}toStream(e){return this._res.once("end",()=>e()),this._res}toJSON(){return new Promise((e,t)=>{let s="";this._res.setEncoding("utf8"),this._res.on("data",r=>{s+=r}),this._res.once("end",()=>{try{e(JSON.parse(s))}catch(r){t(r)}})})}};var T=i=>typeof i=="object"&&Array.isArray(i)&&i!==null,w=i=>i!==null&&Object.prototype.toString.call(i)==="[object Object]",k=i=>w(i)&&Object.keys(i).length===0,G=i=>typeof i=="number"||typeof i=="string"||typeof i=="boolean"||i===null;function ke(i,e){let t={...i};return e.forEach(s=>{delete t[s]}),t}var v=i=>w(i)?ke(i,["__label","__id","__proptypes"]):i,C=i=>T(i)?i.map(C):w(i)?Object.fromEntries(Object.entries(i).filter(([e,t])=>t!==void 0).map(([e,t])=>[e,C(t)])):i,Z=i=>T(i)?i.every(G):G(i),L=i=>w(i)&&Object.values(i).every(Z),ve=i=>w(i)||T(i)&&!i.every(G),ue=i=>{if(T(i)||!w(i))return!0;let e=Object.values(i);return e.length===0?!0:e.some(t=>!ve(t))},A=i=>typeof i=="string",b=i=>{if(typeof i=="string"){if(i.toLowerCase()==="true")return!0;if(i.toLowerCase()==="false")return!1}return T(i)&&i.length===0||w(i)&&Object.keys(i).length===0?!1:!!i};var X=["httpClient","timeout","host","port","protocol","url","logger","options"];var q=class i extends Error{constructor(e,t){super(`Record with label "${e}" and properties ${JSON.stringify(t)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,i.prototype)}},O=class i extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,i.prototype)}},$=class i extends Error{constructor(e,t){super(`Expected a unique result but found ${e} matches for the provided SearchQuery: ${JSON.stringify(t)}. Ensure your search parameters uniquely identify a single result.`),this.name="NonUniqueResultError",Object.setPrototypeOf(this,i.prototype)}};var F=async(i,e)=>{let t=Object.entries(i).map(async([n,a])=>a.default&&typeof a.default<"u"&&typeof e[n]>"u"?{key:n,value:typeof a.default=="function"?await a.default():a.default}:{key:n,value:void 0});return{...(await Promise.all(t)).reduce((n,{key:a,value:o})=>(o!==void 0&&(n[a]=o),n),{}),...e}},N=(i,e)=>Object.entries(e).filter(([t])=>{var s;return(s=i[t])==null?void 0:s.unique}).reduce((t,[s,r])=>(s in i&&(t[s]=r),t),{}),ee=(i,e,t)=>{let s={},r=Object.entries(e).filter(([,n])=>n.unique).reduce((n,[a])=>(n[a]=!0,n),{});return i.forEach(n=>{Object.entries(n).forEach(([a,o])=>{if(a in r)if(s[a]){if(s[a].includes(o))throw new q(t,{[a]:o});s[a]=[...s[a],o]}else s[a]=[o]})}),s},te=i=>{if(!i)return{};if(!w(i))throw new Error("Config must be an object");if(Object.keys(i).filter(t=>!X.includes(t)).length>0)throw new Error(`Config object may only contain the following: ${X.join(", ")}`);return i};function re(i,e,t){if(!Number.isInteger(e)){if(t!==void 0)return t;throw new Error(`${i} must be an integer`)}return e}function K(i){let e=i.split("-"),t=e[0]+e[1].slice(0,4);return parseInt(t,16)}function se(i){return new Date(K(i))}var S=class{constructor(e={}){this.data=e}get exists(){return b(this.data.__id)&&b(this.data.__label)}get id(){if(!b(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(!b(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(!b(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 se(this.id)}catch{throw new Error("DBRecordInstance: Unable to access 'date'. The Record's `data.__id` is missing or incorrect.")}}get timestamp(){try{return K(this.id)}catch{throw new Error("DBRecordInstance: Unable to access 'timestamp'. The Record's `data.__id` is missing or incorrect.")}}async delete(e){if(!b(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return await m.getInstance().records.deleteById(this.id,e)}async update(e,t){if(!b(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return m.getInstance().records.update({label:this.label,target:this.id,data:e},t)}async set(e,t){if(!b(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return m.getInstance().records.set({label:this.label,target:this.id,data:e},t)}async attach(e,t,s){if(!b(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return m.getInstance().records.attach({source:this.id,target:e,options:t},s)}async detach(e,t,s){if(!b(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return m.getInstance().records.detach({source:this.id,target:e,options:t},s)}},I=class{constructor(e=[],t=0,s,r){this.data=e,this.total=t,this.searchQuery=s,this.warnings=r}async deleteAll(e){let t=this.data.map(r=>r.id);return t.length?await m.getInstance().records.deleteById(t,e):{success:!0}}async next(e){var o,c;if(!this.searchQuery)throw new Error("DBRecordsArrayInstance: Cannot paginate \u2014 no searchQuery was provided.");let t=(o=this.searchQuery.skip)!=null?o:0,s=(c=this.searchQuery.limit)!=null?c:100,r={...this.searchQuery,skip:t+s},a=await m.getInstance().records.find(r,void 0);return e!=null&&e.preserveData?(this.data=[...this.data,...a.data],this.total=a.total,this.searchQuery=r,this):a}exportCsv(){if(!this.data.length)return"";let e=new Set(["__id","__label","__proptypes"]),t=Object.keys(this.data[0].data).filter(n=>!e.has(n)),s=n=>{let a=n==null?"":String(n);return a.includes(",")||a.includes('"')||a.includes(`
|
|
2
2
|
`)?`"${a.replace(/"/g,'""')}"`:a},r=this.data.map(n=>t.map(a=>s(n.data[a])).join(","));return[t.join(","),...r].join(`
|
|
3
|
-
`)}async setProperties(e,t){let r=y.getInstance();for(let n=0;n<this.data.length;n+=100){let a=this.data.slice(n,n+100);await Promise.all(a.map(o=>r.records.update({target:o.id,label:o.data.__label,data:e},t)))}}};var Ue={"Content-Type":"application/json"},ge=({httpClient:i,token:e,url:t})=>async(s,{headers:r,...n})=>{var p;let a=await i.makeRequest(`${t}${s}`,{credentials:"omit",headers:Object.assign({...Ue,...r},typeof e<"u"?{Authorization:`Bearer ${e}`}:{}),...n});if(a.getStatusCode()>=200&&a.getStatusCode()<300)return await a.toJSON();let o="",c;try{let l=await a.toJSON();c=l;let h=(p=l==null?void 0:l.message)!=null?p:l==null?void 0:l.error;Array.isArray(h)?o=h.join("; "):typeof h=="string"&&(o=h)}catch{}let d=new Error(o?`${a.getStatusCode()} ${o}`:`${a.getStatusCode()}`);throw d.status=a.getStatusCode(),d.body=c,d};var q=class{constructor(e){this.id=e}async rollback(){return await y.getInstance().tx.rollback(this.id)}async commit(){return await y.getInstance().tx.commit(this.id)}};var ue="api.rushdb.com";var ye="https",me="/api/v1";var f=i=>i?{"x-transaction-id":i}:void 0,ve=i=>E(i)||i instanceof q,m=i=>ve(i)?i instanceof q?i.id:i:void 0,fe=i=>/^[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(i),x=i=>{if(E(i)&&fe(i))return i;if(i instanceof S&&i.data)return i.data.__id;if(T(i)&&"__id"in i&&fe(i.__id))return i.__id},j=i=>!(!T(i)||T(i)&&"name"in i&&!E(i.name)||T(i)&&"type"in i&&(!E(i.type)||!ce.includes(i.type))||!("value"in i)||!G(i.value)||"metadata"in i&&!E(i.metadata)||"valueSeparator"in i&&!E(i.valueSeparator)),Se=i=>{let e=ye,t=ue,s=443,r=me;if("url"in i){let a=new URL(i.url);e=a.protocol.replace(":",""),t=a.hostname,s=parseInt(a.port||(e==="http"?"80":e==="https"?"443":""))}"host"in i&&"port"in i&&"protocol"in i&&(e=i.protocol.replace(":",""),t=i.host,s=i.port),r&&!r.startsWith("/")&&(r="/"+r);let n="";return e==="http"&&s===80||e==="https"&&s===443||(n=":"+s),`${e}://${t}${n}${r}`},g=(i=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let s=0;s<i;s++){let r=Math.floor(Math.random()*e.length);t+=e[r]}return t};var U=class{constructor(e,t){this.records={attach:async({source:e,target:t,options:s},r)=>{var l,h;let n=m(r),o=`/relationships/${x(e)}`,c={headers:Object.assign({},f(n)),method:"POST",requestData:{targetIds:this._extractTargetIds(t,"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}}},d=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:d,path:o,...c});let p=await this.fetcher(o,c);return(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c,responseData:p.data}),p},detach:async({source:e,target:t,options:s},r)=>{var l,h;let n=m(r),o=`/relationships/${x(e)}`,c={headers:Object.assign({},f(n)),method:"PUT",requestData:{targetIds:this._extractTargetIds(t,"Detach"),...(s==null?void 0:s.typeOrTypes)&&{typeOrTypes:s.typeOrTypes},...(s==null?void 0:s.direction)&&{direction:s.direction}}},d=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:d,path:o,...c});let p=await this.fetcher(o,c);return(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c,responseData:p.data}),p},create:async({label:e,data:t,options:s,vectors:r},n)=>{var h,u;let a=m(n),o="/records",c={headers:Object.assign({},f(a)),method:"POST",requestData:{}},d=typeof this.logger=="function"?g():"",p=v(B(t));if(R(p)&&p.every(j))c.requestData={label:e,properties:p,options:s,...(r==null?void 0:r.length)&&{vectors:r}};else if(L(p))c.requestData={label:e,data:p,options:s,...(r==null?void 0:r.length)&&{vectors:r}};else throw T(p)?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.");(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c});let l=await this.fetcher(o,c);return(u=this.logger)==null||u.call(this,{requestId:d,path:o,...c,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)?new S(l.data):new S},createMany:async(e,t)=>{var l,h,u,w;let s=R(e.data)?e.data:[e.data];if(!s.every(D=>L(D)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");if(e.vectors&&e.vectors.length>s.length)throw new Error(`records.createMany: vectors length (${e.vectors.length}) exceeds the number of data rows (${s.length}).`);let n=(l=e.vectors)!=null&&l.length?s.map((D,C)=>{var ae;return(ae=e.vectors[C])!=null&&ae.length?{...D,$vectors:e.vectors[C]}:D}):s,a=m(t),o="/records/import/json",c={headers:Object.assign({},f(a)),method:"POST",requestData:{label:e.label,data:n,options:e.options}},d=typeof this.logger=="function"?g():"";(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c});let p=await this.fetcher(o,c);if((u=this.logger)==null||u.call(this,{requestId:d,path:o,...c,responseData:p.data}),p!=null&&p.success&&(p!=null&&p.data)){let D=R(p.data)?(w=p.data)==null?void 0:w.map(C=>new S(C)):[];return new I(D,p.total)}return new I([])},importJson:async(e,t)=>{var h,u,w;let{data:s,options:r}=e,{label:n}=e,a=s;if(!n){let D=T(s)&&!R(s)?v(s):s;if(he(D))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 o=m(t),c="/records/import/json",d={headers:Object.assign({},f(o)),method:"POST",requestData:{label:n,data:a,options:r}},p=typeof this.logger=="function"?g():"";(h=this.logger)==null||h.call(this,{requestId:p,path:c,...d});let l=await this.fetcher(c,d);if((u=this.logger)==null||u.call(this,{requestId:p,path:c,...d,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)){let D=R(l.data)?(w=l.data)==null?void 0:w.map(C=>new S(C)):[];return new I(D,l.total)}return new I([])},importCsv:async(e,t)=>{var c,d;let s=m(t),r="/records/import/csv",n={headers:Object.assign({},f(s)),method:"POST",requestData:e},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);if((d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o!=null&&o.success&&(o!=null&&o.data)){let p=R(o.data)?o.data.map(l=>new S(l)):[];return new I(p,o.total)}return new I([])},delete:async(e,t)=>{var c,d,p;if(k(e.where)&&!((c=this==null?void 0:this.options)!=null&&c.allowForceDelete))throw new P("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let s=m(t),r="/records/delete",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},deleteById:async(e,t)=>{var d,p;let s=m(t),r=R(e),n=r?"/records/delete":`/records/${e}`,a={headers:Object.assign({},f(s)),method:r?"POST":"DELETE",requestData:r?{limit:1e3,where:{$id:{$in:e}}}:void 0},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:n,...a});let c=await this.fetcher(n,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:n,...a,responseData:c.data}),c},export:async(e,t)=>{var c,d;let s=m(t),r="/records/export/csv",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},find:async(e,t)=>{var l,h;let{id:s,...r}=e,n=m(t),a=s?`/records/${s}/search`:"/records/search",o={headers:Object.assign({},f(n)),method:"POST",requestData:r!=null?r:{}},c=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:c,path:a,...o});let d=await this.fetcher(a,o);(h=this.logger)==null||h.call(this,{requestId:c,path:a,...o,responseData:d.data});let p=d.data.map(u=>new S(u));return new I(p,d.total,e)},findById:async(e,t)=>{var c,d;let s=m(t),r=R(e)?"/records":`/records/${e}`,n={headers:Object.assign({},f(s)),method:R(e)?"POST":"GET",requestData:R(e)?{ids:e}:void 0},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);if((d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),R(e)){let p=o.data.map(l=>new S(l));return new I(p,o.total)}else return new S(o.data)},findOne:async(e,t)=>{var d,p;let s=m(t),r="/records/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:{...e,limit:1,skip:0}},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);(p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data});let[c]=o.data;return new S(c)},findUniq:async(e,t)=>{var d,p;let s=m(t),r="/records/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:{...e,limit:1,skip:0}},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);if((p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data}),typeof o.total<"u"&&o.total>1)throw new M(o.total,e);let[c]=o.data;return new S(c)},set:async({target:e,label:t,data:s,options:r,vectors:n},a)=>{var w,D;let o=m(a),d=`/records/${x(e)}`,p={headers:Object.assign({},f(o)),method:"PUT",requestData:{}},l=typeof this.logger=="function"?g():"",h=v(B(s));if(R(h)&&h.every(j))p.requestData={label:t,properties:h,...(n==null?void 0:n.length)&&{vectors:n}};else if(L(h))p.requestData={label:t,data:h,options:r,...(n==null?void 0:n.length)&&{vectors:n}};else throw T(h)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(w=this.logger)==null||w.call(this,{requestId:l,path:d,...p});let u=await this.fetcher(d,p);return(D=this.logger)==null||D.call(this,{requestId:l,path:d,...p,responseData:u.data}),u!=null&&u.success&&(u!=null&&u.data)?new S(u.data):new S},update:async({target:e,label:t,data:s,options:r},n)=>{var u,w;let a=m(n),c=`/records/${x(e)}`,d={headers:Object.assign({},f(a)),method:"PATCH",requestData:{}},p=typeof this.logger=="function"?g():"",l=v(B(s));if(R(l)&&l.every(j))d.requestData={label:t,properties:l};else if(L(l))d.requestData={label:t,data:l,options:r};else throw T(l)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(u=this.logger)==null||u.call(this,{requestId:p,path:c,...d});let h=await this.fetcher(c,d);return(w=this.logger)==null||w.call(this,{requestId:p,path:c,...d,responseData:h.data}),h!=null&&h.success&&(h!=null&&h.data)?new S(h.data):new S},upsert:async({label:e,data:t,options:s,vectors:r},n)=>{var u,w,D;let a=m(n),o="/records",c={headers:Object.assign({},f(a)),method:"POST",requestData:{}},d=typeof this.logger=="function"?g():"",p=v(B(t)),l={...s,mergeBy:(u=s==null?void 0:s.mergeBy)!=null?u:[]};if(R(p)&&p.every(j))c.requestData={label:e,properties:p,options:l,...(r==null?void 0:r.length)&&{vectors:r}};else if(L(p))c.requestData={label:e,data:p,options:l,...(r==null?void 0:r.length)&&{vectors:r}};else throw T(p)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(w=this.logger)==null||w.call(this,{requestId:d,path:o,...c});let h=await this.fetcher(o,c);return(D=this.logger)==null||D.call(this,{requestId:d,path:o,...c,responseData:h.data}),h!=null&&h.success&&(h!=null&&h.data)?new S(h.data):new S}};this.relationships={patterns:{list:async()=>{var n,a;let e="/relationships/patterns",t={method:"GET",headers:{}},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r},analyze:async()=>{var n,a;let e="/relationships/patterns/analyze",t={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r},approve:async e=>{var a,o;let t=`/relationships/patterns/${encodeURIComponent(e)}/approve`,s={method:"POST",headers:{},requestData:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n},ignore:async e=>{var a,o;let t=`/relationships/patterns/${encodeURIComponent(e)}/ignore`,s={method:"POST",headers:{},requestData:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n},delete:async(e,t)=>{var c,d;let s=t!=null&&t.deleteExisting?"?deleteExisting=true":"",r=`/relationships/patterns/${encodeURIComponent(e)}${s}`,n={method:"DELETE",headers:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o}},createMany:async(e,t)=>{var c,d;let s=m(t),r="/relationships/create-many",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},deleteMany:async(e,t)=>{var c,d;let s=m(t),r="/relationships/delete-many",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},find:async(e={},t)=>{var c,d;let s=m(t),r="/relationships/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o}};this.properties={delete:async(e,t)=>{var c,d;let s=m(t),r=`/properties/${e}`,n={headers:Object.assign({},f(s)),method:"DELETE"},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},find:async(e,t)=>{var c,d;let s=m(t),r="/properties/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},findById:async(e,t)=>{var c,d;let s=m(t),r=`/properties/${e}`,n={headers:Object.assign({},f(s)),method:"GET"},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},values:async(e,t,s)=>{var d,p;let r=m(s),n=`/properties/${e}/values`,a={headers:Object.assign({},f(r)),method:"POST",requestData:t!=null?t:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:n,...a});let c=await this.fetcher(n,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:n,...a,responseData:c.data}),c}};this.labels={find:async(e,t)=>{var c,d;let s=m(t),r="/labels/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o}};this.tx={begin:async e=>{var a,o;let t="/tx",s={method:"POST",requestData:T(e)&&"ttl"in e?e:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),new q(n.data.id)},commit:async e=>{var o,c;let s=`/tx/${m(e)}/commit`,r={method:"POST",requestData:{}},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),a},get:async e=>{var o,c;let s=`/tx/${m(e)}`,r={method:"GET"},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),new q(a.data.id)},rollback:async e=>{var o,c;let s=`/tx/${m(e)}/rollback`,r={method:"POST",requestData:{}},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),a}};this.settings={get:async()=>{var n,a;let e="/sdk/settings",t={method:"GET"},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r}};this.query={raw:async({query:e,params:t},s)=>{var d,p;let r=m(s),n="/query/raw",a={headers:Object.assign({},f(r)),method:"POST",requestData:{query:e,params:t}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:n,...a});let c=await this.fetcher(n,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:n,...a,responseData:c.data}),c}};this.ai={getSchema:async(e,t)=>{var c,d;let s=m(t),r="/ai/schema",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},getSchemaMarkdown:async(e,t)=>{var c,d;let s=m(t),r="/ai/schema/md",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},indexes:{find:async()=>{var n,a;let e="/ai/indexes",t={method:"GET",headers:{}},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r},create:async e=>{var d,p;let t="/ai/indexes",{external:s,...r}=e,n=s===!0?{...r,sourceType:"external"}:r,a={method:"POST",headers:{},requestData:n},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:t,...a});let c=await this.fetcher(t,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:t,...a,responseData:c.data}),c},upsertVectors:async(e,t)=>{var o,c;let s=`/ai/indexes/${e}/vectors/upsert`,r={method:"POST",headers:{},requestData:t},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),a},delete:async e=>{var a,o;let t=`/ai/indexes/${e}`,s={method:"DELETE",headers:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n},stats:async e=>{var a,o;let t=`/ai/indexes/${e}/stats`,s={method:"GET",headers:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n}},search:async e=>{var o,c,d,p;let t="/ai/search",s={method:"POST",headers:{},requestData:e},r=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);(c=this.logger)==null||c.call(this,{requestId:r,path:t,...s,responseData:n.data});let a=((d=n.data)!=null?d:[]).map(l=>new S(l));return new I(a,(p=n.total)!=null?p:0)}};if(this.fetcher=null,t!=null&&t.httpClient){let s=Se(t);this.fetcher=ge({httpClient:t.httpClient,token:e,url:s})}t!=null&&t.options&&(this.options=t==null?void 0:t.options),t!=null&&t.logger&&(this.logger=t==null?void 0:t.logger)}_extractTargetIds(e,t){var s;if(e instanceof S){let r=x(e);if(!r)throw new P(`${t} error: Target id is empty`);return[r]}if(R(e)&&e.every(r=>r instanceof S)){let r=e.map(x).filter(b);if(!r.length)throw new P(`${t} error: Target ids are empty`);return r}if(e instanceof I){let r=(s=e.data)==null?void 0:s.map(x).filter(b);if(!(r!=null&&r.length))throw new P(`${t} error: Target ids are empty`);return r}if(T(e)&&"__id"in e)return[e.__id];if(R(e)&&e.every(r=>T(r)&&"__id"in r)){let r=e.map(x).filter(b);if(!r.length)throw new P(`${t} error: Target ids are empty`);return r}return R(e)?e:E(e)?[e]:[]}};var Re,_=class _ extends U{constructor(e,t){var n,a;let s=e!=null?e:typeof process<"u"?(n=process.env)==null?void 0:n.RUSHDB_API_KEY:void 0,r=ee(t);super(s,{...r,httpClient:(a=r.httpClient)!=null?a:Re}),_.instance=this,this.initializeSync(s,r)}initializeSync(e,t){_.state={initialized:!0,debug:!1,timeout:te("timeout",t==null?void 0:t.timeout,8e4),token:e}}static getInstance(){if(_.instance)return _.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static isInitialized(){return b(_.instance)}toDBRecordInstance(e){return new S(e)}};_.instance=null,_.state={initialized:!1,debug:!1,timeout:8e4};var y=_,se=i=>{Re=i};var ne=class{constructor(e,t,s){this.label=e,this.schema=t,this.config=s!=null?s:{}}getLabel(){return this.label}async toDBRecordInstance(e){try{return y.getInstance().toDBRecordInstance(e)}catch{throw new Error("No RushDB instance was provided during model initialization.")}}async find(e,t){let s=e!=null?e:{};return y.getInstance().records.find({...s,labels:[this.label]},t)}async findOne(e,t){let s=e!=null?e:{};return y.getInstance().records.findOne({...s,labels:[this.label]},t)}async findById(e,t){return this.findOne({where:{$id:e}},t)}async findUniq(e,t){let s=e!=null?e:{};return y.getInstance().records.findUniq({...s,labels:[this.label]},t)}async create(e,t,s){var c,d;let r=await $(this.schema,e),n=W(this.schema,r),a=b(n),o=y.getInstance();if(a){let p=t!=null?t:await o.tx.begin(),l=await this.find({where:n},p),h=typeof t<"u";if(!((c=l==null?void 0:l.data)!=null&&c.length)){let w=await o.records.create({label:this.label,data:r},p);return h||await p.commit(),w}else switch((d=s==null?void 0:s.onConflict)!=null?d:"throw"){case"upsert":{let D=l.data[0],C=await o.records.set({target:D.id,label:this.label,data:r},p);return h||await p.commit(),C}case"skip":return h||await p.commit(),null;default:throw h||await p.commit(),new A(this.label,n)}}return await o.records.create({label:this.label,data:r},t)}async attach({source:e,target:t,options:s},r){return await y.getInstance().records.attach({source:e,target:t,options:s},r)}async detach({source:e,target:t,options:s},r){return await y.getInstance().records.detach({source:e,target:t,options:s},r)}async validateTargetLabel(e,t){let s=x(e);if(!s)return;let n=await y.getInstance().records.findById(s,t);if(!n)throw new Error(`Record with id "${s}" not found.`);if(n.data.__label!==this.label)throw new TypeError(`Target record label "${n.data.__label}" does not match model label "${this.label}".`)}async handleSetOrUpdate(e,t,s,r){var c,d;if(this.config.validateTargetLabel&&await this.validateTargetLabel(e,r),R(t)&&t.every(j))return await y.getInstance().records[s]({label:this.label,target:e,data:t},r);let n=y.getInstance(),a=await $(this.schema,t),o=W(this.schema,a);if(!k(o)){let p=r!=null?r:await n.tx.begin(),l=await this.find({where:o},p),h=typeof r<"u";if(!((c=l==null?void 0:l.data)!=null&&c.length)||l.data.length===1&&((d=l.data[0])==null?void 0:d.id)===x(e)){let w=await n.records[s]({target:e,label:this.label,data:a},p);return h||await p.commit(),w}else throw h||await p.commit(),new A(this.label,o)}return await n.records[s]({label:this.label,target:e,data:a},r)}async set(e,t,s){return await this.handleSetOrUpdate(e,t,"set",s)}async update(e,t,s){return await this.handleSetOrUpdate(e,t,"update",s)}async createMany(e,t){var a;let s=y.getInstance(),r=typeof t<"u",n=t!=null?t:await s.tx.begin();try{let o=await Promise.all(e.map(async p=>await $(this.schema,p))),c=X(o,this.schema,this.label);if(!k(c)){let p=Object.entries(c).map(([h,u])=>({[h]:{$in:u}})),l=await this.find({where:{$or:p}},n);if((a=l==null?void 0:l.data)!=null&&a.length)throw new A(this.label,Object.keys(c))}let d=await s.records.createMany({label:this.label,data:o},n);return r||await n.commit(),d}catch(o){throw r||await n.rollback(),o}}async delete(e,t){if(k(e.where))throw new P(`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 await y.getInstance().records.delete({...e,labels:[this.label]},t)}async deleteById(e,t){return await y.getInstance().records.deleteById(e,t)}};se(new V);var Le=y;0&&(module.exports={DBRecordInstance,DBRecordsArrayInstance,EmptyTargetError,HttpClient,HttpClientResponse,Model,NonUniqueResultError,RestAPI,RushDB,Transaction,UniquenessError,idToDate,idToTimestamp,initSDK,mergeDefaultsWithPayload,parseConfig,pickUniqFieldsFromRecord,pickUniqFieldsFromRecords,validateInteger});
|
|
3
|
+
`)}async setProperties(e,t){let r=m.getInstance();for(let n=0;n<this.data.length;n+=100){let a=this.data.slice(n,n+100);await Promise.all(a.map(o=>r.records.update({target:o.id,label:o.data.__label,data:e},t)))}}};var Le={"Content-Type":"application/json"},ye=({httpClient:i,token:e,url:t})=>async(s,{headers:r,...n})=>{var p;let a=await i.makeRequest(`${t}${s}`,{credentials:"omit",headers:Object.assign({...Le,...r},typeof e<"u"?{Authorization:`Bearer ${e}`}:{}),...n});if(a.getStatusCode()>=200&&a.getStatusCode()<300)return await a.toJSON();let o="",c;try{let l=await a.toJSON();c=l;let h=(p=l==null?void 0:l.message)!=null?p:l==null?void 0:l.error;Array.isArray(h)?o=h.join("; "):typeof h=="string"&&(o=h)}catch{}let d=new Error(o?`${a.getStatusCode()} ${o}`:`${a.getStatusCode()}`);throw d.status=a.getStatusCode(),d.body=c,d};var _=class{constructor(e){this.id=e}async rollback(){return await m.getInstance().tx.rollback(this.id)}async commit(){return await m.getInstance().tx.commit(this.id)}};var me="api.rushdb.com";var fe="https",Se="/api/v1";var f=i=>i?{"x-transaction-id":i}:void 0,$e=i=>A(i)||i instanceof _,y=i=>$e(i)?i instanceof _?i.id:i:void 0,Re=i=>/^[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(i),x=i=>{if(A(i)&&Re(i))return i;if(i instanceof S&&i.data)return i.data.__id;if(w(i)&&"__id"in i&&Re(i.__id))return i.__id},j=i=>!(!w(i)||w(i)&&"name"in i&&!A(i.name)||w(i)&&"type"in i&&(!A(i.type)||!pe.includes(i.type))||!("value"in i)||!Z(i.value)||"metadata"in i&&!A(i.metadata)||"valueSeparator"in i&&!A(i.valueSeparator)),Te=i=>{let e=fe,t=me,s=443,r=Se;if("url"in i){let a=new URL(i.url);e=a.protocol.replace(":",""),t=a.hostname,s=parseInt(a.port||(e==="http"?"80":e==="https"?"443":""))}"host"in i&&"port"in i&&"protocol"in i&&(e=i.protocol.replace(":",""),t=i.host,s=i.port),r&&!r.startsWith("/")&&(r="/"+r);let n="";return e==="http"&&s===80||e==="https"&&s===443||(n=":"+s),`${e}://${t}${n}${r}`},g=(i=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let s=0;s<i;s++){let r=Math.floor(Math.random()*e.length);t+=e[r]}return t};var U=class{constructor(e,t){this.records={attach:async({source:e,target:t,options:s},r)=>{var l,h;let n=y(r),o=`/relationships/${x(e)}`,c={headers:Object.assign({},f(n)),method:"POST",requestData:{targetIds:this._extractTargetIds(t,"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}}},d=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:d,path:o,...c});let p=await this.fetcher(o,c);return(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c,responseData:p.data}),p},detach:async({source:e,target:t,options:s},r)=>{var l,h;let n=y(r),o=`/relationships/${x(e)}`,c={headers:Object.assign({},f(n)),method:"PUT",requestData:{targetIds:this._extractTargetIds(t,"Detach"),...(s==null?void 0:s.typeOrTypes)&&{typeOrTypes:s.typeOrTypes},...(s==null?void 0:s.direction)&&{direction:s.direction}}},d=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:d,path:o,...c});let p=await this.fetcher(o,c);return(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c,responseData:p.data}),p},create:async({label:e,data:t,options:s,vectors:r},n)=>{var h,u;let a=y(n),o="/records",c={headers:Object.assign({},f(a)),method:"POST",requestData:{}},d=typeof this.logger=="function"?g():"",p=v(C(t));if(T(p)&&p.every(j))c.requestData={label:e,properties:p,options:s,...(r==null?void 0:r.length)&&{vectors:r}};else if(L(p))c.requestData={label:e,data:p,options:s,...(r==null?void 0:r.length)&&{vectors:r}};else throw w(p)?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.");(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c});let l=await this.fetcher(o,c);return(u=this.logger)==null||u.call(this,{requestId:d,path:o,...c,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)?new S(l.data):new S},createMany:async(e,t)=>{var l,h,u,R;let s=T(e.data)?e.data:[e.data];if(!s.every(D=>L(D)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");if(e.vectors&&e.vectors.length>s.length)throw new Error(`records.createMany: vectors length (${e.vectors.length}) exceeds the number of data rows (${s.length}).`);let n=(l=e.vectors)!=null&&l.length?s.map((D,P)=>{var M;return(M=e.vectors[P])!=null&&M.length?{...D,$vectors:e.vectors[P]}:D}):s,a=y(t),o="/records/import/json",c={headers:Object.assign({},f(a)),method:"POST",requestData:{label:e.label,data:n,options:e.options}},d=typeof this.logger=="function"?g():"";(h=this.logger)==null||h.call(this,{requestId:d,path:o,...c});let p=await this.fetcher(o,c);if((u=this.logger)==null||u.call(this,{requestId:d,path:o,...c,responseData:p.data}),p!=null&&p.success&&(p!=null&&p.data)){let D=T(p.data)?(R=p.data)==null?void 0:R.map(P=>new S(P)):[];return new I(D,p.total)}return new I([])},importJson:async(e,t)=>{var h,u,R;let{data:s,options:r}=e,{label:n}=e,a=s;if(!n){let D=w(s)&&!T(s)?v(s):s;if(ue(D))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 o=y(t),c="/records/import/json",d={headers:Object.assign({},f(o)),method:"POST",requestData:{label:n,data:a,options:r}},p=typeof this.logger=="function"?g():"";(h=this.logger)==null||h.call(this,{requestId:p,path:c,...d});let l=await this.fetcher(c,d);if((u=this.logger)==null||u.call(this,{requestId:p,path:c,...d,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)){let D=T(l.data)?(R=l.data)==null?void 0:R.map(P=>new S(P)):[];return new I(D,l.total)}return new I([])},importCsv:async(e,t)=>{var c,d;let s=y(t),r="/records/import/csv",n={headers:Object.assign({},f(s)),method:"POST",requestData:e},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);if((d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o!=null&&o.success&&(o!=null&&o.data)){let p=T(o.data)?o.data.map(l=>new S(l)):[];return new I(p,o.total)}return new I([])},delete:async(e,t)=>{var c,d,p;if(k(e.where)&&!((c=this==null?void 0:this.options)!=null&&c.allowForceDelete))throw new O("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let s=y(t),r="/records/delete",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},deleteById:async(e,t)=>{var d,p;let s=y(t),r=T(e),n=r?"/records/delete":`/records/${e}`,a={headers:Object.assign({},f(s)),method:r?"POST":"DELETE",requestData:r?{limit:1e3,where:{$id:{$in:e}}}:void 0},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:n,...a});let c=await this.fetcher(n,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:n,...a,responseData:c.data}),c},export:async(e,t)=>{var c,d;let s=y(t),r="/records/export/csv",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},find:async(e,t)=>{var l,h;let{id:s,...r}=e,n=y(t),a=s?`/records/${s}/search`:"/records/search",o={headers:Object.assign({},f(n)),method:"POST",requestData:r!=null?r:{}},c=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:c,path:a,...o});let d=await this.fetcher(a,o);(h=this.logger)==null||h.call(this,{requestId:c,path:a,...o,responseData:d.data});let p=d.data.map(u=>new S(u));return new I(p,d.total,e)},vectorSearch:async(e,t)=>{var d,p,l,h;let s=y(t),r="/ai/search",n={method:"POST",headers:Object.assign({},f(s)),requestData:e},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);(p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data});let c=((l=o.data)!=null?l:[]).map(u=>new S(u));return new I(c,(h=o.total)!=null?h:0)},findById:async(e,t)=>{var c,d;let s=y(t),r=T(e)?"/records":`/records/${e}`,n={headers:Object.assign({},f(s)),method:T(e)?"POST":"GET",requestData:T(e)?{ids:e}:void 0},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);if((d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),T(e)){let p=o.data.map(l=>new S(l));return new I(p,o.total)}else return new S(o.data)},findOne:async(e,t)=>{var d,p;let s=y(t),r="/records/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:{...e,limit:1,skip:0}},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);(p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data});let[c]=o.data;return new S(c)},findUniq:async(e,t)=>{var d,p;let s=y(t),r="/records/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:{...e,limit:1,skip:0}},a=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);if((p=this.logger)==null||p.call(this,{requestId:a,path:r,...n,responseData:o.data}),typeof o.total<"u"&&o.total>1)throw new $(o.total,e);let[c]=o.data;return new S(c)},set:async({target:e,label:t,data:s,options:r,vectors:n},a)=>{var R,D;let o=y(a),d=`/records/${x(e)}`,p={headers:Object.assign({},f(o)),method:"PUT",requestData:{}},l=typeof this.logger=="function"?g():"",h=v(C(s));if(T(h)&&h.every(j))p.requestData={label:t,properties:h,...(n==null?void 0:n.length)&&{vectors:n}};else if(L(h))p.requestData={label:t,data:h,options:r,...(n==null?void 0:n.length)&&{vectors:n}};else throw w(h)?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,{requestId:l,path:d,...p});let u=await this.fetcher(d,p);return(D=this.logger)==null||D.call(this,{requestId:l,path:d,...p,responseData:u.data}),u!=null&&u.success&&(u!=null&&u.data)?new S(u.data):new S},update:async({target:e,label:t,data:s,options:r},n)=>{var u,R;let a=y(n),c=`/records/${x(e)}`,d={headers:Object.assign({},f(a)),method:"PATCH",requestData:{}},p=typeof this.logger=="function"?g():"",l=v(C(s));if(T(l)&&l.every(j))d.requestData={label:t,properties:l};else if(L(l))d.requestData={label:t,data:l,options:r};else throw w(l)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(u=this.logger)==null||u.call(this,{requestId:p,path:c,...d});let h=await this.fetcher(c,d);return(R=this.logger)==null||R.call(this,{requestId:p,path:c,...d,responseData:h.data}),h!=null&&h.success&&(h!=null&&h.data)?new S(h.data):new S},upsert:async({label:e,data:t,options:s,vectors:r},n)=>{var u,R,D;let a=y(n),o="/records",c={headers:Object.assign({},f(a)),method:"POST",requestData:{}},d=typeof this.logger=="function"?g():"",p=v(C(t)),l={...s,mergeBy:(u=s==null?void 0:s.mergeBy)!=null?u:[]};if(T(p)&&p.every(j))c.requestData={label:e,properties:p,options:l,...(r==null?void 0:r.length)&&{vectors:r}};else if(L(p))c.requestData={label:e,data:p,options:l,...(r==null?void 0:r.length)&&{vectors:r}};else throw w(p)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(R=this.logger)==null||R.call(this,{requestId:d,path:o,...c});let h=await this.fetcher(o,c);return(D=this.logger)==null||D.call(this,{requestId:d,path:o,...c,responseData:h.data}),h!=null&&h.success&&(h!=null&&h.data)?new S(h.data):new S}};this.relationships={patterns:{list:async()=>{var n,a;let e="/relationships/patterns",t={method:"GET",headers:{}},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r},analyze:async()=>{var n,a;let e="/relationships/patterns/analyze",t={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r},approve:async e=>{var a,o;let t=`/relationships/patterns/${encodeURIComponent(e)}/approve`,s={method:"POST",headers:{},requestData:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n},ignore:async e=>{var a,o;let t=`/relationships/patterns/${encodeURIComponent(e)}/ignore`,s={method:"POST",headers:{},requestData:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n},delete:async(e,t)=>{var c,d;let s=t!=null&&t.deleteExisting?"?deleteExisting=true":"",r=`/relationships/patterns/${encodeURIComponent(e)}${s}`,n={method:"DELETE",headers:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o}},createMany:async(e,t)=>{var c,d;let s=y(t),r="/relationships/create-many",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},deleteMany:async(e,t)=>{var c,d;let s=y(t),r="/relationships/delete-many",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},find:async(e={},t)=>{var c,d;let s=y(t),r="/relationships/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o}};this.properties={delete:async(e,t)=>{var c,d;let s=y(t),r=`/properties/${e}`,n={headers:Object.assign({},f(s)),method:"DELETE"},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},find:async(e,t)=>{var c,d;let s=y(t),r="/properties/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},findById:async(e,t)=>{var c,d;let s=y(t),r=`/properties/${e}`,n={headers:Object.assign({},f(s)),method:"GET"},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},values:async(e,t,s)=>{var d,p;let r=y(s),n=`/properties/${e}/values`,a={headers:Object.assign({},f(r)),method:"POST",requestData:t!=null?t:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:n,...a});let c=await this.fetcher(n,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:n,...a,responseData:c.data}),c}};this.labels={find:async(e,t)=>{var c,d;let s=y(t),r="/labels/search",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o}};this.tx={begin:async e=>{var a,o;let t="/tx",s={method:"POST",requestData:w(e)&&"ttl"in e?e:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),new _(n.data.id)},commit:async e=>{var o,c;let s=`/tx/${y(e)}/commit`,r={method:"POST",requestData:{}},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),a},get:async e=>{var o,c;let s=`/tx/${y(e)}`,r={method:"GET"},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),new _(a.data.id)},rollback:async e=>{var o,c;let s=`/tx/${y(e)}/rollback`,r={method:"POST",requestData:{}},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),a}};this.settings={get:async()=>{var n,a;let e="/sdk/settings",t={method:"GET"},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r}};this.query={raw:async({query:e,params:t},s)=>{var d,p;let r=y(s),n="/query/raw",a={headers:Object.assign({},f(r)),method:"POST",requestData:{query:e,params:t}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:n,...a});let c=await this.fetcher(n,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:n,...a,responseData:c.data}),c}};this.ai={getSchema:async(e,t)=>{var c,d;let s=y(t),r="/ai/schema",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},getSchemaMarkdown:async(e,t)=>{var c,d;let s=y(t),r="/ai/schema/md",n={headers:Object.assign({},f(s)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...n,responseData:o.data}),o},indexes:{find:async()=>{var n,a;let e="/ai/indexes",t={method:"GET",headers:{}},s=typeof this.logger=="function"?g():"";(n=this.logger)==null||n.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(a=this.logger)==null||a.call(this,{requestId:s,path:e,...t,responseData:r.data}),r},create:async e=>{var d,p;let t="/ai/indexes",{external:s,...r}=e,n=s===!0?{...r,sourceType:"external"}:r,a={method:"POST",headers:{},requestData:n},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:t,...a});let c=await this.fetcher(t,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:t,...a,responseData:c.data}),c},upsertVectors:async(e,t)=>{var o,c;let s=`/ai/indexes/${e}/vectors/upsert`,r={method:"POST",headers:{},requestData:t},n=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:n,path:s,...r});let a=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:n,path:s,...r,responseData:a.data}),a},delete:async e=>{var a,o;let t=`/ai/indexes/${e}`,s={method:"DELETE",headers:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n},stats:async e=>{var a,o;let t=`/ai/indexes/${e}/stats`,s={method:"GET",headers:{}},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s});let n=await this.fetcher(t,s);return(o=this.logger)==null||o.call(this,{requestId:r,path:t,...s,responseData:n.data}),n}},search:async(e,t)=>{var R,D,P,M,oe,ie;let s=y(t==null?void 0:t.transaction),r="/ai/search-query",n={method:"POST",headers:Object.assign({},f(s)),requestData:{prompt:e,currentQuery:t==null?void 0:t.currentQuery}},a=typeof this.logger=="function"?g():"";(R=this.logger)==null||R.call(this,{requestId:a,path:r,...n});let o=await this.fetcher(r,n);(D=this.logger)==null||D.call(this,{requestId:a,path:r,...n,responseData:o.data});let c=o.data.searchQuery,d="/records/search",p={method:"POST",headers:Object.assign({},f(s)),requestData:c!=null?c:{}},l=typeof this.logger=="function"?g():"";(P=this.logger)==null||P.call(this,{requestId:l,path:d,...p});let h=await this.fetcher(d,p);(M=this.logger)==null||M.call(this,{requestId:l,path:d,...p,responseData:h.data});let u=((oe=h.data)!=null?oe:[]).map(De=>new S(De));return new I(u,(ie=h.total)!=null?ie:0,c,o.data.warnings)}};if(this.fetcher=null,t!=null&&t.httpClient){let s=Te(t);this.fetcher=ye({httpClient:t.httpClient,token:e,url:s})}t!=null&&t.options&&(this.options=t==null?void 0:t.options),t!=null&&t.logger&&(this.logger=t==null?void 0:t.logger)}_extractTargetIds(e,t){var s;if(e instanceof S){let r=x(e);if(!r)throw new O(`${t} error: Target id is empty`);return[r]}if(T(e)&&e.every(r=>r instanceof S)){let r=e.map(x).filter(b);if(!r.length)throw new O(`${t} error: Target ids are empty`);return r}if(e instanceof I){let r=(s=e.data)==null?void 0:s.map(x).filter(b);if(!(r!=null&&r.length))throw new O(`${t} error: Target ids are empty`);return r}if(w(e)&&"__id"in e)return[e.__id];if(T(e)&&e.every(r=>w(r)&&"__id"in r)){let r=e.map(x).filter(b);if(!r.length)throw new O(`${t} error: Target ids are empty`);return r}return T(e)?e:A(e)?[e]:[]}};var we,B=class B extends U{constructor(e,t){var n,a;let s=e!=null?e:typeof process<"u"?(n=process.env)==null?void 0:n.RUSHDB_API_KEY:void 0,r=te(t);super(s,{...r,httpClient:(a=r.httpClient)!=null?a:we}),B.instance=this,this.initializeSync(s,r)}initializeSync(e,t){B.state={initialized:!0,debug:!1,timeout:re("timeout",t==null?void 0:t.timeout,8e4),token:e}}static getInstance(){if(B.instance)return B.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static isInitialized(){return b(B.instance)}toDBRecordInstance(e){return new S(e)}};B.instance=null,B.state={initialized:!1,debug:!1,timeout:8e4};var m=B,ne=i=>{we=i};var ae=class{constructor(e,t,s){this.label=e,this.schema=t,this.config=s!=null?s:{}}getLabel(){return this.label}async toDBRecordInstance(e){try{return m.getInstance().toDBRecordInstance(e)}catch{throw new Error("No RushDB instance was provided during model initialization.")}}async find(e,t){let s=e!=null?e:{};return m.getInstance().records.find({...s,labels:[this.label]},t)}async findOne(e,t){let s=e!=null?e:{};return m.getInstance().records.findOne({...s,labels:[this.label]},t)}async findById(e,t){return this.findOne({where:{$id:e}},t)}async findUniq(e,t){let s=e!=null?e:{};return m.getInstance().records.findUniq({...s,labels:[this.label]},t)}async create(e,t,s){var c,d;let r=await F(this.schema,e),n=N(this.schema,r),a=b(n),o=m.getInstance();if(a){let p=t!=null?t:await o.tx.begin(),l=await this.find({where:n},p),h=typeof t<"u";if(!((c=l==null?void 0:l.data)!=null&&c.length)){let R=await o.records.create({label:this.label,data:r},p);return h||await p.commit(),R}else switch((d=s==null?void 0:s.onConflict)!=null?d:"throw"){case"upsert":{let D=l.data[0],P=await o.records.set({target:D.id,label:this.label,data:r},p);return h||await p.commit(),P}case"skip":return h||await p.commit(),null;default:throw h||await p.commit(),new q(this.label,n)}}return await o.records.create({label:this.label,data:r},t)}async attach({source:e,target:t,options:s},r){return await m.getInstance().records.attach({source:e,target:t,options:s},r)}async detach({source:e,target:t,options:s},r){return await m.getInstance().records.detach({source:e,target:t,options:s},r)}async validateTargetLabel(e,t){let s=x(e);if(!s)return;let n=await m.getInstance().records.findById(s,t);if(!n)throw new Error(`Record with id "${s}" not found.`);if(n.data.__label!==this.label)throw new TypeError(`Target record label "${n.data.__label}" does not match model label "${this.label}".`)}async handleSetOrUpdate(e,t,s,r){var c,d;if(this.config.validateTargetLabel&&await this.validateTargetLabel(e,r),T(t)&&t.every(j))return await m.getInstance().records[s]({label:this.label,target:e,data:t},r);let n=m.getInstance(),a=await F(this.schema,t),o=N(this.schema,a);if(!k(o)){let p=r!=null?r:await n.tx.begin(),l=await this.find({where:o},p),h=typeof r<"u";if(!((c=l==null?void 0:l.data)!=null&&c.length)||l.data.length===1&&((d=l.data[0])==null?void 0:d.id)===x(e)){let R=await n.records[s]({target:e,label:this.label,data:a},p);return h||await p.commit(),R}else throw h||await p.commit(),new q(this.label,o)}return await n.records[s]({label:this.label,target:e,data:a},r)}async set(e,t,s){return await this.handleSetOrUpdate(e,t,"set",s)}async update(e,t,s){return await this.handleSetOrUpdate(e,t,"update",s)}async createMany(e,t){var a;let s=m.getInstance(),r=typeof t<"u",n=t!=null?t:await s.tx.begin();try{let o=await Promise.all(e.map(async p=>await F(this.schema,p))),c=ee(o,this.schema,this.label);if(!k(c)){let p=Object.entries(c).map(([h,u])=>({[h]:{$in:u}})),l=await this.find({where:{$or:p}},n);if((a=l==null?void 0:l.data)!=null&&a.length)throw new q(this.label,Object.keys(c))}let d=await s.records.createMany({label:this.label,data:o},n);return r||await n.commit(),d}catch(o){throw r||await n.rollback(),o}}async delete(e,t){if(k(e.where))throw new O(`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 await m.getInstance().records.delete({...e,labels:[this.label]},t)}async deleteById(e,t){return await m.getInstance().records.deleteById(e,t)}};ne(new W);var Fe=m;0&&(module.exports={DBRecordInstance,DBRecordsArrayInstance,EmptyTargetError,HttpClient,HttpClientResponse,Model,NonUniqueResultError,RestAPI,RushDB,Transaction,UniquenessError,idToDate,idToTimestamp,initSDK,mergeDefaultsWithPayload,parseConfig,pickUniqFieldsFromRecord,pickUniqFieldsFromRecords,validateInteger});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Ie=Object.defineProperty,Pe=Object.defineProperties;var xe=Object.getOwnPropertyDescriptors;var Q=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,oe=Object.prototype.propertyIsEnumerable;var ne=(o,e,t)=>e in o?Ie(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,c=(o,e)=>{for(var t in e||(e={}))ae.call(e,t)&&ne(o,t,e[t]);if(Q)for(var t of Q(e))oe.call(e,t)&&ne(o,t,e[t]);return o},u=(o,e)=>Pe(o,xe(e));var V=(o,e)=>{var t={};for(var r in o)ae.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&Q)for(var r of Q(o))e.indexOf(r)<0&&oe.call(o,r)&&(t[r]=o[r]);return t};var h=(o,e,t)=>new Promise((r,s)=>{var n=d=>{try{i(t.next(d))}catch(p){s(p)}},a=d=>{try{i(t.throw(d))}catch(p){s(p)}},i=d=>d.done?r(d.value):Promise.resolve(d.value).then(n,a);i((t=t.apply(o,e)).next())});var Oe="string",Ee="datetime",Ae="boolean",qe="number",ie=[Oe,Ee,Ae,qe];var C=class o{makeRequest(e,{headers:t,method:r,protocol:s,requestData:n,timeout:a}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(o.TIMEOUT_ERROR_CODE);return e.code=o.TIMEOUT_ERROR_CODE,e}};C.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];C.TIMEOUT_ERROR_CODE="ETIMEDOUT";var W=class{constructor(e,t){this._statusCode=e,this._headers=t}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.")}},Y=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 N=class o extends C{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=o.makeFetchWithAbortTimeout(e):this._fetchFn=o.makeFetchWithRaceTimeout(e)}static makeFetchWithRaceTimeout(e){return(t,r,s)=>{let n,a=new Promise((d,p)=>{n=setTimeout(()=>{n=null,p(C.makeTimeoutError())},s)}),i=e(t,r);return Promise.race([i,a]).finally(()=>{n&&clearTimeout(n)})}}static makeFetchWithAbortTimeout(e){return(t,r,s)=>h(this,null,function*(){let n=new AbortController,a=setTimeout(()=>{a=null,n.abort(C.makeTimeoutError())},s);try{return yield e(t,u(c({},r),{signal:n.signal}))}catch(i){throw i.name==="AbortError"?C.makeTimeoutError():i}finally{a&&clearTimeout(a)}})}makeRequest(i,d){return h(this,arguments,function*(e,{headers:t,method:r,protocol:s,requestData:n,timeout:a}){let p=r=="POST"||r=="PUT"||r=="PATCH",l=JSON.stringify(n)||(p?"":void 0),g=yield this._fetchFn(e,{body:l,headers:t,method:r},a!=null?a:8e4);return new z(g)})}},z=class o extends W{constructor(e){super(e.status,o._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 t={};for(let r of e){if(!Array.isArray(r)||r.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.");t[r[0]]=r[1]}return t}};var I=o=>typeof o=="object"&&Array.isArray(o)&&o!==null,P=o=>o!==null&&Object.prototype.toString.call(o)==="[object Object]",H=o=>P(o)&&Object.keys(o).length===0,G=o=>typeof o=="number"||typeof o=="string"||typeof o=="boolean"||o===null;function Ce(o,e){let t=c({},o);return e.forEach(r=>{delete t[r]}),t}var M=o=>P(o)?Ce(o,["__label","__id","__proptypes"]):o,v=o=>I(o)?o.map(v):P(o)?Object.fromEntries(Object.entries(o).filter(([e,t])=>t!==void 0).map(([e,t])=>[e,v(t)])):o,Z=o=>I(o)?o.every(G):G(o),$=o=>P(o)&&Object.values(o).every(Z),Be=o=>P(o)||I(o)&&!o.every(G),de=o=>{if(I(o)||!P(o))return!0;let e=Object.values(o);return e.length===0?!0:e.some(t=>!Be(t))},_=o=>typeof o=="string",O=o=>{if(typeof o=="string"){if(o.toLowerCase()==="true")return!0;if(o.toLowerCase()==="false")return!1}return I(o)&&o.length===0||P(o)&&Object.keys(o).length===0?!1:!!o};var X=["httpClient","timeout","host","port","protocol","url","logger","options"];var k=class o extends Error{constructor(e,t){super(`Record with label "${e}" and properties ${JSON.stringify(t)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,o.prototype)}},B=class o extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,o.prototype)}},K=class o extends Error{constructor(e,t){super(`Expected a unique result but found ${e} matches for the provided SearchQuery: ${JSON.stringify(t)}. Ensure your search parameters uniquely identify a single result.`),this.name="NonUniqueResultError",Object.setPrototypeOf(this,o.prototype)}};var J=(o,e)=>h(void 0,null,function*(){let t=Object.entries(o).map(i=>h(void 0,[i],function*([n,a]){return a.default&&typeof a.default!="undefined"&&typeof e[n]=="undefined"?{key:n,value:typeof a.default=="function"?yield a.default():a.default}:{key:n,value:void 0}})),s=(yield Promise.all(t)).reduce((n,{key:a,value:i})=>(i!==void 0&&(n[a]=i),n),{});return c(c({},s),e)}),ee=(o,e)=>Object.entries(e).filter(([t])=>{var r;return(r=o[t])==null?void 0:r.unique}).reduce((t,[r,s])=>(r in o&&(t[r]=s),t),{}),pe=(o,e,t)=>{let r={},s=Object.entries(e).filter(([,n])=>n.unique).reduce((n,[a])=>(n[a]=!0,n),{});return o.forEach(n=>{Object.entries(n).forEach(([a,i])=>{if(a in s)if(r[a]){if(r[a].includes(i))throw new k(t,{[a]:i});r[a]=[...r[a],i]}else r[a]=[i]})}),r},le=o=>{if(!o)return{};if(!P(o))throw new Error("Config must be an object");if(Object.keys(o).filter(t=>!X.includes(t)).length>0)throw new Error(`Config object may only contain the following: ${X.join(", ")}`);return o};function he(o,e,t){if(!Number.isInteger(e)){if(t!==void 0)return t;throw new Error(`${o} must be an integer`)}return e}function te(o){let e=o.split("-"),t=e[0]+e[1].slice(0,4);return parseInt(t,16)}function ge(o){return new Date(te(o))}var D=class{constructor(e={}){this.data=e}get exists(){return O(this.data.__id)&&O(this.data.__label)}get id(){if(!O(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(!O(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(!O(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 ge(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 te(this.id)}catch(e){throw new Error("DBRecordInstance: Unable to access 'timestamp'. The Record's `data.__id` is missing or incorrect.")}}delete(e){return h(this,null,function*(){if(!O(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return yield w.getInstance().records.deleteById(this.id,e)})}update(e,t){return h(this,null,function*(){if(!O(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return w.getInstance().records.update({label:this.label,target:this.id,data:e},t)})}set(e,t){return h(this,null,function*(){if(!O(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return w.getInstance().records.set({label:this.label,target:this.id,data:e},t)})}attach(e,t,r){return h(this,null,function*(){if(!O(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return w.getInstance().records.attach({source:this.id,target:e,options:t},r)})}detach(e,t,r){return h(this,null,function*(){if(!O(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return w.getInstance().records.detach({source:this.id,target:e,options:t},r)})}},E=class{constructor(e=[],t=0,r,s){this.data=e,this.total=t,this.searchQuery=r,this.warnings=s}deleteAll(e){return h(this,null,function*(){let t=this.data.map(s=>s.id);return t.length?yield w.getInstance().records.deleteById(t,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 t=(i=this.searchQuery.skip)!=null?i:0,r=(d=this.searchQuery.limit)!=null?d:100,s=u(c({},this.searchQuery),{skip:t+r}),a=yield w.getInstance().records.find(s,void 0);return e!=null&&e.preserveData?(this.data=[...this.data,...a.data],this.total=a.total,this.searchQuery=s,this):a})}exportCsv(){if(!this.data.length)return"";let e=new Set(["__id","__label","__proptypes"]),t=Object.keys(this.data[0].data).filter(n=>!e.has(n)),r=n=>{let a=n==null?"":String(n);return a.includes(",")||a.includes('"')||a.includes(`
|
|
2
2
|
`)?`"${a.replace(/"/g,'""')}"`:a},s=this.data.map(n=>t.map(a=>r(n.data[a])).join(","));return[t.join(","),...s].join(`
|
|
3
|
-
`)}setProperties(e,t){return h(this,null,function*(){let s=b.getInstance();for(let n=0;n<this.data.length;n+=100){let a=this.data.slice(n,n+100);yield Promise.all(a.map(i=>s.records.update({target:i.id,label:i.data.__label,data:e},t)))}})}};var Ce={"Content-Type":"application/json"},he=({httpClient:o,token:e,url:t})=>(r,a)=>h(void 0,null,function*(){var i=a,{headers:s}=i,n=Q(i,["headers"]);var y;let d=yield o.makeRequest(`${t}${r}`,c({credentials:"omit",headers:Object.assign(c(c({},Ce),s),typeof e!="undefined"?{Authorization:`Bearer ${e}`}:{})},n));if(d.getStatusCode()>=200&&d.getStatusCode()<300)return yield d.toJSON();let p="",l;try{let f=yield d.toJSON();l=f;let m=(y=f==null?void 0:f.message)!=null?y:f==null?void 0:f.error;Array.isArray(m)?p=m.join("; "):typeof m=="string"&&(p=m)}catch(f){}let g=new Error(p?`${d.getStatusCode()} ${p}`:`${d.getStatusCode()}`);throw g.status=d.getStatusCode(),g.body=l,g});var U=class{constructor(e){this.id=e}rollback(){return h(this,null,function*(){return yield b.getInstance().tx.rollback(this.id)})}commit(){return h(this,null,function*(){return yield b.getInstance().tx.commit(this.id)})}};var ge="api.rushdb.com";var ue="https",ye="/api/v1";var w=o=>o?{"x-transaction-id":o}:void 0,Be=o=>B(o)||o instanceof U,R=o=>Be(o)?o instanceof U?o.id:o:void 0,me=o=>/^[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(o),A=o=>{if(B(o)&&me(o))return o;if(o instanceof D&&o.data)return o.data.__id;if(x(o)&&"__id"in o&&me(o.__id))return o.__id},F=o=>!(!x(o)||x(o)&&"name"in o&&!B(o.name)||x(o)&&"type"in o&&(!B(o.type)||!ae.includes(o.type))||!("value"in o)||!Z(o.value)||"metadata"in o&&!B(o.metadata)||"valueSeparator"in o&&!B(o.valueSeparator)),fe=o=>{let e=ue,t=ge,r=443,s=ye;if("url"in o){let a=new URL(o.url);e=a.protocol.replace(":",""),t=a.hostname,r=parseInt(a.port||(e==="http"?"80":e==="https"?"443":""))}"host"in o&&"port"in o&&"protocol"in o&&(e=o.protocol.replace(":",""),t=o.host,r=o.port),s&&!s.startsWith("/")&&(s="/"+s);let n="";return e==="http"&&r===80||e==="https"&&r===443||(n=":"+r),`${e}://${t}${n}${s}`},S=(o=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let r=0;r<o;r++){let s=Math.floor(Math.random()*e.length);t+=e[s]}return t};var L=class{constructor(e,t){this.records={attach:(n,a)=>h(this,[n,a],function*({source:e,target:t,options:r},s){var f,m;let i=R(s),p=`/relationships/${A(e)}`,l={headers:Object.assign({},w(i)),method:"POST",requestData:c(c(c({targetIds:this._extractTargetIds(t,"Attach")},(r==null?void 0:r.type)&&{type:r.type}),(r==null?void 0:r.direction)&&{direction:r.direction}),(r==null?void 0:r.properties)&&{properties:r.properties})},g=typeof this.logger=="function"?S():"";(f=this.logger)==null||f.call(this,c({requestId:g,path:p},l));let y=yield this.fetcher(p,l);return(m=this.logger)==null||m.call(this,u(c({requestId:g,path:p},l),{responseData:y.data})),y}),detach:(n,a)=>h(this,[n,a],function*({source:e,target:t,options:r},s){var f,m;let i=R(s),p=`/relationships/${A(e)}`,l={headers:Object.assign({},w(i)),method:"PUT",requestData:c(c({targetIds:this._extractTargetIds(t,"Detach")},(r==null?void 0:r.typeOrTypes)&&{typeOrTypes:r.typeOrTypes}),(r==null?void 0:r.direction)&&{direction:r.direction})},g=typeof this.logger=="function"?S():"";(f=this.logger)==null||f.call(this,c({requestId:g,path:p},l));let y=yield this.fetcher(p,l);return(m=this.logger)==null||m.call(this,u(c({requestId:g,path:p},l),{responseData:y.data})),y}),create:(a,i)=>h(this,[a,i],function*({label:e,data:t,options:r,vectors:s},n){var m,T;let d=R(n),p="/records",l={headers:Object.assign({},w(d)),method:"POST",requestData:{}},g=typeof this.logger=="function"?S():"",y=M(v(t));if(I(y)&&y.every(F))l.requestData=c({label:e,properties:y,options:r},(s==null?void 0:s.length)&&{vectors:s});else if($(y))l.requestData=c({label:e,data:y,options:r},(s==null?void 0:s.length)&&{vectors:s});else throw x(y)?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.");(m=this.logger)==null||m.call(this,c({requestId:g,path:p},l));let f=yield this.fetcher(p,l);return(T=this.logger)==null||T.call(this,u(c({requestId:g,path:p},l),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D}),createMany:(e,t)=>h(this,null,function*(){var g,y,f,m;let r=I(e.data)?e.data:[e.data];if(!r.every(T=>$(T)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");if(e.vectors&&e.vectors.length>r.length)throw new Error(`records.createMany: vectors length (${e.vectors.length}) exceeds the number of data rows (${r.length}).`);let n=(g=e.vectors)!=null&&g.length?r.map((T,O)=>{var j;return(j=e.vectors[O])!=null&&j.length?u(c({},T),{$vectors:e.vectors[O]}):T}):r,a=R(t),i="/records/import/json",d={headers:Object.assign({},w(a)),method:"POST",requestData:{label:e.label,data:n,options:e.options}},p=typeof this.logger=="function"?S():"";(y=this.logger)==null||y.call(this,c({requestId:p,path:i},d));let l=yield this.fetcher(i,d);if((f=this.logger)==null||f.call(this,u(c({requestId:p,path:i},d),{responseData:l.data})),l!=null&&l.success&&(l!=null&&l.data)){let T=I(l.data)?(m=l.data)==null?void 0:m.map(O=>new D(O)):[];return new E(T,l.total)}return new E([])}),importJson:(e,t)=>h(this,null,function*(){var y,f,m;let{data:r,options:s}=e,{label:n}=e,a=r;if(!n){let T=x(r)&&!I(r)?M(r):r;if(ie(T))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=R(t),d="/records/import/json",p={headers:Object.assign({},w(i)),method:"POST",requestData:{label:n,data:a,options:s}},l=typeof this.logger=="function"?S():"";(y=this.logger)==null||y.call(this,c({requestId:l,path:d},p));let g=yield this.fetcher(d,p);if((f=this.logger)==null||f.call(this,u(c({requestId:l,path:d},p),{responseData:g.data})),g!=null&&g.success&&(g!=null&&g.data)){let T=I(g.data)?(m=g.data)==null?void 0:m.map(O=>new D(O)):[];return new E(T,g.total)}return new E([])}),importCsv:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/records/import/csv",n={headers:Object.assign({},w(r)),method:"POST",requestData:e},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);if((p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i!=null&&i.success&&(i!=null&&i.data)){let l=I(i.data)?i.data.map(g=>new D(g)):[];return new E(l,i.total)}return new E([])}),delete:(e,t)=>h(this,null,function*(){var d,p,l;if(H(e.where)&&!((d=this==null?void 0:this.options)!=null&&d.allowForceDelete))throw new q("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let r=R(t),s="/records/delete",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),deleteById:(e,t)=>h(this,null,function*(){var p,l;let r=R(t),s=I(e),n=s?"/records/delete":`/records/${e}`,a={headers:Object.assign({},w(r)),method:s?"POST":"DELETE",requestData:s?{limit:1e3,where:{$id:{$in:e}}}:void 0},i=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:i,path:n},a));let d=yield this.fetcher(n,a);return(l=this.logger)==null||l.call(this,u(c({requestId:i,path:n},a),{responseData:d.data})),d}),export:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/records/export/csv",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),find:(e,t)=>h(this,null,function*(){var y,f;let g=e,{id:r}=g,s=Q(g,["id"]),n=R(t),a=r?`/records/${r}/search`:"/records/search",i={headers:Object.assign({},w(n)),method:"POST",requestData:s!=null?s:{}},d=typeof this.logger=="function"?S():"";(y=this.logger)==null||y.call(this,c({requestId:d,path:a},i));let p=yield this.fetcher(a,i);(f=this.logger)==null||f.call(this,u(c({requestId:d,path:a},i),{responseData:p.data}));let l=p.data.map(m=>new D(m));return new E(l,p.total,e)}),findById:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s=I(e)?"/records":`/records/${e}`,n={headers:Object.assign({},w(r)),method:I(e)?"POST":"GET",requestData:I(e)?{ids:e}:void 0},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);if((p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),I(e)){let l=i.data.map(g=>new D(g));return new E(l,i.total)}else return new D(i.data)}),findOne:(e,t)=>h(this,null,function*(){var p,l;let r=R(t),s="/records/search",n={headers:Object.assign({},w(r)),method:"POST",requestData:u(c({},e),{limit:1,skip:0})},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);(l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data}));let[d]=i.data;return new D(d)}),findUniq:(e,t)=>h(this,null,function*(){var p,l;let r=R(t),s="/records/search",n={headers:Object.assign({},w(r)),method:"POST",requestData:u(c({},e),{limit:1,skip:0})},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);if((l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),typeof i.total!="undefined"&&i.total>1)throw new K(i.total,e);let[d]=i.data;return new D(d)}),set:(i,d)=>h(this,[i,d],function*({target:e,label:t,data:r,options:s,vectors:n},a){var O,j;let p=R(a),g=`/records/${A(e)}`,y={headers:Object.assign({},w(p)),method:"PUT",requestData:{}},f=typeof this.logger=="function"?S():"",m=M(v(r));if(I(m)&&m.every(F))y.requestData=c({label:t,properties:m},(n==null?void 0:n.length)&&{vectors:n});else if($(m))y.requestData=c({label:t,data:m,options:s},(n==null?void 0:n.length)&&{vectors:n});else throw x(m)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(O=this.logger)==null||O.call(this,c({requestId:f,path:g},y));let T=yield this.fetcher(g,y);return(j=this.logger)==null||j.call(this,u(c({requestId:f,path:g},y),{responseData:T.data})),T!=null&&T.success&&(T!=null&&T.data)?new D(T.data):new D}),update:(a,i)=>h(this,[a,i],function*({target:e,label:t,data:r,options:s},n){var T,O;let d=R(n),l=`/records/${A(e)}`,g={headers:Object.assign({},w(d)),method:"PATCH",requestData:{}},y=typeof this.logger=="function"?S():"",f=M(v(r));if(I(f)&&f.every(F))g.requestData={label:t,properties:f};else if($(f))g.requestData={label:t,data:f,options:s};else throw x(f)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(T=this.logger)==null||T.call(this,c({requestId:y,path:l},g));let m=yield this.fetcher(l,g);return(O=this.logger)==null||O.call(this,u(c({requestId:y,path:l},g),{responseData:m.data})),m!=null&&m.success&&(m!=null&&m.data)?new D(m.data):new D}),upsert:(a,i)=>h(this,[a,i],function*({label:e,data:t,options:r,vectors:s},n){var T,O,j;let d=R(n),p="/records",l={headers:Object.assign({},w(d)),method:"POST",requestData:{}},g=typeof this.logger=="function"?S():"",y=M(v(t)),f=u(c({},r),{mergeBy:(T=r==null?void 0:r.mergeBy)!=null?T:[]});if(I(y)&&y.every(F))l.requestData=c({label:e,properties:y,options:f},(s==null?void 0:s.length)&&{vectors:s});else if($(y))l.requestData=c({label:e,data:y,options:f},(s==null?void 0:s.length)&&{vectors:s});else throw x(y)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(O=this.logger)==null||O.call(this,c({requestId:g,path:p},l));let m=yield this.fetcher(p,l);return(j=this.logger)==null||j.call(this,u(c({requestId:g,path:p},l),{responseData:m.data})),m!=null&&m.success&&(m!=null&&m.data)?new D(m.data):new D})};this.relationships={patterns:{list:()=>h(this,null,function*(){var n,a;let e="/relationships/patterns",t={method:"GET",headers:{}},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s}),analyze:()=>h(this,null,function*(){var n,a;let e="/relationships/patterns/analyze",t={method:"POST",headers:{},requestData:{}},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s}),approve:e=>h(this,null,function*(){var a,i;let t=`/relationships/patterns/${encodeURIComponent(e)}/approve`,r={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n}),ignore:e=>h(this,null,function*(){var a,i;let t=`/relationships/patterns/${encodeURIComponent(e)}/ignore`,r={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n}),delete:(e,t)=>h(this,null,function*(){var d,p;let r=t!=null&&t.deleteExisting?"?deleteExisting=true":"",s=`/relationships/patterns/${encodeURIComponent(e)}${r}`,n={method:"DELETE",headers:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i})},createMany:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/relationships/create-many",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),deleteMany:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/relationships/delete-many",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),find:(...r)=>h(this,[...r],function*(e={},t){var p,l;let s=R(t),n="/relationships/search",a={headers:Object.assign({},w(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:i,path:n},a));let d=yield this.fetcher(n,a);return(l=this.logger)==null||l.call(this,u(c({requestId:i,path:n},a),{responseData:d.data})),d})};this.properties={delete:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s=`/properties/${e}`,n={headers:Object.assign({},w(r)),method:"DELETE"},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),find:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/properties/search",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),findById:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s=`/properties/${e}`,n={headers:Object.assign({},w(r)),method:"GET"},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),values:(e,t,r)=>h(this,null,function*(){var p,l;let s=R(r),n=`/properties/${e}/values`,a={headers:Object.assign({},w(s)),method:"POST",requestData:t!=null?t:{}},i=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:i,path:n},a));let d=yield this.fetcher(n,a);return(l=this.logger)==null||l.call(this,u(c({requestId:i,path:n},a),{responseData:d.data})),d})};this.labels={find:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/labels/search",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i})};this.tx={begin:e=>h(this,null,function*(){var a,i;let t="/tx",r={method:"POST",requestData:x(e)&&"ttl"in e?e:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),new U(n.data.id)}),commit:e=>h(this,null,function*(){var i,d;let r=`/tx/${R(e)}/commit`,s={method:"POST",requestData:{}},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),a}),get:e=>h(this,null,function*(){var i,d;let r=`/tx/${R(e)}`,s={method:"GET"},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),new U(a.data.id)}),rollback:e=>h(this,null,function*(){var i,d;let r=`/tx/${R(e)}/rollback`,s={method:"POST",requestData:{}},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),a})};this.settings={get:()=>h(this,null,function*(){var n,a;let e="/sdk/settings",t={method:"GET"},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s})};this.query={raw:(s,n)=>h(this,[s,n],function*({query:e,params:t},r){var g,y;let a=R(r),i="/query/raw",d={headers:Object.assign({},w(a)),method:"POST",requestData:{query:e,params:t}},p=typeof this.logger=="function"?S():"";(g=this.logger)==null||g.call(this,c({requestId:p,path:i},d));let l=yield this.fetcher(i,d);return(y=this.logger)==null||y.call(this,u(c({requestId:p,path:i},d),{responseData:l.data})),l})};this.ai={getSchema:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/ai/schema",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),getSchemaMarkdown:(e,t)=>h(this,null,function*(){var d,p;let r=R(t),s="/ai/schema/md",n={headers:Object.assign({},w(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),indexes:{find:()=>h(this,null,function*(){var n,a;let e="/ai/indexes",t={method:"GET",headers:{}},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s}),create:e=>h(this,null,function*(){var l,g;let t="/ai/indexes",p=e,{external:r}=p,s=Q(p,["external"]),n=r===!0?u(c({},s),{sourceType:"external"}):s,a={method:"POST",headers:{},requestData:n},i=typeof this.logger=="function"?S():"";(l=this.logger)==null||l.call(this,c({requestId:i,path:t},a));let d=yield this.fetcher(t,a);return(g=this.logger)==null||g.call(this,u(c({requestId:i,path:t},a),{responseData:d.data})),d}),upsertVectors:(e,t)=>h(this,null,function*(){var i,d;let r=`/ai/indexes/${e}/vectors/upsert`,s={method:"POST",headers:{},requestData:t},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),a}),delete:e=>h(this,null,function*(){var a,i;let t=`/ai/indexes/${e}`,r={method:"DELETE",headers:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n}),stats:e=>h(this,null,function*(){var a,i;let t=`/ai/indexes/${e}/stats`,r={method:"GET",headers:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n})},search:e=>h(this,null,function*(){var i,d,p,l;let t="/ai/search",r={method:"POST",headers:{},requestData:e},s=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);(d=this.logger)==null||d.call(this,u(c({requestId:s,path:t},r),{responseData:n.data}));let a=((p=n.data)!=null?p:[]).map(g=>new D(g));return new E(a,(l=n.total)!=null?l:0)})};if(this.fetcher=null,t!=null&&t.httpClient){let r=fe(t);this.fetcher=he({httpClient:t.httpClient,token:e,url:r})}t!=null&&t.options&&(this.options=t==null?void 0:t.options),t!=null&&t.logger&&(this.logger=t==null?void 0:t.logger)}_extractTargetIds(e,t){var r;if(e instanceof D){let s=A(e);if(!s)throw new q(`${t} error: Target id is empty`);return[s]}if(I(e)&&e.every(s=>s instanceof D)){let s=e.map(A).filter(P);if(!s.length)throw new q(`${t} error: Target ids are empty`);return s}if(e instanceof E){let s=(r=e.data)==null?void 0:r.map(A).filter(P);if(!(s!=null&&s.length))throw new q(`${t} error: Target ids are empty`);return s}if(x(e)&&"__id"in e)return[e.__id];if(I(e)&&e.every(s=>x(s)&&"__id"in s)){let s=e.map(A).filter(P);if(!s.length)throw new q(`${t} error: Target ids are empty`);return s}return I(e)?e:B(e)?[e]:[]}};var Se,_=class _ extends L{constructor(e,t){var n,a;let r=e!=null?e:typeof process!="undefined"?(n=process.env)==null?void 0:n.RUSHDB_API_KEY:void 0,s=de(t);super(r,u(c({},s),{httpClient:(a=s.httpClient)!=null?a:Se})),_.instance=this,this.initializeSync(r,s)}initializeSync(e,t){_.state={initialized:!0,debug:!1,timeout:pe("timeout",t==null?void 0:t.timeout,8e4),token:e}}static getInstance(){if(_.instance)return _.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static isInitialized(){return P(_.instance)}toDBRecordInstance(e){return new D(e)}};_.instance=null,_.state={initialized:!1,debug:!1,timeout:8e4};var b=_,Re=o=>{Se=o};var Te=class{constructor(e,t,r){this.label=e,this.schema=t,this.config=r!=null?r:{}}getLabel(){return this.label}toDBRecordInstance(e){return h(this,null,function*(){try{return b.getInstance().toDBRecordInstance(e)}catch(t){throw new Error("No RushDB instance was provided during model initialization.")}})}find(e,t){return h(this,null,function*(){let r=e!=null?e:{};return b.getInstance().records.find(u(c({},r),{labels:[this.label]}),t)})}findOne(e,t){return h(this,null,function*(){let r=e!=null?e:{};return b.getInstance().records.findOne(u(c({},r),{labels:[this.label]}),t)})}findById(e,t){return h(this,null,function*(){return this.findOne({where:{$id:e}},t)})}findUniq(e,t){return h(this,null,function*(){let r=e!=null?e:{};return b.getInstance().records.findUniq(u(c({},r),{labels:[this.label]}),t)})}create(e,t,r){return h(this,null,function*(){var d,p;let s=yield J(this.schema,e),n=ee(this.schema,s),a=P(n),i=b.getInstance();if(a){let l=t!=null?t:yield i.tx.begin(),g=yield this.find({where:n},l),y=typeof t!="undefined";if(!((d=g==null?void 0:g.data)!=null&&d.length)){let m=yield i.records.create({label:this.label,data:s},l);return y||(yield l.commit()),m}else switch((p=r==null?void 0:r.onConflict)!=null?p:"throw"){case"upsert":{let T=g.data[0],O=yield i.records.set({target:T.id,label:this.label,data:s},l);return y||(yield l.commit()),O}case"skip":return y||(yield l.commit()),null;default:throw y||(yield l.commit()),new k(this.label,n)}}return yield i.records.create({label:this.label,data:s},t)})}attach(n,a){return h(this,arguments,function*({source:e,target:t,options:r},s){return yield b.getInstance().records.attach({source:e,target:t,options:r},s)})}detach(n,a){return h(this,arguments,function*({source:e,target:t,options:r},s){return yield b.getInstance().records.detach({source:e,target:t,options:r},s)})}validateTargetLabel(e,t){return h(this,null,function*(){let r=A(e);if(!r)return;let n=yield b.getInstance().records.findById(r,t);if(!n)throw new Error(`Record with id "${r}" not found.`);if(n.data.__label!==this.label)throw new TypeError(`Target record label "${n.data.__label}" does not match model label "${this.label}".`)})}handleSetOrUpdate(e,t,r,s){return h(this,null,function*(){var d,p;if(this.config.validateTargetLabel&&(yield this.validateTargetLabel(e,s)),I(t)&&t.every(F))return yield b.getInstance().records[r]({label:this.label,target:e,data:t},s);let n=b.getInstance(),a=yield J(this.schema,t),i=ee(this.schema,a);if(!H(i)){let l=s!=null?s:yield n.tx.begin(),g=yield this.find({where:i},l),y=typeof s!="undefined";if(!((d=g==null?void 0:g.data)!=null&&d.length)||g.data.length===1&&((p=g.data[0])==null?void 0:p.id)===A(e)){let m=yield n.records[r]({target:e,label:this.label,data:a},l);return y||(yield l.commit()),m}else throw y||(yield l.commit()),new k(this.label,i)}return yield n.records[r]({label:this.label,target:e,data:a},s)})}set(e,t,r){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,t,"set",r)})}update(e,t,r){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,t,"update",r)})}createMany(e,t){return h(this,null,function*(){var a;let r=b.getInstance(),s=typeof t!="undefined",n=t!=null?t:yield r.tx.begin();try{let i=yield Promise.all(e.map(l=>h(this,null,function*(){return yield J(this.schema,l)}))),d=ce(i,this.schema,this.label);if(!H(d)){let l=Object.entries(d).map(([y,f])=>({[y]:{$in:f}})),g=yield this.find({where:{$or:l}},n);if((a=g==null?void 0:g.data)!=null&&a.length)throw new k(this.label,Object.keys(d))}let p=yield r.records.createMany({label:this.label,data:i},n);return s||(yield n.commit()),p}catch(i){throw s||(yield n.rollback()),i}})}delete(e,t){return h(this,null,function*(){if(H(e.where))throw new q(`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 b.getInstance().records.delete(u(c({},e),{labels:[this.label]}),t)})}deleteById(e,t){return h(this,null,function*(){return yield b.getInstance().records.deleteById(e,t)})}};Re(new N);var Ft=b;export{D as DBRecordInstance,E as DBRecordsArrayInstance,q as EmptyTargetError,C as HttpClient,Y as HttpClientResponse,Te as Model,K as NonUniqueResultError,L as RestAPI,b as RushDB,U as Transaction,k as UniquenessError,Ft as default,le as idToDate,te as idToTimestamp,Re as initSDK,J as mergeDefaultsWithPayload,de as parseConfig,ee as pickUniqFieldsFromRecord,ce as pickUniqFieldsFromRecords,pe as validateInteger};
|
|
3
|
+
`)}setProperties(e,t){return h(this,null,function*(){let s=w.getInstance();for(let n=0;n<this.data.length;n+=100){let a=this.data.slice(n,n+100);yield Promise.all(a.map(i=>s.records.update({target:i.id,label:i.data.__label,data:e},t)))}})}};var _e={"Content-Type":"application/json"},ue=({httpClient:o,token:e,url:t})=>(r,a)=>h(void 0,null,function*(){var i=a,{headers:s}=i,n=V(i,["headers"]);var y;let d=yield o.makeRequest(`${t}${r}`,c({credentials:"omit",headers:Object.assign(c(c({},_e),s),typeof e!="undefined"?{Authorization:`Bearer ${e}`}:{})},n));if(d.getStatusCode()>=200&&d.getStatusCode()<300)return yield d.toJSON();let p="",l;try{let m=yield d.toJSON();l=m;let f=(y=m==null?void 0:m.message)!=null?y:m==null?void 0:m.error;Array.isArray(f)?p=f.join("; "):typeof f=="string"&&(p=f)}catch(m){}let g=new Error(p?`${d.getStatusCode()} ${p}`:`${d.getStatusCode()}`);throw g.status=d.getStatusCode(),g.body=l,g});var U=class{constructor(e){this.id=e}rollback(){return h(this,null,function*(){return yield w.getInstance().tx.rollback(this.id)})}commit(){return h(this,null,function*(){return yield w.getInstance().tx.commit(this.id)})}};var ye="api.rushdb.com";var me="https",fe="/api/v1";var b=o=>o?{"x-transaction-id":o}:void 0,ke=o=>_(o)||o instanceof U,T=o=>ke(o)?o instanceof U?o.id:o:void 0,Se=o=>/^[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(o),A=o=>{if(_(o)&&Se(o))return o;if(o instanceof D&&o.data)return o.data.__id;if(P(o)&&"__id"in o&&Se(o.__id))return o.__id},F=o=>!(!P(o)||P(o)&&"name"in o&&!_(o.name)||P(o)&&"type"in o&&(!_(o.type)||!ie.includes(o.type))||!("value"in o)||!Z(o.value)||"metadata"in o&&!_(o.metadata)||"valueSeparator"in o&&!_(o.valueSeparator)),Re=o=>{let e=me,t=ye,r=443,s=fe;if("url"in o){let a=new URL(o.url);e=a.protocol.replace(":",""),t=a.hostname,r=parseInt(a.port||(e==="http"?"80":e==="https"?"443":""))}"host"in o&&"port"in o&&"protocol"in o&&(e=o.protocol.replace(":",""),t=o.host,r=o.port),s&&!s.startsWith("/")&&(s="/"+s);let n="";return e==="http"&&r===80||e==="https"&&r===443||(n=":"+r),`${e}://${t}${n}${s}`},S=(o=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let r=0;r<o;r++){let s=Math.floor(Math.random()*e.length);t+=e[s]}return t};var L=class{constructor(e,t){this.records={attach:(n,a)=>h(this,[n,a],function*({source:e,target:t,options:r},s){var m,f;let i=T(s),p=`/relationships/${A(e)}`,l={headers:Object.assign({},b(i)),method:"POST",requestData:c(c(c({targetIds:this._extractTargetIds(t,"Attach")},(r==null?void 0:r.type)&&{type:r.type}),(r==null?void 0:r.direction)&&{direction:r.direction}),(r==null?void 0:r.properties)&&{properties:r.properties})},g=typeof this.logger=="function"?S():"";(m=this.logger)==null||m.call(this,c({requestId:g,path:p},l));let y=yield this.fetcher(p,l);return(f=this.logger)==null||f.call(this,u(c({requestId:g,path:p},l),{responseData:y.data})),y}),detach:(n,a)=>h(this,[n,a],function*({source:e,target:t,options:r},s){var m,f;let i=T(s),p=`/relationships/${A(e)}`,l={headers:Object.assign({},b(i)),method:"PUT",requestData:c(c({targetIds:this._extractTargetIds(t,"Detach")},(r==null?void 0:r.typeOrTypes)&&{typeOrTypes:r.typeOrTypes}),(r==null?void 0:r.direction)&&{direction:r.direction})},g=typeof this.logger=="function"?S():"";(m=this.logger)==null||m.call(this,c({requestId:g,path:p},l));let y=yield this.fetcher(p,l);return(f=this.logger)==null||f.call(this,u(c({requestId:g,path:p},l),{responseData:y.data})),y}),create:(a,i)=>h(this,[a,i],function*({label:e,data:t,options:r,vectors:s},n){var f,R;let d=T(n),p="/records",l={headers:Object.assign({},b(d)),method:"POST",requestData:{}},g=typeof this.logger=="function"?S():"",y=M(v(t));if(I(y)&&y.every(F))l.requestData=c({label:e,properties:y,options:r},(s==null?void 0:s.length)&&{vectors:s});else if($(y))l.requestData=c({label:e,data:y,options:r},(s==null?void 0:s.length)&&{vectors:s});else throw P(y)?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.");(f=this.logger)==null||f.call(this,c({requestId:g,path:p},l));let m=yield this.fetcher(p,l);return(R=this.logger)==null||R.call(this,u(c({requestId:g,path:p},l),{responseData:m.data})),m!=null&&m.success&&(m!=null&&m.data)?new D(m.data):new D}),createMany:(e,t)=>h(this,null,function*(){var g,y,m,f;let r=I(e.data)?e.data:[e.data];if(!r.every(R=>$(R)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");if(e.vectors&&e.vectors.length>r.length)throw new Error(`records.createMany: vectors length (${e.vectors.length}) exceeds the number of data rows (${r.length}).`);let n=(g=e.vectors)!=null&&g.length?r.map((R,x)=>{var q;return(q=e.vectors[x])!=null&&q.length?u(c({},R),{$vectors:e.vectors[x]}):R}):r,a=T(t),i="/records/import/json",d={headers:Object.assign({},b(a)),method:"POST",requestData:{label:e.label,data:n,options:e.options}},p=typeof this.logger=="function"?S():"";(y=this.logger)==null||y.call(this,c({requestId:p,path:i},d));let l=yield this.fetcher(i,d);if((m=this.logger)==null||m.call(this,u(c({requestId:p,path:i},d),{responseData:l.data})),l!=null&&l.success&&(l!=null&&l.data)){let R=I(l.data)?(f=l.data)==null?void 0:f.map(x=>new D(x)):[];return new E(R,l.total)}return new E([])}),importJson:(e,t)=>h(this,null,function*(){var y,m,f;let{data:r,options:s}=e,{label:n}=e,a=r;if(!n){let R=P(r)&&!I(r)?M(r):r;if(de(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(t),d="/records/import/json",p={headers:Object.assign({},b(i)),method:"POST",requestData:{label:n,data:a,options:s}},l=typeof this.logger=="function"?S():"";(y=this.logger)==null||y.call(this,c({requestId:l,path:d},p));let g=yield this.fetcher(d,p);if((m=this.logger)==null||m.call(this,u(c({requestId:l,path:d},p),{responseData:g.data})),g!=null&&g.success&&(g!=null&&g.data)){let R=I(g.data)?(f=g.data)==null?void 0:f.map(x=>new D(x)):[];return new E(R,g.total)}return new E([])}),importCsv:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/records/import/csv",n={headers:Object.assign({},b(r)),method:"POST",requestData:e},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);if((p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i!=null&&i.success&&(i!=null&&i.data)){let l=I(i.data)?i.data.map(g=>new D(g)):[];return new E(l,i.total)}return new E([])}),delete:(e,t)=>h(this,null,function*(){var d,p,l;if(H(e.where)&&!((d=this==null?void 0:this.options)!=null&&d.allowForceDelete))throw new B("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let r=T(t),s="/records/delete",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),deleteById:(e,t)=>h(this,null,function*(){var p,l;let r=T(t),s=I(e),n=s?"/records/delete":`/records/${e}`,a={headers:Object.assign({},b(r)),method:s?"POST":"DELETE",requestData:s?{limit:1e3,where:{$id:{$in:e}}}:void 0},i=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:i,path:n},a));let d=yield this.fetcher(n,a);return(l=this.logger)==null||l.call(this,u(c({requestId:i,path:n},a),{responseData:d.data})),d}),export:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/records/export/csv",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),find:(e,t)=>h(this,null,function*(){var y,m;let g=e,{id:r}=g,s=V(g,["id"]),n=T(t),a=r?`/records/${r}/search`:"/records/search",i={headers:Object.assign({},b(n)),method:"POST",requestData:s!=null?s:{}},d=typeof this.logger=="function"?S():"";(y=this.logger)==null||y.call(this,c({requestId:d,path:a},i));let p=yield this.fetcher(a,i);(m=this.logger)==null||m.call(this,u(c({requestId:d,path:a},i),{responseData:p.data}));let l=p.data.map(f=>new D(f));return new E(l,p.total,e)}),vectorSearch:(e,t)=>h(this,null,function*(){var p,l,g,y;let r=T(t),s="/ai/search",n={method:"POST",headers:Object.assign({},b(r)),requestData:e},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);(l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data}));let d=((g=i.data)!=null?g:[]).map(m=>new D(m));return new E(d,(y=i.total)!=null?y:0)}),findById:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s=I(e)?"/records":`/records/${e}`,n={headers:Object.assign({},b(r)),method:I(e)?"POST":"GET",requestData:I(e)?{ids:e}:void 0},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);if((p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),I(e)){let l=i.data.map(g=>new D(g));return new E(l,i.total)}else return new D(i.data)}),findOne:(e,t)=>h(this,null,function*(){var p,l;let r=T(t),s="/records/search",n={headers:Object.assign({},b(r)),method:"POST",requestData:u(c({},e),{limit:1,skip:0})},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);(l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data}));let[d]=i.data;return new D(d)}),findUniq:(e,t)=>h(this,null,function*(){var p,l;let r=T(t),s="/records/search",n={headers:Object.assign({},b(r)),method:"POST",requestData:u(c({},e),{limit:1,skip:0})},a=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);if((l=this.logger)==null||l.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),typeof i.total!="undefined"&&i.total>1)throw new K(i.total,e);let[d]=i.data;return new D(d)}),set:(i,d)=>h(this,[i,d],function*({target:e,label:t,data:r,options:s,vectors:n},a){var x,q;let p=T(a),g=`/records/${A(e)}`,y={headers:Object.assign({},b(p)),method:"PUT",requestData:{}},m=typeof this.logger=="function"?S():"",f=M(v(r));if(I(f)&&f.every(F))y.requestData=c({label:t,properties:f},(n==null?void 0:n.length)&&{vectors:n});else if($(f))y.requestData=c({label:t,data:f,options:s},(n==null?void 0:n.length)&&{vectors:n});else throw P(f)?new Error("Provided data is not a flat object. Consider to use `importJson` method."):new Error("Provided data is not valid.");(x=this.logger)==null||x.call(this,c({requestId:m,path:g},y));let R=yield this.fetcher(g,y);return(q=this.logger)==null||q.call(this,u(c({requestId:m,path:g},y),{responseData:R.data})),R!=null&&R.success&&(R!=null&&R.data)?new D(R.data):new D}),update:(a,i)=>h(this,[a,i],function*({target:e,label:t,data:r,options:s},n){var R,x;let d=T(n),l=`/records/${A(e)}`,g={headers:Object.assign({},b(d)),method:"PATCH",requestData:{}},y=typeof this.logger=="function"?S():"",m=M(v(r));if(I(m)&&m.every(F))g.requestData={label:t,properties:m};else if($(m))g.requestData={label:t,data:m,options:s};else throw P(m)?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,c({requestId:y,path:l},g));let f=yield this.fetcher(l,g);return(x=this.logger)==null||x.call(this,u(c({requestId:y,path:l},g),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D}),upsert:(a,i)=>h(this,[a,i],function*({label:e,data:t,options:r,vectors:s},n){var R,x,q;let d=T(n),p="/records",l={headers:Object.assign({},b(d)),method:"POST",requestData:{}},g=typeof this.logger=="function"?S():"",y=M(v(t)),m=u(c({},r),{mergeBy:(R=r==null?void 0:r.mergeBy)!=null?R:[]});if(I(y)&&y.every(F))l.requestData=c({label:e,properties:y,options:m},(s==null?void 0:s.length)&&{vectors:s});else if($(y))l.requestData=c({label:e,data:y,options:m},(s==null?void 0:s.length)&&{vectors:s});else throw P(y)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(x=this.logger)==null||x.call(this,c({requestId:g,path:p},l));let f=yield this.fetcher(p,l);return(q=this.logger)==null||q.call(this,u(c({requestId:g,path:p},l),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D})};this.relationships={patterns:{list:()=>h(this,null,function*(){var n,a;let e="/relationships/patterns",t={method:"GET",headers:{}},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s}),analyze:()=>h(this,null,function*(){var n,a;let e="/relationships/patterns/analyze",t={method:"POST",headers:{},requestData:{}},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s}),approve:e=>h(this,null,function*(){var a,i;let t=`/relationships/patterns/${encodeURIComponent(e)}/approve`,r={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n}),ignore:e=>h(this,null,function*(){var a,i;let t=`/relationships/patterns/${encodeURIComponent(e)}/ignore`,r={method:"POST",headers:{},requestData:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n}),delete:(e,t)=>h(this,null,function*(){var d,p;let r=t!=null&&t.deleteExisting?"?deleteExisting=true":"",s=`/relationships/patterns/${encodeURIComponent(e)}${r}`,n={method:"DELETE",headers:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i})},createMany:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/relationships/create-many",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),deleteMany:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/relationships/delete-many",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),find:(...r)=>h(this,[...r],function*(e={},t){var p,l;let s=T(t),n="/relationships/search",a={headers:Object.assign({},b(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:i,path:n},a));let d=yield this.fetcher(n,a);return(l=this.logger)==null||l.call(this,u(c({requestId:i,path:n},a),{responseData:d.data})),d})};this.properties={delete:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s=`/properties/${e}`,n={headers:Object.assign({},b(r)),method:"DELETE"},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),find:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/properties/search",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),findById:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s=`/properties/${e}`,n={headers:Object.assign({},b(r)),method:"GET"},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),values:(e,t,r)=>h(this,null,function*(){var p,l;let s=T(r),n=`/properties/${e}/values`,a={headers:Object.assign({},b(s)),method:"POST",requestData:t!=null?t:{}},i=typeof this.logger=="function"?S():"";(p=this.logger)==null||p.call(this,c({requestId:i,path:n},a));let d=yield this.fetcher(n,a);return(l=this.logger)==null||l.call(this,u(c({requestId:i,path:n},a),{responseData:d.data})),d})};this.labels={find:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/labels/search",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i})};this.tx={begin:e=>h(this,null,function*(){var a,i;let t="/tx",r={method:"POST",requestData:P(e)&&"ttl"in e?e:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),new U(n.data.id)}),commit:e=>h(this,null,function*(){var i,d;let r=`/tx/${T(e)}/commit`,s={method:"POST",requestData:{}},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),a}),get:e=>h(this,null,function*(){var i,d;let r=`/tx/${T(e)}`,s={method:"GET"},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),new U(a.data.id)}),rollback:e=>h(this,null,function*(){var i,d;let r=`/tx/${T(e)}/rollback`,s={method:"POST",requestData:{}},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),a})};this.settings={get:()=>h(this,null,function*(){var n,a;let e="/sdk/settings",t={method:"GET"},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s})};this.query={raw:(s,n)=>h(this,[s,n],function*({query:e,params:t},r){var g,y;let a=T(r),i="/query/raw",d={headers:Object.assign({},b(a)),method:"POST",requestData:{query:e,params:t}},p=typeof this.logger=="function"?S():"";(g=this.logger)==null||g.call(this,c({requestId:p,path:i},d));let l=yield this.fetcher(i,d);return(y=this.logger)==null||y.call(this,u(c({requestId:p,path:i},d),{responseData:l.data})),l})};this.ai={getSchema:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/ai/schema",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),getSchemaMarkdown:(e,t)=>h(this,null,function*(){var d,p;let r=T(t),s="/ai/schema/md",n={headers:Object.assign({},b(r)),method:"POST",requestData:e!=null?e:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);return(p=this.logger)==null||p.call(this,u(c({requestId:a,path:s},n),{responseData:i.data})),i}),indexes:{find:()=>h(this,null,function*(){var n,a;let e="/ai/indexes",t={method:"GET",headers:{}},r=typeof this.logger=="function"?S():"";(n=this.logger)==null||n.call(this,c({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(a=this.logger)==null||a.call(this,u(c({requestId:r,path:e},t),{responseData:s.data})),s}),create:e=>h(this,null,function*(){var l,g;let t="/ai/indexes",p=e,{external:r}=p,s=V(p,["external"]),n=r===!0?u(c({},s),{sourceType:"external"}):s,a={method:"POST",headers:{},requestData:n},i=typeof this.logger=="function"?S():"";(l=this.logger)==null||l.call(this,c({requestId:i,path:t},a));let d=yield this.fetcher(t,a);return(g=this.logger)==null||g.call(this,u(c({requestId:i,path:t},a),{responseData:d.data})),d}),upsertVectors:(e,t)=>h(this,null,function*(){var i,d;let r=`/ai/indexes/${e}/vectors/upsert`,s={method:"POST",headers:{},requestData:t},n=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,c({requestId:n,path:r},s));let a=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,u(c({requestId:n,path:r},s),{responseData:a.data})),a}),delete:e=>h(this,null,function*(){var a,i;let t=`/ai/indexes/${e}`,r={method:"DELETE",headers:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n}),stats:e=>h(this,null,function*(){var a,i;let t=`/ai/indexes/${e}/stats`,r={method:"GET",headers:{}},s=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,c({requestId:s,path:t},r));let n=yield this.fetcher(t,r);return(i=this.logger)==null||i.call(this,u(c({requestId:s,path:t},r),{responseData:n.data})),n})},search:(e,t)=>h(this,null,function*(){var f,R,x,q,re,se;let r=T(t==null?void 0:t.transaction),s="/ai/search-query",n={method:"POST",headers:Object.assign({},b(r)),requestData:{prompt:e,currentQuery:t==null?void 0:t.currentQuery}},a=typeof this.logger=="function"?S():"";(f=this.logger)==null||f.call(this,c({requestId:a,path:s},n));let i=yield this.fetcher(s,n);(R=this.logger)==null||R.call(this,u(c({requestId:a,path:s},n),{responseData:i.data}));let d=i.data.searchQuery,p="/records/search",l={method:"POST",headers:Object.assign({},b(r)),requestData:d!=null?d:{}},g=typeof this.logger=="function"?S():"";(x=this.logger)==null||x.call(this,c({requestId:g,path:p},l));let y=yield this.fetcher(p,l);(q=this.logger)==null||q.call(this,u(c({requestId:g,path:p},l),{responseData:y.data}));let m=((re=y.data)!=null?re:[]).map(De=>new D(De));return new E(m,(se=y.total)!=null?se:0,d,i.data.warnings)})};if(this.fetcher=null,t!=null&&t.httpClient){let r=Re(t);this.fetcher=ue({httpClient:t.httpClient,token:e,url:r})}t!=null&&t.options&&(this.options=t==null?void 0:t.options),t!=null&&t.logger&&(this.logger=t==null?void 0:t.logger)}_extractTargetIds(e,t){var r;if(e instanceof D){let s=A(e);if(!s)throw new B(`${t} error: Target id is empty`);return[s]}if(I(e)&&e.every(s=>s instanceof D)){let s=e.map(A).filter(O);if(!s.length)throw new B(`${t} error: Target ids are empty`);return s}if(e instanceof E){let s=(r=e.data)==null?void 0:r.map(A).filter(O);if(!(s!=null&&s.length))throw new B(`${t} error: Target ids are empty`);return s}if(P(e)&&"__id"in e)return[e.__id];if(I(e)&&e.every(s=>P(s)&&"__id"in s)){let s=e.map(A).filter(O);if(!s.length)throw new B(`${t} error: Target ids are empty`);return s}return I(e)?e:_(e)?[e]:[]}};var Te,j=class j extends L{constructor(e,t){var n,a;let r=e!=null?e:typeof process!="undefined"?(n=process.env)==null?void 0:n.RUSHDB_API_KEY:void 0,s=le(t);super(r,u(c({},s),{httpClient:(a=s.httpClient)!=null?a:Te})),j.instance=this,this.initializeSync(r,s)}initializeSync(e,t){j.state={initialized:!0,debug:!1,timeout:he("timeout",t==null?void 0:t.timeout,8e4),token:e}}static getInstance(){if(j.instance)return j.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static isInitialized(){return O(j.instance)}toDBRecordInstance(e){return new D(e)}};j.instance=null,j.state={initialized:!1,debug:!1,timeout:8e4};var w=j,be=o=>{Te=o};var we=class{constructor(e,t,r){this.label=e,this.schema=t,this.config=r!=null?r:{}}getLabel(){return this.label}toDBRecordInstance(e){return h(this,null,function*(){try{return w.getInstance().toDBRecordInstance(e)}catch(t){throw new Error("No RushDB instance was provided during model initialization.")}})}find(e,t){return h(this,null,function*(){let r=e!=null?e:{};return w.getInstance().records.find(u(c({},r),{labels:[this.label]}),t)})}findOne(e,t){return h(this,null,function*(){let r=e!=null?e:{};return w.getInstance().records.findOne(u(c({},r),{labels:[this.label]}),t)})}findById(e,t){return h(this,null,function*(){return this.findOne({where:{$id:e}},t)})}findUniq(e,t){return h(this,null,function*(){let r=e!=null?e:{};return w.getInstance().records.findUniq(u(c({},r),{labels:[this.label]}),t)})}create(e,t,r){return h(this,null,function*(){var d,p;let s=yield J(this.schema,e),n=ee(this.schema,s),a=O(n),i=w.getInstance();if(a){let l=t!=null?t:yield i.tx.begin(),g=yield this.find({where:n},l),y=typeof t!="undefined";if(!((d=g==null?void 0:g.data)!=null&&d.length)){let f=yield i.records.create({label:this.label,data:s},l);return y||(yield l.commit()),f}else switch((p=r==null?void 0:r.onConflict)!=null?p:"throw"){case"upsert":{let R=g.data[0],x=yield i.records.set({target:R.id,label:this.label,data:s},l);return y||(yield l.commit()),x}case"skip":return y||(yield l.commit()),null;default:throw y||(yield l.commit()),new k(this.label,n)}}return yield i.records.create({label:this.label,data:s},t)})}attach(n,a){return h(this,arguments,function*({source:e,target:t,options:r},s){return yield w.getInstance().records.attach({source:e,target:t,options:r},s)})}detach(n,a){return h(this,arguments,function*({source:e,target:t,options:r},s){return yield w.getInstance().records.detach({source:e,target:t,options:r},s)})}validateTargetLabel(e,t){return h(this,null,function*(){let r=A(e);if(!r)return;let n=yield w.getInstance().records.findById(r,t);if(!n)throw new Error(`Record with id "${r}" not found.`);if(n.data.__label!==this.label)throw new TypeError(`Target record label "${n.data.__label}" does not match model label "${this.label}".`)})}handleSetOrUpdate(e,t,r,s){return h(this,null,function*(){var d,p;if(this.config.validateTargetLabel&&(yield this.validateTargetLabel(e,s)),I(t)&&t.every(F))return yield w.getInstance().records[r]({label:this.label,target:e,data:t},s);let n=w.getInstance(),a=yield J(this.schema,t),i=ee(this.schema,a);if(!H(i)){let l=s!=null?s:yield n.tx.begin(),g=yield this.find({where:i},l),y=typeof s!="undefined";if(!((d=g==null?void 0:g.data)!=null&&d.length)||g.data.length===1&&((p=g.data[0])==null?void 0:p.id)===A(e)){let f=yield n.records[r]({target:e,label:this.label,data:a},l);return y||(yield l.commit()),f}else throw y||(yield l.commit()),new k(this.label,i)}return yield n.records[r]({label:this.label,target:e,data:a},s)})}set(e,t,r){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,t,"set",r)})}update(e,t,r){return h(this,null,function*(){return yield this.handleSetOrUpdate(e,t,"update",r)})}createMany(e,t){return h(this,null,function*(){var a;let r=w.getInstance(),s=typeof t!="undefined",n=t!=null?t:yield r.tx.begin();try{let i=yield Promise.all(e.map(l=>h(this,null,function*(){return yield J(this.schema,l)}))),d=pe(i,this.schema,this.label);if(!H(d)){let l=Object.entries(d).map(([y,m])=>({[y]:{$in:m}})),g=yield this.find({where:{$or:l}},n);if((a=g==null?void 0:g.data)!=null&&a.length)throw new k(this.label,Object.keys(d))}let p=yield r.records.createMany({label:this.label,data:i},n);return s||(yield n.commit()),p}catch(i){throw s||(yield n.rollback()),i}})}delete(e,t){return h(this,null,function*(){if(H(e.where))throw new B(`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 w.getInstance().records.delete(u(c({},e),{labels:[this.label]}),t)})}deleteById(e,t){return h(this,null,function*(){return yield w.getInstance().records.deleteById(e,t)})}};be(new N);var $t=w;export{D as DBRecordInstance,E as DBRecordsArrayInstance,B as EmptyTargetError,C as HttpClient,Y as HttpClientResponse,we as Model,K as NonUniqueResultError,L as RestAPI,w as RushDB,U as Transaction,k as UniquenessError,$t as default,ge as idToDate,te as idToTimestamp,be as initSDK,J as mergeDefaultsWithPayload,le as parseConfig,ee as pickUniqFieldsFromRecord,pe as pickUniqFieldsFromRecords,he as validateInteger};
|
package/dist/index.node.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpClient, HttpClientResponse } from './network/HttpClient.js';
|
|
2
2
|
import { RushDB } from './sdk/index.js';
|
|
3
|
-
import { type ApiResponse, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndex, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult, RestAPI } from './api/index.js';
|
|
4
|
-
export { RushDB, HttpClient, HttpClientResponse, RestAPI, type ApiResponse, type EmbeddingIndex, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult };
|
|
3
|
+
import { type ApiResponse, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndex, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult, type VectorSearchParams, type VectorSearchResult, RestAPI } from './api/index.js';
|
|
4
|
+
export { RushDB, HttpClient, HttpClientResponse, RestAPI, type ApiResponse, type EmbeddingIndex, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult, type VectorSearchParams, type VectorSearchResult };
|
|
5
5
|
export * from './types/index.js';
|
|
6
6
|
export * from './sdk/index.js';
|
|
7
7
|
export default RushDB;
|
package/dist/index.worker.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpClient, HttpClientResponse } from './network/HttpClient.js';
|
|
2
2
|
import { RushDB } from './sdk/index.js';
|
|
3
|
-
import { type ApiResponse, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndex, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult, RestAPI } from './api/index.js';
|
|
4
|
-
export { RushDB, HttpClient, HttpClientResponse, RestAPI, type ApiResponse, type EmbeddingIndex, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult };
|
|
3
|
+
import { type ApiResponse, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndex, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult, type VectorSearchParams, type VectorSearchResult, RestAPI } from './api/index.js';
|
|
4
|
+
export { RushDB, HttpClient, HttpClientResponse, RestAPI, type ApiResponse, type EmbeddingIndex, type CreateEmbeddingIndexParams, type DeleteRelationshipPatternOptions, type EmbeddingIndexStats, type RelationshipPattern, type RelationshipPatternDirection, type RelationshipPatternDto, type RelationshipPatternEndpoint, type RelationshipPatternListResponse, type RelationshipPatternMode, type RelationshipPatternOrigin, type RelationshipPatternStatus, type SemanticSearchParams, type SemanticSearchResult, type UpsertEmbeddingVectorItem, type UpsertEmbeddingVectorsParams, type UpsertEmbeddingVectorsResult, type VectorSearchParams, type VectorSearchResult };
|
|
5
5
|
export * from './types/index.js';
|
|
6
6
|
export * from './sdk/index.js';
|
|
7
7
|
export default RushDB;
|
package/dist/sdk/record.d.ts
CHANGED
|
@@ -201,6 +201,8 @@ export declare class DBRecordsArrayInstance<S extends Schema = Schema, Q extends
|
|
|
201
201
|
total: number;
|
|
202
202
|
/** The search query that was used to retrieve these records */
|
|
203
203
|
searchQuery?: SearchQuery<S>;
|
|
204
|
+
/** Warnings returned by AI-assisted query generation, when applicable. */
|
|
205
|
+
warnings?: string[];
|
|
204
206
|
/**
|
|
205
207
|
* Creates a new DBRecordsArrayInstance.
|
|
206
208
|
* Typically, you don't create these directly but receive them from query results.
|
|
@@ -209,7 +211,7 @@ export declare class DBRecordsArrayInstance<S extends Schema = Schema, Q extends
|
|
|
209
211
|
* @param total - The total number of records matching the query
|
|
210
212
|
* @param searchQuery - The search query that was used to retrieve these records
|
|
211
213
|
*/
|
|
212
|
-
constructor(data?: Array<DBRecordInstance<S, Q>>, total?: number, searchQuery?: SearchQuery<S
|
|
214
|
+
constructor(data?: Array<DBRecordInstance<S, Q>>, total?: number, searchQuery?: SearchQuery<S>, warnings?: string[]);
|
|
213
215
|
/**
|
|
214
216
|
* Deletes all records in this result set.
|
|
215
217
|
*
|