@data-client/core 0.14.13 → 0.14.16

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.
Files changed (64) hide show
  1. package/dist/index.js +62 -40
  2. package/dist/index.umd.min.js +1 -1
  3. package/legacy/actionTypes.js +23 -12
  4. package/legacy/actions.js +1 -1
  5. package/legacy/controller/actions/createExpireAll.js +3 -3
  6. package/legacy/controller/actions/createFetch.js +3 -3
  7. package/legacy/controller/actions/createInvalidate.js +3 -3
  8. package/legacy/controller/actions/createInvalidateAll.js +3 -3
  9. package/legacy/controller/actions/createOptimistic.js +3 -3
  10. package/legacy/controller/actions/createReset.js +3 -3
  11. package/legacy/controller/actions/createSet.js +3 -3
  12. package/legacy/controller/actions/createSetResponse.js +3 -3
  13. package/legacy/controller/actions/createSubscription.js +4 -4
  14. package/legacy/manager/LogoutManager.js +3 -3
  15. package/legacy/manager/NetworkManager.js +6 -6
  16. package/legacy/manager/SubscriptionManager.js +4 -4
  17. package/legacy/state/reducer/createReducer.js +11 -11
  18. package/legacy/state/reducer/invalidateReducer.js +3 -3
  19. package/legacy/state/reducer/setResponseReducer.js +4 -4
  20. package/lib/actionTypes.d.ts +11 -0
  21. package/lib/actionTypes.d.ts.map +1 -1
  22. package/lib/actionTypes.js +23 -12
  23. package/lib/actions.d.ts +12 -12
  24. package/lib/actions.d.ts.map +1 -1
  25. package/lib/actions.js +1 -1
  26. package/lib/controller/actions/createExpireAll.js +3 -3
  27. package/lib/controller/actions/createFetch.js +3 -3
  28. package/lib/controller/actions/createInvalidate.js +3 -3
  29. package/lib/controller/actions/createInvalidateAll.js +3 -3
  30. package/lib/controller/actions/createOptimistic.js +3 -3
  31. package/lib/controller/actions/createReset.js +3 -3
  32. package/lib/controller/actions/createSet.js +3 -3
  33. package/lib/controller/actions/createSetResponse.js +3 -3
  34. package/lib/controller/actions/createSubscription.js +4 -4
  35. package/lib/manager/LogoutManager.js +3 -3
  36. package/lib/manager/NetworkManager.js +6 -6
  37. package/lib/manager/SubscriptionManager.js +4 -4
  38. package/lib/state/reducer/createReducer.js +11 -11
  39. package/lib/state/reducer/invalidateReducer.js +3 -3
  40. package/lib/state/reducer/setResponseReducer.js +4 -4
  41. package/package.json +2 -2
  42. package/src/actionTypes.ts +23 -11
  43. package/src/actions.ts +22 -22
  44. package/src/controller/actions/createExpireAll.ts +2 -2
  45. package/src/controller/actions/createFetch.ts +2 -2
  46. package/src/controller/actions/createInvalidate.ts +2 -2
  47. package/src/controller/actions/createInvalidateAll.ts +2 -2
  48. package/src/controller/actions/createOptimistic.ts +2 -2
  49. package/src/controller/actions/createReset.ts +2 -2
  50. package/src/controller/actions/createSet.ts +2 -2
  51. package/src/controller/actions/createSetResponse.ts +2 -2
  52. package/src/controller/actions/createSubscription.ts +3 -3
  53. package/src/manager/LogoutManager.ts +2 -2
  54. package/src/manager/NetworkManager.ts +5 -5
  55. package/src/manager/SubscriptionManager.ts +3 -3
  56. package/src/manager/__tests__/logoutManager.ts +3 -3
  57. package/src/manager/__tests__/networkManager.ts +6 -6
  58. package/src/manager/__tests__/subscriptionManager.ts +4 -4
  59. package/src/state/__tests__/reducer.ts +22 -22
  60. package/src/state/reducer/createReducer.ts +18 -18
  61. package/src/state/reducer/invalidateReducer.ts +2 -2
  62. package/src/state/reducer/setResponseReducer.ts +3 -3
  63. package/ts3.4/actionTypes.d.ts +11 -0
  64. package/ts3.4/actions.d.ts +12 -12
