@data-client/core 0.12.5 → 0.13.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 +1 -1
- package/dist/index.js +85 -13
- package/dist/index.umd.min.js +1 -1
- package/legacy/actionTypes.js +2 -1
- package/legacy/actions.js +1 -1
- package/legacy/controller/Controller.js +21 -7
- package/legacy/controller/createSet.js +7 -11
- package/legacy/controller/createSetResponse.js +32 -0
- package/legacy/index.js +2 -1
- package/legacy/manager/DevtoolsManager.js +1 -1
- package/legacy/manager/LogoutManager.js +3 -3
- package/legacy/manager/NetworkManager.js +5 -5
- package/legacy/manager/PollingSubscription.js +1 -1
- package/legacy/manager/SubscriptionManager.js +1 -1
- package/legacy/next/index.js +1 -1
- package/legacy/state/reducer/createReducer.js +6 -3
- package/legacy/state/reducer/fetchReducer.js +1 -1
- package/legacy/state/reducer/setReducer.js +7 -85
- package/legacy/state/reducer/setResponseReducer.js +107 -0
- package/legacy/types.js +1 -1
- package/lib/actionTypes.d.ts +1 -0
- package/lib/actionTypes.d.ts.map +1 -1
- package/lib/actionTypes.js +2 -1
- package/lib/actions.d.ts +23 -11
- package/lib/actions.d.ts.map +1 -1
- package/lib/actions.js +1 -1
- package/lib/controller/Controller.d.ts +7 -2
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +21 -7
- package/lib/controller/createSet.d.ts +5 -17
- package/lib/controller/createSet.d.ts.map +1 -1
- package/lib/controller/createSet.js +7 -11
- package/lib/controller/createSetResponse.d.ts +20 -0
- package/lib/controller/createSetResponse.d.ts.map +1 -0
- package/lib/controller/createSetResponse.js +32 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/manager/DevtoolsManager.js +1 -1
- package/lib/manager/LogoutManager.js +3 -3
- package/lib/manager/NetworkManager.d.ts +2 -2
- package/lib/manager/NetworkManager.d.ts.map +1 -1
- package/lib/manager/NetworkManager.js +5 -5
- package/lib/manager/PollingSubscription.js +1 -1
- package/lib/manager/SubscriptionManager.js +1 -1
- package/lib/next/index.js +1 -1
- package/lib/state/reducer/createReducer.d.ts.map +1 -1
- package/lib/state/reducer/createReducer.js +6 -3
- package/lib/state/reducer/expireReducer.d.ts +1 -1
- package/lib/state/reducer/fetchReducer.js +1 -1
- package/lib/state/reducer/invalidateReducer.d.ts +1 -1
- package/lib/state/reducer/setReducer.d.ts +2 -3
- package/lib/state/reducer/setReducer.d.ts.map +1 -1
- package/lib/state/reducer/setReducer.js +7 -90
- package/lib/state/reducer/setResponseReducer.d.ts +4 -0
- package/lib/state/reducer/setResponseReducer.d.ts.map +1 -0
- package/lib/state/reducer/setResponseReducer.js +112 -0
- package/lib/types.d.ts +2 -4
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +1 -1
- package/package.json +1 -1
- package/src/actionTypes.ts +1 -0
- package/src/actions.ts +29 -10
- package/src/controller/Controller.ts +25 -8
- package/src/controller/createSet.ts +11 -51
- package/src/controller/createSetResponse.ts +79 -0
- package/src/index.ts +1 -0
- package/src/manager/LogoutManager.ts +2 -2
- package/src/manager/NetworkManager.ts +6 -6
- package/src/manager/__tests__/logoutManager.ts +5 -5
- package/src/manager/__tests__/networkManager.ts +6 -6
- package/src/manager/__tests__/subscriptionManager.ts +2 -2
- package/src/state/__tests__/reducer.ts +64 -25
- package/src/state/reducer/createReducer.ts +6 -1
- package/src/state/reducer/fetchReducer.ts +2 -2
- package/src/state/reducer/setReducer.ts +9 -121
- package/src/state/reducer/setResponseReducer.ts +151 -0
- package/src/types.ts +6 -5
- package/ts3.4/actionTypes.d.ts +1 -0
- package/ts3.4/actions.d.ts +23 -11
- package/ts3.4/controller/Controller.d.ts +10 -2
- package/ts3.4/controller/createSet.d.ts +5 -19
- package/ts3.4/controller/createSetResponse.d.ts +24 -0
- package/ts3.4/index.d.ts +1 -0
- package/ts3.4/manager/NetworkManager.d.ts +2 -2
- package/ts3.4/state/reducer/expireReducer.d.ts +1 -1
- package/ts3.4/state/reducer/invalidateReducer.d.ts +1 -1
- package/ts3.4/state/reducer/setReducer.d.ts +2 -3
- package/ts3.4/state/reducer/setResponseReducer.d.ts +4 -0
- package/ts3.4/types.d.ts +2 -4
package/ts3.4/actions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { EndpointInterface, ResolveType, UnknownError } from '@data-client/normalizr';
|
|
2
|
-
import { SET_TYPE, RESET_TYPE, FETCH_TYPE, SUBSCRIBE_TYPE, UNSUBSCRIBE_TYPE, INVALIDATE_TYPE, GC_TYPE, OPTIMISTIC_TYPE, INVALIDATEALL_TYPE, EXPIREALL_TYPE } from './actionTypes.js';
|
|
1
|
+
import { Denormalize, EndpointInterface, Queryable, ResolveType, UnknownError } from '@data-client/normalizr';
|
|
2
|
+
import { SET_TYPE, RESET_TYPE, FETCH_TYPE, SUBSCRIBE_TYPE, UNSUBSCRIBE_TYPE, INVALIDATE_TYPE, GC_TYPE, OPTIMISTIC_TYPE, INVALIDATEALL_TYPE, EXPIREALL_TYPE, SET_RESPONSE_TYPE } from './actionTypes.js';
|
|
3
3
|
import { EndpointUpdateFunction } from './controller/types.js';
|
|
4
4
|
type EndpointAndUpdate<E extends EndpointInterface> = EndpointInterface & {
|
|
5
5
|
update?: EndpointUpdateFunction<E>;
|
|
@@ -9,26 +9,38 @@ type EndpointDefault = EndpointInterface & {
|
|
|
9
9
|
};
|
|
10
10
|
export interface SetMeta {
|
|
11
11
|
args: readonly any[];
|
|
12
|
-
key: string;
|
|
13
12
|
fetchedAt: number;
|
|
14
13
|
date: number;
|
|
15
14
|
expiresAt: number;
|
|
16
15
|
}
|
|
17
|
-
export interface
|
|
16
|
+
export interface SetAction<S extends Queryable = any> {
|
|
18
17
|
type: typeof SET_TYPE;
|
|
19
|
-
|
|
18
|
+
schema: S;
|
|
20
19
|
meta: SetMeta;
|
|
20
|
+
value: Denormalize<S>;
|
|
21
|
+
}
|
|
22
|
+
export interface SetResponseMeta {
|
|
23
|
+
args: readonly any[];
|
|
24
|
+
key: string;
|
|
25
|
+
fetchedAt: number;
|
|
26
|
+
date: number;
|
|
27
|
+
expiresAt: number;
|
|
28
|
+
}
|
|
29
|
+
export interface SetResponseActionSuccess<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
30
|
+
type: typeof SET_RESPONSE_TYPE;
|
|
31
|
+
endpoint: E;
|
|
32
|
+
meta: SetResponseMeta;
|
|
21
33
|
payload: ResolveType<E>;
|
|
22
34
|
error?: false;
|
|
23
35
|
}
|
|
24
|
-
export interface
|
|
25
|
-
type: typeof
|
|
36
|
+
export interface SetResponseActionError<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
37
|
+
type: typeof SET_RESPONSE_TYPE;
|
|
26
38
|
endpoint: E;
|
|
27
|
-
meta:
|
|
39
|
+
meta: SetResponseMeta;
|
|
28
40
|
payload: UnknownError;
|
|
29
41
|
error: true;
|
|
30
42
|
}
|
|
31
|
-
export type
|
|
43
|
+
export type SetResponseAction<E extends EndpointAndUpdate<E> = EndpointDefault> = SetResponseActionSuccess<E> | SetResponseActionError<E>;
|
|
32
44
|
export interface FetchMeta<A extends readonly any[] = readonly any[]> {
|
|
33
45
|
args: A;
|
|
34
46
|
key: string;
|
|
@@ -50,7 +62,7 @@ export interface FetchAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
|
50
62
|
export interface OptimisticAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
51
63
|
type: typeof OPTIMISTIC_TYPE;
|
|
52
64
|
endpoint: E;
|
|
53
|
-
meta:
|
|
65
|
+
meta: SetResponseMeta;
|
|
54
66
|
error?: false;
|
|
55
67
|
}
|
|
56
68
|
export interface SubscribeAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
@@ -95,6 +107,6 @@ export interface GCAction {
|
|
|
95
107
|
][];
|
|
96
108
|
endpoints: string[];
|
|
97
109
|
}
|
|
98
|
-
export type ActionTypes = FetchAction | OptimisticAction | SetAction | SubscribeAction | UnsubscribeAction | InvalidateAction | InvalidateAllAction | ExpireAllAction | ResetAction | GCAction;
|
|
110
|
+
export type ActionTypes = FetchAction | OptimisticAction | SetAction | SetResponseAction | SubscribeAction | UnsubscribeAction | InvalidateAction | InvalidateAllAction | ExpireAllAction | ResetAction | GCAction;
|
|
99
111
|
export {};
|
|
100
112
|
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -79,9 +79,17 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
79
79
|
*/
|
|
80
80
|
resetEntireStore: () => Promise<void>;
|
|
81
81
|
/**
|
|
82
|
-
*
|
|
82
|
+
* Sets value for the Queryable and args.
|
|
83
83
|
* @see https://dataclient.io/docs/api/Controller#set
|
|
84
84
|
*/
|
|
85
|
+
set: <S extends Queryable>(schema: S, ...rest: readonly [
|
|
86
|
+
...SchemaArgs<S>,
|
|
87
|
+
any
|
|
88
|
+
]) => Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Sets response for the Endpoint and args.
|
|
91
|
+
* @see https://dataclient.io/docs/api/Controller#setResponse
|
|
92
|
+
*/
|
|
85
93
|
setResponse: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
86
94
|
update?: EndpointUpdateFunction<E> | undefined;
|
|
87
95
|
}>(endpoint: E, ...rest: readonly [
|
|
@@ -89,7 +97,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
89
97
|
any
|
|
90
98
|
]) => Promise<void>;
|
|
91
99
|
/**
|
|
92
|
-
*
|
|
100
|
+
* Sets an error response for the Endpoint and args.
|
|
93
101
|
* @see https://dataclient.io/docs/api/Controller#setError
|
|
94
102
|
*/
|
|
95
103
|
setError: <E extends EndpointInterface<FetchFunction, Schema | undefined, boolean | undefined> & {
|
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EndpointUpdateFunction } from './types.js';
|
|
1
|
+
import { Queryable, SchemaArgs } from '@data-client/normalizr';
|
|
3
2
|
import { SetAction } from '../types.js';
|
|
4
|
-
export default function createSet<
|
|
5
|
-
update?: EndpointUpdateFunction<E>;
|
|
6
|
-
}>(endpoint: E, options: {
|
|
3
|
+
export default function createSet<S extends Queryable>(schema: S, { args, fetchedAt, value, }: {
|
|
7
4
|
args: readonly [
|
|
8
|
-
...
|
|
5
|
+
...SchemaArgs<S>
|
|
9
6
|
];
|
|
10
|
-
|
|
7
|
+
value: any;
|
|
11
8
|
fetchedAt?: number;
|
|
12
|
-
|
|
13
|
-
}): SetAction<E>;
|
|
14
|
-
export default function createSet<E extends EndpointInterface & {
|
|
15
|
-
update?: EndpointUpdateFunction<E>;
|
|
16
|
-
}>(endpoint: E, options: {
|
|
17
|
-
args: readonly [
|
|
18
|
-
...Parameters<E>
|
|
19
|
-
];
|
|
20
|
-
response: ResolveType<E>;
|
|
21
|
-
fetchedAt?: number;
|
|
22
|
-
error?: false;
|
|
23
|
-
}): SetAction<E>;
|
|
9
|
+
}): SetAction<S>;
|
|
24
10
|
//# sourceMappingURL=createSet.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EndpointInterface, ResolveType } from '@data-client/normalizr';
|
|
2
|
+
import { EndpointUpdateFunction } from './types.js';
|
|
3
|
+
import { SetResponseAction } from '../types.js';
|
|
4
|
+
export default function createSetResponse<E extends EndpointInterface & {
|
|
5
|
+
update?: EndpointUpdateFunction<E>;
|
|
6
|
+
}>(endpoint: E, options: {
|
|
7
|
+
args: readonly [
|
|
8
|
+
...Parameters<E>
|
|
9
|
+
];
|
|
10
|
+
response: Error;
|
|
11
|
+
fetchedAt?: number;
|
|
12
|
+
error: true;
|
|
13
|
+
}): SetResponseAction<E>;
|
|
14
|
+
export default function createSetResponse<E extends EndpointInterface & {
|
|
15
|
+
update?: EndpointUpdateFunction<E>;
|
|
16
|
+
}>(endpoint: E, options: {
|
|
17
|
+
args: readonly [
|
|
18
|
+
...Parameters<E>
|
|
19
|
+
];
|
|
20
|
+
response: ResolveType<E>;
|
|
21
|
+
fetchedAt?: number;
|
|
22
|
+
error?: false;
|
|
23
|
+
}): SetResponseAction<E>;
|
|
24
|
+
//# sourceMappingURL=createSetResponse.d.ts.map
|
package/ts3.4/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ 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
11
|
export { default as createSet } from './controller/createSet.js';
|
|
12
|
+
export { default as createSetResponse } from './controller/createSetResponse.js';
|
|
12
13
|
export * from './controller/types.js';
|
|
13
14
|
import * as actionTypes_1 from './actionTypes.js';
|
|
14
15
|
export { actionTypes_1 as actionTypes };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Controller from '../controller/Controller.js';
|
|
2
|
-
import { FetchAction, Manager, ActionTypes, Middleware,
|
|
2
|
+
import { FetchAction, Manager, ActionTypes, Middleware, SetResponseAction } from '../types.js';
|
|
3
3
|
export declare class ResetError extends Error {
|
|
4
4
|
name: string;
|
|
5
5
|
constructor();
|
|
@@ -57,7 +57,7 @@ export default class NetworkManager implements Manager {
|
|
|
57
57
|
*
|
|
58
58
|
* Will resolve the promise associated with set key.
|
|
59
59
|
*/
|
|
60
|
-
protected handleSet(action:
|
|
60
|
+
protected handleSet(action: SetResponseAction): void;
|
|
61
61
|
/** Attaches NetworkManager to store
|
|
62
62
|
*
|
|
63
63
|
* Intercepts 'rdc/fetch' actions to start requests.
|
|
@@ -28,7 +28,7 @@ export declare function expireReducer(state: State<unknown>, action: ExpireAllAc
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
optimistic: (import("../../actions.js").
|
|
31
|
+
optimistic: (import("../../actions.js").SetResponseAction | 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("../../actions.js").
|
|
31
|
+
optimistic: (import("../../actions.js").SetResponseAction | 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;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare function setReducer(state: State<unknown>, action: OptimisticAction | SetAction, controller: Controller): State<unknown>;
|
|
1
|
+
import { State, SetAction } from '../../types.js';
|
|
2
|
+
export declare function setReducer(state: State<unknown>, action: SetAction): State<unknown>;
|
|
4
3
|
//# sourceMappingURL=setReducer.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import Controller from '../../controller/Controller.js';
|
|
2
|
+
import { State, SetResponseAction, OptimisticAction } from '../../types.js';
|
|
3
|
+
export declare function setResponseReducer(state: State<unknown>, action: OptimisticAction | SetResponseAction, controller: Controller): State<unknown>;
|
|
4
|
+
//# sourceMappingURL=setResponseReducer.d.ts.map
|
package/ts3.4/types.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { NormalizedIndex } from '@data-client/normalizr';
|
|
2
2
|
import { UpdateFunction, AbstractInstanceType } from '@data-client/normalizr';
|
|
3
3
|
import { ErrorTypes } from '@data-client/normalizr';
|
|
4
|
-
import { ActionTypes,
|
|
5
|
-
import { SET_TYPE } from './actionTypes.js';
|
|
4
|
+
import { ActionTypes, SetResponseAction, OptimisticAction } from './actions.js';
|
|
6
5
|
import { Dispatch, Middleware, MiddlewareAPI } from './middlewareTypes.js';
|
|
7
6
|
export { AbstractInstanceType, UpdateFunction };
|
|
8
|
-
export type SetTypes = typeof SET_TYPE;
|
|
9
7
|
export type PK = string;
|
|
10
8
|
export interface State<T> {
|
|
11
9
|
readonly entities: {
|
|
@@ -36,7 +34,7 @@ export interface State<T> {
|
|
|
36
34
|
};
|
|
37
35
|
};
|
|
38
36
|
};
|
|
39
|
-
readonly optimistic: (
|
|
37
|
+
readonly optimistic: (SetResponseAction | OptimisticAction)[];
|
|
40
38
|
readonly lastReset: number;
|
|
41
39
|
}
|
|
42
40
|
export * from './actions.js';
|