@rushdb/javascript-sdk 1.17.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api/api.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { HttpClient } from '../network/HttpClient.js';
2
2
  import type { DBRecordCreationOptions, DBRecordTarget, Relation, RelationDetachOptions, RelationDirection, RelationOptions, RelationTarget } from '../sdk/record.js';
3
3
  import { DBRecordInstance, DBRecordsArrayInstance } from '../sdk/record.js';
4
4
  import type { SDKConfig } from '../sdk/types.js';
5
- import type { AnyObject, FlatObject, InferSchemaTypesWrite, MaybeArray, OrderDirection, Property, PropertyDraft, PropertyValuesData, Schema, SearchQuery, Where } from '../types/index.js';
5
+ import type { FlatObject, InferSchemaTypesWrite, MaybeArray, OrderDirection, Property, PropertyDraft, PropertyValuesData, Schema, SearchQuery, Where } from '../types/index.js';
6
6
  import type { ApiResponse } from './types.js';
7
7
  import { createFetcher } from '../network/index.js';
8
8
  import { Transaction } from '../sdk/transaction.js';
@@ -67,17 +67,41 @@ export declare class RestAPI {
67
67
  options?: Omit<DBRecordCreationOptions, "returnResult" | "capitalizeLabels" | "relationshipType">;
68
68
  }, transaction?: Transaction | string) => Promise<DBRecordInstance<S>>;
69
69
  /**
70
- * Creates multiple records in a single operation
71
- * @param data - Object containing label, options and data array or object for multiple records
70
+ * Creates multiple flat records in a single operation.
71
+ * Use this only for CSV-like flat rows (no nested objects/arrays).
72
+ * For nested/complex JSON, use `records.importJson`.
73
+ *
74
+ * @param data - Object containing label, options and data array (of flat objects)
72
75
  * @param data.label - The label/type for all records
73
76
  * @param data.options - Optional write configuration
74
- * @param data.data - Array of record data to create
77
+ * @param data.data - Array of flat record data to create
75
78
  * @param transaction - Optional transaction for atomic operations
76
79
  * @returns Promise resolving to DBRecordsArrayInstance containing created records
80
+ * @throws Error if any record is not flat. Use `records.importJson` for nested JSON.
77
81
  */
78
82
  createMany: <S extends Schema = any>(data: {
79
83
  label: string;
80
- data: MaybeArray<AnyObject>;
84
+ data: Array<InferSchemaTypesWrite<S>>;
85
+ options?: DBRecordCreationOptions;
86
+ }, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S>>;
87
+ /**
88
+ * Import nested or complex JSON payloads.
89
+ * Works in two modes:
90
+ * - With `label` provided
91
+ * - Without `label`: expects an object with a single top-level key used as the label, e.g. { ITEM: [...] }
92
+ *
93
+ * Throws if `label` is missing and the input does not conform to the single-key rule
94
+ * (e.g. { some: 'key', data: 1, nested: { level: 2 } }).
95
+ *
96
+ * @example
97
+ * // with label
98
+ * await db.records.importJson({ label: 'ITEM', data: [{...}, {...}] })
99
+ * // without label
100
+ * await db.records.importJson({ data: { ITEM: [{...}, {...}] } })
101
+ */
102
+ importJson: <S extends Schema = any>(params: {
103
+ data: any;
104
+ label?: string;
81
105
  options?: DBRecordCreationOptions;
82
106
  }, transaction?: Transaction | string) => Promise<DBRecordsArrayInstance<S>>;
83
107
  /**
@@ -196,6 +220,26 @@ export declare class RestAPI {
196
220
  data: Partial<InferSchemaTypesWrite<S>> | Array<PropertyDraft>;
197
221
  options?: Omit<DBRecordCreationOptions, "returnResult" | "capitalizeLabels" | "relationshipType">;
198
222
  }, transaction?: Transaction | string) => Promise<DBRecordInstance<S, SearchQuery<S>>>;
223
+ /**
224
+ * Upserts a record: attempts to find an existing record matching mergeBy property values (and optional label)
225
+ * If found: mergeStrategy determines behavior.
226
+ * - 'rewrite': replaces all existing own properties with incoming (like set)
227
+ * - 'append': updates/adds provided properties, keeps others
228
+ * If not found: creates a new record.
229
+ * @param label - The label/type of the record
230
+ * @param data - Flat object or array of property drafts
231
+ * @param options.mergeBy - Property names to match on; If `[]`, all incoming keys are used for matching.
232
+ * @param options.mergeStrategy - 'rewrite' | 'append'
233
+ * @param transaction - Optional transaction for atomic operations
234
+ */
235
+ upsert: <S extends Schema = any>({ label, data: rawData, options }: {
236
+ label?: string;
237
+ data: InferSchemaTypesWrite<S> | Array<PropertyDraft>;
238
+ options?: Omit<DBRecordCreationOptions, "returnResult" | "capitalizeLabels" | "relationshipType"> & {
239
+ mergeBy?: string[];
240
+ mergeStrategy?: "rewrite" | "append";
241
+ };
242
+ }, transaction?: Transaction | string) => Promise<DBRecordInstance<S>>;
199
243
  };
