@tanstack/query-core 5.0.0-alpha.3 → 5.0.0-alpha.6

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.
Files changed (103) hide show
  1. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +13 -0
  2. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
  3. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +16 -0
  4. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  5. package/build/lib/focusManager.esm.js +31 -15
  6. package/build/lib/focusManager.esm.js.map +1 -1
  7. package/build/lib/focusManager.js +31 -15
  8. package/build/lib/focusManager.js.map +1 -1
  9. package/build/lib/hydration.esm.js +4 -2
  10. package/build/lib/hydration.esm.js.map +1 -1
  11. package/build/lib/hydration.js +4 -2
  12. package/build/lib/hydration.js.map +1 -1
  13. package/build/lib/infiniteQueryBehavior.d.ts +2 -2
  14. package/build/lib/infiniteQueryBehavior.esm.js +52 -48
  15. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
  16. package/build/lib/infiniteQueryBehavior.js +52 -48
  17. package/build/lib/infiniteQueryBehavior.js.map +1 -1
  18. package/build/lib/infiniteQueryBehavior.mjs +48 -45
  19. package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
  20. package/build/lib/infiniteQueryObserver.d.ts +6 -6
  21. package/build/lib/infiniteQueryObserver.esm.js +7 -8
  22. package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
  23. package/build/lib/infiniteQueryObserver.js +7 -8
  24. package/build/lib/infiniteQueryObserver.js.map +1 -1
  25. package/build/lib/infiniteQueryObserver.mjs +4 -6
  26. package/build/lib/infiniteQueryObserver.mjs.map +1 -1
  27. package/build/lib/mutation.esm.js +127 -102
  28. package/build/lib/mutation.esm.js.map +1 -1
  29. package/build/lib/mutation.js +127 -102
  30. package/build/lib/mutation.js.map +1 -1
  31. package/build/lib/mutationCache.esm.js +30 -17
  32. package/build/lib/mutationCache.esm.js.map +1 -1
  33. package/build/lib/mutationCache.js +30 -17
  34. package/build/lib/mutationCache.js.map +1 -1
  35. package/build/lib/mutationObserver.esm.js +81 -51
  36. package/build/lib/mutationObserver.esm.js.map +1 -1
  37. package/build/lib/mutationObserver.js +81 -51
  38. package/build/lib/mutationObserver.js.map +1 -1
  39. package/build/lib/onlineManager.esm.js +29 -14
  40. package/build/lib/onlineManager.esm.js.map +1 -1
  41. package/build/lib/onlineManager.js +29 -14
  42. package/build/lib/onlineManager.js.map +1 -1
  43. package/build/lib/queriesObserver.esm.js +94 -65
  44. package/build/lib/queriesObserver.esm.js.map +1 -1
  45. package/build/lib/queriesObserver.js +94 -65
  46. package/build/lib/queriesObserver.js.map +1 -1
  47. package/build/lib/query.d.ts +4 -3
  48. package/build/lib/query.esm.js +210 -161
  49. package/build/lib/query.esm.js.map +1 -1
  50. package/build/lib/query.js +210 -161
  51. package/build/lib/query.js.map +1 -1
  52. package/build/lib/query.mjs.map +1 -1
  53. package/build/lib/queryCache.esm.js +16 -9
  54. package/build/lib/queryCache.esm.js.map +1 -1
  55. package/build/lib/queryCache.js +16 -9
  56. package/build/lib/queryCache.js.map +1 -1
  57. package/build/lib/queryClient.esm.js +103 -63
  58. package/build/lib/queryClient.esm.js.map +1 -1
  59. package/build/lib/queryClient.js +103 -63
  60. package/build/lib/queryClient.js.map +1 -1
  61. package/build/lib/queryObserver.esm.js +308 -207
  62. package/build/lib/queryObserver.esm.js.map +1 -1
  63. package/build/lib/queryObserver.js +307 -206
  64. package/build/lib/queryObserver.js.map +1 -1
  65. package/build/lib/removable.esm.js +13 -6
  66. package/build/lib/removable.esm.js.map +1 -1
  67. package/build/lib/removable.js +13 -6
  68. package/build/lib/removable.js.map +1 -1
  69. package/build/lib/retryer.esm.js +15 -14
  70. package/build/lib/retryer.esm.js.map +1 -1
  71. package/build/lib/retryer.js +15 -14
  72. package/build/lib/retryer.js.map +1 -1
  73. package/build/lib/tests/utils.d.ts +4 -5
  74. package/build/lib/types.d.ts +5 -3
  75. package/build/lib/utils.esm.js +1 -1
  76. package/build/lib/utils.esm.js.map +1 -1
  77. package/build/lib/utils.js +1 -1
  78. package/build/lib/utils.js.map +1 -1
  79. package/build/umd/index.development.js +52 -51
  80. package/build/umd/index.development.js.map +1 -1
  81. package/build/umd/index.production.js +1 -1
  82. package/build/umd/index.production.js.map +1 -1
  83. package/package.json +2 -2
  84. package/src/infiniteQueryBehavior.ts +52 -60
  85. package/src/infiniteQueryObserver.ts +15 -10
  86. package/src/query.ts +6 -4
  87. package/src/tests/focusManager.test.tsx +12 -14
  88. package/src/tests/hydration.test.tsx +15 -14
  89. package/src/tests/infiniteQueryBehavior.test.tsx +16 -9
  90. package/src/tests/infiniteQueryObserver.test.tsx +62 -1
  91. package/src/tests/mutationCache.test.tsx +11 -10
  92. package/src/tests/mutationObserver.test.tsx +3 -2
  93. package/src/tests/mutations.test.tsx +11 -10
  94. package/src/tests/notifyManager.test.tsx +7 -6
  95. package/src/tests/onlineManager.test.tsx +12 -17
  96. package/src/tests/queriesObserver.test.tsx +18 -17
  97. package/src/tests/query.test.tsx +18 -17
  98. package/src/tests/queryCache.test.tsx +14 -13
  99. package/src/tests/queryClient.test.tsx +49 -48
  100. package/src/tests/queryObserver.test.tsx +10 -9
  101. package/src/tests/utils.test.tsx +2 -1
  102. package/src/tests/utils.ts +5 -4
  103. package/src/types.ts +9 -1
