react-redux-cache 0.19.3 → 0.19.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.
Files changed (57) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/createActions.js +65 -0
  3. package/dist/cjs/createCache.js +208 -0
  4. package/dist/cjs/createCacheReducer.js +285 -0
  5. package/dist/cjs/createSelectors.js +68 -0
  6. package/dist/cjs/index.js +83 -0
  7. package/dist/cjs/mutate.js +161 -0
  8. package/dist/cjs/query.js +180 -0
  9. package/dist/cjs/types.js +2 -0
  10. package/dist/cjs/useMutation.js +82 -0
  11. package/dist/cjs/useQuery.js +121 -0
  12. package/dist/cjs/utilsAndConstants.js +189 -0
  13. package/dist/esm/createActions.js +61 -0
  14. package/dist/esm/createCache.js +203 -0
  15. package/dist/esm/createCacheReducer.js +271 -0
  16. package/dist/esm/createSelectors.js +64 -0
  17. package/dist/esm/index.js +3 -0
  18. package/dist/esm/mutate.js +157 -0
  19. package/dist/esm/query.js +169 -0
  20. package/dist/esm/types.js +1 -0
  21. package/dist/esm/useMutation.js +88 -0
  22. package/dist/esm/useQuery.js +125 -0
  23. package/dist/esm/utilsAndConstants.js +168 -0
  24. package/dist/types/createActions.d.ts +106 -0
  25. package/dist/types/createCache.d.ts +712 -0
  26. package/dist/types/createCacheReducer.d.ts +11 -0
  27. package/dist/types/createSelectors.d.ts +79 -0
  28. package/dist/types/index.d.ts +3 -0
  29. package/dist/types/mutate.d.ts +94 -0
  30. package/dist/types/query.d.ts +122 -0
  31. package/dist/types/types.d.ts +322 -0
  32. package/dist/types/useMutation.d.ts +39 -0
  33. package/dist/types/useQuery.d.ts +40 -0
  34. package/dist/types/utilsAndConstants.d.ts +39 -0
  35. package/package.json +21 -10
  36. package/dist/createActions.d.ts +0 -83
  37. package/dist/createActions.js +0 -64
  38. package/dist/createCache.d.ts +0 -378
  39. package/dist/createCache.js +0 -192
  40. package/dist/createCacheReducer.d.ts +0 -3
  41. package/dist/createCacheReducer.js +0 -243
  42. package/dist/createSelectors.d.ts +0 -18
  43. package/dist/createSelectors.js +0 -61
  44. package/dist/index.d.ts +0 -3
  45. package/dist/index.js +0 -53
  46. package/dist/mutate.d.ts +0 -4
  47. package/dist/mutate.js +0 -98
  48. package/dist/query.d.ts +0 -4
  49. package/dist/query.js +0 -107
  50. package/dist/types.d.ts +0 -187
  51. package/dist/types.js +0 -3
  52. package/dist/useMutation.d.ts +0 -4
  53. package/dist/useMutation.js +0 -61
  54. package/dist/useQuery.d.ts +0 -4
  55. package/dist/useQuery.js +0 -77
  56. package/dist/utilsAndConstants.d.ts +0 -20
  57. package/dist/utilsAndConstants.js +0 -161
