@data-client/core 0.14.24 → 0.15.0-beta-20251006024044-92bd01c4976f2921993b8c9f1e4dbb87af87ba7b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.js +100 -97
- package/dist/index.umd.min.js +1 -1
- package/legacy/controller/Controller.js +31 -46
- package/legacy/index.js +1 -1
- package/legacy/manager/NetworkManager.js +44 -33
- package/legacy/state/GCPolicy.js +20 -12
- package/legacy/state/reducer/createReducer.js +4 -4
- package/legacy/state/reducer/setReducer.js +3 -3
- package/legacy/state/reducer/setResponseReducer.js +4 -4
- package/legacy/types.js +1 -1
- package/lib/controller/Controller.d.ts +3 -3
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +31 -46
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/manager/NetworkManager.d.ts +7 -12
- package/lib/manager/NetworkManager.d.ts.map +1 -1
- package/lib/manager/NetworkManager.js +44 -34
- package/lib/state/GCPolicy.d.ts.map +1 -1
- package/lib/state/GCPolicy.js +20 -12
- package/lib/state/reducer/createReducer.js +4 -4
- package/lib/state/reducer/expireReducer.d.ts +1 -1
- package/lib/state/reducer/invalidateReducer.d.ts +1 -1
- package/lib/state/reducer/setReducer.d.ts +1 -1
- package/lib/state/reducer/setReducer.js +3 -3
- package/lib/state/reducer/setResponseReducer.d.ts +1 -1
- package/lib/state/reducer/setResponseReducer.js +4 -4
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -1
- package/package.json +3 -3
- package/src/controller/Controller.ts +38 -80
- package/src/controller/__tests__/Controller.ts +2 -2
- package/src/controller/__tests__/__snapshots__/get.ts.snap +34 -8
- package/src/controller/__tests__/__snapshots__/getResponse.ts.snap +1 -1
- package/src/controller/__tests__/get.ts +163 -22
- package/src/controller/__tests__/getResponse.ts +1 -1
- package/src/index.ts +4 -0
- package/src/manager/NetworkManager.ts +46 -32
- package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +1 -1
- package/src/manager/__tests__/pollingSubscription.ts +9 -5
- package/src/state/GCPolicy.ts +12 -10
- package/src/state/__tests__/GCPolicy.test.ts +6 -6
- package/src/state/__tests__/__snapshots__/reducer.ts.snap +3 -3
- package/src/state/__tests__/reducer.ts +17 -9
- package/src/state/reducer/createReducer.ts +2 -2
- package/src/state/reducer/setReducer.ts +2 -2
- package/src/state/reducer/setResponseReducer.ts +3 -3
- package/src/types.ts +1 -1
- package/ts3.4/controller/Controller.d.ts +3 -3
- package/ts3.4/index.d.ts +2 -1
- package/ts3.4/manager/NetworkManager.d.ts +7 -12
- package/ts3.4/state/reducer/expireReducer.d.ts +1 -1
- package/ts3.4/state/reducer/invalidateReducer.d.ts +1 -1
- package/ts3.4/state/reducer/setReducer.d.ts +1 -1
- package/ts3.4/state/reducer/setResponseReducer.d.ts +1 -1
- package/ts3.4/types.d.ts +1 -1
package/README.md
CHANGED
|
@@ -43,12 +43,12 @@ function useSuspense(endpoint, ...args)
|
|
|
43
43
|
|
|
44
44
|
// Compute denormalized value
|
|
45
45
|
const { data, expiryStatus, expiresAt } = useMemo(() => {
|
|
46
|
-
return controller.
|
|
46
|
+
return controller.getResponseMeta(endpoint, ...args, state);
|
|
47
47
|
}, [
|
|
48
48
|
cacheResults,
|
|
49
49
|
state.indexes,
|
|
50
50
|
state.entities,
|
|
51
|
-
state.
|
|
51
|
+
state.entitiesMeta,
|
|
52
52
|
meta,
|
|
53
53
|
key,
|
|
54
54
|
]);
|
package/dist/index.js
CHANGED
|
@@ -151,14 +151,14 @@ function setReducer(state, action, controller) {
|
|
|
151
151
|
const {
|
|
152
152
|
entities,
|
|
153
153
|
indexes,
|
|
154
|
-
|
|
154
|
+
entitiesMeta
|
|
155
155
|
} = normalizr.normalize(action.schema, value, action.args, state, action.meta);
|
|
156
156
|
return {
|
|
157
157
|
entities,
|
|
158
158
|
endpoints: state.endpoints,
|
|
159
159
|
indexes,
|
|
160
160
|
meta: state.meta,
|
|
161
|
-
|
|
161
|
+
entitiesMeta,
|
|
162
162
|
optimistic: state.optimistic,
|
|
163
163
|
lastReset: state.lastReset
|
|
164
164
|
};
|
|
@@ -204,7 +204,7 @@ function setResponseReducer(state, action, controller) {
|
|
|
204
204
|
result,
|
|
205
205
|
entities,
|
|
206
206
|
indexes,
|
|
207
|
-
|
|
207
|
+
entitiesMeta
|
|
208
208
|
} = normalizr.normalize(action.endpoint.schema, response, action.args, state, action.meta);
|
|
209
209
|
const endpoints = {
|
|
210
210
|
...state.endpoints,
|
|
@@ -236,7 +236,7 @@ function setResponseReducer(state, action, controller) {
|
|
|
236
236
|
prevExpiresAt: (_state$meta$action$ke = state.meta[action.key]) == null ? void 0 : _state$meta$action$ke.expiresAt
|
|
237
237
|
}
|
|
238
238
|
},
|
|
239
|
-
|
|
239
|
+
entitiesMeta,
|
|
240
240
|
optimistic: filterOptimistic(state, action),
|
|
241
241
|
lastReset: state.lastReset
|
|
242
242
|
};
|
|
@@ -260,7 +260,7 @@ function reduceError(state, action, error) {
|
|
|
260
260
|
if (error.name === 'AbortError') {
|
|
261
261
|
// In case we abort simply undo the optimistic update and act like no fetch even occured
|
|
262
262
|
// We still want those watching promises from fetch directly to observed the abort, but we don't want to
|
|
263
|
-
// Trigger errors in this case. This means theoretically improperly built
|
|
263
|
+
// Trigger errors in this case. This means theoretically improperly built aborts useSuspense() could suspend forever.
|
|
264
264
|
return {
|
|
265
265
|
...state,
|
|
266
266
|
optimistic: filterOptimistic(state, action)
|
|
@@ -296,9 +296,9 @@ function createReducer(controller) {
|
|
|
296
296
|
key,
|
|
297
297
|
pk
|
|
298
298
|
}) => {
|
|
299
|
-
var _entities$key,
|
|
299
|
+
var _entities$key, _entitiesMeta$key;
|
|
300
300
|
(_entities$key = state.entities[key]) == null || delete _entities$key[pk];
|
|
301
|
-
(
|
|
301
|
+
(_entitiesMeta$key = state.entitiesMeta[key]) == null || delete _entitiesMeta$key[pk];
|
|
302
302
|
});
|
|
303
303
|
action.endpoints.forEach(fetchKey => {
|
|
304
304
|
delete state.endpoints[fetchKey];
|
|
@@ -335,7 +335,7 @@ const initialState = {
|
|
|
335
335
|
endpoints: {},
|
|
336
336
|
indexes: {},
|
|
337
337
|
meta: {},
|
|
338
|
-
|
|
338
|
+
entitiesMeta: {},
|
|
339
339
|
optimistic: [],
|
|
340
340
|
lastReset: 0
|
|
341
341
|
};
|
|
@@ -521,11 +521,15 @@ class GCPolicy {
|
|
|
521
521
|
if (key) this.endpointCount.set(key, ((_this$endpointCount$g = this.endpointCount.get(key)) != null ? _this$endpointCount$g : 0) + 1);
|
|
522
522
|
paths.forEach(path => {
|
|
523
523
|
var _instanceCount$get;
|
|
524
|
-
|
|
525
|
-
|
|
524
|
+
const {
|
|
525
|
+
key,
|
|
526
|
+
pk
|
|
527
|
+
} = path;
|
|
528
|
+
if (!this.entityCount.has(key)) {
|
|
529
|
+
this.entityCount.set(key, new Map());
|
|
526
530
|
}
|
|
527
|
-
const instanceCount = this.entityCount.get(
|
|
528
|
-
instanceCount.set(
|
|
531
|
+
const instanceCount = this.entityCount.get(key);
|
|
532
|
+
instanceCount.set(pk, ((_instanceCount$get = instanceCount.get(pk)) != null ? _instanceCount$get : 0) + 1);
|
|
529
533
|
});
|
|
530
534
|
|
|
531
535
|
// decrement
|
|
@@ -543,18 +547,22 @@ class GCPolicy {
|
|
|
543
547
|
}
|
|
544
548
|
}
|
|
545
549
|
paths.forEach(path => {
|
|
546
|
-
|
|
550
|
+
const {
|
|
551
|
+
key,
|
|
552
|
+
pk
|
|
553
|
+
} = path;
|
|
554
|
+
if (!this.entityCount.has(key)) {
|
|
547
555
|
return;
|
|
548
556
|
}
|
|
549
|
-
const instanceCount = this.entityCount.get(
|
|
550
|
-
const entityCount = instanceCount.get(
|
|
557
|
+
const instanceCount = this.entityCount.get(key);
|
|
558
|
+
const entityCount = instanceCount.get(pk);
|
|
551
559
|
if (entityCount !== undefined) {
|
|
552
560
|
if (entityCount <= 1) {
|
|
553
|
-
instanceCount.delete(
|
|
561
|
+
instanceCount.delete(pk);
|
|
554
562
|
// queue for cleanup
|
|
555
563
|
this.entitiesQ.push(path);
|
|
556
564
|
} else {
|
|
557
|
-
instanceCount.set(
|
|
565
|
+
instanceCount.set(pk, entityCount - 1);
|
|
558
566
|
}
|
|
559
567
|
}
|
|
560
568
|
});
|
|
@@ -588,8 +596,8 @@ class GCPolicy {
|
|
|
588
596
|
this.endpointsQ = nextEndpointsQ;
|
|
589
597
|
const nextEntitiesQ = [];
|
|
590
598
|
for (const path of this.entitiesQ) {
|
|
591
|
-
var _this$entityCount$get, _state$
|
|
592
|
-
if (!((_this$entityCount$get = this.entityCount.get(path.key)) != null && _this$entityCount$get.has(path.pk)) && this.expiresAt((_state$
|
|
599
|
+
var _this$entityCount$get, _state$entitiesMeta$p, _state$entitiesMeta$p2;
|
|
600
|
+
if (!((_this$entityCount$get = this.entityCount.get(path.key)) != null && _this$entityCount$get.has(path.pk)) && this.expiresAt((_state$entitiesMeta$p = (_state$entitiesMeta$p2 = state.entitiesMeta[path.key]) == null ? void 0 : _state$entitiesMeta$p2[path.pk]) != null ? _state$entitiesMeta$p : {
|
|
593
601
|
fetchedAt: 0,
|
|
594
602
|
date: 0,
|
|
595
603
|
expiresAt: 0
|
|
@@ -727,7 +735,7 @@ class Controller {
|
|
|
727
735
|
data,
|
|
728
736
|
expiresAt,
|
|
729
737
|
expiryStatus
|
|
730
|
-
} = this.
|
|
738
|
+
} = this.getResponseMeta(endpoint, ...args, this.getState());
|
|
731
739
|
if (expiryStatus !== normalizr.ExpiryStatus.Invalid && Date.now() <= expiresAt) return data;
|
|
732
740
|
return this.fetch(endpoint, ...args);
|
|
733
741
|
};
|
|
@@ -891,7 +899,7 @@ class Controller {
|
|
|
891
899
|
const shouldQuery = cacheEndpoints === undefined && schema !== undefined;
|
|
892
900
|
const input = shouldQuery ?
|
|
893
901
|
// nothing in endpoints cache, so try querying if we have a schema to do so
|
|
894
|
-
this.memo.buildQueryKey(schema, args, state
|
|
902
|
+
this.memo.buildQueryKey(schema, args, state, key) : cacheEndpoints;
|
|
895
903
|
if (!isActive) {
|
|
896
904
|
// when not active simply return the query input without denormalizing
|
|
897
905
|
return {
|
|
@@ -908,24 +916,32 @@ class Controller {
|
|
|
908
916
|
} else if (!schema || !schemaHasEntity(schema)) {
|
|
909
917
|
return {
|
|
910
918
|
data: cacheEndpoints,
|
|
911
|
-
expiryStatus:
|
|
919
|
+
expiryStatus: this.getExpiryStatus(!cacheEndpoints, !!endpoint.invalidIfStale, meta),
|
|
912
920
|
expiresAt: expiresAt || 0,
|
|
913
921
|
countRef: this.gcPolicy.createCountRef({
|
|
914
922
|
key
|
|
915
923
|
})
|
|
916
924
|
};
|
|
917
925
|
}
|
|
918
|
-
|
|
919
|
-
// second argument is false if any entities are missing
|
|
920
|
-
|
|
921
926
|
const {
|
|
922
927
|
data,
|
|
923
928
|
paths
|
|
924
929
|
} = this.memo.denormalize(schema, input, state.entities, args);
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
930
|
+
if (!expiresAt) {
|
|
931
|
+
// note: isInvalid can only be true if shouldQuery is true
|
|
932
|
+
if (isInvalid) expiresAt = 1;
|
|
933
|
+
// fallback to entity expiry time
|
|
934
|
+
else expiresAt = entityExpiresAt(paths, state.entitiesMeta);
|
|
935
|
+
}
|
|
936
|
+
return {
|
|
937
|
+
data,
|
|
938
|
+
expiryStatus: this.getExpiryStatus(typeof data === 'symbol', !!endpoint.invalidIfStale || isInvalid, meta),
|
|
939
|
+
expiresAt,
|
|
940
|
+
countRef: this.gcPolicy.createCountRef({
|
|
941
|
+
key,
|
|
942
|
+
paths
|
|
943
|
+
})
|
|
944
|
+
};
|
|
929
945
|
}
|
|
930
946
|
|
|
931
947
|
/**
|
|
@@ -936,7 +952,10 @@ class Controller {
|
|
|
936
952
|
const state = rest[rest.length - 1];
|
|
937
953
|
// this is typescript generics breaking
|
|
938
954
|
const args = rest.slice(0, rest.length - 1).map(ensurePojo);
|
|
939
|
-
|
|
955
|
+
const {
|
|
956
|
+
data
|
|
957
|
+
} = this.memo.query(schema, args, state);
|
|
958
|
+
return typeof data === 'symbol' ? undefined : data;
|
|
940
959
|
}
|
|
941
960
|
|
|
942
961
|
/**
|
|
@@ -947,20 +966,10 @@ class Controller {
|
|
|
947
966
|
const state = rest[rest.length - 1];
|
|
948
967
|
// this is typescript generics breaking
|
|
949
968
|
const args = rest.slice(0, rest.length - 1).map(ensurePojo);
|
|
950
|
-
|
|
951
|
-
// TODO: breaking: Switch back to this.memo.query(schema, args, state.entities as any, state.indexes) to do
|
|
952
|
-
// this logic
|
|
953
|
-
const input = this.memo.buildQueryKey(schema, args, state.entities, state.indexes, JSON.stringify(args));
|
|
954
|
-
if (!input) {
|
|
955
|
-
return {
|
|
956
|
-
data: undefined,
|
|
957
|
-
countRef: () => () => undefined
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
969
|
const {
|
|
961
970
|
data,
|
|
962
971
|
paths
|
|
963
|
-
} = this.memo.
|
|
972
|
+
} = this.memo.query(schema, args, state);
|
|
964
973
|
return {
|
|
965
974
|
data: typeof data === 'symbol' ? undefined : data,
|
|
966
975
|
countRef: this.gcPolicy.createCountRef({
|
|
@@ -968,40 +977,24 @@ class Controller {
|
|
|
968
977
|
})
|
|
969
978
|
};
|
|
970
979
|
}
|
|
971
|
-
|
|
972
|
-
const invalidDenormalize = typeof data === 'symbol';
|
|
973
|
-
|
|
974
|
-
// fallback to entity expiry time
|
|
975
|
-
if (!expiresAt) {
|
|
976
|
-
expiresAt = entityExpiresAt(paths, entityMeta);
|
|
977
|
-
}
|
|
978
|
-
|
|
980
|
+
getExpiryStatus(invalidData, invalidIfStale, meta = {}) {
|
|
979
981
|
// https://dataclient.io/docs/concepts/expiry-policy#expiry-status
|
|
980
982
|
// we don't track the difference between stale or fresh because that is tied to triggering
|
|
981
983
|
// conditions
|
|
982
|
-
|
|
983
|
-
return {
|
|
984
|
-
data,
|
|
985
|
-
expiryStatus,
|
|
986
|
-
expiresAt,
|
|
987
|
-
countRef: this.gcPolicy.createCountRef({
|
|
988
|
-
key,
|
|
989
|
-
paths
|
|
990
|
-
})
|
|
991
|
-
};
|
|
984
|
+
return meta.invalidated || invalidData && !meta.error ? normalizr.ExpiryStatus.Invalid : invalidData || invalidIfStale ? normalizr.ExpiryStatus.InvalidIfStale : normalizr.ExpiryStatus.Valid;
|
|
992
985
|
}
|
|
993
986
|
}
|
|
994
987
|
|
|
995
988
|
// benchmark: https://www.measurethat.net/Benchmarks/Show/24691/0/min-reducer-vs-imperative-with-paths
|
|
996
989
|
// earliest expiry dictates age
|
|
997
|
-
function entityExpiresAt(paths,
|
|
990
|
+
function entityExpiresAt(paths, entitiesMeta) {
|
|
998
991
|
let expiresAt = Infinity;
|
|
999
992
|
for (const {
|
|
1000
|
-
|
|
1001
|
-
|
|
993
|
+
key,
|
|
994
|
+
pk
|
|
1002
995
|
} of paths) {
|
|
1003
|
-
var
|
|
1004
|
-
const entityExpiry = (
|
|
996
|
+
var _entitiesMeta$key;
|
|
997
|
+
const entityExpiry = (_entitiesMeta$key = entitiesMeta[key]) == null || (_entitiesMeta$key = _entitiesMeta$key[pk]) == null ? void 0 : _entitiesMeta$key.expiresAt;
|
|
1005
998
|
// expiresAt will always resolve to false with any comparison
|
|
1006
999
|
if (entityExpiry < expiresAt) expiresAt = entityExpiry;
|
|
1007
1000
|
}
|
|
@@ -1078,7 +1071,6 @@ class ResetError extends Error {
|
|
|
1078
1071
|
super('Aborted due to RESET');
|
|
1079
1072
|
}
|
|
1080
1073
|
}
|
|
1081
|
-
|
|
1082
1074
|
/** Handles all async network dispatches
|
|
1083
1075
|
*
|
|
1084
1076
|
* Dedupes concurrent requests by keeping track of all fetches in flight
|
|
@@ -1089,10 +1081,7 @@ class ResetError extends Error {
|
|
|
1089
1081
|
* @see https://dataclient.io/docs/api/NetworkManager
|
|
1090
1082
|
*/
|
|
1091
1083
|
class NetworkManager {
|
|
1092
|
-
|
|
1093
|
-
resolvers = {};
|
|
1094
|
-
rejectors = {};
|
|
1095
|
-
fetchedAt = {};
|
|
1084
|
+
fetching = new Map();
|
|
1096
1085
|
controller = new Controller();
|
|
1097
1086
|
constructor({
|
|
1098
1087
|
dataExpiryLength = 60000,
|
|
@@ -1117,7 +1106,7 @@ class NetworkManager {
|
|
|
1117
1106
|
case SET_RESPONSE:
|
|
1118
1107
|
// only set after new state is computed
|
|
1119
1108
|
return next(action).then(() => {
|
|
1120
|
-
if (action.key
|
|
1109
|
+
if (this.fetching.has(action.key)) {
|
|
1121
1110
|
var _controller$getState$;
|
|
1122
1111
|
// Note: meta *must* be set by reducer so this should be safe
|
|
1123
1112
|
const error = (_controller$getState$ = controller.getState().meta[action.key]) == null ? void 0 : _controller$getState$.error;
|
|
@@ -1136,15 +1125,17 @@ class NetworkManager {
|
|
|
1136
1125
|
});
|
|
1137
1126
|
case RESET:
|
|
1138
1127
|
{
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1128
|
+
// take snapshot of rejectors at this point in time
|
|
1129
|
+
// we must use Array.from since iteration does not freeze state at this point in time
|
|
1130
|
+
const fetches = Array.from(this.fetching.values());
|
|
1142
1131
|
this.clearAll();
|
|
1143
1132
|
return next(action).then(() => {
|
|
1144
1133
|
// there could be external listeners to the promise
|
|
1145
1134
|
// this must happen after commit so our own rejector knows not to dispatch an error based on this
|
|
1146
|
-
for (const
|
|
1147
|
-
|
|
1135
|
+
for (const {
|
|
1136
|
+
reject
|
|
1137
|
+
} of fetches) {
|
|
1138
|
+
reject(new ResetError());
|
|
1148
1139
|
}
|
|
1149
1140
|
});
|
|
1150
1141
|
}
|
|
@@ -1169,27 +1160,27 @@ class NetworkManager {
|
|
|
1169
1160
|
/** Used by DevtoolsManager to determine whether to log an action */
|
|
1170
1161
|
skipLogging(action) {
|
|
1171
1162
|
/* istanbul ignore next */
|
|
1172
|
-
return action.type === FETCH && action.key
|
|
1163
|
+
return action.type === FETCH && this.fetching.has(action.key);
|
|
1173
1164
|
}
|
|
1174
1165
|
allSettled() {
|
|
1175
|
-
|
|
1176
|
-
|
|
1166
|
+
if (this.fetching.size) return Promise.allSettled(this.fetching.values().map(({
|
|
1167
|
+
promise
|
|
1168
|
+
}) => promise));
|
|
1177
1169
|
}
|
|
1178
1170
|
|
|
1179
1171
|
/** Clear all promise state */
|
|
1180
1172
|
clearAll() {
|
|
1181
|
-
for (const k
|
|
1173
|
+
for (const k of this.fetching.keys()) {
|
|
1182
1174
|
this.clear(k);
|
|
1183
1175
|
}
|
|
1184
1176
|
}
|
|
1185
1177
|
|
|
1186
1178
|
/** Clear promise state for a given key */
|
|
1187
1179
|
clear(key) {
|
|
1188
|
-
this.
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
delete this.fetchedAt[key];
|
|
1180
|
+
if (this.fetching.has(key)) {
|
|
1181
|
+
this.fetching.get(key).promise.catch(() => {});
|
|
1182
|
+
this.fetching.delete(key);
|
|
1183
|
+
}
|
|
1193
1184
|
}
|
|
1194
1185
|
getLastReset() {
|
|
1195
1186
|
if (this.cleanupDate) return this.cleanupDate;
|
|
@@ -1272,14 +1263,17 @@ class NetworkManager {
|
|
|
1272
1263
|
*/
|
|
1273
1264
|
handleSet(action) {
|
|
1274
1265
|
// this can still turn out to be untrue since this is async
|
|
1275
|
-
if (action.key
|
|
1276
|
-
|
|
1266
|
+
if (this.fetching.has(action.key)) {
|
|
1267
|
+
const {
|
|
1268
|
+
reject,
|
|
1269
|
+
resolve
|
|
1270
|
+
} = this.fetching.get(action.key);
|
|
1277
1271
|
if (action.error) {
|
|
1278
|
-
|
|
1272
|
+
reject(action.response);
|
|
1279
1273
|
} else {
|
|
1280
|
-
|
|
1274
|
+
resolve(action.response);
|
|
1281
1275
|
}
|
|
1282
|
-
|
|
1276
|
+
|
|
1283
1277
|
// since we're resolved we no longer need to keep track of this promise
|
|
1284
1278
|
this.clear(action.key);
|
|
1285
1279
|
}
|
|
@@ -1297,16 +1291,15 @@ class NetworkManager {
|
|
|
1297
1291
|
*/
|
|
1298
1292
|
throttle(key, fetch, fetchedAt) {
|
|
1299
1293
|
const lastReset = this.getLastReset();
|
|
1294
|
+
let fetchMeta = this.fetching.get(key);
|
|
1295
|
+
|
|
1300
1296
|
// we're already fetching so reuse the promise
|
|
1301
1297
|
// fetches after reset do not count
|
|
1302
|
-
if (
|
|
1303
|
-
return
|
|
1298
|
+
if (fetchMeta && fetchMeta.fetchedAt > lastReset) {
|
|
1299
|
+
return fetchMeta.promise;
|
|
1304
1300
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
this.rejectors[key] = reject;
|
|
1308
|
-
});
|
|
1309
|
-
this.fetchedAt[key] = fetchedAt;
|
|
1301
|
+
fetchMeta = newFetchMeta(fetchedAt);
|
|
1302
|
+
this.fetching.set(key, fetchMeta);
|
|
1310
1303
|
this.idleCallback(() => {
|
|
1311
1304
|
// since our real promise is resolved via the wrapReducer(),
|
|
1312
1305
|
// we should just stop all errors here.
|
|
@@ -1315,7 +1308,7 @@ class NetworkManager {
|
|
|
1315
1308
|
}, {
|
|
1316
1309
|
timeout: 500
|
|
1317
1310
|
});
|
|
1318
|
-
return
|
|
1311
|
+
return fetchMeta.promise;
|
|
1319
1312
|
}
|
|
1320
1313
|
|
|
1321
1314
|
/** Calls the callback when client is not 'busy' with high priority interaction tasks
|
|
@@ -1326,6 +1319,16 @@ class NetworkManager {
|
|
|
1326
1319
|
callback();
|
|
1327
1320
|
}
|
|
1328
1321
|
}
|
|
1322
|
+
function newFetchMeta(fetchedAt) {
|
|
1323
|
+
const fetchMeta = {
|
|
1324
|
+
fetchedAt
|
|
1325
|
+
};
|
|
1326
|
+
fetchMeta.promise = new Promise((resolve, reject) => {
|
|
1327
|
+
fetchMeta.resolve = resolve;
|
|
1328
|
+
fetchMeta.reject = reject;
|
|
1329
|
+
});
|
|
1330
|
+
return fetchMeta;
|
|
1331
|
+
}
|
|
1329
1332
|
|
|
1330
1333
|
function applyManager(managers, controller) {
|
|
1331
1334
|
/* istanbul ignore next */
|
package/dist/index.umd.min.js
CHANGED
|
@@ -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";const t=Symbol("INVALID");function n(e){return!("function"!=typeof e.hasOwnProperty||!(Object.hasOwnProperty.call(e,"__ownerID")||e._map&&Object.hasOwnProperty.call(e._map,"__ownerID")))}function s(e){return n(e)?({key:t,pk:n})=>e.getIn([t,n]):({key:t,pk:n})=>{var s;return null==(s=e[t])?void 0:s[n]}}class i{constructor(){this.localCache=new Map}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:[]}}}const r={};function o(e){return null!==e&&void 0!==e.pk}const a=e=>e[0],c=e=>void 0!==e&&"symbol"!=typeof e,l=(e,t,n,s,i,r,o,c,l)=>{e=a(e);const h=(e=>Array.isArray(e)?e:Object.keys(e).map((t=>e[t])))(t);return h.map(((t,o)=>r(e,t,n,s,i)))},h=(e,t,n,s)=>(e=a(e),t.map?t.map((t=>s(e,t))).filter(c):t);function u(e,t,n,s,i){}function d(){return d=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},d.apply(null,arguments)}const p=(e,t,n,s,i,r,o,a,c)=>{const l=d({},t);return Object.keys(e).forEach((n=>{const s=e[n],o=r(s,t[n],t,n,i);void 0===o?delete l[n]:l[n]=o})),l},f=(e,s,i,r)=>{if(n(s))return function(e,n,s,i){let r=!1;const o=Object.keys(e).reduce(((t,n)=>{const s=`${n}`,o=i(e[s],t.get(s));return"symbol"==typeof o&&(r=!0),t.has(s)?t.set(s,o):t}),n);return r?t:o}(e,s,0,r);const o=d({},s);let a=!1;return Object.keys(e).forEach((t=>{const n=r(e[t],o[t]);void 0!==o[t]&&(o[t]=n),"symbol"==typeof n&&(a=!0)})),a?t:o};function y(e,t,n,s,i){const r={};for(const o of Object.keys(e))r[o]=n(e[o],t,s,i);return r}function g(e,t,s,i,o,a){const c="object"==typeof t?t:o({key:e.key,pk:t});if("symbol"==typeof c&&"function"==typeof e.denormalize)return e.denormalize(c,s,i);if(void 0===c&&"object"!=typeof t&&""!==t&&"undefined"!==t)return a.getEntity(t,e,r,(e=>{e.set(t,void 0)}));if("object"!=typeof c||null===c)return c;let l="object"!=typeof t?t:e.pk(n(c)?c.toJS():c,void 0,void 0,s);return void 0===l||""===l||"undefined"===l?function(e){const t=new Map;return e(t),t.get("")}((t=>m(c,e,i,"",t,s))):("string"!=typeof l&&(l=`${l}`),a.getEntity(l,e,c,(t=>m(c,e,i,l,t,s))))}function m(e,s,i,r,o,a){const c=n(e)?s.createIfValid(e.toObject()):s.createIfValid(e);o.set(r,c),void 0===c?o.set(r,t):"function"==typeof s.denormalize&&o.set(r,s.denormalize(c,a,i))}const v=(e,t,n)=>{function s(i,r){if(!i)return r;if(null==r)return r;if("function"==typeof i.denormalize)return o(i)?g(i,r,n,s,e,t):i.denormalize(r,n,s);if("function"==typeof i)return i(r);if("object"==typeof i){return(Array.isArray(i)?h:f)(i,r,n,s)}return r}return(e,n)=>{const i=Object(n)===n&&Object(e)===e;return t.getResults(n,i,(()=>s(e,n)))}};class E{constructor(){this.next=new WeakMap,this.nextPath=void 0}get(e,t){let n=this.next.get(e);if(!n)return b;for(;n.nextPath;){var s;const e=null!=(s=t(n.nextPath))?s:r;if(n=n.next.get(e),!n)return b}return[n.value,n.journey]}set(e,t){if(e.length<1)throw new w;let n=this;for(const{entity:t,path:s}of e){let e=n.next.get(t);e||(e=new k,n.next.set(null!=t?t:r,e)),n.nextPath=s,n=e}n.nextPath=void 0,n.value=t,n.journey=e.map((e=>e.path))}}const b=[void 0,void 0];class k{constructor(){this.next=new WeakMap,this.value=void 0,this.journey=[],this.nextPath=void 0}}class w extends Error{constructor(...e){super(...e),this.message="Keys must include at least one member"}}const I=(e,n,s,i,r,o)=>(a,c,l)=>{const h=a.key;e.has(h)||(e.set(h,new Map),s[h]=d({},s[h]),r[h]=d({},r[h]));const u=e.get(h),p=u.get(l);if(p)u.set(l,a.merge(p,c));else{const e=s[h][l];let t;e&&(t=r[h][l])?(u.set(l,a.mergeWithStore(t,o,e,c)),r[h][l]=a.mergeMetaWithStore(t,o,e,c)):(u.set(l,c),r[h][l]=o)}a.indexes&&(n.has(h)||(n.set(h,new Map),i[h]=d({},i[h])),function(e,n,s,i,r,o){for(const a of n){s.has(a)||s.set(a,i[a]={});const n=s.get(a);o[e]&&delete n[o[e][a]],o&&o[e]&&o[e][a]!==r[a]&&(n[o[e][a]]=t),a in r&&(n[r[a]]=e)}}(l,a.indexes,n.get(h),i[h],u.get(l),s[h])),s[h][l]=u.get(l)};const x=(e,t)=>{const n=function(){const e=new Map;return function(t,n,s){e.has(t)||e.set(t,new Map);const i=e.get(t);i.has(n)||i.set(n,[]);const r=i.get(n);return!!r.some((e=>e===s))||(r.push(s),!1)}}(),s=(i,r,o,a,c)=>{if(!r||!i)return r;if(i.normalize&&"function"==typeof i.normalize)return"object"!=typeof r?i.pk?`${r}`:r:i.normalize(r,o,a,c,s,e,t,n);if("object"!=typeof r||"object"!=typeof i)return r;return(Array.isArray(i)?l:p)(i,r,o,a,c,s)};return s};class A{constructor(e,t,n){this.dependencies=[],this.cycleCache=new Map,this.cycleIndex=-1,this.localCache=new Map,this._getEntity=e,this.getCache=S(t),this.resultCache=n}getEntity(e,t,n,s){const i=t.key,{localCacheKey:r,cycleCacheKey:o}=this.getCacheKey(i);if(r.get(e))o.has(e)?this.cycleIndex=o.get(e):this.dependencies.push({entity:n,path:{key:i,pk:e}});else{const a=this.getCache(e,t),[c,l]=a.get(n,this._getEntity);if(l)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({entity:n,path:{key:i,pk:e}}),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.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[s,i]=this.resultCache.get(e,this._getEntity);return void 0===i?(s=n(),i=this.paths(),this.dependencies.unshift({entity:e,path:{key:"",pk:""}}),this.resultCache.set(this.dependencies,s)):i.shift(),{data:s,paths:i}}paths(){return this.dependencies.map((e=>e.path))}}const S=e=>(t,n)=>{var s;const i=n.key,r=null!=(s=n.cacheWith)?s:n;e.has(i)||e.set(i,new Map);const o=e.get(i);o.get(t)||o.set(t,new WeakMap);const a=o.get(t);let c=a.get(r);return c||(c=new E,a.set(r,c)),c};function L(e,t,n,s){if(function(e){return!!e&&"function"==typeof e.queryKey}(e))return e.queryKey(t,L,n,s);if("object"==typeof e&&e){return(Array.isArray(e)?u:y)(e,t,L,n,s)}return e}function C(e){return void 0!==e&&(!(e&&"object"==typeof e&&!Array.isArray(e))||Object.values(e).every(C))}class M{constructor(){this.entities=new Map,this.endpoints=new E,this.queryKeys=new Map}denormalize(e,t,n,i=[]){if(void 0===e)return{data:t,paths:[]};if(void 0===t)return{data:void 0,paths:[]};const r=s(n);return v(r,new A(r,this.entities,this.endpoints),i)(e,t)}query(e,t,n,s,i=JSON.stringify(t)){const r=this.buildQueryKey(e,t,n,s,i);if(!r)return;const{data:o}=this.denormalize(e,r,n,t);return"symbol"==typeof o?void 0:o}buildQueryKey(e,t,s,i,r=JSON.stringify(t)){if("object"!=typeof e&&"function"!=typeof e.queryKey||!e)return e;this.queryKeys.get(r)||this.queryKeys.set(r,new E);const o=this.queryKeys.get(r),a=R(s),c=function(e){const t=n(e);return t?(t,n,s)=>{var i;return null==(i=e.getIn([t,n]))||null==i.toJS?void 0:i.toJS()}:(t,n,s)=>e[t]?e[t][n]:{}}(i);let[l,h]=o.get(e,function(e,t){return n=>3===n.length?t(...n):e(...n)}(a,c));if(!h){const n=[{path:[""],entity:e}];l=L(e,t,O(a,n),O(c,n)),o.set(n,l)}return l}}function O(e,t){return(...n)=>{const s=e(...n);return t.push({path:n,entity:s}),s}}function R(e){return n(e)?(...t)=>{var n;return null==(n=e.getIn(t))||null==n.toJS?void 0:n.toJS()}:(t,n)=>{var s;return n?null==(s=e[t])?void 0:s[n]:e[t]}}const _=(e,t,n=[],{entities:s,indexes:i,entityMeta:r}=j,o={fetchedAt:0,date:Date.now(),expiresAt:1/0})=>{if(null==e)return{result:t,entities:s,indexes:i,entityMeta:r};const a=function(e){return["object","function"].includes(typeof e)?"object":typeof e}(e);if(null===t||typeof t!==a&&(void 0===e.key||void 0!==e.pk||"string"!=typeof t))throw new Error(`Unexpected input given to normalize. Expected type to be "${a}", found "${null===t?"null":typeof t}".`);const c=new Map,l=new Map,h={result:"",entities:d({},s),indexes:d({},i),entityMeta:d({},r)},u=I(c,l,h.entities,h.indexes,h.entityMeta,o),p=x(u,R(s));return h.result=p(e,t,t,void 0,n),h};const j={entities:{},indexes:{},entityMeta:{}};var P={Invalid:1,InvalidIfStale:2,Valid:3};function T(e,t){const n=Date.now();return{fetchedAt:null!=t?t:n,date:n,expiresAt:n+e}}const q="rdc/fetch",D="rdc/set",K="rdc/setresponse",N="rdc/optimistic",z="rdc/reset",H="rdc/subscribe",Q="rdc/unsubscribe",F="rdc/invalidate",V="rdc/invalidateall",B="rdc/expireall",U="rdc/gc",Y=q,J=D,$=K,W=N,X=z,G=H,Z=Q,ee=F,te=V,ne=B,se=U;var ie=Object.freeze({__proto__:null,EXPIREALL:B,EXPIREALL_TYPE:ne,FETCH:q,FETCH_TYPE:Y,GC:U,GC_TYPE:se,INVALIDATE:F,INVALIDATEALL:V,INVALIDATEALL_TYPE:te,INVALIDATE_TYPE:ee,OPTIMISTIC:N,OPTIMISTIC_TYPE:W,RESET:z,RESET_TYPE:X,SET:D,SET_RESPONSE:K,SET_RESPONSE_TYPE:$,SET_TYPE:J,SUBSCRIBE:H,SUBSCRIBE_TYPE:G,UNSUBSCRIBE:Q,UNSUBSCRIBE_TYPE:Z});function re(e,t,n){var s;return{type:N,key:e.key(...t),args:t,endpoint:e,meta:T(null!=(s=e.dataExpiryLength)?s:6e4,n)}}class oe extends Error{}function ae(e,t,n){return"AbortError"===n.name?d({},e,{optimistic:ce(e,t)}):d({},e,{meta:d({},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:ce(e,t)})}function ce(e,t){return e.optimistic.filter((e=>e.key!==t.key||(e.type===N?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}const le={entities:{},endpoints:{},indexes:{},meta:{},entityMeta:{},optimistic:[],lastReset:0};var he=Object.freeze({__proto__:null,INVALID:t,MemoCache:M,initialState:le});function ue(e,{args:t}){return{type:H,key:e.key(...t),args:t,endpoint:e}}function de(e,{args:t}){return{type:Q,key:e.key(...t),args:t,endpoint:e}}const pe="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function fe(e,{args:t,fetchedAt:n,response:s,error:i=!1}){var r,o;const a=i?null!=(r=e.errorExpiryLength)?r:1e3:null!=(o=e.dataExpiryLength)?o:6e4;return{type:K,key:e.key(...t),response:s,args:t.map(pe),endpoint:e,meta:T(a,n),error:i}}function ye(e,{args:t,fetchedAt:n,value:s}){return{type:D,value:s,args:t.map(pe),schema:e,meta:T(6e4,n)}}function ge(){return{type:z,date:Date.now()}}function me(e){return{type:V,testKey:e}}function ve(e,{args:t}){return{type:F,key:e.key(...t)}}function Ee(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:q,key:e.key(...t),args:t,endpoint:e,meta:r}}function be(e){return{type:B,testKey:e}}var ke=Object.freeze({__proto__:null,createExpireAll:be,createFetch:Ee,createInvalidate:ve,createInvalidateAll:me,createMeta:T,createOptimistic:re,createReset:ge,createSet:ye,createSetResponse:fe,createSubscription:ue,createUnsubscription:de});class we{init(){}cleanup(){}createCountRef(){return()=>()=>{}}}function Ie(e,t){return e.meta[t]}const xe=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},Ae=()=>le;class Se{constructor({dispatch:e=xe,getState:t=Ae,memo:n=new M,gcPolicy:r=new we}={}){this.fetch=(e,...t)=>{const n=Ee(e,{args:t});return this.dispatch(n),e.schema?n.meta.promise.then((n=>function(e,t,n,r=[]){return void 0===e||void 0===t?t:v(s(n),new i,r)(e,t).data}(e.schema,n,{},t))):n.meta.promise},this.fetchIfStale=(e,...t)=>{const{data:n,expiresAt:s,expiryStatus:i}=this.getResponse(e,...t,this.getState());return i!==P.Invalid&&Date.now()<=s?n:this.fetch(e,...t)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(ve(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch(me((t=>e.testKey(t)))),this.expireAll=e=>this.dispatch(be((t=>e.testKey(t)))),this.resetEntireStore=()=>this.dispatch(ge()),this.setResponse=(e,...t)=>{const n=t[t.length-1],s=fe(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=fe(e,{args:t.slice(0,t.length-1),response:n,error:!0});return this.dispatch(s)},this.resolve=(e,t)=>this.dispatch(fe(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(ue(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(de(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new Ce(this,e,t),this._dispatch=e,this.getState=t,this.memo=n,this.gcPolicy=r}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=ye(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=Ie(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=t[t.length-1],s=t.slice(0,t.length-1).map(pe),i=1!==s.length||null!==s[0],r=i?e.key(...s):"",o=i?n.endpoints[r]:void 0,a=e.schema,c=Ie(n,r);let l=null==c?void 0:c.expiresAt;const h=void 0===o&&void 0!==a,u=h?this.memo.buildQueryKey(a,s,n.entities,n.indexes,r):o;if(!i)return{data:u,expiryStatus:P.Valid,expiresAt:1/0,countRef:()=>()=>{}};let d=!1;if(h)d=!C(u);else if(!a||!Le(a))return{data:o,expiryStatus:null!=c&&c.invalidated?P.Invalid:o&&!e.invalidIfStale?P.Valid:P.InvalidIfStale,expiresAt:l||0,countRef:this.gcPolicy.createCountRef({key:r})};const{data:p,paths:f}=this.memo.denormalize(a,u,n.entities,s);return!l&&d&&(l=1),this.getSchemaResponse(p,r,f,n.entityMeta,l,e.invalidIfStale||d,c)}get(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(pe);return this.memo.query(e,s,n.entities,n.indexes)}getQueryMeta(e,...t){const n=t[t.length-1],s=t.slice(0,t.length-1).map(pe),i=this.memo.buildQueryKey(e,s,n.entities,n.indexes,JSON.stringify(s));if(!i)return{data:void 0,countRef:()=>()=>{}};const{data:r,paths:o}=this.memo.denormalize(e,i,n.entities,s);return{data:"symbol"==typeof r?void 0:r,countRef:this.gcPolicy.createCountRef({paths:o})}}getSchemaResponse(e,t,n,s,i,r,o={}){const a="symbol"==typeof e;i||(i=function(e,t){let n=1/0;for(const{pk:i,key:r}of e){var s;const e=null==(s=t[r])||null==(s=s[i])?void 0:s.expiresAt;e<n&&(n=e)}return n}(n,s));return{data:e,expiryStatus:null!=o&&o.invalidated||a&&(null==o||!o.error)?P.Invalid:a||r?P.InvalidIfStale:P.Valid,expiresAt:i,countRef:this.gcPolicy.createCountRef({key:t,paths:n})}}}function Le(e){if(o(e))return!0;if(Array.isArray(e))return 0!==e.length&&Le(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?Le(t):Object.values(t).some((e=>Le(e)))}return!1}class Ce{constructor(e,t,n=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.abort=Ce.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)}}Ce.abort=new oe;class Me extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class Oe{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 Re{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}let _e;_e="undefined"!=typeof navigator&&"function"==typeof addEventListener?Oe:Re;var je=_e;let Pe={};class Te{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(d({},Pe,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(){}}Te.prototype.middleware=()=>e=>t=>e(t);e.Controller=Se,e.DefaultConnectionListener=je,e.DevToolsManager=Te,e.ExpiryStatus=P,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;this.entityCount.has(e.key)||this.entityCount.set(e.key,new Map);const n=this.entityCount.get(e.key);n.set(e.pk,(null!=(t=n.get(e.pk))?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=>{if(!this.entityCount.has(e.key))return;const t=this.entityCount.get(e.key),n=t.get(e.pk);void 0!==n&&(n<=1?(t.delete(e.pk),this.entitiesQ.push(e)):t.set(e.pk,n-1))}))}}}expiresAt({fetchedAt:e,expiresAt:t}){return Math.max((t-e)*this.options.expiryMultiplier,12e4)+e}runSweep(){const e=this.controller.getState(),t=[],n=[],s=Date.now(),i=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})<s?n.push(t):i.add(t)}this.endpointsQ=i;const o=[];for(const n of this.entitiesQ){var a,c,l;(null==(a=this.entityCount.get(n.key))||!a.has(n.pk))&&this.expiresAt(null!=(c=null==(l=e.entityMeta[n.key])?void 0:l[n.pk])?c:{fetchedAt:0,date:0,expiresAt:0})<s?t.push(n):o.push(n)}this.entitiesQ=o,(t.length||n.length)&&this.controller.dispatch({type:U,entities:t,endpoints:n})}idleCallback(e,t){"function"==typeof requestIdleCallback?requestIdleCallback(e,t):e()}},e.ImmortalGCPolicy=we,e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){this.middleware=e=>t=>async n=>{await t(n),n.type===K&&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.fetched=Object.create(null),this.resolvers={},this.rejectors={},this.fetchedAt={},this.controller=new Se,this.middleware=e=>(this.controller=e,t=>n=>{switch(n.type){case q:return this.handleFetch(n),void 0!==n.endpoint.getOptimisticResponse&&n.endpoint.sideEffect?t(n):Promise.resolve();case K:return t(n).then((()=>{if(n.key in this.fetched){var t;const s=null==(t=e.getState().meta[n.key])?void 0:t.error;s?this.handleSet(fe(n.endpoint,{args:n.args,response:s,fetchedAt:n.meta.fetchedAt,error:!0})):this.handleSet(n)}}));case z:{const e=d({},this.rejectors);return this.clearAll(),t(n).then((()=>{for(const t in e)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===q&&e.key in this.fetched}allSettled(){const e=Object.values(this.fetched);if(e.length)return Promise.allSettled(e)}clearAll(){for(const e in this.rejectors)this.clear(e)}clear(e){this.fetched[e].catch((()=>{})),delete this.resolvers[e],delete this.rejectors[e],delete this.fetched[e],delete this.fetchedAt[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(e.key in this.fetched){let t;t=e.error?this.rejectors[e.key]:this.resolvers[e.key],t(e.response),this.clear(e.key)}}throttle(e,t,n){const s=this.getLastReset();return e in this.fetched&&this.fetchedAt[e]>s||(this.fetched[e]=new Promise(((t,n)=>{this.resolvers[e]=t,this.rejectors[e]=n})),this.fetchedAt[e]=n,this.idleCallback((()=>{t().catch((()=>null))}),{timeout:500})),this.fetched[e]}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 je,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=Me,e.SubscriptionManager=class{constructor(e){this.subscriptions={},this.controller=new Se,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case H:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case Q: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__=he,e.actionTypes=ie,e.actions=ke,e.applyManager=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)))))},e.createReducer=function(e){return function(t,n){switch(t||(t=le),n.type){case U:return n.entities.forEach((({key:e,pk:n})=>{var s,i;null==(s=t.entities[e])||delete s[n],null==(i=t.entityMeta[e])||delete i[n]})),n.endpoints.forEach((e=>{delete t.endpoints[e],delete t.meta[e]})),t;case q:return function(e,t){if(t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect){const n=re(t.endpoint,t.args,t.meta.fetchedAt);return d({},e,{optimistic:[...e.optimistic,n]})}return e}(t,n);case N:case K:return function(e,t,n){if(t.error)return ae(e,t,t.response);try{var s;let i;if(t.type===N){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===oe)return e;throw t}}else i=t.response;const{result:r,entities:o,indexes:a,entityMeta:c}=_(t.endpoint.schema,i,t.args,e,t.meta),l=d({},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(`The following error occured during Endpoint.update() for ${t.key}`),console.error(e)}return{entities:o,endpoints:l,indexes:a,meta:d({},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}}),entityMeta:c,optimistic:ce(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),ae(e,t,n)}}(t,n,e);case D: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,entityMeta:r}=_(t.schema,s,t.args,e,t.meta);return{entities:n,endpoints:e.endpoints,indexes:i,meta:e.meta,entityMeta:r,optimistic:e.optimistic,lastReset:e.lastReset}}catch(t){return e}}(t,n,e);case V:case F:return function(e,t){const n=d({},e.endpoints),s=d({},e.meta),i=e=>{delete n[e];const t=d({},s[e],{expiresAt:0,invalidated:!0});delete t.error,s[e]=t};return t.type===F?i(t.key):Object.keys(n).forEach((e=>{t.testKey(e)&&i(e)})),d({},e,{endpoints:n,meta:s})}(t,n);case B:return function(e,t){const n=d({},e.meta);return Object.keys(n).forEach((e=>{t.testKey(e)&&(n[e]=d({},n[e],{expiresAt:1}))})),d({},e,{meta:n})}(t,n);case z:return d({},le,{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=le}));
|
|
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){e.has(t)||e.set(t,new Map);const s=e.get(t);s.has(n)||s.set(n,[]);const r=s.get(n);return!!r.some((e=>e===i))||(r.push(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}));
|