@tanstack/query-core 5.0.0-alpha.2 → 5.0.0-alpha.21
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/_virtual/_rollupPluginBabelHelpers.esm.js +13 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js +16 -0
- package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/lib/focusManager.esm.js +31 -15
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +31 -15
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/hydration.d.ts +2 -6
- package/build/lib/hydration.esm.js +9 -20
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +9 -20
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +4 -18
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +3 -3
- package/build/lib/infiniteQueryBehavior.d.ts +2 -2
- package/build/lib/infiniteQueryBehavior.esm.js +52 -48
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +52 -48
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.mjs +48 -45
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +6 -6
- package/build/lib/infiniteQueryObserver.esm.js +7 -8
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +7 -8
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs +4 -6
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +2 -1
- package/build/lib/mutation.esm.js +134 -101
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +134 -101
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +10 -2
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +2 -2
- package/build/lib/mutationCache.esm.js +34 -20
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +34 -20
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +5 -4
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.esm.js +81 -50
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +81 -50
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +1 -0
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/onlineManager.esm.js +29 -14
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +29 -14
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/queriesObserver.esm.js +95 -65
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +95 -65
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +4 -3
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.d.ts +4 -3
- package/build/lib/query.esm.js +210 -161
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +210 -161
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +1 -1
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +2 -2
- package/build/lib/queryCache.esm.js +21 -13
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js +21 -13
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs +5 -4
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.esm.js +107 -66
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +107 -66
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +5 -4
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +2 -4
- package/build/lib/queryObserver.esm.js +299 -211
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +297 -209
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +11 -23
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/removable.esm.js +13 -6
- package/build/lib/removable.esm.js.map +1 -1
- package/build/lib/removable.js +13 -6
- package/build/lib/removable.js.map +1 -1
- package/build/lib/retryer.esm.js +15 -14
- package/build/lib/retryer.esm.js.map +1 -1
- package/build/lib/retryer.js +15 -14
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/tests/utils.d.ts +4 -5
- package/build/lib/types.d.ts +5 -15
- package/build/lib/utils.esm.js +1 -1
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/umd/index.development.js +97 -109
- 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 +2 -2
- package/src/hydration.ts +18 -37
- package/src/index.ts +2 -4
- package/src/infiniteQueryBehavior.ts +52 -60
- package/src/infiniteQueryObserver.ts +15 -10
- package/src/mutation.ts +14 -5
- package/src/mutationCache.ts +6 -6
- package/src/mutationObserver.ts +1 -0
- package/src/queriesObserver.ts +8 -8
- package/src/query.ts +13 -8
- package/src/queryCache.ts +9 -8
- package/src/queryClient.ts +2 -4
- package/src/queryObserver.ts +17 -31
- package/src/tests/focusManager.test.tsx +12 -14
- package/src/tests/hydration.test.tsx +22 -17
- package/src/tests/infiniteQueryBehavior.test.tsx +16 -9
- package/src/tests/infiniteQueryObserver.test.tsx +62 -1
- package/src/tests/mutationCache.test.tsx +11 -10
- package/src/tests/mutationObserver.test.tsx +3 -2
- package/src/tests/mutations.test.tsx +41 -9
- package/src/tests/notifyManager.test.tsx +7 -6
- package/src/tests/onlineManager.test.tsx +12 -17
- package/src/tests/queriesObserver.test.tsx +18 -17
- package/src/tests/query.test.tsx +18 -17
- package/src/tests/queryCache.test.tsx +14 -13
- package/src/tests/queryClient.test.tsx +49 -48
- package/src/tests/queryObserver.test.tsx +65 -9
- package/src/tests/utils.test.tsx +2 -1
- package/src/tests/utils.ts +5 -4
- package/src/types.ts +9 -13
package/build/lib/query.js
CHANGED
|
@@ -1,73 +1,107 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
3
4
|
var utils = require('./utils.js');
|
|
4
5
|
var notifyManager = require('./notifyManager.js');
|
|
5
6
|
var retryer = require('./retryer.js');
|
|
6
7
|
var removable = require('./removable.js');
|
|
7
8
|
|
|
8
9
|
// TYPES
|
|
9
|
-
|
|
10
|
+
var _initialState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("initialState");
|
|
11
|
+
var _revertState = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("revertState");
|
|
12
|
+
var _cache = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("cache");
|
|
13
|
+
var _promise = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("promise");
|
|
14
|
+
var _retryer = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("retryer");
|
|
15
|
+
var _observers = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("observers");
|
|
16
|
+
var _defaultOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("defaultOptions");
|
|
17
|
+
var _abortSignalConsumed = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("abortSignalConsumed");
|
|
18
|
+
var _setOptions = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("setOptions");
|
|
19
|
+
var _dispatch = /*#__PURE__*/_rollupPluginBabelHelpers.classPrivateFieldLooseKey("dispatch");
|
|
10
20
|
// CLASS
|
|
11
21
|
|
|
12
22
|
class Query extends removable.Removable {
|
|
13
|
-
#initialState;
|
|
14
|
-
#revertState;
|
|
15
|
-
#cache;
|
|
16
|
-
#promise;
|
|
17
|
-
#retryer;
|
|
18
|
-
#observers;
|
|
19
|
-
#defaultOptions;
|
|
20
|
-
#abortSignalConsumed;
|
|
21
23
|
constructor(config) {
|
|
22
24
|
super();
|
|
23
|
-
this
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this
|
|
27
|
-
|
|
25
|
+
Object.defineProperty(this, _dispatch, {
|
|
26
|
+
value: _dispatch2
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, _setOptions, {
|
|
29
|
+
value: _setOptions2
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(this, _initialState, {
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, _revertState, {
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(this, _cache, {
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, _promise, {
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, _retryer, {
|
|
48
|
+
writable: true,
|
|
49
|
+
value: void 0
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(this, _observers, {
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, _defaultOptions, {
|
|
56
|
+
writable: true,
|
|
57
|
+
value: void 0
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(this, _abortSignalConsumed, {
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = false;
|
|
64
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions] = config.defaultOptions;
|
|
65
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](config.options);
|
|
66
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = [];
|
|
67
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache] = config.cache;
|
|
28
68
|
this.queryKey = config.queryKey;
|
|
29
69
|
this.queryHash = config.queryHash;
|
|
30
|
-
this
|
|
31
|
-
this.state = this
|
|
70
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _initialState)[_initialState] = config.state || getDefaultState(this.options);
|
|
71
|
+
this.state = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _initialState)[_initialState];
|
|
32
72
|
this.scheduleGc();
|
|
33
73
|
}
|
|
34
74
|
get meta() {
|
|
35
75
|
return this.options.meta;
|
|
36
76
|
}
|
|
37
|
-
#setOptions(options) {
|
|
38
|
-
this.options = {
|
|
39
|
-
...this.#defaultOptions,
|
|
40
|
-
...options
|
|
41
|
-
};
|
|
42
|
-
this.updateGcTime(this.options.gcTime);
|
|
43
|
-
}
|
|
44
77
|
optionalRemove() {
|
|
45
|
-
if (!this
|
|
46
|
-
this
|
|
78
|
+
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length && this.state.fetchStatus === 'idle') {
|
|
79
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].remove(this);
|
|
47
80
|
}
|
|
48
81
|
}
|
|
49
82
|
setData(newData, options) {
|
|
50
83
|
const data = utils.replaceData(this.state.data, newData, this.options);
|
|
51
84
|
|
|
52
85
|
// Set data and mark it as cached
|
|
53
|
-
this
|
|
86
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
54
87
|
data,
|
|
55
88
|
type: 'success',
|
|
56
|
-
dataUpdatedAt: options
|
|
57
|
-
manual: options
|
|
89
|
+
dataUpdatedAt: options == null ? void 0 : options.updatedAt,
|
|
90
|
+
manual: options == null ? void 0 : options.manual
|
|
58
91
|
});
|
|
59
92
|
return data;
|
|
60
93
|
}
|
|
61
94
|
setState(state, setStateOptions) {
|
|
62
|
-
this
|
|
95
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
63
96
|
type: 'setState',
|
|
64
97
|
state,
|
|
65
98
|
setStateOptions
|
|
66
99
|
});
|
|
67
100
|
}
|
|
68
101
|
cancel(options) {
|
|
69
|
-
|
|
70
|
-
this
|
|
102
|
+
var _classPrivateFieldLoo;
|
|
103
|
+
const promise = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise];
|
|
104
|
+
(_classPrivateFieldLoo = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo.cancel(options);
|
|
71
105
|
return promise ? promise.then(utils.noop).catch(utils.noop) : Promise.resolve();
|
|
72
106
|
}
|
|
73
107
|
destroy() {
|
|
@@ -78,45 +112,47 @@ class Query extends removable.Removable {
|
|
|
78
112
|
}
|
|
79
113
|
reset() {
|
|
80
114
|
this.destroy();
|
|
81
|
-
this.setState(this
|
|
115
|
+
this.setState(_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _initialState)[_initialState]);
|
|
82
116
|
}
|
|
83
117
|
isActive() {
|
|
84
|
-
return this
|
|
118
|
+
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].some(observer => observer.options.enabled !== false);
|
|
85
119
|
}
|
|
86
120
|
isDisabled() {
|
|
87
121
|
return this.getObserversCount() > 0 && !this.isActive();
|
|
88
122
|
}
|
|
89
123
|
isStale() {
|
|
90
|
-
return this.state.isInvalidated || !this.state.dataUpdatedAt || this
|
|
124
|
+
return this.state.isInvalidated || !this.state.dataUpdatedAt || _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].some(observer => observer.getCurrentResult().isStale);
|
|
91
125
|
}
|
|
92
126
|
isStaleByTime(staleTime = 0) {
|
|
93
127
|
return this.state.isInvalidated || !this.state.dataUpdatedAt || !utils.timeUntilStale(this.state.dataUpdatedAt, staleTime);
|
|
94
128
|
}
|
|
95
129
|
onFocus() {
|
|
96
|
-
|
|
97
|
-
observer
|
|
130
|
+
var _classPrivateFieldLoo2;
|
|
131
|
+
const observer = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(x => x.shouldFetchOnWindowFocus());
|
|
132
|
+
observer == null ? void 0 : observer.refetch({
|
|
98
133
|
cancelRefetch: false
|
|
99
134
|
});
|
|
100
135
|
|
|
101
136
|
// Continue fetch if currently paused
|
|
102
|
-
this
|
|
137
|
+
(_classPrivateFieldLoo2 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo2.continue();
|
|
103
138
|
}
|
|
104
139
|
onOnline() {
|
|
105
|
-
|
|
106
|
-
observer
|
|
140
|
+
var _classPrivateFieldLoo3;
|
|
141
|
+
const observer = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(x => x.shouldFetchOnReconnect());
|
|
142
|
+
observer == null ? void 0 : observer.refetch({
|
|
107
143
|
cancelRefetch: false
|
|
108
144
|
});
|
|
109
145
|
|
|
110
146
|
// Continue fetch if currently paused
|
|
111
|
-
this
|
|
147
|
+
(_classPrivateFieldLoo3 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo3.continue();
|
|
112
148
|
}
|
|
113
149
|
addObserver(observer) {
|
|
114
|
-
if (this
|
|
115
|
-
this
|
|
150
|
+
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].indexOf(observer) === -1) {
|
|
151
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].push(observer);
|
|
116
152
|
|
|
117
153
|
// Stop the query from being garbage collected
|
|
118
154
|
this.clearGcTimeout();
|
|
119
|
-
this
|
|
155
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
|
|
120
156
|
type: 'observerAdded',
|
|
121
157
|
query: this,
|
|
122
158
|
observer
|
|
@@ -124,23 +160,23 @@ class Query extends removable.Removable {
|
|
|
124
160
|
}
|
|
125
161
|
}
|
|
126
162
|
removeObserver(observer) {
|
|
127
|
-
if (this
|
|
128
|
-
this
|
|
129
|
-
if (!this
|
|
163
|
+
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].indexOf(observer) !== -1) {
|
|
164
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].filter(x => x !== observer);
|
|
165
|
+
if (!_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length) {
|
|
130
166
|
// If the transport layer does not support cancellation
|
|
131
167
|
// we'll let the query continue so the result can be cached
|
|
132
|
-
if (this
|
|
133
|
-
if (this
|
|
134
|
-
this
|
|
168
|
+
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) {
|
|
169
|
+
if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed]) {
|
|
170
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].cancel({
|
|
135
171
|
revert: true
|
|
136
172
|
});
|
|
137
173
|
} else {
|
|
138
|
-
this
|
|
174
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].cancelRetry();
|
|
139
175
|
}
|
|
140
176
|
}
|
|
141
177
|
this.scheduleGc();
|
|
142
178
|
}
|
|
143
|
-
this
|
|
179
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
|
|
144
180
|
type: 'observerRemoved',
|
|
145
181
|
query: this,
|
|
146
182
|
observer
|
|
@@ -148,41 +184,43 @@ class Query extends removable.Removable {
|
|
|
148
184
|
}
|
|
149
185
|
}
|
|
150
186
|
getObserversCount() {
|
|
151
|
-
return this
|
|
187
|
+
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].length;
|
|
152
188
|
}
|
|
153
189
|
invalidate() {
|
|
154
190
|
if (!this.state.isInvalidated) {
|
|
155
|
-
this
|
|
191
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
156
192
|
type: 'invalidate'
|
|
157
193
|
});
|
|
158
194
|
}
|
|
159
195
|
}
|
|
160
196
|
fetch(options, fetchOptions) {
|
|
197
|
+
var _this$options$behavio, _context$fetchOptions;
|
|
161
198
|
if (this.state.fetchStatus !== 'idle') {
|
|
162
|
-
if (this.state.dataUpdatedAt && fetchOptions
|
|
199
|
+
if (this.state.dataUpdatedAt && fetchOptions != null && fetchOptions.cancelRefetch) {
|
|
163
200
|
// Silently cancel current fetch if the user wants to cancel refetches
|
|
164
201
|
this.cancel({
|
|
165
202
|
silent: true
|
|
166
203
|
});
|
|
167
|
-
} else if (this
|
|
204
|
+
} else if (_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise]) {
|
|
205
|
+
var _classPrivateFieldLoo4;
|
|
168
206
|
// make sure that retries that were potentially cancelled due to unmounts can continue
|
|
169
|
-
this
|
|
207
|
+
(_classPrivateFieldLoo4 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer]) == null ? void 0 : _classPrivateFieldLoo4.continueRetry();
|
|
170
208
|
// Return current promise if we are already fetching
|
|
171
|
-
return this
|
|
209
|
+
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise];
|
|
172
210
|
}
|
|
173
211
|
}
|
|
174
212
|
|
|
175
213
|
// Update config if passed, otherwise the config from the last execution is used
|
|
176
214
|
if (options) {
|
|
177
|
-
this
|
|
215
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](options);
|
|
178
216
|
}
|
|
179
217
|
|
|
180
218
|
// Use the options from the first observer with a query function if no function is found.
|
|
181
219
|
// This can happen when the query is hydrated or created with setQueryData.
|
|
182
220
|
if (!this.options.queryFn) {
|
|
183
|
-
const observer = this
|
|
221
|
+
const observer = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].find(x => x.options.queryFn);
|
|
184
222
|
if (observer) {
|
|
185
|
-
this
|
|
223
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _setOptions)[_setOptions](observer.options);
|
|
186
224
|
}
|
|
187
225
|
}
|
|
188
226
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -205,7 +243,7 @@ class Query extends removable.Removable {
|
|
|
205
243
|
Object.defineProperty(object, 'signal', {
|
|
206
244
|
enumerable: true,
|
|
207
245
|
get: () => {
|
|
208
|
-
this
|
|
246
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = true;
|
|
209
247
|
return abortController.signal;
|
|
210
248
|
}
|
|
211
249
|
});
|
|
@@ -217,7 +255,7 @@ class Query extends removable.Removable {
|
|
|
217
255
|
if (!this.options.queryFn) {
|
|
218
256
|
return Promise.reject(new Error('Missing queryFn'));
|
|
219
257
|
}
|
|
220
|
-
this
|
|
258
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _abortSignalConsumed)[_abortSignalConsumed] = false;
|
|
221
259
|
return this.options.queryFn(queryFnContext);
|
|
222
260
|
};
|
|
223
261
|
|
|
@@ -230,30 +268,32 @@ class Query extends removable.Removable {
|
|
|
230
268
|
fetchFn
|
|
231
269
|
};
|
|
232
270
|
addSignalProperty(context);
|
|
233
|
-
this.options.behavior
|
|
271
|
+
(_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch(context);
|
|
234
272
|
|
|
235
273
|
// Store state in case the current fetch needs to be reverted
|
|
236
|
-
this
|
|
274
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState] = this.state;
|
|
237
275
|
|
|
238
276
|
// Set to fetching state if not already in it
|
|
239
|
-
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== context.fetchOptions
|
|
240
|
-
|
|
277
|
+
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) == null ? void 0 : _context$fetchOptions.meta)) {
|
|
278
|
+
var _context$fetchOptions2;
|
|
279
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
241
280
|
type: 'fetch',
|
|
242
|
-
meta: context.fetchOptions
|
|
281
|
+
meta: (_context$fetchOptions2 = context.fetchOptions) == null ? void 0 : _context$fetchOptions2.meta
|
|
243
282
|
});
|
|
244
283
|
}
|
|
245
284
|
const onError = error => {
|
|
246
285
|
// Optimistically update state if needed
|
|
247
286
|
if (!(retryer.isCancelledError(error) && error.silent)) {
|
|
248
|
-
this
|
|
287
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
249
288
|
type: 'error',
|
|
250
289
|
error: error
|
|
251
290
|
});
|
|
252
291
|
}
|
|
253
292
|
if (!retryer.isCancelledError(error)) {
|
|
293
|
+
var _classPrivateFieldLoo5, _classPrivateFieldLoo6, _classPrivateFieldLoo7, _classPrivateFieldLoo8;
|
|
254
294
|
// Notify cache callback
|
|
255
|
-
this
|
|
256
|
-
this
|
|
295
|
+
(_classPrivateFieldLoo5 = (_classPrivateFieldLoo6 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onError) == null ? void 0 : _classPrivateFieldLoo5.call(_classPrivateFieldLoo6, error, this);
|
|
296
|
+
(_classPrivateFieldLoo7 = (_classPrivateFieldLoo8 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onSettled) == null ? void 0 : _classPrivateFieldLoo7.call(_classPrivateFieldLoo8, this.state.data, error, this);
|
|
257
297
|
}
|
|
258
298
|
if (!this.isFetchingOptimistic) {
|
|
259
299
|
// Schedule query gc after fetching
|
|
@@ -263,10 +303,11 @@ class Query extends removable.Removable {
|
|
|
263
303
|
};
|
|
264
304
|
|
|
265
305
|
// Try to fetch the data
|
|
266
|
-
this
|
|
306
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer] = retryer.createRetryer({
|
|
267
307
|
fn: context.fetchFn,
|
|
268
308
|
abort: abortController.abort.bind(abortController),
|
|
269
309
|
onSuccess: data => {
|
|
310
|
+
var _classPrivateFieldLoo9, _classPrivateFieldLoo10, _classPrivateFieldLoo11, _classPrivateFieldLoo12;
|
|
270
311
|
if (typeof data === 'undefined') {
|
|
271
312
|
if (process.env.NODE_ENV !== 'production') {
|
|
272
313
|
console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
|
|
@@ -277,8 +318,8 @@ class Query extends removable.Removable {
|
|
|
277
318
|
this.setData(data);
|
|
278
319
|
|
|
279
320
|
// Notify cache callback
|
|
280
|
-
this
|
|
281
|
-
this
|
|
321
|
+
(_classPrivateFieldLoo9 = (_classPrivateFieldLoo10 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onSuccess) == null ? void 0 : _classPrivateFieldLoo9.call(_classPrivateFieldLoo10, data, this);
|
|
322
|
+
(_classPrivateFieldLoo11 = (_classPrivateFieldLoo12 = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].config).onSettled) == null ? void 0 : _classPrivateFieldLoo11.call(_classPrivateFieldLoo12, data, this.state.error, this);
|
|
282
323
|
if (!this.isFetchingOptimistic) {
|
|
283
324
|
// Schedule query gc after fetching
|
|
284
325
|
this.scheduleGc();
|
|
@@ -287,19 +328,19 @@ class Query extends removable.Removable {
|
|
|
287
328
|
},
|
|
288
329
|
onError,
|
|
289
330
|
onFail: (failureCount, error) => {
|
|
290
|
-
this
|
|
331
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
291
332
|
type: 'failed',
|
|
292
333
|
failureCount,
|
|
293
334
|
error
|
|
294
335
|
});
|
|
295
336
|
},
|
|
296
337
|
onPause: () => {
|
|
297
|
-
this
|
|
338
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
298
339
|
type: 'pause'
|
|
299
340
|
});
|
|
300
341
|
},
|
|
301
342
|
onContinue: () => {
|
|
302
|
-
this
|
|
343
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _dispatch)[_dispatch]({
|
|
303
344
|
type: 'continue'
|
|
304
345
|
});
|
|
305
346
|
},
|
|
@@ -307,96 +348,104 @@ class Query extends removable.Removable {
|
|
|
307
348
|
retryDelay: context.options.retryDelay,
|
|
308
349
|
networkMode: context.options.networkMode
|
|
309
350
|
});
|
|
310
|
-
this
|
|
311
|
-
return this
|
|
351
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise] = _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _retryer)[_retryer].promise;
|
|
352
|
+
return _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _promise)[_promise];
|
|
312
353
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
dataUpdatedAt: action.dataUpdatedAt ?? Date.now(),
|
|
354
|
+
}
|
|
355
|
+
function _setOptions2(options) {
|
|
356
|
+
this.options = {
|
|
357
|
+
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _defaultOptions)[_defaultOptions],
|
|
358
|
+
...options
|
|
359
|
+
};
|
|
360
|
+
this.updateGcTime(this.options.gcTime);
|
|
361
|
+
}
|
|
362
|
+
function _dispatch2(action) {
|
|
363
|
+
const reducer = state => {
|
|
364
|
+
var _action$meta, _action$dataUpdatedAt;
|
|
365
|
+
switch (action.type) {
|
|
366
|
+
case 'failed':
|
|
367
|
+
return {
|
|
368
|
+
...state,
|
|
369
|
+
fetchFailureCount: action.failureCount,
|
|
370
|
+
fetchFailureReason: action.error
|
|
371
|
+
};
|
|
372
|
+
case 'pause':
|
|
373
|
+
return {
|
|
374
|
+
...state,
|
|
375
|
+
fetchStatus: 'paused'
|
|
376
|
+
};
|
|
377
|
+
case 'continue':
|
|
378
|
+
return {
|
|
379
|
+
...state,
|
|
380
|
+
fetchStatus: 'fetching'
|
|
381
|
+
};
|
|
382
|
+
case 'fetch':
|
|
383
|
+
return {
|
|
384
|
+
...state,
|
|
385
|
+
fetchFailureCount: 0,
|
|
386
|
+
fetchFailureReason: null,
|
|
387
|
+
fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
|
|
388
|
+
fetchStatus: retryer.canFetch(this.options.networkMode) ? 'fetching' : 'paused',
|
|
389
|
+
...(!state.dataUpdatedAt && {
|
|
350
390
|
error: null,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
return {
|
|
367
|
-
...state,
|
|
368
|
-
error: error,
|
|
369
|
-
errorUpdateCount: state.errorUpdateCount + 1,
|
|
370
|
-
errorUpdatedAt: Date.now(),
|
|
371
|
-
fetchFailureCount: state.fetchFailureCount + 1,
|
|
372
|
-
fetchFailureReason: error,
|
|
391
|
+
status: 'pending'
|
|
392
|
+
})
|
|
393
|
+
};
|
|
394
|
+
case 'success':
|
|
395
|
+
return {
|
|
396
|
+
...state,
|
|
397
|
+
data: action.data,
|
|
398
|
+
dataUpdateCount: state.dataUpdateCount + 1,
|
|
399
|
+
dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
|
|
400
|
+
error: null,
|
|
401
|
+
isInvalidated: false,
|
|
402
|
+
status: 'success',
|
|
403
|
+
...(!action.manual && {
|
|
373
404
|
fetchStatus: 'idle',
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
case 'setState':
|
|
405
|
+
fetchFailureCount: 0,
|
|
406
|
+
fetchFailureReason: null
|
|
407
|
+
})
|
|
408
|
+
};
|
|
409
|
+
case 'error':
|
|
410
|
+
const error = action.error;
|
|
411
|
+
if (retryer.isCancelledError(error) && error.revert && _rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState]) {
|
|
382
412
|
return {
|
|
383
|
-
...
|
|
384
|
-
...action.state
|
|
413
|
+
..._rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _revertState)[_revertState]
|
|
385
414
|
};
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
...state,
|
|
418
|
+
error: error,
|
|
419
|
+
errorUpdateCount: state.errorUpdateCount + 1,
|
|
420
|
+
errorUpdatedAt: Date.now(),
|
|
421
|
+
fetchFailureCount: state.fetchFailureCount + 1,
|
|
422
|
+
fetchFailureReason: error,
|
|
423
|
+
fetchStatus: 'idle',
|
|
424
|
+
status: 'error'
|
|
425
|
+
};
|
|
426
|
+
case 'invalidate':
|
|
427
|
+
return {
|
|
428
|
+
...state,
|
|
429
|
+
isInvalidated: true
|
|
430
|
+
};
|
|
431
|
+
case 'setState':
|
|
432
|
+
return {
|
|
433
|
+
...state,
|
|
434
|
+
...action.state
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
this.state = reducer(this.state);
|
|
439
|
+
notifyManager.notifyManager.batch(() => {
|
|
440
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _observers)[_observers].forEach(observer => {
|
|
441
|
+
observer.onQueryUpdate();
|
|
398
442
|
});
|
|
399
|
-
|
|
443
|
+
_rollupPluginBabelHelpers.classPrivateFieldLooseBase(this, _cache)[_cache].notify({
|
|
444
|
+
query: this,
|
|
445
|
+
type: 'updated',
|
|
446
|
+
action
|
|
447
|
+
});
|
|
448
|
+
});
|
|
400
449
|
}
|
|
401
450
|
function getDefaultState(options) {
|
|
402
451
|
const data = typeof options.initialData === 'function' ? options.initialData() : options.initialData;
|
|
@@ -405,7 +454,7 @@ function getDefaultState(options) {
|
|
|
405
454
|
return {
|
|
406
455
|
data,
|
|
407
456
|
dataUpdateCount: 0,
|
|
408
|
-
dataUpdatedAt: hasData ? initialDataUpdatedAt
|
|
457
|
+
dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
|
|
409
458
|
error: null,
|
|
410
459
|
errorUpdateCount: 0,
|
|
411
460
|
errorUpdatedAt: 0,
|