react-redux-cache 0.19.5 → 0.20.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.
@@ -1,28 +1,38 @@
1
1
  import type {
2
2
  Cache,
3
3
  CacheOptions,
4
+ CacheState,
5
+ Dict,
6
+ EntitiesMap,
7
+ EntityChanges,
4
8
  Globals,
5
9
  Key,
6
10
  MutateOptions,
11
+ MutationInfo,
7
12
  MutationResult,
13
+ MutationState,
14
+ NormalizedQueryResponse,
8
15
  OptionalPartial,
16
+ QueryInfo,
9
17
  QueryOptions,
10
18
  QueryResult,
19
+ QueryState,
11
20
  Store,
12
21
  Typenames,
22
+ UseQueryOptions,
13
23
  } from './types'
14
24
  import {useMutation} from './useMutation'
15
25
  import {useQuery} from './useQuery'
16
26
  import {applyEntityChanges} from './utilsAndConstants'
27
+
17
28
  /**
18
29
  * Function to provide generic Typenames if normalization is needed - this is a Typescript limitation.
19
30
  * Returns object with createCache function with provided typenames.
20
31
  * @example
21
- * const cache = withTypenames<MyTypenames>().createCache({
22
- * ...
23
- * })
32
+ * `const cache = withTypenames<MyTypenames>().createCache({...})`
24
33
  */