@@ -1,29 +1,126 @@
1
- import { shallowEqualObjects, noop, isServer, isValidTimeout, timeUntilStale, replaceData } from './utils.esm.js';
1
+ import { classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey } from './_virtual/_rollupPluginBabelHelpers.esm.js';
2
+ import { shallowEqualObjects, replaceData, noop, isServer, isValidTimeout, timeUntilStale } from './utils.esm.js';
2
3
  import { notifyManager } from './notifyManager.esm.js';
3
4
  import { focusManager } from './focusManager.esm.js';
4
5
  import { Subscribable } from './subscribable.esm.js';
5
6
  import { canFetch, isCancelledError } from './retryer.esm.js';
6
7
 
8
+ var _client = /*#__PURE__*/_classPrivateFieldLooseKey("client");
9
+ var _currentQuery = /*#__PURE__*/_classPrivateFieldLooseKey("currentQuery");
10
+ var _currentQueryInitialState = /*#__PURE__*/_classPrivateFieldLooseKey("currentQueryInitialState");
11
+ var _currentResult = /*#__PURE__*/_classPrivateFieldLooseKey("currentResult");
12
+ var _currentResultState = /*#__PURE__*/_classPrivateFieldLooseKey("currentResultState");
13
+ var _currentResultOptions = /*#__PURE__*/_classPrivateFieldLooseKey("currentResultOptions");
14
+ var _previousQueryResult = /*#__PURE__*/_classPrivateFieldLooseKey("previousQueryResult");
15
+ var _selectError = /*#__PURE__*/_classPrivateFieldLooseKey("selectError");
16
+ var _selectFn = /*#__PURE__*/_classPrivateFieldLooseKey("selectFn");
17
+ var _selectResult = /*#__PURE__*/_classPrivateFieldLooseKey("selectResult");
18
+ var _staleTimeoutId = /*#__PURE__*/_classPrivateFieldLooseKey("staleTimeoutId");
19
+ var _refetchIntervalId = /*#__PURE__*/_classPrivateFieldLooseKey("refetchIntervalId");
20
+ var _currentRefetchInterval = /*#__PURE__*/_classPrivateFieldLooseKey("currentRefetchInterval");
21
+ var _trackedProps = /*#__PURE__*/_classPrivateFieldLooseKey("trackedProps");
22
+ var _executeFetch = /*#__PURE__*/_classPrivateFieldLooseKey("executeFetch");
23
+ var _updateStaleTimeout = /*#__PURE__*/_classPrivateFieldLooseKey("updateStaleTimeout");
24
+ var _computeRefetchInterval = /*#__PURE__*/_classPrivateFieldLooseKey("computeRefetchInterval");
25
+ var _updateRefetchInterval = /*#__PURE__*/_classPrivateFieldLooseKey("updateRefetchInterval");
26
+ var _updateTimers = /*#__PURE__*/_classPrivateFieldLooseKey("updateTimers");
27
+ var _clearStaleTimeout = /*#__PURE__*/_classPrivateFieldLooseKey("clearStaleTimeout");
28
+ var _clearRefetchInterval = /*#__PURE__*/_classPrivateFieldLooseKey("clearRefetchInterval");
29
+ var _updateResult = /*#__PURE__*/_classPrivateFieldLooseKey("updateResult");
30
+ var _updateQuery = /*#__PURE__*/_classPrivateFieldLooseKey("updateQuery");
31
+ var _notify = /*#__PURE__*/_classPrivateFieldLooseKey("notify");
7
32
  class QueryObserver extends Subscribable {
8
- #client;
9
- #currentQuery = undefined;
10
- #currentQueryInitialState = undefined;
11
- #currentResult = undefined;
12
- #currentResultState;
13
- #currentResultOptions;
14
- #previousQueryResult;
15
- #selectError;
16
- #selectFn;
17
- #selectResult;
18
- #staleTimeoutId;
19
- #refetchIntervalId;
20
- #currentRefetchInterval;
21
- #trackedProps = new Set();
22
33
  constructor(client, options) {
23
34
  super();
24
- this.#client = client;
35
+ Object.defineProperty(this, _notify, {
36
+ value: _notify2
37
+ });
38
+ Object.defineProperty(this, _updateQuery, {
39
+ value: _updateQuery2
40
+ });
41
+ Object.defineProperty(this, _updateResult, {
42
+ value: _updateResult2
43
+ });
44
+ Object.defineProperty(this, _clearRefetchInterval, {
45
+ value: _clearRefetchInterval2
46
+ });
47
+ Object.defineProperty(this, _clearStaleTimeout, {
48
+ value: _clearStaleTimeout2
49
+ });
50
+ Object.defineProperty(this, _updateTimers, {
51
+ value: _updateTimers2
52
+ });
53
+ Object.defineProperty(this, _updateRefetchInterval, {
54
+ value: _updateRefetchInterval2
55
+ });
56
+ Object.defineProperty(this, _computeRefetchInterval, {
57
+ value: _computeRefetchInterval2
58
+ });
59
+ Object.defineProperty(this, _updateStaleTimeout, {
60
+ value: _updateStaleTimeout2
61
+ });
62
+ Object.defineProperty(this, _executeFetch, {
63
+ value: _executeFetch2
64
+ });
65
+ Object.defineProperty(this, _client, {
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, _currentQuery, {
70
+ writable: true,
71
+ value: undefined
72
+ });
73
+ Object.defineProperty(this, _currentQueryInitialState, {
74
+ writable: true,
75
+ value: undefined
76
+ });
77
+ Object.defineProperty(this, _currentResult, {
78
+ writable: true,
79
+ value: undefined
80
+ });
81
+ Object.defineProperty(this, _currentResultState, {
82
+ writable: true,
83
+ value: void 0
84
+ });
85
+ Object.defineProperty(this, _currentResultOptions, {
86
+ writable: true,
87
+ value: void 0
88
+ });
89
+ Object.defineProperty(this, _previousQueryResult, {
90
+ writable: true,
91
+ value: void 0
92
+ });
93
+ Object.defineProperty(this, _selectError, {
94
+ writable: true,
95
+ value: void 0
96
+ });
97
+ Object.defineProperty(this, _selectFn, {
98
+ writable: true,
99
+ value: void 0
100
+ });
101
+ Object.defineProperty(this, _selectResult, {
102
+ writable: true,
103
+ value: void 0
104
+ });
105
+ Object.defineProperty(this, _staleTimeoutId, {
106
+ writable: true,
107
+ value: void 0
108
+ });
109
+ Object.defineProperty(this, _refetchIntervalId, {
110
+ writable: true,
111
+ value: void 0
112
+ });
113
+ Object.defineProperty(this, _currentRefetchInterval, {
114
+ writable: true,
115
+ value: void 0
116
+ });
117
+ Object.defineProperty(this, _trackedProps, {
118
+ writable: true,
119
+ value: new Set()
120
+ });
121
+ _classPrivateFieldLooseBase(this, _client)[_client] = client;
25
122
  this.options = options;
26
- this.#selectError = null;
123
+ _classPrivateFieldLooseBase(this, _selectError)[_selectError] = null;
27
124
  this.bindMethods();
28
125
  this.setOptions(options);
29
126
  }
@@ -32,11 +129,11 @@ class QueryObserver extends Subscribable {
32
129
  }
33
130
  onSubscribe() {
34
131
  if (this.listeners.length === 1) {
35
- this.#currentQuery.addObserver(this);
36
- if (shouldFetchOnMount(this.#currentQuery, this.options)) {
37
- this.#executeFetch();
132
+ _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].addObserver(this);
133
+ if (shouldFetchOnMount(_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options)) {
134
+ _classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
38
135
  }
39
- this.#updateTimers();
136
+ _classPrivateFieldLooseBase(this, _updateTimers)[_updateTimers]();
40
137
  }
41
138
  }
42
139
  onUnsubscribe() {
@@ -45,25 +142,25 @@ class QueryObserver extends Subscribable {
45
142
  }
46
143
  }
47
144
  shouldFetchOnReconnect() {
48
- return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
145
+ return shouldFetchOn(_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options, this.options.refetchOnReconnect);
49
146
  }
50
147
  shouldFetchOnWindowFocus() {
51
- return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
148
+ return shouldFetchOn(_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options, this.options.refetchOnWindowFocus);
52
149
  }
53
150
  destroy() {
54
151
  this.listeners = [];
55
- this.#clearStaleTimeout();
56
- this.#clearRefetchInterval();
57
- this.#currentQuery.removeObserver(this);
152
+ _classPrivateFieldLooseBase(this, _clearStaleTimeout)[_clearStaleTimeout]();
153
+ _classPrivateFieldLooseBase(this, _clearRefetchInterval)[_clearRefetchInterval]();
154
+ _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].removeObserver(this);
58
155
  }
59
156
  setOptions(options, notifyOptions) {
60
157
  const prevOptions = this.options;
61
- const prevQuery = this.#currentQuery;
62
- this.options = this.#client.defaultQueryOptions(options);
158
+ const prevQuery = _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
159
+ this.options = _classPrivateFieldLooseBase(this, _client)[_client].defaultQueryOptions(options);
63
160
  if (!shallowEqualObjects(prevOptions, this.options)) {
64
- this.#client.getQueryCache().notify({
161
+ _classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().notify({
65
162
  type: 'observerOptionsUpdated',
66
- query: this.#currentQuery,
163
+ query: _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery],
67
164
  observer: this
68
165
  });
69
166
  }
@@ -75,34 +172,34 @@ class QueryObserver extends Subscribable {
75
172
  if (!this.options.queryKey) {
76
173
  this.options.queryKey = prevOptions.queryKey;
77
174
  }
78
- this.#updateQuery();
175
+ _classPrivateFieldLooseBase(this, _updateQuery)[_updateQuery]();
79
176
  const mounted = this.hasListeners();
80
177
 
81
178
  // Fetch if there are subscribers
82
- if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) {
83
- this.#executeFetch();
179
+ if (mounted && shouldFetchOptionally(_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], prevQuery, this.options, prevOptions)) {
180
+ _classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
84
181
  }
85
182
 
86
183
  // Update result
87
- this.#updateResult(notifyOptions);
184
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult](notifyOptions);
88
185
 
89
186
  // Update stale interval if needed
90
- if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
91
- this.#updateStaleTimeout();
187
+ if (mounted && (_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery] !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
188
+ _classPrivateFieldLooseBase(this, _updateStaleTimeout)[_updateStaleTimeout]();
92
189
  }
93
- const nextRefetchInterval = this.#computeRefetchInterval();
190
+ const nextRefetchInterval = _classPrivateFieldLooseBase(this, _computeRefetchInterval)[_computeRefetchInterval]();
94
191
 
95
192
  // Update refetch interval if needed
96
- if (mounted && (this.#currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.#currentRefetchInterval)) {
97
- this.#updateRefetchInterval(nextRefetchInterval);
193
+ if (mounted && (_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery] !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== _classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval])) {
194
+ _classPrivateFieldLooseBase(this, _updateRefetchInterval)[_updateRefetchInterval](nextRefetchInterval);
98
195
  }
99
196
  }
