@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,489 +1,343 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/queryObserver.ts
21
- var queryObserver_exports = {};
22
- __export(queryObserver_exports, {
23
- QueryObserver: () => QueryObserver
24
- });
25
- module.exports = __toCommonJS(queryObserver_exports);
26
- var import_focusManager = require("./focusManager.cjs");
27
- var import_environmentManager = require("./environmentManager.cjs");
28
- var import_notifyManager = require("./notifyManager.cjs");
29
- var import_query = require("./query.cjs");
30
- var import_subscribable = require("./subscribable.cjs");
31
- var import_thenable = require("./thenable.cjs");
32
- var import_utils = require("./utils.cjs");
33
- var import_timeoutManager = require("./timeoutManager.cjs");
34
- var QueryObserver = class extends import_subscribable.Subscribable {
35
- constructor(client, options) {
36
- super();
37
- this.options = options;
38
- this.#client = client;
39
- this.#selectError = null;
40
- this.#currentThenable = (0, import_thenable.pendingThenable)();
41
- this.bindMethods();
42
- this.setOptions(options);
43
- }
44
- #client;
45
- #currentQuery = void 0;
46
- #currentQueryInitialState = void 0;
47
- #currentResult = void 0;
48
- #currentResultState;
49
- #currentResultOptions;
50
- #currentThenable;
51
- #selectError;
52
- #selectFn;
53
- #selectResult;
54
- // This property keeps track of the last query with defined data.
55
- // It will be used to pass the previous data and query to the placeholder function between renders.
56
- #lastQueryWithDefinedData;
57
- #staleTimeoutId;
58
- #refetchIntervalId;
59
- #currentRefetchInterval;
60
- #trackedProps = /* @__PURE__ */ new Set();
61
- bindMethods() {
62
- this.refetch = this.refetch.bind(this);
63
- }
64
- onSubscribe() {
65
- if (this.listeners.size === 1) {
66
- this.#currentQuery.addObserver(this);
67
- if (shouldFetchOnMount(this.#currentQuery, this.options)) {
68
- this.#executeFetch();
69
- } else {
70
- this.updateResult();
71
- }
72
- this.#updateTimers();
73
- }
74
- }
75
- onUnsubscribe() {
76
- if (!this.hasListeners()) {
77
- this.destroy();
78
- }
79
- }
80
- shouldFetchOnReconnect() {
81
- return shouldFetchOn(
82
- this.#currentQuery,
83
- this.options,
84
- this.options.refetchOnReconnect
85
- );
86
- }
87
- shouldFetchOnWindowFocus() {
88
- return shouldFetchOn(
89
- this.#currentQuery,
90
- this.options,
91
- this.options.refetchOnWindowFocus
92
- );
93
- }
94
- destroy() {
95
- this.listeners = /* @__PURE__ */ new Set();
96
- this.#clearStaleTimeout();
97
- this.#clearRefetchInterval();
98
- this.#currentQuery.removeObserver(this);
99
- }
100
- setOptions(options) {
101
- const prevOptions = this.options;
102
- const prevQuery = this.#currentQuery;
103
- this.options = this.#client.defaultQueryOptions(options);
104
- if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof (0, import_utils.resolveQueryBoolean)(this.options.enabled, this.#currentQuery) !== "boolean") {
105
- throw new Error(
106
- "Expected enabled to be a boolean or a callback that returns a boolean"
107
- );
108
- }
109
- this.#updateQuery();
110
- this.#currentQuery.setOptions(this.options);
111
- if (prevOptions._defaulted && !(0, import_utils.shallowEqualObjects)(this.options, prevOptions)) {
112
- this.#client.getQueryCache().notify({
113
- type: "observerOptionsUpdated",
114
- query: this.#currentQuery,
115
- observer: this
116
- });
117
- }
118
- const mounted = this.hasListeners();
119
- if (mounted && shouldFetchOptionally(
120
- this.#currentQuery,
121
- prevQuery,
122
- this.options,
123
- prevOptions
124
- )) {
125
- this.#executeFetch();
126
- }
127
- this.updateResult();
128
- if (mounted && (this.#currentQuery !== prevQuery || (0, import_utils.resolveQueryBoolean)(this.options.enabled, this.#currentQuery) !== (0, import_utils.resolveQueryBoolean)(prevOptions.enabled, this.#currentQuery) || (0, import_utils.resolveStaleTime)(this.options.staleTime, this.#currentQuery) !== (0, import_utils.resolveStaleTime)(prevOptions.staleTime, this.#currentQuery))) {
129
- this.#updateStaleTimeout();
130
- }
131
- const nextRefetchInterval = this.#computeRefetchInterval();
132
- if (mounted && (this.#currentQuery !== prevQuery || (0, import_utils.resolveQueryBoolean)(this.options.enabled, this.#currentQuery) !== (0, import_utils.resolveQueryBoolean)(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) {
133
- this.#updateRefetchInterval(nextRefetchInterval);
134
- }
135
- }
136
- getOptimisticResult(options) {
137
- const query = this.#client.getQueryCache().build(this.#client, options);
138
- const result = this.createResult(query, options);
139
- if (shouldAssignObserverCurrentProperties(this, result)) {
140
- this.#currentResult = result;
141
- this.#currentResultOptions = this.options;
142
- this.#currentResultState = this.#currentQuery.state;
143
- }
144
- return result;
145
- }
146
- getCurrentResult() {
147
- return this.#currentResult;
148
- }
149
- trackResult(result, onPropTracked) {
150
- return new Proxy(result, {
151
- get: (target, key) => {
152
- this.trackProp(key);
153
- onPropTracked?.(key);
154
- if (key === "promise") {
155
- this.trackProp("data");
156
- if (!this.options.experimental_prefetchInRender && this.#currentThenable.status === "pending") {
157
- this.#currentThenable.reject(
158
- new Error(
159
- "experimental_prefetchInRender feature flag is not enabled"
160
- )
161
- );
162
- }
163
- }
164
- return Reflect.get(target, key);
165
- }
166
- });
167
- }
168
- trackProp(key) {
169
- this.#trackedProps.add(key);
170
- }
171
- getCurrentQuery() {
172
- return this.#currentQuery;
173
- }
174
- refetch({ ...options } = {}) {
175
- return this.fetch({
176
- ...options
177
- });
178
- }
179
- fetchOptimistic(options) {
180
- const defaultedOptions = this.#client.defaultQueryOptions(options);
181
- const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
182
- return query.fetch().then(() => this.createResult(query, defaultedOptions));
183
- }
184
- fetch(fetchOptions) {
185
- return this.#executeFetch({
186
- ...fetchOptions,
187
- cancelRefetch: fetchOptions.cancelRefetch ?? true
188
- }).then(() => {
189
- this.updateResult();
190
- return this.#currentResult;
191
- });
192
- }
193
- #executeFetch(fetchOptions) {
194
- this.#updateQuery();
195
- let promise = this.#currentQuery.fetch(
196
- this.options,
197
- fetchOptions
198
- );
199
- if (!fetchOptions?.throwOnError) {
200
- promise = promise.catch(import_utils.noop);
201
- }
202
- return promise;
203
- }
204
- #updateStaleTimeout() {
205
- this.#clearStaleTimeout();
206
- const staleTime = (0, import_utils.resolveStaleTime)(
207
- this.options.staleTime,
208
- this.#currentQuery
209
- );
210
- if (import_environmentManager.environmentManager.isServer() || this.#currentResult.isStale || !(0, import_utils.isValidTimeout)(staleTime)) {
211
- return;
212
- }
213
- const time = (0, import_utils.timeUntilStale)(this.#currentResult.dataUpdatedAt, staleTime);
214
- const timeout = time + 1;
215
- this.#staleTimeoutId = import_timeoutManager.timeoutManager.setTimeout(() => {
216
- if (!this.#currentResult.isStale) {
217
- this.updateResult();
218
- }
219
- }, timeout);
220
- }
221
- #computeRefetchInterval() {
222
- return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
223
- }
224
- #updateRefetchInterval(nextInterval) {
225
- this.#clearRefetchInterval();
226
- this.#currentRefetchInterval = nextInterval;
227
- if (import_environmentManager.environmentManager.isServer() || (0, import_utils.resolveQueryBoolean)(this.options.enabled, this.#currentQuery) === false || !(0, import_utils.isValidTimeout)(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
228
- return;
229
- }
230
- this.#refetchIntervalId = import_timeoutManager.timeoutManager.setInterval(() => {
231
- if (this.options.refetchIntervalInBackground || import_focusManager.focusManager.isFocused()) {
232
- this.#executeFetch();
233
- }
234
- }, this.#currentRefetchInterval);
235
- }
236
- #updateTimers() {
237
- this.#updateStaleTimeout();
238
- this.#updateRefetchInterval(this.#computeRefetchInterval());
239
- }
240
- #clearStaleTimeout() {
241
- if (this.#staleTimeoutId !== void 0) {
242
- import_timeoutManager.timeoutManager.clearTimeout(this.#staleTimeoutId);
243
- this.#staleTimeoutId = void 0;
244
- }
245
- }
246
- #clearRefetchInterval() {
247
- if (this.#refetchIntervalId !== void 0) {
248
- import_timeoutManager.timeoutManager.clearInterval(this.#refetchIntervalId);
249
- this.#refetchIntervalId = void 0;
250
- }
251
- }
252
- createResult(query, options) {
253
- const prevQuery = this.#currentQuery;
254
- const prevOptions = this.options;
255
- const prevResult = this.#currentResult;
256
- const prevResultState = this.#currentResultState;
257
- const prevResultOptions = this.#currentResultOptions;
258
- const queryChange = query !== prevQuery;
259
- const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
260
- const { state } = query;
261
- let newState = { ...state };
262
- let isPlaceholderData = false;
263
- let data;
264
- if (options._optimisticResults) {
265
- const mounted = this.hasListeners();
266
- const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
267
- const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
268
- if (fetchOnMount || fetchOptionally) {
269
- newState = {
270
- ...newState,
271
- ...(0, import_query.fetchState)(state.data, query.options)
272
- };
273
- }
274
- if (options._optimisticResults === "isRestoring") {
275
- newState.fetchStatus = "idle";
276
- }
277
- }
278
- let { error, errorUpdatedAt, status } = newState;
279
- data = newState.data;
280
- let skipSelect = false;
281
- if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
282
- let placeholderData;
283
- if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
284
- placeholderData = prevResult.data;
285
- skipSelect = true;
286
- } else {
287
- placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(
288
- this.#lastQueryWithDefinedData?.state.data,
289
- this.#lastQueryWithDefinedData
290
- ) : options.placeholderData;
291
- }
292
- if (placeholderData !== void 0) {
293
- status = "success";
294
- data = (0, import_utils.replaceData)(
295
- prevResult?.data,
296
- placeholderData,
297
- options
298
- );
299
- isPlaceholderData = true;
300
- }
301
- }
302
- if (options.select && data !== void 0 && !skipSelect) {
303
- if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) {
304
- data = this.#selectResult;
305
- } else {
306
- try {
307
- this.#selectFn = options.select;
308
- data = options.select(data);
309
- data = (0, import_utils.replaceData)(prevResult?.data, data, options);
310
- this.#selectResult = data;
311
- this.#selectError = null;
312
- } catch (selectError) {
313
- this.#selectError = selectError;
314
- }
315
- }
316
- }
317
- if (this.#selectError) {
318
- error = this.#selectError;
319
- data = this.#selectResult;
320
- errorUpdatedAt = Date.now();
321
- status = "error";
322
- }
323
- const isFetching = newState.fetchStatus === "fetching";
324
- const isPending = status === "pending";
325
- const isError = status === "error";
326
- const isLoading = isPending && isFetching;
327
- const hasData = data !== void 0;
328
- const result = {
329
- status,
330
- fetchStatus: newState.fetchStatus,
331
- isPending,
332
- isSuccess: status === "success",
333
- isError,
334
- isInitialLoading: isLoading,
335
- isLoading,
336
- data,
337
- dataUpdatedAt: newState.dataUpdatedAt,
338
- error,
339
- errorUpdatedAt,
340
- failureCount: newState.fetchFailureCount,
341
- failureReason: newState.fetchFailureReason,
342
- errorUpdateCount: newState.errorUpdateCount,
343
- isFetched: query.isFetched(),
344
- isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
345
- isFetching,
346
- isRefetching: isFetching && !isPending,
347
- isLoadingError: isError && !hasData,
348
- isPaused: newState.fetchStatus === "paused",
349
- isPlaceholderData,
350
- isRefetchError: isError && hasData,
351
- isStale: isStale(query, options),
352
- refetch: this.refetch,
353
- promise: this.#currentThenable,
354
- isEnabled: (0, import_utils.resolveQueryBoolean)(options.enabled, query) !== false
355
- };
356
- const nextResult = result;
357
- if (this.options.experimental_prefetchInRender) {
358
- const hasResultData = nextResult.data !== void 0;
359
- const isErrorWithoutData = nextResult.status === "error" && !hasResultData;
360
- const finalizeThenableIfPossible = (thenable) => {
361
- if (isErrorWithoutData) {
362
- thenable.reject(nextResult.error);
363
- } else if (hasResultData) {
364
- thenable.resolve(nextResult.data);
365
- }
366
- };
367
- const recreateThenable = () => {
368
- const pending = this.#currentThenable = nextResult.promise = (0, import_thenable.pendingThenable)();
369
- finalizeThenableIfPossible(pending);
370
- };
371
- const prevThenable = this.#currentThenable;
372
- switch (prevThenable.status) {
373
- case "pending":
374
- if (query.queryHash === prevQuery.queryHash) {
375
- finalizeThenableIfPossible(prevThenable);
376
- }
377
- break;
378
- case "fulfilled":
379
- if (isErrorWithoutData || nextResult.data !== prevThenable.value) {
380
- recreateThenable();
381
- }
382
- break;
383
- case "rejected":
384
- if (!isErrorWithoutData || nextResult.error !== prevThenable.reason) {
385
- recreateThenable();
386
- }
387
- break;
388
- }
389
- }
390
- return nextResult;
391
- }
392
- updateResult() {
393
- const prevResult = this.#currentResult;
394
- const nextResult = this.createResult(this.#currentQuery, this.options);
395
- this.#currentResultState = this.#currentQuery.state;
396
- this.#currentResultOptions = this.options;
397
- if (this.#currentResultState.data !== void 0) {
398
- this.#lastQueryWithDefinedData = this.#currentQuery;
399
- }
400
- if ((0, import_utils.shallowEqualObjects)(nextResult, prevResult)) {
401
- return;
402
- }
403
- this.#currentResult = nextResult;
404
- const shouldNotifyListeners = () => {
405
- if (!prevResult) {
406
- return true;
407
- }
408
- const { notifyOnChangeProps } = this.options;
409
- const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
410
- if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) {
411
- return true;
412
- }
413
- const includedProps = new Set(
414
- notifyOnChangePropsValue ?? this.#trackedProps
415
- );
416
- if (this.options.throwOnError) {
417
- includedProps.add("error");
418
- }
419
- return Object.keys(this.#currentResult).some((key) => {
420
- const typedKey = key;
421
- const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
422
- return changed && includedProps.has(typedKey);
423
- });
424
- };
425
- this.#notify({ listeners: shouldNotifyListeners() });
426
- }
427
- #updateQuery() {
428
- const query = this.#client.getQueryCache().build(this.#client, this.options);
429
- if (query === this.#currentQuery) {
430
- return;
431
- }
432
- const prevQuery = this.#currentQuery;
433
- this.#currentQuery = query;
434
- this.#currentQueryInitialState = query.state;
435
- if (this.hasListeners()) {
436
- prevQuery?.removeObserver(this);
437
- query.addObserver(this);
438
- }
439
- }
440
- onQueryUpdate() {
441
- this.updateResult();
442
- if (this.hasListeners()) {
443
- this.#updateTimers();
444
- }
445
- }
446
- #notify(notifyOptions) {
447
- import_notifyManager.notifyManager.batch(() => {
448
- if (notifyOptions.listeners) {
449
- this.listeners.forEach((listener) => {
450
- listener(this.#currentResult);
451
- });
452
- }
453
- this.#client.getQueryCache().notify({
454
- query: this.#currentQuery,
455
- type: "observerResultsUpdated"
456
- });
457
- });
458
- }
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_timeoutManager = require("./timeoutManager.cjs");
3
+ const require_utils = require("./utils.cjs");
4
+ const require_environmentManager = require("./environmentManager.cjs");
5
+ const require_subscribable = require("./subscribable.cjs");
6
+ const require_focusManager = require("./focusManager.cjs");
7
+ const require_notifyManager = require("./notifyManager.cjs");
8
+ const require_query = require("./query.cjs");
9
+ //#region src/queryObserver.ts
10
+ var QueryObserver = class extends require_subscribable.Subscribable {
11
+ #client;
12
+ #currentQuery = void 0;
13
+ #currentQueryInitialState = void 0;
14
+ #currentResult = void 0;
15
+ #currentResultState;
16
+ #currentResultOptions;
17
+ #selectError;
18
+ #selectFn;
19
+ #selectResult;
20
+ #lastQueryWithDefinedData;
21
+ #staleTimeoutId;
22
+ #refetchIntervalId;
23
+ #currentRefetchInterval;
24
+ #trackedProps = /* @__PURE__ */ new Set();
25
+ constructor(client, options) {
26
+ super();
27
+ this.options = options;
28
+ this.#client = client;
29
+ this.#selectError = null;
30
+ this.bindMethods();
31
+ this.setOptions(options);
32
+ }
33
+ bindMethods() {
34
+ this.refetch = this.refetch.bind(this);
35
+ }
36
+ onSubscribe() {
37
+ if (this.listeners.size === 1) {
38
+ this.#currentQuery.addObserver(this);
39
+ if (shouldFetchOnMount(this.#currentQuery, this.options)) this.#executeFetch();
40
+ else this.updateResult();
41
+ this.#updateTimers();
42
+ }
43
+ }
44
+ onUnsubscribe() {
45
+ if (!this.hasListeners()) this.destroy();
46
+ }
47
+ shouldFetchOnReconnect() {
48
+ return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnReconnect);
49
+ }
50
+ shouldFetchOnWindowFocus() {
51
+ return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
52
+ }
53
+ destroy() {
54
+ this.listeners = /* @__PURE__ */ new Set();
55
+ this.#clearStaleTimeout();
56
+ this.#clearRefetchInterval();
57
+ this.#currentQuery.removeObserver(this);
58
+ }
59
+ setOptions(options) {
60
+ const prevOptions = this.options;
61
+ const prevQuery = this.#currentQuery;
62
+ this.options = this.#client.defaultQueryOptions(options);
63
+ if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof require_utils.resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== "boolean") throw new Error("Expected enabled to be a boolean or a callback that returns a boolean");
64
+ this.#updateQuery();
65
+ this.#currentQuery.setOptions(this.options);
66
+ if (prevOptions._defaulted && !require_utils.shallowEqualObjects(this.options, prevOptions)) this.#client.getQueryCache().notify({
67
+ type: "observerOptionsUpdated",
68
+ query: this.#currentQuery,
69
+ observer: this
70
+ });
71
+ const mounted = this.hasListeners();
72
+ if (mounted && shouldFetchOptionally(this.#currentQuery, prevQuery, this.options, prevOptions)) this.#executeFetch();
73
+ this.updateResult();
74
+ if (mounted && (this.#currentQuery !== prevQuery || require_utils.resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== require_utils.resolveQueryBoolean(prevOptions.enabled, this.#currentQuery) || require_utils.resolveStaleTime(this.options.staleTime, this.#currentQuery) !== require_utils.resolveStaleTime(prevOptions.staleTime, this.#currentQuery))) this.#updateStaleTimeout();
75
+ const nextRefetchInterval = this.#computeRefetchInterval();
76
+ if (mounted && (this.#currentQuery !== prevQuery || require_utils.resolveQueryBoolean(this.options.enabled, this.#currentQuery) !== require_utils.resolveQueryBoolean(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) this.#updateRefetchInterval(nextRefetchInterval);
77
+ }
78
+ getOptimisticResult(options) {
79
+ const query = this.#client.getQueryCache().build(this.#client, options);
80
+ const result = this.createResult(query, options);
81
+ if (shouldAssignObserverCurrentProperties(this, result)) {
82
+ this.#currentResult = result;
83
+ this.#currentResultOptions = this.options;
84
+ this.#currentResultState = this.#currentQuery.state;
85
+ }
86
+ return result;
87
+ }
88
+ getCurrentResult() {
89
+ return this.#currentResult;
90
+ }
91
+ trackResult(result, onPropTracked) {
92
+ return new Proxy(result, { get: (target, key) => {
93
+ this.trackProp(key);
94
+ onPropTracked?.(key);
95
+ return Reflect.get(target, key);
96
+ } });
97
+ }
98
+ trackProp(key) {
99
+ this.#trackedProps.add(key);
100
+ }
101
+ getCurrentQuery() {
102
+ return this.#currentQuery;
103
+ }
104
+ refetch({ ...options } = {}) {
105
+ return this.fetch({ ...options });
106
+ }
107
+ fetchOptimistic(options) {
108
+ const defaultedOptions = this.#client.defaultQueryOptions(options);
109
+ const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
110
+ let unsubscribe = () => {};
111
+ let resolveEarly;
112
+ const cachePromise = new Promise((resolve) => {
113
+ resolveEarly = resolve;
114
+ unsubscribe = this.#client.getQueryCache().subscribe((event) => {
115
+ if (event.type === "updated" && event.query.queryHash === query.queryHash && query.state.data !== void 0) {
116
+ unsubscribe();
117
+ resolve(this.createResult(query, defaultedOptions));
118
+ }
119
+ });
120
+ });
121
+ return Promise.race([query.fetch().then(() => {
122
+ const result = this.createResult(query, defaultedOptions);
123
+ resolveEarly?.(result);
124
+ return result;
125
+ }).finally(() => {
126
+ unsubscribe();
127
+ }), cachePromise]);
128
+ }
129
+ fetch(fetchOptions) {
130
+ return this.#executeFetch({
131
+ ...fetchOptions,
132
+ cancelRefetch: fetchOptions.cancelRefetch ?? true
133
+ }).then(() => {
134
+ this.updateResult();
135
+ return this.#currentResult;
136
+ });
137
+ }
138
+ #executeFetch(fetchOptions) {
139
+ this.#updateQuery();
140
+ let promise = this.#currentQuery.fetch(this.options, fetchOptions);
141
+ if (!fetchOptions?.throwOnError) promise = promise.catch(require_utils.noop);
142
+ return promise;
143
+ }
144
+ #updateStaleTimeout() {
145
+ this.#clearStaleTimeout();
146
+ const staleTime = require_utils.resolveStaleTime(this.options.staleTime, this.#currentQuery);
147
+ if (require_environmentManager.environmentManager.isServer() || this.#currentResult.isStale || !require_utils.isValidTimeout(staleTime)) return;
148
+ const timeout = require_utils.timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime) + 1;
149
+ this.#staleTimeoutId = require_timeoutManager.timeoutManager.setTimeout(() => {
150
+ if (!this.#currentResult.isStale) this.updateResult();
151
+ }, timeout);
152
+ }
153
+ #computeRefetchInterval() {
154
+ return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
155
+ }
156
+ #updateRefetchInterval(nextInterval) {
157
+ this.#clearRefetchInterval();
158
+ this.#currentRefetchInterval = nextInterval;
159
+ if (require_environmentManager.environmentManager.isServer() || require_utils.resolveQueryBoolean(this.options.enabled, this.#currentQuery) === false || !require_utils.isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) return;
160
+ this.#refetchIntervalId = require_timeoutManager.timeoutManager.setInterval(() => {
161
+ if (this.options.refetchIntervalInBackground || require_focusManager.focusManager.isFocused()) this.#executeFetch();
162
+ }, this.#currentRefetchInterval);
163
+ }
164
+ #updateTimers() {
165
+ this.#updateStaleTimeout();
166
+ this.#updateRefetchInterval(this.#computeRefetchInterval());
167
+ }
168
+ #clearStaleTimeout() {
169
+ if (this.#staleTimeoutId !== void 0) {
170
+ require_timeoutManager.timeoutManager.clearTimeout(this.#staleTimeoutId);
171
+ this.#staleTimeoutId = void 0;
172
+ }
173
+ }
174
+ #clearRefetchInterval() {
175
+ if (this.#refetchIntervalId !== void 0) {
176
+ require_timeoutManager.timeoutManager.clearInterval(this.#refetchIntervalId);
177
+ this.#refetchIntervalId = void 0;
178
+ }
179
+ }
180
+ createResult(query, options) {
181
+ const prevQuery = this.#currentQuery;
182
+ const prevOptions = this.options;
183
+ const prevResult = this.#currentResult;
184
+ const prevResultState = this.#currentResultState;
185
+ const prevResultOptions = this.#currentResultOptions;
186
+ const queryInitialState = query !== prevQuery ? query.state : this.#currentQueryInitialState;
187
+ const { state } = query;
188
+ let newState = { ...state };
189
+ let isPlaceholderData = false;
190
+ let data;
191
+ if (options._optimisticResults) {
192
+ const mounted = this.hasListeners();
193
+ const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
194
+ const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
195
+ if (fetchOnMount || fetchOptionally) newState = {
196
+ ...newState,
197
+ ...require_query.fetchState(state.data, query.options)
198
+ };
199
+ if (options._optimisticResults === "isRestoring") newState.fetchStatus = "idle";
200
+ }
201
+ let { error, errorUpdatedAt, status } = newState;
202
+ data = newState.data;
203
+ let skipSelect = false;
204
+ if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
205
+ let placeholderData;
206
+ if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
207
+ placeholderData = prevResult.data;
208
+ skipSelect = true;
209
+ } else placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
210
+ if (placeholderData !== void 0) {
211
+ status = "success";
212
+ data = require_utils.replaceData(prevResult?.data, placeholderData, options);
213
+ isPlaceholderData = true;
214
+ }
215
+ }
216
+ if (options.select && data !== void 0 && !skipSelect) {
217
+ if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) data = this.#selectResult;
218
+ else try {
219
+ this.#selectFn = options.select;
220
+ data = options.select(data);
221
+ data = require_utils.replaceData(prevResult?.data, data, options);
222
+ this.#selectResult = data;
223
+ this.#selectError = null;
224
+ } catch (selectError) {
225
+ this.#selectError = selectError;
226
+ }
227
+ } else if (data === void 0) this.#selectError = null;
228
+ if (this.#selectError) {
229
+ error = this.#selectError;
230
+ data = this.#selectResult;
231
+ errorUpdatedAt = Date.now();
232
+ status = "error";
233
+ isPlaceholderData = false;
234
+ }
235
+ const isFetching = newState.fetchStatus === "fetching";
236
+ const isPending = status === "pending";
237
+ const isError = status === "error";
238
+ const isLoading = isPending && isFetching;
239
+ const hasData = data !== void 0;
240
+ return {
241
+ status,
242
+ fetchStatus: newState.fetchStatus,
243
+ isPending,
244
+ isSuccess: status === "success",
245
+ isError,
246
+ isInitialLoading: isLoading,
247
+ isLoading,
248
+ data,
249
+ dataUpdatedAt: newState.dataUpdatedAt,
250
+ error,
251
+ errorUpdatedAt,
252
+ failureCount: newState.fetchFailureCount,
253
+ failureReason: newState.fetchFailureReason,
254
+ errorUpdateCount: newState.errorUpdateCount,
255
+ isFetched: query.isFetched(),
256
+ isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
257
+ isFetching,
258
+ isRefetching: isFetching && !isPending,
259
+ isLoadingError: isError && !hasData,
260
+ isPaused: newState.fetchStatus === "paused",
261
+ isPlaceholderData,
262
+ isRefetchError: isError && hasData,
263
+ isStale: isStale(query, options),
264
+ refetch: this.refetch,
265
+ isEnabled: require_utils.resolveQueryBoolean(options.enabled, query) !== false
266
+ };
267
+ }
268
+ updateResult() {
269
+ const prevResult = this.#currentResult;
270
+ const nextResult = this.createResult(this.#currentQuery, this.options);
271
+ this.#currentResultState = this.#currentQuery.state;
272
+ this.#currentResultOptions = this.options;
273
+ if (this.#currentResultState.data !== void 0) this.#lastQueryWithDefinedData = this.#currentQuery;
274
+ if (require_utils.shallowEqualObjects(nextResult, prevResult)) return;
275
+ this.#currentResult = nextResult;
276
+ const shouldNotifyListeners = () => {
277
+ if (!prevResult) return true;
278
+ const { notifyOnChangeProps } = this.options;
279
+ const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
280
+ if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) return true;
281
+ const includedProps = new Set(notifyOnChangePropsValue ?? this.#trackedProps);
282
+ if (this.options.throwOnError) includedProps.add("error");
283
+ return Object.keys(this.#currentResult).some((key) => {
284
+ const typedKey = key;
285
+ return this.#currentResult[typedKey] !== prevResult[typedKey] && includedProps.has(typedKey);
286
+ });
287
+ };
288
+ this.#notify({ listeners: shouldNotifyListeners() });
289
+ }
290
+ #updateQuery() {
291
+ const query = this.#client.getQueryCache().build(this.#client, this.options);
292
+ if (query === this.#currentQuery) return;
293
+ const prevQuery = this.#currentQuery;
294
+ this.#currentQuery = query;
295
+ this.#currentQueryInitialState = query.state;
296
+ if (this.hasListeners()) {
297
+ prevQuery?.removeObserver(this);
298
+ query.addObserver(this);
299
+ }
300
+ }
301
+ onQueryUpdate() {
302
+ this.updateResult();
303
+ if (this.hasListeners()) this.#updateTimers();
304
+ }
305
+ #notify(notifyOptions) {
306
+ require_notifyManager.notifyManager.batch(() => {
307
+ if (notifyOptions.listeners) this.listeners.forEach((listener) => {
308
+ listener(this.#currentResult);
309
+ });
310
+ this.#client.getQueryCache().notify({
311
+ query: this.#currentQuery,
312
+ type: "observerResultsUpdated"
313
+ });
314
+ });
315
+ }
459
316
  };