200
244
  /**
201
245
  * API methods for managing relations between records
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var Se=Object.create;var M=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var be=(n,e)=>{for(var t in e)M(n,t,{get:e[t],enumerable:!0})},se=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Te(e))!we.call(n,r)&&r!==t&&M(n,r,{get:()=>e[r],enumerable:!(s=Re(e,r))||s.enumerable});return n};var ne=(n,e,t)=>(t=n!=null?Se(De(n)):{},se(e||!n||!n.__esModule?M(t,"default",{value:n,enumerable:!0}):t,n)),Ie=n=>se(M({},"__esModule",{value:!0}),n);var He={};be(He,{DBRecordInstance:()=>f,DBRecordsArrayInstance:()=>b,EmptyTargetError:()=>w,HttpClient:()=>P,HttpClientResponse:()=>v,Model:()=>re,NonUniqueResultError:()=>k,RestAPI:()=>_,RushDB:()=>D,Transaction:()=>B,UniquenessError:()=>A,default:()=>Me,extractMixedPropertiesFromToken:()=>ee,idToDate:()=>Z,idToTimestamp:()=>W,initSDK:()=>te,mergeDefaultsWithPayload:()=>U,parseConfig:()=>G,pickUniqFieldsFromRecord:()=>N,pickUniqFieldsFromRecords:()=>J,validateInteger:()=>X});module.exports=Ie(He);var P=class n{makeRequest(e,{headers:t,method:s,protocol:r,requestData:o,timeout:i}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(n.TIMEOUT_ERROR_CODE);return e.code=n.TIMEOUT_ERROR_CODE,e}};P.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];P.TIMEOUT_ERROR_CODE="ETIMEDOUT";var H=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.")}},v=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 V=ne(require("http"),1),Y=ne(require("https"),1);var xe="string",Oe="datetime",Pe="boolean",Ee="number",Ae="null",Be="vector",ae=[xe,Oe,Pe,Ee,Ae,Be];var ie=V.default||V,ce=Y.default||Y,_e=new ie.Agent({keepAlive:!0}),Ce=new ce.Agent({keepAlive:!0}),F=class extends P{constructor(e){super(),this._agent=e}makeRequest(e,{headers:t,method:s,protocol:r,requestData:o,timeout:i}){let a=new URL(e),c=r==="http"||a.protocol==="http:",d=this._agent;return d||(d=c?_e:Ce),new Promise((p,h)=>{let l=(c?ie:ce).request({agent:d,ciphers:"DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5",headers:t,host:a.hostname,method:s,path:a.pathname+a.search,port:a.port});l.setTimeout(i!=null?i:8e4,()=>{l.destroy(P.makeTimeoutError())}),l.on("response",m=>{p(new K(m))}),l.on("error",m=>{h(m)}),l.once("socket",m=>{let x=o?JSON.stringify(o):"";m.connecting?m.once(c?"connect":"secureConnect",()=>{l.write(x),l.end()}):(l.write(x),l.end())})})}},K=class extends H{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 S=n=>typeof n=="object"&&Array.isArray(n)&&n!==null,R=n=>n!==null&&Object.prototype.toString.call(n)==="[object Object]",q=n=>R(n)&&Object.keys(n).length===0,de=n=>typeof n=="number"||typeof n=="string"||typeof n=="boolean"||n===null;function qe(n,e){let t={...n};return e.forEach(s=>{delete t[s]}),t}var L=n=>R(n)?qe(n,["__label","__id","__proptypes"]):n,C=n=>S(n)?n.map(C):R(n)?Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>[e,C(t)])):n,Q=n=>S(n)?n.every(de):de(n),$=n=>R(n)&&Object.values(n).every(Q),E=n=>typeof n=="string",T=n=>{if(typeof n=="string"){if(n.toLowerCase()==="true")return!0;if(n.toLowerCase()==="false")return!1}return S(n)&&n.length===0||R(n)&&Object.keys(n).length===0?!1:!!n};var z=["httpClient","timeout","host","port","protocol","url","logger","options"],pe={initial:"in",extended:"ex",fullFeatured:"ff"};var A=class n extends Error{constructor(e,t){super(`Record with label "${e}" and properties ${JSON.stringify(t)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,n.prototype)}},w=class n extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,n.prototype)}},k=class n 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,n.prototype)}};var U=async(n,e)=>{let t=Object.entries(n).map(async([o,i])=>i.default&&typeof i.default<"u"&&typeof e[o]>"u"?{key:o,value:typeof i.default=="function"?await i.default():i.default}:{key:o,value:void 0});return{...(await Promise.all(t)).reduce((o,{key:i,value:a})=>(a!==void 0&&(o[i]=a),o),{}),...e}},N=(n,e)=>Object.entries(e).filter(([t])=>{var s;return(s=n[t])==null?void 0:s.unique}).reduce((t,[s,r])=>(s in n&&(t[s]=r),t),{}),J=(n,e,t)=>{let s={},r=Object.entries(e).filter(([,o])=>o.unique).reduce((o,[i])=>(o[i]=!0,o),{});return n.forEach(o=>{Object.entries(o).forEach(([i,a])=>{if(i in r)if(s[i]){if(s[i].includes(a))throw new A(t,{[i]:a});s[i]=[...s[i],a]}else s[i]=[a]})}),s},G=n=>{if(!n)return{};if(!R(n))throw new Error("Config must be an object");if(Object.keys(n).filter(t=>!z.includes(t)).length>0)throw new Error(`Config object may only contain the following: ${z.join(", ")}`);return n};function X(n,e,t){if(!Number.isInteger(e)){if(t!==void 0)return t;throw new Error(`${n} must be an integer`)}return e}function W(n){let e=n.split("-"),t=e[0]+e[1].slice(0,4);return parseInt(t,16)}function Z(n){return new Date(W(n))}function ee(n){let e=/^([a-z]{2})_([01]{3}\d{0,})_(.+)$/,t=n.match(e);if(!t)return[null,n];let[,s,r,o]=t,a=Object.entries(pe).find(([l,m])=>m===s)[0],[c,d,p]=r.split("");return[{...{customDB:c==="1",managedDB:d==="1",selfHosted:p==="1",planType:a}},o]}var f=class{constructor(e={}){this.data=e}exists(){return T(this.data.__id)&&T(this.data.__label)}id(){if(!T(this.data.__id))throw new Error("DBRecordInstance: Unable to access 'id'. The Record's `data.__id` is missing or incorrect.");return this.data.__id}label(){if(!T(this.data.__label))throw new Error("DBRecordInstance: Unable to access 'label'. The Record's `data.__label` is missing or incorrect.");return this.data.__label}proptypes(){if(!T(this.data.__proptypes))throw new Error("DBRecordInstance: Unable to access 'proptypes'. The Record's `data.__proptypes` is missing or incorrect.");return this.data.__proptypes}date(){try{return Z(this.id())}catch{throw new Error("DBRecordInstance: Unable to access 'date'. The Record's `data.__id` is missing or incorrect.")}}timestamp(){try{return W(this.id())}catch{throw new Error("DBRecordInstance: Unable to access 'timestamp'. The Record's `data.__id` is missing or incorrect.")}}async delete(e){if(!T(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return await D.init().records.deleteById(this.id(),e)}async update(e,t){if(!T(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return D.init().records.update({label:this.label(),target:this.id(),data:e},t)}async set(e,t){if(!T(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return D.init().records.set({label:this.label(),target:this.id(),data:e},t)}async attach(e,t,s){if(!T(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return D.init().records.attach({source:this.id(),target:e,options:t},s)}async detach(e,t,s){if(!T(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return D.init().records.detach({source:this.id(),target:e,options:t},s)}},b=class{constructor(e=[],t=0,s){this.data=e,this.total=t,this.searchQuery=s}};var je={"Content-Type":"application/json"},le=({httpClient:n,token:e,url:t})=>async(s,{headers:r,...o})=>{let i=await n.makeRequest(`${t}${s}`,{credentials:"omit",headers:Object.assign({...je,...r},typeof e<"u"?{token:e}:{}),...o});if(i.getStatusCode()>=200&&i.getStatusCode()<300)return await i.toJSON();throw new Error(`${i.getStatusCode()}`)};var B=class{constructor(e){this.id=e}async rollback(){return await D.init().tx.rollback(this.id)}async commit(){return await D.init().tx.commit(this.id)}};var he="api.rushdb.com";var ue="https",ge="/api/v1";var y=n=>n?{"x-transaction-id":n}:void 0,Ue=n=>E(n)||n instanceof B,g=n=>Ue(n)?n instanceof B?n.id:n:void 0,ye=n=>/^[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(n),I=n=>{if(E(n)&&ye(n))return n;if(n instanceof f&&n.data)return n.data.__id;if(R(n)&&"__id"in n&&ye(n.__id))return n.__id},j=n=>!(!R(n)||R(n)&&"name"in n&&!E(n.name)||R(n)&&"type"in n&&(!E(n.type)||!ae.includes(n.type))||!("value"in n)||!Q(n.value)||"metadata"in n&&!E(n.metadata)||"valueSeparator"in n&&!E(n.valueSeparator)),fe=n=>{let e=ue,t=he,s=443,r=ge;if("url"in n){let i=new URL(n.url);e=i.protocol.replace(":",""),t=i.hostname,s=parseInt(i.port||(e==="http"?"80":e==="https"?"443":""))}"host"in n&&"port"in n&&"protocol"in n&&(e=n.protocol.replace(":",""),t=n.host,s=n.port),r&&!r.startsWith("/")&&(r="/"+r);let o="";return e==="http"&&s===80||e==="https"&&s===443||(o=":"+s),`${e}://${t}${o}${r}`},u=(n=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let s=0;s<n;s++){let r=Math.floor(Math.random()*e.length);t+=e[r]}return t};var _=class{constructor(e,t){this.records={attach:async({source:e,target:t,options:s},r)=>{var h,l;let o=g(r),a=`/relationships/${I(e)}`,c={headers:Object.assign({},y(o)),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}}},d=typeof this.logger=="function"?u():"";(h=this.logger)==null||h.call(this,{requestId:d,path:a,...c});let p=await this.fetcher(a,c);return(l=this.logger)==null||l.call(this,{requestId:d,path:a,...c,responseData:p.data}),p},detach:async({source:e,target:t,options:s},r)=>{var h,l;let o=g(r),a=`/relationships/${I(e)}`,c={headers:Object.assign({},y(o)),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"?u():"";(h=this.logger)==null||h.call(this,{requestId:d,path:a,...c});let p=await this.fetcher(a,c);return(l=this.logger)==null||l.call(this,{requestId:d,path:a,...c,responseData:p.data}),p},create:async({label:e,data:t,options:s},r)=>{var h,l;let o=g(r),i="/records",a={headers:Object.assign({},y(o)),method:"POST",requestData:{}},c=typeof this.logger=="function"?u():"",d=L(C(t));if(S(d)&&d.every(j))a.requestData={label:e,properties:d};else if($(d))a.requestData={label:e,data:d,options:s};else throw R(d)?new Error("Provided data is not a flat object. Consider to use `createMany` method."):new Error("Provided data is not valid.");(h=this.logger)==null||h.call(this,{requestId:c,path:i,...a});let p=await this.fetcher(i,a);return(l=this.logger)==null||l.call(this,{requestId:c,path:i,...a,responseData:p.data}),p!=null&&p.success&&(p!=null&&p.data)?new f(p.data):new f},createMany:async(e,t)=>{var c,d,p;let s=g(t),r="/records/import/json",o={headers:Object.assign({},y(s)),method:"POST",requestData:e},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);if((d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a!=null&&a.success&&(a!=null&&a.data)){let h=S(a.data)?(p=a.data)==null?void 0:p.map(l=>new f(l)):[];return new b(h,a.total)}return new b([])},importCsv:async(e,t)=>{var c,d;let s=g(t),r="/records/import/csv",o={headers:Object.assign({},y(s)),method:"POST",requestData:e},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);if((d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a!=null&&a.success&&(a!=null&&a.data)){let p=S(a.data)?a.data.map(h=>new f(h)):[];return new b(p,a.total)}return new b([])},delete:async(e,t)=>{var c,d,p;if(q(e.where)&&!((c=this==null?void 0:this.options)!=null&&c.allowForceDelete))throw new w("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let s=g(t),r="/records/delete",o={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?u():"";(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(p=this.logger)==null||p.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},deleteById:async(e,t)=>{var d,p;let s=g(t),r=S(e),o=r?"/records/delete":`/records/${e}`,i={headers:Object.assign({},y(s)),method:r?"POST":"DELETE",requestData:r?{limit:1e3,where:{$id:{$in:e}}}:void 0},a=typeof this.logger=="function"?u():"";(d=this.logger)==null||d.call(this,{requestId:a,path:o,...i});let c=await this.fetcher(o,i);return(p=this.logger)==null||p.call(this,{requestId:a,path:o,...i,responseData:c.data}),c},export:async(e,t)=>{var c,d;let s=g(t),r="/records/export/csv",o={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},find:async(e,t)=>{var h,l;let{id:s,...r}=e,o=g(t),i=s?`/records/${s}/search`:"/records/search",a={headers:Object.assign({},y(o)),method:"POST",requestData:r!=null?r:{}},c=typeof this.logger=="function"?u():"";(h=this.logger)==null||h.call(this,{requestId:c,path:i,...a});let d=await this.fetcher(i,a);(l=this.logger)==null||l.call(this,{requestId:c,path:i,...a,responseData:d.data});let p=d.data.map(m=>new f(m));return new b(p,d.total,e)},findById:async(e,t)=>{var c,d;let s=g(t),r=S(e)?"/records":`/records/${e}`,o={headers:Object.assign({},y(s)),method:S(e)?"POST":"GET",requestData:S(e)?{ids:e}:void 0},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);if((d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),S(e)){let p=a.data.map(h=>new f(h));return new b(p,a.total)}else return new f(a.data)},findOne:async(e,t)=>{var d,p;let s=g(t),r="/records/search",o={headers:Object.assign({},y(s)),method:"POST",requestData:{...e,limit:1,skip:0}},i=typeof this.logger=="function"?u():"";(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);(p=this.logger)==null||p.call(this,{requestId:i,path:r,...o,responseData:a.data});let[c]=a.data;return new f(c)},findUniq:async(e,t)=>{var d,p;let s=g(t),r="/records/search",o={headers:Object.assign({},y(s)),method:"POST",requestData:{...e,limit:1,skip:0}},i=typeof this.logger=="function"?u():"";(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);if((p=this.logger)==null||p.call(this,{requestId:i,path:r,...o,responseData:a.data}),typeof a.total<"u"&&a.total>1)throw new k(a.total,e);let[c]=a.data;return new f(c)},set:async({target:e,label:t,data:s,options:r},o)=>{var m,x;let i=g(o),c=`/records/${I(e)}`,d={headers:Object.assign({},y(i)),method:"PUT",requestData:{}},p=typeof this.logger=="function"?u():"",h=L(C(s));if(S(h)&&h.every(j))d.requestData={label:t,properties:h};else if($(h))d.requestData={label:t,data:h,options:r};else throw R(h)?new Error("Provided data is not a flat object. Consider to use `createMany` method."):new Error("Provided data is not valid.");(m=this.logger)==null||m.call(this,{requestId:p,path:c,...d});let l=await this.fetcher(c,d);return(x=this.logger)==null||x.call(this,{requestId:p,path:c,...d,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)?new f(l.data):new f},update:async({target:e,label:t,data:s,options:r},o)=>{var m,x;let i=g(o),c=`/records/${I(e)}`,d={headers:Object.assign({},y(i)),method:"PATCH",requestData:{}},p=typeof this.logger=="function"?u():"",h=L(C(s));if(S(h)&&h.every(j))d.requestData={label:t,properties:h};else if($(h))d.requestData={label:t,data:h,options:r};else throw R(h)?new Error("Provided data is not a flat object. Consider to use `createMany` method."):new Error("Provided data is not valid.");(m=this.logger)==null||m.call(this,{requestId:p,path:c,...d});let l=await this.fetcher(c,d);return(x=this.logger)==null||x.call(this,{requestId:p,path:c,...d,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)?new f(l.data):new f}};this.relationships={createMany:async(e,t)=>{var c,d;let s=g(t),r="/relationships/create-many",o={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},deleteMany:async(e,t)=>{var c,d;let s=g(t),r="/relationships/delete-many",o={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},find:async(e,t)=>{var p,h;let s=g(t),r=new URLSearchParams;(e==null?void 0:e.limit)!==void 0&&r.append("limit",e.limit.toString()),(e==null?void 0:e.skip)!==void 0&&r.append("skip",e.skip.toString());let i=`/relationships/search${r.toString()?"?"+r.toString():""}`,a={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},c=typeof this.logger=="function"?u():"";(p=this.logger)==null||p.call(this,{requestId:c,path:i,...a});let d=await this.fetcher(i,a);return(h=this.logger)==null||h.call(this,{requestId:c,path:i,...a,responseData:d.data}),d}};this.properties={delete:async(e,t)=>{var c,d;let s=g(t),r=`/properties/${e}`,o={headers:Object.assign({},y(s)),method:"DELETE"},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},find:async(e,t)=>{var c,d;let s=g(t),r="/properties/search",o={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},findById:async(e,t)=>{var c,d;let s=g(t),r=`/properties/${e}`,o={headers:Object.assign({},y(s)),method:"GET"},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a},values:async(e,t,s)=>{var d,p;let r=g(s),o=`/properties/${e}/values`,i={headers:Object.assign({},y(r)),method:"POST",requestData:t!=null?t:{}},a=typeof this.logger=="function"?u():"";(d=this.logger)==null||d.call(this,{requestId:a,path:o,...i});let c=await this.fetcher(o,i);return(p=this.logger)==null||p.call(this,{requestId:a,path:o,...i,responseData:c.data}),c}};this.labels={find:async(e,t)=>{var c,d;let s=g(t),r="/labels/search",o={headers:Object.assign({},y(s)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?u():"";(c=this.logger)==null||c.call(this,{requestId:i,path:r,...o});let a=await this.fetcher(r,o);return(d=this.logger)==null||d.call(this,{requestId:i,path:r,...o,responseData:a.data}),a}};this.tx={begin:async e=>{var i,a;let t="/tx",s={method:"POST",requestData:R(e)&&"ttl"in e?e:{}},r=typeof this.logger=="function"?u():"";(i=this.logger)==null||i.call(this,{requestId:r,path:t,...s});let o=await this.fetcher(t,s);return(a=this.logger)==null||a.call(this,{requestId:r,path:t,...s,responseData:o.data}),new B(o.data.id)},commit:async e=>{var a,c;let s=`/tx/${g(e)}/commit`,r={method:"POST",requestData:{}},o=typeof this.logger=="function"?u():"";(a=this.logger)==null||a.call(this,{requestId:o,path:s,...r});let i=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...r,responseData:i.data}),i},get:async e=>{var a,c;let s=`/tx/${g(e)}`,r={method:"GET"},o=typeof this.logger=="function"?u():"";(a=this.logger)==null||a.call(this,{requestId:o,path:s,...r});let i=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...r,responseData:i.data}),new B(i.data.id)},rollback:async e=>{var a,c;let s=`/tx/${g(e)}/rollback`,r={method:"POST",requestData:{}},o=typeof this.logger=="function"?u():"";(a=this.logger)==null||a.call(this,{requestId:o,path:s,...r});let i=await this.fetcher(s,r);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...r,responseData:i.data}),i}};this.settings={get:async()=>{var o,i;let e="/sdk/settings",t={method:"GET"},s=typeof this.logger=="function"?u():"";(o=this.logger)==null||o.call(this,{requestId:s,path:e,...t});let r=await this.fetcher(e,t);return(i=this.logger)==null||i.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=g(s),o="/query/raw",i={headers:Object.assign({},y(r)),method:"POST",requestData:{query:e,params:t}},a=typeof this.logger=="function"?u():"";(d=this.logger)==null||d.call(this,{requestId:a,path:o,...i});let c=await this.fetcher(o,i);return(p=this.logger)==null||p.call(this,{requestId:a,path:o,...i,responseData:c.data}),c}};if(this.fetcher=null,t!=null&&t.httpClient){let s=fe(t);this.fetcher=le({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 f){let r=I(e);if(!r)throw new w(`${t} error: Target id is empty`);return[r]}if(S(e)&&e.every(r=>r instanceof f)){let r=e.map(I).filter(T);if(!r.length)throw new w(`${t} error: Target ids are empty`);return r}if(e instanceof b){let r=(s=e.data)==null?void 0:s.map(I).filter(T);if(!(r!=null&&r.length))throw new w(`${t} error: Target ids are empty`);return r}if(R(e)&&"__id"in e)return[e.__id];if(S(e)&&e.every(r=>R(r)&&"__id"in r)){let r=e.map(I).filter(T);if(!r.length)throw new w(`${t} error: Target ids are empty`);return r}return S(e)?e:E(e)?[e]:[]}};var me,O=class O extends _{constructor(e,t){var o;let s=G(t);super(e,{...s,httpClient:(o=s.httpClient)!=null?o:me}),O.instance=this;let[r]=ee(e!=null?e:"");this.initializeSync(r,e,s)}initializeSync(e,t,s){let r=e?{planType:e.planType,customDB:e.customDB,managedDB:e.managedDB,selfHosted:e.selfHosted}:null;O.state={initialized:!0,debug:!1,timeout:X("timeout",s==null?void 0:s.timeout,8e4),token:t,...r&&{serverSettings:r}}}static init(){if(O.instance)return O.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static getInstance(){return O.instance}static isInitialized(){return O.instance!==null}toDBRecordInstance(e){return new f(e)}};O.instance=null,O.state={initialized:!1,debug:!1,timeout:8e4};var D=O,te=n=>{me=n};var re=class{constructor(e,t){this.label=e,this.schema=t}getLabel(){return this.label}async getRushDBInstance(){if(D.getInstance())return D.init();throw new Error('No RushDB instance found. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}async toDBRecordInstance(e){try{return(await this.getRushDBInstance()).toDBRecordInstance(e)}catch{throw new Error("No RushDB instance was provided during model initialization.")}}async find(e,t){let s=e!=null?e:{};return(await this.getRushDBInstance()).records.find({...s,labels:[this.label]},t)}async findOne(e,t){let s=e!=null?e:{};return(await this.getRushDBInstance()).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(await this.getRushDBInstance()).records.findUniq({...s,labels:[this.label]},t)}async create(e,t){var a;let s=await U(this.schema,e),r=N(this.schema,s),o=T(r),i=await this.getRushDBInstance();if(o){let c=t!=null?t:await i.tx.begin(),d=await this.find({where:r},c),p=typeof t<"u";if(!((a=d==null?void 0:d.data)!=null&&a.length)){let l=await i.records.create({label:this.label,data:s},c);return p||await c.commit(),l}else throw p||await c.commit(),new A(this.label,r)}return await i.records.create({label:this.label,data:s},t)}async attach({source:e,target:t,options:s},r){return await(await this.getRushDBInstance()).records.attach({source:e,target:t,options:s},r)}async detach({source:e,target:t,options:s},r){return await(await this.getRushDBInstance()).records.detach({source:e,target:t,options:s},r)}async handleSetOrUpdate(e,t,s,r){var c,d;if(S(t)&&t.every(j))throw new Error(`Model.${s} with Array<PropertyDraft> as payload is not implemented yet.`);let o=await this.getRushDBInstance(),i=await U(this.schema,t),a=N(this.schema,i);if(!q(a)){let p=r!=null?r:await o.tx.begin(),h=await this.find({where:a},p),l=typeof r<"u";if(!((c=h==null?void 0:h.data)!=null&&c.length)||h.data.length===1&&((d=h.data[0])==null?void 0:d.id())===I(e)){let x=await o.records[s]({target:e,label:this.label,data:i},p);return l||await p.commit(),x}else throw l||await p.commit(),new A(this.label,a)}return await o.records[s]({label:this.label,target:e,data:i},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 i;let s=await this.getRushDBInstance(),r=typeof t<"u",o=t!=null?t:await s.tx.begin();try{let a=await Promise.all(e.map(async p=>await U(this.schema,p))),c=J(a,this.schema,this.label);if(!q(c)){let p=Object.entries(c).map(([l,m])=>({[l]:{$in:m}})),h=await this.find({where:{$or:p}},o);if((i=h==null?void 0:h.data)!=null&&i.length)throw new A(this.label,Object.keys(c))}let d=await s.records.createMany({label:this.label,data:a},o);return r||await o.commit(),d}catch(a){throw r||await o.rollback(),a}}async delete(e,t){if(q(e.where))throw new w(`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(await this.getRushDBInstance()).records.delete({...e,labels:[this.label]},t)}async deleteById(e,t){return await(await this.getRushDBInstance()).records.deleteById(e,t)}};te(new F);var Me=D;0&&(module.exports={DBRecordInstance,DBRecordsArrayInstance,EmptyTargetError,HttpClient,HttpClientResponse,Model,NonUniqueResultError,RestAPI,RushDB,Transaction,UniquenessError,extractMixedPropertiesFromToken,idToDate,idToTimestamp,initSDK,mergeDefaultsWithPayload,parseConfig,pickUniqFieldsFromRecord,pickUniqFieldsFromRecords,validateInteger});
1
+ "use strict";var Te=Object.create;var L=Object.defineProperty;var De=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var be=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty;var xe=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},ae=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of we(e))!Ie.call(n,s)&&s!==t&&L(n,s,{get:()=>e[s],enumerable:!(r=De(e,s))||r.enumerable});return n};var oe=(n,e,t)=>(t=n!=null?Te(be(n)):{},ae(e||!n||!n.__esModule?L(t,"default",{value:n,enumerable:!0}):t,n)),Oe=n=>ae(L({},"__esModule",{value:!0}),n);var He={};xe(He,{DBRecordInstance:()=>m,DBRecordsArrayInstance:()=>b,EmptyTargetError:()=>I,HttpClient:()=>O,HttpClientResponse:()=>N,Model:()=>ne,NonUniqueResultError:()=>v,RestAPI:()=>C,RushDB:()=>f,Transaction:()=>A,UniquenessError:()=>E,default:()=>Fe,extractMixedPropertiesFromToken:()=>re,idToDate:()=>te,idToTimestamp:()=>V,initSDK:()=>se,mergeDefaultsWithPayload:()=>M,parseConfig:()=>Z,pickUniqFieldsFromRecord:()=>K,pickUniqFieldsFromRecords:()=>X,validateInteger:()=>ee});module.exports=Oe(He);var O=class n{makeRequest(e,{headers:t,method:r,protocol:s,requestData:a,timeout:o}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(n.TIMEOUT_ERROR_CODE);return e.code=n.TIMEOUT_ERROR_CODE,e}};O.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];O.TIMEOUT_ERROR_CODE="ETIMEDOUT";var $=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.")}},N=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 Y=oe(require("http"),1),Q=oe(require("https"),1);var Pe="string",Ee="datetime",Ae="boolean",Be="number",_e="null",qe="vector",ie=[Pe,Ee,Ae,Be,_e,qe];var de=Y.default||Y,pe=Q.default||Q,Ce=new de.Agent({keepAlive:!0}),je=new pe.Agent({keepAlive:!0}),W=class extends O{constructor(e){super(),this._agent=e}makeRequest(e,{headers:t,method:r,protocol:s,requestData:a,timeout:o}){let i=new URL(e),d=s==="http"||i.protocol==="http:",c=this._agent;return c||(c=d?Ce:je),new Promise((p,l)=>{let h=(d?de:pe).request({agent:c,ciphers:"DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2:!MD5",headers:t,host:i.hostname,method:r,path:i.pathname+i.search,port:i.port});h.setTimeout(o!=null?o:8e4,()=>{h.destroy(O.makeTimeoutError())}),h.on("response",y=>{p(new J(y))}),h.on("error",y=>{l(y)}),h.once("socket",y=>{let w=a?JSON.stringify(a):"";y.connecting?y.once(d?"connect":"secureConnect",()=>{h.write(w),h.end()}):(h.write(w),h.end())})})}},J=class extends ${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 r="";this._res.setEncoding("utf8"),this._res.on("data",s=>{r+=s}),this._res.once("end",()=>{try{e(JSON.parse(r))}catch(s){t(s)}})})}};var R=n=>typeof n=="object"&&Array.isArray(n)&&n!==null,T=n=>n!==null&&Object.prototype.toString.call(n)==="[object Object]",j=n=>T(n)&&Object.keys(n).length===0,le=n=>typeof n=="number"||typeof n=="string"||typeof n=="boolean"||n===null;function ke(n,e){let t={...n};return e.forEach(r=>{delete t[r]}),t}var k=n=>T(n)?ke(n,["__label","__id","__proptypes"]):n,_=n=>R(n)?n.map(_):T(n)?Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>[e,_(t)])):n,z=n=>R(n)?n.every(le):le(n),U=n=>T(n)&&Object.values(n).every(z),P=n=>typeof n=="string",D=n=>{if(typeof n=="string"){if(n.toLowerCase()==="true")return!0;if(n.toLowerCase()==="false")return!1}return R(n)&&n.length===0||T(n)&&Object.keys(n).length===0?!1:!!n};var G=["httpClient","timeout","host","port","protocol","url","logger","options"],he={initial:"in",extended:"ex",fullFeatured:"ff"};var E=class n extends Error{constructor(e,t){super(`Record with label "${e}" and properties ${JSON.stringify(t)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,n.prototype)}},I=class n extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,n.prototype)}},v=class n 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,n.prototype)}};var M=async(n,e)=>{let t=Object.entries(n).map(async([a,o])=>o.default&&typeof o.default<"u"&&typeof e[a]>"u"?{key:a,value:typeof o.default=="function"?await o.default():o.default}:{key:a,value:void 0});return{...(await Promise.all(t)).reduce((a,{key:o,value:i})=>(i!==void 0&&(a[o]=i),a),{}),...e}},K=(n,e)=>Object.entries(e).filter(([t])=>{var r;return(r=n[t])==null?void 0:r.unique}).reduce((t,[r,s])=>(r in n&&(t[r]=s),t),{}),X=(n,e,t)=>{let r={},s=Object.entries(e).filter(([,a])=>a.unique).reduce((a,[o])=>(a[o]=!0,a),{});return n.forEach(a=>{Object.entries(a).forEach(([o,i])=>{if(o in s)if(r[o]){if(r[o].includes(i))throw new E(t,{[o]:i});r[o]=[...r[o],i]}else r[o]=[i]})}),r},Z=n=>{if(!n)return{};if(!T(n))throw new Error("Config must be an object");if(Object.keys(n).filter(t=>!G.includes(t)).length>0)throw new Error(`Config object may only contain the following: ${G.join(", ")}`);return n};function ee(n,e,t){if(!Number.isInteger(e)){if(t!==void 0)return t;throw new Error(`${n} must be an integer`)}return e}function V(n){let e=n.split("-"),t=e[0]+e[1].slice(0,4);return parseInt(t,16)}function te(n){return new Date(V(n))}function re(n){let e=/^([a-z]{2})_([01]{3}\d{0,})_(.+)$/,t=n.match(e);if(!t)return[null,n];let[,r,s,a]=t,i=Object.entries(he).find(([h,y])=>y===r)[0],[d,c,p]=s.split("");return[{...{customDB:d==="1",managedDB:c==="1",selfHosted:p==="1",planType:i}},a]}var m=class{constructor(e={}){this.data=e}exists(){return D(this.data.__id)&&D(this.data.__label)}id(){if(!D(this.data.__id))throw new Error("DBRecordInstance: Unable to access 'id'. The Record's `data.__id` is missing or incorrect.");return this.data.__id}label(){if(!D(this.data.__label))throw new Error("DBRecordInstance: Unable to access 'label'. The Record's `data.__label` is missing or incorrect.");return this.data.__label}proptypes(){if(!D(this.data.__proptypes))throw new Error("DBRecordInstance: Unable to access 'proptypes'. The Record's `data.__proptypes` is missing or incorrect.");return this.data.__proptypes}date(){try{return te(this.id())}catch{throw new Error("DBRecordInstance: Unable to access 'date'. The Record's `data.__id` is missing or incorrect.")}}timestamp(){try{return V(this.id())}catch{throw new Error("DBRecordInstance: Unable to access 'timestamp'. The Record's `data.__id` is missing or incorrect.")}}async delete(e){if(!D(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return await f.getInstance().records.deleteById(this.id(),e)}async update(e,t){if(!D(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return f.getInstance().records.update({label:this.label(),target:this.id(),data:e},t)}async set(e,t){if(!D(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return f.getInstance().records.set({label:this.label(),target:this.id(),data:e},t)}async attach(e,t,r){if(!D(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return f.getInstance().records.attach({source:this.id(),target:e,options:t},r)}async detach(e,t,r){if(!D(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return f.getInstance().records.detach({source:this.id(),target:e,options:t},r)}},b=class{constructor(e=[],t=0,r){this.data=e,this.total=t,this.searchQuery=r}};var Ue={"Content-Type":"application/json"},ge=({httpClient:n,token:e,url:t})=>async(r,{headers:s,...a})=>{let o=await n.makeRequest(`${t}${r}`,{credentials:"omit",headers:Object.assign({...Ue,...s},typeof e<"u"?{token:e}:{}),...a});if(o.getStatusCode()>=200&&o.getStatusCode()<300)return await o.toJSON();throw new Error(`${o.getStatusCode()}`)};var A=class{constructor(e){this.id=e}async rollback(){return await f.getInstance().tx.rollback(this.id)}async commit(){return await f.getInstance().tx.commit(this.id)}};var ye="api.rushdb.com";var ue="https",fe="/api/v1";var S=n=>n?{"x-transaction-id":n}:void 0,Me=n=>P(n)||n instanceof A,u=n=>Me(n)?n instanceof A?n.id:n:void 0,me=n=>/^[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(n),x=n=>{if(P(n)&&me(n))return n;if(n instanceof m&&n.data)return n.data.__id;if(T(n)&&"__id"in n&&me(n.__id))return n.__id},q=n=>!(!T(n)||T(n)&&"name"in n&&!P(n.name)||T(n)&&"type"in n&&(!P(n.type)||!ie.includes(n.type))||!("value"in n)||!z(n.value)||"metadata"in n&&!P(n.metadata)||"valueSeparator"in n&&!P(n.valueSeparator)),Se=n=>{let e=ue,t=ye,r=443,s=fe;if("url"in n){let o=new URL(n.url);e=o.protocol.replace(":",""),t=o.hostname,r=parseInt(o.port||(e==="http"?"80":e==="https"?"443":""))}"host"in n&&"port"in n&&"protocol"in n&&(e=n.protocol.replace(":",""),t=n.host,r=n.port),s&&!s.startsWith("/")&&(s="/"+s);let a="";return e==="http"&&r===80||e==="https"&&r===443||(a=":"+r),`${e}://${t}${a}${s}`},g=(n=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let r=0;r<n;r++){let s=Math.floor(Math.random()*e.length);t+=e[s]}return t};var C=class{constructor(e,t){this.records={attach:async({source:e,target:t,options:r},s)=>{var l,h;let a=u(s),i=`/relationships/${x(e)}`,d={headers:Object.assign({},S(a)),method:"POST",requestData:{targetIds:this._extractTargetIds(t,"Attach"),...(r==null?void 0:r.type)&&{type:r.type},...(r==null?void 0:r.direction)&&{direction:r.direction}}},c=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:c,path:i,...d});let p=await this.fetcher(i,d);return(h=this.logger)==null||h.call(this,{requestId:c,path:i,...d,responseData:p.data}),p},detach:async({source:e,target:t,options:r},s)=>{var l,h;let a=u(s),i=`/relationships/${x(e)}`,d={headers:Object.assign({},S(a)),method:"PUT",requestData:{targetIds:this._extractTargetIds(t,"Detach"),...(r==null?void 0:r.typeOrTypes)&&{typeOrTypes:r.typeOrTypes},...(r==null?void 0:r.direction)&&{direction:r.direction}}},c=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:c,path:i,...d});let p=await this.fetcher(i,d);return(h=this.logger)==null||h.call(this,{requestId:c,path:i,...d,responseData:p.data}),p},create:async({label:e,data:t,options:r},s)=>{var l,h;let a=u(s),o="/records",i={headers:Object.assign({},S(a)),method:"POST",requestData:{}},d=typeof this.logger=="function"?g():"",c=k(_(t));if(R(c)&&c.every(q))i.requestData={label:e,properties:c,options:r};else if(U(c))i.requestData={label:e,data:c,options:r};else throw T(c)?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.");(l=this.logger)==null||l.call(this,{requestId:d,path:o,...i});let p=await this.fetcher(o,i);return(h=this.logger)==null||h.call(this,{requestId:d,path:o,...i,responseData:p.data}),p!=null&&p.success&&(p!=null&&p.data)?new m(p.data):new m},createMany:async(e,t)=>{var p,l,h;let r=R(e.data)?e.data:[e.data];if(!r.every(y=>U(y)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");let a=u(t),o="/records/import/json",i={headers:Object.assign({},S(a)),method:"POST",requestData:{...e,data:r}},d=typeof this.logger=="function"?g():"";(p=this.logger)==null||p.call(this,{requestId:d,path:o,...i});let c=await this.fetcher(o,i);if((l=this.logger)==null||l.call(this,{requestId:d,path:o,...i,responseData:c.data}),c!=null&&c.success&&(c!=null&&c.data)){let y=R(c.data)?(h=c.data)==null?void 0:h.map(w=>new m(w)):[];return new b(y,c.total)}return new b([])},importJson:async(e,t)=>{var h,y,w;let{data:r,options:s}=e,{label:a}=e,o=r;if(!a)if(T(r)&&!R(r)){let F=k(r),H=Object.keys(F);if(H.length===1)a=H[0],o=F[a];else throw new Error("records.importJson: Missing `label`. Provide `label` or pass an object with a single top-level key that determines the label, e.g. { ITEM: [...] }")}else throw new Error("records.importJson: Missing `label`. Provide `label` or pass an object with a single top-level key that determines the label, e.g. { ITEM: [...] }");let i=u(t),d="/records/import/json",c={headers:Object.assign({},S(i)),method:"POST",requestData:{label:a,data:o,options:s}},p=typeof this.logger=="function"?g():"";(h=this.logger)==null||h.call(this,{requestId:p,path:d,...c});let l=await this.fetcher(d,c);if((y=this.logger)==null||y.call(this,{requestId:p,path:d,...c,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)){let F=R(l.data)?(w=l.data)==null?void 0:w.map(H=>new m(H)):[];return new b(F,l.total)}return new b([])},importCsv:async(e,t)=>{var d,c;let r=u(t),s="/records/import/csv",a={headers:Object.assign({},S(r)),method:"POST",requestData:e},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);if((c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i!=null&&i.success&&(i!=null&&i.data)){let p=R(i.data)?i.data.map(l=>new m(l)):[];return new b(p,i.total)}return new b([])},delete:async(e,t)=>{var d,c,p;if(j(e.where)&&!((d=this==null?void 0:this.options)!=null&&d.allowForceDelete))throw new I("You must specify criteria to delete records. Empty criteria are not allowed. If this was intentional, use the Dashboard instead.");let r=u(t),s="/records/delete",a={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(p=this.logger)==null||p.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},deleteById:async(e,t)=>{var c,p;let r=u(t),s=R(e),a=s?"/records/delete":`/records/${e}`,o={headers:Object.assign({},S(r)),method:s?"POST":"DELETE",requestData:s?{limit:1e3,where:{$id:{$in:e}}}:void 0},i=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:i,path:a,...o});let d=await this.fetcher(a,o);return(p=this.logger)==null||p.call(this,{requestId:i,path:a,...o,responseData:d.data}),d},export:async(e,t)=>{var d,c;let r=u(t),s="/records/export/csv",a={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},find:async(e,t)=>{var l,h;let{id:r,...s}=e,a=u(t),o=r?`/records/${r}/search`:"/records/search",i={headers:Object.assign({},S(a)),method:"POST",requestData:s!=null?s:{}},d=typeof this.logger=="function"?g():"";(l=this.logger)==null||l.call(this,{requestId:d,path:o,...i});let c=await this.fetcher(o,i);(h=this.logger)==null||h.call(this,{requestId:d,path:o,...i,responseData:c.data});let p=c.data.map(y=>new m(y));return new b(p,c.total,e)},findById:async(e,t)=>{var d,c;let r=u(t),s=R(e)?"/records":`/records/${e}`,a={headers:Object.assign({},S(r)),method:R(e)?"POST":"GET",requestData:R(e)?{ids:e}:void 0},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);if((c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),R(e)){let p=i.data.map(l=>new m(l));return new b(p,i.total)}else return new m(i.data)},findOne:async(e,t)=>{var c,p;let r=u(t),s="/records/search",a={headers:Object.assign({},S(r)),method:"POST",requestData:{...e,limit:1,skip:0}},o=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);(p=this.logger)==null||p.call(this,{requestId:o,path:s,...a,responseData:i.data});let[d]=i.data;return new m(d)},findUniq:async(e,t)=>{var c,p;let r=u(t),s="/records/search",a={headers:Object.assign({},S(r)),method:"POST",requestData:{...e,limit:1,skip:0}},o=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);if((p=this.logger)==null||p.call(this,{requestId:o,path:s,...a,responseData:i.data}),typeof i.total<"u"&&i.total>1)throw new v(i.total,e);let[d]=i.data;return new m(d)},set:async({target:e,label:t,data:r,options:s},a)=>{var y,w;let o=u(a),d=`/records/${x(e)}`,c={headers:Object.assign({},S(o)),method:"PUT",requestData:{}},p=typeof this.logger=="function"?g():"",l=k(_(r));if(R(l)&&l.every(q))c.requestData={label:t,properties:l};else if(U(l))c.requestData={label:t,data:l,options:s};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.");(y=this.logger)==null||y.call(this,{requestId:p,path:d,...c});let h=await this.fetcher(d,c);return(w=this.logger)==null||w.call(this,{requestId:p,path:d,...c,responseData:h.data}),h!=null&&h.success&&(h!=null&&h.data)?new m(h.data):new m},update:async({target:e,label:t,data:r,options:s},a)=>{var y,w;let o=u(a),d=`/records/${x(e)}`,c={headers:Object.assign({},S(o)),method:"PATCH",requestData:{}},p=typeof this.logger=="function"?g():"",l=k(_(r));if(R(l)&&l.every(q))c.requestData={label:t,properties:l};else if(U(l))c.requestData={label:t,data:l,options:s};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.");(y=this.logger)==null||y.call(this,{requestId:p,path:d,...c});let h=await this.fetcher(d,c);return(w=this.logger)==null||w.call(this,{requestId:p,path:d,...c,responseData:h.data}),h!=null&&h.success&&(h!=null&&h.data)?new m(h.data):new m},upsert:async({label:e,data:t,options:r},s)=>{var h,y,w;let a=u(s),o="/records",i={headers:Object.assign({},S(a)),method:"POST",requestData:{}},d=typeof this.logger=="function"?g():"",c=k(_(t)),p={...r,mergeBy:(h=r==null?void 0:r.mergeBy)!=null?h:[]};if(R(c)&&c.every(q))i.requestData={label:e,properties:c,options:p};else if(U(c))i.requestData={label:e,data:c,options:p};else throw T(c)?new Error("Provided data is not a flat object. Upsert supports flat objects or property drafts array."):new Error("Provided data is not valid.");(y=this.logger)==null||y.call(this,{requestId:d,path:o,...i});let l=await this.fetcher(o,i);return(w=this.logger)==null||w.call(this,{requestId:d,path:o,...i,responseData:l.data}),l!=null&&l.success&&(l!=null&&l.data)?new m(l.data):new m}};this.relationships={createMany:async(e,t)=>{var d,c;let r=u(t),s="/relationships/create-many",a={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},deleteMany:async(e,t)=>{var d,c;let r=u(t),s="/relationships/delete-many",a={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},find:async(e,t)=>{var p,l;let r=u(t),s=new URLSearchParams;(e==null?void 0:e.limit)!==void 0&&s.append("limit",e.limit.toString()),(e==null?void 0:e.skip)!==void 0&&s.append("skip",e.skip.toString());let o=`/relationships/search${s.toString()?"?"+s.toString():""}`,i={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},d=typeof this.logger=="function"?g():"";(p=this.logger)==null||p.call(this,{requestId:d,path:o,...i});let c=await this.fetcher(o,i);return(l=this.logger)==null||l.call(this,{requestId:d,path:o,...i,responseData:c.data}),c}};this.properties={delete:async(e,t)=>{var d,c;let r=u(t),s=`/properties/${e}`,a={headers:Object.assign({},S(r)),method:"DELETE"},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},find:async(e,t)=>{var d,c;let r=u(t),s="/properties/search",a={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},findById:async(e,t)=>{var d,c;let r=u(t),s=`/properties/${e}`,a={headers:Object.assign({},S(r)),method:"GET"},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i},values:async(e,t,r)=>{var c,p;let s=u(r),a=`/properties/${e}/values`,o={headers:Object.assign({},S(s)),method:"POST",requestData:t!=null?t:{}},i=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:i,path:a,...o});let d=await this.fetcher(a,o);return(p=this.logger)==null||p.call(this,{requestId:i,path:a,...o,responseData:d.data}),d}};this.labels={find:async(e,t)=>{var d,c;let r=u(t),s="/labels/search",a={headers:Object.assign({},S(r)),method:"POST",requestData:e!=null?e:{}},o=typeof this.logger=="function"?g():"";(d=this.logger)==null||d.call(this,{requestId:o,path:s,...a});let i=await this.fetcher(s,a);return(c=this.logger)==null||c.call(this,{requestId:o,path:s,...a,responseData:i.data}),i}};this.tx={begin:async e=>{var o,i;let t="/tx",r={method:"POST",requestData:T(e)&&"ttl"in e?e:{}},s=typeof this.logger=="function"?g():"";(o=this.logger)==null||o.call(this,{requestId:s,path:t,...r});let a=await this.fetcher(t,r);return(i=this.logger)==null||i.call(this,{requestId:s,path:t,...r,responseData:a.data}),new A(a.data.id)},commit:async e=>{var i,d;let r=`/tx/${u(e)}/commit`,s={method:"POST",requestData:{}},a=typeof this.logger=="function"?g():"";(i=this.logger)==null||i.call(this,{requestId:a,path:r,...s});let o=await this.fetcher(r,s);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...s,responseData:o.data}),o},get:async e=>{var i,d;let r=`/tx/${u(e)}`,s={method:"GET"},a=typeof this.logger=="function"?g():"";(i=this.logger)==null||i.call(this,{requestId:a,path:r,...s});let o=await this.fetcher(r,s);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...s,responseData:o.data}),new A(o.data.id)},rollback:async e=>{var i,d;let r=`/tx/${u(e)}/rollback`,s={method:"POST",requestData:{}},a=typeof this.logger=="function"?g():"";(i=this.logger)==null||i.call(this,{requestId:a,path:r,...s});let o=await this.fetcher(r,s);return(d=this.logger)==null||d.call(this,{requestId:a,path:r,...s,responseData:o.data}),o}};this.settings={get:async()=>{var a,o;let e="/sdk/settings",t={method:"GET"},r=typeof this.logger=="function"?g():"";(a=this.logger)==null||a.call(this,{requestId:r,path:e,...t});let s=await this.fetcher(e,t);return(o=this.logger)==null||o.call(this,{requestId:r,path:e,...t,responseData:s.data}),s}};this.query={raw:async({query:e,params:t},r)=>{var c,p;let s=u(r),a="/query/raw",o={headers:Object.assign({},S(s)),method:"POST",requestData:{query:e,params:t}},i=typeof this.logger=="function"?g():"";(c=this.logger)==null||c.call(this,{requestId:i,path:a,...o});let d=await this.fetcher(a,o);return(p=this.logger)==null||p.call(this,{requestId:i,path:a,...o,responseData:d.data}),d}};if(this.fetcher=null,t!=null&&t.httpClient){let r=Se(t);this.fetcher=ge({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 m){let s=x(e);if(!s)throw new I(`${t} error: Target id is empty`);return[s]}if(R(e)&&e.every(s=>s instanceof m)){let s=e.map(x).filter(D);if(!s.length)throw new I(`${t} error: Target ids are empty`);return s}if(e instanceof b){let s=(r=e.data)==null?void 0:r.map(x).filter(D);if(!(s!=null&&s.length))throw new I(`${t} error: Target ids are empty`);return s}if(T(e)&&"__id"in e)return[e.__id];if(R(e)&&e.every(s=>T(s)&&"__id"in s)){let s=e.map(x).filter(D);if(!s.length)throw new I(`${t} error: Target ids are empty`);return s}return R(e)?e:P(e)?[e]:[]}};var Re,B=class B extends C{constructor(e,t){var a;let r=Z(t);super(e,{...r,httpClient:(a=r.httpClient)!=null?a:Re}),B.instance=this;let[s]=re(e!=null?e:"");this.initializeSync(s,e,r)}initializeSync(e,t,r){let s=e?{planType:e.planType,customDB:e.customDB,managedDB:e.managedDB,selfHosted:e.selfHosted}:null;B.state={initialized:!0,debug:!1,timeout:ee("timeout",r==null?void 0:r.timeout,8e4),token:t,...s&&{serverSettings:s}}}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 D(B.instance)}toDBRecordInstance(e){return new m(e)}};B.instance=null,B.state={initialized:!1,debug:!1,timeout:8e4};var f=B,se=n=>{Re=n};var ne=class{constructor(e,t){this.label=e,this.schema=t}getLabel(){return this.label}async toDBRecordInstance(e){try{return f.getInstance().toDBRecordInstance(e)}catch{throw new Error("No RushDB instance was provided during model initialization.")}}async find(e,t){let r=e!=null?e:{};return f.getInstance().records.find({...r,labels:[this.label]},t)}async findOne(e,t){let r=e!=null?e:{};return f.getInstance().records.findOne({...r,labels:[this.label]},t)}async findById(e,t){return this.findOne({where:{$id:e}},t)}async findUniq(e,t){let r=e!=null?e:{};return f.getInstance().records.findUniq({...r,labels:[this.label]},t)}async create(e,t){var i;let r=await M(this.schema,e),s=K(this.schema,r),a=D(s),o=f.getInstance();if(a){let d=t!=null?t:await o.tx.begin(),c=await this.find({where:s},d),p=typeof t<"u";if(!((i=c==null?void 0:c.data)!=null&&i.length)){let h=await o.records.create({label:this.label,data:r},d);return p||await d.commit(),h}else throw p||await d.commit(),new E(this.label,s)}return await o.records.create({label:this.label,data:r},t)}async attach({source:e,target:t,options:r},s){return await f.getInstance().records.attach({source:e,target:t,options:r},s)}async detach({source:e,target:t,options:r},s){return await f.getInstance().records.detach({source:e,target:t,options:r},s)}async handleSetOrUpdate(e,t,r,s){var d,c;if(R(t)&&t.every(q))throw new Error(`Model.${r} with Array<PropertyDraft> as payload is not implemented yet.`);let a=f.getInstance(),o=await M(this.schema,t),i=K(this.schema,o);if(!j(i)){let p=s!=null?s:await a.tx.begin(),l=await this.find({where:i},p),h=typeof s<"u";if(!((d=l==null?void 0:l.data)!=null&&d.length)||l.data.length===1&&((c=l.data[0])==null?void 0:c.id())===x(e)){let w=await a.records[r]({target:e,label:this.label,data:o},p);return h||await p.commit(),w}else throw h||await p.commit(),new E(this.label,i)}return await a.records[r]({label:this.label,target:e,data:o},s)}async set(e,t,r){return await this.handleSetOrUpdate(e,t,"set",r)}async update(e,t,r){return await this.handleSetOrUpdate(e,t,"update",r)}async createMany(e,t){var o;let r=f.getInstance(),s=typeof t<"u",a=t!=null?t:await r.tx.begin();try{let i=await Promise.all(e.map(async p=>await M(this.schema,p))),d=X(i,this.schema,this.label);if(!j(d)){let p=Object.entries(d).map(([h,y])=>({[h]:{$in:y}})),l=await this.find({where:{$or:p}},a);if((o=l==null?void 0:l.data)!=null&&o.length)throw new E(this.label,Object.keys(d))}let c=await r.records.createMany({label:this.label,data:i},a);return s||await a.commit(),c}catch(i){throw s||await a.rollback(),i}}async delete(e,t){if(j(e.where))throw new I(`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 f.getInstance().records.delete({...e,labels:[this.label]},t)}async deleteById(e,t){return await f.getInstance().records.deleteById(e,t)}};se(new W);var Fe=f;0&&(module.exports={DBRecordInstance,DBRecordsArrayInstance,EmptyTargetError,HttpClient,HttpClientResponse,Model,NonUniqueResultError,RestAPI,RushDB,Transaction,UniquenessError,extractMixedPropertiesFromToken,idToDate,idToTimestamp,initSDK,mergeDefaultsWithPayload,parseConfig,pickUniqFieldsFromRecord,pickUniqFieldsFromRecords,validateInteger});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var De=Object.defineProperty,be=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var ee=(n,e,t)=>e in n?De(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,p=(n,e)=>{for(var t in e||(e={}))te.call(e,t)&&ee(n,t,e[t]);if(M)for(var t of M(e))re.call(e,t)&&ee(n,t,e[t]);return n},y=(n,e)=>be(n,we(e));var $=(n,e)=>{var t={};for(var r in n)te.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&M)for(var r of M(n))e.indexOf(r)<0&&re.call(n,r)&&(t[r]=n[r]);return t};var h=(n,e,t)=>new Promise((r,s)=>{var o=c=>{try{a(t.next(c))}catch(d){s(d)}},i=c=>{try{a(t.throw(c))}catch(d){s(d)}},a=c=>c.done?r(c.value):Promise.resolve(c.value).then(o,i);a((t=t.apply(n,e)).next())});var Ie="string",xe="datetime",Oe="boolean",Pe="number",Ee="null",Ae="vector",se=[Ie,xe,Oe,Pe,Ee,Ae];var P=class n{makeRequest(e,{headers:t,method:r,protocol:s,requestData:o,timeout:i}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(n.TIMEOUT_ERROR_CODE);return e.code=n.TIMEOUT_ERROR_CODE,e}};P.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];P.TIMEOUT_ERROR_CODE="ETIMEDOUT";var L=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 W=class n extends P{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=n.makeFetchWithAbortTimeout(e):this._fetchFn=n.makeFetchWithRaceTimeout(e)}static makeFetchWithRaceTimeout(e){return(t,r,s)=>{let o,i=new Promise((c,d)=>{o=setTimeout(()=>{o=null,d(P.makeTimeoutError())},s)}),a=e(t,r);return Promise.race([a,i]).finally(()=>{o&&clearTimeout(o)})}}static makeFetchWithAbortTimeout(e){return(t,r,s)=>h(this,null,function*(){let o=new AbortController,i=setTimeout(()=>{i=null,o.abort(P.makeTimeoutError())},s);try{return yield e(t,y(p({},r),{signal:o.signal}))}catch(a){throw a.name==="AbortError"?P.makeTimeoutError():a}finally{i&&clearTimeout(i)}})}makeRequest(a,c){return h(this,arguments,function*(e,{headers:t,method:r,protocol:s,requestData:o,timeout:i}){let d=r=="POST"||r=="PUT"||r=="PATCH",l=JSON.stringify(o)||(d?"":void 0),u=yield this._fetchFn(e,{body:l,headers:t,method:r},i!=null?i:8e4);return new z(u)})}},z=class n extends L{constructor(e){super(e.status,n._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 b=n=>typeof n=="object"&&Array.isArray(n)&&n!==null,w=n=>n!==null&&Object.prototype.toString.call(n)==="[object Object]",k=n=>w(n)&&Object.keys(n).length===0,ae=n=>typeof n=="number"||typeof n=="string"||typeof n=="boolean"||n===null;function Be(n,e){let t=p({},n);return e.forEach(r=>{delete t[r]}),t}var N=n=>w(n)?Be(n,["__label","__id","__proptypes"]):n,j=n=>b(n)?n.map(j):w(n)?Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>[e,j(t)])):n,J=n=>b(n)?n.every(ae):ae(n),K=n=>w(n)&&Object.values(n).every(J),C=n=>typeof n=="string",I=n=>{if(typeof n=="string"){if(n.toLowerCase()==="true")return!0;if(n.toLowerCase()==="false")return!1}return b(n)&&n.length===0||w(n)&&Object.keys(n).length===0?!1:!!n};var G=["httpClient","timeout","host","port","protocol","url","logger","options"],oe={initial:"in",extended:"ex",fullFeatured:"ff"};var _=class n extends Error{constructor(e,t){super(`Record with label "${e}" and properties ${JSON.stringify(t)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,n.prototype)}},E=class n extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,n.prototype)}},V=class n 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,n.prototype)}};var Y=(n,e)=>h(void 0,null,function*(){let t=Object.entries(n).map(a=>h(void 0,[a],function*([o,i]){return i.default&&typeof i.default!="undefined"&&typeof e[o]=="undefined"?{key:o,value:typeof i.default=="function"?yield i.default():i.default}:{key:o,value:void 0}})),s=(yield Promise.all(t)).reduce((o,{key:i,value:a})=>(a!==void 0&&(o[i]=a),o),{});return p(p({},s),e)}),Z=(n,e)=>Object.entries(e).filter(([t])=>{var r;return(r=n[t])==null?void 0:r.unique}).reduce((t,[r,s])=>(r in n&&(t[r]=s),t),{}),ie=(n,e,t)=>{let r={},s=Object.entries(e).filter(([,o])=>o.unique).reduce((o,[i])=>(o[i]=!0,o),{});return n.forEach(o=>{Object.entries(o).forEach(([i,a])=>{if(i in s)if(r[i]){if(r[i].includes(a))throw new _(t,{[i]:a});r[i]=[...r[i],a]}else r[i]=[a]})}),r},ce=n=>{if(!n)return{};if(!w(n))throw new Error("Config must be an object");if(Object.keys(n).filter(t=>!G.includes(t)).length>0)throw new Error(`Config object may only contain the following: ${G.join(", ")}`);return n};function de(n,e,t){if(!Number.isInteger(e)){if(t!==void 0)return t;throw new Error(`${n} must be an integer`)}return e}function X(n){let e=n.split("-"),t=e[0]+e[1].slice(0,4);return parseInt(t,16)}function pe(n){return new Date(X(n))}function le(n){let e=/^([a-z]{2})_([01]{3}\d{0,})_(.+)$/,t=n.match(e);if(!t)return[null,n];let[,r,s,o]=t,a=Object.entries(oe).find(([g,m])=>m===r)[0],[c,d,l]=s.split("");return[p({},{customDB:c==="1",managedDB:d==="1",selfHosted:l==="1",planType:a}),o]}var D=class{constructor(e={}){this.data=e}exists(){return I(this.data.__id)&&I(this.data.__label)}id(){if(!I(this.data.__id))throw new Error("DBRecordInstance: Unable to access 'id'. The Record's `data.__id` is missing or incorrect.");return this.data.__id}label(){if(!I(this.data.__label))throw new Error("DBRecordInstance: Unable to access 'label'. The Record's `data.__label` is missing or incorrect.");return this.data.__label}proptypes(){if(!I(this.data.__proptypes))throw new Error("DBRecordInstance: Unable to access 'proptypes'. The Record's `data.__proptypes` is missing or incorrect.");return this.data.__proptypes}date(){try{return pe(this.id())}catch(e){throw new Error("DBRecordInstance: Unable to access 'date'. The Record's `data.__id` is missing or incorrect.")}}timestamp(){try{return X(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(!I(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return yield x.init().records.deleteById(this.id(),e)})}update(e,t){return h(this,null,function*(){if(!I(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return x.init().records.update({label:this.label(),target:this.id(),data:e},t)})}set(e,t){return h(this,null,function*(){if(!I(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return x.init().records.set({label:this.label(),target:this.id(),data:e},t)})}attach(e,t,r){return h(this,null,function*(){if(!I(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return x.init().records.attach({source:this.id(),target:e,options:t},r)})}detach(e,t,r){return h(this,null,function*(){if(!I(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return x.init().records.detach({source:this.id(),target:e,options:t},r)})}},A=class{constructor(e=[],t=0,r){this.data=e,this.total=t,this.searchQuery=r}};var Ce={"Content-Type":"application/json"},he=({httpClient:n,token:e,url:t})=>(r,i)=>h(void 0,null,function*(){var a=i,{headers:s}=a,o=$(a,["headers"]);let c=yield n.makeRequest(`${t}${r}`,p({credentials:"omit",headers:Object.assign(p(p({},Ce),s),typeof e!="undefined"?{token:e}:{})},o));if(c.getStatusCode()>=200&&c.getStatusCode()<300)return yield c.toJSON();throw new Error(`${c.getStatusCode()}`)});var q=class{constructor(e){this.id=e}rollback(){return h(this,null,function*(){return yield x.init().tx.rollback(this.id)})}commit(){return h(this,null,function*(){return yield x.init().tx.commit(this.id)})}};var ue="api.rushdb.com";var ye="https",ge="/api/v1";var T=n=>n?{"x-transaction-id":n}:void 0,qe=n=>C(n)||n instanceof q,R=n=>qe(n)?n instanceof q?n.id:n:void 0,me=n=>/^[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(n),O=n=>{if(C(n)&&me(n))return n;if(n instanceof D&&n.data)return n.data.__id;if(w(n)&&"__id"in n&&me(n.__id))return n.__id},U=n=>!(!w(n)||w(n)&&"name"in n&&!C(n.name)||w(n)&&"type"in n&&(!C(n.type)||!se.includes(n.type))||!("value"in n)||!J(n.value)||"metadata"in n&&!C(n.metadata)||"valueSeparator"in n&&!C(n.valueSeparator)),fe=n=>{let e=ye,t=ue,r=443,s=ge;if("url"in n){let i=new URL(n.url);e=i.protocol.replace(":",""),t=i.hostname,r=parseInt(i.port||(e==="http"?"80":e==="https"?"443":""))}"host"in n&&"port"in n&&"protocol"in n&&(e=n.protocol.replace(":",""),t=n.host,r=n.port),s&&!s.startsWith("/")&&(s="/"+s);let o="";return e==="http"&&r===80||e==="https"&&r===443||(o=":"+r),`${e}://${t}${o}${s}`},S=(n=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let r=0;r<n;r++){let s=Math.floor(Math.random()*e.length);t+=e[s]}return t};var H=class{constructor(e,t){this.records={attach:(o,i)=>h(this,[o,i],function*({source:e,target:t,options:r},s){var m,f;let a=R(s),d=`/relationships/${O(e)}`,l={headers:Object.assign({},T(a)),method:"POST",requestData:p(p({targetIds:this._extractTargetIds(t,"Attach")},(r==null?void 0:r.type)&&{type:r.type}),(r==null?void 0:r.direction)&&{direction:r.direction})},u=typeof this.logger=="function"?S():"";(m=this.logger)==null||m.call(this,p({requestId:u,path:d},l));let g=yield this.fetcher(d,l);return(f=this.logger)==null||f.call(this,y(p({requestId:u,path:d},l),{responseData:g.data})),g}),detach:(o,i)=>h(this,[o,i],function*({source:e,target:t,options:r},s){var m,f;let a=R(s),d=`/relationships/${O(e)}`,l={headers:Object.assign({},T(a)),method:"PUT",requestData:p(p({targetIds:this._extractTargetIds(t,"Detach")},(r==null?void 0:r.typeOrTypes)&&{typeOrTypes:r.typeOrTypes}),(r==null?void 0:r.direction)&&{direction:r.direction})},u=typeof this.logger=="function"?S():"";(m=this.logger)==null||m.call(this,p({requestId:u,path:d},l));let g=yield this.fetcher(d,l);return(f=this.logger)==null||f.call(this,y(p({requestId:u,path:d},l),{responseData:g.data})),g}),create:(o,i)=>h(this,[o,i],function*({label:e,data:t,options:r},s){var m,f;let a=R(s),c="/records",d={headers:Object.assign({},T(a)),method:"POST",requestData:{}},l=typeof this.logger=="function"?S():"",u=N(j(t));if(b(u)&&u.every(U))d.requestData={label:e,properties:u};else if(K(u))d.requestData={label:e,data:u,options:r};else throw w(u)?new Error("Provided data is not a flat object. Consider to use `createMany` method."):new Error("Provided data is not valid.");(m=this.logger)==null||m.call(this,p({requestId:l,path:c},d));let g=yield this.fetcher(c,d);return(f=this.logger)==null||f.call(this,y(p({requestId:l,path:c},d),{responseData:g.data})),g!=null&&g.success&&(g!=null&&g.data)?new D(g.data):new D}),createMany:(e,t)=>h(this,null,function*(){var c,d,l;let r=R(t),s="/records/import/json",o={headers:Object.assign({},T(r)),method:"POST",requestData:e},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);if((d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a!=null&&a.success&&(a!=null&&a.data)){let u=b(a.data)?(l=a.data)==null?void 0:l.map(g=>new D(g)):[];return new A(u,a.total)}return new A([])}),importCsv:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s="/records/import/csv",o={headers:Object.assign({},T(r)),method:"POST",requestData:e},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);if((d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a!=null&&a.success&&(a!=null&&a.data)){let l=b(a.data)?a.data.map(u=>new D(u)):[];return new A(l,a.total)}return new A([])}),delete:(e,t)=>h(this,null,function*(){var c,d,l;if(k(e.where)&&!((c=this==null?void 0:this.options)!=null&&c.allowForceDelete))throw new E("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",o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(l=this.logger)==null||l.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),deleteById:(e,t)=>h(this,null,function*(){var d,l;let r=R(t),s=b(e),o=s?"/records/delete":`/records/${e}`,i={headers:Object.assign({},T(r)),method:s?"POST":"DELETE",requestData:s?{limit:1e3,where:{$id:{$in:e}}}:void 0},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:a,path:o},i));let c=yield this.fetcher(o,i);return(l=this.logger)==null||l.call(this,y(p({requestId:a,path:o},i),{responseData:c.data})),c}),export:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s="/records/export/csv",o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),find:(e,t)=>h(this,null,function*(){var g,m;let u=e,{id:r}=u,s=$(u,["id"]),o=R(t),i=r?`/records/${r}/search`:"/records/search",a={headers:Object.assign({},T(o)),method:"POST",requestData:s!=null?s:{}},c=typeof this.logger=="function"?S():"";(g=this.logger)==null||g.call(this,p({requestId:c,path:i},a));let d=yield this.fetcher(i,a);(m=this.logger)==null||m.call(this,y(p({requestId:c,path:i},a),{responseData:d.data}));let l=d.data.map(f=>new D(f));return new A(l,d.total,e)}),findById:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s=b(e)?"/records":`/records/${e}`,o={headers:Object.assign({},T(r)),method:b(e)?"POST":"GET",requestData:b(e)?{ids:e}:void 0},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);if((d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),b(e)){let l=a.data.map(u=>new D(u));return new A(l,a.total)}else return new D(a.data)}),findOne:(e,t)=>h(this,null,function*(){var d,l;let r=R(t),s="/records/search",o={headers:Object.assign({},T(r)),method:"POST",requestData:y(p({},e),{limit:1,skip:0})},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);(l=this.logger)==null||l.call(this,y(p({requestId:i,path:s},o),{responseData:a.data}));let[c]=a.data;return new D(c)}),findUniq:(e,t)=>h(this,null,function*(){var d,l;let r=R(t),s="/records/search",o={headers:Object.assign({},T(r)),method:"POST",requestData:y(p({},e),{limit:1,skip:0})},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);if((l=this.logger)==null||l.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),typeof a.total!="undefined"&&a.total>1)throw new V(a.total,e);let[c]=a.data;return new D(c)}),set:(i,a)=>h(this,[i,a],function*({target:e,label:t,data:r,options:s},o){var F,v;let c=R(o),l=`/records/${O(e)}`,u={headers:Object.assign({},T(c)),method:"PUT",requestData:{}},g=typeof this.logger=="function"?S():"",m=N(j(r));if(b(m)&&m.every(U))u.requestData={label:t,properties:m};else if(K(m))u.requestData={label:t,data:m,options:s};else throw w(m)?new Error("Provided data is not a flat object. Consider to use `createMany` method."):new Error("Provided data is not valid.");(F=this.logger)==null||F.call(this,p({requestId:g,path:l},u));let f=yield this.fetcher(l,u);return(v=this.logger)==null||v.call(this,y(p({requestId:g,path:l},u),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D}),update:(i,a)=>h(this,[i,a],function*({target:e,label:t,data:r,options:s},o){var F,v;let c=R(o),l=`/records/${O(e)}`,u={headers:Object.assign({},T(c)),method:"PATCH",requestData:{}},g=typeof this.logger=="function"?S():"",m=N(j(r));if(b(m)&&m.every(U))u.requestData={label:t,properties:m};else if(K(m))u.requestData={label:t,data:m,options:s};else throw w(m)?new Error("Provided data is not a flat object. Consider to use `createMany` method."):new Error("Provided data is not valid.");(F=this.logger)==null||F.call(this,p({requestId:g,path:l},u));let f=yield this.fetcher(l,u);return(v=this.logger)==null||v.call(this,y(p({requestId:g,path:l},u),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D})};this.relationships={createMany:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s="/relationships/create-many",o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),deleteMany:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s="/relationships/delete-many",o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),find:(e,t)=>h(this,null,function*(){var l,u;let r=R(t),s=new URLSearchParams;(e==null?void 0:e.limit)!==void 0&&s.append("limit",e.limit.toString()),(e==null?void 0:e.skip)!==void 0&&s.append("skip",e.skip.toString());let i=`/relationships/search${s.toString()?"?"+s.toString():""}`,a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},c=typeof this.logger=="function"?S():"";(l=this.logger)==null||l.call(this,p({requestId:c,path:i},a));let d=yield this.fetcher(i,a);return(u=this.logger)==null||u.call(this,y(p({requestId:c,path:i},a),{responseData:d.data})),d})};this.properties={delete:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s=`/properties/${e}`,o={headers:Object.assign({},T(r)),method:"DELETE"},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),find:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s="/properties/search",o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),findById:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s=`/properties/${e}`,o={headers:Object.assign({},T(r)),method:"GET"},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a}),values:(e,t,r)=>h(this,null,function*(){var d,l;let s=R(r),o=`/properties/${e}/values`,i={headers:Object.assign({},T(s)),method:"POST",requestData:t!=null?t:{}},a=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:a,path:o},i));let c=yield this.fetcher(o,i);return(l=this.logger)==null||l.call(this,y(p({requestId:a,path:o},i),{responseData:c.data})),c})};this.labels={find:(e,t)=>h(this,null,function*(){var c,d;let r=R(t),s="/labels/search",o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},o));let a=yield this.fetcher(s,o);return(d=this.logger)==null||d.call(this,y(p({requestId:i,path:s},o),{responseData:a.data})),a})};this.tx={begin:e=>h(this,null,function*(){var i,a;let t="/tx",r={method:"POST",requestData:w(e)&&"ttl"in e?e:{}},s=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,p({requestId:s,path:t},r));let o=yield this.fetcher(t,r);return(a=this.logger)==null||a.call(this,y(p({requestId:s,path:t},r),{responseData:o.data})),new q(o.data.id)}),commit:e=>h(this,null,function*(){var a,c;let r=`/tx/${R(e)}/commit`,s={method:"POST",requestData:{}},o=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,p({requestId:o,path:r},s));let i=yield this.fetcher(r,s);return(c=this.logger)==null||c.call(this,y(p({requestId:o,path:r},s),{responseData:i.data})),i}),get:e=>h(this,null,function*(){var a,c;let r=`/tx/${R(e)}`,s={method:"GET"},o=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,p({requestId:o,path:r},s));let i=yield this.fetcher(r,s);return(c=this.logger)==null||c.call(this,y(p({requestId:o,path:r},s),{responseData:i.data})),new q(i.data.id)}),rollback:e=>h(this,null,function*(){var a,c;let r=`/tx/${R(e)}/rollback`,s={method:"POST",requestData:{}},o=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,p({requestId:o,path:r},s));let i=yield this.fetcher(r,s);return(c=this.logger)==null||c.call(this,y(p({requestId:o,path:r},s),{responseData:i.data})),i})};this.settings={get:()=>h(this,null,function*(){var o,i;let e="/sdk/settings",t={method:"GET"},r=typeof this.logger=="function"?S():"";(o=this.logger)==null||o.call(this,p({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(i=this.logger)==null||i.call(this,y(p({requestId:r,path:e},t),{responseData:s.data})),s})};this.query={raw:(s,o)=>h(this,[s,o],function*({query:e,params:t},r){var u,g;let i=R(r),a="/query/raw",c={headers:Object.assign({},T(i)),method:"POST",requestData:{query:e,params:t}},d=typeof this.logger=="function"?S():"";(u=this.logger)==null||u.call(this,p({requestId:d,path:a},c));let l=yield this.fetcher(a,c);return(g=this.logger)==null||g.call(this,y(p({requestId:d,path:a},c),{responseData:l.data})),l})};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=O(e);if(!s)throw new E(`${t} error: Target id is empty`);return[s]}if(b(e)&&e.every(s=>s instanceof D)){let s=e.map(O).filter(I);if(!s.length)throw new E(`${t} error: Target ids are empty`);return s}if(e instanceof A){let s=(r=e.data)==null?void 0:r.map(O).filter(I);if(!(s!=null&&s.length))throw new E(`${t} error: Target ids are empty`);return s}if(w(e)&&"__id"in e)return[e.__id];if(b(e)&&e.every(s=>w(s)&&"__id"in s)){let s=e.map(O).filter(I);if(!s.length)throw new E(`${t} error: Target ids are empty`);return s}return b(e)?e:C(e)?[e]:[]}};var Se,B=class B extends H{constructor(e,t){var o;let r=ce(t);super(e,y(p({},r),{httpClient:(o=r.httpClient)!=null?o:Se})),B.instance=this;let[s]=le(e!=null?e:"");this.initializeSync(s,e,r)}initializeSync(e,t,r){let s=e?{planType:e.planType,customDB:e.customDB,managedDB:e.managedDB,selfHosted:e.selfHosted}:null;B.state=p({initialized:!0,debug:!1,timeout:de("timeout",r==null?void 0:r.timeout,8e4),token:t},s&&{serverSettings:s})}static init(){if(B.instance)return B.instance;throw new Error('RushDB not initialized. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')}static getInstance(){return B.instance}static isInitialized(){return B.instance!==null}toDBRecordInstance(e){return new D(e)}};B.instance=null,B.state={initialized:!1,debug:!1,timeout:8e4};var x=B,Re=n=>{Se=n};var Te=class{constructor(e,t){this.label=e,this.schema=t}getLabel(){return this.label}getRushDBInstance(){return h(this,null,function*(){if(x.getInstance())return x.init();throw new Error('No RushDB instance found. Please create a RushDB instance first: new RushDB("RUSHDB_API_KEY")')})}toDBRecordInstance(e){return h(this,null,function*(){try{return(yield this.getRushDBInstance()).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(yield this.getRushDBInstance()).records.find(y(p({},r),{labels:[this.label]}),t)})}findOne(e,t){return h(this,null,function*(){let r=e!=null?e:{};return(yield this.getRushDBInstance()).records.findOne(y(p({},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(yield this.getRushDBInstance()).records.findUniq(y(p({},r),{labels:[this.label]}),t)})}create(e,t){return h(this,null,function*(){var a;let r=yield Y(this.schema,e),s=Z(this.schema,r),o=I(s),i=yield this.getRushDBInstance();if(o){let c=t!=null?t:yield i.tx.begin(),d=yield this.find({where:s},c),l=typeof t!="undefined";if(!((a=d==null?void 0:d.data)!=null&&a.length)){let g=yield i.records.create({label:this.label,data:r},c);return l||(yield c.commit()),g}else throw l||(yield c.commit()),new _(this.label,s)}return yield i.records.create({label:this.label,data:r},t)})}attach(o,i){return h(this,arguments,function*({source:e,target:t,options:r},s){return yield(yield this.getRushDBInstance()).records.attach({source:e,target:t,options:r},s)})}detach(o,i){return h(this,arguments,function*({source:e,target:t,options:r},s){return yield(yield this.getRushDBInstance()).records.detach({source:e,target:t,options:r},s)})}handleSetOrUpdate(e,t,r,s){return h(this,null,function*(){var c,d;if(b(t)&&t.every(U))throw new Error(`Model.${r} with Array<PropertyDraft> as payload is not implemented yet.`);let o=yield this.getRushDBInstance(),i=yield Y(this.schema,t),a=Z(this.schema,i);if(!k(a)){let l=s!=null?s:yield o.tx.begin(),u=yield this.find({where:a},l),g=typeof s!="undefined";if(!((c=u==null?void 0:u.data)!=null&&c.length)||u.data.length===1&&((d=u.data[0])==null?void 0:d.id())===O(e)){let f=yield o.records[r]({target:e,label:this.label,data:i},l);return g||(yield l.commit()),f}else throw g||(yield l.commit()),new _(this.label,a)}return yield o.records[r]({label:this.label,target:e,data:i},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 i;let r=yield this.getRushDBInstance(),s=typeof t!="undefined",o=t!=null?t:yield r.tx.begin();try{let a=yield Promise.all(e.map(l=>h(this,null,function*(){return yield Y(this.schema,l)}))),c=ie(a,this.schema,this.label);if(!k(c)){let l=Object.entries(c).map(([g,m])=>({[g]:{$in:m}})),u=yield this.find({where:{$or:l}},o);if((i=u==null?void 0:u.data)!=null&&i.length)throw new _(this.label,Object.keys(c))}let d=yield r.records.createMany({label:this.label,data:a},o);return s||(yield o.commit()),d}catch(a){throw s||(yield o.rollback()),a}})}delete(e,t){return h(this,null,function*(){if(k(e.where))throw new E(`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(yield this.getRushDBInstance()).records.delete(y(p({},e),{labels:[this.label]}),t)})}deleteById(e,t){return h(this,null,function*(){return yield(yield this.getRushDBInstance()).records.deleteById(e,t)})}};Re(new W);var Ft=x;export{D as DBRecordInstance,A as DBRecordsArrayInstance,E as EmptyTargetError,P as HttpClient,Q as HttpClientResponse,Te as Model,V as NonUniqueResultError,H as RestAPI,x as RushDB,q as Transaction,_ as UniquenessError,Ft as default,le as extractMixedPropertiesFromToken,pe as idToDate,X as idToTimestamp,Re as initSDK,Y as mergeDefaultsWithPayload,ce as parseConfig,Z as pickUniqFieldsFromRecord,ie as pickUniqFieldsFromRecords,de as validateInteger};
1
+ var be=Object.defineProperty,De=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var ee=(n,e,t)=>e in n?be(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,p=(n,e)=>{for(var t in e||(e={}))te.call(e,t)&&ee(n,t,e[t]);if(W)for(var t of W(e))re.call(e,t)&&ee(n,t,e[t]);return n},g=(n,e)=>De(n,we(e));var $=(n,e)=>{var t={};for(var r in n)te.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&W)for(var r of W(n))e.indexOf(r)<0&&re.call(n,r)&&(t[r]=n[r]);return t};var y=(n,e,t)=>new Promise((r,s)=>{var a=d=>{try{o(t.next(d))}catch(c){s(c)}},i=d=>{try{o(t.throw(d))}catch(c){s(c)}},o=d=>d.done?r(d.value):Promise.resolve(d.value).then(a,i);o((t=t.apply(n,e)).next())});var Ie="string",xe="datetime",Oe="boolean",Pe="number",Ee="null",Ae="vector",se=[Ie,xe,Oe,Pe,Ee,Ae];var B=class n{makeRequest(e,{headers:t,method:r,protocol:s,requestData:a,timeout:i}){throw new Error("makeRequest not implemented.")}static makeTimeoutError(){let e=new TypeError(n.TIMEOUT_ERROR_CODE);return e.code=n.TIMEOUT_ERROR_CODE,e}};B.CONNECTION_CLOSED_ERROR_CODES=["ECONNRESET","EPIPE"];B.TIMEOUT_ERROR_CODE="ETIMEDOUT";var N=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 K=class n extends B{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=n.makeFetchWithAbortTimeout(e):this._fetchFn=n.makeFetchWithRaceTimeout(e)}static makeFetchWithRaceTimeout(e){return(t,r,s)=>{let a,i=new Promise((d,c)=>{a=setTimeout(()=>{a=null,c(B.makeTimeoutError())},s)}),o=e(t,r);return Promise.race([o,i]).finally(()=>{a&&clearTimeout(a)})}}static makeFetchWithAbortTimeout(e){return(t,r,s)=>y(this,null,function*(){let a=new AbortController,i=setTimeout(()=>{i=null,a.abort(B.makeTimeoutError())},s);try{return yield e(t,g(p({},r),{signal:a.signal}))}catch(o){throw o.name==="AbortError"?B.makeTimeoutError():o}finally{i&&clearTimeout(i)}})}makeRequest(o,d){return y(this,arguments,function*(e,{headers:t,method:r,protocol:s,requestData:a,timeout:i}){let c=r=="POST"||r=="PUT"||r=="PATCH",h=JSON.stringify(a)||(c?"":void 0),l=yield this._fetchFn(e,{body:h,headers:t,method:r},i!=null?i:8e4);return new Q(l)})}},Q=class n extends N{constructor(e){super(e.status,n._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 w=n=>typeof n=="object"&&Array.isArray(n)&&n!==null,I=n=>n!==null&&Object.prototype.toString.call(n)==="[object Object]",F=n=>I(n)&&Object.keys(n).length===0,ae=n=>typeof n=="number"||typeof n=="string"||typeof n=="boolean"||n===null;function Be(n,e){let t=p({},n);return e.forEach(r=>{delete t[r]}),t}var H=n=>I(n)?Be(n,["__label","__id","__proptypes"]):n,v=n=>w(n)?n.map(v):I(n)?Object.fromEntries(Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>[e,v(t)])):n,z=n=>w(n)?n.every(ae):ae(n),M=n=>I(n)&&Object.values(n).every(z),C=n=>typeof n=="string",x=n=>{if(typeof n=="string"){if(n.toLowerCase()==="true")return!0;if(n.toLowerCase()==="false")return!1}return w(n)&&n.length===0||I(n)&&Object.keys(n).length===0?!1:!!n};var G=["httpClient","timeout","host","port","protocol","url","logger","options"],oe={initial:"in",extended:"ex",fullFeatured:"ff"};var j=class n extends Error{constructor(e,t){super(`Record with label "${e}" and properties ${JSON.stringify(t)} already exists`),this.name="UniquenessError",Object.setPrototypeOf(this,n.prototype)}},q=class n extends Error{constructor(e){super(e),this.name="EmptyTarget",Object.setPrototypeOf(this,n.prototype)}},V=class n 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,n.prototype)}};var J=(n,e)=>y(void 0,null,function*(){let t=Object.entries(n).map(o=>y(void 0,[o],function*([a,i]){return i.default&&typeof i.default!="undefined"&&typeof e[a]=="undefined"?{key:a,value:typeof i.default=="function"?yield i.default():i.default}:{key:a,value:void 0}})),s=(yield Promise.all(t)).reduce((a,{key:i,value:o})=>(o!==void 0&&(a[i]=o),a),{});return p(p({},s),e)}),Z=(n,e)=>Object.entries(e).filter(([t])=>{var r;return(r=n[t])==null?void 0:r.unique}).reduce((t,[r,s])=>(r in n&&(t[r]=s),t),{}),ie=(n,e,t)=>{let r={},s=Object.entries(e).filter(([,a])=>a.unique).reduce((a,[i])=>(a[i]=!0,a),{});return n.forEach(a=>{Object.entries(a).forEach(([i,o])=>{if(i in s)if(r[i]){if(r[i].includes(o))throw new j(t,{[i]:o});r[i]=[...r[i],o]}else r[i]=[o]})}),r},ce=n=>{if(!n)return{};if(!I(n))throw new Error("Config must be an object");if(Object.keys(n).filter(t=>!G.includes(t)).length>0)throw new Error(`Config object may only contain the following: ${G.join(", ")}`);return n};function de(n,e,t){if(!Number.isInteger(e)){if(t!==void 0)return t;throw new Error(`${n} must be an integer`)}return e}function X(n){let e=n.split("-"),t=e[0]+e[1].slice(0,4);return parseInt(t,16)}function pe(n){return new Date(X(n))}function le(n){let e=/^([a-z]{2})_([01]{3}\d{0,})_(.+)$/,t=n.match(e);if(!t)return[null,n];let[,r,s,a]=t,o=Object.entries(oe).find(([m,u])=>u===r)[0],[d,c,h]=s.split("");return[p({},{customDB:d==="1",managedDB:c==="1",selfHosted:h==="1",planType:o}),a]}var D=class{constructor(e={}){this.data=e}exists(){return x(this.data.__id)&&x(this.data.__label)}id(){if(!x(this.data.__id))throw new Error("DBRecordInstance: Unable to access 'id'. The Record's `data.__id` is missing or incorrect.");return this.data.__id}label(){if(!x(this.data.__label))throw new Error("DBRecordInstance: Unable to access 'label'. The Record's `data.__label` is missing or incorrect.");return this.data.__label}proptypes(){if(!x(this.data.__proptypes))throw new Error("DBRecordInstance: Unable to access 'proptypes'. The Record's `data.__proptypes` is missing or incorrect.");return this.data.__proptypes}date(){try{return pe(this.id())}catch(e){throw new Error("DBRecordInstance: Unable to access 'date'. The Record's `data.__id` is missing or incorrect.")}}timestamp(){try{return X(this.id())}catch(e){throw new Error("DBRecordInstance: Unable to access 'timestamp'. The Record's `data.__id` is missing or incorrect.")}}delete(e){return y(this,null,function*(){if(!x(this.data))throw new Error("DBRecordInstance: Unable to delete Record. The Record data is undefined.");return yield b.getInstance().records.deleteById(this.id(),e)})}update(e,t){return y(this,null,function*(){if(!x(this.data))throw new Error("DBRecordInstance: Unable to update Record. The Record data is undefined.");return b.getInstance().records.update({label:this.label(),target:this.id(),data:e},t)})}set(e,t){return y(this,null,function*(){if(!x(this.data))throw new Error("DBRecordInstance: Unable to set. The Record data is undefined.");return b.getInstance().records.set({label:this.label(),target:this.id(),data:e},t)})}attach(e,t,r){return y(this,null,function*(){if(!x(this.data))throw new Error("DBRecordInstance: Unable to attach Record. The Record data is undefined.");return b.getInstance().records.attach({source:this.id(),target:e,options:t},r)})}detach(e,t,r){return y(this,null,function*(){if(!x(this.data))throw new Error("DBRecordInstance: Unable to detach Record. The Record data is undefined.");return b.getInstance().records.detach({source:this.id(),target:e,options:t},r)})}},E=class{constructor(e=[],t=0,r){this.data=e,this.total=t,this.searchQuery=r}};var qe={"Content-Type":"application/json"},he=({httpClient:n,token:e,url:t})=>(r,i)=>y(void 0,null,function*(){var o=i,{headers:s}=o,a=$(o,["headers"]);let d=yield n.makeRequest(`${t}${r}`,p({credentials:"omit",headers:Object.assign(p(p({},qe),s),typeof e!="undefined"?{token:e}:{})},a));if(d.getStatusCode()>=200&&d.getStatusCode()<300)return yield d.toJSON();throw new Error(`${d.getStatusCode()}`)});var k=class{constructor(e){this.id=e}rollback(){return y(this,null,function*(){return yield b.getInstance().tx.rollback(this.id)})}commit(){return y(this,null,function*(){return yield b.getInstance().tx.commit(this.id)})}};var ye="api.rushdb.com";var ue="https",ge="/api/v1";var T=n=>n?{"x-transaction-id":n}:void 0,_e=n=>C(n)||n instanceof k,R=n=>_e(n)?n instanceof k?n.id:n:void 0,me=n=>/^[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(n),A=n=>{if(C(n)&&me(n))return n;if(n instanceof D&&n.data)return n.data.__id;if(I(n)&&"__id"in n&&me(n.__id))return n.__id},U=n=>!(!I(n)||I(n)&&"name"in n&&!C(n.name)||I(n)&&"type"in n&&(!C(n.type)||!se.includes(n.type))||!("value"in n)||!z(n.value)||"metadata"in n&&!C(n.metadata)||"valueSeparator"in n&&!C(n.valueSeparator)),fe=n=>{let e=ue,t=ye,r=443,s=ge;if("url"in n){let i=new URL(n.url);e=i.protocol.replace(":",""),t=i.hostname,r=parseInt(i.port||(e==="http"?"80":e==="https"?"443":""))}"host"in n&&"port"in n&&"protocol"in n&&(e=n.protocol.replace(":",""),t=n.host,r=n.port),s&&!s.startsWith("/")&&(s="/"+s);let a="";return e==="http"&&r===80||e==="https"&&r===443||(a=":"+r),`${e}://${t}${a}${s}`},S=(n=8)=>{let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t="";for(let r=0;r<n;r++){let s=Math.floor(Math.random()*e.length);t+=e[s]}return t};var L=class{constructor(e,t){this.records={attach:(a,i)=>y(this,[a,i],function*({source:e,target:t,options:r},s){var u,f;let o=R(s),c=`/relationships/${A(e)}`,h={headers:Object.assign({},T(o)),method:"POST",requestData:p(p({targetIds:this._extractTargetIds(t,"Attach")},(r==null?void 0:r.type)&&{type:r.type}),(r==null?void 0:r.direction)&&{direction:r.direction})},l=typeof this.logger=="function"?S():"";(u=this.logger)==null||u.call(this,p({requestId:l,path:c},h));let m=yield this.fetcher(c,h);return(f=this.logger)==null||f.call(this,g(p({requestId:l,path:c},h),{responseData:m.data})),m}),detach:(a,i)=>y(this,[a,i],function*({source:e,target:t,options:r},s){var u,f;let o=R(s),c=`/relationships/${A(e)}`,h={headers:Object.assign({},T(o)),method:"PUT",requestData:p(p({targetIds:this._extractTargetIds(t,"Detach")},(r==null?void 0:r.typeOrTypes)&&{typeOrTypes:r.typeOrTypes}),(r==null?void 0:r.direction)&&{direction:r.direction})},l=typeof this.logger=="function"?S():"";(u=this.logger)==null||u.call(this,p({requestId:l,path:c},h));let m=yield this.fetcher(c,h);return(f=this.logger)==null||f.call(this,g(p({requestId:l,path:c},h),{responseData:m.data})),m}),create:(a,i)=>y(this,[a,i],function*({label:e,data:t,options:r},s){var u,f;let o=R(s),d="/records",c={headers:Object.assign({},T(o)),method:"POST",requestData:{}},h=typeof this.logger=="function"?S():"",l=H(v(t));if(w(l)&&l.every(U))c.requestData={label:e,properties:l,options:r};else if(M(l))c.requestData={label:e,data:l,options:r};else throw I(l)?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.");(u=this.logger)==null||u.call(this,p({requestId:h,path:d},c));let m=yield this.fetcher(d,c);return(f=this.logger)==null||f.call(this,g(p({requestId:h,path:d},c),{responseData:m.data})),m!=null&&m.success&&(m!=null&&m.data)?new D(m.data):new D}),createMany:(e,t)=>y(this,null,function*(){var h,l,m;let r=w(e.data)?e.data:[e.data];if(!r.every(u=>M(u)))throw new Error("records.createMany supports only flat records (no nested objects/arrays). Use records.importJson for nested JSON.");let a=R(t),i="/records/import/json",o={headers:Object.assign({},T(a)),method:"POST",requestData:g(p({},e),{data:r})},d=typeof this.logger=="function"?S():"";(h=this.logger)==null||h.call(this,p({requestId:d,path:i},o));let c=yield this.fetcher(i,o);if((l=this.logger)==null||l.call(this,g(p({requestId:d,path:i},o),{responseData:c.data})),c!=null&&c.success&&(c!=null&&c.data)){let u=w(c.data)?(m=c.data)==null?void 0:m.map(f=>new D(f)):[];return new E(u,c.total)}return new E([])}),importJson:(e,t)=>y(this,null,function*(){var m,u,f;let{data:r,options:s}=e,{label:a}=e,i=r;if(!a)if(I(r)&&!w(r)){let O=H(r),P=Object.keys(O);if(P.length===1)a=P[0],i=O[a];else throw new Error("records.importJson: Missing `label`. Provide `label` or pass an object with a single top-level key that determines the label, e.g. { ITEM: [...] }")}else throw new Error("records.importJson: Missing `label`. Provide `label` or pass an object with a single top-level key that determines the label, e.g. { ITEM: [...] }");let o=R(t),d="/records/import/json",c={headers:Object.assign({},T(o)),method:"POST",requestData:{label:a,data:i,options:s}},h=typeof this.logger=="function"?S():"";(m=this.logger)==null||m.call(this,p({requestId:h,path:d},c));let l=yield this.fetcher(d,c);if((u=this.logger)==null||u.call(this,g(p({requestId:h,path:d},c),{responseData:l.data})),l!=null&&l.success&&(l!=null&&l.data)){let O=w(l.data)?(f=l.data)==null?void 0:f.map(P=>new D(P)):[];return new E(O,l.total)}return new E([])}),importCsv:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s="/records/import/csv",a={headers:Object.assign({},T(r)),method:"POST",requestData:e},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);if((c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o!=null&&o.success&&(o!=null&&o.data)){let h=w(o.data)?o.data.map(l=>new D(l)):[];return new E(h,o.total)}return new E([])}),delete:(e,t)=>y(this,null,function*(){var d,c,h;if(F(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",a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(h=this.logger)==null||h.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),deleteById:(e,t)=>y(this,null,function*(){var c,h;let r=R(t),s=w(e),a=s?"/records/delete":`/records/${e}`,i={headers:Object.assign({},T(r)),method:s?"POST":"DELETE",requestData:s?{limit:1e3,where:{$id:{$in:e}}}:void 0},o=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:o,path:a},i));let d=yield this.fetcher(a,i);return(h=this.logger)==null||h.call(this,g(p({requestId:o,path:a},i),{responseData:d.data})),d}),export:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s="/records/export/csv",a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),find:(e,t)=>y(this,null,function*(){var m,u;let l=e,{id:r}=l,s=$(l,["id"]),a=R(t),i=r?`/records/${r}/search`:"/records/search",o={headers:Object.assign({},T(a)),method:"POST",requestData:s!=null?s:{}},d=typeof this.logger=="function"?S():"";(m=this.logger)==null||m.call(this,p({requestId:d,path:i},o));let c=yield this.fetcher(i,o);(u=this.logger)==null||u.call(this,g(p({requestId:d,path:i},o),{responseData:c.data}));let h=c.data.map(f=>new D(f));return new E(h,c.total,e)}),findById:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s=w(e)?"/records":`/records/${e}`,a={headers:Object.assign({},T(r)),method:w(e)?"POST":"GET",requestData:w(e)?{ids:e}:void 0},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);if((c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),w(e)){let h=o.data.map(l=>new D(l));return new E(h,o.total)}else return new D(o.data)}),findOne:(e,t)=>y(this,null,function*(){var c,h;let r=R(t),s="/records/search",a={headers:Object.assign({},T(r)),method:"POST",requestData:g(p({},e),{limit:1,skip:0})},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);(h=this.logger)==null||h.call(this,g(p({requestId:i,path:s},a),{responseData:o.data}));let[d]=o.data;return new D(d)}),findUniq:(e,t)=>y(this,null,function*(){var c,h;let r=R(t),s="/records/search",a={headers:Object.assign({},T(r)),method:"POST",requestData:g(p({},e),{limit:1,skip:0})},i=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);if((h=this.logger)==null||h.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),typeof o.total!="undefined"&&o.total>1)throw new V(o.total,e);let[d]=o.data;return new D(d)}),set:(i,o)=>y(this,[i,o],function*({target:e,label:t,data:r,options:s},a){var O,P;let d=R(a),h=`/records/${A(e)}`,l={headers:Object.assign({},T(d)),method:"PUT",requestData:{}},m=typeof this.logger=="function"?S():"",u=H(v(r));if(w(u)&&u.every(U))l.requestData={label:t,properties:u};else if(M(u))l.requestData={label:t,data:u,options:s};else throw I(u)?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,p({requestId:m,path:h},l));let f=yield this.fetcher(h,l);return(P=this.logger)==null||P.call(this,g(p({requestId:m,path:h},l),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D}),update:(i,o)=>y(this,[i,o],function*({target:e,label:t,data:r,options:s},a){var O,P;let d=R(a),h=`/records/${A(e)}`,l={headers:Object.assign({},T(d)),method:"PATCH",requestData:{}},m=typeof this.logger=="function"?S():"",u=H(v(r));if(w(u)&&u.every(U))l.requestData={label:t,properties:u};else if(M(u))l.requestData={label:t,data:u,options:s};else throw I(u)?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,p({requestId:m,path:h},l));let f=yield this.fetcher(h,l);return(P=this.logger)==null||P.call(this,g(p({requestId:m,path:h},l),{responseData:f.data})),f!=null&&f.success&&(f!=null&&f.data)?new D(f.data):new D}),upsert:(a,i)=>y(this,[a,i],function*({label:e,data:t,options:r},s){var f,O,P;let o=R(s),d="/records",c={headers:Object.assign({},T(o)),method:"POST",requestData:{}},h=typeof this.logger=="function"?S():"",l=H(v(t)),m=g(p({},r),{mergeBy:(f=r==null?void 0:r.mergeBy)!=null?f:[]});if(w(l)&&l.every(U))c.requestData={label:e,properties:l,options:m};else if(M(l))c.requestData={label:e,data:l,options:m};else throw I(l)?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,p({requestId:h,path:d},c));let u=yield this.fetcher(d,c);return(P=this.logger)==null||P.call(this,g(p({requestId:h,path:d},c),{responseData:u.data})),u!=null&&u.success&&(u!=null&&u.data)?new D(u.data):new D})};this.relationships={createMany:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s="/relationships/create-many",a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),deleteMany:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s="/relationships/delete-many",a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),find:(e,t)=>y(this,null,function*(){var h,l;let r=R(t),s=new URLSearchParams;(e==null?void 0:e.limit)!==void 0&&s.append("limit",e.limit.toString()),(e==null?void 0:e.skip)!==void 0&&s.append("skip",e.skip.toString());let i=`/relationships/search${s.toString()?"?"+s.toString():""}`,o={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},d=typeof this.logger=="function"?S():"";(h=this.logger)==null||h.call(this,p({requestId:d,path:i},o));let c=yield this.fetcher(i,o);return(l=this.logger)==null||l.call(this,g(p({requestId:d,path:i},o),{responseData:c.data})),c})};this.properties={delete:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s=`/properties/${e}`,a={headers:Object.assign({},T(r)),method:"DELETE"},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),find:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s="/properties/search",a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),findById:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s=`/properties/${e}`,a={headers:Object.assign({},T(r)),method:"GET"},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o}),values:(e,t,r)=>y(this,null,function*(){var c,h;let s=R(r),a=`/properties/${e}/values`,i={headers:Object.assign({},T(s)),method:"POST",requestData:t!=null?t:{}},o=typeof this.logger=="function"?S():"";(c=this.logger)==null||c.call(this,p({requestId:o,path:a},i));let d=yield this.fetcher(a,i);return(h=this.logger)==null||h.call(this,g(p({requestId:o,path:a},i),{responseData:d.data})),d})};this.labels={find:(e,t)=>y(this,null,function*(){var d,c;let r=R(t),s="/labels/search",a={headers:Object.assign({},T(r)),method:"POST",requestData:e!=null?e:{}},i=typeof this.logger=="function"?S():"";(d=this.logger)==null||d.call(this,p({requestId:i,path:s},a));let o=yield this.fetcher(s,a);return(c=this.logger)==null||c.call(this,g(p({requestId:i,path:s},a),{responseData:o.data})),o})};this.tx={begin:e=>y(this,null,function*(){var i,o;let t="/tx",r={method:"POST",requestData:I(e)&&"ttl"in e?e:{}},s=typeof this.logger=="function"?S():"";(i=this.logger)==null||i.call(this,p({requestId:s,path:t},r));let a=yield this.fetcher(t,r);return(o=this.logger)==null||o.call(this,g(p({requestId:s,path:t},r),{responseData:a.data})),new k(a.data.id)}),commit:e=>y(this,null,function*(){var o,d;let r=`/tx/${R(e)}/commit`,s={method:"POST",requestData:{}},a=typeof this.logger=="function"?S():"";(o=this.logger)==null||o.call(this,p({requestId:a,path:r},s));let i=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,g(p({requestId:a,path:r},s),{responseData:i.data})),i}),get:e=>y(this,null,function*(){var o,d;let r=`/tx/${R(e)}`,s={method:"GET"},a=typeof this.logger=="function"?S():"";(o=this.logger)==null||o.call(this,p({requestId:a,path:r},s));let i=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,g(p({requestId:a,path:r},s),{responseData:i.data})),new k(i.data.id)}),rollback:e=>y(this,null,function*(){var o,d;let r=`/tx/${R(e)}/rollback`,s={method:"POST",requestData:{}},a=typeof this.logger=="function"?S():"";(o=this.logger)==null||o.call(this,p({requestId:a,path:r},s));let i=yield this.fetcher(r,s);return(d=this.logger)==null||d.call(this,g(p({requestId:a,path:r},s),{responseData:i.data})),i})};this.settings={get:()=>y(this,null,function*(){var a,i;let e="/sdk/settings",t={method:"GET"},r=typeof this.logger=="function"?S():"";(a=this.logger)==null||a.call(this,p({requestId:r,path:e},t));let s=yield this.fetcher(e,t);return(i=this.logger)==null||i.call(this,g(p({requestId:r,path:e},t),{responseData:s.data})),s})};this.query={raw:(s,a)=>y(this,[s,a],function*({query:e,params:t},r){var l,m;let i=R(r),o="/query/raw",d={headers:Object.assign({},T(i)),method:"POST",requestData:{query:e,params:t}},c=typeof this.logger=="function"?S():"";(l=this.logger)==null||l.call(this,p({requestId:c,path:o},d));let h=yield this.fetcher(o,d);return(m=this.logger)==null||m.call(this,g(p({requestId:c,path:o},d),{responseData:h.data})),h})};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(w(e)&&e.every(s=>s instanceof D)){let s=e.map(A).filter(x);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(x);if(!(s!=null&&s.length))throw new q(`${t} error: Target ids are empty`);return s}if(I(e)&&"__id"in e)return[e.__id];if(w(e)&&e.every(s=>I(s)&&"__id"in s)){let s=e.map(A).filter(x);if(!s.length)throw new q(`${t} error: Target ids are empty`);return s}return w(e)?e:C(e)?[e]:[]}};var Se,_=class _ extends L{constructor(e,t){var a;let r=ce(t);super(e,g(p({},r),{httpClient:(a=r.httpClient)!=null?a:Se})),_.instance=this;let[s]=le(e!=null?e:"");this.initializeSync(s,e,r)}initializeSync(e,t,r){let s=e?{planType:e.planType,customDB:e.customDB,managedDB:e.managedDB,selfHosted:e.selfHosted}:null;_.state=p({initialized:!0,debug:!1,timeout:de("timeout",r==null?void 0:r.timeout,8e4),token:t},s&&{serverSettings:s})}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 x(_.instance)}toDBRecordInstance(e){return new D(e)}};_.instance=null,_.state={initialized:!1,debug:!1,timeout:8e4};var b=_,Re=n=>{Se=n};var Te=class{constructor(e,t){this.label=e,this.schema=t}getLabel(){return this.label}toDBRecordInstance(e){return y(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 y(this,null,function*(){let r=e!=null?e:{};return b.getInstance().records.find(g(p({},r),{labels:[this.label]}),t)})}findOne(e,t){return y(this,null,function*(){let r=e!=null?e:{};return b.getInstance().records.findOne(g(p({},r),{labels:[this.label]}),t)})}findById(e,t){return y(this,null,function*(){return this.findOne({where:{$id:e}},t)})}findUniq(e,t){return y(this,null,function*(){let r=e!=null?e:{};return b.getInstance().records.findUniq(g(p({},r),{labels:[this.label]}),t)})}create(e,t){return y(this,null,function*(){var o;let r=yield J(this.schema,e),s=Z(this.schema,r),a=x(s),i=b.getInstance();if(a){let d=t!=null?t:yield i.tx.begin(),c=yield this.find({where:s},d),h=typeof t!="undefined";if(!((o=c==null?void 0:c.data)!=null&&o.length)){let m=yield i.records.create({label:this.label,data:r},d);return h||(yield d.commit()),m}else throw h||(yield d.commit()),new j(this.label,s)}return yield i.records.create({label:this.label,data:r},t)})}attach(a,i){return y(this,arguments,function*({source:e,target:t,options:r},s){return yield b.getInstance().records.attach({source:e,target:t,options:r},s)})}detach(a,i){return y(this,arguments,function*({source:e,target:t,options:r},s){return yield b.getInstance().records.detach({source:e,target:t,options:r},s)})}handleSetOrUpdate(e,t,r,s){return y(this,null,function*(){var d,c;if(w(t)&&t.every(U))throw new Error(`Model.${r} with Array<PropertyDraft> as payload is not implemented yet.`);let a=b.getInstance(),i=yield J(this.schema,t),o=Z(this.schema,i);if(!F(o)){let h=s!=null?s:yield a.tx.begin(),l=yield this.find({where:o},h),m=typeof s!="undefined";if(!((d=l==null?void 0:l.data)!=null&&d.length)||l.data.length===1&&((c=l.data[0])==null?void 0:c.id())===A(e)){let f=yield a.records[r]({target:e,label:this.label,data:i},h);return m||(yield h.commit()),f}else throw m||(yield h.commit()),new j(this.label,o)}return yield a.records[r]({label:this.label,target:e,data:i},s)})}set(e,t,r){return y(this,null,function*(){return yield this.handleSetOrUpdate(e,t,"set",r)})}update(e,t,r){return y(this,null,function*(){return yield this.handleSetOrUpdate(e,t,"update",r)})}createMany(e,t){return y(this,null,function*(){var i;let r=b.getInstance(),s=typeof t!="undefined",a=t!=null?t:yield r.tx.begin();try{let o=yield Promise.all(e.map(h=>y(this,null,function*(){return yield J(this.schema,h)}))),d=ie(o,this.schema,this.label);if(!F(d)){let h=Object.entries(d).map(([m,u])=>({[m]:{$in:u}})),l=yield this.find({where:{$or:h}},a);if((i=l==null?void 0:l.data)!=null&&i.length)throw new j(this.label,Object.keys(d))}let c=yield r.records.createMany({label:this.label,data:o},a);return s||(yield a.commit()),c}catch(o){throw s||(yield a.rollback()),o}})}delete(e,t){return y(this,null,function*(){if(F(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(g(p({},e),{labels:[this.label]}),t)})}deleteById(e,t){return y(this,null,function*(){return yield b.getInstance().records.deleteById(e,t)})}};Re(new K);var Ht=b;export{D as DBRecordInstance,E as DBRecordsArrayInstance,q as EmptyTargetError,B as HttpClient,Y as HttpClientResponse,Te as Model,V as NonUniqueResultError,L as RestAPI,b as RushDB,k as Transaction,j as UniquenessError,Ht as default,le as extractMixedPropertiesFromToken,pe as idToDate,X as idToTimestamp,Re as initSDK,J as mergeDefaultsWithPayload,ce as parseConfig,Z as pickUniqFieldsFromRecord,ie as pickUniqFieldsFromRecords,de as validateInteger};
@@ -1,7 +1,6 @@
1
1
  import type { SearchQuery, Schema, FlattenTypes, InferSchemaTypesRead, InferSchemaTypesWrite, MaybeArray } from '../types/index.js';
2
2
  import type { DBRecord, DBRecordInstance, DBRecordsArrayInstance, DBRecordTarget, RelationDetachOptions, RelationOptions, RelationTarget } from './record.js';
3
3
  import type { Transaction } from './transaction.js';
4
- import { RushDB } from './sdk';
5
4
  /**
6
5
  * Represents a model in the RushDB database.
7
6
  * A model defines the structure and behavior of a specific type of record in the database.
@@ -75,7 +74,6 @@ export declare class Model<S extends Schema = any> {
75
74
  * @returns Promise resolving to the initialized RushDB instance
76
75
  * @throws Error if no RushDB instance has been created yet
77
76
  */
