@data-client/core 0.4.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data_client_logo_and_text.svg +50 -0
- package/dist/index.js +66 -92
- package/dist/index.umd.min.js +1 -1
- package/dist/next.js +0 -447
- package/legacy/actionTypes.js +11 -13
- package/legacy/actions.js +2 -0
- package/legacy/controller/Controller.js +26 -42
- package/legacy/controller/createSet.js +3 -2
- package/legacy/controller/ensurePojo.js +7 -0
- package/legacy/index.js +2 -2
- package/legacy/internal.js +2 -2
- package/legacy/manager/DevtoolsManager.js +3 -3
- package/legacy/manager/NetworkManager.js +11 -11
- package/legacy/manager/SubscriptionManager.js +6 -6
- package/legacy/manager/applyManager.js +2 -9
- package/legacy/middlewareTypes.js +1 -1
- package/legacy/next/index.js +2 -3
- package/legacy/state/reducer/fetchReducer.js +5 -5
- package/legacy/state/reducer/setReducer.js +2 -2
- package/legacy/types.js +3 -4
- package/lib/actionTypes.d.ts +10 -12
- package/lib/actionTypes.d.ts.map +1 -1
- package/lib/actionTypes.js +11 -13
- package/lib/{newActions.d.ts → actions.d.ts} +1 -3
- package/lib/actions.d.ts.map +1 -0
- package/lib/actions.js +2 -0
- package/lib/controller/Controller.d.ts +20 -33
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +26 -42
- package/lib/controller/createSet.d.ts.map +1 -1
- package/lib/controller/createSet.js +3 -2
- package/lib/controller/ensurePojo.d.ts +3 -0
- package/lib/controller/ensurePojo.d.ts.map +1 -0
- package/lib/controller/ensurePojo.js +7 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/internal.d.ts +1 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +2 -2
- package/lib/manager/DevtoolsManager.js +3 -3
- package/lib/manager/NetworkManager.d.ts +6 -6
- package/lib/manager/NetworkManager.d.ts.map +1 -1
- package/lib/manager/NetworkManager.js +11 -11
- package/lib/manager/SubscriptionManager.d.ts +5 -5
- package/lib/manager/SubscriptionManager.js +6 -6
- package/lib/manager/applyManager.d.ts.map +1 -1
- package/lib/manager/applyManager.js +2 -9
- package/lib/middlewareTypes.d.ts +2 -5
- package/lib/middlewareTypes.d.ts.map +1 -1
- package/lib/middlewareTypes.js +1 -1
- package/lib/next/index.d.ts +0 -2
- package/lib/next/index.d.ts.map +1 -1
- package/lib/next/index.js +2 -3
- package/lib/state/reducer/expireReducer.d.ts +1 -1
- package/lib/state/reducer/fetchReducer.js +5 -5
- package/lib/state/reducer/invalidateReducer.d.ts +1 -1
- package/lib/state/reducer/setReducer.d.ts +2 -2
- package/lib/state/reducer/setReducer.d.ts.map +1 -1
- package/lib/state/reducer/setReducer.js +2 -2
- package/lib/types.d.ts +3 -4
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +3 -4
- package/package.json +3 -3
- package/src/actionTypes.ts +10 -12
- package/src/{newActions.ts → actions.ts} +1 -6
- package/src/controller/Controller.ts +27 -55
- package/src/controller/createSet.ts +2 -1
- package/src/controller/ensurePojo.ts +11 -0
- package/src/index.ts +1 -1
- package/src/internal.ts +1 -1
- package/src/manager/DevtoolsManager.ts +2 -2
- package/src/manager/NetworkManager.ts +10 -10
- package/src/manager/SubscriptionManager.ts +5 -5
- package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +2 -2
- package/src/manager/__tests__/logoutManager.ts +2 -2
- package/src/manager/__tests__/manager.ts +1 -1
- package/src/manager/__tests__/networkManager.ts +13 -16
- package/src/manager/applyManager.ts +1 -6
- package/src/middlewareTypes.ts +4 -9
- package/src/next/index.ts +0 -2
- package/src/state/__tests__/__snapshots__/reducer.ts.snap +1 -1
- package/src/state/__tests__/reducer.ts +27 -9
- package/src/state/reducer/fetchReducer.ts +5 -5
- package/src/state/reducer/setReducer.ts +5 -5
- package/src/types.ts +3 -4
- package/ts3.4/actionTypes.d.ts +10 -12
- package/ts3.4/{newActions.d.ts → actions.d.ts} +1 -3
- package/ts3.4/controller/Controller.d.ts +20 -39
- package/ts3.4/controller/ensurePojo.d.ts +3 -0
- package/ts3.4/index.d.ts +1 -1
- package/ts3.4/internal.d.ts +1 -1
- package/ts3.4/manager/NetworkManager.d.ts +6 -6
- package/ts3.4/manager/SubscriptionManager.d.ts +5 -5
- package/ts3.4/middlewareTypes.d.ts +2 -5
- package/ts3.4/next/index.d.ts +0 -2
- 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 +2 -2
- package/ts3.4/types.d.ts +3 -5
- package/legacy/fsa.js +0 -2
- package/legacy/newActions.js +0 -2
- package/lib/fsa.d.ts +0 -41
- package/lib/fsa.d.ts.map +0 -1
- package/lib/fsa.js +0 -2
- package/lib/newActions.d.ts.map +0 -1
- package/lib/newActions.js +0 -2
- package/src/fsa.ts +0 -99
- package/ts3.4/fsa.d.ts +0 -41
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
3
|
+
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
4
|
+
width="419.02px" height="90px" viewBox="0 0 419.02 90" enable-background="new 0 0 419.02 90" xml:space="preserve">
|
|
5
|
+
<g>
|
|
6
|
+
<g>
|
|
7
|
+
<polygon fill="#00F2E6" points="31.4,58.6 23.1,68.85 31.1,82.85 47.1,85.79 47.1,70.85 35.1,66.85 "/>
|
|
8
|
+
<polygon fill="#00F2E6" points="62.79,58.6 75.1,56.85 82.1,43.85 78.49,31.41 67.1,31.85 66.1,51.85 "/>
|
|
9
|
+
<polygon fill="#00F2E6" points="47.1,31.41 45.1,13.85 22.1,23.85 15.7,31.41 22.1,40.85 38.1,31.85 "/>
|
|
10
|
+
<path fill="#00F2E6" d="M31.4,58.6c0-11.62,6.32-21.76,15.7-27.19c-4.62-2.67-9.98-4.21-15.7-4.21C14.06,27.2,0,41.26,0,58.6
|
|
11
|
+
S14.06,90,31.4,90c5.72,0,11.08-1.54,15.7-4.21C37.72,80.36,31.4,70.22,31.4,58.6z"/>
|
|
12
|
+
<path fill="#633EFF" d="M62.79,58.6c-10.06,5.81-22,5.41-31.39,0c-0.01,5.34,1.34,10.75,4.2,15.7
|
|
13
|
+
c8.67,15.02,27.87,20.16,42.89,11.49S98.65,57.91,89.98,42.9c-2.86-4.95-6.87-8.83-11.5-11.49C78.48,42.25,72.86,52.79,62.79,58.6
|
|
14
|
+
z"/>
|
|
15
|
+
<path fill="#F93AEB" d="M47.09,31.4c10.06,5.81,15.68,16.35,15.7,27.19c4.62-2.66,8.64-6.54,11.5-11.49
|
|
16
|
+
c8.67-15.02,3.53-34.22-11.49-42.89S28.57,0.69,19.9,15.7c-2.86,4.95-4.21,10.36-4.2,15.7C25.09,26,37.03,25.59,47.09,31.4z"/>
|
|
17
|
+
<path d="M167.92,38.77c0,4.8-3.38,8.18-7.95,8.18h-1.75c0.06,0.45,0.4,1.07,0.62,1.52L167.7,65h-4.68l-7.73-14.5
|
|
18
|
+
c-0.68-1.24-1.13-2.37-1.35-3.55h-8.41V65h-4.23V25h18.67c4.57,0,7.95,3.44,7.95,8.24V38.77z M163.69,33.24
|
|
19
|
+
c0-2.6-1.52-4.34-3.61-4.34h-14.56v14.16h14.5c2.14,0,3.67-1.69,3.67-4.29V33.24z"/>
|
|
20
|
+
<path d="M196.86,47.79c0,2.82-1.75,4.51-4.29,4.51h-14.5v4.63c0,2.65,1.52,4.4,3.72,4.4h12.92V65h-12.81
|
|
21
|
+
c-4.46,0-7.79-3.33-7.79-8.07V45.08c0-4.74,3.27-8.07,7.73-8.07h7.17c4.46,0,7.84,3.33,7.84,8.07V47.79z M192.86,45.14
|
|
22
|
+
c0-2.65-1.52-4.46-3.72-4.46h-7.28c-2.2,0-3.78,1.75-3.78,4.4v3.55h14.78V45.14z"/>
|
|
23
|
+
<path d="M222.08,60.15l-0.79,1.52c-1.3,2.54-2.82,3.33-5.36,3.33h-11.9v-3.67h11.51c1.24,0,1.75-0.45,2.31-1.47l0.73-1.35
|
|
24
|
+
c0.34-0.62,0.57-1.35,0.57-2.14l-13.37-7.39c-1.81-1.01-2.71-2.09-2.71-4.06c0-0.9,0.34-1.75,1.07-3.16l0.79-1.52
|
|
25
|
+
c1.3-2.48,2.82-3.22,5.36-3.22h11.57v3.67h-11.17c-1.24,0-1.75,0.28-2.31,1.35l-0.73,1.41c-0.4,0.73-0.56,1.24-0.56,1.98
|
|
26
|
+
l13.26,7.39c1.92,1.07,2.82,2.09,2.82,4.06C223.15,57.78,222.81,58.74,222.08,60.15z"/>
|
|
27
|
+
<path d="M238.67,65c-1.92,0-3.5-0.96-4.57-2.99l-0.73-1.41c-0.51-0.96-0.62-1.69-0.62-3.16V40.68h-5.92v-3.67h5.92v-6.38h3.95
|
|
28
|
+
v6.38h8.91v3.67h-8.91v16.76c0,0.79,0.17,1.41,0.45,1.97l0.45,0.85c0.39,0.68,1.02,1.07,1.8,1.07h6.21V65H238.67z"/>
|
|
29
|
+
<path d="M291.81,65V46.89h-18.84V65h-4.23V25h4.23v18h18.84V25h4.23v40H291.81z"/>
|
|
30
|
+
<path d="M315.16,65c-3.22,0-5.3-1.41-6.77-4.12l-3.1-5.81c-0.73-1.35-1.07-2.59-1.07-4.06c0-1.41,0.4-2.71,1.13-4.06l3.1-5.87
|
|
31
|
+
c1.47-2.82,3.84-4.06,6.83-4.06h4.63c2.99,0,5.36,1.24,6.83,4.06l3.1,5.87c0.73,1.35,1.13,2.65,1.13,4.06
|
|
32
|
+
c0,1.47-0.34,2.71-1.07,4.06l-3.1,5.81c-1.47,2.71-3.55,4.12-6.77,4.12H315.16z M320.01,61.33c1.64,0,2.54-0.73,3.38-2.31
|
|
33
|
+
l3.05-5.87c0.4-0.79,0.56-1.35,0.56-2.14c0-0.73-0.17-1.47-0.56-2.2l-3.1-5.81c-0.79-1.47-1.8-2.31-3.55-2.31h-4.4
|
|
34
|
+
c-1.75,0-2.76,0.85-3.55,2.31l-3.1,5.81c-0.39,0.73-0.56,1.47-0.56,2.2c0,0.79,0.17,1.35,0.56,2.14l3.05,5.87
|
|
35
|
+
c0.85,1.58,1.75,2.31,3.39,2.31H320.01z"/>
|
|
36
|
+
<path d="M346.98,65c-3.22,0-5.3-1.41-6.77-4.12l-3.1-5.81c-0.73-1.35-1.07-2.59-1.07-4.06c0-1.41,0.4-2.71,1.13-4.06l3.1-5.87
|
|
37
|
+
c1.47-2.82,3.84-4.06,6.83-4.06h4.63c2.99,0,5.36,1.24,6.83,4.06l3.1,5.87c0.73,1.35,1.13,2.65,1.13,4.06
|
|
38
|
+
c0,1.47-0.34,2.71-1.07,4.06l-3.1,5.81c-1.47,2.71-3.55,4.12-6.77,4.12H346.98z M351.83,61.33c1.64,0,2.54-0.73,3.38-2.31
|
|
39
|
+
l3.05-5.87c0.4-0.79,0.56-1.35,0.56-2.14c0-0.73-0.17-1.47-0.56-2.2l-3.1-5.81c-0.79-1.47-1.81-2.31-3.55-2.31h-4.4
|
|
40
|
+
c-1.75,0-2.76,0.85-3.55,2.31l-3.1,5.81c-0.39,0.73-0.56,1.47-0.56,2.2c0,0.79,0.17,1.35,0.56,2.14l3.05,5.87
|
|
41
|
+
c0.85,1.58,1.75,2.31,3.39,2.31H351.83z"/>
|
|
42
|
+
<path d="M386.69,48.92c3.22,0.85,5.25,3.67,5.25,7.45V65h-3.95v-8.63c0-2.48-1.3-4.06-3.5-4.06h-10.16V65h-3.95V25h3.95v23.64
|
|
43
|
+
h8.12l6.26-11.62h4.29L386.69,48.92z"/>
|
|
44
|
+
<path d="M417.95,60.15l-0.79,1.52c-1.3,2.54-2.82,3.33-5.36,3.33h-11.9v-3.67h11.51c1.24,0,1.75-0.45,2.31-1.47l0.73-1.35
|
|
45
|
+
c0.34-0.62,0.56-1.35,0.56-2.14l-13.37-7.39c-1.81-1.01-2.71-2.09-2.71-4.06c0-0.9,0.34-1.75,1.07-3.16l0.79-1.52
|
|
46
|
+
c1.3-2.48,2.82-3.22,5.36-3.22h11.57v3.67h-11.17c-1.24,0-1.75,0.28-2.31,1.35l-0.73,1.41c-0.4,0.73-0.56,1.24-0.56,1.98
|
|
47
|
+
l13.26,7.39c1.92,1.07,2.82,2.09,2.82,4.06C419.02,57.78,418.68,58.74,417.95,60.15z"/>
|
|
48
|
+
</g>
|
|
49
|
+
</g>
|
|
50
|
+
</svg>
|
package/dist/index.js
CHANGED
|
@@ -26,23 +26,20 @@ function expireReducer(state, action) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const FETCH_TYPE = '
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const EXPIREALL_TYPE = 'rest-hooks/expireall';
|
|
40
|
-
const GC_TYPE = 'rest-hooks/gc';
|
|
29
|
+
const FETCH_TYPE = 'rdc/fetch';
|
|
30
|
+
const SET_TYPE = 'rdc/set';
|
|
31
|
+
const OPTIMISTIC_TYPE = 'rdc/optimistic';
|
|
32
|
+
const RESET_TYPE = 'rdc/reset';
|
|
33
|
+
const SUBSCRIBE_TYPE = 'rdc/subscribe';
|
|
34
|
+
const UNSUBSCRIBE_TYPE = 'rdc/unsubscribe';
|
|
35
|
+
const INVALIDATE_TYPE = 'rdc/invalidate';
|
|
36
|
+
const INVALIDATEALL_TYPE = 'rdc/invalidateall';
|
|
37
|
+
const EXPIREALL_TYPE = 'rdc/expireall';
|
|
38
|
+
const GC_TYPE = 'rdc/gc';
|
|
41
39
|
|
|
42
40
|
var actionTypes = /*#__PURE__*/Object.freeze({
|
|
43
41
|
__proto__: null,
|
|
44
42
|
FETCH_TYPE: FETCH_TYPE,
|
|
45
|
-
RECEIVE_TYPE: RECEIVE_TYPE,
|
|
46
43
|
SET_TYPE: SET_TYPE,
|
|
47
44
|
OPTIMISTIC_TYPE: OPTIMISTIC_TYPE,
|
|
48
45
|
RESET_TYPE: RESET_TYPE,
|
|
@@ -81,9 +78,9 @@ function createOptimistic(endpoint, {
|
|
|
81
78
|
}
|
|
82
79
|
|
|
83
80
|
function fetchReducer(state, action) {
|
|
84
|
-
let
|
|
81
|
+
let setAction;
|
|
85
82
|
if (action.endpoint.getOptimisticResponse && action.endpoint.sideEffect) {
|
|
86
|
-
|
|
83
|
+
setAction = createOptimistic(action.endpoint, {
|
|
87
84
|
args: action.meta.args,
|
|
88
85
|
fetchedAt: action.meta.createdAt
|
|
89
86
|
});
|
|
@@ -92,13 +89,13 @@ function fetchReducer(state, action) {
|
|
|
92
89
|
/* istanbul ignore next */
|
|
93
90
|
if (process.env.NODE_ENV !== 'production') {
|
|
94
91
|
console.warn('Fetch appears unhandled - you are likely missing the NetworkManager middleware');
|
|
95
|
-
console.warn('See https://
|
|
92
|
+
console.warn('See https://dataclient.io/docs/guides/redux#indextsx for hooking up redux');
|
|
96
93
|
}
|
|
97
94
|
return state;
|
|
98
95
|
}
|
|
99
96
|
return {
|
|
100
97
|
...state,
|
|
101
|
-
optimistic: [...state.optimistic,
|
|
98
|
+
optimistic: [...state.optimistic, setAction]
|
|
102
99
|
};
|
|
103
100
|
}
|
|
104
101
|
|
|
@@ -142,7 +139,7 @@ function setReducer(state, action, controller) {
|
|
|
142
139
|
try {
|
|
143
140
|
var _state$meta$action$me;
|
|
144
141
|
let payload;
|
|
145
|
-
// for true
|
|
142
|
+
// for true set's payload is contained in action
|
|
146
143
|
if (action.type === OPTIMISTIC_TYPE) {
|
|
147
144
|
// this should never happen
|
|
148
145
|
if (!action.endpoint.getOptimisticResponse) return state;
|
|
@@ -296,7 +293,6 @@ const initialState = {
|
|
|
296
293
|
var internal = /*#__PURE__*/Object.freeze({
|
|
297
294
|
__proto__: null,
|
|
298
295
|
inferResults: normalizr.inferResults,
|
|
299
|
-
DELETED: normalizr.DELETED,
|
|
300
296
|
INVALID: normalizr.INVALID,
|
|
301
297
|
RIC: RIC$1,
|
|
302
298
|
initialState: initialState
|
|
@@ -364,6 +360,13 @@ function createReset() {
|
|
|
364
360
|
};
|
|
365
361
|
}
|
|
366
362
|
|
|
363
|
+
const ensurePojo =
|
|
364
|
+
// FormData doesn't exist in node
|
|
365
|
+
/* istanbul ignore else we don't run coverage when we test node*/
|
|
366
|
+
typeof FormData !== 'undefined' ? body => body instanceof FormData ? Object.fromEntries(body.entries()) : body : /* istanbul ignore next */
|
|
367
|
+
body => body;
|
|
368
|
+
var ensurePojo$1 = ensurePojo;
|
|
369
|
+
|
|
367
370
|
function createSet(endpoint, {
|
|
368
371
|
args,
|
|
369
372
|
fetchedAt,
|
|
@@ -378,7 +381,7 @@ function createSet(endpoint, {
|
|
|
378
381
|
}
|
|
379
382
|
const now = Date.now();
|
|
380
383
|
const meta = {
|
|
381
|
-
args,
|
|
384
|
+
args: args.map(ensurePojo$1),
|
|
382
385
|
fetchedAt: fetchedAt != null ? fetchedAt : now,
|
|
383
386
|
date: now,
|
|
384
387
|
expiresAt: now + expiryLength,
|
|
@@ -433,14 +436,14 @@ const unsetState = () => {
|
|
|
433
436
|
};
|
|
434
437
|
|
|
435
438
|
/**
|
|
436
|
-
* Imperative control of
|
|
437
|
-
* @see https://
|
|
439
|
+
* Imperative control of Reactive Data Client store
|
|
440
|
+
* @see https://dataclient.io/docs/api/Controller
|
|
438
441
|
*/
|
|
439
442
|
class Controller {
|
|
440
443
|
/**
|
|
441
|
-
* Dispatches an action to
|
|
444
|
+
* Dispatches an action to Reactive Data Client reducer.
|
|
442
445
|
*
|
|
443
|
-
* @see https://
|
|
446
|
+
* @see https://dataclient.io/docs/api/Controller#dispatch
|
|
444
447
|
*/
|
|
445
448
|
|
|
446
449
|
/**
|
|
@@ -448,7 +451,7 @@ class Controller {
|
|
|
448
451
|
*
|
|
449
452
|
* This can be useful for imperative use-cases like event handlers.
|
|
450
453
|
* This should *not* be used to render; instead useSuspense() or useCache()
|
|
451
|
-
* @see https://
|
|
454
|
+
* @see https://dataclient.io/docs/api/Controller#getState
|
|
452
455
|
*/
|
|
453
456
|
|
|
454
457
|
constructor({
|
|
@@ -461,8 +464,8 @@ class Controller {
|
|
|
461
464
|
} = {}) {
|
|
462
465
|
/*************** Action Dispatchers ***************/
|
|
463
466
|
/**
|
|
464
|
-
* Fetches the endpoint with given args, updating the
|
|
465
|
-
* @see https://
|
|
467
|
+
* Fetches the endpoint with given args, updating the Reactive Data Client cache with the response or error upon completion.
|
|
468
|
+
* @see https://dataclient.io/docs/api/Controller#fetch
|
|
466
469
|
*/
|
|
467
470
|
this.fetch = (endpoint, ...args) => {
|
|
468
471
|
const action = createFetch(endpoint, {
|
|
@@ -489,14 +492,14 @@ class Controller {
|
|
|
489
492
|
};
|
|
490
493
|
/**
|
|
491
494
|
* Forces refetching and suspense on useSuspense with the same Endpoint and parameters.
|
|
492
|
-
* @see https://
|
|
495
|
+
* @see https://dataclient.io/docs/api/Controller#invalidate
|
|
493
496
|
*/
|
|
494
497
|
this.invalidate = (endpoint, ...args) => args[0] !== null ? this.dispatch(createInvalidate(endpoint, {
|
|
495
498
|
args: args
|
|
496
499
|
})) : Promise.resolve();
|
|
497
500
|
/**
|
|
498
501
|
* Forces refetching and suspense on useSuspense on all matching endpoint result keys.
|
|
499
|
-
* @see https://
|
|
502
|
+
* @see https://dataclient.io/docs/api/Controller#invalidateAll
|
|
500
503
|
* @returns Promise that resolves when invalidation is commited.
|
|
501
504
|
*/
|
|
502
505
|
this.invalidateAll = options => this.dispatch(createInvalidateAll(key => options.testKey(key)));
|
|
@@ -507,13 +510,13 @@ class Controller {
|
|
|
507
510
|
*/
|
|
508
511
|
this.expireAll = options => this.dispatch(createExpireAll(key => options.testKey(key)));
|
|
509
512
|
/**
|
|
510
|
-
* Resets the entire
|
|
511
|
-
* @see https://
|
|
513
|
+
* Resets the entire Reactive Data Client cache. All inflight requests will not resolve.
|
|
514
|
+
* @see https://dataclient.io/docs/api/Controller#resetEntireStore
|
|
512
515
|
*/
|
|
513
516
|
this.resetEntireStore = () => this.dispatch(createReset());
|
|
514
517
|
/**
|
|
515
518
|
* Stores response in cache for given Endpoint and args.
|
|
516
|
-
* @see https://
|
|
519
|
+
* @see https://dataclient.io/docs/api/Controller#set
|
|
517
520
|
*/
|
|
518
521
|
this.setResponse = (endpoint, ...rest) => {
|
|
519
522
|
const response = rest[rest.length - 1];
|
|
@@ -523,17 +526,9 @@ class Controller {
|
|
|
523
526
|
});
|
|
524
527
|
return this.dispatch(action);
|
|
525
528
|
};
|
|
526
|
-
/**
|
|
527
|
-
* @deprecated use https://resthooks.io/docs/api/Controller#setResponse instead
|
|
528
|
-
*/
|
|
529
|
-
/* istanbul ignore next */
|
|
530
|
-
this.receive = (endpoint, ...rest) => {
|
|
531
|
-
/* istanbul ignore next */
|
|
532
|
-
return this.setResponse(endpoint, ...rest);
|
|
533
|
-
};
|
|
534
529
|
/**
|
|
535
530
|
* Stores the result of Endpoint and args as the error provided.
|
|
536
|
-
* @see https://
|
|
531
|
+
* @see https://dataclient.io/docs/api/Controller#setError
|
|
537
532
|
*/
|
|
538
533
|
this.setError = (endpoint, ...rest) => {
|
|
539
534
|
const response = rest[rest.length - 1];
|
|
@@ -544,32 +539,23 @@ class Controller {
|
|
|
544
539
|
});
|
|
545
540
|
return this.dispatch(action);
|
|
546
541
|
};
|
|
547
|
-
/**
|
|
548
|
-
* Another name for setError
|
|
549
|
-
* @deprecated use https://resthooks.io/docs/api/Controller#setError instead
|
|
550
|
-
*/
|
|
551
|
-
/* istanbul ignore next */
|
|
552
|
-
this.receiveError = (endpoint, ...rest) => {
|
|
553
|
-
/* istanbul ignore next */
|
|
554
|
-
return this.setError(endpoint, ...rest);
|
|
555
|
-
};
|
|
556
542
|
/**
|
|
557
543
|
* Resolves an inflight fetch. `fetchedAt` should `fetch`'s `createdAt`
|
|
558
|
-
* @see https://
|
|
544
|
+
* @see https://dataclient.io/docs/api/Controller#resolve
|
|
559
545
|
*/
|
|
560
546
|
this.resolve = (endpoint, meta) => {
|
|
561
547
|
return this.dispatch(createSet(endpoint, meta));
|
|
562
548
|
};
|
|
563
549
|
/**
|
|
564
550
|
* Marks a new subscription to a given Endpoint.
|
|
565
|
-
* @see https://
|
|
551
|
+
* @see https://dataclient.io/docs/api/Controller#subscribe
|
|
566
552
|
*/
|
|
567
553
|
this.subscribe = (endpoint, ...args) => args[0] !== null ? this.dispatch(createSubscription(endpoint, {
|
|
568
554
|
args: args
|
|
569
555
|
})) : Promise.resolve();
|
|
570
556
|
/**
|
|
571
557
|
* Marks completion of subscription to a given Endpoint.
|
|
572
|
-
* @see https://
|
|
558
|
+
* @see https://dataclient.io/docs/api/Controller#unsubscribe
|
|
573
559
|
*/
|
|
574
560
|
this.unsubscribe = (endpoint, ...args) => args[0] !== null ? this.dispatch(createUnsubscription(endpoint, {
|
|
575
561
|
args: args
|
|
@@ -582,15 +568,15 @@ class Controller {
|
|
|
582
568
|
): Promise<void>
|
|
583
569
|
*/
|
|
584
570
|
/**
|
|
585
|
-
* Gets a snapshot (https://
|
|
586
|
-
* @see https://
|
|
571
|
+
* Gets a snapshot (https://dataclient.io/docs/api/Snapshot)
|
|
572
|
+
* @see https://dataclient.io/docs/api/Controller#snapshot
|
|
587
573
|
*/
|
|
588
574
|
this.snapshot = (state, fetchedAt) => {
|
|
589
575
|
return new Snapshot(this, state, fetchedAt);
|
|
590
576
|
};
|
|
591
577
|
/**
|
|
592
578
|
* Gets the error, if any, for a given endpoint. Returns undefined for no errors.
|
|
593
|
-
* @see https://
|
|
579
|
+
* @see https://dataclient.io/docs/api/Controller#getError
|
|
594
580
|
*/
|
|
595
581
|
this.getError = (endpoint, ...rest) => {
|
|
596
582
|
if (rest[0] === null) return;
|
|
@@ -605,12 +591,12 @@ class Controller {
|
|
|
605
591
|
};
|
|
606
592
|
/**
|
|
607
593
|
* Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
|
|
608
|
-
* @see https://
|
|
594
|
+
* @see https://dataclient.io/docs/api/Controller#getResponse
|
|
609
595
|
*/
|
|
610
596
|
this.getResponse = (endpoint, ...rest) => {
|
|
611
597
|
const state = rest[rest.length - 1];
|
|
612
598
|
// this is typescript generics breaking
|
|
613
|
-
const args = rest.slice(0, rest.length - 1);
|
|
599
|
+
const args = rest.slice(0, rest.length - 1).map(ensurePojo$1);
|
|
614
600
|
const isActive = args.length !== 1 || args[0] !== null;
|
|
615
601
|
const key = isActive ? endpoint.key(...args) : '';
|
|
616
602
|
const cacheResults = isActive ? state.results[key] : undefined;
|
|
@@ -655,7 +641,7 @@ class Controller {
|
|
|
655
641
|
expiresAt = entityExpiresAt(paths, state.entityMeta);
|
|
656
642
|
}
|
|
657
643
|
|
|
658
|
-
// https://
|
|
644
|
+
// https://dataclient.io/docs/concepts/expiry-policy#expiry-status
|
|
659
645
|
// we don't track the difference between stale or fresh because that is tied to triggering
|
|
660
646
|
// conditions
|
|
661
647
|
const expiryStatus = meta != null && meta.invalidated || invalidDenormalize && !(meta != null && meta.error) ? normalizr.ExpiryStatus.Invalid : invalidDenormalize || endpoint.invalidIfStale || invalidResults ? normalizr.ExpiryStatus.InvalidIfStale : normalizr.ExpiryStatus.Valid;
|
|
@@ -709,11 +695,11 @@ class Snapshot {
|
|
|
709
695
|
this.controller = void 0;
|
|
710
696
|
this.fetchedAt = void 0;
|
|
711
697
|
/*************** Data Access ***************/
|
|
712
|
-
/** @see https://
|
|
698
|
+
/** @see https://dataclient.io/docs/api/Snapshot#getResponse */
|
|
713
699
|
this.getResponse = (endpoint, ...args) => {
|
|
714
700
|
return this.controller.getResponse(endpoint, ...args, this.state);
|
|
715
701
|
};
|
|
716
|
-
/** @see https://
|
|
702
|
+
/** @see https://dataclient.io/docs/api/Snapshot#getError */
|
|
717
703
|
this.getError = (endpoint, ...args) => {
|
|
718
704
|
return this.controller.getError(endpoint, ...args, this.state);
|
|
719
705
|
};
|
|
@@ -762,7 +748,7 @@ class NetworkManager {
|
|
|
762
748
|
}
|
|
763
749
|
return Promise.resolve();
|
|
764
750
|
case SET_TYPE:
|
|
765
|
-
// only
|
|
751
|
+
// only set after new state is computed
|
|
766
752
|
return next(action).then(() => {
|
|
767
753
|
if (action.meta.key in this.fetched) {
|
|
768
754
|
var _controller$getState$;
|
|
@@ -770,14 +756,14 @@ class NetworkManager {
|
|
|
770
756
|
const error = (_controller$getState$ = controller.getState().meta[action.meta.key]) == null ? void 0 : _controller$getState$.error;
|
|
771
757
|
// processing errors result in state meta having error, so we should reject the promise
|
|
772
758
|
if (error) {
|
|
773
|
-
this.
|
|
759
|
+
this.handleSet(createSet(action.endpoint, {
|
|
774
760
|
args: action.meta.args,
|
|
775
761
|
response: error,
|
|
776
762
|
fetchedAt: action.meta.fetchedAt,
|
|
777
763
|
error: true
|
|
778
764
|
}));
|
|
779
765
|
} else {
|
|
780
|
-
this.
|
|
766
|
+
this.handleSet(action);
|
|
781
767
|
}
|
|
782
768
|
}
|
|
783
769
|
});
|
|
@@ -844,7 +830,7 @@ class NetworkManager {
|
|
|
844
830
|
return this.controller.getState().lastReset;
|
|
845
831
|
}
|
|
846
832
|
|
|
847
|
-
/** Called when middleware intercepts '
|
|
833
|
+
/** Called when middleware intercepts 'rdc/fetch' action.
|
|
848
834
|
*
|
|
849
835
|
* Will then start a promise for a key and potentially start the network
|
|
850
836
|
* fetch.
|
|
@@ -870,7 +856,7 @@ class NetworkManager {
|
|
|
870
856
|
reject(error);
|
|
871
857
|
throw error;
|
|
872
858
|
});
|
|
873
|
-
// schedule non-throttled resolutions in a microtask before
|
|
859
|
+
// schedule non-throttled resolutions in a microtask before set
|
|
874
860
|
// this enables users awaiting their fetch to trigger any react updates needed to deal
|
|
875
861
|
// with upcoming changes because of the fetch (for instance avoiding suspense if something is deleted)
|
|
876
862
|
if (!throttle) {
|
|
@@ -916,11 +902,11 @@ class NetworkManager {
|
|
|
916
902
|
}
|
|
917
903
|
}
|
|
918
904
|
|
|
919
|
-
/** Called when middleware intercepts a
|
|
905
|
+
/** Called when middleware intercepts a set action.
|
|
920
906
|
*
|
|
921
|
-
* Will resolve the promise associated with
|
|
907
|
+
* Will resolve the promise associated with set key.
|
|
922
908
|
*/
|
|
923
|
-
|
|
909
|
+
handleSet(action) {
|
|
924
910
|
// this can still turn out to be untrue since this is async
|
|
925
911
|
if (action.meta.key in this.fetched) {
|
|
926
912
|
let promiseHandler;
|
|
@@ -937,9 +923,9 @@ class NetworkManager {
|
|
|
937
923
|
|
|
938
924
|
/** Attaches NetworkManager to store
|
|
939
925
|
*
|
|
940
|
-
* Intercepts '
|
|
926
|
+
* Intercepts 'rdc/fetch' actions to start requests.
|
|
941
927
|
*
|
|
942
|
-
* Resolve/rejects a request when matching '
|
|
928
|
+
* Resolve/rejects a request when matching 'rdc/set' event
|
|
943
929
|
* is seen.
|
|
944
930
|
*/
|
|
945
931
|
getMiddleware() {
|
|
@@ -984,31 +970,20 @@ class NetworkManager {
|
|
|
984
970
|
function applyManager(managers, controller) {
|
|
985
971
|
return managers.map(manager => {
|
|
986
972
|
const middleware = manager.getMiddleware();
|
|
987
|
-
// TODO(breaking): remove this once controller prop is no longer supported
|
|
988
973
|
return ({
|
|
989
974
|
dispatch,
|
|
990
975
|
getState
|
|
991
976
|
}) => {
|
|
992
977
|
controller.dispatch = dispatch;
|
|
993
978
|
controller.getState = getState;
|
|
994
|
-
// this is needed for backwards compatibility as we added 'controller' prop previously
|
|
995
|
-
const API = Object.create(controller, {
|
|
996
|
-
controller: {
|
|
997
|
-
value: controller
|
|
998
|
-
}
|
|
999
|
-
});
|
|
1000
979
|
// controller is a superset of the middleware API
|
|
1001
|
-
return middleware(
|
|
980
|
+
return middleware(controller);
|
|
1002
981
|
};
|
|
1003
982
|
});
|
|
1004
983
|
}
|
|
1005
984
|
|
|
1006
985
|
/* These should be compatible with redux */
|
|
1007
986
|
|
|
1008
|
-
var newActions = /*#__PURE__*/Object.freeze({
|
|
1009
|
-
__proto__: null
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
987
|
class BrowserConnectionListener {
|
|
1013
988
|
isOnline() {
|
|
1014
989
|
if (navigator.onLine !== undefined) {
|
|
@@ -1202,7 +1177,7 @@ class PollingSubscription {
|
|
|
1202
1177
|
|
|
1203
1178
|
/** The static class that constructs Subscription */
|
|
1204
1179
|
|
|
1205
|
-
/** Handles subscription actions -> fetch or
|
|
1180
|
+
/** Handles subscription actions -> fetch or set actions
|
|
1206
1181
|
*
|
|
1207
1182
|
* Constructor takes a SubscriptionConstructable class to control how
|
|
1208
1183
|
* subscriptions are handled. (e.g., polling, websockets)
|
|
@@ -1242,7 +1217,7 @@ class SubscriptionManager {
|
|
|
1242
1217
|
}
|
|
1243
1218
|
}
|
|
1244
1219
|
|
|
1245
|
-
/** Called when middleware intercepts '
|
|
1220
|
+
/** Called when middleware intercepts 'rdc/subscribe' action.
|
|
1246
1221
|
*
|
|
1247
1222
|
*/
|
|
1248
1223
|
handleSubscribe(action) {
|
|
@@ -1255,7 +1230,7 @@ class SubscriptionManager {
|
|
|
1255
1230
|
}
|
|
1256
1231
|
}
|
|
1257
1232
|
|
|
1258
|
-
/** Called when middleware intercepts '
|
|
1233
|
+
/** Called when middleware intercepts 'rdc/unsubscribe' action.
|
|
1259
1234
|
*
|
|
1260
1235
|
*/
|
|
1261
1236
|
handleUnsubscribe(action) {
|
|
@@ -1275,10 +1250,10 @@ class SubscriptionManager {
|
|
|
1275
1250
|
|
|
1276
1251
|
/** Attaches Manager to store
|
|
1277
1252
|
*
|
|
1278
|
-
* Intercepts '
|
|
1253
|
+
* Intercepts 'rdc/subscribe'/'rest-hordc/ribe' to register resources that
|
|
1279
1254
|
* need to be kept up to date.
|
|
1280
1255
|
*
|
|
1281
|
-
* Will possibly dispatch '
|
|
1256
|
+
* Will possibly dispatch 'rdc/fetch' or 'rest-hordc/' to keep resources fresh
|
|
1282
1257
|
*
|
|
1283
1258
|
*/
|
|
1284
1259
|
getMiddleware() {
|
|
@@ -1289,7 +1264,7 @@ class SubscriptionManager {
|
|
|
1289
1264
|
var _globalThis$document;
|
|
1290
1265
|
const HASINTL = typeof Intl !== 'undefined';
|
|
1291
1266
|
const DEFAULT_CONFIG = {
|
|
1292
|
-
name: `
|
|
1267
|
+
name: `RDC: ${(_globalThis$document = globalThis.document) == null ? void 0 : _globalThis$document.title}`,
|
|
1293
1268
|
autoPause: true,
|
|
1294
1269
|
serialize: {
|
|
1295
1270
|
options: undefined,
|
|
@@ -1332,7 +1307,7 @@ class DevToolsManager {
|
|
|
1332
1307
|
ret.then(() => {
|
|
1333
1308
|
if (skipLogging != null && skipLogging(action)) return;
|
|
1334
1309
|
const state = controller.getState();
|
|
1335
|
-
this.devTools.send(action, state.optimistic.reduce(reducer, state), undefined, '
|
|
1310
|
+
this.devTools.send(action, state.optimistic.reduce(reducer, state), undefined, 'RDC');
|
|
1336
1311
|
});
|
|
1337
1312
|
return ret;
|
|
1338
1313
|
};
|
|
@@ -1412,7 +1387,6 @@ exports.__INTERNAL__ = internal;
|
|
|
1412
1387
|
exports.actionTypes = actionTypes;
|
|
1413
1388
|
exports.applyManager = applyManager;
|
|
1414
1389
|
exports.createFetch = createFetch;
|
|
1415
|
-
exports.createReceive = createSet;
|
|
1416
1390
|
exports.createReducer = createReducer;
|
|
1391
|
+
exports.createSet = createSet;
|
|
1417
1392
|
exports.initialState = initialState;
|
|
1418
|
-
exports.newActions = newActions;
|
package/dist/index.umd.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@data-client/normalizr")):"function"==typeof define&&define.amd?define(["exports","@data-client/normalizr"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).dataClientCore={},e.normalizr)}(this,(function(e,t){"use strict";var s="function"==typeof requestIdleCallback?requestIdleCallback:e=>setTimeout(e,0);const i="rest-hooks/fetch",r="rest-hooks/receive",n=r,o="rest-hooks/optimistic",a="rest-hooks/reset",l="rest-hooks/subscribe",c="rest-hook/unsubscribe",h="rest-hooks/invalidate",d="rest-hooks/invalidateall",u="rest-hooks/expireall",p="rest-hooks/gc";var f=Object.freeze({__proto__:null,FETCH_TYPE:i,RECEIVE_TYPE:r,SET_TYPE:n,OPTIMISTIC_TYPE:o,RESET_TYPE:a,SUBSCRIBE_TYPE:l,UNSUBSCRIBE_TYPE:c,INVALIDATE_TYPE:h,INVALIDATEALL_TYPE:d,EXPIREALL_TYPE:u,GC_TYPE:p});function m(e,t){let s;return t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect?(s=function(e,{args:t,fetchedAt:s}){var i;const r=null!=(i=e.dataExpiryLength)?i:6e4,n=Date.now(),a={args:t,fetchedAt:s,date:n,expiresAt:n+r,key:e.key(...t)};return{type:o,endpoint:e,meta:a}}(t.endpoint,{args:t.meta.args,fetchedAt:t.meta.createdAt}),Object.assign({},e,{optimistic:[...e.optimistic,s]})):e}function y(e,t,s){return"AbortError"===s.name?Object.assign({},e,{optimistic:g(e,t)}):Object.assign({},e,{meta:Object.assign({},e.meta,{[t.meta.key]:{date:t.meta.date,error:s,expiresAt:t.meta.expiresAt,errorPolicy:null==t.endpoint.errorPolicy?void 0:t.endpoint.errorPolicy(s)}}),optimistic:g(e,t)})}function g(e,t){return e.optimistic.filter((e=>e.meta.key!==t.meta.key||(e.type===o?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function v(e){return function(s,r){switch(s||(s=E),r.type){case p:return r.entities.forEach((([e,t])=>{var i,r;null==(i=s.entities[e])||delete i[t],null==(r=s.entityMeta[e])||delete r[t]})),r.results.forEach((e=>{delete s.results[e],delete s.meta[e]})),s;case i:return m(s,r);case o:case n:return function(e,s,i){if(s.error)return y(e,s,s.payload);try{var r;let a;if(s.type===o){if(!s.endpoint.getOptimisticResponse)return e;try{a=s.endpoint.getOptimisticResponse.call(s.endpoint,i.snapshot(e,s.meta.fetchedAt),...s.meta.args)}catch(t){var n;if("AbortOptimistic"===(null==(n=t.constructor)?void 0:n.name))return e;throw t}}else a=s.payload;const{result:l,entities:c,indexes:h,entityMeta:d}=t.normalize(a,s.endpoint.schema,s.meta.args,e.entities,e.indexes,e.entityMeta,s.meta),u=Object.assign({},e.results,{[s.meta.key]:l});try{if(s.endpoint.update){const e=s.endpoint.update(l,...s.meta.args);Object.keys(e).forEach((t=>{u[t]=e[t](u[t])}))}}catch(e){console.error(`The following error occured during Endpoint.update() for ${s.meta.key}`),console.error(e)}return{entities:c,indexes:h,results:u,entityMeta:d,meta:Object.assign({},e.meta,{[s.meta.key]:{date:s.meta.date,expiresAt:s.meta.expiresAt,prevExpiresAt:null==(r=e.meta[s.meta.key])?void 0:r.expiresAt}}),optimistic:g(e,s),lastReset:e.lastReset}}catch(t){return"object"==typeof t&&(t.message=`Error processing ${s.meta.key}\n\nFull Schema: ${JSON.stringify(s.endpoint.schema,void 0,2)}\n\nError:\n${t.message}`,"payload"in s&&(t.payload=s.payload),t.status=400),y(e,s,t)}}(s,r,e);case d:case h:return function(e,t){const s=Object.assign({},e.results),i=Object.assign({},e.meta),r=e=>{delete s[e];const t=Object.assign({},i[e],{expiresAt:0,invalidated:!0});delete t.error,i[e]=t};return t.type===h?r(t.meta.key):Object.keys(s).forEach((e=>{t.testKey(e)&&r(e)})),Object.assign({},e,{results:s,meta:i})}(s,r);case u:return function(e,t){const s=Object.assign({},e.meta);return Object.keys(s).forEach((e=>{t.testKey(e)&&(s[e]=Object.assign({},s[e],{expiresAt:1}))})),Object.assign({},e,{meta:s})}(s,r);case a:return Object.assign({},E,{lastReset:r.date});default:return s}}}const E={entities:{},indexes:{},results:{},meta:{},entityMeta:{},optimistic:[],lastReset:0};var b=Object.freeze({__proto__:null,inferResults:t.inferResults,DELETED:t.DELETED,INVALID:t.INVALID,RIC:s,initialState:E});function L(e,{args:t}){const s=e.key(...t);let r=0,n=0;const o=new Promise(((e,t)=>{[r,n]=[e,t]})),a={args:t,key:s,throttle:!e.sideEffect,resolve:r,reject:n,promise:o,createdAt:Date.now(),nm:!1};return{type:i,payload:()=>e(...t),meta:a,endpoint:e}}function O(e,{args:t,fetchedAt:s,response:i,error:r=!1}){var o,a;const l=r?null!=(o=e.errorExpiryLength)?o:1e3:null!=(a=e.dataExpiryLength)?a:6e4,c=Date.now(),h={args:t,fetchedAt:null!=s?s:c,date:c,expiresAt:c+l,key:e.key(...t)},d={type:n,payload:i,endpoint:e,meta:h};return r&&(d.error=!0),d}function I(e,t){return e.meta[t]}const k=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},w=()=>E;class S{constructor({dispatch:e=k,getState:s=w,globalCache:i={entities:{},results:{}}}={}){this.fetch=(e,...s)=>{const i=L(e,{args:s});return this.dispatch(i),e.schema?i.meta.promise.then((i=>t.denormalize(i,e.schema,{},s))):i.meta.promise},this.fetchIfStale=(e,...s)=>{const{data:i,expiresAt:r,expiryStatus:n}=this.getResponse(e,...s,this.getState());return n!==t.ExpiryStatus.Invalid&&Date.now()<=r?i:this.fetch(e,...s)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:h,meta:{key:e.key(...t)}}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:d,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:u,testKey:t=>e.testKey(t)}),this.resetEntireStore=()=>this.dispatch({type:a,date:Date.now()}),this.setResponse=(e,...t)=>{const s=t[t.length-1],i=O(e,{args:t.slice(0,t.length-1),response:s});return this.dispatch(i)},this.receive=(e,...t)=>this.setResponse(e,...t),this.setError=(e,...t)=>{const s=t[t.length-1],i=O(e,{args:t.slice(0,t.length-1),response:s,error:!0});return this.dispatch(i)},this.receiveError=(e,...t)=>this.setError(e,...t),this.resolve=(e,t)=>this.dispatch(O(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:l,endpoint:e,meta:{args:t,key:e.key(...t)}}}(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:c,endpoint:e,meta:{args:t,key:e.key(...t)}}}(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new x(this,e,t),this.getError=(e,...t)=>{if(null===t[0])return;const s=t[t.length-1],i=t.slice(0,t.length-1),r=e.key(...i),n=I(s,r);return void 0===s.results[r]||"soft"!==(null==n?void 0:n.errorPolicy)?null==n?void 0:n.error:void 0},this.getResponse=(e,...s)=>{const i=s[s.length-1],r=s.slice(0,s.length-1),n=1!==r.length||null!==r[0],o=n?e.key(...r):"",a=n?i.results[o]:void 0,l=e.schema,c=I(i,o);let h,d=null==c?void 0:c.expiresAt,u=!1;if(void 0===a&&void 0!==e.schema?(h=t.inferResults(e.schema,r,i.indexes,i.entities),u=!t.validateInference(h),!d&&u&&(d=1)):h=a,!n)return{data:h,expiryStatus:t.ExpiryStatus.Valid,expiresAt:1/0};if(!e.schema||!A(e.schema))return{data:h,expiryStatus:null!=c&&c.invalidated?t.ExpiryStatus.Invalid:a&&!e.invalidIfStale?t.ExpiryStatus.Valid:t.ExpiryStatus.InvalidIfStale,expiresAt:d||0};this.globalCache.results[o]||(this.globalCache.results[o]=new t.WeakEntityMap);const{data:p,paths:f}=t.denormalizeCached(h,l,i.entities,this.globalCache.entities,this.globalCache.results[o],r),m="symbol"==typeof p;d||(d=function(e,t){let s=1/0;for(const{pk:n,key:o}of e){var i,r;const e=null==(i=t[o])||null==(r=i[n])?void 0:r.expiresAt;e<s&&(s=e)}return s}(f,i.entityMeta));return{data:p,expiryStatus:null!=c&&c.invalidated||m&&(null==c||!c.error)?t.ExpiryStatus.Invalid:m||e.invalidIfStale||u?t.ExpiryStatus.InvalidIfStale:t.ExpiryStatus.Valid,expiresAt:d}},this.dispatch=e,this.getState=s,this.globalCache=i}}function A(e){if(t.isEntity(e))return!0;if(Array.isArray(e))return 0!==e.length&&A(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?A(t):Object.values(t).some((e=>A(e)))}return!1}class x{constructor(e,t,s=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.getResponse=(e,...t)=>this.controller.getResponse(e,...t,this.state),this.getError=(e,...t)=>this.controller.getError(e,...t,this.state),this.state=t,this.controller=e,this.fetchedAt=s}}class T extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}var j=Object.freeze({__proto__:null});class _{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 R{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}let P;P="undefined"!=typeof navigator&&"function"==typeof addEventListener?_:R;var q,D=P;const M="undefined"!=typeof Intl,C={name:`Rest Hooks: ${null==(q=globalThis.document)?void 0:q.title}`,autoPause:!0,serialize:{options:void 0,replacer:M?(e,t)=>"number"==typeof t&&"string"==typeof e&&isFinite(t)&&("date"===e||e.endsWith("At"))?Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3}).format(t):t:void 0}};Object.hasOwn=Object.hasOwn||function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},Object.defineProperty(e,"ExpiryStatus",{enumerable:!0,get:function(){return t.ExpiryStatus}}),e.Controller=S,e.DefaultConnectionListener=D,e.DevToolsManager=class{constructor(e,t){this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign({},C,{config:e})),this.devTools?this.middleware=e=>{const s=v(e);return i=>r=>{const n=i(r);return n.then((()=>{if(null!=t&&t(r))return;const i=e.getState();this.devTools.send(r,i.optimistic.reduce(s,i),void 0,"REST_HOOKS")})),n}}:this.middleware=()=>e=>t=>e(t)}init(e){this.devTools&&this.devTools.init(e)}cleanup(){}getMiddleware(){return this.middleware}},e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){e&&(this.handleLogout=e),t&&(this.shouldLogout=t),this.middleware=e=>t=>async s=>{await t(s),s.type===n&&s.error&&this.shouldLogout(s.payload)&&this.handleLogout(e)}}cleanup(){}getMiddleware(){return this.middleware}shouldLogout(e){return 401===e.status}handleLogout(e){e.resetEntireStore()}},e.NetworkManager=class{constructor(e=6e4,t=1e3){this.fetched=Object.create(null),this.resolvers={},this.rejectors={},this.fetchedAt={},this.controller=new S,this.dataExpiryLength=e,this.errorExpiryLength=t,this.middleware=e=>(this.controller=e,t=>s=>{switch(s.type){case i:return this.handleFetch(s),void 0!==s.endpoint.getOptimisticResponse&&s.endpoint.sideEffect?t(s):Promise.resolve();case n:return t(s).then((()=>{if(s.meta.key in this.fetched){var t;const i=null==(t=e.getState().meta[s.meta.key])?void 0:t.error;i?this.handleReceive(O(s.endpoint,{args:s.meta.args,response:i,fetchedAt:s.meta.fetchedAt,error:!0})):this.handleReceive(s)}}));case a:{const e=Object.assign({},this.rejectors);return this.clearAll(),t(s).then((()=>{for(const t in e)e[t](new T)}))}default:return t(s)}})}skipLogging(e){return e.type===i&&e.meta.key in this.fetched}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}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 t=e.payload,{key:s,throttle:i,resolve:r,reject:n,createdAt:o}=e.meta,a=()=>{let s=t();return i||(s=(e=>e.then((e=>(r(e),e))).catch((e=>{throw n(e),e})))(s)),s=s.then((t=>{let s=this.getLastReset();return o>=s&&this.controller.resolve(e.endpoint,{args:e.meta.args,response:t,fetchedAt:o}),t})).catch((t=>{const s=this.getLastReset();throw o>=s&&this.controller.resolve(e.endpoint,{args:e.meta.args,response:t,fetchedAt:o,error:!0}),t})),s};return i?this.throttle(s,a,o).then((e=>r(e))).catch((e=>n(e))):a().catch((()=>{}))}handleReceive(e){if(e.meta.key in this.fetched){let t;t=e.error?this.rejectors[e.meta.key]:this.resolvers[e.meta.key],t(e.payload),this.clear(e.meta.key)}}getMiddleware(){return this.middleware}throttle(e,t,i){const r=this.getLastReset();return e in this.fetched&&this.fetchedAt[e]>r||(this.fetched[e]=new Promise(((t,s)=>{this.resolvers[e]=t,this.rejectors[e]=s})),this.fetchedAt[e]=i,s((()=>{t().catch((()=>null))}),{timeout:500})),this.fetched[e]}},e.PollingSubscription=class{constructor(e,t,s){if(this.frequencyHistogram=new Map,this.offlineListener=()=>{this.cleanup(),this.connectionListener.addOnlineListener(this.onlineListener)},this.onlineListener=()=>{this.connectionListener.removeOnlineListener(this.onlineListener);const e=Date.now();this.startId=setTimeout((()=>{this.startId&&(delete this.startId,this.update(),this.run())}),Math.max(0,this.lastFetchTime()-e+this.frequency)),this.connectionListener.addOfflineListener(this.offlineListener)},void 0===e.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=e.endpoint,this.frequency=e.endpoint.pollFrequency,this.args=e.meta.args,this.key=e.meta.key,this.frequencyHistogram.set(this.frequency,1),this.controller=t,this.connectionListener=s||new D,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=T,e.SubscriptionManager=class{constructor(e){this.subscriptions={},this.controller=new S,this.Subscription=e,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case l:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case c:return this.handleUnsubscribe(t),Promise.resolve();default:return e(t)}})}cleanup(){for(const e in this.subscriptions)this.subscriptions[e].cleanup()}handleSubscribe(e){const t=e.meta.key;if(t in this.subscriptions){const s=e.endpoint.pollFrequency;this.subscriptions[t].add(s)}else this.subscriptions[t]=new this.Subscription(e,this.controller)}handleUnsubscribe(e){const t=e.meta.key;if(t in this.subscriptions){const s=e.endpoint.pollFrequency;this.subscriptions[t].remove(s)&&delete this.subscriptions[t]}}getMiddleware(){return this.middleware}},e.__INTERNAL__=b,e.actionTypes=f,e.applyManager=function(e,t){return e.map((e=>{const s=e.getMiddleware();return({dispatch:e,getState:i})=>{t.dispatch=e,t.getState=i;const r=Object.create(t,{controller:{value:t}});return s(r)}}))},e.createFetch=L,e.createReceive=O,e.createReducer=v,e.initialState=E,e.newActions=j,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@data-client/normalizr")):"function"==typeof define&&define.amd?define(["exports","@data-client/normalizr"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).dataClientCore={},e.normalizr)}(this,(function(e,t){"use strict";var s="function"==typeof requestIdleCallback?requestIdleCallback:e=>setTimeout(e,0);const i="rdc/fetch",r="rdc/set",n="rdc/optimistic",a="rdc/reset",o="rdc/subscribe",l="rdc/unsubscribe",c="rdc/invalidate",h="rdc/invalidateall",d="rdc/expireall",u="rdc/gc";var p=Object.freeze({__proto__:null,FETCH_TYPE:i,SET_TYPE:r,OPTIMISTIC_TYPE:n,RESET_TYPE:a,SUBSCRIBE_TYPE:o,UNSUBSCRIBE_TYPE:l,INVALIDATE_TYPE:c,INVALIDATEALL_TYPE:h,EXPIREALL_TYPE:d,GC_TYPE:u});function f(e,t){let s;return t.endpoint.getOptimisticResponse&&t.endpoint.sideEffect?(s=function(e,{args:t,fetchedAt:s}){var i;const r=null!=(i=e.dataExpiryLength)?i:6e4,a=Date.now(),o={args:t,fetchedAt:s,date:a,expiresAt:a+r,key:e.key(...t)};return{type:n,endpoint:e,meta:o}}(t.endpoint,{args:t.meta.args,fetchedAt:t.meta.createdAt}),Object.assign({},e,{optimistic:[...e.optimistic,s]})):e}function m(e,t,s){return"AbortError"===s.name?Object.assign({},e,{optimistic:y(e,t)}):Object.assign({},e,{meta:Object.assign({},e.meta,{[t.meta.key]:{date:t.meta.date,error:s,expiresAt:t.meta.expiresAt,errorPolicy:null==t.endpoint.errorPolicy?void 0:t.endpoint.errorPolicy(s)}}),optimistic:y(e,t)})}function y(e,t){return e.optimistic.filter((e=>e.meta.key!==t.meta.key||(e.type===n?e.meta.fetchedAt!==t.meta.fetchedAt:e.meta.date>t.meta.date)))}function g(e){return function(s,o){switch(s||(s=v),o.type){case u:return o.entities.forEach((([e,t])=>{var i,r;null==(i=s.entities[e])||delete i[t],null==(r=s.entityMeta[e])||delete r[t]})),o.results.forEach((e=>{delete s.results[e],delete s.meta[e]})),s;case i:return f(s,o);case n:case r:return function(e,s,i){if(s.error)return m(e,s,s.payload);try{var r;let o;if(s.type===n){if(!s.endpoint.getOptimisticResponse)return e;try{o=s.endpoint.getOptimisticResponse.call(s.endpoint,i.snapshot(e,s.meta.fetchedAt),...s.meta.args)}catch(t){var a;if("AbortOptimistic"===(null==(a=t.constructor)?void 0:a.name))return e;throw t}}else o=s.payload;const{result:l,entities:c,indexes:h,entityMeta:d}=t.normalize(o,s.endpoint.schema,s.meta.args,e.entities,e.indexes,e.entityMeta,s.meta),u=Object.assign({},e.results,{[s.meta.key]:l});try{if(s.endpoint.update){const e=s.endpoint.update(l,...s.meta.args);Object.keys(e).forEach((t=>{u[t]=e[t](u[t])}))}}catch(e){console.error(`The following error occured during Endpoint.update() for ${s.meta.key}`),console.error(e)}return{entities:c,indexes:h,results:u,entityMeta:d,meta:Object.assign({},e.meta,{[s.meta.key]:{date:s.meta.date,expiresAt:s.meta.expiresAt,prevExpiresAt:null==(r=e.meta[s.meta.key])?void 0:r.expiresAt}}),optimistic:y(e,s),lastReset:e.lastReset}}catch(t){return"object"==typeof t&&(t.message=`Error processing ${s.meta.key}\n\nFull Schema: ${JSON.stringify(s.endpoint.schema,void 0,2)}\n\nError:\n${t.message}`,"payload"in s&&(t.payload=s.payload),t.status=400),m(e,s,t)}}(s,o,e);case h:case c:return function(e,t){const s=Object.assign({},e.results),i=Object.assign({},e.meta),r=e=>{delete s[e];const t=Object.assign({},i[e],{expiresAt:0,invalidated:!0});delete t.error,i[e]=t};return t.type===c?r(t.meta.key):Object.keys(s).forEach((e=>{t.testKey(e)&&r(e)})),Object.assign({},e,{results:s,meta:i})}(s,o);case d:return function(e,t){const s=Object.assign({},e.meta);return Object.keys(s).forEach((e=>{t.testKey(e)&&(s[e]=Object.assign({},s[e],{expiresAt:1}))})),Object.assign({},e,{meta:s})}(s,o);case a:return Object.assign({},v,{lastReset:o.date});default:return s}}}const v={entities:{},indexes:{},results:{},meta:{},entityMeta:{},optimistic:[],lastReset:0};var b=Object.freeze({__proto__:null,inferResults:t.inferResults,INVALID:t.INVALID,RIC:s,initialState:v});function E(e,{args:t}){const s=e.key(...t);let r=0,n=0;const a=new Promise(((e,t)=>{[r,n]=[e,t]})),o={args:t,key:s,throttle:!e.sideEffect,resolve:r,reject:n,promise:a,createdAt:Date.now(),nm:!1};return{type:i,payload:()=>e(...t),meta:o,endpoint:e}}var L="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function I(e,{args:t,fetchedAt:s,response:i,error:n=!1}){var a,o;const l=n?null!=(a=e.errorExpiryLength)?a:1e3:null!=(o=e.dataExpiryLength)?o:6e4,c=Date.now(),h={args:t.map(L),fetchedAt:null!=s?s:c,date:c,expiresAt:c+l,key:e.key(...t)},d={type:r,payload:i,endpoint:e,meta:h};return n&&(d.error=!0),d}function O(e,t){return e.meta[t]}const S=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},w=()=>v;class A{constructor({dispatch:e=S,getState:s=w,globalCache:i={entities:{},results:{}}}={}){this.fetch=(e,...s)=>{const i=E(e,{args:s});return this.dispatch(i),e.schema?i.meta.promise.then((i=>t.denormalize(i,e.schema,{},s))):i.meta.promise},this.fetchIfStale=(e,...s)=>{const{data:i,expiresAt:r,expiryStatus:n}=this.getResponse(e,...s,this.getState());return n!==t.ExpiryStatus.Invalid&&Date.now()<=r?i:this.fetch(e,...s)},this.invalidate=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:c,meta:{key:e.key(...t)}}}(e,{args:t})):Promise.resolve(),this.invalidateAll=e=>this.dispatch({type:h,testKey:t=>e.testKey(t)}),this.expireAll=e=>this.dispatch({type:d,testKey:t=>e.testKey(t)}),this.resetEntireStore=()=>this.dispatch({type:a,date:Date.now()}),this.setResponse=(e,...t)=>{const s=t[t.length-1],i=I(e,{args:t.slice(0,t.length-1),response:s});return this.dispatch(i)},this.setError=(e,...t)=>{const s=t[t.length-1],i=I(e,{args:t.slice(0,t.length-1),response:s,error:!0});return this.dispatch(i)},this.resolve=(e,t)=>this.dispatch(I(e,t)),this.subscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:o,endpoint:e,meta:{args:t,key:e.key(...t)}}}(e,{args:t})):Promise.resolve(),this.unsubscribe=(e,...t)=>null!==t[0]?this.dispatch(function(e,{args:t}){return{type:l,endpoint:e,meta:{args:t,key:e.key(...t)}}}(e,{args:t})):Promise.resolve(),this.snapshot=(e,t)=>new x(this,e,t),this.getError=(e,...t)=>{if(null===t[0])return;const s=t[t.length-1],i=t.slice(0,t.length-1),r=e.key(...i),n=O(s,r);return void 0===s.results[r]||"soft"!==(null==n?void 0:n.errorPolicy)?null==n?void 0:n.error:void 0},this.getResponse=(e,...s)=>{const i=s[s.length-1],r=s.slice(0,s.length-1).map(L),n=1!==r.length||null!==r[0],a=n?e.key(...r):"",o=n?i.results[a]:void 0,l=e.schema,c=O(i,a);let h,d=null==c?void 0:c.expiresAt,u=!1;if(void 0===o&&void 0!==e.schema?(h=t.inferResults(e.schema,r,i.indexes,i.entities),u=!t.validateInference(h),!d&&u&&(d=1)):h=o,!n)return{data:h,expiryStatus:t.ExpiryStatus.Valid,expiresAt:1/0};if(!e.schema||!k(e.schema))return{data:h,expiryStatus:null!=c&&c.invalidated?t.ExpiryStatus.Invalid:o&&!e.invalidIfStale?t.ExpiryStatus.Valid:t.ExpiryStatus.InvalidIfStale,expiresAt:d||0};this.globalCache.results[a]||(this.globalCache.results[a]=new t.WeakEntityMap);const{data:p,paths:f}=t.denormalizeCached(h,l,i.entities,this.globalCache.entities,this.globalCache.results[a],r),m="symbol"==typeof p;d||(d=function(e,t){let s=1/0;for(const{pk:n,key:a}of e){var i,r;const e=null==(i=t[a])||null==(r=i[n])?void 0:r.expiresAt;e<s&&(s=e)}return s}(f,i.entityMeta));return{data:p,expiryStatus:null!=c&&c.invalidated||m&&(null==c||!c.error)?t.ExpiryStatus.Invalid:m||e.invalidIfStale||u?t.ExpiryStatus.InvalidIfStale:t.ExpiryStatus.Valid,expiresAt:d}},this.dispatch=e,this.getState=s,this.globalCache=i}}function k(e){if(t.isEntity(e))return!0;if(Array.isArray(e))return 0!==e.length&&k(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?k(t):Object.values(t).some((e=>k(e)))}return!1}class x{constructor(e,t,s=0){this.state=void 0,this.controller=void 0,this.fetchedAt=void 0,this.getResponse=(e,...t)=>this.controller.getResponse(e,...t,this.state),this.getError=(e,...t)=>this.controller.getError(e,...t,this.state),this.state=t,this.controller=e,this.fetchedAt=s}}class j extends Error{constructor(){super("Aborted due to RESET"),this.name="ResetError"}}class T{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 _{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}let R;R="undefined"!=typeof navigator&&"function"==typeof addEventListener?T:_;var q,P=R;const D="undefined"!=typeof Intl,M={name:`RDC: ${null==(q=globalThis.document)?void 0:q.title}`,autoPause:!0,serialize:{options:void 0,replacer:D?(e,t)=>"number"==typeof t&&"string"==typeof e&&isFinite(t)&&("date"===e||e.endsWith("At"))?Intl.DateTimeFormat("en-US",{hour:"numeric",minute:"numeric",second:"numeric",fractionalSecondDigits:3}).format(t):t:void 0}};Object.hasOwn=Object.hasOwn||function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},Object.defineProperty(e,"ExpiryStatus",{enumerable:!0,get:function(){return t.ExpiryStatus}}),e.Controller=A,e.DefaultConnectionListener=P,e.DevToolsManager=class{constructor(e,t){this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign({},M,{config:e})),this.devTools?this.middleware=e=>{const s=g(e);return i=>r=>{const n=i(r);return n.then((()=>{if(null!=t&&t(r))return;const i=e.getState();this.devTools.send(r,i.optimistic.reduce(s,i),void 0,"RDC")})),n}}:this.middleware=()=>e=>t=>e(t)}init(e){this.devTools&&this.devTools.init(e)}cleanup(){}getMiddleware(){return this.middleware}},e.LogoutManager=class{constructor({handleLogout:e,shouldLogout:t}={}){e&&(this.handleLogout=e),t&&(this.shouldLogout=t),this.middleware=e=>t=>async s=>{await t(s),s.type===r&&s.error&&this.shouldLogout(s.payload)&&this.handleLogout(e)}}cleanup(){}getMiddleware(){return this.middleware}shouldLogout(e){return 401===e.status}handleLogout(e){e.resetEntireStore()}},e.NetworkManager=class{constructor(e=6e4,t=1e3){this.fetched=Object.create(null),this.resolvers={},this.rejectors={},this.fetchedAt={},this.controller=new A,this.dataExpiryLength=e,this.errorExpiryLength=t,this.middleware=e=>(this.controller=e,t=>s=>{switch(s.type){case i:return this.handleFetch(s),void 0!==s.endpoint.getOptimisticResponse&&s.endpoint.sideEffect?t(s):Promise.resolve();case r:return t(s).then((()=>{if(s.meta.key in this.fetched){var t;const i=null==(t=e.getState().meta[s.meta.key])?void 0:t.error;i?this.handleSet(I(s.endpoint,{args:s.meta.args,response:i,fetchedAt:s.meta.fetchedAt,error:!0})):this.handleSet(s)}}));case a:{const e=Object.assign({},this.rejectors);return this.clearAll(),t(s).then((()=>{for(const t in e)e[t](new j)}))}default:return t(s)}})}skipLogging(e){return e.type===i&&e.meta.key in this.fetched}init(){delete this.cleanupDate}cleanup(){this.cleanupDate=Date.now()}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 t=e.payload,{key:s,throttle:i,resolve:r,reject:n,createdAt:a}=e.meta,o=()=>{let s=t();return i||(s=(e=>e.then((e=>(r(e),e))).catch((e=>{throw n(e),e})))(s)),s=s.then((t=>{let s=this.getLastReset();return a>=s&&this.controller.resolve(e.endpoint,{args:e.meta.args,response:t,fetchedAt:a}),t})).catch((t=>{const s=this.getLastReset();throw a>=s&&this.controller.resolve(e.endpoint,{args:e.meta.args,response:t,fetchedAt:a,error:!0}),t})),s};return i?this.throttle(s,o,a).then((e=>r(e))).catch((e=>n(e))):o().catch((()=>{}))}handleSet(e){if(e.meta.key in this.fetched){let t;t=e.error?this.rejectors[e.meta.key]:this.resolvers[e.meta.key],t(e.payload),this.clear(e.meta.key)}}getMiddleware(){return this.middleware}throttle(e,t,i){const r=this.getLastReset();return e in this.fetched&&this.fetchedAt[e]>r||(this.fetched[e]=new Promise(((t,s)=>{this.resolvers[e]=t,this.rejectors[e]=s})),this.fetchedAt[e]=i,s((()=>{t().catch((()=>null))}),{timeout:500})),this.fetched[e]}},e.PollingSubscription=class{constructor(e,t,s){if(this.frequencyHistogram=new Map,this.offlineListener=()=>{this.cleanup(),this.connectionListener.addOnlineListener(this.onlineListener)},this.onlineListener=()=>{this.connectionListener.removeOnlineListener(this.onlineListener);const e=Date.now();this.startId=setTimeout((()=>{this.startId&&(delete this.startId,this.update(),this.run())}),Math.max(0,this.lastFetchTime()-e+this.frequency)),this.connectionListener.addOfflineListener(this.offlineListener)},void 0===e.endpoint.pollFrequency)throw new Error("frequency needed for polling subscription");this.endpoint=e.endpoint,this.frequency=e.endpoint.pollFrequency,this.args=e.meta.args,this.key=e.meta.key,this.frequencyHistogram.set(this.frequency,1),this.controller=t,this.connectionListener=s||new P,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=j,e.SubscriptionManager=class{constructor(e){this.subscriptions={},this.controller=new A,this.Subscription=e,this.middleware=e=>(this.controller=e,e=>t=>{switch(t.type){case o:try{this.handleSubscribe(t)}catch(e){console.error(e)}return Promise.resolve();case l:return this.handleUnsubscribe(t),Promise.resolve();default:return e(t)}})}cleanup(){for(const e in this.subscriptions)this.subscriptions[e].cleanup()}handleSubscribe(e){const t=e.meta.key;if(t in this.subscriptions){const s=e.endpoint.pollFrequency;this.subscriptions[t].add(s)}else this.subscriptions[t]=new this.Subscription(e,this.controller)}handleUnsubscribe(e){const t=e.meta.key;if(t in this.subscriptions){const s=e.endpoint.pollFrequency;this.subscriptions[t].remove(s)&&delete this.subscriptions[t]}}getMiddleware(){return this.middleware}},e.__INTERNAL__=b,e.actionTypes=p,e.applyManager=function(e,t){return e.map((e=>{const s=e.getMiddleware();return({dispatch:e,getState:i})=>(t.dispatch=e,t.getState=i,s(t))}))},e.createFetch=E,e.createReducer=g,e.createSet=I,e.initialState=v,Object.defineProperty(e,"__esModule",{value:!0})}));
|