@tanstack/query-core 4.24.10 → 5.0.0-alpha.0

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