@data-client/core 0.4.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/data_client_logo_and_text.svg +50 -0
  2. package/dist/index.js +66 -92
  3. package/dist/index.umd.min.js +1 -1
  4. package/dist/next.js +0 -447
  5. package/legacy/actionTypes.js +11 -13
  6. package/legacy/actions.js +2 -0
  7. package/legacy/controller/Controller.js +26 -42
  8. package/legacy/controller/createSet.js +3 -2
  9. package/legacy/controller/ensurePojo.js +7 -0
  10. package/legacy/index.js +2 -2
  11. package/legacy/internal.js +2 -2
  12. package/legacy/manager/DevtoolsManager.js +3 -3
  13. package/legacy/manager/NetworkManager.js +11 -11
  14. package/legacy/manager/SubscriptionManager.js +6 -6
  15. package/legacy/manager/applyManager.js +2 -9
  16. package/legacy/middlewareTypes.js +1 -1
  17. package/legacy/next/index.js +2 -3
  18. package/legacy/state/reducer/fetchReducer.js +5 -5
  19. package/legacy/state/reducer/setReducer.js +2 -2
  20. package/legacy/types.js +3 -4
  21. package/lib/actionTypes.d.ts +10 -12
  22. package/lib/actionTypes.d.ts.map +1 -1
  23. package/lib/actionTypes.js +11 -13
  24. package/lib/{newActions.d.ts → actions.d.ts} +1 -3
  25. package/lib/actions.d.ts.map +1 -0
  26. package/lib/actions.js +2 -0
  27. package/lib/controller/Controller.d.ts +20 -33
  28. package/lib/controller/Controller.d.ts.map +1 -1
  29. package/lib/controller/Controller.js +26 -42
  30. package/lib/controller/createSet.d.ts.map +1 -1
  31. package/lib/controller/createSet.js +3 -2
  32. package/lib/controller/ensurePojo.d.ts +3 -0
  33. package/lib/controller/ensurePojo.d.ts.map +1 -0
  34. package/lib/controller/ensurePojo.js +7 -0
  35. package/lib/index.d.ts +1 -1
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +2 -2
  38. package/lib/internal.d.ts +1 -1
  39. package/lib/internal.d.ts.map +1 -1
  40. package/lib/internal.js +2 -2
  41. package/lib/manager/DevtoolsManager.js +3 -3
  42. package/lib/manager/NetworkManager.d.ts +6 -6
  43. package/lib/manager/NetworkManager.d.ts.map +1 -1
  44. package/lib/manager/NetworkManager.js +11 -11
  45. package/lib/manager/SubscriptionManager.d.ts +5 -5
  46. package/lib/manager/SubscriptionManager.js +6 -6
  47. package/lib/manager/applyManager.d.ts.map +1 -1
  48. package/lib/manager/applyManager.js +2 -9
  49. package/lib/middlewareTypes.d.ts +2 -5
  50. package/lib/middlewareTypes.d.ts.map +1 -1
  51. package/lib/middlewareTypes.js +1 -1
  52. package/lib/next/index.d.ts +0 -2
  53. package/lib/next/index.d.ts.map +1 -1
  54. package/lib/next/index.js +2 -3
  55. package/lib/state/reducer/expireReducer.d.ts +1 -1
  56. package/lib/state/reducer/fetchReducer.js +5 -5
  57. package/lib/state/reducer/invalidateReducer.d.ts +1 -1
  58. package/lib/state/reducer/setReducer.d.ts +2 -2
  59. package/lib/state/reducer/setReducer.d.ts.map +1 -1
  60. package/lib/state/reducer/setReducer.js +2 -2
  61. package/lib/types.d.ts +3 -4
  62. package/lib/types.d.ts.map +1 -1
  63. package/lib/types.js +3 -4
  64. package/package.json +3 -3
  65. package/src/actionTypes.ts +10 -12
  66. package/src/{newActions.ts → actions.ts} +1 -6
  67. package/src/controller/Controller.ts +27 -55
  68. package/src/controller/createSet.ts +2 -1
  69. package/src/controller/ensurePojo.ts +11 -0
  70. package/src/index.ts +1 -1
  71. package/src/internal.ts +1 -1
  72. package/src/manager/DevtoolsManager.ts +2 -2
  73. package/src/manager/NetworkManager.ts +10 -10
  74. package/src/manager/SubscriptionManager.ts +5 -5
  75. package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +2 -2
  76. package/src/manager/__tests__/logoutManager.ts +2 -2
  77. package/src/manager/__tests__/manager.ts +1 -1
  78. package/src/manager/__tests__/networkManager.ts +13 -16
  79. package/src/manager/applyManager.ts +1 -6
  80. package/src/middlewareTypes.ts +4 -9
  81. package/src/next/index.ts +0 -2
  82. package/src/state/__tests__/__snapshots__/reducer.ts.snap +1 -1
  83. package/src/state/__tests__/reducer.ts +27 -9
  84. package/src/state/reducer/fetchReducer.ts +5 -5
  85. package/src/state/reducer/setReducer.ts +5 -5
  86. package/src/types.ts +3 -4
  87. package/ts3.4/actionTypes.d.ts +10 -12
  88. package/ts3.4/{newActions.d.ts → actions.d.ts} +1 -3
  89. package/ts3.4/controller/Controller.d.ts +20 -39
  90. package/ts3.4/controller/ensurePojo.d.ts +3 -0
  91. package/ts3.4/index.d.ts +1 -1
  92. package/ts3.4/internal.d.ts +1 -1
  93. package/ts3.4/manager/NetworkManager.d.ts +6 -6
  94. package/ts3.4/manager/SubscriptionManager.d.ts +5 -5
  95. package/ts3.4/middlewareTypes.d.ts +2 -5
  96. package/ts3.4/next/index.d.ts +0 -2
  97. package/ts3.4/state/reducer/expireReducer.d.ts +1 -1
  98. package/ts3.4/state/reducer/invalidateReducer.d.ts +1 -1
  99. package/ts3.4/state/reducer/setReducer.d.ts +2 -2
  100. package/ts3.4/types.d.ts +3 -5
  101. package/legacy/fsa.js +0 -2
  102. package/legacy/newActions.js +0 -2
  103. package/lib/fsa.d.ts +0 -41
  104. package/lib/fsa.d.ts.map +0 -1
  105. package/lib/fsa.js +0 -2
  106. package/lib/newActions.d.ts.map +0 -1
  107. package/lib/newActions.js +0 -2
  108. package/src/fsa.ts +0 -99
  109. package/ts3.4/fsa.d.ts +0 -41