460
317
  function shouldLoadOnMount(query, options) {
461
- return (0, import_utils.resolveQueryBoolean)(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && (0, import_utils.resolveQueryBoolean)(options.retryOnMount, query) === false);
318
+ return require_utils.resolveQueryBoolean(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && require_utils.resolveQueryBoolean(options.retryOnMount, query) === false);
462
319
  }
463
320
  function shouldFetchOnMount(query, options) {
464
- return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
321
+ return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
465
322
  }
466
323
  function shouldFetchOn(query, options, field) {
467
- if ((0, import_utils.resolveQueryBoolean)(options.enabled, query) !== false && (0, import_utils.resolveStaleTime)(options.staleTime, query) !== "static") {
468
- const value = typeof field === "function" ? field(query) : field;
469
- return value === "always" || value !== false && isStale(query, options);
470
- }
471
- return false;
324
+ if (require_utils.resolveQueryBoolean(options.enabled, query) !== false && require_utils.resolveStaleTime(options.staleTime, query) !== "static") {
325
+ const value = typeof field === "function" ? field(query) : field;
326
+ return value === "always" || value !== false && isStale(query, options);
327
+ }
328
+ return false;
472
329
  }
473
330
  function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
474
- return (query !== prevQuery || (0, import_utils.resolveQueryBoolean)(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
331
+ return (query !== prevQuery || require_utils.resolveQueryBoolean(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
475
332
  }
476
333
  function isStale(query, options) {
477
- return (0, import_utils.resolveQueryBoolean)(options.enabled, query) !== false && query.isStaleByTime((0, import_utils.resolveStaleTime)(options.staleTime, query));
334
+ return require_utils.resolveQueryBoolean(options.enabled, query) !== false && query.isStaleByTime(require_utils.resolveStaleTime(options.staleTime, query));
478
335
  }
479
336
  function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
480
- if (!(0, import_utils.shallowEqualObjects)(observer.getCurrentResult(), optimisticResult)) {
481
- return true;
482
- }
483
- return false;
337
+ if (!require_utils.shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) return true;
338
+ return false;
484
339
  }
485
- // Annotate the CommonJS export names for ESM import in node:
486
- 0 && (module.exports = {
487
- QueryObserver
488
- });
340
+ //#endregion
341
+ exports.QueryObserver = QueryObserver;
342
+
489
343
  //# sourceMappingURL=queryObserver.cjs.map