@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,28 +1,24 @@
1
- import "./chunk-PXG64RU4.js";
2
-
3
- // src/subscribable.ts
1
+ //#region src/subscribable.ts
4
2
  var Subscribable = class {
5
- constructor() {
6
- this.listeners = /* @__PURE__ */ new Set();
7
- this.subscribe = this.subscribe.bind(this);
8
- }
9
- subscribe(listener) {
10
- this.listeners.add(listener);
11
- this.onSubscribe();
12
- return () => {
13
- this.listeners.delete(listener);
14
- this.onUnsubscribe();
15
- };
16
- }
17
- hasListeners() {
18
- return this.listeners.size > 0;
19
- }
20
- onSubscribe() {
21
- }
22
- onUnsubscribe() {
23
- }
24
- };
25
- export {
26
- Subscribable
3
+ constructor() {
4
+ this.listeners = /* @__PURE__ */ new Set();
5
+ this.subscribe = this.subscribe.bind(this);
6
+ }
7
+ subscribe(listener) {
8
+ this.listeners.add(listener);
9
+ this.onSubscribe();
10
+ return () => {
11
+ this.listeners.delete(listener);
12
+ this.onUnsubscribe();
13
+ };
14
+ }
15
+ hasListeners() {
16
+ return this.listeners.size > 0;
17
+ }
18
+ onSubscribe() {}
19
+ onUnsubscribe() {}
27
20
  };
21
+ //#endregion
22
+ export { Subscribable };
23
+
28
24
  //# sourceMappingURL=subscribable.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/subscribable.ts"],"sourcesContent":["export class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";;;AAAO,IAAM,eAAN,MAA+C;AAAA,EAGpD,cAAc;AAFd,SAAU,YAAY,oBAAI,IAAe;AAGvC,SAAK,YAAY,KAAK,UAAU,KAAK,IAAI;AAAA,EAC3C;AAAA,EAEA,UAAU,UAAiC;AACzC,SAAK,UAAU,IAAI,QAAQ;AAE3B,SAAK,YAAY;AAEjB,WAAO,MAAM;AACX,WAAK,UAAU,OAAO,QAAQ;AAC9B,WAAK,cAAc;AAAA,IACrB;AAAA,EACF;AAAA,EAEA,eAAwB;AACtB,WAAO,KAAK,UAAU,OAAO;AAAA,EAC/B;AAAA,EAEU,cAAoB;AAAA,EAE9B;AAAA,EAEU,gBAAsB;AAAA,EAEhC;AACF;","names":[]}
