@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
@@ -1 +1 @@
1
- {"version":3,"file":"queryCache.cjs","names":["Subscribable","hashQueryKeyByOptions","Query","matchQuery"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n Query<TQueryFnData, TError, TData, TQueryKey> | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,aAAb,cAAgCA,qBAAAA,aAAiC;CAG/D,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;;EAEjB,8BAAA,uBAAA,UAAA,sBAAgB,IAAI,IAAmB,CAAA;CACzC;;;;;;;;;;;;;;;;;CAkBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAaC,cAAAA,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAIC,cAAAA,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;CAGA,IAAI,OAAwC;EAC1C,IAAI,CAAA,8BAAA,uBAAA,UAAC,IAAA,CAAA,CAAc,IAAI,MAAM,SAAS,GAAG;GACvC,8BAAA,uBAAA,UAAA,IAAA,CAAA,CAAc,IAAI,MAAM,WAAW,KAAK;GAExC,KAAK,OAAO;IACV,MAAM;IACN;GACF,CAAC;EACH;CACF;;;;;;;;;;;;;;;;;CAkBA,OAAO,OAAwC;EAG7C,IAAA,8BAAA,uBAAA,UAFmB,IAAA,CAAA,CAAc,IAAI,MAAM,SAE9B,MAAM,OAAO;GACxB,MAAM,QAAQ;GACd,8BAAA,uBAAA,UAAA,IAAA,CAAA,CAAc,OAAO,MAAM,SAAS;GACpC,KAAK,OAAO;IAAE,MAAM;IAAW;GAAM,CAAC;EACxC;CACF;;;;;;;;;;;CAYA,QAAc;EACZ,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,KAAK,OAAO,KAAK;GACnB,CAAC;EACH,CAAC;CACH;;;;;;;;;;;;;;;CAgBA,IAME,WAC2D;EAC3D,OAAA,8BAAA,uBAAA,UAAO,IAAA,CAAA,CAAc,IAAI,SAAS;CAEpC;;;;;;;;;;;CAYA,SAAuB;EACrB,OAAO,CAAC,GAAA,8BAAA,uBAAA,UAAG,IAAA,CAAA,CAAc,OAAO,CAAC;CACnC;;;;;;;;;;;;;;;;;;;CAoBA,KACE,SACgD;EAChD,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzBC,cAAAA,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAUA,cAAAA,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;CAGA,OAAO,OAAoC;EACzC,sBAAA,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,UAAgB;EACd,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,WAAiB;EACf,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"queryCache.cjs","names":["Subscribable","hashQueryKeyByOptions","Query","matchQuery"],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\n/**\n * The store a `QueryCache` keeps its queries in, keyed by query hash.\n */\nexport interface QueryStore {\n /**\n * Returns whether a query with the given hash is stored.\n */\n has: (queryHash: string) => boolean\n /**\n * Stores a query under its hash.\n */\n set: (queryHash: string, query: Query) => void\n /**\n * Returns the query with the given hash, if any.\n */\n get: (queryHash: string) => Query | undefined\n /**\n * Removes the query with the given hash.\n */\n delete: (queryHash: string) => void\n /**\n * Returns an iterator over all stored queries.\n */\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n * @param client - The client the query belongs to, used to default its options.\n * @param options - The query options, including the `queryKey`. A new query is created with the\n * options defaulted by {@link QueryClient#defaultQueryOptions}.\n * @param state - The initial state of a newly created query, e.g. when hydrating. Ignored if the\n * query already exists.\n * @returns The existing or newly created query.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /**\n * Adds a query to the cache.\n * @internal\n * @param query - The query to add. If a query with the same hash is already cached, nothing\n * happens.\n */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n * @param query - The query to remove.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n * @param queryHash - The hash of the query to look up.\n * @returns The query stored under the hash, or `undefined`.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n /**\n * Returns all queries within the cache.\n * @returns Every query in the cache.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n * @param filters - The filters to match, including the required `queryKey`. `exact` defaults to\n * `true`.\n * @returns The first matching query, or `undefined`.\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n * @param filters - The filters to match. Without filters, every query is returned.\n * @returns The matching queries.\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /**\n * Notifies every cache listener of an event, in one batch.\n * @internal\n * @param event - The event passed to every listener.\n */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /**\n * Calls {@link Query#onFocus} on every cached query, in one batch.\n * @internal\n */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /**\n * Calls {@link Query#onOnline} on every cached query, in one batch.\n * @internal\n */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2IA,IAAa,aAAb,cAAgCA,qBAAAA,aAAiC;CAG/D,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;;EAEjB,8BAAA,uBAAA,UAAA,sBAAgB,IAAI,IAAmB,CAAA;CACzC;;;;;;;;;;;;;;;;;;;;;;CAuBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAaC,cAAAA,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAIC,cAAAA,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;;;;;;CAQA,IAAI,OAAwC;EAC1C,IAAI,CAAA,8BAAA,uBAAA,UAAC,IAAA,CAAA,CAAc,IAAI,MAAM,SAAS,GAAG;GACvC,8BAAA,uBAAA,UAAA,IAAA,CAAA,CAAc,IAAI,MAAM,WAAW,KAAK;GAExC,KAAK,OAAO;IACV,MAAM;IACN;GACF,CAAC;EACH;CACF;;;;;;;;;;;;;;;;;CAkBA,OAAO,OAAwC;EAG7C,IAAA,8BAAA,uBAAA,UAFmB,IAAA,CAAA,CAAc,IAAI,MAAM,SAE9B,MAAM,OAAO;GACxB,MAAM,QAAQ;GACd,8BAAA,uBAAA,UAAA,IAAA,CAAA,CAAc,OAAO,MAAM,SAAS;GACpC,KAAK,OAAO;IAAE,MAAM;IAAW;GAAM,CAAC;EACxC;CACF;;;;;;;;;;CAWA,QAAc;EACZ,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,KAAK,OAAO,KAAK;GACnB,CAAC;EACH,CAAC;CACH;;;;;;;;;;;;;;;;CAiBA,IAME,WAC2D;EAC3D,OAAA,8BAAA,uBAAA,UAAO,IAAA,CAAA,CAAc,IAAI,SAAS;CAGpC;;;;;;;;;;;CAYA,SAAuB;EACrB,OAAO,CAAC,GAAA,8BAAA,uBAAA,UAAG,IAAA,CAAA,CAAc,OAAO,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;CAsBA,KACE,SACgD;EAChD,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzBC,cAAAA,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;;CAkBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAUA,cAAAA,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;;;;;CAOA,OAAO,OAAoC;EACzC,sBAAA,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;;;;CAMA,UAAgB;EACd,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;;;;CAMA,WAAiB;EACf,sBAAA,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
@@ -1,2 +1,2 @@
1
- import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-Br9VIGXa.cjs";
1
+ import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-C6zghADG.cjs";
2
2
  export { QueryCache, QueryCacheConfig, QueryCacheNotifyEvent, QueryStore };
@@ -1,2 +1,2 @@
1
- import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-B9t5w6NC.js";
1
+ import { cn as QueryCacheConfig, ln as QueryCacheNotifyEvent, sn as QueryCache, un as QueryStore } from "./hydration-Bf0oMcwO.js";
2
2
  export { QueryCache, QueryCacheConfig, QueryCacheNotifyEvent, QueryStore };
@@ -14,7 +14,6 @@ var _queries = /* @__PURE__ */ new WeakMap();
14
14
  * safe/known updates to the cache, such as queries being added, removed, or updated — updates made
15
15
  * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do
16
16
  * not notify subscribers.
17
- *
18
17
  * @example
19
18
  * ```ts
20
19
  * const unsubscribe = queryCache.subscribe((event) => {
@@ -34,7 +33,12 @@ var QueryCache = class extends Subscribable {
34
33
  * builds and adds a new one to the cache if none exists yet. Used by framework adapters and
35
34
  * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
36
35
  * the reactive `QueryObserver` machinery.
37
- *
36
+ * @param client - The client the query belongs to, used to default its options.
37
+ * @param options - The query options, including the `queryKey`. A new query is created with the
38
+ * options defaulted by {@link QueryClient#defaultQueryOptions}.
39
+ * @param state - The initial state of a newly created query, e.g. when hydrating. Ignored if the
40
+ * query already exists.
41
+ * @returns The existing or newly created query.
38
42
  * @example
39
43
  * ```ts
40
44
  * const queryCache = queryClient.getQueryCache()
@@ -62,7 +66,12 @@ var QueryCache = class extends Subscribable {
62
66
  }
63
67
  return query;
64
68
  }
65
- /** @internal */
69
+ /**
70
+ * Adds a query to the cache.
71
+ * @internal
72
+ * @param query - The query to add. If a query with the same hash is already cached, nothing
73
+ * happens.
74
+ */
66
75
  add(query) {
67
76
  if (!_classPrivateFieldGet2(_queries, this).has(query.queryHash)) {
68
77
  _classPrivateFieldGet2(_queries, this).set(query.queryHash, query);
@@ -77,7 +86,7 @@ var QueryCache = class extends Subscribable {
77
86
  * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
78
87
  * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
79
88
  * removals across `QueryCache` instances.
80
- *
89
+ * @param query - The query to remove.
81
90
  * @example
82
91
  * ```ts
83
92
  * const queryCache = queryClient.getQueryCache()
@@ -100,7 +109,6 @@ var QueryCache = class extends Subscribable {
100
109
  }
101
110
  /**
102
111
  * Removes all queries from the cache.
103
- *
104
112
  * @example
105
113
  * ```ts
106
114
  * const queryCache = queryClient.getQueryCache()
@@ -120,7 +128,8 @@ var QueryCache = class extends Subscribable {
120
128
  * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
121
129
  * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
122
130
  * to look up directly.
123
- *
131
+ * @param queryHash - The hash of the query to look up.
132
+ * @returns The query stored under the hash, or `undefined`.
124
133
  * @example
125
134
  * ```ts
126
135
  * const queryCache = queryClient.getQueryCache()
@@ -134,7 +143,7 @@ var QueryCache = class extends Subscribable {
134
143
  }
135
144
  /**
136
145
  * Returns all queries within the cache.
137
- *
146
+ * @returns Every query in the cache.
138
147
  * @example
139
148
  * ```ts
140
149
  * const queryCache = queryClient.getQueryCache()
@@ -154,7 +163,9 @@ var QueryCache = class extends Subscribable {
154
163
  * This is not typically needed for most applications, but can come in handy when needing more
155
164
  * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
156
165
  * decide whether a query is fresh enough to be used as an initial value).
157
- *
166
+ * @param filters - The filters to match, including the required `queryKey`. `exact` defaults to
167
+ * `true`.
168
+ * @returns The first matching query, or `undefined`.
158
169
  * @see {@link QueryCache#findAll}
159
170
  * @example
160
171
  * ```ts
@@ -176,7 +187,8 @@ var QueryCache = class extends Subscribable {
176
187
  *
177
188
  * This is not typically needed for most applications, but can come in handy when needing more
178
189
  * information about queries in rare scenarios.
179
- *
190
+ * @param filters - The filters to match. Without filters, every query is returned.
191
+ * @returns The matching queries.
180
192
  * @see {@link QueryCache#find}
181
193
  * @example
182
194
  * ```ts
@@ -189,7 +201,11 @@ var QueryCache = class extends Subscribable {
189
201
  const queries = this.getAll();
190
202
  return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
191
203
  }
192
- /** @internal */
204
+ /**
205
+ * Notifies every cache listener of an event, in one batch.
206
+ * @internal
207
+ * @param event - The event passed to every listener.
208
+ */
193
209
  notify(event) {
194
210
  notifyManager.batch(() => {
195
211
  this.listeners.forEach((listener) => {
@@ -197,7 +213,10 @@ var QueryCache = class extends Subscribable {
197
213
  });
198
214
  });
199
215
  }
200
- /** @internal */
216
+ /**
217
+ * Calls {@link Query#onFocus} on every cached query, in one batch.
218
+ * @internal
219
+ */
201
220
  onFocus() {
202
221
  notifyManager.batch(() => {
203
222
  this.getAll().forEach((query) => {
@@ -205,7 +224,10 @@ var QueryCache = class extends Subscribable {
205
224
  });
206
225
  });
207
226
  }
208
- /** @internal */
227
+ /**
228
+ * Calls {@link Query#onOnline} on every cached query, in one batch.
229
+ * @internal
230
+ */
209
231
  onOnline() {
210
232
  notifyManager.batch(() => {
211
233
  this.getAll().forEach((query) => {
@@ -1 +1 @@
1
- {"version":3,"file":"queryCache.js","names":[],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\nexport interface QueryStore {\n has: (queryHash: string) => boolean\n set: (queryHash: string, query: Query) => void\n get: (queryHash: string) => Query | undefined\n delete: (queryHash: string) => void\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n *\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /** @internal */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n Query<TQueryFnData, TError, TData, TQueryKey> | undefined\n }\n\n /**\n * Returns all queries within the cache.\n *\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n *\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n *\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /** @internal */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /** @internal */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /** @internal */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0HA,IAAa,aAAb,cAAgC,aAAiC;CAG/D,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;;EAEjB,uBAAA,UAAA,sBAAgB,IAAI,IAAmB,CAAA;CACzC;;;;;;;;;;;;;;;;;CAkBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAa,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAI,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;CAGA,IAAI,OAAwC;EAC1C,IAAI,CAAA,uBAAA,UAAC,IAAA,CAAA,CAAc,IAAI,MAAM,SAAS,GAAG;GACvC,uBAAA,UAAA,IAAA,CAAA,CAAc,IAAI,MAAM,WAAW,KAAK;GAExC,KAAK,OAAO;IACV,MAAM;IACN;GACF,CAAC;EACH;CACF;;;;;;;;;;;;;;;;;CAkBA,OAAO,OAAwC;EAG7C,IAAA,uBAAA,UAFmB,IAAA,CAAA,CAAc,IAAI,MAAM,SAE9B,MAAM,OAAO;GACxB,MAAM,QAAQ;GACd,uBAAA,UAAA,IAAA,CAAA,CAAc,OAAO,MAAM,SAAS;GACpC,KAAK,OAAO;IAAE,MAAM;IAAW;GAAM,CAAC;EACxC;CACF;;;;;;;;;;;CAYA,QAAc;EACZ,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,KAAK,OAAO,KAAK;GACnB,CAAC;EACH,CAAC;CACH;;;;;;;;;;;;;;;CAgBA,IAME,WAC2D;EAC3D,OAAA,uBAAA,UAAO,IAAA,CAAA,CAAc,IAAI,SAAS;CAEpC;;;;;;;;;;;CAYA,SAAuB;EACrB,OAAO,CAAC,GAAA,uBAAA,UAAG,IAAA,CAAA,CAAc,OAAO,CAAC;CACnC;;;;;;;;;;;;;;;;;;;CAoBA,KACE,SACgD;EAChD,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzB,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;CAiBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAU,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;CAGA,OAAO,OAAoC;EACzC,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,UAAgB;EACd,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;CAGA,WAAiB;EACf,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"queryCache.js","names":[],"sources":["../../src/queryCache.ts"],"sourcesContent":["import { hashQueryKeyByOptions, matchQuery } from './utils'\nimport { Query } from './query'\nimport { notifyManager } from './notifyManager'\nimport { Subscribable } from './subscribable'\nimport type { QueryFilters } from './utils'\nimport type { Action, QueryState } from './query'\nimport type {\n DefaultError,\n NotifyEvent,\n QueryKey,\n QueryOptions,\n WithRequired,\n} from './types'\nimport type { QueryClient } from './queryClient'\nimport type { QueryObserver } from './queryObserver'\n\n// TYPES\n\n/**\n * Global callbacks that fire for every query handled by a `QueryCache`, regardless of which\n * component or observer triggered it. Unlike `QueryClient`'s `defaultOptions`, which a query can\n * override, these callbacks are always called. Unlike `MutationCacheConfig`'s callbacks, these\n * are fire-and-forget: their return value is not awaited before the query settles.\n */\nexport interface QueryCacheConfig {\n /** Called when any query in the cache encounters an error. */\n onError?: (\n error: DefaultError,\n query: Query<unknown, unknown, unknown>,\n ) => void\n /** Called when any query in the cache is successful. */\n onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void\n /** Called when any query in the cache is settled, either successfully or with an error. */\n onSettled?: (\n data: unknown | undefined,\n error: DefaultError | null,\n query: Query<unknown, unknown, unknown>,\n ) => void\n}\n\ninterface NotifyEventQueryAdded extends NotifyEvent {\n type: 'added'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryRemoved extends NotifyEvent {\n type: 'removed'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryUpdated extends NotifyEvent {\n type: 'updated'\n query: Query<any, any, any, any>\n action: Action<any, any>\n}\n\ninterface NotifyEventQueryObserverAdded extends NotifyEvent {\n type: 'observerAdded'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverRemoved extends NotifyEvent {\n type: 'observerRemoved'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverResultsUpdated extends NotifyEvent {\n type: 'observerResultsUpdated'\n query: Query<any, any, any, any>\n}\n\ninterface NotifyEventQueryObserverOptionsUpdated extends NotifyEvent {\n type: 'observerOptionsUpdated'\n query: Query<any, any, any, any>\n observer: QueryObserver<any, any, any, any, any>\n}\n\n/**\n * The event passed to a `QueryCache` subscriber. Fired whenever a query is added or removed from\n * the cache, its state is updated (e.g. via `query.setState` or `queryClient.removeQueries`), or\n * one of its observers is added, removed, or has its results or options updated.\n */\nexport type QueryCacheNotifyEvent =\n | NotifyEventQueryAdded\n | NotifyEventQueryRemoved\n | NotifyEventQueryUpdated\n | NotifyEventQueryObserverAdded\n | NotifyEventQueryObserverRemoved\n | NotifyEventQueryObserverResultsUpdated\n | NotifyEventQueryObserverOptionsUpdated\n\ntype QueryCacheListener = (event: QueryCacheNotifyEvent) => void\n\n/**\n * The store a `QueryCache` keeps its queries in, keyed by query hash.\n */\nexport interface QueryStore {\n /**\n * Returns whether a query with the given hash is stored.\n */\n has: (queryHash: string) => boolean\n /**\n * Stores a query under its hash.\n */\n set: (queryHash: string, query: Query) => void\n /**\n * Returns the query with the given hash, if any.\n */\n get: (queryHash: string) => Query | undefined\n /**\n * Removes the query with the given hash.\n */\n delete: (queryHash: string) => void\n /**\n * Returns an iterator over all stored queries.\n */\n values: () => IterableIterator<Query>\n}\n\n// CLASS\n\n/**\n * The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta\n * information, and state of the queries it contains.\n *\n * Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`\n * for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of\n * safe/known updates to the cache, such as queries being added, removed, or updated — updates made\n * outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do\n * not notify subscribers.\n * @example\n * ```ts\n * const unsubscribe = queryCache.subscribe((event) => {\n * console.log(event.type, event.query)\n * })\n * ```\n */\nexport class QueryCache extends Subscribable<QueryCacheListener> {\n #queries: QueryStore\n\n constructor(public config: QueryCacheConfig = {}) {\n super()\n this.#queries = new Map<string, Query>()\n }\n\n /**\n * Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or\n * builds and adds a new one to the cache if none exists yet. Used by framework adapters and\n * plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing\n * the reactive `QueryObserver` machinery.\n * @param client - The client the query belongs to, used to default its options.\n * @param options - The query options, including the `queryKey`. A new query is created with the\n * options defaulted by {@link QueryClient#defaultQueryOptions}.\n * @param state - The initial state of a newly created query, e.g. when hydrating. Ignored if the\n * query already exists.\n * @returns The existing or newly created query.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.build(queryClient, {\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * })\n * ```\n */\n build<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n client: QueryClient,\n options: WithRequired<\n QueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n state?: QueryState<TData, TError>,\n ): Query<TQueryFnData, TError, TData, TQueryKey> {\n const queryKey = options.queryKey\n const queryHash =\n options.queryHash ?? hashQueryKeyByOptions(queryKey, options)\n let query = this.get<TQueryFnData, TError, TData, TQueryKey>(queryHash)\n\n if (!query) {\n query = new Query({\n client,\n queryKey,\n queryHash,\n options: client.defaultQueryOptions(options),\n state,\n defaultOptions: client.getQueryDefaults(queryKey),\n })\n this.add(query)\n }\n\n return query\n }\n\n /**\n * Adds a query to the cache.\n * @internal\n * @param query - The query to add. If a query with the same hash is already cached, nothing\n * happens.\n */\n add(query: Query<any, any, any, any>): void {\n if (!this.#queries.has(query.queryHash)) {\n this.#queries.set(query.queryHash, query)\n\n this.notify({\n type: 'added',\n query,\n })\n }\n }\n\n /**\n * Destroys the given `Query` and removes it from the cache, notifying subscribers with a\n * `'removed'` event. A no-op if the query is no longer the one currently stored under its hash\n * (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror\n * removals across `QueryCache` instances.\n * @param query - The query to remove.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const query = queryCache.find({ queryKey: ['posts'] })\n *\n * if (query) {\n * queryCache.remove(query)\n * }\n * ```\n */\n remove(query: Query<any, any, any, any>): void {\n const queryInMap = this.#queries.get(query.queryHash)\n\n if (queryInMap === query) {\n query.destroy()\n this.#queries.delete(query.queryHash)\n this.notify({ type: 'removed', query })\n }\n }\n\n /**\n * Removes all queries from the cache.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * queryCache.clear()\n * ```\n */\n clear(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n this.remove(query)\n })\n })\n }\n\n /**\n * Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none\n * exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather\n * than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash\n * to look up directly.\n * @param queryHash - The hash of the query to look up.\n * @returns The query stored under the hash, or `undefined`.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n * const queryHash = hashKey(['posts'])\n *\n * const query = queryCache.get(queryHash)\n * ```\n */\n get<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n >(\n queryHash: string,\n ): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {\n return this.#queries.get(queryHash) as\n | Query<TQueryFnData, TError, TData, TQueryKey>\n | undefined\n }\n\n /**\n * Returns all queries within the cache.\n * @returns Every query in the cache.\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.getAll()\n * ```\n */\n getAll(): Array<Query> {\n return [...this.#queries.values()]\n }\n\n /**\n * A slightly more advanced method that can be used to get an existing query instance from the\n * cache. This instance not only contains all the state for the query, but all of the instances,\n * and underlying guts of the query as well. If the query does not exist, `undefined` is\n * returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to\n * decide whether a query is fresh enough to be used as an initial value).\n * @param filters - The filters to match, including the required `queryKey`. `exact` defaults to\n * `true`.\n * @returns The first matching query, or `undefined`.\n * @see {@link QueryCache#findAll}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const query = queryCache.find({ queryKey: ['posts'] })\n * ```\n */\n find<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData>(\n filters: WithRequired<QueryFilters, 'queryKey'>,\n ): Query<TQueryFnData, TError, TData> | undefined {\n const defaultedFilters = { exact: true, ...filters }\n\n return this.getAll().find((query) =>\n matchQuery(defaultedFilters, query),\n ) as Query<TQueryFnData, TError, TData> | undefined\n }\n\n /**\n * An even more advanced method that can be used to get existing query instances from the cache\n * that partially match a query key. If no queries match, an empty array is returned.\n *\n * This is not typically needed for most applications, but can come in handy when needing more\n * information about queries in rare scenarios.\n * @param filters - The filters to match. Without filters, every query is returned.\n * @returns The matching queries.\n * @see {@link QueryCache#find}\n * @example\n * ```ts\n * const queryCache = queryClient.getQueryCache()\n *\n * const queries = queryCache.findAll({ queryKey: ['posts'] })\n * ```\n */\n findAll(filters: QueryFilters<any> = {}): Array<Query> {\n const queries = this.getAll()\n return Object.keys(filters).length > 0\n ? queries.filter((query) => matchQuery(filters, query))\n : queries\n }\n\n /**\n * Notifies every cache listener of an event, in one batch.\n * @internal\n * @param event - The event passed to every listener.\n */\n notify(event: QueryCacheNotifyEvent): void {\n notifyManager.batch(() => {\n this.listeners.forEach((listener) => {\n listener(event)\n })\n })\n }\n\n /**\n * Calls {@link Query#onFocus} on every cached query, in one batch.\n * @internal\n */\n onFocus(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onFocus()\n })\n })\n }\n\n /**\n * Calls {@link Query#onOnline} on every cached query, in one batch.\n * @internal\n */\n onOnline(): void {\n notifyManager.batch(() => {\n this.getAll().forEach((query) => {\n query.onOnline()\n })\n })\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2IA,IAAa,aAAb,cAAgC,aAAiC;CAG/D,YAAY,SAAkC,CAAC,GAAG;EAChD,MAAM;EADW,KAAA,SAAA;;EAEjB,uBAAA,UAAA,sBAAgB,IAAI,IAAmB,CAAA;CACzC;;;;;;;;;;;;;;;;;;;;;;CAuBA,MAME,QACA,SAIA,OAC+C;EAC/C,MAAM,WAAW,QAAQ;EACzB,MAAM,YACJ,QAAQ,aAAa,sBAAsB,UAAU,OAAO;EAC9D,IAAI,QAAQ,KAAK,IAA4C,SAAS;EAEtE,IAAI,CAAC,OAAO;GACV,QAAQ,IAAI,MAAM;IAChB;IACA;IACA;IACA,SAAS,OAAO,oBAAoB,OAAO;IAC3C;IACA,gBAAgB,OAAO,iBAAiB,QAAQ;GAClD,CAAC;GACD,KAAK,IAAI,KAAK;EAChB;EAEA,OAAO;CACT;;;;;;;CAQA,IAAI,OAAwC;EAC1C,IAAI,CAAA,uBAAA,UAAC,IAAA,CAAA,CAAc,IAAI,MAAM,SAAS,GAAG;GACvC,uBAAA,UAAA,IAAA,CAAA,CAAc,IAAI,MAAM,WAAW,KAAK;GAExC,KAAK,OAAO;IACV,MAAM;IACN;GACF,CAAC;EACH;CACF;;;;;;;;;;;;;;;;;CAkBA,OAAO,OAAwC;EAG7C,IAAA,uBAAA,UAFmB,IAAA,CAAA,CAAc,IAAI,MAAM,SAE9B,MAAM,OAAO;GACxB,MAAM,QAAQ;GACd,uBAAA,UAAA,IAAA,CAAA,CAAc,OAAO,MAAM,SAAS;GACpC,KAAK,OAAO;IAAE,MAAM;IAAW;GAAM,CAAC;EACxC;CACF;;;;;;;;;;CAWA,QAAc;EACZ,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,KAAK,OAAO,KAAK;GACnB,CAAC;EACH,CAAC;CACH;;;;;;;;;;;;;;;;CAiBA,IAME,WAC2D;EAC3D,OAAA,uBAAA,UAAO,IAAA,CAAA,CAAc,IAAI,SAAS;CAGpC;;;;;;;;;;;CAYA,SAAuB;EACrB,OAAO,CAAC,GAAA,uBAAA,UAAG,IAAA,CAAA,CAAc,OAAO,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;CAsBA,KACE,SACgD;EAChD,MAAM,mBAAmB;GAAE,OAAO;GAAM,GAAG;EAAQ;EAEnD,OAAO,KAAK,OAAO,CAAC,CAAC,MAAM,UACzB,WAAW,kBAAkB,KAAK,CACpC;CACF;;;;;;;;;;;;;;;;;CAkBA,QAAQ,UAA6B,CAAC,GAAiB;EACrD,MAAM,UAAU,KAAK,OAAO;EAC5B,OAAO,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,IACjC,QAAQ,QAAQ,UAAU,WAAW,SAAS,KAAK,CAAC,IACpD;CACN;;;;;;CAOA,OAAO,OAAoC;EACzC,cAAc,YAAY;GACxB,KAAK,UAAU,SAAS,aAAa;IACnC,SAAS,KAAK;GAChB,CAAC;EACH,CAAC;CACH;;;;;CAMA,UAAgB;EACd,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;CACH;;;;;CAMA,WAAiB;EACf,cAAc,YAAY;GACxB,KAAK,OAAO,CAAC,CAAC,SAAS,UAAU;IAC/B,MAAM,SAAS;GACjB,CAAC;EACH,CAAC;CACH;AACF"}
@@ -19,7 +19,6 @@ var _unsubscribeOnline = /* @__PURE__ */ new WeakMap();
19
19
  * `QueryClient` is used to interact with a cache of queries and mutations. It owns a
20
20
  * `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds
21
21
  * the default options that are applied to queries and mutations created through it.
22
- *
23
22
  * @example
24
23
  * ```ts
25
24
  * const queryClient = new QueryClient({
@@ -91,7 +90,9 @@ var QueryClient = class {
91
90
  * Returns the number of queries in the cache that are currently fetching, optionally
92
91
  * matching a set of filters. This includes background-fetching, loading new pages, and
93
92
  * loading more infinite query results.
94
- *
93
+ * @param filters - Narrows down which fetching queries are counted. Without filters, every
94
+ * fetching query is counted.
95
+ * @returns The number of matching queries whose `fetchStatus` is `'fetching'`.
95
96
  * @example
96
97
  * ```ts
97
98
  * if (queryClient.isFetching()) {
@@ -108,7 +109,9 @@ var QueryClient = class {
108
109
  /**
109
110
  * Returns the number of mutations in the cache that are currently pending, optionally
110
111
  * matching a set of filters.
111
- *
112
+ * @param filters - Narrows down which pending mutations are counted. Without filters, every
113
+ * pending mutation is counted.
114
+ * @returns The number of matching mutations whose `status` is `'pending'`.
112
115
  * @example
113
116
  * ```ts
114
117
  * if (queryClient.isMutating()) {
@@ -128,7 +131,7 @@ var QueryClient = class {
128
131
  *
129
132
  * Hint: Do not use this function inside a component, because it won't receive updates.
130
133
  * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
131
- *
134
+ * @param queryKey - The query key of the query to read.
132
135
  * @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.
133
136
  * @see {@link QueryClient#getQueriesData}
134
137
  */
@@ -138,6 +141,12 @@ var QueryClient = class {
138
141
  return (_classPrivateFieldGet4 = require_classPrivateFieldSet2._classPrivateFieldGet2(_queryCache, this).get(options.queryHash)) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.state.data;
139
142
  }
140
143
  /**
144
+ * Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,
145
+ * stale cached data is also refetched in the background.
146
+ * @param options - The query options. If the query has no cached data yet, it is fetched with
147
+ * these options.
148
+ * @returns A promise that resolves to the cached data, or to the fetched data if nothing was
149
+ * cached yet.
141
150
  * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
142
151
  */
143
152
  ensureQueryData(options) {
@@ -158,7 +167,7 @@ var QueryClient = class {
158
167
  * than being inferred. Passing a more specific type is a convenience for call sites that know
159
168
  * every matched query holds the same shape — it is not checked against the actual cache
160
169
  * contents.
161
- *
170
+ * @param filters - The filters that select which queries to read.
162
171
  * @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.
163
172
  * @see {@link QueryClient#getQueryData}
164
173
  * @example
@@ -179,14 +188,12 @@ var QueryClient = class {
179
188
  *
180
189
  * Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
181
190
  * via {@link QueryClient#getQueryData}, in place.
182
- *
183
191
  * @param queryKey - The query key to set data for.
184
192
  * @param updater - Either the new data, or a function that receives the current data (which
185
193
  * may be `undefined`) and returns the new data.
186
194
  * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
187
195
  * @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case
188
196
  * the write is skipped and the cache is left unchanged.
189
- *
190
197
  * @example
191
198
  * ```ts
192
199
  * queryClient.setQueryData(['posts'], newPosts)
@@ -211,7 +218,10 @@ var QueryClient = class {
211
218
  * filters or partial query key matching. Only queries that already exist and match the given
212
219
  * filters are updated; no new cache entries are created. Internally this calls
213
220
  * {@link QueryClient#setQueryData} for each matching query.
214
- *
221
+ * @param filters - The filters that select which existing queries to update.
222
+ * @param updater - Either the new data, or a function that receives each matched query's current
223
+ * data (which may be `undefined`) and returns the new data.
224
+ * @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
215
225
  * @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same
216
226
  * `undefined` case as {@link QueryClient#setQueryData}.
217
227
  * @example
@@ -227,7 +237,8 @@ var QueryClient = class {
227
237
  /**
228
238
  * Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
229
239
  * exist, `undefined` is returned.
230
- *
240
+ * @param queryKey - The query key of the query to read.
241
+ * @returns The query's state, or `undefined` if no query with this key exists.
231
242
  * @example
232
243
  * ```ts
233
244
  * const state = queryClient.getQueryState(['posts'])
@@ -244,7 +255,8 @@ var QueryClient = class {
244
255
  * {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
245
256
  * matching queries from the cache instead of refetching them. Without filters, every query in
246
257
  * the cache is removed.
247
- *
258
+ * @param filters - The filters that select which queries to remove. Without filters, every query
259
+ * is removed.
248
260
  * @example
249
261
  * ```ts
250
262
  * queryClient.removeQueries({ queryKey: ['posts'], exact: true })
@@ -262,7 +274,11 @@ var QueryClient = class {
262
274
  * Resets queries matching the given filters back to their initial state (e.g. any
263
275
  * `initialData`), notifying subscribers rather than removing them. Active queries among the
264
276
  * matched set are then refetched, and the returned promise resolves once that refetch settles.
265
- *
277
+ * @param filters - The filters that select which queries to reset. Without filters, every query
278
+ * is reset.
279
+ * @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and
280
+ * `throwOnError`.
281
+ * @returns A promise that resolves once the refetch of the active matched queries settles.
266
282
  * @example
267
283
  * ```ts
268
284
  * await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
@@ -289,7 +305,11 @@ var QueryClient = class {
289
305
  * reverted to its state before the outgoing fetch started.
290
306
  *
291
307
  * The returned promise never rejects, even if individual cancellations fail.
292
- *
308
+ * @param filters - The filters that select which queries to cancel. Without filters, every query
309
+ * is cancelled.
310
+ * @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to
311
+ * `true`.
312
+ * @returns A promise that resolves once every cancellation has settled.
293
313
  * @example
294
314
  * ```ts
295
315
  * await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
@@ -310,7 +330,12 @@ var QueryClient = class {
310
330
  * Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
311
331
  * {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
312
332
  * `filters.type`, otherwise `'active'`.
313
- *
333
+ * @param filters - The filters that select which queries to invalidate, plus `refetchType` to
334
+ * control which of them to refetch afterwards. Without filters, every query is invalidated.
335
+ * @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and
336
+ * `throwOnError`.
337
+ * @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is
338
+ * `'none'`.
314
339
  * @example
315
340
  * ```ts
316
341
  * await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
@@ -336,7 +361,11 @@ var QueryClient = class {
336
361
  * By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
337
362
  * one starts. The returned promise resolves once all matching queries have settled; it does
338
363
  * not reject on individual query failures unless `throwOnError` is set.
339
- *
364
+ * @param filters - The filters that select which queries to refetch. Without filters, every query
365
+ * in the cache is included.
366
+ * @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
367
+ * it, and `throwOnError` to `true` to reject when a refetch fails.
368
+ * @returns A promise that resolves once every matched query has settled.
340
369
  * @example
341
370
  * ```ts
342
371
  * // refetch all active queries partially matching a query key:
@@ -376,7 +405,10 @@ var QueryClient = class {
376
405
  *
377
406
  * This method replaces the deprecated `fetchQuery`, and — combined with
378
407
  * `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
379
- *
408
+ * @param options - The query options, including the `queryKey` and the `queryFn` used if the
409
+ * query needs to fetch.
410
+ * @returns A promise that resolves to the data, or to the result of `select` if provided. It
411
+ * rejects with the error from the fetch or from `select`.
380
412
  * @example
381
413
  * ```ts
382
414
  * try {
@@ -396,6 +428,12 @@ var QueryClient = class {
396
428
  return queryData;
397
429
  }
398
430
  /**
431
+ * Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,
432
+ * the fetch isn't retried unless `retry` is set.
433
+ * @param options - The query options, including the `queryKey` and the `queryFn` used if the
434
+ * query needs to fetch.
435
+ * @returns A promise that resolves to the cached or fetched data, or rejects with the fetch
436
+ * error.
399
437
  * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
400
438
  */
401
439
  fetchQuery(options) {
@@ -405,6 +443,11 @@ var QueryClient = class {
405
443
  return query.isStaleByTime(require_utils.resolveQueryValue(defaultedOptions.staleTime, query)) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
406
444
  }
407
445
  /**
446
+ * Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any
447
+ * error.
448
+ * @param options - The query options, including the `queryKey` and the `queryFn` used if the
449
+ * query needs to fetch.
450
+ * @returns A promise that resolves once the fetch settles. It never rejects.
408
451
  * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
409
452
  */
410
453
  prefetchQuery(options) {
@@ -420,7 +463,10 @@ var QueryClient = class {
420
463
  *
421
464
  * This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
422
465
  * `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
423
- *
466
+ * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
467
+ * `initialPageParam`.
468
+ * @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if
469
+ * provided. It rejects with the error from the fetch or from `select`.
424
470
  * @example
425
471
  * ```ts
426
472
  * try {
@@ -436,6 +482,11 @@ var QueryClient = class {
436
482
  return this.query(options);
437
483
  }
438
484
  /**
485
+ * Fetches and caches an infinite query, or returns its cached data if it isn't stale.
486
+ * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
487
+ * `initialPageParam`.
488
+ * @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with
489
+ * the fetch error.
439
490
  * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
440
491
  */
441
492
  fetchInfiniteQuery(options) {
@@ -443,12 +494,23 @@ var QueryClient = class {
443
494
  return this.fetchQuery(options);
444
495
  }
445
496
  /**
497
+ * Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores
498
+ * the result and any error.
499
+ * @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
500
+ * `initialPageParam`.
501
+ * @returns A promise that resolves once the fetch settles. It never rejects.
446
502
  * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
447
503
  */
448
504
  prefetchInfiniteQuery(options) {
449
505
  return this.fetchInfiniteQuery(options).then(require_utils.noop).catch(require_utils.noop);
450
506
  }
451
507
  /**
508
+ * Returns the cached data of an infinite query, or fetches it if there is none. With
509
+ * `revalidateIfStale`, stale cached data is also refetched in the background.
510
+ * @param options - The infinite query options. If the query has no cached data yet, it is fetched
511
+ * with these options.
512
+ * @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if
513
+ * nothing was cached yet.
452
514
  * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
453
515
  */
454
516
  ensureInfiniteQueryData(options) {
@@ -458,7 +520,7 @@ var QueryClient = class {
458
520
  /**
459
521
  * Resumes mutations that were paused because there was no network connection. Does nothing
460
522
  * (resolving immediately) if the client is currently offline.
461
- *
523
+ * @returns A promise that resolves once the resumed mutations have settled.
462
524
  * @example
463
525
  * ```ts
464
526
  * import { QueryClient } from '@tanstack/query-core'
@@ -473,7 +535,7 @@ var QueryClient = class {
473
535
  }
474
536
  /**
475
537
  * Returns the query cache this client is connected to.
476
- *
538
+ * @returns The {@link QueryCache} instance.
477
539
  * @example
478
540
  * ```ts
479
541
  * import { QueryClient } from '@tanstack/query-core'
@@ -488,7 +550,7 @@ var QueryClient = class {
488
550
  }
489
551
  /**
490
552
  * Returns the mutation cache this client is connected to.
491
- *
553
+ * @returns The {@link MutationCache} instance.
492
554
  * @example
493
555
  * ```ts
494
556
  * import { QueryClient } from '@tanstack/query-core'
@@ -504,7 +566,7 @@ var QueryClient = class {
504
566
  /**
505
567
  * Returns the default options that were set when creating the client, or via
506
568
  * {@link QueryClient#setDefaultOptions}.
507
- *
569
+ * @returns The client's current default options.
508
570
  * @example
509
571
  * ```ts
510
572
  * import { QueryClient } from '@tanstack/query-core'
@@ -519,7 +581,7 @@ var QueryClient = class {
519
581
  /**
520
582
  * Dynamically sets the default options for this client, overwriting any previously defined
521
583
  * default options.
522
- *
584
+ * @param options - The new default options for queries and mutations.
523
585
  * @see {@link QueryClient#getDefaultOptions}
524
586
  * @example
525
587
  * ```ts
@@ -543,7 +605,8 @@ var QueryClient = class {
543
605
  * registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
544
606
  * most generic key to the least generic one — more specific defaults should be registered
545
607
  * after more generic ones so they take precedence.
546
- *
608
+ * @param queryKey - The query key that query keys are partially matched against.
609
+ * @param options - The default options applied to matching queries.
547
610
  * @example
548
611
  * ```ts
549
612
  * queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
@@ -561,7 +624,9 @@ var QueryClient = class {
561
624
  * Returns the default options registered for queries whose query key partially matches the
562
625
  * given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
563
626
  * match, they are merged together in registration order.
564
- *
627
+ * @param queryKey - The query key to look up registered defaults for.
628
+ * @returns The merged default options of every registration that matches, or an empty object if
629
+ * none match.
565
630
  * @example
566
631
  * ```ts
567
632
  * const defaultOptions = queryClient.getQueryDefaults(['posts'])
@@ -579,7 +644,8 @@ var QueryClient = class {
579
644
  * Sets default options for mutations whose mutation key partially matches the given
580
645
  * `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
581
646
  * matters when several registered defaults match the same mutation key.
582
- *
647
+ * @param mutationKey - The mutation key that mutation keys are partially matched against.
648
+ * @param options - The default options applied to matching mutations.
583
649
  * @see {@link QueryClient#getMutationDefaults}
584
650
  * @example
585
651
  * ```ts
@@ -596,7 +662,9 @@ var QueryClient = class {
596
662
  * Returns the default options registered for mutations whose mutation key partially matches
597
663
  * the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
598
664
  * defaults match, they are merged together in registration order.
599
- *
665
+ * @param mutationKey - The mutation key to look up registered defaults for.
666
+ * @returns The merged default options of every registration that matches, or an empty object if
667
+ * none match.
600
668
  * @example
601
669
  * ```ts
602
670
  * const defaultOptions = queryClient.getMutationDefaults(['addPost'])
@@ -612,9 +680,12 @@ var QueryClient = class {
612
680
  }
613
681
  /**
614
682
  * Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
615
- * caller into their final, defaulted form: merging `queryClient.setQueryDefaults` for the
616
- * given `queryKey`, then the client's own `defaultOptions.queries`, then the caller's options
617
- * on top. A no-op if the options are already defaulted (`_defaulted: true`).
683
+ * caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,
684
+ * then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on
685
+ * top. A no-op if the options are already defaulted (`_defaulted: true`).
686
+ * @param options - The query options passed by the caller.
687
+ * @returns The defaulted options, with `queryHash` and dependent defaults (e.g.
688
+ * `refetchOnReconnect`) filled in.
618
689
  */
619
690
  defaultQueryOptions(options) {
620
691
  if (options._defaulted) return options;
@@ -633,9 +704,11 @@ var QueryClient = class {
633
704
  }
634
705
  /**
635
706
  * The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
636
- * adapters (e.g. inside `useMutation`) to merge `queryClient.setMutationDefaults` for the
637
- * given `mutationKey`, then the client's `defaultOptions.mutations`, then the caller's options
638
- * on top. A no-op if the options are already defaulted (`_defaulted: true`).
707
+ * adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then
708
+ * `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on
709
+ * top. A no-op if the options are already defaulted (`_defaulted: true`).
710
+ * @param options - The mutation options passed by the caller.
711
+ * @returns The defaulted options.
639
712
  */
640
713
  defaultMutationOptions(options) {
641
714
  if (options === null || options === void 0 ? void 0 : options._defaulted) return options;
@@ -648,7 +721,6 @@ var QueryClient = class {
648
721
  }
649
722
  /**
650
723
  * Clears both the query cache and the mutation cache this client is connected to.
651
- *
652
724
  * @example
653
725
  * ```ts
654
726
  * import { QueryClient } from '@tanstack/query-core'