@data-client/vue 0.18.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @data-client/vue
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3960](https://github.com/reactive/data-client/pull/3960) [`dfa657e`](https://github.com/reactive/data-client/commit/dfa657eb419641845bc7c39abe52189905773190) - Endpoints that resolve to falsy values (`''`, `0`, `false`, or `null`) no longer trigger infinite refetches.
8
+
9
+ - Updated dependencies [[`dfa657e`](https://github.com/reactive/data-client/commit/dfa657eb419641845bc7c39abe52189905773190)]:
10
+ - @data-client/core@0.18.1
11
+
3
12
  ## 0.18.0
4
13
 
5
14
  ### Minor Changes
@@ -34,7 +43,7 @@
34
43
  }
35
44
  ```
36
45
 
37
- The new [`IDenormalizeDelegate`](https://dataclient.io/rest/api/CustomSchema)
46
+ The new [`IDenormalizeDelegate`](https://dataclient.io/rest/api/SchemaSimple)
38
47
  exposes `unvisit`, `args`, and a new `argsKey(fn)` helper that registers
39
48
  a memoization dimension when output varies with endpoint args. Reading
40
49
  `delegate.args` directly does _not_ contribute to cache invalidation —
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VDC={},e.Vue)}(this,(function(e,t){"use strict";class n{constructor(e=[]){this.localCache=new Map,this._args=e}getEntity(e,t,n,s){const i=t.key;this.localCache.has(i)||this.localCache.set(i,new Map);const r=this.localCache.get(i);return r.get(e)||s(r),r.get(e)}getResults(e,t,n){return{data:n(),paths:[]}}argsKey(e){return e(this._args)}}const s=Symbol("INVALID"),i={};const r=e=>e[0],a=e=>void 0!==e&&"symbol"!=typeof e,o=(e,t,n,s,i)=>{e=r(e);const a=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return a.map((t=>i.visit(e,t,n,s)))},c=(e,t,n)=>(e=r(e),t.map?t.map((t=>n.unvisit(e,t))).filter(a):t);function l(){}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},u.apply(null,arguments)}const h=(e,t,n,s,i)=>{const r=u({},t),a=Object.keys(e);for(let n=0;n<a.length;n++){const s=a[n],o=e[s],c=i.visit(o,t[s],t,s);void 0===c?delete r[s]:r[s]=c}return r},d=(e,t,n)=>{if(function(e){return!("function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}(t))return function(e,t,n){let i=!1;const r=Object.keys(e).reduce(((t,s)=>{const r=`${s}`,a=n.unvisit(e[r],t.get(r));return"symbol"==typeof a&&(i=!0),t.has(r)?t.set(r,a):t}),t);return i?s:r}(e,t,n);const i=u({},t);let r=!1;const a=Object.keys(e);for(let t=0;t<a.length;t++){const s=a[t],o=n.unvisit(e[s],i[s]);void 0!==i[s]&&(i[s]=o),"symbol"==typeof o&&(r=!0)}return r?s:i};function p(e,t,n,s){const i={};for(const r of Object.keys(e))i[r]=n(e[r],t,s);return i}const f=(e,t,n)=>function(s,r){const a="object"!=typeof r,o=a?e({key:s.key,pk:r}):r;if("symbol"==typeof o)return s.denormalize(o,n);if(void 0===o&&a&&""!==r&&"undefined"!==r)return t.getEntity(r,s,i,(e=>{e.set(r,void 0)}));if("object"!=typeof o||null===o)return o;let c=a?r:s.pk(o,void 0,void 0,n.args);return void 0===c||""===c||"undefined"===c?function(e){const t=new Map;return e(t),t.get("")}((e=>y(s,o,"",e,n))):("string"!=typeof c&&(c=`${c}`),t.getEntity(c,s,o,(e=>y(s,o,c,e,n))))};function y(e,t,n,i,r){const a=e.createIfValid(t);void 0===a?i.set(n,s):(i.set(n,a),i.set(n,e.denormalize(a,r)))}const g=(e,t,n)=>{let i=0;const r={args:n,unvisit:o,argsKey:e=>t.argsKey(e)},a=f(e,t,r);function o(t,n){if(!t)return n;if(null==n)return n;if("function"==typeof t.denormalize){if(function(e){return null!==e&&void 0!==e.pk}(t)){var o;if(i>=(null!=(o=t.maxEntityDepth)?o:64))return function(e,t,n){var i;const r="object"!=typeof n?e({key:t.key,pk:n}):n;return"object"!=typeof r||null===r?r:null!=(i=t.createIfValid(r))?i:s}(e,t,n);i++;const r=a(t,n);return i--,r}return"function"==typeof t.createIfValid&&"string"==typeof n?a(t,n):t.denormalize(n,r)}if("function"==typeof t)return t(n);if("object"==typeof t){return(Array.isArray(t)?c:d)(t,n,r)}return n}return(e,n)=>{const s=Object(n)===n&&Object(e)===e;return t.getResults(n,s,(()=>o(e,n)))}};class v{constructor({entities:e,indexes:t}){this.entities=e,this.indexes=t}tracked(e){const t=this,n=[{path:[""],entity:e}];return[{INVALID:s,getIndex(...e){const s=t.getIndex(...e);return n.push({path:e,entity:s}),t.getIndexEnd(s,e[2])},getEntity(...e){const s=t.getEntity(...e);return n.push({path:e,entity:s}),s},getEntities(e){const s=t.getEntitiesObject(e);return n.push({path:[e],entity:s}),t.getEntities(e)}},n]}}class m extends v{constructor(e){super(e)}getEntitiesObject(e){return this.entities[e]}getEntities(e){const t=this.entities[e];if(void 0!==t)return{keys:()=>Object.keys(t),entries:()=>Object.entries(t)}}getEntity(e,t){var n;return null==(n=this.entities[e])?void 0:n[t]}getIndex(e,t){var n;return null==(n=this.indexes[e])?void 0:n[t]}getIndexEnd(e,t){return null==e?void 0:e[t]}}const w={QueryDelegate:m,getEntities:e=>({key:t,pk:n})=>{var s;return null==(s=e[t])?void 0:s[n]}};class E{constructor(){this.next=new WeakMap,this.nextPath=void 0,this.hasStr=!1}get(e,t,n=[]){let s=this.next.get(e);if(!s)return x;if(this.hasStr)return this._getMixed(s,t,n);for(;s.nextPath;){var r;const e=null!=(r=t(s.nextPath))?r:i,n=s.next.get(e);if(!n)return x;s=n}return[s.value,s.journey]}_getMixed(e,t,n){for(;e.nextPath;){let o;if("function"==typeof e.nextPath){var s,r;const t=null!=(s=e.nextPath(n))?s:"\0";o=null==(r=e.nextStr)?void 0:r.get(t)}else{var a;const n=null!=(a=t(e.nextPath))?a:i;o=e.next.get(n)}if(!o)return x;e=o}return[e.value,e.journey]}set(e,t,n=[],s){if(e.length<1)throw new k;let r=this;for(const t of e){let e;if("function"==typeof t.path){var a;this.hasStr=!0,r.nextStr||(r.nextStr=new Map);const s=null!=(a=t.path(n))?a:"\0";e=r.nextStr.get(s),e||(e=new b,r.nextStr.set(s,e))}else{var o;if(e=r.next.get(t.entity),!e)e=new b,r.next.set(null!=(o=t.entity)?o:i,e)}r.nextPath=t.path,r=e}r.nextPath=void 0,r.value=t,r.journey=null!=s?s:e.map((e=>e.path))}get hasStringDeps(){return this.hasStr}}const x=[void 0,void 0];class b{constructor(){this.next=new WeakMap,this.nextStr=void 0,this.nextPath=void 0,this.value=void 0,this.journey=[]}}class k extends Error{constructor(...e){super(...e),this.message="Keys must include at least one member"}}class S extends m{constructor(e,t,n){super(e),this.newEntities=new Map,this.newIndexes=new Map,this.entitiesMeta=e.entitiesMeta,this.args=t,this.meta=n,this.checkLoop=function(){const e=new Map;return function(t,n,s){let i=e.get(t);i||(i=new Map,e.set(t,i));let r=i.get(n);return r||(r=new Set,i.set(n,r)),!!r.has(s)||(r.add(s),!1)}}()}getNewEntity(e,t){return this.getNewEntities(e).get(t)}getNewEntities(e){let t=this.newEntities.get(e);return void 0===t&&(t=new Map,this.newEntities.set(e,t)),t}getNewIndexes(e){return this.newIndexes.has(e)||(this.newIndexes.set(e,new Map),this.indexes[e]=u({},this.indexes[e])),this.newIndexes.get(e)}mergeEntity(e,t,n){const s=e.key;let i=n,r=this.meta,a=this.getNewEntity(s,t);if(a)i=e.merge(a,n);else if(a=this.getEntity(s,t),a){const o=this.getMeta(s,t);i=e.mergeWithStore(o,r,a,n),r=e.mergeMetaWithStore(o,r,a,n)}this.setEntity(e,t,i,r)}setEntity(e,t,n,i=this.meta){const r=e.key,a=this.getNewEntities(r),o=!a.has(t);o&&0===a.size&&(this.entities[r]=u({},this.entities[r]),this.entitiesMeta[r]=u({},this.entitiesMeta[r])),a.set(t,n),e.indexes&&function(e,t,n,i,r,a){for(const o of t){n.has(o)||n.set(o,i[o]={});const t=n.get(o);a[e]&&delete t[a[e][o]],a&&a[e]&&a[e][o]!==r[o]&&(t[a[e][o]]=s),o in r&&(t[r[o]]=e)}}(t,e.indexes,this.getNewIndexes(r),this.indexes[r],n,this.entities[r]),this._setEntity(r,t,n),o&&this._setMeta(r,t,i)}invalidate({key:e},t){this.setEntity({key:e},t,s)}_setEntity(e,t,n){this.entities[e][t]=n}_setMeta(e,t,n){this.entitiesMeta[e][t]=n}getMeta(e,t){return this.entitiesMeta[e][t]}}const I=(e,t,n=[],{entities:s,indexes:i,entitiesMeta:r}=L,a={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:s,indexes:i,entitiesMeta:r};const c=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(e);if(null===t||typeof t!==c&&(void 0===e.key||void 0!==e.pk||"string"!=typeof t))throw new Error(`Unexpected input given to normalize. Expected type to be "${c}", found "${null===t?"null":typeof t}".`);const l={entities:u({},s),indexes:u({},i),entitiesMeta:u({},r)},d=(e=>{let t;const n=(n,s,i,r)=>{if(null==s||!n)return s;if("object"!=typeof s){if("function"!=typeof n.normalize)return s;if(!n.acceptsPrimitives)return s&&n.pk?`${s}`:s}if("function"==typeof n.normalize){const a=t;n.pk&&(t=n);const o=n.normalize(s,i,r,e,a);return t=a,o}return"object"!=typeof n?s:(Array.isArray(n)?o:h)(n,s,i,r,e)};return e.visit=n,n})(new S(l,n,a));return{result:d(e,t,t,void 0),entities:l.entities,indexes:l.indexes,entitiesMeta:l.entitiesMeta}};const L={entities:{},indexes:{},entitiesMeta:{}},A={path:{key:"",pk:""},entity:void 0};class M{constructor(e,t,n,s=[]){this.dependencies=[A],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._hasArgsKey=!1,this._getEntity=e,this._getCache=t,this._resultCache=n,this._args=s}argsKey(e){return this._hasArgsKey=!0,this.dependencies.push({path:e,entity:void 0}),e(this._args)}getEntity(e,t,n,s){const i=t.key,r=this.getOrCreateLocalCache(i);if(r.get(e)){const t=this.cycleCache.get(i);null!=t&&t.has(e)?this.cycleIndex=t.get(e):this.dependencies.push({path:{key:i,pk:e},entity:n})}else{const a=this._getCache(e,t),[o,c]=a.get(n,this._getEntity,this._args);if(c){r.set(e,o.value);const t=o.dependencies;for(let e=0;e<t.length;e++)this.dependencies.push(t[e]);return a.hasStringDeps&&(this._hasArgsKey=!0),o.value}{const t=this.dependencies.length,o=this.getOrCreateCycleCache(i);o.set(e,t),this.dependencies.push({path:{key:i,pk:e},entity:n}),s(r),o.delete(e);const c=this.dependencies.slice(-1===this.cycleIndex?t:this.cycleIndex),l={dependencies:c,value:r.get(e)};a.set(c,l,this._args),this.cycleIndex===t&&(this.cycleIndex=-1)}}return r.get(e)}getOrCreateLocalCache(e){let t=this.localCache.get(e);return t||(t=new Map,this.localCache.set(e,t)),t}getOrCreateCycleCache(e){let t=this.cycleCache.get(e);return t||(t=new Map,this.cycleCache.set(e,t)),t}getResults(e,t,n){if(!t)return{data:n(),paths:this.paths()};let[s,i]=this._resultCache.get(e,this._getEntity,this._args);return void 0===i&&(s=n(),i=this.paths(),this.dependencies[0]={path:{key:"",pk:""},entity:e},this._resultCache.set(this.dependencies,s,this._args,i)),{data:s,paths:i}}paths(){const e=this.dependencies;if(!this._hasArgsKey){const t=new Array(e.length-1);for(let n=1;n<e.length;n++)t[n-1]=e[n].path;return t}const t=[];for(let n=1;n<e.length;n++){const s=e[n].path;"function"!=typeof s&&t.push(s)}return t}}function R(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(R))}class O{constructor(e=w){var t;this.endpoints=new E,this.queryKeys=new Map,this.policy=e,this._getCache=(t=new Map,(e,n)=>{var s;const i=n.key,r=null!=(s=n.cacheWith)?s:n;t.has(i)||t.set(i,new Map);const a=t.get(i);a.has(e)||a.set(e,new WeakMap);const o=a.get(e);let c=o.get(r);return c||(c=new E,o.set(r,c)),c})}denormalize(e,t,n,s=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const i=this.policy.getEntities(n);return g(i,new M(i,this._getCache,this.endpoints,s),s)(e,t)}query(e,t,n,s=JSON.stringify(t)){const i=this.buildQueryKey(e,t,n,s);return i?this.denormalize(e,i,n.entities,t):{data:void 0,paths:[]}}buildQueryKey(e,t,n,s=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;let i=this.queryKeys.get(s);i||(i=new E,this.queryKeys.set(s,i));const r=new this.policy.QueryDelegate(n);let[a,o]=i.get(e,(c=r,e=>{switch(e.length){case 1:return c.getEntitiesObject(e[0]);case 2:return c.getEntity(e[0],e[1]);case 3:return c.getIndex(e[0],e[1],e[2])}}));var c;if(!o){const[n,s]=r.tracked(e);a=function(e){return function t(n,s){if(function(e){return!!e&&"function"==typeof e.queryKey}(n)){if(1===s.length&&null===s[0])return;return n.queryKey(s,t,e)}return"object"==typeof n&&n?(Array.isArray(n)?l:p)(n,s,t,e):n}}(n)(e,t),i.set(s,a)}return a}}var _={Invalid:1,InvalidIfStale:2,Valid:3};function C(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const P="rdc/fetch",j="rdc/set",D="rdc/setresponse",T="rdc/optimistic",q="rdc/reset",N="rdc/subscribe",K="rdc/unsubscribe",V="rdc/invalidate",z="rdc/invalidateall",H="rdc/expireall",F="rdc/gc",U=P,B=j,Y=D,$=T,Q=q,W=N,X=K,J=V,G=z,Z=H,ee=F;var te=Object.freeze({__proto__:null,EXPIREALL:H,EXPIREALL_TYPE:Z,FETCH:P,FETCH_TYPE:U,GC:F,GC_TYPE:ee,INVALIDATE:V,INVALIDATEALL:z,INVALIDATEALL_TYPE:G,INVALIDATE_TYPE:J,OPTIMISTIC:T,OPTIMISTIC_TYPE:$,RESET:q,RESET_TYPE:Q,SET:j,SET_RESPONSE:D,SET_RESPONSE_TYPE:Y,SET_TYPE:B,SUBSCRIBE:N,SUBSCRIBE_TYPE:W,UNSUBSCRIBE:K,UNSUBSCRIBE_TYPE:X});const ne="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function se(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const a=(n=t.endpoint,s=t.args,i=t.meta.fetchedAt,{type:T,key:n.key(...s),args:s.map(ne),endpoint:n,meta:C(null!=(r=n.dataExpiryLength)?r:6e4,i)});return u({},e,{optimistic:[...e.optimistic,a]})}var n,s,i,r;return e}class ie extends Error{}function re(e,t,n){return"AbortError"===n.name?u({},e,{optimistic:ae(e,t)}):u({},e,{meta:u({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,error:n,errorPolicy:null==t.endpoint.errorPolicy?void 0:t.endpoint.errorPolicy(n)}}),optimistic:ae(e,t)})}function ae(e,t){return e.optimistic.filter((e=>e.key!==t.key||(e.type===T?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function oe(e){return function(t,n){switch(t||(t=ce),n.type){case F:return n.entities.forEach((({key:e,pk:n})=>{var s,i;null==(s=t.entities[e])||delete s[n],null==(i=t.entitiesMeta[e])||delete i[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case P:return se(t,n);case T:case D:return function(e,t,n){if(t.error)return re(e,t,t.response);try{var s;let i;if(t.type===T){if(!t.endpoint.getOptimisticResponse)return e;try{i=t.endpoint.getOptimisticResponse.call(t.endpoint,n.snapshot(e,t.meta.fetchedAt),...t.args)}catch(t){if(t.constructor===ie)return e;throw t}}else i=t.response;const{result:r,entities:a,indexes:o,entitiesMeta:c}=I(t.endpoint.schema,i,t.args,e,t.meta),l=u({},e.endpoints,{[t.key]:r});try{if(t.endpoint.update){const e=t.endpoint.update(r,...t.args);Object.keys(e).forEach((t=>{l[t]=e[t](l[t])}))}}catch(e){console.error(`Endpoint.update() error: ${t.key}`),console.error(e)}return{entities:a,endpoints:l,indexes:o,meta:u({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,prevExpiresAt:null==(s=e.meta[t.key])?void 0:s.expiresAt}}),entitiesMeta:c,optimistic:ae(e,t),lastReset:e.lastReset}}catch(n){return"object"==typeof n&&(n.message=`Error processing ${t.key}\n\nFull Schema: ${JSON.stringify(t.endpoint.schema,void 0,2)}\n\nError:\n${n.message}`,"response"in t&&(n.response=t.response),n.status=400),re(e,t,n)}}(t,n,e);case j:return function(e,t,n){let s;if("function"==typeof t.value){const i=n.get(t.schema,...t.args,e);if(void 0===i)return e;s=t.value(i)}else s=t.value;try{const{entities:n,indexes:i,entitiesMeta:r}=I(t.schema,s,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:i,meta:e.meta,entitiesMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case z:case V:return function(e,t){const n=u({},e.endpoints),s=u({},e.meta),i=e=>{delete n[e];const t=u({},s[e],{expiresAt:0,invalidated:!0});delete t.error,s[e]=t};return t.type===V?i(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&i(e)})),u({},e,{endpoints:n,meta:s})}(t,n);case H:return function(e,t){const n=u({},e.meta);return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]=u({},n[e],{expiresAt:1}))})),u({},e,{meta:n})}(t,n);case q:return u({},ce,{lastReset:n.date});default:return t}}}const ce={entities:{},endpoints:{},indexes:{},meta:{},entitiesMeta:{},optimistic:[],lastReset:0};function le(e,{args:t,fetchedAt:n,response:s,error:i=!1}){var r,a;const o=i?null!=(r=e.errorExpiryLength)?r:1e3:null!=(a=e.dataExpiryLength)?a:6e4;return{type:D,key:e.key(...t),response:s,args:t.map(ne),endpoint:e,meta:C(o,n),error:i}}class ue{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function he(e,t){return e.meta[t]}const de=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},pe=()=>ce;class fe{constructor({dispatch:e=de,getState:t=pe,memo:s=new O,gcPolicy:i=new ue}={}){this.fetch=(e,...t)=>{const s=function(e,{args:t}){let n=0,s=0;const i=new Promise(((e,t)=>{[n,s]=[e,t]})),r={fetchedAt:Date.now(),resolve:n,reject:s,promise:i};return{type:P,key:e.key(...t),args:t,endpoint:e,meta:r}}(e,{args:t});return this.dispatch(s),e.schema?s.meta.promise.then((s=>function(e,t,s,i=[]){return void 0===e||void 0===t?t:g(w.getEntities(s),new n(i),i)(e,t).data}(e.schema,s,{},t))):s.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:s,expiryStatus:i}=this.getResponseMeta(e,...t,this.getState());return i!==_.Invalid&&Date.now()<=s?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:V,key:e.key(...t)}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:z,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:H,testKey:t=>e.testKey(t)}),this.resetEntireStore=()=>this.dispatch({type:q,date:Date.now()}),this.setResponse=(e,...t)=>{const n=t[t.length-1],s=le(e,{args:t.slice(0,t.length-1),response:n});return this.dispatch(s)},this.setError=(e,...t)=>{const n=t[t.length-1],s=le(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(s)},this.resolve=(e,t)=>this.dispatch(le(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:N,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:K,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new ge(this,e,t),this._dispatch=e,this.getState=t,this.memo=s,this.gcPolicy=i}set dispatch(e){this._dispatch=e}get dispatch(){return this._dispatch}bindMiddleware({dispatch:e,getState:t}){this._dispatch=e,this.getState=t}set(e,...t){const n=t[t.length-1],s=function(e,{args:t,fetchedAt:n,value:s}){return{type:j,value:s,args:t.map(ne),schema:e,meta:C(6e4,n)}}(e,{args:t.slice(0,t.length-1),value:n});return this.dispatch(s)}getError(e,...t){if(null===t[0])return;const n=t[t.length-1],s=t.slice(0,t.length-1),i=e.key(...s),r=he(n,i);return void 0===n.endpoints[i]||"soft"!==(null==r?void 0:r.errorPolicy)?null==r?void 0:r.error:void 0}getResponse(e,...t){return this.getResponseMeta(e,...t)}getResponseMeta(e,...t){const[n,s]=ve(t),i=1!==s.length||null!==s[0],r=i?e.key(...s):"",a=i?n.endpoints[r]:void 0,o=e.schema,c=he(n,r);let l=null==c?void 0:c.expiresAt;const u=void 0===a&&void 0!==o,h=u?this.memo.buildQueryKey(o,s,n,r):a;if(!i)return{data:h,expiryStatus:_.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(u)d=!R(h);else if(!o||!ye(o))return{data:a,expiryStatus:this.getExpiryStatus(!a,!!e.invalidIfStale,c),expiresAt:l||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(o,h,n.entities,s);return l||(l=d?1:function(e,t){let n=1/0;for(const{key:i,pk:r}of e){var s;const e=null==(s=t[i])||null==(s=s[r])?void 0:s.expiresAt;e<n&&(n=e)}return n}(f,n.entitiesMeta)),{data:p,expiryStatus:this.getExpiryStatus("symbol"==typeof p,!!e.invalidIfStale||d,c),expiresAt:l,countRef:this.gcPolicy.createCountRef({key:r,paths:f})}}get(e,...t){const[n,s]=ve(t),{data:i}=this.memo.query(e,s,n);return"symbol"==typeof i?void 0:i}getQueryMeta(e,...t){const[n,s]=ve(t),{data:i,paths:r}=this.memo.query(e,s,n);return{data:"symbol"==typeof i?void 0:i,countRef:this.gcPolicy.createCountRef({paths:r})}}getExpiryStatus(e,t,n={}){return n.invalidated||e&&!n.error?_.Invalid:e||t?_.InvalidIfStale:_.Valid}}function ye(e){if(!e)return!1;if(Array.isArray(e))return 0!==e.length&&ye(e[0]);const t=typeof e;return("object"===t||"function"===t)&&("function"==typeof e.normalize||Object.values(e).some((e=>ye(e))))}class ge{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=ge.abort,this.state=t,this.controller=e,this.fetchedAt=n}getResponse(e,...t){return this.controller.getResponse(e,...t,this.state)}getResponseMeta(e,...t){return this.controller.getResponseMeta(e,...t,this.state)}getError(e,...t){return this.controller.getError(e,...t,this.state)}get(e,...t){return this.controller.get(e,...t,this.state)}getQueryMeta(e,...t){return this.controller.getQueryMeta(e,...t,this.state)}}function ve(e){const t=e.length,n=new Array(t-1);for(let s=0;s<t-1;s++)n[s]=ne(e[s]);return[e[t-1],n]}ge.abort=new ie;class me extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class we{constructor({dataExpiryLength:e=6e4,errorExpiryLength:t=1e3}={}){this.fetching=new Map,this.controller=new fe,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case P:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case D:return t(n).then((()=>{if(this.fetching.has(n.key)){var t;const s=null==(t=e.getState().meta[n.key])?void 0:t.error;s?this.handleSet(le(n.endpoint,{args:n.args,response:s,fetchedAt:n.meta.fetchedAt,error:!0})):this.handleSet(n)}}));case q:{const e=Array.from(this.fetching.values());return this.clearAll(),t(n).then((()=>{for(const{reject:t}of e)t(new me)}))}default:return t(n)}}),this.dataExpiryLength=e,this.errorExpiryLength=t}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}skipLogging(e){return e.type===P&&this.fetching.has(e.key)}allSettled(){if(this.fetching.size)return Promise.allSettled(this.fetching.values().map((({promise:e})=>e)))}clearAll(){for(const e of this.fetching.keys())this.clear(e)}clear(e){this.fetching.has(e)&&(this.fetching.get(e).promise.catch((()=>{})),this.fetching.delete(e))}getLastReset(){return this.cleanupDate?this.cleanupDate:this.controller.getState().lastReset}handleFetch(e){const{resolve:t,reject:n,fetchedAt:s}=e.meta,i=!e.endpoint.sideEffect,r=()=>{let r=e.endpoint(...e.args);return i||(r=(e=>e.then((e=>(t(e),e))).catch((e=>{throw n(e),e})))(r)),r=r.then((t=>{let n=this.getLastReset();return s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s}),t})).catch((t=>{const n=this.getLastReset();throw s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s,error:!0}),t})),r};return i?this.throttle(e.key,r,s).then((e=>t(e))).catch((e=>n(e))):r().catch((()=>{}))}handleSet(e){if(this.fetching.has(e.key)){const{reject:t,resolve:n}=this.fetching.get(e.key);e.error?t(e.response):n(e.response),this.clear(e.key)}}throttle(e,t,n){const s=this.getLastReset();let i=this.fetching.get(e);return i&&i.fetchedAt>s||(i=function(e){const t={fetchedAt:e};return t.promise=new Promise(((e,n)=>{t.resolve=e,t.reject=n})),t}(n),this.fetching.set(e,i),this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),i.promise}idleCallback(e,t){e()}}class Ee{isOnline(){return void 0===navigator.onLine||navigator.onLine}addOnlineListener(e){addEventListener("online",e)}removeOnlineListener(e){removeEventListener("online",e)}addOfflineListener(e){addEventListener("offline",e)}removeOfflineListener(e){removeEventListener("offline",e)}}class xe{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}e.DefaultConnectionListener=void 0,"undefined"!=typeof navigator&&"function"==typeof addEventListener?e.DefaultConnectionListener=Ee:e.DefaultConnectionListener=xe;class be{constructor(t,n,s){if(this.frequencyHistogram=new Map,this.offlineListener=()=>{this.cleanup(),this.connectionListener.addOnlineListener(this.onlineListener)},this.onlineListener=()=>{this.connectionListener.removeOnlineListener(this.onlineListener);const e=Date.now();this.startId=setTimeout((()=>{this.startId&&(delete this.startId,this.update(),this.run())}),Math.max(0,this.lastFetchTime()-e+this.frequency)),this.connectionListener.addOfflineListener(this.offlineListener)},void 0===t.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=t.endpoint,this.frequency=t.endpoint.pollFrequency,this.args=t.args,this.key=t.key,this.frequencyHistogram.set(this.frequency,1),this.controller=n,this.connectionListener=s||new e.DefaultConnectionListener,this.connectionListener.isOnline()?this.onlineListener():this.offlineListener()}add(e){void 0!==e&&(this.frequencyHistogram.has(e)?this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)+1):(this.frequencyHistogram.set(e,1),e<this.frequency&&(this.frequency=e,this.run())))}remove(e){if(void 0===e)return!1;if(this.frequencyHistogram.has(e)&&(this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)-1),this.frequencyHistogram.get(e)<1)){if(this.frequencyHistogram.delete(e),0===this.frequencyHistogram.size)return this.cleanup(),!0;e<=this.frequency&&(this.frequency=Math.min(...this.frequencyHistogram.keys()),this.run())}return!1}cleanup(){this.intervalId&&(clearInterval(this.intervalId),delete this.intervalId),this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.startId&&(clearTimeout(this.startId),delete this.startId),this.connectionListener.removeOnlineListener(this.onlineListener),this.connectionListener.removeOfflineListener(this.offlineListener)}update(){const e=this.endpoint,t=function(...t){return e.call(this,...t)};Object.assign(t,this.endpoint),t.dataExpiryLength=this.frequency/2,t.errorExpiryLength=this.frequency/10,t.errorPolicy=()=>"soft",t.key=()=>this.key,this.controller.fetch(t,...this.args).catch((()=>null))}run(){this.startId||(this.intervalId&&(this.lastIntervalId=this.intervalId),this.intervalId=setInterval((()=>{this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.intervalId&&this.update()}),this.frequency))}lastFetchTime(){var e,t;return null!=(e=null==(t=this.controller.getState().meta[this.key])?void 0:t.date)?e:0}}class ke{constructor(e){this.subscriptions={},this.controller=new fe,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case N:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case K:return this.handleUnsubscribe(t),Promise.resolve();default:return e(t)}}),this.Subscription=e}cleanup(){for(const e in this.subscriptions)this.subscriptions[e].cleanup()}handleSubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].add(n)}else this.subscriptions[t]=new this.Subscription(e,this.controller)}handleUnsubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].remove(n)&&delete this.subscriptions[t]}}}let Se={};class Ie{constructor(e,t){var n,s;this.started=!1,this.actions=[],this.maxBufferLength=100;const i=u({},Se,e);this.devtoolsName=null!=(n=i.name)?n:`Data Client: ${null==(s=globalThis.document)?void 0:s.title}`,this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(i),null!=e&&e.maxAge&&(this.maxBufferLength=2*e.maxAge),t&&(this.skipLogging=t)}handleAction(e,t){this.started?this.devTools.send(e,t):(this.actions.length>this.maxBufferLength&&(this.actions=this.actions.slice(this.maxBufferLength/2)),this.actions.push([e,t]))}init(e){}cleanup(){}}Ie.prototype.middleware=()=>e=>t=>e(t);const Le=Symbol("DataClientState"),Ae=Symbol("DataClientController"),Me=t.shallowRef(ce);function Re(){const e=t.inject(Ae,null);return e||new fe}function Oe(){const e=t.inject(Le,null);return e||Me}async function _e(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=async()=>{if(!a.value)return;const t=o.value,n=t.expiryStatus===_.Invalid;Date.now()<=t.expiresAt&&!n||await i.fetch(e,...r.value)};return t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(()=>c())),t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>null==s?void 0:s()))}),{immediate:!0}),await c(),t.readonly(t.computed((()=>o.value.data)))}function Ce(e,...n){const s=Re(),i=t.computed((()=>n.map((e=>t.unref(e))))),r=t.computed((()=>null===i.value[0]?"":e.key(...i.value)));t.watch(r,((t,n,a)=>{if(!r.value)return;const o=i.value;s.subscribe(e,...o),a((()=>{s.unsubscribe(e,...o)}))}),{immediate:!0})}const Pe=Object.assign(Promise.resolve(),{resolved:!0});let je=(e={})=>{const{networkManager:t,subscriptionManager:n=be}=e;return null===n?[De(we,null!=t?t:{})]:[De(we,null!=t?t:{}),De(ke,n)]};function De(e,t){return t instanceof e?t:new e(t)}function Te(e={}){var n,s;const{Controller:i=fe,gcPolicy:r,app:a}=e,o=new i({gcPolicy:r}),c=null!=(n=e.managers)?n:je(),l=null!=(s=e.initialState)?s:ce,u=function(e,t,n){return()=>(e.forEach((e=>{null==e.init||e.init(n)})),t.gcPolicy.init(t),()=>{e.forEach((e=>{e.cleanup()})),t.gcPolicy.cleanup()})}(c,o,l),h=function(e,t){return e.map(((e,n)=>(e.middleware||(e.middleware=null==e.getMiddleware?void 0:e.getMiddleware()),s=>(0===n&&t.bindMiddleware(s),e.middleware(t)))))}(c,o),d=oe(o),p=t.shallowRef(l),f=t.shallowRef(x(l));let y=null;const g=()=>p.value,v=h.map((e=>e({getState:g,dispatch:e=>m(e)}))),m=(w=v,e=>w.reduceRight(((e,t)=>t(e)),e))((async e=>{const t=new Promise((e=>{y=e}));return await(async e=>{const t=d(p.value,e);if(p.value=t,f.value=x(t),y){const e=y;y=null,e()}})(e),t}));var w;let E;o.bindMiddleware({getState:g,dispatch:e=>m(e)});return a?(a.provide(Le,f),a.provide(Ae,o)):(t.provide(Le,f),t.provide(Ae,o)),{controller:o,stateRef:f,start:()=>{E=u()},stop:()=>{E&&E()}};function x(e){return e.optimistic.reduce(d,e)}}const qe={install(e,t={}){const n=Te(u({},t,{app:e}));return e.config.globalProperties.$dataClient=n.controller,n.start(),e.onUnmount((()=>{n.stop()})),n}};e.Controller=fe,e.DataClientPlugin=qe,e.DevToolsManager=Ie,e.ExpiryStatus=_,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===D&&n.error&&this.shouldLogout(n.response)&&this.handleLogout(e)},e&&(this.handleLogout=e),t&&(this.shouldLogout=t)}cleanup(){}shouldLogout(e){return 401===e.status}handleLogout(e){e.resetEntireStore()}},e.NetworkManager=we,e.PollingSubscription=be,e.SubscriptionManager=ke,e.actionTypes=te,e.createDataClient=Te,e.getDefaultManagers=je,e.useCache=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.computed((()=>o.value.expiryStatus===_.Invalid)),l=t.computed((()=>(Date.now()>o.value.expiresAt||c.value)&&a.value)),h=t.computed((()=>o.value.expiryStatus!==_.Valid&&l.value));return t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>{if(h.value){if(!e.schema)return;return i.getResponseMeta(e,...r.value,u({},s.value,{entities:{}})).data}return o.value.data}))},e.useController=Re,e.useDLE=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.computed((()=>o.value.expiryStatus===_.Invalid)),l=t.computed((()=>!(!(Date.now()>o.value.expiresAt||c.value)||!a.value))),h=t.computed((()=>!(o.value.expiryStatus===_.Valid||!l.value)));t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(async()=>{if(!a.value)return;const t=o.value,n=c.value;Date.now()<=t.expiresAt&&!n||await i.fetch(e,...r.value).catch((()=>{}))}),{immediate:!0}),t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0});const d=t.computed((()=>{if(h.value){if(!e.schema)return;return i.getResponseMeta(e,...r.value,u({},s.value,{entities:{}})).data}return o.value.data})),p=t.computed((()=>i.getError(e,...r.value,s.value)));return t.markRaw({data:d,loading:h,error:p})},e.useDebounce=function(e,n,s=!0){const i=t.ref("object"==typeof e&&null!==e&&"value"in e?e.value:e),r=t.ref(!1);let a=null;const o=()=>{null!==a&&(clearTimeout(a),a=null)};return t.watch([()=>"object"==typeof e&&null!==e&&"value"in e?e.value:e,()=>"object"==typeof s&&null!==s&&"value"in s?s.value:s,()=>n],(([e,t])=>{o(),t?(r.value=!0,a=setTimeout((()=>{i.value=e,r.value=!1,a=null}),n)):r.value=!1}),{immediate:!1}),t.onUnmounted((()=>{o()})),[i,r]},e.useFetch=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.ref(void 0);let l="";const u=()=>{const t=a.value;if(!t)return c.value=void 0,void(l="");const n=o.value,s=n.expiryStatus===_.Invalid;Date.now()>n.expiresAt||s?(c.value=function(e){const t=e;t.resolved=!1;const n=()=>{t.resolved=!0};return t.then(n,n),t}(i.fetch(e,...r.value)),l=t):c.value&&l===t||(c.value=Pe,l=t)};return u(),t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(()=>{u()})),c},e.useLive=async function(e,...t){return Ce(e,...t),_e(e,...t)},e.useLoading=function(e){const n=t.ref(!1),s=t.ref(void 0),i=t.ref(!0);return t.onUnmounted((()=>{i.value=!1})),[async(...t)=>{let r;n.value=!0,s.value=void 0;try{r=await e(...t)}catch(e){s.value=e}finally{i.value&&(n.value=!1)}return r},n,s]},e.useQuery=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>i.getQueryMeta(e,...r.value,s.value)));return t.watch((()=>a.value.data),((e,t,n)=>{const s=a.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>a.value.data))},e.useSubscription=Ce,e.useSuspense=_e}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VDC={},e.Vue)}(this,(function(e,t){"use strict";class n{constructor(e=[]){this.localCache=new Map,this._args=e}getEntity(e,t,n,s){const i=t.key;this.localCache.has(i)||this.localCache.set(i,new Map);const r=this.localCache.get(i);return r.get(e)||s(r),r.get(e)}getResults(e,t,n){return{data:n(),paths:[]}}argsKey(e){return e(this._args)}}const s=Symbol("INVALID"),i={};const r=e=>e[0],a=e=>void 0!==e&&"symbol"!=typeof e,o=(e,t,n,s,i)=>{e=r(e);const a=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return a.map((t=>i.visit(e,t,n,s)))},c=(e,t,n)=>(e=r(e),t.map?t.map((t=>n.unvisit(e,t))).filter(a):t);function l(){}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},u.apply(null,arguments)}const h=(e,t,n,s,i)=>{const r=u({},t),a=Object.keys(e);for(let n=0;n<a.length;n++){const s=a[n],o=e[s],c=i.visit(o,t[s],t,s);void 0===c?delete r[s]:r[s]=c}return r},d=(e,t,n)=>{if(function(e){return!("function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}(t))return function(e,t,n){let i=!1;const r=Object.keys(e).reduce(((t,s)=>{const r=`${s}`,a=n.unvisit(e[r],t.get(r));return"symbol"==typeof a&&(i=!0),t.has(r)?t.set(r,a):t}),t);return i?s:r}(e,t,n);const i=u({},t);let r=!1;const a=Object.keys(e);for(let t=0;t<a.length;t++){const s=a[t],o=n.unvisit(e[s],i[s]);void 0!==i[s]&&(i[s]=o),"symbol"==typeof o&&(r=!0)}return r?s:i};function p(e,t,n,s){const i={};for(const r of Object.keys(e))i[r]=n(e[r],t,s);return i}const f=(e,t,n)=>function(s,r){const a="object"!=typeof r,o=a?e({key:s.key,pk:r}):r;if("symbol"==typeof o)return s.denormalize(o,n);if(void 0===o&&a&&""!==r&&"undefined"!==r)return t.getEntity(r,s,i,(e=>{e.set(r,void 0)}));if("object"!=typeof o||null===o)return o;let c=a?r:s.pk(o,void 0,void 0,n.args);return void 0===c||""===c||"undefined"===c?function(e){const t=new Map;return e(t),t.get("")}((e=>y(s,o,"",e,n))):("string"!=typeof c&&(c=`${c}`),t.getEntity(c,s,o,(e=>y(s,o,c,e,n))))};function y(e,t,n,i,r){const a=e.createIfValid(t);void 0===a?i.set(n,s):(i.set(n,a),i.set(n,e.denormalize(a,r)))}const g=(e,t,n)=>{let i=0;const r={args:n,unvisit:o,argsKey:e=>t.argsKey(e)},a=f(e,t,r);function o(t,n){if(!t)return n;if(null==n)return n;if("function"==typeof t.denormalize){if(function(e){return null!==e&&void 0!==e.pk}(t)){var o;if(i>=(null!=(o=t.maxEntityDepth)?o:64))return function(e,t,n){var i;const r="object"!=typeof n?e({key:t.key,pk:n}):n;return"object"!=typeof r||null===r?r:null!=(i=t.createIfValid(r))?i:s}(e,t,n);i++;const r=a(t,n);return i--,r}return"function"==typeof t.createIfValid&&"string"==typeof n?a(t,n):t.denormalize(n,r)}if("function"==typeof t)return t(n);if("object"==typeof t){return(Array.isArray(t)?c:d)(t,n,r)}return n}return(e,n)=>{const s=Object(n)===n&&Object(e)===e;return t.getResults(n,s,(()=>o(e,n)))}};class v{constructor({entities:e,indexes:t}){this.entities=e,this.indexes=t}tracked(e){const t=this,n=[{path:[""],entity:e}];return[{INVALID:s,getIndex(...e){const s=t.getIndex(...e);return n.push({path:e,entity:s}),t.getIndexEnd(s,e[2])},getEntity(...e){const s=t.getEntity(...e);return n.push({path:e,entity:s}),s},getEntities(e){const s=t.getEntitiesObject(e);return n.push({path:[e],entity:s}),t.getEntities(e)}},n]}}class m extends v{constructor(e){super(e)}getEntitiesObject(e){return this.entities[e]}getEntities(e){const t=this.entities[e];if(void 0!==t)return{keys:()=>Object.keys(t),entries:()=>Object.entries(t)}}getEntity(e,t){var n;return null==(n=this.entities[e])?void 0:n[t]}getIndex(e,t){var n;return null==(n=this.indexes[e])?void 0:n[t]}getIndexEnd(e,t){return null==e?void 0:e[t]}}const w={QueryDelegate:m,getEntities:e=>({key:t,pk:n})=>{var s;return null==(s=e[t])?void 0:s[n]}};class E{constructor(){this.next=new WeakMap,this.nextPath=void 0,this.hasStr=!1}get(e,t,n=[]){let s=this.next.get(e);if(!s)return x;if(this.hasStr)return this._getMixed(s,t,n);for(;s.nextPath;){var r;const e=null!=(r=t(s.nextPath))?r:i,n=s.next.get(e);if(!n)return x;s=n}return[s.value,s.journey]}_getMixed(e,t,n){for(;e.nextPath;){let o;if("function"==typeof e.nextPath){var s,r;const t=null!=(s=e.nextPath(n))?s:"\0";o=null==(r=e.nextStr)?void 0:r.get(t)}else{var a;const n=null!=(a=t(e.nextPath))?a:i;o=e.next.get(n)}if(!o)return x;e=o}return[e.value,e.journey]}set(e,t,n=[],s){if(e.length<1)throw new k;let r=this;for(const t of e){let e;if("function"==typeof t.path){var a;this.hasStr=!0,r.nextStr||(r.nextStr=new Map);const s=null!=(a=t.path(n))?a:"\0";e=r.nextStr.get(s),e||(e=new b,r.nextStr.set(s,e))}else{var o;if(e=r.next.get(t.entity),!e)e=new b,r.next.set(null!=(o=t.entity)?o:i,e)}r.nextPath=t.path,r=e}r.nextPath=void 0,r.value=t,r.journey=null!=s?s:e.map((e=>e.path))}get hasStringDeps(){return this.hasStr}}const x=[void 0,void 0];class b{constructor(){this.next=new WeakMap,this.nextStr=void 0,this.nextPath=void 0,this.value=void 0,this.journey=[]}}class k extends Error{constructor(...e){super(...e),this.message="Keys must include at least one member"}}class S extends m{constructor(e,t,n){super(e),this.newEntities=new Map,this.newIndexes=new Map,this.entitiesMeta=e.entitiesMeta,this.args=t,this.meta=n,this.checkLoop=function(){const e=new Map;return function(t,n,s){let i=e.get(t);i||(i=new Map,e.set(t,i));let r=i.get(n);return r||(r=new Set,i.set(n,r)),!!r.has(s)||(r.add(s),!1)}}()}getNewEntity(e,t){return this.getNewEntities(e).get(t)}getNewEntities(e){let t=this.newEntities.get(e);return void 0===t&&(t=new Map,this.newEntities.set(e,t)),t}getNewIndexes(e){return this.newIndexes.has(e)||(this.newIndexes.set(e,new Map),this.indexes[e]=u({},this.indexes[e])),this.newIndexes.get(e)}mergeEntity(e,t,n){const s=e.key;let i=n,r=this.meta,a=this.getNewEntity(s,t);if(a)i=e.merge(a,n);else if(a=this.getEntity(s,t),a){const o=this.getMeta(s,t);i=e.mergeWithStore(o,r,a,n),r=e.mergeMetaWithStore(o,r,a,n)}this.setEntity(e,t,i,r)}setEntity(e,t,n,i=this.meta){const r=e.key,a=this.getNewEntities(r),o=!a.has(t);o&&0===a.size&&(this.entities[r]=u({},this.entities[r]),this.entitiesMeta[r]=u({},this.entitiesMeta[r])),a.set(t,n),e.indexes&&function(e,t,n,i,r,a){for(const o of t){n.has(o)||n.set(o,i[o]={});const t=n.get(o);a[e]&&delete t[a[e][o]],a&&a[e]&&a[e][o]!==r[o]&&(t[a[e][o]]=s),o in r&&(t[r[o]]=e)}}(t,e.indexes,this.getNewIndexes(r),this.indexes[r],n,this.entities[r]),this._setEntity(r,t,n),o&&this._setMeta(r,t,i)}invalidate({key:e},t){this.setEntity({key:e},t,s)}_setEntity(e,t,n){this.entities[e][t]=n}_setMeta(e,t,n){this.entitiesMeta[e][t]=n}getMeta(e,t){return this.entitiesMeta[e][t]}}const I=(e,t,n=[],{entities:s,indexes:i,entitiesMeta:r}=L,a={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:s,indexes:i,entitiesMeta:r};const c=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(e);if(null===t||typeof t!==c&&(void 0===e.key||void 0!==e.pk||"string"!=typeof t))throw new Error(`Unexpected input given to normalize. Expected type to be "${c}", found "${null===t?"null":typeof t}".`);const l={entities:u({},s),indexes:u({},i),entitiesMeta:u({},r)},d=(e=>{let t;const n=(n,s,i,r)=>{if(null==s||!n)return s;if("object"!=typeof s){if("function"!=typeof n.normalize)return s;if(!n.acceptsPrimitives)return s&&n.pk?`${s}`:s}if("function"==typeof n.normalize){const a=t;n.pk&&(t=n);const o=n.normalize(s,i,r,e,a);return t=a,o}return"object"!=typeof n?s:(Array.isArray(n)?o:h)(n,s,i,r,e)};return e.visit=n,n})(new S(l,n,a));return{result:d(e,t,t,void 0),entities:l.entities,indexes:l.indexes,entitiesMeta:l.entitiesMeta}};const L={entities:{},indexes:{},entitiesMeta:{}},A={path:{key:"",pk:""},entity:void 0};class M{constructor(e,t,n,s=[]){this.dependencies=[A],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._hasArgsKey=!1,this._getEntity=e,this._getCache=t,this._resultCache=n,this._args=s}argsKey(e){return this._hasArgsKey=!0,this.dependencies.push({path:e,entity:void 0}),e(this._args)}getEntity(e,t,n,s){const i=t.key,r=this.getOrCreateLocalCache(i);if(r.get(e)){const t=this.cycleCache.get(i);null!=t&&t.has(e)?this.cycleIndex=t.get(e):this.dependencies.push({path:{key:i,pk:e},entity:n})}else{const a=this._getCache(e,t),[o,c]=a.get(n,this._getEntity,this._args);if(c){r.set(e,o.value);const t=o.dependencies;for(let e=0;e<t.length;e++)this.dependencies.push(t[e]);return a.hasStringDeps&&(this._hasArgsKey=!0),o.value}{const t=this.dependencies.length,o=this.getOrCreateCycleCache(i);o.set(e,t),this.dependencies.push({path:{key:i,pk:e},entity:n}),s(r),o.delete(e);const c=this.dependencies.slice(-1===this.cycleIndex?t:this.cycleIndex),l={dependencies:c,value:r.get(e)};a.set(c,l,this._args),this.cycleIndex===t&&(this.cycleIndex=-1)}}return r.get(e)}getOrCreateLocalCache(e){let t=this.localCache.get(e);return t||(t=new Map,this.localCache.set(e,t)),t}getOrCreateCycleCache(e){let t=this.cycleCache.get(e);return t||(t=new Map,this.cycleCache.set(e,t)),t}getResults(e,t,n){if(!t)return{data:n(),paths:this.paths()};let[s,i]=this._resultCache.get(e,this._getEntity,this._args);return void 0===i&&(s=n(),i=this.paths(),this.dependencies[0]={path:{key:"",pk:""},entity:e},this._resultCache.set(this.dependencies,s,this._args,i)),{data:s,paths:i}}paths(){const e=this.dependencies;if(!this._hasArgsKey){const t=new Array(e.length-1);for(let n=1;n<e.length;n++)t[n-1]=e[n].path;return t}const t=[];for(let n=1;n<e.length;n++){const s=e[n].path;"function"!=typeof s&&t.push(s)}return t}}function R(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(R))}class O{constructor(e=w){var t;this.endpoints=new E,this.queryKeys=new Map,this.policy=e,this._getCache=(t=new Map,(e,n)=>{var s;const i=n.key,r=null!=(s=n.cacheWith)?s:n;t.has(i)||t.set(i,new Map);const a=t.get(i);a.has(e)||a.set(e,new WeakMap);const o=a.get(e);let c=o.get(r);return c||(c=new E,o.set(r,c)),c})}denormalize(e,t,n,s=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const i=this.policy.getEntities(n);return g(i,new M(i,this._getCache,this.endpoints,s),s)(e,t)}query(e,t,n,s=JSON.stringify(t)){const i=this.buildQueryKey(e,t,n,s);return i?this.denormalize(e,i,n.entities,t):{data:void 0,paths:[]}}buildQueryKey(e,t,n,s=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;let i=this.queryKeys.get(s);i||(i=new E,this.queryKeys.set(s,i));const r=new this.policy.QueryDelegate(n);let[a,o]=i.get(e,(c=r,e=>{switch(e.length){case 1:return c.getEntitiesObject(e[0]);case 2:return c.getEntity(e[0],e[1]);case 3:return c.getIndex(e[0],e[1],e[2])}}));var c;if(!o){const[n,s]=r.tracked(e);a=function(e){return function t(n,s){if(function(e){return!!e&&"function"==typeof e.queryKey}(n)){if(1===s.length&&null===s[0])return;return n.queryKey(s,t,e)}return"object"==typeof n&&n?(Array.isArray(n)?l:p)(n,s,t,e):n}}(n)(e,t),i.set(s,a)}return a}}var _={Invalid:1,InvalidIfStale:2,Valid:3};function C(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const P="rdc/fetch",j="rdc/set",D="rdc/setresponse",T="rdc/optimistic",q="rdc/reset",N="rdc/subscribe",K="rdc/unsubscribe",V="rdc/invalidate",z="rdc/invalidateall",H="rdc/expireall",F="rdc/gc",U=P,B=j,Y=D,$=T,Q=q,W=N,X=K,J=V,G=z,Z=H,ee=F;var te=Object.freeze({__proto__:null,EXPIREALL:H,EXPIREALL_TYPE:Z,FETCH:P,FETCH_TYPE:U,GC:F,GC_TYPE:ee,INVALIDATE:V,INVALIDATEALL:z,INVALIDATEALL_TYPE:G,INVALIDATE_TYPE:J,OPTIMISTIC:T,OPTIMISTIC_TYPE:$,RESET:q,RESET_TYPE:Q,SET:j,SET_RESPONSE:D,SET_RESPONSE_TYPE:Y,SET_TYPE:B,SUBSCRIBE:N,SUBSCRIBE_TYPE:W,UNSUBSCRIBE:K,UNSUBSCRIBE_TYPE:X});const ne="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function se(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const a=(n=t.endpoint,s=t.args,i=t.meta.fetchedAt,{type:T,key:n.key(...s),args:s.map(ne),endpoint:n,meta:C(null!=(r=n.dataExpiryLength)?r:6e4,i)});return u({},e,{optimistic:[...e.optimistic,a]})}var n,s,i,r;return e}class ie extends Error{}function re(e,t,n){return"AbortError"===n.name?u({},e,{optimistic:ae(e,t)}):u({},e,{meta:u({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,error:n,errorPolicy:null==t.endpoint.errorPolicy?void 0:t.endpoint.errorPolicy(n)}}),optimistic:ae(e,t)})}function ae(e,t){return e.optimistic.filter((e=>e.key!==t.key||(e.type===T?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function oe(e){return function(t,n){switch(t||(t=ce),n.type){case F:return n.entities.forEach((({key:e,pk:n})=>{var s,i;null==(s=t.entities[e])||delete s[n],null==(i=t.entitiesMeta[e])||delete i[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case P:return se(t,n);case T:case D:return function(e,t,n){if(t.error)return re(e,t,t.response);try{var s;let i;if(t.type===T){if(!t.endpoint.getOptimisticResponse)return e;try{i=t.endpoint.getOptimisticResponse.call(t.endpoint,n.snapshot(e,t.meta.fetchedAt),...t.args)}catch(t){if(t.constructor===ie)return e;throw t}}else i=t.response;const{result:r,entities:a,indexes:o,entitiesMeta:c}=I(t.endpoint.schema,i,t.args,e,t.meta),l=u({},e.endpoints,{[t.key]:r});try{if(t.endpoint.update){const e=t.endpoint.update(r,...t.args);Object.keys(e).forEach((t=>{l[t]=e[t](l[t])}))}}catch(e){console.error(`Endpoint.update() error: ${t.key}`),console.error(e)}return{entities:a,endpoints:l,indexes:o,meta:u({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,prevExpiresAt:null==(s=e.meta[t.key])?void 0:s.expiresAt}}),entitiesMeta:c,optimistic:ae(e,t),lastReset:e.lastReset}}catch(n){return"object"==typeof n&&(n.message=`Error processing ${t.key}\n\nFull Schema: ${JSON.stringify(t.endpoint.schema,void 0,2)}\n\nError:\n${n.message}`,"response"in t&&(n.response=t.response),n.status=400),re(e,t,n)}}(t,n,e);case j:return function(e,t,n){let s;if("function"==typeof t.value){const i=n.get(t.schema,...t.args,e);if(void 0===i)return e;s=t.value(i)}else s=t.value;try{const{entities:n,indexes:i,entitiesMeta:r}=I(t.schema,s,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:i,meta:e.meta,entitiesMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case z:case V:return function(e,t){const n=u({},e.endpoints),s=u({},e.meta),i=e=>{delete n[e];const t=u({},s[e],{expiresAt:0,invalidated:!0});delete t.error,s[e]=t};return t.type===V?i(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&i(e)})),u({},e,{endpoints:n,meta:s})}(t,n);case H:return function(e,t){const n=u({},e.meta);return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]=u({},n[e],{expiresAt:1}))})),u({},e,{meta:n})}(t,n);case q:return u({},ce,{lastReset:n.date});default:return t}}}const ce={entities:{},endpoints:{},indexes:{},meta:{},entitiesMeta:{},optimistic:[],lastReset:0};function le(e,{args:t,fetchedAt:n,response:s,error:i=!1}){var r,a;const o=i?null!=(r=e.errorExpiryLength)?r:1e3:null!=(a=e.dataExpiryLength)?a:6e4;return{type:D,key:e.key(...t),response:s,args:t.map(ne),endpoint:e,meta:C(o,n),error:i}}class ue{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function he(e,t){return e.meta[t]}const de=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},pe=()=>ce;class fe{constructor({dispatch:e=de,getState:t=pe,memo:s=new O,gcPolicy:i=new ue}={}){this.fetch=(e,...t)=>{const s=function(e,{args:t}){let n=0,s=0;const i=new Promise(((e,t)=>{[n,s]=[e,t]})),r={fetchedAt:Date.now(),resolve:n,reject:s,promise:i};return{type:P,key:e.key(...t),args:t,endpoint:e,meta:r}}(e,{args:t});return this.dispatch(s),e.schema?s.meta.promise.then((s=>function(e,t,s,i=[]){return void 0===e||void 0===t?t:g(w.getEntities(s),new n(i),i)(e,t).data}(e.schema,s,{},t))):s.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:s,expiryStatus:i}=this.getResponseMeta(e,...t,this.getState());return i!==_.Invalid&&Date.now()<=s?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:V,key:e.key(...t)}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:z,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:H,testKey:t=>e.testKey(t)}),this.resetEntireStore=()=>this.dispatch({type:q,date:Date.now()}),this.setResponse=(e,...t)=>{const n=t[t.length-1],s=le(e,{args:t.slice(0,t.length-1),response:n});return this.dispatch(s)},this.setError=(e,...t)=>{const n=t[t.length-1],s=le(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(s)},this.resolve=(e,t)=>this.dispatch(le(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:N,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:K,key:e.key(...t),args:t,endpoint:e}}(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new ge(this,e,t),this._dispatch=e,this.getState=t,this.memo=s,this.gcPolicy=i}set dispatch(e){this._dispatch=e}get dispatch(){return this._dispatch}bindMiddleware({dispatch:e,getState:t}){this._dispatch=e,this.getState=t}set(e,...t){const n=t[t.length-1],s=function(e,{args:t,fetchedAt:n,value:s}){return{type:j,value:s,args:t.map(ne),schema:e,meta:C(6e4,n)}}(e,{args:t.slice(0,t.length-1),value:n});return this.dispatch(s)}getError(e,...t){if(null===t[0])return;const n=t[t.length-1],s=t.slice(0,t.length-1),i=e.key(...s),r=he(n,i);return void 0===n.endpoints[i]||"soft"!==(null==r?void 0:r.errorPolicy)?null==r?void 0:r.error:void 0}getResponse(e,...t){return this.getResponseMeta(e,...t)}getResponseMeta(e,...t){const[n,s]=ve(t),i=1!==s.length||null!==s[0],r=i?e.key(...s):"",a=i?n.endpoints[r]:void 0,o=e.schema,c=he(n,r);let l=null==c?void 0:c.expiresAt;const u=void 0===a&&void 0!==o,h=u?this.memo.buildQueryKey(o,s,n,r):a;if(!i)return{data:h,expiryStatus:_.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(u)d=!R(h);else if(!o||!ye(o))return{data:a,expiryStatus:this.getExpiryStatus(void 0===a,!!e.invalidIfStale,c),expiresAt:l||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(o,h,n.entities,s);return l||(l=d?1:function(e,t){let n=1/0;for(const{key:i,pk:r}of e){var s;const e=null==(s=t[i])||null==(s=s[r])?void 0:s.expiresAt;e<n&&(n=e)}return n}(f,n.entitiesMeta)),{data:p,expiryStatus:this.getExpiryStatus("symbol"==typeof p,!!e.invalidIfStale||d,c),expiresAt:l,countRef:this.gcPolicy.createCountRef({key:r,paths:f})}}get(e,...t){const[n,s]=ve(t),{data:i}=this.memo.query(e,s,n);return"symbol"==typeof i?void 0:i}getQueryMeta(e,...t){const[n,s]=ve(t),{data:i,paths:r}=this.memo.query(e,s,n);return{data:"symbol"==typeof i?void 0:i,countRef:this.gcPolicy.createCountRef({paths:r})}}getExpiryStatus(e,t,n={}){return n.invalidated||e&&!n.error?_.Invalid:e||t?_.InvalidIfStale:_.Valid}}function ye(e){if(!e)return!1;if(Array.isArray(e))return 0!==e.length&&ye(e[0]);const t=typeof e;return("object"===t||"function"===t)&&("function"==typeof e.normalize||Object.values(e).some((e=>ye(e))))}class ge{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=ge.abort,this.state=t,this.controller=e,this.fetchedAt=n}getResponse(e,...t){return this.controller.getResponse(e,...t,this.state)}getResponseMeta(e,...t){return this.controller.getResponseMeta(e,...t,this.state)}getError(e,...t){return this.controller.getError(e,...t,this.state)}get(e,...t){return this.controller.get(e,...t,this.state)}getQueryMeta(e,...t){return this.controller.getQueryMeta(e,...t,this.state)}}function ve(e){const t=e.length,n=new Array(t-1);for(let s=0;s<t-1;s++)n[s]=ne(e[s]);return[e[t-1],n]}ge.abort=new ie;class me extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class we{constructor({dataExpiryLength:e=6e4,errorExpiryLength:t=1e3}={}){this.fetching=new Map,this.controller=new fe,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case P:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case D:return t(n).then((()=>{if(this.fetching.has(n.key)){var t;const s=null==(t=e.getState().meta[n.key])?void 0:t.error;s?this.handleSet(le(n.endpoint,{args:n.args,response:s,fetchedAt:n.meta.fetchedAt,error:!0})):this.handleSet(n)}}));case q:{const e=Array.from(this.fetching.values());return this.clearAll(),t(n).then((()=>{for(const{reject:t}of e)t(new me)}))}default:return t(n)}}),this.dataExpiryLength=e,this.errorExpiryLength=t}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}skipLogging(e){return e.type===P&&this.fetching.has(e.key)}allSettled(){if(this.fetching.size)return Promise.allSettled(this.fetching.values().map((({promise:e})=>e)))}clearAll(){for(const e of this.fetching.keys())this.clear(e)}clear(e){this.fetching.has(e)&&(this.fetching.get(e).promise.catch((()=>{})),this.fetching.delete(e))}getLastReset(){return this.cleanupDate?this.cleanupDate:this.controller.getState().lastReset}handleFetch(e){const{resolve:t,reject:n,fetchedAt:s}=e.meta,i=!e.endpoint.sideEffect,r=()=>{let r=e.endpoint(...e.args);return i||(r=(e=>e.then((e=>(t(e),e))).catch((e=>{throw n(e),e})))(r)),r=r.then((t=>{let n=this.getLastReset();return s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s}),t})).catch((t=>{const n=this.getLastReset();throw s>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:s,error:!0}),t})),r};return i?this.throttle(e.key,r,s).then((e=>t(e))).catch((e=>n(e))):r().catch((()=>{}))}handleSet(e){if(this.fetching.has(e.key)){const{reject:t,resolve:n}=this.fetching.get(e.key);e.error?t(e.response):n(e.response),this.clear(e.key)}}throttle(e,t,n){const s=this.getLastReset();let i=this.fetching.get(e);return i&&i.fetchedAt>s||(i=function(e){const t={fetchedAt:e};return t.promise=new Promise(((e,n)=>{t.resolve=e,t.reject=n})),t}(n),this.fetching.set(e,i),this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),i.promise}idleCallback(e,t){e()}}class Ee{isOnline(){return void 0===navigator.onLine||navigator.onLine}addOnlineListener(e){addEventListener("online",e)}removeOnlineListener(e){removeEventListener("online",e)}addOfflineListener(e){addEventListener("offline",e)}removeOfflineListener(e){removeEventListener("offline",e)}}class xe{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}e.DefaultConnectionListener=void 0,"undefined"!=typeof navigator&&"function"==typeof addEventListener?e.DefaultConnectionListener=Ee:e.DefaultConnectionListener=xe;class be{constructor(t,n,s){if(this.frequencyHistogram=new Map,this.offlineListener=()=>{this.cleanup(),this.connectionListener.addOnlineListener(this.onlineListener)},this.onlineListener=()=>{this.connectionListener.removeOnlineListener(this.onlineListener);const e=Date.now();this.startId=setTimeout((()=>{this.startId&&(delete this.startId,this.update(),this.run())}),Math.max(0,this.lastFetchTime()-e+this.frequency)),this.connectionListener.addOfflineListener(this.offlineListener)},void 0===t.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=t.endpoint,this.frequency=t.endpoint.pollFrequency,this.args=t.args,this.key=t.key,this.frequencyHistogram.set(this.frequency,1),this.controller=n,this.connectionListener=s||new e.DefaultConnectionListener,this.connectionListener.isOnline()?this.onlineListener():this.offlineListener()}add(e){void 0!==e&&(this.frequencyHistogram.has(e)?this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)+1):(this.frequencyHistogram.set(e,1),e<this.frequency&&(this.frequency=e,this.run())))}remove(e){if(void 0===e)return!1;if(this.frequencyHistogram.has(e)&&(this.frequencyHistogram.set(e,this.frequencyHistogram.get(e)-1),this.frequencyHistogram.get(e)<1)){if(this.frequencyHistogram.delete(e),0===this.frequencyHistogram.size)return this.cleanup(),!0;e<=this.frequency&&(this.frequency=Math.min(...this.frequencyHistogram.keys()),this.run())}return!1}cleanup(){this.intervalId&&(clearInterval(this.intervalId),delete this.intervalId),this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.startId&&(clearTimeout(this.startId),delete this.startId),this.connectionListener.removeOnlineListener(this.onlineListener),this.connectionListener.removeOfflineListener(this.offlineListener)}update(){const e=this.endpoint,t=function(...t){return e.call(this,...t)};Object.assign(t,this.endpoint),t.dataExpiryLength=this.frequency/2,t.errorExpiryLength=this.frequency/10,t.errorPolicy=()=>"soft",t.key=()=>this.key,this.controller.fetch(t,...this.args).catch((()=>null))}run(){this.startId||(this.intervalId&&(this.lastIntervalId=this.intervalId),this.intervalId=setInterval((()=>{this.lastIntervalId&&(clearInterval(this.lastIntervalId),delete this.lastIntervalId),this.intervalId&&this.update()}),this.frequency))}lastFetchTime(){var e,t;return null!=(e=null==(t=this.controller.getState().meta[this.key])?void 0:t.date)?e:0}}class ke{constructor(e){this.subscriptions={},this.controller=new fe,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case N:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case K:return this.handleUnsubscribe(t),Promise.resolve();default:return e(t)}}),this.Subscription=e}cleanup(){for(const e in this.subscriptions)this.subscriptions[e].cleanup()}handleSubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].add(n)}else this.subscriptions[t]=new this.Subscription(e,this.controller)}handleUnsubscribe(e){const t=e.key;if(t in this.subscriptions){const n=e.endpoint.pollFrequency;this.subscriptions[t].remove(n)&&delete this.subscriptions[t]}}}let Se={};class Ie{constructor(e,t){var n,s;this.started=!1,this.actions=[],this.maxBufferLength=100;const i=u({},Se,e);this.devtoolsName=null!=(n=i.name)?n:`Data Client: ${null==(s=globalThis.document)?void 0:s.title}`,this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(i),null!=e&&e.maxAge&&(this.maxBufferLength=2*e.maxAge),t&&(this.skipLogging=t)}handleAction(e,t){this.started?this.devTools.send(e,t):(this.actions.length>this.maxBufferLength&&(this.actions=this.actions.slice(this.maxBufferLength/2)),this.actions.push([e,t]))}init(e){}cleanup(){}}Ie.prototype.middleware=()=>e=>t=>e(t);const Le=Symbol("DataClientState"),Ae=Symbol("DataClientController"),Me=t.shallowRef(ce);function Re(){const e=t.inject(Ae,null);return e||new fe}function Oe(){const e=t.inject(Le,null);return e||Me}async function _e(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=async()=>{if(!a.value)return;const t=o.value,n=t.expiryStatus===_.Invalid;Date.now()<=t.expiresAt&&!n||await i.fetch(e,...r.value)};return t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(()=>c())),t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>null==s?void 0:s()))}),{immediate:!0}),await c(),t.readonly(t.computed((()=>o.value.data)))}function Ce(e,...n){const s=Re(),i=t.computed((()=>n.map((e=>t.unref(e))))),r=t.computed((()=>null===i.value[0]?"":e.key(...i.value)));t.watch(r,((t,n,a)=>{if(!r.value)return;const o=i.value;s.subscribe(e,...o),a((()=>{s.unsubscribe(e,...o)}))}),{immediate:!0})}const Pe=Object.assign(Promise.resolve(),{resolved:!0});let je=(e={})=>{const{networkManager:t,subscriptionManager:n=be}=e;return null===n?[De(we,null!=t?t:{})]:[De(we,null!=t?t:{}),De(ke,n)]};function De(e,t){return t instanceof e?t:new e(t)}function Te(e={}){var n,s;const{Controller:i=fe,gcPolicy:r,app:a}=e,o=new i({gcPolicy:r}),c=null!=(n=e.managers)?n:je(),l=null!=(s=e.initialState)?s:ce,u=function(e,t,n){return()=>(e.forEach((e=>{null==e.init||e.init(n)})),t.gcPolicy.init(t),()=>{e.forEach((e=>{e.cleanup()})),t.gcPolicy.cleanup()})}(c,o,l),h=function(e,t){return e.map(((e,n)=>(e.middleware||(e.middleware=null==e.getMiddleware?void 0:e.getMiddleware()),s=>(0===n&&t.bindMiddleware(s),e.middleware(t)))))}(c,o),d=oe(o),p=t.shallowRef(l),f=t.shallowRef(x(l));let y=null;const g=()=>p.value,v=h.map((e=>e({getState:g,dispatch:e=>m(e)}))),m=(w=v,e=>w.reduceRight(((e,t)=>t(e)),e))((async e=>{const t=new Promise((e=>{y=e}));return await(async e=>{const t=d(p.value,e);if(p.value=t,f.value=x(t),y){const e=y;y=null,e()}})(e),t}));var w;let E;o.bindMiddleware({getState:g,dispatch:e=>m(e)});return a?(a.provide(Le,f),a.provide(Ae,o)):(t.provide(Le,f),t.provide(Ae,o)),{controller:o,stateRef:f,start:()=>{E=u()},stop:()=>{E&&E()}};function x(e){return e.optimistic.reduce(d,e)}}const qe={install(e,t={}){const n=Te(u({},t,{app:e}));return e.config.globalProperties.$dataClient=n.controller,n.start(),e.onUnmount((()=>{n.stop()})),n}};e.Controller=fe,e.DataClientPlugin=qe,e.DevToolsManager=Ie,e.ExpiryStatus=_,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===D&&n.error&&this.shouldLogout(n.response)&&this.handleLogout(e)},e&&(this.handleLogout=e),t&&(this.shouldLogout=t)}cleanup(){}shouldLogout(e){return 401===e.status}handleLogout(e){e.resetEntireStore()}},e.NetworkManager=we,e.PollingSubscription=be,e.SubscriptionManager=ke,e.actionTypes=te,e.createDataClient=Te,e.getDefaultManagers=je,e.useCache=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.computed((()=>o.value.expiryStatus===_.Invalid)),l=t.computed((()=>(Date.now()>o.value.expiresAt||c.value)&&a.value)),h=t.computed((()=>o.value.expiryStatus!==_.Valid&&l.value));return t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>{if(h.value){if(!e.schema)return;return i.getResponseMeta(e,...r.value,u({},s.value,{entities:{}})).data}return o.value.data}))},e.useController=Re,e.useDLE=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.computed((()=>o.value.expiryStatus===_.Invalid)),l=t.computed((()=>!(!(Date.now()>o.value.expiresAt||c.value)||!a.value))),h=t.computed((()=>!(o.value.expiryStatus===_.Valid||!l.value)));t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(async()=>{if(!a.value)return;const t=o.value,n=c.value;Date.now()<=t.expiresAt&&!n||await i.fetch(e,...r.value).catch((()=>{}))}),{immediate:!0}),t.watch((()=>o.value.data),((e,t,n)=>{const s=o.value.countRef();n((()=>s()))}),{immediate:!0});const d=t.computed((()=>{if(h.value){if(!e.schema)return;return i.getResponseMeta(e,...r.value,u({},s.value,{entities:{}})).data}return o.value.data})),p=t.computed((()=>i.getError(e,...r.value,s.value)));return t.markRaw({data:d,loading:h,error:p})},e.useDebounce=function(e,n,s=!0){const i=t.ref("object"==typeof e&&null!==e&&"value"in e?e.value:e),r=t.ref(!1);let a=null;const o=()=>{null!==a&&(clearTimeout(a),a=null)};return t.watch([()=>"object"==typeof e&&null!==e&&"value"in e?e.value:e,()=>"object"==typeof s&&null!==s&&"value"in s?s.value:s,()=>n],(([e,t])=>{o(),t?(r.value=!0,a=setTimeout((()=>{i.value=e,r.value=!1,a=null}),n)):r.value=!1}),{immediate:!1}),t.onUnmounted((()=>{o()})),[i,r]},e.useFetch=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>null!==r.value[0]?e.key(...r.value):"")),o=t.computed((()=>i.getResponseMeta(e,...r.value,s.value))),c=t.ref(void 0);let l="";const u=()=>{const t=a.value;if(!t)return c.value=void 0,void(l="");const n=o.value,s=n.expiryStatus===_.Invalid;Date.now()>n.expiresAt||s?(c.value=function(e){const t=e;t.resolved=!1;const n=()=>{t.resolved=!0};return t.then(n,n),t}(i.fetch(e,...r.value)),l=t):c.value&&l===t||(c.value=Pe,l=t)};return u(),t.watch((()=>{const e=o.value;return[e.expiresAt,e.expiryStatus,s.value.lastReset,a.value]}),(()=>{u()})),c},e.useLive=async function(e,...t){return Ce(e,...t),_e(e,...t)},e.useLoading=function(e){const n=t.ref(!1),s=t.ref(void 0),i=t.ref(!0);return t.onUnmounted((()=>{i.value=!1})),[async(...t)=>{let r;n.value=!0,s.value=void 0;try{r=await e(...t)}catch(e){s.value=e}finally{i.value&&(n.value=!1)}return r},n,s]},e.useQuery=function(e,...n){const s=Oe(),i=Re(),r=t.computed((()=>n.map((e=>t.unref(e))))),a=t.computed((()=>i.getQueryMeta(e,...r.value,s.value)));return t.watch((()=>a.value.data),((e,t,n)=>{const s=a.value.countRef();n((()=>s()))}),{immediate:!0}),t.computed((()=>a.value.data))},e.useSubscription=Ce,e.useSuspense=_e}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-client/vue",
3
- "version": "0.18.0",
3
+ "version": "0.18.1",
4
4
  "description": "Async State Management without the Management. REST, GraphQL, SSE, Websockets, Fetch",
5
5
  "homepage": "https://dataclient.io",
6
6
  "repository": {
@@ -94,7 +94,7 @@
94
94
  "license": "Apache-2.0",
95
95
  "dependencies": {
96
96
  "@babel/runtime": "^7.20.0",
97
- "@data-client/core": "^0.18.0"
97
+ "@data-client/core": "^0.18.1"
98
98
  },
99
99
  "peerDependencies": {
100
100
  "@types/vue": "^3.0.0",
@@ -111,10 +111,10 @@
111
111
  },
112
112
  "devDependencies": {
113
113
  "@anansi/browserslist-config": "^1.4.2",
114
- "@data-client/rest": "0.18.0",
114
+ "@data-client/rest": "0.18.1",
115
115
  "@jest/globals": "^30.0.0",
116
116
  "@types/jest": "30.0.0",
117
- "@types/node": "^24.0.0",
117
+ "@types/node": "^25.0.0",
118
118
  "@vue/test-utils": "^2.4.0",
119
119
  "jest-environment-jsdom": "^30.0.0",
120
120
  "jest-mock": "^30.0.0",