@data-client/core 0.14.4 → 0.14.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +64 -95
- package/dist/index.umd.min.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/manager/DevtoolsManager.js +50 -52
- package/legacy/manager/LogoutManager.js +3 -8
- package/legacy/manager/NetworkManager.js +9 -21
- package/legacy/manager/SubscriptionManager.js +2 -15
- package/legacy/manager/applyManager.js +5 -3
- package/legacy/middlewareTypes.js +1 -1
- package/legacy/types.js +13 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/manager/DevtoolsManager.d.ts +4 -7
- package/lib/manager/DevtoolsManager.d.ts.map +1 -1
- package/lib/manager/DevtoolsManager.js +50 -52
- package/lib/manager/LogoutManager.d.ts +5 -8
- package/lib/manager/LogoutManager.d.ts.map +1 -1
- package/lib/manager/LogoutManager.js +3 -8
- package/lib/manager/NetworkManager.d.ts +3 -11
- package/lib/manager/NetworkManager.d.ts.map +1 -1
- package/lib/manager/NetworkManager.js +9 -21
- package/lib/manager/SubscriptionManager.d.ts +1 -10
- package/lib/manager/SubscriptionManager.d.ts.map +1 -1
- package/lib/manager/SubscriptionManager.js +2 -15
- package/lib/manager/applyManager.d.ts +8 -5
- package/lib/manager/applyManager.d.ts.map +1 -1
- package/lib/manager/applyManager.js +5 -3
- package/lib/middlewareTypes.d.ts +6 -10
- package/lib/middlewareTypes.d.ts.map +1 -1
- package/lib/middlewareTypes.js +1 -1
- package/lib/types.d.ts +16 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +13 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/manager/DevtoolsManager.ts +37 -40
- package/src/manager/LogoutManager.ts +15 -27
- package/src/manager/NetworkManager.ts +57 -70
- package/src/manager/SubscriptionManager.ts +18 -32
- package/src/manager/__tests__/applyManager.ts +61 -1
- package/src/manager/__tests__/logoutManager.ts +8 -10
- package/src/manager/__tests__/manager.ts +2 -3
- package/src/manager/__tests__/networkManager.ts +15 -18
- package/src/manager/__tests__/subscriptionManager.ts +14 -16
- package/src/manager/applyManager.ts +20 -8
- package/src/middlewareTypes.ts +7 -17
- package/src/types.ts +16 -1
- package/ts3.4/index.d.ts +1 -1
- package/ts3.4/manager/DevtoolsManager.d.ts +3 -6
- package/ts3.4/manager/LogoutManager.d.ts +4 -7
- package/ts3.4/manager/NetworkManager.d.ts +3 -11
- package/ts3.4/manager/SubscriptionManager.d.ts +1 -10
- package/ts3.4/manager/applyManager.d.ts +8 -5
- package/ts3.4/middlewareTypes.d.ts +5 -9
- package/ts3.4/types.d.ts +16 -1
|
@@ -33,18 +33,17 @@ describe('NetworkManager', () => {
|
|
|
33
33
|
expect(hacked.getHacked()).toEqual(initialState);
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
describe('
|
|
36
|
+
describe('middleware', () => {
|
|
37
37
|
it('should return the same value every call', () => {
|
|
38
|
-
const a = manager.
|
|
39
|
-
expect(a).toBe(manager.
|
|
40
|
-
expect(a).toBe(manager.getMiddleware());
|
|
38
|
+
const a = manager.middleware;
|
|
39
|
+
expect(a).toBe(manager.middleware);
|
|
41
40
|
});
|
|
42
41
|
it('should return the different value for a different instance', () => {
|
|
43
|
-
const a = manager.
|
|
42
|
+
const a = manager.middleware;
|
|
44
43
|
const manager2 = new NetworkManager();
|
|
45
|
-
const a2 = manager2.
|
|
44
|
+
const a2 = manager2.middleware;
|
|
46
45
|
expect(a).not.toBe(a2);
|
|
47
|
-
expect(a2).toBe(manager2.
|
|
46
|
+
expect(a2).toBe(manager2.middleware);
|
|
48
47
|
manager2.cleanup();
|
|
49
48
|
});
|
|
50
49
|
});
|
|
@@ -132,10 +131,8 @@ describe('NetworkManager', () => {
|
|
|
132
131
|
(fetchRejectAction.meta.promise as any).catch((e: unknown) => {});
|
|
133
132
|
|
|
134
133
|
let NM: NetworkManager;
|
|
135
|
-
let middleware: Middleware;
|
|
136
134
|
beforeEach(() => {
|
|
137
135
|
NM = new NetworkManager({ dataExpiryLength: 42, errorExpiryLength: 7 });
|
|
138
|
-
middleware = NM.getMiddleware();
|
|
139
136
|
});
|
|
140
137
|
afterEach(() => {
|
|
141
138
|
NM.cleanup();
|
|
@@ -152,7 +149,7 @@ describe('NetworkManager', () => {
|
|
|
152
149
|
},
|
|
153
150
|
);
|
|
154
151
|
|
|
155
|
-
middleware(API)(next)(fetchResolveAction);
|
|
152
|
+
NM.middleware(API)(next)(fetchResolveAction);
|
|
156
153
|
|
|
157
154
|
const response = await fetchResolveAction.endpoint(
|
|
158
155
|
...fetchResolveAction.args,
|
|
@@ -188,7 +185,7 @@ describe('NetworkManager', () => {
|
|
|
188
185
|
},
|
|
189
186
|
);
|
|
190
187
|
|
|
191
|
-
middleware(API)(next)(fetchSetWithUpdatersAction);
|
|
188
|
+
NM.middleware(API)(next)(fetchSetWithUpdatersAction);
|
|
192
189
|
|
|
193
190
|
const response = await fetchSetWithUpdatersAction.endpoint(
|
|
194
191
|
...fetchSetWithUpdatersAction.args,
|
|
@@ -224,7 +221,7 @@ describe('NetworkManager', () => {
|
|
|
224
221
|
},
|
|
225
222
|
);
|
|
226
223
|
|
|
227
|
-
middleware(API)(next)(fetchRpcWithUpdatersAction);
|
|
224
|
+
NM.middleware(API)(next)(fetchRpcWithUpdatersAction);
|
|
228
225
|
|
|
229
226
|
const response = await fetchRpcWithUpdatersAction.endpoint(
|
|
230
227
|
...fetchRpcWithUpdatersAction.args,
|
|
@@ -260,7 +257,7 @@ describe('NetworkManager', () => {
|
|
|
260
257
|
},
|
|
261
258
|
);
|
|
262
259
|
|
|
263
|
-
middleware(API)(next)(fetchRpcWithUpdatersAndOptimisticAction);
|
|
260
|
+
NM.middleware(API)(next)(fetchRpcWithUpdatersAndOptimisticAction);
|
|
264
261
|
|
|
265
262
|
const response = await fetchRpcWithUpdatersAndOptimisticAction.endpoint(
|
|
266
263
|
...fetchRpcWithUpdatersAndOptimisticAction.args,
|
|
@@ -293,7 +290,7 @@ describe('NetworkManager', () => {
|
|
|
293
290
|
},
|
|
294
291
|
);
|
|
295
292
|
|
|
296
|
-
middleware(API)(() => Promise.resolve())({
|
|
293
|
+
NM.middleware(API)(() => Promise.resolve())({
|
|
297
294
|
...fetchResolveAction,
|
|
298
295
|
endpoint: detailEndpoint.extend({ dataExpiryLength: 314 }),
|
|
299
296
|
});
|
|
@@ -314,7 +311,7 @@ describe('NetworkManager', () => {
|
|
|
314
311
|
},
|
|
315
312
|
);
|
|
316
313
|
|
|
317
|
-
middleware(API)(() => Promise.resolve())({
|
|
314
|
+
NM.middleware(API)(() => Promise.resolve())({
|
|
318
315
|
...fetchResolveAction,
|
|
319
316
|
endpoint: detailEndpoint.extend({ dataExpiryLength: undefined }),
|
|
320
317
|
});
|
|
@@ -337,7 +334,7 @@ describe('NetworkManager', () => {
|
|
|
337
334
|
);
|
|
338
335
|
|
|
339
336
|
try {
|
|
340
|
-
await middleware(API)(next)(fetchRejectAction);
|
|
337
|
+
await NM.middleware(API)(next)(fetchRejectAction);
|
|
341
338
|
} catch (error) {
|
|
342
339
|
expect(next).not.toHaveBeenCalled();
|
|
343
340
|
expect(dispatch).toHaveBeenCalledWith({
|
|
@@ -363,7 +360,7 @@ describe('NetworkManager', () => {
|
|
|
363
360
|
);
|
|
364
361
|
|
|
365
362
|
try {
|
|
366
|
-
await middleware(API)(() => Promise.resolve())({
|
|
363
|
+
await NM.middleware(API)(() => Promise.resolve())({
|
|
367
364
|
...fetchRejectAction,
|
|
368
365
|
meta: {
|
|
369
366
|
...fetchRejectAction.meta,
|
|
@@ -386,7 +383,7 @@ describe('NetworkManager', () => {
|
|
|
386
383
|
);
|
|
387
384
|
|
|
388
385
|
try {
|
|
389
|
-
await middleware(API)(() => Promise.resolve())({
|
|
386
|
+
await NM.middleware(API)(() => Promise.resolve())({
|
|
390
387
|
...fetchRejectAction,
|
|
391
388
|
meta: {
|
|
392
389
|
...fetchRejectAction.meta,
|
|
@@ -27,11 +27,10 @@ describe('SubscriptionManager', () => {
|
|
|
27
27
|
const manager = new SubscriptionManager(TestSubscription);
|
|
28
28
|
const getState = () => initialState;
|
|
29
29
|
|
|
30
|
-
describe('
|
|
30
|
+
describe('middleware', () => {
|
|
31
31
|
it('should return the same value every call', () => {
|
|
32
|
-
const a = manager.
|
|
33
|
-
expect(a).toBe(manager.
|
|
34
|
-
expect(a).toBe(manager.getMiddleware());
|
|
32
|
+
const a = manager.middleware;
|
|
33
|
+
expect(a).toBe(manager.middleware);
|
|
35
34
|
});
|
|
36
35
|
});
|
|
37
36
|
|
|
@@ -74,7 +73,6 @@ describe('SubscriptionManager', () => {
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
const manager = new SubscriptionManager(TestSubscription);
|
|
77
|
-
const middleware = manager.getMiddleware();
|
|
78
76
|
const next = jest.fn();
|
|
79
77
|
const dispatch = () => Promise.resolve();
|
|
80
78
|
const controller = new Controller({ dispatch, getState });
|
|
@@ -86,14 +84,14 @@ describe('SubscriptionManager', () => {
|
|
|
86
84
|
);
|
|
87
85
|
it('subscribe should add a subscription', () => {
|
|
88
86
|
const action = createSubscribeAction({ id: 5 });
|
|
89
|
-
middleware(API)(next)(action);
|
|
87
|
+
manager.middleware(API)(next)(action);
|
|
90
88
|
|
|
91
89
|
expect(next).not.toHaveBeenCalled();
|
|
92
90
|
expect((manager as any).subscriptions[action.key]).toBeDefined();
|
|
93
91
|
});
|
|
94
92
|
it('subscribe should add a subscription (no frequency)', () => {
|
|
95
93
|
const action = createSubscribeAction({ id: 597 });
|
|
96
|
-
middleware(API)(next)(action);
|
|
94
|
+
manager.middleware(API)(next)(action);
|
|
97
95
|
|
|
98
96
|
expect(next).not.toHaveBeenCalled();
|
|
99
97
|
expect((manager as any).subscriptions[action.key]).toBeDefined();
|
|
@@ -101,19 +99,19 @@ describe('SubscriptionManager', () => {
|
|
|
101
99
|
|
|
102
100
|
it('subscribe with same should call subscription.add', () => {
|
|
103
101
|
const action = createSubscribeAction({ id: 5, title: 'four' });
|
|
104
|
-
middleware(API)(next)(action);
|
|
102
|
+
manager.middleware(API)(next)(action);
|
|
105
103
|
|
|
106
104
|
expect(
|
|
107
105
|
(manager as any).subscriptions[action.key].add.mock.calls.length,
|
|
108
106
|
).toBe(1);
|
|
109
|
-
middleware(API)(next)(action);
|
|
107
|
+
manager.middleware(API)(next)(action);
|
|
110
108
|
expect(
|
|
111
109
|
(manager as any).subscriptions[action.key].add.mock.calls.length,
|
|
112
110
|
).toBe(2);
|
|
113
111
|
});
|
|
114
112
|
it('subscribe with another should create another', () => {
|
|
115
113
|
const action = createSubscribeAction({ id: 7, title: 'four cakes' });
|
|
116
|
-
middleware(API)(next)(action);
|
|
114
|
+
manager.middleware(API)(next)(action);
|
|
117
115
|
|
|
118
116
|
expect((manager as any).subscriptions[action.key]).toBeDefined();
|
|
119
117
|
expect(
|
|
@@ -134,13 +132,13 @@ describe('SubscriptionManager', () => {
|
|
|
134
132
|
() => true,
|
|
135
133
|
);
|
|
136
134
|
|
|
137
|
-
middleware(API)(next)(action);
|
|
135
|
+
manager.middleware(API)(next)(action);
|
|
138
136
|
|
|
139
137
|
expect((manager as any).subscriptions[action.key]).not.toBeDefined();
|
|
140
138
|
});
|
|
141
139
|
|
|
142
140
|
it('unsubscribe should delete when remove returns true (no frequency)', () => {
|
|
143
|
-
middleware(API)(next)(
|
|
141
|
+
manager.middleware(API)(next)(
|
|
144
142
|
createSubscribeAction({ id: 50, title: 'four cakes' }),
|
|
145
143
|
);
|
|
146
144
|
|
|
@@ -149,7 +147,7 @@ describe('SubscriptionManager', () => {
|
|
|
149
147
|
() => true,
|
|
150
148
|
);
|
|
151
149
|
|
|
152
|
-
middleware(API)(next)(action);
|
|
150
|
+
manager.middleware(API)(next)(action);
|
|
153
151
|
|
|
154
152
|
expect((manager as any).subscriptions[action.key]).not.toBeDefined();
|
|
155
153
|
});
|
|
@@ -160,7 +158,7 @@ describe('SubscriptionManager', () => {
|
|
|
160
158
|
() => false,
|
|
161
159
|
);
|
|
162
160
|
|
|
163
|
-
middleware(API)(next)(action);
|
|
161
|
+
manager.middleware(API)(next)(action);
|
|
164
162
|
|
|
165
163
|
expect((manager as any).subscriptions[action.key]).toBeDefined();
|
|
166
164
|
expect(
|
|
@@ -174,7 +172,7 @@ describe('SubscriptionManager', () => {
|
|
|
174
172
|
|
|
175
173
|
const action = createUnsubscribeAction({ id: 25 });
|
|
176
174
|
|
|
177
|
-
middleware(API)(next)(action);
|
|
175
|
+
manager.middleware(API)(next)(action);
|
|
178
176
|
|
|
179
177
|
expect((manager as any).subscriptions[action.key]).not.toBeDefined();
|
|
180
178
|
|
|
@@ -190,7 +188,7 @@ describe('SubscriptionManager', () => {
|
|
|
190
188
|
const action = { type: SET_RESPONSE_TYPE };
|
|
191
189
|
next.mockReset();
|
|
192
190
|
|
|
193
|
-
middleware(API)(next)(action as any);
|
|
191
|
+
manager.middleware(API)(next)(action as any);
|
|
194
192
|
|
|
195
193
|
expect(next.mock.calls.length).toBe(1);
|
|
196
194
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import NetworkManager from './NetworkManager.js';
|
|
2
2
|
import type Controller from '../controller/Controller.js';
|
|
3
|
-
import type { Reducer, Dispatch, ReducerState } from '../middlewareTypes.js';
|
|
4
3
|
import { Manager } from '../types.js';
|
|
5
4
|
|
|
6
5
|
export default function applyManager(
|
|
7
6
|
managers: Manager[],
|
|
8
7
|
controller: Controller,
|
|
9
|
-
):
|
|
8
|
+
): ReduxMiddleware[] {
|
|
10
9
|
/* istanbul ignore next */
|
|
11
10
|
if (
|
|
12
11
|
process.env.NODE_ENV !== 'production' &&
|
|
@@ -18,25 +17,38 @@ export default function applyManager(
|
|
|
18
17
|
);
|
|
19
18
|
}
|
|
20
19
|
return managers.map((manager, i) => {
|
|
21
|
-
|
|
20
|
+
if (!manager.middleware) manager.middleware = manager.getMiddleware?.();
|
|
22
21
|
return ({ dispatch, getState }) => {
|
|
23
22
|
if (i === 0) {
|
|
24
23
|
(controller as any).dispatch = dispatch;
|
|
25
24
|
(controller as any).getState = getState;
|
|
26
25
|
}
|
|
27
26
|
// controller is a superset of the middleware API
|
|
28
|
-
return
|
|
27
|
+
return (manager as Manager & { middleware: ReduxMiddleware }).middleware(
|
|
28
|
+
controller as Controller<any>,
|
|
29
|
+
);
|
|
29
30
|
};
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/* These should be compatible with redux */
|
|
34
|
-
export interface
|
|
35
|
+
export interface ReduxMiddlewareAPI<
|
|
35
36
|
R extends Reducer<any, any> = Reducer<any, any>,
|
|
36
37
|
> {
|
|
37
38
|
getState: () => ReducerState<R>;
|
|
38
|
-
dispatch:
|
|
39
|
+
dispatch: ReactDispatch<R>;
|
|
39
40
|
}
|
|
40
|
-
export type
|
|
41
|
+
export type ReduxMiddleware = <R extends Reducer<any, any>>({
|
|
41
42
|
dispatch,
|
|
42
|
-
}:
|
|
43
|
+
}: ReduxMiddlewareAPI<R>) => (next: ReactDispatch<R>) => ReactDispatch<R>;
|
|
44
|
+
|
|
45
|
+
/* The next are types from React; but we don't want dependencies on it */
|
|
46
|
+
export type ReactDispatch<R extends Reducer<any, any>> = (
|
|
47
|
+
action: ReducerAction<R>,
|
|
48
|
+
) => Promise<void>;
|
|
49
|
+
|
|
50
|
+
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
51
|
+
export type ReducerState<R extends Reducer<any, any>> =
|
|
52
|
+
R extends Reducer<infer S, any> ? S : never;
|
|
53
|
+
export type ReducerAction<R extends Reducer<any, any>> =
|
|
54
|
+
R extends Reducer<any, infer A> ? A : never;
|
package/src/middlewareTypes.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type Controller from './controller/Controller.js';
|
|
2
|
-
import { ActionTypes, State } from './types.js';
|
|
2
|
+
import type { ActionTypes, State } from './types.js';
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
export type Dispatch<Actions = ActionTypes> = (value: Actions) => Promise<void>;
|
|
5
|
+
|
|
6
|
+
export interface MiddlewareAPI extends Controller<Dispatch<ActionTypes>> {}
|
|
5
7
|
|
|
6
|
-
export interface MiddlewareAPI<R extends DataClientReducer = DataClientReducer>
|
|
7
|
-
extends Controller<RHDispatch<ActionTypes>> {}
|
|
8
8
|
export interface MiddlewareController<Actions = ActionTypes>
|
|
9
|
-
extends Controller<
|
|
9
|
+
extends Controller<Dispatch<Actions>> {}
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/** @see https://dataclient.io/docs/api/Manager#middleware */
|
|
12
|
+
export type Middleware<Actions = ActionTypes> = <
|
|
12
13
|
C extends MiddlewareController<Actions>,
|
|
13
14
|
>(
|
|
14
15
|
controller: C,
|
|
@@ -18,14 +19,3 @@ export type DataClientReducer = (
|
|
|
18
19
|
prevState: State<unknown>,
|
|
19
20
|
action: ActionTypes,
|
|
20
21
|
) => State<unknown>;
|
|
21
|
-
|
|
22
|
-
/* The next are types from React; but we don't want dependencies on it */
|
|
23
|
-
export type Dispatch<R extends Reducer<any, any>> = (
|
|
24
|
-
action: ReducerAction<R>,
|
|
25
|
-
) => Promise<void>;
|
|
26
|
-
|
|
27
|
-
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
28
|
-
export type ReducerState<R extends Reducer<any, any>> =
|
|
29
|
-
R extends Reducer<infer S, any> ? S : never;
|
|
30
|
-
export type ReducerAction<R extends Reducer<any, any>> =
|
|
31
|
-
R extends Reducer<any, infer A> ? A : never;
|
package/src/types.ts
CHANGED
|
@@ -18,6 +18,10 @@ export type { AbstractInstanceType, UpdateFunction };
|
|
|
18
18
|
|
|
19
19
|
export type PK = string;
|
|
20
20
|
|
|
21
|
+
/** Normalized state for Reactive Data Client
|
|
22
|
+
*
|
|
23
|
+
* @see https://dataclient.io/docs/concepts/normalization
|
|
24
|
+
*/
|
|
21
25
|
export interface State<T> {
|
|
22
26
|
readonly entities: {
|
|
23
27
|
readonly [entityKey: string]: { readonly [pk: string]: T } | undefined;
|
|
@@ -49,9 +53,20 @@ export interface State<T> {
|
|
|
49
53
|
readonly lastReset: number;
|
|
50
54
|
}
|
|
51
55
|
|
|
56
|
+
/** Singletons that handle global side-effects
|
|
57
|
+
*
|
|
58
|
+
* Kind of like useEffect() for the central data store
|
|
59
|
+
*
|
|
60
|
+
* @see https://dataclient.io/docs/api/Manager
|
|
61
|
+
*/
|
|
52
62
|
export interface Manager<Actions = ActionTypes> {
|
|
53
|
-
|
|
63
|
+
/** @see https://dataclient.io/docs/api/Manager#getmiddleware */
|
|
64
|
+
getMiddleware?(): Middleware<Actions>;
|
|
65
|
+
/** @see https://dataclient.io/docs/api/Manager#middleware */
|
|
66
|
+
middleware?: Middleware<Actions>;
|
|
67
|
+
/** @see https://dataclient.io/docs/api/Manager#cleanup */
|
|
54
68
|
cleanup(): void;
|
|
69
|
+
/** @see https://dataclient.io/docs/api/Manager#init */
|
|
55
70
|
init?: (state: State<any>) => void;
|
|
56
71
|
}
|
|
57
72
|
|
package/ts3.4/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as __INTERNAL__1 from './internal.js';
|
|
2
2
|
export { __INTERNAL__1 as __INTERNAL__ };
|
|
3
|
-
export { NetworkError, UnknownError, ErrorTypes, Schema, EndpointInterface, EntityInterface, ResolveType, DenormalizeNullable, Denormalize, Normalize, NormalizeNullable, FetchFunction, EndpointExtraOptions, Queryable, SchemaArgs, NI, } from '@data-client/normalizr';
|
|
3
|
+
export { NetworkError, UnknownError, ErrorTypes, Schema, EndpointInterface, EntityInterface, SchemaClass, ResolveType, DenormalizeNullable, Denormalize, Normalize, NormalizeNullable, FetchFunction, EndpointExtraOptions, Queryable, SchemaArgs, NI, } from '@data-client/normalizr';
|
|
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';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DevToolsConfig } from './devtoolsTypes.js';
|
|
2
|
-
import { Middleware } from './LogoutManager.js';
|
|
3
2
|
import { Controller } from '../index.js';
|
|
3
|
+
import { Middleware } from '../middlewareTypes.js';
|
|
4
4
|
import { Manager, State, ActionTypes } from '../types.js';
|
|
5
5
|
export { DevToolsConfig };
|
|
6
6
|
/** Integrates with https://github.com/reduxjs/redux-devtools
|
|
@@ -10,7 +10,7 @@ export { DevToolsConfig };
|
|
|
10
10
|
* @see https://dataclient.io/docs/api/DevToolsManager
|
|
11
11
|
*/
|
|
12
12
|
export default class DevToolsManager implements Manager {
|
|
13
|
-
|
|
13
|
+
middleware: Middleware;
|
|
14
14
|
protected devTools: undefined | any;
|
|
15
15
|
protected started: boolean;
|
|
16
16
|
protected actions: [
|
|
@@ -18,6 +18,7 @@ export default class DevToolsManager implements Manager {
|
|
|
18
18
|
State<unknown>
|
|
19
19
|
][];
|
|
20
20
|
protected controller: Controller;
|
|
21
|
+
skipLogging?: (action: ActionTypes) => boolean;
|
|
21
22
|
maxBufferLength: number;
|
|
22
23
|
constructor(config?: DevToolsConfig, skipLogging?: (action: ActionTypes) => boolean);
|
|
23
24
|
handleAction(action: any, state: any): void;
|
|
@@ -25,9 +26,5 @@ export default class DevToolsManager implements Manager {
|
|
|
25
26
|
init(state: State<any>): void;
|
|
26
27
|
/** Ensures all subscriptions are cleaned up. */
|
|
27
28
|
cleanup(): void;
|
|
28
|
-
/** Attaches Manager to store
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
getMiddleware(): Middleware;
|
|
32
29
|
}
|
|
33
30
|
//# sourceMappingURL=DevtoolsManager.d.ts.map
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import Controller from '../controller/Controller.js';
|
|
2
2
|
import { UnknownError } from '../index.js';
|
|
3
|
-
import {
|
|
3
|
+
import { Manager, Middleware } from '../types.js';
|
|
4
4
|
/** Handling network unauthorized indicators like HTTP 401
|
|
5
5
|
*
|
|
6
6
|
* @see https://dataclient.io/docs/api/LogoutManager
|
|
7
7
|
*/
|
|
8
8
|
export default class LogoutManager implements Manager {
|
|
9
|
-
protected middleware: Middleware;
|
|
10
9
|
constructor({ handleLogout, shouldLogout }?: Props);
|
|
10
|
+
middleware: Middleware;
|
|
11
11
|
cleanup(): void;
|
|
12
|
-
getMiddleware(): Middleware;
|
|
13
12
|
protected shouldLogout(error: UnknownError): boolean;
|
|
14
|
-
handleLogout(controller: Controller
|
|
13
|
+
handleLogout(controller: Controller): void;
|
|
15
14
|
}
|
|
16
|
-
type
|
|
17
|
-
export type Middleware = <C extends Controller<Dispatch>>(controller: C) => (next: C['dispatch']) => C['dispatch'];
|
|
18
|
-
type HandleLogout = (controller: Controller<Dispatch>) => void;
|
|
15
|
+
type HandleLogout = (controller: Controller) => void;
|
|
19
16
|
interface Props {
|
|
20
17
|
handleLogout?: HandleLogout;
|
|
21
18
|
shouldLogout?: (error: UnknownError) => boolean;
|
|
@@ -28,19 +28,19 @@ export default class NetworkManager implements Manager {
|
|
|
28
28
|
};
|
|
29
29
|
readonly dataExpiryLength: number;
|
|
30
30
|
readonly errorExpiryLength: number;
|
|
31
|
-
protected middleware: Middleware;
|
|
32
31
|
protected controller: Controller;
|
|
33
32
|
cleanupDate?: number;
|
|
34
33
|
constructor({ dataExpiryLength, errorExpiryLength }?: {
|
|
35
34
|
dataExpiryLength?: number | undefined;
|
|
36
35
|
errorExpiryLength?: number | undefined;
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
skipLogging(action: ActionTypes): boolean;
|
|
37
|
+
middleware: Middleware;
|
|
40
38
|
/** On mount */
|
|
41
39
|
init(): void;
|
|
42
40
|
/** Ensures all promises are completed by rejecting remaining. */
|
|
43
41
|
cleanup(): void;
|
|
42
|
+
/** Used by DevtoolsManager to determine whether to log an action */
|
|
43
|
+
skipLogging(action: ActionTypes): boolean;
|
|
44
44
|
allSettled(): Promise<PromiseSettledResult<any>[]> | undefined;
|
|
45
45
|
/** Clear all promise state */
|
|
46
46
|
protected clearAll(): void;
|
|
@@ -61,14 +61,6 @@ export default class NetworkManager implements Manager {
|
|
|
61
61
|
* Will resolve the promise associated with set key.
|
|
62
62
|
*/
|
|
63
63
|
protected handleSet(action: SetResponseAction): void;
|
|
64
|
-
/** Attaches NetworkManager to store
|
|
65
|
-
*
|
|
66
|
-
* Intercepts 'rdc/fetch' actions to start requests.
|
|
67
|
-
*
|
|
68
|
-
* Resolve/rejects a request when matching 'rdc/set' event
|
|
69
|
-
* is seen.
|
|
70
|
-
*/
|
|
71
|
-
getMiddleware(): Middleware;
|
|
72
64
|
/** Ensures only one request for a given key is in flight at any time
|
|
73
65
|
*
|
|
74
66
|
* Uses key to either retrieve in-flight promise, or if not
|
|
@@ -23,9 +23,9 @@ export default class SubscriptionManager<S extends SubscriptionConstructable = S
|
|
|
23
23
|
[key: string]: InstanceType<S>;
|
|
24
24
|
};
|
|
25
25
|
protected readonly Subscription: S;
|
|
26
|
-
protected middleware: Middleware;
|
|
27
26
|
protected controller: Controller;
|
|
28
27
|
constructor(Subscription: S);
|
|
28
|
+
middleware: Middleware;
|
|
29
29
|
/** Ensures all subscriptions are cleaned up. */
|
|
30
30
|
cleanup(): void;
|
|
31
31
|
/** Called when middleware intercepts 'rdc/subscribe' action.
|
|
@@ -36,15 +36,6 @@ export default class SubscriptionManager<S extends SubscriptionConstructable = S
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
protected handleUnsubscribe(action: UnsubscribeAction): void;
|
|
39
|
-
/** Attaches Manager to store
|
|
40
|
-
*
|
|
41
|
-
* Intercepts 'rdc/subscribe'/'rest-hordc/ribe' to register resources that
|
|
42
|
-
* need to be kept up to date.
|
|
43
|
-
*
|
|
44
|
-
* Will possibly dispatch 'rdc/fetch' or 'rest-hordc/' to keep resources fresh
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
getMiddleware(): Middleware;
|
|
48
39
|
}
|
|
49
40
|
export {};
|
|
50
41
|
//# sourceMappingURL=SubscriptionManager.d.ts.map
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import Controller from '../controller/Controller.js';
|
|
2
|
-
import { Reducer, Dispatch, ReducerState } from '../middlewareTypes.js';
|
|
3
2
|
import { Manager } from '../types.js';
|
|
4
|
-
export default function applyManager(managers: Manager[], controller: Controller):
|
|
5
|
-
export interface
|
|
3
|
+
export default function applyManager(managers: Manager[], controller: Controller): ReduxMiddleware[];
|
|
4
|
+
export interface ReduxMiddlewareAPI<R extends Reducer<any, any> = Reducer<any, any>> {
|
|
6
5
|
getState: () => ReducerState<R>;
|
|
7
|
-
dispatch:
|
|
6
|
+
dispatch: ReactDispatch<R>;
|
|
8
7
|
}
|
|
9
|
-
export type
|
|
8
|
+
export type ReduxMiddleware = <R extends Reducer<any, any>>({ dispatch, }: ReduxMiddlewareAPI<R>) => (next: ReactDispatch<R>) => ReactDispatch<R>;
|
|
9
|
+
export type ReactDispatch<R extends Reducer<any, any>> = (action: ReducerAction<R>) => Promise<void>;
|
|
10
|
+
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
11
|
+
export type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never;
|
|
12
|
+
export type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<any, infer A> ? A : never;
|
|
10
13
|
//# sourceMappingURL=applyManager.d.ts.map
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import Controller from './controller/Controller.js';
|
|
2
2
|
import { ActionTypes, State } from './types.js';
|
|
3
|
-
type
|
|
4
|
-
export interface MiddlewareAPI
|
|
3
|
+
export type Dispatch<Actions = ActionTypes> = (value: Actions) => Promise<void>;
|
|
4
|
+
export interface MiddlewareAPI extends Controller<Dispatch<ActionTypes>> {
|
|
5
5
|
}
|
|
6
|
-
export interface MiddlewareController<Actions = ActionTypes> extends Controller<
|
|
6
|
+
export interface MiddlewareController<Actions = ActionTypes> extends Controller<Dispatch<Actions>> {
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
/** @see https://dataclient.io/docs/api/Manager#middleware */
|
|
9
|
+
export type Middleware<Actions = ActionTypes> = <C extends MiddlewareController<Actions>>(controller: C) => (next: C['dispatch']) => C['dispatch'];
|
|
9
10
|
export type DataClientReducer = (prevState: State<unknown>, action: ActionTypes) => State<unknown>;
|
|
10
|
-
export type Dispatch<R extends Reducer<any, any>> = (action: ReducerAction<R>) => Promise<void>;
|
|
11
|
-
export type Reducer<S, A> = (prevState: S, action: A) => S;
|
|
12
|
-
export type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never;
|
|
13
|
-
export type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<any, infer A> ? A : never;
|
|
14
|
-
export {};
|
|
15
11
|
//# sourceMappingURL=middlewareTypes.d.ts.map
|
package/ts3.4/types.d.ts
CHANGED
|
@@ -6,6 +6,10 @@ import { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
|
|
|
6
6
|
export * from './actions.js';
|
|
7
7
|
export { AbstractInstanceType, UpdateFunction };
|
|
8
8
|
export type PK = string;
|
|
9
|
+
/** Normalized state for Reactive Data Client
|
|
10
|
+
*
|
|
11
|
+
* @see https://dataclient.io/docs/concepts/normalization
|
|
12
|
+
*/
|
|
9
13
|
export interface State<T> {
|
|
10
14
|
readonly entities: {
|
|
11
15
|
readonly [entityKey: string]: {
|
|
@@ -38,9 +42,20 @@ export interface State<T> {
|
|
|
38
42
|
readonly optimistic: (SetResponseAction | OptimisticAction)[];
|
|
39
43
|
readonly lastReset: number;
|
|
40
44
|
}
|
|
45
|
+
/** Singletons that handle global side-effects
|
|
46
|
+
*
|
|
47
|
+
* Kind of like useEffect() for the central data store
|
|
48
|
+
*
|
|
49
|
+
* @see https://dataclient.io/docs/api/Manager
|
|
50
|
+
*/
|
|
41
51
|
export interface Manager<Actions = ActionTypes> {
|
|
42
|
-
|
|
52
|
+
/** @see https://dataclient.io/docs/api/Manager#getmiddleware */
|
|
53
|
+
getMiddleware?(): Middleware<Actions>;
|
|
54
|
+
/** @see https://dataclient.io/docs/api/Manager#middleware */
|
|
55
|
+
middleware?: Middleware<Actions>;
|
|
56
|
+
/** @see https://dataclient.io/docs/api/Manager#cleanup */
|
|
43
57
|
cleanup(): void;
|
|
58
|
+
/** @see https://dataclient.io/docs/api/Manager#init */
|
|
44
59
|
init?: (state: State<any>) => void;
|
|
45
60
|
}
|
|
46
61
|
export { Dispatch, Middleware, MiddlewareAPI };
|