@tanstack/query-core 4.24.10 → 5.0.0-alpha.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/build/lib/focusManager.d.ts +1 -3
- package/build/lib/focusManager.esm.js +19 -36
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +19 -38
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.mjs +19 -36
- package/build/lib/focusManager.mjs.map +1 -1
- package/build/lib/hydration.esm.js +21 -23
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +21 -25
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +21 -23
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +1 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +2 -8
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/infiniteQueryBehavior.d.ts +3 -7
- package/build/lib/infiniteQueryBehavior.esm.js +52 -75
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +50 -77
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.mjs +52 -75
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +4 -4
- package/build/lib/infiniteQueryObserver.esm.js +18 -26
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +18 -28
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs +18 -26
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +11 -22
- package/build/lib/mutation.esm.js +73 -105
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +73 -107
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +73 -105
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +4 -6
- package/build/lib/mutationCache.esm.js +23 -32
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +23 -34
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +23 -32
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.d.ts +4 -9
- package/build/lib/mutationObserver.esm.js +42 -73
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +42 -75
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +42 -73
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/notifyManager.esm.js +7 -17
- package/build/lib/notifyManager.esm.js.map +1 -1
- package/build/lib/notifyManager.js +7 -19
- package/build/lib/notifyManager.js.map +1 -1
- package/build/lib/notifyManager.mjs +7 -17
- package/build/lib/notifyManager.mjs.map +1 -1
- package/build/lib/onlineManager.d.ts +1 -3
- package/build/lib/onlineManager.esm.js +16 -30
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +16 -32
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.mjs +16 -30
- package/build/lib/onlineManager.mjs.map +1 -1
- package/build/lib/queriesObserver.d.ts +3 -10
- package/build/lib/queriesObserver.esm.js +47 -71
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +49 -75
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +47 -71
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.d.ts +14 -21
- package/build/lib/query.esm.js +140 -194
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +139 -195
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +140 -194
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +12 -7
- package/build/lib/queryCache.esm.js +21 -45
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js +20 -46
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs +21 -45
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +18 -46
- package/build/lib/queryClient.esm.js +137 -216
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +136 -217
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +137 -216
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +4 -29
- package/build/lib/queryObserver.esm.js +176 -258
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +176 -260
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +176 -258
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/removable.d.ts +3 -3
- package/build/lib/removable.esm.js +10 -14
- package/build/lib/removable.esm.js.map +1 -1
- package/build/lib/removable.js +10 -16
- package/build/lib/removable.js.map +1 -1
- package/build/lib/removable.mjs +10 -14
- package/build/lib/removable.mjs.map +1 -1
- package/build/lib/retryer.d.ts +5 -5
- package/build/lib/retryer.esm.js +27 -44
- package/build/lib/retryer.esm.js.map +1 -1
- package/build/lib/retryer.js +27 -46
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/retryer.mjs +27 -44
- package/build/lib/retryer.mjs.map +1 -1
- package/build/lib/subscribable.esm.js +4 -7
- package/build/lib/subscribable.esm.js.map +1 -1
- package/build/lib/subscribable.js +4 -9
- package/build/lib/subscribable.js.map +1 -1
- package/build/lib/subscribable.mjs +4 -7
- package/build/lib/subscribable.mjs.map +1 -1
- package/build/lib/tests/utils.d.ts +3 -12
- package/build/lib/types.d.ts +111 -99
- package/build/lib/utils.d.ts +8 -18
- package/build/lib/utils.esm.js +39 -132
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +42 -144
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +39 -132
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +867 -1399
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/focusManager.ts +17 -24
- package/src/index.ts +1 -11
- package/src/infiniteQueryBehavior.ts +54 -94
- package/src/infiniteQueryObserver.ts +10 -12
- package/src/mutation.ts +68 -92
- package/src/mutationCache.ts +27 -27
- package/src/mutationObserver.ts +58 -97
- package/src/onlineManager.ts +14 -14
- package/src/queriesObserver.ts +50 -54
- package/src/query.ts +107 -111
- package/src/queryCache.ts +42 -41
- package/src/queryClient.ts +155 -434
- package/src/queryObserver.ts +155 -192
- package/src/removable.ts +13 -13
- package/src/retryer.ts +5 -5
- package/src/subscribable.ts +1 -1
- package/src/tests/focusManager.test.tsx +25 -25
- package/src/tests/hydration.test.tsx +167 -81
- package/src/tests/infiniteQueryBehavior.test.tsx +209 -17
- package/src/tests/infiniteQueryObserver.test.tsx +6 -2
- package/src/tests/mutationCache.test.tsx +127 -127
- package/src/tests/mutationObserver.test.tsx +1 -31
- package/src/tests/mutations.test.tsx +62 -43
- package/src/tests/onlineManager.test.tsx +12 -4
- package/src/tests/queriesObserver.test.tsx +41 -77
- package/src/tests/query.test.tsx +175 -243
- package/src/tests/queryCache.test.tsx +170 -93
- package/src/tests/queryClient.test.tsx +229 -378
- package/src/tests/queryObserver.test.tsx +23 -147
- package/src/tests/utils.test.tsx +84 -29
- package/src/tests/utils.ts +9 -18
- package/src/types.ts +187 -140
- package/src/utils.ts +31 -124
- package/build/lib/logger.d.ts +0 -8
- package/build/lib/logger.esm.js +0 -4
- package/build/lib/logger.esm.js.map +0 -1
- package/build/lib/logger.js +0 -8
- package/build/lib/logger.js.map +0 -1
- package/build/lib/logger.mjs +0 -4
- package/build/lib/logger.mjs.map +0 -1
- package/build/lib/logger.native.d.ts +0 -6
- package/build/lib/logger.native.esm.js +0 -12
- package/build/lib/logger.native.esm.js.map +0 -1
- package/build/lib/logger.native.js +0 -16
- package/build/lib/logger.native.js.map +0 -1
- package/build/lib/logger.native.mjs +0 -12
- package/build/lib/logger.native.mjs.map +0 -1
- package/src/logger.native.ts +0 -11
- package/src/logger.ts +0 -9
package/build/lib/queryClient.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var utils = require('./utils.js');
|
|
6
4
|
var queryCache = require('./queryCache.js');
|
|
7
5
|
var mutationCache = require('./mutationCache.js');
|
|
@@ -9,78 +7,73 @@ var focusManager = require('./focusManager.js');
|
|
|
9
7
|
var onlineManager = require('./onlineManager.js');
|
|
10
8
|
var notifyManager = require('./notifyManager.js');
|
|
11
9
|
var infiniteQueryBehavior = require('./infiniteQueryBehavior.js');
|
|
12
|
-
var logger = require('./logger');
|
|
13
10
|
|
|
14
11
|
// CLASS
|
|
12
|
+
|
|
15
13
|
class QueryClient {
|
|
14
|
+
#queryCache;
|
|
15
|
+
#mutationCache;
|
|
16
|
+
#defaultOptions;
|
|
17
|
+
#queryDefaults;
|
|
18
|
+
#mutationDefaults;
|
|
19
|
+
#mountCount;
|
|
20
|
+
#unsubscribeFocus;
|
|
21
|
+
#unsubscribeOnline;
|
|
16
22
|
constructor(config = {}) {
|
|
17
|
-
this
|
|
18
|
-
this
|
|
19
|
-
this
|
|
20
|
-
this
|
|
21
|
-
this
|
|
22
|
-
this
|
|
23
|
-
this.mountCount = 0;
|
|
24
|
-
|
|
25
|
-
if (process.env.NODE_ENV !== 'production' && config.logger) {
|
|
26
|
-
this.logger.error("Passing a custom logger has been deprecated and will be removed in the next major version.");
|
|
27
|
-
}
|
|
23
|
+
this.#queryCache = config.queryCache || new queryCache.QueryCache();
|
|
24
|
+
this.#mutationCache = config.mutationCache || new mutationCache.MutationCache();
|
|
25
|
+
this.#defaultOptions = config.defaultOptions || {};
|
|
26
|
+
this.#queryDefaults = new Map();
|
|
27
|
+
this.#mutationDefaults = new Map();
|
|
28
|
+
this.#mountCount = 0;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
30
|
mount() {
|
|
31
|
-
this
|
|
32
|
-
if (this
|
|
33
|
-
this
|
|
31
|
+
this.#mountCount++;
|
|
32
|
+
if (this.#mountCount !== 1) return;
|
|
33
|
+
this.#unsubscribeFocus = focusManager.focusManager.subscribe(() => {
|
|
34
34
|
if (focusManager.focusManager.isFocused()) {
|
|
35
35
|
this.resumePausedMutations();
|
|
36
|
-
this
|
|
36
|
+
this.#queryCache.onFocus();
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
this
|
|
39
|
+
this.#unsubscribeOnline = onlineManager.onlineManager.subscribe(() => {
|
|
40
40
|
if (onlineManager.onlineManager.isOnline()) {
|
|
41
41
|
this.resumePausedMutations();
|
|
42
|
-
this
|
|
42
|
+
this.#queryCache.onOnline();
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
|
|
47
46
|
unmount() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
filters.fetchStatus = 'fetching';
|
|
61
|
-
return this.queryCache.findAll(filters).length;
|
|
47
|
+
this.#mountCount--;
|
|
48
|
+
if (this.#mountCount !== 0) return;
|
|
49
|
+
this.#unsubscribeFocus?.();
|
|
50
|
+
this.#unsubscribeFocus = undefined;
|
|
51
|
+
this.#unsubscribeOnline?.();
|
|
52
|
+
this.#unsubscribeOnline = undefined;
|
|
53
|
+
}
|
|
54
|
+
isFetching(filters) {
|
|
55
|
+
return this.#queryCache.findAll({
|
|
56
|
+
...filters,
|
|
57
|
+
fetchStatus: 'fetching'
|
|
58
|
+
}).length;
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
isMutating(filters) {
|
|
65
|
-
return this
|
|
66
|
-
|
|
61
|
+
return this.#mutationCache.findAll({
|
|
62
|
+
...filters,
|
|
63
|
+
status: 'pending'
|
|
67
64
|
}).length;
|
|
68
65
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return (_this$queryCache$find = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find.state.data;
|
|
66
|
+
getQueryData(queryKey) {
|
|
67
|
+
return this.#queryCache.find({
|
|
68
|
+
queryKey
|
|
69
|
+
})?.state.data;
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const cachedData = this.getQueryData(parsedOptions.queryKey);
|
|
79
|
-
return cachedData ? Promise.resolve(cachedData) : this.fetchQuery(parsedOptions);
|
|
71
|
+
ensureQueryData(options) {
|
|
72
|
+
const cachedData = this.getQueryData(options.queryKey);
|
|
73
|
+
return cachedData ? Promise.resolve(cachedData) : this.fetchQuery(options);
|
|
80
74
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return this.getQueryCache().findAll(queryKeyOrFilters).map(({
|
|
75
|
+
getQueriesData(filters) {
|
|
76
|
+
return this.getQueryCache().findAll(filters).map(({
|
|
84
77
|
queryKey,
|
|
85
78
|
state
|
|
86
79
|
}) => {
|
|
@@ -88,48 +81,43 @@ class QueryClient {
|
|
|
88
81
|
return [queryKey, data];
|
|
89
82
|
});
|
|
90
83
|
}
|
|
91
|
-
|
|
92
84
|
setQueryData(queryKey, updater, options) {
|
|
93
|
-
const query = this
|
|
94
|
-
|
|
85
|
+
const query = this.#queryCache.find({
|
|
86
|
+
queryKey
|
|
87
|
+
});
|
|
88
|
+
const prevData = query?.state.data;
|
|
95
89
|
const data = utils.functionalUpdate(updater, prevData);
|
|
96
|
-
|
|
97
90
|
if (typeof data === 'undefined') {
|
|
98
91
|
return undefined;
|
|
99
92
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return this
|
|
93
|
+
const defaultedOptions = this.defaultQueryOptions({
|
|
94
|
+
queryKey
|
|
95
|
+
});
|
|
96
|
+
return this.#queryCache.build(this, defaultedOptions).setData(data, {
|
|
97
|
+
...options,
|
|
104
98
|
manual: true
|
|
105
99
|
});
|
|
106
100
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return notifyManager.notifyManager.batch(() => this.getQueryCache().findAll(queryKeyOrFilters).map(({
|
|
101
|
+
setQueriesData(filters, updater, options) {
|
|
102
|
+
return notifyManager.notifyManager.batch(() => this.getQueryCache().findAll(filters).map(({
|
|
110
103
|
queryKey
|
|
111
104
|
}) => [queryKey, this.setQueryData(queryKey, updater, options)]));
|
|
112
105
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return (_this$queryCache$find2 = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find2.state;
|
|
106
|
+
getQueryState(queryKey) {
|
|
107
|
+
return this.#queryCache.find({
|
|
108
|
+
queryKey
|
|
109
|
+
})?.state;
|
|
118
110
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const [filters] = utils.parseFilterArgs(arg1, arg2);
|
|
122
|
-
const queryCache = this.queryCache;
|
|
111
|
+
removeQueries(filters) {
|
|
112
|
+
const queryCache = this.#queryCache;
|
|
123
113
|
notifyManager.notifyManager.batch(() => {
|
|
124
114
|
queryCache.findAll(filters).forEach(query => {
|
|
125
115
|
queryCache.remove(query);
|
|
126
116
|
});
|
|
127
117
|
});
|
|
128
118
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const [filters, options] = utils.parseFilterArgs(arg1, arg2, arg3);
|
|
132
|
-
const queryCache = this.queryCache;
|
|
119
|
+
resetQueries(filters, options) {
|
|
120
|
+
const queryCache = this.#queryCache;
|
|
133
121
|
const refetchFilters = {
|
|
134
122
|
type: 'active',
|
|
135
123
|
...filters
|
|
@@ -141,219 +129,150 @@ class QueryClient {
|
|
|
141
129
|
return this.refetchQueries(refetchFilters, options);
|
|
142
130
|
});
|
|
143
131
|
}
|
|
144
|
-
|
|
145
|
-
cancelQueries(arg1, arg2, arg3) {
|
|
146
|
-
const [filters, cancelOptions = {}] = utils.parseFilterArgs(arg1, arg2, arg3);
|
|
147
|
-
|
|
132
|
+
cancelQueries(filters = {}, cancelOptions = {}) {
|
|
148
133
|
if (typeof cancelOptions.revert === 'undefined') {
|
|
149
134
|
cancelOptions.revert = true;
|
|
150
135
|
}
|
|
151
|
-
|
|
152
|
-
const promises = notifyManager.notifyManager.batch(() => this.queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
|
|
136
|
+
const promises = notifyManager.notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
|
|
153
137
|
return Promise.all(promises).then(utils.noop).catch(utils.noop);
|
|
154
138
|
}
|
|
155
|
-
|
|
156
|
-
invalidateQueries(arg1, arg2, arg3) {
|
|
157
|
-
const [filters, options] = utils.parseFilterArgs(arg1, arg2, arg3);
|
|
139
|
+
invalidateQueries(filters = {}, options = {}) {
|
|
158
140
|
return notifyManager.notifyManager.batch(() => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.queryCache.findAll(filters).forEach(query => {
|
|
141
|
+
this.#queryCache.findAll(filters).forEach(query => {
|
|
162
142
|
query.invalidate();
|
|
163
143
|
});
|
|
164
|
-
|
|
165
144
|
if (filters.refetchType === 'none') {
|
|
166
145
|
return Promise.resolve();
|
|
167
146
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
type:
|
|
147
|
+
const refetchFilters = {
|
|
148
|
+
...filters,
|
|
149
|
+
type: filters.refetchType ?? filters.type ?? 'active'
|
|
171
150
|
};
|
|
172
151
|
return this.refetchQueries(refetchFilters, options);
|
|
173
152
|
});
|
|
174
153
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return query.fetch(undefined, { ...options,
|
|
182
|
-
cancelRefetch: (_options$cancelRefetc = options == null ? void 0 : options.cancelRefetch) != null ? _options$cancelRefetc : true,
|
|
183
|
-
meta: {
|
|
184
|
-
refetchPage: filters.refetchPage
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}));
|
|
154
|
+
refetchQueries(filters = {}, options) {
|
|
155
|
+
const promises = notifyManager.notifyManager.batch(() => this.#queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => query.fetch(undefined, {
|
|
156
|
+
...options,
|
|
157
|
+
cancelRefetch: options?.cancelRefetch ?? true
|
|
158
|
+
})));
|
|
188
159
|
let promise = Promise.all(promises).then(utils.noop);
|
|
189
|
-
|
|
190
|
-
if (!(options != null && options.throwOnError)) {
|
|
160
|
+
if (!options?.throwOnError) {
|
|
191
161
|
promise = promise.catch(utils.noop);
|
|
192
162
|
}
|
|
193
|
-
|
|
194
163
|
return promise;
|
|
195
164
|
}
|
|
165
|
+
fetchQuery(options) {
|
|
166
|
+
const defaultedOptions = this.defaultQueryOptions(options);
|
|
196
167
|
|
|
197
|
-
|
|
198
|
-
const parsedOptions = utils.parseQueryArgs(arg1, arg2, arg3);
|
|
199
|
-
const defaultedOptions = this.defaultQueryOptions(parsedOptions); // https://github.com/tannerlinsley/react-query/issues/652
|
|
200
|
-
|
|
168
|
+
// https://github.com/tannerlinsley/react-query/issues/652
|
|
201
169
|
if (typeof defaultedOptions.retry === 'undefined') {
|
|
202
170
|
defaultedOptions.retry = false;
|
|
203
171
|
}
|
|
204
|
-
|
|
205
|
-
const query = this.queryCache.build(this, defaultedOptions);
|
|
172
|
+
const query = this.#queryCache.build(this, defaultedOptions);
|
|
206
173
|
return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
|
|
207
174
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return this.fetchQuery(arg1, arg2, arg3).then(utils.noop).catch(utils.noop);
|
|
175
|
+
prefetchQuery(options) {
|
|
176
|
+
return this.fetchQuery(options).then(utils.noop).catch(utils.noop);
|
|
211
177
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
parsedOptions.behavior = infiniteQueryBehavior.infiniteQueryBehavior();
|
|
216
|
-
return this.fetchQuery(parsedOptions);
|
|
178
|
+
fetchInfiniteQuery(options) {
|
|
179
|
+
options.behavior = infiniteQueryBehavior.infiniteQueryBehavior();
|
|
180
|
+
return this.fetchQuery(options);
|
|
217
181
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return this.fetchInfiniteQuery(arg1, arg2, arg3).then(utils.noop).catch(utils.noop);
|
|
182
|
+
prefetchInfiniteQuery(options) {
|
|
183
|
+
return this.fetchInfiniteQuery(options).then(utils.noop).catch(utils.noop);
|
|
221
184
|
}
|
|
222
|
-
|
|
223
185
|
resumePausedMutations() {
|
|
224
|
-
return this
|
|
186
|
+
return this.#mutationCache.resumePausedMutations();
|
|
225
187
|
}
|
|
226
|
-
|
|
227
188
|
getQueryCache() {
|
|
228
|
-
return this
|
|
189
|
+
return this.#queryCache;
|
|
229
190
|
}
|
|
230
|
-
|
|
231
191
|
getMutationCache() {
|
|
232
|
-
return this
|
|
192
|
+
return this.#mutationCache;
|
|
233
193
|
}
|
|
234
|
-
|
|
235
|
-
getLogger() {
|
|
236
|
-
return this.logger;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
194
|
getDefaultOptions() {
|
|
240
|
-
return this
|
|
195
|
+
return this.#defaultOptions;
|
|
241
196
|
}
|
|
242
|
-
|
|
243
197
|
setDefaultOptions(options) {
|
|
244
|
-
this
|
|
198
|
+
this.#defaultOptions = options;
|
|
245
199
|
}
|
|
246
|
-
|
|
247
200
|
setQueryDefaults(queryKey, options) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
} else {
|
|
253
|
-
this.queryDefaults.push({
|
|
254
|
-
queryKey,
|
|
255
|
-
defaultOptions: options
|
|
256
|
-
});
|
|
257
|
-
}
|
|
201
|
+
this.#queryDefaults.set(utils.hashKey(queryKey), {
|
|
202
|
+
queryKey,
|
|
203
|
+
defaultOptions: options
|
|
204
|
+
});
|
|
258
205
|
}
|
|
259
|
-
|
|
260
206
|
getQueryDefaults(queryKey) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// Retrieve all matching defaults for the given key
|
|
270
|
-
const matchingDefaults = this.queryDefaults.filter(x => utils.partialMatchKey(queryKey, x.queryKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
|
|
271
|
-
|
|
272
|
-
if (matchingDefaults.length > 1) {
|
|
273
|
-
this.logger.error("[QueryClient] Several query defaults match with key '" + JSON.stringify(queryKey) + "'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.");
|
|
207
|
+
const defaults = [...this.#queryDefaults.values()];
|
|
208
|
+
let result = {};
|
|
209
|
+
defaults.forEach(queryDefault => {
|
|
210
|
+
if (utils.partialMatchKey(queryKey, queryDefault.queryKey)) {
|
|
211
|
+
result = {
|
|
212
|
+
...result,
|
|
213
|
+
...queryDefault.defaultOptions
|
|
214
|
+
};
|
|
274
215
|
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
|
|
216
|
+
});
|
|
217
|
+
return result;
|
|
278
218
|
}
|
|
279
|
-
|
|
280
219
|
setMutationDefaults(mutationKey, options) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
} else {
|
|
286
|
-
this.mutationDefaults.push({
|
|
287
|
-
mutationKey,
|
|
288
|
-
defaultOptions: options
|
|
289
|
-
});
|
|
290
|
-
}
|
|
220
|
+
this.#mutationDefaults.set(utils.hashKey(mutationKey), {
|
|
221
|
+
mutationKey,
|
|
222
|
+
defaultOptions: options
|
|
223
|
+
});
|
|
291
224
|
}
|
|
292
|
-
|
|
293
225
|
getMutationDefaults(mutationKey) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
// Retrieve all matching defaults for the given key
|
|
303
|
-
const matchingDefaults = this.mutationDefaults.filter(x => utils.partialMatchKey(mutationKey, x.mutationKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
|
|
304
|
-
|
|
305
|
-
if (matchingDefaults.length > 1) {
|
|
306
|
-
this.logger.error("[QueryClient] Several mutation defaults match with key '" + JSON.stringify(mutationKey) + "'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults.");
|
|
226
|
+
const defaults = [...this.#mutationDefaults.values()];
|
|
227
|
+
let result = {};
|
|
228
|
+
defaults.forEach(queryDefault => {
|
|
229
|
+
if (utils.partialMatchKey(mutationKey, queryDefault.mutationKey)) {
|
|
230
|
+
result = {
|
|
231
|
+
...result,
|
|
232
|
+
...queryDefault.defaultOptions
|
|
233
|
+
};
|
|
307
234
|
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
|
|
235
|
+
});
|
|
236
|
+
return result;
|
|
311
237
|
}
|
|
312
|
-
|
|
313
238
|
defaultQueryOptions(options) {
|
|
314
|
-
if (options
|
|
239
|
+
if (options?._defaulted) {
|
|
315
240
|
return options;
|
|
316
241
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
...this.getQueryDefaults(options
|
|
242
|
+
const defaultedOptions = {
|
|
243
|
+
...this.#defaultOptions.queries,
|
|
244
|
+
...(options?.queryKey && this.getQueryDefaults(options.queryKey)),
|
|
320
245
|
...options,
|
|
321
246
|
_defaulted: true
|
|
322
247
|
};
|
|
323
|
-
|
|
324
|
-
if (!defaultedOptions.queryHash && defaultedOptions.queryKey) {
|
|
248
|
+
if (!defaultedOptions.queryHash) {
|
|
325
249
|
defaultedOptions.queryHash = utils.hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
|
|
326
|
-
}
|
|
327
|
-
|
|
250
|
+
}
|
|
328
251
|
|
|
252
|
+
// dependent default values
|
|
329
253
|
if (typeof defaultedOptions.refetchOnReconnect === 'undefined') {
|
|
330
254
|
defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== 'always';
|
|
331
255
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
defaultedOptions.useErrorBoundary = !!defaultedOptions.suspense;
|
|
256
|
+
if (typeof defaultedOptions.throwErrors === 'undefined') {
|
|
257
|
+
defaultedOptions.throwErrors = !!defaultedOptions.suspense;
|
|
335
258
|
}
|
|
336
|
-
|
|
337
259
|
return defaultedOptions;
|
|
338
260
|
}
|
|
339
|
-
|
|
340
261
|
defaultMutationOptions(options) {
|
|
341
|
-
if (options
|
|
262
|
+
if (options?._defaulted) {
|
|
342
263
|
return options;
|
|
343
264
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
...this.getMutationDefaults(options
|
|
265
|
+
return {
|
|
266
|
+
...this.#defaultOptions.mutations,
|
|
267
|
+
...(options?.mutationKey && this.getMutationDefaults(options.mutationKey)),
|
|
347
268
|
...options,
|
|
348
269
|
_defaulted: true
|
|
349
270
|
};
|
|
350
271
|
}
|
|
351
|
-
|
|
352
272
|
clear() {
|
|
353
|
-
this
|
|
354
|
-
this
|
|
273
|
+
this.#queryCache.clear();
|
|
274
|
+
this.#mutationCache.clear();
|
|
355
275
|
}
|
|
356
|
-
|
|
357
276
|
}
|
|
358
277
|
|
|
359
278
|
exports.QueryClient = QueryClient;
|