100
197
  getOptimisticResult(options) {
101
- const query = this.#client.getQueryCache().build(this.#client, options);
198
+ const query = _classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_classPrivateFieldLooseBase(this, _client)[_client], options);
102
199
  return this.createResult(query, options);
103
200
  }
104
201
  getCurrentResult() {
105
- return this.#currentResult;
202
+ return _classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
106
203
  }
107
204
  trackResult(result) {
108
205
  const trackedResult = {};
@@ -111,7 +208,7 @@ class QueryObserver extends Subscribable {
111
208
  configurable: false,
112
209
  enumerable: true,
113
210
  get: () => {
114
- this.#trackedProps.add(key);
211
+ _classPrivateFieldLooseBase(this, _trackedProps)[_trackedProps].add(key);
115
212
  return result[key];
116
213
  }
117
214
  });
@@ -119,7 +216,7 @@ class QueryObserver extends Subscribable {
119
216
  return trackedResult;
120
217
  }
121
218
  getCurrentQuery() {
122
- return this.#currentQuery;
219
+ return _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
123
220
  }
124
221
  refetch({
125
222
  ...options
@@ -129,87 +226,30 @@ class QueryObserver extends Subscribable {
129
226
  });
130
227
  }
131
228
  fetchOptimistic(options) {
132
- const defaultedOptions = this.#client.defaultQueryOptions(options);
133
- const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
229
+ const defaultedOptions = _classPrivateFieldLooseBase(this, _client)[_client].defaultQueryOptions(options);
230
+ const query = _classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_classPrivateFieldLooseBase(this, _client)[_client], defaultedOptions);
134
231
  query.isFetchingOptimistic = true;