@@ -0,0 +1,712 @@
1
+ import type {
2
+ Cache,
3
+ CacheOptions,
4
+ Globals,
5
+ Key,
6
+ MutateOptions,
7
+ MutationResult,
8
+ OptionalPartial,
9
+ QueryOptions,
10
+ QueryResult,
11
+ Store,
12
+ Typenames,
13
+ } from './types'
14
+ import {useMutation} from './useMutation'
15
+ import {useQuery} from './useQuery'
16
+ import {applyEntityChanges} from './utilsAndConstants'
17
+ /**
18
+ * Function to provide generic Typenames if normalization is needed - this is a Typescript limitation.
19
+ * Returns object with createCache function with provided typenames.
20
+ * @example
21
+ * const cache = withTypenames<MyTypenames>().createCache({
22
+ * ...
23
+ * })
24
+ */
25
+ export declare const withTypenames: <T extends Typenames = Typenames>() => {
26
+ createCache: <N extends string, QP, QR, MP, MR>(
27
+ partialCache: OptionalPartial<
28
+ Omit<Cache<N, T, QP, QR, MP, MR>, 'globals'>,
29
+ 'options' | 'queries' | 'mutations' | 'cacheStateSelector' | 'storeHooks'
30
+ > & {
31
+ globals?: OptionalPartial<Cache<N, T, QP, QR, MP, MR>['globals'], 'queries'>
32
+ }
33
+ ) => {
34
+ /** Keeps all options, passed while creating the cache. */
35
+ cache: Cache<N, T, QP, QR, MP, MR>
36
+ /** Reducer of the cache, should be added to redux store. */
37
+ reducer: (
38
+ state: import('./types').CacheState<T, QP, QR, MP, MR> | undefined,
39
+ action:
40
+ | {
41
+ type: `@rrc/${N}/updateQueryStateAndEntities`
42
+ queryKey: keyof QP & keyof QR
43
+ 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
48
+ }
49
+ | {
50
+ type: `@rrc/${N}/updateMutationStateAndEntities`
51
+ 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
56
+ }
57
+ | {
58
+ type: `@rrc/${N}/mergeEntityChanges`
59
+ changes: import('./types').EntityChanges<T>
60
+ }
61
+ | {
62
+ type: `@rrc/${N}/invalidateQuery`
63
+ queries: {
64
+ query: keyof QP & keyof QR
65
+ cacheKey?: Key
66
+ expiresAt?: number
67
+ }[]
68
+ }
69
+ | {
70
+ type: `@rrc/${N}/clearQueryState`
71
+ queries: {
72
+ query: keyof QP & keyof QR
73
+ cacheKey?: Key
74
+ }[]
75
+ }
76
+ | {
77
+ type: `@rrc/${N}/clearMutationState`
78
+ mutationKeys: (keyof MP & keyof MR)[]
79
+ }
80
+ | {
81
+ type: `@rrc/${N}/clearCache`
82
+ stateToKeep: Partial<import('./types').CacheState<T, QP, QR, MP, MR>> | undefined
83
+ }
84
+ ) => import('./types').CacheState<T, QP, QR, MP, MR>
85
+ actions: {
86
+ /** Updates query state, and optionally merges entity changes in a single action. */
87
+ updateQueryStateAndEntities: {
88
+ <K extends keyof QP & keyof QR>(
89
+ queryKey: K,
90
+ queryCacheKey: Key,
91
+ state?: Partial<import('./types').QueryState<T, QP[K], QR[K]>> | undefined,
92
+ entityChanges?: import('./types').EntityChanges<T> | undefined
93
+ ): {
94
+ type: `@rrc/${N}/updateQueryStateAndEntities`
95
+ queryKey: K
96
+ queryCacheKey: Key
97
+ state: Partial<import('./types').QueryState<T, QP[K], QR[K]>> | undefined
98
+ entityChanges: import('./types').EntityChanges<T> | undefined
99
+ }
100
+ type: `@rrc/${N}/updateQueryStateAndEntities`
101
+ }
102
+ /** Updates mutation state, and optionally merges entity changes in a single action. */
103
+ updateMutationStateAndEntities: {
104
+ <K extends keyof MP & keyof MR>(
105
+ mutationKey: K,
106
+ state?: Partial<import('./types').MutationState<T, MP[K], MR[K]>> | undefined,
107
+ entityChanges?: import('./types').EntityChanges<T> | undefined
108
+ ): {
109
+ type: `@rrc/${N}/updateMutationStateAndEntities`
110
+ mutationKey: K
111
+ state: Partial<import('./types').MutationState<T, MP[K], MR[K]>> | undefined
112
+ entityChanges: import('./types').EntityChanges<T> | undefined
113
+ }
114
+ type: `@rrc/${N}/updateMutationStateAndEntities`
115
+ }
116
+ /** Merges EntityChanges to the state. */
117
+ mergeEntityChanges: {
118
+ (changes: import('./types').EntityChanges<T>): {
119
+ type: `@rrc/${N}/mergeEntityChanges`
120
+ changes: import('./types').EntityChanges<T>
121
+ }
122
+ type: `@rrc/${N}/mergeEntityChanges`
123
+ }
124
+ /** Invalidates query states. */
125
+ invalidateQuery: {
126
+ <K extends keyof QP & keyof QR>(
127
+ queries: {
128
+ query: K
129
+ cacheKey?: Key
130
+ expiresAt?: number
131
+ }[]
132
+ ): {
133
+ type: `@rrc/${N}/invalidateQuery`
134
+ queries: {
135
+ query: K
136
+ cacheKey?: Key
137
+ expiresAt?: number
138
+ }[]
139
+ }
140
+ type: `@rrc/${N}/invalidateQuery`
141
+ }
142
+ /** Clears states for provided query keys and cache keys.
143
+ * If cache key for query key is not provided, the whole state for query key is cleared. */
144
+ clearQueryState: {
145
+ <K extends keyof QP & keyof QR>(
146
+ queries: {
147
+ query: K
148
+ cacheKey?: Key
149
+ }[]
150
+ ): {
151
+ type: `@rrc/${N}/clearQueryState`
152
+ queries: {
153
+ query: K
154
+ cacheKey?: Key
155
+ }[]
156
+ }
157
+ type: `@rrc/${N}/clearQueryState`
158
+ }
159
+ /** Clears states for provided mutation keys. */
160
+ clearMutationState: {
161
+ <K extends keyof MP & keyof MR>(mutationKeys: K[]): {
162
+ type: `@rrc/${N}/clearMutationState`
163
+ mutationKeys: K[]
164
+ }
165
+ type: `@rrc/${N}/clearMutationState`
166
+ }
167
+ /** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
168
+ clearCache: {
169
+ (stateToKeep?: Partial<import('./types').CacheState<T, QP, QR, MP, MR>> | undefined): {
170
+ type: `@rrc/${N}/clearCache`
171
+ stateToKeep: Partial<import('./types').CacheState<T, QP, QR, MP, MR>> | undefined
172
+ }
173
+ type: `@rrc/${N}/clearCache`
174
+ }
175
+ }
176
+ selectors: {
177
+ /** 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>
179
+ /** Selects query state. */
180
+ selectQueryState: <QK extends keyof QP | keyof QR>(
181
+ state: unknown,
182
+ query: QK,
183
+ cacheKey: Key
184
+ ) => import('./types').QueryState<
185
+ T,
186
+ QK extends keyof QP & keyof QR ? QP[QK] : never,
187
+ QK extends keyof QP & keyof QR ? QR[QK] : never
188
+ >
189
+ /** Selects query latest result. */
190
+ selectQueryResult: <QK extends keyof QP | keyof QR>(
191
+ state: unknown,
192
+ query: QK,
193
+ cacheKey: Key
194
+ ) => (QK extends keyof QP & keyof QR ? QR[QK] : never) | undefined
195
+ /** Selects query loading state. */
196
+ selectQueryLoading: <QK extends keyof QP | keyof QR>(
197
+ state: unknown,
198
+ query: QK,
199
+ cacheKey: Key
200
+ ) =>
201
+ | false
202
+ | Promise<
203
+ import('./types').NormalizedQueryResponse<T, QK extends keyof QP & keyof QR ? QR[QK] : never>
204
+ >
205
+ /** Selects query latest error. */
206
+ selectQueryError: <QK extends keyof QP | keyof QR>(
207
+ state: unknown,
208
+ query: QK,
209
+ cacheKey: Key
210
+ ) => Error | undefined
211
+ /** Selects query latest params. */
212
+ selectQueryParams: <QK extends keyof QP | keyof QR>(
213
+ state: unknown,
214
+ query: QK,
215
+ cacheKey: Key
216
+ ) => (QK extends keyof QP & keyof QR ? QP[QK] : never) | undefined
217
+ /** Selects query latest expiresAt. */
218
+ selectQueryExpiresAt: <QK extends keyof QP | keyof QR>(
219
+ state: unknown,
220
+ query: QK,
221
+ cacheKey: Key
222
+ ) => number | undefined
223
+ /** Selects mutation state. */
224
+ selectMutationState: <MK extends keyof MP | keyof MR>(
225
+ state: unknown,
226
+ mutation: MK
227
+ ) => import('./types').MutationState<
228
+ T,
229
+ MK extends keyof MP & keyof MR ? MP[MK] : never,
230
+ MK extends keyof MP & keyof MR ? MR[MK] : never
231
+ >
232
+ /** Selects mutation latest result. */
233
+ selectMutationResult: <MK extends keyof MP | keyof MR>(
234
+ state: unknown,
235
+ mutation: MK
236
+ ) => (MK extends keyof MP & keyof MR ? MR[MK] : never) | undefined
237
+ /** Selects mutation loading state. */
238
+ selectMutationLoading: <MK extends keyof MP | keyof MR>(
239
+ state: unknown,
240
+ mutation: MK
241
+ ) =>
242
+ | false
243
+ | Promise<
244
+ import('./types').NormalizedQueryResponse<T, MK extends keyof MP & keyof MR ? MR[MK] : never>
245
+ >
246
+ /** Selects mutation latest error. */
247
+ selectMutationError: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => Error | undefined
248
+ /** Selects mutation latest params. */
249
+ selectMutationParams: <MK extends keyof MP | keyof MR>(
250
+ state: unknown,
251
+ mutation: MK
252
+ ) => (MK extends keyof MP & keyof MR ? MP[MK] : never) | undefined
253
+ /** Selects entity by id and typename. */
254
+ selectEntityById: <TN extends keyof T>(
255
+ state: unknown,
256
+ id: Key | null | undefined,
257
+ typename: TN
258
+ ) => T[TN] | undefined
259
+ /** Selects all entities. */
260
+ selectEntities: (state: unknown) => import('./types').EntitiesMap<T>
261
+ /** Selects all entities of provided typename. */
262
+ selectEntitiesByTypename: <TN extends keyof T>(
263
+ state: unknown,
264
+ typename: TN
265
+ ) => import('./types').EntitiesMap<T>[TN]
266
+ }
267
+ hooks: {
268
+ /** Returns client object with query and mutate functions. */
269
+ useClient: () => {
270
+ query: <QK extends keyof (QP & QR)>(
271
+ options: QueryOptions<N, T, QP, QR, QK, MP, MR>
272
+ ) => Promise<QueryResult<QK extends keyof QP & keyof QR ? QR[QK] : never>>
273
+ mutate: <MK extends keyof (MP & MR)>(
274
+ options: MutateOptions<N, T, QP, QR, MP, MR, MK>
275
+ ) => Promise<MutationResult<MK extends keyof MP & keyof MR ? MR[MK] : never>>
276
+ }
277
+ /** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
278
+ useQuery: <QK extends keyof (QP & QR)>(
279
+ options: Parameters<typeof useQuery<N, T, QP, QR, MP, MR, QK>>[3]
280
+ ) => readonly [
281
+ Omit<
282
+ import('./types').QueryState<
283
+ T,
284
+ QK extends keyof QP & keyof QR ? QP[QK] : never,
285
+ QK extends keyof QP & keyof QR ? QR[QK] : never
286
+ >,
287
+ 'expiresAt'
288
+ >,
289
+ (
290
+ options?:
291
+ | Partial<Pick<QueryOptions<N, T, QP, QR, QK, MP, MR>, 'params' | 'onlyIfExpired'>>
292
+ | undefined
293
+ ) => Promise<
294
+ QueryResult<
295
+ QK extends infer T_1
296
+ ? T_1 extends QK
297
+ ? T_1 extends keyof QP & keyof QR
298
+ ? QR[T_1]
299
+ : never
300
+ : never
301
+ : never
302
+ >
303
+ >
304
+ ]
305
+ /** Subscribes to provided mutation state and provides mutate function. */
306
+ useMutation: <MK extends keyof (MP & MR)>(
307
+ options: Parameters<typeof useMutation<N, T, QP, QR, MP, MR, MK>>[3]
308
+ ) => readonly [
309
+ (
310
+ params: MK extends keyof MP & keyof MR ? MP[MK] : never
311
+ ) => Promise<
312
+ MutationResult<
313
+ MK extends infer T_1
314
+ ? T_1 extends MK
315
+ ? T_1 extends keyof MP & keyof MR
316
+ ? MR[T_1]
317
+ : never
318
+ : never
319
+ : never
320
+ >
321
+ >,
322
+ import('./types').MutationState<
323
+ T,
324
+ MK extends keyof MP & keyof MR ? MP[MK] : never,
325
+ MK extends keyof MP & keyof MR ? MP[MK] : never
326
+ >,
327
+ () => boolean
328
+ ]
329
+ /** useSelector + selectEntityById. */
330
+ useSelectEntityById: <TN extends keyof T>(id: Key | null | undefined, typename: TN) => T[TN] | undefined
331
+ }
332
+ 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. */
334
+ createClient: (store: Store) => {
335
+ query: <QK extends keyof (QP & QR)>(
336
+ options: QueryOptions<N, T, QP, QR, QK, MP, MR>
337
+ ) => Promise<QueryResult<QK extends keyof QP & keyof QR ? QR[QK] : never>>
338
+ mutate: <MK extends keyof (MP & MR)>(
339
+ options: MutateOptions<N, T, QP, QR, MP, MR, MK>
340
+ ) => Promise<MutationResult<MK extends keyof MP & keyof MR ? MR[MK] : never>>
341
+ }
342
+ /** 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>
344
+ /** Apply changes to the entities map.
345
+ * @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
346
+ applyEntityChanges: (
347
+ entities: Parameters<typeof applyEntityChanges<T>>[0],
348
+ changes: Parameters<typeof applyEntityChanges<T>>[1]
349
+ ) => import('./types').EntitiesMap<T> | undefined
350
+ }
351
+ }
352
+ }
353
+ /**
354
+ * Creates reducer, actions and hooks for managing queries and mutations through redux cache.
355
+ */
356
+ export declare const createCache: <N extends string, QP, QR, MP, MR>(
357
+ partialCache: Partial<{
358
+ queries: Partial<{
359
+ [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>
361
+ : never
362
+ }>
363
+ mutations: Partial<{
364
+ [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>
366
+ : never
367
+ }>
368
+ options: Partial<CacheOptions>
369
+ storeHooks: Partial<{
370
+ useStore: () => Store
371
+ useSelector: <R>(selector: (state: unknown) => R, comparer?: (x: R, y: R) => boolean) => R
372
+ }>
373
+ cacheStateSelector: Partial<(state: any) => import('./types').CacheState<Typenames, QP, QR, MP, MR>>
374
+ }> &
375
+ Omit<
376
+ Omit<Cache<N, Typenames, QP, QR, MP, MR>, 'globals'>,
377
+ 'queries' | 'mutations' | 'options' | 'storeHooks' | 'cacheStateSelector'
378
+ > & {
379
+ globals?: OptionalPartial<Globals<N, Typenames, QP, QR, MP, MR>, 'queries'> | undefined
380
+ }
381
+ ) => {
382
+ /** Keeps all options, passed while creating the cache. */
383
+ cache: Cache<N, Typenames, QP, QR, MP, MR>
384
+ /** Reducer of the cache, should be added to redux store. */
385
+ reducer: (
386
+ state: import('./types').CacheState<Typenames, QP, QR, MP, MR> | undefined,
387
+ action:
388
+ | {
389
+ type: `@rrc/${N}/updateQueryStateAndEntities`
390
+ queryKey: keyof QP & keyof QR
391
+ 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
398
+ }
399
+ | {
400
+ type: `@rrc/${N}/updateMutationStateAndEntities`
401
+ mutationKey: keyof MP & keyof MR
402
+ state:
403
+ | Partial<
404
+ import('./types').MutationState<Typenames, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>
405
+ >
406
+ | undefined
407
+ entityChanges: import('./types').EntityChanges<Typenames> | undefined
408
+ }
409
+ | {
410
+ type: `@rrc/${N}/mergeEntityChanges`
411
+ changes: import('./types').EntityChanges<Typenames>
412
+ }
413
+ | {
414
+ type: `@rrc/${N}/invalidateQuery`
415
+ queries: {
416
+ query: keyof QP & keyof QR
417
+ cacheKey?: Key
418
+ expiresAt?: number
419
+ }[]
420
+ }
421
+ | {
422
+ type: `@rrc/${N}/clearQueryState`
423
+ queries: {
424
+ query: keyof QP & keyof QR
425
+ cacheKey?: Key
426
+ }[]
427
+ }
428
+ | {
429
+ type: `@rrc/${N}/clearMutationState`
430
+ mutationKeys: (keyof MP & keyof MR)[]
431
+ }
432
+ | {
433
+ type: `@rrc/${N}/clearCache`
434
+ stateToKeep: Partial<import('./types').CacheState<Typenames, QP, QR, MP, MR>> | undefined
435
+ }
436
+ ) => import('./types').CacheState<Typenames, QP, QR, MP, MR>
437
+ actions: {
438
+ /** Updates query state, and optionally merges entity changes in a single action. */
439
+ updateQueryStateAndEntities: {
440
+ <K extends keyof QP & keyof QR>(
441
+ queryKey: K,
442
+ queryCacheKey: Key,
443
+ state?: Partial<import('./types').QueryState<Typenames, QP[K], QR[K]>> | undefined,
444
+ entityChanges?: import('./types').EntityChanges<Typenames> | undefined
445
+ ): {
446
+ type: `@rrc/${N}/updateQueryStateAndEntities`
447
+ queryKey: K
448
+ queryCacheKey: Key
449
+ state: Partial<import('./types').QueryState<Typenames, QP[K], QR[K]>> | undefined
450
+ entityChanges: import('./types').EntityChanges<Typenames> | undefined
451
+ }
452
+ type: `@rrc/${N}/updateQueryStateAndEntities`
453
+ }
454
+ /** Updates mutation state, and optionally merges entity changes in a single action. */
455
+ updateMutationStateAndEntities: {
456
+ <K extends keyof MP & keyof MR>(
457
+ mutationKey: K,
458
+ state?: Partial<import('./types').MutationState<Typenames, MP[K], MR[K]>> | undefined,
459
+ entityChanges?: import('./types').EntityChanges<Typenames> | undefined
460
+ ): {
461
+ type: `@rrc/${N}/updateMutationStateAndEntities`
462
+ mutationKey: K
463
+ state: Partial<import('./types').MutationState<Typenames, MP[K], MR[K]>> | undefined
464
+ entityChanges: import('./types').EntityChanges<Typenames> | undefined
465
+ }
466
+ type: `@rrc/${N}/updateMutationStateAndEntities`
467
+ }
468
+ /** Merges EntityChanges to the state. */
469
+ mergeEntityChanges: {
470
+ (changes: import('./types').EntityChanges<Typenames>): {
471
+ type: `@rrc/${N}/mergeEntityChanges`
472
+ changes: import('./types').EntityChanges<Typenames>
473
+ }
474
+ type: `@rrc/${N}/mergeEntityChanges`
475
+ }
476
+ /** Invalidates query states. */
477
+ invalidateQuery: {
478
+ <K extends keyof QP & keyof QR>(
479
+ queries: {
480
+ query: K
481
+ cacheKey?: Key
482
+ expiresAt?: number
483
+ }[]
484
+ ): {
485
+ type: `@rrc/${N}/invalidateQuery`
486
+ queries: {
487
+ query: K
488
+ cacheKey?: Key
489
+ expiresAt?: number
490
+ }[]
491
+ }
492
+ type: `@rrc/${N}/invalidateQuery`
493
+ }
494
+ /** Clears states for provided query keys and cache keys.
495
+ * If cache key for query key is not provided, the whole state for query key is cleared. */
496
+ clearQueryState: {
497
+ <K extends keyof QP & keyof QR>(
498
+ queries: {
499
+ query: K
500
+ cacheKey?: Key
501
+ }[]
502
+ ): {
503
+ type: `@rrc/${N}/clearQueryState`
504
+ queries: {
505
+ query: K
506
+ cacheKey?: Key
507
+ }[]
508
+ }
509
+ type: `@rrc/${N}/clearQueryState`
510
+ }
511
+ /** Clears states for provided mutation keys. */
512
+ clearMutationState: {
513
+ <K extends keyof MP & keyof MR>(mutationKeys: K[]): {
514
+ type: `@rrc/${N}/clearMutationState`
515
+ mutationKeys: K[]
516
+ }
517
+ type: `@rrc/${N}/clearMutationState`
518
+ }
519
+ /** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
520
+ clearCache: {
521
+ (stateToKeep?: Partial<import('./types').CacheState<Typenames, QP, QR, MP, MR>> | undefined): {
522
+ type: `@rrc/${N}/clearCache`
523
+ stateToKeep: Partial<import('./types').CacheState<Typenames, QP, QR, MP, MR>> | undefined
524
+ }
525
+ type: `@rrc/${N}/clearCache`
526
+ }
527
+ }
528
+ selectors: {
529
+ /** 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>
531
+ /** Selects query state. */
532
+ selectQueryState: <QK_1 extends keyof QP | keyof QR>(
533
+ state: unknown,
534
+ query: QK_1,
535
+ cacheKey: Key
536
+ ) => import('./types').QueryState<
537
+ Typenames,
538
+ QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never,
539
+ QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never
540
+ >
541
+ /** Selects query latest result. */
542
+ selectQueryResult: <QK_1 extends keyof QP | keyof QR>(
543
+ state: unknown,
544
+ query: QK_1,
545
+ cacheKey: Key
546
+ ) => (QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never) | undefined
547
+ /** Selects query loading state. */
548
+ selectQueryLoading: <QK_1 extends keyof QP | keyof QR>(
549
+ state: unknown,
550
+ query: QK_1,
551
+ cacheKey: Key
552
+ ) =>
553
+ | false
554
+ | Promise<
555
+ import('./types').NormalizedQueryResponse<
556
+ Typenames,
557
+ QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never
558
+ >
559
+ >
560
+ /** Selects query latest error. */
561
+ selectQueryError: <QK_1 extends keyof QP | keyof QR>(
562
+ state: unknown,
563
+ query: QK_1,
564
+ cacheKey: Key
565
+ ) => Error | undefined
566
+ /** Selects query latest params. */
567
+ selectQueryParams: <QK_1 extends keyof QP | keyof QR>(
568
+ state: unknown,
569
+ query: QK_1,
570
+ cacheKey: Key
571
+ ) => (QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never) | undefined
572
+ /** Selects query latest expiresAt. */
573
+ selectQueryExpiresAt: <QK_1 extends keyof QP | keyof QR>(
574
+ state: unknown,
575
+ query: QK_1,
576
+ cacheKey: Key
577
+ ) => number | undefined
578
+ /** Selects mutation state. */
579
+ selectMutationState: <MK_1 extends keyof MP | keyof MR>(
580
+ state: unknown,
581
+ mutation: MK_1
582
+ ) => import('./types').MutationState<
583
+ Typenames,
584
+ MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never,
585
+ MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never
586
+ >
587
+ /** Selects mutation latest result. */
588
+ selectMutationResult: <MK_1 extends keyof MP | keyof MR>(
589
+ state: unknown,
590
+ mutation: MK_1
591
+ ) => (MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never) | undefined
592
+ /** Selects mutation loading state. */
593
+ selectMutationLoading: <MK_1 extends keyof MP | keyof MR>(
594
+ state: unknown,
595
+ mutation: MK_1
596
+ ) =>
597
+ | false
598
+ | Promise<
599
+ import('./types').NormalizedQueryResponse<
600
+ Typenames,
601
+ MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never
602
+ >
603
+ >
604
+ /** Selects mutation latest error. */
605
+ selectMutationError: <MK_1 extends keyof MP | keyof MR>(
606
+ state: unknown,
607
+ mutation: MK_1
608
+ ) => Error | undefined
609
+ /** Selects mutation latest params. */
610
+ selectMutationParams: <MK_1 extends keyof MP | keyof MR>(
611
+ state: unknown,
612
+ mutation: MK_1
613
+ ) => (MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never) | undefined
614
+ /** Selects entity by id and typename. */
615
+ selectEntityById: <TN extends string>(
616
+ state: unknown,
617
+ id: Key | null | undefined,
618
+ typename: TN
619
+ ) => object | undefined
620
+ /** Selects all entities. */
621
+ selectEntities: (state: unknown) => import('./types').EntitiesMap<Typenames>
622
+ /** Selects all entities of provided typename. */
623
+ selectEntitiesByTypename: <TN extends string>(
624
+ state: unknown,
625
+ typename: TN
626
+ ) => import('./types').Dict<object> | undefined
627
+ }
628
+ hooks: {
629
+ /** Returns client object with query and mutate functions. */
630
+ useClient: () => {
631
+ query: <QK_1 extends keyof QP | keyof QR>(
632
+ options: QueryOptions<N, Typenames, QP, QR, QK_1, MP, MR>
633
+ ) => Promise<QueryResult<QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>>
634
+ mutate: <MK_1 extends keyof MP | keyof MR>(
635
+ options: MutateOptions<N, Typenames, QP, QR, MP, MR, MK_1>
636
+ ) => Promise<MutationResult<MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>>
637
+ }
638
+ /** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
639
+ useQuery: <QK_1 extends keyof QP | keyof QR>(
640
+ options: import('./types').UseQueryOptions<N, Typenames, QK_1, QP, QR, MP, MR>
641
+ ) => readonly [
642
+ Omit<
643
+ import('./types').QueryState<
644
+ Typenames,
645
+ QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never,
646
+ QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never
647
+ >,
648
+ 'expiresAt'
649
+ >,
650
+ (
651
+ options?:
652
+ | Partial<Pick<QueryOptions<N, Typenames, QP, QR, QK_1, MP, MR>, 'params' | 'onlyIfExpired'>>
653
+ | undefined
654
+ ) => Promise<
655
+ QueryResult<
656
+ QK_1 extends infer T
657
+ ? T extends QK_1
658
+ ? T extends keyof QP & keyof QR
659
+ ? QR[T]
660
+ : never
661
+ : never
662
+ : never
663
+ >
664
+ >
665
+ ]
666
+ /** Subscribes to provided mutation state and provides mutate function. */
667
+ useMutation: <MK_1 extends keyof MP | keyof MR>(
668
+ options: Omit<MutateOptions<N, Typenames, QP, QR, MP, MR, MK_1>, 'params'>
669
+ ) => readonly [
670
+ (
671
+ params: MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never
672
+ ) => Promise<
673
+ MutationResult<
674
+ MK_1 extends infer T
675
+ ? T extends MK_1
676
+ ? T extends keyof MP & keyof MR
677
+ ? MR[T]
678
+ : never
679
+ : never
680
+ : never
681
+ >
682
+ >,
683
+ import('./types').MutationState<
684
+ Typenames,
685
+ MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never,
686
+ MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never
687
+ >,
688
+ () => boolean
689
+ ]
690
+ /** useSelector + selectEntityById. */
691
+ useSelectEntityById: <TN extends string>(id: Key | null | undefined, typename: TN) => object | undefined
692
+ }
693
+ 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
+ createClient: (store: Store) => {
696
+ query: <QK_1 extends keyof QP | keyof QR>(
697
+ options: QueryOptions<N, Typenames, QP, QR, QK_1, MP, MR>
698
+ ) => Promise<QueryResult<QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>>
699
+ mutate: <MK_1 extends keyof MP | keyof MR>(
700
+ options: MutateOptions<N, Typenames, QP, QR, MP, MR, MK_1>
701
+ ) => Promise<MutationResult<MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>>
702
+ }
703
+ /** 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>
705
+ /** Apply changes to the entities map.
706
+ * @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
707
+ applyEntityChanges: (
708
+ entities: import('./types').EntitiesMap<Typenames>,
709
+ changes: import('./types').EntityChanges<Typenames>
710
+ ) => import('./types').EntitiesMap<Typenames> | undefined
711
+ }
712
+ }