78
- getRushDBInstance(): Promise<RushDB>;
79
77
  /**
80
78
  * Converts a database record to a record instance (DBRecordInstance) with additional methods.
81
79
  *
@@ -79,6 +79,8 @@ export type DBRecordCreationOptions = {
79
79
  convertNumericValuesToNumbers?: boolean;
80
80
  capitalizeLabels?: boolean;
81
81
  relationshipType?: string;
82
+ mergeStrategy?: 'append' | 'rewrite';
83
+ mergeBy?: string[];
82
84
  };
83
85
  export declare class DBRecordInstance<S extends Schema = Schema, Q extends SearchQuery<S> = SearchQuery<S>> {
84
86
  data: DBRecordInferred<S, Q>;
package/dist/sdk/sdk.d.ts CHANGED
@@ -9,15 +9,10 @@ export declare class RushDB extends RestAPI {
9
9
  static state: State;
10
10
  constructor(token?: string, config?: SDKConfig);
11
11
  private initializeSync;
12
- /**
13
- * Static method to get instance
14
- * This is the preferred way to get an initialized RushDB instance
15
- */
16
- static init(): RushDB;
17
12
  /**
18
13
  * Synchronous getInstance that returns instance or null
19
14
  */
20
- static getInstance(): RushDB | null;
15
+ static getInstance(): RushDB;
21
16
  /**
22
17
  * Check if the SDK is initialized
23
18
  */
package/package.json CHANGED
@@ -33,7 +33,7 @@
33
33
  "rushdb"
34
34
  ],
35
35
  "license": "Apache-2.0",
36
- "version": "1.17.0",
36
+ "version": "1.19.0",
37
37
  "type": "module",
38
38
  "files": [
39
39
  "dist"