@data-client/core 0.10.0 → 0.11.4
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 +3 -1
- package/src/internal.ts +1 -1
- package/src/manager/__tests__/logoutManager.ts +0 -2
- 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
|
@@ -207,7 +207,7 @@ describe('reducer', () => {
|
|
|
207
207
|
});
|
|
208
208
|
});
|
|
209
209
|
|
|
210
|
-
it('mutate should never change
|
|
210
|
+
it('mutate should never change endpoints', () => {
|
|
211
211
|
const id = 20;
|
|
212
212
|
const payload = { id, title: 'hi', content: 'this is the content' };
|
|
213
213
|
const action: SetAction = {
|
|
@@ -224,10 +224,10 @@ describe('reducer', () => {
|
|
|
224
224
|
};
|
|
225
225
|
const iniState = {
|
|
226
226
|
...initialState,
|
|
227
|
-
|
|
227
|
+
endpoints: { abc: '5', [ArticleResource.get.key(payload)]: `${id}` },
|
|
228
228
|
};
|
|
229
229
|
const newState = reducer(iniState, action);
|
|
230
|
-
expect(newState.
|
|
230
|
+
expect(newState.endpoints).toStrictEqual(iniState.endpoints);
|
|
231
231
|
});
|
|
232
232
|
it('purge should delete entities', () => {
|
|
233
233
|
const id = 20;
|
|
@@ -256,10 +256,10 @@ describe('reducer', () => {
|
|
|
256
256
|
},
|
|
257
257
|
'5': undefined,
|
|
258
258
|
},
|
|
259
|
-
|
|
259
|
+
endpoints: { abc: '20' },
|
|
260
260
|
};
|
|
261
261
|
const newState = reducer(iniState, action);
|
|
262
|
-
expect(newState.
|
|
262
|
+
expect(newState.endpoints.abc).toBe(iniState.endpoints.abc);
|
|
263
263
|
const expectedEntities = { ...iniState.entities[Article.key] };
|
|
264
264
|
expectedEntities['20'] = INVALID;
|
|
265
265
|
expect(newState.entities[Article.key]).toEqual(expectedEntities);
|
|
@@ -277,8 +277,8 @@ describe('reducer', () => {
|
|
|
277
277
|
'10': PaginatedArticle.fromJS({ id: 10 }),
|
|
278
278
|
},
|
|
279
279
|
},
|
|
280
|
-
|
|
281
|
-
[PaginatedArticleResource.getList.key({})]: {
|
|
280
|
+
endpoints: {
|
|
281
|
+
[PaginatedArticleResource.getList.key({})]: { endpoints: ['10'] },
|
|
282
282
|
},
|
|
283
283
|
};
|
|
284
284
|
|
|
@@ -301,7 +301,7 @@ describe('reducer', () => {
|
|
|
301
301
|
);
|
|
302
302
|
const newState = reducer(iniState, action);
|
|
303
303
|
expect(
|
|
304
|
-
newState.
|
|
304
|
+
newState.endpoints[PaginatedArticleResource.getList.key({})],
|
|
305
305
|
).toStrictEqual({
|
|
306
306
|
results: ['10', '11', '12'],
|
|
307
307
|
});
|
|
@@ -328,7 +328,7 @@ describe('reducer', () => {
|
|
|
328
328
|
),
|
|
329
329
|
);
|
|
330
330
|
expect(
|
|
331
|
-
newState.
|
|
331
|
+
newState.endpoints[PaginatedArticleResource.getList.key({})],
|
|
332
332
|
).toStrictEqual({
|
|
333
333
|
results: ['11', '12', '10'],
|
|
334
334
|
});
|
|
@@ -342,7 +342,7 @@ describe('reducer', () => {
|
|
|
342
342
|
'10': PaginatedArticle.fromJS({ id: 10 }),
|
|
343
343
|
},
|
|
344
344
|
},
|
|
345
|
-
|
|
345
|
+
endpoints: {
|
|
346
346
|
[PaginatedArticleResource.getList.key({ admin: true })]: {
|
|
347
347
|
results: ['10'],
|
|
348
348
|
},
|
|
@@ -369,7 +369,7 @@ describe('reducer', () => {
|
|
|
369
369
|
),
|
|
370
370
|
);
|
|
371
371
|
expect(
|
|
372
|
-
newState.
|
|
372
|
+
newState.endpoints[
|
|
373
373
|
PaginatedArticleResource.getList.key({ admin: true })
|
|
374
374
|
],
|
|
375
375
|
).toStrictEqual({
|
|
@@ -400,7 +400,7 @@ describe('reducer', () => {
|
|
|
400
400
|
},
|
|
401
401
|
'5': undefined,
|
|
402
402
|
},
|
|
403
|
-
|
|
403
|
+
endpoints: { abc: '20' },
|
|
404
404
|
meta: {
|
|
405
405
|
'20': {
|
|
406
406
|
expiresAt: 500,
|
|
@@ -411,7 +411,7 @@ describe('reducer', () => {
|
|
|
411
411
|
},
|
|
412
412
|
};
|
|
413
413
|
const newState = reducer(iniState, action);
|
|
414
|
-
expect(newState.
|
|
414
|
+
expect(newState.endpoints).toEqual(iniState.endpoints);
|
|
415
415
|
expect(newState.entities).toBe(iniState.entities);
|
|
416
416
|
const expectedMeta = { ...iniState.meta };
|
|
417
417
|
expectedMeta['20'] = { expiresAt: 0, invalidated: true };
|
|
@@ -481,7 +481,7 @@ describe('reducer', () => {
|
|
|
481
481
|
[id]: Article.fromJS({}),
|
|
482
482
|
},
|
|
483
483
|
},
|
|
484
|
-
|
|
484
|
+
endpoints: {
|
|
485
485
|
[ArticleResource.get.url({ id })]: id,
|
|
486
486
|
},
|
|
487
487
|
};
|
|
@@ -509,7 +509,7 @@ describe('reducer', () => {
|
|
|
509
509
|
};
|
|
510
510
|
const iniState = {
|
|
511
511
|
...initialState,
|
|
512
|
-
|
|
512
|
+
endpoints: { abc: '5' },
|
|
513
513
|
};
|
|
514
514
|
const newState = reducer(iniState, action);
|
|
515
515
|
expect(newState).toBe(iniState);
|
|
@@ -524,7 +524,7 @@ describe('reducer', () => {
|
|
|
524
524
|
};
|
|
525
525
|
const iniState = {
|
|
526
526
|
...initialState,
|
|
527
|
-
|
|
527
|
+
endpoints: { abc: '5' },
|
|
528
528
|
};
|
|
529
529
|
const newState = reducer(iniState, action);
|
|
530
530
|
expect(newState).toBe(iniState);
|
|
@@ -556,10 +556,10 @@ describe('reducer', () => {
|
|
|
556
556
|
},
|
|
557
557
|
'5': undefined,
|
|
558
558
|
},
|
|
559
|
-
|
|
559
|
+
endpoints: { abc: '20' },
|
|
560
560
|
};
|
|
561
561
|
const newState = reducer(iniState, action);
|
|
562
|
-
expect(newState.
|
|
562
|
+
expect(newState.endpoints).toEqual({});
|
|
563
563
|
expect(newState.meta).toEqual({});
|
|
564
564
|
expect(newState.entities).toEqual({});
|
|
565
565
|
});
|
|
@@ -591,7 +591,7 @@ describe('reducer', () => {
|
|
|
591
591
|
'250': { date: 0, expiresAt: 10000, fetchedAt: 0 },
|
|
592
592
|
},
|
|
593
593
|
},
|
|
594
|
-
|
|
594
|
+
endpoints: { abc: '20' },
|
|
595
595
|
};
|
|
596
596
|
});
|
|
597
597
|
|
|
@@ -599,13 +599,13 @@ describe('reducer', () => {
|
|
|
599
599
|
const action: GCAction = {
|
|
600
600
|
type: GC_TYPE,
|
|
601
601
|
entities: [],
|
|
602
|
-
|
|
602
|
+
endpoints: [],
|
|
603
603
|
};
|
|
604
604
|
|
|
605
605
|
const newState = reducer(iniState, action);
|
|
606
606
|
expect(newState).toBe(iniState);
|
|
607
607
|
expect(Object.keys(newState.entities[Article.key] ?? {}).length).toBe(4);
|
|
608
|
-
expect(Object.keys(newState.
|
|
608
|
+
expect(Object.keys(newState.endpoints).length).toBe(1);
|
|
609
609
|
});
|
|
610
610
|
|
|
611
611
|
it('empty deleting entities should work', () => {
|
|
@@ -615,7 +615,7 @@ describe('reducer', () => {
|
|
|
615
615
|
[Article.key, '10'],
|
|
616
616
|
[Article.key, '250'],
|
|
617
617
|
],
|
|
618
|
-
|
|
618
|
+
endpoints: ['abc'],
|
|
619
619
|
};
|
|
620
620
|
|
|
621
621
|
const newState = reducer(iniState, action);
|
|
@@ -624,7 +624,7 @@ describe('reducer', () => {
|
|
|
624
624
|
expect(Object.keys(newState.entityMeta[Article.key] ?? {}).length).toBe(
|
|
625
625
|
2,
|
|
626
626
|
);
|
|
627
|
-
expect(Object.keys(newState.
|
|
627
|
+
expect(Object.keys(newState.endpoints).length).toBe(0);
|
|
628
628
|
});
|
|
629
629
|
|
|
630
630
|
it('empty deleting nonexistant things should passthrough', () => {
|
|
@@ -634,13 +634,13 @@ describe('reducer', () => {
|
|
|
634
634
|
[Article.key, '100000000'],
|
|
635
635
|
['sillythings', '10'],
|
|
636
636
|
],
|
|
637
|
-
|
|
637
|
+
endpoints: [],
|
|
638
638
|
};
|
|
639
639
|
|
|
640
640
|
const newState = reducer(iniState, action);
|
|
641
641
|
expect(newState).toBe(iniState);
|
|
642
642
|
expect(Object.keys(newState.entities[Article.key] ?? {}).length).toBe(4);
|
|
643
|
-
expect(Object.keys(newState.
|
|
643
|
+
expect(Object.keys(newState.endpoints).length).toBe(1);
|
|
644
644
|
});
|
|
645
645
|
});
|
|
646
646
|
});
|
|
@@ -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, 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';
|
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: {
|