@data-client/core 0.1.0 → 0.2.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 (243) hide show
  1. package/dist/index.js +133 -409
  2. package/dist/index.umd.min.js +1 -1
  3. package/dist/next.js +61 -101
  4. package/legacy/actionTypes.js +2 -2
  5. package/legacy/controller/Controller.js +276 -6
  6. package/legacy/controller/createFetch.js +3 -14
  7. package/legacy/controller/createInvalidate.js +1 -1
  8. package/legacy/controller/createInvalidateAll.js +1 -1
  9. package/legacy/controller/createOptimistic.js +1 -7
  10. package/legacy/controller/createReset.js +1 -1
  11. package/legacy/controller/createSet.js +31 -0
  12. package/legacy/controller/createSubscription.js +3 -7
  13. package/legacy/index.js +2 -5
  14. package/legacy/internal.js +2 -2
  15. package/legacy/manager/DevtoolsManager.js +2 -2
  16. package/legacy/manager/LogoutManager.js +2 -2
  17. package/legacy/manager/NetworkManager.js +28 -59
  18. package/legacy/manager/PollingSubscription.js +18 -27
  19. package/legacy/manager/SubscriptionManager.js +16 -42
  20. package/legacy/middlewareTypes.js +1 -1
  21. package/legacy/newActions.js +1 -1
  22. package/legacy/next/index.js +3 -3
  23. package/legacy/state/reducer/createReducer.js +2 -6
  24. package/legacy/state/reducer/fetchReducer.js +3 -13
  25. package/legacy/state/reducer/invalidateReducer.js +1 -1
  26. package/legacy/state/reducer/setReducer.js +9 -16
  27. package/legacy/types.js +2 -6
  28. package/lib/actionTypes.d.ts +1 -0
  29. package/lib/actionTypes.d.ts.map +1 -1
  30. package/lib/actionTypes.js +2 -2
  31. package/lib/controller/Controller.d.ts +126 -6
  32. package/lib/controller/Controller.d.ts.map +1 -1
  33. package/lib/controller/Controller.js +276 -6
  34. package/lib/controller/createFetch.d.ts +2 -2
  35. package/lib/controller/createFetch.d.ts.map +1 -1
  36. package/lib/controller/createFetch.js +3 -14
  37. package/lib/controller/createInvalidate.d.ts +1 -1
  38. package/lib/controller/createInvalidate.d.ts.map +1 -1
  39. package/lib/controller/createInvalidate.js +1 -1
  40. package/lib/controller/createInvalidateAll.d.ts +1 -1
  41. package/lib/controller/createInvalidateAll.d.ts.map +1 -1
  42. package/lib/controller/createInvalidateAll.js +1 -1
  43. package/lib/controller/createOptimistic.d.ts +2 -2
  44. package/lib/controller/createOptimistic.d.ts.map +1 -1
  45. package/lib/controller/createOptimistic.js +1 -7
  46. package/lib/controller/createReset.d.ts +1 -1
  47. package/lib/controller/createReset.d.ts.map +1 -1
  48. package/lib/controller/createReset.js +1 -1
  49. package/lib/controller/{createReceive.d.ts → createSet.d.ts} +6 -6
  50. package/lib/controller/createSet.d.ts.map +1 -0
  51. package/lib/controller/createSet.js +31 -0
  52. package/lib/controller/createSubscription.d.ts +3 -3
  53. package/lib/controller/createSubscription.d.ts.map +1 -1
  54. package/lib/controller/createSubscription.js +3 -7
  55. package/lib/index.d.ts +2 -6
  56. package/lib/index.d.ts.map +1 -1
  57. package/lib/index.js +2 -5
  58. package/lib/internal.d.ts +1 -1
  59. package/lib/internal.d.ts.map +1 -1
  60. package/lib/internal.js +2 -2
  61. package/lib/manager/DevtoolsManager.d.ts +1 -1
  62. package/lib/manager/DevtoolsManager.js +2 -2
  63. package/lib/manager/LogoutManager.d.ts +4 -5
  64. package/lib/manager/LogoutManager.d.ts.map +1 -1
  65. package/lib/manager/LogoutManager.js +2 -2
  66. package/lib/manager/NetworkManager.d.ts +4 -5
  67. package/lib/manager/NetworkManager.d.ts.map +1 -1
  68. package/lib/manager/NetworkManager.js +28 -61
  69. package/lib/manager/PollingSubscription.d.ts +9 -9
  70. package/lib/manager/PollingSubscription.d.ts.map +1 -1
  71. package/lib/manager/PollingSubscription.js +18 -27
  72. package/lib/manager/SubscriptionManager.d.ts +10 -15
  73. package/lib/manager/SubscriptionManager.d.ts.map +1 -1
  74. package/lib/manager/SubscriptionManager.js +16 -42
  75. package/lib/middlewareTypes.d.ts +5 -5
  76. package/lib/middlewareTypes.d.ts.map +1 -1
  77. package/lib/middlewareTypes.js +1 -1
  78. package/lib/newActions.d.ts +26 -18
  79. package/lib/newActions.d.ts.map +1 -1
  80. package/lib/newActions.js +1 -1
  81. package/lib/next/index.d.ts +2 -2
  82. package/lib/next/index.d.ts.map +1 -1
  83. package/lib/next/index.js +3 -3
  84. package/lib/state/reducer/createReducer.d.ts.map +1 -1
  85. package/lib/state/reducer/createReducer.js +2 -6
  86. package/lib/state/reducer/fetchReducer.d.ts +1 -2
  87. package/lib/state/reducer/fetchReducer.d.ts.map +1 -1
  88. package/lib/state/reducer/fetchReducer.js +3 -14
  89. package/lib/state/reducer/invalidateReducer.d.ts +3 -4
  90. package/lib/state/reducer/invalidateReducer.d.ts.map +1 -1
  91. package/lib/state/reducer/invalidateReducer.js +1 -1
  92. package/lib/state/reducer/setReducer.d.ts +2 -38
  93. package/lib/state/reducer/setReducer.d.ts.map +1 -1
  94. package/lib/state/reducer/setReducer.js +9 -17
  95. package/lib/types.d.ts +9 -30
  96. package/lib/types.d.ts.map +1 -1
  97. package/lib/types.js +2 -6
  98. package/package.json +3 -3
  99. package/src/actionTypes.ts +1 -1
  100. package/src/controller/Controller.ts +491 -10
  101. package/src/controller/createFetch.ts +4 -19
  102. package/src/controller/createInvalidate.ts +1 -1
  103. package/src/controller/createInvalidateAll.ts +1 -1
  104. package/src/controller/createOptimistic.ts +3 -9
  105. package/src/controller/createReset.ts +1 -1
  106. package/src/controller/{createReceive.ts → createSet.ts} +9 -17
  107. package/src/controller/createSubscription.ts +3 -10
  108. package/src/index.ts +2 -16
  109. package/src/internal.ts +1 -1
  110. package/src/manager/DevtoolsManager.ts +1 -1
  111. package/src/manager/LogoutManager.ts +4 -5
  112. package/src/manager/NetworkManager.ts +31 -80
  113. package/src/manager/PollingSubscription.ts +26 -27
  114. package/src/manager/SubscriptionManager.ts +22 -54
  115. package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +10 -8
  116. package/src/manager/__tests__/logoutManager.ts +5 -5
  117. package/src/manager/__tests__/manager.ts +2 -4
  118. package/src/manager/__tests__/networkManager.ts +8 -42
  119. package/src/manager/__tests__/pollingSubscription.ts +259 -151
  120. package/src/manager/__tests__/subscriptionManager.ts +7 -13
  121. package/src/middlewareTypes.ts +5 -10
  122. package/src/newActions.ts +33 -23
  123. package/src/next/index.ts +2 -2
  124. package/src/state/__tests__/reducer.ts +59 -297
  125. package/src/state/reducer/createReducer.ts +3 -11
  126. package/src/state/reducer/fetchReducer.ts +5 -18
  127. package/src/state/reducer/invalidateReducer.ts +2 -2
  128. package/src/state/reducer/setReducer.ts +10 -22
  129. package/src/types.ts +9 -78
  130. package/ts3.4/actionTypes.d.ts +1 -0
  131. package/ts3.4/controller/Controller.d.ts +168 -6
  132. package/ts3.4/controller/createFetch.d.ts +2 -2
  133. package/ts3.4/controller/createInvalidate.d.ts +1 -1
  134. package/ts3.4/controller/createInvalidateAll.d.ts +1 -1
  135. package/ts3.4/controller/createOptimistic.d.ts +1 -1
  136. package/ts3.4/controller/createReset.d.ts +1 -1
  137. package/ts3.4/controller/{createReceive.d.ts → createSet.d.ts} +6 -6
  138. package/ts3.4/controller/createSubscription.d.ts +3 -3
  139. package/ts3.4/index.d.ts +2 -7
  140. package/ts3.4/internal.d.ts +1 -1
  141. package/ts3.4/manager/DevtoolsManager.d.ts +1 -1
  142. package/ts3.4/manager/LogoutManager.d.ts +4 -5
  143. package/ts3.4/manager/NetworkManager.d.ts +4 -5
  144. package/ts3.4/manager/PollingSubscription.d.ts +9 -9
  145. package/ts3.4/manager/SubscriptionManager.d.ts +10 -15
  146. package/ts3.4/middlewareTypes.d.ts +5 -5
  147. package/ts3.4/newActions.d.ts +26 -18
  148. package/ts3.4/next/index.d.ts +2 -2
  149. package/ts3.4/state/reducer/fetchReducer.d.ts +1 -2
  150. package/ts3.4/state/reducer/invalidateReducer.d.ts +3 -4
  151. package/ts3.4/state/reducer/setReducer.d.ts +2 -38
  152. package/ts3.4/types.d.ts +8 -30
  153. package/legacy/compatibleActions.js +0 -2
  154. package/legacy/controller/BaseController.js +0 -289
  155. package/legacy/controller/createReceive.js +0 -36
  156. package/legacy/endpoint/index.js +0 -2
  157. package/legacy/endpoint/shapes.js +0 -2
  158. package/legacy/endpoint/types.js +0 -2
  159. package/legacy/legacyActions.js +0 -2
  160. package/legacy/next/Controller.js +0 -24
  161. package/legacy/previousActions.js +0 -2
  162. package/legacy/state/applyUpdatersToResults.js +0 -4
  163. package/legacy/state/legacy-actions/createFetch.js +0 -62
  164. package/legacy/state/legacy-actions/createReceive.js +0 -37
  165. package/legacy/state/legacy-actions/createReceiveError.js +0 -28
  166. package/legacy/state/legacy-actions/index.js +0 -4
  167. package/legacy/state/reducerInstance.js +0 -9
  168. package/lib/compatibleActions.d.ts +0 -47
  169. package/lib/compatibleActions.d.ts.map +0 -1
  170. package/lib/compatibleActions.js +0 -2
  171. package/lib/controller/BaseController.d.ts +0 -128
  172. package/lib/controller/BaseController.d.ts.map +0 -1
  173. package/lib/controller/BaseController.js +0 -289
  174. package/lib/controller/createReceive.d.ts.map +0 -1
  175. package/lib/controller/createReceive.js +0 -36
  176. package/lib/endpoint/index.d.ts +0 -3
  177. package/lib/endpoint/index.d.ts.map +0 -1
  178. package/lib/endpoint/index.js +0 -2
  179. package/lib/endpoint/shapes.d.ts +0 -25
  180. package/lib/endpoint/shapes.d.ts.map +0 -1
  181. package/lib/endpoint/shapes.js +0 -2
  182. package/lib/endpoint/types.d.ts +0 -45
  183. package/lib/endpoint/types.d.ts.map +0 -1
  184. package/lib/endpoint/types.js +0 -2
  185. package/lib/legacyActions.d.ts +0 -92
  186. package/lib/legacyActions.d.ts.map +0 -1
  187. package/lib/legacyActions.js +0 -2
  188. package/lib/next/Controller.d.ts +0 -14
  189. package/lib/next/Controller.d.ts.map +0 -1
  190. package/lib/next/Controller.js +0 -24
  191. package/lib/previousActions.d.ts +0 -91
  192. package/lib/previousActions.d.ts.map +0 -1
  193. package/lib/previousActions.js +0 -2
  194. package/lib/state/applyUpdatersToResults.d.ts +0 -13
  195. package/lib/state/applyUpdatersToResults.d.ts.map +0 -1
  196. package/lib/state/applyUpdatersToResults.js +0 -7
  197. package/lib/state/legacy-actions/createFetch.d.ts +0 -19
  198. package/lib/state/legacy-actions/createFetch.d.ts.map +0 -1
  199. package/lib/state/legacy-actions/createFetch.js +0 -62
  200. package/lib/state/legacy-actions/createReceive.d.ts +0 -14
  201. package/lib/state/legacy-actions/createReceive.d.ts.map +0 -1
  202. package/lib/state/legacy-actions/createReceive.js +0 -37
  203. package/lib/state/legacy-actions/createReceiveError.d.ts +0 -9
  204. package/lib/state/legacy-actions/createReceiveError.d.ts.map +0 -1
  205. package/lib/state/legacy-actions/createReceiveError.js +0 -28
  206. package/lib/state/legacy-actions/index.d.ts +0 -4
  207. package/lib/state/legacy-actions/index.d.ts.map +0 -1
  208. package/lib/state/legacy-actions/index.js +0 -4
  209. package/lib/state/reducerInstance.d.ts +0 -7
  210. package/lib/state/reducerInstance.d.ts.map +0 -1
  211. package/lib/state/reducerInstance.js +0 -9
  212. package/src/compatibleActions.ts +0 -96
  213. package/src/controller/BaseController.ts +0 -508
  214. package/src/endpoint/index.ts +0 -14
  215. package/src/endpoint/shapes.ts +0 -53
  216. package/src/endpoint/types.ts +0 -72
  217. package/src/legacyActions.ts +0 -163
  218. package/src/manager/__tests__/__snapshots__/pollingSubscription-endpoint.ts.snap +0 -49
  219. package/src/manager/__tests__/networkManager-legacy.ts +0 -394
  220. package/src/manager/__tests__/pollingSubscription-endpoint.ts +0 -423
  221. package/src/next/Controller.ts +0 -39
  222. package/src/previousActions.ts +0 -159
  223. package/src/state/__tests__/applyUpdatersToResults.ts +0 -40
  224. package/src/state/applyUpdatersToResults.ts +0 -29
  225. package/src/state/legacy-actions/createFetch.ts +0 -95
  226. package/src/state/legacy-actions/createReceive.ts +0 -68
  227. package/src/state/legacy-actions/createReceiveError.ts +0 -43
  228. package/src/state/legacy-actions/index.ts +0 -3
  229. package/src/state/reducerInstance.ts +0 -14
  230. package/ts3.4/compatibleActions.d.ts +0 -47
  231. package/ts3.4/controller/BaseController.d.ts +0 -170
  232. package/ts3.4/endpoint/index.d.ts +0 -3
  233. package/ts3.4/endpoint/shapes.d.ts +0 -25
  234. package/ts3.4/endpoint/types.d.ts +0 -45
  235. package/ts3.4/legacyActions.d.ts +0 -95
  236. package/ts3.4/next/Controller.d.ts +0 -14
  237. package/ts3.4/previousActions.d.ts +0 -94
  238. package/ts3.4/state/applyUpdatersToResults.d.ts +0 -13
  239. package/ts3.4/state/legacy-actions/createFetch.d.ts +0 -19
  240. package/ts3.4/state/legacy-actions/createReceive.d.ts +0 -14
  241. package/ts3.4/state/legacy-actions/createReceiveError.d.ts +0 -9
  242. package/ts3.4/state/legacy-actions/index.d.ts +0 -4
  243. package/ts3.4/state/reducerInstance.d.ts +0 -7
