@tanstack/query-core 5.101.4 → 5.102.1

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 (370) hide show
  1. package/build/legacy/classPrivateFieldSet2-Bo0ZyOIv.cjs +56 -0
  2. package/build/legacy/classPrivateFieldSet2-CV7wyte-.js +27 -0
  3. package/build/legacy/classPrivateMethodInitSpec-CBwa_Y7C.js +7 -0
  4. package/build/legacy/classPrivateMethodInitSpec-DVhcLejn.cjs +12 -0
  5. package/build/legacy/environmentManager.cjs +25 -46
  6. package/build/legacy/environmentManager.cjs.map +1 -1
  7. package/build/legacy/environmentManager.d.cts +18 -2
  8. package/build/legacy/environmentManager.d.cts.map +1 -0
  9. package/build/legacy/environmentManager.d.ts +18 -2
  10. package/build/legacy/environmentManager.d.ts.map +1 -0
  11. package/build/legacy/environmentManager.js +23 -22
  12. package/build/legacy/environmentManager.js.map +1 -1
  13. package/build/legacy/focusManager.cjs +63 -104
  14. package/build/legacy/focusManager.cjs.map +1 -1
  15. package/build/legacy/focusManager.d.cts +18 -2
  16. package/build/legacy/focusManager.d.cts.map +1 -0
  17. package/build/legacy/focusManager.d.ts +18 -2
  18. package/build/legacy/focusManager.d.ts.map +1 -0
  19. package/build/legacy/focusManager.js +60 -76
  20. package/build/legacy/focusManager.js.map +1 -1
  21. package/build/legacy/hydration-BhSbkfZj.d.cts +1374 -0
  22. package/build/legacy/hydration-BhSbkfZj.d.cts.map +1 -0
  23. package/build/legacy/hydration-Hebl6yHM.d.ts +1374 -0
  24. package/build/legacy/hydration-Hebl6yHM.d.ts.map +1 -0
  25. package/build/legacy/hydration.cjs +111 -194
  26. package/build/legacy/hydration.cjs.map +1 -1
  27. package/build/legacy/hydration.d.cts +2 -7
  28. package/build/legacy/hydration.d.ts +2 -7
  29. package/build/legacy/hydration.js +105 -167
  30. package/build/legacy/hydration.js.map +1 -1
  31. package/build/legacy/index.cjs +59 -111
  32. package/build/legacy/index.cjs.map +1 -1
  33. package/build/legacy/index.d.cts +10 -141
  34. package/build/legacy/index.d.ts +10 -141
  35. package/build/legacy/index.js +16 -66
  36. package/build/legacy/index.js.map +1 -1
  37. package/build/legacy/infiniteQueryBehavior.cjs +92 -135
  38. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  39. package/build/legacy/infiniteQueryBehavior.d.cts +14 -3
  40. package/build/legacy/infiniteQueryBehavior.d.cts.map +1 -0
  41. package/build/legacy/infiniteQueryBehavior.d.ts +14 -3
  42. package/build/legacy/infiniteQueryBehavior.d.ts.map +1 -0
  43. package/build/legacy/infiniteQueryBehavior.js +89 -115
  44. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  45. package/build/legacy/infiniteQueryObserver.cjs +59 -88
  46. package/build/legacy/infiniteQueryObserver.cjs.map +1 -1
  47. package/build/legacy/infiniteQueryObserver.d.cts +20 -1
  48. package/build/legacy/infiniteQueryObserver.d.cts.map +1 -0
  49. package/build/legacy/infiniteQueryObserver.d.ts +20 -1
  50. package/build/legacy/infiniteQueryObserver.d.ts.map +1 -0
  51. package/build/legacy/infiniteQueryObserver.js +57 -64
  52. package/build/legacy/infiniteQueryObserver.js.map +1 -1
  53. package/build/legacy/mutation.cjs +236 -329
  54. package/build/legacy/mutation.cjs.map +1 -1
  55. package/build/legacy/mutation.d.cts +2 -4
  56. package/build/legacy/mutation.d.ts +2 -4
  57. package/build/legacy/mutation.js +231 -299
  58. package/build/legacy/mutation.js.map +1 -1
  59. package/build/legacy/mutationCache.cjs +121 -166
  60. package/build/legacy/mutationCache.cjs.map +1 -1
  61. package/build/legacy/mutationCache.d.cts +2 -2
  62. package/build/legacy/mutationCache.d.ts +2 -2
  63. package/build/legacy/mutationCache.js +117 -130
  64. package/build/legacy/mutationCache.js.map +1 -1
  65. package/build/legacy/mutationObserver.cjs +134 -187
  66. package/build/legacy/mutationObserver.cjs.map +1 -1
  67. package/build/legacy/mutationObserver.d.cts +2 -1
  68. package/build/legacy/mutationObserver.d.ts +2 -1
  69. package/build/legacy/mutationObserver.js +132 -160
  70. package/build/legacy/mutationObserver.js.map +1 -1
  71. package/build/legacy/notifyManager.cjs +76 -110
  72. package/build/legacy/notifyManager.cjs.map +1 -1
  73. package/build/legacy/notifyManager.d.cts +48 -3
  74. package/build/legacy/notifyManager.d.cts.map +1 -0
  75. package/build/legacy/notifyManager.d.ts +48 -3
  76. package/build/legacy/notifyManager.d.ts.map +1 -0
  77. package/build/legacy/notifyManager.js +73 -84
  78. package/build/legacy/notifyManager.js.map +1 -1
  79. package/build/legacy/onlineManager.cjs +57 -93
  80. package/build/legacy/onlineManager.cjs.map +1 -1
  81. package/build/legacy/onlineManager.d.cts +17 -2
  82. package/build/legacy/onlineManager.d.cts.map +1 -0
  83. package/build/legacy/onlineManager.d.ts +17 -2
  84. package/build/legacy/onlineManager.d.ts.map +1 -0
  85. package/build/legacy/onlineManager.js +54 -65
  86. package/build/legacy/onlineManager.js.map +1 -1
  87. package/build/legacy/queriesObserver.cjs +203 -262
  88. package/build/legacy/queriesObserver.cjs.map +1 -1
  89. package/build/legacy/queriesObserver.d.cts +23 -2
  90. package/build/legacy/queriesObserver.d.cts.map +1 -0
  91. package/build/legacy/queriesObserver.d.ts +23 -2
  92. package/build/legacy/queriesObserver.d.ts.map +1 -0
  93. package/build/legacy/queriesObserver.js +199 -233
  94. package/build/legacy/queriesObserver.js.map +1 -1
  95. package/build/legacy/query.cjs +409 -491
  96. package/build/legacy/query.cjs.map +1 -1
  97. package/build/legacy/query.d.cts +2 -9
  98. package/build/legacy/query.d.ts +2 -9
  99. package/build/legacy/query.js +402 -467
  100. package/build/legacy/query.js.map +1 -1
  101. package/build/legacy/queryCache.cjs +99 -128
  102. package/build/legacy/queryCache.cjs.map +1 -1
  103. package/build/legacy/queryCache.d.cts +2 -3
  104. package/build/legacy/queryCache.d.ts +2 -3
  105. package/build/legacy/queryCache.js +96 -100
  106. package/build/legacy/queryCache.js.map +1 -1
  107. package/build/legacy/queryClient.cjs +295 -345
  108. package/build/legacy/queryClient.cjs.map +1 -1
  109. package/build/legacy/queryClient.d.cts +2 -1
  110. package/build/legacy/queryClient.d.ts +2 -1
  111. package/build/legacy/queryClient.js +292 -318
  112. package/build/legacy/queryClient.js.map +1 -1
  113. package/build/legacy/queryObserver.cjs +350 -502
  114. package/build/legacy/queryObserver.cjs.map +1 -1
  115. package/build/legacy/queryObserver.d.cts +2 -1
  116. package/build/legacy/queryObserver.d.ts +2 -1
  117. package/build/legacy/queryObserver.js +345 -480
  118. package/build/legacy/queryObserver.js.map +1 -1
  119. package/build/legacy/removable-DeMjhW5M.d.cts +13 -0
  120. package/build/legacy/removable-DeMjhW5M.d.cts.map +1 -0
  121. package/build/legacy/removable-DeMjhW5M.d.ts +13 -0
  122. package/build/legacy/removable-DeMjhW5M.d.ts.map +1 -0
  123. package/build/legacy/removable.cjs +31 -67
  124. package/build/legacy/removable.cjs.map +1 -1
  125. package/build/legacy/removable.d.cts +2 -1
  126. package/build/legacy/removable.d.ts +2 -1
  127. package/build/legacy/removable.js +28 -39
  128. package/build/legacy/removable.js.map +1 -1
  129. package/build/legacy/retryer.cjs +127 -155
  130. package/build/legacy/retryer.cjs.map +1 -1
  131. package/build/legacy/retryer.d.cts +2 -7
  132. package/build/legacy/retryer.d.ts +2 -7
  133. package/build/legacy/retryer.js +121 -127
  134. package/build/legacy/retryer.js.map +1 -1
  135. package/build/legacy/streamedQuery.cjs +49 -78
  136. package/build/legacy/streamedQuery.cjs.map +1 -1
  137. package/build/legacy/streamedQuery.d.cts +33 -1
  138. package/build/legacy/streamedQuery.d.cts.map +1 -0
  139. package/build/legacy/streamedQuery.d.ts +33 -1
  140. package/build/legacy/streamedQuery.d.ts.map +1 -0
  141. package/build/legacy/streamedQuery.js +47 -54
  142. package/build/legacy/streamedQuery.js.map +1 -1
  143. package/build/legacy/subscribable-CbifVTKz.d.cts +12 -0
  144. package/build/legacy/subscribable-CbifVTKz.d.cts.map +1 -0
  145. package/build/legacy/subscribable-CbifVTKz.d.ts +12 -0
  146. package/build/legacy/subscribable-CbifVTKz.d.ts.map +1 -0
  147. package/build/legacy/subscribable.cjs +22 -48
  148. package/build/legacy/subscribable.cjs.map +1 -1
  149. package/build/legacy/subscribable.d.cts +2 -1
  150. package/build/legacy/subscribable.d.ts +2 -1
  151. package/build/legacy/subscribable.js +21 -25
  152. package/build/legacy/subscribable.js.map +1 -1
  153. package/build/legacy/timeoutManager.cjs +64 -105
  154. package/build/legacy/timeoutManager.cjs.map +1 -1
  155. package/build/legacy/timeoutManager.d.cts +60 -7
  156. package/build/legacy/timeoutManager.d.cts.map +1 -0
  157. package/build/legacy/timeoutManager.d.ts +60 -7
  158. package/build/legacy/timeoutManager.d.ts.map +1 -0
  159. package/build/legacy/timeoutManager.js +60 -76
  160. package/build/legacy/timeoutManager.js.map +1 -1
  161. package/build/legacy/types.cjs +10 -35
  162. package/build/legacy/types.cjs.map +1 -1
  163. package/build/legacy/types.d.cts +2 -94
  164. package/build/legacy/types.d.ts +2 -94
  165. package/build/legacy/types.js +7 -10
  166. package/build/legacy/types.js.map +1 -1
  167. package/build/legacy/utils.cjs +175 -300
  168. package/build/legacy/utils.cjs.map +1 -1
  169. package/build/legacy/utils.d.cts +2 -30
  170. package/build/legacy/utils.d.ts +2 -30
  171. package/build/legacy/utils.js +149 -252
  172. package/build/legacy/utils.js.map +1 -1
  173. package/build/modern/environmentManager.cjs +25 -46
  174. package/build/modern/environmentManager.cjs.map +1 -1
  175. package/build/modern/environmentManager.d.cts +18 -2
  176. package/build/modern/environmentManager.d.cts.map +1 -0
  177. package/build/modern/environmentManager.d.ts +18 -2
  178. package/build/modern/environmentManager.d.ts.map +1 -0
  179. package/build/modern/environmentManager.js +23 -20
  180. package/build/modern/environmentManager.js.map +1 -1
  181. package/build/modern/focusManager.cjs +56 -90
  182. package/build/modern/focusManager.cjs.map +1 -1
  183. package/build/modern/focusManager.d.cts +18 -2
  184. package/build/modern/focusManager.d.cts.map +1 -0
  185. package/build/modern/focusManager.d.ts +18 -2
  186. package/build/modern/focusManager.d.ts.map +1 -0
  187. package/build/modern/focusManager.js +53 -63
  188. package/build/modern/focusManager.js.map +1 -1
  189. package/build/modern/hydration-BhSbkfZj.d.cts +1374 -0
  190. package/build/modern/hydration-BhSbkfZj.d.cts.map +1 -0
  191. package/build/modern/hydration-Hebl6yHM.d.ts +1374 -0
  192. package/build/modern/hydration-Hebl6yHM.d.ts.map +1 -0
  193. package/build/modern/hydration.cjs +102 -189
  194. package/build/modern/hydration.cjs.map +1 -1
  195. package/build/modern/hydration.d.cts +2 -7
  196. package/build/modern/hydration.d.ts +2 -7
  197. package/build/modern/hydration.js +96 -160
  198. package/build/modern/hydration.js.map +1 -1
  199. package/build/modern/index.cjs +59 -111
  200. package/build/modern/index.cjs.map +1 -1
  201. package/build/modern/index.d.cts +10 -141
  202. package/build/modern/index.d.ts +10 -141
  203. package/build/modern/index.js +16 -64
  204. package/build/modern/index.js.map +1 -1
  205. package/build/modern/infiniteQueryBehavior.cjs +89 -131
  206. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  207. package/build/modern/infiniteQueryBehavior.d.cts +14 -3
  208. package/build/modern/infiniteQueryBehavior.d.cts.map +1 -0
  209. package/build/modern/infiniteQueryBehavior.d.ts +14 -3
  210. package/build/modern/infiniteQueryBehavior.d.ts.map +1 -0
  211. package/build/modern/infiniteQueryBehavior.js +86 -109
  212. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  213. package/build/modern/infiniteQueryObserver.cjs +58 -87
  214. package/build/modern/infiniteQueryObserver.cjs.map +1 -1
  215. package/build/modern/infiniteQueryObserver.d.cts +20 -1
  216. package/build/modern/infiniteQueryObserver.d.cts.map +1 -0
  217. package/build/modern/infiniteQueryObserver.d.ts +20 -1
  218. package/build/modern/infiniteQueryObserver.d.ts.map +1 -0
  219. package/build/modern/infiniteQueryObserver.js +56 -61
  220. package/build/modern/infiniteQueryObserver.js.map +1 -1
  221. package/build/modern/mutation.cjs +221 -303
  222. package/build/modern/mutation.cjs.map +1 -1
  223. package/build/modern/mutation.d.cts +2 -4
  224. package/build/modern/mutation.d.ts +2 -4
  225. package/build/modern/mutation.js +216 -274
  226. package/build/modern/mutation.js.map +1 -1
  227. package/build/modern/mutationCache.cjs +111 -145
  228. package/build/modern/mutationCache.cjs.map +1 -1
  229. package/build/modern/mutationCache.d.cts +2 -2
  230. package/build/modern/mutationCache.d.ts +2 -2
  231. package/build/modern/mutationCache.js +107 -117
  232. package/build/modern/mutationCache.js.map +1 -1
  233. package/build/modern/mutationObserver.cjs +115 -162
  234. package/build/modern/mutationObserver.cjs.map +1 -1
  235. package/build/modern/mutationObserver.d.cts +2 -1
  236. package/build/modern/mutationObserver.d.ts +2 -1
  237. package/build/modern/mutationObserver.js +113 -136
  238. package/build/modern/mutationObserver.js.map +1 -1
  239. package/build/modern/notifyManager.cjs +76 -110
  240. package/build/modern/notifyManager.cjs.map +1 -1
  241. package/build/modern/notifyManager.d.cts +48 -3
  242. package/build/modern/notifyManager.d.cts.map +1 -0
  243. package/build/modern/notifyManager.d.ts +48 -3
  244. package/build/modern/notifyManager.d.ts.map +1 -0
  245. package/build/modern/notifyManager.js +73 -82
  246. package/build/modern/notifyManager.js.map +1 -1
  247. package/build/modern/onlineManager.cjs +51 -80
  248. package/build/modern/onlineManager.cjs.map +1 -1
  249. package/build/modern/onlineManager.d.cts +17 -2
  250. package/build/modern/onlineManager.d.cts.map +1 -0
  251. package/build/modern/onlineManager.d.ts +17 -2
  252. package/build/modern/onlineManager.d.ts.map +1 -0
  253. package/build/modern/onlineManager.js +48 -53
  254. package/build/modern/onlineManager.js.map +1 -1
  255. package/build/modern/queriesObserver.cjs +185 -237
  256. package/build/modern/queriesObserver.cjs.map +1 -1
  257. package/build/modern/queriesObserver.d.cts +23 -2
  258. package/build/modern/queriesObserver.d.cts.map +1 -0
  259. package/build/modern/queriesObserver.d.ts +23 -2
  260. package/build/modern/queriesObserver.d.ts.map +1 -0
  261. package/build/modern/queriesObserver.js +181 -209
  262. package/build/modern/queriesObserver.js.map +1 -1
  263. package/build/modern/query.cjs +384 -464
  264. package/build/modern/query.cjs.map +1 -1
  265. package/build/modern/query.d.cts +2 -9
  266. package/build/modern/query.d.ts +2 -9
  267. package/build/modern/query.js +377 -441
  268. package/build/modern/query.js.map +1 -1
  269. package/build/modern/queryCache.cjs +97 -119
  270. package/build/modern/queryCache.cjs.map +1 -1
  271. package/build/modern/queryCache.d.cts +2 -3
  272. package/build/modern/queryCache.d.ts +2 -3
  273. package/build/modern/queryCache.js +94 -92
  274. package/build/modern/queryCache.js.map +1 -1
  275. package/build/modern/queryClient.cjs +281 -318
  276. package/build/modern/queryClient.cjs.map +1 -1
  277. package/build/modern/queryClient.d.cts +2 -1
  278. package/build/modern/queryClient.d.ts +2 -1
  279. package/build/modern/queryClient.js +278 -299
  280. package/build/modern/queryClient.js.map +1 -1
  281. package/build/modern/queryObserver.cjs +329 -475
  282. package/build/modern/queryObserver.cjs.map +1 -1
  283. package/build/modern/queryObserver.d.cts +2 -1
  284. package/build/modern/queryObserver.d.ts +2 -1
  285. package/build/modern/queryObserver.js +324 -454
  286. package/build/modern/queryObserver.js.map +1 -1
  287. package/build/modern/removable-DeMjhW5M.d.cts +13 -0
  288. package/build/modern/removable-DeMjhW5M.d.cts.map +1 -0
  289. package/build/modern/removable-DeMjhW5M.d.ts +13 -0
  290. package/build/modern/removable-DeMjhW5M.d.ts.map +1 -0
  291. package/build/modern/removable.cjs +27 -56
  292. package/build/modern/removable.cjs.map +1 -1
  293. package/build/modern/removable.d.cts +2 -1
  294. package/build/modern/removable.d.ts +2 -1
  295. package/build/modern/removable.js +24 -29
  296. package/build/modern/removable.js.map +1 -1
  297. package/build/modern/retryer.cjs +121 -151
  298. package/build/modern/retryer.cjs.map +1 -1
  299. package/build/modern/retryer.d.cts +2 -7
  300. package/build/modern/retryer.d.ts +2 -7
  301. package/build/modern/retryer.js +115 -121
  302. package/build/modern/retryer.js.map +1 -1
  303. package/build/modern/streamedQuery.cjs +49 -78
  304. package/build/modern/streamedQuery.cjs.map +1 -1
  305. package/build/modern/streamedQuery.d.cts +33 -1
  306. package/build/modern/streamedQuery.d.cts.map +1 -0
  307. package/build/modern/streamedQuery.d.ts +33 -1
  308. package/build/modern/streamedQuery.d.ts.map +1 -0
  309. package/build/modern/streamedQuery.js +47 -52
  310. package/build/modern/streamedQuery.js.map +1 -1
  311. package/build/modern/subscribable-CbifVTKz.d.cts +12 -0
  312. package/build/modern/subscribable-CbifVTKz.d.cts.map +1 -0
  313. package/build/modern/subscribable-CbifVTKz.d.ts +12 -0
  314. package/build/modern/subscribable-CbifVTKz.d.ts.map +1 -0
  315. package/build/modern/subscribable.cjs +22 -48
  316. package/build/modern/subscribable.cjs.map +1 -1
  317. package/build/modern/subscribable.d.cts +2 -1
  318. package/build/modern/subscribable.d.ts +2 -1
  319. package/build/modern/subscribable.js +21 -23
  320. package/build/modern/subscribable.js.map +1 -1
  321. package/build/modern/timeoutManager.cjs +59 -93
  322. package/build/modern/timeoutManager.cjs.map +1 -1
  323. package/build/modern/timeoutManager.d.cts +60 -7
  324. package/build/modern/timeoutManager.d.cts.map +1 -0
  325. package/build/modern/timeoutManager.d.ts +60 -7
  326. package/build/modern/timeoutManager.d.ts.map +1 -0
  327. package/build/modern/timeoutManager.js +55 -65
  328. package/build/modern/timeoutManager.js.map +1 -1
  329. package/build/modern/types.cjs +10 -35
  330. package/build/modern/types.cjs.map +1 -1
  331. package/build/modern/types.d.cts +2 -94
  332. package/build/modern/types.d.ts +2 -94
  333. package/build/modern/types.js +8 -9
  334. package/build/modern/types.js.map +1 -1
  335. package/build/modern/utils.cjs +175 -300
  336. package/build/modern/utils.cjs.map +1 -1
  337. package/build/modern/utils.d.cts +2 -30
  338. package/build/modern/utils.d.ts +2 -30
  339. package/build/modern/utils.js +149 -250
  340. package/build/modern/utils.js.map +1 -1
  341. package/package.json +3 -5
  342. package/src/hydration.ts +65 -56
  343. package/src/index.ts +1 -0
  344. package/src/mutation.ts +14 -6
  345. package/src/mutationObserver.ts +8 -0
  346. package/src/queriesObserver.ts +14 -8
  347. package/src/query.ts +14 -6
  348. package/src/queryClient.ts +90 -2
  349. package/src/queryObserver.ts +41 -64
  350. package/src/retryer.ts +20 -12
  351. package/src/types.ts +70 -58
  352. package/build/legacy/_tsup-dts-rollup.d.cts +0 -2188
  353. package/build/legacy/_tsup-dts-rollup.d.ts +0 -2188
  354. package/build/legacy/chunk-PXG64RU4.js +0 -25
  355. package/build/legacy/chunk-PXG64RU4.js.map +0 -1
  356. package/build/legacy/thenable.cjs +0 -76
  357. package/build/legacy/thenable.cjs.map +0 -1
  358. package/build/legacy/thenable.d.cts +0 -6
  359. package/build/legacy/thenable.d.ts +0 -6
  360. package/build/legacy/thenable.js +0 -52
  361. package/build/legacy/thenable.js.map +0 -1
  362. package/build/modern/_tsup-dts-rollup.d.cts +0 -2188
  363. package/build/modern/_tsup-dts-rollup.d.ts +0 -2188
  364. package/build/modern/thenable.cjs +0 -75
  365. package/build/modern/thenable.cjs.map +0 -1
  366. package/build/modern/thenable.d.cts +0 -6
  367. package/build/modern/thenable.d.ts +0 -6
  368. package/build/modern/thenable.js +0 -49
  369. package/build/modern/thenable.js.map +0 -1
  370. package/src/thenable.ts +0 -111
