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,358 +1,301 @@
|
|
|
1
|
-
|
|
2
|
-
var __rest =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]
|
|
11
|
-
}
|
|
12
|
-
return t
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(exports, '__esModule', {value: true})
|
|
15
|
-
exports.createReducer = void 0
|
|
16
|
-
const utilsAndConstants_1 = require('./utilsAndConstants')
|
|
17
|
-
const optionalQueryKeys = ['error', 'expiresAt', 'result', 'params', 'loading']
|
|
18
|
-
const optionalMutationKeys = ['error', 'result', 'params', 'loading']
|
|
19
|
-
const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
20
|
-
const mutable = cacheOptions.mutableCollections
|
|
21
|
-
cacheOptions.logsEnabled &&
|
|
22
|
-
(0, utilsAndConstants_1.logDebug)('createCacheReducer', {
|
|
23
|
-
queryKeys,
|
|
24
|
-
mutable,
|
|
25
|
-
})
|
|
26
|
-
const getMutableInitialState = mutable
|
|
27
|
-
? () => {
|
|
28
|
-
return {
|
|
29
|
-
entities: {},
|
|
30
|
-
queries: queryKeys.reduce((result, x) => {
|
|
31
|
-
result[x] = {}
|
|
32
|
-
return result
|
|
33
|
-
}, {}),
|
|
34
|
-
mutations: {},
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
: undefined
|
|
38
|
-
const immutableInitialState = mutable
|
|
39
|
-
? undefined
|
|
40
|
-
: Object.freeze({
|
|
41
|
-
entities: Object.freeze({}),
|
|
42
|
-
queries: Object.freeze(
|
|
43
|
-
queryKeys.reduce((result, x) => {
|
|
44
|
-
result[x] = Object.freeze({})
|
|
45
|
-
return result
|
|
46
|
-
}, {})
|
|
47
|
-
),
|
|
48
|
-
mutations: Object.freeze({}),
|
|
49
|
-
})
|
|
50
|
-
const {
|
|
51
|
-
clearCache,
|
|
52
|
-
clearMutationState,
|
|
53
|
-
clearQueryState,
|
|
54
|
-
invalidateQuery,
|
|
55
|
-
mergeEntityChanges,
|
|
56
|
-
updateMutationStateAndEntities,
|
|
57
|
-
updateQueryStateAndEntities,
|
|
58
|
-
} = actions
|
|
59
|
-
const deepEqual = cacheOptions.deepComparisonEnabled
|
|
60
|
-
? utilsAndConstants_1.optionalUtils.deepEqual
|
|
61
|
-
: undefined
|
|
62
|
-
return (state = mutable ? getMutableInitialState() : immutableInitialState, action) => {
|
|
63
|
-
switch (action.type) {
|
|
64
|
-
case updateQueryStateAndEntities.type: {
|
|
65
|
-
const {queryKey, queryCacheKey, state: queryState, entityChanges} = action
|
|
66
|
-
const oldQueryState = state.queries[queryKey][queryCacheKey]
|
|
67
|
-
let newQueryState = queryState && Object.assign(Object.assign({}, oldQueryState), queryState)
|
|
68
|
-
if (newQueryState) {
|
|
69
|
-
if (oldQueryState && deepEqual) {
|
|
70
|
-
if (
|
|
71
|
-
newQueryState.params !== oldQueryState.params &&
|
|
72
|
-
deepEqual(newQueryState.params, oldQueryState.params)
|
|
73
|
-
) {
|
|
74
|
-
newQueryState.params = oldQueryState.params
|
|
75
|
-
}
|
|
76
|
-
if (
|
|
77
|
-
newQueryState.result !== oldQueryState.result &&
|
|
78
|
-
deepEqual(newQueryState.result, oldQueryState.result)
|
|
79
|
-
) {
|
|
80
|
-
newQueryState.result = oldQueryState.result
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
for (const key of optionalQueryKeys) {
|
|
84
|
-
if (key in newQueryState && newQueryState[key] === undefined) {
|
|
85
|
-
delete newQueryState[key]
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (
|
|
89
|
-
deepEqual === null || deepEqual === void 0
|
|
90
|
-
? void 0
|
|
91
|
-
: deepEqual(
|
|
92
|
-
oldQueryState !== null && oldQueryState !== void 0
|
|
93
|
-
? oldQueryState
|
|
94
|
-
: utilsAndConstants_1.EMPTY_OBJECT,
|
|
95
|
-
newQueryState
|
|
96
|
-
)
|
|
97
|
-
) {
|
|
98
|
-
newQueryState = undefined
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const newEntities =
|
|
102
|
-
entityChanges &&
|
|
103
|
-
(0, utilsAndConstants_1.applyEntityChanges)(state.entities, entityChanges, cacheOptions)
|
|
104
|
-
let newState
|
|
105
|
-
if (newEntities) {
|
|
106
|
-
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state))
|
|
107
|
-
newState.entities = newEntities
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
108
10
|
}
|
|
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
|
-
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createReducer = void 0;
|
|
15
|
+
const utilsAndConstants_1 = require("./utilsAndConstants");
|
|
16
|
+
const optionalQueryKeys = [
|
|
17
|
+
'error',
|
|
18
|
+
'expiresAt',
|
|
19
|
+
'result',
|
|
20
|
+
'params',
|
|
21
|
+
'loading',
|
|
22
|
+
];
|
|
23
|
+
const optionalMutationKeys = [
|
|
24
|
+
'error',
|
|
25
|
+
'result',
|
|
26
|
+
'params',
|
|
27
|
+
'loading',
|
|
28
|
+
];
|
|
29
|
+
const createReducer = (actions, queryKeys, cacheOptions) => {
|
|
30
|
+
const mutable = cacheOptions.mutableCollections;
|
|
31
|
+
cacheOptions.logsEnabled &&
|
|
32
|
+
(0, utilsAndConstants_1.logDebug)('createReducer', {
|
|
33
|
+
queryKeys,
|
|
34
|
+
mutable,
|
|
35
|
+
});
|
|
36
|
+
const getMutableInitialState = mutable
|
|
37
|
+
? () => {
|
|
38
|
+
return {
|
|
39
|
+
entities: {},
|
|
40
|
+
queries: queryKeys.reduce((result, x) => {
|
|
41
|
+
result[x] = {};
|
|
42
|
+
return result;
|
|
43
|
+
}, {}),
|
|
44
|
+
mutations: {},
|
|
45
|
+
};
|
|
138
46
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
47
|
+
: undefined;
|
|
48
|
+
const immutableInitialState = mutable
|
|
49
|
+
? undefined
|
|
50
|
+
: Object.freeze({
|
|
51
|
+
entities: Object.freeze({}),
|
|
52
|
+
queries: Object.freeze(queryKeys.reduce((result, x) => {
|
|
53
|
+
result[x] = Object.freeze({});
|
|
54
|
+
return result;
|
|
55
|
+
}, {})),
|
|
56
|
+
mutations: Object.freeze({}),
|
|
57
|
+
});
|
|
58
|
+
const { clearCache, clearMutationState, clearQueryState, invalidateQuery, mergeEntityChanges, updateMutationStateAndEntities, updateQueryStateAndEntities, } = actions;
|
|
59
|
+
const deepEqual = cacheOptions.deepComparisonEnabled ? utilsAndConstants_1.optionalUtils.deepEqual : undefined;
|
|
60
|
+
return (state = mutable ? getMutableInitialState() : immutableInitialState, action) => {
|
|
61
|
+
switch (action.type) {
|
|
62
|
+
case updateQueryStateAndEntities.type: {
|
|
63
|
+
const { queryKey, queryCacheKey, state: queryState, entityChanges, } = action;
|
|
64
|
+
const oldQueryState = state.queries[queryKey][queryCacheKey];
|
|
65
|
+
let newQueryState = queryState && Object.assign(Object.assign({}, oldQueryState), queryState);
|
|
66
|
+
if (newQueryState) {
|
|
67
|
+
if (oldQueryState && deepEqual) {
|
|
68
|
+
if (newQueryState.params !== oldQueryState.params &&
|
|
69
|
+
deepEqual(newQueryState.params, oldQueryState.params)) {
|
|
70
|
+
newQueryState.params = oldQueryState.params;
|
|
71
|
+
}
|
|
72
|
+
if (newQueryState.result !== oldQueryState.result &&
|
|
73
|
+
deepEqual(newQueryState.result, oldQueryState.result)) {
|
|
74
|
+
newQueryState.result = oldQueryState.result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const key of optionalQueryKeys) {
|
|
78
|
+
if (key in newQueryState && newQueryState[key] === undefined) {
|
|
79
|
+
delete newQueryState[key];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldQueryState !== null && oldQueryState !== void 0 ? oldQueryState : utilsAndConstants_1.EMPTY_OBJECT, newQueryState)) {
|
|
83
|
+
newQueryState = undefined;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const newEntities = entityChanges && (0, utilsAndConstants_1.applyEntityChanges)(state.entities, entityChanges, cacheOptions);
|
|
87
|
+
let newState;
|
|
88
|
+
if (newEntities) {
|
|
89
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
90
|
+
newState.entities = newEntities;
|
|
91
|
+
}
|
|
92
|
+
if (newQueryState) {
|
|
93
|
+
if (!(0, utilsAndConstants_1.isEmptyObject)(newQueryState)) {
|
|
94
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
95
|
+
if (mutable) {
|
|
96
|
+
newState.queries[queryKey][queryCacheKey] = newQueryState;
|
|
97
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newState.queries);
|
|
98
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newState.queries[queryKey]);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
newState.queries = Object.assign(Object.assign({}, state.queries), { [queryKey]: Object.assign(Object.assign({}, state.queries[queryKey]), { [queryCacheKey]: newQueryState }) });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (oldQueryState !== undefined) {
|
|
105
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
106
|
+
if (mutable) {
|
|
107
|
+
delete newState.queries[queryKey][queryCacheKey];
|
|
108
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newState.queries);
|
|
109
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newState.queries[queryKey]);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const _a = state.queries[queryKey], _b = queryCacheKey, _ = _a[_b], withoutCacheKey = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
|
|
113
|
+
newState.queries = Object.assign(Object.assign({}, state.queries), { [queryKey]: withoutCacheKey });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return newState !== null && newState !== void 0 ? newState : state;
|
|
159
118
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
119
|
+
case updateMutationStateAndEntities.type: {
|
|
120
|
+
const { mutationKey, state: mutationState, entityChanges, } = action;
|
|
121
|
+
const oldMutationState = state.mutations[mutationKey];
|
|
122
|
+
let newMutationState = mutationState && Object.assign(Object.assign({}, oldMutationState), mutationState);
|
|
123
|
+
if (newMutationState) {
|
|
124
|
+
if (oldMutationState && deepEqual) {
|
|
125
|
+
if (newMutationState.params !== oldMutationState.params &&
|
|
126
|
+
deepEqual(newMutationState.params, oldMutationState.params)) {
|
|
127
|
+
newMutationState.params = oldMutationState.params;
|
|
128
|
+
}
|
|
129
|
+
if (newMutationState.result !== oldMutationState.result &&
|
|
130
|
+
deepEqual(newMutationState.result, oldMutationState.result)) {
|
|
131
|
+
newMutationState.result = oldMutationState.result;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const key of optionalMutationKeys) {
|
|
135
|
+
if (key in newMutationState && newMutationState[key] === undefined) {
|
|
136
|
+
delete newMutationState[key];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (deepEqual === null || deepEqual === void 0 ? void 0 : deepEqual(oldMutationState !== null && oldMutationState !== void 0 ? oldMutationState : utilsAndConstants_1.EMPTY_OBJECT, newMutationState)) {
|
|
140
|
+
newMutationState = undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const newEntities = entityChanges && (0, utilsAndConstants_1.applyEntityChanges)(state.entities, entityChanges, cacheOptions);
|
|
144
|
+
let newState;
|
|
145
|
+
if (newEntities) {
|
|
146
|
+
newState = Object.assign(Object.assign({}, state), { entities: newEntities });
|
|
147
|
+
}
|
|
148
|
+
if (newMutationState) {
|
|
149
|
+
if (!(0, utilsAndConstants_1.isEmptyObject)(newMutationState)) {
|
|
150
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
151
|
+
if (mutable) {
|
|
152
|
+
state.mutations[mutationKey] = newMutationState;
|
|
153
|
+
(0, utilsAndConstants_1.incrementChangeKey)(state.mutations);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
newState.mutations = Object.assign(Object.assign({}, state.mutations), { [mutationKey]: newMutationState });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (oldMutationState !== undefined) {
|
|
160
|
+
newState !== null && newState !== void 0 ? newState : (newState = Object.assign({}, state));
|
|
161
|
+
if (mutable) {
|
|
162
|
+
delete state.mutations[mutationKey];
|
|
163
|
+
(0, utilsAndConstants_1.incrementChangeKey)(state.mutations);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const _c = state.mutations, _d = mutationKey, _ = _c[_d], withoutMutationKey = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
|
|
167
|
+
newState.mutations = withoutMutationKey;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return newState !== null && newState !== void 0 ? newState : state;
|
|
207
172
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
case mergeEntityChanges.type: {
|
|
213
|
-
const {changes} = action
|
|
214
|
-
const newEntities = (0, utilsAndConstants_1.applyEntityChanges)(state.entities, changes, cacheOptions)
|
|
215
|
-
return newEntities ? Object.assign(Object.assign({}, state), {entities: newEntities}) : state
|
|
216
|
-
}
|
|
217
|
-
case invalidateQuery.type: {
|
|
218
|
-
const {queries: queriesToInvalidate} = action
|
|
219
|
-
if (queriesToInvalidate.length === 0) {
|
|
220
|
-
return state
|
|
221
|
-
}
|
|
222
|
-
const now = Date.now()
|
|
223
|
-
let newStatesByQueryKey
|
|
224
|
-
const copiedQueryKeys = mutable ? undefined : new Set()
|
|
225
|
-
for (const {query: queryKey, cacheKey, expiresAt = now} of queriesToInvalidate) {
|
|
226
|
-
const statesByCacheKey = (
|
|
227
|
-
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
228
|
-
? newStatesByQueryKey
|
|
229
|
-
: state.queries
|
|
230
|
-
)[queryKey]
|
|
231
|
-
const cacheKeysToInvalidate = cacheKey != null ? [cacheKey] : Object.keys(statesByCacheKey)
|
|
232
|
-
for (const cacheKey of cacheKeysToInvalidate) {
|
|
233
|
-
const queryState = statesByCacheKey[cacheKey]
|
|
234
|
-
if (!queryState || queryState.expiresAt === expiresAt) {
|
|
235
|
-
continue
|
|
173
|
+
case mergeEntityChanges.type: {
|
|
174
|
+
const { changes } = action;
|
|
175
|
+
const newEntities = (0, utilsAndConstants_1.applyEntityChanges)(state.entities, changes, cacheOptions);
|
|
176
|
+
return newEntities ? Object.assign(Object.assign({}, state), { entities: newEntities }) : state;
|
|
236
177
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
?
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
178
|
+
case invalidateQuery.type: {
|
|
179
|
+
const { queries: queriesToInvalidate } = action;
|
|
180
|
+
if (queriesToInvalidate.length === 0) {
|
|
181
|
+
return state;
|
|
182
|
+
}
|
|
183
|
+
const now = Date.now();
|
|
184
|
+
let newStatesByQueryKey;
|
|
185
|
+
const copiedQueryKeys = mutable ? undefined : new Set();
|
|
186
|
+
for (const { query: queryKey, cacheKey, expiresAt = now } of queriesToInvalidate) {
|
|
187
|
+
const statesByCacheKey = (newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : state.queries)[queryKey];
|
|
188
|
+
const cacheKeysToInvalidate = cacheKey != null ? [cacheKey] : Object.keys(statesByCacheKey);
|
|
189
|
+
for (const cacheKey of cacheKeysToInvalidate) {
|
|
190
|
+
const queryState = statesByCacheKey[cacheKey];
|
|
191
|
+
if (!queryState || queryState.expiresAt === expiresAt) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (mutable) {
|
|
195
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = state.queries);
|
|
196
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newStatesByQueryKey[queryKey]);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = Object.assign({}, state.queries));
|
|
200
|
+
if (!copiedQueryKeys.has(queryKey)) {
|
|
201
|
+
newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey]);
|
|
202
|
+
copiedQueryKeys.add(queryKey);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (expiresAt !== undefined) {
|
|
206
|
+
newStatesByQueryKey[queryKey][cacheKey] = Object.assign(Object.assign({}, queryState), { expiresAt });
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
const { expiresAt: _ } = queryState, newQueryState = __rest(queryState, ["expiresAt"]);
|
|
210
|
+
if ((0, utilsAndConstants_1.isEmptyObject)(newQueryState)) {
|
|
211
|
+
delete newStatesByQueryKey[queryKey][cacheKey];
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
newStatesByQueryKey[queryKey][cacheKey] = newQueryState;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!newStatesByQueryKey) {
|
|
220
|
+
return state;
|
|
221
|
+
}
|
|
222
|
+
if (mutable) {
|
|
223
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newStatesByQueryKey);
|
|
224
|
+
}
|
|
225
|
+
return Object.assign(Object.assign({}, state), { queries: newStatesByQueryKey });
|
|
250
226
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
227
|
+
case clearQueryState.type: {
|
|
228
|
+
const { queries: queriesToClear } = action;
|
|
229
|
+
if (queriesToClear.length === 0) {
|
|
230
|
+
return state;
|
|
231
|
+
}
|
|
232
|
+
let newStatesByQueryKey;
|
|
233
|
+
const copiedQueryKeys = mutable ? undefined : new Set();
|
|
234
|
+
for (const { query: queryKey, cacheKey } of queriesToClear) {
|
|
235
|
+
const statesByCacheKey = (newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : state.queries)[queryKey];
|
|
236
|
+
if (cacheKey != null) {
|
|
237
|
+
if (!statesByCacheKey[cacheKey]) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
if (mutable) {
|
|
241
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = state.queries);
|
|
242
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newStatesByQueryKey[queryKey]);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = Object.assign({}, state.queries));
|
|
246
|
+
if (!copiedQueryKeys.has(queryKey)) {
|
|
247
|
+
newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey]);
|
|
248
|
+
copiedQueryKeys.add(queryKey);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
delete newStatesByQueryKey[queryKey][cacheKey];
|
|
252
|
+
}
|
|
253
|
+
else if (mutable) {
|
|
254
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = state.queries);
|
|
255
|
+
newStatesByQueryKey[queryKey] = {};
|
|
256
|
+
}
|
|
257
|
+
else if (statesByCacheKey !== utilsAndConstants_1.EMPTY_OBJECT) {
|
|
258
|
+
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0 ? newStatesByQueryKey : (newStatesByQueryKey = Object.assign({}, state.queries));
|
|
259
|
+
newStatesByQueryKey[queryKey] = utilsAndConstants_1.EMPTY_OBJECT;
|
|
260
|
+
copiedQueryKeys.add(queryKey);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (newStatesByQueryKey === undefined) {
|
|
264
|
+
return state;
|
|
265
|
+
}
|
|
266
|
+
if (mutable) {
|
|
267
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newStatesByQueryKey);
|
|
268
|
+
}
|
|
269
|
+
return Object.assign(Object.assign({}, state), { queries: newStatesByQueryKey });
|
|
263
270
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
284
|
-
? newStatesByQueryKey
|
|
285
|
-
: state.queries
|
|
286
|
-
)[queryKey]
|
|
287
|
-
if (cacheKey != null) {
|
|
288
|
-
if (!statesByCacheKey[cacheKey]) {
|
|
289
|
-
continue
|
|
271
|
+
case clearMutationState.type: {
|
|
272
|
+
const { mutationKeys } = action;
|
|
273
|
+
if (mutationKeys.length === 0) {
|
|
274
|
+
return state;
|
|
275
|
+
}
|
|
276
|
+
let newMutations = undefined;
|
|
277
|
+
for (const mutation of mutationKeys) {
|
|
278
|
+
if (state.mutations[mutation]) {
|
|
279
|
+
newMutations !== null && newMutations !== void 0 ? newMutations : (newMutations = mutable ? state.mutations : Object.assign({}, state.mutations));
|
|
280
|
+
delete newMutations[mutation];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (newMutations === undefined) {
|
|
284
|
+
return state;
|
|
285
|
+
}
|
|
286
|
+
if (mutable) {
|
|
287
|
+
(0, utilsAndConstants_1.incrementChangeKey)(newMutations);
|
|
288
|
+
}
|
|
289
|
+
return Object.assign(Object.assign({}, state), { mutations: newMutations });
|
|
290
290
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
?
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
} else {
|
|
297
|
-
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
298
|
-
? newStatesByQueryKey
|
|
299
|
-
: (newStatesByQueryKey = Object.assign({}, state.queries))
|
|
300
|
-
if (!copiedQueryKeys.has(queryKey)) {
|
|
301
|
-
newStatesByQueryKey[queryKey] = Object.assign({}, newStatesByQueryKey[queryKey])
|
|
302
|
-
copiedQueryKeys.add(queryKey)
|
|
303
|
-
}
|
|
291
|
+
case clearCache.type: {
|
|
292
|
+
const { stateToKeep } = action;
|
|
293
|
+
const initialState = mutable ? getMutableInitialState() : immutableInitialState;
|
|
294
|
+
return stateToKeep
|
|
295
|
+
? Object.assign(Object.assign({}, initialState), stateToKeep) : initialState;
|
|
304
296
|
}
|
|
305
|
-
delete newStatesByQueryKey[queryKey][cacheKey]
|
|
306
|
-
} else if (mutable) {
|
|
307
|
-
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
308
|
-
? newStatesByQueryKey
|
|
309
|
-
: (newStatesByQueryKey = state.queries)
|
|
310
|
-
newStatesByQueryKey[queryKey] = {}
|
|
311
|
-
} else if (statesByCacheKey !== utilsAndConstants_1.EMPTY_OBJECT) {
|
|
312
|
-
newStatesByQueryKey !== null && newStatesByQueryKey !== void 0
|
|
313
|
-
? newStatesByQueryKey
|
|
314
|
-
: (newStatesByQueryKey = Object.assign({}, state.queries))
|
|
315
|
-
newStatesByQueryKey[queryKey] = utilsAndConstants_1.EMPTY_OBJECT
|
|
316
|
-
copiedQueryKeys.add(queryKey)
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
if (newStatesByQueryKey === undefined) {
|
|
320
|
-
return state
|
|
321
|
-
}
|
|
322
|
-
if (mutable) {
|
|
323
|
-
;(0, utilsAndConstants_1.incrementChangeKey)(newStatesByQueryKey)
|
|
324
|
-
}
|
|
325
|
-
return Object.assign(Object.assign({}, state), {queries: newStatesByQueryKey})
|
|
326
|
-
}
|
|
327
|
-
case clearMutationState.type: {
|
|
328
|
-
const {mutationKeys} = action
|
|
329
|
-
if (mutationKeys.length === 0) {
|
|
330
|
-
return state
|
|
331
|
-
}
|
|
332
|
-
let newMutations = undefined
|
|
333
|
-
for (const mutation of mutationKeys) {
|
|
334
|
-
if (state.mutations[mutation]) {
|
|
335
|
-
newMutations !== null && newMutations !== void 0
|
|
336
|
-
? newMutations
|
|
337
|
-
: (newMutations = mutable ? state.mutations : Object.assign({}, state.mutations))
|
|
338
|
-
delete newMutations[mutation]
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (newMutations === undefined) {
|
|
342
|
-
return state
|
|
343
|
-
}
|
|
344
|
-
if (mutable) {
|
|
345
|
-
;(0, utilsAndConstants_1.incrementChangeKey)(newMutations)
|
|
346
297
|
}
|
|
347
|
-
return
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const initialState = mutable ? getMutableInitialState() : immutableInitialState
|
|
352
|
-
return stateToKeep ? Object.assign(Object.assign({}, initialState), stateToKeep) : initialState
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return state
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
exports.createReducer = createReducer
|
|
298
|
+
return state;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
exports.createReducer = createReducer;
|