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