@data-client/core 0.4.3 → 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.
Files changed (99) hide show
  1. package/data_client_logo_and_text.svg +50 -0
  2. package/dist/index.js +57 -90
  3. package/dist/index.umd.min.js +1 -1
  4. package/dist/next.js +0 -454
  5. package/legacy/actionTypes.js +11 -13
  6. package/legacy/actions.js +2 -0
  7. package/legacy/controller/Controller.js +24 -41
  8. package/legacy/index.js +2 -2
  9. package/legacy/internal.js +2 -2
  10. package/legacy/manager/DevtoolsManager.js +3 -3
  11. package/legacy/manager/NetworkManager.js +11 -11
  12. package/legacy/manager/SubscriptionManager.js +6 -6
  13. package/legacy/manager/applyManager.js +2 -9
  14. package/legacy/middlewareTypes.js +1 -1
  15. package/legacy/next/index.js +2 -3
  16. package/legacy/state/reducer/fetchReducer.js +5 -5
  17. package/legacy/state/reducer/setReducer.js +2 -2
  18. package/legacy/types.js +3 -4
  19. package/lib/actionTypes.d.ts +10 -12
  20. package/lib/actionTypes.d.ts.map +1 -1
  21. package/lib/actionTypes.js +11 -13
  22. package/lib/{newActions.d.ts → actions.d.ts} +1 -3
  23. package/lib/actions.d.ts.map +1 -0
  24. package/lib/actions.js +2 -0
  25. package/lib/controller/Controller.d.ts +20 -33
  26. package/lib/controller/Controller.d.ts.map +1 -1
  27. package/lib/controller/Controller.js +24 -41
  28. package/lib/index.d.ts +1 -1
  29. package/lib/index.d.ts.map +1 -1
  30. package/lib/index.js +2 -2
  31. package/lib/internal.d.ts +1 -1
  32. package/lib/internal.d.ts.map +1 -1
  33. package/lib/internal.js +2 -2
  34. package/lib/manager/DevtoolsManager.js +3 -3
  35. package/lib/manager/NetworkManager.d.ts +6 -6
  36. package/lib/manager/NetworkManager.d.ts.map +1 -1
  37. package/lib/manager/NetworkManager.js +11 -11
  38. package/lib/manager/SubscriptionManager.d.ts +5 -5
  39. package/lib/manager/SubscriptionManager.js +6 -6
  40. package/lib/manager/applyManager.d.ts.map +1 -1
  41. package/lib/manager/applyManager.js +2 -9
  42. package/lib/middlewareTypes.d.ts +2 -5
  43. package/lib/middlewareTypes.d.ts.map +1 -1
  44. package/lib/middlewareTypes.js +1 -1
  45. package/lib/next/index.d.ts +0 -2
  46. package/lib/next/index.d.ts.map +1 -1
  47. package/lib/next/index.js +2 -3
  48. package/lib/state/reducer/expireReducer.d.ts +1 -1
  49. package/lib/state/reducer/fetchReducer.js +5 -5
  50. package/lib/state/reducer/invalidateReducer.d.ts +1 -1
  51. package/lib/state/reducer/setReducer.d.ts +2 -2
  52. package/lib/state/reducer/setReducer.d.ts.map +1 -1
  53. package/lib/state/reducer/setReducer.js +2 -2
  54. package/lib/types.d.ts +3 -4
  55. package/lib/types.d.ts.map +1 -1
  56. package/lib/types.js +3 -4
  57. package/package.json +3 -3
  58. package/src/actionTypes.ts +10 -12
  59. package/src/{newActions.ts → actions.ts} +1 -6
  60. package/src/controller/Controller.ts +23 -54
  61. package/src/index.ts +1 -1
  62. package/src/internal.ts +1 -1
  63. package/src/manager/DevtoolsManager.ts +2 -2
  64. package/src/manager/NetworkManager.ts +10 -10
  65. package/src/manager/SubscriptionManager.ts +5 -5
  66. package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +2 -2
  67. package/src/manager/__tests__/logoutManager.ts +2 -2
  68. package/src/manager/__tests__/manager.ts +1 -1
  69. package/src/manager/__tests__/networkManager.ts +13 -16
  70. package/src/manager/applyManager.ts +1 -6
  71. package/src/middlewareTypes.ts +4 -9
  72. package/src/next/index.ts +0 -2
  73. package/src/state/__tests__/__snapshots__/reducer.ts.snap +1 -1
  74. package/src/state/__tests__/reducer.ts +27 -9
  75. package/src/state/reducer/fetchReducer.ts +5 -5
  76. package/src/state/reducer/setReducer.ts +5 -5
  77. package/src/types.ts +3 -4
  78. package/ts3.4/actionTypes.d.ts +10 -12
  79. package/ts3.4/{newActions.d.ts → actions.d.ts} +1 -3
  80. package/ts3.4/controller/Controller.d.ts +20 -39
  81. package/ts3.4/index.d.ts +1 -1
  82. package/ts3.4/internal.d.ts +1 -1
  83. package/ts3.4/manager/NetworkManager.d.ts +6 -6
  84. package/ts3.4/manager/SubscriptionManager.d.ts +5 -5
  85. package/ts3.4/middlewareTypes.d.ts +2 -5
  86. package/ts3.4/next/index.d.ts +0 -2
  87. package/ts3.4/state/reducer/expireReducer.d.ts +1 -1
  88. package/ts3.4/state/reducer/invalidateReducer.d.ts +1 -1
  89. package/ts3.4/state/reducer/setReducer.d.ts +2 -2
  90. package/ts3.4/types.d.ts +3 -5
  91. package/legacy/fsa.js +0 -2
  92. package/legacy/newActions.js +0 -2
  93. package/lib/fsa.d.ts +0 -41
  94. package/lib/fsa.d.ts.map +0 -1
  95. package/lib/fsa.js +0 -2
  96. package/lib/newActions.d.ts.map +0 -1
  97. package/lib/newActions.js +0 -2
  98. package/src/fsa.ts +0 -99
  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 = 'rest-hooks/fetch';