@@ -71,12 +71,9 @@ describe('NetworkManager', () => {
71
71
  return updates;
72
72
  },
73
73
  });
74
- const fetchReceiveWithUpdatersAction = createFetch(
75
- detailWithUpdaterEndpoint,
76
- {
77
- args: [{ id: 5 }],
78
- },
79
- );
74
+ const fetchSetWithUpdatersAction = createFetch(detailWithUpdaterEndpoint, {
75
+ args: [{ id: 5 }],
76
+ });
80
77
 
81
78
  const updateShape = new Endpoint(
82
79
  (params: any, body: any) => Promise.resolve(body),
@@ -158,7 +155,7 @@ describe('NetworkManager', () => {
158
155
 
159
156
  const data = await fetchResolveAction.payload();
160
157
 
161
- // mutations resolve before dispatch, so we must wait for next tick to see receive
158
+ // mutations resolve before dispatch, so we must wait for next tick to see set
162
159
  await new Promise(resolve => setTimeout(resolve, 0));
163
160
 
164
161
  const action = {
@@ -176,7 +173,7 @@ describe('NetworkManager', () => {
176
173
  expect(dispatch).toHaveBeenCalledWith(action);
177
174
  expect(next).not.toHaveBeenCalledWith(action);
178
175
  });
179
- it('should handle fetch receive action and dispatch on success with updaters', async () => {
176
+ it('should handle fetch set action and dispatch on success with updaters', async () => {
180
177
  const next = jest.fn();
181
178
  const dispatch = jest.fn();
182
179
  const controller = new Controller({ dispatch, getState });
@@ -187,20 +184,20 @@ describe('NetworkManager', () => {
187
184
  },
188
185
  );
189
186
 
190
- middleware(API)(next)(fetchReceiveWithUpdatersAction);
187
+ middleware(API)(next)(fetchSetWithUpdatersAction);
191
188
 
192
- const data = await fetchReceiveWithUpdatersAction.payload();
189
+ const data = await fetchSetWithUpdatersAction.payload();
193
190
 
194
- // mutations resolve before dispatch, so we must wait for next tick to see receive
191
+ // mutations resolve before dispatch, so we must wait for next tick to see set
195
192
  await new Promise(resolve => setTimeout(resolve, 0));
196
193
 
197
194
  const action = {
198
195
  type: SET_TYPE,
199
- endpoint: fetchReceiveWithUpdatersAction.endpoint,
196
+ endpoint: fetchSetWithUpdatersAction.endpoint,
200
197
  payload: data,
201
198
  meta: {
202
- args: fetchReceiveWithUpdatersAction.meta.args,
203
- key: fetchReceiveWithUpdatersAction.meta.key,
199
+ args: fetchSetWithUpdatersAction.meta.args,
200
+ key: fetchSetWithUpdatersAction.meta.key,
204
201
  date: expect.any(Number),
205
202
  expiresAt: expect.any(Number),
206
203
  fetchedAt: expect.any(Number),
@@ -224,7 +221,7 @@ describe('NetworkManager', () => {
224
221
 
225
222
  const data = await fetchRpcWithUpdatersAction.payload();
226
223
 
227
- // mutations resolve before dispatch, so we must wait for next tick to see receive
224
+ // mutations resolve before dispatch, so we must wait for next tick to see set
228
225
  await new Promise(resolve => setTimeout(resolve, 0));
229
226
 
230
227
  const action = {
@@ -258,7 +255,7 @@ describe('NetworkManager', () => {
258
255
  const data = await fetchRpcWithUpdatersAndOptimisticAction.payload();
259
256
 
260
257
  expect(next).toHaveBeenCalled();
261
- // mutations resolve before dispatch, so we must wait for next tick to see receive
258
+ // mutations resolve before dispatch, so we must wait for next tick to see set
262
259
  await new Promise(resolve => setTimeout(resolve, 0));
263
260
  expect(dispatch).toHaveBeenCalledWith({
264
261
  type: SET_TYPE,
@@ -8,16 +8,11 @@ export default function applyManager(
8
8
  ): Middleware[] {
9
9
  return managers.map(manager => {
10
10
  const middleware = manager.getMiddleware();
11
- // TODO(breaking): remove this once controller prop is no longer supported
12
11
  return ({ dispatch, getState }) => {
13
12
  (controller as any).dispatch = dispatch;
14
13
  (controller as any).getState = getState;
15
- // this is needed for backwards compatibility as we added 'controller' prop previously
16
- const API = Object.create(controller, {
17
- controller: { value: controller },
18
- });
19
14
  // controller is a superset of the middleware API
20
- return middleware(API);
15
+ return middleware(controller as Controller<any>);
21
16
  };
22
17
  });
23
18
  }
@@ -3,15 +3,10 @@ import { ActionTypes, State } from './types.js';
3
3
 
4
4
  type RHDispatch<Actions = any> = (value: Actions) => Promise<void>;
5
5
 
6
- export interface MiddlewareAPI<R extends RestHooksReducer = RestHooksReducer>
7
- extends Controller<RHDispatch<ActionTypes>> {
8
- /** @deprecated use members directly instead */
9
- controller: Controller<RHDispatch<ActionTypes>>;
10
- }
6
+ export interface MiddlewareAPI<R extends DataClientReducer = DataClientReducer>
7
+ extends Controller<RHDispatch<ActionTypes>> {}
11
8
  export interface MiddlewareController<Actions = ActionTypes>
12
- extends Controller<RHDispatch<Actions>> {
13
- controller: Controller<RHDispatch<Actions>>;
14
- }
9
+ extends Controller<RHDispatch<Actions>> {}
15
10
 
16
11
  export type Middleware<Actions = any> = <
17
12
  C extends MiddlewareController<Actions>,
@@ -19,7 +14,7 @@ export type Middleware<Actions = any> = <
19
14
  controller: C,
20
15
  ) => (next: C['dispatch']) => C['dispatch'];
21
16
 
22
- export type RestHooksReducer = (
17
+ export type DataClientReducer = (
23
18
  prevState: State<unknown>,
24
19
  action: ActionTypes,
25
20
  ) => State<unknown>;
package/src/next/index.ts CHANGED
@@ -1,2 +0,0 @@
1
- export { default as Controller } from '../controller/Controller.js';
2
- export * from '../controller/Controller.js';
@@ -1,6 +1,6 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`reducer should set error in meta for "receive" 1`] = `
3
+ exports[`reducer should set error in meta for "set" 1`] = `
4
4
  {
5
5
  "entities": {},
6
6
  "entityMeta": {},
@@ -143,20 +143,38 @@ describe('reducer', () => {
143
143
  expect(nextMeta.date).toBe(action.meta.date);
144
144
  });
145
145
 
146
- it('should use entity.expiresAt()', () => {
146
+ it('should use entity.mergeMetaWithStore()', () => {
147
147
  class ExpiresSoon extends Article {
148
148
  static get key() {
149
149
  return Article.key;
150
150
  }
151
151
 
152
- static expiresAt(
153
- { expiresAt, date }: { expiresAt: number; date: number },
154
- input: any,
155
- ): number {
156
- return input.content ? expiresAt : 0;
152
+ static mergeMetaWithStore(
153
+ existingMeta: {
154
+ expiresAt: number;
155
+ date: number;
156
+ fetchedAt: number;
157
+ },
158
+ incomingMeta: { expiresAt: number; date: number; fetchedAt: number },
159
+ existing: any,
160
+ incoming: any,
161
+ ) {
162
+ return this.shouldReorder(
163
+ existingMeta,
164
+ incomingMeta,
165
+ existing,
166
+ incoming,
167
+ )
168
+ ? existingMeta
169
+ : {
170
+ ...incomingMeta,
171
+ expiresAt: incoming.content
172
+ ? incomingMeta.expiresAt
173
+ : existingMeta.expiresAt,
174
+ };
157
175
  }
158
176
  }
159
- const spy = jest.spyOn(ExpiresSoon, 'expiresAt');
177
+ const spy = jest.spyOn(ExpiresSoon, 'mergeMetaWithStore');
160
178
  const localAction = {
161
179
  ...partialResultAction,
162
180
  endpoint: (partialResultAction.endpoint as any).extend({
@@ -401,7 +419,7 @@ describe('reducer', () => {
401
419
  expectedMeta['20'] = { expiresAt: 0, invalidated: true };
402
420
  expect(newState.meta).toEqual(expectedMeta);
403
421
  });
404
- it('should set error in meta for "receive"', () => {
422
+ it('should set error in meta for "set"', () => {
405
423
  const id = 20;
406
424
  const error = new Error('hi');
407
425
  const action: SetAction = {
@@ -472,7 +490,7 @@ describe('reducer', () => {
472
490
  const newState = reducer(iniState, action);
473
491
  expect(newState.entities).toBe(iniState.entities);
474
492
  });
475
- it('rest-hooks/fetch should console.warn()', () => {
493
+ it('rdc/fetch should console.warn()', () => {
476
494
  const warnspy = jest
477
495
  .spyOn(global.console, 'warn')
478
496
  .mockImplementation(() => {});
@@ -1,16 +1,16 @@
1
1
  import createOptimistic from '../../controller/createOptimistic.js';
2
2
  import type {
3
3
  State,
4
- ReceiveAction,
4
+ SetAction,
5
5
  OptimisticAction,
6
6
  FetchAction,
7
7
  } from '../../types.js';
8
8
 
9
9
  export function fetchReducer(state: State<unknown>, action: FetchAction) {
10
- let receiveAction: ReceiveAction | OptimisticAction;
10
+ let setAction: SetAction | OptimisticAction;
11
11
 
12
12
  if (action.endpoint.getOptimisticResponse && action.endpoint.sideEffect) {
13
- receiveAction = createOptimistic(action.endpoint, {
13
+ setAction = createOptimistic(action.endpoint, {
14
14
  args: action.meta.args,
15
15
  fetchedAt: action.meta.createdAt,
16
16
  });
@@ -22,7 +22,7 @@ export function fetchReducer(state: State<unknown>, action: FetchAction) {
22
22
  'Fetch appears unhandled - you are likely missing the NetworkManager middleware',
23
23
  );
24
24
  console.warn(
25
- 'See https://resthooks.io/docs/guides/redux#indextsx for hooking up redux',
25
+ 'See https://dataclient.io/docs/guides/redux#indextsx for hooking up redux',
26
26
  );
27
27
  }
28
28
 
@@ -30,6 +30,6 @@ export function fetchReducer(state: State<unknown>, action: FetchAction) {
30
30
  }
31
31
  return {
32
32
  ...state,
33
- optimistic: [...state.optimistic, receiveAction],
33
+ optimistic: [...state.optimistic, setAction],
34
34
  };
35
35
  }
@@ -2,11 +2,11 @@ import { normalize } from '@data-client/normalizr';
2
2
 
3
3
  import { OPTIMISTIC_TYPE } from '../../actionTypes.js';
4
4
  import type Controller from '../../controller/Controller.js';
5
- import type { State, ReceiveAction, OptimisticAction } from '../../types.js';
5
+ import type { State, SetAction, OptimisticAction } from '../../types.js';
6
6
 
7
7
  export function setReducer(
8
8
  state: State<unknown>,
9
- action: OptimisticAction | ReceiveAction,
9
+ action: OptimisticAction | SetAction,
10
10
  controller: Controller,
11
11
  ) {
12
12
  if (action.error) {
@@ -14,7 +14,7 @@ export function setReducer(
14
14
  }
15
15
  try {
16
16
  let payload: any;
17
- // for true receives payload is contained in action
17
+ // for true set's payload is contained in action
18
18
  if (action.type === OPTIMISTIC_TYPE) {
19
19
  // this should never happen
20
20
  if (!action.endpoint.getOptimisticResponse) return state;
@@ -104,7 +104,7 @@ export function setReducer(
104
104
 
105
105
  function reduceError(
106
106
  state: State<unknown>,
107
- action: ReceiveAction | OptimisticAction,
107
+ action: SetAction | OptimisticAction,
108
108
  error: any,
109
109
  ): State<unknown> {
110
110
  if (error.name === 'AbortError') {
@@ -133,7 +133,7 @@ function reduceError(
133
133
  /** Filter all requests with same serialization that did not start after the resolving request */
134
134
  function filterOptimistic(
135
135
  state: State<unknown>,
136
- resolvingAction: ReceiveAction | OptimisticAction,
136
+ resolvingAction: SetAction | OptimisticAction,
137
137
  ) {
138
138
  return state.optimistic.filter(
139
139
  optimisticAction =>
package/src/types.ts CHANGED
@@ -5,13 +5,13 @@ import type {
5
5
  } from '@data-client/normalizr';
6
6
  import type { ErrorTypes } from '@data-client/normalizr';
7
7
 
8
+ import type { ActionTypes, SetAction, OptimisticAction } from './actions.js';
8
9
  import { SET_TYPE } from './actionTypes.js';
9
10
  import type { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
10
- import type { ActionTypes, SetAction, OptimisticAction } from './newActions.js';
11
11
 
12
12
  export type { AbstractInstanceType, UpdateFunction };
13
13
 
14
- export type ReceiveTypes = typeof SET_TYPE;
14
+ export type SetTypes = typeof SET_TYPE;
15
15
 
16
16
  export type PK = string;
17
17
 
@@ -44,8 +44,7 @@ export interface State<T> {
44
44
  readonly lastReset: number;
45
45
  }
46
46
 
47
- export * as newActions from './newActions.js';
48
- export * from './newActions.js';
47
+ export * from './actions.js';
49
48
 
50
49
  export interface Manager<Actions = ActionTypes> {
51
50
  getMiddleware(): Middleware<Actions>;
@@ -1,13 +1,11 @@
1
- export declare const FETCH_TYPE: "rest-hooks/fetch";
2
- /** @deprecated use SET_TYPE instead */
3
- export declare const RECEIVE_TYPE: "rest-hooks/receive";
4
- export declare const SET_TYPE: "rest-hooks/receive";
5
- export declare const OPTIMISTIC_TYPE: "rest-hooks/optimistic";
6
- export declare const RESET_TYPE: "rest-hooks/reset";
7
- export declare const SUBSCRIBE_TYPE: "rest-hooks/subscribe";
8
- export declare const UNSUBSCRIBE_TYPE: "rest-hook/unsubscribe";
9
- export declare const INVALIDATE_TYPE: "rest-hooks/invalidate";
10
- export declare const INVALIDATEALL_TYPE: "rest-hooks/invalidateall";
11
- export declare const EXPIREALL_TYPE: "rest-hooks/expireall";
12
- export declare const GC_TYPE: "rest-hooks/gc";
1
+ export declare const FETCH_TYPE: "rdc/fetch";
2
+ export declare const SET_TYPE: "rdc/set";
3
+ export declare const OPTIMISTIC_TYPE: "rdc/optimistic";
4
+ export declare const RESET_TYPE: "rdc/reset";
5
+ export declare const SUBSCRIBE_TYPE: "rdc/subscribe";
6
+ export declare const UNSUBSCRIBE_TYPE: "rdc/unsubscribe";
7
+ export declare const INVALIDATE_TYPE: "rdc/invalidate";
8
+ export declare const INVALIDATEALL_TYPE: "rdc/invalidateall";
9
+ export declare const EXPIREALL_TYPE: "rdc/expireall";
10
+ export declare const GC_TYPE: "rdc/gc";
13
11
  //# sourceMappingURL=actionTypes.d.ts.map
@@ -29,8 +29,6 @@ export interface SetActionError<E extends EndpointAndUpdate<E> = EndpointDefault
29
29
  error: true;
30
30
  }
31
31
  export type SetAction<E extends EndpointAndUpdate<E> = EndpointDefault> = SetActionSuccess<E> | SetActionError<E>;
32
- /** @deprecated use SetAction instead */
33
- export type ReceiveAction<E extends EndpointAndUpdate<E> = EndpointDefault> = SetAction<E>;
34
32
  export interface FetchMeta {
35
33
  args: readonly any[];
36
34
  key: string;
@@ -97,4 +95,4 @@ export interface GCAction {
97
95
  }
98
96
  export type ActionTypes = FetchAction | OptimisticAction | SetAction | SubscribeAction | UnsubscribeAction | InvalidateAction | InvalidateAllAction | ExpireAllAction | ResetAction | GCAction;
99
97
  export {};
100
- //# sourceMappingURL=newActions.d.ts.map
98
+ //# sourceMappingURL=actions.d.ts.map
@@ -10,14 +10,14 @@ interface ConstructorProps<D extends GenericDispatch = DataClientDispatch> {
10
10
  globalCache?: DenormalizeCache;
11
11
  }
12
12
  /**
13
- * Imperative control of Rest Hooks store
14
- * @see https://resthooks.io/docs/api/Controller
13
+ * Imperative control of Reactive Data Client store
14
+ * @see https://dataclient.io/docs/api/Controller
15
15
  */
16
16
  export default class Controller<D extends GenericDispatch = DataClientDispatch> {
17
17
  /**
18
- * Dispatches an action to Rest Hooks reducer.
18
+ * Dispatches an action to Reactive Data Client reducer.
19
19
  *
20
- * @see https://resthooks.io/docs/api/Controller#dispatch
20
+ * @see https://dataclient.io/docs/api/Controller#dispatch
21
21
  */
22
22
  readonly dispatch: D;
23
23
  /**
@@ -25,15 +25,15 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
25
25
  *
26
26
  * This can be useful for imperative use-cases like event handlers.
27
27
  * This should *not* be used to render; instead useSuspense() or useCache()
28
- * @see https://resthooks.io/docs/api/Controller#getState
28
+ * @see https://dataclient.io/docs/api/Controller#getState
29
29
  */
30
30
  readonly getState: () => State<unknown>;
31
31
  readonly globalCache: DenormalizeCache;
32
32
  constructor({ dispatch, getState, globalCache, }?: ConstructorProps<D>);
33
33
  /*************** Action Dispatchers ***************/
34
34
  /**
35
- * Fetches the endpoint with given args, updating the Rest Hooks cache with the response or error upon completion.
36
- * @see https://resthooks.io/docs/api/Controller#fetch
35
+ * Fetches the endpoint with given args, updating the Reactive Data Client cache with the response or error upon completion.
36
+ * @see https://dataclient.io/docs/api/Controller#fetch
37
37
  */
38
38
  fetch: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
39
39
  update?: EndpointUpdateFunction<E> | undefined;
@@ -47,7 +47,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
47
47
  }>(endpoint: E, ...args_0: Parameters<E>) => E["schema"] extends null | undefined ? ReturnType<E> | ResolveType<E> : Denormalize<E["schema"]> | Promise<Denormalize<E["schema"]>>;
48
48
  /**
49
49
  * Forces refetching and suspense on useSuspense with the same Endpoint and parameters.
50
- * @see https://resthooks.io/docs/api/Controller#invalidate
50
+ * @see https://dataclient.io/docs/api/Controller#invalidate
51
51
  */
52
52
  invalidate: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>>(endpoint: E, ...args: readonly [
53
53
  ...Parameters<E>
@@ -56,7 +56,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
56
56
  ]) => Promise<void>;
57
57
  /**
58
58
  * Forces refetching and suspense on useSuspense on all matching endpoint result keys.
59
- * @see https://resthooks.io/docs/api/Controller#invalidateAll
59
+ * @see https://dataclient.io/docs/api/Controller#invalidateAll
60
60
  * @returns Promise that resolves when invalidation is commited.
61
61
  */
62
62
  invalidateAll: (options: {
@@ -71,13 +71,13 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
71
71
  testKey: (key: string) => boolean;
72
72
  }) => Promise<void>;
73
73
  /**
74
- * Resets the entire Rest Hooks cache. All inflight requests will not resolve.
75
- * @see https://resthooks.io/docs/api/Controller#resetEntireStore
74
+ * Resets the entire Reactive Data Client cache. All inflight requests will not resolve.
75
+ * @see https://dataclient.io/docs/api/Controller#resetEntireStore
76
76
  */
77
77
  resetEntireStore: () => Promise<void>;
78
78
  /**
79
79
  * Stores response in cache for given Endpoint and args.
80
- * @see https://resthooks.io/docs/api/Controller#set
80
+ * @see https://dataclient.io/docs/api/Controller#set
81
81
  */
82
82
  setResponse: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
83
83
  update?: EndpointUpdateFunction<E> | undefined;
@@ -85,18 +85,9 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
85
85
  ...Parameters<E>,
86
86
  any
87
87
  ]) => Promise<void>;
88
- /**
89
- * @deprecated use https://resthooks.io/docs/api/Controller#setResponse instead
90
- */
91
- receive: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
92
- update?: EndpointUpdateFunction<E> | undefined;
93
- }>(endpoint: E, ...rest: readonly [
94
- ...Parameters<E>,
95
- any
96
- ]) => Promise<void>;
97
88
  /**
98
89
  * Stores the result of Endpoint and args as the error provided.
99
- * @see https://resthooks.io/docs/api/Controller#setError
90
+ * @see https://dataclient.io/docs/api/Controller#setError
100
91
  */
101
92
  setError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
102
93
  update?: EndpointUpdateFunction<E> | undefined;
@@ -104,19 +95,9 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
104
95
  ...Parameters<E>,
105
96
  Error
106
97
  ]) => Promise<void>;
107
- /**
108
- * Another name for setError
109
- * @deprecated use https://resthooks.io/docs/api/Controller#setError instead
110
- */
111
- receiveError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
112
- update?: EndpointUpdateFunction<E> | undefined;
113
- }>(endpoint: E, ...rest: readonly [
114
- ...Parameters<E>,
115
- Error
116
- ]) => Promise<void>;
117
98
  /**
118
99
  * Resolves an inflight fetch. `fetchedAt` should `fetch`'s `createdAt`
119
- * @see https://resthooks.io/docs/api/Controller#resolve
100
+ * @see https://dataclient.io/docs/api/Controller#resolve
120
101
  */
121
102
  resolve: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
122
103
  update?: EndpointUpdateFunction<E> | undefined;
@@ -137,7 +118,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
137
118
  }) => Promise<void>;
138
119
  /**
139
120
  * Marks a new subscription to a given Endpoint.
140
- * @see https://resthooks.io/docs/api/Controller#subscribe
121
+ * @see https://dataclient.io/docs/api/Controller#subscribe
141
122
  */
142
123
  subscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
143
124
  null
@@ -146,7 +127,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
146
127
  ]) => Promise<void>;
147
128
  /**
148
129
  * Marks completion of subscription to a given Endpoint.
149
- * @see https://resthooks.io/docs/api/Controller#unsubscribe
130
+ * @see https://dataclient.io/docs/api/Controller#unsubscribe
150
131
  */
151
132
  unsubscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
152
133
  null
@@ -155,13 +136,13 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
155
136
  ]) => Promise<void>;
156
137
  /*************** More ***************/
157
138
  /**
158
- * Gets a snapshot (https://resthooks.io/docs/api/Snapshot)
159
- * @see https://resthooks.io/docs/api/Controller#snapshot
139
+ * Gets a snapshot (https://dataclient.io/docs/api/Snapshot)
140
+ * @see https://dataclient.io/docs/api/Controller#snapshot
160
141
  */
161
142
  snapshot: (state: State<unknown>, fetchedAt?: number) => SnapshotInterface;
162
143
  /**
163
144
  * Gets the error, if any, for a given endpoint. Returns undefined for no errors.
164
- * @see https://resthooks.io/docs/api/Controller#getError
145
+ * @see https://dataclient.io/docs/api/Controller#getError
165
146
  */
166
147
  getError: <E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>, "key">, Args extends readonly [
167
148
  null
@@ -173,7 +154,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
173
154
  ]) => ErrorTypes | undefined;
174
155
  /**
175
156
  * Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
176
- * @see https://resthooks.io/docs/api/Controller#getResponse
157
+ * @see https://dataclient.io/docs/api/Controller#getResponse
177
158
  */
178
159
  getResponse: <E extends Pick<EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined>, "schema" | "key" | "invalidIfStale">, Args extends readonly [
179
160
  null
@@ -0,0 +1,3 @@
1
+ export declare const ensurePojo: (body: any) => any;
2
+ export default ensurePojo;
3
+ //# sourceMappingURL=ensurePojo.d.ts.map
package/ts3.4/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { default as applyManager } from './manager/applyManager.js';
8
8
  export { default as Controller } from './controller/Controller.js';
9
9
  export { DataClientDispatch, GenericDispatch, } from './controller/Controller.js';
10
10
  export { default as createFetch } from './controller/createFetch.js';
11
- export { default as createReceive } from './controller/createSet.js';
11
+ export { default as createSet } from './controller/createSet.js';
12
12
  export * from './controller/types.js';
13
13
  import * as actionTypes_1 from './actionTypes.js';
14
14
  export { actionTypes_1 as actionTypes };
@@ -1,4 +1,4 @@
1
- export { inferResults, DELETED, INVALID } from '@data-client/normalizr';
1
+ export { inferResults, 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
@@ -44,7 +44,7 @@ export default class NetworkManager implements Manager {
44
44
  /** Clear promise state for a given key */
45
45
  protected clear(key: string): void;
46
46
  protected getLastReset(): number;
47
- /** Called when middleware intercepts 'rest-hooks/fetch' action.
47
+ /** Called when middleware intercepts 'rdc/fetch' action.
48
48
  *
49
49
  * Will then start a promise for a key and potentially start the network
50
50
  * fetch.
@@ -53,16 +53,16 @@ export default class NetworkManager implements Manager {
53
53
  * for ensures mutation requests always go through.
54
54
  */
55
55
  protected handleFetch(action: FetchAction): Promise<any>;
56
- /** Called when middleware intercepts a receive action.
56
+ /** Called when middleware intercepts a set action.
57
57
  *
58
- * Will resolve the promise associated with receive key.
58
+ * Will resolve the promise associated with set key.
59
59
  */
60
- protected handleReceive(action: SetAction): void;
60
+ protected handleSet(action: SetAction): void;
61
61
  /** Attaches NetworkManager to store
62
62
  *
63
- * Intercepts 'rest-hooks/fetch' actions to start requests.
63
+ * Intercepts 'rdc/fetch' actions to start requests.
64
64
  *
65
- * Resolve/rejects a request when matching 'rest-hooks/receive' event
65
+ * Resolve/rejects a request when matching 'rdc/set' event
66
66
  * is seen.
67
67
  */
68
68
  getMiddleware(): Middleware;
@@ -11,7 +11,7 @@ export interface Subscription {
11
11
  export interface SubscriptionConstructable {
12
12
  new (action: Pick<SubscribeAction, Exclude<keyof SubscribeAction, 'type'>>, controller: Controller): Subscription;
13
13
  }
14
- /** Handles subscription actions -> fetch or receive actions
14
+ /** Handles subscription actions -> fetch or set actions
15
15
  *
16
16
  * Constructor takes a SubscriptionConstructable class to control how
17
17
  * subscriptions are handled. (e.g., polling, websockets)
@@ -28,20 +28,20 @@ export default class SubscriptionManager<S extends SubscriptionConstructable> im
28
28
  constructor(Subscription: S);
29
29
  /** Ensures all subscriptions are cleaned up. */
30
30
  cleanup(): void;
31
- /** Called when middleware intercepts 'rest-hooks/subscribe' action.
31
+ /** Called when middleware intercepts 'rdc/subscribe' action.
32
32
  *
33
33
  */
34
34
  protected handleSubscribe(action: SubscribeAction): void;
35
- /** Called when middleware intercepts 'rest-hooks/unsubscribe' action.
35
+ /** Called when middleware intercepts 'rdc/unsubscribe' action.
36
36
  *
37
37
  */
38
38
  protected handleUnsubscribe(action: UnsubscribeAction): void;
39
39
  /** Attaches Manager to store
40
40
  *
41
- * Intercepts 'rest-hooks/subscribe'/'rest-hooks/unsubscribe' to register resources that
41
+ * Intercepts 'rdc/subscribe'/'rest-hordc/ribe' to register resources that
42
42
  * need to be kept up to date.
43
43
  *
44
- * Will possibly dispatch 'rest-hooks/fetch' or 'rest-hooks/receive' to keep resources fresh
44
+ * Will possibly dispatch 'rdc/fetch' or 'rest-hordc/' to keep resources fresh
45
45
  *
46
46
  */
47
47
  getMiddleware(): Middleware;
@@ -1,15 +1,12 @@
1
1
  import Controller from './controller/Controller.js';
2
2
  import { ActionTypes, State } from './types.js';
3
3
  type RHDispatch<Actions = any> = (value: Actions) => Promise<void>;
4
- export interface MiddlewareAPI<R extends RestHooksReducer = RestHooksReducer> extends Controller<RHDispatch<ActionTypes>> {
5
- /** @deprecated use members directly instead */
6
- controller: Controller<RHDispatch<ActionTypes>>;
4
+ export interface MiddlewareAPI<R extends DataClientReducer = DataClientReducer> extends Controller<RHDispatch<ActionTypes>> {
7
5
  }
8
6
  export interface MiddlewareController<Actions = ActionTypes> extends Controller<RHDispatch<Actions>> {
9
- controller: Controller<RHDispatch<Actions>>;
10
7
  }
11
8
  export type Middleware<Actions = any> = <C extends MiddlewareController<Actions>>(controller: C) => (next: C['dispatch']) => C['dispatch'];
12
- export type RestHooksReducer = (prevState: State<unknown>, action: ActionTypes) => State<unknown>;
9
+ export type DataClientReducer = (prevState: State<unknown>, action: ActionTypes) => State<unknown>;
13
10
  export type Dispatch<R extends Reducer<any, any>> = (action: ReducerAction<R>) => Promise<void>;
14
11
  export type Reducer<S, A> = (prevState: S, action: A) => S;
15
12
  export type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never;
@@ -1,3 +1 @@
1
- export { default as Controller } from '../controller/Controller.js';
2
- export * from '../controller/Controller.js';
3
1
  //# sourceMappingURL=index.d.ts.map
@@ -28,7 +28,7 @@ export declare function expireReducer(state: State<unknown>, action: ExpireAllAc
28
28
  };
29
29
  };
30
30
  };
31
- optimistic: (import("../../newActions.js").SetAction | import("../../newActions.js").OptimisticAction<import("packages/normalizr/lib/index.js").EndpointInterface<import("packages/normalizr/lib/index.js").FetchFunction, import("packages/normalizr/lib/interface.js").Schema | undefined, boolean | undefined> & {
31
+ optimistic: (import("../../actions.js").SetAction | import("../../actions.js").OptimisticAction<import("packages/normalizr/lib/index.js").EndpointInterface<import("packages/normalizr/lib/index.js").FetchFunction, import("packages/normalizr/lib/interface.js").Schema | undefined, boolean | undefined> & {
32
32
  update?: import("../../index.js").EndpointUpdateFunction<import("packages/normalizr/lib/index.js").EndpointInterface<import("packages/normalizr/lib/index.js").FetchFunction, import("packages/normalizr/lib/interface.js").Schema | undefined, boolean | undefined>> | undefined;
33
33
  }>)[];
34
34
  lastReset: number;
@@ -28,7 +28,7 @@ export declare function invalidateReducer(state: State<unknown>, action: Invalid
28
28
  };
29
29
  };
30
30
  };
31
- optimistic: (import("../../newActions.js").SetAction | import("../../newActions.js").OptimisticAction<import("packages/normalizr/lib/index.js").EndpointInterface<import("packages/normalizr/lib/index.js").FetchFunction, import("packages/normalizr/lib/interface.js").Schema | undefined, boolean | undefined> & {
31
+ optimistic: (import("../../actions.js").SetAction | import("../../actions.js").OptimisticAction<import("packages/normalizr/lib/index.js").EndpointInterface<import("packages/normalizr/lib/index.js").FetchFunction, import("packages/normalizr/lib/interface.js").Schema | undefined, boolean | undefined> & {
32
32
  update?: import("../../index.js").EndpointUpdateFunction<import("packages/normalizr/lib/index.js").EndpointInterface<import("packages/normalizr/lib/index.js").FetchFunction, import("packages/normalizr/lib/interface.js").Schema | undefined, boolean | undefined>> | undefined;
33
33
  }>)[];
34
34
  lastReset: number;