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