@data-client/core 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +198 -214
- package/dist/index.umd.min.js +1 -1
- package/legacy/actions.js +1 -1
- package/legacy/controller/Controller.js +21 -30
- package/legacy/controller/actions/createExpireAll.js +8 -0
- package/legacy/controller/actions/createFetch.js +27 -0
- package/legacy/controller/actions/createInvalidate.js +10 -0
- package/legacy/controller/actions/createInvalidateAll.js +8 -0
- package/legacy/controller/actions/createMeta.js +9 -0
- package/legacy/controller/actions/createOptimistic.js +17 -0
- package/legacy/controller/actions/createReset.js +8 -0
- package/legacy/controller/actions/createSet.js +17 -0
- package/legacy/controller/actions/createSetResponse.js +26 -0
- package/legacy/controller/actions/createSubscription.js +22 -0
- package/legacy/controller/actions/index.js +11 -0
- package/legacy/index.js +3 -4
- package/legacy/internal.js +1 -2
- package/legacy/manager/LogoutManager.js +2 -2
- package/legacy/manager/NetworkManager.js +39 -35
- package/legacy/manager/PollingSubscription.js +3 -3
- package/legacy/manager/SubscriptionManager.js +3 -3
- package/legacy/state/reducer/createReducer.js +2 -2
- package/legacy/state/reducer/fetchReducer.js +6 -10
- package/legacy/state/reducer/invalidateReducer.js +2 -2
- package/legacy/state/reducer/setReducer.js +11 -3
- package/legacy/state/reducer/setResponseReducer.js +17 -17
- package/legacy/types.js +1 -1
- package/lib/actions.d.ts +35 -41
- package/lib/actions.d.ts.map +1 -1
- package/lib/actions.js +1 -1
- package/lib/controller/Controller.d.ts +18 -17
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +21 -30
- package/lib/controller/actions/createExpireAll.d.ts +3 -0
- package/lib/controller/actions/createExpireAll.d.ts.map +1 -0
- package/lib/controller/actions/createExpireAll.js +8 -0
- package/lib/controller/{createFetch.d.ts → actions/createFetch.d.ts} +3 -3
- package/lib/controller/actions/createFetch.d.ts.map +1 -0
- package/lib/controller/actions/createFetch.js +27 -0
- package/lib/controller/actions/createInvalidate.d.ts +6 -0
- package/lib/controller/actions/createInvalidate.d.ts.map +1 -0
- package/lib/controller/actions/createInvalidate.js +10 -0
- package/lib/controller/actions/createInvalidateAll.d.ts +3 -0
- package/lib/controller/actions/createInvalidateAll.d.ts.map +1 -0
- package/lib/controller/actions/createInvalidateAll.js +8 -0
- package/lib/controller/actions/createMeta.d.ts +3 -0
- package/lib/controller/actions/createMeta.d.ts.map +1 -0
- package/lib/controller/actions/createMeta.js +9 -0
- package/lib/controller/actions/createOptimistic.d.ts +7 -0
- package/lib/controller/actions/createOptimistic.d.ts.map +1 -0
- package/lib/controller/actions/createOptimistic.js +17 -0
- package/lib/controller/actions/createReset.d.ts +3 -0
- package/lib/controller/actions/createReset.d.ts.map +1 -0
- package/lib/controller/actions/createReset.js +8 -0
- package/lib/controller/actions/createSet.d.ts +8 -0
- package/lib/controller/actions/createSet.d.ts.map +1 -0
- package/lib/controller/actions/createSet.js +17 -0
- package/lib/controller/{createSetResponse.d.ts → actions/createSetResponse.d.ts} +4 -4
- package/lib/controller/actions/createSetResponse.d.ts.map +1 -0
- package/lib/controller/actions/createSetResponse.js +26 -0
- package/lib/controller/{createSubscription.d.ts → actions/createSubscription.d.ts} +1 -1
- package/lib/controller/actions/createSubscription.d.ts.map +1 -0
- package/lib/controller/actions/createSubscription.js +22 -0
- package/lib/controller/actions/index.d.ts +11 -0
- package/lib/controller/actions/index.d.ts.map +1 -0
- package/lib/controller/actions/index.js +11 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -4
- package/lib/internal.d.ts +0 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +1 -2
- package/lib/manager/LogoutManager.js +2 -2
- package/lib/manager/NetworkManager.d.ts +7 -2
- package/lib/manager/NetworkManager.d.ts.map +1 -1
- package/lib/manager/NetworkManager.js +39 -35
- package/lib/manager/PollingSubscription.js +3 -3
- package/lib/manager/SubscriptionManager.js +3 -3
- package/lib/state/reducer/createReducer.js +2 -2
- package/lib/state/reducer/expireReducer.d.ts +6 -8
- package/lib/state/reducer/expireReducer.d.ts.map +1 -1
- package/lib/state/reducer/fetchReducer.d.ts.map +1 -1
- package/lib/state/reducer/fetchReducer.js +8 -12
- package/lib/state/reducer/invalidateReducer.d.ts +5 -7
- package/lib/state/reducer/invalidateReducer.d.ts.map +1 -1
- package/lib/state/reducer/invalidateReducer.js +2 -2
- package/lib/state/reducer/setReducer.d.ts +2 -1
- package/lib/state/reducer/setReducer.d.ts.map +1 -1
- package/lib/state/reducer/setReducer.js +11 -3
- package/lib/state/reducer/setResponseReducer.d.ts.map +1 -1
- package/lib/state/reducer/setResponseReducer.js +17 -17
- package/lib/types.d.ts +3 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -1
- package/package.json +2 -2
- package/src/actions.ts +37 -43
- package/src/controller/Controller.ts +29 -26
- package/src/controller/__tests__/Controller.ts +2 -2
- package/src/controller/actions/createExpireAll.ts +11 -0
- package/src/controller/{createFetch.ts → actions/createFetch.ts} +9 -13
- package/src/controller/actions/createInvalidate.ts +14 -0
- package/src/controller/actions/createInvalidateAll.ts +11 -0
- package/src/controller/actions/createMeta.ts +13 -0
- package/src/controller/actions/createOptimistic.ts +32 -0
- package/src/controller/actions/createReset.ts +9 -0
- package/src/controller/actions/createSet.ts +31 -0
- package/src/controller/{createSetResponse.ts → actions/createSetResponse.ts} +17 -23
- package/src/controller/{createSubscription.ts → actions/createSubscription.ts} +6 -10
- package/src/controller/actions/index.ts +13 -0
- package/src/index.ts +1 -3
- package/src/internal.ts +0 -1
- package/src/manager/LogoutManager.ts +1 -1
- package/src/manager/NetworkManager.ts +41 -32
- package/src/manager/PollingSubscription.ts +2 -2
- package/src/manager/SubscriptionManager.ts +2 -2
- package/src/manager/__tests__/__snapshots__/pollingSubscription.ts.snap +4 -10
- package/src/manager/__tests__/logoutManager.ts +1 -1
- package/src/manager/__tests__/networkManager.ts +37 -25
- package/src/manager/__tests__/pollingSubscription.ts +3 -3
- package/src/manager/__tests__/subscriptionManager.ts +22 -27
- package/src/state/__tests__/reducer.ts +110 -44
- package/src/state/reducer/createReducer.ts +1 -1
- package/src/state/reducer/fetchReducer.ts +12 -18
- package/src/state/reducer/invalidateReducer.ts +1 -1
- package/src/state/reducer/setReducer.ts +17 -6
- package/src/state/reducer/setResponseReducer.ts +18 -20
- package/src/types.ts +4 -4
- package/ts3.4/actions.d.ts +36 -42
- package/ts3.4/controller/Controller.d.ts +23 -19
- package/ts3.4/controller/actions/createExpireAll.d.ts +3 -0
- package/ts3.4/controller/{createFetch.d.ts → actions/createFetch.d.ts} +3 -3
- package/ts3.4/controller/{createInvalidate.d.ts → actions/createInvalidate.d.ts} +2 -2
- package/ts3.4/controller/actions/createInvalidateAll.d.ts +3 -0
- package/ts3.4/controller/actions/createMeta.d.ts +3 -0
- package/ts3.4/controller/actions/createOptimistic.d.ts +9 -0
- package/ts3.4/controller/actions/createReset.d.ts +3 -0
- package/ts3.4/controller/actions/createSet.d.ts +10 -0
- package/ts3.4/controller/{createSetResponse.d.ts → actions/createSetResponse.d.ts} +4 -4
- package/ts3.4/controller/{createSubscription.d.ts → actions/createSubscription.d.ts} +1 -1
- package/ts3.4/controller/actions/index.d.ts +11 -0
- package/ts3.4/index.d.ts +2 -3
- package/ts3.4/internal.d.ts +0 -1
- package/ts3.4/manager/NetworkManager.d.ts +7 -2
- package/ts3.4/state/reducer/expireReducer.d.ts +6 -8
- package/ts3.4/state/reducer/invalidateReducer.d.ts +5 -7
- package/ts3.4/state/reducer/setReducer.d.ts +2 -1
- package/ts3.4/types.d.ts +3 -3
- package/legacy/controller/createExpireAll.js +0 -8
- package/legacy/controller/createFetch.js +0 -31
- package/legacy/controller/createInvalidate.js +0 -12
- package/legacy/controller/createInvalidateAll.js +0 -8
- package/legacy/controller/createOptimistic.js +0 -27
- package/legacy/controller/createReset.js +0 -8
- package/legacy/controller/createSet.js +0 -28
- package/legacy/controller/createSetResponse.js +0 -32
- package/legacy/controller/createSubscription.js +0 -26
- package/legacy/state/RIC.js +0 -3
- package/lib/controller/createExpireAll.d.ts +0 -3
- package/lib/controller/createExpireAll.d.ts.map +0 -1
- package/lib/controller/createExpireAll.js +0 -8
- package/lib/controller/createFetch.d.ts.map +0 -1
- package/lib/controller/createFetch.js +0 -31
- package/lib/controller/createInvalidate.d.ts +0 -6
- package/lib/controller/createInvalidate.d.ts.map +0 -1
- package/lib/controller/createInvalidate.js +0 -12
- package/lib/controller/createInvalidateAll.d.ts +0 -3
- package/lib/controller/createInvalidateAll.d.ts.map +0 -1
- package/lib/controller/createInvalidateAll.js +0 -8
- package/lib/controller/createOptimistic.d.ts +0 -10
- package/lib/controller/createOptimistic.d.ts.map +0 -1
- package/lib/controller/createOptimistic.js +0 -27
- package/lib/controller/createReset.d.ts +0 -3
- package/lib/controller/createReset.d.ts.map +0 -1
- package/lib/controller/createReset.js +0 -8
- package/lib/controller/createSet.d.ts +0 -8
- package/lib/controller/createSet.d.ts.map +0 -1
- package/lib/controller/createSet.js +0 -28
- package/lib/controller/createSetResponse.d.ts.map +0 -1
- package/lib/controller/createSetResponse.js +0 -32
- package/lib/controller/createSubscription.d.ts.map +0 -1
- package/lib/controller/createSubscription.js +0 -26
- package/lib/state/RIC.d.ts +0 -3
- package/lib/state/RIC.d.ts.map +0 -1
- package/lib/state/RIC.js +0 -3
- package/src/controller/createExpireAll.ts +0 -11
- package/src/controller/createInvalidate.ts +0 -16
- package/src/controller/createInvalidateAll.ts +0 -11
- package/src/controller/createOptimistic.ts +0 -41
- package/src/controller/createReset.ts +0 -9
- package/src/controller/createSet.ts +0 -39
- package/src/state/RIC.ts +0 -5
- package/src/state/__tests__/RIC.web.ts +0 -16
- package/ts3.4/controller/createExpireAll.d.ts +0 -3
- package/ts3.4/controller/createInvalidateAll.d.ts +0 -3
- package/ts3.4/controller/createOptimistic.d.ts +0 -12
- package/ts3.4/controller/createReset.d.ts +0 -3
- package/ts3.4/controller/createSet.d.ts +0 -10
- package/ts3.4/state/RIC.d.ts +0 -3
package/src/actions.ts
CHANGED
|
@@ -28,102 +28,98 @@ type EndpointDefault = EndpointInterface & {
|
|
|
28
28
|
update?: EndpointUpdateFunction<EndpointInterface>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
export interface
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
expiresAt: number;
|
|
31
|
+
/** General meta-data for operators */
|
|
32
|
+
export interface ActionMeta {
|
|
33
|
+
readonly fetchedAt: number;
|
|
34
|
+
readonly date: number;
|
|
35
|
+
readonly expiresAt: number;
|
|
37
36
|
}
|
|
38
37
|
|
|
38
|
+
/** Action for Controller.set() */
|
|
39
39
|
export interface SetAction<S extends Queryable = any> {
|
|
40
40
|
type: typeof SET_TYPE;
|
|
41
41
|
schema: S;
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
args: readonly any[];
|
|
43
|
+
meta: ActionMeta;
|
|
44
|
+
value: {} | ((previousValue: Denormalize<S>) => {});
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
/* setResponse */
|
|
47
|
-
export interface
|
|
48
|
+
export interface SetResponseActionBase<
|
|
49
|
+
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
50
|
+
> {
|
|
51
|
+
type: typeof SET_RESPONSE_TYPE;
|
|
52
|
+
endpoint: E;
|
|
48
53
|
args: readonly any[];
|
|
49
54
|
key: string;
|
|
50
|
-
|
|
51
|
-
date: number;
|
|
52
|
-
expiresAt: number;
|
|
55
|
+
meta: ActionMeta;
|
|
53
56
|
}
|
|
54
57
|
export interface SetResponseActionSuccess<
|
|
55
58
|
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
56
|
-
> {
|
|
57
|
-
|
|
58
|
-
endpoint: E;
|
|
59
|
-
meta: SetResponseMeta;
|
|
60
|
-
payload: ResolveType<E>;
|
|
59
|
+
> extends SetResponseActionBase<E> {
|
|
60
|
+
response: ResolveType<E>;
|
|
61
61
|
error?: false;
|
|
62
62
|
}
|
|
63
63
|
export interface SetResponseActionError<
|
|
64
64
|
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
65
|
-
> {
|
|
66
|
-
|
|
67
|
-
endpoint: E;
|
|
68
|
-
meta: SetResponseMeta;
|
|
69
|
-
payload: UnknownError;
|
|
65
|
+
> extends SetResponseActionBase<E> {
|
|
66
|
+
response: UnknownError;
|
|
70
67
|
error: true;
|
|
71
68
|
}
|
|
69
|
+
/** Action for Controller.setResponse() */
|
|
72
70
|
export type SetResponseAction<
|
|
73
71
|
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
74
72
|
> = SetResponseActionSuccess<E> | SetResponseActionError<E>;
|
|
75
73
|
|
|
76
74
|
/* FETCH */
|
|
77
|
-
export interface FetchMeta
|
|
78
|
-
|
|
79
|
-
key: string;
|
|
80
|
-
throttle: boolean;
|
|
75
|
+
export interface FetchMeta {
|
|
76
|
+
fetchedAt: number;
|
|
81
77
|
resolve: (value?: any | PromiseLike<any>) => void;
|
|
82
78
|
reject: (reason?: any) => void;
|
|
83
79
|
promise: PromiseLike<any>;
|
|
84
|
-
createdAt: number;
|
|
85
|
-
// indicates whether network manager processed it
|
|
86
|
-
nm?: boolean;
|
|
87
80
|
}
|
|
88
81
|
|
|
82
|
+
/** Action for Controller.fetch() */
|
|
89
83
|
export interface FetchAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
90
84
|
type: typeof FETCH_TYPE;
|
|
91
85
|
endpoint: E;
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
args: readonly [...Parameters<E>];
|
|
87
|
+
key: string;
|
|
88
|
+
meta: FetchMeta;
|
|
94
89
|
}
|
|
95
90
|
|
|
96
91
|
/* OPTIMISTIC */
|
|
92
|
+
/** Action for Endpoint.getOptimisticResponse() */
|
|
97
93
|
export interface OptimisticAction<
|
|
98
94
|
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
99
95
|
> {
|
|
100
96
|
type: typeof OPTIMISTIC_TYPE;
|
|
101
97
|
endpoint: E;
|
|
102
|
-
|
|
98
|
+
args: readonly any[];
|
|
99
|
+
key: string;
|
|
100
|
+
meta: ActionMeta;
|
|
103
101
|
error?: false;
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
/* SUBSCRIBE */
|
|
105
|
+
/** Action for Controller.subscribe() */
|
|
107
106
|
export interface SubscribeAction<
|
|
108
107
|
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
109
108
|
> {
|
|
110
109
|
type: typeof SUBSCRIBE_TYPE;
|
|
111
110
|
endpoint: E;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
key: string;
|
|
115
|
-
};
|
|
111
|
+
args: readonly any[];
|
|
112
|
+
key: string;
|
|
116
113
|
}
|
|
117
114
|
|
|
115
|
+
/** Action for Controller.unsubscribe() */
|
|
118
116
|
export interface UnsubscribeAction<
|
|
119
117
|
E extends EndpointAndUpdate<E> = EndpointDefault,
|
|
120
118
|
> {
|
|
121
119
|
type: typeof UNSUBSCRIBE_TYPE;
|
|
122
120
|
endpoint: E;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
key: string;
|
|
126
|
-
};
|
|
121
|
+
args: readonly any[];
|
|
122
|
+
key: string;
|
|
127
123
|
}
|
|
128
124
|
|
|
129
125
|
/* EXPIRY */
|
|
@@ -140,9 +136,7 @@ export interface InvalidateAllAction {
|
|
|
140
136
|
|
|
141
137
|
export interface InvalidateAction {
|
|
142
138
|
type: typeof INVALIDATE_TYPE;
|
|
143
|
-
|
|
144
|
-
key: string;
|
|
145
|
-
};
|
|
139
|
+
key: string;
|
|
146
140
|
}
|
|
147
141
|
|
|
148
142
|
/* RESET */
|
|
@@ -20,17 +20,19 @@ import {
|
|
|
20
20
|
} from '@data-client/normalizr';
|
|
21
21
|
|
|
22
22
|
import AbortOptimistic from './AbortOptimistic.js';
|
|
23
|
-
import createExpireAll from './createExpireAll.js';
|
|
24
|
-
import createFetch from './createFetch.js';
|
|
25
|
-
import createInvalidate from './createInvalidate.js';
|
|
26
|
-
import createInvalidateAll from './createInvalidateAll.js';
|
|
27
|
-
import createReset from './createReset.js';
|
|
28
|
-
import createSet from './createSet.js';
|
|
29
|
-
import createSetResponse from './createSetResponse.js';
|
|
30
23
|
import {
|
|
31
24
|
createUnsubscription,
|
|
32
25
|
createSubscription,
|
|
33
|
-
} from './createSubscription.js';
|
|
26
|
+
} from './actions/createSubscription.js';
|
|
27
|
+
import {
|
|
28
|
+
createExpireAll,
|
|
29
|
+
createFetch,
|
|
30
|
+
createInvalidate,
|
|
31
|
+
createInvalidateAll,
|
|
32
|
+
createReset,
|
|
33
|
+
createSet,
|
|
34
|
+
createSetResponse,
|
|
35
|
+
} from './actions/index.js';
|
|
34
36
|
import ensurePojo from './ensurePojo.js';
|
|
35
37
|
import type { EndpointUpdateFunction } from './types.js';
|
|
36
38
|
import { initialState } from '../state/reducer/createReducer.js';
|
|
@@ -117,7 +119,7 @@ export default class Controller<
|
|
|
117
119
|
|
|
118
120
|
if (endpoint.schema) {
|
|
119
121
|
return action.meta.promise.then(input =>
|
|
120
|
-
denormalize(
|
|
122
|
+
denormalize(endpoint.schema, input, {}, args),
|
|
121
123
|
) as any;
|
|
122
124
|
}
|
|
123
125
|
return action.meta.promise as any;
|
|
@@ -186,18 +188,28 @@ export default class Controller<
|
|
|
186
188
|
* Sets value for the Queryable and args.
|
|
187
189
|
* @see https://dataclient.io/docs/api/Controller#set
|
|
188
190
|
*/
|
|
189
|
-
set
|
|
191
|
+
set<S extends Queryable>(
|
|
192
|
+
schema: S,
|
|
193
|
+
...rest: readonly [...SchemaArgs<S>, (previousValue: Denormalize<S>) => {}]
|
|
194
|
+
): Promise<void>;
|
|
195
|
+
|
|
196
|
+
set<S extends Queryable>(
|
|
197
|
+
schema: S,
|
|
198
|
+
...rest: readonly [...SchemaArgs<S>, {}]
|
|
199
|
+
): Promise<void>;
|
|
200
|
+
|
|
201
|
+
set<S extends Queryable>(
|
|
190
202
|
schema: S,
|
|
191
203
|
...rest: readonly [...SchemaArgs<S>, any]
|
|
192
|
-
): Promise<void>
|
|
193
|
-
const value
|
|
204
|
+
): Promise<void> {
|
|
205
|
+
const value = rest[rest.length - 1];
|
|
194
206
|
const action = createSet(schema, {
|
|
195
207
|
args: rest.slice(0, rest.length - 1) as SchemaArgs<S>,
|
|
196
208
|
value,
|
|
197
209
|
});
|
|
198
210
|
// TODO: reject with error if this fails in reducer
|
|
199
211
|
return this.dispatch(action);
|
|
200
|
-
}
|
|
212
|
+
}
|
|
201
213
|
|
|
202
214
|
/**
|
|
203
215
|
* Sets response for the Endpoint and args.
|
|
@@ -241,7 +253,7 @@ export default class Controller<
|
|
|
241
253
|
};
|
|
242
254
|
|
|
243
255
|
/**
|
|
244
|
-
* Resolves an inflight fetch.
|
|
256
|
+
* Resolves an inflight fetch.
|
|
245
257
|
* @see https://dataclient.io/docs/api/Controller#resolve
|
|
246
258
|
*/
|
|
247
259
|
resolve = <
|
|
@@ -420,11 +432,11 @@ export default class Controller<
|
|
|
420
432
|
shouldQuery ?
|
|
421
433
|
// nothing in endpoints cache, so try querying if we have a schema to do so
|
|
422
434
|
this.memo.buildQueryKey(
|
|
423
|
-
key,
|
|
424
435
|
schema,
|
|
425
436
|
args,
|
|
426
437
|
state.entities as any,
|
|
427
438
|
state.indexes,
|
|
439
|
+
key,
|
|
428
440
|
)
|
|
429
441
|
: cacheEndpoints;
|
|
430
442
|
|
|
@@ -454,8 +466,8 @@ export default class Controller<
|
|
|
454
466
|
// second argument is false if any entities are missing
|
|
455
467
|
// eslint-disable-next-line prefer-const
|
|
456
468
|
const { data, paths } = this.memo.denormalize(
|
|
457
|
-
input,
|
|
458
469
|
schema,
|
|
470
|
+
input,
|
|
459
471
|
state.entities,
|
|
460
472
|
args,
|
|
461
473
|
) as { data: any; paths: EntityPath[] };
|
|
@@ -490,16 +502,7 @@ export default class Controller<
|
|
|
490
502
|
.slice(0, rest.length - 1)
|
|
491
503
|
.map(ensurePojo) as SchemaArgs<S>;
|
|
492
504
|
|
|
493
|
-
|
|
494
|
-
const key = JSON.stringify(args);
|
|
495
|
-
|
|
496
|
-
return this.memo.query(
|
|
497
|
-
key,
|
|
498
|
-
schema,
|
|
499
|
-
args,
|
|
500
|
-
state.entities as any,
|
|
501
|
-
state.indexes,
|
|
502
|
-
);
|
|
505
|
+
return this.memo.query(schema, args, state.entities as any, state.indexes);
|
|
503
506
|
}
|
|
504
507
|
|
|
505
508
|
private getSchemaResponse<T>(
|
|
@@ -36,8 +36,8 @@ describe('Controller', () => {
|
|
|
36
36
|
tags: ['a', 'best', 'react'],
|
|
37
37
|
};
|
|
38
38
|
const { entities, result } = normalize(
|
|
39
|
-
payload,
|
|
40
39
|
CoolerArticleResource.get.schema,
|
|
40
|
+
payload,
|
|
41
41
|
);
|
|
42
42
|
const fetchKey = CoolerArticleResource.get.key({ id: payload.id });
|
|
43
43
|
const state = {
|
|
@@ -73,8 +73,8 @@ describe('Controller', () => {
|
|
|
73
73
|
tags: ['a', 'best', 'react'],
|
|
74
74
|
};
|
|
75
75
|
const { entities, result } = normalize(
|
|
76
|
-
payload,
|
|
77
76
|
CoolerArticleResource.get.schema,
|
|
77
|
+
payload,
|
|
78
78
|
);
|
|
79
79
|
const fetchKey = CoolerArticleResource.get.key({ id: payload.id });
|
|
80
80
|
const state = {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EXPIREALL_TYPE } from '../../actionTypes.js';
|
|
2
|
+
import type { ExpireAllAction } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export function createExpireAll(
|
|
5
|
+
testKey: (key: string) => boolean,
|
|
6
|
+
): ExpireAllAction {
|
|
7
|
+
return {
|
|
8
|
+
type: EXPIREALL_TYPE,
|
|
9
|
+
testKey,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
import type { EndpointInterface, NI } from '@data-client/normalizr';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
3
|
+
import { FETCH_TYPE } from '../../actionTypes.js';
|
|
4
|
+
import type { FetchAction, FetchMeta } from '../../types.js';
|
|
5
|
+
import { EndpointUpdateFunction } from '../types.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Requesting a fetch to begin
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export function createFetch<
|
|
11
11
|
E extends EndpointInterface & { update?: EndpointUpdateFunction<E> },
|
|
12
12
|
>(
|
|
13
13
|
endpoint: E,
|
|
14
14
|
{ args }: { args: readonly [...Parameters<E>] },
|
|
15
15
|
): FetchAction<E> {
|
|
16
|
-
const key = endpoint.key(...args);
|
|
17
16
|
let resolve: (value?: any | PromiseLike<any>) => void = 0 as any;
|
|
18
17
|
let reject: (reason?: any) => void = 0 as any;
|
|
19
18
|
const promise = new Promise<any>((a, b) => {
|
|
20
19
|
[resolve, reject] = [a, b];
|
|
21
20
|
});
|
|
22
|
-
const meta: FetchMeta
|
|
23
|
-
|
|
24
|
-
key,
|
|
25
|
-
throttle: !endpoint.sideEffect,
|
|
21
|
+
const meta: FetchMeta = {
|
|
22
|
+
fetchedAt: Date.now(),
|
|
26
23
|
resolve,
|
|
27
24
|
reject,
|
|
28
25
|
promise,
|
|
29
|
-
createdAt: Date.now(),
|
|
30
|
-
nm: false,
|
|
31
26
|
};
|
|
32
27
|
|
|
33
28
|
return {
|
|
34
29
|
type: FETCH_TYPE,
|
|
35
|
-
payload: () => endpoint(...args) as any,
|
|
36
|
-
meta,
|
|
37
30
|
endpoint,
|
|
31
|
+
args,
|
|
32
|
+
key: endpoint.key(...args),
|
|
33
|
+
meta,
|
|
38
34
|
};
|
|
39
35
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
|
|
3
|
+
import { INVALIDATE_TYPE } from '../../actionTypes.js';
|
|
4
|
+
import type { InvalidateAction } from '../../types.js';
|
|
5
|
+
|
|
6
|
+
export function createInvalidate<E extends EndpointInterface>(
|
|
7
|
+
endpoint: E,
|
|
8
|
+
{ args }: { args: readonly [...Parameters<E>] },
|
|
9
|
+
): InvalidateAction {
|
|
10
|
+
return {
|
|
11
|
+
type: INVALIDATE_TYPE,
|
|
12
|
+
key: endpoint.key(...args),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { INVALIDATEALL_TYPE } from '../../actionTypes.js';
|
|
2
|
+
import type { InvalidateAllAction } from '../../types.js';
|
|
3
|
+
|
|
4
|
+
export function createInvalidateAll(
|
|
5
|
+
testKey: (key: string) => boolean,
|
|
6
|
+
): InvalidateAllAction {
|
|
7
|
+
return {
|
|
8
|
+
type: INVALIDATEALL_TYPE,
|
|
9
|
+
testKey,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ActionMeta } from '../../actions.js';
|
|
2
|
+
|
|
3
|
+
export function createMeta(
|
|
4
|
+
expiryLength: number,
|
|
5
|
+
fetchedAt?: number,
|
|
6
|
+
): ActionMeta {
|
|
7
|
+
const now = Date.now();
|
|
8
|
+
return {
|
|
9
|
+
fetchedAt: fetchedAt ?? now,
|
|
10
|
+
date: now,
|
|
11
|
+
expiresAt: now + expiryLength,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { EndpointInterface } from '@data-client/normalizr';
|
|
2
|
+
|
|
3
|
+
import { createMeta } from './createMeta.js';
|
|
4
|
+
import { OPTIMISTIC_TYPE } from '../../actionTypes.js';
|
|
5
|
+
import type { OptimisticAction } from '../../types.js';
|
|
6
|
+
import type { EndpointUpdateFunction } from '../types.js';
|
|
7
|
+
|
|
8
|
+
export function createOptimistic<
|
|
9
|
+
E extends EndpointInterface & {
|
|
10
|
+
update?: EndpointUpdateFunction<E>;
|
|
11
|
+
},
|
|
12
|
+
>(
|
|
13
|
+
endpoint: E,
|
|
14
|
+
args: readonly [...Parameters<E>],
|
|
15
|
+
fetchedAt: number,
|
|
16
|
+
): OptimisticAction<E> {
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
if (
|
|
19
|
+
process.env.NODE_ENV === 'development' &&
|
|
20
|
+
(endpoint.dataExpiryLength ?? 0) < 0
|
|
21
|
+
) {
|
|
22
|
+
throw new Error('Negative expiry length are not allowed.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
type: OPTIMISTIC_TYPE,
|
|
27
|
+
endpoint,
|
|
28
|
+
args,
|
|
29
|
+
key: endpoint.key(...args),
|
|
30
|
+
meta: createMeta(endpoint.dataExpiryLength ?? 60000, fetchedAt),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Denormalize,
|
|
3
|
+
Queryable,
|
|
4
|
+
SchemaArgs,
|
|
5
|
+
} from '@data-client/normalizr';
|
|
6
|
+
|
|
7
|
+
import { createMeta } from './createMeta.js';
|
|
8
|
+
import { SET_TYPE } from '../../actionTypes.js';
|
|
9
|
+
import type { SetAction } from '../../types.js';
|
|
10
|
+
import ensurePojo from '../ensurePojo.js';
|
|
11
|
+
|
|
12
|
+
export function createSet<S extends Queryable>(
|
|
13
|
+
schema: S,
|
|
14
|
+
{
|
|
15
|
+
args,
|
|
16
|
+
fetchedAt,
|
|
17
|
+
value,
|
|
18
|
+
}: {
|
|
19
|
+
args: readonly [...SchemaArgs<S>];
|
|
20
|
+
value: {} | ((previousValue: Denormalize<S>) => {});
|
|
21
|
+
fetchedAt?: number;
|
|
22
|
+
},
|
|
23
|
+
): SetAction<S> {
|
|
24
|
+
return {
|
|
25
|
+
type: SET_TYPE,
|
|
26
|
+
schema,
|
|
27
|
+
value,
|
|
28
|
+
args: args.map(ensurePojo) as SchemaArgs<S>,
|
|
29
|
+
meta: createMeta(60000, fetchedAt),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { EndpointInterface, ResolveType } from '@data-client/normalizr';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
3
|
+
import { createMeta } from './createMeta.js';
|
|
4
|
+
import { SET_RESPONSE_TYPE } from '../../actionTypes.js';
|
|
5
|
+
import type { SetResponseAction } from '../../types.js';
|
|
6
|
+
import ensurePojo from '../ensurePojo.js';
|
|
7
|
+
import { EndpointUpdateFunction } from '../types.js';
|
|
7
8
|
|
|
8
|
-
export
|
|
9
|
+
export function createSetResponse<
|
|
9
10
|
E extends EndpointInterface & {
|
|
10
11
|
update?: EndpointUpdateFunction<E>;
|
|
11
12
|
},
|
|
@@ -19,7 +20,7 @@ export default function createSetResponse<
|
|
|
19
20
|
},
|
|
20
21
|
): SetResponseAction<E>;
|
|
21
22
|
|
|
22
|
-
export
|
|
23
|
+
export function createSetResponse<
|
|
23
24
|
E extends EndpointInterface & {
|
|
24
25
|
update?: EndpointUpdateFunction<E>;
|
|
25
26
|
},
|
|
@@ -33,7 +34,7 @@ export default function createSetResponse<
|
|
|
33
34
|
},
|
|
34
35
|
): SetResponseAction<E>;
|
|
35
36
|
|
|
36
|
-
export
|
|
37
|
+
export function createSetResponse<
|
|
37
38
|
E extends EndpointInterface & {
|
|
38
39
|
update?: EndpointUpdateFunction<E>;
|
|
39
40
|
},
|
|
@@ -53,27 +54,20 @@ export default function createSetResponse<
|
|
|
53
54
|
): SetResponseAction<E> {
|
|
54
55
|
const expiryLength: number =
|
|
55
56
|
error ?
|
|
56
|
-
endpoint.errorExpiryLength ?? 1000
|
|
57
|
-
: endpoint.dataExpiryLength ?? 60000;
|
|
57
|
+
(endpoint.errorExpiryLength ?? 1000)
|
|
58
|
+
: (endpoint.dataExpiryLength ?? 60000);
|
|
58
59
|
/* istanbul ignore next */
|
|
59
60
|
if (process.env.NODE_ENV === 'development' && expiryLength < 0) {
|
|
60
61
|
throw new Error('Negative expiry length are not allowed.');
|
|
61
62
|
}
|
|
62
|
-
const now = Date.now();
|
|
63
|
-
const meta: SetResponseMeta = {
|
|
64
|
-
args: args.map(ensurePojo),
|
|
65
|
-
fetchedAt: fetchedAt ?? now,
|
|
66
|
-
date: now,
|
|
67
|
-
expiresAt: now + expiryLength,
|
|
68
|
-
key: endpoint.key(...args),
|
|
69
|
-
};
|
|
70
63
|
|
|
71
|
-
|
|
64
|
+
return {
|
|
72
65
|
type: SET_RESPONSE_TYPE,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
endpoint,
|
|
67
|
+
response,
|
|
68
|
+
args: args.map(ensurePojo),
|
|
69
|
+
key: endpoint.key(...args),
|
|
70
|
+
meta: createMeta(expiryLength, fetchedAt),
|
|
71
|
+
error,
|
|
76
72
|
};
|
|
77
|
-
if (error) (action as any).error = true;
|
|
78
|
-
return action;
|
|
79
73
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EndpointInterface } from '@data-client/normalizr';
|
|
2
2
|
|
|
3
|
-
import { SUBSCRIBE_TYPE, UNSUBSCRIBE_TYPE } from '
|
|
4
|
-
import type { SubscribeAction, UnsubscribeAction } from '
|
|
3
|
+
import { SUBSCRIBE_TYPE, UNSUBSCRIBE_TYPE } from '../../actionTypes.js';
|
|
4
|
+
import type { SubscribeAction, UnsubscribeAction } from '../../types.js';
|
|
5
5
|
|
|
6
6
|
export function createSubscription<E extends EndpointInterface>(
|
|
7
7
|
endpoint: E,
|
|
@@ -10,10 +10,8 @@ export function createSubscription<E extends EndpointInterface>(
|
|
|
10
10
|
return {
|
|
11
11
|
type: SUBSCRIBE_TYPE,
|
|
12
12
|
endpoint,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
key: endpoint.key(...args),
|
|
16
|
-
},
|
|
13
|
+
args,
|
|
14
|
+
key: endpoint.key(...args),
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -24,9 +22,7 @@ export function createUnsubscription<E extends EndpointInterface>(
|
|
|
24
22
|
return {
|
|
25
23
|
type: UNSUBSCRIBE_TYPE,
|
|
26
24
|
endpoint,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
key: endpoint.key(...args),
|
|
30
|
-
},
|
|
25
|
+
args,
|
|
26
|
+
key: endpoint.key(...args),
|
|
31
27
|
};
|
|
32
28
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createSubscription,
|
|
3
|
+
createUnsubscription,
|
|
4
|
+
} from './createSubscription.js';
|
|
5
|
+
export { createSetResponse } from './createSetResponse.js';
|
|
6
|
+
export { createSet } from './createSet.js';
|
|
7
|
+
export { createReset } from './createReset.js';
|
|
8
|
+
export { createOptimistic } from './createOptimistic.js';
|
|
9
|
+
export { createMeta } from './createMeta.js';
|
|
10
|
+
export { createInvalidateAll } from './createInvalidateAll.js';
|
|
11
|
+
export { createInvalidate } from './createInvalidate.js';
|
|
12
|
+
export { createFetch } from './createFetch.js';
|
|
13
|
+
export { createExpireAll } from './createExpireAll.js';
|
package/src/index.ts
CHANGED
|
@@ -39,9 +39,7 @@ export type {
|
|
|
39
39
|
DataClientDispatch,
|
|
40
40
|
GenericDispatch,
|
|
41
41
|
} from './controller/Controller.js';
|
|
42
|
-
export
|
|
43
|
-
export { default as createSet } from './controller/createSet.js';
|
|
44
|
-
export { default as createSetResponse } from './controller/createSetResponse.js';
|
|
42
|
+
export * as actions from './controller/actions/index.js';
|
|
45
43
|
|
|
46
44
|
export * from './controller/types.js';
|
|
47
45
|
export * as actionTypes from './actionTypes.js';
|
package/src/internal.ts
CHANGED