@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
@@ -23,7 +23,6 @@ var _Query_brand = /* @__PURE__ */ new WeakSet();
23
23
  * code typically interacts with queries indirectly through `QueryClient` or
24
24
  * a framework hook like `useQuery`. Direct access to a `Query` instance is
25
25
  * possible via `queryCache.find()`/`findAll()` for inspecting cache state.
26
- *
27
26
  * @example
28
27
  * ```ts
29
28
  * const queryCache = queryClient.getQueryCache()
@@ -60,23 +59,34 @@ var Query = class extends Removable {
60
59
  }
61
60
  /**
62
61
  * The `meta` object passed in the query's options, if any.
62
+ * @returns The query's `meta`, or `undefined` if none was set.
63
63
  */
64
64
  get meta() {
65
65
  return this.options.meta;
66
66
  }
67
- /** @internal */
67
+ /**
68
+ * `'infinite'` for an infinite query, otherwise `undefined`.
69
+ * @internal
70
+ * @returns The type of the query, set from the `_type` option (e.g. `'infinite'`).
71
+ */
68
72
  get queryType() {
69
73
  return _classPrivateFieldGet2(_queryType, this);
70
74
  }
71
75
  /**
72
76
  * The promise for the currently in-flight fetch, if the query is fetching.
73
77
  * `undefined` when the query is not fetching.
78
+ * @returns The promise of the in-flight fetch, or `undefined`.
74
79
  */
75
80
  get promise() {
76
81
  var _classPrivateFieldGet2$1;
77
82
  return (_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.promise;
78
83
  }
79
- /** @internal */
84
+ /**
85
+ * Replaces the query's options and applies their `gcTime`. If the query has no data yet, it gets
86
+ * the `initialData` from the new options, if any.
87
+ * @internal
88
+ * @param options - The new query options, merged on top of the query's default options.
89
+ */
80
90
  setOptions(options) {
81
91
  this.options = {
82
92
  ..._classPrivateFieldGet2(_defaultOptions, this),
@@ -95,7 +105,14 @@ var Query = class extends Removable {
95
105
  optionalRemove() {
96
106
  if (!this.observers.length && this.state.fetchStatus === "idle") _classPrivateFieldGet2(_cache, this).remove(this);
97
107
  }
98
- /** @internal */
108
+ /**
109
+ * Writes new data to the query and marks it as successfully fetched.
110
+ * @internal
111
+ * @param newData - The data to write. Structural sharing with the current data is applied.
112
+ * @param options - Set `updatedAt` to override the timestamp, and `manual` to mark the write as
113
+ * manual (e.g. from `queryClient.setQueryData`).
114
+ * @returns The data that was written.
115
+ */
99
116
  setData(newData, options) {
100
117
  const data = replaceData(this.state.data, newData, this.options);
101
118
  _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
@@ -110,6 +127,7 @@ var Query = class extends Removable {
110
127
  * Merges the given partial state directly into this query's state, notifying observers. Used
111
128
  * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a
112
129
  * user manually trigger a loading/error state or edit the cached data.
130
+ * @param state - The partial state to merge into the query's state.
113
131
  */
114
132
  setState(state) {
115
133
  _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
@@ -121,7 +139,9 @@ var Query = class extends Removable {
121
139
  * Cancels the query's currently in-flight fetch, if any.
122
140
  * - Returns a promise that resolves once the cancellation has settled.
123
141
  * - If no fetch is in progress, resolves immediately.
124
- *
142
+ * @param options - Set `revert` to restore the state from before the fetch started, and `silent`
143
+ * to suppress the cancellation error when a new fetch replaces the cancelled one.
144
+ * @returns A promise that resolves once the cancellation has settled.
125
145
  * @example
126
146
  * ```ts
127
147
  * await query.cancel()