25
34
  export declare const withTypenames: <T extends Typenames = Typenames>() => {
35
+ /** Creates reducer, actions and hooks for managing queries and mutations through redux cache. */
26
36
  createCache: <N extends string, QP, QR, MP, MR>(
27
37
  partialCache: OptionalPartial<
28
38
  Omit<Cache<N, T, QP, QR, MP, MR>, 'globals'>,
@@ -35,28 +45,24 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
35
45
  cache: Cache<N, T, QP, QR, MP, MR>
36
46
  /** Reducer of the cache, should be added to redux store. */
37
47
  reducer: (
38
- state: import('./types').CacheState<T, QP, QR, MP, MR> | undefined,
48
+ state: CacheState<T, QP, QR, MP, MR> | undefined,
39
49
  action:
40
50
  | {
41
51
  type: `@rrc/${N}/updateQueryStateAndEntities`
42
52
  queryKey: keyof QP & keyof QR
43
53
  queryCacheKey: Key
44
- state:
45
- | Partial<import('./types').QueryState<T, QP[keyof QP & keyof QR], QR[keyof QP & keyof QR]>>
46
- | undefined
47
- entityChanges: import('./types').EntityChanges<T> | undefined
54
+ state: Partial<QueryState<T, QP[keyof QP & keyof QR], QR[keyof QP & keyof QR]>> | undefined
55
+ entityChanges: EntityChanges<T> | undefined
48
56
  }
49
57
  | {
50
58
  type: `@rrc/${N}/updateMutationStateAndEntities`
51
59
  mutationKey: keyof MP & keyof MR
52
- state:
53
- | Partial<import('./types').MutationState<T, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>>
54
- | undefined
55
- entityChanges: import('./types').EntityChanges<T> | undefined
60
+ state: Partial<MutationState<T, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>> | undefined
61
+ entityChanges: EntityChanges<T> | undefined
56
62
  }
57
63
  | {
58
64
  type: `@rrc/${N}/mergeEntityChanges`
59
- changes: import('./types').EntityChanges<T>
65
+ changes: EntityChanges<T>
60
66
  }
61
67
  | {
62
68
  type: `@rrc/${N}/invalidateQuery`
@@ -79,23 +85,23 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
79
85
  }
80
86
  | {
81
87
  type: `@rrc/${N}/clearCache`
82
- stateToKeep: Partial<import('./types').CacheState<T, QP, QR, MP, MR>> | undefined
88
+ stateToKeep: Partial<CacheState<T, QP, QR, MP, MR>> | undefined
83
89
  }
84
- ) => import('./types').CacheState<T, QP, QR, MP, MR>
90
+ ) => CacheState<T, QP, QR, MP, MR>
85
91
  actions: {
86
92
  /** Updates query state, and optionally merges entity changes in a single action. */
87
93
  updateQueryStateAndEntities: {
88
94
  <K extends keyof QP & keyof QR>(
89
95
  queryKey: K,
90
96
  queryCacheKey: Key,
91
- state?: Partial<import('./types').QueryState<T, QP[K], QR[K]>> | undefined,
92
- entityChanges?: import('./types').EntityChanges<T> | undefined
97
+ state?: Partial<QueryState<T, QP[K], QR[K]>> | undefined,
98
+ entityChanges?: EntityChanges<T> | undefined
93
99
  ): {
94
100
  type: `@rrc/${N}/updateQueryStateAndEntities`
95
101
  queryKey: K
96
102
  queryCacheKey: Key
97
- state: Partial<import('./types').QueryState<T, QP[K], QR[K]>> | undefined
98
- entityChanges: import('./types').EntityChanges<T> | undefined
103
+ state: Partial<QueryState<T, QP[K], QR[K]>> | undefined
104
+ entityChanges: EntityChanges<T> | undefined
99
105
  }
100
106
  type: `@rrc/${N}/updateQueryStateAndEntities`
101
107
  }
@@ -103,21 +109,21 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
103
109
  updateMutationStateAndEntities: {
104
110
  <K extends keyof MP & keyof MR>(
105
111
  mutationKey: K,
106
- state?: Partial<import('./types').MutationState<T, MP[K], MR[K]>> | undefined,
107
- entityChanges?: import('./types').EntityChanges<T> | undefined
112
+ state?: Partial<MutationState<T, MP[K], MR[K]>> | undefined,
113
+ entityChanges?: EntityChanges<T> | undefined
108
114
  ): {
109
115
  type: `@rrc/${N}/updateMutationStateAndEntities`
110
116
  mutationKey: K
111
- state: Partial<import('./types').MutationState<T, MP[K], MR[K]>> | undefined
112
- entityChanges: import('./types').EntityChanges<T> | undefined
117
+ state: Partial<MutationState<T, MP[K], MR[K]>> | undefined
118
+ entityChanges: EntityChanges<T> | undefined
113
119
  }
114
120
  type: `@rrc/${N}/updateMutationStateAndEntities`
115
121
  }
116
122
  /** Merges EntityChanges to the state. */
117
123
  mergeEntityChanges: {
118
- (changes: import('./types').EntityChanges<T>): {
124
+ (changes: EntityChanges<T>): {
119
125
  type: `@rrc/${N}/mergeEntityChanges`
120
- changes: import('./types').EntityChanges<T>
126
+ changes: EntityChanges<T>
121
127
  }
122
128
  type: `@rrc/${N}/mergeEntityChanges`
123
129
  }
@@ -166,22 +172,22 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
166
172
  }
167
173
  /** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
168
174
  clearCache: {
169
- (stateToKeep?: Partial<import('./types').CacheState<T, QP, QR, MP, MR>> | undefined): {
175
+ (stateToKeep?: Partial<CacheState<T, QP, QR, MP, MR>> | undefined): {
170
176
  type: `@rrc/${N}/clearCache`
171
- stateToKeep: Partial<import('./types').CacheState<T, QP, QR, MP, MR>> | undefined
177
+ stateToKeep: Partial<CacheState<T, QP, QR, MP, MR>> | undefined
172
178
  }
173
179
  type: `@rrc/${N}/clearCache`
174
180
  }
175
181
  }
176
182
  selectors: {
177
183
  /** This is a cacheStateSelector from createCache options, or default one if was not provided. */
178
- selectCacheState: (state: any) => import('./types').CacheState<T, QP, QR, MP, MR>
184
+ selectCacheState: (state: any) => CacheState<T, QP, QR, MP, MR>
179
185
  /** Selects query state. */
180
186
  selectQueryState: <QK extends keyof QP | keyof QR>(
181
187
  state: unknown,
182
188
  query: QK,
183
189
  cacheKey: Key
184
- ) => import('./types').QueryState<
190
+ ) => QueryState<
185
191
  T,
186
192
  QK extends keyof QP & keyof QR ? QP[QK] : never,
187
193
  QK extends keyof QP & keyof QR ? QR[QK] : never
@@ -197,11 +203,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
197
203
  state: unknown,
198
204
  query: QK,
199
205
  cacheKey: Key
200
- ) =>
201
- | false
202
- | Promise<
203
- import('./types').NormalizedQueryResponse<T, QK extends keyof QP & keyof QR ? QR[QK] : never>
204
- >
206
+ ) => false | Promise<NormalizedQueryResponse<T, QK extends keyof QP & keyof QR ? QR[QK] : never>>
205
207
  /** Selects query latest error. */
