@tanstack/query-core 5.101.4 → 5.102.1

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