@@ -137,14 +157,17 @@ var Query = class extends Removable {
137
157
  * Clears the query's garbage collection timeout and silently cancels any
138
158
  * in-flight fetch. Called by `QueryCache` when the query is removed from
139
159
  * the cache.
140
- *
141
160
  * @see {@link Query#cancel}
142
161
  */
143
162
  destroy() {
144
163
  super.destroy();
145
164
  this.cancel({ silent: true });
146
165
  }
147
- /** @internal */
166
+ /**
167
+ * The state the query was created with.
168
+ * @internal
169
+ * @returns The state the query had when it was first created, used by {@link Query#reset}.
170
+ */
148
171
  get resetState() {
149
172
  return _classPrivateFieldGet2(_initialState, this);
150
173
  }
@@ -160,6 +183,7 @@ var Query = class extends Removable {
160
183
  /**
161
184
  * Returns `true` if the query has at least one observer for which `enabled`
162
185
  * does not resolve to `false`.
186
+ * @returns `true` if the query has an enabled observer.
163
187
  */
164
188
  isActive() {
165
189
  return this.observers.some((observer) => resolveQueryValue(observer.options.enabled, this) !== false);
@@ -171,6 +195,7 @@ var Query = class extends Removable {
171
195
  * (see `isActive`).
172
196
  * - If the query has no observers, it is disabled when its `queryFn` is
173
197
  * `skipToken` or it has never been fetched.
198
+ * @returns `true` if the query is disabled.
174
199
  */
175
200
  isDisabled() {
176
201
  if (this.getObserversCount() > 0) return !this.isActive();
@@ -179,6 +204,7 @@ var Query = class extends Removable {
179
204
  /**
180
205
  * Returns `true` if the query has been fetched, i.e. it has resolved with
181
206
  * either data or an error at least once.
207
+ * @returns `true` if the query has been fetched.
182
208
  */
183
209
  isFetched() {
184
210
  return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
@@ -186,6 +212,7 @@ var Query = class extends Removable {
186
212
  /**
187
213
  * Returns `true` if the query has at least one observer configured with
188
214
  * `staleTime: 'static'`, meaning it is treated as never stale.
215
+ * @returns `true` if the query is static.
189
216
  */
190
217
  isStatic() {
191
218
  if (this.getObserversCount() > 0) return this.observers.some((observer) => resolveQueryValue(observer.options.staleTime, this) === "static");
@@ -198,7 +225,7 @@ var Query = class extends Removable {
198
225
  * `staleTime` and `enabled` state).
199
226
  * - If the query has no observers, it is considered stale when it has no
200
227
  * data or has been invalidated.
201
- *
228
+ * @returns `true` if the query is stale.
202
229
  * @see {@link Query#isStaleByTime}
203
230
  * @example
204
231
  * ```ts
@@ -218,7 +245,9 @@ var Query = class extends Removable {
218
245
  * - `staleTime: 'static'` is never stale.
219
246
  * - An invalidated query is always stale.
220
247
  * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.
221
- *
248
+ * @param staleTime - The time, in milliseconds, after which data is considered stale, or
249
+ * `'static'` to never treat existing data as stale. A query without data is stale either way.
250
+ * @returns `true` if the query's data is stale.
222
251
  * @see {@link Query#isStale}
223
252
  * @example
224
253
  * ```ts
@@ -231,21 +260,34 @@ var Query = class extends Removable {
231
260
  if (this.state.isInvalidated) return true;
232
261
  return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
233
262
  }
234
- /** @internal */
263
+ /**
264
+ * Refetches the query when the window regains focus, if an observer wants that, and continues a
265
+ * paused fetch.
266
+ * @internal
267
+ */
235
268
  onFocus() {
236
269
  var _classPrivateFieldGet5;
237
270
  const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
238
271
  observer === null || observer === void 0 || observer.refetch({ cancelRefetch: false });
239
272
  (_classPrivateFieldGet5 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.continue();
240
273
  }
241
- /** @internal */
274
+ /**
275
+ * Refetches the query when the app reconnects, if an observer wants that, and continues a paused
276
+ * fetch.
277
+ * @internal
278
+ */
242
279
  onOnline() {
243
280
  var _classPrivateFieldGet6;
244
281
  const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
245
282
  observer === null || observer === void 0 || observer.refetch({ cancelRefetch: false });
246
283
  (_classPrivateFieldGet6 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.continue();
247
284
  }
248
- /** @internal */
285
+ /**
286
+ * Subscribes an observer to the query and stops its garbage collection.
287
+ * @internal
288
+ * @param observer - The observer to add. Adding an observer that is already subscribed does
289
+ * nothing.
290
+ */
249
291
  addObserver(observer) {
250
292
  if (!this.observers.includes(observer)) {
251
293
  this.observers.push(observer);
@@ -257,7 +299,13 @@ var Query = class extends Removable {
257
299
  });
258
300
  }
259
301
  }
260
- /** @internal */
302
+ /**
303
+ * Unsubscribes an observer from the query.
304
+ * @internal
305
+ * @param observer - The observer to remove. When the last observer is removed, the in-flight
306
+ * fetch is cancelled if its abort signal was consumed (otherwise only its retries are stopped),
307
+ * and garbage collection is scheduled.
308
+ */
261
309
  removeObserver(observer) {
262
310
  const index = this.observers.indexOf(observer);
263
311
  if (index !== -1) {
@@ -278,7 +326,7 @@ var Query = class extends Removable {
278
326
  }
279
327
  /**
280
328
  * Returns the number of observers currently subscribed to this query.
281
- *
329
+ * @returns The number of observers.
282
330
  * @example
283
331
  * ```ts
284
332
  * if (query.getObserversCount() === 0) {
@@ -293,7 +341,6 @@ var Query = class extends Removable {
293
341
  * Marks the query as invalidated, unless it is already invalidated. This
294
342
  * updates `state.isInvalidated` and notifies observers, but does not by
295
343
  * itself trigger a refetch.
296
- *
297
344
  * @example
298
345
  * ```ts
299
346
  * query.invalidate()
@@ -311,6 +358,13 @@ var Query = class extends Removable {
311
358
  * cancelled first.
312
359
  * - If `options` is passed, it replaces the query's current options
313
360
  * before fetching.
361
+ * @param options - Query options that replace the query's current options before fetching. They
362
+ * are not applied when an in-flight fetch is reused.
363
+ * @param fetchOptions - Set `cancelRefetch` to cancel an in-flight fetch first (only if the query
364
+ * already has data), and `meta` to pass extra information to the query's behavior.
365
+ * @returns A promise that resolves with the fetched data, or rejects with the fetch error. If the
366
+ * fetch is cancelled with `revert` while the query has data, it resolves with the restored data
367
+ * instead.
314
368
  */
315
369
  async fetch(options, fetchOptions) {
316
370
  var _classPrivateFieldGet7, _context$fetchOptions;
@@ -508,6 +562,14 @@ function _dispatch(action) {
508
562
  });
509
563
  });
510
564
  }
565
+ /**
566
+ * Returns the state changes applied when a query starts fetching.
567
+ * @param data - The query's current data. If it is `undefined`, the query is also reset to
568
+ * `'pending'` with no error.
569
+ * @param options - The query options, whose `networkMode` decides whether the query is `'fetching'`
570
+ * or `'paused'`.
571
+ * @returns The partial query state for a starting fetch.
572
+ */
511
573
  function fetchState(data, options) {
512
574
  return {
513
575
  fetchFailureCount: 0,
@@ -519,6 +581,12 @@ function fetchState(data, options) {
519
581
  }
520
582
  };
521
583
  }
584
+ /**
585
+ * Returns the state changes applied when a query receives data.
586
+ * @param data - The new data.
587
+ * @param dataUpdatedAt - The timestamp the data is recorded with. Defaults to the current time.
588
+ * @returns The partial query state for a successful update.
589
+ */
522
590
  function successState(data, dataUpdatedAt) {
523
591
  return {
524
592
  data,
@@ -528,6 +596,12 @@ function successState(data, dataUpdatedAt) {
528
596
  status: "success"
529
597
  };
530
598
  }
599
+ /**
600
+ * Returns the initial state of a query, based on its `initialData` and `initialDataUpdatedAt`
601
+ * options.
602
+ * @param options - The query options.
603
+ * @returns The initial query state: `'success'` if `initialData` is set, otherwise `'pending'`.
604
+ */
531
605
  function getDefaultState(options) {
532
606
  const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
533
607
  const hasData = data !== void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","names":[],"sources":["../../src/query.ts"],"sourcesContent":["import {\n ensureQueryFn,\n noop,\n replaceData,\n resolveQueryValue,\n skipToken,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport { CancelledError, canFetch, createRetryer } from './retryer'\nimport { Removable } from './removable'\nimport { infiniteQueryBehavior } from './infiniteQueryBehavior'\nimport type { QueryCache } from './queryCache'\nimport type { QueryClient } from './queryClient'\nimport type {\n CancelOptions,\n DefaultError,\n FetchStatus,\n InitialDataFunction,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n QueryMeta,\n QueryOptions,\n QueryStatus,\n SetDataOptions,\n StaleTime,\n} from './types'\nimport type { QueryObserver } from './queryObserver'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface QueryConfig<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n client: QueryClient\n queryKey: TQueryKey\n queryHash: string\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state?: QueryState<TData, TError>\n}\n\n/**\n * The raw state stored on a `Query` instance. This is the underlying state\n * that observer results (e.g. `QueryObserverResult`) are derived from.\n */\nexport interface QueryState<TData = unknown, TError = DefaultError> {\n /**\n * The last successfully resolved data for the query.\n */\n data: TData | undefined\n /**\n * The number of times the query has successfully resolved.\n */\n dataUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"success\"`.\n */\n dataUpdatedAt: number\n /**\n * The error object for the query, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The sum of all errors, incremented every time the query resolves with an error.\n */\n errorUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"error\"`.\n */\n errorUpdatedAt: number\n /**\n * The failure count for the current fetch.\n * - Incremented every time the fetch fails.\n * - Reset to `0` when the fetch succeeds.\n */\n fetchFailureCount: number\n /**\n * The reason the current fetch failed, as reported by the retryer.\n * - Reset to `null` when the fetch succeeds.\n */\n fetchFailureReason: TError | null\n /**\n * Metadata passed to the currently in-flight (or most recent) fetch, e.g. the\n * `fetchMore` direction for infinite queries.\n */\n fetchMeta: FetchMeta | null\n /**\n * Whether the query has been marked as invalidated via `invalidate()`.\n * - Reset to `false` whenever the query resolves successfully.\n */\n isInvalidated: boolean\n /**\n * The status of the query.\n * - `pending` if there's no cached data and no attempt was finished yet.\n * - `error` if the last attempt resulted in an error.\n * - `success` if the query has data.\n */\n status: QueryStatus\n /**\n * The fetch status of the query.\n * - `fetching`: the `queryFn` is currently executing.\n * - `paused`: a fetch wanted to run but has been paused (see network mode).\n * - `idle`: the query is not fetching.\n */\n fetchStatus: FetchStatus\n}\n\nexport interface FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n fetchFn: () => unknown | Promise<unknown>\n fetchOptions?: FetchOptions\n signal: AbortSignal\n options: QueryOptions<TQueryFnData, TError, TData, any>\n client: QueryClient\n queryKey: TQueryKey\n state: QueryState<TData, TError>\n}\n\nexport interface QueryBehavior<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n onFetch: (\n context: FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n query: Query,\n ) => void\n}\n\nexport type FetchDirection = 'forward' | 'backward'\n\nexport interface FetchMeta {\n fetchMore?: { direction: FetchDirection }\n}\n\nexport interface FetchOptions<TData = unknown> {\n cancelRefetch?: boolean\n meta?: FetchMeta\n initialPromise?: Promise<TData>\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError\n}\n\ninterface FetchAction {\n type: 'fetch'\n meta?: FetchMeta\n}\n\ninterface SuccessAction<TData> {\n data: TData | undefined\n type: 'success'\n dataUpdatedAt?: number\n manual?: boolean\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface InvalidateAction {\n type: 'invalidate'\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\ninterface SetStateAction<TData, TError> {\n type: 'setState'\n state: Partial<QueryState<TData, TError>>\n}\n\nexport type Action<TData, TError> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | FetchAction\n | InvalidateAction\n | PauseAction\n | SetStateAction<TData, TError>\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single cached query. A `Query` holds the query's key, options,\n * state (data/error/status), and the observers currently subscribed to it.\n *\n * Instances are created and managed internally by `QueryCache`; application\n * code typically interacts with queries indirectly through `QueryClient` or\n * a framework hook like `useQuery`. Direct access to a `Query` instance is\n * possible via `queryCache.find()`/`findAll()` for inspecting cache state.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * console.log(query.state.dataUpdatedAt)\n * }\n * ```\n */\nexport class Query<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Removable {\n queryKey: TQueryKey\n queryHash: string\n options!: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state: QueryState<TData, TError>\n #queryType?: 'infinite'\n\n #initialState: QueryState<TData, TError>\n #revertState?: QueryState<TData, TError>\n #cache: QueryCache\n #client: QueryClient\n #retryer?: Retryer<TData>\n observers: Array<QueryObserver<any, any, any, any, any>>\n #defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n #abortSignalConsumed: boolean\n\n constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>) {\n super()\n\n this.#abortSignalConsumed = false\n this.#defaultOptions = config.defaultOptions\n this.setOptions(config.options)\n this.observers = []\n this.#client = config.client\n this.#cache = this.#client.getQueryCache()\n this.queryKey = config.queryKey\n this.queryHash = config.queryHash\n this.#initialState = getDefaultState(this.options)\n this.state = config.state ?? this.#initialState\n this.scheduleGc()\n }\n /**\n * The `meta` object passed in the query's options, if any.\n */\n get meta(): QueryMeta | undefined {\n return this.options.meta\n }\n\n /** @internal */\n get queryType() {\n return this.#queryType\n }\n\n /**\n * The promise for the currently in-flight fetch, if the query is fetching.\n * `undefined` when the query is not fetching.\n */\n get promise(): Promise<TData> | undefined {\n return this.#retryer?.promise\n }\n\n /** @internal */\n setOptions(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): void {\n this.options = { ...this.#defaultOptions, ...options }\n\n if (options?._type) {\n this.#queryType = options._type\n }\n\n this.updateGcTime(this.options.gcTime)\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (this.state && this.state.data === undefined) {\n const defaultState = getDefaultState(this.options)\n if (defaultState.data !== undefined) {\n this.setState(\n successState(defaultState.data, defaultState.dataUpdatedAt),\n )\n this.#initialState = defaultState\n }\n }\n }\n\n protected optionalRemove() {\n if (!this.observers.length && this.state.fetchStatus === 'idle') {\n this.#cache.remove(this)\n }\n }\n\n /** @internal */\n setData(\n newData: TData,\n options?: SetDataOptions & { manual: boolean },\n ): TData {\n const data = replaceData(this.state.data, newData, this.options)\n\n // Set data and mark it as cached\n this.#dispatch({\n data,\n type: 'success',\n dataUpdatedAt: options?.updatedAt,\n manual: options?.manual,\n })\n\n return data\n }\n\n /**\n * Merges the given partial state directly into this query's state, notifying observers. Used\n * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a\n * user manually trigger a loading/error state or edit the cached data.\n */\n setState(state: Partial<QueryState<TData, TError>>): void {\n this.#dispatch({ type: 'setState', state })\n }\n\n /**\n * Cancels the query's currently in-flight fetch, if any.\n * - Returns a promise that resolves once the cancellation has settled.\n * - If no fetch is in progress, resolves immediately.\n *\n * @example\n * ```ts\n * await query.cancel()\n * ```\n */\n cancel(options?: CancelOptions): Promise<void> {\n const promise = this.#retryer?.promise\n this.#retryer?.cancel(options)\n return promise ? promise.then(noop).catch(noop) : Promise.resolve()\n }\n\n /**\n * Clears the query's garbage collection timeout and silently cancels any\n * in-flight fetch. Called by `QueryCache` when the query is removed from\n * the cache.\n *\n * @see {@link Query#cancel}\n */\n destroy(): void {\n super.destroy()\n\n this.cancel({ silent: true })\n }\n\n /** @internal */\n get resetState(): QueryState<TData, TError> {\n return this.#initialState\n }\n\n /**\n * Resets the query back to its initial state (the state it had when it was\n * first created, e.g. any `initialData`), destroying it first to cancel any\n * in-flight fetch.\n */\n reset(): void {\n this.destroy()\n this.setState(this.resetState)\n }\n\n /**\n * Returns `true` if the query has at least one observer for which `enabled`\n * does not resolve to `false`.\n */\n isActive(): boolean {\n return this.observers.some(\n (observer) => resolveQueryValue(observer.options.enabled, this) !== false,\n )\n }\n\n /**\n * Returns `true` if the query is disabled, meaning it will not fetch\n * automatically.\n * - If the query has observers, it is disabled when none of them are active\n * (see `isActive`).\n * - If the query has no observers, it is disabled when its `queryFn` is\n * `skipToken` or it has never been fetched.\n */\n isDisabled(): boolean {\n if (this.getObserversCount() > 0) {\n return !this.isActive()\n }\n // if a query has no observers, it should still be considered disabled if it never attempted a fetch\n return this.options.queryFn === skipToken || !this.isFetched()\n }\n\n /**\n * Returns `true` if the query has been fetched, i.e. it has resolved with\n * either data or an error at least once.\n */\n isFetched() {\n return this.state.dataUpdateCount + this.state.errorUpdateCount > 0\n }\n\n /**\n * Returns `true` if the query has at least one observer configured with\n * `staleTime: 'static'`, meaning it is treated as never stale.\n */\n isStatic(): boolean {\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) =>\n resolveQueryValue(observer.options.staleTime, this) === 'static',\n )\n }\n\n return false\n }\n\n /**\n * Returns `true` if the query is stale.\n * - If the query has observers, defers to whether any observer's current\n * result reports `isStale` (which accounts for each observer's own\n * `staleTime` and `enabled` state).\n * - If the query has no observers, it is considered stale when it has no\n * data or has been invalidated.\n *\n * @see {@link Query#isStaleByTime}\n * @example\n * ```ts\n * if (query.isStale()) {\n * // refetch or otherwise treat the cached data as outdated\n * }\n * ```\n */\n isStale(): boolean {\n // check observers first, their `isStale` has the source of truth\n // calculated with `isStaleByTime` and it takes `enabled` into account\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) => observer.getCurrentResult().isStale,\n )\n }\n\n return this.state.data === undefined || this.state.isInvalidated\n }\n\n /**\n * Returns `true` if the query's data is stale relative to the given\n * `staleTime` (defaults to `0`).\n * - A query with no data is always stale.\n * - `staleTime: 'static'` is never stale.\n * - An invalidated query is always stale.\n * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.\n *\n * @see {@link Query#isStale}\n * @example\n * ```ts\n * const isStale = query.isStaleByTime(1000 * 60)\n * ```\n */\n isStaleByTime(staleTime: StaleTime = 0): boolean {\n // no data is always stale\n if (this.state.data === undefined) {\n return true\n }\n // static is never stale\n if (staleTime === 'static') {\n return false\n }\n // if the query is invalidated, it is stale\n if (this.state.isInvalidated) {\n return true\n }\n\n return !timeUntilStale(this.state.dataUpdatedAt, staleTime)\n }\n\n /** @internal */\n onFocus(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /** @internal */\n onOnline(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnReconnect())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /** @internal */\n addObserver(observer: QueryObserver<any, any, any, any, any>): void {\n if (!this.observers.includes(observer)) {\n this.observers.push(observer)\n\n // Stop the query from being garbage collected\n this.clearGcTimeout()\n\n this.#cache.notify({ type: 'observerAdded', query: this, observer })\n }\n }\n\n /** @internal */\n removeObserver(observer: QueryObserver<any, any, any, any, any>): void {\n const index = this.observers.indexOf(observer)\n if (index !== -1) {\n this.observers.splice(index, 1)\n\n if (!this.observers.length) {\n // If the transport layer does not support cancellation\n // we'll let the query continue so the result can be cached\n if (this.#retryer) {\n if (\n this.#abortSignalConsumed ||\n (this.state.fetchStatus === 'paused' &&\n this.state.status === 'pending')\n ) {\n this.#retryer.cancel({ revert: true })\n } else {\n this.#retryer.cancelRetry()\n }\n }\n\n this.scheduleGc()\n }\n\n this.#cache.notify({ type: 'observerRemoved', query: this, observer })\n }\n }\n\n /**\n * Returns the number of observers currently subscribed to this query.\n *\n * @example\n * ```ts\n * if (query.getObserversCount() === 0) {\n * // no component is currently watching this query\n * }\n * ```\n */\n getObserversCount(): number {\n return this.observers.length\n }\n\n /**\n * Marks the query as invalidated, unless it is already invalidated. This\n * updates `state.isInvalidated` and notifies observers, but does not by\n * itself trigger a refetch.\n *\n * @example\n * ```ts\n * query.invalidate()\n * ```\n */\n invalidate(): void {\n if (!this.state.isInvalidated) {\n this.#dispatch({ type: 'invalidate' })\n }\n }\n\n /**\n * Fetches the query, i.e. runs its `queryFn` (through any configured\n * retryer/behavior) and updates the query's state with the result.\n * - If a fetch is already in flight, returns its promise instead of\n * starting a new one, unless `fetchOptions.cancelRefetch` is set and the\n * query already has data, in which case the current fetch is silently\n * cancelled first.\n * - If `options` is passed, it replaces the query's current options\n * before fetching.\n */\n async fetch(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n fetchOptions?: FetchOptions<TQueryFnData>,\n ): Promise<TData> {\n if (\n this.state.fetchStatus !== 'idle' &&\n // If the promise in the retryer is already rejected, we have to definitely\n // re-start the fetch; there is a chance that the query is still in a\n // pending state when that happens\n this.#retryer?.status() !== 'rejected'\n ) {\n if (this.state.data !== undefined && fetchOptions?.cancelRefetch) {\n // Silently cancel current fetch if the user wants to cancel refetch\n this.cancel({ silent: true })\n } else if (this.#retryer) {\n // make sure that retries that were potentially cancelled due to unmounts can continue\n this.#retryer.continueRetry()\n // Return current promise if we are already fetching\n return this.#retryer.promise\n }\n }\n\n // Update config if passed, otherwise the config from the last execution is used\n if (options) {\n this.setOptions(options)\n }\n\n // Use the options from the first observer with a query function if no function is found.\n // This can happen when the query is hydrated or created with setQueryData.\n if (!this.options.queryFn) {\n const observer = this.observers.find((x) => x.options.queryFn)\n if (observer) {\n this.setOptions(observer.options)\n }\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!Array.isArray(this.options.queryKey)) {\n console.error(\n `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`,\n )\n }\n }\n\n const abortController = new AbortController()\n\n // Adds an enumerable signal property to the object that\n // which sets abortSignalConsumed to true when the signal\n // is read.\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n this.#abortSignalConsumed = true\n return abortController.signal\n },\n })\n }\n\n // Create fetch function\n const fetchFn = () => {\n const queryFn = ensureQueryFn(this.options, fetchOptions)\n\n // Create query function context\n const createQueryFnContext = (): QueryFunctionContext<TQueryKey> => {\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<TQueryKey>,\n 'signal'\n > = {\n client: this.#client,\n queryKey: this.queryKey,\n meta: this.meta,\n }\n addSignalProperty(queryFnContext)\n return queryFnContext as QueryFunctionContext<TQueryKey>\n }\n\n const queryFnContext = createQueryFnContext()\n\n this.#abortSignalConsumed = false\n if (this.options.persister) {\n return this.options.persister(\n queryFn,\n queryFnContext,\n this as unknown as Query,\n )\n }\n\n return queryFn(queryFnContext)\n }\n\n // Trigger behavior hook\n const createFetchContext = (): FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n > => {\n const context: OmitKeyof<\n FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n 'signal'\n > = {\n fetchOptions,\n options: this.options,\n queryKey: this.queryKey,\n client: this.#client,\n state: this.state,\n fetchFn,\n }\n\n addSignalProperty(context)\n return context as FetchContext<TQueryFnData, TError, TData, TQueryKey>\n }\n\n const context = createFetchContext()\n\n const behavior =\n this.#queryType === 'infinite'\n ? (infiniteQueryBehavior(\n (this.options as { pages?: number }).pages,\n ) as QueryBehavior<TQueryFnData, TError, TData, TQueryKey>)\n : this.options.behavior\n behavior?.onFetch(context, this as unknown as Query)\n\n // Store state in case the current fetch needs to be reverted\n this.#revertState = this.state\n\n // Set to fetching state if not already in it\n if (\n this.state.fetchStatus === 'idle' ||\n this.state.fetchMeta !== context.fetchOptions?.meta\n ) {\n this.#dispatch({ type: 'fetch', meta: context.fetchOptions?.meta })\n }\n\n // Try to fetch the data\n const retryer = (this.#retryer = createRetryer({\n initialPromise: fetchOptions?.initialPromise as\n Promise<TData> | undefined,\n fn: context.fetchFn as () => Promise<TData>,\n onCancel: (error) => {\n if (error instanceof CancelledError && error.revert) {\n this.setState({\n ...this.#revertState,\n fetchStatus: 'idle' as const,\n })\n }\n abortController.abort()\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.#dispatch({ type: 'continue' })\n },\n retry: context.options.retry,\n retryDelay: context.options.retryDelay,\n networkMode: context.options.networkMode,\n canRun: () => true,\n }))\n\n try {\n const data = await retryer.start()\n // this is more of a runtime guard\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (data === undefined) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`,\n )\n }\n throw new Error(`${this.queryHash} data is undefined`)\n }\n\n this.setData(data)\n\n // Notify cache callback\n this.#cache.config.onSuccess?.(data, this as Query<any, any, any, any>)\n this.#cache.config.onSettled?.(\n data,\n this.state.error as any,\n this as Query<any, any, any, any>,\n )\n return data\n } catch (error) {\n if (error instanceof CancelledError) {\n if (error.silent) {\n // silent cancellation implies a new fetch is going to be started,\n // so we piggyback onto that promise\n return this.#retryer.promise\n } else if (error.revert) {\n // transform error into reverted state data\n // if the initial fetch was cancelled, we have no data, so we have\n // to get reject with a CancelledError\n if (this.state.data === undefined) {\n throw error\n }\n return this.state.data\n }\n }\n this.#dispatch({\n type: 'error',\n error: error as TError,\n })\n\n // Notify cache callback\n this.#cache.config.onError?.(\n error as any,\n this as Query<any, any, any, any>,\n )\n this.#cache.config.onSettled?.(\n this.state.data,\n error as any,\n this as Query<any, any, any, any>,\n )\n\n throw error // rethrow the error for further handling\n } finally {\n // The settled retryer's promise would otherwise pin this fetch's raw\n // result (a second copy after structural sharing) for the query's lifetime\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n // Schedule query gc after fetching\n this.scheduleGc()\n }\n }\n\n #dispatch(action: Action<TData, TError>): void {\n const reducer = (\n state: QueryState<TData, TError>,\n ): QueryState<TData, TError> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n fetchFailureCount: action.failureCount,\n fetchFailureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n fetchStatus: 'paused',\n }\n case 'continue':\n return {\n ...state,\n fetchStatus: 'fetching',\n }\n case 'fetch':\n return {\n ...state,\n ...fetchState(state.data, this.options),\n fetchMeta: action.meta ?? null,\n }\n case 'success':\n const newState = {\n ...state,\n ...successState(action.data, action.dataUpdatedAt),\n dataUpdateCount: state.dataUpdateCount + 1,\n ...(!action.manual && {\n fetchStatus: 'idle' as const,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n }),\n }\n // If fetching ends successfully, we don't need revertState as a fallback anymore.\n // For manual updates, capture the state to revert to it in case of a cancellation.\n this.#revertState = action.manual ? newState : undefined\n\n return newState\n case 'error':\n const error = action.error\n return {\n ...state,\n error,\n errorUpdateCount: state.errorUpdateCount + 1,\n errorUpdatedAt: Date.now(),\n fetchFailureCount: state.fetchFailureCount + 1,\n fetchFailureReason: error,\n fetchStatus: 'idle',\n status: 'error',\n // flag existing data as invalidated if we get a background error\n // note that \"no data\" always means stale so we can set unconditionally here\n isInvalidated: true,\n }\n case 'invalidate':\n return {\n ...state,\n isInvalidated: true,\n }\n case 'setState':\n return {\n ...state,\n ...action.state,\n }\n }\n }\n\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n // Keep the current iteration stable if an observer unsubscribes\n // synchronously while it is being notified.\n this.observers.slice().forEach((observer) => {\n observer.onQueryUpdate()\n })\n\n this.#cache.notify({ query: this, type: 'updated', action })\n })\n }\n}\n\nexport function fetchState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n data: TData | undefined,\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n) {\n return {\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',\n ...(data === undefined &&\n ({\n error: null,\n status: 'pending',\n } as const)),\n } as const\n}\n\nfunction successState<TData>(data: TData | undefined, dataUpdatedAt?: number) {\n return {\n data,\n dataUpdatedAt: dataUpdatedAt ?? Date.now(),\n error: null,\n isInvalidated: false,\n status: 'success' as const,\n }\n}\n\nfunction getDefaultState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): QueryState<TData, TError> {\n const data =\n typeof options.initialData === 'function'\n ? (options.initialData as InitialDataFunction<TData>)()\n : options.initialData\n\n const hasData = data !== undefined\n\n const initialDataUpdatedAt = hasData\n ? typeof options.initialDataUpdatedAt === 'function'\n ? options.initialDataUpdatedAt()\n : options.initialDataUpdatedAt\n : 0\n\n return {\n data,\n dataUpdateCount: 0,\n dataUpdatedAt: hasData ? (initialDataUpdatedAt ?? Date.now()) : 0,\n error: null,\n errorUpdateCount: 0,\n errorUpdatedAt: 0,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchMeta: null,\n isInvalidated: false,\n status: hasData ? 'success' : 'pending',\n fetchStatus: 'idle',\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgOA,IAAa,QAAb,cAKU,UAAU;CAgBlB,YAAY,QAA6D;EACvE,MAAM;;;;;;;;;;EAEN,uBAAA,sBAAA,MAA4B,KAAA;EAC5B,uBAAA,iBAAA,MAAuB,OAAO,cAAA;EAC9B,KAAK,WAAW,OAAO,OAAO;EAC9B,KAAK,YAAY,CAAC;EAClB,uBAAA,SAAA,MAAe,OAAO,MAAA;EACtB,uBAAA,QAAA,MAAA,uBAAA,SAAc,IAAA,CAAA,CAAa,cAAc,CAAA;EACzC,KAAK,WAAW,OAAO;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BAAyB,aACtC,QAAQ,qBAAqB,IAC7B,QAAQ,uBACV;CAEJ,OAAO;EACL;EACA,iBAAiB;EACjB,eAAe,UAAW,wBAAwB,KAAK,IAAI,IAAK;EAChE,OAAO;EACP,kBAAkB;EAClB,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;EACpB,WAAW;EACX,eAAe;EACf,QAAQ,UAAU,YAAY;EAC9B,aAAa;CACf;AACF"}
1
+ {"version":3,"file":"query.js","names":[],"sources":["../../src/query.ts"],"sourcesContent":["import {\n ensureQueryFn,\n noop,\n replaceData,\n resolveQueryValue,\n skipToken,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport { CancelledError, canFetch, createRetryer } from './retryer'\nimport { Removable } from './removable'\nimport { infiniteQueryBehavior } from './infiniteQueryBehavior'\nimport type { QueryCache } from './queryCache'\nimport type { QueryClient } from './queryClient'\nimport type {\n CancelOptions,\n DefaultError,\n FetchStatus,\n InitialDataFunction,\n OmitKeyof,\n QueryFunctionContext,\n QueryKey,\n QueryMeta,\n QueryOptions,\n QueryStatus,\n SetDataOptions,\n StaleTime,\n} from './types'\nimport type { QueryObserver } from './queryObserver'\nimport type { Retryer } from './retryer'\n\n// TYPES\n\ninterface QueryConfig<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n client: QueryClient\n queryKey: TQueryKey\n queryHash: string\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state?: QueryState<TData, TError>\n}\n\n/**\n * The raw state stored on a `Query` instance. This is the underlying state\n * that observer results (e.g. `QueryObserverResult`) are derived from.\n */\nexport interface QueryState<TData = unknown, TError = DefaultError> {\n /**\n * The last successfully resolved data for the query.\n */\n data: TData | undefined\n /**\n * The number of times the query has successfully resolved.\n */\n dataUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"success\"`.\n */\n dataUpdatedAt: number\n /**\n * The error object for the query, if the last attempt resulted in an error.\n * - Defaults to `null`.\n */\n error: TError | null\n /**\n * The sum of all errors, incremented every time the query resolves with an error.\n */\n errorUpdateCount: number\n /**\n * The timestamp for when the query most recently returned the `status` as `\"error\"`.\n */\n errorUpdatedAt: number\n /**\n * The failure count for the current fetch.\n * - Incremented every time the fetch fails.\n * - Reset to `0` when the fetch succeeds.\n */\n fetchFailureCount: number\n /**\n * The reason the current fetch failed, as reported by the retryer.\n * - Reset to `null` when the fetch succeeds.\n */\n fetchFailureReason: TError | null\n /**\n * Metadata passed to the currently in-flight (or most recent) fetch, e.g. the\n * `fetchMore` direction for infinite queries.\n */\n fetchMeta: FetchMeta | null\n /**\n * Whether the query has been marked as invalidated via `invalidate()`.\n * - Reset to `false` whenever the query resolves successfully.\n */\n isInvalidated: boolean\n /**\n * The status of the query.\n * - `pending` if there's no cached data and no attempt was finished yet.\n * - `error` if the last attempt resulted in an error.\n * - `success` if the query has data.\n */\n status: QueryStatus\n /**\n * The fetch status of the query.\n * - `fetching`: the `queryFn` is currently executing.\n * - `paused`: a fetch wanted to run but has been paused (see network mode).\n * - `idle`: the query is not fetching.\n */\n fetchStatus: FetchStatus\n}\n\n/**\n * The context passed to a {@link QueryBehavior}'s `onFetch`, which can replace `fetchFn` to change\n * how the query fetches (e.g. to fetch pages for an infinite query).\n */\nexport interface FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n /**\n * The function that runs the fetch. By default it calls `queryFn`; `onFetch` can replace it.\n */\n fetchFn: () => unknown | Promise<unknown>\n /**\n * The options of this fetch.\n */\n fetchOptions?: FetchOptions\n /**\n * The `AbortSignal` that aborts when the fetch is cancelled.\n */\n signal: AbortSignal\n /**\n * The options of the query.\n */\n options: QueryOptions<TQueryFnData, TError, TData, any>\n /**\n * The `QueryClient` the query belongs to.\n */\n client: QueryClient\n /**\n * The key of the query.\n */\n queryKey: TQueryKey\n /**\n * The state of the query when the fetch starts.\n */\n state: QueryState<TData, TError>\n}\n\n/**\n * Customizes how a query fetches, e.g. the behavior that fetches the pages of an infinite query.\n */\nexport interface QueryBehavior<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> {\n /**\n * Called before each fetch of the query, e.g. to replace `fetchFn` in the context.\n */\n onFetch: (\n context: FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n query: Query,\n ) => void\n}\n\n/**\n * The direction an infinite query fetches in: `'forward'` for the next page, `'backward'` for the\n * previous one.\n */\nexport type FetchDirection = 'forward' | 'backward'\n\n/**\n * Metadata for a fetch, e.g. the direction when an infinite query fetches more pages.\n */\nexport interface FetchMeta {\n /**\n * Set when an infinite query fetches another page, with the direction to fetch in.\n */\n fetchMore?: { direction: FetchDirection }\n}\n\n/**\n * Options for a single fetch of a query.\n */\nexport interface FetchOptions<TData = unknown> {\n /**\n * If `true`, an in-flight fetch is cancelled before starting a new one, when the query already\n * has data. Otherwise, the in-flight fetch is reused.\n */\n cancelRefetch?: boolean\n /**\n * Metadata of the fetch, stored in the query's `fetchMeta` state.\n */\n meta?: FetchMeta\n /**\n * A promise to use for the first attempt instead of calling `fetchFn`, e.g. a pending promise\n * restored by `hydrate`.\n */\n initialPromise?: Promise<TData>\n}\n\ninterface FailedAction<TError> {\n type: 'failed'\n failureCount: number\n error: TError\n}\n\ninterface FetchAction {\n type: 'fetch'\n meta?: FetchMeta\n}\n\ninterface SuccessAction<TData> {\n data: TData | undefined\n type: 'success'\n dataUpdatedAt?: number\n manual?: boolean\n}\n\ninterface ErrorAction<TError> {\n type: 'error'\n error: TError\n}\n\ninterface InvalidateAction {\n type: 'invalidate'\n}\n\ninterface PauseAction {\n type: 'pause'\n}\n\ninterface ContinueAction {\n type: 'continue'\n}\n\ninterface SetStateAction<TData, TError> {\n type: 'setState'\n state: Partial<QueryState<TData, TError>>\n}\n\n/**\n * The actions a query dispatches to update its state, e.g. when it starts fetching, fails, or\n * succeeds.\n */\nexport type Action<TData, TError> =\n | ContinueAction\n | ErrorAction<TError>\n | FailedAction<TError>\n | FetchAction\n | InvalidateAction\n | PauseAction\n | SetStateAction<TData, TError>\n | SuccessAction<TData>\n\n// CLASS\n\n/**\n * Represents a single cached query. A `Query` holds the query's key, options,\n * state (data/error/status), and the observers currently subscribed to it.\n *\n * Instances are created and managed internally by `QueryCache`; application\n * code typically interacts with queries indirectly through `QueryClient` or\n * a framework hook like `useQuery`. Direct access to a `Query` instance is\n * possible via `queryCache.find()`/`findAll()` for inspecting cache state.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * console.log(query.state.dataUpdatedAt)\n * }\n * ```\n */\nexport class Query<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Removable {\n queryKey: TQueryKey\n queryHash: string\n options!: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n state: QueryState<TData, TError>\n #queryType?: 'infinite'\n\n #initialState: QueryState<TData, TError>\n #revertState?: QueryState<TData, TError>\n #cache: QueryCache\n #client: QueryClient\n #retryer?: Retryer<TData>\n observers: Array<QueryObserver<any, any, any, any, any>>\n #defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>\n #abortSignalConsumed: boolean\n\n constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>) {\n super()\n\n this.#abortSignalConsumed = false\n this.#defaultOptions = config.defaultOptions\n this.setOptions(config.options)\n this.observers = []\n this.#client = config.client\n this.#cache = this.#client.getQueryCache()\n this.queryKey = config.queryKey\n this.queryHash = config.queryHash\n this.#initialState = getDefaultState(this.options)\n this.state = config.state ?? this.#initialState\n this.scheduleGc()\n }\n /**\n * The `meta` object passed in the query's options, if any.\n * @returns The query's `meta`, or `undefined` if none was set.\n */\n get meta(): QueryMeta | undefined {\n return this.options.meta\n }\n\n /**\n * `'infinite'` for an infinite query, otherwise `undefined`.\n * @internal\n * @returns The type of the query, set from the `_type` option (e.g. `'infinite'`).\n */\n get queryType() {\n return this.#queryType\n }\n\n /**\n * The promise for the currently in-flight fetch, if the query is fetching.\n * `undefined` when the query is not fetching.\n * @returns The promise of the in-flight fetch, or `undefined`.\n */\n get promise(): Promise<TData> | undefined {\n return this.#retryer?.promise\n }\n\n /**\n * Replaces the query's options and applies their `gcTime`. If the query has no data yet, it gets\n * the `initialData` from the new options, if any.\n * @internal\n * @param options - The new query options, merged on top of the query's default options.\n */\n setOptions(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n ): void {\n this.options = { ...this.#defaultOptions, ...options }\n\n if (options?._type) {\n this.#queryType = options._type\n }\n\n this.updateGcTime(this.options.gcTime)\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (this.state && this.state.data === undefined) {\n const defaultState = getDefaultState(this.options)\n if (defaultState.data !== undefined) {\n this.setState(\n successState(defaultState.data, defaultState.dataUpdatedAt),\n )\n this.#initialState = defaultState\n }\n }\n }\n\n protected override optionalRemove() {\n if (!this.observers.length && this.state.fetchStatus === 'idle') {\n this.#cache.remove(this)\n }\n }\n\n /**\n * Writes new data to the query and marks it as successfully fetched.\n * @internal\n * @param newData - The data to write. Structural sharing with the current data is applied.\n * @param options - Set `updatedAt` to override the timestamp, and `manual` to mark the write as\n * manual (e.g. from `queryClient.setQueryData`).\n * @returns The data that was written.\n */\n setData(\n newData: TData,\n options?: SetDataOptions & { manual: boolean },\n ): TData {\n const data = replaceData(this.state.data, newData, this.options)\n\n // Set data and mark it as cached\n this.#dispatch({\n data,\n type: 'success',\n dataUpdatedAt: options?.updatedAt,\n manual: options?.manual,\n })\n\n return data\n }\n\n /**\n * Merges the given partial state directly into this query's state, notifying observers. Used\n * by persistence and broadcast plugins to restore a state snapshot, and by devtools to let a\n * user manually trigger a loading/error state or edit the cached data.\n * @param state - The partial state to merge into the query's state.\n */\n setState(state: Partial<QueryState<TData, TError>>): void {\n this.#dispatch({ type: 'setState', state })\n }\n\n /**\n * Cancels the query's currently in-flight fetch, if any.\n * - Returns a promise that resolves once the cancellation has settled.\n * - If no fetch is in progress, resolves immediately.\n * @param options - Set `revert` to restore the state from before the fetch started, and `silent`\n * to suppress the cancellation error when a new fetch replaces the cancelled one.\n * @returns A promise that resolves once the cancellation has settled.\n * @example\n * ```ts\n * await query.cancel()\n * ```\n */\n cancel(options?: CancelOptions): Promise<void> {\n const promise = this.#retryer?.promise\n this.#retryer?.cancel(options)\n return promise ? promise.then(noop).catch(noop) : Promise.resolve()\n }\n\n /**\n * Clears the query's garbage collection timeout and silently cancels any\n * in-flight fetch. Called by `QueryCache` when the query is removed from\n * the cache.\n * @see {@link Query#cancel}\n */\n override destroy(): void {\n super.destroy()\n\n this.cancel({ silent: true })\n }\n\n /**\n * The state the query was created with.\n * @internal\n * @returns The state the query had when it was first created, used by {@link Query#reset}.\n */\n get resetState(): QueryState<TData, TError> {\n return this.#initialState\n }\n\n /**\n * Resets the query back to its initial state (the state it had when it was\n * first created, e.g. any `initialData`), destroying it first to cancel any\n * in-flight fetch.\n */\n reset(): void {\n this.destroy()\n this.setState(this.resetState)\n }\n\n /**\n * Returns `true` if the query has at least one observer for which `enabled`\n * does not resolve to `false`.\n * @returns `true` if the query has an enabled observer.\n */\n isActive(): boolean {\n return this.observers.some(\n (observer) => resolveQueryValue(observer.options.enabled, this) !== false,\n )\n }\n\n /**\n * Returns `true` if the query is disabled, meaning it will not fetch\n * automatically.\n * - If the query has observers, it is disabled when none of them are active\n * (see `isActive`).\n * - If the query has no observers, it is disabled when its `queryFn` is\n * `skipToken` or it has never been fetched.\n * @returns `true` if the query is disabled.\n */\n isDisabled(): boolean {\n if (this.getObserversCount() > 0) {\n return !this.isActive()\n }\n // if a query has no observers, it should still be considered disabled if it never attempted a fetch\n return this.options.queryFn === skipToken || !this.isFetched()\n }\n\n /**\n * Returns `true` if the query has been fetched, i.e. it has resolved with\n * either data or an error at least once.\n * @returns `true` if the query has been fetched.\n */\n isFetched() {\n return this.state.dataUpdateCount + this.state.errorUpdateCount > 0\n }\n\n /**\n * Returns `true` if the query has at least one observer configured with\n * `staleTime: 'static'`, meaning it is treated as never stale.\n * @returns `true` if the query is static.\n */\n isStatic(): boolean {\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) =>\n resolveQueryValue(observer.options.staleTime, this) === 'static',\n )\n }\n\n return false\n }\n\n /**\n * Returns `true` if the query is stale.\n * - If the query has observers, defers to whether any observer's current\n * result reports `isStale` (which accounts for each observer's own\n * `staleTime` and `enabled` state).\n * - If the query has no observers, it is considered stale when it has no\n * data or has been invalidated.\n * @returns `true` if the query is stale.\n * @see {@link Query#isStaleByTime}\n * @example\n * ```ts\n * if (query.isStale()) {\n * // refetch or otherwise treat the cached data as outdated\n * }\n * ```\n */\n isStale(): boolean {\n // check observers first, their `isStale` has the source of truth\n // calculated with `isStaleByTime` and it takes `enabled` into account\n if (this.getObserversCount() > 0) {\n return this.observers.some(\n (observer) => observer.getCurrentResult().isStale,\n )\n }\n\n return this.state.data === undefined || this.state.isInvalidated\n }\n\n /**\n * Returns `true` if the query's data is stale relative to the given\n * `staleTime` (defaults to `0`).\n * - A query with no data is always stale.\n * - `staleTime: 'static'` is never stale.\n * - An invalidated query is always stale.\n * - Otherwise, staleness is based on elapsed time since `dataUpdatedAt`.\n * @param staleTime - The time, in milliseconds, after which data is considered stale, or\n * `'static'` to never treat existing data as stale. A query without data is stale either way.\n * @returns `true` if the query's data is stale.\n * @see {@link Query#isStale}\n * @example\n * ```ts\n * const isStale = query.isStaleByTime(1000 * 60)\n * ```\n */\n isStaleByTime(staleTime: StaleTime = 0): boolean {\n // no data is always stale\n if (this.state.data === undefined) {\n return true\n }\n // static is never stale\n if (staleTime === 'static') {\n return false\n }\n // if the query is invalidated, it is stale\n if (this.state.isInvalidated) {\n return true\n }\n\n return !timeUntilStale(this.state.dataUpdatedAt, staleTime)\n }\n\n /**\n * Refetches the query when the window regains focus, if an observer wants that, and continues a\n * paused fetch.\n * @internal\n */\n onFocus(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /**\n * Refetches the query when the app reconnects, if an observer wants that, and continues a paused\n * fetch.\n * @internal\n */\n onOnline(): void {\n const observer = this.observers.find((x) => x.shouldFetchOnReconnect())\n\n observer?.refetch({ cancelRefetch: false })\n\n // Continue fetch if currently paused\n this.#retryer?.continue()\n }\n\n /**\n * Subscribes an observer to the query and stops its garbage collection.\n * @internal\n * @param observer - The observer to add. Adding an observer that is already subscribed does\n * nothing.\n */\n addObserver(observer: QueryObserver<any, any, any, any, any>): void {\n if (!this.observers.includes(observer)) {\n this.observers.push(observer)\n\n // Stop the query from being garbage collected\n this.clearGcTimeout()\n\n this.#cache.notify({ type: 'observerAdded', query: this, observer })\n }\n }\n\n /**\n * Unsubscribes an observer from the query.\n * @internal\n * @param observer - The observer to remove. When the last observer is removed, the in-flight\n * fetch is cancelled if its abort signal was consumed (otherwise only its retries are stopped),\n * and garbage collection is scheduled.\n */\n removeObserver(observer: QueryObserver<any, any, any, any, any>): void {\n const index = this.observers.indexOf(observer)\n if (index !== -1) {\n this.observers.splice(index, 1)\n\n if (!this.observers.length) {\n // If the transport layer does not support cancellation\n // we'll let the query continue so the result can be cached\n if (this.#retryer) {\n if (\n this.#abortSignalConsumed ||\n (this.state.fetchStatus === 'paused' &&\n this.state.status === 'pending')\n ) {\n this.#retryer.cancel({ revert: true })\n } else {\n this.#retryer.cancelRetry()\n }\n }\n\n this.scheduleGc()\n }\n\n this.#cache.notify({ type: 'observerRemoved', query: this, observer })\n }\n }\n\n /**\n * Returns the number of observers currently subscribed to this query.\n * @returns The number of observers.\n * @example\n * ```ts\n * if (query.getObserversCount() === 0) {\n * // no component is currently watching this query\n * }\n * ```\n */\n getObserversCount(): number {\n return this.observers.length\n }\n\n /**\n * Marks the query as invalidated, unless it is already invalidated. This\n * updates `state.isInvalidated` and notifies observers, but does not by\n * itself trigger a refetch.\n * @example\n * ```ts\n * query.invalidate()\n * ```\n */\n invalidate(): void {\n if (!this.state.isInvalidated) {\n this.#dispatch({ type: 'invalidate' })\n }\n }\n\n /**\n * Fetches the query, i.e. runs its `queryFn` (through any configured\n * retryer/behavior) and updates the query's state with the result.\n * - If a fetch is already in flight, returns its promise instead of\n * starting a new one, unless `fetchOptions.cancelRefetch` is set and the\n * query already has data, in which case the current fetch is silently\n * cancelled first.\n * - If `options` is passed, it replaces the query's current options\n * before fetching.\n * @param options - Query options that replace the query's current options before fetching. They\n * are not applied when an in-flight fetch is reused.\n * @param fetchOptions - Set `cancelRefetch` to cancel an in-flight fetch first (only if the query\n * already has data), and `meta` to pass extra information to the query's behavior.\n * @returns A promise that resolves with the fetched data, or rejects with the fetch error. If the\n * fetch is cancelled with `revert` while the query has data, it resolves with the restored data\n * instead.\n */\n async fetch(\n options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n fetchOptions?: FetchOptions<TQueryFnData>,\n ): Promise<TData> {\n if (\n this.state.fetchStatus !== 'idle' &&\n // If the promise in the retryer is already rejected, we have to definitely\n // re-start the fetch; there is a chance that the query is still in a\n // pending state when that happens\n this.#retryer?.status() !== 'rejected'\n ) {\n if (this.state.data !== undefined && fetchOptions?.cancelRefetch) {\n // Silently cancel current fetch if the user wants to cancel refetch\n this.cancel({ silent: true })\n } else if (this.#retryer) {\n // make sure that retries that were potentially cancelled due to unmounts can continue\n this.#retryer.continueRetry()\n // Return current promise if we are already fetching\n return this.#retryer.promise\n }\n }\n\n // Update config if passed, otherwise the config from the last execution is used\n if (options) {\n this.setOptions(options)\n }\n\n // Use the options from the first observer with a query function if no function is found.\n // This can happen when the query is hydrated or created with setQueryData.\n if (!this.options.queryFn) {\n const observer = this.observers.find((x) => x.options.queryFn)\n if (observer) {\n this.setOptions(observer.options)\n }\n }\n\n if (process.env.NODE_ENV !== 'production') {\n if (!Array.isArray(this.options.queryKey)) {\n console.error(\n `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`,\n )\n }\n }\n\n const abortController = new AbortController()\n\n // Adds an enumerable signal property to the object that\n // which sets abortSignalConsumed to true when the signal\n // is read.\n const addSignalProperty = (object: unknown) => {\n Object.defineProperty(object, 'signal', {\n enumerable: true,\n get: () => {\n this.#abortSignalConsumed = true\n return abortController.signal\n },\n })\n }\n\n // Create fetch function\n const fetchFn = () => {\n const queryFn = ensureQueryFn(this.options, fetchOptions)\n\n // Create query function context\n const createQueryFnContext = (): QueryFunctionContext<TQueryKey> => {\n const queryFnContext: OmitKeyof<\n QueryFunctionContext<TQueryKey>,\n 'signal'\n > = {\n client: this.#client,\n queryKey: this.queryKey,\n meta: this.meta,\n }\n addSignalProperty(queryFnContext)\n return queryFnContext as QueryFunctionContext<TQueryKey>\n }\n\n const queryFnContext = createQueryFnContext()\n\n this.#abortSignalConsumed = false\n if (this.options.persister) {\n return this.options.persister(\n queryFn,\n queryFnContext,\n this as unknown as Query,\n )\n }\n\n return queryFn(queryFnContext)\n }\n\n // Trigger behavior hook\n const createFetchContext = (): FetchContext<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n > => {\n const context: OmitKeyof<\n FetchContext<TQueryFnData, TError, TData, TQueryKey>,\n 'signal'\n > = {\n fetchOptions,\n options: this.options,\n queryKey: this.queryKey,\n client: this.#client,\n state: this.state,\n fetchFn,\n }\n\n addSignalProperty(context)\n return context as FetchContext<TQueryFnData, TError, TData, TQueryKey>\n }\n\n const context = createFetchContext()\n\n const behavior =\n this.#queryType === 'infinite'\n ? (infiniteQueryBehavior(\n (this.options as { pages?: number }).pages,\n ) as QueryBehavior<TQueryFnData, TError, TData, TQueryKey>)\n : this.options.behavior\n behavior?.onFetch(context, this as unknown as Query)\n\n // Store state in case the current fetch needs to be reverted\n this.#revertState = this.state\n\n // Set to fetching state if not already in it\n if (\n this.state.fetchStatus === 'idle' ||\n this.state.fetchMeta !== context.fetchOptions?.meta\n ) {\n this.#dispatch({ type: 'fetch', meta: context.fetchOptions?.meta })\n }\n\n // Try to fetch the data\n const retryer = (this.#retryer = createRetryer({\n initialPromise: fetchOptions?.initialPromise as\n | Promise<TData>\n | undefined,\n fn: context.fetchFn as () => Promise<TData>,\n onCancel: (error) => {\n if (error instanceof CancelledError && error.revert) {\n this.setState({\n ...this.#revertState,\n fetchStatus: 'idle' as const,\n })\n }\n abortController.abort()\n },\n onFail: (failureCount, error) => {\n this.#dispatch({ type: 'failed', failureCount, error })\n },\n onPause: () => {\n this.#dispatch({ type: 'pause' })\n },\n onContinue: () => {\n this.#dispatch({ type: 'continue' })\n },\n retry: context.options.retry,\n retryDelay: context.options.retryDelay,\n networkMode: context.options.networkMode,\n canRun: () => true,\n }))\n\n try {\n const data = await retryer.start()\n // this is more of a runtime guard\n if (data === undefined) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`,\n )\n }\n throw new Error(`${this.queryHash} data is undefined`)\n }\n\n this.setData(data)\n\n // Notify cache callback\n this.#cache.config.onSuccess?.(data, this as Query<any, any, any, any>)\n this.#cache.config.onSettled?.(\n data,\n this.state.error as any,\n this as Query<any, any, any, any>,\n )\n return data\n } catch (error) {\n if (error instanceof CancelledError) {\n if (error.silent) {\n // silent cancellation implies a new fetch is going to be started,\n // so we piggyback onto that promise\n return this.#retryer.promise\n } else if (error.revert) {\n // transform error into reverted state data\n // if the initial fetch was cancelled, we have no data, so we have\n // to get reject with a CancelledError\n if (this.state.data === undefined) {\n throw error\n }\n return this.state.data\n }\n }\n this.#dispatch({\n type: 'error',\n error: error as TError,\n })\n\n // Notify cache callback\n this.#cache.config.onError?.(\n error as any,\n this as Query<any, any, any, any>,\n )\n this.#cache.config.onSettled?.(\n this.state.data,\n error as any,\n this as Query<any, any, any, any>,\n )\n\n throw error // rethrow the error for further handling\n } finally {\n // The settled retryer's promise would otherwise pin this fetch's raw\n // result (a second copy after structural sharing) for the query's lifetime\n if (this.#retryer === retryer) {\n this.#retryer = undefined\n }\n // Schedule query gc after fetching\n this.scheduleGc()\n }\n }\n\n #dispatch(action: Action<TData, TError>): void {\n const reducer = (\n state: QueryState<TData, TError>,\n ): QueryState<TData, TError> => {\n switch (action.type) {\n case 'failed':\n return {\n ...state,\n fetchFailureCount: action.failureCount,\n fetchFailureReason: action.error,\n }\n case 'pause':\n return {\n ...state,\n fetchStatus: 'paused',\n }\n case 'continue':\n return {\n ...state,\n fetchStatus: 'fetching',\n }\n case 'fetch':\n return {\n ...state,\n ...fetchState(state.data, this.options),\n fetchMeta: action.meta ?? null,\n }\n case 'success':\n const newState = {\n ...state,\n ...successState(action.data, action.dataUpdatedAt),\n dataUpdateCount: state.dataUpdateCount + 1,\n ...(!action.manual && {\n fetchStatus: 'idle' as const,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n }),\n }\n // If fetching ends successfully, we don't need revertState as a fallback anymore.\n // For manual updates, capture the state to revert to it in case of a cancellation.\n this.#revertState = action.manual ? newState : undefined\n\n return newState\n case 'error':\n const error = action.error\n return {\n ...state,\n error,\n errorUpdateCount: state.errorUpdateCount + 1,\n errorUpdatedAt: Date.now(),\n fetchFailureCount: state.fetchFailureCount + 1,\n fetchFailureReason: error,\n fetchStatus: 'idle',\n status: 'error',\n // flag existing data as invalidated if we get a background error\n // note that \"no data\" always means stale so we can set unconditionally here\n isInvalidated: true,\n }\n case 'invalidate':\n return {\n ...state,\n isInvalidated: true,\n }\n case 'setState':\n return {\n ...state,\n ...action.state,\n }\n }\n }\n\n this.state = reducer(this.state)\n\n notifyManager.batch(() => {\n // Keep the current iteration stable if an observer unsubscribes\n // synchronously while it is being notified.\n this.observers.slice().forEach((observer) => {\n observer.onQueryUpdate()\n })\n\n this.#cache.notify({ query: this, type: 'updated', action })\n })\n }\n}\n\n/**\n * Returns the state changes applied when a query starts fetching.\n * @param data - The query's current data. If it is `undefined`, the query is also reset to\n * `'pending'` with no error.\n * @param options - The query options, whose `networkMode` decides whether the query is `'fetching'`\n * or `'paused'`.\n * @returns The partial query state for a starting fetch.\n */\nexport function fetchState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n data: TData | undefined,\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n) {\n return {\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',\n ...(data === undefined &&\n ({\n error: null,\n status: 'pending',\n } as const)),\n } as const\n}\n\n/**\n * Returns the state changes applied when a query receives data.\n * @param data - The new data.\n * @param dataUpdatedAt - The timestamp the data is recorded with. Defaults to the current time.\n * @returns The partial query state for a successful update.\n */\nfunction successState<TData>(data: TData | undefined, dataUpdatedAt?: number) {\n return {\n data,\n dataUpdatedAt: dataUpdatedAt ?? Date.now(),\n error: null,\n isInvalidated: false,\n status: 'success' as const,\n }\n}\n\n/**\n * Returns the initial state of a query, based on its `initialData` and `initialDataUpdatedAt`\n * options.\n * @param options - The query options.\n * @returns The initial query state: `'success'` if `initialData` is set, otherwise `'pending'`.\n */\nfunction getDefaultState<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): QueryState<TData, TError> {\n const data =\n typeof options.initialData === 'function'\n ? (options.initialData as InitialDataFunction<TData>)()\n : options.initialData\n\n const hasData = data !== undefined\n\n const initialDataUpdatedAt = hasData\n ? typeof options.initialDataUpdatedAt === 'function'\n ? options.initialDataUpdatedAt()\n : options.initialDataUpdatedAt\n : 0\n\n return {\n data,\n dataUpdateCount: 0,\n dataUpdatedAt: hasData ? (initialDataUpdatedAt ?? Date.now()) : 0,\n error: null,\n errorUpdateCount: 0,\n errorUpdatedAt: 0,\n fetchFailureCount: 0,\n fetchFailureReason: null,\n fetchMeta: null,\n isInvalidated: false,\n status: hasData ? 'success' : 'pending',\n fetchStatus: 'idle',\n }\n}\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AMd,MACA,SACA;CACA,OAAO;EACL,mBAAmB;EACnB,oBAAoB;EACpB,aAAa,SAAS,QAAQ,WAAW,IAAI,aAAa;EAC1D,GAAI,SAAS,KAAA,KACV;GACC,OAAO;GACP,QAAQ;EACV;CACJ;AACF;;;;;;;AAQA,SAAS,aAAoB,MAAyB,eAAwB;CAC5E,OAAO;EACL;EACA,eAAe,iBAAiB,KAAK,IAAI;EACzC,OAAO;EACP,eAAe;EACf,QAAQ;CACV;AACF;;;;;;;AAQA,SAAS,gBAMP,SAC2B;CAC3B,MAAM,OACJ,OAAO,QAAQ,gBAAgB,aAC1B,QAAQ,YAA2C,IACpD,QAAQ;CAEd,MAAM,UAAU,SAAS,KAAA;CAEzB,MAAM,uBAAuB,UACzB,OAAO,QAAQ,yBAAyB,aACtC,QAAQ,qBAAqB,IAC7B,QAAQ,uBACV;CAEJ,OAAO;EACL;EACA,iBAAiB;EACjB,eAAe,UAAW,wBAAwB,KAAK,IAAI,IAAK;EAChE,OAAO;EACP,kBAAkB;EAClB,gBAAgB;EAChB,mBAAmB;EACnB,oBAAoB;EACpB,WAAW;EACX,eAAe;EACf,QAAQ,UAAU,YAAY;EAC9B,aAAa;CACf;AACF"}
@@ -15,7 +15,6 @@ var _queries = /* @__PURE__ */ new WeakMap();
15
15
  * safe/known updates to the cache, such as queries being added, removed, or updated — updates made
16
16
  * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do
17
17
  * not notify subscribers.
18
- *
19
18
  * @example
20
19
  * ```ts
21
20
  * const unsubscribe = queryCache.subscribe((event) => {
@@ -35,7 +34,12 @@ var QueryCache = class extends require_subscribable.Subscribable {
35
34
  * builds and adds a new one to the cache if none exists yet. Used by framework adapters and
36
35
  * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
37
36
  * the reactive `QueryObserver` machinery.
38
- *
37
+ * @param client - The client the query belongs to, used to default its options.
38
+ * @param options - The query options, including the `queryKey`. A new query is created with the
39
+ * options defaulted by {@link QueryClient#defaultQueryOptions}.
40
+ * @param state - The initial state of a newly created query, e.g. when hydrating. Ignored if the
41
+ * query already exists.
42
+ * @returns The existing or newly created query.
39
43
  * @example
40
44
  * ```ts
41
45
  * const queryCache = queryClient.getQueryCache()
@@ -63,7 +67,12 @@ var QueryCache = class extends require_subscribable.Subscribable {
63
67
  }
64
68
  return query;
65
69
  }
66
- /** @internal */
70
+ /**
71
+ * Adds a query to the cache.
72
+ * @internal
73
+ * @param query - The query to add. If a query with the same hash is already cached, nothing
74
+ * happens.
75
+ */
67
76
  add(query) {
68
77
  if (!require_classPrivateFieldSet2._classPrivateFieldGet2(_queries, this).has(query.queryHash)) {
69
78
  require_classPrivateFieldSet2._classPrivateFieldGet2(_queries, this).set(query.queryHash, query);
@@ -78,7 +87,7 @@ var QueryCache = class extends require_subscribable.Subscribable {
78
87
  * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
79
88
  * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
80
89
  * removals across `QueryCache` instances.
81
- *
90
+ * @param query - The query to remove.
82
91
  * @example
83
92
  * ```ts
84
93
  * const queryCache = queryClient.getQueryCache()
@@ -101,7 +110,6 @@ var QueryCache = class extends require_subscribable.Subscribable {
101
110
  }
102
111
  /**
103
112
  * Removes all queries from the cache.
104
- *
105
113
  * @example
106
114
  * ```ts
107
115
  * const queryCache = queryClient.getQueryCache()
@@ -121,7 +129,8 @@ var QueryCache = class extends require_subscribable.Subscribable {
121
129
  * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
122
130
  * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
123
131
  * to look up directly.
124
- *
132
+ * @param queryHash - The hash of the query to look up.
133
+ * @returns The query stored under the hash, or `undefined`.
125
134
  * @example
126
135
  * ```ts
127
136
  * const queryCache = queryClient.getQueryCache()
@@ -135,7 +144,7 @@ var QueryCache = class extends require_subscribable.Subscribable {
135
144
  }
136
145
  /**
137
146
  * Returns all queries within the cache.
138
- *
147
+ * @returns Every query in the cache.
139
148
  * @example
140
149
  * ```ts
141
150
  * const queryCache = queryClient.getQueryCache()
@@ -155,7 +164,9 @@ var QueryCache = class extends require_subscribable.Subscribable {
155
164
  * This is not typically needed for most applications, but can come in handy when needing more
156
165
  * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
157
166
  * decide whether a query is fresh enough to be used as an initial value).
158
- *
167
+ * @param filters - The filters to match, including the required `queryKey`. `exact` defaults to
168
+ * `true`.
169
+ * @returns The first matching query, or `undefined`.
159
170
  * @see {@link QueryCache#findAll}
160
171
  * @example
161
172
  * ```ts
@@ -177,7 +188,8 @@ var QueryCache = class extends require_subscribable.Subscribable {
177
188
  *
178
189
  * This is not typically needed for most applications, but can come in handy when needing more
179
190
  * information about queries in rare scenarios.
180
- *
191
+ * @param filters - The filters to match. Without filters, every query is returned.
192
+ * @returns The matching queries.
181
193
  * @see {@link QueryCache#find}
182
194
  * @example
183
195
  * ```ts
@@ -190,7 +202,11 @@ var QueryCache = class extends require_subscribable.Subscribable {
190
202
  const queries = this.getAll();
191
203
  return Object.keys(filters).length > 0 ? queries.filter((query) => require_utils.matchQuery(filters, query)) : queries;
192
204
  }
193
- /** @internal */
205
+ /**
206
+ * Notifies every cache listener of an event, in one batch.
207
+ * @internal
208
+ * @param event - The event passed to every listener.
209
+ */
194
210
  notify(event) {
195
211
  require_notifyManager.notifyManager.batch(() => {
196
212
  this.listeners.forEach((listener) => {
@@ -198,7 +214,10 @@ var QueryCache = class extends require_subscribable.Subscribable {
198
214
  });
199
215
  });
200
216
  }
201
- /** @internal */
217
+ /**
218
+ * Calls {@link Query#onFocus} on every cached query, in one batch.
219
+ * @internal
220
+ */
202
221
  onFocus() {
203
222
  require_notifyManager.notifyManager.batch(() => {
204
223
  this.getAll().forEach((query) => {
@@ -206,7 +225,10 @@ var QueryCache = class extends require_subscribable.Subscribable {
206
225
  });
207
226
  });
208
227
  }
209
- /** @internal */
228
+ /**
229
+ * Calls {@link Query#onOnline} on every cached query, in one batch.
230
+ * @internal
231
+ */
210
232
  onOnline() {
211
233
  require_notifyManager.notifyManager.batch(() => {
212
234
  this.getAll().forEach((query) => {