206
208
  selectQueryError: <QK extends keyof QP | keyof QR>(
207
209
  state: unknown,
@@ -224,7 +226,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
224
226
  selectMutationState: <MK extends keyof MP | keyof MR>(
225
227
  state: unknown,
226
228
  mutation: MK
227
- ) => import('./types').MutationState<
229
+ ) => MutationState<
228
230
  T,
229
231
  MK extends keyof MP & keyof MR ? MP[MK] : never,
230
232
  MK extends keyof MP & keyof MR ? MR[MK] : never
@@ -238,11 +240,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
238
240
  selectMutationLoading: <MK extends keyof MP | keyof MR>(
239
241
  state: unknown,
240
242
  mutation: MK
241
- ) =>
242
- | false
243
- | Promise<
244
- import('./types').NormalizedQueryResponse<T, MK extends keyof MP & keyof MR ? MR[MK] : never>
245
- >
243
+ ) => false | Promise<NormalizedQueryResponse<T, MK extends keyof MP & keyof MR ? MR[MK] : never>>
246
244
  /** Selects mutation latest error. */
247
245
  selectMutationError: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => Error | undefined
248
246
  /** Selects mutation latest params. */
@@ -257,29 +255,34 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
257
255
  typename: TN
258
256
  ) => T[TN] | undefined
259
257
  /** Selects all entities. */
260
- selectEntities: (state: unknown) => import('./types').EntitiesMap<T>
258
+ selectEntities: (state: unknown) => EntitiesMap<T>
261
259
  /** Selects all entities of provided typename. */
262
- selectEntitiesByTypename: <TN extends keyof T>(
263
- state: unknown,
264
- typename: TN
265
- ) => import('./types').EntitiesMap<T>[TN]
260
+ selectEntitiesByTypename: <TN extends keyof T>(state: unknown, typename: TN) => EntitiesMap<T>[TN]
266
261
  }
