@data-client/core 0.11.5 → 0.12.1
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 +24 -19
- package/dist/index.umd.min.js +1 -1
- package/legacy/actions.js +1 -1
- package/legacy/controller/Controller.js +25 -20
- package/legacy/controller/createFetch.js +1 -1
- package/legacy/manager/NetworkManager.js +1 -1
- package/lib/actions.d.ts +3 -3
- package/lib/actions.d.ts.map +1 -1
- package/lib/actions.js +1 -1
- package/lib/controller/Controller.d.ts +3 -7
- package/lib/controller/Controller.d.ts.map +1 -1
- package/lib/controller/Controller.js +25 -20
- package/lib/controller/createFetch.d.ts.map +1 -1
- package/lib/controller/createFetch.js +1 -1
- package/lib/manager/NetworkManager.js +1 -1
- package/package.json +1 -1
- package/src/actions.ts +3 -3
- package/src/controller/Controller.ts +38 -26
- package/src/controller/createFetch.ts +2 -2
- package/src/manager/NetworkManager.ts +3 -3
- package/src/manager/__tests__/networkManager.ts +1 -0
- package/src/manager/__tests__/pollingSubscription.ts +3 -1
- package/ts3.4/actions.d.ts +5 -3
- package/ts3.4/controller/Controller.d.ts +13 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EndpointInterface } from '@data-client/normalizr';
|
|
1
|
+
import type { EndpointInterface, NI } from '@data-client/normalizr';
|
|
2
2
|
|
|
3
3
|
import { EndpointUpdateFunction } from './types.js';
|
|
4
4
|
import { FETCH_TYPE } from '../actionTypes.js';
|
|
@@ -19,7 +19,7 @@ export default function createFetch<
|
|
|
19
19
|
const promise = new Promise<any>((a, b) => {
|
|
20
20
|
[resolve, reject] = [a, b];
|
|
21
21
|
});
|
|
22
|
-
const meta: FetchMeta = {
|
|
22
|
+
const meta: FetchMeta<typeof args> = {
|
|
23
23
|
args,
|
|
24
24
|
key,
|
|
25
25
|
throttle: !endpoint.sideEffect,
|
|
@@ -71,7 +71,7 @@ export default class NetworkManager implements Manager {
|
|
|
71
71
|
if (error) {
|
|
72
72
|
this.handleSet(
|
|
73
73
|
createSet(action.endpoint, {
|
|
74
|
-
args: action.meta.args
|
|
74
|
+
args: action.meta.args,
|
|
75
75
|
response: error,
|
|
76
76
|
fetchedAt: action.meta.fetchedAt,
|
|
77
77
|
error: true,
|
|
@@ -192,7 +192,7 @@ export default class NetworkManager implements Manager {
|
|
|
192
192
|
// don't update state with promises started before last clear
|
|
193
193
|
if (createdAt >= lastReset) {
|
|
194
194
|
this.controller.resolve(action.endpoint, {
|
|
195
|
-
args: action.meta.args
|
|
195
|
+
args: action.meta.args,
|
|
196
196
|
response: data,
|
|
197
197
|
fetchedAt: createdAt,
|
|
198
198
|
});
|
|
@@ -204,7 +204,7 @@ export default class NetworkManager implements Manager {
|
|
|
204
204
|
// don't update state with promises started before last clear
|
|
205
205
|
if (createdAt >= lastReset) {
|
|
206
206
|
this.controller.resolve(action.endpoint, {
|
|
207
|
-
args: action.meta.args
|
|
207
|
+
args: action.meta.args,
|
|
208
208
|
response: error,
|
|
209
209
|
fetchedAt: createdAt,
|
|
210
210
|
error: true,
|
|
@@ -288,7 +288,9 @@ describe('PollingSubscription', () => {
|
|
|
288
288
|
afterEach(() => {
|
|
289
289
|
warnSpy.mockRestore();
|
|
290
290
|
});
|
|
291
|
-
beforeEach(() =>
|
|
291
|
+
beforeEach(() =>
|
|
292
|
+
(warnSpy = jest.spyOn(console, 'warn')).mockImplementation(() => {}),
|
|
293
|
+
);
|
|
292
294
|
|
|
293
295
|
it('should stop all timers', () => {
|
|
294
296
|
dispatch.mockClear();
|
package/ts3.4/actions.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export interface SetActionError<E extends EndpointAndUpdate<E> = EndpointDefault
|
|
|
29
29
|
error: true;
|
|
30
30
|
}
|
|
31
31
|
export type SetAction<E extends EndpointAndUpdate<E> = EndpointDefault> = SetActionSuccess<E> | SetActionError<E>;
|
|
32
|
-
export interface FetchMeta {
|
|
33
|
-
args:
|
|
32
|
+
export interface FetchMeta<A extends readonly any[] = readonly any[]> {
|
|
33
|
+
args: A;
|
|
34
34
|
key: string;
|
|
35
35
|
throttle: boolean;
|
|
36
36
|
resolve: (value?: any | PromiseLike<any>) => void;
|
|
@@ -42,7 +42,9 @@ export interface FetchMeta {
|
|
|
42
42
|
export interface FetchAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
43
43
|
type: typeof FETCH_TYPE;
|
|
44
44
|
endpoint: E;
|
|
45
|
-
meta: FetchMeta
|
|
45
|
+
meta: FetchMeta<readonly [
|
|
46
|
+
...Parameters<E>
|
|
47
|
+
]>;
|
|
46
48
|
payload: () => ReturnType<E>;
|
|
47
49
|
}
|
|
48
50
|
export interface OptimisticAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
|
|
@@ -147,14 +147,20 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
147
147
|
* Gets the error, if any, for a given endpoint. Returns undefined for no errors.
|
|
148
148
|
* @see https://dataclient.io/docs/api/Controller#getError
|
|
149
149
|
*/
|
|
150
|
-
getError
|
|
151
|
-
null
|
|
150
|
+
getError<E extends EndpointInterface>(endpoint: E, ...rest: readonly [
|
|
151
|
+
null,
|
|
152
|
+
State<unknown>
|
|
153
|
+
] | readonly [
|
|
154
|
+
...Parameters<E>,
|
|
155
|
+
State<unknown>
|
|
156
|
+
]): ErrorTypes | undefined;
|
|
157
|
+
getError<E extends Pick<EndpointInterface, 'key'>>(endpoint: E, ...rest: readonly [
|
|
158
|
+
null,
|
|
159
|
+
State<unknown>
|
|
152
160
|
] | readonly [
|
|
153
|
-
...Parameters<E[
|
|
154
|
-
]>(endpoint: E, ...rest: [
|
|
155
|
-
...Args,
|
|
161
|
+
...Parameters<E['key']>,
|
|
156
162
|
State<unknown>
|
|
157
|
-
])
|
|
163
|
+
]): ErrorTypes | undefined;
|
|
158
164
|
/**
|
|
159
165
|
* Gets the (globally referentially stable) response for a given endpoint/args pair from state given.
|
|
160
166
|
* @see https://dataclient.io/docs/api/Controller#getResponse
|
|
@@ -162,12 +168,7 @@ export default class Controller<D extends GenericDispatch = DataClientDispatch>
|
|
|
162
168
|
getResponse<E extends EndpointInterface>(endpoint: E, ...rest: readonly [
|
|
163
169
|
null,
|
|
164
170
|
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
|
+
] | readonly [
|
|
171
172
|
...Parameters<E>,
|
|
172
173
|
State<unknown>
|
|
173
174
|
]): {
|