135
232
  return query.fetch().then(() => this.createResult(query, defaultedOptions));
136
233
  }
137
234
  fetch(fetchOptions) {
138
- return this.#executeFetch({
235
+ var _fetchOptions$cancelR;
236
+ return _classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]({
139
237
  ...fetchOptions,
140
- cancelRefetch: fetchOptions.cancelRefetch ?? true
238
+ cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
141
239
  }).then(() => {
142
- this.#updateResult();
143
- return this.#currentResult;
240
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
241
+ return _classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
144
242
  });
145
243
  }
146
- #executeFetch(fetchOptions) {
147
- // Make sure we reference the latest query as the current one might have been removed
148
- this.#updateQuery();
149
-
150
- // Fetch
151
- let promise = this.#currentQuery.fetch(this.options, fetchOptions);
152
- if (!fetchOptions?.throwOnError) {
153
- promise = promise.catch(noop);
154
- }
155
- return promise;
156
- }
157
- #updateStaleTimeout() {
158
- this.#clearStaleTimeout();
159
- if (isServer || this.#currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
160
- return;
161
- }
162
- const time = timeUntilStale(this.#currentResult.dataUpdatedAt, this.options.staleTime);
163
-
164
- // The timeout is sometimes triggered 1 ms before the stale time expiration.
165
- // To mitigate this issue we always add 1 ms to the timeout.
166
- const timeout = time + 1;
167
- this.#staleTimeoutId = setTimeout(() => {
168
- if (!this.#currentResult.isStale) {
169
- this.#updateResult();
170
- }
171
- }, timeout);
172
- }
173
- #computeRefetchInterval() {
174
- return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval ?? false;
175
- }
176
- #updateRefetchInterval(nextInterval) {
177
- this.#clearRefetchInterval();
178
- this.#currentRefetchInterval = nextInterval;
179
- if (isServer || this.options.enabled === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
180
- return;
181
- }
182
- this.#refetchIntervalId = setInterval(() => {
183
- if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
184
- this.#executeFetch();
185
- }
186
- }, this.#currentRefetchInterval);
187
- }
188
- #updateTimers() {
189
- this.#updateStaleTimeout();
190
- this.#updateRefetchInterval(this.#computeRefetchInterval());
191
- }
192
- #clearStaleTimeout() {
193
- if (this.#staleTimeoutId) {
194
- clearTimeout(this.#staleTimeoutId);
195
- this.#staleTimeoutId = undefined;
196
- }
197
- }
198
- #clearRefetchInterval() {
199
- if (this.#refetchIntervalId) {
200
- clearInterval(this.#refetchIntervalId);
201
- this.#refetchIntervalId = undefined;
202
- }
203
- }
204
244
  createResult(query, options) {
205
- const prevQuery = this.#currentQuery;
245
+ const prevQuery = _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
206
246
  const prevOptions = this.options;
207
- const prevResult = this.#currentResult;
208
- const prevResultState = this.#currentResultState;
209
- const prevResultOptions = this.#currentResultOptions;
247
+ const prevResult = _classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
248
+ const prevResultState = _classPrivateFieldLooseBase(this, _currentResultState)[_currentResultState];
249
+ const prevResultOptions = _classPrivateFieldLooseBase(this, _currentResultOptions)[_currentResultOptions];
210
250
  const queryChange = query !== prevQuery;
211
- const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
212
- const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
251
+ const queryInitialState = queryChange ? query.state : _classPrivateFieldLooseBase(this, _currentQueryInitialState)[_currentQueryInitialState];
252
+ const prevQueryResult = queryChange ? _classPrivateFieldLooseBase(this, _currentResult)[_currentResult] : _classPrivateFieldLooseBase(this, _previousQueryResult)[_previousQueryResult];
213
253
  const {
214
254
  state
215
255
  } = query;
@@ -241,17 +281,17 @@ class QueryObserver extends Subscribable {
241
281
  // Select data if needed
242
282
  if (options.select && typeof state.data !== 'undefined') {
243
283
  // Memoize select result
244
- if (prevResult && state.data === prevResultState?.data && options.select === this.#selectFn) {
245
- data = this.#selectResult;
284
+ if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === _classPrivateFieldLooseBase(this, _selectFn)[_selectFn]) {
285
+ data = _classPrivateFieldLooseBase(this, _selectResult)[_selectResult];
246
286
  } else {
247
287
  try {
248
- this.#selectFn = options.select;
288
+ _classPrivateFieldLooseBase(this, _selectFn)[_selectFn] = options.select;
249
289
  data = options.select(state.data);
250
- data = replaceData(prevResult?.data, data, options);
251
- this.#selectResult = data;
252
- this.#selectError = null;
290
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
291
+ _classPrivateFieldLooseBase(this, _selectResult)[_selectResult] = data;
292
+ _classPrivateFieldLooseBase(this, _selectError)[_selectError] = null;
253
293
  } catch (selectError) {
254
- this.#selectError = selectError;
294
+ _classPrivateFieldLooseBase(this, _selectError)[_selectError] = selectError;
255
295
  }
256
296
  }
257
297
  }
@@ -265,28 +305,28 @@ class QueryObserver extends Subscribable {
265
305
  let placeholderData;
266
306
 
267
307
  // Memoize placeholder data
268
- if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
308
+ if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
269
309
  placeholderData = prevResult.data;
270
310
  } else {
271
- placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(prevQueryResult?.data) : options.placeholderData;
311
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(prevQueryResult == null ? void 0 : prevQueryResult.data) : options.placeholderData;
272
312
  if (options.select && typeof placeholderData !== 'undefined') {
273
313
  try {
274
314
  placeholderData = options.select(placeholderData);
275
- this.#selectError = null;
315
+ _classPrivateFieldLooseBase(this, _selectError)[_selectError] = null;
276
316
  } catch (selectError) {
277
- this.#selectError = selectError;
317
+ _classPrivateFieldLooseBase(this, _selectError)[_selectError] = selectError;
278
318
  }
279
319
  }
280
320
  }
281
321
  if (typeof placeholderData !== 'undefined') {
282
322
  status = 'success';
283
- data = replaceData(prevResult?.data, placeholderData, options);
323
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
284
324
  isPlaceholderData = true;
285
325
  }
286
326
  }
287
- if (this.#selectError) {
288
- error = this.#selectError;
289
- data = this.#selectResult;
327
+ if (_classPrivateFieldLooseBase(this, _selectError)[_selectError]) {
328
+ error = _classPrivateFieldLooseBase(this, _selectError)[_selectError];
329
+ data = _classPrivateFieldLooseBase(this, _selectResult)[_selectResult];
290
330
  errorUpdatedAt = Date.now();
291
331
  status = 'error';
292
332
  }
@@ -322,62 +362,6 @@ class QueryObserver extends Subscribable {
322
362
  };
323
363
  return result;
324
364
  }
325
- #updateResult(notifyOptions) {
326
- const prevResult = this.#currentResult;
327
- const nextResult = this.createResult(this.#currentQuery, this.options);
328
- this.#currentResultState = this.#currentQuery.state;
329
- this.#currentResultOptions = this.options;
330
-
331
- // Only notify and update result if something has changed
332
- if (shallowEqualObjects(nextResult, prevResult)) {
333
- return;
334
- }
335
- this.#currentResult = nextResult;
336
-
337
- // Determine which callbacks to trigger
338
- const defaultNotifyOptions = {};
339
- const shouldNotifyListeners = () => {
340
- if (!prevResult) {
341
- return true;
342
- }
343
- const {
344
- notifyOnChangeProps
345
- } = this.options;
346
- if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.#trackedProps.size) {
347
- return true;
348
- }
349
- const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
350
- if (this.options.throwErrors) {
351
- includedProps.add('error');
352
- }
353
- return Object.keys(this.#currentResult).some(key => {
354
- const typedKey = key;
355
- const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
356
- return changed && includedProps.has(typedKey);
357
- });
358
- };
359
- if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {
360
- defaultNotifyOptions.listeners = true;
361
- }
362
- this.#notify({
363
- ...defaultNotifyOptions,
364
- ...notifyOptions
365
- });
366
- }
367
- #updateQuery() {
368
- const query = this.#client.getQueryCache().build(this.#client, this.options);
369
- if (query === this.#currentQuery) {
370
- return;
371
- }
372
- const prevQuery = this.#currentQuery;
373
- this.#currentQuery = query;
374
- this.#currentQueryInitialState = query.state;
375
- this.#previousQueryResult = this.#currentResult;
376
- if (this.hasListeners()) {
377
- prevQuery?.removeObserver(this);
378
- query.addObserver(this);
379
- }
380
- }
381
365
  onQueryUpdate(action) {
382
366
  const notifyOptions = {};
383
367
  if (action.type === 'success') {
@@ -385,36 +369,153 @@ class QueryObserver extends Subscribable {
385
369
  } else if (action.type === 'error' && !isCancelledError(action.error)) {
386
370
  notifyOptions.onError = true;
387
371
  }
388
- this.#updateResult(notifyOptions);
372
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult](notifyOptions);
389
373
  if (this.hasListeners()) {
390
- this.#updateTimers();
374
+ _classPrivateFieldLooseBase(this, _updateTimers)[_updateTimers]();
391
375
  }
392
376
  }
