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