package/src/types.ts CHANGED
@@ -1,30 +1,17 @@
1
- import {
2
- EndpointInterface,
3
- NormalizedIndex,
4
- Schema,
5
- } from '@data-client/normalizr';
1
+ import { NormalizedIndex } from '@data-client/normalizr';
6
2
  import type {
7
3
  UpdateFunction,
8
4
  AbstractInstanceType,
9
5
  } from '@data-client/normalizr';
10
6
  import type { ErrorTypes } from '@data-client/normalizr';
11
7
 
12
- import { RECEIVE_TYPE } from './actionTypes.js';
13
- import {
14
- CompatibleFetchAction,
15
- CompatibleReceiveAction,
16
- CompatibleSubscribeAction,
17
- CompatibleUnsubscribeAction,
18
- } from './compatibleActions.js';
19
- import { EndpointUpdateFunction } from './controller/types.js';
20
- import * as legacyActions from './legacyActions.js';
21
- import { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
22
- import * as newActions from './newActions.js';
23
- import * as previousActions from './previousActions.js';
8
+ import { SET_TYPE } from './actionTypes.js';
9
+ import type { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
10
+ import type { ActionTypes, SetAction, OptimisticAction } from './newActions.js';
24
11
 
25
12
  export type { AbstractInstanceType, UpdateFunction };
26
13
 
27
- export type ReceiveTypes = typeof RECEIVE_TYPE;
14
+ export type ReceiveTypes = typeof SET_TYPE;
28
15
 
29
16
  export type PK = string;
30
17
 
@@ -53,70 +40,14 @@ export interface State<T> {
53
40
  };
54
41
  };
55
42
  };
