rest-client-vue 1.0.0-a1

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.
@@ -0,0 +1 @@
1
+ (function(g,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("lodash"),require("uuid"),require("vue"),require("axios"),require("jsog"),require("json-stringify-deterministic"),require("pinia")):typeof define=="function"&&define.amd?define(["exports","lodash","uuid","vue","axios","jsog","json-stringify-deterministic","pinia"],r):(g=typeof globalThis<"u"?globalThis:g||self,r(g["rest-client-vue"]={},g._,g.uuid,g.Vue,g.axios,g.jsog,g.stringify,g.pinia))})(this,function(g,r,I,a,L,ne,J,ae){"use strict";var Pe=Object.defineProperty;var Fe=(g,r,I)=>r in g?Pe(g,r,{enumerable:!0,configurable:!0,writable:!0,value:I}):g[r]=I;var le=(g,r,I)=>(Fe(g,typeof r!="symbol"?r+"":r,I),I),Ne=(g,r,I)=>{if(!r.has(g))throw TypeError("Cannot "+I)};var j=(g,r,I)=>(Ne(g,r,"read from private field"),I?I.call(g):r.get(g)),Ie=(g,r,I)=>{if(r.has(g))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(g):r.set(g,I)};var A;const oe={apiBaseUrl:"",useVueLogger:!1};class we extends Error{constructor(C,$=void 0,e=void 0){super(C);le(this,"context");le(this,"innerError");this.context=$,this.innerError=e}}class ce{constructor(){Ie(this,A,{})}clearAllStores(){for(const n in j(this,A))j(this,A)[n].clear()}destroyStore(n){j(this,A)[n]&&(j(this,A)[n].$dispose(),delete j(this,A)[n])}getStore(n){return j(this,A)[n]}registerStore(n,C){j(this,A)[n]=C}}A=new WeakMap;function v(w,n){return r.get(w,(n==null?void 0:n.idProperty)||"_id")}function De(w,n){var C;return w&&((C=n.filter)!=null&&C.resourceIds)&&!n.order?n.filter.resourceIds.map($=>w.find(e=>v(e,n)==$)).filter($=>$!=null):w}const ue={detail:{allowMultiple:!0,autoEdit:!1,autoFromMultipleSelection:!0,autoFromSingleInsertion:!0,autoFromSingleSelection:!0,constrainToSelection:!0},filter:{namedFilter:null,query:null,resourceIds:null},idProperty:"_id",limit:5e3,limitTransientDataToLocalCollection:!0,loading:{firstPageSize:500,pageSize:5e3},order:[[{path:"history.creation.timestamp"},"desc"],[{path:"history.creation.orderInBatch"},"desc"]]},K={resources:[],status:"NotLoaded",selection:[],detailSelection:[],invalidResources:[],transientData:{}},te={editingDetailSelection:!1,batchSaveAttempted:!1,editors:[],listNavigators:{}},Ee=(w,n)=>{n=r.merge({},ue,n);const C=ae.defineStore(w,{state:()=>({idProperty:n.idProperty,filter:n.filter,order:n.order||null,referencePathsToExpand:n.referencePathsToExpand||null,...K,...te}),getters:{fixedQueryParams:e=>{var l,d,u,h;const s={};(l=e.filter)!=null&&l.namedFilter&&(s.namedFilter=e.filter.namedFilter);const t=[];if((d=e.filter)!=null&&d.resourceIds&&t.push({l:{path:e.idProperty},r:{constant:e.filter.resourceIds},operator:"in"}),(u=e.filter)!=null&&u.query&&t.push((h=e.filter)==null?void 0:h.query),t.length>0){const p=t.length==1?t[0]:{and:t};s.q=J(p)}return e.order&&(s.o=J(e.order)),e.referencePathsToExpand&&(s.r=J(e.referencePathsToExpand)),s}},actions:{reset(){for(const e in K)this[e]=K[e];for(const e in te)this[e]=te[e]},resetRetainingTransientData(){if(n.limitTransientDataToLocalCollection)this.reset();else{const e=this.transientData;this.reset(),this.transientData=e}},setEditingDetailSelection(e){this.editingDetailSelection=e},setFilter(e){r.isEqual(e,this.filter)||(this.filter=e,this.status="NotLoaded",this.resources=[],this.selection=[],this.detailSelection=[],this.invalidResources=[],this.editingDetailSelection=!1)},async setQuery(e){var s,t;if(!r.isEqual(e,(s=this.filter)==null?void 0:s.query)&&(e!=null||((t=this.filter)==null?void 0:t.query)!=null)){const l=r.cloneDeep(this.filter)||{};e!==null?l.query=e:r.unset(l,"query");const d=this.status;this.setFilter(l),d!="NotLoaded"&&await this.loadResources()}},async setFilterResourceIds(e){if(!r.isEqual(e,r.get(this.filter,"resourceIds"))){const s=r.cloneDeep(this.filter)||{};e!=null?s.resourceIds=e:r.unset(s,"resourceIds");const t=this.status;this.setFilter(s),t!="NotLoaded"&&await this.loadResources()}},setBatchSaveAttempted(e){e!=this.batchSaveAttempted&&(this.batchSaveAttempted=e)},clear(){for(const e in K)this[e]=K[e]},clearRetainingTransientData(){if(n.limitTransientDataToLocalCollection)this.reset();else{const e=this.transientData;this.reset(),this.transientData=e}},async ensureCollectionLoaded(){["Loaded","Loading","LoadingMore","Failed"].includes(this.status)||await this.loadResources()},async loadResources(e={}){this.resetRetainingTransientData();const s=I.v4();this._loadId=s,await this._loadResources(0,s,e)},async _loadResources(e,s,t){var b,F,O,k,Q;const l=e==0;if(this.status=l?"Loading":"LoadingMore",this._loadOffset=e,((b=this.filter)==null?void 0:b.query)===!1){this.resources=[];return}const d=this.fixedQueryParams,u=r.cloneDeep(d),h=l?(F=this.filter)!=null&&F.resourceIds&&!this.order?null:t.firstPageSize||((O=n.loading)==null?void 0:O.firstPageSize)||t.pageSize||((k=n.loading)==null?void 0:k.pageSize)||null:t.pageSize||((Q=n.loading)==null?void 0:Q.pageSize)||null,p=h!=null||n.limit!=null?r.min(r.filter([h,n.limit],R=>R!=null)):void 0;p!=null?(u.offset=e,u.limit=p):e!=0&&(u.offset=e);const D=r.map(u,(R,m)=>R!=null?`${encodeURIComponent(m)}=${encodeURIComponent(R)}`:null).filter(R=>R!=null).join("&"),T=r.isEmpty(D)?n.restCollectionUrl:`${n.restCollectionUrl}?${D}`;try{const R=await L.get(T),m=this.fixedQueryParams;if(s!=this._loadId||e!=this._loadOffset||!r.isEqual(d,m))console.log(`Discarding resources fetched by obsolete query from ${n.restCollectionUrl}.`);else{const E=ne.decode(r.get(R,"data.data",[])),q=(l?0:this.resources.length)+E.length,y=p==null||E.length<p||n.limit&&q>=n.limit;console.log(`Loaded ${E.length}${l?"":" more"} resources from ${n.restCollectionUrl}`),l&&(this.resources=[]);const X=[...this.resources,...E.map(Z=>Object.freeze(Z))];this.resources=De(X,this),this.status=y?"Loaded":"LoadingMore",y||this._loadResources(this.resources.length,s,t)}}catch(R){console.log(`Error while loading resources (URL="${T}"):`,R),this.clearRetainingTransientData(),this.status="Failed"}},async checkForDeletedResource(e){let s;try{s=await L.get(`${n.restCollectionUrl}/${e}`)}catch(t){L.isAxiosError(t)&&(s=t.response)}return s&&s.status==404?(this.recordDeletion(e),!0):!1},recordDeletion(e){var s;if(["Loaded","LoadingMore"].includes(this.status)){let t=this.resources.findIndex(l=>v(l,this)==e);t>=0&&this.resources.splice(t,1),t=this.selection.findIndex(l=>v(l,this)==e),t>=0&&this.selection.splice(t,1),t=this.detailSelection.findIndex(l=>v(l,this)==e),t>=0&&(this.detailSelection.splice(t,1),this.detailSelection.length==0&&(this.editingDetailSelection=((s=n.detail)==null?void 0:s.autoEdit)||!1)),n.limitTransientDataToLocalCollection&&delete this.transientData[e]}},recordInsertion(e,{insertAtBeginning:s,transientData:t}={}){var l;if(["Loaded","LoadingMore"].includes(this.status)){const d=Object.freeze(e);s?this.resources.unshift(d):this.resources.push(d),(l=n.detail)!=null&&l.autoFromSingleInsertion&&(this.detailSelection.length==0||this.detailSelection.length==1&&v(this.detailSelection[0],this)==null)&&(this.detailSelection=[d],this.editingDetailSelection=n.detail.autoEdit);const u=v(e,this);u&&(t===void 0?delete this.transientData[u]:this.transientData[u]=t)}},recordUpdate(e){const s=v(e,this);if(s&&["Loaded","LoadingMore"].includes(this.status)){const t=Object.freeze(e);let l=this.resources.findIndex(d=>v(d,this)==s);l>=0&&(this.resources[l]=t),l=this.selection.findIndex(d=>v(d,this)==s),l>=0&&(this.selection[l]=t),l=this.detailSelection.findIndex(d=>v(d,this)==s),l>=0&&(this.detailSelection[l]=t)}},async refreshResource(e){if(e){const s={};this.referencePathsToExpand&&(s.r=J(this.referencePathsToExpand));const t=r.map(s,(u,h)=>u!=null?`${encodeURIComponent(h)}=${encodeURIComponent(u)}`:null).filter(u=>u!=null).join("&"),l=r.isEmpty(t)?`${n.restCollectionUrl}/${e}`:`${n.restCollectionUrl}/${e}?${t}`,d=await L.get(l);if(d.status==200){const u=d.data;return this.recordUpdate(u),u}}return null},addResource(e={}){this.detailSelection=[r.omit(r.merge({},e),this.idProperty)],this.editingDetailSelection=!0},async deleteResource(e){if((await L.delete(`${n.restCollectionUrl}/${e}`)).status==200&&["Loaded","LoadingMore"].includes(this.status)){let t=this.resources.findIndex(l=>v(l,this)==e);t>=0&&this.resources.splice(t,1),t=this.selection.findIndex(l=>v(l,this)==e),t>=0&&this.selection.splice(t,1),t=this.detailSelection.findIndex(l=>v(l,this)==e),t>=0&&(this.detailSelection.splice(t,1),this.detailSelection.length==0&&(this.editingDetailSelection=n.detail.autoEdit)),n.limitTransientDataToLocalCollection&&delete this.transientData[e]}},async saveResource(e){const s=v(e,this),t=s==null,l=await L({method:t?"post":"put",url:t?n.restCollectionUrl:`${n.restCollectionUrl}/${s}`,data:e});if(l.status==200){const d=l.data,u=v(d,this),h=u?await this.refreshResource(u):null;return t&&this.recordInsertion(h||Object.freeze(d)),h||d}return null},async saveResources(e){const s=await L({method:"put",url:n.restCollectionUrl,data:e});if(s.status==200){const t=s.data||[],l=[];for(const[d,u]of t.entries()){const h=v(e[d],this)==null,p=v(u,this),D=p?await this.refreshResource(p):null;h&&this.recordInsertion(D||u),l.push(D||Object.freeze(u))}return l}return[]},clearTransientData(){this.transientData={}},setInvalidResourceIds(e){r.isEqual(e,this.invalidResources.map(s=>v(s,this)))||(this.invalidResources=e.map(s=>this.resources.find(t=>v(t,this)==s)).filter(s=>s!=null))},setTransientDataForResources(e){const{transientData:s,merge:t=!0}=e;t?r.merge(this.transientData,s):r.assign(this.transientData,s)},clearSelection(){this.setSelection([])},deselectResources(e){const s=this.selection.map(t=>v(t,this)).filter(t=>t!=null&&!e.includes(t));this.setSelection(s)},selectResources(e,s){const{addToSelection:t,edit:l}=s||{},d=this.selection.map(h=>v(h,this));let u=e;if(t){const h=r.difference(e,d);h.length>0&&(u=d.concat(h).filter(p=>p!=null))}r.isEqual(d,u)||this.setSelection(u,l)},setSelection(e,s){if(!r.isEqual(e,this.selection.map(t=>v(t,this)))){let t=!0;if(this.editors.length>0){if(n.detail.autoFromSingleSelection&&this.selection.length==1)t=!1;else if(n.detail.autoFromMultipleSelection&&n.detail.allowMultiple&&this.selection.length>1)t=!1;else if(n.detail.constrainToSelection){const l=this.selection.map(h=>v(h,this)),u=this.detailSelection.map(h=>v(h,this)).filter(h=>l.includes(h));this.detailSelection.filter(h=>!u.includes(v(h,this))).length>0&&(t=!1)}}if(!t)return;if(this.selection=e.map(l=>this.resources.find(d=>v(d,this)==l)).filter(l=>l!=null),n.detail.autoFromSingleSelection&&this.selection.length==1){const l=this.selection[0];(this.detailSelection.length!=1||v(this.detailSelection[0],this)!=v(l,this))&&(this.detailSelection=[l])}else if(n.detail.autoFromMultipleSelection&&n.detail.allowMultiple&&this.selection.length>1)r.isEqual(this.selection.map(l=>v(l,this)),this.detailSelection.map(l=>v(l,this)))||(this.detailSelection=r.clone(this.selection));else if(n.detail.constrainToSelection){const l=this.selection.map(h=>v(h,this)),d=this.detailSelection.map(h=>v(h,this)),u=d.filter(h=>l.includes(h));r.isEqual(u,d)||(this.detailSelection=this.detailSelection.filter(h=>u.includes(v(h,this))))}this.detailSelection.length==0?this.editingDetailSelection=!1:this.editingDetailSelection=s!==void 0?s:this.editingDetailSelection||n.detail.autoEdit}},hideDetail(){this.detailSelection.length>0&&(this.detailSelection=[],this.editingDetailSelection=!1)},showSelectionAsDetail(e){if(this.selection.length<=1||n.detail.allowMultiple){const s=this.selection.map(l=>v(l,this)),t=this.detailSelection.map(l=>v(l,this));r.isEqual(s,t)||(this.detailSelection=r.clone(this.selection)),this.detailSelection.length==0?this.editingDetailSelection=!1:this.editingDetailSelection=e!==void 0?e:this.editingDetailSelection||n.detail.autoEdit}},deregisterEditor(e){r.remove(this.editors,s=>s==e)},registerEditor(e){this.editors.includes(e)||this.editors.push(e)},deregisterListNavigator({name:e,listNavigator:s}){(s==null||this.listNavigators[e]==s)&&delete this.listNavigators[e]},registerListNavigator({name:e,listNavigator:s}){this.listNavigators[e]!=s&&(this.listNavigators[e]=s)}}});return(()=>{const e=(s,t)=>{const l=C(s,t);return ee.registerStore(l.$id,l),l};return e.$id=C.$id,e})()},ee=new ce,Ue=(w={})=>{var he,fe,ve,ge;const{collectionId:n,draftBatchId:C,enabled:$,resourceType:e,options:s}=w,t=a.ref(void 0),l=a.ref(n),d=a.ref(C),u=a.ref($??!0),h=a.ref([a.toRef(e)]),p=a.ref(s),D=a.computed(()=>d.value),T=a.ref(u.value),b=a.ref(I.v4()),F=a.ref((fe=(he=p.value)==null?void 0:he.filter)==null?void 0:fe.resourceIds),O=a.ref((ge=(ve=p.value)==null?void 0:ve.filter)==null?void 0:ge.query),k=a.computed(()=>d.value==null&&l.value!=null&&ee.getStore(l.value)!=null),Q=a.ref(k.value),R=a.computed(()=>q("status","Uninitialized"));function m(i){if(t.value)return i(t.value)}async function E(i){if(t.value)return await i(t.value)}function q(i,c){if(t.value)return t.value[i];if(c!==void 0)return c;throw"Attempted to use a REST collection store that has not been created, with no default value."}const y=(i={})=>{var me,pe,Se,ye;const{collectionId:c,draftBatchId:U,enabled:z,resourceType:re,options:Re}=i;l.value=c,d.value=U,u.value=z??!0,h.value=[a.toRef(re)],Re!=null&&(p.value=Re,F.value=(pe=(me=p.value)==null?void 0:me.filter)==null?void 0:pe.resourceIds,O.value=(ye=(Se=p.value)==null?void 0:Se.filter)==null?void 0:ye.query),b.value=I.v4(),X(u.value)},X=async i=>{i!=T.value&&(T.value=i,i&&(_(),x()))},Z=async i=>{F.value=i,await E(async c=>await c.setFilterResourceIds(F.value||null))},V=async i=>{if(O.value=i,R.value!="Uninitialized"){const c=i,U=a.computed(()=>r.isFunction(c)?S.value?c(S.value):null:c);await E(z=>z.setQuery(U.value||null))}},_=()=>{p.value=r.merge({},p.value||{},{filter:{resourceIds:F.value,query:O.value}})},S=a.computed(()=>h.value[0].value||void 0),B=function(i){const c=r.get(i,"filter.query"),U=r.get(i,"referencePathsToExpand"),z=r.isFunction(c)?c(S.value):c,re=S.value?r.isFunction(U)?U(S.value):U||[]:[];return{...r.cloneDeep(i||{}),filter:{...r.cloneDeep((i==null?void 0:i.filter)||{}),query:z},referencePathsToExpand:re}},P=a.computed(()=>B(p.value)),M=a.computed(()=>{if(!S.value)return null;if(P.value.restCollectionUrl!==void 0)return P.value.restCollectionUrl;if(!Q.value)return!S.value||!S.value.collectionName?null:D.value?`${G.config.apiBaseUrl}/draft-batches/${D.value}/${S.value.collectionName}`:`${G.config.apiBaseUrl}/${S.value.collectionName}`}),o=a.computed(()=>{var i;if(S.value)return r.mergeWith(r.cloneDeep(ue),P.value,{idProperty:(i=S.value)==null?void 0:i.idProperty,restCollectionUrl:M.value||""},(c,U)=>{if(r.isArray(U)&&U.length==0&&(c==null||r.isArray(c)))return U})}),f=a.ref(0),N=a.computed(()=>{var i;return f.value,l.value||S.value&&((i=S.value)==null?void 0:i.collectionName)&&(D.value?`draftBatches/${D.value}/${S.value.collectionName}/${b.value}`:`${S.value.collectionName}/${b.value}`)||null}),x=()=>{if(T.value){let i=!1;return S.value&&N.value&&(t.value=ee.getStore(N.value),t.value?i=!1:o.value&&(Q.value=!1,t.value=Ee(N.value,o.value)(),i=!0)),i}else return!1},H=()=>{N.value&&l.value==N.value?(t.value=void 0,x()):(t.value=void 0,f.value=f.value+1,x())};a.watch(D,(i,c)=>{r.isEqual(i,c)||H()}),a.watch(T,(i,c)=>{i!=c&&(i?x():t.value=void 0)}),a.watch(S,(i,c)=>{i&&!c?x():!i&&c||r.isEqual(i,c)||H()}),a.watch(o,(i,c)=>{r.isEqual(i,c)||H()}),a.watch(k,()=>{k.value||(Q.value=!1)}),a.watch(N,()=>x()),a.watch(M,(i,c)=>{r.isEqual(i,c)||H()});const W=[],qe=function(i){R.value!="Uninitialized"?a.nextTick(i):W.push(i)};return a.watch(R,(i,c)=>{if(i!="Uninitialized"&&c=="Uninitialized"){const U=r.clone(W);W.splice(0,W.length);for(const z of U)z()}}),x(),{collectionId:N,draftBatchId:D,resourceType:S,enabled:T,status:R,batchSaveAttempted:a.computed(()=>q("batchSaveAttempted",!1)),invalidResources:a.computed(()=>q("invalidResources",[])),resources:a.computed(()=>R.value!="Uninitialized"?(E(i=>i.ensureCollectionLoaded()),q("resources",[])):[]),transientData:a.computed(()=>q("transientData",[])),detailSelection:a.computed(()=>q("detailSelection",[])),editingDetailSelection:a.computed(()=>q("editingDetailSelection",!1)),selection:a.computed(()=>q("selection",[])),reconfigureCollection:y,setEditingDetailSelection:i=>m(c=>c.setEditingDetailSelection(i)),setEnabled:X,setFilterResourceIds:Z,setQuery:V,ensureStore:x,setBatchSaveAttempted:i=>m(c=>c.setBatchSaveAttempted(i)),clear:()=>m(i=>i.clear()),ensureCollectionLoaded:async()=>await E(async i=>i.ensureCollectionLoaded()),loadResources:async()=>await E(async i=>await i.loadResources()),addResource:i=>m(c=>c.addResource(i)),checkForDeletedResource:async i=>await E(async c=>await c.checkForDeletedResource(i))==!0,recordDeletion:i=>m(c=>c.recordDeletion(i)),recordInsertion:(i,{insertAtBeginning:c=!1,transientData:U=void 0}={})=>m(z=>z.recordInsertion(i,{insertAtBeginning:c,transientData:U})),recordUpdate:i=>m(c=>c.recordUpdate(i)),refreshResource:async i=>await E(async c=>await c.refreshResource(i)),deleteResource:async i=>await E(async c=>await c.deleteResource(i)),saveResource:async i=>await E(async c=>await c.saveResource(i)),saveResources:async i=>await E(async c=>await c.saveResources(i)),clearTransientData:()=>m(i=>i.clearTransientData()),setInvalidResourceIds:i=>m(c=>c.setInvalidResourceIds(i)),setTransientDataForResources:i=>m(c=>c.setTransientDataForResources(i)),clearSelection:()=>m(i=>i.clearSelection()),deselectResources:i=>m(c=>c.deselectResources(i)),selectResources:(i,c)=>m(U=>U.selectResources(i,c)),hideDetail:()=>m(i=>i.hideDetail()),deregisterEditor:i=>m(c=>c.deregisterEditor(i)),registerEditor:i=>m(c=>c.registerEditor(i)),deregisterListNavigator:i=>m(c=>c.deregisterListNavigator(i)),registerListNavigator:i=>m(c=>c.registerListNavigator(i)),onItemsStoreReady:qe}},Ce=()=>{ee.clearAllStores()};function ie(w,n){return r.get(w,(n==null?void 0:n.idProperty)||"_id")}const de={idProperty:"_id"},Y={resource:null,status:"NotLoaded"},Te=(w,n)=>{n=r.merge({},de,n);const C=ae.defineStore(w,{state:()=>({idProperty:n.idProperty,resourceId:n.resourceId||null,resourceUrl:n.resourceUrl||null,referencePathsToExpand:n.referencePathsToExpand||null,...Y}),getters:{currentResourceUrl:e=>e.resourceUrl||(n.restCollectionUrl&&e.resourceId?`${n.restCollectionUrl}/${e.resourceId}`:null)||n.restCollectionUrl||null,fixedQueryParams:e=>{const s={};return e.referencePathsToExpand&&(s.r=J(e.referencePathsToExpand)),s}},actions:{reset(){for(const e in Y)this[e]=Y[e]},async setResourceId(e){const s=this.currentResourceUrl;this.resourceId=e,!r.isEqual(this.currentResourceUrl,s)&&this.status!="NotLoaded"&&await this.loadResource()},async setResourceUrl(e){const s=this.currentResourceUrl;this.resourceUrl=e,!r.isEqual(this.currentResourceUrl,s)&&this.status!="NotLoaded"&&await this.loadResource()},clear(){for(const e in Y)this[e]=Y[e]},async ensureResourceLoaded(){["Loaded","Loading","Failed"].includes(this.status)||await this.loadResource()},async loadResource(){this.reset();const e=I.v4();if(this._loadId=e,this.currentResourceUrl){this.status="Loading";const s=this.fixedQueryParams,t=r.cloneDeep(s),l=r.map(t,(u,h)=>u!=null?`${encodeURIComponent(h)}=${encodeURIComponent(u)}`:null).filter(u=>u!=null).join("&"),d=r.isEmpty(l)?this.currentResourceUrl:`${this.currentResourceUrl}?${l}`;try{const u=await L.get(d),h=this.fixedQueryParams;e!=this._loadId||!r.isEqual(s,h)?console.log(`Discarding resource fetched by obsolete query from ${d}.`):(this.resource=ne.decode(r.get(u,"data",{})),this.status="Loaded")}catch(u){console.log(`Error while loading resource (URL="${d}")`,u),this.reset(),this.status="Failed"}}else throw"Cannot load a resource because its URL, or its ID and collection URL, are unknown."},async checkForDeletedResource(){if(this.currentResourceUrl){let e;try{e=await L.get(this.currentResourceUrl)}catch(s){L.isAxiosError(s)&&(e=s.response)}return e&&e.status==404?(this.recordDeletion(),!0):!1}else throw"Cannot check for a deleted resource because its URL, or its ID and collection URL, are unknown."},recordDeletion(){this.resource=null,this.status="Loaded"},recordInsertion(e){this.resourceId=ie(e,this)||null,this.status=="Loaded"&&(this.resource=Object.freeze(e))},recordUpdate(e){this.resourceId=ie(e,this)||null,this.status=="Loaded"&&(this.resource=Object.freeze(e))},async refreshResource(){return await this.loadResource(),this.resource},async deleteResource(){if(this.currentResourceUrl)(await L.delete(this.currentResourceUrl)).status==200&&this.recordDeletion();else throw"Cannot delete a resource because its URL, or its ID and collection URL, are unknown."},async saveResource(e){const s=ie(e,this),t=s==null;if(!s)throw"The REST resource store cannot create new resources on the server.";if(!this.currentResourceUrl)throw"Cannot save a resource because its URL, or its ID and collection URL, are unknown.";const l=await L({method:t?"post":"put",url:this.currentResourceUrl,data:e});if(l.status==200){const d=l.data,u=await this.refreshResource();return t&&this.recordInsertion(u||d),u||Object.freeze(d)}return null},async makeCustomApiRequest(e){const{method:s,subpath:t,url:l,data:d}=e;let u=l;if(!u)if(this.currentResourceUrl)u=`${this.currentResourceUrl}/${t}`;else throw"Cannot make a custom API request for a resource because its URL, or its ID and collection URL, are unknown.";const h=await L({method:s||"get",url:u,data:d});return h.status>=200&&h.status<300?h.data:null}}});return(()=>{const e=(s,t)=>{const l=C(s,t);return se.registerStore(l.$id,l),l};return e.$id=C.$id,e})()},se=new ce,Le=(w={})=>{const{resourceClientId:n,draftBatchId:C,enabled:$,resourceType:e,options:s}=w,t=a.ref(void 0),l=a.ref(n),d=a.ref(C),u=a.ref($??!0),h=a.ref([a.toRef(e)]),p=a.ref(s),D=a.computed(()=>d.value),T=a.ref(u.value),b=a.ref(I.v4()),F=a.computed(()=>d.value==null&&l.value!=null&&se.getStore(l.value)!=null),O=a.ref(F.value),k=a.computed(()=>m("status","Uninitialized"));function Q(o){if(t.value)return o(t.value)}async function R(o){if(t.value)return await o(t.value)}function m(o,f){if(t.value)return t.value[o];if(f!==void 0)return f;throw"Attempted to use a REST resource store that has not been created, with no default value."}const E=(o={})=>{const{resourceClientId:f,draftBatchId:N,enabled:x,resourceType:H,options:W}=o;l.value=f,d.value=N,u.value=x??!0,h.value=[a.toRef(H)],W!=null&&(p.value=W),b.value=I.v4(),q(u.value)},q=async o=>{o!=T.value&&(T.value=o,o&&P())},y=a.computed(()=>h.value[0].value||void 0),X=function(o){const f=r.get(o,"referencePathsToExpand"),N=y.value?r.isFunction(f)?f(y.value):f||[]:[];return{...r.cloneDeep(o||{}),referencePathsToExpand:N}},Z=a.computed(()=>X(p.value)),V=a.computed(()=>{if(!y.value)return null;if(!O.value)return!y.value||!y.value.collectionName?null:D.value?`${G.config.apiBaseUrl}/draft-batches/${D.value}/${y.value.collectionName}`:`${G.config.apiBaseUrl}/${y.value.collectionName}`}),_=a.computed(()=>{if(y.value&&V.value)return r.mergeWith(r.cloneDeep(de),Z.value,{idProperty:y.value.idProperty,restCollectionUrl:V.value},(o,f)=>{if(r.isArray(f)&&f.length==0&&(o==null||r.isArray(o)))return f})}),S=a.ref(0),B=a.computed(()=>{var o;return S.value,l.value||y.value&&((o=y.value)==null?void 0:o.collectionName)&&(D.value?`draftBatches/${D.value}/${y.value.collectionName}/${b.value}`:`${y.value.collectionName}/${b.value}`)||null}),P=()=>{if(T.value){let o=!1;return y.value&&B.value&&(t.value=se.getStore(B.value),t.value?o=!1:_.value&&(O.value=!1,t.value=Te(B.value,_.value)(),o=!0)),o}else return!1},M=()=>{B.value&&l.value==B.value?(t.value=void 0,P()):(t.value=void 0,S.value=S.value+1,P())};return a.watch(D,(o,f)=>{r.isEqual(o,f)||M()}),a.watch(T,(o,f)=>{o!=f&&(o?P():t.value=void 0)}),a.watch(y,(o,f)=>{o&&!f?P():!o&&f||r.isEqual(o,f)||M()}),a.watch(_,(o,f)=>{r.isEqual(o,f)||M()}),a.watch(F,()=>{F.value||(O.value=!1)}),a.watch(B,()=>P()),a.watch(V,(o,f)=>{r.isEqual(o,f)||M()}),P(),{resourceClientId:B,draftBatchId:D,enabled:T,resourceType:y,status:k,resource:a.computed(()=>k.value!="Uninitialized"?(R(o=>o.ensureResourceLoaded()),m("resource",[])):[]),resourceId:a.computed(()=>m("resourceId",null)),resourceUrl:a.computed(()=>m("resourceUrl",null)),reconfigureClient:E,setEnabled:q,setResourceId:async o=>await R(async f=>await f.setResourceId(o)),setResourceUrl:async o=>await R(async f=>await f.setResourceUrl(o)),ensureStore:P,clear:()=>Q(o=>o.clear()),ensureResourceLoaded:async()=>await R(async o=>o.ensureResourceLoaded()),loadResource:async()=>await R(async o=>await o.loadResource()),checkForDeletedResource:async()=>await R(async o=>await o.checkForDeletedResource())==!0,recordDeletion:()=>R(o=>o.recordDeletion()),recordInsertion:o=>R(f=>f.recordInsertion(o)),recordUpdate:o=>R(f=>f.recordUpdate(o)),refreshResource:async()=>await R(async o=>await o.refreshResource()),deleteResource:async()=>await R(async o=>await o.deleteResource()),saveResource:async o=>await R(async f=>await f.saveResource(o)),makeCustomApiRequest:async o=>await R(async f=>await f.makeCustomApiRequest(o))}},G={config:{...oe}};function $e(w){G.config=r.merge({},oe,w)}g.ApiClientError=we,g.clearAllRestCollections=Ce,g.initRestClient=$e,g.restClient=G,g.useRestCollection=Ue,g.useRestResource=Le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,12 @@
1
+ export interface RestClientConfigInput {
2
+ apiBaseUrl?: string;
3
+ useVueLogger?: boolean;
4
+ }
5
+ export interface RestClientConfig extends RestClientConfigInput {
6
+ apiBaseUrl: string;
7
+ useVueLogger: boolean;
8
+ }
9
+ export declare const DEFAULT_REST_CLIENT_CONFIG: {
10
+ apiBaseUrl: string;
11
+ useVueLogger: boolean;
12
+ };
@@ -0,0 +1,5 @@
1
+ export declare class ApiClientError extends Error {
2
+ context: object | undefined;
3
+ innerError: any;
4
+ constructor(message: any, context?: object | undefined, innerError?: any);
5
+ }
@@ -0,0 +1,11 @@
1
+ import { RestClientConfig, RestClientConfigInput } from './config.js';
2
+ export declare const restClient: {
3
+ config: RestClientConfig;
4
+ };
5
+ export declare function initRestClient(config: RestClientConfigInput): void;
6
+ export * from './errors.js';
7
+ export { default as useRestCollection } from './rest-collection.js';
8
+ export * from './rest-collection.js';
9
+ export { default as useRestResource } from './rest-resource.js';
10
+ export * from './rest-resource.js';
11
+ export * from './rest-collection-resources.js';
@@ -0,0 +1,95 @@
1
+ export type PropertyPathStr = string;
2
+ export type PropertyPathArray = (string | number)[];
3
+ export type PropertyPath = PropertyPathStr | PropertyPathArray;
4
+ export type JsonPathStr = string;
5
+ export type JsonPointerStr = string;
6
+ export type QueryConstant = string | number | boolean | null;
7
+ export type QueryFullTextSearchContext = 'default';
8
+ export type QueryPath = string;
9
+ export interface QueryCoalesceExpression {
10
+ coalesce: (QueryConstantExpression | QueryPathExpression)[];
11
+ }
12
+ export interface QueryConstantExpression {
13
+ constant: QueryConstant;
14
+ }
15
+ export interface QueryConstantListExpression {
16
+ constant: QueryConstant[];
17
+ }
18
+ export interface QueryFullTextExpression {
19
+ text: QueryFullTextSearchContext;
20
+ }
21
+ export interface QueryFunctionExpression {
22
+ function: string;
23
+ parameters: (QueryConstantExpression | QueryPathExpression)[];
24
+ }
25
+ export interface QueryOperatorExpression {
26
+ operator: string;
27
+ parameters: (QueryConstantExpression | QueryPathExpression)[];
28
+ }
29
+ export interface QueryPathExpression {
30
+ path: QueryPath;
31
+ sqlType?: string;
32
+ }
33
+ export interface QueryRangeExpression {
34
+ range: [QueryConstantExpression, QueryConstantExpression];
35
+ }
36
+ export type QueryExpression = QueryCoalesceExpression | QueryConstantExpression | QueryConstantListExpression | QueryFullTextExpression | QueryFunctionExpression | QueryOperatorExpression | QueryPathExpression | QueryRangeExpression;
37
+ export interface QueryBetweenClause {
38
+ operator: 'between';
39
+ l: QueryConstantExpression | QueryPathExpression;
40
+ r: QueryRangeExpression;
41
+ }
42
+ export interface QueryComparisonClause {
43
+ operator?: '=' | '<' | '>' | '<=' | '>=' | '!=' | 'like';
44
+ l: QueryConstantExpression | QueryPathExpression;
45
+ r: QueryConstantExpression | QueryPathExpression;
46
+ }
47
+ export interface QueryInClause {
48
+ operator: 'in';
49
+ l: QueryConstantExpression | QueryPathExpression;
50
+ r: QueryConstantListExpression;
51
+ }
52
+ export interface QueryFullTextSearchClause {
53
+ operator: 'contains';
54
+ l: QueryFullTextExpression;
55
+ r: QueryConstantExpression | QueryPathExpression;
56
+ }
57
+ export type QuerySimpleClause = QueryBetweenClause | QueryComparisonClause | QueryInClause | QueryFullTextSearchClause;
58
+ export interface QueryAndClause {
59
+ and: QueryClause[];
60
+ }
61
+ export interface QueryOrClause {
62
+ or: QueryClause[];
63
+ }
64
+ export interface QueryNotClause {
65
+ not: QueryClause;
66
+ }
67
+ export type QueryClause = QuerySimpleClause | QueryAndClause | QueryOrClause | QueryNotClause | true | false;
68
+ export type QueryOrderProperty = QueryPathExpression;
69
+ export type QueryOrderDirection = 'asc' | 'desc' | 'ASC' | 'DESC';
70
+ export type QueryOrderElement = QueryOrderProperty | [QueryOrderProperty, QueryOrderDirection];
71
+ export type QueryOrder = QueryOrderElement[];
72
+ export interface SqlExpression {
73
+ expression: string;
74
+ parameterValues: any[];
75
+ }
76
+ export interface SqlClause {
77
+ sqlClause: string | null;
78
+ parameterValues: any[];
79
+ }
80
+ export declare function queryExpressionIsCoalesce(expression: QueryExpression): expression is QueryCoalesceExpression;
81
+ export declare function queryExpressionIsConstant(expression: QueryExpression): expression is QueryConstantExpression;
82
+ export declare function queryExpressionIsConstantList(expression: QueryExpression): expression is QueryConstantListExpression;
83
+ export declare function queryExpressionIsFunction(expression: QueryExpression): expression is QueryFunctionExpression;
84
+ export declare function queryExpressionIsOperator(expression: QueryExpression): expression is QueryOperatorExpression;
85
+ export declare function queryExpressionIsFullText(expression: QueryExpression): expression is QueryFullTextExpression;
86
+ export declare function queryExpressionIsPath(expression: QueryExpression): expression is QueryPathExpression;
87
+ export declare function queryExpressionIsRange(expression: QueryExpression): expression is QueryRangeExpression;
88
+ export declare function queryClauseIsBetween(clause: QueryClause): clause is QueryBetweenClause;
89
+ export declare function queryClauseIsComparisonn(clause: QueryClause): clause is QueryComparisonClause;
90
+ export declare function queryClauseIsIn(clause: QueryClause): clause is QueryInClause;
91
+ export declare function queryClauseIsFullTextSearch(clause: QueryClause): clause is QueryFullTextSearchClause;
92
+ export declare function queryClauseIsSimple(clause: QueryClause): clause is QuerySimpleClause;
93
+ export declare function queryClauseIsAnd(clause: QueryClause): clause is QueryAndClause;
94
+ export declare function queryClauseIsOr(clause: QueryClause): clause is QueryOrClause;
95
+ export declare function queryClauseIsNot(clause: QueryClause): clause is QueryNotClause;
@@ -0,0 +1,30 @@
1
+ /** A REST resource type, i.e. a description of items in one REST collection. */
2
+ export interface ResourceType {
3
+ /** The REST collection name, which is used in constructing its path. */
4
+ collectionName: string;
5
+ /** The property path (in dot notation) for each resource's primary key. */
6
+ idProperty?: string;
7
+ /** Subcollections of each resource. */
8
+ subcollections?: ResourceSubcollection[];
9
+ /** Custom data attached by the client. */
10
+ custom?: {
11
+ [key: string]: any;
12
+ };
13
+ }
14
+ /** A subcollection belonging to each resource of a certain type. */
15
+ export interface ResourceSubcollection {
16
+ /** The subcollection name, which is used in constructing its path. */
17
+ name: string;
18
+ /** The resource type of subcollection members. */
19
+ type: ResourceType;
20
+ }
21
+ /**
22
+ * A primary key value identifying a resource within its collection.
23
+ *
24
+ * Every resource must have an ID, which is currently assumed to be stored in its _id property.
25
+ */
26
+ export type ResourceId<T = string | number> = T;
27
+ /** A resource from a REST collection. */
28
+ export type Resource = object;
29
+ export type RestCollectionQuery = any;
30
+ export type RestCollectionOrder = any;
@@ -0,0 +1,308 @@
1
+ import { Ref } from 'vue';
2
+ import { Resource, ResourceId, ResourceType } from './rest-collection-resources.js';
3
+ import { RestCollectionStatus } from './stores/rest-collection-store.js';
4
+ /** Options that define a REST collection. */
5
+ export interface RestCollectionOptions {
6
+ /**
7
+ * The REST collection's unique identifier, which will be used as the ID of its Pinia store.
8
+ *
9
+ * This is normally generated, and the generated ID may be accessed using the collection's {@link collectionId}
10
+ * property.
11
+ *
12
+ * There are two circumstances where you may want to specify a collection ID:
13
+ * 1. You have already created a collection and want to give another Vue component access to it. In this case, pass
14
+ * the value of the collection's {@link collectionId} property in the options to the second component's
15
+ * {@link useRestCollection} call.
16
+ * 2. You want to assign a canonical ID to the collection, so that components can call {@link useRestCollection} to
17
+ * create it or to access it if it already exists. In this case, you can assign the ID manually, but you must ensure
18
+ * that it does not conflict with any other Pinia store IDs used in the Vue application.
19
+ *
20
+ * - If not specified, an unique ID will be generated.
21
+ * - If specified, the REST collection will check whether a Pinia store with this ID already exists.
22
+ * - If one exists, that store will be used, and other options will be ignored. This is a way to have multiple
23
+ * components' {@link RestCollection}s share a single data store.
24
+ * - If a Pinia store does not exist, then when creating a new collection, the ID will be used instead of generating
25
+ * a new unique ID.
26
+ */
27
+ collectionId?: string;
28
+ draftBatchId?: string;
29
+ enabled?: boolean;
30
+ /** The resource type. */
31
+ resourceType?: Ref<ResourceType | undefined> | ResourceType;
32
+ /** Options that govern the behavior of the REST collections's data store module. */
33
+ options?: RestCollectionStoreOptionsInput;
34
+ }
35
+ export interface ConcreteRestCollectionStoreOptionsInput {
36
+ detail?: {
37
+ allowMultiple?: boolean;
38
+ autoEdit?: boolean;
39
+ autoFromMultipleSelection?: boolean;
40
+ autoFromSingleInsertion?: boolean;
41
+ autoFromSingleSelection?: boolean;
42
+ constrainToSelection?: boolean;
43
+ };
44
+ filter?: {
45
+ namedFilter?: string | null;
46
+ query?: any | null;
47
+ resourceIds?: ResourceId[] | null;
48
+ };
49
+ limit?: number | null;
50
+ limitTransientDataToLocalCollection?: boolean;
51
+ loadId?: string | null;
52
+ loading?: {
53
+ firstPageSize?: number | null;
54
+ pageSize?: number | null;
55
+ };
56
+ order?: [any, string][];
57
+ referencePathsToExpand?: string[];
58
+ restCollectionUrl?: string | null;
59
+ }
60
+ export interface RestCollectionStoreOptionsInput {
61
+ detail?: {
62
+ allowMultiple?: boolean;
63
+ autoEdit?: boolean;
64
+ autoFromMultipleSelection?: boolean;
65
+ autoFromSingleInsertion?: boolean;
66
+ autoFromSingleSelection?: boolean;
67
+ constrainToSelection?: boolean;
68
+ };
69
+ filter?: {
70
+ namedFilter?: string | null;
71
+ query?: any | null | ((resourceType: ResourceType) => any | null);
72
+ resourceIds?: ResourceId[] | null;
73
+ };
74
+ limit?: number | null;
75
+ limitTransientDataToLocalCollection?: boolean;
76
+ loadId?: string | null;
77
+ loading?: {
78
+ firstPageSize?: number | null;
79
+ pageSize?: number | null;
80
+ };
81
+ order?: [any, string][];
82
+ referencePathsToExpand?: string[] | ((resourceType: ResourceType) => string[]);
83
+ restCollectionUrl?: string | null;
84
+ }
85
+ export interface LoadResourcesParams {
86
+ firstPageSize?: number;
87
+ pageSize?: number;
88
+ }
89
+ export interface SelectResourcesOptions {
90
+ addToSelection?: boolean;
91
+ edit?: boolean;
92
+ }
93
+ /** Parameters to {@link RestCollection.setTransientDataForResources} */
94
+ export interface SetTransientDataParams {
95
+ /** Transient data keyed by resource ID. */
96
+ transientData: {
97
+ /** Transient data for one resource. */
98
+ [resourceId: ResourceId]: object;
99
+ };
100
+ /**
101
+ * Flag indicating whether new transient data should replace existing transient data for each resource or be merged
102
+ * with it.
103
+ */
104
+ merge?: boolean;
105
+ }
106
+ export type RestCollectionStoreReadyCallback = (() => void) | (() => Promise<void>);
107
+ /**
108
+ * A REST collection.
109
+ *
110
+ * This represents a collection of resources (records) fetched from a REST API. Most commonly, it represents all the
111
+ * resources from one collection endpoint of the REST API; but filters can be added when using a REST API that supports
112
+ * them.
113
+ */
114
+ export interface RestCollection {
115
+ /**
116
+ * The REST collection's unique ID, which is used as the ID of its Pinia store.
117
+ *
118
+ * If you want to share the store with another component, you can pass this ID when creating the second component's
119
+ * {@link RestCollection}.
120
+ */
121
+ collectionId: Ref<string | null>;
122
+ /** The draft batch ID, if one was passed in {@link RestCollectionOptions.draftBatchId}. */
123
+ draftBatchId: Ref<string | undefined>;
124
+ /** A flag indicating whether accessing the local collection will fetch data from the remote collection. */
125
+ enabled: Ref<boolean>;
126
+ /**
127
+ * The resource type for this collection.
128
+ *
129
+ * To allow for asynchronous loading of resource types, this may be undefined.
130
+ */
131
+ resourceType: Ref<ResourceType | undefined>;
132
+ /** A status indicating whether resources have been loaded yet from the REST API. */
133
+ status: Ref<RestCollectionStatus>;
134
+ batchSaveAttempted: Ref<boolean>;
135
+ /**
136
+ * An array of resources that have failed validation. The client must manage this list by calling
137
+ * {@link setInvalidResourceIds}
138
+ **/
139
+ invalidResources: Ref<Resource[]>;
140
+ /** The array of resources that have been loaded from the REST API into the local collection. */
141
+ resources: Ref<Resource[]>;
142
+ /** Transient data that a client has associated with the resources via {@link setTransientDataForResources}. */
143
+ transientData: Ref<any[]>;
144
+ /** Resources in the current detail view, a sublist of {@link resources}. */
145
+ detailSelection: Ref<Resource[]>;
146
+ /** A flag indicating whether the detail selection is currently being edited or only displayed. */
147
+ editingDetailSelection: Ref<boolean>;
148
+ /** The current selection, a sublist of {@link resources}. */
149
+ selection: Ref<Resource[]>;
150
+ /**
151
+ * Apply new configuration options.
152
+ *
153
+ * The result is much like creating a new RestCollection, except that the client can continue using the same
154
+ * properties.
155
+ *
156
+ * @param options New options to apply.
157
+ */
158
+ reconfigureCollection: (options: RestCollectionOptions) => void;
159
+ setEditingDetailSelection: (editingDetailSelection: boolean) => void;
160
+ setEnabled: (enabled: boolean) => void;
161
+ /**
162
+ * Set filter consisting of a list of resource IDs to fetch from the collection.
163
+ *
164
+ * This relies on a filtering request format that is not a part of the informal REST standard, so use of this method
165
+ * should be limited to APIs that adhere to our extended REST standard, i.e. TODO.
166
+ *
167
+ * If the previous state was anything other than NotLoaded, the collection will be immediately refreshed as if the
168
+ * client had called {@link loadResources}. Calls made with await will return once the first page of results have
169
+ * loaded or failed (just as when you call {@link loadResources} with await).
170
+ *
171
+ * @param filterResourceIds The list if resource IDs to fetch from the REST collection.
172
+ * @return A promise that resolves when the first page of resources is loaded, or immediately if the collection does
173
+ * not need to be reloaded.
174
+ */
175
+ setFilterResourceIds: (filterResourceIds: ResourceId[]) => Promise<void>;
176
+ /**
177
+ * Apply a new filter query.
178
+ *
179
+ * Since filter queries are not a part of the informal REST standard, use of this method should be limited to APIs
180
+ * that adhere to our extended REST standard, i.e. TODO.
181
+ *
182
+ * If the previous state was anything other than NotLoaded, the collection will be immediately refreshed as if the
183
+ * client had called {@link loadResources}. Calls made with await will return once the first page of results have
184
+ * loaded or failed (just as when you call {@link loadResources} with await).
185
+ *
186
+ * @param query The query for filtering the REST collection. This will be sent to the REST API as a query parameter.
187
+ */
188
+ setQuery: (query: any | null | ((resourceType: ResourceType) => any | null)) => Promise<void>;
189
+ /**
190
+ * Ensure that a Pinia store has been created for this REST collection.
191
+ *
192
+ * This does not normally need to be called, because it will happen automatically when the {@link RestCollection} is
193
+ * created and when {@link collectionId}, {@link resourceType}, or options change.
194
+ *
195
+ * @return true if the store has been created or replaced. (Note that false does not indicate that the store does not
196
+ * exist.)
197
+ */
198
+ ensureStore: () => boolean;
199
+ setBatchSaveAttempted: (batchSaveAttempted: boolean) => void;
200
+ /** Return the {@link RestCollection} to the NotLoaded state, where no resources have been fetched yet. */
201
+ clear: () => void;
202
+ /**
203
+ * Fetch the collection from the REST API, if this has not happened yet.
204
+ *
205
+ * A client that observes changes to the reactive property {@link resources} should never need to call this.
206
+ *
207
+ * @return A promise that resolves when the first page of results have loaded or loading has failed.
208
+ */
209
+ ensureCollectionLoaded: () => Promise<void>;
210
+ /**
211
+ * Fetch the collection from the REST API.
212
+ *
213
+ * A client that observes changes to the reactive property {@link resources} should never need to call this.
214
+ *
215
+ * If you call this with await, the call will return once the first page of results have loaded or failed.
216
+ *
217
+ * @param payload Parameters governing page size.
218
+ * @return A promise that resolves when the first page of results have loaded or loading has failed.
219
+ */
220
+ loadResources: (params: LoadResourcesParams) => Promise<void>;
221
+ /**
222
+ * Start editing a new resource, whose properties are all undefined except for any passed in the parameter.
223
+ *
224
+ * @param resourceDefaults An object containing initial property values for the new resource.
225
+ */
226
+ addResource: (resourceDefaults?: Resource) => void;
227
+ checkForDeletedResource: (resourceId: ResourceId) => Promise<boolean>;
228
+ recordDeletion: (resourceId: ResourceId) => void;
229
+ recordInsertion: (resource: Resource, { insertAtBeginning, transientData }?: {
230
+ insertAtBeginning?: boolean;
231
+ transientData?: any;
232
+ }) => void;
233
+ recordUpdate: (resource: Resource) => void;
234
+ /**
235
+ * Refresh one resource by fetching it again from the REST API.
236
+ *
237
+ * If you call this with await, it will return once the API call has completed.
238
+ *
239
+ * @param resourceId The ID of the resource to refresh.
240
+ */
241
+ refreshResource: (resourceId: ResourceId) => Promise<Resource | null | undefined>;
242
+ /**
243
+ * Delete one resource.
244
+ *
245
+ * If you call this with await, it will return once the API call has completed.
246
+ *
247
+ * @param resourceId The ID of the resource to delete.
248
+ */
249
+ deleteResource: (resourceId: ResourceId) => Promise<void>;
250
+ /**
251
+ * Save one resource (new or updated).
252
+ *
253
+ * The resource will be updated if it has a resource ID, created if not.
254
+ *
255
+ * If you call this with await, it will return once the API call has completed, and if the APi call succeeded, it will
256
+ * return the newly saved item.
257
+ *
258
+ * @param resource The resource to create or update.
259
+ */
260
+ saveResource: (resource: Resource) => Promise<Resource | null | undefined>;
261
+ /**
262
+ * Save multiple resources (new or updated).
263
+ *
264
+ * Each resource will be updated if it has a resource ID, created if not.
265
+ *
266
+ * If you call this with await, it will return once the API call has completed, and if the APi call succeeded, it will
267
+ * return the newly saved item.
268
+ *
269
+ * @param params TODO
270
+ */
271
+ saveResources: (resources: Resource[]) => Promise<Resource[] | undefined>;
272
+ /**
273
+ * Record which resources have failed validation.
274
+ *
275
+ * The REST collection does not interact directly with any validation code. The ability to record which resources
276
+ * failed validation is purely a convenience for clients that want to store this information. To store more complex
277
+ * information about validation, consider setting transient data associated with resources.
278
+ *
279
+ * @param resourceIds The IDs of all resources that failed validation.
280
+ */
281
+ setInvalidResourceIds: (resourceIds: ResourceId[]) => void;
282
+ /** Clear all transient data associated with resources. */
283
+ clearTransientData: () => void;
284
+ /**
285
+ * Associate transient data with REST resources that have been fetched from the API.
286
+ *
287
+ * @param params Parameters, including transient data for zero or more resources, keyed by resource ID.
288
+ */
289
+ setTransientDataForResources: (params: SetTransientDataParams) => void;
290
+ clearSelection: () => void;
291
+ deselectResources: (resourceIds: ResourceId[]) => void;
292
+ selectResources: (resourceIds: ResourceId[], options?: SelectResourcesOptions) => void;
293
+ hideDetail: () => void;
294
+ deregisterEditor: (editor: any) => void;
295
+ registerEditor: (editor: any) => void;
296
+ deregisterListNavigator: ({ name, listNavigator }: {
297
+ name: string;
298
+ listNavigator: any;
299
+ }) => void;
300
+ registerListNavigator: ({ name, listNavigator }: {
301
+ name: string;
302
+ listNavigator: any;
303
+ }) => void;
304
+ onItemsStoreReady: (callback: RestCollectionStoreReadyCallback) => void;
305
+ }
306
+ declare const _default: (params?: RestCollectionOptions) => RestCollection;
307
+ export default _default;
308
+ export declare const clearAllRestCollections: () => void;