393
- #notify(notifyOptions) {
394
- notifyManager.batch(() => {
395
- // First trigger the configuration callbacks
396
- if (notifyOptions.onSuccess) {
397
- this.options.onSuccess?.(this.#currentResult.data);
398
- this.options.onSettled?.(this.#currentResult.data, null);
399
- } else if (notifyOptions.onError) {
400
- this.options.onError?.(this.#currentResult.error);
401
- this.options.onSettled?.(undefined, this.#currentResult.error);
402
- }
377
+ }
378
+ function _executeFetch2(fetchOptions) {
379
+ // Make sure we reference the latest query as the current one might have been removed
380
+ _classPrivateFieldLooseBase(this, _updateQuery)[_updateQuery]();
403
381
 
404
- // Then trigger the listeners
405
- if (notifyOptions.listeners) {
406
- this.listeners.forEach(listener => {
407
- listener(this.#currentResult);
408
- });
409
- }
382
+ // Fetch
383
+ let promise = _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].fetch(this.options, fetchOptions);
384
+ if (!(fetchOptions != null && fetchOptions.throwOnError)) {
385
+ promise = promise.catch(noop);
386
+ }
387
+ return promise;
388
+ }
389
+ function _updateStaleTimeout2() {
390
+ _classPrivateFieldLooseBase(this, _clearStaleTimeout)[_clearStaleTimeout]();
391
+ if (isServer || _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].isStale || !isValidTimeout(this.options.staleTime)) {
392
+ return;
393
+ }
394
+ const time = timeUntilStale(_classPrivateFieldLooseBase(this, _currentResult)[_currentResult].dataUpdatedAt, this.options.staleTime);
410
395
 
411
- // Then the cache listeners
412
- this.#client.getQueryCache().notify({
413
- query: this.#currentQuery,
414
- type: 'observerResultsUpdated'
415
- });
396
+ // The timeout is sometimes triggered 1 ms before the stale time expiration.
397
+ // To mitigate this issue we always add 1 ms to the timeout.
398
+ const timeout = time + 1;
399
+ _classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId] = setTimeout(() => {
400
+ if (!_classPrivateFieldLooseBase(this, _currentResult)[_currentResult].isStale) {
401
+ _classPrivateFieldLooseBase(this, _updateResult)[_updateResult]();
402
+ }
403
+ }, timeout);
404
+ }
405
+ function _computeRefetchInterval2() {
406
+ var _this$options$refetch;
407
+ return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(_classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data, _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery]) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
408
+ }
409
+ function _updateRefetchInterval2(nextInterval) {
410
+ _classPrivateFieldLooseBase(this, _clearRefetchInterval)[_clearRefetchInterval]();
411
+ _classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval] = nextInterval;
412
+ if (isServer || this.options.enabled === false || !isValidTimeout(_classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval]) || _classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval] === 0) {
413
+ return;
414
+ }
415
+ _classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId] = setInterval(() => {
416
+ if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
417
+ _classPrivateFieldLooseBase(this, _executeFetch)[_executeFetch]();
418
+ }
419
+ }, _classPrivateFieldLooseBase(this, _currentRefetchInterval)[_currentRefetchInterval]);
420
+ }
421
+ function _updateTimers2() {
422
+ _classPrivateFieldLooseBase(this, _updateStaleTimeout)[_updateStaleTimeout]();
423
+ _classPrivateFieldLooseBase(this, _updateRefetchInterval)[_updateRefetchInterval](_classPrivateFieldLooseBase(this, _computeRefetchInterval)[_computeRefetchInterval]());
424
+ }
425
+ function _clearStaleTimeout2() {
426
+ if (_classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId]) {
427
+ clearTimeout(_classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId]);
428
+ _classPrivateFieldLooseBase(this, _staleTimeoutId)[_staleTimeoutId] = undefined;
429
+ }
430
+ }
431
+ function _clearRefetchInterval2() {
432
+ if (_classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId]) {
433
+ clearInterval(_classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId]);
434
+ _classPrivateFieldLooseBase(this, _refetchIntervalId)[_refetchIntervalId] = undefined;
435
+ }
436
+ }
437
+ function _updateResult2(notifyOptions) {
438
+ const prevResult = _classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
439
+ const nextResult = this.createResult(_classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery], this.options);
440
+ _classPrivateFieldLooseBase(this, _currentResultState)[_currentResultState] = _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery].state;
441
+ _classPrivateFieldLooseBase(this, _currentResultOptions)[_currentResultOptions] = this.options;
442
+
443
+ // Only notify and update result if something has changed
444
+ if (shallowEqualObjects(nextResult, prevResult)) {
445
+ return;
446
+ }
447
+ _classPrivateFieldLooseBase(this, _currentResult)[_currentResult] = nextResult;
448
+
449
+ // Determine which callbacks to trigger
450
+ const defaultNotifyOptions = {};
451
+ const shouldNotifyListeners = () => {
452
+ if (!prevResult) {
453
+ return true;
454
+ }
455
+ const {
456
+ notifyOnChangeProps
457
+ } = this.options;
458
+ if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !_classPrivateFieldLooseBase(this, _trackedProps)[_trackedProps].size) {
459
+ return true;
460
+ }
461
+ const includedProps = new Set(notifyOnChangeProps != null ? notifyOnChangeProps : _classPrivateFieldLooseBase(this, _trackedProps)[_trackedProps]);
462
+ if (this.options.throwErrors) {
463
+ includedProps.add('error');
464
+ }
465
+ return Object.keys(_classPrivateFieldLooseBase(this, _currentResult)[_currentResult]).some(key => {
466
+ const typedKey = key;
467
+ const changed = _classPrivateFieldLooseBase(this, _currentResult)[_currentResult][typedKey] !== prevResult[typedKey];
468
+ return changed && includedProps.has(typedKey);
416
469
  });
