@tanstack/query-core 5.104.1 → 5.104.3

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 (359) hide show
  1. package/build/legacy/environmentManager.cjs +3 -1
  2. package/build/legacy/environmentManager.cjs.map +1 -1
  3. package/build/legacy/environmentManager.d.cts +6 -1
  4. package/build/legacy/environmentManager.d.cts.map +1 -1
  5. package/build/legacy/environmentManager.d.ts +6 -1
  6. package/build/legacy/environmentManager.d.ts.map +1 -1
  7. package/build/legacy/environmentManager.js +3 -1
  8. package/build/legacy/environmentManager.js.map +1 -1
  9. package/build/legacy/focusManager.cjs +4 -2
  10. package/build/legacy/focusManager.cjs.map +1 -1
  11. package/build/legacy/focusManager.d.cts +5 -3
  12. package/build/legacy/focusManager.d.cts.map +1 -1
  13. package/build/legacy/focusManager.d.ts +5 -3
  14. package/build/legacy/focusManager.d.ts.map +1 -1
  15. package/build/legacy/focusManager.js +4 -2
  16. package/build/legacy/focusManager.js.map +1 -1
  17. package/build/legacy/{hydration-B9t5w6NC.d.ts → hydration-Bf0oMcwO.d.ts} +1411 -129
  18. package/build/legacy/hydration-Bf0oMcwO.d.ts.map +1 -0
  19. package/build/legacy/{hydration-Br9VIGXa.d.cts → hydration-C6zghADG.d.cts} +1411 -129
  20. package/build/legacy/hydration-C6zghADG.d.cts.map +1 -0
  21. package/build/legacy/hydration.cjs +35 -0
  22. package/build/legacy/hydration.cjs.map +1 -1
  23. package/build/legacy/hydration.d.cts +1 -1
  24. package/build/legacy/hydration.d.ts +1 -1
  25. package/build/legacy/hydration.js +35 -0
  26. package/build/legacy/hydration.js.map +1 -1
  27. package/build/legacy/index.d.cts +1 -1
  28. package/build/legacy/index.d.ts +1 -1
  29. package/build/legacy/infiniteQueryBehavior.cjs +29 -0
  30. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  31. package/build/legacy/infiniteQueryBehavior.d.cts +16 -1
  32. package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -1
  33. package/build/legacy/infiniteQueryBehavior.d.ts +16 -1
  34. package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -1
  35. package/build/legacy/infiniteQueryBehavior.js +29 -0
  36. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  37. package/build/legacy/infiniteQueryObserver.cjs +13 -7
  38. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  39. package/build/legacy/infiniteQueryObserver.d.cts +15 -9
  40. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -1
  41. package/build/legacy/infiniteQueryObserver.d.ts +15 -9
  42. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -1
  43. package/build/legacy/infiniteQueryObserver.js +13 -7
  44. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  45. package/build/legacy/mutation.cjs +27 -10
  46. package/build/legacy/mutation.cjs.map +1 -1
  47. package/build/legacy/mutation.d.cts +1 -1
  48. package/build/legacy/mutation.d.ts +1 -1
  49. package/build/legacy/mutation.js +27 -10
  50. package/build/legacy/mutation.js.map +1 -1
  51. package/build/legacy/mutationCache.cjs +53 -12
  52. package/build/legacy/mutationCache.cjs.map +1 -1
  53. package/build/legacy/mutationCache.d.cts +1 -1
  54. package/build/legacy/mutationCache.d.ts +1 -1
  55. package/build/legacy/mutationCache.js +53 -12
  56. package/build/legacy/mutationCache.js.map +1 -1
  57. package/build/legacy/mutationObserver.cjs +27 -16
  58. package/build/legacy/mutationObserver.cjs.map +1 -1
  59. package/build/legacy/mutationObserver.d.cts +1 -1
  60. package/build/legacy/mutationObserver.d.ts +1 -1
  61. package/build/legacy/mutationObserver.js +27 -16
  62. package/build/legacy/mutationObserver.js.map +1 -1
  63. package/build/legacy/notifyManager.cjs +12 -2
  64. package/build/legacy/notifyManager.cjs.map +1 -1
  65. package/build/legacy/notifyManager.d.cts +19 -4
  66. package/build/legacy/notifyManager.d.cts.map +1 -1
  67. package/build/legacy/notifyManager.d.ts +19 -4
  68. package/build/legacy/notifyManager.d.ts.map +1 -1
  69. package/build/legacy/notifyManager.js +12 -2
  70. package/build/legacy/notifyManager.js.map +1 -1
  71. package/build/legacy/onlineManager.cjs +4 -2
  72. package/build/legacy/onlineManager.cjs.map +1 -1
  73. package/build/legacy/onlineManager.d.cts +5 -3
  74. package/build/legacy/onlineManager.d.cts.map +1 -1
  75. package/build/legacy/onlineManager.d.ts +5 -3
  76. package/build/legacy/onlineManager.d.ts.map +1 -1
  77. package/build/legacy/onlineManager.js +4 -2
  78. package/build/legacy/onlineManager.js.map +1 -1
  79. package/build/legacy/queriesObserver.cjs +15 -3
  80. package/build/legacy/queriesObserver.cjs.map +1 -1
  81. package/build/legacy/queriesObserver.d.cts +14 -5
  82. package/build/legacy/queriesObserver.d.cts.map +1 -1
  83. package/build/legacy/queriesObserver.d.ts +14 -5
  84. package/build/legacy/queriesObserver.d.ts.map +1 -1
  85. package/build/legacy/queriesObserver.js +15 -3
  86. package/build/legacy/queriesObserver.js.map +1 -1
  87. package/build/legacy/query.cjs +89 -15
  88. package/build/legacy/query.cjs.map +1 -1
  89. package/build/legacy/query.d.cts +1 -1
  90. package/build/legacy/query.d.ts +1 -1
  91. package/build/legacy/query.js +89 -15
  92. package/build/legacy/query.js.map +1 -1
  93. package/build/legacy/queryCache.cjs +34 -12
  94. package/build/legacy/queryCache.cjs.map +1 -1
  95. package/build/legacy/queryCache.d.cts +1 -1
  96. package/build/legacy/queryCache.d.ts +1 -1
  97. package/build/legacy/queryCache.js +34 -12
  98. package/build/legacy/queryCache.js.map +1 -1
  99. package/build/legacy/queryClient.cjs +104 -32
  100. package/build/legacy/queryClient.cjs.map +1 -1
  101. package/build/legacy/queryClient.d.cts +1 -1
  102. package/build/legacy/queryClient.d.ts +1 -1
  103. package/build/legacy/queryClient.js +104 -32
  104. package/build/legacy/queryClient.js.map +1 -1
  105. package/build/legacy/queryObserver.cjs +78 -6
  106. package/build/legacy/queryObserver.cjs.map +1 -1
  107. package/build/legacy/queryObserver.d.cts +1 -1
  108. package/build/legacy/queryObserver.d.ts +1 -1
  109. package/build/legacy/queryObserver.js +78 -6
  110. package/build/legacy/queryObserver.js.map +1 -1
  111. package/build/{modern/removable-0GzhW1PK.d.cts → legacy/removable-Cw9GNGyK.d.cts} +17 -1
  112. package/build/legacy/removable-Cw9GNGyK.d.cts.map +1 -0
  113. package/build/legacy/{removable-0GzhW1PK.d.cts → removable-Cw9GNGyK.d.ts} +17 -1
  114. package/build/legacy/removable-Cw9GNGyK.d.ts.map +1 -0
  115. package/build/legacy/removable.cjs +12 -0
  116. package/build/legacy/removable.cjs.map +1 -1
  117. package/build/legacy/removable.d.cts +1 -1
  118. package/build/legacy/removable.d.ts +1 -1
  119. package/build/legacy/removable.js +12 -0
  120. package/build/legacy/removable.js.map +1 -1
  121. package/build/legacy/retryer.cjs +26 -4
  122. package/build/legacy/retryer.cjs.map +1 -1
  123. package/build/legacy/retryer.d.cts +1 -1
  124. package/build/legacy/retryer.d.ts +1 -1
  125. package/build/legacy/retryer.js +26 -4
  126. package/build/legacy/retryer.js.map +1 -1
  127. package/build/legacy/streamedQuery.cjs +3 -1
  128. package/build/legacy/streamedQuery.cjs.map +1 -1
  129. package/build/legacy/streamedQuery.d.cts +4 -2
  130. package/build/legacy/streamedQuery.d.cts.map +1 -1
  131. package/build/legacy/streamedQuery.d.ts +4 -2
  132. package/build/legacy/streamedQuery.d.ts.map +1 -1
  133. package/build/legacy/streamedQuery.js +3 -1
  134. package/build/legacy/streamedQuery.js.map +1 -1
  135. package/build/{modern/subscribable-CysQ0tne.d.cts → legacy/subscribable-czlHOxMP.d.cts} +11 -1
  136. package/build/legacy/subscribable-czlHOxMP.d.cts.map +1 -0
  137. package/build/legacy/{subscribable-CysQ0tne.d.cts → subscribable-czlHOxMP.d.ts} +11 -1
  138. package/build/legacy/subscribable-czlHOxMP.d.ts.map +1 -0
  139. package/build/legacy/subscribable.cjs +10 -0
  140. package/build/legacy/subscribable.cjs.map +1 -1
  141. package/build/legacy/subscribable.d.cts +1 -1
  142. package/build/legacy/subscribable.d.ts +1 -1
  143. package/build/legacy/subscribable.js +10 -0
  144. package/build/legacy/subscribable.js.map +1 -1
  145. package/build/legacy/timeoutManager.cjs +11 -6
  146. package/build/legacy/timeoutManager.cjs.map +1 -1
  147. package/build/legacy/timeoutManager.d.cts +23 -6
  148. package/build/legacy/timeoutManager.d.cts.map +1 -1
  149. package/build/legacy/timeoutManager.d.ts +23 -6
  150. package/build/legacy/timeoutManager.d.ts.map +1 -1
  151. package/build/legacy/timeoutManager.js +11 -6
  152. package/build/legacy/timeoutManager.js.map +1 -1
  153. package/build/legacy/types.cjs.map +1 -1
  154. package/build/legacy/types.d.cts +1 -1
  155. package/build/legacy/types.d.ts +1 -1
  156. package/build/legacy/types.js.map +1 -1
  157. package/build/legacy/utils.cjs +117 -8
  158. package/build/legacy/utils.cjs.map +1 -1
  159. package/build/legacy/utils.d.cts +1 -1
  160. package/build/legacy/utils.d.ts +1 -1
  161. package/build/legacy/utils.js +117 -8
  162. package/build/legacy/utils.js.map +1 -1
  163. package/build/modern/environmentManager.cjs +3 -1
  164. package/build/modern/environmentManager.cjs.map +1 -1
  165. package/build/modern/environmentManager.d.cts +6 -1
  166. package/build/modern/environmentManager.d.cts.map +1 -1
  167. package/build/modern/environmentManager.d.ts +6 -1
  168. package/build/modern/environmentManager.d.ts.map +1 -1
  169. package/build/modern/environmentManager.js +3 -1
  170. package/build/modern/environmentManager.js.map +1 -1
  171. package/build/modern/focusManager.cjs +4 -2
  172. package/build/modern/focusManager.cjs.map +1 -1
  173. package/build/modern/focusManager.d.cts +5 -3
  174. package/build/modern/focusManager.d.cts.map +1 -1
  175. package/build/modern/focusManager.d.ts +5 -3
  176. package/build/modern/focusManager.d.ts.map +1 -1
  177. package/build/modern/focusManager.js +4 -2
  178. package/build/modern/focusManager.js.map +1 -1
  179. package/build/modern/{hydration-B9t5w6NC.d.ts → hydration-Bf0oMcwO.d.ts} +1411 -129
  180. package/build/modern/hydration-Bf0oMcwO.d.ts.map +1 -0
  181. package/build/modern/{hydration-Br9VIGXa.d.cts → hydration-C6zghADG.d.cts} +1411 -129
  182. package/build/modern/hydration-C6zghADG.d.cts.map +1 -0
  183. package/build/modern/hydration.cjs +35 -0
  184. package/build/modern/hydration.cjs.map +1 -1
  185. package/build/modern/hydration.d.cts +1 -1
  186. package/build/modern/hydration.d.ts +1 -1
  187. package/build/modern/hydration.js +35 -0
  188. package/build/modern/hydration.js.map +1 -1
  189. package/build/modern/index.d.cts +1 -1
  190. package/build/modern/index.d.ts +1 -1
  191. package/build/modern/infiniteQueryBehavior.cjs +29 -0
  192. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  193. package/build/modern/infiniteQueryBehavior.d.cts +16 -1
  194. package/build/modern/infiniteQueryBehavior.d.cts.map +1 -1
  195. package/build/modern/infiniteQueryBehavior.d.ts +16 -1
  196. package/build/modern/infiniteQueryBehavior.d.ts.map +1 -1
  197. package/build/modern/infiniteQueryBehavior.js +29 -0
  198. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  199. package/build/modern/infiniteQueryObserver.cjs +13 -7
  200. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  201. package/build/modern/infiniteQueryObserver.d.cts +15 -9
  202. package/build/modern/infiniteQueryObserver.d.cts.map +1 -1
  203. package/build/modern/infiniteQueryObserver.d.ts +15 -9
  204. package/build/modern/infiniteQueryObserver.d.ts.map +1 -1
  205. package/build/modern/infiniteQueryObserver.js +13 -7
  206. package/build/modern/infiniteQueryObserver.js.map +1 -1
  207. package/build/modern/mutation.cjs +27 -10
  208. package/build/modern/mutation.cjs.map +1 -1
  209. package/build/modern/mutation.d.cts +1 -1
  210. package/build/modern/mutation.d.ts +1 -1
  211. package/build/modern/mutation.js +27 -10
  212. package/build/modern/mutation.js.map +1 -1
  213. package/build/modern/mutationCache.cjs +53 -12
  214. package/build/modern/mutationCache.cjs.map +1 -1
  215. package/build/modern/mutationCache.d.cts +1 -1
  216. package/build/modern/mutationCache.d.ts +1 -1
  217. package/build/modern/mutationCache.js +53 -12
  218. package/build/modern/mutationCache.js.map +1 -1
  219. package/build/modern/mutationObserver.cjs +23 -12
  220. package/build/modern/mutationObserver.cjs.map +1 -1
  221. package/build/modern/mutationObserver.d.cts +1 -1
  222. package/build/modern/mutationObserver.d.ts +1 -1
  223. package/build/modern/mutationObserver.js +23 -12
  224. package/build/modern/mutationObserver.js.map +1 -1
  225. package/build/modern/notifyManager.cjs +12 -2
  226. package/build/modern/notifyManager.cjs.map +1 -1
  227. package/build/modern/notifyManager.d.cts +19 -4
  228. package/build/modern/notifyManager.d.cts.map +1 -1
  229. package/build/modern/notifyManager.d.ts +19 -4
  230. package/build/modern/notifyManager.d.ts.map +1 -1
  231. package/build/modern/notifyManager.js +12 -2
  232. package/build/modern/notifyManager.js.map +1 -1
  233. package/build/modern/onlineManager.cjs +4 -2
  234. package/build/modern/onlineManager.cjs.map +1 -1
  235. package/build/modern/onlineManager.d.cts +5 -3
  236. package/build/modern/onlineManager.d.cts.map +1 -1
  237. package/build/modern/onlineManager.d.ts +5 -3
  238. package/build/modern/onlineManager.d.ts.map +1 -1
  239. package/build/modern/onlineManager.js +4 -2
  240. package/build/modern/onlineManager.js.map +1 -1
  241. package/build/modern/queriesObserver.cjs +15 -3
  242. package/build/modern/queriesObserver.cjs.map +1 -1
  243. package/build/modern/queriesObserver.d.cts +14 -5
  244. package/build/modern/queriesObserver.d.cts.map +1 -1
  245. package/build/modern/queriesObserver.d.ts +14 -5
  246. package/build/modern/queriesObserver.d.ts.map +1 -1
  247. package/build/modern/queriesObserver.js +15 -3
  248. package/build/modern/queriesObserver.js.map +1 -1
  249. package/build/modern/query.cjs +89 -15
  250. package/build/modern/query.cjs.map +1 -1
  251. package/build/modern/query.d.cts +1 -1
  252. package/build/modern/query.d.ts +1 -1
  253. package/build/modern/query.js +89 -15
  254. package/build/modern/query.js.map +1 -1
  255. package/build/modern/queryCache.cjs +34 -12
  256. package/build/modern/queryCache.cjs.map +1 -1
  257. package/build/modern/queryCache.d.cts +1 -1
  258. package/build/modern/queryCache.d.ts +1 -1
  259. package/build/modern/queryCache.js +34 -12
  260. package/build/modern/queryCache.js.map +1 -1
  261. package/build/modern/queryClient.cjs +104 -32
  262. package/build/modern/queryClient.cjs.map +1 -1
  263. package/build/modern/queryClient.d.cts +1 -1
  264. package/build/modern/queryClient.d.ts +1 -1
  265. package/build/modern/queryClient.js +104 -32
  266. package/build/modern/queryClient.js.map +1 -1
  267. package/build/modern/queryObserver.cjs +78 -6
  268. package/build/modern/queryObserver.cjs.map +1 -1
  269. package/build/modern/queryObserver.d.cts +1 -1
  270. package/build/modern/queryObserver.d.ts +1 -1
  271. package/build/modern/queryObserver.js +78 -6
  272. package/build/modern/queryObserver.js.map +1 -1
  273. package/build/modern/{removable-0GzhW1PK.d.ts → removable-Cw9GNGyK.d.cts} +17 -1
  274. package/build/modern/removable-Cw9GNGyK.d.cts.map +1 -0
  275. package/build/{legacy/removable-0GzhW1PK.d.ts → modern/removable-Cw9GNGyK.d.ts} +17 -1
  276. package/build/modern/removable-Cw9GNGyK.d.ts.map +1 -0
  277. package/build/modern/removable.cjs +12 -0
  278. package/build/modern/removable.cjs.map +1 -1
  279. package/build/modern/removable.d.cts +1 -1
  280. package/build/modern/removable.d.ts +1 -1
  281. package/build/modern/removable.js +12 -0
  282. package/build/modern/removable.js.map +1 -1
  283. package/build/modern/retryer.cjs +26 -4
  284. package/build/modern/retryer.cjs.map +1 -1
  285. package/build/modern/retryer.d.cts +1 -1
  286. package/build/modern/retryer.d.ts +1 -1
  287. package/build/modern/retryer.js +26 -4
  288. package/build/modern/retryer.js.map +1 -1
  289. package/build/modern/streamedQuery.cjs +3 -1
  290. package/build/modern/streamedQuery.cjs.map +1 -1
  291. package/build/modern/streamedQuery.d.cts +4 -2
  292. package/build/modern/streamedQuery.d.cts.map +1 -1
  293. package/build/modern/streamedQuery.d.ts +4 -2
  294. package/build/modern/streamedQuery.d.ts.map +1 -1
  295. package/build/modern/streamedQuery.js +3 -1
  296. package/build/modern/streamedQuery.js.map +1 -1
  297. package/build/modern/{subscribable-CysQ0tne.d.ts → subscribable-czlHOxMP.d.cts} +11 -1
  298. package/build/modern/subscribable-czlHOxMP.d.cts.map +1 -0
  299. package/build/{legacy/subscribable-CysQ0tne.d.ts → modern/subscribable-czlHOxMP.d.ts} +11 -1
  300. package/build/modern/subscribable-czlHOxMP.d.ts.map +1 -0
  301. package/build/modern/subscribable.cjs +10 -0
  302. package/build/modern/subscribable.cjs.map +1 -1
  303. package/build/modern/subscribable.d.cts +1 -1
  304. package/build/modern/subscribable.d.ts +1 -1
  305. package/build/modern/subscribable.js +10 -0
  306. package/build/modern/subscribable.js.map +1 -1
  307. package/build/modern/timeoutManager.cjs +11 -6
  308. package/build/modern/timeoutManager.cjs.map +1 -1
  309. package/build/modern/timeoutManager.d.cts +23 -6
  310. package/build/modern/timeoutManager.d.cts.map +1 -1
  311. package/build/modern/timeoutManager.d.ts +23 -6
  312. package/build/modern/timeoutManager.d.ts.map +1 -1
  313. package/build/modern/timeoutManager.js +11 -6
  314. package/build/modern/timeoutManager.js.map +1 -1
  315. package/build/modern/types.cjs.map +1 -1
  316. package/build/modern/types.d.cts +1 -1
  317. package/build/modern/types.d.ts +1 -1
  318. package/build/modern/types.js.map +1 -1
  319. package/build/modern/utils.cjs +117 -8
  320. package/build/modern/utils.cjs.map +1 -1
  321. package/build/modern/utils.d.cts +1 -1
  322. package/build/modern/utils.d.ts +1 -1
  323. package/build/modern/utils.js +117 -8
  324. package/build/modern/utils.js.map +1 -1
  325. package/package.json +3 -3
  326. package/src/environmentManager.ts +6 -1
  327. package/src/focusManager.ts +8 -6
  328. package/src/hydration.ts +42 -1
  329. package/src/infiniteQueryBehavior.ts +29 -0
  330. package/src/infiniteQueryObserver.ts +20 -14
  331. package/src/mutation.ts +32 -11
  332. package/src/mutationCache.ts +53 -12
  333. package/src/mutationObserver.ts +29 -14
  334. package/src/notifyManager.ts +12 -2
  335. package/src/onlineManager.ts +7 -5
  336. package/src/queriesObserver.ts +20 -5
  337. package/src/query.ts +153 -20
  338. package/src/queryCache.ts +54 -13
  339. package/src/queryClient.ts +114 -42
  340. package/src/queryObserver.ts +88 -12
  341. package/src/removable.ts +16 -0
  342. package/src/retryer.ts +57 -4
  343. package/src/streamedQuery.ts +4 -3
  344. package/src/subscribable.ts +10 -0
  345. package/src/timeoutManager.ts +23 -6
  346. package/src/types.ts +801 -27
  347. package/src/utils.ts +130 -10
  348. package/build/legacy/hydration-B9t5w6NC.d.ts.map +0 -1
  349. package/build/legacy/hydration-Br9VIGXa.d.cts.map +0 -1
  350. package/build/legacy/removable-0GzhW1PK.d.cts.map +0 -1
  351. package/build/legacy/removable-0GzhW1PK.d.ts.map +0 -1
  352. package/build/legacy/subscribable-CysQ0tne.d.cts.map +0 -1
  353. package/build/legacy/subscribable-CysQ0tne.d.ts.map +0 -1
  354. package/build/modern/hydration-B9t5w6NC.d.ts.map +0 -1
  355. package/build/modern/hydration-Br9VIGXa.d.cts.map +0 -1
  356. package/build/modern/removable-0GzhW1PK.d.cts.map +0 -1
  357. package/build/modern/removable-0GzhW1PK.d.ts.map +0 -1
  358. package/build/modern/subscribable-CysQ0tne.d.cts.map +0 -1
  359. package/build/modern/subscribable-CysQ0tne.d.ts.map +0 -1