267
262
  hooks: {
268
- /** Returns client object with query and mutate functions. */
263
+ /** Returns memoized object with query and mutate functions. Memoization dependency is the store. */
269
264
  useClient: () => {
265
+ /**
266
+ * Performs a query using provided options. Deduplicates calls with the same cache key. Always returns current cached result, even when query is cancelled or finished with error.
267
+ * @param onlyIfExpired When true, cancels fetch if result is not yet expired.
268
+ * @param skipFetch Fetch is cancelled and current cached result is returned.
269
+ */
270
270
  query: <QK extends keyof (QP & QR)>(
271
271
  options: QueryOptions<N, T, QP, QR, QK, MP, MR>
272
272
  ) => Promise<QueryResult<QK extends keyof QP & keyof QR ? QR[QK] : never>>
273
+ /**
274
+ * Performs a mutation, aborting previous one with the same mutation key. Returns result only if finished succesfully.
275
+ */
273
276
  mutate: <MK extends keyof (MP & MR)>(
274
277
  options: MutateOptions<N, T, QP, QR, MP, MR, MK>
275
278
  ) => Promise<MutationResult<MK extends keyof MP & keyof MR ? MR[MK] : never>>
276
279
  }
277
- /** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
280
+ /** Fetches query when params change and subscribes to query state changes (subscription depends on `selectorComparer`). */
278
281
  useQuery: <QK extends keyof (QP & QR)>(
279
282
  options: Parameters<typeof useQuery<N, T, QP, QR, MP, MR, QK>>[3]
280
283
  ) => readonly [
281
284
  Omit<
282
- import('./types').QueryState<
285
+ QueryState<
283
286
  T,
284
287
  QK extends keyof QP & keyof QR ? QP[QK] : never,
285
288
  QK extends keyof QP & keyof QR ? QR[QK] : never
@@ -319,7 +322,7 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
319
322
  : never
320
323
  >
321
324
  >,
322
- import('./types').MutationState<
325
+ MutationState<
323
326
  T,
324
327
  MK extends keyof MP & keyof MR ? MP[MK] : never,
325
328
  MK extends keyof MP & keyof MR ? MP[MK] : never
@@ -330,26 +333,35 @@ export declare const withTypenames: <T extends Typenames = Typenames>() => {
330
333
  useSelectEntityById: <TN extends keyof T>(id: Key | null | undefined, typename: TN) => T[TN] | undefined
331
334
  }
332
335
  utils: {
333
- /** Creates client by providing the store. Can be used when the store is a singleton - to not use a hook for getting the client, but import it directly. */
336
+ /** Creates client by providing the store. Can be used when the store is a singleton - to not use a useClient hook for getting the client, but import it directly. */
334
337
  createClient: (store: Store) => {
338
+ /**
339
+ * Performs a query using provided options. Deduplicates calls with the same cache key. Always returns current cached result, even when query is cancelled or finished with error.
340
+ * @param onlyIfExpired When true, cancels fetch if result is not yet expired.
341
+ * @param skipFetch Fetch is cancelled and current cached result is returned.
342
+ */
335
343
  query: <QK extends keyof (QP & QR)>(
336
344
  options: QueryOptions<N, T, QP, QR, QK, MP, MR>
337
345
  ) => Promise<QueryResult<QK extends keyof QP & keyof QR ? QR[QK] : never>>
346
+ /**
347
+ * Performs a mutation, aborting previous one with the same mutation key. Returns result only if finished succesfully.
348
+ */
338
349
  mutate: <MK extends keyof (MP & MR)>(
339
350
  options: MutateOptions<N, T, QP, QR, MP, MR, MK>
340
351
  ) => Promise<MutationResult<MK extends keyof MP & keyof MR ? MR[MK] : never>>
341
352
  }
342
353
  /** Generates the initial state by calling a reducer. Not needed for redux — it already generates it the same way when creating the store. */
343
- getInitialState: () => import('./types').CacheState<T, QP, QR, MP, MR>
354
+ getInitialState: () => CacheState<T, QP, QR, MP, MR>
344
355
  /** Apply changes to the entities map.
345
356
  * @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
346
357
  applyEntityChanges: (
347
358
  entities: Parameters<typeof applyEntityChanges<T>>[0],
348
359
  changes: Parameters<typeof applyEntityChanges<T>>[1]
349
- ) => import('./types').EntitiesMap<T> | undefined
360
+ ) => EntitiesMap<T> | undefined
350
361
  }
351
362
  }
352
363
  }
364
+
353
365
  /**
354
366
  * Creates reducer, actions and hooks for managing queries and mutations through redux cache.
355
367
  */
@@ -357,12 +369,12 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
357
369
  partialCache: Partial<{
358
370
  queries: Partial<{
359
371
  [QK in keyof (QP & QR)]: QK extends keyof QP & keyof QR
360
- ? import('./types').QueryInfo<N, Typenames, QP[QK], QR[QK], QP, QR, MP, MR>
372
+ ? QueryInfo<N, Typenames, QP[QK], QR[QK], QP, QR, MP, MR>
361
373
  : never
362
374
  }>
363
375
  mutations: Partial<{
364
376
  [MK in keyof (MP & MR)]: MK extends keyof MP & keyof MR
365
- ? import('./types').MutationInfo<N, Typenames, MP[MK], MR[MK], QP, QR, MP, MR>
377
+ ? MutationInfo<N, Typenames, MP[MK], MR[MK], QP, QR, MP, MR>
366
378
  : never
367
379
  }>
368
380
  options: Partial<CacheOptions>
@@ -370,7 +382,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
370
382
  useStore: () => Store
371
383
  useSelector: <R>(selector: (state: unknown) => R, comparer?: (x: R, y: R) => boolean) => R
372
384
  }>
373
- cacheStateSelector: Partial<(state: any) => import('./types').CacheState<Typenames, QP, QR, MP, MR>>
385
+ cacheStateSelector: Partial<(state: any) => CacheState<Typenames, QP, QR, MP, MR>>
374
386
  }> &
375
387
  Omit<
376
388
  Omit<Cache<N, Typenames, QP, QR, MP, MR>, 'globals'>,
@@ -383,32 +395,26 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
383
395
  cache: Cache<N, Typenames, QP, QR, MP, MR>
384
396
  /** Reducer of the cache, should be added to redux store. */
385
397
  reducer: (
386
- state: import('./types').CacheState<Typenames, QP, QR, MP, MR> | undefined,
398
+ state: CacheState<Typenames, QP, QR, MP, MR> | undefined,
387
399
  action:
388
400
  | {
389
401
  type: `@rrc/${N}/updateQueryStateAndEntities`
390
402
  queryKey: keyof QP & keyof QR
391
403
  queryCacheKey: Key
392
- state:
393
- | Partial<
394
- import('./types').QueryState<Typenames, QP[keyof QP & keyof QR], QR[keyof QP & keyof QR]>
395
- >
396
- | undefined
397
- entityChanges: import('./types').EntityChanges<Typenames> | undefined
404
+ state: Partial<QueryState<Typenames, QP[keyof QP & keyof QR], QR[keyof QP & keyof QR]>> | undefined
405
+ entityChanges: EntityChanges<Typenames> | undefined
398
406
  }
399
407
  | {
400
408
  type: `@rrc/${N}/updateMutationStateAndEntities`
401
409
  mutationKey: keyof MP & keyof MR
402
410
  state:
403
- | Partial<
404
- import('./types').MutationState<Typenames, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>
405
- >
411
+ | Partial<MutationState<Typenames, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>>
406
412
  | undefined
407
- entityChanges: import('./types').EntityChanges<Typenames> | undefined
413
+ entityChanges: EntityChanges<Typenames> | undefined
408
414
  }
409
415
  | {
410
416
  type: `@rrc/${N}/mergeEntityChanges`
411
- changes: import('./types').EntityChanges<Typenames>
417
+ changes: EntityChanges<Typenames>
412
418
  }
413
419
  | {
414
420
  type: `@rrc/${N}/invalidateQuery`
@@ -431,23 +437,23 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
431
437
  }
432
438
  | {
433
439
  type: `@rrc/${N}/clearCache`
434
- stateToKeep: Partial<import('./types').CacheState<Typenames, QP, QR, MP, MR>> | undefined
440
+ stateToKeep: Partial<CacheState<Typenames, QP, QR, MP, MR>> | undefined
435
441
  }
436
- ) => import('./types').CacheState<Typenames, QP, QR, MP, MR>
442
+ ) => CacheState<Typenames, QP, QR, MP, MR>
437
443
  actions: {
438
444
  /** Updates query state, and optionally merges entity changes in a single action. */
439
445
  updateQueryStateAndEntities: {
440
446
  <K extends keyof QP & keyof QR>(
441
447
  queryKey: K,
442
448
  queryCacheKey: Key,
443
- state?: Partial<import('./types').QueryState<Typenames, QP[K], QR[K]>> | undefined,
444
- entityChanges?: import('./types').EntityChanges<Typenames> | undefined
449
+ state?: Partial<QueryState<Typenames, QP[K], QR[K]>> | undefined,
450
+ entityChanges?: EntityChanges<Typenames> | undefined
445
451
  ): {
446
452
  type: `@rrc/${N}/updateQueryStateAndEntities`
447
453
  queryKey: K
448
454
  queryCacheKey: Key
449
- state: Partial<import('./types').QueryState<Typenames, QP[K], QR[K]>> | undefined
450
- entityChanges: import('./types').EntityChanges<Typenames> | undefined
455
+ state: Partial<QueryState<Typenames, QP[K], QR[K]>> | undefined
456
+ entityChanges: EntityChanges<Typenames> | undefined
451
457
  }
452
458
  type: `@rrc/${N}/updateQueryStateAndEntities`
453
459
  }
@@ -455,21 +461,21 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
455
461
  updateMutationStateAndEntities: {
456
462
  <K extends keyof MP & keyof MR>(
457
463
  mutationKey: K,
458
- state?: Partial<import('./types').MutationState<Typenames, MP[K], MR[K]>> | undefined,
459
- entityChanges?: import('./types').EntityChanges<Typenames> | undefined
464
+ state?: Partial<MutationState<Typenames, MP[K], MR[K]>> | undefined,
465
+ entityChanges?: EntityChanges<Typenames> | undefined
460
466
  ): {
461
467
  type: `@rrc/${N}/updateMutationStateAndEntities`
462
468
  mutationKey: K
463
- state: Partial<import('./types').MutationState<Typenames, MP[K], MR[K]>> | undefined
464
- entityChanges: import('./types').EntityChanges<Typenames> | undefined
469
+ state: Partial<MutationState<Typenames, MP[K], MR[K]>> | undefined
470
+ entityChanges: EntityChanges<Typenames> | undefined
465
471
  }
466
472
  type: `@rrc/${N}/updateMutationStateAndEntities`
467
473
  }
468
474
  /** Merges EntityChanges to the state. */
469
475
  mergeEntityChanges: {
470
- (changes: import('./types').EntityChanges<Typenames>): {
476
+ (changes: EntityChanges<Typenames>): {
471
477
  type: `@rrc/${N}/mergeEntityChanges`
472
- changes: import('./types').EntityChanges<Typenames>
478
+ changes: EntityChanges<Typenames>
473
479
  }
474
480
  type: `@rrc/${N}/mergeEntityChanges`
475
481
  }
@@ -518,22 +524,22 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
518
524
  }
519
525
  /** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
520
526
  clearCache: {
521
- (stateToKeep?: Partial<import('./types').CacheState<Typenames, QP, QR, MP, MR>> | undefined): {
527
+ (stateToKeep?: Partial<CacheState<Typenames, QP, QR, MP, MR>> | undefined): {
522
528
  type: `@rrc/${N}/clearCache`
523
- stateToKeep: Partial<import('./types').CacheState<Typenames, QP, QR, MP, MR>> | undefined
529
+ stateToKeep: Partial<CacheState<Typenames, QP, QR, MP, MR>> | undefined
524
530
  }
525
531
  type: `@rrc/${N}/clearCache`
526
532
  }
527
533
  }
528
534
  selectors: {
529
535
  /** This is a cacheStateSelector from createCache options, or default one if was not provided. */
530
- selectCacheState: (state: any) => import('./types').CacheState<Typenames, QP, QR, MP, MR>
536
+ selectCacheState: (state: any) => CacheState<Typenames, QP, QR, MP, MR>
531
537
  /** Selects query state. */
532
538
  selectQueryState: <QK_1 extends keyof QP | keyof QR>(
533
539
  state: unknown,
534
540
  query: QK_1,
535
541
  cacheKey: Key
536
- ) => import('./types').QueryState<
542
+ ) => QueryState<
537
543
  Typenames,
538
544
  QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never,
539
545
  QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never
@@ -551,12 +557,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
551
557
  cacheKey: Key
552
558
  ) =>