30
- /** @deprecated use SET_TYPE instead */
31
- const RECEIVE_TYPE = 'rest-hooks/receive';
32
- const SET_TYPE = RECEIVE_TYPE;
33
- const OPTIMISTIC_TYPE = 'rest-hooks/optimistic';
34
- const RESET_TYPE = 'rest-hooks/reset';
35
- const SUBSCRIBE_TYPE = 'rest-hooks/subscribe';
36
- const UNSUBSCRIBE_TYPE = 'rest-hook/unsubscribe';
37
- const INVALIDATE_TYPE = 'rest-hooks/invalidate';
38
- const INVALIDATEALL_TYPE = 'rest-hooks/invalidateall';
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 receiveAction;
81
+ let setAction;
85
82
  if (action.endpoint.getOptimisticResponse && action.endpoint.sideEffect) {
86
- receiveAction = createOptimistic(action.endpoint, {
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://resthooks.io/docs/guides/redux#indextsx for hooking up redux');
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, receiveAction]
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 receives payload is contained in action
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
@@ -440,14 +436,14 @@ const unsetState = () => {
440
436
  };
441
437
 
442
438
  /**
443
- * Imperative control of Rest Hooks store
444
- * @see https://resthooks.io/docs/api/Controller
439
+ * Imperative control of Reactive Data Client store
440
+ * @see https://dataclient.io/docs/api/Controller
445
441
  */
446
442
  class Controller {
447
443
  /**
448
- * Dispatches an action to Rest Hooks reducer.
444
+ * Dispatches an action to Reactive Data Client reducer.
449
445
  *
450
- * @see https://resthooks.io/docs/api/Controller#dispatch
446
+ * @see https://dataclient.io/docs/api/Controller#dispatch
451
447
  */
452
448
 
453
449
  /**
@@ -455,7 +451,7 @@ class Controller {
455
451
  *
456
452
  * This can be useful for imperative use-cases like event handlers.
457
453
  * This should *not* be used to render; instead useSuspense() or useCache()
458
- * @see https://resthooks.io/docs/api/Controller#getState
454
+ * @see https://dataclient.io/docs/api/Controller#getState
459
455
  */
460
456
 
461
457
  constructor({
@@ -468,8 +464,8 @@ class Controller {
468
464
  } = {}) {
469
465
  /*************** Action Dispatchers ***************/
470
466
  /**
471
- * Fetches the endpoint with given args, updating the Rest Hooks cache with the response or error upon completion.
472
- * @see https://resthooks.io/docs/api/Controller#fetch
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
473
469
  */
474
470
  this.fetch = (endpoint, ...args) => {
475
471
  const action = createFetch(endpoint, {
@@ -496,14 +492,14 @@ class Controller {
496
492
  };
497
493
  /**
498
494
  * Forces refetching and suspense on useSuspense with the same Endpoint and parameters.
499
- * @see https://resthooks.io/docs/api/Controller#invalidate
495
+ * @see https://dataclient.io/docs/api/Controller#invalidate
500
496
  */
501
497
  this.invalidate = (endpoint, ...args) => args[0] !== null ? this.dispatch(createInvalidate(endpoint, {
502
498
  args: args
503
499
  })) : Promise.resolve();
504
500
  /**
505
501
  * Forces refetching and suspense on useSuspense on all matching endpoint result keys.
506
- * @see https://resthooks.io/docs/api/Controller#invalidateAll
502
+ * @see https://dataclient.io/docs/api/Controller#invalidateAll
507
503
  * @returns Promise that resolves when invalidation is commited.
508
504
  */
509
505
  this.invalidateAll = options => this.dispatch(createInvalidateAll(key => options.testKey(key)));
@@ -514,13 +510,13 @@ class Controller {
514
510
  */
515
511
  this.expireAll = options => this.dispatch(createExpireAll(key => options.testKey(key)));
516
512
  /**
517
- * Resets the entire Rest Hooks cache. All inflight requests will not resolve.
518
- * @see https://resthooks.io/docs/api/Controller#resetEntireStore
513
+ * Resets the entire Reactive Data Client cache. All inflight requests will not resolve.
514
+ * @see https://dataclient.io/docs/api/Controller#resetEntireStore
519
515
  */
520
516
  this.resetEntireStore = () => this.dispatch(createReset());
521
517
  /**
522
518
  * Stores response in cache for given Endpoint and args.
523
- * @see https://resthooks.io/docs/api/Controller#set
519
+ * @see https://dataclient.io/docs/api/Controller#set
524
520
  */
525
521
  this.setResponse = (endpoint, ...rest) => {
526
522
  const response = rest[rest.length - 1];
@@ -530,17 +526,9 @@ class Controller {
530
526
  });
531
527
  return this.dispatch(action);
532
528
  };
533
- /**
534
- * @deprecated use https://resthooks.io/docs/api/Controller#setResponse instead
535
- */
536
- /* istanbul ignore next */
537
- this.receive = (endpoint, ...rest) => {
538
- /* istanbul ignore next */
539
- return this.setResponse(endpoint, ...rest);
540
- };
541
529
  /**
542
530
  * Stores the result of Endpoint and args as the error provided.
543
- * @see https://resthooks.io/docs/api/Controller#setError
531
+ * @see https://dataclient.io/docs/api/Controller#setError
544
532
  */
545
533
  this.setError = (endpoint, ...rest) => {
546
534
  const response = rest[rest.length - 1];
@@ -551,32 +539,23 @@ class Controller {
551
539
  });
552
540
  return this.dispatch(action);
553
541
  };
554
- /**
555
- * Another name for setError
556
- * @deprecated use https://resthooks.io/docs/api/Controller#setError instead
557
- */
558
- /* istanbul ignore next */
559
- this.receiveError = (endpoint, ...rest) => {
560
- /* istanbul ignore next */
561
- return this.setError(endpoint, ...rest);
562
- };
563
542
  /**
564
543
  * Resolves an inflight fetch. `fetchedAt` should `fetch`'s `createdAt`
565
- * @see https://resthooks.io/docs/api/Controller#resolve
544
+ * @see https://dataclient.io/docs/api/Controller#resolve
566
545
  */
567
546
  this.resolve = (endpoint, meta) => {
568
547
  return this.dispatch(createSet(endpoint, meta));
569
548
  };
570
549
  /**
571
550
  * Marks a new subscription to a given Endpoint.
572
- * @see https://resthooks.io/docs/api/Controller#subscribe
551
+ * @see https://dataclient.io/docs/api/Controller#subscribe
573
552
  */
574
553
  this.subscribe = (endpoint, ...args) => args[0] !== null ? this.dispatch(createSubscription(endpoint, {
575
554
  args: args
576
555
  })) : Promise.resolve();
577
556
  /**
578
557
  * Marks completion of subscription to a given Endpoint.
579
- * @see https://resthooks.io/docs/api/Controller#unsubscribe
558
+ * @see https://dataclient.io/docs/api/Controller#unsubscribe
580
559
  */
581
560
  this.unsubscribe = (endpoint, ...args) => args[0] !== null ? this.dispatch(createUnsubscription(endpoint, {
582
561
  args: args
@@ -589,15 +568,15 @@ class Controller {
589
568
  ): Promise<void>
590
569
  */
591
570
  /**
592
- * Gets a snapshot (https://resthooks.io/docs/api/Snapshot)
593
- * @see https://resthooks.io/docs/api/Controller#snapshot
571
+ * Gets a snapshot (https://dataclient.io/docs/api/Snapshot)
572
+ * @see https://dataclient.io/docs/api/Controller#snapshot
594
573
  */
595
574
  this.snapshot = (state, fetchedAt) => {
596
575
  return new Snapshot(this, state, fetchedAt);
597
576
  };
598
577
  /**
599
578
  * Gets the error, if any, for a given endpoint. Returns undefined for no errors.
600
- * @see https://resthooks.io/docs/api/Controller#getError
579
+ * @see https://dataclient.io/docs/api/Controller#getError
601
580
  */
602
581
  this.getError = (endpoint, ...rest) => {
603
582
  if (rest[0] === null) return;
@@ -612,7 +591,7 @@ class Controller {
612
591
  };
613
592
  /**
614
593
  * Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
615
- * @see https://resthooks.io/docs/api/Controller#getResponse
594
+ * @see https://dataclient.io/docs/api/Controller#getResponse
616
595
  */
617
596
  this.getResponse = (endpoint, ...rest) => {
618
597
  const state = rest[rest.length - 1];
@@ -662,7 +641,7 @@ class Controller {
662
641
  expiresAt = entityExpiresAt(paths, state.entityMeta);
663
642
  }
664
643
 
665
- // https://resthooks.io/docs/concepts/expiry-policy#expiry-status
644
+ // https://dataclient.io/docs/concepts/expiry-policy#expiry-status
666
645
  // we don't track the difference between stale or fresh because that is tied to triggering
667
646
  // conditions
668
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;
@@ -716,11 +695,11 @@ class Snapshot {
716
695
  this.controller = void 0;
717
696
  this.fetchedAt = void 0;
718
697
  /*************** Data Access ***************/
719
- /** @see https://resthooks.io/docs/api/Snapshot#getResponse */
698
+ /** @see https://dataclient.io/docs/api/Snapshot#getResponse */
720
699
  this.getResponse = (endpoint, ...args) => {
721
700
  return this.controller.getResponse(endpoint, ...args, this.state);
722
701
  };
723
- /** @see https://resthooks.io/docs/api/Snapshot#getError */
702
+ /** @see https://dataclient.io/docs/api/Snapshot#getError */
724
703
  this.getError = (endpoint, ...args) => {
725
704
  return this.controller.getError(endpoint, ...args, this.state);
726
705
  };
@@ -769,7 +748,7 @@ class NetworkManager {
769
748
  }
770
749
  return Promise.resolve();
771
750
  case SET_TYPE:
772
- // only receive after new state is computed
751
+ // only set after new state is computed
773
752
  return next(action).then(() => {
774
753
  if (action.meta.key in this.fetched) {
775
754
  var _controller$getState$;
@@ -777,14 +756,14 @@ class NetworkManager {
777
756
  const error = (_controller$getState$ = controller.getState().meta[action.meta.key]) == null ? void 0 : _controller$getState$.error;
778
757
  // processing errors result in state meta having error, so we should reject the promise
779
758
  if (error) {
780
- this.handleReceive(createSet(action.endpoint, {
759
+ this.handleSet(createSet(action.endpoint, {
781
760
  args: action.meta.args,
782
761
  response: error,
783
762
  fetchedAt: action.meta.fetchedAt,
784
763
  error: true
785
764
  }));
786
765
  } else {
787
- this.handleReceive(action);
766
+ this.handleSet(action);
788
767
  }
789
768
  }
790
769
  });
@@ -851,7 +830,7 @@ class NetworkManager {
851
830
  return this.controller.getState().lastReset;
852
831
  }
853
832
 
854
- /** Called when middleware intercepts 'rest-hooks/fetch' action.
833
+ /** Called when middleware intercepts 'rdc/fetch' action.
855
834
  *
856
835
  * Will then start a promise for a key and potentially start the network
857
836
  * fetch.
@@ -877,7 +856,7 @@ class NetworkManager {
877
856
  reject(error);
878
857
  throw error;
879
858
  });
880
- // schedule non-throttled resolutions in a microtask before receive
859
+ // schedule non-throttled resolutions in a microtask before set
881
860
  // this enables users awaiting their fetch to trigger any react updates needed to deal
882
861
  // with upcoming changes because of the fetch (for instance avoiding suspense if something is deleted)
883
862
  if (!throttle) {
@@ -923,11 +902,11 @@ class NetworkManager {
923
902
  }
924
903
  }
925
904
 
926
- /** Called when middleware intercepts a receive action.
905
+ /** Called when middleware intercepts a set action.
927
906
  *
928
- * Will resolve the promise associated with receive key.
907
+ * Will resolve the promise associated with set key.
929
908
  */
930
- handleReceive(action) {
909
+ handleSet(action) {
931
910
  // this can still turn out to be untrue since this is async
932
911
  if (action.meta.key in this.fetched) {
933
912
  let promiseHandler;
@@ -944,9 +923,9 @@ class NetworkManager {
944
923
 
945
924
  /** Attaches NetworkManager to store
946
925
  *
947
- * Intercepts 'rest-hooks/fetch' actions to start requests.
926
+ * Intercepts 'rdc/fetch' actions to start requests.
948
927
  *
949
- * Resolve/rejects a request when matching 'rest-hooks/receive' event
928
+ * Resolve/rejects a request when matching 'rdc/set' event
950
929
  * is seen.
951
930
  */
952
931
  getMiddleware() {
@@ -991,31 +970,20 @@ class NetworkManager {
991
970
  function applyManager(managers, controller) {
992
971
  return managers.map(manager => {
993
972
  const middleware = manager.getMiddleware();
994
- // TODO(breaking): remove this once controller prop is no longer supported
995
973
  return ({
996
974
  dispatch,
997
975
  getState
998
976
  }) => {
999
977
  controller.dispatch = dispatch;
1000
978
  controller.getState = getState;
1001
- // this is needed for backwards compatibility as we added 'controller' prop previously
1002
- const API = Object.create(controller, {
1003
- controller: {
1004
- value: controller
1005
- }
1006
- });
1007
979
  // controller is a superset of the middleware API
1008
- return middleware(API);
980
+ return middleware(controller);
1009
981
  };
1010
982
  });
1011
983
  }
1012
984
 
1013
985
  /* These should be compatible with redux */
1014
986
 
1015
- var newActions = /*#__PURE__*/Object.freeze({
1016
- __proto__: null
1017
- });
1018
-
1019
987
  class BrowserConnectionListener {
1020
988
  isOnline() {
1021
989
  if (navigator.onLine !== undefined) {
@@ -1209,7 +1177,7 @@ class PollingSubscription {
1209
1177
 
1210
1178
  /** The static class that constructs Subscription */
1211
1179
 
1212
- /** Handles subscription actions -> fetch or receive actions
1180
+ /** Handles subscription actions -> fetch or set actions
1213
1181
  *
1214
1182
  * Constructor takes a SubscriptionConstructable class to control how
1215
1183
  * subscriptions are handled. (e.g., polling, websockets)
@@ -1249,7 +1217,7 @@ class SubscriptionManager {
1249
1217
  }
1250
1218
  }
1251
1219
 
1252
- /** Called when middleware intercepts 'rest-hooks/subscribe' action.
1220
+ /** Called when middleware intercepts 'rdc/subscribe' action.
1253
1221
  *
1254
1222
  */
1255
1223
  handleSubscribe(action) {
@@ -1262,7 +1230,7 @@ class SubscriptionManager {
1262
1230
  }
1263
1231
  }
1264
1232
 
1265
- /** Called when middleware intercepts 'rest-hooks/unsubscribe' action.
1233
+ /** Called when middleware intercepts 'rdc/unsubscribe' action.
1266
1234
  *
1267
1235
  */
1268
1236
  handleUnsubscribe(action) {
@@ -1282,10 +1250,10 @@ class SubscriptionManager {
1282
1250
 
1283
1251
  /** Attaches Manager to store
1284
1252
  *
1285
- * Intercepts 'rest-hooks/subscribe'/'rest-hooks/unsubscribe' to register resources that
1253
+ * Intercepts 'rdc/subscribe'/'rest-hordc/ribe' to register resources that
1286
1254
  * need to be kept up to date.
1287
1255
  *
1288
- * Will possibly dispatch 'rest-hooks/fetch' or 'rest-hooks/receive' to keep resources fresh
1256
+ * Will possibly dispatch 'rdc/fetch' or 'rest-hordc/' to keep resources fresh
1289
1257
  *
1290
1258
  */
1291
1259
  getMiddleware() {
@@ -1296,7 +1264,7 @@ class SubscriptionManager {
1296
1264
  var _globalThis$document;
1297
1265
  const HASINTL = typeof Intl !== 'undefined';
1298
1266
  const DEFAULT_CONFIG = {
1299
- name: `Rest Hooks: ${(_globalThis$document = globalThis.document) == null ? void 0 : _globalThis$document.title}`,
1267
+ name: `RDC: ${(_globalThis$document = globalThis.document) == null ? void 0 : _globalThis$document.title}`,
1300
1268
  autoPause: true,
1301
1269
  serialize: {
1302
1270
  options: undefined,
@@ -1339,7 +1307,7 @@ class DevToolsManager {
1339
1307
  ret.then(() => {
1340
1308
  if (skipLogging != null && skipLogging(action)) return;
1341
1309
  const state = controller.getState();
1342
- this.devTools.send(action, state.optimistic.reduce(reducer, state), undefined, 'REST_HOOKS');
1310
+ this.devTools.send(action, state.optimistic.reduce(reducer, state), undefined, 'RDC');
1343
1311
  });
1344
1312
  return ret;
1345
1313
  };
@@ -1419,7 +1387,6 @@ exports.__INTERNAL__ = internal;
1419
1387
  exports.actionTypes = actionTypes;
1420
1388
  exports.applyManager = applyManager;
1421
1389
  exports.createFetch = createFetch;
1422
- exports.createReceive = createSet;
1423
1390
  exports.createReducer = createReducer;
1391
+ exports.createSet = createSet;
1424
1392
  exports.initialState = initialState;
1425
- exports.newActions = newActions;
@@ -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,a="rest-hooks/optimistic",o="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:a,RESET_TYPE:o,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(),o={args:t,fetchedAt:s,date:n,expiresAt:n+r,key:e.key(...t)};return{type:a,endpoint:e,meta:o}}(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===a?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 a:case n:return function(e,s,i){if(s.error)return y(e,s,s.payload);try{var r;let o;if(s.type===a){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 n;if("AbortOptimistic"===(null==(n=t.constructor)?void 0:n.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: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 o: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 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 O="undefined"!=typeof FormData?e=>e instanceof FormData?Object.fromEntries(e.entries()):e:e=>e;function I(e,{args:t,fetchedAt:s,response:i,error:r=!1}){var a,o;const l=r?null!=(a=e.errorExpiryLength)?a:1e3:null!=(o=e.dataExpiryLength)?o:6e4,c=Date.now(),h={args:t.map(O),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 k(e,t){return e.meta[t]}const w=e=>{throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},S=()=>E;class A{constructor({dispatch:e=w,getState:s=S,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:o,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.receive=(e,...t)=>this.setResponse(e,...t),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.receiveError=(e,...t)=>this.setError(e,...t),this.resolve=(e,t)=>this.dispatch(I(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 j(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=k(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(O),n=1!==r.length||null!==r[0],a=n?e.key(...r):"",o=n?i.results[a]:void 0,l=e.schema,c=k(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||!x(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 x(e){if(t.isEntity(e))return!0;if(Array.isArray(e))return 0!==e.length&&x(e[0]);if(e&&("object"==typeof e||"function"==typeof e)){const t="schema"in e?e.schema:e;return"function"==typeof t?x(t):Object.values(t).some((e=>x(e)))}return!1}class j{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 _=Object.freeze({__proto__:null});class R{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 P{isOnline(){return!0}addOnlineListener(){}removeOnlineListener(){}addOfflineListener(){}removeOfflineListener(){}}let q;q="undefined"!=typeof navigator&&"function"==typeof addEventListener?R:P;var D,M=q;const C="undefined"!=typeof Intl,H={name:`Rest Hooks: ${null==(D=globalThis.document)?void 0:D.title}`,autoPause:!0,serialize:{options:void 0,replacer:C?(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=M,e.DevToolsManager=class{constructor(e,t){this.devTools="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__&&window.__REDUX_DEVTOOLS_EXTENSION__.connect(Object.assign({},H,{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 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 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(I(s.endpoint,{args:s.meta.args,response:i,fetchedAt:s.meta.fetchedAt,error:!0})):this.handleReceive(s)}}));case o:{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: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((()=>{}))}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 M,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 A,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=I,e.createReducer=v,e.initialState=E,e.newActions=_,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})}));