@data-client/core 0.15.3 → 0.15.7

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,48 @@
1
1
  # @data-client/core
2
2
 
3
+ ## 0.15.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3738](https://github.com/reactive/data-client/pull/3738) [`4425a37`](https://github.com/reactive/data-client/commit/4425a371484d3eaed66240ea8c9c1c8874e220f1) - Optimistic updates support FormData
8
+
9
+ - Updated dependencies []:
10
+ - @data-client/normalizr@0.15.4
11
+
12
+ ## 0.15.4
13
+
14
+ ### Patch Changes
15
+
16
+ - [#3703](https://github.com/reactive/data-client/pull/3703) [`4fe8779`](https://github.com/reactive/data-client/commit/4fe8779706cb14d9018b3375d07b486a758ccb57) Thanks [@ntucker](https://github.com/ntucker)! - Improve normalize/denormalize performance 10-15%
17
+ - Replace `Object.keys().forEach()` with indexed for loops
18
+ - Replace `reduce()` with spreading to direct object mutation
19
+ - Cache getter results to avoid repeated property lookups
20
+ - Centralize arg extraction with pre-allocated loop
21
+ - Eliminate Map double-get pattern
22
+
23
+ #### Microbenchmark Results
24
+
25
+ | # | Optimization | Before | After | Improvement |
26
+ | --- | ---------------------------- | ----------------- | ----------------- | ---------------- |
27
+ | 1 | **forEach → forLoop** | 7,164 ops/sec | 7,331 ops/sec | **+2.3%** |
28
+ | 2 | **reduce+spread → mutation** | 912 ops/sec | 7,468 ops/sec | **+719% (8.2x)** |
29
+ | 3 | **getter repeated → cached** | 1,652,211 ops/sec | 4,426,994 ops/sec | **+168% (2.7x)** |
30
+ | 4 | **slice+map → indexed** | 33,221 ops/sec | 54,701 ops/sec | **+65% (1.65x)** |
31
+ | 5 | **Map double-get → single** | 23,046 ops/sec | 23,285 ops/sec | **+1%** |
32
+
33
+ #### Impact Summary by Codepath
34
+
35
+ | Codepath | Optimizations Applied | Expected Improvement |
36
+ | ------------------------------------------ | --------------------- | -------------------- |
37
+ | **normalize** (setResponse) | 1, 2, 4 | 10-15% |
38
+ | **denormalize** (getResponse) | 1, 2, 4 | 10-15% |
39
+ | **Controller queries** (get, getQueryMeta) | 5, 6 | 5-10% |
40
+
41
+ - [`09056b0`](https://github.com/reactive/data-client/commit/09056b0adf1375e0aa17df6c1db6f73f721c518f) Thanks [@ntucker](https://github.com/ntucker)! - Simplify endpoint.update() error message
42
+
43
+ - Updated dependencies [[`4fe8779`](https://github.com/reactive/data-client/commit/4fe8779706cb14d9018b3375d07b486a758ccb57)]:
44
+ - @data-client/normalizr@0.15.4
45
+
3
46
  ## 0.15.3
4
47
 
5
48
  ### Patch Changes
package/dist/index.js CHANGED
@@ -79,6 +79,11 @@ var actionTypes = /*#__PURE__*/Object.freeze({
79
79
  UNSUBSCRIBE_TYPE: UNSUBSCRIBE_TYPE
80
80
  });
81
81
 
82
+ const ensurePojo =
83
+ // FormData doesn't exist in node
84
+ /* istanbul ignore else we don't run coverage when we test node*/
85
+ typeof FormData !== 'undefined' ? body => body instanceof FormData ? Object.fromEntries(body.entries()) : body : /* istanbul ignore next */body => body;
86
+
82
87
  function createOptimistic(endpoint, args, fetchedAt) {
83
88
  var _endpoint$dataExpiryL, _endpoint$dataExpiryL2;
84
89
  /* istanbul ignore next */
@@ -88,7 +93,7 @@ function createOptimistic(endpoint, args, fetchedAt) {
88
93
  return {
89
94
  type: OPTIMISTIC,
90
95
  key: endpoint.key(...args),
91
- args,
96
+ args: args.map(ensurePojo),
92
97
  endpoint,
93
98
  meta: createMeta((_endpoint$dataExpiryL2 = endpoint.dataExpiryLength) != null ? _endpoint$dataExpiryL2 : 60000, fetchedAt)
94
99
  };
@@ -220,7 +225,7 @@ function setResponseReducer(state, action, controller) {
220
225
  // no reason to completely fail because of user-code error
221
226
  // integrity of this state update is still guaranteed
222
227
  } catch (error) {
223
- console.error(`The following error occured during Endpoint.update() for ${action.key}`);
228
+ console.error(`Endpoint.update() error: ${action.key}`);
224
229
  console.error(error);
225
230
  }
226
231
  return {
@@ -368,11 +373,6 @@ function createUnsubscription(endpoint, {
368
373
  };
369
374
  }
370
375
 
371
- const ensurePojo =
372
- // FormData doesn't exist in node
373
- /* istanbul ignore else we don't run coverage when we test node*/
374
- typeof FormData !== 'undefined' ? body => body instanceof FormData ? Object.fromEntries(body.entries()) : body : /* istanbul ignore next */body => body;
375
-
376
376
  function createSetResponse(endpoint, {
377
377
  args,
378
378
  fetchedAt,
@@ -884,11 +884,7 @@ class Controller {
884
884
  */
885
885
 
886
886
  getResponseMeta(endpoint, ...rest) {
887
- const state = rest[rest.length - 1];
888
- // this is typescript generics breaking
889
- const args = rest.slice(0, rest.length - 1)
890
- // handle FormData
891
- .map(ensurePojo);
887
+ const [state, args] = extractStateAndArgs(rest);
892
888
  const isActive = args.length !== 1 || args[0] !== null;
893
889
  const key = isActive ? endpoint.key(...args) : '';
894
890
  const cacheEndpoints = isActive ? state.endpoints[key] : undefined;
@@ -949,9 +945,7 @@ class Controller {
949
945
  * @see https://dataclient.io/docs/api/Controller#get
950
946
  */
951
947
  get(schema, ...rest) {
952
- const state = rest[rest.length - 1];
953
- // this is typescript generics breaking
954
- const args = rest.slice(0, rest.length - 1).map(ensurePojo);
948
+ const [state, args] = extractStateAndArgs(rest);
955
949
  const {
956
950
  data
957
951
  } = this.memo.query(schema, args, state);
@@ -963,9 +957,7 @@ class Controller {
963
957
  * @see https://dataclient.io/docs/api/Controller#getQueryMeta
964
958
  */
965
959
  getQueryMeta(schema, ...rest) {
966
- const state = rest[rest.length - 1];
967
- // this is typescript generics breaking
968
- const args = rest.slice(0, rest.length - 1).map(ensurePojo);
960
+ const [state, args] = extractStateAndArgs(rest);
969
961
  const {
970
962
  data,
971
963
  paths
@@ -1065,6 +1057,18 @@ class Snapshot {
1065
1057
  }
1066
1058
  }
1067
1059
 
1060
+ /** Extract state and args from rest params, applying ensurePojo to args */
1061
+ function extractStateAndArgs(rest) {
1062
+ const l = rest.length;
1063
+ const args = new Array(l - 1);
1064
+ for (let i = 0; i < l - 1; i++) {
1065
+ // handle FormData
1066
+ args[i] = ensurePojo(rest[i]);
1067
+ }
1068
+ // this is typescript generics breaking
1069
+ return [rest[l - 1], args];
1070
+ }
1071
+
1068
1072
  class ResetError extends Error {
1069
1073
  name = 'ResetError';
1070
1074
  constructor() {
@@ -1285,7 +1289,7 @@ class NetworkManager {
1285
1289
  * create a new promise and call fetch.
1286
1290
  *
1287
1291
  * Note: The new promise is not actually tied to fetch at all,
1288
- * but is resolved when the expected 'recieve' action is processed.
1292
+ * but is resolved when the expected 'receive' action is processed.
1289
1293
  * This ensures promises are resolved only once their data is processed
1290
1294
  * by the reducer.
1291
1295
  */
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).RDC=e.RDC||{},e.RDC.Core={}))}(this,(function(e){"use strict";class t{constructor(){this.localCache=new Map}getEntity(e,t,n,i){const s=t.key;this.localCache.has(s)||this.localCache.set(s,new Map);const r=this.localCache.get(s);return r.get(e)||i(r),r.get(e)}getResults(e,t,n){return{data:n(),paths:[]}}}const n=Symbol("INVALID"),i={};function s(e){return null!==e&&void 0!==e.pk}const r=e=>e[0],o=e=>void 0!==e&&"symbol"!=typeof e,a=(e,t,n,i,s,o)=>{e=r(e);const a=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return a.map((t=>o(e,t,n,i,s)))},c=(e,t,n,i)=>(e=r(e),t.map?t.map((t=>i(e,t))).filter(o):t);function h(){}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},l.apply(null,arguments)}const u=(e,t,n,i,s,r)=>{const o=l({},t);return Object.keys(e).forEach((n=>{const i=e[n],a=r(i,t[n],t,n,s);void 0===a?delete o[n]:o[n]=a})),o},d=(e,t,i,s)=>{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,i,s){let r=!1;const o=Object.keys(e).reduce(((t,n)=>{const i=`${n}`,o=s(e[i],t.get(i));return"symbol"==typeof o&&(r=!0),t.has(i)?t.set(i,o):t}),t);return r?n:o}(e,t,0,s);const r=l({},t);let o=!1;return Object.keys(e).forEach((t=>{const n=s(e[t],r[t]);void 0!==r[t]&&(r[t]=n),"symbol"==typeof n&&(o=!0)})),o?n:r};function p(e,t,n,i){const s={};for(const r of Object.keys(e))s[r]=n(e[r],t,i);return s}const f=(e,t,n,s)=>function(r,o){const a="object"!=typeof o,c=a?e({key:r.key,pk:o}):o;if("symbol"==typeof c)return r.denormalize(c,n,s);if(void 0===c&&a&&""!==o&&"undefined"!==o)return t.getEntity(o,r,i,(e=>{e.set(o,void 0)}));if("object"!=typeof c||null===c)return c;let h=a?o:r.pk(c,void 0,void 0,n);return void 0===h||""===h||"undefined"===h?function(e){const t=new Map;return e(t),t.get("")}((e=>y(r,c,"",e,n,s))):("string"!=typeof h&&(h=`${h}`),t.getEntity(h,r,c,(e=>y(r,c,h,e,n,s))))};function y(e,t,i,s,r,o){const a=e.createIfValid(t);void 0===a?s.set(i,n):(s.set(i,a),s.set(i,e.denormalize(a,r,o)))}const g=(e,t,n)=>{const i=f(e,t,n,r);function r(e,t){if(!e)return t;if(null==t)return t;if("function"==typeof e.denormalize)return s(e)?i(e,t):e.denormalize(t,n,r);if("function"==typeof e)return e(t);if("object"==typeof e){return(Array.isArray(e)?c:d)(e,t,n,r)}return t}return(e,n)=>{const i=Object(n)===n&&Object(e)===e;return t.getResults(n,i,(()=>r(e,n)))}};class m{constructor({entities:e,indexes:t}){this.entities=e,this.indexes=t}tracked(e){const t=this,i=[{path:[""],entity:e}];return[{INVALID:n,getIndex(...e){const n=t.getIndex(...e);return i.push({path:e,entity:n}),t.getIndexEnd(n,e[2])},getEntity(...e){const n=t.getEntity(...e);return i.push({path:e,entity:n}),n},getEntities(e){const n=t.getEntitiesObject(e);return i.push({path:[e],entity:n}),t.getEntities(e)}},i]}}class v extends m{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 E={QueryDelegate:v,getEntities:e=>({key:t,pk:n})=>{var i;return null==(i=e[t])?void 0:i[n]}};class w{constructor(){this.next=new WeakMap,this.nextPath=void 0}get(e,t){let n=this.next.get(e);if(!n)return x;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:i;if(n=n.next.get(e),!n)return x}return[n.value,n.journey]}set(e,t){if(e.length<1)throw new k;let n=this;for(const{path:t,entity:s}of e){let e=n.next.get(s);e||(e=new b,n.next.set(null!=s?s:i,e)),n.nextPath=t,n=e}n.nextPath=void 0,n.value=t,n.journey=e.map((e=>e.path))}}const x=[void 0,void 0];class b{constructor(){this.next=new WeakMap,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 I extends v{constructor(e,t){super(e),this.newEntities=new Map,this.newIndexes=new Map,this.entitiesMeta=e.entitiesMeta,this.meta=t,this.checkLoop=function(){const e=new Map;return function(t,n,i){let s=e.get(t);s||(s=new Map,e.set(t,s));let r=s.get(n);return r||(r=new Set,s.set(n,r)),!!r.has(i)||(r.add(i),!1)}}()}getNewEntity(e,t){return this.getNewEntities(e).get(t)}getNewEntities(e){return this.newEntities.has(e)||(this.newEntities.set(e,new Map),this.entities[e]=l({},this.entities[e]),this.entitiesMeta[e]=l({},this.entitiesMeta[e])),this.newEntities.get(e)}getNewIndexes(e){return this.newIndexes.has(e)||(this.newIndexes.set(e,new Map),this.indexes[e]=l({},this.indexes[e])),this.newIndexes.get(e)}mergeEntity(e,t,n){const i=e.key;let s=n,r=this.meta,o=this.getNewEntity(i,t);if(o)s=e.merge(o,n);else if(o=this.getEntity(i,t),o){const a=this.getMeta(i,t);s=e.mergeWithStore(a,r,o,n),r=e.mergeMetaWithStore(a,r,o,n)}this.setEntity(e,t,s,r)}setEntity(e,t,i,s=this.meta){const r=e.key,o=this.getNewEntities(r),a=!o.has(t);o.set(t,i),e.indexes&&function(e,t,i,s,r,o){for(const a of t){i.has(a)||i.set(a,s[a]={});const t=i.get(a);o[e]&&delete t[o[e][a]],o&&o[e]&&o[e][a]!==r[a]&&(t[o[e][a]]=n),a in r&&(t[r[a]]=e)}}(t,e.indexes,this.getNewIndexes(r),this.indexes[r],i,this.entities[r]),this._setEntity(r,t,i),a&&this._setMeta(r,t,s)}invalidate({key:e},t){this.setEntity({key:e},t,n)}_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 A=(e,t,n=[],{entities:i,indexes:s,entitiesMeta:r}=L,o={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:i,indexes:s,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 h={result:"",entities:l({},i),indexes:l({},s),entitiesMeta:l({},r)},d=(e=>{const t=(n,i,s,r,o)=>i&&n?n.normalize&&"function"==typeof n.normalize?"object"!=typeof i?n.pk?`${i}`:i:n.normalize(i,s,r,o,t,e):"object"!=typeof i||"object"!=typeof n?i:(Array.isArray(n)?a:u)(n,i,s,r,o,t):i;return t})(new I(h,o));return h.result=d(e,t,t,void 0,n),h};const L={entities:{},indexes:{},entitiesMeta:{}};class S{constructor(e,t,n){this.dependencies=[],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._getEntity=e,this._getCache=t,this._resultCache=n}getEntity(e,t,n,i){const s=t.key,{localCacheKey:r,cycleCacheKey:o}=this.getCacheKey(s);if(r.get(e))o.has(e)?this.cycleIndex=o.get(e):this.dependencies.push({path:{key:s,pk:e},entity:n});else{const a=this._getCache(e,t),[c,h]=a.get(n,this._getEntity);if(h)return r.set(e,c.value),this.dependencies.push(...c.dependencies),c.value;{const t=this.dependencies.length;o.set(e,t),this.dependencies.push({path:{key:s,pk:e},entity:n}),i(r),o.delete(e);const c=this.dependencies.slice(-1===this.cycleIndex?t:this.cycleIndex),h={dependencies:c,value:r.get(e)};a.set(c,h),this.cycleIndex===t&&(this.cycleIndex=-1)}}return r.get(e)}getCacheKey(e){this.localCache.has(e)||this.localCache.set(e,new Map),this.cycleCache.has(e)||this.cycleCache.set(e,new Map);return{localCacheKey:this.localCache.get(e),cycleCacheKey:this.cycleCache.get(e)}}getResults(e,t,n){if(!t)return{data:n(),paths:this.paths()};let[i,s]=this._resultCache.get(e,this._getEntity);return void 0===s?(i=n(),s=this.paths(),this.dependencies.unshift({path:{key:"",pk:""},entity:e}),this._resultCache.set(this.dependencies,i)):s.shift(),{data:i,paths:s}}paths(){return this.dependencies.map((e=>e.path))}}function M(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(M))}class C{constructor(e=E){var t;this.endpoints=new w,this.queryKeys=new Map,this.policy=e,this._getCache=(t=new Map,(e,n)=>{var i;const s=n.key,r=null!=(i=n.cacheWith)?i:n;t.has(s)||t.set(s,new Map);const o=t.get(s);o.has(e)||o.set(e,new WeakMap);const a=o.get(e);let c=a.get(r);return c||(c=new w,a.set(r,c)),c})}denormalize(e,t,n,i=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const s=this.policy.getEntities(n);return g(s,new S(s,this._getCache,this.endpoints),i)(e,t)}query(e,t,n,i=JSON.stringify(t)){const s=this.buildQueryKey(e,t,n,i);return s?this.denormalize(e,s,n.entities,t):{data:void 0,paths:[]}}buildQueryKey(e,t,n,i=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;this.queryKeys.get(i)||this.queryKeys.set(i,new w);const s=this.queryKeys.get(i),r=new this.policy.QueryDelegate(n);let[o,a]=s.get(e,(c=r,e=>c[["","getEntitiesObject","getEntity","getIndex"][e.length]](...e)));var c;if(!a){const[n,i]=r.tracked(e);o=function(e){return function t(n,i){return function(e){return!!e&&"function"==typeof e.queryKey}(n)?n.queryKey(i,t,e):"object"==typeof n&&n?(Array.isArray(n)?h:p)(n,i,t,e):n}}(n)(e,t),s.set(i,o)}return o}}var O={Invalid:1,InvalidIfStale:2,Valid:3};function _(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const R="rdc/fetch",P="rdc/set",j="rdc/setresponse",T="rdc/optimistic",q="rdc/reset",D="rdc/subscribe",N="rdc/unsubscribe",K="rdc/invalidate",z="rdc/invalidateall",Q="rdc/expireall",H="rdc/gc",F=R,V=P,B=j,U=T,Y=q,$=D,W=N,X=K,G=z,J=Q,Z=H;var ee=Object.freeze({__proto__:null,EXPIREALL:Q,EXPIREALL_TYPE:J,FETCH:R,FETCH_TYPE:F,GC:H,GC_TYPE:Z,INVALIDATE:K,INVALIDATEALL:z,INVALIDATEALL_TYPE:G,INVALIDATE_TYPE:X,OPTIMISTIC:T,OPTIMISTIC_TYPE:U,RESET:q,RESET_TYPE:Y,SET:P,SET_RESPONSE:j,SET_RESPONSE_TYPE:B,SET_TYPE:V,SUBSCRIBE:D,SUBSCRIBE_TYPE:$,UNSUBSCRIBE:N,UNSUBSCRIBE_TYPE:W});function te(e,t,n){var i;return{type:T,key:e.key(...t),args:t,endpoint:e,meta:_(null!=(i=e.dataExpiryLength)?i:6e4,n)}}class ne extends Error{}function ie(e,t,n){return"AbortError"===n.name?l({},e,{optimistic:se(e,t)}):l({},e,{meta:l({},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:se(e,t)})}function se(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)))}const re={entities:{},endpoints:{},indexes:{},meta:{},entitiesMeta:{},optimistic:[],lastReset:0};var oe=Object.freeze({__proto__:null,INVALID:n,MemoCache:C,initialState:re});function ae(e,{args:t}){return{type:D,key:e.key(...t),args:t,endpoint:e}}function ce(e,{args:t}){return{type:N,key:e.key(...t),args:t,endpoint:e}}const he="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function le(e,{args:t,fetchedAt:n,response:i,error:s=!1}){var r,o;const a=s?null!=(r=e.errorExpiryLength)?r:1e3:null!=(o=e.dataExpiryLength)?o:6e4;return{type:j,key:e.key(...t),response:i,args:t.map(he),endpoint:e,meta:_(a,n),error:s}}function ue(e,{args:t,fetchedAt:n,value:i}){return{type:P,value:i,args:t.map(he),schema:e,meta:_(6e4,n)}}function de(){return{type:q,date:Date.now()}}function pe(e){return{type:z,testKey:e}}function fe(e,{args:t}){return{type:K,key:e.key(...t)}}function ye(e,{args:t}){let n=0,i=0;const s=new Promise(((e,t)=>{[n,i]=[e,t]})),r={fetchedAt:Date.now(),resolve:n,reject:i,promise:s};return{type:R,key:e.key(...t),args:t,endpoint:e,meta:r}}function ge(e){return{type:Q,testKey:e}}var me=Object.freeze({__proto__:null,createExpireAll:ge,createFetch:ye,createInvalidate:fe,createInvalidateAll:pe,createMeta:_,createOptimistic:te,createReset:de,createSet:ue,createSetResponse:le,createSubscription:ae,createUnsubscription:ce});class ve{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function Ee(e,t){return e.meta[t]}const we=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},xe=()=>re;class be{constructor({dispatch:e=we,getState:n=xe,memo:i=new C,gcPolicy:s=new ve}={}){this.fetch=(e,...n)=>{const i=ye(e,{args:n});return this.dispatch(i),e.schema?i.meta.promise.then((i=>function(e,n,i,s=[]){return void 0===e||void 0===n?n:g(E.getEntities(i),new t,s)(e,n).data}(e.schema,i,{},n))):i.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:i,expiryStatus:s}=this.getResponseMeta(e,...t,this.getState());return s!==O.Invalid&&Date.now()<=i?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(fe(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch(pe((t=>e.testKey(t)))),this.expireAll=e=>this.dispatch(ge((t=>e.testKey(t)))),this.resetEntireStore=()=>this.dispatch(de()),this.setResponse=(e,...t)=>{const n=t[t.length-1],i=le(e,{args:t.slice(0,t.length-1),response:n});return this.dispatch(i)},this.setError=(e,...t)=>{const n=t[t.length-1],i=le(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(i)},this.resolve=(e,t)=>this.dispatch(le(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(ae(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(ce(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new Ie(this,e,t),this._dispatch=e,this.getState=n,this.memo=i,this.gcPolicy=s}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],i=ue(e,{args:t.slice(0,t.length-1),value:n});return this.dispatch(i)}getError(e,...t){if(null===t[0])return;const n=t[t.length-1],i=t.slice(0,t.length-1),s=e.key(...i),r=Ee(n,s);return void 0===n.endpoints[s]||"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=t[t.length-1],i=t.slice(0,t.length-1).map(he),s=1!==i.length||null!==i[0],r=s?e.key(...i):"",o=s?n.endpoints[r]:void 0,a=e.schema,c=Ee(n,r);let h=null==c?void 0:c.expiresAt;const l=void 0===o&&void 0!==a,u=l?this.memo.buildQueryKey(a,i,n,r):o;if(!s)return{data:u,expiryStatus:O.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(l)d=!M(u);else if(!a||!ke(a))return{data:o,expiryStatus:this.getExpiryStatus(!o,!!e.invalidIfStale,c),expiresAt:h||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(a,u,n.entities,i);return h||(h=d?1:function(e,t){let n=1/0;for(const{key:s,pk:r}of e){var i;const e=null==(i=t[s])||null==(i=i[r])?void 0:i.expiresAt;e<n&&(n=e)}return n}(f,n.entitiesMeta)),{data:p,expiryStatus:this.getExpiryStatus("symbol"==typeof p,!!e.invalidIfStale||d,c),expiresAt:h,countRef:this.gcPolicy.createCountRef({key:r,paths:f})}}get(e,...t){const n=t[t.length-1],i=t.slice(0,t.length-1).map(he),{data:s}=this.memo.query(e,i,n);return"symbol"==typeof s?void 0:s}getQueryMeta(e,...t){const n=t[t.length-1],i=t.slice(0,t.length-1).map(he),{data:s,paths:r}=this.memo.query(e,i,n);return{data:"symbol"==typeof s?void 0:s,countRef:this.gcPolicy.createCountRef({paths:r})}}getExpiryStatus(e,t,n={}){return n.invalidated||e&&!n.error?O.Invalid:e||t?O.InvalidIfStale:O.Valid}}function ke(e){if(s(e))return!0;if(Array.isArray(e))return 0!==e.length&&ke(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?ke(t):Object.values(t).some((e=>ke(e)))}return!1}class Ie{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=Ie.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)}}Ie.abort=new ne;class Ae extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class Le{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 Se{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}let Me;Me="undefined"!=typeof navigator&&"function"==typeof addEventListener?Le:Se;var Ce=Me;let Oe={};class _e{constructor(e,t){this.started=!1,this.actions=[],this.maxBufferLength=100,this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(l({},Oe,e)),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(){}}_e.prototype.middleware=()=>e=>t=>e(t);e.Controller=be,e.DefaultConnectionListener=Ce,e.DevToolsManager=_e,e.ExpiryStatus=O,e.GCPolicy=class{constructor({intervalMS:e=3e5,expiryMultiplier:t=2,expiresAt:n}={}){this.endpointCount=new Map,this.entityCount=new Map,this.endpointsQ=new Set,this.entitiesQ=[],n&&(this.expiresAt=n.bind(this)),this.options={intervalMS:e,expiryMultiplier:t}}init(e){this.controller=e,this.intervalId=setInterval((()=>{this.idleCallback((()=>this.runSweep()),{timeout:1e3})}),this.options.intervalMS)}cleanup(){clearInterval(this.intervalId)}createCountRef({key:e,paths:t=[]}){return()=>{var n;return e&&this.endpointCount.set(e,(null!=(n=this.endpointCount.get(e))?n:0)+1),t.forEach((e=>{var t;const{key:n,pk:i}=e;this.entityCount.has(n)||this.entityCount.set(n,new Map);const s=this.entityCount.get(n);s.set(i,(null!=(t=s.get(i))?t:0)+1)})),()=>{if(e){const t=this.endpointCount.get(e);void 0!==t&&(t<=1?(this.endpointCount.delete(e),this.endpointsQ.add(e)):this.endpointCount.set(e,t-1))}t.forEach((e=>{const{key:t,pk:n}=e;if(!this.entityCount.has(t))return;const i=this.entityCount.get(t),s=i.get(n);void 0!==s&&(s<=1?(i.delete(n),this.entitiesQ.push(e)):i.set(n,s-1))}))}}}expiresAt({fetchedAt:e,expiresAt:t}){return Math.max((t-e)*this.options.expiryMultiplier,12e4)+e}runSweep(){const e=this.controller.getState(),t=[],n=[],i=Date.now(),s=new Set;for(const t of this.endpointsQ){var r;!this.endpointCount.has(t)&&this.expiresAt(null!=(r=e.meta[t])?r:{fetchedAt:0,date:0,expiresAt:0})<i?n.push(t):s.add(t)}this.endpointsQ=s;const o=[];for(const n of this.entitiesQ){var a,c,h;(null==(a=this.entityCount.get(n.key))||!a.has(n.pk))&&this.expiresAt(null!=(c=null==(h=e.entitiesMeta[n.key])?void 0:h[n.pk])?c:{fetchedAt:0,date:0,expiresAt:0})<i?t.push(n):o.push(n)}this.entitiesQ=o,(t.length||n.length)&&this.controller.dispatch({type:H,entities:t,endpoints:n})}idleCallback(e,t){"function"==typeof requestIdleCallback?requestIdleCallback(e,t):e()}},e.ImmortalGCPolicy=ve,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===j&&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=class{constructor({dataExpiryLength:e=6e4,errorExpiryLength:t=1e3}={}){this.fetching=new Map,this.controller=new be,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case R:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case j:return t(n).then((()=>{if(this.fetching.has(n.key)){var t;const i=null==(t=e.getState().meta[n.key])?void 0:t.error;i?this.handleSet(le(n.endpoint,{args:n.args,response:i,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 Ae)}))}default:return t(n)}}),this.dataExpiryLength=e,this.errorExpiryLength=t}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}skipLogging(e){return e.type===R&&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:i}=e.meta,s=!e.endpoint.sideEffect,r=()=>{let r=e.endpoint(...e.args);return s||(r=(e=>e.then((e=>(t(e),e))).catch((e=>{throw n(e),e})))(r)),r=r.then((t=>{let n=this.getLastReset();return i>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:i}),t})).catch((t=>{const n=this.getLastReset();throw i>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:i,error:!0}),t})),r};return s?this.throttle(e.key,r,i).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 i=this.getLastReset();let s=this.fetching.get(e);return s&&s.fetchedAt>i||(s=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,s),this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),s.promise}idleCallback(e,t){e()}},e.PollingSubscription=class{constructor(e,t,n){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===e.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=e.endpoint,this.frequency=e.endpoint.pollFrequency,this.args=e.args,this.key=e.key,this.frequencyHistogram.set(this.frequency,1),this.controller=t,this.connectionListener=n||new Ce,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}},e.ResetError=Ae,e.SubscriptionManager=class{constructor(e){this.subscriptions={},this.controller=new be,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case D:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case N: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]}}},e.__INTERNAL__=oe,e.actionTypes=ee,e.actions=me,e.applyManager=function(e,t){return e.map(((e,n)=>(e.middleware||(e.middleware=null==e.getMiddleware?void 0:e.getMiddleware()),i=>(0===n&&t.bindMiddleware(i),e.middleware(t)))))},e.createReducer=function(e){return function(t,n){switch(t||(t=re),n.type){case H:return n.entities.forEach((({key:e,pk:n})=>{var i,s;null==(i=t.entities[e])||delete i[n],null==(s=t.entitiesMeta[e])||delete s[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case R:return function(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const n=te(t.endpoint,t.args,t.meta.fetchedAt);return l({},e,{optimistic:[...e.optimistic,n]})}return e}(t,n);case T:case j:return function(e,t,n){if(t.error)return ie(e,t,t.response);try{var i;let s;if(t.type===T){if(!t.endpoint.getOptimisticResponse)return e;try{s=t.endpoint.getOptimisticResponse.call(t.endpoint,n.snapshot(e,t.meta.fetchedAt),...t.args)}catch(t){if(t.constructor===ne)return e;throw t}}else s=t.response;const{result:r,entities:o,indexes:a,entitiesMeta:c}=A(t.endpoint.schema,s,t.args,e,t.meta),h=l({},e.endpoints,{[t.key]:r});try{if(t.endpoint.update){const e=t.endpoint.update(r,...t.args);Object.keys(e).forEach((t=>{h[t]=e[t](h[t])}))}}catch(e){console.error(`The following error occured during Endpoint.update() for ${t.key}`),console.error(e)}return{entities:o,endpoints:h,indexes:a,meta:l({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,prevExpiresAt:null==(i=e.meta[t.key])?void 0:i.expiresAt}}),entitiesMeta:c,optimistic:se(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),ie(e,t,n)}}(t,n,e);case P:return function(e,t,n){let i;if("function"==typeof t.value){const s=n.get(t.schema,...t.args,e);if(void 0===s)return e;i=t.value(s)}else i=t.value;try{const{entities:n,indexes:s,entitiesMeta:r}=A(t.schema,i,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:s,meta:e.meta,entitiesMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case z:case K:return function(e,t){const n=l({},e.endpoints),i=l({},e.meta),s=e=>{delete n[e];const t=l({},i[e],{expiresAt:0,invalidated:!0});delete t.error,i[e]=t};return t.type===K?s(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&s(e)})),l({},e,{endpoints:n,meta:i})}(t,n);case Q:return function(e,t){const n=l({},e.meta);return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]=l({},n[e],{expiresAt:1}))})),l({},e,{meta:n})}(t,n);case q:return l({},re,{lastReset:n.date});default:return t}}},e.initManager=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()})},e.initialState=re}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).RDC=e.RDC||{},e.RDC.Core={}))}(this,(function(e){"use strict";class t{constructor(){this.localCache=new Map}getEntity(e,t,n,i){const s=t.key;this.localCache.has(s)||this.localCache.set(s,new Map);const r=this.localCache.get(s);return r.get(e)||i(r),r.get(e)}getResults(e,t,n){return{data:n(),paths:[]}}}const n=Symbol("INVALID"),i={};function s(e){return null!==e&&void 0!==e.pk}const r=e=>e[0],o=e=>void 0!==e&&"symbol"!=typeof e,a=(e,t,n,i,s,o)=>{e=r(e);const a=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return a.map((t=>o(e,t,n,i,s)))},c=(e,t,n,i)=>(e=r(e),t.map?t.map((t=>i(e,t))).filter(o):t);function h(){}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)({}).hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},l.apply(null,arguments)}const u=(e,t,n,i,s,r)=>{const o=l({},t),a=Object.keys(e);for(let n=0;n<a.length;n++){const i=a[n],c=r(e[i],t[i],t,i,s);void 0===c?delete o[i]:o[i]=c}return o},d=(e,t,i,s)=>{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,i,s){let r=!1;const o=Object.keys(e).reduce(((t,n)=>{const i=`${n}`,o=s(e[i],t.get(i));return"symbol"==typeof o&&(r=!0),t.has(i)?t.set(i,o):t}),t);return r?n:o}(e,t,0,s);const r=l({},t);let o=!1;const a=Object.keys(e);for(let t=0;t<a.length;t++){const n=a[t],i=s(e[n],r[n]);void 0!==r[n]&&(r[n]=i),"symbol"==typeof i&&(o=!0)}return o?n:r};function p(e,t,n,i){const s={};for(const r of Object.keys(e))s[r]=n(e[r],t,i);return s}const f=(e,t,n,s)=>function(r,o){const a="object"!=typeof o,c=a?e({key:r.key,pk:o}):o;if("symbol"==typeof c)return r.denormalize(c,n,s);if(void 0===c&&a&&""!==o&&"undefined"!==o)return t.getEntity(o,r,i,(e=>{e.set(o,void 0)}));if("object"!=typeof c||null===c)return c;let h=a?o:r.pk(c,void 0,void 0,n);return void 0===h||""===h||"undefined"===h?function(e){const t=new Map;return e(t),t.get("")}((e=>y(r,c,"",e,n,s))):("string"!=typeof h&&(h=`${h}`),t.getEntity(h,r,c,(e=>y(r,c,h,e,n,s))))};function y(e,t,i,s,r,o){const a=e.createIfValid(t);void 0===a?s.set(i,n):(s.set(i,a),s.set(i,e.denormalize(a,r,o)))}const g=(e,t,n)=>{const i=f(e,t,n,r);function r(e,t){if(!e)return t;if(null==t)return t;if("function"==typeof e.denormalize)return s(e)?i(e,t):e.denormalize(t,n,r);if("function"==typeof e)return e(t);if("object"==typeof e){return(Array.isArray(e)?c:d)(e,t,n,r)}return t}return(e,n)=>{const i=Object(n)===n&&Object(e)===e;return t.getResults(n,i,(()=>r(e,n)))}};class m{constructor({entities:e,indexes:t}){this.entities=e,this.indexes=t}tracked(e){const t=this,i=[{path:[""],entity:e}];return[{INVALID:n,getIndex(...e){const n=t.getIndex(...e);return i.push({path:e,entity:n}),t.getIndexEnd(n,e[2])},getEntity(...e){const n=t.getEntity(...e);return i.push({path:e,entity:n}),n},getEntities(e){const n=t.getEntitiesObject(e);return i.push({path:[e],entity:n}),t.getEntities(e)}},i]}}class v extends m{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 E={QueryDelegate:v,getEntities:e=>({key:t,pk:n})=>{var i;return null==(i=e[t])?void 0:i[n]}};class w{constructor(){this.next=new WeakMap,this.nextPath=void 0}get(e,t){let n=this.next.get(e);if(!n)return x;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:i;if(n=n.next.get(e),!n)return x}return[n.value,n.journey]}set(e,t){if(e.length<1)throw new k;let n=this;for(const{path:t,entity:s}of e){let e=n.next.get(s);e||(e=new b,n.next.set(null!=s?s:i,e)),n.nextPath=t,n=e}n.nextPath=void 0,n.value=t,n.journey=e.map((e=>e.path))}}const x=[void 0,void 0];class b{constructor(){this.next=new WeakMap,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 I extends v{constructor(e,t){super(e),this.newEntities=new Map,this.newIndexes=new Map,this.entitiesMeta=e.entitiesMeta,this.meta=t,this.checkLoop=function(){const e=new Map;return function(t,n,i){let s=e.get(t);s||(s=new Map,e.set(t,s));let r=s.get(n);return r||(r=new Set,s.set(n,r)),!!r.has(i)||(r.add(i),!1)}}()}getNewEntity(e,t){return this.getNewEntities(e).get(t)}getNewEntities(e){return this.newEntities.has(e)||(this.newEntities.set(e,new Map),this.entities[e]=l({},this.entities[e]),this.entitiesMeta[e]=l({},this.entitiesMeta[e])),this.newEntities.get(e)}getNewIndexes(e){return this.newIndexes.has(e)||(this.newIndexes.set(e,new Map),this.indexes[e]=l({},this.indexes[e])),this.newIndexes.get(e)}mergeEntity(e,t,n){const i=e.key;let s=n,r=this.meta,o=this.getNewEntity(i,t);if(o)s=e.merge(o,n);else if(o=this.getEntity(i,t),o){const a=this.getMeta(i,t);s=e.mergeWithStore(a,r,o,n),r=e.mergeMetaWithStore(a,r,o,n)}this.setEntity(e,t,s,r)}setEntity(e,t,i,s=this.meta){const r=e.key,o=this.getNewEntities(r),a=!o.has(t);o.set(t,i),e.indexes&&function(e,t,i,s,r,o){for(const a of t){i.has(a)||i.set(a,s[a]={});const t=i.get(a);o[e]&&delete t[o[e][a]],o&&o[e]&&o[e][a]!==r[a]&&(t[o[e][a]]=n),a in r&&(t[r[a]]=e)}}(t,e.indexes,this.getNewIndexes(r),this.indexes[r],i,this.entities[r]),this._setEntity(r,t,i),a&&this._setMeta(r,t,s)}invalidate({key:e},t){this.setEntity({key:e},t,n)}_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 A=(e,t,n=[],{entities:i,indexes:s,entitiesMeta:r}=L,o={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:i,indexes:s,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 h={result:"",entities:l({},i),indexes:l({},s),entitiesMeta:l({},r)},d=(e=>{const t=(n,i,s,r,o)=>i&&n?n.normalize&&"function"==typeof n.normalize?"object"!=typeof i?n.pk?`${i}`:i:n.normalize(i,s,r,o,t,e):"object"!=typeof i||"object"!=typeof n?i:(Array.isArray(n)?a:u)(n,i,s,r,o,t):i;return t})(new I(h,o));return h.result=d(e,t,t,void 0,n),h};const L={entities:{},indexes:{},entitiesMeta:{}};class S{constructor(e,t,n){this.dependencies=[],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._getEntity=e,this._getCache=t,this._resultCache=n}getEntity(e,t,n,i){const s=t.key,{localCacheKey:r,cycleCacheKey:o}=this.getCacheKey(s);if(r.get(e))o.has(e)?this.cycleIndex=o.get(e):this.dependencies.push({path:{key:s,pk:e},entity:n});else{const a=this._getCache(e,t),[c,h]=a.get(n,this._getEntity);if(h)return r.set(e,c.value),this.dependencies.push(...c.dependencies),c.value;{const t=this.dependencies.length;o.set(e,t),this.dependencies.push({path:{key:s,pk:e},entity:n}),i(r),o.delete(e);const c=this.dependencies.slice(-1===this.cycleIndex?t:this.cycleIndex),h={dependencies:c,value:r.get(e)};a.set(c,h),this.cycleIndex===t&&(this.cycleIndex=-1)}}return r.get(e)}getCacheKey(e){this.localCache.has(e)||this.localCache.set(e,new Map),this.cycleCache.has(e)||this.cycleCache.set(e,new Map);return{localCacheKey:this.localCache.get(e),cycleCacheKey:this.cycleCache.get(e)}}getResults(e,t,n){if(!t)return{data:n(),paths:this.paths()};let[i,s]=this._resultCache.get(e,this._getEntity);return void 0===s?(i=n(),s=this.paths(),this.dependencies.unshift({path:{key:"",pk:""},entity:e}),this._resultCache.set(this.dependencies,i)):s.shift(),{data:i,paths:s}}paths(){return this.dependencies.map((e=>e.path))}}function M(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(M))}class C{constructor(e=E){var t;this.endpoints=new w,this.queryKeys=new Map,this.policy=e,this._getCache=(t=new Map,(e,n)=>{var i;const s=n.key,r=null!=(i=n.cacheWith)?i:n;t.has(s)||t.set(s,new Map);const o=t.get(s);o.has(e)||o.set(e,new WeakMap);const a=o.get(e);let c=a.get(r);return c||(c=new w,a.set(r,c)),c})}denormalize(e,t,n,i=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const s=this.policy.getEntities(n);return g(s,new S(s,this._getCache,this.endpoints),i)(e,t)}query(e,t,n,i=JSON.stringify(t)){const s=this.buildQueryKey(e,t,n,i);return s?this.denormalize(e,s,n.entities,t):{data:void 0,paths:[]}}buildQueryKey(e,t,n,i=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;let s=this.queryKeys.get(i);s||(s=new w,this.queryKeys.set(i,s));const r=new this.policy.QueryDelegate(n);let[o,a]=s.get(e,(c=r,e=>c[["","getEntitiesObject","getEntity","getIndex"][e.length]](...e)));var c;if(!a){const[n,i]=r.tracked(e);o=function(e){return function t(n,i){return function(e){return!!e&&"function"==typeof e.queryKey}(n)?n.queryKey(i,t,e):"object"==typeof n&&n?(Array.isArray(n)?h:p)(n,i,t,e):n}}(n)(e,t),s.set(i,o)}return o}}var O={Invalid:1,InvalidIfStale:2,Valid:3};function _(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const R="rdc/fetch",P="rdc/set",j="rdc/setresponse",T="rdc/optimistic",q="rdc/reset",D="rdc/subscribe",N="rdc/unsubscribe",K="rdc/invalidate",z="rdc/invalidateall",Q="rdc/expireall",H="rdc/gc",F=R,V=P,B=j,U=T,Y=q,$=D,W=N,X=K,G=z,J=Q,Z=H;var ee=Object.freeze({__proto__:null,EXPIREALL:Q,EXPIREALL_TYPE:J,FETCH:R,FETCH_TYPE:F,GC:H,GC_TYPE:Z,INVALIDATE:K,INVALIDATEALL:z,INVALIDATEALL_TYPE:G,INVALIDATE_TYPE:X,OPTIMISTIC:T,OPTIMISTIC_TYPE:U,RESET:q,RESET_TYPE:Y,SET:P,SET_RESPONSE:j,SET_RESPONSE_TYPE:B,SET_TYPE:V,SUBSCRIBE:D,SUBSCRIBE_TYPE:$,UNSUBSCRIBE:N,UNSUBSCRIBE_TYPE:W});const te="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function ne(e,t,n){var i;return{type:T,key:e.key(...t),args:t.map(te),endpoint:e,meta:_(null!=(i=e.dataExpiryLength)?i:6e4,n)}}class ie extends Error{}function se(e,t,n){return"AbortError"===n.name?l({},e,{optimistic:re(e,t)}):l({},e,{meta:l({},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:re(e,t)})}function re(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)))}const oe={entities:{},endpoints:{},indexes:{},meta:{},entitiesMeta:{},optimistic:[],lastReset:0};var ae=Object.freeze({__proto__:null,INVALID:n,MemoCache:C,initialState:oe});function ce(e,{args:t}){return{type:D,key:e.key(...t),args:t,endpoint:e}}function he(e,{args:t}){return{type:N,key:e.key(...t),args:t,endpoint:e}}function le(e,{args:t,fetchedAt:n,response:i,error:s=!1}){var r,o;const a=s?null!=(r=e.errorExpiryLength)?r:1e3:null!=(o=e.dataExpiryLength)?o:6e4;return{type:j,key:e.key(...t),response:i,args:t.map(te),endpoint:e,meta:_(a,n),error:s}}function ue(e,{args:t,fetchedAt:n,value:i}){return{type:P,value:i,args:t.map(te),schema:e,meta:_(6e4,n)}}function de(){return{type:q,date:Date.now()}}function pe(e){return{type:z,testKey:e}}function fe(e,{args:t}){return{type:K,key:e.key(...t)}}function ye(e,{args:t}){let n=0,i=0;const s=new Promise(((e,t)=>{[n,i]=[e,t]})),r={fetchedAt:Date.now(),resolve:n,reject:i,promise:s};return{type:R,key:e.key(...t),args:t,endpoint:e,meta:r}}function ge(e){return{type:Q,testKey:e}}var me=Object.freeze({__proto__:null,createExpireAll:ge,createFetch:ye,createInvalidate:fe,createInvalidateAll:pe,createMeta:_,createOptimistic:ne,createReset:de,createSet:ue,createSetResponse:le,createSubscription:ce,createUnsubscription:he});class ve{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function Ee(e,t){return e.meta[t]}const we=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},xe=()=>oe;class be{constructor({dispatch:e=we,getState:n=xe,memo:i=new C,gcPolicy:s=new ve}={}){this.fetch=(e,...n)=>{const i=ye(e,{args:n});return this.dispatch(i),e.schema?i.meta.promise.then((i=>function(e,n,i,s=[]){return void 0===e||void 0===n?n:g(E.getEntities(i),new t,s)(e,n).data}(e.schema,i,{},n))):i.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:i,expiryStatus:s}=this.getResponseMeta(e,...t,this.getState());return s!==O.Invalid&&Date.now()<=i?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(fe(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch(pe((t=>e.testKey(t)))),this.expireAll=e=>this.dispatch(ge((t=>e.testKey(t)))),this.resetEntireStore=()=>this.dispatch(de()),this.setResponse=(e,...t)=>{const n=t[t.length-1],i=le(e,{args:t.slice(0,t.length-1),response:n});return this.dispatch(i)},this.setError=(e,...t)=>{const n=t[t.length-1],i=le(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(i)},this.resolve=(e,t)=>this.dispatch(le(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(ce(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(he(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new Ie(this,e,t),this._dispatch=e,this.getState=n,this.memo=i,this.gcPolicy=s}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],i=ue(e,{args:t.slice(0,t.length-1),value:n});return this.dispatch(i)}getError(e,...t){if(null===t[0])return;const n=t[t.length-1],i=t.slice(0,t.length-1),s=e.key(...i),r=Ee(n,s);return void 0===n.endpoints[s]||"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,i]=Ae(t),s=1!==i.length||null!==i[0],r=s?e.key(...i):"",o=s?n.endpoints[r]:void 0,a=e.schema,c=Ee(n,r);let h=null==c?void 0:c.expiresAt;const l=void 0===o&&void 0!==a,u=l?this.memo.buildQueryKey(a,i,n,r):o;if(!s)return{data:u,expiryStatus:O.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(l)d=!M(u);else if(!a||!ke(a))return{data:o,expiryStatus:this.getExpiryStatus(!o,!!e.invalidIfStale,c),expiresAt:h||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(a,u,n.entities,i);return h||(h=d?1:function(e,t){let n=1/0;for(const{key:s,pk:r}of e){var i;const e=null==(i=t[s])||null==(i=i[r])?void 0:i.expiresAt;e<n&&(n=e)}return n}(f,n.entitiesMeta)),{data:p,expiryStatus:this.getExpiryStatus("symbol"==typeof p,!!e.invalidIfStale||d,c),expiresAt:h,countRef:this.gcPolicy.createCountRef({key:r,paths:f})}}get(e,...t){const[n,i]=Ae(t),{data:s}=this.memo.query(e,i,n);return"symbol"==typeof s?void 0:s}getQueryMeta(e,...t){const[n,i]=Ae(t),{data:s,paths:r}=this.memo.query(e,i,n);return{data:"symbol"==typeof s?void 0:s,countRef:this.gcPolicy.createCountRef({paths:r})}}getExpiryStatus(e,t,n={}){return n.invalidated||e&&!n.error?O.Invalid:e||t?O.InvalidIfStale:O.Valid}}function ke(e){if(s(e))return!0;if(Array.isArray(e))return 0!==e.length&&ke(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?ke(t):Object.values(t).some((e=>ke(e)))}return!1}class Ie{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=Ie.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 Ae(e){const t=e.length,n=new Array(t-1);for(let i=0;i<t-1;i++)n[i]=te(e[i]);return[e[t-1],n]}Ie.abort=new ie;class Le extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class Se{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 Me{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}let Ce;Ce="undefined"!=typeof navigator&&"function"==typeof addEventListener?Se:Me;var Oe=Ce;let _e={};class Re{constructor(e,t){this.started=!1,this.actions=[],this.maxBufferLength=100,this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(l({},_e,e)),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(){}}Re.prototype.middleware=()=>e=>t=>e(t);e.Controller=be,e.DefaultConnectionListener=Oe,e.DevToolsManager=Re,e.ExpiryStatus=O,e.GCPolicy=class{constructor({intervalMS:e=3e5,expiryMultiplier:t=2,expiresAt:n}={}){this.endpointCount=new Map,this.entityCount=new Map,this.endpointsQ=new Set,this.entitiesQ=[],n&&(this.expiresAt=n.bind(this)),this.options={intervalMS:e,expiryMultiplier:t}}init(e){this.controller=e,this.intervalId=setInterval((()=>{this.idleCallback((()=>this.runSweep()),{timeout:1e3})}),this.options.intervalMS)}cleanup(){clearInterval(this.intervalId)}createCountRef({key:e,paths:t=[]}){return()=>{var n;return e&&this.endpointCount.set(e,(null!=(n=this.endpointCount.get(e))?n:0)+1),t.forEach((e=>{var t;const{key:n,pk:i}=e;this.entityCount.has(n)||this.entityCount.set(n,new Map);const s=this.entityCount.get(n);s.set(i,(null!=(t=s.get(i))?t:0)+1)})),()=>{if(e){const t=this.endpointCount.get(e);void 0!==t&&(t<=1?(this.endpointCount.delete(e),this.endpointsQ.add(e)):this.endpointCount.set(e,t-1))}t.forEach((e=>{const{key:t,pk:n}=e;if(!this.entityCount.has(t))return;const i=this.entityCount.get(t),s=i.get(n);void 0!==s&&(s<=1?(i.delete(n),this.entitiesQ.push(e)):i.set(n,s-1))}))}}}expiresAt({fetchedAt:e,expiresAt:t}){return Math.max((t-e)*this.options.expiryMultiplier,12e4)+e}runSweep(){const e=this.controller.getState(),t=[],n=[],i=Date.now(),s=new Set;for(const t of this.endpointsQ){var r;!this.endpointCount.has(t)&&this.expiresAt(null!=(r=e.meta[t])?r:{fetchedAt:0,date:0,expiresAt:0})<i?n.push(t):s.add(t)}this.endpointsQ=s;const o=[];for(const n of this.entitiesQ){var a,c,h;(null==(a=this.entityCount.get(n.key))||!a.has(n.pk))&&this.expiresAt(null!=(c=null==(h=e.entitiesMeta[n.key])?void 0:h[n.pk])?c:{fetchedAt:0,date:0,expiresAt:0})<i?t.push(n):o.push(n)}this.entitiesQ=o,(t.length||n.length)&&this.controller.dispatch({type:H,entities:t,endpoints:n})}idleCallback(e,t){"function"==typeof requestIdleCallback?requestIdleCallback(e,t):e()}},e.ImmortalGCPolicy=ve,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===j&&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=class{constructor({dataExpiryLength:e=6e4,errorExpiryLength:t=1e3}={}){this.fetching=new Map,this.controller=new be,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case R:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case j:return t(n).then((()=>{if(this.fetching.has(n.key)){var t;const i=null==(t=e.getState().meta[n.key])?void 0:t.error;i?this.handleSet(le(n.endpoint,{args:n.args,response:i,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 Le)}))}default:return t(n)}}),this.dataExpiryLength=e,this.errorExpiryLength=t}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}skipLogging(e){return e.type===R&&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:i}=e.meta,s=!e.endpoint.sideEffect,r=()=>{let r=e.endpoint(...e.args);return s||(r=(e=>e.then((e=>(t(e),e))).catch((e=>{throw n(e),e})))(r)),r=r.then((t=>{let n=this.getLastReset();return i>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:i}),t})).catch((t=>{const n=this.getLastReset();throw i>=n&&this.controller.resolve(e.endpoint,{args:e.args,response:t,fetchedAt:i,error:!0}),t})),r};return s?this.throttle(e.key,r,i).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 i=this.getLastReset();let s=this.fetching.get(e);return s&&s.fetchedAt>i||(s=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,s),this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),s.promise}idleCallback(e,t){e()}},e.PollingSubscription=class{constructor(e,t,n){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===e.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=e.endpoint,this.frequency=e.endpoint.pollFrequency,this.args=e.args,this.key=e.key,this.frequencyHistogram.set(this.frequency,1),this.controller=t,this.connectionListener=n||new Oe,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}},e.ResetError=Le,e.SubscriptionManager=class{constructor(e){this.subscriptions={},this.controller=new be,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case D:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case N: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]}}},e.__INTERNAL__=ae,e.actionTypes=ee,e.actions=me,e.applyManager=function(e,t){return e.map(((e,n)=>(e.middleware||(e.middleware=null==e.getMiddleware?void 0:e.getMiddleware()),i=>(0===n&&t.bindMiddleware(i),e.middleware(t)))))},e.createReducer=function(e){return function(t,n){switch(t||(t=oe),n.type){case H:return n.entities.forEach((({key:e,pk:n})=>{var i,s;null==(i=t.entities[e])||delete i[n],null==(s=t.entitiesMeta[e])||delete s[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case R:return function(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const n=ne(t.endpoint,t.args,t.meta.fetchedAt);return l({},e,{optimistic:[...e.optimistic,n]})}return e}(t,n);case T:case j:return function(e,t,n){if(t.error)return se(e,t,t.response);try{var i;let s;if(t.type===T){if(!t.endpoint.getOptimisticResponse)return e;try{s=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 s=t.response;const{result:r,entities:o,indexes:a,entitiesMeta:c}=A(t.endpoint.schema,s,t.args,e,t.meta),h=l({},e.endpoints,{[t.key]:r});try{if(t.endpoint.update){const e=t.endpoint.update(r,...t.args);Object.keys(e).forEach((t=>{h[t]=e[t](h[t])}))}}catch(e){console.error(`Endpoint.update() error: ${t.key}`),console.error(e)}return{entities:o,endpoints:h,indexes:a,meta:l({},e.meta,{[t.key]:{date:t.meta.date,fetchedAt:t.meta.fetchedAt,expiresAt:t.meta.expiresAt,prevExpiresAt:null==(i=e.meta[t.key])?void 0:i.expiresAt}}),entitiesMeta:c,optimistic:re(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),se(e,t,n)}}(t,n,e);case P:return function(e,t,n){let i;if("function"==typeof t.value){const s=n.get(t.schema,...t.args,e);if(void 0===s)return e;i=t.value(s)}else i=t.value;try{const{entities:n,indexes:s,entitiesMeta:r}=A(t.schema,i,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:s,meta:e.meta,entitiesMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case z:case K:return function(e,t){const n=l({},e.endpoints),i=l({},e.meta),s=e=>{delete n[e];const t=l({},i[e],{expiresAt:0,invalidated:!0});delete t.error,i[e]=t};return t.type===K?s(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&s(e)})),l({},e,{endpoints:n,meta:i})}(t,n);case Q:return function(e,t){const n=l({},e.meta);return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]=l({},n[e],{expiresAt:1}))})),l({},e,{meta:n})}(t,n);case q:return l({},oe,{lastReset:n.date});default:return t}}},e.initManager=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()})},e.initialState=oe}));
package/dist/mock.js CHANGED
@@ -43,6 +43,11 @@ const EXPIREALL = 'rdc/expireall';
43
43
  const GC = 'rdc/gc';