470
+ };
471
+ if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
472
+ defaultNotifyOptions.listeners = true;
473
+ }
474
+ _classPrivateFieldLooseBase(this, _notify)[_notify]({
475
+ ...defaultNotifyOptions,
476
+ ...notifyOptions
477
+ });
478
+ }
479
+ function _updateQuery2() {
480
+ const query = _classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().build(_classPrivateFieldLooseBase(this, _client)[_client], this.options);
481
+ if (query === _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery]) {
482
+ return;
417
483
  }
484
+ const prevQuery = _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery];
485
+ _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery] = query;
486
+ _classPrivateFieldLooseBase(this, _currentQueryInitialState)[_currentQueryInitialState] = query.state;
487
+ _classPrivateFieldLooseBase(this, _previousQueryResult)[_previousQueryResult] = _classPrivateFieldLooseBase(this, _currentResult)[_currentResult];
488
+ if (this.hasListeners()) {
489
+ prevQuery == null ? void 0 : prevQuery.removeObserver(this);
490
+ query.addObserver(this);
491
+ }
492
+ }
493
+ function _notify2(notifyOptions) {
494
+ notifyManager.batch(() => {
495
+ // First trigger the configuration callbacks
496
+ if (notifyOptions.onSuccess) {
497
+ var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
498
+ (_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data);
499
+ (_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].data, null);
500
+ } else if (notifyOptions.onError) {
501
+ var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
502
+ (_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].error);
503
+ (_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, undefined, _classPrivateFieldLooseBase(this, _currentResult)[_currentResult].error);
504
+ }
505
+
506
+ // Then trigger the listeners
507
+ if (notifyOptions.listeners) {
508
+ this.listeners.forEach(listener => {
509
+ listener(_classPrivateFieldLooseBase(this, _currentResult)[_currentResult]);
510
+ });
511
+ }
512
+
513
+ // Then the cache listeners
514
+ _classPrivateFieldLooseBase(this, _client)[_client].getQueryCache().notify({
515
+ query: _classPrivateFieldLooseBase(this, _currentQuery)[_currentQuery],
516
+ type: 'observerResultsUpdated'
517
+ });
518
+ });
418
519
  }
419
520
  function shouldLoadOnMount(query, options) {
420
521
  return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);