@tanstack/query-core 5.0.0-alpha.2 → 5.0.0-alpha.21

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