@data-client/core 0.10.0 → 0.11.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/README.md +2 -1
- package/dist/index.js +122 -89
- package/dist/index.umd.min.js +1 -1
- package/legacy/actionTypes.js +1 -1
- package/legacy/actions.js +1 -1
- package/legacy/controller/AbortOptimistic.js +2 -0
- package/legacy/controller/Controller.js +108 -76
- package/legacy/controller/createExpireAll.js +1 -1
- package/legacy/controller/createFetch.js +1 -1
- package/legacy/controller/createInvalidate.js +1 -1
- package/legacy/controller/createInvalidateAll.js +1 -1
- package/legacy/controller/createOptimistic.js +1 -1
- package/legacy/controller/createReset.js +1 -1
- package/legacy/controller/createSet.js +1 -1
- package/legacy/controller/createSubscription.js +1 -1
- package/legacy/controller/ensurePojo.js +1 -1
- package/legacy/controller/types.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/internal.js +2 -2
- package/legacy/manager/ConnectionListener.js +1 -1
- package/legacy/manager/DefaultConnectionListener.js +1 -1
- package/legacy/manager/DevtoolsManager.js +1 -1
- package/legacy/manager/LogoutManager.js +1 -1
- package/legacy/manager/NetworkManager.js +1 -1
- package/legacy/manager/PollingSubscription.js +1 -1
- package/legacy/manager/SubscriptionManager.js +1 -1
- package/legacy/manager/applyManager.js +1 -1
- package/legacy/manager/devtoolsTypes.js +1 -1
- package/legacy/manager/index.js +1 -1
- package/legacy/middlewareTypes.js +1 -1
- package/legacy/next/index.js +1 -1
- package/legacy/state/RIC.js +1 -1
- package/legacy/state/reducer/createReducer.js +4 -4
- package/legacy/state/reducer/expireReducer.js +1 -1
- package/legacy/state/reducer/fetchReducer.js +1 -1
- package/legacy/state/reducer/invalidateReducer.js +5 -5
- package/legacy/state/reducer/setReducer.js +7 -7
- package/legacy/state/selectMeta.js +1 -1
- package/legacy/types.js +1 -1
- package/lib/actionTypes.js +1 -1
- package/lib/actions.d.ts +1 -1
- package/lib/actions.d.ts.map +1 -1
- package/lib/actions.js +1 -1
- package/lib/controller/AbortOptimistic.d.ts +3 -0
- package/lib/controller/AbortOptimistic.d.ts.map +1 -0
- package/lib/controller/AbortOptimistic.js +2 -0
- package/lib/controller/Controller.d.ts +36 -11
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +108 -76
- package/lib/controller/createExpireAll.js +1 -1
- package/lib/controller/createFetch.js +1 -1
- package/lib/controller/createInvalidate.js +1 -1
- package/lib/controller/createInvalidateAll.js +1 -1
- package/lib/controller/createOptimistic.js +1 -1
- package/lib/controller/createReset.js +1 -1
- package/lib/controller/createSet.js +1 -1
- package/lib/controller/createSubscription.js +1 -1
- package/lib/controller/ensurePojo.js +1 -1
- package/lib/controller/types.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/internal.d.ts +1 -1
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +2 -2
- package/lib/manager/ConnectionListener.js +1 -1
- package/lib/manager/DefaultConnectionListener.js +1 -1
- package/lib/manager/DevtoolsManager.js +1 -1
- package/lib/manager/LogoutManager.js +1 -1
- package/lib/manager/NetworkManager.js +1 -1
- package/lib/manager/PollingSubscription.js +1 -1
- package/lib/manager/SubscriptionManager.js +1 -1
- package/lib/manager/applyManager.js +1 -1
- package/lib/manager/devtoolsTypes.js +1 -1
- package/lib/manager/index.js +1 -1
- package/lib/middlewareTypes.js +1 -1
- package/lib/next/index.js +1 -1
- package/lib/state/RIC.js +1 -1
- package/lib/state/reducer/createReducer.js +4 -4
- package/lib/state/reducer/expireReducer.d.ts +1 -1
- package/lib/state/reducer/expireReducer.js +1 -1
- package/lib/state/reducer/fetchReducer.js +1 -1
- package/lib/state/reducer/invalidateReducer.d.ts +1 -1
- package/lib/state/reducer/invalidateReducer.js +6 -6
- package/lib/state/reducer/setReducer.d.ts.map +1 -1
- package/lib/state/reducer/setReducer.js +8 -8
- package/lib/state/selectMeta.js +1 -1
- package/lib/types.d.ts +1 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -1
- package/package.json +3 -3
- package/src/actions.ts +1 -1
- package/src/controller/AbortOptimistic.ts +1 -0
- package/src/controller/Controller.ts +185 -63
- package/src/controller/__tests__/Controller.ts +2 -4
- package/src/controller/__tests__/__snapshots__/get.ts.snap +120 -0
- package/src/controller/__tests__/get.ts +285 -0
- package/src/controller/__tests__/getResponse.ts +2 -2
- package/src/index.ts +2 -1
- package/src/internal.ts +1 -1
- package/src/state/__tests__/__snapshots__/reducer.ts.snap +4 -4
- package/src/state/__tests__/reducer.ts +25 -25
- package/src/state/reducer/createReducer.ts +3 -3
- package/src/state/reducer/invalidateReducer.ts +4 -4
- package/src/state/reducer/setReducer.ts +7 -6
- package/src/types.ts +3 -1
- package/ts3.4/actions.d.ts +1 -1
- package/ts3.4/controller/AbortOptimistic.d.ts +3 -0
- package/ts3.4/controller/Controller.d.ts +47 -19
- package/ts3.4/index.d.ts +1 -1
- package/ts3.4/internal.d.ts +1 -1
- package/ts3.4/state/reducer/expireReducer.d.ts +1 -1
- package/ts3.4/state/reducer/invalidateReducer.d.ts +1 -1
- package/ts3.4/types.d.ts +1 -1
|
@@ -28,8 +28,8 @@ export default function createReducer(controller: Controller): ReducerType {
|
|
|
28
28
|
delete (state as any).entities[key]?.[pk];
|
|
29
29
|
delete (state as any).entityMeta[key]?.[pk];
|
|
30
30
|
});
|
|
31
|
-
action.
|
|
32
|
-
delete (state as any).
|
|
31
|
+
action.endpoints.forEach(fetchKey => {
|
|
32
|
+
delete (state as any).endpoints[fetchKey];
|
|
33
33
|
delete (state as any).meta[fetchKey];
|
|
34
34
|
});
|
|
35
35
|
return state;
|
|
@@ -62,7 +62,7 @@ export default function createReducer(controller: Controller): ReducerType {
|
|
|
62
62
|
export const initialState: State<unknown> = {
|
|
63
63
|
entities: {},
|
|
64
64
|
indexes: {},
|
|
65
|
-
|
|
65
|
+
endpoints: {},
|
|
66
66
|
meta: {},
|
|
67
67
|
entityMeta: {},
|
|
68
68
|
optimistic: [],
|
|
@@ -9,10 +9,10 @@ export function invalidateReducer(
|
|
|
9
9
|
state: State<unknown>,
|
|
10
10
|
action: InvalidateAction | InvalidateAllAction,
|
|
11
11
|
) {
|
|
12
|
-
const
|
|
12
|
+
const endpoints = { ...state.endpoints };
|
|
13
13
|
const meta = { ...state.meta };
|
|
14
14
|
const invalidateKey = (key: string) => {
|
|
15
|
-
delete
|
|
15
|
+
delete endpoints[key];
|
|
16
16
|
const itemMeta = {
|
|
17
17
|
...meta[key],
|
|
18
18
|
expiresAt: 0,
|
|
@@ -24,7 +24,7 @@ export function invalidateReducer(
|
|
|
24
24
|
if (action.type === INVALIDATE_TYPE) {
|
|
25
25
|
invalidateKey(action.meta.key);
|
|
26
26
|
} else {
|
|
27
|
-
Object.keys(
|
|
27
|
+
Object.keys(endpoints).forEach(key => {
|
|
28
28
|
if (action.testKey(key)) {
|
|
29
29
|
invalidateKey(key);
|
|
30
30
|
}
|
|
@@ -33,7 +33,7 @@ export function invalidateReducer(
|
|
|
33
33
|
|
|
34
34
|
return {
|
|
35
35
|
...state,
|
|
36
|
-
|
|
36
|
+
endpoints,
|
|
37
37
|
meta,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { normalize } from '@data-client/normalizr';
|
|
2
2
|
|
|
3
3
|
import { OPTIMISTIC_TYPE } from '../../actionTypes.js';
|
|
4
|
+
import AbortOptimistic from '../../controller/AbortOptimistic.js';
|
|
4
5
|
import type Controller from '../../controller/Controller.js';
|
|
5
6
|
import type { State, SetAction, OptimisticAction } from '../../types.js';
|
|
6
7
|
|
|
@@ -27,7 +28,7 @@ export function setReducer(
|
|
|
27
28
|
);
|
|
28
29
|
} catch (e: any) {
|
|
29
30
|
// AbortOptimistic means 'do nothing', otherwise we count the exception as endpoint failure
|
|
30
|
-
if (e.constructor
|
|
31
|
+
if (e.constructor === AbortOptimistic) {
|
|
31
32
|
return state;
|
|
32
33
|
}
|
|
33
34
|
throw e;
|
|
@@ -44,15 +45,15 @@ export function setReducer(
|
|
|
44
45
|
state.entityMeta,
|
|
45
46
|
action.meta,
|
|
46
47
|
);
|
|
47
|
-
const
|
|
48
|
-
...state.
|
|
48
|
+
const endpoints = {
|
|
49
|
+
...state.endpoints,
|
|
49
50
|
[action.meta.key]: result,
|
|
50
51
|
};
|
|
51
52
|
try {
|
|
52
53
|
if (action.endpoint.update) {
|
|
53
54
|
const updaters = action.endpoint.update(result, ...action.meta.args);
|
|
54
55
|
Object.keys(updaters).forEach(key => {
|
|
55
|
-
|
|
56
|
+
endpoints[key] = updaters[key](endpoints[key]);
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
// no reason to completely fail because of user-code error
|
|
@@ -66,7 +67,7 @@ export function setReducer(
|
|
|
66
67
|
return {
|
|
67
68
|
entities,
|
|
68
69
|
indexes,
|
|
69
|
-
|
|
70
|
+
endpoints,
|
|
70
71
|
entityMeta,
|
|
71
72
|
meta: {
|
|
72
73
|
...state.meta,
|
|
@@ -79,7 +80,7 @@ export function setReducer(
|
|
|
79
80
|
optimistic: filterOptimistic(state, action),
|
|
80
81
|
lastReset: state.lastReset,
|
|
81
82
|
};
|
|
82
|
-
// reducer must update the state, so in case of processing errors we simply compute the
|
|
83
|
+
// reducer must update the state, so in case of processing errors we simply compute the endpoints inline
|
|
83
84
|
} catch (error: any) {
|
|
84
85
|
if (typeof error === 'object') {
|
|
85
86
|
error.message = `Error processing ${
|
package/src/types.ts
CHANGED
|
@@ -20,7 +20,9 @@ export interface State<T> {
|
|
|
20
20
|
readonly [entityKey: string]: { readonly [pk: string]: T } | undefined;
|
|
21
21
|
};
|
|
22
22
|
readonly indexes: NormalizedIndex;
|
|
23
|
-
readonly
|
|
23
|
+
readonly endpoints: {
|
|
24
|
+
readonly [key: string]: unknown | PK[] | PK | undefined;
|
|
25
|
+
};
|
|
24
26
|
readonly meta: {
|
|
25
27
|
readonly [key: string]: {
|
|
26
28
|
readonly date: number;
|
package/ts3.4/actions.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ export interface GCAction {
|
|
|
91
91
|
string,
|
|
92
92
|
string
|
|
93
93
|
][];
|
|
94
|
-
|
|
94
|
+
endpoints: string[];
|
|
95
95
|
}
|
|
96
96
|
export type ActionTypes = FetchAction | OptimisticAction | SetAction | SubscribeAction | UnsubscribeAction | InvalidateAction | InvalidateAllAction | ExpireAllAction | ResetAction | GCAction;
|
|
97
97
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ErrorTypes, SnapshotInterface,
|
|
2
|
-
import { ExpiryStatus, EndpointInterface, FetchFunction, ResolveType, DenormalizeNullable } from '@data-client/normalizr';
|
|
1
|
+
import { ErrorTypes, SnapshotInterface, Schema, Denormalize, Queryable, SchemaArgs } from '@data-client/normalizr';
|
|
2
|
+
import { ExpiryStatus, EndpointInterface, FetchFunction, ResolveType, DenormalizeNullable, MemoCache } from '@data-client/normalizr';
|
|
3
3
|
import { EndpointUpdateFunction } from './types.js';
|
|
4
4
|
import { ActionTypes, State } from '../types.js';
|
|
5
5
|
export type GenericDispatch = (value: any) => Promise<void>;
|
|
@@ -7,7 +7,7 @@ export type DataClientDispatch = (value: ActionTypes) => Promise<void>;
|
|
|
7
7
|
interface ConstructorProps<D extends GenericDispatch = DataClientDispatch> {
|
|
8
8
|
dispatch?: D;
|
|
9
9
|
getState?: () => State<unknown>;
|
|
10
|
-
|
|
10
|
+
memo?: Pick<MemoCache, 'denormalize' | 'query' | 'buildQueryKey'>;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Imperative control of Reactive Data Client store
|
|
@@ -28,8 +28,11 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
28
28
|
* @see https://dataclient.io/docs/api/Controller#getState
|
|
29
29
|
*/
|
|
30
30
|
readonly getState: () => State<unknown>;
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Singleton to maintain referential equality between calls
|
|
33
|
+
*/
|
|
34
|
+
readonly memo: Pick<MemoCache, 'denormalize' | 'query' | 'buildQueryKey'>;
|
|
35
|
+
constructor({ dispatch, getState, memo, }?: ConstructorProps<D>);
|
|
33
36
|
/*************** Action Dispatchers ***************/
|
|
34
37
|
/**
|
|
35
38
|
* Fetches the endpoint with given args, updating the Reactive Data Client cache with the response or error upon completion.
|
|
@@ -37,14 +40,14 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
37
40
|
*/
|
|
38
41
|
fetch: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
39
42
|
update?: EndpointUpdateFunction<E> | undefined;
|
|
40
|
-
}>(endpoint: E, ...args_0: Parameters<E>) => E[
|
|
43
|
+
}>(endpoint: E, ...args_0: Parameters<E>) => E['schema'] extends undefined | null ? ReturnType<E> : Promise<Denormalize<E['schema']>>;
|
|
41
44
|
/**
|
|
42
45
|
* Fetches only if endpoint is considered 'stale'; otherwise returns undefined
|
|
43
46
|
* @see https://dataclient.io/docs/api/Controller#fetchIfStale
|
|
44
47
|
*/
|
|
45
48
|
fetchIfStale: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
46
49
|
update?: EndpointUpdateFunction<E> | undefined;
|
|
47
|
-
}>(endpoint: E, ...args_0: Parameters<E>) => E[
|
|
50
|
+
}>(endpoint: E, ...args_0: Parameters<E>) => E['schema'] extends undefined | null ? ReturnType<E> | ResolveType<E> : Promise<Denormalize<E['schema']>> | Denormalize<E['schema']>;
|
|
48
51
|
/**
|
|
49
52
|
* Forces refetching and suspense on useSuspense with the same Endpoint and parameters.
|
|
50
53
|
* @see https://dataclient.io/docs/api/Controller#invalidate
|
|
@@ -121,18 +124,18 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
121
124
|
* @see https://dataclient.io/docs/api/Controller#subscribe
|
|
122
125
|
*/
|
|
123
126
|
subscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
|
|
124
|
-
null
|
|
125
|
-
] | readonly [
|
|
126
127
|
...Parameters<E>
|
|
128
|
+
] | readonly [
|
|
129
|
+
null
|
|
127
130
|
]) => Promise<void>;
|
|
128
131
|
/**
|
|
129
132
|
* Marks completion of subscription to a given Endpoint.
|
|
130
133
|
* @see https://dataclient.io/docs/api/Controller#unsubscribe
|
|
131
134
|
*/
|
|
132
135
|
unsubscribe: <E extends EndpointInterface<FetchFunction, Schema | undefined, false | undefined>>(endpoint: E, ...args: readonly [
|
|
133
|
-
null
|
|
134
|
-
] | readonly [
|
|
135
136
|
...Parameters<E>
|
|
137
|
+
] | readonly [
|
|
138
|
+
null
|
|
136
139
|
]) => Promise<void>;
|
|
137
140
|
/*************** More ***************/
|
|
138
141
|
/**
|
|
@@ -156,18 +159,43 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
156
159
|
* Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
|
|
157
160
|
* @see https://dataclient.io/docs/api/Controller#getResponse
|
|
158
161
|
*/
|
|
159
|
-
getResponse
|
|
160
|
-
null
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
getResponse<E extends EndpointInterface>(endpoint: E, ...rest: readonly [
|
|
163
|
+
null,
|
|
164
|
+
State<unknown>
|
|
165
|
+
]): {
|
|
166
|
+
data: DenormalizeNullable<E['schema']>;
|
|
167
|
+
expiryStatus: ExpiryStatus;
|
|
168
|
+
expiresAt: number;
|
|
169
|
+
};
|
|
170
|
+
getResponse<E extends EndpointInterface>(endpoint: E, ...rest: readonly [
|
|
171
|
+
...Parameters<E>,
|
|
165
172
|
State<unknown>
|
|
166
|
-
])
|
|
167
|
-
data: DenormalizeNullable<E[
|
|
173
|
+
]): {
|
|
174
|
+
data: DenormalizeNullable<E['schema']>;
|
|
168
175
|
expiryStatus: ExpiryStatus;
|
|
169
176
|
expiresAt: number;
|
|
170
177
|
};
|
|
178
|
+
getResponse<E extends Pick<EndpointInterface, 'key' | 'schema' | 'invalidIfStale'>>(endpoint: E, ...rest: readonly [
|
|
179
|
+
...(readonly [
|
|
180
|
+
...Parameters<E['key']>
|
|
181
|
+
] | readonly [
|
|
182
|
+
null
|
|
183
|
+
]),
|
|
184
|
+
State<unknown>
|
|
185
|
+
]): {
|
|
186
|
+
data: DenormalizeNullable<E['schema']>;
|
|
187
|
+
expiryStatus: ExpiryStatus;
|
|
188
|
+
expiresAt: number;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Queries the store for a Querable schema
|
|
192
|
+
* @see https://dataclient.io/docs/api/Controller#get
|
|
193
|
+
*/
|
|
194
|
+
get<S extends Queryable>(schema: S, ...rest: readonly [
|
|
195
|
+
...SchemaArgs<S>,
|
|
196
|
+
Pick<State<unknown>, 'entities' | 'entityMeta'>
|
|
197
|
+
]): DenormalizeNullable<S> | undefined;
|
|
198
|
+
private getSchemaResponse;
|
|
171
199
|
}
|
|
172
200
|
export { ErrorTypes };
|
|
173
201
|
//# sourceMappingURL=Controller.d.ts.map
|
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,
|
|
3
|
+
export { NetworkError, UnknownError, ErrorTypes, Schema, EndpointInterface, EntityInterface, ResolveType, DenormalizeNullable, Denormalize, Normalize, NormalizeNullable, FetchFunction, EndpointExtraOptions, Queryable, SchemaArgs, } 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';
|
package/ts3.4/internal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { MemoCache, 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
|
|
@@ -16,7 +16,7 @@ export declare function expireReducer(state: State<unknown>, action: ExpireAllAc
|
|
|
16
16
|
} | undefined;
|
|
17
17
|
};
|
|
18
18
|
indexes: import("packages/normalizr/lib/interface.js").NormalizedIndex;
|
|
19
|
-
|
|
19
|
+
endpoints: {
|
|
20
20
|
readonly [key: string]: unknown;
|
|
21
21
|
};
|
|
22
22
|
entityMeta: {
|