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.
- package/README.md +1 -1
- package/dist/cjs/createActions.js +65 -0
- package/dist/cjs/createCache.js +208 -0
- package/dist/cjs/createCacheReducer.js +285 -0
- package/dist/cjs/createSelectors.js +68 -0
- package/dist/cjs/index.js +83 -0
- package/dist/cjs/mutate.js +161 -0
- package/dist/cjs/query.js +180 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/useMutation.js +82 -0
- package/dist/cjs/useQuery.js +121 -0
- package/dist/cjs/utilsAndConstants.js +189 -0
- package/dist/esm/createActions.js +61 -0
- package/dist/esm/createCache.js +203 -0
- package/dist/esm/createCacheReducer.js +271 -0
- package/dist/esm/createSelectors.js +64 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/mutate.js +157 -0
- package/dist/esm/query.js +169 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/useMutation.js +88 -0
- package/dist/esm/useQuery.js +125 -0
- package/dist/esm/utilsAndConstants.js +168 -0
- package/dist/types/createActions.d.ts +106 -0
- package/dist/types/createCache.d.ts +712 -0
- package/dist/types/createCacheReducer.d.ts +11 -0
- package/dist/types/createSelectors.d.ts +79 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/mutate.d.ts +94 -0
- package/dist/types/query.d.ts +122 -0
- package/dist/types/types.d.ts +322 -0
- package/dist/types/useMutation.d.ts +39 -0
- package/dist/types/useQuery.d.ts +40 -0
- package/dist/types/utilsAndConstants.d.ts +39 -0
- package/package.json +21 -10
- package/dist/createActions.d.ts +0 -83
- package/dist/createActions.js +0 -64
- package/dist/createCache.d.ts +0 -378
- package/dist/createCache.js +0 -192
- package/dist/createCacheReducer.d.ts +0 -3
- package/dist/createCacheReducer.js +0 -243
- package/dist/createSelectors.d.ts +0 -18
- package/dist/createSelectors.js +0 -61
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -53
- package/dist/mutate.d.ts +0 -4
- package/dist/mutate.js +0 -98
- package/dist/query.d.ts +0 -4
- package/dist/query.js +0 -107
- package/dist/types.d.ts +0 -187
- package/dist/types.js +0 -3
- package/dist/useMutation.d.ts +0 -4
- package/dist/useMutation.js +0 -61
- package/dist/useQuery.d.ts +0 -4
- package/dist/useQuery.js +0 -77
- package/dist/utilsAndConstants.d.ts +0 -20
- package/dist/utilsAndConstants.js +0 -161
package/dist/createCache.d.ts
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import type { Cache, CacheOptions, Globals, Key, MutateOptions, MutationResult, OptionalPartial, QueryOptions, QueryResult, Store, Typenames } from './types';
|
|
2
|
-
import { useMutation } from './useMutation';
|
|
3
|
-
import { useQuery } from './useQuery';
|
|
4
|
-
import { applyEntityChanges } from './utilsAndConstants';
|
|
5
|
-
/**
|
|
6
|
-
* Function to provide generic Typenames if normalization is needed - this is a Typescript limitation.
|
|
7
|
-
* Returns object with createCache function with provided typenames.
|
|
8
|
-
* @example
|
|
9
|
-
* const cache = withTypenames<MyTypenames>().createCache({
|
|
10
|
-
* ...
|
|
11
|
-
* })
|
|
12
|
-
*/
|
|
13
|
-
export declare const withTypenames: <T extends Typenames = Typenames>() => {
|
|
14
|
-
createCache: <N extends string, QP, QR, MP, MR>(partialCache: OptionalPartial<Omit<Cache<N, T, QP, QR, MP, MR>, "globals">, "options" | "queries" | "mutations" | "cacheStateSelector" | "storeHooks"> & {
|
|
15
|
-
globals?: OptionalPartial<Cache<N, T, QP, QR, MP, MR>["globals"], "queries">;
|
|
16
|
-
}) => {
|
|
17
|
-
/** Keeps all options, passed while creating the cache. */
|
|
18
|
-
cache: Cache<N, T, QP, QR, MP, MR>;
|
|
19
|
-
/** Reducer of the cache, should be added to redux store. */
|
|
20
|
-
reducer: (state: import("./types").CacheState<T, QP, QR, MP, MR> | undefined, action: {
|
|
21
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
22
|
-
queryKey: keyof QP & keyof QR;
|
|
23
|
-
queryCacheKey: Key;
|
|
24
|
-
state: Partial<import("./types").QueryState<T, QP[keyof QP & keyof QR], QR[keyof QP & keyof QR]>> | undefined;
|
|
25
|
-
entityChanges: import("./types").EntityChanges<T> | undefined;
|
|
26
|
-
} | {
|
|
27
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
28
|
-
mutationKey: keyof MP & keyof MR;
|
|
29
|
-
state: Partial<import("./types").MutationState<T, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>> | undefined;
|
|
30
|
-
entityChanges: import("./types").EntityChanges<T> | undefined;
|
|
31
|
-
} | {
|
|
32
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
33
|
-
changes: import("./types").EntityChanges<T>;
|
|
34
|
-
} | {
|
|
35
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
36
|
-
queries: {
|
|
37
|
-
query: keyof QP & keyof QR;
|
|
38
|
-
cacheKey?: Key;
|
|
39
|
-
expiresAt?: number;
|
|
40
|
-
}[];
|
|
41
|
-
} | {
|
|
42
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
43
|
-
queries: {
|
|
44
|
-
query: keyof QP & keyof QR;
|
|
45
|
-
cacheKey?: Key;
|
|
46
|
-
}[];
|
|
47
|
-
} | {
|
|
48
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
49
|
-
mutationKeys: (keyof MP & keyof MR)[];
|
|
50
|
-
} | {
|
|
51
|
-
type: `@rrc/${N}/clearCache`;
|
|
52
|
-
stateToKeep: Partial<import("./types").CacheState<T, QP, QR, MP, MR>> | undefined;
|
|
53
|
-
}) => import("./types").CacheState<T, QP, QR, MP, MR>;
|
|
54
|
-
actions: {
|
|
55
|
-
/** Updates query state, and optionally merges entity changes in a single action. */
|
|
56
|
-
updateQueryStateAndEntities: {
|
|
57
|
-
<K extends keyof QP & keyof QR>(queryKey: K, queryCacheKey: Key, state?: Partial<import("./types").QueryState<T, QP[K], QR[K]>> | undefined, entityChanges?: import("./types").EntityChanges<T> | undefined): {
|
|
58
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
59
|
-
queryKey: K;
|
|
60
|
-
queryCacheKey: Key;
|
|
61
|
-
state: Partial<import("./types").QueryState<T, QP[K], QR[K]>> | undefined;
|
|
62
|
-
entityChanges: import("./types").EntityChanges<T> | undefined;
|
|
63
|
-
};
|
|
64
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
65
|
-
};
|
|
66
|
-
/** Updates mutation state, and optionally merges entity changes in a single action. */
|
|
67
|
-
updateMutationStateAndEntities: {
|
|
68
|
-
<K extends keyof MP & keyof MR>(mutationKey: K, state?: Partial<import("./types").MutationState<T, MP[K], MR[K]>> | undefined, entityChanges?: import("./types").EntityChanges<T> | undefined): {
|
|
69
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
70
|
-
mutationKey: K;
|
|
71
|
-
state: Partial<import("./types").MutationState<T, MP[K], MR[K]>> | undefined;
|
|
72
|
-
entityChanges: import("./types").EntityChanges<T> | undefined;
|
|
73
|
-
};
|
|
74
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
75
|
-
};
|
|
76
|
-
/** Merges EntityChanges to the state. */
|
|
77
|
-
mergeEntityChanges: {
|
|
78
|
-
(changes: import("./types").EntityChanges<T>): {
|
|
79
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
80
|
-
changes: import("./types").EntityChanges<T>;
|
|
81
|
-
};
|
|
82
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
83
|
-
};
|
|
84
|
-
/** Invalidates query states. */
|
|
85
|
-
invalidateQuery: {
|
|
86
|
-
<K extends keyof QP & keyof QR>(queries: {
|
|
87
|
-
query: K;
|
|
88
|
-
cacheKey?: Key;
|
|
89
|
-
expiresAt?: number;
|
|
90
|
-
}[]): {
|
|
91
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
92
|
-
queries: {
|
|
93
|
-
query: K;
|
|
94
|
-
cacheKey?: Key;
|
|
95
|
-
expiresAt?: number;
|
|
96
|
-
}[];
|
|
97
|
-
};
|
|
98
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
99
|
-
};
|
|
100
|
-
/** Clears states for provided query keys and cache keys.
|
|
101
|
-
* If cache key for query key is not provided, the whole state for query key is cleared. */
|
|
102
|
-
clearQueryState: {
|
|
103
|
-
<K extends keyof QP & keyof QR>(queries: {
|
|
104
|
-
query: K;
|
|
105
|
-
cacheKey?: Key;
|
|
106
|
-
}[]): {
|
|
107
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
108
|
-
queries: {
|
|
109
|
-
query: K;
|
|
110
|
-
cacheKey?: Key;
|
|
111
|
-
}[];
|
|
112
|
-
};
|
|
113
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
114
|
-
};
|
|
115
|
-
/** Clears states for provided mutation keys. */
|
|
116
|
-
clearMutationState: {
|
|
117
|
-
<K extends keyof MP & keyof MR>(mutationKeys: K[]): {
|
|
118
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
119
|
-
mutationKeys: K[];
|
|
120
|
-
};
|
|
121
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
122
|
-
};
|
|
123
|
-
/** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
|
|
124
|
-
clearCache: {
|
|
125
|
-
(stateToKeep?: Partial<import("./types").CacheState<T, QP, QR, MP, MR>> | undefined): {
|
|
126
|
-
type: `@rrc/${N}/clearCache`;
|
|
127
|
-
stateToKeep: Partial<import("./types").CacheState<T, QP, QR, MP, MR>> | undefined;
|
|
128
|
-
};
|
|
129
|
-
type: `@rrc/${N}/clearCache`;
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
|
-
selectors: {
|
|
133
|
-
/** This is a cacheStateSelector from createCache options, or default one if was not provided. */
|
|
134
|
-
selectCacheState: (state: any) => import("./types").CacheState<T, QP, QR, MP, MR>;
|
|
135
|
-
/** Selects query state. */
|
|
136
|
-
selectQueryState: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => import("./types").QueryState<T, QK extends keyof QP & keyof QR ? QP[QK] : never, QK extends keyof QP & keyof QR ? QR[QK] : never>;
|
|
137
|
-
/** Selects query latest result. */
|
|
138
|
-
selectQueryResult: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => (QK extends keyof QP & keyof QR ? QR[QK] : never) | undefined;
|
|
139
|
-
/** Selects query loading state. */
|
|
140
|
-
selectQueryLoading: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => false | Promise<import("./types").NormalizedQueryResponse<T, QK extends keyof QP & keyof QR ? QR[QK] : never>>;
|
|
141
|
-
/** Selects query latest error. */
|
|
142
|
-
selectQueryError: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => Error | undefined;
|
|
143
|
-
/** Selects query latest params. */
|
|
144
|
-
selectQueryParams: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => (QK extends keyof QP & keyof QR ? QP[QK] : never) | undefined;
|
|
145
|
-
/** Selects query latest expiresAt. */
|
|
146
|
-
selectQueryExpiresAt: <QK extends keyof QP | keyof QR>(state: unknown, query: QK, cacheKey: Key) => number | undefined;
|
|
147
|
-
/** Selects mutation state. */
|
|
148
|
-
selectMutationState: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => import("./types").MutationState<T, MK extends keyof MP & keyof MR ? MP[MK] : never, MK extends keyof MP & keyof MR ? MR[MK] : never>;
|
|
149
|
-
/** Selects mutation latest result. */
|
|
150
|
-
selectMutationResult: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => (MK extends keyof MP & keyof MR ? MR[MK] : never) | undefined;
|
|
151
|
-
/** Selects mutation loading state. */
|
|
152
|
-
selectMutationLoading: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => false | Promise<import("./types").NormalizedQueryResponse<T, MK extends keyof MP & keyof MR ? MR[MK] : never>>;
|
|
153
|
-
/** Selects mutation latest error. */
|
|
154
|
-
selectMutationError: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => Error | undefined;
|
|
155
|
-
/** Selects mutation latest params. */
|
|
156
|
-
selectMutationParams: <MK extends keyof MP | keyof MR>(state: unknown, mutation: MK) => (MK extends keyof MP & keyof MR ? MP[MK] : never) | undefined;
|
|
157
|
-
/** Selects entity by id and typename. */
|
|
158
|
-
selectEntityById: <TN extends keyof T>(state: unknown, id: Key | null | undefined, typename: TN) => T[TN] | undefined;
|
|
159
|
-
/** Selects all entities. */
|
|
160
|
-
selectEntities: (state: unknown) => import("./types").EntitiesMap<T>;
|
|
161
|
-
/** Selects all entities of provided typename. */
|
|
162
|
-
selectEntitiesByTypename: <TN extends keyof T>(state: unknown, typename: TN) => import("./types").EntitiesMap<T>[TN];
|
|
163
|
-
};
|
|
164
|
-
hooks: {
|
|
165
|
-
/** Returns client object with query and mutate functions. */
|
|
166
|
-
useClient: () => {
|
|
167
|
-
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>>;
|
|
168
|
-
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>>;
|
|
169
|
-
};
|
|
170
|
-
/** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
|
|
171
|
-
useQuery: <QK extends keyof (QP & QR)>(options: Parameters<typeof useQuery<N, T, QP, QR, MP, MR, QK>>[3]) => readonly [Omit<import("./types").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>>];
|
|
172
|
-
/** Subscribes to provided mutation state and provides mutate function. */
|
|
173
|
-
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>>, import("./types").MutationState<T, MK extends keyof MP & keyof MR ? MP[MK] : never, MK extends keyof MP & keyof MR ? MP[MK] : never>, () => boolean];
|
|
174
|
-
/** useSelector + selectEntityById. */
|
|
175
|
-
useSelectEntityById: <TN extends keyof T>(id: Key | null | undefined, typename: TN) => T[TN] | undefined;
|
|
176
|
-
};
|
|
177
|
-
utils: {
|
|
178
|
-
/** 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. */
|
|
179
|
-
createClient: (store: Store) => {
|
|
180
|
-
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>>;
|
|
181
|
-
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>>;
|
|
182
|
-
};
|
|
183
|
-
/** Generates the initial state by calling a reducer. Not needed for redux — it already generates it the same way when creating the store. */
|
|
184
|
-
getInitialState: () => import("./types").CacheState<T, QP, QR, MP, MR>;
|
|
185
|
-
/** Apply changes to the entities map.
|
|
186
|
-
* @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
|
|
187
|
-
applyEntityChanges: (entities: Parameters<typeof applyEntityChanges<T>>[0], changes: Parameters<typeof applyEntityChanges<T>>[1]) => import("./types").EntitiesMap<T> | undefined;
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Creates reducer, actions and hooks for managing queries and mutations through redux cache.
|
|
193
|
-
*/
|
|
194
|
-
export declare const createCache: <N extends string, QP, QR, MP, MR>(partialCache: Partial<{
|
|
195
|
-
queries: Partial<{ [QK in keyof (QP & QR)]: QK extends keyof QP & keyof QR ? import("./types").QueryInfo<N, Typenames, QP[QK], QR[QK], QP, QR, MP, MR> : never; }>;
|
|
196
|
-
mutations: Partial<{ [MK in keyof (MP & MR)]: MK extends keyof MP & keyof MR ? import("./types").MutationInfo<N, Typenames, MP[MK], MR[MK], QP, QR, MP, MR> : never; }>;
|
|
197
|
-
options: Partial<CacheOptions>;
|
|
198
|
-
storeHooks: Partial<{
|
|
199
|
-
useStore: () => Store;
|
|
200
|
-
useSelector: <R>(selector: (state: unknown) => R, comparer?: (x: R, y: R) => boolean) => R;
|
|
201
|
-
}>;
|
|
202
|
-
cacheStateSelector: Partial<(state: any) => import("./types").CacheState<Typenames, QP, QR, MP, MR>>;
|
|
203
|
-
}> & Omit<Omit<Cache<N, Typenames, QP, QR, MP, MR>, "globals">, "queries" | "mutations" | "options" | "storeHooks" | "cacheStateSelector"> & {
|
|
204
|
-
globals?: OptionalPartial<Globals<N, Typenames, QP, QR, MP, MR>, "queries"> | undefined;
|
|
205
|
-
}) => {
|
|
206
|
-
/** Keeps all options, passed while creating the cache. */
|
|
207
|
-
cache: Cache<N, Typenames, QP, QR, MP, MR>;
|
|
208
|
-
/** Reducer of the cache, should be added to redux store. */
|
|
209
|
-
reducer: (state: import("./types").CacheState<Typenames, QP, QR, MP, MR> | undefined, action: {
|
|
210
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
211
|
-
queryKey: keyof QP & keyof QR;
|
|
212
|
-
queryCacheKey: Key;
|
|
213
|
-
state: Partial<import("./types").QueryState<Typenames, QP[keyof QP & keyof QR], QR[keyof QP & keyof QR]>> | undefined;
|
|
214
|
-
entityChanges: import("./types").EntityChanges<Typenames> | undefined;
|
|
215
|
-
} | {
|
|
216
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
217
|
-
mutationKey: keyof MP & keyof MR;
|
|
218
|
-
state: Partial<import("./types").MutationState<Typenames, MP[keyof MP & keyof MR], MR[keyof MP & keyof MR]>> | undefined;
|
|
219
|
-
entityChanges: import("./types").EntityChanges<Typenames> | undefined;
|
|
220
|
-
} | {
|
|
221
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
222
|
-
changes: import("./types").EntityChanges<Typenames>;
|
|
223
|
-
} | {
|
|
224
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
225
|
-
queries: {
|
|
226
|
-
query: keyof QP & keyof QR;
|
|
227
|
-
cacheKey?: Key;
|
|
228
|
-
expiresAt?: number;
|
|
229
|
-
}[];
|
|
230
|
-
} | {
|
|
231
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
232
|
-
queries: {
|
|
233
|
-
query: keyof QP & keyof QR;
|
|
234
|
-
cacheKey?: Key;
|
|
235
|
-
}[];
|
|
236
|
-
} | {
|
|
237
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
238
|
-
mutationKeys: (keyof MP & keyof MR)[];
|
|
239
|
-
} | {
|
|
240
|
-
type: `@rrc/${N}/clearCache`;
|
|
241
|
-
stateToKeep: Partial<import("./types").CacheState<Typenames, QP, QR, MP, MR>> | undefined;
|
|
242
|
-
}) => import("./types").CacheState<Typenames, QP, QR, MP, MR>;
|
|
243
|
-
actions: {
|
|
244
|
-
/** Updates query state, and optionally merges entity changes in a single action. */
|
|
245
|
-
updateQueryStateAndEntities: {
|
|
246
|
-
<K extends keyof QP & keyof QR>(queryKey: K, queryCacheKey: Key, state?: Partial<import("./types").QueryState<Typenames, QP[K], QR[K]>> | undefined, entityChanges?: import("./types").EntityChanges<Typenames> | undefined): {
|
|
247
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
248
|
-
queryKey: K;
|
|
249
|
-
queryCacheKey: Key;
|
|
250
|
-
state: Partial<import("./types").QueryState<Typenames, QP[K], QR[K]>> | undefined;
|
|
251
|
-
entityChanges: import("./types").EntityChanges<Typenames> | undefined;
|
|
252
|
-
};
|
|
253
|
-
type: `@rrc/${N}/updateQueryStateAndEntities`;
|
|
254
|
-
};
|
|
255
|
-
/** Updates mutation state, and optionally merges entity changes in a single action. */
|
|
256
|
-
updateMutationStateAndEntities: {
|
|
257
|
-
<K extends keyof MP & keyof MR>(mutationKey: K, state?: Partial<import("./types").MutationState<Typenames, MP[K], MR[K]>> | undefined, entityChanges?: import("./types").EntityChanges<Typenames> | undefined): {
|
|
258
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
259
|
-
mutationKey: K;
|
|
260
|
-
state: Partial<import("./types").MutationState<Typenames, MP[K], MR[K]>> | undefined;
|
|
261
|
-
entityChanges: import("./types").EntityChanges<Typenames> | undefined;
|
|
262
|
-
};
|
|
263
|
-
type: `@rrc/${N}/updateMutationStateAndEntities`;
|
|
264
|
-
};
|
|
265
|
-
/** Merges EntityChanges to the state. */
|
|
266
|
-
mergeEntityChanges: {
|
|
267
|
-
(changes: import("./types").EntityChanges<Typenames>): {
|
|
268
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
269
|
-
changes: import("./types").EntityChanges<Typenames>;
|
|
270
|
-
};
|
|
271
|
-
type: `@rrc/${N}/mergeEntityChanges`;
|
|
272
|
-
};
|
|
273
|
-
/** Invalidates query states. */
|
|
274
|
-
invalidateQuery: {
|
|
275
|
-
<K extends keyof QP & keyof QR>(queries: {
|
|
276
|
-
query: K;
|
|
277
|
-
cacheKey?: Key;
|
|
278
|
-
expiresAt?: number;
|
|
279
|
-
}[]): {
|
|
280
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
281
|
-
queries: {
|
|
282
|
-
query: K;
|
|
283
|
-
cacheKey?: Key;
|
|
284
|
-
expiresAt?: number;
|
|
285
|
-
}[];
|
|
286
|
-
};
|
|
287
|
-
type: `@rrc/${N}/invalidateQuery`;
|
|
288
|
-
};
|
|
289
|
-
/** Clears states for provided query keys and cache keys.
|
|
290
|
-
* If cache key for query key is not provided, the whole state for query key is cleared. */
|
|
291
|
-
clearQueryState: {
|
|
292
|
-
<K extends keyof QP & keyof QR>(queries: {
|
|
293
|
-
query: K;
|
|
294
|
-
cacheKey?: Key;
|
|
295
|
-
}[]): {
|
|
296
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
297
|
-
queries: {
|
|
298
|
-
query: K;
|
|
299
|
-
cacheKey?: Key;
|
|
300
|
-
}[];
|
|
301
|
-
};
|
|
302
|
-
type: `@rrc/${N}/clearQueryState`;
|
|
303
|
-
};
|
|
304
|
-
/** Clears states for provided mutation keys. */
|
|
305
|
-
clearMutationState: {
|
|
306
|
-
<K extends keyof MP & keyof MR>(mutationKeys: K[]): {
|
|
307
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
308
|
-
mutationKeys: K[];
|
|
309
|
-
};
|
|
310
|
-
type: `@rrc/${N}/clearMutationState`;
|
|
311
|
-
};
|
|
312
|
-
/** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
|
|
313
|
-
clearCache: {
|
|
314
|
-
(stateToKeep?: Partial<import("./types").CacheState<Typenames, QP, QR, MP, MR>> | undefined): {
|
|
315
|
-
type: `@rrc/${N}/clearCache`;
|
|
316
|
-
stateToKeep: Partial<import("./types").CacheState<Typenames, QP, QR, MP, MR>> | undefined;
|
|
317
|
-
};
|
|
318
|
-
type: `@rrc/${N}/clearCache`;
|
|
319
|
-
};
|
|
320
|
-
};
|
|
321
|
-
selectors: {
|
|
322
|
-
/** This is a cacheStateSelector from createCache options, or default one if was not provided. */
|
|
323
|
-
selectCacheState: (state: any) => import("./types").CacheState<Typenames, QP, QR, MP, MR>;
|
|
324
|
-
/** Selects query state. */
|
|
325
|
-
selectQueryState: <QK_1 extends keyof QP | keyof QR>(state: unknown, query: QK_1, cacheKey: Key) => import("./types").QueryState<Typenames, QK_1 extends keyof QP & keyof QR ? QP[QK_1] : never, QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>;
|
|
326
|
-
/** Selects query latest result. */
|
|
327
|
-
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;
|
|
328
|
-
/** Selects query loading state. */
|
|
329
|
-
selectQueryLoading: <QK_1 extends keyof QP | keyof QR>(state: unknown, query: QK_1, cacheKey: Key) => false | Promise<import("./types").NormalizedQueryResponse<Typenames, QK_1 extends keyof QP & keyof QR ? QR[QK_1] : never>>;
|
|
330
|
-
/** Selects query latest error. */
|
|
331
|
-
selectQueryError: <QK_1 extends keyof QP | keyof QR>(state: unknown, query: QK_1, cacheKey: Key) => Error | undefined;
|
|
332
|
-
/** Selects query latest params. */
|
|
333
|
-
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;
|
|
334
|
-
/** Selects query latest expiresAt. */
|
|
335
|
-
selectQueryExpiresAt: <QK_1 extends keyof QP | keyof QR>(state: unknown, query: QK_1, cacheKey: Key) => number | undefined;
|
|
336
|
-
/** Selects mutation state. */
|
|
337
|
-
selectMutationState: <MK_1 extends keyof MP | keyof MR>(state: unknown, mutation: MK_1) => import("./types").MutationState<Typenames, MK_1 extends keyof MP & keyof MR ? MP[MK_1] : never, MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>;
|
|
338
|
-
/** Selects mutation latest result. */
|
|
339
|
-
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;
|
|
340
|
-
/** Selects mutation loading state. */
|
|
341
|
-
selectMutationLoading: <MK_1 extends keyof MP | keyof MR>(state: unknown, mutation: MK_1) => false | Promise<import("./types").NormalizedQueryResponse<Typenames, MK_1 extends keyof MP & keyof MR ? MR[MK_1] : never>>;
|
|
342
|
-
/** Selects mutation latest error. */
|
|
343
|
-
selectMutationError: <MK_1 extends keyof MP | keyof MR>(state: unknown, mutation: MK_1) => Error | undefined;
|
|
344
|
-
/** Selects mutation latest params. */
|
|
345
|
-
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;
|
|
346
|
-
/** Selects entity by id and typename. */
|
|
347
|
-
selectEntityById: <TN extends string>(state: unknown, id: Key | null | undefined, typename: TN) => object | undefined;
|
|
348
|
-
/** Selects all entities. */
|
|
349
|
-
selectEntities: (state: unknown) => import("./types").EntitiesMap<Typenames>;
|
|
350
|
-
/** Selects all entities of provided typename. */
|
|
351
|
-
selectEntitiesByTypename: <TN extends string>(state: unknown, typename: TN) => import("./types").Dict<object> | undefined;
|
|
352
|
-
};
|
|
353
|
-
hooks: {
|
|
354
|
-
/** Returns client object with query and mutate functions. */
|
|
355
|
-
useClient: () => {
|
|
356
|
-
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>>;
|
|
357
|
-
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>>;
|
|
358
|
-
};
|
|
359
|
-
/** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
|
|
360
|
-
useQuery: <QK_1 extends keyof QP | keyof QR>(options: import("./types").UseQueryOptions<N, Typenames, QK_1, QP, QR, MP, MR>) => readonly [Omit<import("./types").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>>];
|
|
361
|
-
/** Subscribes to provided mutation state and provides mutate function. */
|
|
362
|
-
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>>, import("./types").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];
|
|
363
|
-
/** useSelector + selectEntityById. */
|
|
364
|
-
useSelectEntityById: <TN extends string>(id: Key | null | undefined, typename: TN) => object | undefined;
|
|
365
|
-
};
|
|
366
|
-
utils: {
|
|
367
|
-
/** 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. */
|
|
368
|
-
createClient: (store: Store) => {
|
|
369
|
-
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>>;
|
|
370
|
-
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>>;
|
|
371
|
-
};
|
|
372
|
-
/** Generates the initial state by calling a reducer. Not needed for redux — it already generates it the same way when creating the store. */
|
|
373
|
-
getInitialState: () => import("./types").CacheState<Typenames, QP, QR, MP, MR>;
|
|
374
|
-
/** Apply changes to the entities map.
|
|
375
|
-
* @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
|
|
376
|
-
applyEntityChanges: (entities: import("./types").EntitiesMap<Typenames>, changes: import("./types").EntityChanges<Typenames>) => import("./types").EntitiesMap<Typenames> | undefined;
|
|
377
|
-
};
|
|
378
|
-
};
|
package/dist/createCache.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCache = exports.withTypenames = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const createActions_1 = require("./createActions");
|
|
6
|
-
const createCacheReducer_1 = require("./createCacheReducer");
|
|
7
|
-
const createSelectors_1 = require("./createSelectors");
|
|
8
|
-
const mutate_1 = require("./mutate");
|
|
9
|
-
const query_1 = require("./query");
|
|
10
|
-
const useMutation_1 = require("./useMutation");
|
|
11
|
-
const useQuery_1 = require("./useQuery");
|
|
12
|
-
const utilsAndConstants_1 = require("./utilsAndConstants");
|
|
13
|
-
/**
|
|
14
|
-
* Function to provide generic Typenames if normalization is needed - this is a Typescript limitation.
|
|
15
|
-
* Returns object with createCache function with provided typenames.
|
|
16
|
-
* @example
|
|
17
|
-
* const cache = withTypenames<MyTypenames>().createCache({
|
|
18
|
-
* ...
|
|
19
|
-
* })
|
|
20
|
-
*/
|
|
21
|
-
const withTypenames = () => {
|
|
22
|
-
/**
|
|
23
|
-
* Creates reducer, actions and hooks for managing queries and mutations through redux cache.
|
|
24
|
-
*/
|
|
25
|
-
return {
|
|
26
|
-
createCache: (partialCache) => {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
28
|
-
var _o, _p, _q, _r, _s, _t;
|
|
29
|
-
const abortControllers = new WeakMap();
|
|
30
|
-
// Provide all optional fields
|
|
31
|
-
(_a = partialCache.options) !== null && _a !== void 0 ? _a : (partialCache.options = {});
|
|
32
|
-
(_b = (_o = partialCache.options).logsEnabled) !== null && _b !== void 0 ? _b : (_o.logsEnabled = false);
|
|
33
|
-
(_c = (_p = partialCache.options).additionalValidation) !== null && _c !== void 0 ? _c : (_p.additionalValidation = utilsAndConstants_1.IS_DEV);
|
|
34
|
-
(_d = (_q = partialCache.options).deepComparisonEnabled) !== null && _d !== void 0 ? _d : (_q.deepComparisonEnabled = true);
|
|
35
|
-
(_e = partialCache.globals) !== null && _e !== void 0 ? _e : (partialCache.globals = {});
|
|
36
|
-
(_f = (_r = partialCache.globals).queries) !== null && _f !== void 0 ? _f : (_r.queries = {});
|
|
37
|
-
(_g = (_s = partialCache.globals.queries).fetchPolicy) !== null && _g !== void 0 ? _g : (_s.fetchPolicy = utilsAndConstants_1.FetchPolicy.NoCacheOrExpired);
|
|
38
|
-
(_h = (_t = partialCache.globals.queries).skipFetch) !== null && _h !== void 0 ? _h : (_t.skipFetch = false);
|
|
39
|
-
(_j = partialCache.cacheStateSelector) !== null && _j !== void 0 ? _j : (partialCache.cacheStateSelector = (state) => state[cache.name]);
|
|
40
|
-
(_k = partialCache.mutations) !== null && _k !== void 0 ? _k : (partialCache.mutations = {});
|
|
41
|
-
(_l = partialCache.queries) !== null && _l !== void 0 ? _l : (partialCache.queries = {});
|
|
42
|
-
// @ts-expect-error private field for testing
|
|
43
|
-
partialCache.abortControllers = abortControllers;
|
|
44
|
-
// Try/catch just for bunders like metro to consider this as optional dependency
|
|
45
|
-
// eslint-disable-next-line no-useless-catch
|
|
46
|
-
try {
|
|
47
|
-
(_m = partialCache.storeHooks) !== null && _m !== void 0 ? _m : (partialCache.storeHooks = {
|
|
48
|
-
useStore: require('react-redux').useStore,
|
|
49
|
-
useSelector: require('react-redux').useSelector,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
throw e;
|
|
54
|
-
}
|
|
55
|
-
const cache = partialCache;
|
|
56
|
-
// Validate options
|
|
57
|
-
if (cache.options.deepComparisonEnabled && !utilsAndConstants_1.optionalUtils.deepEqual) {
|
|
58
|
-
console.warn('react-redux-cache: optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true');
|
|
59
|
-
}
|
|
60
|
-
// State comparers
|
|
61
|
-
/** Transforms array of keys to comparer function. */
|
|
62
|
-
const setDefaultComparer = (target) => {
|
|
63
|
-
if ((target === null || target === void 0 ? void 0 : target.selectorComparer) != null && typeof target.selectorComparer === 'object') {
|
|
64
|
-
target.selectorComparer = (0, utilsAndConstants_1.createStateComparer)(target.selectorComparer);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
setDefaultComparer(cache.globals.queries);
|
|
68
|
-
for (const queryKey in partialCache.queries) {
|
|
69
|
-
// @ts-expect-error TODO fix types
|
|
70
|
-
setDefaultComparer(partialCache.queries[queryKey]);
|
|
71
|
-
}
|
|
72
|
-
// Selectors
|
|
73
|
-
const selectors = Object.assign({ selectCacheState: cache.cacheStateSelector }, (0, createSelectors_1.createSelectors)(cache));
|
|
74
|
-
const { selectCacheState, selectQueryState, selectQueryResult, selectQueryLoading, selectQueryError, selectQueryParams, selectQueryExpiresAt, selectMutationState, selectMutationResult, selectMutationLoading, selectMutationError, selectMutationParams, selectEntityById, selectEntities, selectEntitiesByTypename, } = selectors;
|
|
75
|
-
// Actions
|
|
76
|
-
const actions = (0, createActions_1.createActions)(cache.name);
|
|
77
|
-
const { updateQueryStateAndEntities, updateMutationStateAndEntities, mergeEntityChanges, invalidateQuery, clearQueryState, clearMutationState, clearCache, } = actions;
|
|
78
|
-
// Reducer
|
|
79
|
-
const reducer = (0, createCacheReducer_1.createCacheReducer)(actions, Object.keys(cache.queries), cache.options);
|
|
80
|
-
// Client creator
|
|
81
|
-
const createClient = (store) => {
|
|
82
|
-
const client = {
|
|
83
|
-
query: (options) => {
|
|
84
|
-
var _a;
|
|
85
|
-
const { query: queryKey, params } = options;
|
|
86
|
-
const getCacheKey = (_a = cache.queries[queryKey].getCacheKey) !== null && _a !== void 0 ? _a : (utilsAndConstants_1.defaultGetCacheKey);
|
|
87
|
-
// @ts-expect-error fix later
|
|
88
|
-
const cacheKey = getCacheKey(params);
|
|
89
|
-
return (0, query_1.query)('query', store, cache, actions, selectors, queryKey, cacheKey, params, options.secondsToLive, options.onlyIfExpired,
|
|
90
|
-
// @ts-expect-error fix later
|
|
91
|
-
options.mergeResults, options.onCompleted, options.onSuccess, options.onError);
|
|
92
|
-
},
|
|
93
|
-
mutate: (options) => {
|
|
94
|
-
return (0, mutate_1.mutate)('mutate', store, cache, actions, selectors, options.mutation, options.params, abortControllers,
|
|
95
|
-
// @ts-expect-error fix later
|
|
96
|
-
options.onCompleted, options.onSuccess, options.onError);
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
return client;
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
/** Keeps all options, passed while creating the cache. */
|
|
103
|
-
cache,
|
|
104
|
-
/** Reducer of the cache, should be added to redux store. */
|
|
105
|
-
reducer,
|
|
106
|
-
actions: {
|
|
107
|
-
/** Updates query state, and optionally merges entity changes in a single action. */
|
|
108
|
-
updateQueryStateAndEntities,
|
|
109
|
-
/** Updates mutation state, and optionally merges entity changes in a single action. */
|
|
110
|
-
updateMutationStateAndEntities,
|
|
111
|
-
/** Merges EntityChanges to the state. */
|
|
112
|
-
mergeEntityChanges,
|
|
113
|
-
/** Invalidates query states. */
|
|
114
|
-
invalidateQuery,
|
|
115
|
-
/** Clears states for provided query keys and cache keys.
|
|
116
|
-
* If cache key for query key is not provided, the whole state for query key is cleared. */
|
|
117
|
-
clearQueryState,
|
|
118
|
-
/** Clears states for provided mutation keys. */
|
|
119
|
-
clearMutationState,
|
|
120
|
-
/** Replaces cache state with initial, optionally merging with provided state. Doesn't cancel running fetches and shoult be used with caution. */
|
|
121
|
-
clearCache,
|
|
122
|
-
},
|
|
123
|
-
selectors: {
|
|
124
|
-
/** This is a cacheStateSelector from createCache options, or default one if was not provided. */
|
|
125
|
-
selectCacheState,
|
|
126
|
-
/** Selects query state. */
|
|
127
|
-
selectQueryState,
|
|
128
|
-
/** Selects query latest result. */
|
|
129
|
-
selectQueryResult,
|
|
130
|
-
/** Selects query loading state. */
|
|
131
|
-
selectQueryLoading,
|
|
132
|
-
/** Selects query latest error. */
|
|
133
|
-
selectQueryError,
|
|
134
|
-
/** Selects query latest params. */
|
|
135
|
-
selectQueryParams,
|
|
136
|
-
/** Selects query latest expiresAt. */
|
|
137
|
-
selectQueryExpiresAt,
|
|
138
|
-
/** Selects mutation state. */
|
|
139
|
-
selectMutationState,
|
|
140
|
-
/** Selects mutation latest result. */
|
|
141
|
-
selectMutationResult,
|
|
142
|
-
/** Selects mutation loading state. */
|
|
143
|
-
selectMutationLoading,
|
|
144
|
-
/** Selects mutation latest error. */
|
|
145
|
-
selectMutationError,
|
|
146
|
-
/** Selects mutation latest params. */
|
|
147
|
-
selectMutationParams,
|
|
148
|
-
/** Selects entity by id and typename. */
|
|
149
|
-
selectEntityById,
|
|
150
|
-
/** Selects all entities. */
|
|
151
|
-
selectEntities,
|
|
152
|
-
/** Selects all entities of provided typename. */
|
|
153
|
-
selectEntitiesByTypename,
|
|
154
|
-
},
|
|
155
|
-
hooks: {
|
|
156
|
-
/** Returns client object with query and mutate functions. */
|
|
157
|
-
useClient: () => {
|
|
158
|
-
const store = cache.storeHooks.useStore();
|
|
159
|
-
return (0, react_1.useMemo)(() => createClient(store), [store]);
|
|
160
|
-
},
|
|
161
|
-
/** Fetches query when params change and subscribes to query state changes (except `expiresAt` field). */
|
|
162
|
-
useQuery: (options) => (0, useQuery_1.useQuery)(cache, actions, selectors, options),
|
|
163
|
-
/** Subscribes to provided mutation state and provides mutate function. */
|
|
164
|
-
useMutation: (options) => (0, useMutation_1.useMutation)(cache, actions, selectors, options, abortControllers),
|
|
165
|
-
/** useSelector + selectEntityById. */
|
|
166
|
-
useSelectEntityById: (id, typename) => {
|
|
167
|
-
return cache.storeHooks.useSelector((state) => selectEntityById(state, id, typename));
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
utils: {
|
|
171
|
-
/** 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. */
|
|
172
|
-
createClient,
|
|
173
|
-
/** Generates the initial state by calling a reducer. Not needed for redux — it already generates it the same way when creating the store. */
|
|
174
|
-
getInitialState: () => {
|
|
175
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
176
|
-
return reducer(undefined, utilsAndConstants_1.EMPTY_OBJECT);
|
|
177
|
-
},
|
|
178
|
-
/** Apply changes to the entities map.
|
|
179
|
-
* @returns `undefined` if nothing to change, otherwise new `EntitiesMap<T>` with applied changes. */
|
|
180
|
-
applyEntityChanges: (entities, changes) => {
|
|
181
|
-
return (0, utilsAndConstants_1.applyEntityChanges)(entities, changes, cache.options);
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
};
|
|
188
|
-
exports.withTypenames = withTypenames;
|
|
189
|
-
/**
|
|
190
|
-
* Creates reducer, actions and hooks for managing queries and mutations through redux cache.
|
|
191
|
-
*/
|
|
192
|
-
exports.createCache = (0, exports.withTypenames)().createCache;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Actions } from './createActions';
|
|
2
|
-
import type { CacheOptions, CacheState, Typenames } from './types';
|
|
3
|
-
export declare const createCacheReducer: <N extends string, T extends Typenames, QP, QR, MP, MR>(actions: Actions<N, T, QP, QR, MP, MR>, queryKeys: (keyof (QP | QR))[], cacheOptions: CacheOptions) => (state: CacheState<T, QP, QR, MP, MR> | undefined, action: ReturnType<(typeof actions)[keyof typeof actions]>) => CacheState<T, QP, QR, MP, MR>;
|