@@ -14,7 +14,6 @@ const require_query = require("./query.cjs");
14
14
  * the primitive that framework adapters (e.g. `useQuery`) build their hooks
15
15
  * on top of, but it can also be used directly to observe and switch between
16
16
  * queries outside of any framework.
17
- *
18
17
  * @example
19
18
  * ```ts
20
19
  * const observer = new QueryObserver(queryClient, {
@@ -50,6 +49,10 @@ var QueryObserver = class extends require_subscribable.Subscribable {
50
49
  this.bindMethods();
51
50
  this.setOptions(options);
52
51
  }
52
+ /**
53
+ * Binds the methods of the result (`refetch`) to the observer, so they keep working when destructured
54
+ * from it. Subclasses override it to bind their own result methods as well.
55
+ */
53
56
  bindMethods() {
54
57
  this.refetch = this.refetch.bind(this);
55
58
  }
@@ -68,6 +71,7 @@ var QueryObserver = class extends require_subscribable.Subscribable {
68
71
  * Returns whether the observed query is currently stale and configured
69
72
  * (via the `refetchOnReconnect` option) to refetch when the network
70
73
  * reconnects.
74
+ * @returns `true` if the observer should refetch the query on reconnect.
71
75
  */
72
76
  shouldFetchOnReconnect() {
73
77
  return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
@@ -76,6 +80,7 @@ var QueryObserver = class extends require_subscribable.Subscribable {
76
80
  * Returns whether the observed query is currently stale and configured
77
81
  * (via the `refetchOnWindowFocus` option) to refetch when the window
78
82
  * regains focus.
83
+ * @returns `true` if the observer should refetch the query on window focus.
79
84
  */
80
85
  shouldFetchOnWindowFocus() {
81
86
  return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
@@ -97,7 +102,9 @@ var QueryObserver = class extends require_subscribable.Subscribable {
97
102
  * trigger a fetch if the new options require one and the observer has
98
103
  * subscribers, recompute the current result, and reschedule the stale and
99
104
  * refetch-interval timers as needed.
100
- *
105
+ * @param options - The new observer options. They are defaulted with {@link
106
+ * QueryClient#defaultQueryOptions} before being applied.
107
+ * @throws {Error} If `enabled` is neither a boolean nor a function.
101
108
  * @example
102
109
  * ```ts
