@tanstack/query-core 5.0.0-alpha.7 → 5.0.0-alpha.81

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