react-redux-cache 0.21.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/README.md CHANGED
@@ -21,9 +21,9 @@ Can be considered as `ApolloClient` for protocols other than `GraphQL`, but with
21
21
  |Supports all kinds of queries / mutations|REST, GraphQL, databases - any async operations can be cached.|
22
22
  |Fully typed|Written on TypeScript, everything is checked by compiler.|
23
23
  |Not overengineered|Simplicity is the main goal.|
24
- |Performance|Every function is heavily optimized, Immer is not used ([RTK [Query] issue](https://github.com/reduxjs/redux-toolkit/issues/4793)).|
24
+ |Performance|Every function is heavily optimized. Immer is not used ([RTK performance issue](https://github.com/reduxjs/redux-toolkit/issues/4793)). Supports mutable collections (O(n) > O(1)).|
25
25
  |Reliability|High test coverage, zero issue policy.|
26
- |Lightweight|`npx minified-size dist/esm/*.js`<br/>minified: 18.2 kB<br/>gzipped: 7.91 kB<br/>brotlied: 7.03 kB
26
+ |Lightweight|`npx minified-size dist/esm/*.js`<br/>minified: 19.1 kB<br/>gzipped: 8.29 kB<br/>brotlied: 7.41 kB
27
27
 
28
28
  |Feature|Description|
29
29
  |--|--|
@@ -35,6 +35,7 @@ Can be considered as `ApolloClient` for protocols other than `GraphQL`, but with
35
35
  |Fetch policies|Decide if data is full enough or need to be fetched.|
36
36
  |Normalization|Consistent state accross the app - better UX, minimum loading states and lower traffic consumption.|
37
37
  |Minimal state|Default values such as `undefined` or default query states are removed from the state tree.|
38
+ |BETA: Mutable collections|Optimizes state merges from O(n) to O(1) by using mutable collections. Separate entities, query and mutation states are still immutable.|
38
39
 
39
40
  #### Examples of states, generated by cache reducer from `/example` project:
40
41
  <details>
@@ -140,6 +141,7 @@ Can be considered as `ApolloClient` for protocols other than `GraphQL`, but with
140
141
  - [api.ts](https://github.com/gentlee/react-redux-cache#apits)
141
142
  - [Usage](https://github.com/gentlee/react-redux-cache#usage)
142
143
  - [Advanced](https://github.com/gentlee/react-redux-cache#advanced)
144
+ - [Mutable collections](https://github.com/gentlee/react-redux-cache#mutable-collections)
143
145
  - [Error handling](https://github.com/gentlee/react-redux-cache#error-handling)
144
146
  - [Invalidation](https://github.com/gentlee/react-redux-cache#invalidation)
145
147
  - [Extended & custom fetch policy](https://github.com/gentlee/react-redux-cache#extended--custom-fetch-policy)
@@ -323,6 +325,38 @@ export const UserScreen = () => {
323
325
 
324
326
  ### Advanced
325
327
 
328
+ #### Mutable collections
329
+
330
+ For huge collections (> 1000 items, see benchmark) immutable approach may be a bottleneck - every merge of entity, query or mutation state is O(n). There is an option `mutableCollections` that makes it O(1) by using mutable approach when working with collections, while still keeping separate entities, query and mutation states immutable.
331
+
332
+ [Benchmark](https://github.com/gentlee/react-redux-cache/blob/main/benchmark.ts) results of adding item to collection depending on collection size, in microseconds (less is better):
333
+
334
+ | Collection size | 0 | 1000 | 10000 | 100000 | 1000000 |
335
+ |-|-|-|-|-|-|
336
+ | immutable | 1.78 | 1.69 | 5.64 | 117.4 | 1284.6 |
337
+ | mutable | 1.68 | 0.92 | 0.98 | 0.98 | 0.99 |
338
+
339
+ Well written code should not subcribe to whole collections, so just enabling this options most of the times should not break anything. But if it is still needed, you should subscribe to both collection (it may still change e.g. when clearing state) and to its `_changeKey`.
340
+
341
+ ```tsx
342
+ const Component = () => {
343
+ // It is usually a bad idea to subscribe to whole collections, consider using order of ids and subscribe to a single entity in each cell.
344
+ const allUsers = useSelector((state) => selectEntitiesByTypename(state, 'users'))
345
+ const allUsersChangeKey = useSelector((state) => selectEntitiesByTypename(state, 'users')._changeKey) // <-- Add this line while subscribing to collections
346
+
347
+ // For memoized components you should also pass it as extra prop to cause its re-render.
348
+ return <List data={allUsers} extra={allUsersChangeKey}/>
349
+ }
350
+
351
+ // Or just use existing hook.
352
+
353
+ const Component = () => {
354
+ const allUsers = useEntitiesByTypename('users')
355
+
356
+ return <List data={allUsers} extra={allUsers._changeKey}>
357
+ }
358
+ ```
359
+
326
360
  #### Error handling
327
361
 
328
362
  Queries and mutations are wrapped in try/catch, so any error will lead to cancelling of any updates to the state except loading state and the caught error. If you still want to make some state updates, or just want to use thrown errors only for unexpected cases, consider returning expected errors as a part of the result:
@@ -1,65 +1,64 @@
1
- 'use strict'
2
- Object.defineProperty(exports, '__esModule', {value: true})
3
- exports.createActions = void 0
4
- const utilsAndConstants_1 = require('./utilsAndConstants')
5
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createActions = void 0;
4
+ const utilsAndConstants_1 = require("./utilsAndConstants");
6
5
  const createActions = (name) => {
7
- const actionPrefix = `@${utilsAndConstants_1.PACKAGE_SHORT_NAME}/${name}/`
8
- const updateQueryStateAndEntitiesType = `${actionPrefix}updateQueryStateAndEntities`
9
- const updateQueryStateAndEntities = (queryKey, queryCacheKey, state, entityChanges) => ({
10
- type: updateQueryStateAndEntitiesType,
11
- queryKey,
12
- queryCacheKey,
13
- state,
14
- entityChanges,
15
- })
16
- updateQueryStateAndEntities.type = updateQueryStateAndEntitiesType
17
- const updateMutationStateAndEntitiesType = `${actionPrefix}updateMutationStateAndEntities`
18
- const updateMutationStateAndEntities = (mutationKey, state, entityChanges) => ({
19
- type: updateMutationStateAndEntitiesType,
20
- mutationKey,
21
- state,
22
- entityChanges,
23
- })
24
- updateMutationStateAndEntities.type = updateMutationStateAndEntitiesType
25
- const mergeEntityChangesType = `${actionPrefix}mergeEntityChanges`
26
- const mergeEntityChanges = (changes) => ({
27
- type: mergeEntityChangesType,
28
- changes,
29
- })
30
- mergeEntityChanges.type = mergeEntityChangesType
31
- const invalidateQueryType = `${actionPrefix}invalidateQuery`
32
- const invalidateQuery = (queries) => ({
33
- type: invalidateQueryType,
34
- queries,
35
- })
36
- invalidateQuery.type = invalidateQueryType
37
- const clearQueryStateType = `${actionPrefix}clearQueryState`
38
- const clearQueryState = (queries) => ({
39
- type: clearQueryStateType,
40
- queries,
41
- })
42
- clearQueryState.type = clearQueryStateType
43
- const clearMutationStateType = `${actionPrefix}clearMutationState`
44
- const clearMutationState = (mutationKeys) => ({
45
- type: clearMutationStateType,
46
- mutationKeys,
47
- })
48
- clearMutationState.type = clearMutationStateType
49
- const clearCacheType = `${actionPrefix}clearCache`
50
- const clearCache = (stateToKeep) => ({
51
- type: clearCacheType,
52
- stateToKeep,
53
- })
54
- clearCache.type = clearCacheType
55
- return {
56
- updateQueryStateAndEntities,
57
- updateMutationStateAndEntities,
58
- mergeEntityChanges,
59
- invalidateQuery,
60
- clearQueryState,
61
- clearMutationState,
62
- clearCache,
63
- }
64
- }
65
- exports.createActions = createActions
6
+ const actionPrefix = `@${utilsAndConstants_1.PACKAGE_SHORT_NAME}/${name}/`;
7
+ const updateQueryStateAndEntitiesType = `${actionPrefix}updateQueryStateAndEntities`;
8
+ const updateQueryStateAndEntities = (queryKey, queryCacheKey, state, entityChanges) => ({
9
+ type: updateQueryStateAndEntitiesType,
10
+ queryKey,
11
+ queryCacheKey,
12
+ state,
13
+ entityChanges,
14
+ });
15
+ updateQueryStateAndEntities.type = updateQueryStateAndEntitiesType;
16
+ const updateMutationStateAndEntitiesType = `${actionPrefix}updateMutationStateAndEntities`;
17
+ const updateMutationStateAndEntities = (mutationKey, state, entityChanges) => ({
18
+ type: updateMutationStateAndEntitiesType,
19
+ mutationKey,
20
+ state,
21
+ entityChanges,
22
+ });
23
+ updateMutationStateAndEntities.type = updateMutationStateAndEntitiesType;
24
+ const mergeEntityChangesType = `${actionPrefix}mergeEntityChanges`;
25
+ const mergeEntityChanges = (changes) => ({
26
+ type: mergeEntityChangesType,
27
+ changes,
28
+ });
29
+ mergeEntityChanges.type = mergeEntityChangesType;
30
+ const invalidateQueryType = `${actionPrefix}invalidateQuery`;
31
+ const invalidateQuery = (queries) => ({
32
+ type: invalidateQueryType,
33
+ queries,
34
+ });
35
+ invalidateQuery.type = invalidateQueryType;
36
+ const clearQueryStateType = `${actionPrefix}clearQueryState`;
37
+ const clearQueryState = (queries) => ({
38
+ type: clearQueryStateType,
39
+ queries,
40
+ });
41
+ clearQueryState.type = clearQueryStateType;
42
+ const clearMutationStateType = `${actionPrefix}clearMutationState`;
43
+ const clearMutationState = (mutationKeys) => ({
44
+ type: clearMutationStateType,
45
+ mutationKeys,
46
+ });
47
+ clearMutationState.type = clearMutationStateType;
48
+ const clearCacheType = `${actionPrefix}clearCache`;
49
+ const clearCache = (stateToKeep) => ({
50
+ type: clearCacheType,
51
+ stateToKeep,
52
+ });
53
+ clearCache.type = clearCacheType;
54
+ return {
55
+ updateQueryStateAndEntities,
56
+ updateMutationStateAndEntities,
57
+ mergeEntityChanges,
58
+ invalidateQuery,
59
+ clearQueryState,
60
+ clearMutationState,
61
+ clearCache,
62
+ };
63
+ };
64
+ exports.createActions = createActions;
@@ -1,206 +1,134 @@
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 createReducer_1 = require('./createReducer')
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
-
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 createReducer_1 = require("./createReducer");
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");
14
13
  const withTypenames = () => {
15
- return {
16
- createCache: (partialCache) => {
17
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m
18
- var _o, _p, _q, _r, _s, _t
19
- const abortControllers = new WeakMap()
20
- ;(_a = partialCache.options) !== null && _a !== void 0 ? _a : (partialCache.options = {})
21
- ;(_b = (_o = partialCache.options).logsEnabled) !== null && _b !== void 0
22
- ? _b
23
- : (_o.logsEnabled = false)
24
- ;(_c = (_p = partialCache.options).additionalValidation) !== null && _c !== void 0
25
- ? _c
26
- : (_p.additionalValidation = utilsAndConstants_1.IS_DEV)
27
- ;(_d = (_q = partialCache.options).deepComparisonEnabled) !== null && _d !== void 0
28
- ? _d
29
- : (_q.deepComparisonEnabled = true)
30
- ;(_e = partialCache.globals) !== null && _e !== void 0 ? _e : (partialCache.globals = {})
31
- ;(_f = (_r = partialCache.globals).queries) !== null && _f !== void 0 ? _f : (_r.queries = {})
32
- ;(_g = (_s = partialCache.globals.queries).fetchPolicy) !== null && _g !== void 0
33
- ? _g
34
- : (_s.fetchPolicy = utilsAndConstants_1.FetchPolicy.NoCacheOrExpired)
35
- ;(_h = (_t = partialCache.globals.queries).skipFetch) !== null && _h !== void 0
36
- ? _h
37
- : (_t.skipFetch = false)
38
- ;(_j = partialCache.cacheStateSelector) !== null && _j !== void 0
39
- ? _j
40
- : (partialCache.cacheStateSelector = (state) => state[cache.name])
41
- ;(_k = partialCache.mutations) !== null && _k !== void 0 ? _k : (partialCache.mutations = {})
42
- ;(_l = partialCache.queries) !== null && _l !== void 0 ? _l : (partialCache.queries = {})
43
- partialCache.abortControllers = abortControllers
44
- try {
45
- ;(_m = partialCache.storeHooks) !== null && _m !== void 0
46
- ? _m
47
- : (partialCache.storeHooks = {
48
- useStore: require('react-redux').useStore,
49
- useSelector: require('react-redux').useSelector,
50
- })
51
- } catch (e) {
52
- throw e
53
- }
54
- const cache = partialCache
55
- if (cache.options.deepComparisonEnabled && !utilsAndConstants_1.optionalUtils.deepEqual) {
56
- ;(0, utilsAndConstants_1.logWarn)(
57
- 'createCache',
58
- 'optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true'
59
- )
60
- }
61
- const setDefaultComparer = (target) => {
62
- if (
63
- (target === null || target === void 0 ? void 0 : target.selectorComparer) != null &&
64
- typeof target.selectorComparer === 'object'
65
- ) {
66
- target.selectorComparer = (0, utilsAndConstants_1.createStateComparer)(target.selectorComparer)
67
- }
68
- }
69
- setDefaultComparer(cache.globals.queries)
70
- for (const queryKey in partialCache.queries) {
71
- setDefaultComparer(partialCache.queries[queryKey])
72
- }
73
- const selectors = Object.assign(
74
- {selectCacheState: cache.cacheStateSelector},
75
- (0, createSelectors_1.createSelectors)(cache)
76
- )
77
- const {
78
- selectCacheState,
79
- selectQueryState,
80
- selectQueryResult,
81
- selectQueryLoading,
82
- selectQueryError,
83
- selectQueryParams,
84
- selectQueryExpiresAt,
85
- selectMutationState,
86
- selectMutationResult,
87
- selectMutationLoading,
88
- selectMutationError,
89
- selectMutationParams,
90
- selectEntityById,
91
- selectEntities,
92
- selectEntitiesByTypename,
93
- } = selectors
94
- const actions = (0, createActions_1.createActions)(cache.name)
95
- const {
96
- updateQueryStateAndEntities,
97
- updateMutationStateAndEntities,
98
- mergeEntityChanges,
99
- invalidateQuery,
100
- clearQueryState,
101
- clearMutationState,
102
- clearCache,
103
- } = actions
104
- const reducer = (0, createReducer_1.createReducer)(actions, Object.keys(cache.queries), cache.options)
105
- const createClient = (store) => {
106
- const client = {
107
- query: (options) => {
108
- var _a
109
- const {query: queryKey, params} = options
110
- const getCacheKey =
111
- (_a = cache.queries[queryKey].getCacheKey) !== null && _a !== void 0
112
- ? _a
113
- : utilsAndConstants_1.defaultGetCacheKey
114
- const cacheKey = getCacheKey(params)
115
- return (0, query_1.query)(
116
- 'query',
117
- store,
118
- cache,
119
- actions,
120
- selectors,
121
- queryKey,
122
- cacheKey,
123
- params,
124
- options.secondsToLive,
125
- options.onlyIfExpired,
126
- options.skipFetch,
127
- options.mergeResults,
128
- options.onCompleted,
129
- options.onSuccess,
130
- options.onError
131
- )
132
- },
133
- mutate: (options) => {
134
- return (0, mutate_1.mutate)(
135
- 'mutate',
136
- store,
137
- cache,
138
- actions,
139
- selectors,
140
- options.mutation,
141
- options.params,
142
- abortControllers,
143
- options.onCompleted,
144
- options.onSuccess,
145
- options.onError
146
- )
147
- },
148
- }
149
- return client
150
- }
151
- return {
152
- cache,
153
- reducer,
154
- actions: {
155
- updateQueryStateAndEntities,
156
- updateMutationStateAndEntities,
157
- mergeEntityChanges,
158
- invalidateQuery,
159
- clearQueryState,
160
- clearMutationState,
161
- clearCache,
14
+ return {
15
+ createCache: (partialCache) => {
16
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
17
+ var _p, _q, _r, _s, _t, _u, _v;
18
+ const abortControllers = new WeakMap();
19
+ (_a = partialCache.options) !== null && _a !== void 0 ? _a : (partialCache.options = {});
20
+ (_b = (_p = partialCache.options).mutableCollections) !== null && _b !== void 0 ? _b : (_p.mutableCollections = false);
21
+ (_c = (_q = partialCache.options).logsEnabled) !== null && _c !== void 0 ? _c : (_q.logsEnabled = false);
22
+ (_d = (_r = partialCache.options).additionalValidation) !== null && _d !== void 0 ? _d : (_r.additionalValidation = utilsAndConstants_1.IS_DEV);
23
+ (_e = (_s = partialCache.options).deepComparisonEnabled) !== null && _e !== void 0 ? _e : (_s.deepComparisonEnabled = true);
24
+ (_f = partialCache.globals) !== null && _f !== void 0 ? _f : (partialCache.globals = {});
25
+ (_g = (_t = partialCache.globals).queries) !== null && _g !== void 0 ? _g : (_t.queries = {});
26
+ (_h = (_u = partialCache.globals.queries).fetchPolicy) !== null && _h !== void 0 ? _h : (_u.fetchPolicy = utilsAndConstants_1.FetchPolicy.NoCacheOrExpired);
27
+ (_j = (_v = partialCache.globals.queries).skipFetch) !== null && _j !== void 0 ? _j : (_v.skipFetch = false);
28
+ (_k = partialCache.cacheStateSelector) !== null && _k !== void 0 ? _k : (partialCache.cacheStateSelector = (state) => state[cache.name]);
29
+ (_l = partialCache.mutations) !== null && _l !== void 0 ? _l : (partialCache.mutations = {});
30
+ (_m = partialCache.queries) !== null && _m !== void 0 ? _m : (partialCache.queries = {});
31
+ partialCache.abortControllers = abortControllers;
32
+ try {
33
+ (_o = partialCache.storeHooks) !== null && _o !== void 0 ? _o : (partialCache.storeHooks = {
34
+ useStore: require('react-redux').useStore,
35
+ useSelector: require('react-redux').useSelector,
36
+ });
37
+ }
38
+ catch (e) {
39
+ throw e;
40
+ }
41
+ const cache = partialCache;
42
+ if (cache.options.deepComparisonEnabled && !utilsAndConstants_1.optionalUtils.deepEqual) {
43
+ (0, utilsAndConstants_1.logWarn)('createCache', 'optional dependency for fast-deep-equal was not provided, while deepComparisonEnabled option is true');
44
+ }
45
+ const setDefaultComparer = (target) => {
46
+ if ((target === null || target === void 0 ? void 0 : target.selectorComparer) != null && typeof target.selectorComparer === 'object') {
47
+ target.selectorComparer = (0, utilsAndConstants_1.createStateComparer)(target.selectorComparer);
48
+ }
49
+ };
50
+ setDefaultComparer(cache.globals.queries);
51
+ for (const queryKey in partialCache.queries) {
52
+ setDefaultComparer(partialCache.queries[queryKey]);
53
+ }
54
+ const selectors = Object.assign({ selectCacheState: cache.cacheStateSelector }, (0, createSelectors_1.createSelectors)(cache));
55
+ const { selectCacheState, selectQueryState, selectQueryResult, selectQueryLoading, selectQueryError, selectQueryParams, selectQueryExpiresAt, selectMutationState, selectMutationResult, selectMutationLoading, selectMutationError, selectMutationParams, selectEntityById, selectEntities, selectEntitiesByTypename, } = selectors;
56
+ const actions = (0, createActions_1.createActions)(cache.name);
57
+ const { updateQueryStateAndEntities, updateMutationStateAndEntities, mergeEntityChanges, invalidateQuery, clearQueryState, clearMutationState, clearCache, } = actions;
58
+ const reducer = (0, createReducer_1.createReducer)(actions, Object.keys(cache.queries), cache.options);
59
+ const createClient = (store) => {
60
+ const client = {
61
+ query: (options) => {
62
+ var _a;
63
+ const { query: queryKey, params } = options;
64
+ const getCacheKey = (_a = cache.queries[queryKey].getCacheKey) !== null && _a !== void 0 ? _a : (utilsAndConstants_1.defaultGetCacheKey);
65
+ const cacheKey = getCacheKey(params);
66
+ return (0, query_1.query)('query', store, cache, actions, selectors, queryKey, cacheKey, params, options.secondsToLive, options.onlyIfExpired, options.skipFetch, options.mergeResults, options.onCompleted, options.onSuccess, options.onError);
67
+ },
68
+ mutate: (options) => {
69
+ return (0, mutate_1.mutate)('mutate', store, cache, actions, selectors, options.mutation, options.params, abortControllers, options.onCompleted, options.onSuccess, options.onError);
70
+ },
71
+ };
72
+ return client;
73
+ };
74
+ return {
75
+ cache,
76
+ reducer,
77
+ actions: {
78
+ updateQueryStateAndEntities,
79
+ updateMutationStateAndEntities,
80
+ mergeEntityChanges,
81
+ invalidateQuery,
82
+ clearQueryState,
83
+ clearMutationState,
84
+ clearCache,
85
+ },
86
+ selectors: {
87
+ selectCacheState,
88
+ selectQueryState,
89
+ selectQueryResult,
90
+ selectQueryLoading,
91
+ selectQueryError,
92
+ selectQueryParams,
93
+ selectQueryExpiresAt,
94
+ selectMutationState,
95
+ selectMutationResult,
96
+ selectMutationLoading,
97
+ selectMutationError,
98
+ selectMutationParams,
99
+ selectEntityById,
100
+ selectEntities,
101
+ selectEntitiesByTypename,
102
+ },
103
+ hooks: {
104
+ useClient: () => {
105
+ const store = cache.storeHooks.useStore();
106
+ return (0, react_1.useMemo)(() => createClient(store), [store]);
107
+ },
108
+ useQuery: (options) => (0, useQuery_1.useQuery)(cache, actions, selectors, options),
109
+ useMutation: (options) => (0, useMutation_1.useMutation)(cache, actions, selectors, options, abortControllers),
110
+ useSelectEntityById: (id, typename) => {
111
+ return cache.storeHooks.useSelector((state) => selectEntityById(state, id, typename));
112
+ },
113
+ useEntitiesByTypename: (typename) => {
114
+ if (cache.options.mutableCollections) {
115
+ cache.storeHooks.useSelector((state) => { var _a; return (_a = selectEntitiesByTypename(state, typename)) === null || _a === void 0 ? void 0 : _a._changeKey; });
116
+ }
117
+ return cache.storeHooks.useSelector((state) => selectEntitiesByTypename(state, typename));
118
+ },
119
+ },
120
+ utils: {
121
+ createClient,
122
+ getInitialState: () => {
123
+ return reducer(undefined, utilsAndConstants_1.EMPTY_OBJECT);
124
+ },
125
+ applyEntityChanges: (entities, changes) => {
126
+ return (0, utilsAndConstants_1.applyEntityChanges)(entities, changes, cache.options);
127
+ },
128
+ },
129
+ };
162
130
  },
163
- selectors: {
164
- selectCacheState,
165
- selectQueryState,
166
- selectQueryResult,
167
- selectQueryLoading,
168
- selectQueryError,
169
- selectQueryParams,
170
- selectQueryExpiresAt,
171
- selectMutationState,
172
- selectMutationResult,
173
- selectMutationLoading,
174
- selectMutationError,
175
- selectMutationParams,
176
- selectEntityById,
177
- selectEntities,
178
- selectEntitiesByTypename,
179
- },
180
- hooks: {
181
- useClient: () => {
182
- const store = cache.storeHooks.useStore()
183
- return (0, react_1.useMemo)(() => createClient(store), [store])
184
- },
185
- useQuery: (options) => (0, useQuery_1.useQuery)(cache, actions, selectors, options),
186
- useMutation: (options) =>
187
- (0, useMutation_1.useMutation)(cache, actions, selectors, options, abortControllers),
188
- useSelectEntityById: (id, typename) => {
189
- return cache.storeHooks.useSelector((state) => selectEntityById(state, id, typename))
190
- },
191
- },
192
- utils: {
193
- createClient,
194
- getInitialState: () => {
195
- return reducer(undefined, utilsAndConstants_1.EMPTY_OBJECT)
196
- },
197
- applyEntityChanges: (entities, changes) => {
198
- return (0, utilsAndConstants_1.applyEntityChanges)(entities, changes, cache.options)
199
- },
200
- },
201
- }
202
- },
203
- }
204
- }
205
- exports.withTypenames = withTypenames
206
- exports.createCache = (0, exports.withTypenames)().createCache
131
+ };
132
+ };
133
+ exports.withTypenames = withTypenames;
134
+ exports.createCache = (0, exports.withTypenames)().createCache;