56
- readonly optimistic: (
57
- | previousActions.ReceiveAction
58
- | previousActions.OptimisticAction
59
- )[];
60
- readonly lastReset: Date | number;
43
+ readonly optimistic: (SetAction | OptimisticAction)[];
44
+ readonly lastReset: number;
61
45
  }
62
46
 
63
- export * as legacyActions from './legacyActions.js';
64
47
  export * as newActions from './newActions.js';
65
- export type { SetAction } from './newActions.js';
66
-
67
- /* maintain backwards compatibility */
68
- /* TODO: switch to only include newActions in future */
69
- export type OptimisticAction<
70
- E extends EndpointInterface & {
71
- update?: EndpointUpdateFunction<E>;
72
- } = EndpointInterface & {
73
- update?: EndpointUpdateFunction<EndpointInterface>;
74
- },
75
- > = newActions.OptimisticAction<E>;
76
- export type InvalidateAction = newActions.InvalidateAction;
77
- export type ResetAction = newActions.ResetAction | legacyActions.ResetAction;
78
- export type GCAction = newActions.GCAction;
79
- export type FetchAction<
80
- Payload extends object | string | number | null =
81
- | object
82
- | string
83
- | number
84
- | null,
85
- S extends Schema | undefined = any,
86
- > = CompatibleFetchAction | legacyActions.FetchAction<Payload, S>;
87
- export type ReceiveAction<
88
- Payload extends object | string | number | null =
89
- | object
90
- | string
91
- | number
92
- | null,
93
- S extends Schema | undefined = any,
94
- > = CompatibleReceiveAction | legacyActions.ReceiveAction<Payload, S>;
95
- export type SubscribeAction =
96
- | CompatibleSubscribeAction
97
- | legacyActions.SubscribeAction;
98
- export type UnsubscribeAction =
99
- | CompatibleUnsubscribeAction
100
- | legacyActions.UnsubscribeAction;
101
-
102
- export type ResponseActions = ReceiveAction;
103
-
104
- // put other actions here in union
105
- export type OldActionTypes = previousActions.ActionTypes;
106
-
107
- export type CombinedActionTypes =
108
- | OptimisticAction
109
- | InvalidateAction
110
- | ResetAction
111
- | GCAction
112
- | FetchAction
113
- | ReceiveAction
114
- | SubscribeAction
115
- | UnsubscribeAction;
116
-
117
- export type ActionTypes = CombinedActionTypes;
48
+ export * from './newActions.js';
118
49
 