1
+ {"version":3,"file":"subscribable.js","names":[],"sources":["../../src/subscribable.ts"],"sourcesContent":["export class Subscribable<TListener extends Function> {\n protected listeners = new Set<TListener>()\n\n constructor() {\n this.subscribe = this.subscribe.bind(this)\n }\n\n subscribe(listener: TListener): () => void {\n this.listeners.add(listener)\n\n this.onSubscribe()\n\n return () => {\n this.listeners.delete(listener)\n this.onUnsubscribe()\n }\n }\n\n hasListeners(): boolean {\n return this.listeners.size > 0\n }\n\n protected onSubscribe(): void {\n // Do nothing\n }\n\n protected onUnsubscribe(): void {\n // Do nothing\n }\n}\n"],"mappings":";AAAA,IAAa,eAAb,MAAsD;CAGpD,cAAc;EAFd,KAAU,4BAAY,IAAI,IAAe;EAGvC,KAAK,YAAY,KAAK,UAAU,KAAK,IAAI;CAC3C;CAEA,UAAU,UAAiC;EACzC,KAAK,UAAU,IAAI,QAAQ;EAE3B,KAAK,YAAY;EAEjB,aAAa;GACX,KAAK,UAAU,OAAO,QAAQ;GAC9B,KAAK,cAAc;EACrB;CACF;CAEA,eAAwB;EACtB,OAAO,KAAK,UAAU,OAAO;CAC/B;CAEA,cAA8B,CAE9B;CAEA,gBAAgC,CAEhC;AACF"}
@@ -1,111 +1,70 @@
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 __typeError = (msg) => {
7
- throw TypeError(msg);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_classPrivateFieldSet2 = require("./classPrivateFieldSet2-Bo0ZyOIv.cjs");
3
+ //#region src/timeoutManager.ts
4
+ const defaultTimeoutProvider = {
5
+ setTimeout: (callback, delay) => setTimeout(callback, delay),
6
+ clearTimeout: (timeoutId) => clearTimeout(timeoutId),
7
+ setInterval: (callback, delay) => setInterval(callback, delay),
8
+ clearInterval: (intervalId) => clearInterval(intervalId)
8
9
  };
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
23
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
24
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
25
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
26
-
27
- // src/timeoutManager.ts
28
- var timeoutManager_exports = {};
29
- __export(timeoutManager_exports, {
30
- TimeoutManager: () => TimeoutManager,
31
- defaultTimeoutProvider: () => defaultTimeoutProvider,
32
- systemSetTimeoutZero: () => systemSetTimeoutZero,
33
- timeoutManager: () => timeoutManager
34
- });
35
- module.exports = __toCommonJS(timeoutManager_exports);
36
- var defaultTimeoutProvider = {
37
- // We need the wrapper function syntax below instead of direct references to
38
- // global setTimeout etc.
39
- //
40
- // BAD: `setTimeout: setTimeout`
41
- // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
42
- //
43
- // If we use direct references here, then anything that wants to spy on or
44
- // replace the global setTimeout (like tests) won't work since we'll already
45
- // have a hard reference to the original implementation at the time when this
46
- // file was imported.
47
- setTimeout: (callback, delay) => setTimeout(callback, delay),
48
- clearTimeout: (timeoutId) => clearTimeout(timeoutId),
49
- setInterval: (callback, delay) => setInterval(callback, delay),
50
- clearInterval: (intervalId) => clearInterval(intervalId)
51
- };
52
- var _provider, _providerCalled;
10
+ var _provider = /* @__PURE__ */ new WeakMap();
11
+ var _providerCalled = /* @__PURE__ */ new WeakMap();
12
+ /**
13
+ * Allows customization of how timeouts are created.
14
+ *
15
+ * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
16
+ * and `gcTime`. The default TimeoutManager provider uses the platform's global
17
+ * `setTimeout` implementation, which is known to have scalability issues with
18
+ * thousands of timeouts on the event loop.
19
+ *
20
+ * If you hit this limitation, consider providing a custom TimeoutProvider that
21
+ * coalesces timeouts.
22
+ */
53
23
  var TimeoutManager = class {
54
- constructor() {
55
- // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
56
- // type at app boot; and if we leave that type, then any new timer provider
57
- // would need to support the default provider's concrete timer ID, which is
58
- // infeasible across environments.
59
- //
60
- // We settle for type safety for the TimeoutProvider type, and accept that
61
- // this class is unsafe internally to allow for extension.
62
- __privateAdd(this, _provider, defaultTimeoutProvider);
63
- __privateAdd(this, _providerCalled, false);
64
- }
65
- setTimeoutProvider(provider) {
66
- if (process.env.NODE_ENV !== "production") {
67
- if (__privateGet(this, _providerCalled) && provider !== __privateGet(this, _provider)) {
68
- console.error(
69
- `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
70
- { previous: __privateGet(this, _provider), provider }
71
- );
72
- }
73
- }
74
- __privateSet(this, _provider, provider);
75
- if (process.env.NODE_ENV !== "production") {
76
- __privateSet(this, _providerCalled, false);
77
- }
78
- }
79
- setTimeout(callback, delay) {
80
- if (process.env.NODE_ENV !== "production") {
81
- __privateSet(this, _providerCalled, true);
82
- }
83
- return __privateGet(this, _provider).setTimeout(callback, delay);
84
- }
85
- clearTimeout(timeoutId) {
86
- __privateGet(this, _provider).clearTimeout(timeoutId);
87
- }
88
- setInterval(callback, delay) {
89
- if (process.env.NODE_ENV !== "production") {
90
- __privateSet(this, _providerCalled, true);
91
- }
92
- return __privateGet(this, _provider).setInterval(callback, delay);
93
- }
94
- clearInterval(intervalId) {
95
- __privateGet(this, _provider).clearInterval(intervalId);
96
- }
24
+ constructor() {
25
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _provider, defaultTimeoutProvider);
26
+ require_classPrivateFieldSet2._classPrivateFieldInitSpec(this, _providerCalled, false);
27
+ }
28
+ setTimeoutProvider(provider) {
29
+ if (process.env.NODE_ENV !== "production") {
30
+ if (require_classPrivateFieldSet2._classPrivateFieldGet2(_providerCalled, this) && provider !== require_classPrivateFieldSet2._classPrivateFieldGet2(_provider, this)) console.error(`[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`, {
31
+ previous: require_classPrivateFieldSet2._classPrivateFieldGet2(_provider, this),
32
+ provider
33
+ });
34
+ }
35
+ require_classPrivateFieldSet2._classPrivateFieldSet2(_provider, this, provider);
36
+ if (process.env.NODE_ENV !== "production") require_classPrivateFieldSet2._classPrivateFieldSet2(_providerCalled, this, false);
37
+ }
38
+ setTimeout(callback, delay) {
39
+ if (process.env.NODE_ENV !== "production") require_classPrivateFieldSet2._classPrivateFieldSet2(_providerCalled, this, true);
40
+ return require_classPrivateFieldSet2._classPrivateFieldGet2(_provider, this).setTimeout(callback, delay);
41
+ }
42
+ clearTimeout(timeoutId) {
43
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_provider, this).clearTimeout(timeoutId);
44
+ }
45
+ setInterval(callback, delay) {
46
+ if (process.env.NODE_ENV !== "production") require_classPrivateFieldSet2._classPrivateFieldSet2(_providerCalled, this, true);
47
+ return require_classPrivateFieldSet2._classPrivateFieldGet2(_provider, this).setInterval(callback, delay);
48
+ }
49
+ clearInterval(intervalId) {
50
+ require_classPrivateFieldSet2._classPrivateFieldGet2(_provider, this).clearInterval(intervalId);
51
+ }
97
52
  };
98
- _provider = new WeakMap();
99
- _providerCalled = new WeakMap();
100
- var timeoutManager = new TimeoutManager();
53
+ const timeoutManager = new TimeoutManager();
54
+ /**
55
+ * In many cases code wants to delay to the next event loop tick; this is not
56
+ * mediated by {@link timeoutManager}.
57
+ *
58
+ * This function is provided to make auditing the `tanstack/query-core` for
59
+ * incorrect use of system `setTimeout` easier.
60
+ */
101
61
  function systemSetTimeoutZero(callback) {
102
- setTimeout(callback, 0);
62
+ setTimeout(callback, 0);
103
63
  }
104
- // Annotate the CommonJS export names for ESM import in node:
105
- 0 && (module.exports = {
106
- TimeoutManager,
107
- defaultTimeoutProvider,
108
- systemSetTimeoutZero,
109
- timeoutManager
110
- });
64
+ //#endregion
65
+ exports.TimeoutManager = TimeoutManager;
66
+ exports.defaultTimeoutProvider = defaultTimeoutProvider;
67
+ exports.systemSetTimeoutZero = systemSetTimeoutZero;
68
+ exports.timeoutManager = timeoutManager;
69
+
111
70
  //# sourceMappingURL=timeoutManager.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\ntype SystemTimerId = ReturnType<typeof setTimeout>\n\nexport const defaultTimeoutProvider: TimeoutProvider = {\n // We need the wrapper function syntax below instead of direct references to\n // global setTimeout etc.\n //\n // BAD: `setTimeout: setTimeout`\n // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`\n //\n // If we use direct references here, then anything that wants to spy on or\n // replace the global setTimeout (like tests) won't work since we'll already\n // have a hard reference to the original implementation at the time when this\n // file was imported.\n setTimeout: (callback, delay) => setTimeout(callback, delay),\n clearTimeout: (timeoutId) =>\n clearTimeout(timeoutId as SystemTimerId | undefined),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) =>\n clearInterval(intervalId as SystemTimerId | undefined),\n}\n\n/**\n * Allows customization of how timeouts are created.\n *\n * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`\n * and `gcTime`. The default TimeoutManager provider uses the platform's global\n * `setTimeout` implementation, which is known to have scalability issues with\n * thousands of timeouts on the event loop.\n *\n * If you hit this limitation, consider providing a custom TimeoutProvider that\n * coalesces timeouts.\n */\nexport class TimeoutManager implements Omit<TimeoutProvider, 'name'> {\n // We cannot have TimeoutManager<T> as we must instantiate it with a concrete\n // type at app boot; and if we leave that type, then any new timer provider\n // would need to support the default provider's concrete timer ID, which is\n // infeasible across environments.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCO,IAAM,yBAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWrD,YAAY,CAAC,UAAU,UAAU,WAAW,UAAU,KAAK;AAAA,EAC3D,cAAc,CAAC,cACb,aAAa,SAAsC;AAAA,EAErD,aAAa,CAAC,UAAU,UAAU,YAAY,UAAU,KAAK;AAAA,EAC7D,eAAe,CAAC,eACd,cAAc,UAAuC;AACzD;AAlDA;AA+DO,IAAM,iBAAN,MAA8D;AAAA,EAA9D;AAQL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAkC;AAClC,wCAAkB;AAAA;AAAA,EAElB,mBACE,UACM;AACN,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,UAAI,mBAAK,oBAAmB,aAAa,mBAAK,YAAW;AAYvD,gBAAQ;AAAA,UACN;AAAA,UACA,EAAE,UAAU,mBAAK,YAAW,SAAS;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAEA,uBAAK,WAAY;AACjB,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,WAAW,UAA2B,OAA+B;AACnE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,WAAW,UAAU,KAAK;AAAA,EAClD;AAAA,EAEA,aAAa,WAA6C;AACxD,uBAAK,WAAU,aAAa,SAAS;AAAA,EACvC;AAAA,EAEA,YAAY,UAA2B,OAA+B;AACpE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,YAAY,UAAU,KAAK;AAAA,EACnD;AAAA,EAEA,cAAc,YAA8C;AAC1D,uBAAK,WAAU,cAAc,UAAU;AAAA,EACzC;AACF;AArDE;AACA;AAsDK,IAAM,iBAAiB,IAAI,eAAe;AAS1C,SAAS,qBAAqB,UAAiC;AACpE,aAAW,UAAU,CAAC;AACxB;","names":[]}
1
+ {"version":3,"file":"timeoutManager.cjs","names":[],"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\ntype SystemTimerId = ReturnType<typeof setTimeout>\n\nexport const defaultTimeoutProvider: TimeoutProvider = {\n // We need the wrapper function syntax below instead of direct references to\n // global setTimeout etc.\n //\n // BAD: `setTimeout: setTimeout`\n // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`\n //\n // If we use direct references here, then anything that wants to spy on or\n // replace the global setTimeout (like tests) won't work since we'll already\n // have a hard reference to the original implementation at the time when this\n // file was imported.\n setTimeout: (callback, delay) => setTimeout(callback, delay),\n clearTimeout: (timeoutId) =>\n clearTimeout(timeoutId as SystemTimerId | undefined),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) =>\n clearInterval(intervalId as SystemTimerId | undefined),\n}\n\n/**\n * Allows customization of how timeouts are created.\n *\n * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`\n * and `gcTime`. The default TimeoutManager provider uses the platform's global\n * `setTimeout` implementation, which is known to have scalability issues with\n * thousands of timeouts on the event loop.\n *\n * If you hit this limitation, consider providing a custom TimeoutProvider that\n * coalesces timeouts.\n */\nexport class TimeoutManager implements Omit<TimeoutProvider, 'name'> {\n // We cannot have TimeoutManager<T> as we must instantiate it with a concrete\n // type at app boot; and if we leave that type, then any new timer provider\n // would need to support the default provider's concrete timer ID, which is\n // infeasible across environments.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;;AAgCA,MAAa,yBAA0C;CAWrD,aAAa,UAAU,UAAU,WAAW,UAAU,KAAK;CAC3D,eAAe,cACb,aAAa,SAAsC;CAErD,cAAc,UAAU,UAAU,YAAY,UAAU,KAAK;CAC7D,gBAAgB,eACd,cAAc,UAAuC;AACzD;;;;;;;;;;;;;;AAaA,IAAa,iBAAb,MAAqE;;EAQjC,8BAAA,2BAAA,MAAA,WAAA,sBAAA;EAChB,8BAAA,2BAAA,MAAA,iBAAA,KAAA;;CAElB,mBACE,UACM;EACN,IAAI,QAAQ,IAAI,aAAa,cACvB;OAAA,8BAAA,uBAAA,iBAAA,IAAA,KAAwB,aAAA,8BAAA,uBAAA,WAAa,IAAA,GAYvC,QAAQ,MACN,8GACA;IAAE,UAAA,8BAAA,uBAAA,WAAU,IAAA;IAAgB;GAAS,CACvC;EAAA;EAIJ,8BAAA,uBAAA,WAAA,MAAiB,QAAA;EACjB,IAAI,QAAQ,IAAI,aAAa,cAC3B,8BAAA,uBAAA,iBAAA,MAAuB,KAAA;CAE3B;CAEA,WAAW,UAA2B,OAA+B;EACnE,IAAI,QAAQ,IAAI,aAAa,cAC3B,8BAAA,uBAAA,iBAAA,MAAuB,IAAA;EAEzB,OAAA,8BAAA,uBAAA,WAAO,IAAA,CAAA,CAAe,WAAW,UAAU,KAAK;CAClD;CAEA,aAAa,WAA6C;EACxD,8BAAA,uBAAA,WAAA,IAAA,CAAA,CAAe,aAAa,SAAS;CACvC;CAEA,YAAY,UAA2B,OAA+B;EACpE,IAAI,QAAQ,IAAI,aAAa,cAC3B,8BAAA,uBAAA,iBAAA,MAAuB,IAAA;EAEzB,OAAA,8BAAA,uBAAA,WAAO,IAAA,CAAA,CAAe,YAAY,UAAU,KAAK;CACnD;CAEA,cAAc,YAA8C;EAC1D,8BAAA,uBAAA,WAAA,IAAA,CAAA,CAAe,cAAc,UAAU;CACzC;AACF;AAEA,MAAa,iBAAiB,IAAI,eAAe;;;;;;;;AASjD,SAAgB,qBAAqB,UAAiC;CACpE,WAAW,UAAU,CAAC;AACxB"}
@@ -1,7 +1,60 @@
1
- export { systemSetTimeoutZero } from './_tsup-dts-rollup.cjs';
2
- export { TimeoutCallback_alias_1 as TimeoutCallback } from './_tsup-dts-rollup.cjs';
3
- export { ManagedTimerId_alias_1 as ManagedTimerId } from './_tsup-dts-rollup.cjs';
4
- export { TimeoutProvider_alias_1 as TimeoutProvider } from './_tsup-dts-rollup.cjs';
5
- export { defaultTimeoutProvider } from './_tsup-dts-rollup.cjs';
6
- export { TimeoutManager } from './_tsup-dts-rollup.cjs';
7
- export { timeoutManager_alias_1 as timeoutManager } from './_tsup-dts-rollup.cjs';
1
+ //#region src/timeoutManager.d.ts
2
+ /**
3
+ * {@link TimeoutManager} does not support passing arguments to the callback.
4
+ *
5
+ * `(_: void)` is the argument type inferred by TypeScript's default typings for
6
+ * `setTimeout(cb, number)`.
7
+ * If we don't accept a single void argument, then
8
+ * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.
9
+ */
10
+ type TimeoutCallback = (_: void) => void;
11
+ /**
12
+ * Wrapping `setTimeout` is awkward from a typing perspective because platform
13
+ * typings may extend the return type of `setTimeout`. For example, NodeJS
14
+ * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be
15
+ * able to return such a type.
16
+ */
17
+ type ManagedTimerId = number | {
18
+ [Symbol.toPrimitive]: () => number;
19
+ };
20
+ /**
21
+ * Backend for timer functions.
22
+ */
23
+ type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> = {
24
+ readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId;
25
+ readonly clearTimeout: (timeoutId: TTimerId | undefined) => void;
26
+ readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId;
27
+ readonly clearInterval: (intervalId: TTimerId | undefined) => void;
28
+ };
29
+ declare const defaultTimeoutProvider: TimeoutProvider;
30
+ /**
31
+ * Allows customization of how timeouts are created.
32
+ *
33
+ * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
34
+ * and `gcTime`. The default TimeoutManager provider uses the platform's global
35
+ * `setTimeout` implementation, which is known to have scalability issues with
36
+ * thousands of timeouts on the event loop.
37
+ *
38
+ * If you hit this limitation, consider providing a custom TimeoutProvider that
39
+ * coalesces timeouts.
40
+ */
41
+ declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
42
+ #private;
43
+ setTimeoutProvider<TTimerId extends ManagedTimerId>(provider: TimeoutProvider<TTimerId>): void;
44
+ setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId;
45
+ clearTimeout(timeoutId: ManagedTimerId | undefined): void;
46
+ setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId;
47
+ clearInterval(intervalId: ManagedTimerId | undefined): void;
48
+ }
49
+ declare const timeoutManager: TimeoutManager;
50
+ /**
51
+ * In many cases code wants to delay to the next event loop tick; this is not
52
+ * mediated by {@link timeoutManager}.
53
+ *
54
+ * This function is provided to make auditing the `tanstack/query-core` for
55
+ * incorrect use of system `setTimeout` easier.
56
+ */
57
+ declare function systemSetTimeoutZero(callback: TimeoutCallback): void;
58
+ //#endregion
59
+ export { ManagedTimerId, TimeoutCallback, TimeoutManager, TimeoutProvider, defaultTimeoutProvider, systemSetTimeoutZero, timeoutManager };
60
+ //# sourceMappingURL=timeoutManager.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeoutManager.d.cts","names":[],"sources":["../../src/timeoutManager.ts"],"mappings":";;;;;;;;;KAQY,mBAAmB;;;;;;;KAQnB;GAA6B,OAAO;;;;;KAKpC,gBAAgB,iBAAiB,iBAAiB;WAEjD,aAAa,UAAU,iBAAiB,kBAAkB;WAC1D,eAAe,WAAW;WAE1B,cAAc,UAAU,iBAAiB,kBAAkB;WAC3D,gBAAgB,YAAY;;cAK5B,wBAAwB;;;;;;;;;;;;cA+BxB,0BAA0B,KAAK;;EAW1C,mBAAmB,iBAAiB,gBAClC,UAAU,gBAAgB;EA4B5B,WAAW,UAAU,iBAAiB,gBAAgB;EAOtD,aAAa,WAAW;EAIxB,YAAY,UAAU,iBAAiB,gBAAgB;EAOvD,cAAc,YAAY;;cAKf,gBAAc;;;;;;;;iBASX,qBAAqB,UAAU"}
@@ -1,7 +1,60 @@
1
- export { systemSetTimeoutZero } from './_tsup-dts-rollup.js';
2
- export { TimeoutCallback_alias_1 as TimeoutCallback } from './_tsup-dts-rollup.js';
3
- export { ManagedTimerId_alias_1 as ManagedTimerId } from './_tsup-dts-rollup.js';
4
- export { TimeoutProvider_alias_1 as TimeoutProvider } from './_tsup-dts-rollup.js';
5
- export { defaultTimeoutProvider } from './_tsup-dts-rollup.js';
6
- export { TimeoutManager } from './_tsup-dts-rollup.js';
7
- export { timeoutManager_alias_1 as timeoutManager } from './_tsup-dts-rollup.js';
1
+ //#region src/timeoutManager.d.ts
2
+ /**
3
+ * {@link TimeoutManager} does not support passing arguments to the callback.
4
+ *
5
+ * `(_: void)` is the argument type inferred by TypeScript's default typings for
6
+ * `setTimeout(cb, number)`.
7
+ * If we don't accept a single void argument, then
8
+ * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.
9
+ */
10
+ type TimeoutCallback = (_: void) => void;
11
+ /**
12
+ * Wrapping `setTimeout` is awkward from a typing perspective because platform
13
+ * typings may extend the return type of `setTimeout`. For example, NodeJS
14
+ * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be
15
+ * able to return such a type.
16
+ */
17
+ type ManagedTimerId = number | {
18
+ [Symbol.toPrimitive]: () => number;
19
+ };
20
+ /**
21
+ * Backend for timer functions.
22
+ */
23
+ type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> = {
24
+ readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId;
25
+ readonly clearTimeout: (timeoutId: TTimerId | undefined) => void;
26
+ readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId;
27
+ readonly clearInterval: (intervalId: TTimerId | undefined) => void;
28
+ };
29
+ declare const defaultTimeoutProvider: TimeoutProvider;
30
+ /**
31
+ * Allows customization of how timeouts are created.
32
+ *
33
+ * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
34
+ * and `gcTime`. The default TimeoutManager provider uses the platform's global
35
+ * `setTimeout` implementation, which is known to have scalability issues with
36
+ * thousands of timeouts on the event loop.
37
+ *
38
+ * If you hit this limitation, consider providing a custom TimeoutProvider that
39
+ * coalesces timeouts.
40
+ */
41
+ declare class TimeoutManager implements Omit<TimeoutProvider, 'name'> {
42
+ #private;
43
+ setTimeoutProvider<TTimerId extends ManagedTimerId>(provider: TimeoutProvider<TTimerId>): void;
44
+ setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId;
45
+ clearTimeout(timeoutId: ManagedTimerId | undefined): void;
46
+ setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId;
47
+ clearInterval(intervalId: ManagedTimerId | undefined): void;
48
+ }
49
+ declare const timeoutManager: TimeoutManager;
50
+ /**
51
+ * In many cases code wants to delay to the next event loop tick; this is not
52
+ * mediated by {@link timeoutManager}.
53
+ *
54
+ * This function is provided to make auditing the `tanstack/query-core` for
55
+ * incorrect use of system `setTimeout` easier.
56
+ */
57
+ declare function systemSetTimeoutZero(callback: TimeoutCallback): void;
58
+ //#endregion
59
+ export { ManagedTimerId, TimeoutCallback, TimeoutManager, TimeoutProvider, defaultTimeoutProvider, systemSetTimeoutZero, timeoutManager };
60
+ //# sourceMappingURL=timeoutManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeoutManager.d.ts","names":[],"sources":["../../src/timeoutManager.ts"],"mappings":";;;;;;;;;KAQY,mBAAmB;;;;;;;KAQnB;GAA6B,OAAO;;;;;KAKpC,gBAAgB,iBAAiB,iBAAiB;WAEjD,aAAa,UAAU,iBAAiB,kBAAkB;WAC1D,eAAe,WAAW;WAE1B,cAAc,UAAU,iBAAiB,kBAAkB;WAC3D,gBAAgB,YAAY;;cAK5B,wBAAwB;;;;;;;;;;;;cA+BxB,0BAA0B,KAAK;;EAW1C,mBAAmB,iBAAiB,gBAClC,UAAU,gBAAgB;EA4B5B,WAAW,UAAU,iBAAiB,gBAAgB;EAOtD,aAAa,WAAW;EAIxB,YAAY,UAAU,iBAAiB,gBAAgB;EAOvD,cAAc,YAAY;;cAKf,gBAAc;;;;;;;;iBASX,qBAAqB,UAAU"}
@@ -1,82 +1,66 @@
1
- import {
2
- __privateAdd,
3
- __privateGet,
4
- __privateSet
5
- } from "./chunk-PXG64RU4.js";
6
-
7
- // src/timeoutManager.ts
8
- var defaultTimeoutProvider = {
9
- // We need the wrapper function syntax below instead of direct references to
10
- // global setTimeout etc.
11
- //
12
- // BAD: `setTimeout: setTimeout`
13
- // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
14
- //
15
- // If we use direct references here, then anything that wants to spy on or
16
- // replace the global setTimeout (like tests) won't work since we'll already
17
- // have a hard reference to the original implementation at the time when this
18
- // file was imported.
19
- setTimeout: (callback, delay) => setTimeout(callback, delay),
20
- clearTimeout: (timeoutId) => clearTimeout(timeoutId),
21
- setInterval: (callback, delay) => setInterval(callback, delay),
22
- clearInterval: (intervalId) => clearInterval(intervalId)
1
+ import { i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, t as _classPrivateFieldSet2 } from "./classPrivateFieldSet2-CV7wyte-.js";
2
+ //#region src/timeoutManager.ts
3
+ const defaultTimeoutProvider = {
4
+ setTimeout: (callback, delay) => setTimeout(callback, delay),
5
+ clearTimeout: (timeoutId) => clearTimeout(timeoutId),
6
+ setInterval: (callback, delay) => setInterval(callback, delay),
7
+ clearInterval: (intervalId) => clearInterval(intervalId)
23
8
  };
24
- var _provider, _providerCalled;
9
+ var _provider = /* @__PURE__ */ new WeakMap();
10
+ var _providerCalled = /* @__PURE__ */ new WeakMap();
11
+ /**
12
+ * Allows customization of how timeouts are created.
13
+ *
14
+ * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`
15
+ * and `gcTime`. The default TimeoutManager provider uses the platform's global
16
+ * `setTimeout` implementation, which is known to have scalability issues with
17
+ * thousands of timeouts on the event loop.
18
+ *
19
+ * If you hit this limitation, consider providing a custom TimeoutProvider that
20
+ * coalesces timeouts.
21
+ */
25
22
  var TimeoutManager = class {
26
- constructor() {
27
- // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
28
- // type at app boot; and if we leave that type, then any new timer provider
29
- // would need to support the default provider's concrete timer ID, which is
30
- // infeasible across environments.
31
- //
32
- // We settle for type safety for the TimeoutProvider type, and accept that
33
- // this class is unsafe internally to allow for extension.
34
- __privateAdd(this, _provider, defaultTimeoutProvider);
35
- __privateAdd(this, _providerCalled, false);
36
- }
37
- setTimeoutProvider(provider) {
38
- if (process.env.NODE_ENV !== "production") {
39
- if (__privateGet(this, _providerCalled) && provider !== __privateGet(this, _provider)) {
40
- console.error(
41
- `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
42
- { previous: __privateGet(this, _provider), provider }
43
- );
44
- }
45
- }
46
- __privateSet(this, _provider, provider);
47
- if (process.env.NODE_ENV !== "production") {
48
- __privateSet(this, _providerCalled, false);
49
- }
50
- }
51
- setTimeout(callback, delay) {
52
- if (process.env.NODE_ENV !== "production") {
53
- __privateSet(this, _providerCalled, true);
54
- }
55
- return __privateGet(this, _provider).setTimeout(callback, delay);
56
- }
57
- clearTimeout(timeoutId) {
58
- __privateGet(this, _provider).clearTimeout(timeoutId);
59
- }
60
- setInterval(callback, delay) {
61
- if (process.env.NODE_ENV !== "production") {
62
- __privateSet(this, _providerCalled, true);
63
- }
64
- return __privateGet(this, _provider).setInterval(callback, delay);
65
- }
66
- clearInterval(intervalId) {
67
- __privateGet(this, _provider).clearInterval(intervalId);
68
- }
23
+ constructor() {
24
+ _classPrivateFieldInitSpec(this, _provider, defaultTimeoutProvider);
25
+ _classPrivateFieldInitSpec(this, _providerCalled, false);
26
+ }
27
+ setTimeoutProvider(provider) {
28
+ if (process.env.NODE_ENV !== "production") {
29
+ if (_classPrivateFieldGet2(_providerCalled, this) && provider !== _classPrivateFieldGet2(_provider, this)) console.error(`[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`, {
30
+ previous: _classPrivateFieldGet2(_provider, this),
31
+ provider
32
+ });
33
+ }
34
+ _classPrivateFieldSet2(_provider, this, provider);
35
+ if (process.env.NODE_ENV !== "production") _classPrivateFieldSet2(_providerCalled, this, false);
36
+ }
37
+ setTimeout(callback, delay) {
38
+ if (process.env.NODE_ENV !== "production") _classPrivateFieldSet2(_providerCalled, this, true);
39
+ return _classPrivateFieldGet2(_provider, this).setTimeout(callback, delay);
40
+ }
41
+ clearTimeout(timeoutId) {
42
+ _classPrivateFieldGet2(_provider, this).clearTimeout(timeoutId);
43
+ }
44
+ setInterval(callback, delay) {
45
+ if (process.env.NODE_ENV !== "production") _classPrivateFieldSet2(_providerCalled, this, true);
46
+ return _classPrivateFieldGet2(_provider, this).setInterval(callback, delay);
47
+ }
48
+ clearInterval(intervalId) {
49
+ _classPrivateFieldGet2(_provider, this).clearInterval(intervalId);
50
+ }
69
51
  };
70
- _provider = new WeakMap();
71
- _providerCalled = new WeakMap();
72
- var timeoutManager = new TimeoutManager();
52
+ const timeoutManager = new TimeoutManager();
53
+ /**
54
+ * In many cases code wants to delay to the next event loop tick; this is not
55
+ * mediated by {@link timeoutManager}.
56
+ *
57
+ * This function is provided to make auditing the `tanstack/query-core` for
58
+ * incorrect use of system `setTimeout` easier.
59
+ */
73
60
  function systemSetTimeoutZero(callback) {
74
- setTimeout(callback, 0);
61
+ setTimeout(callback, 0);
75
62
  }
76
- export {
77
- TimeoutManager,
78
- defaultTimeoutProvider,
79
- systemSetTimeoutZero,
80
- timeoutManager
81
- };
63
+ //#endregion
64
+ export { TimeoutManager, defaultTimeoutProvider, systemSetTimeoutZero, timeoutManager };
65
+
82
66
  //# sourceMappingURL=timeoutManager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\ntype SystemTimerId = ReturnType<typeof setTimeout>\n\nexport const defaultTimeoutProvider: TimeoutProvider = {\n // We need the wrapper function syntax below instead of direct references to\n // global setTimeout etc.\n //\n // BAD: `setTimeout: setTimeout`\n // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`\n //\n // If we use direct references here, then anything that wants to spy on or\n // replace the global setTimeout (like tests) won't work since we'll already\n // have a hard reference to the original implementation at the time when this\n // file was imported.\n setTimeout: (callback, delay) => setTimeout(callback, delay),\n clearTimeout: (timeoutId) =>\n clearTimeout(timeoutId as SystemTimerId | undefined),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) =>\n clearInterval(intervalId as SystemTimerId | undefined),\n}\n\n/**\n * Allows customization of how timeouts are created.\n *\n * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`\n * and `gcTime`. The default TimeoutManager provider uses the platform's global\n * `setTimeout` implementation, which is known to have scalability issues with\n * thousands of timeouts on the event loop.\n *\n * If you hit this limitation, consider providing a custom TimeoutProvider that\n * coalesces timeouts.\n */\nexport class TimeoutManager implements Omit<TimeoutProvider, 'name'> {\n // We cannot have TimeoutManager<T> as we must instantiate it with a concrete\n // type at app boot; and if we leave that type, then any new timer provider\n // would need to support the default provider's concrete timer ID, which is\n // infeasible across environments.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;;;;;;AAgCO,IAAM,yBAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWrD,YAAY,CAAC,UAAU,UAAU,WAAW,UAAU,KAAK;AAAA,EAC3D,cAAc,CAAC,cACb,aAAa,SAAsC;AAAA,EAErD,aAAa,CAAC,UAAU,UAAU,YAAY,UAAU,KAAK;AAAA,EAC7D,eAAe,CAAC,eACd,cAAc,UAAuC;AACzD;AAlDA;AA+DO,IAAM,iBAAN,MAA8D;AAAA,EAA9D;AAQL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAkC;AAClC,wCAAkB;AAAA;AAAA,EAElB,mBACE,UACM;AACN,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,UAAI,mBAAK,oBAAmB,aAAa,mBAAK,YAAW;AAYvD,gBAAQ;AAAA,UACN;AAAA,UACA,EAAE,UAAU,mBAAK,YAAW,SAAS;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AAEA,uBAAK,WAAY;AACjB,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AAAA,EACF;AAAA,EAEA,WAAW,UAA2B,OAA+B;AACnE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,WAAW,UAAU,KAAK;AAAA,EAClD;AAAA,EAEA,aAAa,WAA6C;AACxD,uBAAK,WAAU,aAAa,SAAS;AAAA,EACvC;AAAA,EAEA,YAAY,UAA2B,OAA+B;AACpE,QAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,yBAAK,iBAAkB;AAAA,IACzB;AACA,WAAO,mBAAK,WAAU,YAAY,UAAU,KAAK;AAAA,EACnD;AAAA,EAEA,cAAc,YAA8C;AAC1D,uBAAK,WAAU,cAAc,UAAU;AAAA,EACzC;AACF;AArDE;AACA;AAsDK,IAAM,iBAAiB,IAAI,eAAe;AAS1C,SAAS,qBAAqB,UAAiC;AACpE,aAAW,UAAU,CAAC;AACxB;","names":[]}
1
+ {"version":3,"file":"timeoutManager.js","names":[],"sources":["../../src/timeoutManager.ts"],"sourcesContent":["/**\n * {@link TimeoutManager} does not support passing arguments to the callback.\n *\n * `(_: void)` is the argument type inferred by TypeScript's default typings for\n * `setTimeout(cb, number)`.\n * If we don't accept a single void argument, then\n * `new Promise(resolve => timeoutManager.setTimeout(resolve, N))` is a type error.\n */\nexport type TimeoutCallback = (_: void) => void\n\n/**\n * Wrapping `setTimeout` is awkward from a typing perspective because platform\n * typings may extend the return type of `setTimeout`. For example, NodeJS\n * typings add `NodeJS.Timeout`; but a non-default `timeoutManager` may not be\n * able to return such a type.\n */\nexport type ManagedTimerId = number | { [Symbol.toPrimitive]: () => number }\n\n/**\n * Backend for timer functions.\n */\nexport type TimeoutProvider<TTimerId extends ManagedTimerId = ManagedTimerId> =\n {\n readonly setTimeout: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearTimeout: (timeoutId: TTimerId | undefined) => void\n\n readonly setInterval: (callback: TimeoutCallback, delay: number) => TTimerId\n readonly clearInterval: (intervalId: TTimerId | undefined) => void\n }\n\ntype SystemTimerId = ReturnType<typeof setTimeout>\n\nexport const defaultTimeoutProvider: TimeoutProvider = {\n // We need the wrapper function syntax below instead of direct references to\n // global setTimeout etc.\n //\n // BAD: `setTimeout: setTimeout`\n // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`\n //\n // If we use direct references here, then anything that wants to spy on or\n // replace the global setTimeout (like tests) won't work since we'll already\n // have a hard reference to the original implementation at the time when this\n // file was imported.\n setTimeout: (callback, delay) => setTimeout(callback, delay),\n clearTimeout: (timeoutId) =>\n clearTimeout(timeoutId as SystemTimerId | undefined),\n\n setInterval: (callback, delay) => setInterval(callback, delay),\n clearInterval: (intervalId) =>\n clearInterval(intervalId as SystemTimerId | undefined),\n}\n\n/**\n * Allows customization of how timeouts are created.\n *\n * @tanstack/query-core makes liberal use of timeouts to implement `staleTime`\n * and `gcTime`. The default TimeoutManager provider uses the platform's global\n * `setTimeout` implementation, which is known to have scalability issues with\n * thousands of timeouts on the event loop.\n *\n * If you hit this limitation, consider providing a custom TimeoutProvider that\n * coalesces timeouts.\n */\nexport class TimeoutManager implements Omit<TimeoutProvider, 'name'> {\n // We cannot have TimeoutManager<T> as we must instantiate it with a concrete\n // type at app boot; and if we leave that type, then any new timer provider\n // would need to support the default provider's concrete timer ID, which is\n // infeasible across environments.\n //\n // We settle for type safety for the TimeoutProvider type, and accept that\n // this class is unsafe internally to allow for extension.\n #provider: TimeoutProvider<any> = defaultTimeoutProvider\n #providerCalled = false\n\n setTimeoutProvider<TTimerId extends ManagedTimerId>(\n provider: TimeoutProvider<TTimerId>,\n ): void {\n if (process.env.NODE_ENV !== 'production') {\n if (this.#providerCalled && provider !== this.#provider) {\n // After changing providers, `clearTimeout` will not work as expected for\n // timeouts from the previous provider.\n //\n // Since they may allocate the same timeout ID, clearTimeout may cancel an\n // arbitrary different timeout, or unexpected no-op.\n //\n // We could protect against this by mixing the timeout ID bits\n // deterministically with some per-provider bits.\n //\n // We could internally queue `setTimeout` calls to `TimeoutManager` until\n // some API call to set the initial provider.\n console.error(\n `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,\n { previous: this.#provider, provider },\n )\n }\n }\n\n this.#provider = provider\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = false\n }\n }\n\n setTimeout(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setTimeout(callback, delay)\n }\n\n clearTimeout(timeoutId: ManagedTimerId | undefined): void {\n this.#provider.clearTimeout(timeoutId)\n }\n\n setInterval(callback: TimeoutCallback, delay: number): ManagedTimerId {\n if (process.env.NODE_ENV !== 'production') {\n this.#providerCalled = true\n }\n return this.#provider.setInterval(callback, delay)\n }\n\n clearInterval(intervalId: ManagedTimerId | undefined): void {\n this.#provider.clearInterval(intervalId)\n }\n}\n\nexport const timeoutManager = new TimeoutManager()\n\n/**\n * In many cases code wants to delay to the next event loop tick; this is not\n * mediated by {@link timeoutManager}.\n *\n * This function is provided to make auditing the `tanstack/query-core` for\n * incorrect use of system `setTimeout` easier.\n */\nexport function systemSetTimeoutZero(callback: TimeoutCallback): void {\n setTimeout(callback, 0)\n}\n"],"mappings":";;AAgCA,MAAa,yBAA0C;CAWrD,aAAa,UAAU,UAAU,WAAW,UAAU,KAAK;CAC3D,eAAe,cACb,aAAa,SAAsC;CAErD,cAAc,UAAU,UAAU,YAAY,UAAU,KAAK;CAC7D,gBAAgB,eACd,cAAc,UAAuC;AACzD;;;;;;;;;;;;;;AAaA,IAAa,iBAAb,MAAqE;;EAQjC,2BAAA,MAAA,WAAA,sBAAA;EAChB,2BAAA,MAAA,iBAAA,KAAA;;CAElB,mBACE,UACM;EACN,IAAI,QAAQ,IAAI,aAAa,cACvB;OAAA,uBAAA,iBAAA,IAAA,KAAwB,aAAA,uBAAA,WAAa,IAAA,GAYvC,QAAQ,MACN,8GACA;IAAE,UAAA,uBAAA,WAAU,IAAA;IAAgB;GAAS,CACvC;EAAA;EAIJ,uBAAA,WAAA,MAAiB,QAAA;EACjB,IAAI,QAAQ,IAAI,aAAa,cAC3B,uBAAA,iBAAA,MAAuB,KAAA;CAE3B;CAEA,WAAW,UAA2B,OAA+B;EACnE,IAAI,QAAQ,IAAI,aAAa,cAC3B,uBAAA,iBAAA,MAAuB,IAAA;EAEzB,OAAA,uBAAA,WAAO,IAAA,CAAA,CAAe,WAAW,UAAU,KAAK;CAClD;CAEA,aAAa,WAA6C;EACxD,uBAAA,WAAA,IAAA,CAAA,CAAe,aAAa,SAAS;CACvC;CAEA,YAAY,UAA2B,OAA+B;EACpE,IAAI,QAAQ,IAAI,aAAa,cAC3B,uBAAA,iBAAA,MAAuB,IAAA;EAEzB,OAAA,uBAAA,WAAO,IAAA,CAAA,CAAe,YAAY,UAAU,KAAK;CACnD;CAEA,cAAc,YAA8C;EAC1D,uBAAA,WAAA,IAAA,CAAA,CAAe,cAAc,UAAU;CACzC;AACF;AAEA,MAAa,iBAAiB,IAAI,eAAe;;;;;;;;AASjD,SAAgB,qBAAqB,UAAiC;CACpE,WAAW,UAAU,CAAC;AACxB"}