103
110
  * observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
@@ -129,6 +136,8 @@ var QueryObserver = class extends require_subscribable.Subscribable {
129
136
  * right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
130
137
  * subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
131
138
  * returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
139
+ * @param options - The defaulted observer options to compute the result for.
140
+ * @returns The result for the given options.
132
141
  */
133
142
  getOptimisticResult(options) {
134
143
  const query = this.#client.getQueryCache().build(this.#client, options);
@@ -145,7 +154,7 @@ var QueryObserver = class extends require_subscribable.Subscribable {
145
154
  * observed query. This is a point-in-time read; to be notified of updates
146
155
  * as they happen, subscribe to the observer instead (its inherited
147
156
  * `subscribe` method).
148
- *
157
+ * @returns The observer's latest result.
149
158
  * @example
150
159
  * ```ts
151
160
  * const result = observer.getCurrentResult()
@@ -160,6 +169,9 @@ var QueryObserver = class extends require_subscribable.Subscribable {
160
169
  * {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
161
170
  * adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
162
171
  * properties you actually read" behavior.
172
+ * @param result - The result to wrap.
173
+ * @param onPropTracked - Called with the name of each property that is read.
174
+ * @returns A proxy of `result` that tracks property reads.
163
175
  */
164
176
  trackResult(result, onPropTracked) {
165
177
  return new Proxy(result, { get: (target, key) => {
@@ -173,12 +185,14 @@ var QueryObserver = class extends require_subscribable.Subscribable {
173
185
  * notifies this observer if a tracked property actually changed. Normally called indirectly via
174
186
  * {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
175
187
  * access themselves (e.g. through their own reactivity system) instead of via the proxy.
188
+ * @param key - The name of the property that was read.
176
189
  */
177
190
  trackProp(key) {
178
191
  this.#trackedProps.add(key);
179
192
  }
180
193
  /**
181
194
  * Returns the `Query` instance this observer is currently observing.
195
+ * @returns The observed query.
182
196
  */
183
197
  getCurrentQuery() {
184
198
  return this.#currentQuery;
@@ -186,7 +200,9 @@ var QueryObserver = class extends require_subscribable.Subscribable {
186
200
  /**
187
201
  * Refetches the observed query and returns a promise that resolves with
188
202
  * the resulting `QueryObserverResult`.
189
- *
203
+ * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
204
+ * it, and `throwOnError` to `true` to reject when the refetch fails.
205
+ * @returns A promise that resolves with the result after the refetch.
190
206
  * @example
191
207
  * ```ts
192
208
  * const result = await observer.refetch({ cancelRefetch: false })
@@ -202,7 +218,8 @@ var QueryObserver = class extends require_subscribable.Subscribable {
202
218
  * resolves with the `QueryObserverResult` for that fetch. This is useful
203
219
  * for prefetching data that another observer (e.g. a query about to be
204
220
  * navigated to) will need, ahead of time.
205
- *
221
+ * @param options - The observer options of the query to fetch.
222
+ * @returns A promise that resolves with the result for the fetched query.
206
223
  * @example
207
224
  * ```ts
208
225
  * const result = await observer.fetchOptimistic({
@@ -234,6 +251,12 @@ var QueryObserver = class extends require_subscribable.Subscribable {
234
251
  unsubscribe();
235
252
  }), cachePromise]);
236
253
  }
254
+ /**
255
+ * Fetches the observed query and updates the result once the fetch settles. Used by `refetch` and,
256
+ * in `InfiniteQueryObserver`, to fetch more pages.
257
+ * @param fetchOptions - Options for this fetch. `cancelRefetch` defaults to `true`.
258
+ * @returns A promise that resolves with the updated result.
259
+ */
237
260
  fetch(fetchOptions) {
238
261
  return this.#executeFetch({
239
262
  ...fetchOptions,
@@ -288,6 +311,13 @@ var QueryObserver = class extends require_subscribable.Subscribable {
288
311
  this.#refetchIntervalId = void 0;
289
312
  }
290
313
  }
314
+ /**
315
+ * Computes the result for a query and options from the query's state, applying `select`,
316
+ * `placeholderData`, and the derived flags. Subclasses override it to add their own fields.
317
+ * @param query - The query to compute the result for.
318
+ * @param options - The observer options to compute the result with.
319
+ * @returns The computed result.
320
+ */
291
321
  createResult(query, options) {
292
322
  const prevQuery = this.#currentQuery;
293
323
  const prevOptions = this.options;
@@ -423,18 +453,45 @@ var QueryObserver = class extends require_subscribable.Subscribable {
423
453
  query.addObserver(this);
424
454
  }
425
455
  }
426
- /** @internal */
456
+ /**
457
+ * Updates the observer's result when the observed query changes, and reschedules its timers if it
458
+ * has listeners.
459
+ * @internal
460
+ */
427
461
  onQueryUpdate() {
428
462
  this.updateResult();
429
463
  if (this.hasListeners()) this.#updateTimers();
430
464
  }
431
465
  };
466
+ /**
467
+ * Checks whether a query has no data yet and should do its initial load when an observer mounts.
468
+ * @param query - The query to check.
469
+ * @param options - The observer options.
470
+ * @returns `true` if the query is enabled, has no data, and isn't in an error state with
471
+ * `retryOnMount: false`.
472
+ */
432
473
  function shouldLoadOnMount(query, options) {
433
474
  return require_utils.resolveQueryValue(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && require_utils.resolveQueryValue(options.retryOnMount, query) === false);
434
475
  }
476
+ /**
477
+ * Checks whether a query should fetch when an observer mounts: either for its initial load, or
478
+ * because it has data and `refetchOnMount` asks for a refetch.
479
+ * @param query - The query to check.
480
+ * @param options - The observer options.
481
+ * @returns `true` if the query should fetch on mount.
482
+ */
435
483
  function shouldFetchOnMount(query, options) {
436
484
  return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
437
485
  }
486
+ /**
487
+ * Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or
488
+ * `refetchOnReconnect` option.
489
+ * @param query - The query to check.
490
+ * @param options - The observer options.
491
+ * @param field - The value of the option to check.
492
+ * @returns `true` if the query is enabled, not static, and the option is `'always'`, or is not
493
+ * `false` and the query is stale.
494
+ */
438
495
  function shouldFetchOn(query, options, field) {
439
496
  if (require_utils.resolveQueryValue(options.enabled, query) !== false && require_utils.resolveQueryValue(options.staleTime, query) !== "static") {
440
497
  const value = require_utils.resolveQueryValue(field, query);
@@ -442,9 +499,24 @@ function shouldFetchOn(query, options, field) {
442
499
  }
443
500
  return false;
444
501
  }
502
+ /**
503
+ * Checks whether a query should fetch after the observer's options change.
504
+ * @param query - The query observed with the new options.
505
+ * @param prevQuery - The query observed with the previous options.
506
+ * @param options - The new observer options.
507
+ * @param prevOptions - The previous observer options.
508
+ * @returns `true` if the query changed or was disabled before, it isn't a suspense query in an
509
+ * error state, and it is stale.
510
+ */
445
511
  function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
446
512
  return (query !== prevQuery || require_utils.resolveQueryValue(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
447
513
  }
514
+ /**
515
+ * Checks whether a query is stale for the given observer options.
516
+ * @param query - The query to check.
517
+ * @param options - The observer options, whose `enabled` and `staleTime` are used.
518
+ * @returns `true` if the query is enabled and its data is stale for `staleTime`.
519
+ */
448
520
  function isStale(query, options) {
449
521
  return require_utils.resolveQueryValue(options.enabled, query) !== false && query.isStaleByTime(require_utils.resolveQueryValue(options.staleTime, query));
450
522
  }
@@ -1 +1 @@
1
- {"version":3,"file":"queryObserver.cjs","names":["Subscribable","resolveQueryValue","shallowEqualObjects","noop","isServerEnvironment","isValidTimeout","timeUntilStale","timeoutManager","focusManager","fetchState","replaceData"],"sources":["../../src/queryObserver.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { isServer as isServerEnvironment } from './environmentManager'\nimport { notifyManager } from './notifyManager'\nimport { fetchState } from './query'\nimport { Subscribable } from './subscribable'\nimport {\n isValidTimeout,\n noop,\n replaceData,\n resolveQueryValue,\n shallowEqualObjects,\n timeUntilStale,\n} from './utils'\nimport { timeoutManager } from './timeoutManager'\nimport type { ManagedTimerId } from './timeoutManager'\nimport type { FetchOptions, Query, QueryState } from './query'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n DefaultedQueryObserverOptions,\n PlaceholderDataFunction,\n QueryKey,\n QueryObserverBaseResult,\n QueryObserverOptions,\n QueryObserverResult,\n RefetchOptions,\n} from './types'\n\ntype QueryObserverListener<TData, TError> = (\n result: QueryObserverResult<TData, TError>,\n) => void\n\ninterface ObserverFetchOptions extends FetchOptions {\n throwOnError?: boolean\n}\n\n/**\n * A `QueryObserver` watches a single query in the `QueryCache` and computes a\n * `QueryObserverResult` from its state, recomputing and notifying subscribers\n * whenever the underlying query (or the observer's options) changes. It is\n * the primitive that framework adapters (e.g. `useQuery`) build their hooks\n * on top of, but it can also be used directly to observe and switch between\n * queries outside of any framework.\n *\n * @example\n * ```ts\n * const observer = new QueryObserver(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * const unsubscribe = observer.subscribe((result) => {\n * console.log(result.data)\n * })\n * ```\n */\nexport class QueryObserver<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Subscribable<QueryObserverListener<TData, TError>> {\n #client: QueryClient\n #currentQuery: Query<TQueryFnData, TError, TQueryData, TQueryKey> = undefined!\n #currentQueryInitialState: QueryState<TQueryData, TError> = undefined!\n #currentResult: QueryObserverResult<TData, TError> = undefined!\n #currentResultState?: QueryState<TQueryData, TError>\n #currentResultOptions?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n #selectError: TError | null\n #selectFn?: (data: TQueryData) => TData\n #selectResult?: TData\n // This property keeps track of the last query with defined data.\n // It will be used to pass the previous data and query to the placeholder function between renders.\n #lastQueryWithDefinedData?: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n #staleTimeoutId?: ManagedTimerId\n #refetchIntervalId?: ManagedTimerId\n #currentRefetchInterval?: number | false\n #trackedProps = new Set<keyof QueryObserverResult>()\n\n constructor(\n client: QueryClient,\n public options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ) {\n super()\n\n this.#client = client\n this.#selectError = null\n\n this.bindMethods()\n this.setOptions(options)\n }\n\n protected bindMethods(): void {\n this.refetch = this.refetch.bind(this)\n }\n\n protected onSubscribe(): void {\n if (this.listeners.size === 1) {\n this.#currentQuery.addObserver(this)\n\n if (shouldFetchOnMount(this.#currentQuery, this.options)) {\n this.#executeFetch()\n } else {\n this.updateResult()\n }\n\n this.#updateTimers()\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.destroy()\n }\n }\n\n /**\n * Returns whether the observed query is currently stale and configured\n * (via the `refetchOnReconnect` option) to refetch when the network\n * reconnects.\n */\n shouldFetchOnReconnect(): boolean {\n return shouldFetchOn(\n this.#currentQuery,\n this.options,\n this.options.refetchOnReconnect,\n )\n }\n\n /**\n * Returns whether the observed query is currently stale and configured\n * (via the `refetchOnWindowFocus` option) to refetch when the window\n * regains focus.\n */\n shouldFetchOnWindowFocus(): boolean {\n return shouldFetchOn(\n this.#currentQuery,\n this.options,\n this.options.refetchOnWindowFocus,\n )\n }\n\n /**\n * Stops observing the current query: clears all listeners, cancels the\n * stale and refetch-interval timers, and removes this observer from the\n * query it was observing.\n */\n destroy(): void {\n this.listeners = new Set()\n this.#clearStaleTimeout()\n this.#clearRefetchInterval()\n this.#currentQuery.removeObserver(this)\n }\n\n /**\n * Updates the observer's options. This will re-resolve the query being\n * observed (switching to a different query if the `queryKey` changed),\n * trigger a fetch if the new options require one and the observer has\n * subscribers, recompute the current result, and reschedule the stale and\n * refetch-interval timers as needed.\n *\n * @example\n * ```ts\n * observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })\n * // later: switch to a different query, reusing the same observer\n * observer.setOptions({ queryKey: ['posts', 2], queryFn: () => fetchPost(2) })\n * ```\n */\n setOptions(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): void {\n const prevOptions = this.options\n const prevQuery = this.#currentQuery\n\n this.options = this.#client.defaultQueryOptions(options)\n\n if (\n this.options.enabled !== undefined &&\n typeof this.options.enabled !== 'boolean' &&\n typeof this.options.enabled !== 'function' &&\n typeof resolveQueryValue(this.options.enabled, this.#currentQuery) !==\n 'boolean'\n ) {\n throw new Error(\n 'Expected enabled to be a boolean or a callback that returns a boolean',\n )\n }\n\n this.#updateQuery()\n this.#currentQuery.setOptions(this.options)\n\n if (\n prevOptions._defaulted &&\n !shallowEqualObjects(this.options, prevOptions)\n ) {\n this.#client.getQueryCache().notify({\n type: 'observerOptionsUpdated',\n query: this.#currentQuery,\n observer: this,\n })\n }\n\n const mounted = this.hasListeners()\n\n // Fetch if there are subscribers\n if (\n mounted &&\n shouldFetchOptionally(\n this.#currentQuery,\n prevQuery,\n this.options,\n prevOptions,\n )\n ) {\n this.#executeFetch()\n }\n\n // Update result\n this.updateResult()\n\n // Update stale interval if needed\n if (\n mounted &&\n (this.#currentQuery !== prevQuery ||\n resolveQueryValue(this.options.enabled, this.#currentQuery) !==\n resolveQueryValue(prevOptions.enabled, this.#currentQuery) ||\n resolveQueryValue(this.options.staleTime, this.#currentQuery) !==\n resolveQueryValue(prevOptions.staleTime, this.#currentQuery))\n ) {\n this.#updateStaleTimeout()\n }\n\n const nextRefetchInterval = this.#computeRefetchInterval()\n\n // Update refetch interval if needed\n if (\n mounted &&\n (this.#currentQuery !== prevQuery ||\n resolveQueryValue(this.options.enabled, this.#currentQuery) !==\n resolveQueryValue(prevOptions.enabled, this.#currentQuery) ||\n nextRefetchInterval !== this.#currentRefetchInterval)\n ) {\n this.#updateRefetchInterval(nextRefetchInterval)\n }\n }\n\n /**\n * Computes the result the observer would produce for the given (already-defaulted) options\n * right now, building the underlying `Query` if it doesn't exist yet, without waiting for a\n * subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the\n * returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.\n */\n getOptimisticResult(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const query = this.#client.getQueryCache().build(this.#client, options)\n\n const result = this.createResult(query, options)\n\n if (!shallowEqualObjects(this.getCurrentResult(), result)) {\n // this assigns the optimistic result to the current Observer\n // because if the query function changes, useQuery will be performing\n // an effect where it would fetch again.\n // When the fetch finishes, we perform a deep data cloning in order\n // to reuse objects references. This deep data clone is performed against\n // the `observer.currentResult.data` property\n // When QueryKey changes, we refresh the query and get new `optimistic`\n // result, while we leave the `observer.currentResult`, so when new data\n // arrives, it finds the old `observer.currentResult` which is related\n // to the old QueryKey. Which means that currentResult and selectData are\n // out of sync already.\n // To solve this, we move the cursor of the currentResult every time\n // an observer reads an optimistic value.\n\n // When keeping the previous data, the result doesn't change until new\n // data arrives.\n this.#currentResult = result\n this.#currentResultOptions = this.options\n this.#currentResultState = this.#currentQuery.state\n }\n return result\n }\n\n /**\n * Returns the most recently computed `QueryObserverResult` for the\n * observed query. This is a point-in-time read; to be notified of updates\n * as they happen, subscribe to the observer instead (its inherited\n * `subscribe` method).\n *\n * @example\n * ```ts\n * const result = observer.getCurrentResult()\n * console.log(result.status, result.data)\n * ```\n */\n getCurrentResult(): QueryObserverResult<TData, TError> {\n return this.#currentResult\n }\n\n /**\n * Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via\n * {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework\n * adapters when `notifyOnChangeProps` is not set, to implement its default \"only re-render on\n * properties you actually read\" behavior.\n */\n trackResult(\n result: QueryObserverResult<TData, TError>,\n onPropTracked?: (key: keyof QueryObserverResult) => void,\n ): QueryObserverResult<TData, TError> {\n return new Proxy(result, {\n get: (target, key) => {\n this.trackProp(key as keyof QueryObserverResult)\n onPropTracked?.(key as keyof QueryObserverResult)\n return Reflect.get(target, key)\n },\n })\n }\n\n /**\n * Records that the given `QueryObserverResult` property was read, so a subsequent update only\n * notifies this observer if a tracked property actually changed. Normally called indirectly via\n * {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property\n * access themselves (e.g. through their own reactivity system) instead of via the proxy.\n */\n trackProp(key: keyof QueryObserverResult) {\n this.#trackedProps.add(key)\n }\n\n /**\n * Returns the `Query` instance this observer is currently observing.\n */\n getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {\n return this.#currentQuery\n }\n\n /**\n * Refetches the observed query and returns a promise that resolves with\n * the resulting `QueryObserverResult`.\n *\n * @example\n * ```ts\n * const result = await observer.refetch({ cancelRefetch: false })\n * console.log(result.data)\n * ```\n */\n refetch({ ...options }: RefetchOptions = {}): Promise<\n QueryObserverResult<TData, TError>\n > {\n return this.fetch({\n ...options,\n })\n }\n\n /**\n * Fetches a query defined by the given options without affecting this\n * observer's own tracked query or result, and returns a promise that\n * resolves with the `QueryObserverResult` for that fetch. This is useful\n * for prefetching data that another observer (e.g. a query about to be\n * navigated to) will need, ahead of time.\n *\n * @example\n * ```ts\n * const result = await observer.fetchOptimistic({\n * queryKey: ['posts', 2],\n * queryFn: () => fetchPost(2),\n * })\n * console.log(result.data)\n * ```\n */\n fetchOptimistic(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): Promise<QueryObserverResult<TData, TError>> {\n const defaultedOptions = this.#client.defaultQueryOptions(options)\n\n const query = this.#client\n .getQueryCache()\n .build(this.#client, defaultedOptions)\n\n let unsubscribe = () => {}\n let resolveEarly:\n ((result: QueryObserverResult<TData, TError>) => void) | undefined\n\n const cachePromise = new Promise<QueryObserverResult<TData, TError>>(\n (resolve) => {\n resolveEarly = resolve\n unsubscribe = this.#client.getQueryCache().subscribe((event) => {\n if (\n event.type === 'updated' &&\n event.query.queryHash === query.queryHash &&\n query.state.data !== undefined\n ) {\n unsubscribe()\n resolve(this.createResult(query, defaultedOptions))\n }\n })\n },\n )\n\n return Promise.race([\n query\n .fetch()\n .then(() => {\n const result = this.createResult(query, defaultedOptions)\n // Settle the subscriber promise so both branches always settle.\n // This value is ignored by Promise.race since the fetch branch already won.\n resolveEarly?.(result)\n return result\n })\n .finally(() => {\n unsubscribe()\n }),\n cachePromise,\n ])\n }\n\n protected fetch(\n fetchOptions: ObserverFetchOptions,\n ): Promise<QueryObserverResult<TData, TError>> {\n return this.#executeFetch({\n ...fetchOptions,\n cancelRefetch: fetchOptions.cancelRefetch ?? true,\n }).then(() => {\n this.updateResult()\n return this.#currentResult\n })\n }\n\n #executeFetch(\n fetchOptions?: Omit<ObserverFetchOptions, 'initialPromise'>,\n ): Promise<TQueryData | undefined> {\n // Make sure we reference the latest query as the current one might have been removed\n this.#updateQuery()\n\n // Fetch\n let promise: Promise<TQueryData | undefined> = this.#currentQuery.fetch(\n this.options,\n fetchOptions,\n )\n\n if (!fetchOptions?.throwOnError) {\n promise = promise.catch(noop)\n }\n\n return promise\n }\n\n #shouldScheduleTimer(timeout: unknown): timeout is number {\n return (\n !isServerEnvironment() &&\n resolveQueryValue(this.options.enabled, this.#currentQuery) !== false &&\n isValidTimeout(timeout)\n )\n }\n\n #updateStaleTimeout(): void {\n this.#clearStaleTimeout()\n const staleTime = resolveQueryValue(\n this.options.staleTime,\n this.#currentQuery,\n )\n\n if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) {\n return\n }\n\n const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)\n\n // The timeout is sometimes triggered 1 ms before the stale time expiration.\n // To mitigate this issue we always add 1 ms to the timeout.\n const timeout = time + 1\n\n this.#staleTimeoutId = timeoutManager.setTimeout(() => {\n if (!this.#currentResult.isStale) {\n this.updateResult()\n }\n }, timeout)\n }\n\n #computeRefetchInterval() {\n return (\n resolveQueryValue(this.options.refetchInterval, this.#currentQuery) ??\n false\n )\n }\n\n #updateRefetchInterval(nextInterval: number | false): void {\n this.#clearRefetchInterval()\n\n this.#currentRefetchInterval = nextInterval\n\n if (\n this.#currentRefetchInterval === 0 ||\n !this.#shouldScheduleTimer(this.#currentRefetchInterval)\n ) {\n return\n }\n\n this.#refetchIntervalId = timeoutManager.setInterval(() => {\n if (\n this.options.refetchIntervalInBackground ||\n focusManager.isFocused()\n ) {\n this.#executeFetch()\n }\n }, this.#currentRefetchInterval)\n }\n\n #updateTimers(): void {\n this.#updateStaleTimeout()\n this.#updateRefetchInterval(this.#computeRefetchInterval())\n }\n\n #clearStaleTimeout(): void {\n if (this.#staleTimeoutId !== undefined) {\n timeoutManager.clearTimeout(this.#staleTimeoutId)\n this.#staleTimeoutId = undefined\n }\n }\n\n #clearRefetchInterval(): void {\n if (this.#refetchIntervalId !== undefined) {\n timeoutManager.clearInterval(this.#refetchIntervalId)\n this.#refetchIntervalId = undefined\n }\n }\n\n protected createResult(\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const prevQuery = this.#currentQuery\n const prevOptions = this.options\n const prevResult = this.#currentResult as\n QueryObserverResult<TData, TError> | undefined\n const prevResultState = this.#currentResultState\n const prevResultOptions = this.#currentResultOptions\n const queryChange = query !== prevQuery\n const queryInitialState = queryChange\n ? query.state\n : this.#currentQueryInitialState\n\n const { state } = query\n let newState = { ...state }\n let isPlaceholderData = false\n let data: TData | undefined\n\n // Optimistically set result in fetching state if needed\n if (options._optimisticResults) {\n const mounted = this.hasListeners()\n\n const fetchOnMount = !mounted && shouldFetchOnMount(query, options)\n\n const fetchOptionally =\n mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)\n\n if (fetchOnMount || fetchOptionally) {\n newState = {\n ...newState,\n ...fetchState(state.data, query.options),\n }\n }\n if (options._optimisticResults === 'isRestoring') {\n newState.fetchStatus = 'idle'\n }\n }\n\n let { error, errorUpdatedAt, status } = newState\n\n // Per default, use query data\n data = newState.data as unknown as TData\n let skipSelect = false\n\n // use placeholderData if needed\n if (\n options.placeholderData !== undefined &&\n data === undefined &&\n status === 'pending'\n ) {\n let placeholderData\n\n // Memoize placeholder data\n if (\n prevResult?.isPlaceholderData &&\n options.placeholderData === prevResultOptions?.placeholderData\n ) {\n placeholderData = prevResult.data\n // we have to skip select when reading this memoization\n // because prevResult.data is already \"selected\"\n skipSelect = true\n } else {\n // compute placeholderData\n placeholderData =\n typeof options.placeholderData === 'function'\n ? (\n options.placeholderData as unknown as PlaceholderDataFunction<TQueryData>\n )(\n this.#lastQueryWithDefinedData?.state.data,\n this.#lastQueryWithDefinedData as any,\n )\n : options.placeholderData\n }\n\n if (placeholderData !== undefined) {\n status = 'success'\n data = replaceData(\n prevResult?.data,\n placeholderData as unknown,\n options,\n ) as TData\n isPlaceholderData = true\n }\n }\n\n // Select data if needed\n // this also runs placeholderData through the select function\n if (options.select && data !== undefined && !skipSelect) {\n // Memoize select result\n if (\n prevResult &&\n data === prevResultState?.data &&\n options.select === this.#selectFn\n ) {\n data = this.#selectResult\n } else {\n try {\n this.#selectFn = options.select\n data = options.select(data as any)\n data = replaceData(prevResult?.data, data, options)\n this.#selectResult = data\n this.#selectError = null\n } catch (selectError) {\n this.#selectError = selectError as TError\n }\n }\n } else if (data === undefined) {\n // a stored select error belongs to previously selected data; once that\n // data is gone (query switch or reset), it must not leak into this result\n this.#selectError = null\n }\n\n if (this.#selectError) {\n error = this.#selectError\n data = this.#selectResult\n errorUpdatedAt = Date.now()\n status = 'error'\n isPlaceholderData = false\n }\n\n const isFetching = newState.fetchStatus === 'fetching'\n const isPending = status === 'pending'\n const isError = status === 'error'\n\n const isLoading = isPending && isFetching\n const hasData = data !== undefined\n\n const result: QueryObserverBaseResult<TData, TError> = {\n status,\n fetchStatus: newState.fetchStatus,\n isPending,\n isSuccess: status === 'success',\n isError,\n isInitialLoading: isLoading,\n isLoading,\n data,\n dataUpdatedAt: newState.dataUpdatedAt,\n error,\n errorUpdatedAt,\n failureCount: newState.fetchFailureCount,\n failureReason: newState.fetchFailureReason,\n errorUpdateCount: newState.errorUpdateCount,\n isFetched: query.isFetched(),\n isFetchedAfterMount:\n newState.dataUpdateCount > queryInitialState.dataUpdateCount ||\n newState.errorUpdateCount > queryInitialState.errorUpdateCount,\n isFetching,\n isRefetching: isFetching && !isPending,\n isLoadingError: isError && !hasData,\n isPaused: newState.fetchStatus === 'paused',\n isPlaceholderData,\n isRefetchError: isError && hasData,\n isStale: isStale(query, options),\n refetch: this.refetch,\n isEnabled: resolveQueryValue(options.enabled, query) !== false,\n }\n\n const nextResult = result as QueryObserverResult<TData, TError>\n\n return nextResult\n }\n\n /**\n * Recomputes and stores the current result from the current query/options, notifying listeners\n * if it changed. Framework adapters call this right after subscribing to make sure no query\n * update was missed in the gap between creating the observer and subscribing to it.\n */\n updateResult(): void {\n const prevResult = this.#currentResult as\n QueryObserverResult<TData, TError> | undefined\n\n const nextResult = this.createResult(this.#currentQuery, this.options)\n\n this.#currentResultState = this.#currentQuery.state\n this.#currentResultOptions = this.options\n\n if (this.#currentResultState.data !== undefined) {\n this.#lastQueryWithDefinedData = this.#currentQuery\n }\n\n // Only notify and update result if something has changed\n if (shallowEqualObjects(nextResult, prevResult)) {\n return\n }\n\n this.#currentResult = nextResult\n\n const shouldNotifyListeners = (): boolean => {\n if (!prevResult) {\n return true\n }\n\n const { notifyOnChangeProps } = this.options\n const notifyOnChangePropsValue =\n typeof notifyOnChangeProps === 'function'\n ? notifyOnChangeProps()\n : notifyOnChangeProps\n\n if (\n notifyOnChangePropsValue === 'all' ||\n (!notifyOnChangePropsValue && !this.#trackedProps.size)\n ) {\n return true\n }\n\n const includedProps = new Set(\n notifyOnChangePropsValue ?? this.#trackedProps,\n )\n\n if (this.options.throwOnError) {\n includedProps.add('error')\n }\n\n return Object.keys(this.#currentResult).some((key) => {\n const typedKey = key as keyof QueryObserverResult\n const changed = this.#currentResult[typedKey] !== prevResult[typedKey]\n\n return changed && includedProps.has(typedKey)\n })\n }\n\n const notifyListeners = shouldNotifyListeners()\n\n notifyManager.batch(() => {\n // First, trigger the listeners\n if (notifyListeners) {\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n }\n\n // Then the cache listeners\n this.#client.getQueryCache().notify({\n query: this.#currentQuery,\n type: 'observerResultsUpdated',\n })\n })\n }\n\n #updateQuery(): void {\n const query = this.#client.getQueryCache().build(this.#client, this.options)\n\n if (query === this.#currentQuery) {\n return\n }\n\n const prevQuery = this.#currentQuery as\n Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined\n this.#currentQuery = query\n this.#currentQueryInitialState = query.state\n\n if (this.hasListeners()) {\n prevQuery?.removeObserver(this)\n query.addObserver(this)\n }\n }\n\n /** @internal */\n onQueryUpdate(): void {\n this.updateResult()\n\n if (this.hasListeners()) {\n this.#updateTimers()\n }\n }\n}\n\nfunction shouldLoadOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any>,\n): boolean {\n return (\n resolveQueryValue(options.enabled, query) !== false &&\n query.state.data === undefined &&\n !(\n query.state.status === 'error' &&\n resolveQueryValue(options.retryOnMount, query) === false\n )\n )\n}\n\nfunction shouldFetchOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n shouldLoadOnMount(query, options) ||\n (query.state.data !== undefined &&\n shouldFetchOn(query, options, options.refetchOnMount))\n )\n}\n\nfunction shouldFetchOn(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n field: (typeof options)['refetchOnMount'] &\n (typeof options)['refetchOnWindowFocus'] &\n (typeof options)['refetchOnReconnect'],\n) {\n if (\n resolveQueryValue(options.enabled, query) !== false &&\n resolveQueryValue(options.staleTime, query) !== 'static'\n ) {\n const value = resolveQueryValue(field, query)\n\n return value === 'always' || (value !== false && isStale(query, options))\n }\n return false\n}\n\nfunction shouldFetchOptionally(\n query: Query<any, any, any, any>,\n prevQuery: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n prevOptions: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n (query !== prevQuery ||\n resolveQueryValue(prevOptions.enabled, query) === false) &&\n (!options.suspense || query.state.status !== 'error') &&\n isStale(query, options)\n )\n}\n\nfunction isStale(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n resolveQueryValue(options.enabled, query) !== false &&\n query.isStaleByTime(resolveQueryValue(options.staleTime, query))\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,IAAa,gBAAb,cAMUA,qBAAAA,aAAmD;CAC3D;CACA,gBAAoE,KAAA;CACpE,4BAA4D,KAAA;CAC5D,iBAAqD,KAAA;CACrD;CACA;CAOA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA,gCAAgB,IAAI,IAA+B;CAEnD,YACE,QACA,SAOA;EACA,MAAM;EARC,KAAA,UAAA;EAUP,KAAK,UAAU;EACf,KAAK,eAAe;EAEpB,KAAK,YAAY;EACjB,KAAK,WAAW,OAAO;CACzB;CAEA,cAA8B;EAC5B,KAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;CACvC;CAEA,cAA8B;EAC5B,I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,SAAS,cACP,OACA,SACA,OAGA;CACA,IACEA,cAAAA,kBAAkB,QAAQ,SAAS,KAAK,MAAM,SAC9CA,cAAAA,kBAAkB,QAAQ,WAAW,KAAK,MAAM,UAChD;EACA,MAAM,QAAQA,cAAAA,kBAAkB,OAAO,KAAK;EAE5C,OAAO,UAAU,YAAa,UAAU,SAAS,QAAQ,OAAO,OAAO;CACzE;CACA,OAAO;AACT;AAEA,SAAS,sBACP,OACA,WACA,SACA,aACS;CACT,QACG,UAAU,aACTA,cAAAA,kBAAkB,YAAY,SAAS,KAAK,MAAM,WACnD,CAAC,QAAQ,YAAY,MAAM,MAAM,WAAW,YAC7C,QAAQ,OAAO,OAAO;AAE1B;AAEA,SAAS,QACP,OACA,SACS;CACT,OACEA,cAAAA,kBAAkB,QAAQ,SAAS,KAAK,MAAM,SAC9C,MAAM,cAAcA,cAAAA,kBAAkB,QAAQ,WAAW,KAAK,CAAC;AAEnE"}
1
+ {"version":3,"file":"queryObserver.cjs","names":["Subscribable","resolveQueryValue","shallowEqualObjects","noop","isServerEnvironment","isValidTimeout","timeUntilStale","timeoutManager","focusManager","fetchState","replaceData"],"sources":["../../src/queryObserver.ts"],"sourcesContent":["import { focusManager } from './focusManager'\nimport { isServer as isServerEnvironment } from './environmentManager'\nimport { notifyManager } from './notifyManager'\nimport { fetchState } from './query'\nimport { Subscribable } from './subscribable'\nimport {\n isValidTimeout,\n noop,\n replaceData,\n resolveQueryValue,\n shallowEqualObjects,\n timeUntilStale,\n} from './utils'\nimport { timeoutManager } from './timeoutManager'\nimport type { ManagedTimerId } from './timeoutManager'\nimport type { FetchOptions, Query, QueryState } from './query'\nimport type { QueryClient } from './queryClient'\nimport type {\n DefaultError,\n DefaultedQueryObserverOptions,\n PlaceholderDataFunction,\n QueryKey,\n QueryObserverBaseResult,\n QueryObserverOptions,\n QueryObserverResult,\n RefetchOptions,\n} from './types'\n\ntype QueryObserverListener<TData, TError> = (\n result: QueryObserverResult<TData, TError>,\n) => void\n\ninterface ObserverFetchOptions extends FetchOptions {\n throwOnError?: boolean\n}\n\n/**\n * A `QueryObserver` watches a single query in the `QueryCache` and computes a\n * `QueryObserverResult` from its state, recomputing and notifying subscribers\n * whenever the underlying query (or the observer's options) changes. It is\n * the primitive that framework adapters (e.g. `useQuery`) build their hooks\n * on top of, but it can also be used directly to observe and switch between\n * queries outside of any framework.\n * @example\n * ```ts\n * const observer = new QueryObserver(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n *\n * const unsubscribe = observer.subscribe((result) => {\n * console.log(result.data)\n * })\n * ```\n */\nexport class QueryObserver<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Subscribable<QueryObserverListener<TData, TError>> {\n #client: QueryClient\n #currentQuery: Query<TQueryFnData, TError, TQueryData, TQueryKey> = undefined!\n #currentQueryInitialState: QueryState<TQueryData, TError> = undefined!\n #currentResult: QueryObserverResult<TData, TError> = undefined!\n #currentResultState?: QueryState<TQueryData, TError>\n #currentResultOptions?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n #selectError: TError | null\n #selectFn?: (data: TQueryData) => TData\n #selectResult?: TData\n // This property keeps track of the last query with defined data.\n // It will be used to pass the previous data and query to the placeholder function between renders.\n #lastQueryWithDefinedData?: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n #staleTimeoutId?: ManagedTimerId\n #refetchIntervalId?: ManagedTimerId\n #currentRefetchInterval?: number | false\n #trackedProps = new Set<keyof QueryObserverResult>()\n\n constructor(\n client: QueryClient,\n public options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ) {\n super()\n\n this.#client = client\n this.#selectError = null\n\n this.bindMethods()\n this.setOptions(options)\n }\n\n /**\n * Binds the methods of the result (`refetch`) to the observer, so they keep working when destructured\n * from it. Subclasses override it to bind their own result methods as well.\n */\n protected bindMethods(): void {\n this.refetch = this.refetch.bind(this)\n }\n\n protected override onSubscribe(): void {\n if (this.listeners.size === 1) {\n this.#currentQuery.addObserver(this)\n\n if (shouldFetchOnMount(this.#currentQuery, this.options)) {\n this.#executeFetch()\n } else {\n this.updateResult()\n }\n\n this.#updateTimers()\n }\n }\n\n protected override onUnsubscribe(): void {\n if (!this.hasListeners()) {\n this.destroy()\n }\n }\n\n /**\n * Returns whether the observed query is currently stale and configured\n * (via the `refetchOnReconnect` option) to refetch when the network\n * reconnects.\n * @returns `true` if the observer should refetch the query on reconnect.\n */\n shouldFetchOnReconnect(): boolean {\n return shouldFetchOn(\n this.#currentQuery,\n this.options,\n this.options.refetchOnReconnect,\n )\n }\n\n /**\n * Returns whether the observed query is currently stale and configured\n * (via the `refetchOnWindowFocus` option) to refetch when the window\n * regains focus.\n * @returns `true` if the observer should refetch the query on window focus.\n */\n shouldFetchOnWindowFocus(): boolean {\n return shouldFetchOn(\n this.#currentQuery,\n this.options,\n this.options.refetchOnWindowFocus,\n )\n }\n\n /**\n * Stops observing the current query: clears all listeners, cancels the\n * stale and refetch-interval timers, and removes this observer from the\n * query it was observing.\n */\n destroy(): void {\n this.listeners = new Set()\n this.#clearStaleTimeout()\n this.#clearRefetchInterval()\n this.#currentQuery.removeObserver(this)\n }\n\n /**\n * Updates the observer's options. This will re-resolve the query being\n * observed (switching to a different query if the `queryKey` changed),\n * trigger a fetch if the new options require one and the observer has\n * subscribers, recompute the current result, and reschedule the stale and\n * refetch-interval timers as needed.\n * @param options - The new observer options. They are defaulted with {@link\n * QueryClient#defaultQueryOptions} before being applied.\n * @throws {Error} If `enabled` is neither a boolean nor a function.\n * @example\n * ```ts\n * observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })\n * // later: switch to a different query, reusing the same observer\n * observer.setOptions({ queryKey: ['posts', 2], queryFn: () => fetchPost(2) })\n * ```\n */\n setOptions(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): void {\n const prevOptions = this.options\n const prevQuery = this.#currentQuery\n\n this.options = this.#client.defaultQueryOptions(options)\n\n if (\n this.options.enabled !== undefined &&\n typeof this.options.enabled !== 'boolean' &&\n typeof this.options.enabled !== 'function' &&\n typeof resolveQueryValue(this.options.enabled, this.#currentQuery) !==\n 'boolean'\n ) {\n throw new Error(\n 'Expected enabled to be a boolean or a callback that returns a boolean',\n )\n }\n\n this.#updateQuery()\n this.#currentQuery.setOptions(this.options)\n\n if (\n prevOptions._defaulted &&\n !shallowEqualObjects(this.options, prevOptions)\n ) {\n this.#client.getQueryCache().notify({\n type: 'observerOptionsUpdated',\n query: this.#currentQuery,\n observer: this,\n })\n }\n\n const mounted = this.hasListeners()\n\n // Fetch if there are subscribers\n if (\n mounted &&\n shouldFetchOptionally(\n this.#currentQuery,\n prevQuery,\n this.options,\n prevOptions,\n )\n ) {\n this.#executeFetch()\n }\n\n // Update result\n this.updateResult()\n\n // Update stale interval if needed\n if (\n mounted &&\n (this.#currentQuery !== prevQuery ||\n resolveQueryValue(this.options.enabled, this.#currentQuery) !==\n resolveQueryValue(prevOptions.enabled, this.#currentQuery) ||\n resolveQueryValue(this.options.staleTime, this.#currentQuery) !==\n resolveQueryValue(prevOptions.staleTime, this.#currentQuery))\n ) {\n this.#updateStaleTimeout()\n }\n\n const nextRefetchInterval = this.#computeRefetchInterval()\n\n // Update refetch interval if needed\n if (\n mounted &&\n (this.#currentQuery !== prevQuery ||\n resolveQueryValue(this.options.enabled, this.#currentQuery) !==\n resolveQueryValue(prevOptions.enabled, this.#currentQuery) ||\n nextRefetchInterval !== this.#currentRefetchInterval)\n ) {\n this.#updateRefetchInterval(nextRefetchInterval)\n }\n }\n\n /**\n * Computes the result the observer would produce for the given (already-defaulted) options\n * right now, building the underlying `Query` if it doesn't exist yet, without waiting for a\n * subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the\n * returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.\n * @param options - The defaulted observer options to compute the result for.\n * @returns The result for the given options.\n */\n getOptimisticResult(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const query = this.#client.getQueryCache().build(this.#client, options)\n\n const result = this.createResult(query, options)\n\n if (!shallowEqualObjects(this.getCurrentResult(), result)) {\n // this assigns the optimistic result to the current Observer\n // because if the query function changes, useQuery will be performing\n // an effect where it would fetch again.\n // When the fetch finishes, we perform a deep data cloning in order\n // to reuse objects references. This deep data clone is performed against\n // the `observer.currentResult.data` property\n // When QueryKey changes, we refresh the query and get new `optimistic`\n // result, while we leave the `observer.currentResult`, so when new data\n // arrives, it finds the old `observer.currentResult` which is related\n // to the old QueryKey. Which means that currentResult and selectData are\n // out of sync already.\n // To solve this, we move the cursor of the currentResult every time\n // an observer reads an optimistic value.\n\n // When keeping the previous data, the result doesn't change until new\n // data arrives.\n this.#currentResult = result\n this.#currentResultOptions = this.options\n this.#currentResultState = this.#currentQuery.state\n }\n return result\n }\n\n /**\n * Returns the most recently computed `QueryObserverResult` for the\n * observed query. This is a point-in-time read; to be notified of updates\n * as they happen, subscribe to the observer instead (its inherited\n * `subscribe` method).\n * @returns The observer's latest result.\n * @example\n * ```ts\n * const result = observer.getCurrentResult()\n * console.log(result.status, result.data)\n * ```\n */\n getCurrentResult(): QueryObserverResult<TData, TError> {\n return this.#currentResult\n }\n\n /**\n * Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via\n * {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework\n * adapters when `notifyOnChangeProps` is not set, to implement its default \"only re-render on\n * properties you actually read\" behavior.\n * @param result - The result to wrap.\n * @param onPropTracked - Called with the name of each property that is read.\n * @returns A proxy of `result` that tracks property reads.\n */\n trackResult(\n result: QueryObserverResult<TData, TError>,\n onPropTracked?: (key: keyof QueryObserverResult) => void,\n ): QueryObserverResult<TData, TError> {\n return new Proxy(result, {\n get: (target, key) => {\n this.trackProp(key as keyof QueryObserverResult)\n onPropTracked?.(key as keyof QueryObserverResult)\n return Reflect.get(target, key)\n },\n })\n }\n\n /**\n * Records that the given `QueryObserverResult` property was read, so a subsequent update only\n * notifies this observer if a tracked property actually changed. Normally called indirectly via\n * {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property\n * access themselves (e.g. through their own reactivity system) instead of via the proxy.\n * @param key - The name of the property that was read.\n */\n trackProp(key: keyof QueryObserverResult) {\n this.#trackedProps.add(key)\n }\n\n /**\n * Returns the `Query` instance this observer is currently observing.\n * @returns The observed query.\n */\n getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {\n return this.#currentQuery\n }\n\n /**\n * Refetches the observed query and returns a promise that resolves with\n * the resulting `QueryObserverResult`.\n * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling\n * it, and `throwOnError` to `true` to reject when the refetch fails.\n * @returns A promise that resolves with the result after the refetch.\n * @example\n * ```ts\n * const result = await observer.refetch({ cancelRefetch: false })\n * console.log(result.data)\n * ```\n */\n refetch({ ...options }: RefetchOptions = {}): Promise<\n QueryObserverResult<TData, TError>\n > {\n return this.fetch({\n ...options,\n })\n }\n\n /**\n * Fetches a query defined by the given options without affecting this\n * observer's own tracked query or result, and returns a promise that\n * resolves with the `QueryObserverResult` for that fetch. This is useful\n * for prefetching data that another observer (e.g. a query about to be\n * navigated to) will need, ahead of time.\n * @param options - The observer options of the query to fetch.\n * @returns A promise that resolves with the result for the fetched query.\n * @example\n * ```ts\n * const result = await observer.fetchOptimistic({\n * queryKey: ['posts', 2],\n * queryFn: () => fetchPost(2),\n * })\n * console.log(result.data)\n * ```\n */\n fetchOptimistic(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): Promise<QueryObserverResult<TData, TError>> {\n const defaultedOptions = this.#client.defaultQueryOptions(options)\n\n const query = this.#client\n .getQueryCache()\n .build(this.#client, defaultedOptions)\n\n let unsubscribe = () => {}\n let resolveEarly:\n | ((result: QueryObserverResult<TData, TError>) => void)\n | undefined\n\n const cachePromise = new Promise<QueryObserverResult<TData, TError>>(\n (resolve) => {\n resolveEarly = resolve\n unsubscribe = this.#client.getQueryCache().subscribe((event) => {\n if (\n event.type === 'updated' &&\n event.query.queryHash === query.queryHash &&\n query.state.data !== undefined\n ) {\n unsubscribe()\n resolve(this.createResult(query, defaultedOptions))\n }\n })\n },\n )\n\n return Promise.race([\n query\n .fetch()\n .then(() => {\n const result = this.createResult(query, defaultedOptions)\n // Settle the subscriber promise so both branches always settle.\n // This value is ignored by Promise.race since the fetch branch already won.\n resolveEarly?.(result)\n return result\n })\n .finally(() => {\n unsubscribe()\n }),\n cachePromise,\n ])\n }\n\n /**\n * Fetches the observed query and updates the result once the fetch settles. Used by `refetch` and,\n * in `InfiniteQueryObserver`, to fetch more pages.\n * @param fetchOptions - Options for this fetch. `cancelRefetch` defaults to `true`.\n * @returns A promise that resolves with the updated result.\n */\n protected fetch(\n fetchOptions: ObserverFetchOptions,\n ): Promise<QueryObserverResult<TData, TError>> {\n return this.#executeFetch({\n ...fetchOptions,\n cancelRefetch: fetchOptions.cancelRefetch ?? true,\n }).then(() => {\n this.updateResult()\n return this.#currentResult\n })\n }\n\n #executeFetch(\n fetchOptions?: Omit<ObserverFetchOptions, 'initialPromise'>,\n ): Promise<TQueryData | undefined> {\n // Make sure we reference the latest query as the current one might have been removed\n this.#updateQuery()\n\n // Fetch\n let promise: Promise<TQueryData | undefined> = this.#currentQuery.fetch(\n this.options,\n fetchOptions,\n )\n\n if (!fetchOptions?.throwOnError) {\n promise = promise.catch(noop)\n }\n\n return promise\n }\n\n #shouldScheduleTimer(timeout: unknown): timeout is number {\n return (\n !isServerEnvironment() &&\n resolveQueryValue(this.options.enabled, this.#currentQuery) !== false &&\n isValidTimeout(timeout)\n )\n }\n\n #updateStaleTimeout(): void {\n this.#clearStaleTimeout()\n const staleTime = resolveQueryValue(\n this.options.staleTime,\n this.#currentQuery,\n )\n\n if (this.#currentResult.isStale || !this.#shouldScheduleTimer(staleTime)) {\n return\n }\n\n const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime)\n\n // The timeout is sometimes triggered 1 ms before the stale time expiration.\n // To mitigate this issue we always add 1 ms to the timeout.\n const timeout = time + 1\n\n this.#staleTimeoutId = timeoutManager.setTimeout(() => {\n if (!this.#currentResult.isStale) {\n this.updateResult()\n }\n }, timeout)\n }\n\n #computeRefetchInterval() {\n return (\n resolveQueryValue(this.options.refetchInterval, this.#currentQuery) ??\n false\n )\n }\n\n #updateRefetchInterval(nextInterval: number | false): void {\n this.#clearRefetchInterval()\n\n this.#currentRefetchInterval = nextInterval\n\n if (\n this.#currentRefetchInterval === 0 ||\n !this.#shouldScheduleTimer(this.#currentRefetchInterval)\n ) {\n return\n }\n\n this.#refetchIntervalId = timeoutManager.setInterval(() => {\n if (\n this.options.refetchIntervalInBackground ||\n focusManager.isFocused()\n ) {\n this.#executeFetch()\n }\n }, this.#currentRefetchInterval)\n }\n\n #updateTimers(): void {\n this.#updateStaleTimeout()\n this.#updateRefetchInterval(this.#computeRefetchInterval())\n }\n\n #clearStaleTimeout(): void {\n if (this.#staleTimeoutId !== undefined) {\n timeoutManager.clearTimeout(this.#staleTimeoutId)\n this.#staleTimeoutId = undefined\n }\n }\n\n #clearRefetchInterval(): void {\n if (this.#refetchIntervalId !== undefined) {\n timeoutManager.clearInterval(this.#refetchIntervalId)\n this.#refetchIntervalId = undefined\n }\n }\n\n /**\n * Computes the result for a query and options from the query's state, applying `select`,\n * `placeholderData`, and the derived flags. Subclasses override it to add their own fields.\n * @param query - The query to compute the result for.\n * @param options - The observer options to compute the result with.\n * @returns The computed result.\n */\n protected createResult(\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const prevQuery = this.#currentQuery\n const prevOptions = this.options\n const prevResult = this.#currentResult as\n | QueryObserverResult<TData, TError>\n | undefined\n const prevResultState = this.#currentResultState\n const prevResultOptions = this.#currentResultOptions\n const queryChange = query !== prevQuery\n const queryInitialState = queryChange\n ? query.state\n : this.#currentQueryInitialState\n\n const { state } = query\n let newState = { ...state }\n let isPlaceholderData = false\n let data: TData | undefined\n\n // Optimistically set result in fetching state if needed\n if (options._optimisticResults) {\n const mounted = this.hasListeners()\n\n const fetchOnMount = !mounted && shouldFetchOnMount(query, options)\n\n const fetchOptionally =\n mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)\n\n if (fetchOnMount || fetchOptionally) {\n newState = {\n ...newState,\n ...fetchState(state.data, query.options),\n }\n }\n if (options._optimisticResults === 'isRestoring') {\n newState.fetchStatus = 'idle'\n }\n }\n\n let { error, errorUpdatedAt, status } = newState\n\n // Per default, use query data\n data = newState.data as unknown as TData\n let skipSelect = false\n\n // use placeholderData if needed\n if (\n options.placeholderData !== undefined &&\n data === undefined &&\n status === 'pending'\n ) {\n let placeholderData\n\n // Memoize placeholder data\n if (\n prevResult?.isPlaceholderData &&\n options.placeholderData === prevResultOptions?.placeholderData\n ) {\n placeholderData = prevResult.data\n // we have to skip select when reading this memoization\n // because prevResult.data is already \"selected\"\n skipSelect = true\n } else {\n // compute placeholderData\n placeholderData =\n typeof options.placeholderData === 'function'\n ? (\n options.placeholderData as unknown as PlaceholderDataFunction<TQueryData>\n )(\n this.#lastQueryWithDefinedData?.state.data,\n this.#lastQueryWithDefinedData as any,\n )\n : options.placeholderData\n }\n\n if (placeholderData !== undefined) {\n status = 'success'\n data = replaceData(\n prevResult?.data,\n placeholderData as unknown,\n options,\n ) as TData\n isPlaceholderData = true\n }\n }\n\n // Select data if needed\n // this also runs placeholderData through the select function\n if (options.select && data !== undefined && !skipSelect) {\n // Memoize select result\n if (\n prevResult &&\n data === prevResultState?.data &&\n options.select === this.#selectFn\n ) {\n data = this.#selectResult\n } else {\n try {\n this.#selectFn = options.select\n data = options.select(data as any)\n data = replaceData(prevResult?.data, data, options)\n this.#selectResult = data\n this.#selectError = null\n } catch (selectError) {\n this.#selectError = selectError as TError\n }\n }\n } else if (data === undefined) {\n // a stored select error belongs to previously selected data; once that\n // data is gone (query switch or reset), it must not leak into this result\n this.#selectError = null\n }\n\n if (this.#selectError) {\n error = this.#selectError\n data = this.#selectResult\n errorUpdatedAt = Date.now()\n status = 'error'\n isPlaceholderData = false\n }\n\n const isFetching = newState.fetchStatus === 'fetching'\n const isPending = status === 'pending'\n const isError = status === 'error'\n\n const isLoading = isPending && isFetching\n const hasData = data !== undefined\n\n const result: QueryObserverBaseResult<TData, TError> = {\n status,\n fetchStatus: newState.fetchStatus,\n isPending,\n isSuccess: status === 'success',\n isError,\n isInitialLoading: isLoading,\n isLoading,\n data,\n dataUpdatedAt: newState.dataUpdatedAt,\n error,\n errorUpdatedAt,\n failureCount: newState.fetchFailureCount,\n failureReason: newState.fetchFailureReason,\n errorUpdateCount: newState.errorUpdateCount,\n isFetched: query.isFetched(),\n isFetchedAfterMount:\n newState.dataUpdateCount > queryInitialState.dataUpdateCount ||\n newState.errorUpdateCount > queryInitialState.errorUpdateCount,\n isFetching,\n isRefetching: isFetching && !isPending,\n isLoadingError: isError && !hasData,\n isPaused: newState.fetchStatus === 'paused',\n isPlaceholderData,\n isRefetchError: isError && hasData,\n isStale: isStale(query, options),\n refetch: this.refetch,\n isEnabled: resolveQueryValue(options.enabled, query) !== false,\n }\n\n const nextResult = result as QueryObserverResult<TData, TError>\n\n return nextResult\n }\n\n /**\n * Recomputes and stores the current result from the current query/options, notifying listeners\n * if it changed. Framework adapters call this right after subscribing to make sure no query\n * update was missed in the gap between creating the observer and subscribing to it.\n */\n updateResult(): void {\n const prevResult = this.#currentResult as\n | QueryObserverResult<TData, TError>\n | undefined\n\n const nextResult = this.createResult(this.#currentQuery, this.options)\n\n this.#currentResultState = this.#currentQuery.state\n this.#currentResultOptions = this.options\n\n if (this.#currentResultState.data !== undefined) {\n this.#lastQueryWithDefinedData = this.#currentQuery\n }\n\n // Only notify and update result if something has changed\n if (shallowEqualObjects(nextResult, prevResult)) {\n return\n }\n\n this.#currentResult = nextResult\n\n const shouldNotifyListeners = (): boolean => {\n if (!prevResult) {\n return true\n }\n\n const { notifyOnChangeProps } = this.options\n const notifyOnChangePropsValue =\n typeof notifyOnChangeProps === 'function'\n ? notifyOnChangeProps()\n : notifyOnChangeProps\n\n if (\n notifyOnChangePropsValue === 'all' ||\n (!notifyOnChangePropsValue && !this.#trackedProps.size)\n ) {\n return true\n }\n\n const includedProps = new Set(\n notifyOnChangePropsValue ?? this.#trackedProps,\n )\n\n if (this.options.throwOnError) {\n includedProps.add('error')\n }\n\n return Object.keys(this.#currentResult).some((key) => {\n const typedKey = key as keyof QueryObserverResult\n const changed = this.#currentResult[typedKey] !== prevResult[typedKey]\n\n return changed && includedProps.has(typedKey)\n })\n }\n\n const notifyListeners = shouldNotifyListeners()\n\n notifyManager.batch(() => {\n // First, trigger the listeners\n if (notifyListeners) {\n this.listeners.forEach((listener) => {\n listener(this.#currentResult)\n })\n }\n\n // Then the cache listeners\n this.#client.getQueryCache().notify({\n query: this.#currentQuery,\n type: 'observerResultsUpdated',\n })\n })\n }\n\n #updateQuery(): void {\n const query = this.#client.getQueryCache().build(this.#client, this.options)\n\n if (query === this.#currentQuery) {\n return\n }\n\n const prevQuery = this.#currentQuery as\n | Query<TQueryFnData, TError, TQueryData, TQueryKey>\n | undefined\n this.#currentQuery = query\n this.#currentQueryInitialState = query.state\n\n if (this.hasListeners()) {\n prevQuery?.removeObserver(this)\n query.addObserver(this)\n }\n }\n\n /**\n * Updates the observer's result when the observed query changes, and reschedules its timers if it\n * has listeners.\n * @internal\n */\n onQueryUpdate(): void {\n this.updateResult()\n\n if (this.hasListeners()) {\n this.#updateTimers()\n }\n }\n}\n\n/**\n * Checks whether a query has no data yet and should do its initial load when an observer mounts.\n * @param query - The query to check.\n * @param options - The observer options.\n * @returns `true` if the query is enabled, has no data, and isn't in an error state with\n * `retryOnMount: false`.\n */\nfunction shouldLoadOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any>,\n): boolean {\n return (\n resolveQueryValue(options.enabled, query) !== false &&\n query.state.data === undefined &&\n !(\n query.state.status === 'error' &&\n resolveQueryValue(options.retryOnMount, query) === false\n )\n )\n}\n\n/**\n * Checks whether a query should fetch when an observer mounts: either for its initial load, or\n * because it has data and `refetchOnMount` asks for a refetch.\n * @param query - The query to check.\n * @param options - The observer options.\n * @returns `true` if the query should fetch on mount.\n */\nfunction shouldFetchOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n shouldLoadOnMount(query, options) ||\n (query.state.data !== undefined &&\n shouldFetchOn(query, options, options.refetchOnMount))\n )\n}\n\n/**\n * Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or\n * `refetchOnReconnect` option.\n * @param query - The query to check.\n * @param options - The observer options.\n * @param field - The value of the option to check.\n * @returns `true` if the query is enabled, not static, and the option is `'always'`, or is not\n * `false` and the query is stale.\n */\nfunction shouldFetchOn(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n field: (typeof options)['refetchOnMount'] &\n (typeof options)['refetchOnWindowFocus'] &\n (typeof options)['refetchOnReconnect'],\n) {\n if (\n resolveQueryValue(options.enabled, query) !== false &&\n resolveQueryValue(options.staleTime, query) !== 'static'\n ) {\n const value = resolveQueryValue(field, query)\n\n return value === 'always' || (value !== false && isStale(query, options))\n }\n return false\n}\n\n/**\n * Checks whether a query should fetch after the observer's options change.\n * @param query - The query observed with the new options.\n * @param prevQuery - The query observed with the previous options.\n * @param options - The new observer options.\n * @param prevOptions - The previous observer options.\n * @returns `true` if the query changed or was disabled before, it isn't a suspense query in an\n * error state, and it is stale.\n */\nfunction shouldFetchOptionally(\n query: Query<any, any, any, any>,\n prevQuery: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n prevOptions: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n (query !== prevQuery ||\n resolveQueryValue(prevOptions.enabled, query) === false) &&\n (!options.suspense || query.state.status !== 'error') &&\n isStale(query, options)\n )\n}\n\n/**\n * Checks whether a query is stale for the given observer options.\n * @param query - The query to check.\n * @param options - The observer options, whose `enabled` and `staleTime` are used.\n * @returns `true` if the query is enabled and its data is stale for `staleTime`.\n */\nfunction isStale(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n resolveQueryValue(options.enabled, query) !== false &&\n query.isStaleByTime(resolveQueryValue(options.staleTime, query))\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,gBAAb,cAMUA,qBAAAA,aAAmD;CAC3D;CACA,gBAAoE,KAAA;CACpE,4BAA4D,KAAA;CAC5D,iBAAqD,KAAA;CACrD;CACA;CAOA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA,gCAAgB,IAAI,IAA+B;CAEnD,YACE,QACA,SAOA;EACA,MAAM;EARC,KAAA,UAAA;EAUP,KAAK,UAAU;EACf,KAAK,eAAe;EAEpB,KAAK,YAAY;EACjB,KAAK,WAAW,OAAO;CACzB;;;;;CAMA,cAA8B;EAC5B,KAAK,UAAU,KAAK,QAAQ,KAAK,IAAI;CACvC;CAEA,cAAuC;EACrC,IAAI,KAAK,UAAU,SAAS,GAAG;GAC7B,KAAK,cAAc,YAAY,IAAI;GAEnC,IAAI,mBAAmB,KAAK,eAAe,KAAK,OAAO,GACrD,KAAK,cAAc;QAEnB,KAAK,aAAa;GAGpB,KAAK,cAAc;EACrB;CACF;CAEA,gBAAyC;EACvC,IAAI,CAAC,KAAK,aAAa,GACrB,KAAK,QAAQ;CAEjB;;;;;;;CAQA,yBAAkC;EAChC,OAAO,cACL,KAAK,eACL,KAAK,SACL,KAAK,QAAQ,kBACf;CACF;;;;;;;CAQA,2BAAoC;EAClC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A,SACA,aACS;CACT,QACG,UAAU,aACTA,cAAAA,kBAAkB,YAAY,SAAS,KAAK,MAAM,WACnD,CAAC,QAAQ,YAAY,MAAM,MAAM,WAAW,YAC7C,QAAQ,OAAO,OAAO;AAE1B;;;;;;;AAQA,SAAS,QACP,OACA,SACS;CACT,OACEA,cAAAA,kBAAkB,QAAQ,SAAS,KAAK,MAAM,SAC9C,MAAM,cAAcA,cAAAA,kBAAkB,QAAQ,WAAW,KAAK,CAAC;AAEnE"}
@@ -1,2 +1,2 @@
1
- import { rr as QueryObserver } from "./hydration-Br9VIGXa.cjs";
1
+ import { rr as QueryObserver } from "./hydration-C6zghADG.cjs";
2
2
  export { QueryObserver };
@@ -1,2 +1,2 @@
1
- import { rr as QueryObserver } from "./hydration-B9t5w6NC.js";
1
+ import { rr as QueryObserver } from "./hydration-Bf0oMcwO.js";
2
2
  export { QueryObserver };
@@ -13,7 +13,6 @@ import { fetchState } from "./query.js";
13
13
  * the primitive that framework adapters (e.g. `useQuery`) build their hooks
14
14
  * on top of, but it can also be used directly to observe and switch between
15
15
  * queries outside of any framework.
16
- *
17
16
  * @example
18
17
  * ```ts
19
18
  * const observer = new QueryObserver(queryClient, {
@@ -49,6 +48,10 @@ var QueryObserver = class extends Subscribable {
49
48
  this.bindMethods();
50
49
  this.setOptions(options);
51
50
  }
51
+ /**
52
+ * Binds the methods of the result (`refetch`) to the observer, so they keep working when destructured
53
+ * from it. Subclasses override it to bind their own result methods as well.
54
+ */
52
55
  bindMethods() {
53
56
  this.refetch = this.refetch.bind(this);
54
57
  }
@@ -67,6 +70,7 @@ var QueryObserver = class extends Subscribable {
67
70
  * Returns whether the observed query is currently stale and configured
68
71
  * (via the `refetchOnReconnect` option) to refetch when the network
69
72
  * reconnects.
73
+ * @returns `true` if the observer should refetch the query on reconnect.
70
74
  */
71
75
  shouldFetchOnReconnect() {
72
76
  return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
@@ -75,6 +79,7 @@ var QueryObserver = class extends Subscribable {
75
79
  * Returns whether the observed query is currently stale and configured
76
80
  * (via the `refetchOnWindowFocus` option) to refetch when the window
77
81
  * regains focus.
82
+ * @returns `true` if the observer should refetch the query on window focus.
78
83
  */
79
84
  shouldFetchOnWindowFocus() {
80
85
  return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
@@ -96,7 +101,9 @@ var QueryObserver = class extends Subscribable {
96
101
  * trigger a fetch if the new options require one and the observer has
97
102
  * subscribers, recompute the current result, and reschedule the stale and
98
103
  * refetch-interval timers as needed.
99
- *
104
+ * @param options - The new observer options. They are defaulted with {@link
105
+ * QueryClient#defaultQueryOptions} before being applied.
106
+ * @throws {Error} If `enabled` is neither a boolean nor a function.
100
107
  * @example
101
108
  * ```ts
102
109
  * observer.setOptions({ queryKey: ['posts', 1], queryFn: () => fetchPost(1) })
@@ -128,6 +135,8 @@ var QueryObserver = class extends Subscribable {
128
135
  * right now, building the underlying `Query` if it doesn't exist yet, without waiting for a
129
136
  * subscription callback. Called by framework adapters on every render (e.g. `useQuery`) so the
130
137
  * returned value is available synchronously, ahead of `setOptions` triggering an actual fetch.
138
+ * @param options - The defaulted observer options to compute the result for.
139
+ * @returns The result for the given options.
131
140
  */
132
141
  getOptimisticResult(options) {
133
142
  const query = this.#client.getQueryCache().build(this.#client, options);
@@ -144,7 +153,7 @@ var QueryObserver = class extends Subscribable {
144
153
  * observed query. This is a point-in-time read; to be notified of updates
145
154
  * as they happen, subscribe to the observer instead (its inherited
146
155
  * `subscribe` method).
147
- *
156
+ * @returns The observer's latest result.
148
157
  * @example
149
158
  * ```ts
150
159
  * const result = observer.getCurrentResult()
@@ -159,6 +168,9 @@ var QueryObserver = class extends Subscribable {
159
168
  * {@link QueryObserver#trackProp} (and an optional `onPropTracked` callback). Used by framework
160
169
  * adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on
161
170
  * properties you actually read" behavior.
171
+ * @param result - The result to wrap.
172
+ * @param onPropTracked - Called with the name of each property that is read.
173
+ * @returns A proxy of `result` that tracks property reads.
162
174
  */
163
175
  trackResult(result, onPropTracked) {
164
176
  return new Proxy(result, { get: (target, key) => {
@@ -172,12 +184,14 @@ var QueryObserver = class extends Subscribable {
172
184
  * notifies this observer if a tracked property actually changed. Normally called indirectly via
173
185
  * {@link QueryObserver#trackResult}'s proxy; exposed directly for adapters that track property
174
186
  * access themselves (e.g. through their own reactivity system) instead of via the proxy.
187
+ * @param key - The name of the property that was read.
175
188
  */
176
189
  trackProp(key) {
177
190
  this.#trackedProps.add(key);
178
191
  }
179
192
  /**
180
193
  * Returns the `Query` instance this observer is currently observing.
194
+ * @returns The observed query.
181
195
  */
182
196
  getCurrentQuery() {
183
197
  return this.#currentQuery;
@@ -185,7 +199,9 @@ var QueryObserver = class extends Subscribable {
185
199
  /**
186
200
  * Refetches the observed query and returns a promise that resolves with
187
201
  * the resulting `QueryObserverResult`.
188
- *
202
+ * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
203
+ * it, and `throwOnError` to `true` to reject when the refetch fails.
204
+ * @returns A promise that resolves with the result after the refetch.
189
205
  * @example
190
206
  * ```ts
191
207
  * const result = await observer.refetch({ cancelRefetch: false })
@@ -201,7 +217,8 @@ var QueryObserver = class extends Subscribable {
201
217
  * resolves with the `QueryObserverResult` for that fetch. This is useful
202
218
  * for prefetching data that another observer (e.g. a query about to be
203
219
  * navigated to) will need, ahead of time.
204
- *
220
+ * @param options - The observer options of the query to fetch.
221
+ * @returns A promise that resolves with the result for the fetched query.
205
222
  * @example
206
223
  * ```ts
207
224
  * const result = await observer.fetchOptimistic({
@@ -233,6 +250,12 @@ var QueryObserver = class extends Subscribable {
233
250
  unsubscribe();
234
251
  }), cachePromise]);
235
252
  }
253
+ /**
254
+ * Fetches the observed query and updates the result once the fetch settles. Used by `refetch` and,
255
+ * in `InfiniteQueryObserver`, to fetch more pages.
256
+ * @param fetchOptions - Options for this fetch. `cancelRefetch` defaults to `true`.
257
+ * @returns A promise that resolves with the updated result.
258
+ */
236
259
  fetch(fetchOptions) {
237
260
  return this.#executeFetch({
238
261
  ...fetchOptions,
@@ -287,6 +310,13 @@ var QueryObserver = class extends Subscribable {
287
310
  this.#refetchIntervalId = void 0;
288
311
  }
289
312
  }
313
+ /**
314
+ * Computes the result for a query and options from the query's state, applying `select`,
315
+ * `placeholderData`, and the derived flags. Subclasses override it to add their own fields.
316
+ * @param query - The query to compute the result for.
317
+ * @param options - The observer options to compute the result with.
318
+ * @returns The computed result.
319
+ */
290
320
  createResult(query, options) {
291
321
  const prevQuery = this.#currentQuery;
292
322
  const prevOptions = this.options;
@@ -422,18 +452,45 @@ var QueryObserver = class extends Subscribable {
422
452
  query.addObserver(this);
423
453
  }
424
454
  }
425
- /** @internal */
455
+ /**
456
+ * Updates the observer's result when the observed query changes, and reschedules its timers if it
457
+ * has listeners.
458
+ * @internal
459
+ */
426
460
  onQueryUpdate() {
427
461
  this.updateResult();
428
462
  if (this.hasListeners()) this.#updateTimers();
429
463
  }
430
464
  };
465
+ /**
466
+ * Checks whether a query has no data yet and should do its initial load when an observer mounts.
467
+ * @param query - The query to check.
468
+ * @param options - The observer options.
469
+ * @returns `true` if the query is enabled, has no data, and isn't in an error state with
470
+ * `retryOnMount: false`.
471
+ */
431
472
  function shouldLoadOnMount(query, options) {
432
473
  return resolveQueryValue(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && resolveQueryValue(options.retryOnMount, query) === false);
433
474
  }
475
+ /**
476
+ * Checks whether a query should fetch when an observer mounts: either for its initial load, or
477
+ * because it has data and `refetchOnMount` asks for a refetch.
478
+ * @param query - The query to check.
479
+ * @param options - The observer options.
480
+ * @returns `true` if the query should fetch on mount.
481
+ */
434
482
  function shouldFetchOnMount(query, options) {
435
483
  return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
436
484
  }
485
+ /**
486
+ * Checks whether a query should fetch for a `refetchOnMount`, `refetchOnWindowFocus`, or
487
+ * `refetchOnReconnect` option.
488
+ * @param query - The query to check.
489
+ * @param options - The observer options.
490
+ * @param field - The value of the option to check.
491
+ * @returns `true` if the query is enabled, not static, and the option is `'always'`, or is not
492
+ * `false` and the query is stale.
493
+ */
437
494
  function shouldFetchOn(query, options, field) {
438
495
  if (resolveQueryValue(options.enabled, query) !== false && resolveQueryValue(options.staleTime, query) !== "static") {
439
496
  const value = resolveQueryValue(field, query);
@@ -441,9 +498,24 @@ function shouldFetchOn(query, options, field) {
441
498
  }
442
499
  return false;
443
500
  }
501
+ /**
502
+ * Checks whether a query should fetch after the observer's options change.
503
+ * @param query - The query observed with the new options.
504
+ * @param prevQuery - The query observed with the previous options.
505
+ * @param options - The new observer options.
506
+ * @param prevOptions - The previous observer options.
507
+ * @returns `true` if the query changed or was disabled before, it isn't a suspense query in an
508
+ * error state, and it is stale.
509
+ */
444
510
  function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
445
511
  return (query !== prevQuery || resolveQueryValue(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
446
512
  }
513
+ /**
514
+ * Checks whether a query is stale for the given observer options.
515
+ * @param query - The query to check.
516
+ * @param options - The observer options, whose `enabled` and `staleTime` are used.
517
+ * @returns `true` if the query is enabled and its data is stale for `staleTime`.
518
+ */
447
519
  function isStale(query, options) {
448
520
  return resolveQueryValue(options.enabled, query) !== false && query.isStaleByTime(resolveQueryValue(options.staleTime, query));
449
521
  }