44
44
  const FETCH_TYPE = FETCH;
45
45
 
46
+ const ensurePojo =
47
+ // FormData doesn't exist in node
48
+ /* istanbul ignore else we don't run coverage when we test node*/
49
+ typeof FormData !== 'undefined' ? body => body instanceof FormData ? Object.fromEntries(body.entries()) : body : /* istanbul ignore next */body => body;
50
+
46
51
  function createOptimistic(endpoint, args, fetchedAt) {
47
52
  var _endpoint$dataExpiryL, _endpoint$dataExpiryL2;
48
53
  /* istanbul ignore next */
@@ -52,7 +57,7 @@ function createOptimistic(endpoint, args, fetchedAt) {
52
57
  return {
53
58
  type: OPTIMISTIC,
54
59
  key: endpoint.key(...args),
55
- args,
60
+ args: args.map(ensurePojo),
56
61
  endpoint,
57
62
  meta: createMeta((_endpoint$dataExpiryL2 = endpoint.dataExpiryLength) != null ? _endpoint$dataExpiryL2 : 60000, fetchedAt)
58
63
  };
@@ -184,7 +189,7 @@ function setResponseReducer(state, action, controller) {
184
189
  // no reason to completely fail because of user-code error
185
190
  // integrity of this state update is still guaranteed
186
191
  } catch (error) {
187
- console.error(`The following error occured during Endpoint.update() for ${action.key}`);
192
+ console.error(`Endpoint.update() error: ${action.key}`);
188
193
  console.error(error);
189
194
  }
190
195
  return {
@@ -306,7 +311,6 @@ const initialState$1 = {
306
311
 
307
312
  var __INTERNAL__ = /*#__PURE__*/Object.freeze({
308
313
  __proto__: null,
309
- INVALID: normalizr.INVALID,
310
314
  MemoCache: normalizr.MemoCache,
311
315
  initialState: initialState$1
312
316
  });
@@ -332,11 +336,6 @@ function createUnsubscription(endpoint, {
332
336
  };
333
337
  }
334
338
 
335
- const ensurePojo =
336
- // FormData doesn't exist in node
337
- /* istanbul ignore else we don't run coverage when we test node*/
338
- typeof FormData !== 'undefined' ? body => body instanceof FormData ? Object.fromEntries(body.entries()) : body : /* istanbul ignore next */body => body;
339
-
340
339
  function createSetResponse(endpoint, {
341
340
  args,
342
341
  fetchedAt,
@@ -685,11 +684,7 @@ class Controller {
685
684
  */
686
685
 
687
686
  getResponseMeta(endpoint, ...rest) {
688
- const state = rest[rest.length - 1];
689
- // this is typescript generics breaking
690
- const args = rest.slice(0, rest.length - 1)
691
- // handle FormData
692
- .map(ensurePojo);
687
+ const [state, args] = extractStateAndArgs(rest);
693
688
  const isActive = args.length !== 1 || args[0] !== null;
694
689
  const key = isActive ? endpoint.key(...args) : '';
695
690
  const cacheEndpoints = isActive ? state.endpoints[key] : undefined;
@@ -750,9 +745,7 @@ class Controller {
750
745
  * @see https://dataclient.io/docs/api/Controller#get
751
746
  */
752
747
  get(schema, ...rest) {
753
- const state = rest[rest.length - 1];
754
- // this is typescript generics breaking
755
- const args = rest.slice(0, rest.length - 1).map(ensurePojo);
748
+ const [state, args] = extractStateAndArgs(rest);
756
749
  const {
757
750
  data
758
751
  } = this.memo.query(schema, args, state);
@@ -764,9 +757,7 @@ class Controller {
764
757
  * @see https://dataclient.io/docs/api/Controller#getQueryMeta
765
758
  */
766
759
  getQueryMeta(schema, ...rest) {
767
- const state = rest[rest.length - 1];
768
- // this is typescript generics breaking
769
- const args = rest.slice(0, rest.length - 1).map(ensurePojo);
760
+ const [state, args] = extractStateAndArgs(rest);
770
761
  const {
771
762
  data,
772
763
  paths
@@ -866,6 +857,18 @@ class Snapshot {
866
857
  }
867
858
  }
868
859
 
860
+ /** Extract state and args from rest params, applying ensurePojo to args */
861
+ function extractStateAndArgs(rest) {
862
+ const l = rest.length;
863
+ const args = new Array(l - 1);
864
+ for (let i = 0; i < l - 1; i++) {
865
+ // handle FormData
866
+ args[i] = ensurePojo(rest[i]);
867
+ }
868
+ // this is typescript generics breaking
869
+ return [rest[l - 1], args];
870
+ }
871
+
869
872
  var _DevToolsManager;
870
873
  let DEFAULT_CONFIG = {};
871
874
  if (process.env.NODE_ENV !== 'production') {