@@ -3,12 +3,12 @@ import { ArticleResource, Article, PaginatedArticle } from '__tests__/new';
3
3
 
4
4
  import { Controller } from '../..';
5
5
  import {
6
- INVALIDATE_TYPE,
7
- FETCH_TYPE,
8
- RESET_TYPE,
9
- GC_TYPE,
10
- SET_RESPONSE_TYPE,
11
- SET_TYPE,
6
+ INVALIDATE,
7
+ FETCH,
8
+ RESET,
9
+ GC,
10
+ SET_RESPONSE,
11
+ SET,
12
12
  } from '../../actionTypes';
13
13
  import {
14
14
  State,
@@ -36,7 +36,7 @@ describe('reducer', () => {
36
36
  const id = 20;
37
37
  const response = { id, title: 'hi', content: 'this is the content' };
38
38
  const action: SetResponseAction = {
39
- type: SET_RESPONSE_TYPE,
39
+ type: SET_RESPONSE,
40
40
  response,
41
41
  endpoint: ArticleResource.get,
42
42
  args: [{ id }],
@@ -215,7 +215,7 @@ describe('reducer', () => {
215
215
  static key = 'Counter';
216
216
  }
217
217
  const action: SetAction = {
218
- type: SET_TYPE,
218
+ type: SET,
219
219
  value,
220
220
  schema: Counter,
221
221
  args: [{ id }],
@@ -242,7 +242,7 @@ describe('reducer', () => {
242
242
  static key = 'Counter';
243
243
  }
244
244
  const action: SetAction = {
245
- type: SET_TYPE,
245
+ type: SET,
246
246
  value,
247
247
  schema: Counter,
248
248
  args: [{ id }],
@@ -270,7 +270,7 @@ describe('reducer', () => {
270
270
  const id = 20;
271
271
  const value = { id, title: 'hi', content: 'this is the content' };
272
272
  const action: SetAction = {
273
- type: SET_TYPE,
273
+ type: SET,
274
274
  value,
275
275
  schema: Article,
276
276
  args: [{ id }],
@@ -292,7 +292,7 @@ describe('reducer', () => {
292
292
  const id = 20;
293
293
  const value = { id, title: 'hi', content: 'this is the content' };
294
294
  const action: SetAction = {
295
- type: SET_TYPE,
295
+ type: SET,
296
296
  value,
297
297
  schema: Article,
298
298
  args: [{ id }],
@@ -314,7 +314,7 @@ describe('reducer', () => {
314
314
  const id = 20;
315
315
  const response = { id, title: 'hi', content: 'this is the content' };
316
316
  const action: SetResponseAction = {
317
- type: SET_RESPONSE_TYPE,
317
+ type: SET_RESPONSE,
318
318
  response,
319
319
  endpoint: ArticleResource.get,
320
320
  args: [{ id }],
@@ -335,7 +335,7 @@ describe('reducer', () => {
335
335
  it('purge should delete entities', () => {
336
336
  const id = 20;
337
337
  const action: SetResponseAction = {
338
- type: SET_RESPONSE_TYPE,
338
+ type: SET_RESPONSE,
339
339
  response: { id },
340
340
  endpoint: ArticleResource.delete,
341
341
  args: [{ id }],
@@ -485,7 +485,7 @@ describe('reducer', () => {
485
485
  it('invalidates resources correctly', () => {
486
486
  const id = 20;
487
487
  const action: InvalidateAction = {
488
- type: INVALIDATE_TYPE,
488
+ type: INVALIDATE,
489
489
  key: id.toString(),
490
490
  };
491
491
  const iniState: any = {
@@ -522,7 +522,7 @@ describe('reducer', () => {
522
522
  const id = 20;
523
523
  const error = new Error('hi');
524
524
  const action: SetResponseAction = {
525
- type: SET_RESPONSE_TYPE,
525
+ type: SET_RESPONSE,
526
526
  response: error,
527
527
  endpoint: ArticleResource.get,
528
528
  args: [{ id }],
@@ -542,7 +542,7 @@ describe('reducer', () => {
542
542
  const id = 20;
543
543
  const error = new Error('hi');
544
544
  const action: SetResponseAction = {
545
- type: SET_RESPONSE_TYPE,
545
+ type: SET_RESPONSE,
546
546
  response: error,
547
547
  endpoint: ArticleResource.get,
548
548
  args: [{ id }],
@@ -563,7 +563,7 @@ describe('reducer', () => {
563
563
  const id = 20;
564
564
  const error = new Error('hi');
565
565
  const action: SetResponseAction = {
566
- type: SET_RESPONSE_TYPE,
566
+ type: SET_RESPONSE,
567
567
  response: error,
568
568
  endpoint: ArticleResource.delete,
569
569
  args: [{ id }],
@@ -595,7 +595,7 @@ describe('reducer', () => {
595
595
  .mockImplementation(() => {});
596
596
  try {
597
597
  const action: FetchAction = {
598
- type: FETCH_TYPE,
598
+ type: FETCH,
599
599
  endpoint: ArticleResource.get,
600
600
  args: [{ id: 5 }],
601
601
  key: ArticleResource.get.url({ id: 5 }),
@@ -640,7 +640,7 @@ describe('reducer', () => {
640
640
 
641
641
  it('reset should delete all entries', () => {
642
642
  const action: ResetAction = {
643
- type: RESET_TYPE,
643
+ type: RESET,
644
644
  date: Date.now(),
645
645
  };
646
646
  const iniState: any = {
@@ -697,7 +697,7 @@ describe('reducer', () => {
697
697
 
698
698
  it('empty targets should do nothing', () => {
699
699
  const action: GCAction = {
700
- type: GC_TYPE,
700
+ type: GC,
701
701
  entities: [],
702
702
  endpoints: [],
703
703
  };
@@ -710,7 +710,7 @@ describe('reducer', () => {
710
710
 
711
711
  it('empty deleting entities should work', () => {
712
712
  const action: GCAction = {
713
- type: GC_TYPE,
713
+ type: GC,
714
714
  entities: [
715
715
  [Article.key, '10'],
716
716
  [Article.key, '250'],
@@ -729,7 +729,7 @@ describe('reducer', () => {
729
729
 
730
730
  it('empty deleting nonexistant things should passthrough', () => {
731
731
  const action: GCAction = {
732
- type: GC_TYPE,
732
+ type: GC,
733
733
  entities: [
734
734
  [Article.key, '100000000'],
735
735
  ['sillythings', '10'],
@@ -4,15 +4,15 @@ import { invalidateReducer } from './invalidateReducer.js';
4
4
  import { setReducer } from './setReducer.js';
5
5
  import { setResponseReducer } from './setResponseReducer.js';
6
6
  import {
7
- SET_TYPE,
8
- INVALIDATE_TYPE,
9
- RESET_TYPE,
10
- FETCH_TYPE,
11
- GC_TYPE,
12
- OPTIMISTIC_TYPE,
13
- INVALIDATEALL_TYPE,
14
- EXPIREALL_TYPE,
15
- SET_RESPONSE_TYPE,
7
+ SET,
8
+ INVALIDATE,
9
+ RESET,
10
+ FETCH,
11
+ GC,
12
+ OPTIMISTIC,
13
+ INVALIDATEALL,
14
+ EXPIREALL,
15
+ SET_RESPONSE,
16
16
  } from '../../actionTypes.js';
17
17
  import type Controller from '../../controller/Controller.js';
18
18
  import type { ActionTypes, State } from '../../types.js';
@@ -24,7 +24,7 @@ export default function createReducer(controller: Controller): ReducerType {
24
24
  ): State<unknown> {
25
25
  if (!state) state = initialState;
26
26
  switch (action.type) {
27
- case GC_TYPE:
27
+ case GC:
28
28
  // inline deletes are fine as these should have 0 refcounts
29
29
  action.entities.forEach(([key, pk]) => {
30
30
  delete (state as any).entities[key]?.[pk];
@@ -35,25 +35,25 @@ export default function createReducer(controller: Controller): ReducerType {
35
35
  delete (state as any).meta[fetchKey];
36
36
  });
37
37
  return state;
38
- case FETCH_TYPE:
38
+ case FETCH:
39
39
  return fetchReducer(state, action);
40
40
 
41
- case OPTIMISTIC_TYPE:
41
+ case OPTIMISTIC:
42
42
  // eslint-disable-next-line no-fallthrough
43
- case SET_RESPONSE_TYPE:
43
+ case SET_RESPONSE:
44
44
  return setResponseReducer(state, action, controller);
45
45
 
46
- case SET_TYPE:
46
+ case SET:
47
47
  return setReducer(state, action, controller);
48
48
 
49
- case INVALIDATEALL_TYPE:
50
- case INVALIDATE_TYPE:
49
+ case INVALIDATEALL:
50
+ case INVALIDATE:
51
51
  return invalidateReducer(state, action);
52
52
 
53
- case EXPIREALL_TYPE:
53
+ case EXPIREALL:
54
54
  return expireReducer(state, action);
55
55
 
56
- case RESET_TYPE:
56
+ case RESET:
57
57
  return { ...initialState, lastReset: action.date };
58
58
 
59
59
  default:
@@ -1,4 +1,4 @@
1
- import { INVALIDATE_TYPE } from '../../actionTypes.js';
1
+ import { INVALIDATE } from '../../actionTypes.js';
2
2
  import type {
3
3
  State,
4
4
  InvalidateAllAction,
@@ -21,7 +21,7 @@ export function invalidateReducer(
21
21
  delete itemMeta.error;
22
22
  meta[key] = itemMeta;
23
23
  };
24
- if (action.type === INVALIDATE_TYPE) {
24
+ if (action.type === INVALIDATE) {
25
25
  invalidateKey(action.key);
26
26
  } else {
27
27
  Object.keys(endpoints).forEach(key => {
@@ -1,6 +1,6 @@
1
1
  import { normalize } from '@data-client/normalizr';
2
2
 
3
- import { OPTIMISTIC_TYPE } from '../../actionTypes.js';
3
+ import { OPTIMISTIC } from '../../actionTypes.js';
4
4
  import AbortOptimistic from '../../controller/AbortOptimistic.js';
5
5
  import type Controller from '../../controller/Controller.js';
6
6
  import type {
@@ -20,7 +20,7 @@ export function setResponseReducer(
20
20
  try {
21
21
  let response: any;
22
22
  // for true set's response is contained in action
23
- if (action.type === OPTIMISTIC_TYPE) {
23
+ if (action.type === OPTIMISTIC) {
24
24
  // this should never happen
25
25
  /* istanbul ignore if */
26
26
  if (!action.endpoint.getOptimisticResponse) return state;
@@ -142,7 +142,7 @@ function filterOptimistic(
142
142
  return state.optimistic.filter(
143
143
  optimisticAction =>
144
144
  optimisticAction.key !== resolvingAction.key ||
145
- (optimisticAction.type === OPTIMISTIC_TYPE ?
145
+ (optimisticAction.type === OPTIMISTIC ?
146
146
  optimisticAction.meta.fetchedAt !== resolvingAction.meta.fetchedAt
147
147
  : optimisticAction.meta.date > resolvingAction.meta.date),
148
148
  );
@@ -1,3 +1,14 @@
1
+ export declare const FETCH: "rdc/fetch";
2
+ export declare const SET: "rdc/set";
3
+ export declare const SET_RESPONSE: "rdc/setresponse";
4
+ export declare const OPTIMISTIC: "rdc/optimistic";
5
+ export declare const RESET: "rdc/reset";
6
+ export declare const SUBSCRIBE: "rdc/subscribe";
7
+ export declare const UNSUBSCRIBE: "rdc/unsubscribe";
8
+ export declare const INVALIDATE: "rdc/invalidate";
9
+ export declare const INVALIDATEALL: "rdc/invalidateall";
10
+ export declare const EXPIREALL: "rdc/expireall";
11
+ export declare const GC: "rdc/gc";
1
12
  export declare const FETCH_TYPE: "rdc/fetch";
2
13
  export declare const SET_TYPE: "rdc/set";
3
14
  export declare const SET_RESPONSE_TYPE: "rdc/setresponse";
@@ -1,5 +1,5 @@
1
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';
2
+ import { SET, RESET, FETCH, SUBSCRIBE, UNSUBSCRIBE, INVALIDATE, GC, OPTIMISTIC, INVALIDATEALL, EXPIREALL, SET_RESPONSE } from './actionTypes.js';
3
3
  import { EndpointUpdateFunction } from './controller/types.js';
4
4
  type EndpointAndUpdate<E extends EndpointInterface> = EndpointInterface & {
5
5
  update?: EndpointUpdateFunction<E>;
@@ -15,14 +15,14 @@ export interface ActionMeta {
15
15
  }
16
16
  /** Action for Controller.set() */
17
17
  export interface SetAction<S extends Queryable = any> {
18
- type: typeof SET_TYPE;
18
+ type: typeof SET;
19
19
  schema: S;
20
20
  args: readonly any[];
21
21
  meta: ActionMeta;
22
22
  value: {} | ((previousValue: Denormalize<S>) => {});
23
23
  }
24
24
  export interface SetResponseActionBase<E extends EndpointAndUpdate<E> = EndpointDefault> {
25
- type: typeof SET_RESPONSE_TYPE;
25
+ type: typeof SET_RESPONSE;
26
26
  endpoint: E;
27
27
  args: readonly any[];
28
28
  key: string;
@@ -46,7 +46,7 @@ export interface FetchMeta {
46
46
  }
47
47
  /** Action for Controller.fetch() */
48
48
  export interface FetchAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
49
- type: typeof FETCH_TYPE;
49
+ type: typeof FETCH;
50
50
  endpoint: E;
51
51
  args: readonly [
52
52
  ...Parameters<E>
@@ -56,7 +56,7 @@ export interface FetchAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
56
56
  }
57
57
  /** Action for Endpoint.getOptimisticResponse() */
58
58
  export interface OptimisticAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
59
- type: typeof OPTIMISTIC_TYPE;
59
+ type: typeof OPTIMISTIC;
60
60
  endpoint: E;
61
61
  args: readonly any[];
62
62
  key: string;
@@ -65,36 +65,36 @@ export interface OptimisticAction<E extends EndpointAndUpdate<E> = EndpointDefau
65
65
  }
66
66
  /** Action for Controller.subscribe() */
67
67
  export interface SubscribeAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
68
- type: typeof SUBSCRIBE_TYPE;
68
+ type: typeof SUBSCRIBE;
69
69
  endpoint: E;
70
70
  args: readonly any[];
71
71
  key: string;
72
72
  }
73
73
  /** Action for Controller.unsubscribe() */
74
74
  export interface UnsubscribeAction<E extends EndpointAndUpdate<E> = EndpointDefault> {
75
- type: typeof UNSUBSCRIBE_TYPE;
75
+ type: typeof UNSUBSCRIBE;
76
76
  endpoint: E;
77
77
  args: readonly any[];
78
78
  key: string;
79
79
  }
80
80
  export interface ExpireAllAction {
81
- type: typeof EXPIREALL_TYPE;
81
+ type: typeof EXPIREALL;
82
82
  testKey: (key: string) => boolean;
83
83
  }
84
84
  export interface InvalidateAllAction {
85
- type: typeof INVALIDATEALL_TYPE;
85
+ type: typeof INVALIDATEALL;
86
86
  testKey: (key: string) => boolean;
87
87
  }
88
88
  export interface InvalidateAction {
89
- type: typeof INVALIDATE_TYPE;
89
+ type: typeof INVALIDATE;
90
90
  key: string;
91
91
  }
92
92
  export interface ResetAction {
93
- type: typeof RESET_TYPE;
93
+ type: typeof RESET;
94
94
  date: number;
95
95
  }
96
96
  export interface GCAction {
97
- type: typeof GC_TYPE;
97
+ type: typeof GC;
98
98
  entities: [
99
99
  string,
100
100
  string