553
559
  | false
554
- | Promise<
555
- import('./types').NormalizedQueryResponse<
556
- Typenames,
557
- QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never
558
- >
559
- >
560
+ | Promise<NormalizedQueryResponse<Typenames, QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>>
560
561
  /** Selects query latest error. */
561
562
  selectQueryError: <QK_1 extends keyof QP | keyof QR>(
562
563
  state: unknown,
@@ -579,7 +580,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
579
580
  selectMutationState: <MK_1 extends keyof MP | keyof MR>(
580
581
  state: unknown,
581
582
  mutation: MK_1
582
- ) => import('./types').MutationState<
583
+ ) => MutationState<
583
584
  Typenames,
584
585
  MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never,
585
586
  MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never
@@ -595,12 +596,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
595
596
  mutation: MK_1
596
597
  ) =>
597
598
  | false
598
- | Promise<
599
- import('./types').NormalizedQueryResponse<
600
- Typenames,
601
- MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never
602
- >
603
- >
599
+ | Promise<NormalizedQueryResponse<Typenames, MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>>
604
600
  /** Selects mutation latest error. */
605
601
  selectMutationError: <MK_1 extends keyof MP | keyof MR>(
606
602
  state: unknown,
@@ -618,29 +614,34 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
618
614
  typename: TN
619
615
  ) => object | undefined