119
- export interface Manager<Actions = CombinedActionTypes> {
50
+ export interface Manager<Actions = ActionTypes> {
120
51
  getMiddleware(): Middleware<Actions>;
121
52
  cleanup(): void;
122
53
  init?: (state: State<any>) => void;
@@ -1,4 +1,5 @@
1
1
  export declare const FETCH_TYPE: "rest-hooks/fetch";
2
+ /** @deprecated use SET_TYPE instead */
2
3
  export declare const RECEIVE_TYPE: "rest-hooks/receive";
3
4
  export declare const SET_TYPE: "rest-hooks/receive";
4
5
  export declare const OPTIMISTIC_TYPE: "rest-hooks/optimistic";
@@ -1,14 +1,176 @@
1
- import { EndpointInterface } from '@data-client/normalizr';
2
- import BaseController, { CompatibleDispatch, GenericDispatch } from './BaseController.js';
1
+ import { ErrorTypes, SnapshotInterface, DenormalizeCache, Schema, Denormalize } from '@data-client/normalizr';
2
+ import { ExpiryStatus, EndpointInterface, FetchFunction, DenormalizeNullable } from '@data-client/normalizr';
3
3
  import { EndpointUpdateFunction } from './types.js';
4
- export default class Controller<D extends GenericDispatch = CompatibleDispatch> extends BaseController<D> {
4
+ import { ActionTypes, State } from '../types.js';
5
+ export type GenericDispatch = (value: any) => Promise<void>;
6
+ export type DataClientDispatch = (value: ActionTypes) => Promise<void>;
7
+ interface ConstructorProps<D extends GenericDispatch = DataClientDispatch> {
8
+ dispatch?: D;
9
+ getState?: () => State<unknown>;
10
+ globalCache?: DenormalizeCache;
11
+ }
12
+ /**
13
+ * Imperative control of Rest Hooks store
14
+ * @see https://resthooks.io/docs/api/Controller
15
+ */
16
+ export default class Controller<D extends GenericDispatch = DataClientDispatch> {
17
+ /**
18
+ * Dispatches an action to Rest Hooks reducer.
19
+ *
20
+ * @see https://resthooks.io/docs/api/Controller#dispatch
21
+ */
22
+ readonly dispatch: D;
23
+ /**
24
+ * Gets the latest state snapshot that is fully committed.
25
+ *
26
+ * This can be useful for imperative use-cases like event handlers.
27
+ * This should *not* be used to render; instead useSuspense() or useCache()
28
+ * @see https://resthooks.io/docs/api/Controller#getState
29
+ */
30
+ readonly getState: () => State<unknown>;
31
+ readonly globalCache: DenormalizeCache;
32
+ constructor({ dispatch, getState, globalCache, }?: ConstructorProps<D>);
33
+ /*************** Action Dispatchers ***************/
5
34
  /**
6
35
  * Fetches the endpoint with given args, updating the Rest Hooks cache with the response or error upon completion.
7
36
  * @see https://resthooks.io/docs/api/Controller#fetch
8
37
  */
9
- fetch: <E extends EndpointInterface<import("@data-client/normalizr").FetchFunction, import("@data-client/normalizr").Schema | undefined, boolean | undefined> & {
38
+ fetch: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
39
+ update?: EndpointUpdateFunction<E> | undefined;
40
+ }>(endpoint: E, ...args_0: Parameters<E>) => E["schema"] extends null | undefined ? ReturnType<E> : Promise<Denormalize<E["schema"]>>;
41
+ /**
42
+ * Forces refetching and suspense on useSuspense with the same Endpoint and parameters.
43
+ * @see https://resthooks.io/docs/api/Controller#invalidate
44
+ */
45
+ invalidate: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>>(endpoint: E, ...args: readonly [
46
+ ...Parameters<E>
47
+ ] | readonly [
48
+ null
49
+ ]) => Promise<void>;
50
+ /**
51
+ * Forces refetching and suspense on useSuspense on all matching endpoint result keys.
52
+ * @see https://resthooks.io/docs/api/Controller#invalidateAll
53
+ */
54
+ invalidateAll: (options: {
55
+ testKey: (key: string) => boolean;
56
+ }) => Promise<void>;
57
+ /**
58
+ * Resets the entire Rest Hooks cache. All inflight requests will not resolve.
59
+ * @see https://resthooks.io/docs/api/Controller#resetEntireStore
60
+ */
61
+ resetEntireStore: () => Promise<void>;
62
+ /**
63
+ * Stores response in cache for given Endpoint and args.
64
+ * @see https://resthooks.io/docs/api/Controller#set
65
+ */
66
+ setResponse: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
67
+ update?: EndpointUpdateFunction<E> | undefined;
68
+ }>(endpoint: E, ...rest: readonly [
69
+ ...Parameters<E>,
70
+ any
71
+ ]) => Promise<void>;
72
+ /**
73
+ * @deprecated use https://resthooks.io/docs/api/Controller#setResponse instead
74
+ */
75
+ receive: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
76
+ update?: EndpointUpdateFunction<E> | undefined;
77
+ }>(endpoint: E, ...rest: readonly [
78
+ ...Parameters<E>,
79
+ any
80
+ ]) => Promise<void>;
81
+ /**
82
+ * Stores the result of Endpoint and args as the error provided.
83
+ * @see https://resthooks.io/docs/api/Controller#setError
84
+ */
85
+ setError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
86
+ update?: EndpointUpdateFunction<E> | undefined;
87
+ }>(endpoint: E, ...rest: readonly [
88
+ ...Parameters<E>,
89
+ Error
90
+ ]) => Promise<void>;
91
+ /**
92
+ * Another name for setError
93
+ * @deprecated use https://resthooks.io/docs/api/Controller#setError instead
94
+ */
95
+ receiveError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
10
96
  update?: EndpointUpdateFunction<E> | undefined;
11
- }>(endpoint: E, ...args_0: Parameters<E>) => ReturnType<E>;
97
+ }>(endpoint: E, ...rest: readonly [
98
+ ...Parameters<E>,
99
+ Error
100
+ ]) => Promise<void>;
101
+ /**
102
+ * Resolves an inflight fetch. `fetchedAt` should `fetch`'s `createdAt`
103
+ * @see https://resthooks.io/docs/api/Controller#resolve
104
+ */
105
+ resolve: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
106
+ update?: EndpointUpdateFunction<E> | undefined;
107
+ }>(endpoint: E, meta: {
108
+ args: readonly [
109
+ ...Parameters<E>
110
+ ];
111
+ response: Error;
112
+ fetchedAt: number;
113
+ error: true;
114
+ } | {
115
+ args: readonly [
116
+ ...Parameters<E>
117
+ ];
118
+ response: any;
119
+ fetchedAt: number;
120
+ error?: false | undefined;
121
+ }) => Promise<void>;
122
+ /**
123
+ * Marks a new subscription to a given Endpoint.
124
+ * @see https://resthooks.io/docs/api/Controller#subscribe
125
+ */
126
+ subscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
127
+ null
128
+ ] | readonly [
129
+ ...Parameters<E>
130
+ ]) => Promise<void>;
131
+ /**
132
+ * Marks completion of subscription to a given Endpoint.
133
+ * @see https://resthooks.io/docs/api/Controller#unsubscribe
134
+ */
135
+ unsubscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
136
+ null
137
+ ] | readonly [
138
+ ...Parameters<E>
139
+ ]) => Promise<void>;
140
+ /*************** More ***************/
141
+ /**
142
+ * Gets a snapshot (https://resthooks.io/docs/api/Snapshot)
143
+ * @see https://resthooks.io/docs/api/Controller#snapshot
144
+ */
145
+ snapshot: (state: State<unknown>, fetchedAt?: number) => SnapshotInterface;
146
+ /**
147
+ * Gets the error, if any, for a given endpoint. Returns undefined for no errors.
148
+ * @see https://resthooks.io/docs/api/Controller#getError
149
+ */
150
+ getError: <E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>, "key">, Args extends readonly [
151
+ null
152
+ ] | readonly [
153
+ ...Parameters<E["key"]>
154
+ ]>(endpoint: E, ...rest: [
155
+ ...Args,
156
+ State<unknown>
157
+ ]) => ErrorTypes | undefined;
158
+ /**
159
+ * Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
160
+ * @see https://resthooks.io/docs/api/Controller#getResponse
161
+ */
162
+ getResponse: <E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>, "schema" | "key" | "invalidIfStale">, Args extends readonly [
163
+ null
164
+ ] | readonly [
165
+ ...Parameters<E["key"]>
166
+ ]>(endpoint: E, ...rest: [
167
+ ...Args,
168
+ State<unknown>
169
+ ]) => {
170
+ data: DenormalizeNullable<E["schema"]>;
171
+ expiryStatus: ExpiryStatus;
172
+ expiresAt: number;
173
+ };
12
174
  }
