@tanstack/query-core 5.101.4 → 5.102.0

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