@data-client/core 0.9.7 → 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 +24 -1
- package/dist/index.js +132 -96
- 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 +110 -78
- 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 +2 -3
- 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 +6 -2
- 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 +6 -6
- 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 +110 -78
- 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.d.ts.map +1 -1
- package/lib/controller/ensurePojo.js +2 -3
- package/lib/controller/types.d.ts.map +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.d.ts +1 -0
- package/lib/manager/DevtoolsManager.d.ts.map +1 -1
- package/lib/manager/DevtoolsManager.js +6 -2
- 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.d.ts.map +1 -1
- package/lib/middlewareTypes.js +1 -1
- package/lib/next/index.js +1 -1
- package/lib/state/RIC.d.ts.map +1 -1
- package/lib/state/RIC.js +1 -1
- package/lib/state/reducer/createReducer.js +6 -6
- 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 +215 -96
- 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/controller/createSet.ts +3 -2
- package/src/controller/ensurePojo.ts +6 -7
- package/src/controller/types.ts +2 -4
- package/src/index.ts +2 -1
- package/src/internal.ts +1 -1
- package/src/manager/DevtoolsManager.ts +8 -2
- package/src/manager/__tests__/subscriptionManager.ts +3 -2
- package/src/middlewareTypes.ts +4 -12
- package/src/state/RIC.ts +3 -4
- package/src/state/__tests__/__snapshots__/reducer.ts.snap +4 -4
- package/src/state/__tests__/reducer.ts +32 -34
- package/src/state/reducer/createReducer.ts +3 -3
- package/src/state/reducer/invalidateReducer.ts +4 -4
- package/src/state/reducer/setReducer.ts +10 -9
- 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/manager/DevtoolsManager.d.ts +1 -0
- 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
|
@@ -159,17 +159,15 @@ describe('reducer', () => {
|
|
|
159
159
|
existing: any,
|
|
160
160
|
incoming: any,
|
|
161
161
|
) {
|
|
162
|
-
return
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
incoming,
|
|
167
|
-
)
|
|
168
|
-
? existingMeta
|
|
162
|
+
return (
|
|
163
|
+
this.shouldReorder(existingMeta, incomingMeta, existing, incoming)
|
|
164
|
+
) ?
|
|
165
|
+
existingMeta
|
|
169
166
|
: {
|
|
170
167
|
...incomingMeta,
|
|
171
|
-
expiresAt:
|
|
172
|
-
?
|
|
168
|
+
expiresAt:
|
|
169
|
+
incoming.content ?
|
|
170
|
+
incomingMeta.expiresAt
|
|
173
171
|
: existingMeta.expiresAt,
|
|
174
172
|
};
|
|
175
173
|
}
|
|
@@ -209,7 +207,7 @@ describe('reducer', () => {
|
|
|
209
207
|
});
|
|
210
208
|
});
|
|
211
209
|
|
|
212
|
-
it('mutate should never change
|
|
210
|
+
it('mutate should never change endpoints', () => {
|
|
213
211
|
const id = 20;
|
|
214
212
|
const payload = { id, title: 'hi', content: 'this is the content' };
|
|
215
213
|
const action: SetAction = {
|
|
@@ -226,10 +224,10 @@ describe('reducer', () => {
|
|
|
226
224
|
};
|
|
227
225
|
const iniState = {
|
|
228
226
|
...initialState,
|
|
229
|
-
|
|
227
|
+
endpoints: { abc: '5', [ArticleResource.get.key(payload)]: `${id}` },
|
|
230
228
|
};
|
|
231
229
|
const newState = reducer(iniState, action);
|
|
232
|
-
expect(newState.
|
|
230
|
+
expect(newState.endpoints).toStrictEqual(iniState.endpoints);
|
|
233
231
|
});
|
|
234
232
|
it('purge should delete entities', () => {
|
|
235
233
|
const id = 20;
|
|
@@ -258,10 +256,10 @@ describe('reducer', () => {
|
|
|
258
256
|
},
|
|
259
257
|
'5': undefined,
|
|
260
258
|
},
|
|
261
|
-
|
|
259
|
+
endpoints: { abc: '20' },
|
|
262
260
|
};
|
|
263
261
|
const newState = reducer(iniState, action);
|
|
264
|
-
expect(newState.
|
|
262
|
+
expect(newState.endpoints.abc).toBe(iniState.endpoints.abc);
|
|
265
263
|
const expectedEntities = { ...iniState.entities[Article.key] };
|
|
266
264
|
expectedEntities['20'] = INVALID;
|
|
267
265
|
expect(newState.entities[Article.key]).toEqual(expectedEntities);
|
|
@@ -279,8 +277,8 @@ describe('reducer', () => {
|
|
|
279
277
|
'10': PaginatedArticle.fromJS({ id: 10 }),
|
|
280
278
|
},
|
|
281
279
|
},
|
|
282
|
-
|
|
283
|
-
[PaginatedArticleResource.getList.key({})]: {
|
|
280
|
+
endpoints: {
|
|
281
|
+
[PaginatedArticleResource.getList.key({})]: { endpoints: ['10'] },
|
|
284
282
|
},
|
|
285
283
|
};
|
|
286
284
|
|
|
@@ -303,7 +301,7 @@ describe('reducer', () => {
|
|
|
303
301
|
);
|
|
304
302
|
const newState = reducer(iniState, action);
|
|
305
303
|
expect(
|
|
306
|
-
newState.
|
|
304
|
+
newState.endpoints[PaginatedArticleResource.getList.key({})],
|
|
307
305
|
).toStrictEqual({
|
|
308
306
|
results: ['10', '11', '12'],
|
|
309
307
|
});
|
|
@@ -330,7 +328,7 @@ describe('reducer', () => {
|
|
|
330
328
|
),
|
|
331
329
|
);
|
|
332
330
|
expect(
|
|
333
|
-
newState.
|
|
331
|
+
newState.endpoints[PaginatedArticleResource.getList.key({})],
|
|
334
332
|
).toStrictEqual({
|
|
335
333
|
results: ['11', '12', '10'],
|
|
336
334
|
});
|
|
@@ -344,7 +342,7 @@ describe('reducer', () => {
|
|
|
344
342
|
'10': PaginatedArticle.fromJS({ id: 10 }),
|
|
345
343
|
},
|
|
346
344
|
},
|
|
347
|
-
|
|
345
|
+
endpoints: {
|
|
348
346
|
[PaginatedArticleResource.getList.key({ admin: true })]: {
|
|
349
347
|
results: ['10'],
|
|
350
348
|
},
|
|
@@ -371,7 +369,7 @@ describe('reducer', () => {
|
|
|
371
369
|
),
|
|
372
370
|
);
|
|
373
371
|
expect(
|
|
374
|
-
newState.
|
|
372
|
+
newState.endpoints[
|
|
375
373
|
PaginatedArticleResource.getList.key({ admin: true })
|
|
376
374
|
],
|
|
377
375
|
).toStrictEqual({
|
|
@@ -402,7 +400,7 @@ describe('reducer', () => {
|
|
|
402
400
|
},
|
|
403
401
|
'5': undefined,
|
|
404
402
|
},
|
|
405
|
-
|
|
403
|
+
endpoints: { abc: '20' },
|
|
406
404
|
meta: {
|
|
407
405
|
'20': {
|
|
408
406
|
expiresAt: 500,
|
|
@@ -413,7 +411,7 @@ describe('reducer', () => {
|
|
|
413
411
|
},
|
|
414
412
|
};
|
|
415
413
|
const newState = reducer(iniState, action);
|
|
416
|
-
expect(newState.
|
|
414
|
+
expect(newState.endpoints).toEqual(iniState.endpoints);
|
|
417
415
|
expect(newState.entities).toBe(iniState.entities);
|
|
418
416
|
const expectedMeta = { ...iniState.meta };
|
|
419
417
|
expectedMeta['20'] = { expiresAt: 0, invalidated: true };
|
|
@@ -483,7 +481,7 @@ describe('reducer', () => {
|
|
|
483
481
|
[id]: Article.fromJS({}),
|
|
484
482
|
},
|
|
485
483
|
},
|
|
486
|
-
|
|
484
|
+
endpoints: {
|
|
487
485
|
[ArticleResource.get.url({ id })]: id,
|
|
488
486
|
},
|
|
489
487
|
};
|
|
@@ -511,7 +509,7 @@ describe('reducer', () => {
|
|
|
511
509
|
};
|
|
512
510
|
const iniState = {
|
|
513
511
|
...initialState,
|
|
514
|
-
|
|
512
|
+
endpoints: { abc: '5' },
|
|
515
513
|
};
|
|
516
514
|
const newState = reducer(iniState, action);
|
|
517
515
|
expect(newState).toBe(iniState);
|
|
@@ -526,7 +524,7 @@ describe('reducer', () => {
|
|
|
526
524
|
};
|
|
527
525
|
const iniState = {
|
|
528
526
|
...initialState,
|
|
529
|
-
|
|
527
|
+
endpoints: { abc: '5' },
|
|
530
528
|
};
|
|
531
529
|
const newState = reducer(iniState, action);
|
|
532
530
|
expect(newState).toBe(iniState);
|
|
@@ -558,10 +556,10 @@ describe('reducer', () => {
|
|
|
558
556
|
},
|
|
559
557
|
'5': undefined,
|
|
560
558
|
},
|
|
561
|
-
|
|
559
|
+
endpoints: { abc: '20' },
|
|
562
560
|
};
|
|
563
561
|
const newState = reducer(iniState, action);
|
|
564
|
-
expect(newState.
|
|
562
|
+
expect(newState.endpoints).toEqual({});
|
|
565
563
|
expect(newState.meta).toEqual({});
|
|
566
564
|
expect(newState.entities).toEqual({});
|
|
567
565
|
});
|
|
@@ -593,7 +591,7 @@ describe('reducer', () => {
|
|
|
593
591
|
'250': { date: 0, expiresAt: 10000, fetchedAt: 0 },
|
|
594
592
|
},
|
|
595
593
|
},
|
|
596
|
-
|
|
594
|
+
endpoints: { abc: '20' },
|
|
597
595
|
};
|
|
598
596
|
});
|
|
599
597
|
|
|
@@ -601,13 +599,13 @@ describe('reducer', () => {
|
|
|
601
599
|
const action: GCAction = {
|
|
602
600
|
type: GC_TYPE,
|
|
603
601
|
entities: [],
|
|
604
|
-
|
|
602
|
+
endpoints: [],
|
|
605
603
|
};
|
|
606
604
|
|
|
607
605
|
const newState = reducer(iniState, action);
|
|
608
606
|
expect(newState).toBe(iniState);
|
|
609
607
|
expect(Object.keys(newState.entities[Article.key] ?? {}).length).toBe(4);
|
|
610
|
-
expect(Object.keys(newState.
|
|
608
|
+
expect(Object.keys(newState.endpoints).length).toBe(1);
|
|
611
609
|
});
|
|
612
610
|
|
|
613
611
|
it('empty deleting entities should work', () => {
|
|
@@ -617,7 +615,7 @@ describe('reducer', () => {
|
|
|
617
615
|
[Article.key, '10'],
|
|
618
616
|
[Article.key, '250'],
|
|
619
617
|
],
|
|
620
|
-
|
|
618
|
+
endpoints: ['abc'],
|
|
621
619
|
};
|
|
622
620
|
|
|
623
621
|
const newState = reducer(iniState, action);
|
|
@@ -626,7 +624,7 @@ describe('reducer', () => {
|
|
|
626
624
|
expect(Object.keys(newState.entityMeta[Article.key] ?? {}).length).toBe(
|
|
627
625
|
2,
|
|
628
626
|
);
|
|
629
|
-
expect(Object.keys(newState.
|
|
627
|
+
expect(Object.keys(newState.endpoints).length).toBe(0);
|
|
630
628
|
});
|
|
631
629
|
|
|
632
630
|
it('empty deleting nonexistant things should passthrough', () => {
|
|
@@ -636,13 +634,13 @@ describe('reducer', () => {
|
|
|
636
634
|
[Article.key, '100000000'],
|
|
637
635
|
['sillythings', '10'],
|
|
638
636
|
],
|
|
639
|
-
|
|
637
|
+
endpoints: [],
|
|
640
638
|
};
|
|
641
639
|
|
|
642
640
|
const newState = reducer(iniState, action);
|
|
643
641
|
expect(newState).toBe(iniState);
|
|
644
642
|
expect(Object.keys(newState.entities[Article.key] ?? {}).length).toBe(4);
|
|
645
|
-
expect(Object.keys(newState.
|
|
643
|
+
expect(Object.keys(newState.endpoints).length).toBe(1);
|
|
646
644
|
});
|
|
647
645
|
});
|
|
648
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 ${
|
|
@@ -138,8 +139,8 @@ function filterOptimistic(
|
|
|
138
139
|
return state.optimistic.filter(
|
|
139
140
|
optimisticAction =>
|
|
140
141
|
optimisticAction.meta.key !== resolvingAction.meta.key ||
|
|
141
|
-
(optimisticAction.type === OPTIMISTIC_TYPE
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
(optimisticAction.type === OPTIMISTIC_TYPE ?
|
|
143
|
+
optimisticAction.meta.fetchedAt !== resolvingAction.meta.fetchedAt
|
|
144
|
+
: optimisticAction.meta.date > resolvingAction.meta.date),
|
|
144
145
|
);
|
|
145
146
|
}
|
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
|
|
@@ -18,6 +18,7 @@ export default class DevToolsManager implements Manager {
|
|
|
18
18
|
State<unknown>
|
|
19
19
|
][];
|
|
20
20
|
protected controller: Controller;
|
|
21
|
+
maxBufferLength: number;
|
|
21
22
|
constructor(config?: DevToolsConfig, skipLogging?: (action: ActionTypes) => boolean);
|
|
22
23
|
handleAction(action: any, state: any): void;
|
|
23
24
|
/** Called when initial state is ready */
|
|
@@ -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: {
|