13
- export * from './BaseController.js';
175
+ export { ErrorTypes };
14
176
  //# sourceMappingURL=Controller.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { EndpointInterface } from '@data-client/normalizr';
2
2
  import { EndpointUpdateFunction } from './types.js';
3
- import { CompatibleFetchAction } from '../compatibleActions.js';
3
+ import { FetchAction } from '../types.js';
4
4
  /**
5
5
  * Requesting a fetch to begin
6
6
  */
@@ -10,5 +10,5 @@ export default function createFetch<E extends EndpointInterface & {
10
10
  args: readonly [
11
11
  ...Parameters<E>
12
12
  ];
13
- }): CompatibleFetchAction<E>;
13
+ }): FetchAction<E>;
14
14
  //# sourceMappingURL=createFetch.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { EndpointInterface } from '@data-client/normalizr';
2
- import { InvalidateAction } from '../newActions.js';
2
+ import { InvalidateAction } from '../types.js';
3
3
  export default function createInvalidate<E extends EndpointInterface>(endpoint: E, { args }: {
4
4
  args: readonly [
5
5
  ...Parameters<E>
@@ -1,3 +1,3 @@
1
- import { InvalidateAllAction } from '../newActions.js';
1
+ import { InvalidateAllAction } from '../types.js';
2
2
  export default function createInvalidateAll(testKey: (key: string) => boolean): InvalidateAllAction;
3
3
  //# sourceMappingURL=createInvalidateAll.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { EndpointInterface } from '@data-client/normalizr';
2
2
  import { EndpointUpdateFunction } from './types.js';
3
- import { OptimisticAction } from '../newActions.js';
3
+ import { OptimisticAction } from '../types.js';
4
4
  export default function createOptimistic<E extends EndpointInterface & {
5
5
  update?: EndpointUpdateFunction<E>;
6
6
  }>(endpoint: E, { args, fetchedAt, }: {
@@ -1,3 +1,3 @@
1
- import { ResetAction } from '../newActions.js';
1
+ import { ResetAction } from '../types.js';
2
2
  export default function createReset(): ResetAction;
3
3
  //# sourceMappingURL=createReset.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { EndpointInterface, ResolveType } from '@data-client/normalizr';
2
2
  import { EndpointUpdateFunction } from './types.js';
3
- import { CompatibleReceiveAction } from '../compatibleActions.js';
4
- export default function createReceive<E extends EndpointInterface & {
3
+ import { SetAction } from '../types.js';
4
+ export default function createSet<E extends EndpointInterface & {
5
5
  update?: EndpointUpdateFunction<E>;
6
6
  }>(endpoint: E, options: {
7
7
  args: readonly [
@@ -10,8 +10,8 @@ export default function createReceive<E extends EndpointInterface & {
10
10
  response: Error;
11
11
  fetchedAt?: number;
12
12
  error: true;
13
- }): CompatibleReceiveAction<E>;
14
- export default function createReceive<E extends EndpointInterface & {
13
+ }): SetAction<E>;
14
+ export default function createSet<E extends EndpointInterface & {
15
15
  update?: EndpointUpdateFunction<E>;
16
16
  }>(endpoint: E, options: {
17
17
  args: readonly [
@@ -20,5 +20,5 @@ export default function createReceive<E extends EndpointInterface & {
20
20
  response: ResolveType<E>;
21
21
  fetchedAt?: number;
22
22
  error?: false;
23
- }): CompatibleReceiveAction<E>;
24
- //# sourceMappingURL=createReceive.d.ts.map
23
+ }): SetAction<E>;
24
+ //# sourceMappingURL=createSet.d.ts.map
@@ -1,13 +1,13 @@
1
1
  import { EndpointInterface } from '@data-client/normalizr';
2
- import { CompatibleSubscribeAction, CompatibleUnsubscribeAction } from '../compatibleActions.js';
2
+ import { SubscribeAction, UnsubscribeAction } from '../types.js';
3
3
  export declare function createSubscription<E extends EndpointInterface>(endpoint: E, { args }: {
4
4
  args: readonly [
5
5
  ...Parameters<E>
6
6
  ];
7
- }): CompatibleSubscribeAction<E>;
7
+ }): SubscribeAction<E>;
8
8
  export declare function createUnsubscription<E extends EndpointInterface>(endpoint: E, { args }: {
9
9
  args: readonly [
10
10
  ...Parameters<E>
11
11
  ];
12
- }): CompatibleUnsubscribeAction<E>;
12
+ }): UnsubscribeAction<E>;
13
13
  //# sourceMappingURL=createSubscription.d.ts.map
package/ts3.4/index.d.ts CHANGED
@@ -4,19 +4,14 @@ export { NetworkError, UnknownError, ErrorTypes, Schema, EndpointInterface, Enti
4
4
  export { ExpiryStatus } from '@data-client/normalizr';
5
5
  export { default as NetworkManager, ResetError, } from './manager/NetworkManager.js';
6
6
  export { default as createReducer, initialState, } from './state/reducer/createReducer.js';
7
- export { default as reducer } from './state/reducerInstance.js';
8
7
  export { default as applyManager } from './manager/applyManager.js';
9
8
  export { default as Controller } from './controller/Controller.js';
10
- export { CompatibleDispatch, GenericDispatch, } from './controller/Controller.js';
9
+ export { DataClientDispatch, GenericDispatch, } from './controller/Controller.js';
11
10
  export { default as createFetch } from './controller/createFetch.js';
12
- export { default as createReceive } from './controller/createReceive.js';
11
+ export { default as createReceive } from './controller/createSet.js';
13
12
  export * from './controller/types.js';
14
- import * as legacyActions_1 from './state/legacy-actions/index.js';
15
- export { legacyActions_1 as legacyActions };
16
13
  import * as actionTypes_1 from './actionTypes.js';
17
14
  export { actionTypes_1 as actionTypes };
18
15
  export * from './types.js';
19
- export { FetchShape, ReadShape, MutateShape, DeleteShape, } from './endpoint/shapes.js';
20
- export { SetShapeParams, ParamsFromShape, BodyFromShape, ReturnFromShape, } from './endpoint/types.js';
21
16
  export * from './manager/index.js';
22
17
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- export { inferResults, DELETED } from '@data-client/normalizr';
1
+ export { inferResults, DELETED, INVALID } from '@data-client/normalizr';
2
2
  export { default as RIC } from './state/RIC.js';
3
3
  export { initialState } from './state/reducer/createReducer.js';
4
4
  //# sourceMappingURL=internal.d.ts.map
@@ -6,7 +6,7 @@ export { DevToolsConfig };
6
6
  *
7
7
  * Options: https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md
8
8
  *
9
- * @see https://resthooks.io/docs/api/DevToolsManager
9
+ * @see https://dataclient.io/docs/api/DevToolsManager
10
10
  */
11
11
  export default class DevToolsManager implements Manager {
12
12
  protected middleware: Middleware;
@@ -1,12 +1,11 @@
1
1
  import Controller from '../controller/Controller.js';
2
2
  import { UnknownError } from '../index.js';
3
- import { CombinedActionTypes } from '../types.js';
4
- import { Manager } from '../types.js';
3
+ import { ActionTypes, Manager } from '../types.js';
5
4
  /** Handling network unauthorized indicators like HTTP 401
6
5
  *
7
- * @see https://resthooks.io/docs/api/LogoutManager
6
+ * @see https://dataclient.io/docs/api/LogoutManager
8
7
  */
9
- export default class LogoutManager implements Manager<CombinedActionTypes> {
8
+ export default class LogoutManager implements Manager {
10
9
  protected middleware: Middleware;
11
10
  constructor({ handleLogout, shouldLogout }?: Props);
12
11
  cleanup(): void;
@@ -14,7 +13,7 @@ export default class LogoutManager implements Manager<CombinedActionTypes> {
14
13
  protected shouldLogout(error: UnknownError): boolean;
15
14
  handleLogout(controller: Controller<Dispatch>): void;
16
15
  }
17
- type Dispatch = (value: CombinedActionTypes) => Promise<void>;
16
+ type Dispatch = (value: ActionTypes) => Promise<void>;
18
17
  export type Middleware = <C extends Controller<Dispatch>>(controller: C) => (next: C['dispatch']) => C['dispatch'];
19
18
  type HandleLogout = (controller: Controller<Dispatch>) => void;
20
19
  interface Props {
@@ -1,5 +1,5 @@
1
1
  import Controller from '../controller/Controller.js';
2
- import { FetchAction, ReceiveAction, Manager, ActionTypes, Middleware, State } from '../types.js';
2
+ import { FetchAction, Manager, ActionTypes, Middleware, SetAction } from '../types.js';
3
3
  export declare class ResetError extends Error {
4
4
  name: string;
5
5
  constructor();
@@ -11,7 +11,7 @@ export declare class ResetError extends Error {
11
11
  *
12
12
  * Interfaces with store via a redux-compatible middleware.
13
13
  *
14
- * @see https://resthooks.io/docs/api/NetworkManager
14
+ * @see https://dataclient.io/docs/api/NetworkManager
15
15
  */
16
16
  export default class NetworkManager implements Manager {
17
17
  protected fetched: {
@@ -29,7 +29,6 @@ export default class NetworkManager implements Manager {
29
29
  readonly dataExpiryLength: number;
30
30
  readonly errorExpiryLength: number;
31
31
  protected middleware: Middleware;
32
- protected getState: () => State<unknown>;
33
32
  protected controller: Controller;
34
33
  cleanupDate?: number;
35
34
  constructor(dataExpiryLength?: number, errorExpiryLength?: number);
@@ -53,12 +52,12 @@ export default class NetworkManager implements Manager {
53
52
  * Uses throttle only when instructed by action meta. This is valuable
54
53
  * for ensures mutation requests always go through.
55
54
  */
56
- protected handleFetch(action: FetchAction, dispatch: (action: any) => Promise<void>, controller: Controller): Promise<any>;
55
+ protected handleFetch(action: FetchAction): Promise<any>;
57
56
  /** Called when middleware intercepts a receive action.
58
57
  *
59
58
  * Will resolve the promise associated with receive key.
60
59
  */
61
- protected handleReceive(action: ReceiveAction): void;
60
+ protected handleReceive(action: SetAction): void;
62
61
  /** Attaches NetworkManager to store
63
62
  *
64
63
  * Intercepts 'rest-hooks/fetch' actions to start requests.
@@ -1,27 +1,27 @@
1
- import { Schema } from '@data-client/normalizr';
1
+ import { EndpointInterface } from '@data-client/normalizr';
2
2
  import ConnectionListener from './ConnectionListener.js';
3
- import { Subscription, SubscriptionInit } from './SubscriptionManager.js';
4
- import { State, Dispatch } from '../types.js';
3
+ import { Subscription } from './SubscriptionManager.js';
4
+ import Controller from '../controller/Controller.js';
5
+ import { SubscribeAction } from '../types.js';
5
6
  /**
6
7
  * PollingSubscription keeps a given resource updated by
7
8
  * dispatching a fetch at a rate equal to the minimum update
8
9
  * interval requested.
9
10
  *
10
- * @see https://resthooks.io/docs/api/PollingSubscription
11
+ * @see https://dataclient.io/docs/api/PollingSubscription
11
12
  */
12
13
  export default class PollingSubscription implements Subscription {
13
- protected readonly schema: Schema | undefined;
14
- protected readonly fetch: () => Promise<any>;
14
+ protected readonly endpoint: EndpointInterface;
15
+ protected readonly args: readonly any[];
15
16
  protected readonly key: string;
16
17
  protected frequency: number;
17
18
  protected frequencyHistogram: Map<number, number>;
18
- protected dispatch: Dispatch<any>;
19
- protected getState: () => State<unknown>;
19
+ protected controller: Controller;
20
20
  protected intervalId?: ReturnType<typeof setInterval>;
21
21
  protected lastIntervalId?: ReturnType<typeof setInterval>;
22
22
  protected startId?: ReturnType<typeof setTimeout>;
23
23
  private connectionListener;
24
- constructor({ key, schema, fetch, frequency, getState }: SubscriptionInit, dispatch: Dispatch<any>, connectionListener?: ConnectionListener);
24
+ constructor(action: Pick<SubscribeAction, Exclude<keyof SubscribeAction, 'type'>>, controller: Controller, connectionListener?: ConnectionListener);
25
25
  /** Subscribe to a frequency */
26
26
  add(frequency?: number): void;
27
27
  /** Unsubscribe from a frequency */
@@ -1,13 +1,6 @@
1
- import { Schema } from '@data-client/normalizr';
2
- import { Manager, State, Middleware, Dispatch, UnsubscribeAction, SubscribeAction } from '../types.js';
3
- /** Properties sent to Subscription constructor */
4
- export interface SubscriptionInit {
5
- schema?: Schema | undefined;
6
- fetch: () => Promise<any>;
7
- key: string;
8
- getState: () => State<unknown>;
9
- frequency?: number | undefined;
10
- }
1
+ import Controller from '../controller/Controller.js';
2
+ import { Manager, Middleware, UnsubscribeAction, SubscribeAction } from '../types.js';
3
+ type Actions = UnsubscribeAction | SubscribeAction;
11
4
  /** Interface handling a single resource subscription */
12
5
  export interface Subscription {
13
6
  add(frequency?: number): void;
@@ -16,32 +9,33 @@ export interface Subscription {
16
9
  }
17
10
  /** The static class that constructs Subscription */
18
11
  export interface SubscriptionConstructable {
19
- new (init: SubscriptionInit, dispatch: Dispatch<any>): Subscription;
12
+ new (action: Pick<SubscribeAction, Exclude<keyof SubscribeAction, 'type'>>, controller: Controller): Subscription;
20
13
  }
21
14
  /** Handles subscription actions -> fetch or receive actions
22
15
  *
23
16
  * Constructor takes a SubscriptionConstructable class to control how
24
17
  * subscriptions are handled. (e.g., polling, websockets)
25
18
  *
26
- * @see https://resthooks.io/docs/api/SubscriptionManager
19
+ * @see https://dataclient.io/docs/api/SubscriptionManager
27
20
  */
28
- export default class SubscriptionManager<S extends SubscriptionConstructable> implements Manager {
21
+ export default class SubscriptionManager<S extends SubscriptionConstructable> implements Manager<Actions> {
29
22
  protected subscriptions: {
30
23
  [key: string]: InstanceType<S>;
31
24
  };
32
25
  protected readonly Subscription: S;
33
26
  protected middleware: Middleware;
27
+ protected controller: Controller;
34
28
  constructor(Subscription: S);
35
29
  /** Ensures all subscriptions are cleaned up. */
36
30
  cleanup(): void;
37
31
  /** Called when middleware intercepts 'rest-hooks/subscribe' action.
38
32
  *
39
33
  */
40
- protected handleSubscribe(action: SubscribeAction, dispatch: (action: any) => Promise<void>, getState: () => State<unknown>): void;
34
+ protected handleSubscribe(action: SubscribeAction): void;
41
35
  /** Called when middleware intercepts 'rest-hooks/unsubscribe' action.
42
36
  *
43
37
  */
44
- protected handleUnsubscribe(action: UnsubscribeAction, dispatch: (action: any) => Promise<void>): void;
38
+ protected handleUnsubscribe(action: UnsubscribeAction): void;
45
39
  /** Attaches Manager to store
46
40
  *
47
41
  * Intercepts 'rest-hooks/subscribe'/'rest-hooks/unsubscribe' to register resources that
@@ -52,4 +46,5 @@ export default class SubscriptionManager<S extends SubscriptionConstructable> im
52
46
  */
53
47
  getMiddleware(): Middleware;
54
48
  }
49
+ export {};
55
50
  //# sourceMappingURL=SubscriptionManager.d.ts.map
@@ -1,11 +1,11 @@
1
1
  import Controller from './controller/Controller.js';
2
- import { ActionTypes } from './newActions.js';
3
- import { ActionTypes as LegacyActionTypes, CombinedActionTypes, State } from './types.js';
2
+ import { ActionTypes, State } from './types.js';
4
3
  type RHDispatch<Actions = any> = (value: Actions) => Promise<void>;
5
- export interface MiddlewareAPI<R extends RestHooksReducer = RestHooksReducer> extends Controller<RHDispatch<CombinedActionTypes>> {
6
- controller: Controller<RHDispatch<CombinedActionTypes>>;
4
+ export interface MiddlewareAPI<R extends RestHooksReducer = RestHooksReducer> extends Controller<RHDispatch<ActionTypes>> {
5
+ /** @deprecated use members directly instead */
6
+ controller: Controller<RHDispatch<ActionTypes>>;
7
7
  }
8
- export interface MiddlewareController<Actions = LegacyActionTypes> extends Controller<RHDispatch<Actions>> {
8
+ export interface MiddlewareController<Actions = ActionTypes> extends Controller<RHDispatch<Actions>> {
9
9
  controller: Controller<RHDispatch<Actions>>;
10
10
  }
11
11
  export type Middleware<Actions = any> = <C extends MiddlewareController<Actions>>(controller: C) => (next: C['dispatch']) => C['dispatch'];