620
616
  /** Selects all entities. */
621
- selectEntities: (state: unknown) => import('./types').EntitiesMap<Typenames>
617
+ selectEntities: (state: unknown) => EntitiesMap<Typenames>
622
618
  /** Selects all entities of provided typename. */
623
- selectEntitiesByTypename: <TN extends string>(
624
- state: unknown,
625
- typename: TN
626
- ) => import('./types').Dict<object> | undefined
619
+ selectEntitiesByTypename: <TN extends string>(state: unknown, typename: TN) => Dict<object> | undefined
627
620
  }
628
621
  hooks: {
629
- /** Returns client object with query and mutate functions. */
622
+ /** Returns memoized object with query and mutate functions. Memoization dependency is the store. */
630
623
  useClient: () => {
624
+ /**
625
+ * Performs a query using provided options. Deduplicates calls with the same cache key. Always returns current cached result, even when query is cancelled or finished with error.
626
+ * @param onlyIfExpired When true, cancels fetch if result is not yet expired.
627
+ * @param skipFetch Fetch is cancelled and current cached result is returned.
628
+ */
631
629
  query: <QK_1 extends keyof QP | keyof QR>(
632
630
  options: QueryOptions<N, Typenames, QP, QR, QK_1, MP, MR>
633
631
  ) => Promise<QueryResult<QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>>
632
+ /**
633
+ * Performs a mutation, aborting previous one with the same mutation key. Returns result only if finished succesfully.
634
+ */
634
635
  mutate: <MK_1 extends keyof MP | keyof MR>(
635
636
  options: MutateOptions<N, Typenames, QP, QR, MP, MR, MK_1>
636
637
  ) => Promise<MutationResult<MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>>
637
638
  }
638
- /** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
639
+ /** Fetches query when params change and subscribes to query state changes (subscription depends on `selectorComparer`). */
639
640
  useQuery: <QK_1 extends keyof QP | keyof QR>(
640
- options: import('./types').UseQueryOptions<N, Typenames, QK_1, QP, QR, MP, MR>
641
+ options: UseQueryOptions<N, Typenames, QK_1, QP, QR, MP, MR>
641
642
  ) => readonly [
642
643
  Omit<
643
- import('./types').QueryState<
644
+ QueryState<
644
645
  Typenames,
645
646
  QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never,
646
647
  QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never
@@ -680,7 +681,7 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
680
681
  : never
681
682
  >
682
683
  >,
683
- import('./types').MutationState<
684
+ MutationState<
684
685
  Typenames,
685
686
  MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never,
686
687
  MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never
@@ -691,22 +692,30 @@ export declare const createCache: <N extends string, QP, QR, MP, MR>(
691
692
  useSelectEntityById: <TN extends string>(id: Key | null | undefined, typename: TN) => object | undefined
692
693
  }
693
694
  utils: {
694
- /** Creates client by providing the store. Can be used when the store is a singleton - to not use a hook for getting the client, but import it directly. */
695
+ /** Creates client by providing the store. Can be used when the store is a singleton - to not use a useClient hook for getting the client, but import it directly. */
695
696
  createClient: (store: Store) => {
697
+ /**
698
+ * Performs a query using provided options. Deduplicates calls with the same cache key. Always returns current cached result, even when query is cancelled or finished with error.
699
+ * @param onlyIfExpired When true, cancels fetch if result is not yet expired.
700
+ * @param skipFetch Fetch is cancelled and current cached result is returned.
701
+ */
696
702
  query: <QK_1 extends keyof QP | keyof QR>(
697
703
  options: QueryOptions<N, Typenames, QP, QR, QK_1, MP, MR>
698
704
  ) => Promise<QueryResult<QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>>
705
+ /**
706
+ * Performs a mutation, aborting previous one with the same mutation key. Returns result only if finished succesfully.
707
+ */
699
708
  mutate: <MK_1 extends keyof MP | keyof MR>(
700
709
  options: MutateOptions<N, Typenames, QP, QR, MP, MR, MK_1>
701
710
  ) => Promise<MutationResult<MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>>
702
711
  }
703
712
  /** Generates the initial state by calling a reducer. Not needed for redux — it already generates it the same way when creating the store. */
704
- getInitialState: () => import('./types').CacheState<Typenames, QP, QR, MP, MR>
713
+ getInitialState: () => CacheState<Typenames, QP, QR, MP, MR>
705
714
  /** Apply changes to the entities map.
706
715
  * @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
707
716
  applyEntityChanges: (
708
- entities: import('./types').EntitiesMap<Typenames>,
709
- changes: import('./types').EntityChanges<Typenames>
710
- ) => import('./types').EntitiesMap<Typenames> | undefined
717
+ entities: EntitiesMap<Typenames>,
718
+ changes: EntityChanges<Typenames>
719
+ ) => EntitiesMap<Typenames> | undefined
711
720
  }
712
721
  }
@@ -1,7 +1,7 @@
1
1
  import type {Actions} from './createActions'
2
2
  import type {CacheOptions, CacheState, Typenames} from './types'
3
3
 
4
- export declare const createCacheReducer: <N extends string, T extends Typenames, QP, QR, MP, MR>(
4
+ export declare const createReducer: <N extends string, T extends Typenames, QP, QR, MP, MR>(
5
5
  actions: Actions<N, T, QP, QR, MP, MR>,
6
6
  queryKeys: (keyof (QP | QR))[],
7
7
  cacheOptions: CacheOptions
@@ -8,6 +8,7 @@ export type Selectors<
8
8
  MP = unknown,
9
9
  MR = unknown
10
10
  > = ReturnType<typeof createSelectors<N, T, QP, QR, MP, MR>>
11
+
11
12
  export declare const createSelectors: <N extends string, T extends Typenames, QP, QR, MP, MR>(
12
13
  cache: Cache<N, T, QP, QR, MP, MR>
13
14
  ) => {
@@ -1,3 +1,5 @@
1
1
  export {createCache, withTypenames} from './createCache'
2
+
2
3
  export * from './types'
3
- export {createStateComparer, defaultGetCacheKey, FetchPolicy, isEmptyObject} from './utilsAndConstants'
4
+
5
+ export {createStateComparer, defaultGetCacheKey, FetchPolicy, isEmptyObject, noop} from './utilsAndConstants'
@@ -13,7 +13,7 @@ export declare const mutate: <
13
13
  >(
14
14
  logTag: string,
15
15
  store: Store,
16
- cache: Cache<N, T, QP, QR, MP, MR>,
16
+ cache: Pick<Cache<N, T, QP, QR, MP, MR>, 'options' | 'globals' | 'mutations'>,
17
17
  actions: Actions<N, T, QP, QR, MP, MR>,
18
18
  selectors: Selectors<N, T, QP, QR, MP, MR>,
19
19
  mutationKey: MK,
@@ -13,7 +13,7 @@ export declare const query: <
13
13
  >(
14
14
  logTag: string,
15
15
  store: Store,
16
- cache: Cache<N, T, QP, QR, MP, MR>,
16
+ cache: Pick<Cache<N, T, QP, QR, MP, MR>, 'options' | 'globals' | 'queries'>,
17
17
  actions: Actions<N, T, QP, QR, MP, MR>,
18
18
  selectors: Selectors<N, T, QP, QR, MP, MR>,
19
19
  queryKey: QK,