@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,480 +1,415 @@
1
- import {
2
- __privateAdd,
3
- __privateGet,
4
- __privateMethod,
5
- __privateSet
6
- } from "./chunk-PXG64RU4.js";
7
-
8
- // src/query.ts
9
- import {
10
- ensureQueryFn,
11
- noop,
12
- replaceData,
13
- resolveQueryBoolean,
14
- resolveStaleTime,
15
- skipToken,
16
- timeUntilStale
17
- } from "./utils.js";
1
+ import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, r as _assertClassBrand, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-CV7wyte-.js";
2
+ import { ensureQueryFn, noop, replaceData, resolveQueryBoolean, resolveStaleTime, skipToken, timeUntilStale } from "./utils.js";
18
3
  import { notifyManager } from "./notifyManager.js";
19
4
  import { CancelledError, canFetch, createRetryer } from "./retryer.js";
20
5
  import { Removable } from "./removable.js";
21
6
  import { infiniteQueryBehavior } from "./infiniteQueryBehavior.js";
22
- var _queryType, _initialState, _revertState, _cache, _client, _retryer, _defaultOptions, _abortSignalConsumed, _Query_instances, isInitialPausedFetch_fn, dispatch_fn;
7
+ import { t as _classPrivateMethodInitSpec } from "./classPrivateMethodInitSpec-CBwa_Y7C.js";
8
+ //#region src/query.ts
9
+ var _queryType = /* @__PURE__ */ new WeakMap();
10
+ var _initialState = /* @__PURE__ */ new WeakMap();
11
+ var _revertState = /* @__PURE__ */ new WeakMap();
12
+ var _cache = /* @__PURE__ */ new WeakMap();
13
+ var _client = /* @__PURE__ */ new WeakMap();
14
+ var _retryer = /* @__PURE__ */ new WeakMap();
15
+ var _defaultOptions = /* @__PURE__ */ new WeakMap();
16
+ var _abortSignalConsumed = /* @__PURE__ */ new WeakMap();
17
+ var _Query_brand = /* @__PURE__ */ new WeakSet();
23
18
  var Query = class extends Removable {
24
- constructor(config) {
25
- super();
26
- __privateAdd(this, _Query_instances);
27
- __privateAdd(this, _queryType);
28
- __privateAdd(this, _initialState);
29
- __privateAdd(this, _revertState);
30
- __privateAdd(this, _cache);
31
- __privateAdd(this, _client);
32
- __privateAdd(this, _retryer);
33
- __privateAdd(this, _defaultOptions);
34
- __privateAdd(this, _abortSignalConsumed);
35
- __privateSet(this, _abortSignalConsumed, false);
36
- __privateSet(this, _defaultOptions, config.defaultOptions);
37
- this.setOptions(config.options);
38
- this.observers = [];
39
- __privateSet(this, _client, config.client);
40
- __privateSet(this, _cache, __privateGet(this, _client).getQueryCache());
41
- this.queryKey = config.queryKey;
42
- this.queryHash = config.queryHash;
43
- __privateSet(this, _initialState, getDefaultState(this.options));
44
- this.state = config.state ?? __privateGet(this, _initialState);
45
- this.scheduleGc();
46
- }
47
- get meta() {
48
- return this.options.meta;
49
- }
50
- get queryType() {
51
- return __privateGet(this, _queryType);
52
- }
53
- get promise() {
54
- var _a;
55
- return (_a = __privateGet(this, _retryer)) == null ? void 0 : _a.promise;
56
- }
57
- setOptions(options) {
58
- this.options = { ...__privateGet(this, _defaultOptions), ...options };
59
- if (options == null ? void 0 : options._type) {
60
- __privateSet(this, _queryType, options._type);
61
- }
62
- this.updateGcTime(this.options.gcTime);
63
- if (this.state && this.state.data === void 0) {
64
- const defaultState = getDefaultState(this.options);
65
- if (defaultState.data !== void 0) {
66
- this.setState(
67
- successState(defaultState.data, defaultState.dataUpdatedAt)
68
- );
69
- __privateSet(this, _initialState, defaultState);
70
- }
71
- }
72
- }
73
- optionalRemove() {
74
- if (!this.observers.length && this.state.fetchStatus === "idle") {
75
- __privateGet(this, _cache).remove(this);
76
- }
77
- }
78
- setData(newData, options) {
79
- const data = replaceData(this.state.data, newData, this.options);
80
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, {
81
- data,
82
- type: "success",
83
- dataUpdatedAt: options == null ? void 0 : options.updatedAt,
84
- manual: options == null ? void 0 : options.manual
85
- });
86
- return data;
87
- }
88
- setState(state) {
89
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "setState", state });
90
- }
91
- cancel(options) {
92
- var _a, _b;
93
- const promise = (_a = __privateGet(this, _retryer)) == null ? void 0 : _a.promise;
94
- (_b = __privateGet(this, _retryer)) == null ? void 0 : _b.cancel(options);
95
- return promise ? promise.then(noop).catch(noop) : Promise.resolve();
96
- }
97
- destroy() {
98
- super.destroy();
99
- this.cancel({ silent: true });
100
- }
101
- get resetState() {
102
- return __privateGet(this, _initialState);
103
- }
104
- reset() {
105
- this.destroy();
106
- this.setState(this.resetState);
107
- }
108
- isActive() {
109
- return this.observers.some(
110
- (observer) => resolveQueryBoolean(observer.options.enabled, this) !== false
111
- );
112
- }
113
- isDisabled() {
114
- if (this.getObserversCount() > 0) {
115
- return !this.isActive();
116
- }
117
- return this.options.queryFn === skipToken || !this.isFetched();
118
- }
119
- isFetched() {
120
- return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
121
- }
122
- isStatic() {
123
- if (this.getObserversCount() > 0) {
124
- return this.observers.some(
125
- (observer) => resolveStaleTime(observer.options.staleTime, this) === "static"
126
- );
127
- }
128
- return false;
129
- }
130
- isStale() {
131
- if (this.getObserversCount() > 0) {
132
- return this.observers.some(
133
- (observer) => observer.getCurrentResult().isStale
134
- );
135
- }
136
- return this.state.data === void 0 || this.state.isInvalidated;
137
- }
138
- isStaleByTime(staleTime = 0) {
139
- if (this.state.data === void 0) {
140
- return true;
141
- }
142
- if (staleTime === "static") {
143
- return false;
144
- }
145
- if (this.state.isInvalidated) {
146
- return true;
147
- }
148
- return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
149
- }
150
- onFocus() {
151
- var _a;
152
- const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
153
- observer == null ? void 0 : observer.refetch({ cancelRefetch: false });
154
- (_a = __privateGet(this, _retryer)) == null ? void 0 : _a.continue();
155
- }
156
- onOnline() {
157
- var _a;
158
- const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
159
- observer == null ? void 0 : observer.refetch({ cancelRefetch: false });
160
- (_a = __privateGet(this, _retryer)) == null ? void 0 : _a.continue();
161
- }
162
- addObserver(observer) {
163
- if (!this.observers.includes(observer)) {
164
- this.observers.push(observer);
165
- this.clearGcTimeout();
166
- __privateGet(this, _cache).notify({ type: "observerAdded", query: this, observer });
167
- }
168
- }
169
- removeObserver(observer) {
170
- if (this.observers.includes(observer)) {
171
- this.observers = this.observers.filter((x) => x !== observer);
172
- if (!this.observers.length) {
173
- if (__privateGet(this, _retryer)) {
174
- if (__privateGet(this, _abortSignalConsumed) || __privateMethod(this, _Query_instances, isInitialPausedFetch_fn).call(this)) {
175
- __privateGet(this, _retryer).cancel({ revert: true });
176
- } else {
177
- __privateGet(this, _retryer).cancelRetry();
178
- }
179
- }
180
- this.scheduleGc();
181
- }
182
- __privateGet(this, _cache).notify({ type: "observerRemoved", query: this, observer });
183
- }
184
- }
185
- getObserversCount() {
186
- return this.observers.length;
187
- }
188
- invalidate() {
189
- if (!this.state.isInvalidated) {
190
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "invalidate" });
191
- }
192
- }
193
- async fetch(options, fetchOptions) {
194
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
195
- if (this.state.fetchStatus !== "idle" && // If the promise in the retryer is already rejected, we have to definitely
196
- // re-start the fetch; there is a chance that the query is still in a
197
- // pending state when that happens
198
- ((_a = __privateGet(this, _retryer)) == null ? void 0 : _a.status()) !== "rejected") {
199
- if (this.state.data !== void 0 && (fetchOptions == null ? void 0 : fetchOptions.cancelRefetch)) {
200
- this.cancel({ silent: true });
201
- } else if (__privateGet(this, _retryer)) {
202
- __privateGet(this, _retryer).continueRetry();
203
- return __privateGet(this, _retryer).promise;
204
- }
205
- }
206
- if (options) {
207
- this.setOptions(options);
208
- }
209
- if (!this.options.queryFn) {
210
- const observer = this.observers.find((x) => x.options.queryFn);
211
- if (observer) {
212
- this.setOptions(observer.options);
213
- }
214
- }
215
- if (process.env.NODE_ENV !== "production") {
216
- if (!Array.isArray(this.options.queryKey)) {
217
- console.error(
218
- `As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`
219
- );
220
- }
221
- }
222
- const abortController = new AbortController();
223
- const addSignalProperty = (object) => {
224
- Object.defineProperty(object, "signal", {
225
- enumerable: true,
226
- get: () => {
227
- __privateSet(this, _abortSignalConsumed, true);
228
- return abortController.signal;
229
- }
230
- });
231
- };
232
- const fetchFn = () => {
233
- const queryFn = ensureQueryFn(this.options, fetchOptions);
234
- const createQueryFnContext = () => {
235
- const queryFnContext2 = {
236
- client: __privateGet(this, _client),
237
- queryKey: this.queryKey,
238
- meta: this.meta
239
- };
240
- addSignalProperty(queryFnContext2);
241
- return queryFnContext2;
242
- };
243
- const queryFnContext = createQueryFnContext();
244
- __privateSet(this, _abortSignalConsumed, false);
245
- if (this.options.persister) {
246
- return this.options.persister(
247
- queryFn,
248
- queryFnContext,
249
- this
250
- );
251
- }
252
- return queryFn(queryFnContext);
253
- };
254
- const createFetchContext = () => {
255
- const context2 = {
256
- fetchOptions,
257
- options: this.options,
258
- queryKey: this.queryKey,
259
- client: __privateGet(this, _client),
260
- state: this.state,
261
- fetchFn
262
- };
263
- addSignalProperty(context2);
264
- return context2;
265
- };
266
- const context = createFetchContext();
267
- const behavior = __privateGet(this, _queryType) === "infinite" ? infiniteQueryBehavior(
268
- this.options.pages
269
- ) : this.options.behavior;
270
- behavior == null ? void 0 : behavior.onFetch(context, this);
271
- __privateSet(this, _revertState, this.state);
272
- if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((_b = context.fetchOptions) == null ? void 0 : _b.meta)) {
273
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "fetch", meta: (_c = context.fetchOptions) == null ? void 0 : _c.meta });
274
- }
275
- __privateSet(this, _retryer, createRetryer({
276
- initialPromise: fetchOptions == null ? void 0 : fetchOptions.initialPromise,
277
- fn: context.fetchFn,
278
- onCancel: (error) => {
279
- if (error instanceof CancelledError && error.revert) {
280
- this.setState({
281
- ...__privateGet(this, _revertState),
282
- fetchStatus: "idle"
283
- });
284
- }
285
- abortController.abort();
286
- },
287
- onFail: (failureCount, error) => {
288
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "failed", failureCount, error });
289
- },
290
- onPause: () => {
291
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "pause" });
292
- },
293
- onContinue: () => {
294
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, { type: "continue" });
295
- },
296
- retry: context.options.retry,
297
- retryDelay: context.options.retryDelay,
298
- networkMode: context.options.networkMode,
299
- canRun: () => true
300
- }));
301
- try {
302
- const data = await __privateGet(this, _retryer).start();
303
- if (data === void 0) {
304
- if (process.env.NODE_ENV !== "production") {
305
- console.error(
306
- `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
307
- );
308
- }
309
- throw new Error(`${this.queryHash} data is undefined`);
310
- }
311
- this.setData(data);
312
- (_e = (_d = __privateGet(this, _cache).config).onSuccess) == null ? void 0 : _e.call(_d, data, this);
313
- (_g = (_f = __privateGet(this, _cache).config).onSettled) == null ? void 0 : _g.call(
314
- _f,
315
- data,
316
- this.state.error,
317
- this
318
- );
319
- return data;
320
- } catch (error) {
321
- if (error instanceof CancelledError) {
322
- if (error.silent) {
323
- return __privateGet(this, _retryer).promise;
324
- } else if (error.revert) {
325
- if (this.state.data === void 0) {
326
- throw error;
327
- }
328
- return this.state.data;
329
- }
330
- }
331
- __privateMethod(this, _Query_instances, dispatch_fn).call(this, {
332
- type: "error",
333
- error
334
- });
335
- (_i = (_h = __privateGet(this, _cache).config).onError) == null ? void 0 : _i.call(
336
- _h,
337
- error,
338
- this
339
- );
340
- (_k = (_j = __privateGet(this, _cache).config).onSettled) == null ? void 0 : _k.call(
341
- _j,
342
- this.state.data,
343
- error,
344
- this
345
- );
346
- throw error;
347
- } finally {
348
- this.scheduleGc();
349
- }
350
- }
351
- };
352
- _queryType = new WeakMap();
353
- _initialState = new WeakMap();
354
- _revertState = new WeakMap();
355
- _cache = new WeakMap();
356
- _client = new WeakMap();
357
- _retryer = new WeakMap();
358
- _defaultOptions = new WeakMap();
359
- _abortSignalConsumed = new WeakMap();
360
- _Query_instances = new WeakSet();
361
- isInitialPausedFetch_fn = function() {
362
- return this.state.fetchStatus === "paused" && this.state.status === "pending";
363
- };
364
- dispatch_fn = function(action) {
365
- const reducer = (state) => {
366
- switch (action.type) {
367
- case "failed":
368
- return {
369
- ...state,
370
- fetchFailureCount: action.failureCount,
371
- fetchFailureReason: action.error
372
- };
373
- case "pause":
374
- return {
375
- ...state,
376
- fetchStatus: "paused"
377
- };
378
- case "continue":
379
- return {
380
- ...state,
381
- fetchStatus: "fetching"
382
- };
383
- case "fetch":
384
- return {
385
- ...state,
386
- ...fetchState(state.data, this.options),
387
- fetchMeta: action.meta ?? null
388
- };
389
- case "success":
390
- const newState = {
391
- ...state,
392
- ...successState(action.data, action.dataUpdatedAt),
393
- dataUpdateCount: state.dataUpdateCount + 1,
394
- ...!action.manual && {
395
- fetchStatus: "idle",
396
- fetchFailureCount: 0,
397
- fetchFailureReason: null
398
- }
399
- };
400
- __privateSet(this, _revertState, action.manual ? newState : void 0);
401
- return newState;
402
- case "error":
403
- const error = action.error;
404
- return {
405
- ...state,
406
- error,
407
- errorUpdateCount: state.errorUpdateCount + 1,
408
- errorUpdatedAt: Date.now(),
409
- fetchFailureCount: state.fetchFailureCount + 1,
410
- fetchFailureReason: error,
411
- fetchStatus: "idle",
412
- status: "error",
413
- // flag existing data as invalidated if we get a background error
414
- // note that "no data" always means stale so we can set unconditionally here
415
- isInvalidated: true
416
- };
417
- case "invalidate":
418
- return {
419
- ...state,
420
- isInvalidated: true
421
- };
422
- case "setState":
423
- return {
424
- ...state,
425
- ...action.state
426
- };
427
- }
428
- };
429
- this.state = reducer(this.state);
430
- notifyManager.batch(() => {
431
- this.observers.forEach((observer) => {
432
- observer.onQueryUpdate();
433
- });
434
- __privateGet(this, _cache).notify({ query: this, type: "updated", action });
435
- });
19
+ constructor(config) {
20
+ super();
21
+ _classPrivateMethodInitSpec(this, _Query_brand);
22
+ _classPrivateFieldInitSpec(this, _queryType, void 0);
23
+ _classPrivateFieldInitSpec(this, _initialState, void 0);
24
+ _classPrivateFieldInitSpec(this, _revertState, void 0);
25
+ _classPrivateFieldInitSpec(this, _cache, void 0);
26
+ _classPrivateFieldInitSpec(this, _client, void 0);
27
+ _classPrivateFieldInitSpec(this, _retryer, void 0);
28
+ _classPrivateFieldInitSpec(this, _defaultOptions, void 0);
29
+ _classPrivateFieldInitSpec(this, _abortSignalConsumed, void 0);
30
+ _classPrivateFieldSet2(_abortSignalConsumed, this, false);
31
+ _classPrivateFieldSet2(_defaultOptions, this, config.defaultOptions);
32
+ this.setOptions(config.options);
33
+ this.observers = [];
34
+ _classPrivateFieldSet2(_client, this, config.client);
35
+ _classPrivateFieldSet2(_cache, this, _classPrivateFieldGet2(_client, this).getQueryCache());
36
+ this.queryKey = config.queryKey;
37
+ this.queryHash = config.queryHash;
38
+ _classPrivateFieldSet2(_initialState, this, getDefaultState(this.options));
39
+ this.state = config.state ?? _classPrivateFieldGet2(_initialState, this);
40
+ this.scheduleGc();
41
+ }
42
+ get meta() {
43
+ return this.options.meta;
44
+ }
45
+ get queryType() {
46
+ return _classPrivateFieldGet2(_queryType, this);
47
+ }
48
+ get promise() {
49
+ var _classPrivateFieldGet2$1;
50
+ return (_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.promise;
51
+ }
52
+ setOptions(options) {
53
+ this.options = {
54
+ ..._classPrivateFieldGet2(_defaultOptions, this),
55
+ ...options
56
+ };
57
+ if (options === null || options === void 0 ? void 0 : options._type) _classPrivateFieldSet2(_queryType, this, options._type);
58
+ this.updateGcTime(this.options.gcTime);
59
+ if (this.state && this.state.data === void 0) {
60
+ const defaultState = getDefaultState(this.options);
61
+ if (defaultState.data !== void 0) {
62
+ this.setState(successState(defaultState.data, defaultState.dataUpdatedAt));
63
+ _classPrivateFieldSet2(_initialState, this, defaultState);
64
+ }
65
+ }
66
+ }
67
+ optionalRemove() {
68
+ if (!this.observers.length && this.state.fetchStatus === "idle") _classPrivateFieldGet2(_cache, this).remove(this);
69
+ }
70
+ setData(newData, options) {
71
+ const data = replaceData(this.state.data, newData, this.options);
72
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
73
+ data,
74
+ type: "success",
75
+ dataUpdatedAt: options === null || options === void 0 ? void 0 : options.updatedAt,
76
+ manual: options === null || options === void 0 ? void 0 : options.manual
77
+ });
78
+ return data;
79
+ }
80
+ setState(state) {
81
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
82
+ type: "setState",
83
+ state
84
+ });
85
+ }
86
+ cancel(options) {
87
+ var _classPrivateFieldGet3, _classPrivateFieldGet4;
88
+ const promise = (_classPrivateFieldGet3 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.promise;
89
+ (_classPrivateFieldGet4 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.cancel(options);
90
+ return promise ? promise.then(noop).catch(noop) : Promise.resolve();
91
+ }
92
+ destroy() {
93
+ super.destroy();
94
+ this.cancel({ silent: true });
95
+ }
96
+ get resetState() {
97
+ return _classPrivateFieldGet2(_initialState, this);
98
+ }
99
+ reset() {
100
+ this.destroy();
101
+ this.setState(this.resetState);
102
+ }
103
+ isActive() {
104
+ return this.observers.some((observer) => resolveQueryBoolean(observer.options.enabled, this) !== false);
105
+ }
106
+ isDisabled() {
107
+ if (this.getObserversCount() > 0) return !this.isActive();
108
+ return this.options.queryFn === skipToken || !this.isFetched();
109
+ }
110
+ isFetched() {
111
+ return this.state.dataUpdateCount + this.state.errorUpdateCount > 0;
112
+ }
113
+ isStatic() {
114
+ if (this.getObserversCount() > 0) return this.observers.some((observer) => resolveStaleTime(observer.options.staleTime, this) === "static");
115
+ return false;
116
+ }
117
+ isStale() {
118
+ if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale);
119
+ return this.state.data === void 0 || this.state.isInvalidated;
120
+ }
121
+ isStaleByTime(staleTime = 0) {
122
+ if (this.state.data === void 0) return true;
123
+ if (staleTime === "static") return false;
124
+ if (this.state.isInvalidated) return true;
125
+ return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
126
+ }
127
+ onFocus() {
128
+ var _classPrivateFieldGet5;
129
+ const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
130
+ observer === null || observer === void 0 || observer.refetch({ cancelRefetch: false });
131
+ (_classPrivateFieldGet5 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.continue();
132
+ }
133
+ onOnline() {
134
+ var _classPrivateFieldGet6;
135
+ const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
136
+ observer === null || observer === void 0 || observer.refetch({ cancelRefetch: false });
137
+ (_classPrivateFieldGet6 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.continue();
138
+ }
139
+ addObserver(observer) {
140
+ if (!this.observers.includes(observer)) {
141
+ this.observers.push(observer);
142
+ this.clearGcTimeout();
143
+ _classPrivateFieldGet2(_cache, this).notify({
144
+ type: "observerAdded",
145
+ query: this,
146
+ observer
147
+ });
148
+ }
149
+ }
150
+ removeObserver(observer) {
151
+ const index = this.observers.indexOf(observer);
152
+ if (index !== -1) {
153
+ this.observers.splice(index, 1);
154
+ if (!this.observers.length) {
155
+ if (_classPrivateFieldGet2(_retryer, this)) {
156
+ if (_classPrivateFieldGet2(_abortSignalConsumed, this) || _assertClassBrand(_Query_brand, this, _isInitialPausedFetch).call(this)) _classPrivateFieldGet2(_retryer, this).cancel({ revert: true });
157
+ else _classPrivateFieldGet2(_retryer, this).cancelRetry();
158
+ }
159
+ this.scheduleGc();
160
+ }
161
+ _classPrivateFieldGet2(_cache, this).notify({
162
+ type: "observerRemoved",
163
+ query: this,
164
+ observer
165
+ });
166
+ }
167
+ }
168
+ getObserversCount() {
169
+ return this.observers.length;
170
+ }
171
+ invalidate() {
172
+ if (!this.state.isInvalidated) _assertClassBrand(_Query_brand, this, _dispatch).call(this, { type: "invalidate" });
173
+ }
174
+ async fetch(options, fetchOptions) {
175
+ var _classPrivateFieldGet7, _context$fetchOptions;
176
+ if (this.state.fetchStatus !== "idle" && ((_classPrivateFieldGet7 = _classPrivateFieldGet2(_retryer, this)) === null || _classPrivateFieldGet7 === void 0 ? void 0 : _classPrivateFieldGet7.status()) !== "rejected") {
177
+ if (this.state.data !== void 0 && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.cancelRefetch)) this.cancel({ silent: true });
178
+ else if (_classPrivateFieldGet2(_retryer, this)) {
179
+ _classPrivateFieldGet2(_retryer, this).continueRetry();
180
+ return _classPrivateFieldGet2(_retryer, this).promise;
181
+ }
182
+ }
183
+ if (options) this.setOptions(options);
184
+ if (!this.options.queryFn) {
185
+ const observer = this.observers.find((x) => x.options.queryFn);
186
+ if (observer) this.setOptions(observer.options);
187
+ }
188
+ if (process.env.NODE_ENV !== "production") {
189
+ if (!Array.isArray(this.options.queryKey)) console.error(`As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`);
190
+ }
191
+ const abortController = new AbortController();
192
+ const addSignalProperty = (object) => {
193
+ Object.defineProperty(object, "signal", {
194
+ enumerable: true,
195
+ get: () => {
196
+ _classPrivateFieldSet2(_abortSignalConsumed, this, true);
197
+ return abortController.signal;
198
+ }
199
+ });
200
+ };
201
+ const fetchFn = () => {
202
+ const queryFn = ensureQueryFn(this.options, fetchOptions);
203
+ const createQueryFnContext = () => {
204
+ const queryFnContext = {
205
+ client: _classPrivateFieldGet2(_client, this),
206
+ queryKey: this.queryKey,
207
+ meta: this.meta
208
+ };
209
+ addSignalProperty(queryFnContext);
210
+ return queryFnContext;
211
+ };
212
+ const queryFnContext = createQueryFnContext();
213
+ _classPrivateFieldSet2(_abortSignalConsumed, this, false);
214
+ if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this);
215
+ return queryFn(queryFnContext);
216
+ };
217
+ const createFetchContext = () => {
218
+ const context = {
219
+ fetchOptions,
220
+ options: this.options,
221
+ queryKey: this.queryKey,
222
+ client: _classPrivateFieldGet2(_client, this),
223
+ state: this.state,
224
+ fetchFn
225
+ };
226
+ addSignalProperty(context);
227
+ return context;
228
+ };
229
+ const context = createFetchContext();
230
+ const behavior = _classPrivateFieldGet2(_queryType, this) === "infinite" ? infiniteQueryBehavior(this.options.pages) : this.options.behavior;
231
+ behavior === null || behavior === void 0 || behavior.onFetch(context, this);
232
+ _classPrivateFieldSet2(_revertState, this, this.state);
233
+ if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) === null || _context$fetchOptions === void 0 ? void 0 : _context$fetchOptions.meta)) {
234
+ var _context$fetchOptions2;
235
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
236
+ type: "fetch",
237
+ meta: (_context$fetchOptions2 = context.fetchOptions) === null || _context$fetchOptions2 === void 0 ? void 0 : _context$fetchOptions2.meta
238
+ });
239
+ }
240
+ const retryer = _classPrivateFieldSet2(_retryer, this, createRetryer({
241
+ initialPromise: fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.initialPromise,
242
+ fn: context.fetchFn,
243
+ onCancel: (error) => {
244
+ if (error instanceof CancelledError && error.revert) this.setState({
245
+ ..._classPrivateFieldGet2(_revertState, this),
246
+ fetchStatus: "idle"
247
+ });
248
+ abortController.abort();
249
+ },
250
+ onFail: (failureCount, error) => {
251
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
252
+ type: "failed",
253
+ failureCount,
254
+ error
255
+ });
256
+ },
257
+ onPause: () => {
258
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, { type: "pause" });
259
+ },
260
+ onContinue: () => {
261
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, { type: "continue" });
262
+ },
263
+ retry: context.options.retry,
264
+ retryDelay: context.options.retryDelay,
265
+ networkMode: context.options.networkMode,
266
+ canRun: () => true
267
+ }));
268
+ try {
269
+ var _classPrivateFieldGet8, _classPrivateFieldGet9, _classPrivateFieldGet10, _classPrivateFieldGet11;
270
+ const data = await retryer.start();
271
+ if (data === void 0) {
272
+ if (process.env.NODE_ENV !== "production") console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
273
+ throw new Error(`${this.queryHash} data is undefined`);
274
+ }
275
+ this.setData(data);
276
+ (_classPrivateFieldGet8 = (_classPrivateFieldGet9 = _classPrivateFieldGet2(_cache, this).config).onSuccess) === null || _classPrivateFieldGet8 === void 0 || _classPrivateFieldGet8.call(_classPrivateFieldGet9, data, this);
277
+ (_classPrivateFieldGet10 = (_classPrivateFieldGet11 = _classPrivateFieldGet2(_cache, this).config).onSettled) === null || _classPrivateFieldGet10 === void 0 || _classPrivateFieldGet10.call(_classPrivateFieldGet11, data, this.state.error, this);
278
+ return data;
279
+ } catch (error) {
280
+ var _classPrivateFieldGet12, _classPrivateFieldGet13, _classPrivateFieldGet14, _classPrivateFieldGet15;
281
+ if (error instanceof CancelledError) {
282
+ if (error.silent) return _classPrivateFieldGet2(_retryer, this).promise;
283
+ else if (error.revert) {
284
+ if (this.state.data === void 0) throw error;
285
+ return this.state.data;
286
+ }
287
+ }
288
+ _assertClassBrand(_Query_brand, this, _dispatch).call(this, {
289
+ type: "error",
290
+ error
291
+ });
292
+ (_classPrivateFieldGet12 = (_classPrivateFieldGet13 = _classPrivateFieldGet2(_cache, this).config).onError) === null || _classPrivateFieldGet12 === void 0 || _classPrivateFieldGet12.call(_classPrivateFieldGet13, error, this);
293
+ (_classPrivateFieldGet14 = (_classPrivateFieldGet15 = _classPrivateFieldGet2(_cache, this).config).onSettled) === null || _classPrivateFieldGet14 === void 0 || _classPrivateFieldGet14.call(_classPrivateFieldGet15, this.state.data, error, this);
294
+ throw error;
295
+ } finally {
296
+ if (_classPrivateFieldGet2(_retryer, this) === retryer) _classPrivateFieldSet2(_retryer, this, void 0);
297
+ this.scheduleGc();
298
+ }
299
+ }
436
300
  };
301
+ function _isInitialPausedFetch() {
302
+ return this.state.fetchStatus === "paused" && this.state.status === "pending";
303
+ }
304
+ function _dispatch(action) {
305
+ const reducer = (state) => {
306
+ switch (action.type) {
307
+ case "failed": return {
308
+ ...state,
309
+ fetchFailureCount: action.failureCount,
310
+ fetchFailureReason: action.error
311
+ };
312
+ case "pause": return {
313
+ ...state,
314
+ fetchStatus: "paused"
315
+ };
316
+ case "continue": return {
317
+ ...state,
318
+ fetchStatus: "fetching"
319
+ };
320
+ case "fetch": return {
321
+ ...state,
322
+ ...fetchState(state.data, this.options),
323
+ fetchMeta: action.meta ?? null
324
+ };
325
+ case "success":
326
+ const newState = {
327
+ ...state,
328
+ ...successState(action.data, action.dataUpdatedAt),
329
+ dataUpdateCount: state.dataUpdateCount + 1,
330
+ ...!action.manual && {
331
+ fetchStatus: "idle",
332
+ fetchFailureCount: 0,
333
+ fetchFailureReason: null
334
+ }
335
+ };
336
+ _classPrivateFieldSet2(_revertState, this, action.manual ? newState : void 0);
337
+ return newState;
338
+ case "error":
339
+ const error = action.error;
340
+ return {
341
+ ...state,
342
+ error,
343
+ errorUpdateCount: state.errorUpdateCount + 1,
344
+ errorUpdatedAt: Date.now(),
345
+ fetchFailureCount: state.fetchFailureCount + 1,
346
+ fetchFailureReason: error,
347
+ fetchStatus: "idle",
348
+ status: "error",
349
+ isInvalidated: true
350
+ };
351
+ case "invalidate": return {
352
+ ...state,
353
+ isInvalidated: true
354
+ };
355
+ case "setState": return {
356
+ ...state,
357
+ ...action.state
358
+ };
359
+ }
360
+ };
361
+ this.state = reducer(this.state);
362
+ notifyManager.batch(() => {
363
+ this.observers.slice().forEach((observer) => {
364
+ observer.onQueryUpdate();
365
+ });
366
+ _classPrivateFieldGet2(_cache, this).notify({
367
+ query: this,
368
+ type: "updated",
369
+ action
370
+ });
371
+ });
372
+ }
437
373
  function fetchState(data, options) {
438
- return {
439
- fetchFailureCount: 0,
440
- fetchFailureReason: null,
441
- fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
442
- ...data === void 0 && {
443
- error: null,
444
- status: "pending"
445
- }
446
- };
374
+ return {
375
+ fetchFailureCount: 0,
376
+ fetchFailureReason: null,
377
+ fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
378
+ ...data === void 0 && {
379
+ error: null,
380
+ status: "pending"
381
+ }
382
+ };
447
383
  }
448
384
  function successState(data, dataUpdatedAt) {
449
- return {
450
- data,
451
- dataUpdatedAt: dataUpdatedAt ?? Date.now(),
452
- error: null,
453
- isInvalidated: false,
454
- status: "success"
455
- };
385
+ return {
386
+ data,
387
+ dataUpdatedAt: dataUpdatedAt ?? Date.now(),
388
+ error: null,
389
+ isInvalidated: false,
390
+ status: "success"
391
+ };
456
392
  }
457
393
  function getDefaultState(options) {
458
- const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
459
- const hasData = data !== void 0;
460
- const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
461
- return {
462
- data,
463
- dataUpdateCount: 0,
464
- dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
465
- error: null,
466
- errorUpdateCount: 0,
467
- errorUpdatedAt: 0,
468
- fetchFailureCount: 0,
469
- fetchFailureReason: null,
470
- fetchMeta: null,
471
- isInvalidated: false,
472
- status: hasData ? "success" : "pending",
473
- fetchStatus: "idle"
474
- };
394
+ const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
395
+ const hasData = data !== void 0;
396
+ const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
397
+ return {
398
+ data,
399
+ dataUpdateCount: 0,
400
+ dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
401
+ error: null,
402
+ errorUpdateCount: 0,
403
+ errorUpdatedAt: 0,
404
+ fetchFailureCount: 0,
405
+ fetchFailureReason: null,
406
+ fetchMeta: null,
407
+ isInvalidated: false,
408
+ status: hasData ? "success" : "pending",
409
+ fetchStatus: "idle"
410
+ };
475
411
  }
476
- export {
477
- Query,
478
- fetchState
479
- };
412
+ //#endregion
413
+ export { Query, fetchState };
414
+
480
415
  //# sourceMappingURL=query.js.map