@@ -1,304 +1,283 @@
1
- // src/queryClient.ts
2
- import {
3
- functionalUpdate,
4
- hashKey,
5
- hashQueryKeyByOptions,
6
- noop,
7
- partialMatchKey,
8
- resolveStaleTime,
9
- skipToken
10
- } from "./utils.js";
11
- import { QueryCache } from "./queryCache.js";
12
- import { MutationCache } from "./mutationCache.js";
1
+ import { functionalUpdate, hashKey, hashQueryKeyByOptions, noop, partialMatchKey, resolveStaleTime, skipToken } from "./utils.js";
13
2
  import { focusManager } from "./focusManager.js";
14
- import { onlineManager } from "./onlineManager.js";
15
3
  import { notifyManager } from "./notifyManager.js";
4
+ import { onlineManager } from "./onlineManager.js";
5
+ import { MutationCache } from "./mutationCache.js";
6
+ import { QueryCache } from "./queryCache.js";
7
+ //#region src/queryClient.ts
16
8
  var QueryClient = class {
17
- #queryCache;
18
- #mutationCache;
19
- #defaultOptions;
20
- #queryDefaults;
21
- #mutationDefaults;
22
- #mountCount;
23
- #unsubscribeFocus;
24
- #unsubscribeOnline;
25
- constructor(config = {}) {
26
- this.#queryCache = config.queryCache || new QueryCache();
27
- this.#mutationCache = config.mutationCache || new MutationCache();
28
- this.#defaultOptions = config.defaultOptions || {};
29
- this.#queryDefaults = /* @__PURE__ */ new Map();
30
- this.#mutationDefaults = /* @__PURE__ */ new Map();
31
- this.#mountCount = 0;
32
- }
33
- mount() {
34
- this.#mountCount++;
35
- if (this.#mountCount !== 1) return;
36
- this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {
37
- if (focused) {
38
- await this.resumePausedMutations();
39
- this.#queryCache.onFocus();
40
- }
41
- });
42
- this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {
43
- if (online) {
44
- await this.resumePausedMutations();
45
- this.#queryCache.onOnline();
46
- }
47
- });
48
- }
49
- unmount() {
50
- this.#mountCount--;
51
- if (this.#mountCount !== 0) return;
52
- this.#unsubscribeFocus?.();
53
- this.#unsubscribeFocus = void 0;
54
- this.#unsubscribeOnline?.();
55
- this.#unsubscribeOnline = void 0;
56
- }
57
- isFetching(filters) {
58
- return this.#queryCache.findAll({ ...filters, fetchStatus: "fetching" }).length;
59
- }
60
- isMutating(filters) {
61
- return this.#mutationCache.findAll({ ...filters, status: "pending" }).length;
62
- }
63
- /**
64
- * Imperative (non-reactive) way to retrieve data for a QueryKey.
65
- * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
66
- *
67
- * Hint: Do not use this function inside a component, because it won't receive updates.
68
- * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
69
- */
70
- getQueryData(queryKey) {
71
- const options = this.defaultQueryOptions({ queryKey });
72
- return this.#queryCache.get(options.queryHash)?.state.data;
73
- }
74
- ensureQueryData(options) {
75
- const defaultedOptions = this.defaultQueryOptions(options);
76
- const query = this.#queryCache.build(this, defaultedOptions);
77
- const cachedData = query.state.data;
78
- if (cachedData === void 0) {
79
- return this.fetchQuery(options);
80
- }
81
- if (options.revalidateIfStale && query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query))) {
82
- void this.prefetchQuery(defaultedOptions);
83
- }
84
- return Promise.resolve(cachedData);
85
- }
86
- getQueriesData(filters) {
87
- return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {
88
- const data = state.data;
89
- return [queryKey, data];
90
- });
91
- }
92
- setQueryData(queryKey, updater, options) {
93
- const defaultedOptions = this.defaultQueryOptions({ queryKey });
94
- const query = this.#queryCache.get(
95
- defaultedOptions.queryHash
96
- );
97
- const prevData = query?.state.data;
98
- const data = functionalUpdate(updater, prevData);
99
- if (data === void 0) {
100
- return void 0;
101
- }
102
- return this.#queryCache.build(this, defaultedOptions).setData(data, { ...options, manual: true });
103
- }
104
- setQueriesData(filters, updater, options) {
105
- return notifyManager.batch(
106
- () => this.#queryCache.findAll(filters).map(({ queryKey }) => [
107
- queryKey,
108
- this.setQueryData(queryKey, updater, options)
109
- ])
110
- );
111
- }
112
- getQueryState(queryKey) {
113
- const options = this.defaultQueryOptions({ queryKey });
114
- return this.#queryCache.get(
115
- options.queryHash
116
- )?.state;
117
- }
118
- removeQueries(filters) {
119
- const queryCache = this.#queryCache;
120
- notifyManager.batch(() => {
121
- queryCache.findAll(filters).forEach((query) => {
122
- queryCache.remove(query);
123
- });
124
- });
125
- }
126
- resetQueries(filters, options) {
127
- const queryCache = this.#queryCache;
128
- return notifyManager.batch(() => {
129
- queryCache.findAll(filters).forEach((query) => {
130
- query.reset();
131
- });
132
- return this.refetchQueries(
133
- {
134
- type: "active",
135
- ...filters
136
- },
137
- options
138
- );
139
- });
140
- }
141
- cancelQueries(filters, cancelOptions = {}) {
142
- const defaultedCancelOptions = { revert: true, ...cancelOptions };
143
- const promises = notifyManager.batch(
144
- () => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions))
145
- );
146
- return Promise.all(promises).then(noop).catch(noop);
147
- }
148
- invalidateQueries(filters, options = {}) {
149
- return notifyManager.batch(() => {
150
- this.#queryCache.findAll(filters).forEach((query) => {
151
- query.invalidate();
152
- });
153
- if (filters?.refetchType === "none") {
154
- return Promise.resolve();
155
- }
156
- return this.refetchQueries(
157
- {
158
- ...filters,
159
- type: filters?.refetchType ?? filters?.type ?? "active"
160
- },
161
- options
162
- );
163
- });
164
- }
165
- refetchQueries(filters, options = {}) {
166
- const fetchOptions = {
167
- ...options,
168
- cancelRefetch: options.cancelRefetch ?? true
169
- };
170
- const promises = notifyManager.batch(
171
- () => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
172
- let promise = query.fetch(void 0, fetchOptions);
173
- if (!fetchOptions.throwOnError) {
174
- promise = promise.catch(noop);
175
- }
176
- return query.state.fetchStatus === "paused" ? Promise.resolve() : promise;
177
- })
178
- );
179
- return Promise.all(promises).then(noop);
180
- }
181
- fetchQuery(options) {
182
- const defaultedOptions = this.defaultQueryOptions(options);
183
- if (defaultedOptions.retry === void 0) {
184
- defaultedOptions.retry = false;
185
- }
186
- const query = this.#queryCache.build(this, defaultedOptions);
187
- return query.isStaleByTime(
188
- resolveStaleTime(defaultedOptions.staleTime, query)
189
- ) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
190
- }
191
- prefetchQuery(options) {
192
- return this.fetchQuery(options).then(noop).catch(noop);
193
- }
194
- fetchInfiniteQuery(options) {
195
- options._type = "infinite";
196
- return this.fetchQuery(options);
197
- }
198
- prefetchInfiniteQuery(options) {
199
- return this.fetchInfiniteQuery(options).then(noop).catch(noop);
200
- }
201
- ensureInfiniteQueryData(options) {
202
- options._type = "infinite";
203
- return this.ensureQueryData(options);
204
- }
205
- resumePausedMutations() {
206
- if (onlineManager.isOnline()) {
207
- return this.#mutationCache.resumePausedMutations();
208
- }
209
- return Promise.resolve();
210
- }
211
- getQueryCache() {
212
- return this.#queryCache;
213
- }
214
- getMutationCache() {
215
- return this.#mutationCache;
216
- }
217
- getDefaultOptions() {
218
- return this.#defaultOptions;
219
- }
220
- setDefaultOptions(options) {
221
- this.#defaultOptions = options;
222
- }
223
- setQueryDefaults(queryKey, options) {
224
- this.#queryDefaults.set(hashKey(queryKey), {
225
- queryKey,
226
- defaultOptions: options
227
- });
228
- }
229
- getQueryDefaults(queryKey) {
230
- const defaults = [...this.#queryDefaults.values()];
231
- const result = {};
232
- defaults.forEach((queryDefault) => {
233
- if (partialMatchKey(queryKey, queryDefault.queryKey)) {
234
- Object.assign(result, queryDefault.defaultOptions);
235
- }
236
- });
237
- return result;
238
- }
239
- setMutationDefaults(mutationKey, options) {
240
- this.#mutationDefaults.set(hashKey(mutationKey), {
241
- mutationKey,
242
- defaultOptions: options
243
- });
244
- }
245
- getMutationDefaults(mutationKey) {
246
- const defaults = [...this.#mutationDefaults.values()];
247
- const result = {};
248
- defaults.forEach((queryDefault) => {
249
- if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {
250
- Object.assign(result, queryDefault.defaultOptions);
251
- }
252
- });
253
- return result;
254
- }
255
- defaultQueryOptions(options) {
256
- if (options._defaulted) {
257
- return options;
258
- }
259
- const defaultedOptions = {
260
- ...this.#defaultOptions.queries,
261
- ...this.getQueryDefaults(options.queryKey),
262
- ...options,
263
- _defaulted: true
264
- };
265
- if (!defaultedOptions.queryHash) {
266
- defaultedOptions.queryHash = hashQueryKeyByOptions(
267
- defaultedOptions.queryKey,
268
- defaultedOptions
269
- );
270
- }
271
- if (defaultedOptions.refetchOnReconnect === void 0) {
272
- defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always";
273
- }
274
- if (defaultedOptions.throwOnError === void 0) {
275
- defaultedOptions.throwOnError = !!defaultedOptions.suspense;
276
- }
277
- if (!defaultedOptions.networkMode && defaultedOptions.persister) {
278
- defaultedOptions.networkMode = "offlineFirst";
279
- }
280
- if (defaultedOptions.queryFn === skipToken) {
281
- defaultedOptions.enabled = false;
282
- }
283
- return defaultedOptions;
284
- }
285
- defaultMutationOptions(options) {
286
- if (options?._defaulted) {
287
- return options;
288
- }
289
- return {
290
- ...this.#defaultOptions.mutations,
291
- ...options?.mutationKey && this.getMutationDefaults(options.mutationKey),
292
- ...options,
293
- _defaulted: true
294
- };
295
- }
296
- clear() {
297
- this.#queryCache.clear();
298
- this.#mutationCache.clear();
299
- }
300
- };
301
- export {
302
- QueryClient
9
+ #queryCache;
10
+ #mutationCache;
11
+ #defaultOptions;
12
+ #queryDefaults;
13
+ #mutationDefaults;
14
+ #mountCount;
15
+ #unsubscribeFocus;
16
+ #unsubscribeOnline;
17
+ constructor(config = {}) {
18
+ this.#queryCache = config.queryCache || new QueryCache();
19
+ this.#mutationCache = config.mutationCache || new MutationCache();
20
+ this.#defaultOptions = config.defaultOptions || {};
21
+ this.#queryDefaults = /* @__PURE__ */ new Map();
22
+ this.#mutationDefaults = /* @__PURE__ */ new Map();
23
+ this.#mountCount = 0;
24
+ }
25
+ mount() {
26
+ this.#mountCount++;
27
+ if (this.#mountCount !== 1) return;
28
+ this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {
29
+ if (focused) {
30
+ await this.resumePausedMutations();
31
+ this.#queryCache.onFocus();
32
+ }
33
+ });
34
+ this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {
35
+ if (online) {
36
+ await this.resumePausedMutations();
37
+ this.#queryCache.onOnline();
38
+ }
39
+ });
40
+ }
41
+ unmount() {
42
+ this.#mountCount--;
43
+ if (this.#mountCount !== 0) return;
44
+ this.#unsubscribeFocus?.();
45
+ this.#unsubscribeFocus = void 0;
46
+ this.#unsubscribeOnline?.();
47
+ this.#unsubscribeOnline = void 0;
48
+ }
49
+ isFetching(filters) {
50
+ return this.#queryCache.findAll({
51
+ ...filters,
52
+ fetchStatus: "fetching"
53
+ }).length;
54
+ }
55
+ isMutating(filters) {
56
+ return this.#mutationCache.findAll({
57
+ ...filters,
58
+ status: "pending"
59
+ }).length;
60
+ }
61
+ /**
62
+ * Imperative (non-reactive) way to retrieve data for a QueryKey.
63
+ * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
64
+ *
65
+ * Hint: Do not use this function inside a component, because it won't receive updates.
66
+ * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
67
+ */
68
+ getQueryData(queryKey) {
69
+ const options = this.defaultQueryOptions({ queryKey });
70
+ return this.#queryCache.get(options.queryHash)?.state.data;
71
+ }
72
+ /**
73
+ * @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
74
+ */
75
+ ensureQueryData(options) {
76
+ const defaultedOptions = this.defaultQueryOptions(options);
77
+ const query = this.#queryCache.build(this, defaultedOptions);
78
+ const cachedData = query.state.data;
79
+ if (cachedData === void 0) return this.fetchQuery(options);
80
+ if (options.revalidateIfStale && query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query))) this.prefetchQuery(defaultedOptions);
81
+ return Promise.resolve(cachedData);
82
+ }
83
+ getQueriesData(filters) {
84
+ return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {
85
+ return [queryKey, state.data];
86
+ });
87
+ }
88
+ setQueryData(queryKey, updater, options) {
89
+ const defaultedOptions = this.defaultQueryOptions({ queryKey });
90
+ const prevData = this.#queryCache.get(defaultedOptions.queryHash)?.state.data;
91
+ const data = functionalUpdate(updater, prevData);
92
+ if (data === void 0) return;
93
+ return this.#queryCache.build(this, defaultedOptions).setData(data, {
94
+ ...options,
95
+ manual: true
96
+ });
97
+ }
98
+ setQueriesData(filters, updater, options) {
99
+ return notifyManager.batch(() => this.#queryCache.findAll(filters).map(({ queryKey }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
100
+ }
101
+ getQueryState(queryKey) {
102
+ const options = this.defaultQueryOptions({ queryKey });
103
+ return this.#queryCache.get(options.queryHash)?.state;
104
+ }
105
+ removeQueries(filters) {
106
+ const queryCache = this.#queryCache;
107
+ notifyManager.batch(() => {
108
+ queryCache.findAll(filters).forEach((query) => {
109
+ queryCache.remove(query);
110
+ });
111
+ });
112
+ }
113
+ resetQueries(filters, options) {
114
+ const queryCache = this.#queryCache;
115
+ return notifyManager.batch(() => {
116
+ const matched = queryCache.findAll(filters);
117
+ const queriesToRefetch = new Set(matched);
118
+ matched.forEach((query) => {
119
+ query.reset();
120
+ });
121
+ return this.refetchQueries({
122
+ type: "active",
123
+ predicate: (query) => queriesToRefetch.has(query)
124
+ }, options);
125
+ });
126
+ }
127
+ cancelQueries(filters, cancelOptions = {}) {
128
+ const defaultedCancelOptions = {
129
+ revert: true,
130
+ ...cancelOptions
131
+ };
132
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions)));
133
+ return Promise.all(promises).then(noop).catch(noop);
134
+ }
135
+ invalidateQueries(filters, options = {}) {
136
+ return notifyManager.batch(() => {
137
+ this.#queryCache.findAll(filters).forEach((query) => {
138
+ query.invalidate();
139
+ });
140
+ if (filters?.refetchType === "none") return Promise.resolve();
141
+ return this.refetchQueries({
142
+ ...filters,
143
+ type: filters?.refetchType ?? filters?.type ?? "active"
144
+ }, options);
145
+ });
146
+ }
147
+ refetchQueries(filters, options = {}) {
148
+ const fetchOptions = {
149
+ ...options,
150
+ cancelRefetch: options.cancelRefetch ?? true
151
+ };
152
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
153
+ let promise = query.fetch(void 0, fetchOptions);
154
+ if (!fetchOptions.throwOnError) promise = promise.catch(noop);
155
+ return query.state.fetchStatus === "paused" ? Promise.resolve() : promise;
156
+ }));
157
+ return Promise.all(promises).then(noop);
158
+ }
159
+ async query(options) {
160
+ const defaultedOptions = this.defaultQueryOptions(options);
161
+ if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
162
+ const query = this.#queryCache.build(this, defaultedOptions);
163
+ const queryData = query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query)) ? await query.fetch(defaultedOptions) : query.state.data;
164
+ const select = defaultedOptions.select;
165
+ if (select) return select(queryData);
166
+ return queryData;
167
+ }
168
+ /**
169
+ * @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
170
+ */
171
+ fetchQuery(options) {
172
+ const defaultedOptions = this.defaultQueryOptions(options);
173
+ if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
174
+ const query = this.#queryCache.build(this, defaultedOptions);
175
+ return query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query)) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
176
+ }
177
+ /**
178
+ * @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
179
+ */
180
+ prefetchQuery(options) {
181
+ return this.fetchQuery(options).then(noop).catch(noop);
182
+ }
183
+ infiniteQuery(options) {
184
+ options._type = "infinite";
185
+ return this.query(options);
186
+ }
187
+ /**
188
+ * @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
189
+ */
190
+ fetchInfiniteQuery(options) {
191
+ options._type = "infinite";
192
+ return this.fetchQuery(options);
193
+ }
194
+ /**
195
+ * @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
196
+ */
197
+ prefetchInfiniteQuery(options) {
198
+ return this.fetchInfiniteQuery(options).then(noop).catch(noop);
199
+ }
200
+ /**
201
+ * @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
202
+ */
203
+ ensureInfiniteQueryData(options) {
204
+ options._type = "infinite";
205
+ return this.ensureQueryData(options);
206
+ }
207
+ resumePausedMutations() {
208
+ if (onlineManager.isOnline()) return this.#mutationCache.resumePausedMutations();
209
+ return Promise.resolve();
210
+ }
211
+ getQueryCache() {
212
+ return this.#queryCache;
213
+ }
214
+ getMutationCache() {
215
+ return this.#mutationCache;
216
+ }
217
+ getDefaultOptions() {
218
+ return this.#defaultOptions;
219
+ }
220
+ setDefaultOptions(options) {
221
+ this.#defaultOptions = options;
222
+ }
223
+ setQueryDefaults(queryKey, options) {
224
+ this.#queryDefaults.set(hashKey(queryKey), {
225
+ queryKey,
226
+ defaultOptions: options
227
+ });
228
+ }
229
+ getQueryDefaults(queryKey) {
230
+ const defaults = [...this.#queryDefaults.values()];
231
+ const result = {};
232
+ defaults.forEach((queryDefault) => {
233
+ if (partialMatchKey(queryKey, queryDefault.queryKey)) Object.assign(result, queryDefault.defaultOptions);
234
+ });
235
+ return result;
236
+ }
237
+ setMutationDefaults(mutationKey, options) {
238
+ this.#mutationDefaults.set(hashKey(mutationKey), {
239
+ mutationKey,
240
+ defaultOptions: options
241
+ });
242
+ }
243
+ getMutationDefaults(mutationKey) {
244
+ const defaults = [...this.#mutationDefaults.values()];
245
+ const result = {};
246
+ defaults.forEach((queryDefault) => {
247
+ if (partialMatchKey(mutationKey, queryDefault.mutationKey)) Object.assign(result, queryDefault.defaultOptions);
248
+ });
249
+ return result;
250
+ }
251
+ defaultQueryOptions(options) {
252
+ if (options._defaulted) return options;
253
+ const defaultedOptions = {
254
+ ...this.#defaultOptions.queries,
255
+ ...this.getQueryDefaults(options.queryKey),
256
+ ...options,
257
+ _defaulted: true
258
+ };
259
+ if (!defaultedOptions.queryHash) defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
260
+ if (defaultedOptions.refetchOnReconnect === void 0) defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always";
261
+ if (defaultedOptions.throwOnError === void 0) defaultedOptions.throwOnError = !!defaultedOptions.suspense;
262
+ if (!defaultedOptions.networkMode && defaultedOptions.persister) defaultedOptions.networkMode = "offlineFirst";
263
+ if (defaultedOptions.queryFn === skipToken) defaultedOptions.enabled = false;
264
+ return defaultedOptions;
265
+ }
266
+ defaultMutationOptions(options) {
267
+ if (options?._defaulted) return options;
268
+ return {
269
+ ...this.#defaultOptions.mutations,
270
+ ...options?.mutationKey && this.getMutationDefaults(options.mutationKey),
271
+ ...options,
272
+ _defaulted: true
273
+ };
274
+ }
275
+ clear() {
276
+ this.#queryCache.clear();
277
+ this.#mutationCache.clear();
278
+ }
303
279
  };
280
+ //#endregion
281
+ export { QueryClient };
282
+
304
283
  //# sourceMappingURL=queryClient.js.map